summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-name.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-04-01 13:39:11 -0400
committerGitHub <noreply@github.com>2021-04-01 10:39:11 -0700
commitfa31d21ba92669a521a7768467246918e3947e02 (patch)
treeaf98a593e24bc6309ac4d11a59562be4b22c93d7 /source/compiler-core/slang-name.cpp
parent3f1632a1450a5879f337b4bd178e48880cd583f8 (diff)
Added compiler-core project (#1775)
* #include an absolute path didn't work - because paths were taken to always be relative. * Split out compiler-core initially with just slang-source-loc.cpp * More lexer, name, token to compiler-core. * Split Lexer and Core diagnostics. * Move slang-file-system to core. * Add slang-file-system to core. * More DownstreamCompiler into compiler-core * Fix typo. * Add compiler-core to bootstrap proj. * Small fixes to premake * For linux try with compiler-core * Remove compiler-core from examples. * Added NameConventionUtil to compiler-core * Add global function to CharUtil to *hopefully* avoid linking issue. * Hack to make linkage of CharUtil work on linux.
Diffstat (limited to 'source/compiler-core/slang-name.cpp')
-rw-r--r--source/compiler-core/slang-name.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/source/compiler-core/slang-name.cpp b/source/compiler-core/slang-name.cpp
new file mode 100644
index 000000000..b6035982b
--- /dev/null
+++ b/source/compiler-core/slang-name.cpp
@@ -0,0 +1,42 @@
+// slang-name.cpp
+#include "slang-name.h"
+
+namespace Slang {
+
+String getText(Name* name)
+{
+ if (!name) return String();
+ return name->text;
+}
+
+UnownedStringSlice getUnownedStringSliceText(Name* name)
+{
+ return name ? name->text.getUnownedSlice() : UnownedStringSlice();
+}
+
+const char* getCstr(Name* name)
+{
+ return name ? name->text.getBuffer() : nullptr;
+}
+
+Name* NamePool::getName(String const& text)
+{
+ RefPtr<Name> name;
+ if (rootPool->names.TryGetValue(text, name))
+ return name;
+
+ name = new Name();
+ name->text = text;
+ rootPool->names.Add(text, name);
+ return name;
+}
+
+Name* NamePool::tryGetName(String const& text)
+{
+ RefPtr<Name> name;
+ if (rootPool->names.TryGetValue(text, name))
+ return name;
+ return nullptr;
+}
+
+} // namespace Slang