https://github.com/shader-slang/slang
Revision 895fcff7df1a71af59fad6bb31939ff370920eb4 authored by Tim Foley on 06 December 2019, 21:16:03 UTC, committed by GitHub on 06 December 2019, 21:16:03 UTC
* Add a custom RTTI implementation for the AST

Profiling was showing that the internal routines behind `dynamic_cast` were the worst offenders in the whole codebase, and a lot of this was being driven by casting inside the semantic checking logic.

This change takes advantage of the fact that we *already* had a custom RTTI structure built up for the classes of syntax nodes that was previously being used to implement string->class lookup and factory services to support "magic" types and modifier in the stdlib (e.g., the way that a modifier declaration in the stdlib just lists the *name* of a C++ class that should be instantiated for it).

That RTTI information already included a pointer from each syntax class to its base class (if any), based on the restriction that the AST node types form a single-inheritance hierarchy.
The existing code already had a virtual `getClass()` routine on AST nodes, and an `isSubClassOf` query on the class information.
Putting those pieces together to implement the `dynamicCast` and `as` routines was a cinch.

The work in previous PRs to layer an abstraction over all the existing `dynamic_cast` call sites and to support type-specific `dynamicCast` implementations inside `RefPtr<>` pays off greatly here.

* fixup: refactor implementation to appease more pedantic/correct compilers
1 parent 54d3c5f
History
Tip revision: 895fcff7df1a71af59fad6bb31939ff370920eb4 authored by Tim Foley on 06 December 2019, 21:16:03 UTC
Add a custom RTTI implementation for the AST (#1148)
Tip revision: 895fcff
File Mode Size
docs
examples
external
prelude
source
tests
tools
.editorconfig -rw-r--r-- 937 bytes
.gitattributes -rw-r--r-- 95 bytes
.gitignore -rw-r--r-- 480 bytes
.gitmodules -rw-r--r-- 774 bytes
.travis.yml -rw-r--r-- 1.7 KB
CODE_OF_CONDUCT.md -rw-r--r-- 3.1 KB
LICENSE -rw-r--r-- 1.1 KB
README.md -rw-r--r-- 7.1 KB
appveyor.yml -rw-r--r-- 4.0 KB
premake5.lua -rw-r--r-- 28.3 KB
slang-com-helper.h -rw-r--r-- 4.8 KB
slang-com-ptr.h -rw-r--r-- 4.8 KB
slang-tag-version.h -rw-r--r-- 36 bytes
slang.h -rw-r--r-- 122.6 KB
slang.sln -rw-r--r-- 9.9 KB
test.bat -rw-r--r-- 1.4 KB
travis_build.sh -rw-r--r-- 460 bytes
travis_test.sh -rw-r--r-- 435 bytes

README.md

back to top