summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-06-19 11:09:23 -0700
committerGitHub <noreply@github.com>2017-06-19 11:09:23 -0700
commit838e8331da24744948539c12d2a8edcd9c594ee5 (patch)
treeaf1fffcf4cc3ad7368fb9ae2c1b23b34890dbca8 /source
parentbb9ca29160f5d95f3860504262693ea650d96be5 (diff)
parent91d796da81aade1669abb90b72d4013e5480fb2d (diff)
Merge pull request #30 from tfoleyNV/slang-checking-fix
Make sure that semantic checks always apply to Slang files
Diffstat (limited to 'source')
-rw-r--r--source/slang/check.cpp17
-rw-r--r--source/slang/compiler.h7
-rw-r--r--source/slang/parser.cpp30
-rw-r--r--source/slang/parser.h14
-rw-r--r--source/slang/profile.h3
-rw-r--r--source/slang/slang.cpp26
-rw-r--r--source/slang/slang.vcxproj1
-rw-r--r--source/slang/slang.vcxproj.filters1
-rw-r--r--source/slang/syntax-visitors.h8
9 files changed, 68 insertions, 39 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index 0827641d1..f79df0c40 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -47,6 +47,7 @@ namespace Slang
ProgramSyntaxNode * program = nullptr;
FunctionSyntaxNode * function = nullptr;
CompileOptions const* options = nullptr;
+ TranslationUnitOptions const* translationUnitOptions = nullptr;
CompileRequest* request = nullptr;
// lexical outer statements
@@ -55,14 +56,17 @@ namespace Slang
SemanticsVisitor(
DiagnosticSink * pErr,
CompileOptions const& options,
+ TranslationUnitOptions const& translationUnitOptions,
CompileRequest* request)
: SyntaxVisitor(pErr)
, options(&options)
+ , translationUnitOptions(&translationUnitOptions)
, request(request)
{
}
CompileOptions const& getOptions() { return *options; }
+ TranslationUnitOptions const& getTranslationUnitOptions() { return *translationUnitOptions; }
public:
// Translate Types
@@ -965,7 +969,7 @@ namespace Slang
// expressions without a type, and we need to ignore them.
if( !fromExpr->Type.type )
{
- if(getOptions().flags & SLANG_COMPILE_FLAG_NO_CHECKING )
+ if(getTranslationUnitOptions().compileFlags & SLANG_COMPILE_FLAG_NO_CHECKING )
return fromExpr;
}
@@ -977,7 +981,7 @@ namespace Slang
fromExpr.Ptr(),
nullptr))
{
- if(!(getOptions().flags & SLANG_COMPILE_FLAG_NO_CHECKING))
+ if(!(getTranslationUnitOptions().compileFlags & SLANG_COMPILE_FLAG_NO_CHECKING))
{
getSink()->diagnose(fromExpr->Position, Diagnostics::typeMismatch, toType, fromExpr->Type);
}
@@ -4963,11 +4967,12 @@ namespace Slang
};
SyntaxVisitor* CreateSemanticsVisitor(
- DiagnosticSink* err,
- CompileOptions const& options,
- CompileRequest* request)
+ DiagnosticSink* err,
+ CompileOptions const& options,
+ TranslationUnitOptions const& translationUnitOptions,
+ CompileRequest* request)
{
- return new SemanticsVisitor(err, options, request);
+ return new SemanticsVisitor(err, options, translationUnitOptions, request);
}
//
diff --git a/source/slang/compiler.h b/source/slang/compiler.h
index 38640fd0f..39c91e21b 100644
--- a/source/slang/compiler.h
+++ b/source/slang/compiler.h
@@ -89,6 +89,9 @@ namespace Slang
// Preprocessor definitions to use for this translation unit only
// (whereas the ones on `CompileOptions` will be shared)
Dictionary<String, String> preprocessorDefinitions;
+
+ // Compile flags for this translation unit
+ SlangCompileFlags compileFlags = 0;
};
@@ -132,8 +135,8 @@ namespace Slang
// Should we just pass the input to another compiler?
PassThroughMode passThrough = PassThroughMode::None;
- // Flags supplied through the API
- SlangCompileFlags flags = 0;
+ // Compile flags to be shared by all translation units
+ SlangCompileFlags compileFlags = 0;
};
// This is the representation of a given translation unit
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index fb66fbbcf..75398a40d 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -2,6 +2,7 @@
#include <assert.h>
+#include "compiler.h"
#include "lookup.h"
namespace Slang
@@ -31,7 +32,9 @@ namespace Slang
class Parser
{
public:
- CompileOptions& options;
+ CompileOptions const& options;
+ TranslationUnitOptions const& translationUnitOptions;
+
int anonymousCounter = 0;
RefPtr<Scope> outerScope;
@@ -64,12 +67,14 @@ namespace Slang
currentScope = currentScope->parent;
}
Parser(
- CompileOptions& options,
+ CompileOptions const& options,
+ TranslationUnitOptions const& translationUnitOptions,
TokenSpan const& _tokens,
DiagnosticSink * sink,
String _fileName,
RefPtr<Scope> const& outerScope)
: options(options)
+ , translationUnitOptions(translationUnitOptions)
, tokenReader(_tokens)
, sink(sink)
, fileName(_fileName)
@@ -2495,7 +2500,7 @@ parser->ReadToken(TokenType::Comma);
RefPtr<StatementSyntaxNode> Parser::ParseBlockStatement()
{
- if( options.flags & SLANG_COMPILE_FLAG_NO_CHECKING )
+ if( translationUnitOptions.compileFlags & SLANG_COMPILE_FLAG_NO_CHECKING )
{
// We have been asked to parse the input, but not attempt to understand it.
@@ -3150,16 +3155,17 @@ parser->ReadToken(TokenType::Comma);
return rs;
}
- // Parse a source file into an existing translation unit
+ // Parse a source file into an existing translation unit
void parseSourceFile(
- ProgramSyntaxNode* translationUnitSyntax,
- CompileOptions& options,
- TokenSpan const& tokens,
- DiagnosticSink* sink,
- String const& fileName,
- RefPtr<Scope> const&outerScope)
- {
- Parser parser(options, tokens, sink, fileName, outerScope);
+ ProgramSyntaxNode* translationUnitSyntax,
+ CompileOptions const& options,
+ TranslationUnitOptions const& translationUnitOptions,
+ TokenSpan const& tokens,
+ DiagnosticSink* sink,
+ String const& fileName,
+ RefPtr<Scope> const& outerScope)
+ {
+ Parser parser(options, translationUnitOptions, tokens, sink, fileName, outerScope);
return parser.parseSourceFile(translationUnitSyntax);
}
}
diff --git a/source/slang/parser.h b/source/slang/parser.h
index cc7649e95..d74a3f5a8 100644
--- a/source/slang/parser.h
+++ b/source/slang/parser.h
@@ -9,12 +9,14 @@ namespace Slang
{
// Parse a source file into an existing translation unit
void parseSourceFile(
- ProgramSyntaxNode* translationUnitSyntax,
- CompileOptions& options,
- TokenSpan const& tokens,
- DiagnosticSink* sink,
- String const& fileName,
- RefPtr<Scope> const&outerScope);
+ ProgramSyntaxNode* translationUnitSyntax,
+ CompileOptions const& options,
+ TranslationUnitOptions const& translationUnitOptions,
+ TokenSpan const& tokens,
+ DiagnosticSink* sink,
+ String const& fileName,
+ RefPtr<Scope> const& outerScope);
+;
}
#endif \ No newline at end of file
diff --git a/source/slang/profile.h b/source/slang/profile.h
index f67207c9e..f8839be84 100644
--- a/source/slang/profile.h
+++ b/source/slang/profile.h
@@ -13,9 +13,6 @@ namespace Slang
Slang = SLANG_SOURCE_LANGUAGE_SLANG,
HLSL = SLANG_SOURCE_LANGUAGE_HLSL,
GLSL = SLANG_SOURCE_LANGUAGE_GLSL,
-
- // A separate PACKAGE of Slang code that has been imported
- ImportedSlangCode,
};
// TODO(tfoley): This should merge with the above...
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 5ec530592..d86825766 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -246,6 +246,7 @@ struct CompileRequest
parseSourceFile(
translationUnitSyntax.Ptr(),
options,
+ translationUnitOptions,
tokens,
mResult.GetErrorWriter(),
sourceFilePath,
@@ -279,6 +280,7 @@ struct CompileRequest
RefPtr<SyntaxVisitor> visitor = CreateSemanticsVisitor(
mResult.GetErrorWriter(),
options,
+ translationUnit.options,
this);
checkTranslationUnit(translationUnit, visitor);
@@ -287,14 +289,9 @@ struct CompileRequest
void checkCollectionOfTranslationUnits(
RefPtr<CollectionOfTranslationUnits> collectionOfTranslationUnits)
{
- RefPtr<SyntaxVisitor> visitor = CreateSemanticsVisitor(
- mResult.GetErrorWriter(),
- Options,
- this);
-
for( auto& translationUnit : collectionOfTranslationUnits->translationUnits )
{
- checkTranslationUnit(translationUnit, visitor);
+ checkTranslationUnit(translationUnit, Options);
}
}
@@ -322,6 +319,21 @@ struct CompileRequest
int executeCompilerDriverActions()
{
+ // Do some cleanup on settings specified by user.
+ // In particular, we want to propagate flags from the overall request down to
+ // each translation unit.
+ for( auto& translationUnitOptions : Options.translationUnits )
+ {
+ translationUnitOptions.compileFlags |= Options.compileFlags;
+
+ // However, the "no checking" flag shouldn't be applied to
+ // any translation unit that is native Slang code.
+ if( translationUnitOptions.sourceLanguage == SourceLanguage::Slang )
+ {
+ translationUnitOptions.compileFlags &= SLANG_COMPILE_FLAG_NO_CHECKING;
+ }
+ }
+
// If we are being asked to do pass-through, then we need to do that here...
if (Options.passThrough != PassThroughMode::None)
{
@@ -727,7 +739,7 @@ SLANG_API void spSetCompileFlags(
SlangCompileRequest* request,
SlangCompileFlags flags)
{
- REQ(request)->Options.flags = flags;
+ REQ(request)->Options.compileFlags = flags;
}
SLANG_API void spSetCodeGenTarget(
diff --git a/source/slang/slang.vcxproj b/source/slang/slang.vcxproj
index 4a3313b07..ba97cb03a 100644
--- a/source/slang/slang.vcxproj
+++ b/source/slang/slang.vcxproj
@@ -164,6 +164,7 @@
<Natvis Include="slang.natvis" />
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="..\..\slang.h" />
<ClInclude Include="compiled-program.h" />
<ClInclude Include="compiler.h" />
<ClInclude Include="diagnostic-defs.h" />
diff --git a/source/slang/slang.vcxproj.filters b/source/slang/slang.vcxproj.filters
index 7eee0643d..aa2edb34a 100644
--- a/source/slang/slang.vcxproj.filters
+++ b/source/slang/slang.vcxproj.filters
@@ -25,6 +25,7 @@
<ClInclude Include="token.h" />
<ClInclude Include="token-defs.h" />
<ClInclude Include="type-layout.h" />
+ <ClInclude Include="..\..\slang.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="check.cpp" />
diff --git a/source/slang/syntax-visitors.h b/source/slang/syntax-visitors.h
index f83334155..dbcbf2781 100644
--- a/source/slang/syntax-visitors.h
+++ b/source/slang/syntax-visitors.h
@@ -12,11 +12,13 @@ namespace Slang
class ShaderCompiler;
class ShaderLinkInfo;
class ShaderSymbol;
+ class TranslationUnitOptions;
SyntaxVisitor* CreateSemanticsVisitor(
- DiagnosticSink* err,
- CompileOptions const& options,
- CompileRequest* request);
+ DiagnosticSink* err,
+ CompileOptions const& options,
+ TranslationUnitOptions const& translationUnitOptions,
+ CompileRequest* request);
// Look for a module that matches the given name:
// either one we've loaded already, or one we