summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-check-shader.cpp8
-rw-r--r--source/slang/slang-compiler.cpp2
-rw-r--r--source/slang/slang-diagnostics.cpp8
-rw-r--r--source/slang/slang-diagnostics.h88
-rw-r--r--source/slang/slang-options.cpp6
-rw-r--r--source/slang/slang-parser.cpp6
-rw-r--r--source/slang/slang.cpp46
-rw-r--r--tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp8
8 files changed, 93 insertions, 79 deletions
diff --git a/source/slang/slang-check-shader.cpp b/source/slang/slang-check-shader.cpp
index f68439f8a..a037218f9 100644
--- a/source/slang/slang-check-shader.cpp
+++ b/source/slang/slang-check-shader.cpp
@@ -1269,7 +1269,7 @@ namespace Slang
//
List<SpecializationArg> args;
_extractSpecializationArgs(unspecializedEntryPoint, argExprs, args, sink);
- if(sink->GetErrorCount())
+ if(sink->getErrorCount())
return nullptr;
return ((ComponentType*) unspecializedEntryPoint)->specialize(
@@ -1429,7 +1429,7 @@ namespace Slang
List<SpecializationArg> specializationArgs;
_extractSpecializationArgs(unspecializedProgram, specializationArgExprs, specializationArgs, sink);
- if(sink->GetErrorCount())
+ if(sink->getErrorCount())
return nullptr;
auto specializedProgram = unspecializedProgram->specialize(
@@ -1511,7 +1511,7 @@ namespace Slang
globalSpecializationArgs);
// Don't proceed further if anything failed to parse.
- if(sink->GetErrorCount())
+ if(sink->getErrorCount())
return nullptr;
// Now we create the initial specialized program by
@@ -1635,7 +1635,7 @@ namespace Slang
// then try to create a composite where some of the constituent
// component types might be null.
//
- if(endToEndReq->getSink()->GetErrorCount() != 0)
+ if(endToEndReq->getSink()->getErrorCount() != 0)
return nullptr;
// Any entry points beyond those that were specified up front will be
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index 489808a44..41112f3cc 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -711,7 +711,7 @@ namespace Slang
static String _getDisplayPath(DiagnosticSink* sink, SourceFile* sourceFile)
{
- if (sink->flags & DiagnosticSink::Flag::VerbosePath)
+ if (sink->isFlagSet(DiagnosticSink::Flag::VerbosePath))
{
return sourceFile->calcVerbosePath();
}
diff --git a/source/slang/slang-diagnostics.cpp b/source/slang/slang-diagnostics.cpp
index 6e0cfba4d..a46e0515b 100644
--- a/source/slang/slang-diagnostics.cpp
+++ b/source/slang/slang-diagnostics.cpp
@@ -160,7 +160,7 @@ static void formatDiagnostic(
Diagnostic const& diagnostic,
StringBuilder& sb)
{
- auto sourceManager = sink->sourceManager;
+ auto sourceManager = sink->getSourceManager();
SourceView* sourceView = nullptr;
HumaneSourceLoc humaneLoc;
@@ -174,7 +174,7 @@ static void formatDiagnostic(
formatDiagnostic(humaneLoc, diagnostic, sb);
}
- if (sourceView && (sink->flags & DiagnosticSink::Flag::VerbosePath))
+ if (sourceView && sink->isFlagSet(DiagnosticSink::Flag::VerbosePath))
{
auto actualHumaneLoc = sourceView->getHumaneLoc(diagnostic.loc, SourceLocType::Actual);
@@ -204,7 +204,7 @@ void DiagnosticSink::diagnoseImpl(SourceLoc const& pos, DiagnosticInfo const& in
if (diagnostic.severity >= Severity::Error)
{
- errorCount++;
+ m_errorCount++;
}
// Did the client supply a callback for us to use?
@@ -243,7 +243,7 @@ void DiagnosticSink::diagnoseRaw(
{
if (severity >= Severity::Error)
{
- errorCount++;
+ m_errorCount++;
}
// Did the client supply a callback for us to use?
diff --git a/source/slang/slang-diagnostics.h b/source/slang/slang-diagnostics.h
index 80e14d1c1..1056cf2eb 100644
--- a/source/slang/slang-diagnostics.h
+++ b/source/slang/slang-diagnostics.h
@@ -131,43 +131,18 @@ namespace Slang
class DiagnosticSink
{
public:
- DiagnosticSink(SourceManager* sourceManager)
- : sourceManager(sourceManager)
- {}
-
+ /// Flags to control some aspects of Diagnostic sink behavior
+ typedef uint32_t Flags;
struct Flag
{
- enum Enum: uint32_t
+ enum Enum: Flags
{
VerbosePath = 0x1, ///< Will display a more verbose path (if available) - such as a canonical or absolute path
};
};
- typedef uint32_t Flags;
-
- StringBuilder outputBuffer;
-// List<Diagnostic> diagnostics;
- int errorCount = 0;
- int internalErrorLocsNoted = 0;
-
- ISlangWriter* writer = nullptr;
- Flags flags = 0;
- // The source manager to use when mapping source locations to file+line info
- SourceManager* sourceManager = nullptr;
-
-/*
- void Error(int id, const String & msg, const SourceLoc & pos)
- {
- diagnostics.Add(Diagnostic(msg, id, pos, Severity::Error));
- errorCount++;
- }
-
- void Warning(int id, const String & msg, const SourceLoc & pos)
- {
- diagnostics.Add(Diagnostic(msg, id, pos, Severity::Warning));
- }
-*/
- int GetErrorCount() { return errorCount; }
+ /// Get the total amount of errors that have taken place on this DiagnosticSink
+ SLANG_FORCE_INLINE int getErrorCount() { return m_errorCount; }
void diagnoseDispatch(SourceLoc const& pos, DiagnosticInfo const& info)
{
@@ -204,22 +179,55 @@ namespace Slang
diagnoseDispatch(getDiagnosticPos(pos), info, args...);
}
- void diagnoseImpl(SourceLoc const& pos, DiagnosticInfo const& info, int argCount, DiagnosticArg const* const* args);
-
- // Add a diagnostic with raw text
- // (used when we get errors from a downstream compiler)
- void diagnoseRaw(
- Severity severity,
- char const* message);
- void diagnoseRaw(
- Severity severity,
- const UnownedStringSlice& message);
+ // Add a diagnostic with raw text
+ // (used when we get errors from a downstream compiler)
+ void diagnoseRaw(Severity severity, char const* message);
+ void diagnoseRaw(Severity severity, const UnownedStringSlice& message);
/// During propagation of an exception for an internal
/// error, note that this source location was involved
void noteInternalErrorLoc(SourceLoc const& loc);
+ /// Create a blob containing diagnostics if there were any errors.
+ /// *note* only works if writer is not set, the blob is created from outputBuffer
SlangResult getBlobIfNeeded(ISlangBlob** outBlob);
+
+ /// Get the source manager used
+ SourceManager* getSourceManager() const { return m_sourceManager; }
+ /// Set the source manager used for lookup of source locs
+ void setSourceManager(SourceManager* inSourceManager) { m_sourceManager = inSourceManager; }
+
+ /// Get the flags
+ Flags getFlags() const { return m_flags; }
+ /// Set a flag
+ void setFlag(Flag::Enum flag) { m_flags |= Flags(flag); }
+ /// Reset a flag
+ void resetFlag(Flag::Enum flag) { m_flags &= ~Flags(flag); }
+ /// Test if flag is set
+ bool isFlagSet(Flag::Enum flag) { return (m_flags & Flags(flag)) != 0; }
+
+ /// Ctor
+ DiagnosticSink(SourceManager* sourceManager)
+ : m_sourceManager(sourceManager)
+ {}
+
+ // Public members
+
+ /// The outputBuffer will contain any diagnostics *iff* the writer is *not* set
+ StringBuilder outputBuffer;
+ /// If a writer is set output will *not* be written to the outputBuffer
+ ISlangWriter* writer = nullptr;
+
+ protected:
+ void diagnoseImpl(SourceLoc const& pos, DiagnosticInfo const& info, int argCount, DiagnosticArg const* const* args);
+
+ int m_errorCount = 0;
+ int m_internalErrorLocsNoted = 0;
+
+ Flags m_flags = 0;
+
+ // The source manager to use when mapping source locations to file+line info
+ SourceManager* m_sourceManager = nullptr;
};
/// An `ISlangWriter` that writes directly to a diagnostic sink.
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index 8100fab4f..89fe03255 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -559,7 +559,7 @@ struct OptionsParser
}
else if (argStr == "-verbose-paths")
{
- requestImpl->getSink()->flags |= DiagnosticSink::Flag::VerbosePath;
+ requestImpl->getSink()->setFlag(DiagnosticSink::Flag::VerbosePath);
}
else if (argStr == "-verify-debug-serial-ir")
{
@@ -1494,7 +1494,7 @@ struct OptionsParser
}
}
- return (sink->GetErrorCount() == 0) ? SLANG_OK : SLANG_FAIL;
+ return (sink->getErrorCount() == 0) ? SLANG_OK : SLANG_FAIL;
}
};
@@ -1514,7 +1514,7 @@ SlangResult parseOptions(
Result res = parser.parse(argc, argv);
DiagnosticSink* sink = compileRequest->getSink();
- if (sink->GetErrorCount() > 0)
+ if (sink->getErrorCount() > 0)
{
// Put the errors in the diagnostic
compileRequest->mDiagnosticOutput = sink->outputBuffer.ProduceString();
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index fec7147b5..a90d4bfc9 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -692,7 +692,7 @@ namespace Slang
}
// Make a 'token'
- SourceManager* sourceManager = parser->sink->sourceManager;
+ SourceManager* sourceManager = parser->sink->getSourceManager();
const UnownedStringSlice scopedIdentifier(sourceManager->allocateStringSlice(scopedIdentifierBuilder.getUnownedSlice()));
Token token(TokenType::Identifier, scopedIdentifier, scopedIdSourceLoc);
@@ -1745,11 +1745,11 @@ namespace Slang
TokenSpan tokenSpan;
tokenSpan.m_begin = parser->tokenReader.m_cursor;
tokenSpan.m_end = parser->tokenReader.m_end;
- DiagnosticSink newSink(parser->sink->sourceManager);
+ DiagnosticSink newSink(parser->sink->getSourceManager());
Parser newParser(*parser);
newParser.sink = &newSink;
auto speculateParseRs = parseGenericApp(&newParser, base);
- if (newSink.errorCount == 0)
+ if (newSink.getErrorCount() == 0)
{
// disambiguate based on FOLLOW set
switch (peekTokenType(&newParser))
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 486034876..e70486ca9 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -1143,12 +1143,12 @@ SlangResult FrontEndCompileRequest::executeActionsInner()
parseTranslationUnit(translationUnit.Ptr());
}
- if (getSink()->GetErrorCount() != 0)
+ if (getSink()->getErrorCount() != 0)
return SLANG_FAIL;
// Perform semantic checking on the whole collection
checkAllTranslationUnits();
- if (getSink()->GetErrorCount() != 0)
+ if (getSink()->getErrorCount() != 0)
return SLANG_FAIL;
@@ -1156,13 +1156,13 @@ SlangResult FrontEndCompileRequest::executeActionsInner()
// and use them to populate the `program` member.
//
m_globalComponentType = createUnspecializedGlobalComponentType(this);
- if (getSink()->GetErrorCount() != 0)
+ if (getSink()->getErrorCount() != 0)
return SLANG_FAIL;
m_globalAndEntryPointsComponentType = createUnspecializedGlobalAndEntryPointsComponentType(
this,
m_unspecializedEntryPoints);
- if (getSink()->GetErrorCount() != 0)
+ if (getSink()->getErrorCount() != 0)
return SLANG_FAIL;
// We always generate IR for all the translation units.
@@ -1174,7 +1174,7 @@ SlangResult FrontEndCompileRequest::executeActionsInner()
// makes sense.
//
generateIR();
- if (getSink()->GetErrorCount() != 0)
+ if (getSink()->getErrorCount() != 0)
return SLANG_FAIL;
// Do parameter binding generation, for each compilation target.
@@ -1185,7 +1185,7 @@ SlangResult FrontEndCompileRequest::executeActionsInner()
targetProgram->getOrCreateLayout(getSink());
targetProgram->getOrCreateIRModuleForLayout(getSink());
}
- if (getSink()->GetErrorCount() != 0)
+ if (getSink()->getErrorCount() != 0)
return SLANG_FAIL;
return SLANG_OK;
@@ -1221,7 +1221,7 @@ EndToEndCompileRequest::EndToEndCompileRequest(
void EndToEndCompileRequest::init()
{
- m_sink.sourceManager = m_linkage->getSourceManager();
+ m_sink.setSourceManager(m_linkage->getSourceManager());
// Set all the default writers
for (int i = 0; i < int(WriterChannel::CountOf); ++i)
@@ -1294,13 +1294,13 @@ SlangResult EndToEndCompileRequest::executeActionsInner()
if (passThrough == PassThroughMode::None)
{
m_specializedGlobalComponentType = createSpecializedGlobalComponentType(this);
- if (getSink()->GetErrorCount() != 0)
+ if (getSink()->getErrorCount() != 0)
return SLANG_FAIL;
m_specializedGlobalAndEntryPointsComponentType = createSpecializedGlobalAndEntryPointsComponentType(
this,
m_specializedEntryPoints);
- if (getSink()->GetErrorCount() != 0)
+ if (getSink()->getErrorCount() != 0)
return SLANG_FAIL;
// For each code generation target, we will generate specialized
@@ -1312,7 +1312,7 @@ SlangResult EndToEndCompileRequest::executeActionsInner()
auto targetProgram = m_specializedGlobalAndEntryPointsComponentType->getTargetProgram(targetReq);
targetProgram->getOrCreateLayout(getSink());
}
- if (getSink()->GetErrorCount() != 0)
+ if (getSink()->getErrorCount() != 0)
return SLANG_FAIL;
}
else
@@ -1344,7 +1344,7 @@ SlangResult EndToEndCompileRequest::executeActionsInner()
// Generate output code, in whatever format was requested
getBackEndReq()->setProgram(getSpecializedGlobalAndEntryPointsComponentType());
generateOutput(this);
- if (getSink()->GetErrorCount() != 0)
+ if (getSink()->getErrorCount() != 0)
return SLANG_FAIL;
return SLANG_OK;
@@ -1515,9 +1515,9 @@ void Linkage::loadParsedModule(
auto sink = translationUnit->compileRequest->getSink();
- int errorCountBefore = sink->GetErrorCount();
+ int errorCountBefore = sink->getErrorCount();
checkTranslationUnit(translationUnit.Ptr());
- int errorCountAfter = sink->GetErrorCount();
+ int errorCountAfter = sink->getErrorCount();
if (errorCountAfter != errorCountBefore)
{
@@ -1572,9 +1572,9 @@ RefPtr<Module> Linkage::loadModule(
translationUnit->addSourceFile(sourceFile);
- int errorCountBefore = sink->GetErrorCount();
+ int errorCountBefore = sink->getErrorCount();
frontEndReq->parseTranslationUnit(translationUnit);
- int errorCountAfter = sink->GetErrorCount();
+ int errorCountAfter = sink->getErrorCount();
if( errorCountAfter != errorCountBefore )
{
@@ -1591,7 +1591,7 @@ RefPtr<Module> Linkage::loadModule(
name,
filePathInfo);
- errorCountAfter = sink->GetErrorCount();
+ errorCountAfter = sink->getErrorCount();
if (errorCountAfter != errorCountBefore)
{
@@ -2436,11 +2436,11 @@ void DiagnosticSink::noteInternalErrorLoc(SourceLoc const& loc)
// If this is the first source location being noted,
// then emit a message to help the user isolate what
// code might have confused the compiler.
- if(internalErrorLocsNoted == 0)
+ if(m_internalErrorLocsNoted == 0)
{
diagnose(loc, Diagnostics::noteLocationOfInternalError);
}
- internalErrorLocsNoted++;
+ m_internalErrorLocsNoted++;
}
SlangResult DiagnosticSink::getBlobIfNeeded(ISlangBlob** outBlob)
@@ -2449,8 +2449,14 @@ SlangResult DiagnosticSink::getBlobIfNeeded(ISlangBlob** outBlob)
//
if(!outBlob) return SLANG_OK;
+ // For outputBuffer to be valid and hold diagnostics, writer must not be set
+ SLANG_ASSERT(writer == nullptr);
+
// If there were no errors, and there was no diagnostic output, there is nothing to do.
- if(!GetErrorCount() && !outputBuffer.getLength()) return SLANG_OK;
+ if(getErrorCount() == 0 && outputBuffer.getLength() == 0)
+ {
+ return SLANG_OK;
+ }
Slang::ComPtr<ISlangBlob> blob = Slang::StringUtil::createStringBlob(outputBuffer);
*outBlob = blob.detach();
@@ -2554,7 +2560,7 @@ void Session::addBuiltinSource(
compileRequest->m_isStandardLibraryCode = true;
// Set the source manager on the sink
- sink.sourceManager = sourceManager;
+ sink.setSourceManager(sourceManager);
// Make the linkage use the builtin source manager
Linkage* linkage = compileRequest->getLinkage();
linkage->setSourceManager(sourceManager);
diff --git a/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp b/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp
index 792cf3458..3fa191394 100644
--- a/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp
+++ b/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp
@@ -1365,7 +1365,7 @@ SlangResult CPPExtractor::_maybeParseType(UnownedStringSlice& outType)
{
Index templateDepth = 0;
SlangResult res = _maybeParseType(outType, templateDepth);
- if (SLANG_FAILED(res) && m_sink->errorCount)
+ if (SLANG_FAILED(res) && m_sink->getErrorCount())
{
return res;
}
@@ -1472,7 +1472,7 @@ SlangResult CPPExtractor::_maybeParseField()
UnownedStringSlice typeName;
if (SLANG_FAILED(_maybeParseType(typeName)))
{
- if (m_sink->errorCount)
+ if (m_sink->getErrorCount())
{
return SLANG_FAIL;
}
@@ -1565,7 +1565,7 @@ SlangResult CPPExtractor::parse(SourceFile* sourceFile, const Options* options)
lexer.initialize(sourceView, m_sink, m_namePool, manager->getMemoryArena());
m_tokenList = lexer.lexAllTokens();
// See if there were any errors
- if (m_sink->errorCount)
+ if (m_sink->getErrorCount())
{
return SLANG_FAIL;
}
@@ -2446,7 +2446,7 @@ int main(int argc, const char*const* argv)
{
return 1;
}
- if (sink.errorCount)
+ if (sink.getErrorCount())
{
return 1;
}