summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-05-07 15:00:33 -0400
committerGitHub <noreply@github.com>2020-05-07 15:00:33 -0400
commitc16abd4fe1bda5ebcd50dbb22f30c6be43bb885f (patch)
treed127a9bd48708d909ab36efdd2ac0d9956f7541b /source
parent9245460adaf739c5a4d85f7f477b65fcd07d595b (diff)
Enhanced C++ extractor (#1340)
* Extractor builds without any reference to syntax (as it will be helping to produce this!). * Change macros to include the super class. * Added indexOf(const UnownedSubString& in) to UnownedSubString. Refactored extractor * Output a macro for each type with the extracted info - can be used during injection in class * Simplify the header file - as can get super type and last from macro now * Store the 'origin' of a definition * Some small tidy ups to the extractor. * Improve comments on the extractor options. * Made CPPExtractor own SourceOrigins * Small fixes around SourceOrigin. * Small tidy up around macroOrign
Diffstat (limited to 'source')
-rw-r--r--source/core/slang-string.cpp47
-rw-r--r--source/core/slang-string.h17
-rw-r--r--source/slang/slang-compiler.cpp26
-rw-r--r--source/slang/slang-compiler.h2
-rw-r--r--source/slang/slang-diagnostics.cpp69
-rw-r--r--source/slang/slang-diagnostics.h29
-rw-r--r--source/slang/slang-file-system.cpp2
-rw-r--r--source/slang/slang-ir.cpp9
-rw-r--r--source/slang/slang-ir.h2
-rw-r--r--source/slang/slang-lexer.cpp2
-rw-r--r--source/slang/slang-source-loc.cpp2
-rw-r--r--source/slang/slang-syntax.cpp44
-rw-r--r--source/slang/slang-syntax.h16
13 files changed, 159 insertions, 108 deletions
diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp
index df711218c..bcf5853d5 100644
--- a/source/core/slang-string.cpp
+++ b/source/core/slang-string.cpp
@@ -439,4 +439,51 @@ namespace Slang
sprintf_s(data, kCount, format, val);
m_buffer->length += strnlen_s(data, kCount);
}
+
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UnownedStringSlice !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+ Index UnownedStringSlice::indexOf(char c) const
+ {
+ const Index size = Index(m_end - m_begin);
+ for (Index i = 0; i < size; ++i)
+ {
+ if (m_begin[i] == c)
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ Index UnownedStringSlice::indexOf(const UnownedStringSlice& in) const
+ {
+ const Index len = getLength();
+ const Index inLen = in.getLength();
+ if (inLen > len)
+ {
+ return -1;
+ }
+
+ const char* inChars = in.m_begin;
+ switch (inLen)
+ {
+ case 0: return 0;
+ case 1: return indexOf(inChars[0]);
+ default: break;
+ }
+
+ const char* chars = m_begin;
+ const char firstChar = inChars[0];
+
+ for (Int i = 0; i < len - inLen; ++i)
+ {
+ if (chars[i] == firstChar && in == UnownedStringSlice(chars + i, inLen))
+ {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
}
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index 10bc76048..5eb113dc1 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -104,18 +104,11 @@ namespace Slang
return Index(m_end - m_begin);
}
- Index indexOf(char c) const
- {
- const Index size = int(m_end - m_begin);
- for (Index i = 0; i < size; ++i)
- {
- if (m_begin[i] == c)
- {
- return i;
- }
- }
- return -1;
- }
+ /// Finds first index of char 'c'. If not found returns -1.
+ Index indexOf(char c) const;
+ /// Find first index of slice. If not found returns -1
+ Index indexOf(const UnownedStringSlice& slice) const;
+
Index lastIndexOf(char c) const
{
const Index size = Index(m_end - m_begin);
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index f81a63275..8a8017ef3 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -80,6 +80,32 @@
namespace Slang
{
+
+ // !!!!!!!!!!!!!!!!!!!!!! free functions for DiagnosicSink !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+ void printDiagnosticArg(StringBuilder& sb, CodeGenTarget val)
+ {
+ switch (val)
+ {
+ default:
+ sb << "<unknown>";
+ break;
+
+ #define CASE(TAG, STR) case CodeGenTarget::TAG: sb << STR; break
+ CASE(GLSL, "glsl");
+ CASE(HLSL, "hlsl");
+ CASE(SPIRV, "spirv");
+ CASE(SPIRVAssembly, "spriv-assembly");
+ CASE(DXBytecode, "dxbc");
+ CASE(DXBytecodeAssembly, "dxbc-assembly");
+ CASE(DXIL, "dxil");
+ CASE(DXILAssembly, "dxil-assembly");
+ #undef CASE
+ }
+ }
+
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!! CompileResult !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
SlangResult CompileResult::getSharedLibrary(ComPtr<ISlangSharedLibrary>& outSharedLibrary)
{
if (downstreamResult)
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 89da498ac..fb13ab146 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -72,6 +72,8 @@ namespace Slang
CountOf = SLANG_TARGET_COUNT_OF,
};
+ void printDiagnosticArg(StringBuilder& sb, CodeGenTarget val);
+
enum class ContainerFormat : SlangContainerFormat
{
None = SLANG_CONTAINER_FORMAT_NONE,
diff --git a/source/slang/slang-diagnostics.cpp b/source/slang/slang-diagnostics.cpp
index bb8b63540..615312661 100644
--- a/source/slang/slang-diagnostics.cpp
+++ b/source/slang/slang-diagnostics.cpp
@@ -1,9 +1,7 @@
// slang-diagnostics.cpp
#include "slang-diagnostics.h"
-#include "slang-compiler.h"
#include "slang-name.h"
-#include "slang-syntax.h"
#include <assert.h>
@@ -65,34 +63,6 @@ void printDiagnosticArg(StringBuilder& sb, Name* name)
}
-void printDiagnosticArg(StringBuilder& sb, Decl* decl)
-{
- sb << getText(decl->getName());
-}
-
-void printDiagnosticArg(StringBuilder& sb, Type* type)
-{
- sb << type->ToString();
-}
-
-void printDiagnosticArg(StringBuilder& sb, Val* val)
-{
- sb << val->ToString();
-}
-
-void printDiagnosticArg(StringBuilder& sb, TypeExp const& type)
-{
- sb << type.type->ToString();
-}
-
-void printDiagnosticArg(StringBuilder& sb, QualType const& type)
-{
- if (type.type)
- sb << type.type->ToString();
- else
- sb << "<null>";
-}
-
void printDiagnosticArg(StringBuilder& sb, TokenType tokenType)
{
sb << TokenTypeToString(tokenType);
@@ -103,50 +73,11 @@ void printDiagnosticArg(StringBuilder& sb, Token const& token)
sb << token.Content;
}
-void printDiagnosticArg(StringBuilder& sb, CodeGenTarget val)
-{
- switch( val )
- {
- default:
- sb << "<unknown>";
- break;
-
-#define CASE(TAG, STR) case CodeGenTarget::TAG: sb << STR; break
- CASE(GLSL, "glsl");
- CASE(HLSL, "hlsl");
- CASE(SPIRV, "spirv");
- CASE(SPIRVAssembly, "spriv-assembly");
- CASE(DXBytecode, "dxbc");
- CASE(DXBytecodeAssembly, "dxbc-assembly");
- CASE(DXIL, "dxil");
- CASE(DXILAssembly, "dxil-assembly");
-#undef CASE
- }
-}
-
-
-
-SourceLoc const& getDiagnosticPos(SyntaxNode const* syntax)
-{
- return syntax->loc;
-}
-
SourceLoc const& getDiagnosticPos(Token const& token)
{
return token.loc;
}
-SourceLoc const& getDiagnosticPos(TypeExp const& typeExp)
-{
- return typeExp.exp->loc;
-}
-
-SourceLoc const& getDiagnosticPos(IRInst* inst)
-{
- return inst->sourceLoc;
-}
-
-
// Take the format string for a diagnostic message, along with its arguments, and turn it into a
static void formatDiagnosticMessage(StringBuilder& sb, char const* format, int argCount, DiagnosticArg const* const* args)
{
diff --git a/source/slang/slang-diagnostics.h b/source/slang/slang-diagnostics.h
index 8ab860708..80e14d1c1 100644
--- a/source/slang/slang-diagnostics.h
+++ b/source/slang/slang-diagnostics.h
@@ -69,15 +69,11 @@ namespace Slang
};
class Name;
- class Decl;
- struct QualType;
- class Type;
- struct TypeExp;
- class Val;
- enum class CodeGenTarget;
- enum class Stage : SlangStage;
- enum class ProfileVersion;
+ //enum class CodeGenTarget;
+
+ //enum class Stage : SlangStage;
+ //enum class ProfileVersion;
void printDiagnosticArg(StringBuilder& sb, char const* str);
@@ -92,15 +88,11 @@ namespace Slang
void printDiagnosticArg(StringBuilder& sb, Slang::String const& str);
void printDiagnosticArg(StringBuilder& sb, Slang::UnownedStringSlice const& str);
void printDiagnosticArg(StringBuilder& sb, Name* name);
- void printDiagnosticArg(StringBuilder& sb, Decl* decl);
- void printDiagnosticArg(StringBuilder& sb, Type* type);
- void printDiagnosticArg(StringBuilder& sb, TypeExp const& type);
- void printDiagnosticArg(StringBuilder& sb, QualType const& type);
+
void printDiagnosticArg(StringBuilder& sb, TokenType tokenType);
void printDiagnosticArg(StringBuilder& sb, Token const& token);
- void printDiagnosticArg(StringBuilder& sb, CodeGenTarget val);
- void printDiagnosticArg(StringBuilder& sb, Val* val);
-
+
+
template<typename T>
void printDiagnosticArg(StringBuilder& sb, RefPtr<T> ptr)
{
@@ -109,13 +101,8 @@ namespace Slang
inline SourceLoc const& getDiagnosticPos(SourceLoc const& pos) { return pos; }
- class SyntaxNode;
- SourceLoc const& getDiagnosticPos(SyntaxNode const* syntax);
SourceLoc const& getDiagnosticPos(Token const& token);
- SourceLoc const& getDiagnosticPos(TypeExp const& typeExp);
-
- struct IRInst;
- SourceLoc const& getDiagnosticPos(IRInst* inst);
+
template<typename T>
SourceLoc getDiagnosticPos(RefPtr<T> const& ptr)
diff --git a/source/slang/slang-file-system.cpp b/source/slang/slang-file-system.cpp
index c6bee28e1..29db71459 100644
--- a/source/slang/slang-file-system.cpp
+++ b/source/slang/slang-file-system.cpp
@@ -4,8 +4,6 @@
#include "../core/slang-io.h"
#include "../core/slang-string-util.h"
-#include "slang-compiler.h"
-
namespace Slang
{
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 9a44787ff..9fb966eba 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -10,6 +10,15 @@ namespace Slang
{
struct IRSpecContext;
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!! DiagnosticSink Impls !!!!!!!!!!!!!!!!!!!!!
+
+ SourceLoc const& getDiagnosticPos(IRInst* inst)
+ {
+ return inst->sourceLoc;
+ }
+
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!! DiagnosticSink Impls !!!!!!!!!!!!!!!!!!!!!
+
IRInst* cloneGlobalValueWithLinkage(
IRSpecContext* context,
IRInst* originalVal,
diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h
index 0ca0093f2..d9d09975d 100644
--- a/source/slang/slang-ir.h
+++ b/source/slang/slang-ir.h
@@ -565,6 +565,8 @@ T* cast(IRInst* inst, T* /* */ = nullptr)
return (T*)inst;
}
+SourceLoc const& getDiagnosticPos(IRInst* inst);
+
// Now that `IRInst` is defined we can back-fill the definitions that need to access it.
template<typename T>
diff --git a/source/slang/slang-lexer.cpp b/source/slang/slang-lexer.cpp
index 9b3bed88e..e091de735 100644
--- a/source/slang/slang-lexer.cpp
+++ b/source/slang/slang-lexer.cpp
@@ -5,7 +5,7 @@
// input bytes and turning it into semantically useful tokens.
//
-#include "slang-compiler.h"
+#include "slang-name.h"
#include "slang-source-loc.h"
#include <assert.h>
diff --git a/source/slang/slang-source-loc.cpp b/source/slang/slang-source-loc.cpp
index ef45c42b0..eb2ea6b1b 100644
--- a/source/slang/slang-source-loc.cpp
+++ b/source/slang/slang-source-loc.cpp
@@ -1,8 +1,6 @@
// slang-source-loc.cpp
#include "slang-source-loc.h"
-#include "slang-compiler.h"
-
#include "../core/slang-string-util.h"
namespace Slang {
diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp
index 334273870..2055c2422 100644
--- a/source/slang/slang-syntax.cpp
+++ b/source/slang/slang-syntax.cpp
@@ -74,6 +74,7 @@ ABSTRACT_SYNTAX_CLASS(GlobalGenericParamSubstitution, Substitutions);
#include "slang-val-defs.h"
#include "slang-object-meta-end.h"
+
SyntaxClassBase::ClassInfo::ClassInfo(const char* name, CreateFunc createFunc, const ClassInfo* superClass):
m_name(name),
m_createFunc(createFunc),
@@ -184,7 +185,48 @@ static bool _checkSubClassRange()
return SLANG_OK;
}
- // Free functions
+// !!!!!!!!!!!!!!!!!!!!!!!!!!!!! DiagnosticSink impls !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+void printDiagnosticArg(StringBuilder& sb, Decl* decl)
+{
+ sb << getText(decl->getName());
+}
+
+void printDiagnosticArg(StringBuilder& sb, Type* type)
+{
+ sb << type->ToString();
+}
+
+void printDiagnosticArg(StringBuilder& sb, Val* val)
+{
+ sb << val->ToString();
+}
+
+void printDiagnosticArg(StringBuilder& sb, TypeExp const& type)
+{
+ sb << type.type->ToString();
+}
+
+void printDiagnosticArg(StringBuilder& sb, QualType const& type)
+{
+ if (type.type)
+ sb << type.type->ToString();
+ else
+ sb << "<null>";
+}
+
+SourceLoc const& getDiagnosticPos(SyntaxNode const* syntax)
+{
+ return syntax->loc;
+}
+
+SourceLoc const& getDiagnosticPos(TypeExp const& typeExp)
+{
+ return typeExp.exp->loc;
+}
+
+
+// !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Free functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
const RefPtr<Decl>* adjustFilterCursorImpl(const SyntaxClassBase::ClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr<Decl>* ptr, const RefPtr<Decl>* end)
{
diff --git a/source/slang/slang-syntax.h b/source/slang/slang-syntax.h
index ff5da913f..5e1f057e4 100644
--- a/source/slang/slang-syntax.h
+++ b/source/slang/slang-syntax.h
@@ -33,6 +33,22 @@ namespace Slang
class Parser;
class SyntaxNode;
+ class Decl;
+ struct QualType;
+ class Type;
+ struct TypeExp;
+ class Val;
+
+ void printDiagnosticArg(StringBuilder& sb, Decl* decl);
+ void printDiagnosticArg(StringBuilder& sb, Type* type);
+ void printDiagnosticArg(StringBuilder& sb, TypeExp const& type);
+ void printDiagnosticArg(StringBuilder& sb, QualType const& type);
+ void printDiagnosticArg(StringBuilder& sb, Val* val);
+
+ class SyntaxNode;
+ SourceLoc const& getDiagnosticPos(SyntaxNode const* syntax);
+ SourceLoc const& getDiagnosticPos(TypeExp const& typeExp);
+
typedef RefPtr<RefObject> (*SyntaxParseCallback)(Parser* parser, void* userData);
typedef unsigned int ConversionCost;