From cab694dcead92a554654d7fa3f08909d519425f0 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 29 Jun 2017 08:55:09 -0700 Subject: Add meta-definitions for AST types - The big change here is that all the definitions for syntax-node classes have been macro-ized, to that we can do light metaprogramming over them - The use of macros for this has big down-sides, but I'm not quite ready to do anything more heavy-weight right now - The macro-ized definitions can be included multiple times, to generate different declarations/code as needed - The first example of using this meta-programming facility is a new visitor system - The actual visitor base classes and the dispatch logic are all generated from the meta-files - There was only one visitor left in the code: the semantics checker, so that was ported to the new system. - All current test cases pass, so *of course* that means all is well. --- source/slang/expr-defs.h | 109 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 source/slang/expr-defs.h (limited to 'source/slang/expr-defs.h') diff --git a/source/slang/expr-defs.h b/source/slang/expr-defs.h new file mode 100644 index 000000000..59bad37e7 --- /dev/null +++ b/source/slang/expr-defs.h @@ -0,0 +1,109 @@ +// expr-defs.h + +// Syntax class definitions for expressions. + + +// Base class for expressions that will reference declarations +ABSTRACT_SYNTAX_CLASS(DeclRefExpr, ExpressionSyntaxNode) + +// The scope in which to perform lookup + FIELD(RefPtr, scope) + + // The declaration of the symbol being referenced + DECL_FIELD(DeclRef, declRef) + + // The name of the symbol being referenced + FIELD(String, name) +END_SYNTAX_CLASS() + +SIMPLE_SYNTAX_CLASS(VarExpressionSyntaxNode, DeclRefExpr) + +// An expression that references an overloaded set of declarations +// having the same name. +SYNTAX_CLASS(OverloadedExpr, ExpressionSyntaxNode) + + // Optional: the base expression is this overloaded result + // arose from a member-reference expression. + SYNTAX_FIELD(RefPtr, base) + + // The lookup result that was ambiguous + FIELD(LookupResult, lookupResult2) +END_SYNTAX_CLASS() + +SYNTAX_CLASS(ConstantExpressionSyntaxNode, ExpressionSyntaxNode) + FIELD(Token, token) + + RAW( + enum class ConstantType + { + Int, + Bool, + Float, + String, + }; + ConstantType ConstType; + union + { + IntegerLiteralValue integerValue; + FloatingPointLiteralValue floatingPointValue; + }; + String stringValue; + ) +END_SYNTAX_CLASS() + +// An initializer list, e.g. `{ 1, 2, 3 }` +SYNTAX_CLASS(InitializerListExpr, ExpressionSyntaxNode) + SYNTAX_FIELD(List>, args) +END_SYNTAX_CLASS() + +// A base expression being applied to arguments: covers +// both ordinary `()` function calls and `<>` generic application +ABSTRACT_SYNTAX_CLASS(AppExprBase, ExpressionSyntaxNode) + SYNTAX_FIELD(RefPtr, FunctionExpr) + SYNTAX_FIELD(List>, Arguments) +END_SYNTAX_CLASS() + +SIMPLE_SYNTAX_CLASS(InvokeExpressionSyntaxNode, AppExprBase) + +SIMPLE_SYNTAX_CLASS(OperatorExpressionSyntaxNode, InvokeExpressionSyntaxNode) + +SIMPLE_SYNTAX_CLASS(InfixExpr , OperatorExpressionSyntaxNode) +SIMPLE_SYNTAX_CLASS(PrefixExpr , OperatorExpressionSyntaxNode) +SIMPLE_SYNTAX_CLASS(PostfixExpr, OperatorExpressionSyntaxNode) + +SYNTAX_CLASS(IndexExpressionSyntaxNode, ExpressionSyntaxNode) + SYNTAX_FIELD(RefPtr, BaseExpression) + SYNTAX_FIELD(RefPtr, IndexExpression) +END_SYNTAX_CLASS() + +SYNTAX_CLASS(MemberExpressionSyntaxNode, DeclRefExpr) + SYNTAX_FIELD(RefPtr, BaseExpression) +END_SYNTAX_CLASS() + +SYNTAX_CLASS(SwizzleExpr, ExpressionSyntaxNode) + SYNTAX_FIELD(RefPtr, base) + FIELD(int, elementCount) + FIELD(int, elementIndices[4]) +END_SYNTAX_CLASS() + +// A dereference of a pointer or pointer-like type +SYNTAX_CLASS(DerefExpr, ExpressionSyntaxNode) + SYNTAX_FIELD(RefPtr, base) +END_SYNTAX_CLASS() + +SYNTAX_CLASS(TypeCastExpressionSyntaxNode, ExpressionSyntaxNode) + SYNTAX_FIELD(TypeExp, TargetType) + SYNTAX_FIELD(RefPtr, Expression) +END_SYNTAX_CLASS() + +SIMPLE_SYNTAX_CLASS(SelectExpressionSyntaxNode, OperatorExpressionSyntaxNode) + +SIMPLE_SYNTAX_CLASS(GenericAppExpr, AppExprBase) + +// An expression representing re-use of the syntax for a type in more +// than once conceptually-distinct declaration +SYNTAX_CLASS(SharedTypeExpr, ExpressionSyntaxNode) + // The underlying type expression that we want to share + SYNTAX_FIELD(TypeExp, base) +END_SYNTAX_CLASS() + -- cgit v1.2.3