diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-05-08 14:31:40 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-08 14:31:40 -0400 |
| commit | 798f3bc2236ce81499b05662dc11e7c071e7cde8 (patch) | |
| tree | fbfa2ef90d4cfdace9ce3667cf441e22137792fb /source/slang/slang-ast-reflect.cpp | |
| parent | c16abd4fe1bda5ebcd50dbb22f30c6be43bb885f (diff) | |
AST nodes using C++ Extractor (#1341)
* Extractor builds without any reference to syntax (as it will be helping to produce this!).
* Change macros to include the super class.
* WIP replacing defs files.
* Added indexOf(const UnownedSubString& in) to UnownedSubString.
Refactored extractor
* Output a macro for each type with the extracted info - can be used during injection in class
* Simplify the header file - as can get super type and last from macro now
* Store the 'origin' of a definition
* Some small tidy ups to the extractor.
* Improve comments on the extractor options.
* Made CPPExtractor own SourceOrigins
* Small fixes around SourceOrigin.
* Small tidy up around macroOrign
* WIP Visitor seems now to work correctly.
Split out types used by ast into slang-ast-support-types.h
* Fix remaining problems with C++ extractor being used with AST nodes.
Add CountOf to extractor type ids.
Added ReflectClassInfo::getInfo to turn an ASTNodeType into a ReflectClassInfo
* Fix compiling on linux.
Fix typo in memset.
* Small tidy up around comments/layout.
Moved NodeBase casting to NodeBase.
* Make premake generate project that builds with cpp-extractor for AST.
* Get the source directory from the filter in premake.
* Fix typo in source path
* Explicitly set the source path for premake generation for AST.
* Special case handling of override to apease Clang.
* Use a more general way to find the slang-ast-reflect.h file to run the extractor.
* Appveyor is not triggering slang-cpp-extractor - try putting dependson together.
* Put building slang-cpp-extractor first.
* Disable some project options to stop MSBuild producing internal compiler errors.
* Try reordering the projects in premake5.lua
* Hack to try and make slang-cpp-extractor built on appveyor.
* Disable flags - not required for MSBuild on appveyor.
* Disable flags not required for build on AppVeyor.
* Updated Visual Studio projects with slang-cpp-extractor.
* Added Visual Studio slang-cpp-extractor project.
Diffstat (limited to 'source/slang/slang-ast-reflect.cpp')
| -rw-r--r-- | source/slang/slang-ast-reflect.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/source/slang/slang-ast-reflect.cpp b/source/slang/slang-ast-reflect.cpp new file mode 100644 index 000000000..471daf92b --- /dev/null +++ b/source/slang/slang-ast-reflect.cpp @@ -0,0 +1,70 @@ +#include "../../slang.h" + +#include "slang-ast-reflect.h" + +#include "../core/slang-smart-pointer.h" + +#include "slang-ast-all.h" + +#include <typeinfo> +#include <assert.h> + +#include "slang-ast-generated-macro.h" + +namespace Slang +{ + +#define SLANG_REFLECT_GET_REFLECT_CLASS_INFO(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) infos.infos[int(ASTNodeType::NAME)] = &NAME::kReflectClassInfo; + +static ReflectClassInfo::Infos _calcInfos() +{ + ReflectClassInfo::Infos infos; + memset(&infos, 0, sizeof(infos)); + SLANG_ALL_ASTNode_NodeBase(SLANG_REFLECT_GET_REFLECT_CLASS_INFO, _) + SLANG_ALL_ASTNode_Substitutions(SLANG_REFLECT_GET_REFLECT_CLASS_INFO, _) + return infos; +} + +/* static */const ReflectClassInfo::Infos ReflectClassInfo::kInfos = _calcInfos(); + +bool ReflectClassInfo::isSubClassOfSlow(const ThisType& super) const +{ + ReflectClassInfo const* info = this; + while (info) + { + if (info == &super) + return true; + info = info->m_superClass; + } + return false; +} + +// Now try and implement all of the classes +// Macro generated is of the format + + +template <typename T> +struct CreateImpl +{ + static void* create() { return new T; } +}; + +#define SLANG_GET_SUPER_BASE(SUPER) nullptr +#define SLANG_GET_SUPER_INNER(SUPER) &SUPER::kReflectClassInfo +#define SLANG_GET_SUPER_LEAF(SUPER) &SUPER::kReflectClassInfo + +#define SLANG_GET_CREATE_FUNC_ABSTRACT(NAME) nullptr +#define SLANG_GET_CREATE_FUNC_NONE(NAME) &CreateImpl<NAME>::create + +#define SLANG_GET_CREATE_FUNC_NON_VISITOR_ABSTRACT(NAME) nullptr +#define SLANG_GET_CREATE_FUNC_NON_VISITOR(NAME) &CreateImpl<NAME>::create + + +#define SLANG_REFLECT_CLASS_INFO(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) \ + /* static */const ReflectClassInfo NAME::kReflectClassInfo = { uint32_t(ASTNodeType::NAME), uint32_t(ASTNodeType::LAST), SLANG_GET_SUPER_##TYPE(SUPER), #NAME, SLANG_GET_CREATE_FUNC_##MARKER(NAME) }; + +SLANG_ALL_ASTNode_NodeBase(SLANG_REFLECT_CLASS_INFO, _) +SLANG_ALL_ASTNode_Substitutions(SLANG_REFLECT_CLASS_INFO, _) + + +} // namespace Slang |
