diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2019-01-22 14:57:25 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-22 14:57:25 -0800 |
| commit | a08a3140716b89146bf0a22dc014c5470e90e910 (patch) | |
| tree | 8033fe6e7bb47dce2a1bca3bb767e6ac7329afb9 /source/slang/syntax.h | |
| parent | a005007c2e9132788c92aa5a9c5fed2cb90f7841 (diff) | |
Clean up variable declaration class hierarchy (#787)
The AST class hierarchy for variable declarations had a few messy bits.
First, there are more subclasses of `VarDeclBase` than seem strictly necessary; especially for stuff like `struct` member variable which use `StructField` even for `static` fields (which are effectively globals).
Second, the AST node type for the "cases" within an `enum` was made a subclass of `VarDeclBase` for expediency, but this isn't really semantically accurate (and doesn't seem to be paying off much in deduplication of code).
This change tries to address both of those problems.
First, we replace the existing `Variable` and `StructField` cases with a single `VarDecl` case that covers globals, locals, and member variables.
I haven't gone so far as to replace function parameters or generic value parameters, but that might be worth considering as a further clean-up.
Second, we change `EnumCaseDecl` to inherit directly from `Decl` instead of `VarDeclBase` and add an explicit case for handling them where they were previously handled as if they were variable declarations (this was done by manually surveying all locations in the code that referenced `VarDeclBase`).
Diffstat (limited to 'source/slang/syntax.h')
| -rw-r--r-- | source/slang/syntax.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/source/slang/syntax.h b/source/slang/syntax.h index bd7de74ad..9b0277b56 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -1223,14 +1223,24 @@ namespace Slang return declRef.Substitute(declRef.getDecl()->initExpr); } + inline RefPtr<Type> getType(DeclRef<EnumCaseDecl> const& declRef) + { + return declRef.Substitute(declRef.getDecl()->type.Ptr()); + } + + inline RefPtr<Expr> getTagExpr(DeclRef<EnumCaseDecl> const& declRef) + { + return declRef.Substitute(declRef.getDecl()->tagExpr); + } + inline RefPtr<Type> GetTargetType(DeclRef<ExtensionDecl> const& declRef) { return declRef.Substitute(declRef.getDecl()->targetType.Ptr()); } - inline FilteredMemberRefList<StructField> GetFields(DeclRef<StructDecl> const& declRef) + inline FilteredMemberRefList<VarDecl> GetFields(DeclRef<StructDecl> const& declRef) { - return getMembersOfType<StructField>(declRef); + return getMembersOfType<VarDecl>(declRef); } inline RefPtr<Type> getBaseType(DeclRef<InheritanceDecl> const& declRef) |
