summaryrefslogtreecommitdiff
path: root/tools/slang-cpp-extractor/identifier-lookup.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-04-22 09:32:25 -0400
committerGitHub <noreply@github.com>2021-04-22 09:32:25 -0400
commitda0d295d6c8b6fb03245dea0583437c198890349 (patch)
treeed17baba750b15f6ace1427f04cf19690269161e /tools/slang-cpp-extractor/identifier-lookup.cpp
parent34fba7b5e726136c6eee8a318ab9a75381399c00 (diff)
C++ extractor improvements (#1803)
* #include an absolute path didn't work - because paths were taken to always be relative. * Split of NodeTree. Split out FileUtil. Split out MacroWriter. * Rename slang-cpp-extractor-main.cpp -> cpp-extractor-main.cpp * First pass at extractor unit-tests * Initial parsing of enum. * Ability to disable/enable parsing of scope types. * Initial support for typedef. * Added operator== != to ArrayVIew. Added test for splitting to unit tests. * Improve comment in StringUtil. * Fix comment. * Fix typo.
Diffstat (limited to 'tools/slang-cpp-extractor/identifier-lookup.cpp')
-rw-r--r--tools/slang-cpp-extractor/identifier-lookup.cpp66
1 files changed, 65 insertions, 1 deletions
diff --git a/tools/slang-cpp-extractor/identifier-lookup.cpp b/tools/slang-cpp-extractor/identifier-lookup.cpp
index 07f155248..c7be75d82 100644
--- a/tools/slang-cpp-extractor/identifier-lookup.cpp
+++ b/tools/slang-cpp-extractor/identifier-lookup.cpp
@@ -11,15 +11,19 @@ using namespace Slang;
0, /// Type set
IdentifierFlag::Keyword, /// TypeModifier
IdentifierFlag::Keyword, /// Keyword
+
IdentifierFlag::Keyword | IdentifierFlag::StartScope | IdentifierFlag::ClassLike, /// Class
IdentifierFlag::Keyword | IdentifierFlag::StartScope | IdentifierFlag::ClassLike, /// Struct
IdentifierFlag::Keyword | IdentifierFlag::StartScope, /// Namespace
+ IdentifierFlag::Keyword | IdentifierFlag::StartScope, /// Enum
+
+ IdentifierFlag::Keyword, /// Typedef
+
IdentifierFlag::Keyword, /// Access
IdentifierFlag::Reflection, /// Reflected
IdentifierFlag::Reflection, /// Unreflected
};
-
void IdentifierLookup::set(const UnownedStringSlice& name, IdentifierStyle style)
{
StringSlicePool::Handle handle;
@@ -44,5 +48,65 @@ void IdentifierLookup::set(const char*const* names, size_t namesCount, Identifie
}
}
+void IdentifierLookup::set(const Pair* pairs, Index pairsCount)
+{
+ for (Index i = 0; i < pairsCount; ++i)
+ {
+ const auto& pair = pairs[i];
+ set(UnownedStringSlice(pair.name), pair.style);
+ }
+}
+
+void IdentifierLookup::initDefault(const UnownedStringSlice& markPrefix)
+{
+ reset();
+
+ // Some keywords
+ {
+ const char* names[] = { "virtual", "continue", "if", "case", "break", "catch", "default", "delete", "do", "else", "for", "new", "goto", "return", "switch", "throw", "using", "while", "operator" };
+ set(names, SLANG_COUNT_OF(names), IdentifierStyle::Keyword);
+ }
+
+ // Type modifier keywords
+ {
+ const char* names[] = { "const", "volatile" };
+ set(names, SLANG_COUNT_OF(names), IdentifierStyle::TypeModifier);
+ }
+
+ // Special markers
+ {
+ const char* names[] = { "PRE_DECLARE", "TYPE_SET", "REFLECTED", "UNREFLECTED" };
+ const IdentifierStyle styles[] = { IdentifierStyle::PreDeclare, IdentifierStyle::TypeSet, IdentifierStyle::Reflected, IdentifierStyle::Unreflected };
+ SLANG_COMPILE_TIME_ASSERT(SLANG_COUNT_OF(names) == SLANG_COUNT_OF(styles));
+
+ StringBuilder buf;
+ for (Index i = 0; i < SLANG_COUNT_OF(names); ++i)
+ {
+ buf.Clear();
+ buf << markPrefix << names[i];
+ set(buf.getUnownedSlice(), styles[i]);
+ }
+ }
+
+ // Keywords which introduce types/scopes
+ {
+ const Pair pairs[] =
+ {
+ { "struct", IdentifierStyle::Struct },
+ { "class", IdentifierStyle::Class },
+ { "namespace", IdentifierStyle::Namespace },
+ { "enum", IdentifierStyle::Enum },
+ { "typedef", IdentifierStyle::TypeDef },
+ };
+
+ set(pairs, SLANG_COUNT_OF(pairs));
+ }
+
+ // Keywords that control access
+ {
+ const char* names[] = { "private", "protected", "public" };
+ set(names, SLANG_COUNT_OF(names), IdentifierStyle::Access);
+ }
+}
} // namespace CppExtract