diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-04-19 15:39:42 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-19 15:39:42 -0400 |
| commit | 778428fecc0548af565e92745cf1344bcf19367f (patch) | |
| tree | adaf9be98bb8a4c36e6f7e42f24dbf653973ed7e /tools/slang-cpp-extractor/identifier-lookup.h | |
| parent | 22b562d1a47443f266b114b4b207bcdd4eb3c54f (diff) | |
Splitting up C++ extractor (#1800)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Refactor out ClassLikeNode
* WIP around ScopeNode.
* Use push and popScope.
* Small improvements around C++ extractor.
* Adding dynamic casting support.
* Made Field another Node type.
* Disable command line dumping by default.
* Removed comment.
* Fix shadowed variable bug found on linux.
* Split out node.
* Renamed C++ extractor diagnostics to just diagnostics.cpp/.h
* Remove C++ extractor Options into separate options.cpp/options.h files.
* Split out parser and identifier lookup from C++ extractor.
* Put in CppExtract namespace.
Simplify some of the class names.
* Some simple renaming.
* Split out NodeTree from Parser.
Diffstat (limited to 'tools/slang-cpp-extractor/identifier-lookup.h')
| -rw-r--r-- | tools/slang-cpp-extractor/identifier-lookup.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tools/slang-cpp-extractor/identifier-lookup.h b/tools/slang-cpp-extractor/identifier-lookup.h new file mode 100644 index 000000000..b845f804c --- /dev/null +++ b/tools/slang-cpp-extractor/identifier-lookup.h @@ -0,0 +1,95 @@ +#ifndef CPP_EXTRACT_IDENTIFIER_LOOKUP_H +#define CPP_EXTRACT_IDENTIFIER_LOOKUP_H + +#include "diagnostics.h" + +namespace CppExtract { +using namespace Slang; + +enum class IdentifierStyle +{ + None, ///< It's not an identifier + + Identifier, ///< Just an identifier + + PreDeclare, ///< Declare a type (not visible in C++ code) + TypeSet, ///< TypeSet + + TypeModifier, ///< const, volatile etc + Keyword, ///< A keyword C/C++ keyword that is not another type + Class, ///< class + Struct, ///< struct + Namespace, ///< namespace + Access, ///< public, protected, private + + Reflected, + Unreflected, + + CountOf, +}; + +typedef uint32_t IdentifierFlags; +struct IdentifierFlag +{ + enum Enum : IdentifierFlags + { + StartScope = 0x1, ///< namespace, struct or class + ClassLike = 0x2, ///< Struct or class + Keyword = 0x4, + Reflection = 0x8, + }; +}; + + +class IdentifierLookup +{ +public: + + IdentifierStyle get(const UnownedStringSlice& slice) const + { + Index index = m_pool.findIndex(slice); + return (index >= 0) ? m_styles[index] : IdentifierStyle::None; + } + + void set(const char* name, IdentifierStyle style) + { + set(UnownedStringSlice(name), style); + } + + void set(const UnownedStringSlice& name, IdentifierStyle style); + + void set(const char*const* names, size_t namesCount, IdentifierStyle style); + + void reset() + { + m_styles.clear(); + m_pool.clear(); + } + + IdentifierLookup() : + m_pool(StringSlicePool::Style::Empty) + { + SLANG_ASSERT(m_pool.getSlicesCount() == 0); + } + + static const IdentifierFlags kIdentifierFlags[Index(IdentifierStyle::CountOf)]; + +protected: + List<IdentifierStyle> m_styles; + StringSlicePool m_pool; +}; + + +SLANG_FORCE_INLINE IdentifierFlags getFlags(IdentifierStyle style) +{ + return IdentifierLookup::kIdentifierFlags[Index(style)]; +} + +SLANG_FORCE_INLINE bool hasFlag(IdentifierStyle style, IdentifierFlag::Enum flag) +{ + return (getFlags(style) & flag) != 0; +} + +} // CppExtract + +#endif |
