summaryrefslogtreecommitdiff
path: root/source/slang/slang-check.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-check.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-check.cpp')
-rw-r--r--source/slang/slang-check.cpp343
1 files changed, 179 insertions, 164 deletions
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp
index 3f79b7f41..1fbef899b 100644
--- a/source/slang/slang-check.cpp
+++ b/source/slang/slang-check.cpp
@@ -5,218 +5,233 @@
// checking that don't cleanly land in one of the more
// specialized `slang-check-*` files.
-#include "slang-check-impl.h"
-
#include "../core/slang-type-text-util.h"
+#include "slang-check-impl.h"
namespace Slang
{
- namespace { // anonymous
-
- class SinkSharedLibraryLoader : public RefObject, public ISlangSharedLibraryLoader
+namespace
+{ // anonymous
+
+class SinkSharedLibraryLoader : public RefObject, public ISlangSharedLibraryLoader
+{
+public:
+ SLANG_REF_OBJECT_IUNKNOWN_ALL
+
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL
+ loadSharedLibrary(const char* path, ISlangSharedLibrary** outSharedLibrary) SLANG_OVERRIDE
{
- public:
- SLANG_REF_OBJECT_IUNKNOWN_ALL
+ SlangResult res = m_loader->loadSharedLibrary(path, outSharedLibrary);
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadSharedLibrary(
- const char* path,
- ISlangSharedLibrary** outSharedLibrary) SLANG_OVERRIDE
+ // Special handling for failure...
+ if (SLANG_FAILED(res) && m_sink)
{
- SlangResult res = m_loader->loadSharedLibrary(path, outSharedLibrary);
-
- // Special handling for failure...
- if (SLANG_FAILED(res) && m_sink)
+ String filename = Path::getFileNameWithoutExt(path);
+ if (filename == "dxil")
{
- String filename = Path::getFileNameWithoutExt(path);
- if (filename == "dxil")
- {
- m_sink->diagnose(SourceLoc(), Diagnostics::dxilNotFound);
- }
- else
- {
- m_sink->diagnose(SourceLoc(), Diagnostics::noteFailedToLoadDynamicLibrary, path);
- }
+ m_sink->diagnose(SourceLoc(), Diagnostics::dxilNotFound);
+ }
+ else
+ {
+ m_sink->diagnose(SourceLoc(), Diagnostics::noteFailedToLoadDynamicLibrary, path);
}
- return res;
}
+ return res;
+ }
- SinkSharedLibraryLoader(ISlangSharedLibraryLoader* loader, DiagnosticSink* sink) :
- m_loader(loader),
- m_sink(sink)
- {
- }
+ SinkSharedLibraryLoader(ISlangSharedLibraryLoader* loader, DiagnosticSink* sink)
+ : m_loader(loader), m_sink(sink)
+ {
+ }
- protected:
- ISlangUnknown* getInterface(const Guid& guid)
- {
- return (guid == ISlangUnknown::getTypeGuid() || guid == ISlangSharedLibraryLoader::getTypeGuid()) ? static_cast<ISlangSharedLibraryLoader*>(this) : nullptr;
- }
- ISlangSharedLibraryLoader* m_loader;
- DiagnosticSink* m_sink;
- };
+protected:
+ ISlangUnknown* getInterface(const Guid& guid)
+ {
+ return (guid == ISlangUnknown::getTypeGuid() ||
+ guid == ISlangSharedLibraryLoader::getTypeGuid())
+ ? static_cast<ISlangSharedLibraryLoader*>(this)
+ : nullptr;
+ }
+ ISlangSharedLibraryLoader* m_loader;
+ DiagnosticSink* m_sink;
+};
- } // anonymous
+} // namespace
- void Session::_setSharedLibraryLoader(ISlangSharedLibraryLoader* loader)
+void Session::_setSharedLibraryLoader(ISlangSharedLibraryLoader* loader)
+{
+ if (m_sharedLibraryLoader != loader)
{
- if (m_sharedLibraryLoader != loader)
- {
- // Need to clear all of the libraries
- m_downstreamCompilerSet->clear();
- m_downstreamCompilerInitialized = 0;
+ // Need to clear all of the libraries
+ m_downstreamCompilerSet->clear();
+ m_downstreamCompilerInitialized = 0;
- for (Index i = 0; i < Index(SLANG_PASS_THROUGH_COUNT_OF); ++i)
- {
- m_downstreamCompilers[i].setNull();
- }
-
- // Set the loader
- m_sharedLibraryLoader = loader;
+ for (Index i = 0; i < Index(SLANG_PASS_THROUGH_COUNT_OF); ++i)
+ {
+ m_downstreamCompilers[i].setNull();
}
+
+ // Set the loader
+ m_sharedLibraryLoader = loader;
}
+}
+
+void Session::resetDownstreamCompiler(PassThroughMode type)
+{
+ // Mark as initialized
+ m_downstreamCompilerInitialized &= ~(1 << int(type));
+ m_downstreamCompilers[int(type)].setNull();
+}
- void Session::resetDownstreamCompiler(PassThroughMode type)
+IDownstreamCompiler* Session::getOrLoadDownstreamCompiler(
+ PassThroughMode type,
+ DiagnosticSink* sink)
+{
+ if (m_downstreamCompilerInitialized & (1 << int(type)))
{
- // Mark as initialized
- m_downstreamCompilerInitialized &= ~(1 << int(type));
- m_downstreamCompilers[int(type)].setNull();
+ return m_downstreamCompilers[int(type)];
}
- IDownstreamCompiler* Session::getOrLoadDownstreamCompiler(PassThroughMode type, DiagnosticSink* sink)
+ if (type == PassThroughMode::GenericCCpp)
{
- if (m_downstreamCompilerInitialized & (1 << int(type)))
- {
- return m_downstreamCompilers[int(type)];
- }
-
- if (type == PassThroughMode::GenericCCpp)
- {
- // try testing for availability on all C/C++ compilers
- getOrLoadDownstreamCompiler(PassThroughMode::Clang, nullptr);
- getOrLoadDownstreamCompiler(PassThroughMode::Gcc, nullptr);
- getOrLoadDownstreamCompiler(PassThroughMode::VisualStudio, nullptr);
- getOrLoadDownstreamCompiler(PassThroughMode::LLVM, nullptr);
- }
+ // try testing for availability on all C/C++ compilers
+ getOrLoadDownstreamCompiler(PassThroughMode::Clang, nullptr);
+ getOrLoadDownstreamCompiler(PassThroughMode::Gcc, nullptr);
+ getOrLoadDownstreamCompiler(PassThroughMode::VisualStudio, nullptr);
+ getOrLoadDownstreamCompiler(PassThroughMode::LLVM, nullptr);
+ }
- // Mark that we have tried to load it
- m_downstreamCompilerInitialized |= (1 << int(type));
- m_downstreamCompilers[int(type)].setNull();
+ // Mark that we have tried to load it
+ m_downstreamCompilerInitialized |= (1 << int(type));
+ m_downstreamCompilers[int(type)].setNull();
- // Do we have a locator
- auto locator = m_downstreamCompilerLocators[int(type)];
- if (locator)
+ // Do we have a locator
+ auto locator = m_downstreamCompilerLocators[int(type)];
+ if (locator)
+ {
+ m_downstreamCompilerSet->remove(SlangPassThrough(type));
+
+ // We want to be able to report a diagnostic to the user if a loader
+ // was unable to locate the desired downstream compiler, but we
+ // also need to deal with the fact that the locator might "probe"
+ // multiple possible library versions/names, and failing to load
+ // one library should not be taken as a hard error.
+ //
+ // The approach we use here is to first apply the `locator` directly
+ // with our `m_sharedLibraryLoader` and see if it succeeds. If
+ // it does, then we will move along.
+ //
+ if (SLANG_FAILED(locator(
+ m_downstreamCompilerPaths[int(type)],
+ m_sharedLibraryLoader,
+ m_downstreamCompilerSet)))
{
- m_downstreamCompilerSet->remove(SlangPassThrough(type));
-
- // We want to be able to report a diagnostic to the user if a loader
- // was unable to locate the desired downstream compiler, but we
- // also need to deal with the fact that the locator might "probe"
- // multiple possible library versions/names, and failing to load
- // one library should not be taken as a hard error.
+ // If the locator reported a failure the first time we invoked
+ // it, then we will invoke it against with a wrapper shared library
+ // loader that reported library load failures to our diagnost `sink`.
//
- // The approach we use here is to first apply the `locator` directly
- // with our `m_sharedLibraryLoader` and see if it succeeds. If
- // it does, then we will move along.
+ // This means that in the case of failure the user will see a listing
+ // of all the libraries that the locator attempted to load but failed
+ // to find. The user will know that making one or more of these libraries
+ // available could fix the issue, but we cannot communicate precise
+ // information to them with this approach (e.g., the difference between
+ // "I need all of these libraries" vs. "I need at least one of these
+ // libraries").
//
- if (SLANG_FAILED(locator(m_downstreamCompilerPaths[int(type)], m_sharedLibraryLoader, m_downstreamCompilerSet)))
+ if (sink)
{
- // If the locator reported a failure the first time we invoked
- // it, then we will invoke it against with a wrapper shared library
- // loader that reported library load failures to our diagnost `sink`.
- //
- // This means that in the case of failure the user will see a listing
- // of all the libraries that the locator attempted to load but failed
- // to find. The user will know that making one or more of these libraries
- // available could fix the issue, but we cannot communicate precise
- // information to them with this approach (e.g., the difference between
- // "I need all of these libraries" vs. "I need at least one of these
- // libraries").
- //
- if( sink )
- {
- sink->diagnose(SourceLoc(), Diagnostics::failedToLoadDownstreamCompiler, type);
- }
- SinkSharedLibraryLoader loader(m_sharedLibraryLoader, sink);
- locator(m_downstreamCompilerPaths[int(type)], &loader, m_downstreamCompilerSet);
+ sink->diagnose(SourceLoc(), Diagnostics::failedToLoadDownstreamCompiler, type);
}
-
- DownstreamCompilerUtil::updateDefaults(m_downstreamCompilerSet);
+ SinkSharedLibraryLoader loader(m_sharedLibraryLoader, sink);
+ locator(m_downstreamCompilerPaths[int(type)], &loader, m_downstreamCompilerSet);
}
- IDownstreamCompiler* compiler = nullptr;
-
- if (type == PassThroughMode::GenericCCpp)
- {
- compiler = m_downstreamCompilerSet->getDefaultCompiler(SLANG_SOURCE_LANGUAGE_CPP);
- }
- else
- {
- DownstreamCompilerDesc desc;
- desc.type = SlangPassThrough(type);
- compiler = DownstreamCompilerUtil::findCompiler(m_downstreamCompilerSet, DownstreamCompilerUtil::MatchType::Newest, desc);
- }
- m_downstreamCompilers[int(type)] = compiler;
- return compiler;
+ DownstreamCompilerUtil::updateDefaults(m_downstreamCompilerSet);
}
- void checkTranslationUnit(
- TranslationUnitRequest* translationUnit,
- LoadedModuleDictionary& loadedModules)
+ IDownstreamCompiler* compiler = nullptr;
+
+ if (type == PassThroughMode::GenericCCpp)
+ {
+ compiler = m_downstreamCompilerSet->getDefaultCompiler(SLANG_SOURCE_LANGUAGE_CPP);
+ }
+ else
{
- SLANG_AST_BUILDER_RAII(translationUnit->compileRequest->getLinkage()->getASTBuilder());
+ DownstreamCompilerDesc desc;
+ desc.type = SlangPassThrough(type);
+ compiler = DownstreamCompilerUtil::findCompiler(
+ m_downstreamCompilerSet,
+ DownstreamCompilerUtil::MatchType::Newest,
+ desc);
+ }
+ m_downstreamCompilers[int(type)] = compiler;
+ return compiler;
+}
- SharedSemanticsContext sharedSemanticsContext(
- translationUnit->compileRequest->getLinkage(),
- translationUnit->getModule(),
- translationUnit->compileRequest->getSink(),
- &loadedModules,
- translationUnit);
+void checkTranslationUnit(
+ TranslationUnitRequest* translationUnit,
+ LoadedModuleDictionary& loadedModules)
+{
+ SLANG_AST_BUILDER_RAII(translationUnit->compileRequest->getLinkage()->getASTBuilder());
- SemanticsDeclVisitorBase visitor( (SemanticsContext(&sharedSemanticsContext)) );
+ SharedSemanticsContext sharedSemanticsContext(
+ translationUnit->compileRequest->getLinkage(),
+ translationUnit->getModule(),
+ translationUnit->compileRequest->getSink(),
+ &loadedModules,
+ translationUnit);
- // Apply the visitor to do the main semantic
- // checking that is required on all declarations
- // in the translation unit.
+ SemanticsDeclVisitorBase visitor((SemanticsContext(&sharedSemanticsContext)));
- visitor.checkModule(translationUnit->getModuleDecl());
+ // Apply the visitor to do the main semantic
+ // checking that is required on all declarations
+ // in the translation unit.
- translationUnit->getModule()->_collectShaderParams();
- }
+ visitor.checkModule(translationUnit->getModuleDecl());
- void SemanticsVisitor::dispatchStmt(Stmt* stmt, SemanticsContext const& context)
+ translationUnit->getModule()->_collectShaderParams();
+}
+
+void SemanticsVisitor::dispatchStmt(Stmt* stmt, SemanticsContext const& context)
+{
+ SemanticsStmtVisitor visitor(context);
+ try
{
- SemanticsStmtVisitor visitor(context);
- try
- {
- visitor.dispatch(stmt);
- }
- catch(const AbortCompilationException&) { throw; }
- catch(...)
- {
- getSink()->noteInternalErrorLoc(stmt->loc);
- throw;
- }
+ visitor.dispatch(stmt);
}
-
- Expr* SemanticsVisitor::dispatchExpr(Expr* expr, SemanticsContext const& context)
+ catch (const AbortCompilationException&)
{
- SemanticsExprVisitor visitor(context);
- try
- {
- return visitor.dispatch(expr);
- }
- catch(const AbortCompilationException&) { throw; }
- catch(...)
- {
- getSink()->noteInternalErrorLoc(expr->loc);
- throw;
- }
+ throw;
+ }
+ catch (...)
+ {
+ getSink()->noteInternalErrorLoc(stmt->loc);
+ throw;
}
+}
- ASTBuilder* semanticsVisitorGetASTBuilder(SemanticsVisitor* sv)
+Expr* SemanticsVisitor::dispatchExpr(Expr* expr, SemanticsContext const& context)
+{
+ SemanticsExprVisitor visitor(context);
+ try
{
- return sv->getASTBuilder();
+ return visitor.dispatch(expr);
}
+ catch (const AbortCompilationException&)
+ {
+ throw;
+ }
+ catch (...)
+ {
+ getSink()->noteInternalErrorLoc(expr->loc);
+ throw;
+ }
+}
+ASTBuilder* semanticsVisitorGetASTBuilder(SemanticsVisitor* sv)
+{
+ return sv->getASTBuilder();
}
+
+} // namespace Slang