// decl-defs.h // Syntax class definitions for declarations. // A group of declarations that should be treated as a unit SYNTAX_CLASS(DeclGroup, DeclBase) SYNTAX_FIELD(List>, decls) END_SYNTAX_CLASS() // A "container" decl is a parent to other declarations ABSTRACT_SYNTAX_CLASS(ContainerDecl, Decl) SYNTAX_FIELD(List>, Members) RAW( template FilteredMemberList getMembersOfType() { return FilteredMemberList(Members); } // Dictionary for looking up members by name. // This is built on demand before performing lookup. Dictionary memberDictionary; // Whether the `memberDictionary` is valid. // Should be set to `false` if any members get added/remoed. bool memberDictionaryIsValid = false; // A list of transparent members, to be used in lookup // Note: this is only valid if `memberDictionaryIsValid` is true List transparentMembers; ) END_SYNTAX_CLASS() // Base class for all variable-like declarations ABSTRACT_SYNTAX_CLASS(VarDeclBase, Decl) // type of the variable SYNTAX_FIELD(TypeExp, type) RAW( Type* getType() { return type.type.Ptr(); } ) // Initializer expression (optional) SYNTAX_FIELD(RefPtr, initExpr) END_SYNTAX_CLASS() // A field of a `struct` type SIMPLE_SYNTAX_CLASS(StructField, VarDeclBase) // An `AggTypeDeclBase` captures the shared functionality // between true aggregate type declarations and extension // declarations: // // - Both can container members (they are `ContainerDecl`s) // - Both can have declared bases // - Both expose a `this` variable in their body // ABSTRACT_SYNTAX_CLASS(AggTypeDeclBase, ContainerDecl) END_SYNTAX_CLASS() // An extension to apply to an existing type SYNTAX_CLASS(ExtensionDecl, AggTypeDeclBase) SYNTAX_FIELD(TypeExp, targetType) // next extension attached to the same nominal type DECL_FIELD(ExtensionDecl*, nextCandidateExtension RAW(= nullptr)) END_SYNTAX_CLASS() // Declaration of a type that represents some sort of aggregate ABSTRACT_SYNTAX_CLASS(AggTypeDecl, AggTypeDeclBase) RAW( // extensions that might apply to this declaration ExtensionDecl* candidateExtensions = nullptr; FilteredMemberList GetFields() { return getMembersOfType(); } ) END_SYNTAX_CLASS() SIMPLE_SYNTAX_CLASS(StructDecl, AggTypeDecl) SIMPLE_SYNTAX_CLASS(ClassDecl, AggTypeDecl) // An interface which other types can conform to SIMPLE_SYNTAX_CLASS(InterfaceDecl, AggTypeDecl) // A kind of pseudo-member that represents an explicit // or implicit inheritance relationship. // SYNTAX_CLASS(InheritanceDecl, Decl) // The type expression as written SYNTAX_FIELD(TypeExp, base) RAW( // After checking, this dictionary will map members // required by the base type to their concrete // implementations in the type that contains // this inheritance declaration. Dictionary, Decl*> requirementWitnesses; ) END_SYNTAX_CLASS() // TODO: may eventually need sub-classes for explicit/direct vs. implicit/indirect inheritance // A declaration that represents a simple (non-aggregate) type // // TODO: probably all types will be aggregate decls eventually, // so that we can easily store conformances/constraints on type variables ABSTRACT_SYNTAX_CLASS(SimpleTypeDecl, Decl) END_SYNTAX_CLASS() // A `typedef` declaration SYNTAX_CLASS(TypeDefDecl, SimpleTypeDecl) SYNTAX_FIELD(TypeExp, type) END_SYNTAX_CLASS() // An 'assoctype' declaration, it is a container of inheritance clauses SYNTAX_CLASS(AssocTypeDecl, ContainerDecl) END_SYNTAX_CLASS() // A scope for local declarations (e.g., as part of a statement) SIMPLE_SYNTAX_CLASS(ScopeDecl, ContainerDecl) SIMPLE_SYNTAX_CLASS(ParamDecl, VarDeclBase) // Base class for things that have parameter lists and can thus be applied to arguments ("called") ABSTRACT_SYNTAX_CLASS(CallableDecl, ContainerDecl) RAW( FilteredMemberList GetParameters() { return getMembersOfType(); }) SYNTAX_FIELD(TypeExp, ReturnType) // Fields related to redeclaration, so that we // can support multiple specialized varaitions // of the "same" logical function. // // This should also help us to support redeclaration // of functions when handling HLSL/GLSL. // The "primary" declaration of the function, which will // be used whenever we need to unique things. FIELD_INIT(CallableDecl*, primaryDecl, nullptr) // The next declaration of the "same" function (that is, // with the same `primaryDecl`). FIELD_INIT(CallableDecl*, nextDecl, nullptr); END_SYNTAX_CLASS() // Base class for callable things that may also have a body that is evaluated to produce their result ABSTRACT_SYNTAX_CLASS(FunctionDeclBase, CallableDecl) SYNTAX_FIELD(RefPtr, Body) END_SYNTAX_CLASS() // A constructor/initializer to create instances of a type SIMPLE_SYNTAX_CLASS(ConstructorDecl, FunctionDeclBase) // A subscript operation used to index instances of a type SIMPLE_SYNTAX_CLASS(SubscriptDecl, CallableDecl) // An "accessor" for a subscript or property SIMPLE_SYNTAX_CLASS(AccessorDecl, FunctionDeclBase) SIMPLE_SYNTAX_CLASS(GetterDecl, AccessorDecl) SIMPLE_SYNTAX_CLASS(SetterDecl, AccessorDecl) SIMPLE_SYNTAX_CLASS(FuncDecl, FunctionDeclBase) SIMPLE_SYNTAX_CLASS(Variable, VarDeclBase); // A "module" of code (essentiately, a single translation unit) // that provides a scope for some number of declarations. SIMPLE_SYNTAX_CLASS(ModuleDecl, ContainerDecl) SYNTAX_CLASS(ImportDecl, Decl) // The name of the module we are trying to import FIELD(NameLoc, moduleNameAndLoc) // The scope that we want to import into FIELD(RefPtr, scope) // The module that actually got imported DECL_FIELD(RefPtr, importedModuleDecl) END_SYNTAX_CLASS() // A generic declaration, parameterized on types/values SYNTAX_CLASS(GenericDecl, ContainerDecl) // The decl that is genericized... SYNTAX_FIELD(RefPtr, inner) END_SYNTAX_CLASS() SYNTAX_CLASS(GenericTypeParamDecl, SimpleTypeDecl) // The bound for the type parameter represents a trait that any // type used as this parameter must conform to // TypeExp bound; // The "initializer" for the parameter represents a default value SYNTAX_FIELD(TypeExp, initType) END_SYNTAX_CLASS() // A constraint placed as part of a generic declaration SYNTAX_CLASS(GenericTypeConstraintDecl, Decl) // A type constraint like `T : U` is constraining `T` to be "below" `U` // on a lattice of types. This may not be a subtyping relationship // per se, but it makes sense to use that terminology here, so we // think of these fields as the sub-type and sup-ertype, respectively. SYNTAX_FIELD(TypeExp, sub) SYNTAX_FIELD(TypeExp, sup) END_SYNTAX_CLASS() SIMPLE_SYNTAX_CLASS(GenericValueParamDecl, VarDeclBase) // An empty declaration (which might still have modifiers attached). // // An empty declaration is uncommon in HLSL, but // in GLSL it is often used at the global scope // to declare metadata that logically belongs // to the entry point, e.g.: // // layout(local_size_x = 16) in; // SIMPLE_SYNTAX_CLASS(EmptyDecl, Decl) // A declaration used by the implementation to put syntax keywords // into the current scope. // SYNTAX_CLASS(SyntaxDecl, Decl) // What type of syntax node will be produced when parsing with this keyword? FIELD(SyntaxClass, syntaxClass) // Callback to invoke in order to parse syntax with this keyword. FIELD(SyntaxParseCallback, parseCallback) FIELD(void*, parseUserData) END_SYNTAX_CLASS()