CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
AST.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "ASTEnums.hpp"
11#include "Identifier.hpp"
12#include "Token.hpp"
13#include "TypeDenoter.hpp"
14
16
24
28
30
31#include <functional>
32
36
37 class Visitor;
38
39 // Enumeration for expression finding predicates.
41 SearchLValue = (1 << 0),
42 SearchRValue = (1 << 1),
43 SearchAll = (~0u),
44 };
45
46 // Iteration callback for VarDecl AST nodes.
48
49 // Iteration callback for Expression AST nodes.
51
52 // Iteration callback for argument/parameter-type associations.
54
55 // Predicate callback to find an expression inside an expression tree.
56 using FindPredicateConstFunctor = UniqueFunction<bool(const Expression& expression) const>;
57
58 // Function callback to merge two expressions into one.
60
61#define AST_INTERFACE(CLASS_NAME) \
62 static const Types classType = Types::CLASS_NAME; \
63 explicit CLASS_NAME(const SourcePosition& astPos) { area = SourceArea(astPos, 1); } \
64 explicit CLASS_NAME(const SourceArea& astArea) { area = astArea; } \
65 Types getType() const override { return Types::CLASS_NAME; } \
66 void visit(Visitor* visitor, void* args = nullptr) override { visitor->visit##CLASS_NAME(this, args); }
67
68#define DECLARATION_AST_ALIAS(ALIAS, BASE) \
69 using ALIAS = BASE; \
70 using ALIAS##Ptr = BASE##Ptr
71
72#define FLAG_ENUM enum : UInt32
73
74#define FLAG(IDENT, INDEX) IDENT = (1u << (INDEX))
75
76 // Base class for all AST node classes.
77 struct AST {
78 // Types of AST classes.
79 enum class Types {
80 // Common AST classes
81
82 Program,
83 // AST root node
89 // Register qualifier (e.g. "register(b0)")
91 // Pack-offset qualifier (e.g. "packoffset(c0.x)")
93 // Array dimension (e.g. "[10]")
95 // Type specifier with type denoter/modifiers/classes and optional structure (StructDecl)
96
97 // Declaration objects that can be referenced by an 'ObjectExpression'
98
100 // Variable declaration
102 // Buffer declaration (Texture- and Storage Buffers)
104 // Sampler state declaration
106 // Structure declaration
108 // Type alias declaration
110 // Function declaration
112 // Uniform/constant buffer declaration
113
114 // Declaration statements
115
117 // Variable declaration statement with several variables (VarDecl)
119 // Buffer declaration statement with several buffers (BufferDecl)
121 // Sampler declaration statement with several samplers (SamplerDecl)
123 // Type alias declaration statement with several types (AliasDecl)
125 // Statement with a single declaration object (StructDecl, FunctionDecl, or UniformBufferDecl)
126
127 // Common statements
128
140 // Control transfer statement (Break, Continue, Discard)
142 // GLSL only
143
144 // Expressions
145
161 };
162
163 FLAG_ENUM{
165 // This AST node is reachable from the main entry point.
167 // This AST node is dead code (after return path).
169 // This AST node is a built-in node (not part of the actual program source).
170 };
171
172 SourceArea area; // Source code area.
173 RawFlags flags; // Flags bitmask (default 0).
174
175 virtual ~AST();
176
177 // Returns the AST node type.
178 [[nodiscard]] virtual Types getType() const = 0;
179
180 // Calls the respective visit-function of the specified visitor.
181 virtual void visit(Visitor* visitor, void* args = nullptr) = 0;
182
183 // Returns the AST node as the specified sub class if this AST node has the correct type. Otherwise, null is returned.
184 template<typename T> [[nodiscard]] static T* getAs(AST* ast) {
185 return (ast != nullptr && ast->getType() == T::classType ? static_cast<T*>(ast) : nullptr);
186 }
187
188 // Returns the AST node as the specified sub class if this AST node has the correct type. Otherwise, null is returned.
189 template<typename T> [[nodiscard]] static const T* getAs(const AST* ast) {
190 return (ast != nullptr && ast->getType() == T::classType ? static_cast<const T*>(ast) : nullptr);
191 }
192
193 // Returns this AST node as the specified sub class if this AST node has the correct type. Otherwise, null is returned.
194 template<typename T> [[nodiscard]] T* as() { return (getType() == T::classType ? static_cast<T*>(this) : nullptr); }
195
196 // Returns this AST node as the specified sub class if this AST node has the correct type. Otherwise, null is returned.
197 template<typename T> [[nodiscard]] const T* as() const { return (getType() == T::classType ? static_cast<const T*>(this) : nullptr); }
198 };
199
200 // Returns true if the specified AST type denotes a "Decl" AST.
202
203 // Returns true if the specified AST type denotes an "Expression" AST.
205
206 // Returns true if the specified AST type denotes a "Statement" AST.
208
209 // Returns true if the specified AST type denotes a "...declStatement" AST.
211
212 // MARK: - Common AST classes -
213
214 // Statement AST base class.
215 struct Statement : public AST {
216 String comment; // Optional commentary for this statement. May be a multi-line string.
217 Vector<AttributePtr> attributes; // Attribute list. May be empty.
218
219 // Collects all variable-, buffer-, and sampler AST nodes with their identifiers in the specified map.
221 };
222
223 // AST base class with type denoter.
224 struct TypedAST : public AST {
225 public:
226 // Returns a type denoter for this AST node or throws an std::runtime_error if a type denoter can not be derived.
228
229 // Resets the buffered type denoter.
231
232 protected:
234
235 private:
236 // Buffered type denoter which is stored in the "GetTypeDenoter" function and can be reset with the "resetTypeDenoter" function.
238 };
239
240 // Expression AST base class.
241 struct Expression : public TypedAST {
242 FLAG_ENUM{
244 // This expression has already been converted.
245 };
246
247 // Returns the variable or null if this is not just a single variable expression.
249
254
255 // Returns the semantic of this expression, or Semantic::Undefined if this expression has no semantic.
257
258 // Returns true if this expression can be trivially copied (e.g. simple expressions without potential side effects). By default false.
259 [[nodiscard]] virtual bool isTrivialCopyable(UInt32 maxTreeDepth = 3) const;
260
261 // Returns the first expression for which the specified predicate returns true.
263
264 // Returns the first expression of the specified type in this expression tree.
266
267 // Returns the first expression of a different type than the specified type in this expression tree.
269
270 // Returns the first expression for which the specified predicate returns true.
272
273 // Returns the first expression of the specified type in this expression tree.
275
276 // Returns the first expression of a different type than the specified type in this expression tree.
278 };
279
280 // Declaration AST base class.
281 struct Declaration : public TypedAST {
282 FLAG_ENUM{
284 // This declaration object is eventually written to.
286 // This declaration object is eventually read from.
287 };
288
289 // Identifier of the declaration object (may be empty, e.g. for anonymous structures).
291
292 // Returns a descriptive string of the type signature.
293 [[nodiscard]] virtual String toString() const;
294
295 // Returns the type specifier of this declaration object, or null if there is no type specifier. By default null.
297
298 // Returns true if this is an anonymous structure.
299 [[nodiscard]] bool isAnonymous() const;
300 };
301
302 // Program AST root.
303 struct Program : public AST {
305
306 // Layout meta data for tessellation-control shaders
312
313 // Layout meta data for tessellation-evaluation shaders
319
320 // Layout meta data for fragment shaders
326
327 // Layout meta data for fragment shaders
329 // True, if fragment coordinate (SV_Position) is used inside a fragment shader.
330 bool fragCoordUsed = false;
331
332 // True, if pixel center is assumed to be integral, otherwise pixel center is assumed to have an (0.5, 0.5) offset.
333 bool pixelCenterInteger = false;
334
335 // True, if the [earlydepthstencil] attribute is specified for the fragment shader entry point.
336 bool earlyDepthStencil = false;
337 };
338
339 // Layout meta data for compute shaders
342 };
343
346
349
352
355
358
361
364
367
370
373
376
377 // Registers a usage of an intrinsic with the specified argument data types (only base types).
379
380 // Registers a usage of an intrinsic with the specified arguments (only base types).
381 void registerIntrinsicUsage(const Intrinsic intrinsic, const Vector<ExpressionPtr>& arguments);
382
383 // Returns a usage-container of the specified intrinsic or null if the specified intrinsic was not registered to be used.
384 [[nodiscard]] const IntrinsicUsage* fetchIntrinsicUsage(const Intrinsic intrinsic) const;
385 };
386
387 // Code block.
393
394 // Sampler state value assignment.
395 // see https://msdn.microsoft.com/de-de/library/windows/desktop/bb509644(v=vs.85).aspx
396 struct SamplerValue : public AST {
398
399 String name; // Sampler state name.
400 ExpressionPtr value; // Sampler state value expression.
401 };
402
403 // Attribute (e.g. "[unroll]" or "[numthreads(x,y,z)]").
404 struct Attribute : public AST {
406
407 AttributeType attributeType = AttributeType::Undefined; // Type of this attribute. Must not be undefined.
408 Vector<ExpressionPtr> arguments; // Optional attribute arguments.
409
411
413 };
414
415 // Case block for a switch statement.
416 struct SwitchCase : public AST {
418
419 ExpressionPtr expression; // Case expression; null for the default case.
420 Vector<StatementPtr> statements; // Statement list (switch-case does not require a braced code block).
421
422 // Returns true, if this is a default case (if 'expression' is null).
423 [[nodiscard]] bool isDefaultCase() const;
424 };
425
426 // Register (e.g. ": register(t0)").
427 struct Register : public AST {
429
430 ShaderTarget shaderTarget = ShaderTarget::Undefined; // Shader target (or profile). Undefined means all targets are affected.
431 RegisterType registerType = RegisterType::Undefined; // Type of the register. Must not be undefined.
432 Int32 set = 0; // Zero-based register set index. By default 0.
433 Int32 slot = 0; // Zero-based register slot index. By default 0.
434
436
437 // Returns the first slot register for the specified shader target or null, if there is no register.
439 };
440
441 // Pack offset.
442 struct PackOffset : public AST {
444
445 //TODO: change this to an enumeration (like 'RegisterType').
447 String vectorComponent; // Vector component. May be empty.
448
450 };
451
452 // Array dimension with bufferd expression evaluation.
453 struct ArrayDimension : public TypedAST {
455
456 ExpressionPtr expression; // Array dimension expression. Must be a constant integer expression.
457 Int32 size = 0; // Evaluated array dimension size. Zero for dynamic array dimension.
458
460
462
463 // Returns true if this array dimension has a dynamic size (i.e. size == 0).
464 [[nodiscard]] bool hasDynamicSize() const;
465
466 // Validates the boundary of the specified index, if this array dimension has a fixed size. Throws a runtime error on failure.
467 void validateIndexBoundary(int idx) const;
468
469#if 0 //UNUSED
470 // Returns the array dimension sizes as integral vector.
472#endif
473 };
474
475 // Type specifier with optional structure declaration.
476 struct TypeSpecifier : public TypedAST {
478
479 bool isInput = false; // Input modifier 'in'.
480 bool isOutput = false; // Input modifier 'out'.
481 bool isUniform = false; // Input modifier 'uniform'.
482
483 Set<StorageClass> storageClasses; // Storage classes, e.g. extern, precise, etc.
484 Set<InterpModifier> interpModifiers; // Interpolation modifiers, e.g. nointerpolation, linear, centroid etc.
485 Set<TypeModifier> typeModifiers; // Type modifiers, e.g. const, row_major, column_major (also 'snorm' and 'unorm' for floats).
486 PrimitiveType primitiveType = PrimitiveType::Undefined; // Primitive type for geometry entry pointer parameters.
487 StructDeclarationPtr structDeclaration; // Optional structure declaration.
488
489 TypeDenoterPtr typeDenoter; // Own type denoter.
490
491 // Returns the name of this type and all modifiers.
493
495
496 // Returns the StructDecl reference of this type denoter or null if there is no such reference.
498
499 // Returns true if the 'const' type modifier is set.
500 [[nodiscard]] bool isConst() const;
501
502 // Returns true if the 'const' type modifier or the 'uniform' input modifier is set.
503 [[nodiscard]] bool isConstOrUniform() const;
504
505 // Inserts the specified type modifier. Overlapping matrix packings will be removed.
507
508 // Returns true if any of the specified type modifiers is contained.
510
511 // Returns true if any of the specified storage classes is contained.
513
514 // Swaps the 'row_major' with 'column_major' storage layout, and inserts the specified default layout if none of these are set.
516 };
517
518 // MARK: - Declaration objects -
519
520 // Variable declaration.
521 struct VarDeclaration : public Declaration {
523
524 FLAG_ENUM{
526 // This variable is used as shader input.
528 // This variable is used as shader output.
530 // This variable is a system value (e.g. SV_Position/ gl_Position).
532 // This variable is a dynamic array (for input/output semantics).
534 // This variable is used as entry point output (return value, output parameter, stream output).
536 // This variable is a local variable of the entry point.
537
539 // This variable is used as shader input, and it is a system value.
541 // This variable is used as shader output, and it is a system value.
542 };
543
544 ObjectExpressionPtr namespaceExpression; // Optional namespace expression. May be null.
545 Vector<ArrayDimensionPtr> arrayDimensions; // Array dimension list. May be empty.
546 Vector<RegisterPtr> slotRegisters; // Slot register list. May be empty.
547 IndexedSemantic semantic; // Variable semantic. May be invalid.
548 PackOffsetPtr packOffset; // Optional pack offset. May be null.
549 Vector<VarDeclarationStatementPtr> annotations; // Annotations can be ignored by analyzers and generators.
550 ExpressionPtr initializer; // Optional initializer expression. May be null.
551
552 TypeDenoterPtr customTypeDenoter; // Optional type denoter which can be different from the type of its declaration statement.
553 Variant initializerValue; // Optional variant of the initializer value (if the initializer is a constant expression).
554
555 VarDeclarationStatement* declarationStatementRef = nullptr; // Reference to its declaration statement (parent node). May be null.
556 UniformBufferDeclaration* bufferDeclarationRef = nullptr; // Reference to its uniform buffer declaration (optional parent-parent-node). May be null.
557 StructDeclaration* structDeclarationRef = nullptr; // Reference to its owner structure declaration (optional parent-parent-node). May be null.
558 VarDeclaration* staticMemberVarRef = nullptr; // Bi-directional reference to its static variable declaration or definition. May be null.
559
560 // Returns the variable declaration as string.
561 [[nodiscard]] String toString() const override;
562
563 // Returns a type denoter for this variable declaration or throws an std::runtime_error if the type can not be derived.
565
566 // Returns the type specifier of the declaration statemnt reference (if set).
568
569 // Returns the reference to the static member variable declaration, or null if there is no such declaration (see staticMemberVarRef).
571
572 // Returns the reference to the static member variable definition, or null if there is no such definition (see staticMemberVarRef).
574
575 // Returns true if this variable is declared as static.
576 [[nodiscard]] bool isStatic() const;
577
578 // Returns true if this variable is a function parameter.
579 [[nodiscard]] bool isParameter() const;
580
581 // Returns true if this is a non-parameter local variable with a constant initializer.
583
584 // Sets a custom type denoter, or the default type denoter if the parameter is null.
585 void setCustomTypeDenoter(const TypeDenoterPtr& typeDenoter);
586
587 // Adds the specified flag to this variable and all members and sub members of the structure, if the variable has a structure type.
589
590 // Accumulates the vector size for this variables (with a 16 byte boundary), and returns true on success.
591 bool accumulateAlignedVectorSize(UInt32& size, UInt32& padding, UInt32* offset = nullptr);
592 };
593
594 // Buffer declaration.
597
598 FLAG_ENUM{
600 // This buffer is used in a texture compare operation.
602 // This is a buffer used in an image load or image atomic operation.
603 };
604
605 Vector<ArrayDimensionPtr> arrayDimensions; // Array dimension list. May be empty.
606 Vector<RegisterPtr> slotRegisters; // Slot register list. May be empty.
607 Vector<VarDeclarationStatementPtr> annotations; // Annotations can be ignored by analyzers and generators.
608
609 BufferDeclarationStatement* declarationStatementRef = nullptr; // Reference to its declaration statement (parent node).
610
612
613 // Returns the buffer type of the parent's node type denoter.
615 };
616
617 // Sampler state declaration.
620
621 Vector<ArrayDimensionPtr> arrayDimensions; // Array dimension list. May be empty.
622 Vector<RegisterPtr> slotRegisters; // Slot register list. May be empty.
623 String textureIdent; // Optional variable identifier of the texture object (for DX9 effect files).
624 Vector<SamplerValuePtr> samplerValues; // State values for a sampler decl-ident.
625
626 SamplerDeclarationStatement* declarationStatementRef = nullptr; // Reference to its declaration statmenet (parent node).
627
629
630 // Returns the sampler type of the parent's node type denoter.
632 };
633
634 // StructDecl object.
637
638 FLAG_ENUM{
640 // This structure is used as shader input.
642 // This structure is used as shader output.
644 // This is a nested structure within another structure.
645
646 //TODO: rename this flag, since it's meaning is confusing
648 // This structure is eventually used as variable or parameter type of function other than the entry point.
649 };
650
651 bool isClass = false; // This struct was declared as 'class'.
652 String baseStructName; // May be empty (if no inheritance is used).
653 Vector<StatementPtr> localStatements; // Local declaration statements.
654
655 //TODO: maybe replace "VarDeclStatementPtr" by "VarDeclPtr" here.
656 Vector<VarDeclarationStatementPtr> varMembers; // List of all member variable declaration statements.
657 Vector<FunctionDeclarationPtr> funcMembers; // List of all member function declarations.
658
659 BasicDeclarationStatement* declarationStatementRef = nullptr; // Reference to its declaration statement (parent node).
660 StructDeclaration* baseStructRef = nullptr; // Optional reference to base struct.
661 StructDeclaration* compatibleStructRef = nullptr; // Optional reference to a type compatible struct (only for anonymous structs).
662 Map<String, VarDeclaration*> systemValuesRef; // List of members with system value semantic (SV_...).
663 Set<StructDeclaration*> parentStructDeclarationRefs; // References to all structures that have a member variable with this structure type.
664 Set<VarDeclaration*> shaderOutputVarDeclarationRefs; // References to all variables from this structure that are used as entry point outputs.
665
666 // Returns a descriptive string of the structure signature (e.g. "struct s" or "struct <anonymous>").
667 [[nodiscard]] String toString() const override;
668
669 // Returns true if the specified structure declaration has the same member types as this structure (see 'TypeDenoter' for valid compare flags).
670 [[nodiscard]] bool equalsMemberTypes(const StructDeclaration& rhs, const RawFlags& compareFlags = 0) const;
671
672 // Returns true if this structure type is castable to the specified base type denoter.
673 [[nodiscard]] bool isCastableTo(const BaseTypeDenoter& rhs) const;
674
675 // Returns the VarDecl AST node inside this struct decl for the specified identifier, or null if there is no such VarDecl.
677
678 // Returns the VarDecl AST node of the 'base' member variable, or null if there is no such VarDecl.
680
681 // Returns the StructDecl AST node with the specified identifier, that is a base of this structure (or the structure itself), or null if there is no such StructDecl.
683
684 // Returns the FunctionDecl AST node for the specified argument type denoter list (used to derive the overloaded function).
686 const StructDeclaration** owner = nullptr, bool throwErrorIfNoMatch = false) const;
687
688 // Returns an identifier that is similar to the specified identifier (for suggestions of typos)
690
691 // Returns a type denoter for this structure.
693
694 // Returns true if this structure has at least one member that is not a system value.
696
697 // Returns the total number of member variables (including all base structures).
698 [[nodiscard]] std::size_t numMemberVariables(bool onlyNonStaticMembers = false) const;
699
700 // Returns the total number of member functions (including all base structures).
701 [[nodiscard]] std::size_t numMemberFunctions(bool onlyNonStaticMembers = false) const;
702
703 // Returns a list with the type denoters of all members (including all base structures, if enabled).
705
706 // Iterates over each VarDecl AST node (included nested structures, and members in base structures).
708
709 // Adds the specified variable as an instance of this structure, that is used as shader output (see HasMultipleShaderOutputInstances).
711
712 // Returns true if this structure is used more than once as entry point output (either through variable arrays or multiple variable declarations).
714
715 // Returns true if this structure is a base of the specified sub structure.
717
718 // Adds the specified flags to this structure, all base structures, all nested structures, and all structures of its member variables.
720
721 // Adds the specified flags to this structure, and all parent structures (i.e. all structures that have a member variable with this structure type).
723
724 // Returns the zero-based index of the specified member variable, or ~0 on failure.
725 [[nodiscard]] std::size_t memberVarToIndex(const VarDeclaration* varDeclaration, bool includeBaseStructs = true) const;
726
727 // Returns the member variable of the specified zero-based index, null on failure.
728 [[nodiscard]] VarDeclaration* indexToMemberVar(std::size_t idx, bool includeBaseStructs = true) const;
729
730 // Accumulates the vector size for all members in this structure (with a 16 byte boundary for each member), and returns true on success.
731 bool accumulateAlignedVectorSize(UInt32& size, UInt32& padding, UInt32* offset = nullptr);
732 };
733
734 // Type alias declaration.
737
738 TypeDenoterPtr typeDenoter; // Type denoter of the aliased type.
739 AliasDeclarationStatement* declarationStatementRef = nullptr; // Reference to its declaration statement (parent node).
740
742 };
743
744 // Function declaration.
747
749 using IteratorFunc = FunctionView<void(VarDeclaration* varDeclaration) const>;
750
751 Vector<VarDeclaration*> varDeclarationRefs; // References to all variable declarations of the user defined semantics
752 Vector<VarDeclaration*> varDeclarationRefsSV; // References to all variable declarations of the system value semantics
753
754 void add(VarDeclaration* varDeclaration);
755 [[nodiscard]] bool contains(const VarDeclaration* varDeclaration) const;
756 void forEach(const IteratorFunc& iterator);
757
758 // Returns true if both lists are empty.
759 [[nodiscard]] bool empty() const;
760
761 // Updates the distribution of system-value and non-system-value semantics.
763 };
764
770
771 FLAG_ENUM{
773 // This function is the main entry point.
775 // This function is a secondary entry point (e.g. patch constant function).
777 // At least one control path does not return a value.
778 };
779
780 TypeSpecifierPtr returnType; // Function return type (TypeSpecifier).
782 IndexedSemantic semantic = Semantic::Undefined; // Function return semantic; may be undefined.
783 Vector<VarDeclarationStatementPtr> annotations; // Annotations can be ignored by analyzers and generators.
784 CodeBlockPtr codeBlock; // May be null (if this AST node is a forward declaration).
785
786 ParameterSemantics inputSemantics; // Entry point input semantics.
787 ParameterSemantics outputSemantics; // Entry point output semantics.
788
789 BasicDeclarationStatement* declarationStatementRef = nullptr; // Reference to its declaration statement (parent node). Must not be null.
790 FunctionDeclaration* funcImplRef = nullptr; // Reference to the function implementation (only for forward declarations).
791 Vector<FunctionDeclaration*> funcForwardDeclarationRefs; // Reference to all forward declarations (only for implementations).
792 StructDeclaration* structDeclarationRef = nullptr; // Structure declaration reference if this is a member function; may be null
793
794 Vector<ParameterStructure> paramStructs; // Parameter with structure type (only for entry point).
795
797
798 // Returns true if this function declaration is just a forward declaration (without function body).
800
801 // Returns true if this function has a void return type.
802 [[nodiscard]] bool hasVoidReturnType() const;
803
804 // Returns true if this is a member function (member of a structure).
805 [[nodiscard]] bool isMemberFunction() const;
806
807 // Returns true if this is a static function (see TypeSpecifier::HasAnyStorageClassOf).
808 [[nodiscard]] bool isStatic() const;
809
810 // Returns a descriptive string of the function signature (e.g. "void f(int x)").
811 [[nodiscard]] String toString() const override;
812
813 // Returns a descriptive string of the function signature (e.g. "void f(int x)").
815
816 // Returns a descriptive strinf of the type of this function object (e.g. "void(int)").
818
819 // Returns true if the specified function declaration has the same signature as this function (see 'TypeDenoter' for valid compare flags).
820 [[nodiscard]] bool equalsSignature(const FunctionDeclaration& rhs, const RawFlags& compareFlags = 0) const;
821
822 // Returns the minimal number of arguments for a call to this function.
823 [[nodiscard]] std::size_t numMinArgs() const;
824
825 // Returns the maximal number of arguments for a call to this function (this is merely: parameters.size()).
826 [[nodiscard]] std::size_t numMaxArgs() const;
827
828 // Sets the specified function AST node as the implementation of this forward declaration.
830
831 // Returns true if the specified type denoter matches the parameter.
833
834 // Fetches the function declaration from the list that matches the specified argument types.
837 };
838
839 // Uniform buffer (cbuffer, tbuffer) declaration.
842
843 UniformBufferType bufferType = UniformBufferType::Undefined; // Type of this uniform buffer. Must not be undefined.
844 Vector<RegisterPtr> slotRegisters; // Slot register list. May be empty.
845 Vector<StatementPtr> localStatements; // Local declaration statements.
846 Vector<VarDeclarationStatementPtr> varMembers; // List of all member variable declaration statements.
847 TypeModifier commonStorageLayout = TypeModifier::ColumnMajor; // Type modifier of the common matrix/vector storage.
848 BasicDeclarationStatement* declarationStatementRef = nullptr; // Reference to its declaration statement (parent node). Must not be null.
849
851
852 [[nodiscard]] String toString() const override;
853
854 // Derives the common storage layout type modifier of all variable members (see 'commonStorageLayout' member).
856
857 // Accumulates the vector size of the entire uniform buffer (with 16 byte alignemnd for each vector), and return true on success.
858 bool accumulateAlignedVectorSize(UInt32& size, UInt32& padding, UInt32* offset = nullptr);
859 };
860
861 // MARK: - Declaration statements -
862
863 // Buffer (and texture) declaration.
866
867 BufferTypeDenoterPtr typeDenoter; // Own type denoter.
869
870 // Implements Statement::CollectDeclIdents
872 };
873
874 // Sampler declaration.
877
878 SamplerTypeDenoterPtr typeDenoter; // Own type denoter.
880
881 // Implements Statement::CollectDeclIdents
883 };
884
885 // Basic declaration statement.
891
892 // Variable declaration statement.
895
896 FLAG_ENUM{
898 // This variable is used as shader input.
900 // This variable is used as shader output.
902 // This variable is a function parameter (flag should be set during parsing).
904 // This variable is the 'self' parameter of a member function.
906 // This variable is the 'base' member of a structure with inheritance.
908 // This variable is implicitly declared as constant.
909 };
910
911 TypeSpecifierPtr typeSpecifier; // Type basis for all variables (can be extended by array indices in each individual variable).
912 Vector<VarDeclarationPtr> varDeclarations; // Variable declaration list.
913
914 // Implements Statement::CollectDeclIdents
916
917 // Returns the var-decl statement as string.
918 [[nodiscard]] String toString(bool useVarNames = true) const;
919
920 // Returns the VarDecl AST node inside this var-decl statement for the specified identifier, or null if there is no such VarDecl.
922
923 // Returns the one and only VarDecl AST node (used for parameters of FunctionDecl AST nodes).
925
926 // Returns true if this is an input parameter.
927 [[nodiscard]] bool isInput() const;
928
929 // Returns true if this is an output parameter.
930 [[nodiscard]] bool isOutput() const;
931
932 // Returns true if this is a uniform.
933 [[nodiscard]] bool isUniform() const;
934
935 // Returns true if the 'const' type modifier or the 'uniform' input modifier is set.
936 [[nodiscard]] bool isConstOrUniform() const;
937
938 // Inserts the specified type modifier. Overlapping matrix packings will be removed.
940
941 // Returns true if any of the specified type modifiers is contained.
943
944 // Iterates over each VarDecl AST node.
946
947 // Makes this var-decl statement implicitly constant, iff not explicitly declared as constant (see 'isUniform' and 'isImplicitlyConst').
949
950 // Returns the reference to the owner structure from the first variable entry, or null if there is no such owner structure.
952
953 // Accumulates the vector size for all variables in this statement (with a 16 byte boundary for each member), and returns true on success.
954 bool accumulateAlignedVectorSize(UInt32& size, UInt32& padding, UInt32* offset = nullptr);
955 };
956
957 // Type alias declaration statement.
960
961 StructDeclarationPtr structDeclaration; // Optional structure declaration. May be null.
963 };
964
965 // MARK: - Statements -
966
967 // Null statement.
971
972 // Code block statement.
978
979 // 'for'-loop statemnet.
980 struct ForLoopStatement : public Statement {
982
983 StatementPtr initStatement; // Initializer statement. Must not be null, but can be an instance of 'NullStatement'.
984 ExpressionPtr condition; // Condition expressionesion. May be null.
985 ExpressionPtr iteration; // Loop iteration expression. May be null.
986 StatementPtr bodyStatement; // Loop body statement.
987 };
988
989 // 'while'-loop statement.
992
993 ExpressionPtr condition; // Condition expression.
994 StatementPtr bodyStatement; // Loop body statement.
995 };
996
997 // 'do/while'-loop statement.
1000
1001 StatementPtr bodyStatement; // Loop body statement.
1002 ExpressionPtr condition; // Condition expression.
1003 };
1004
1005 // 'if' statement.
1006 struct IfStatement : public Statement {
1008
1009 ExpressionPtr condition; // Condition expression.
1010 StatementPtr bodyStatement; // 'then'-branch body statement.
1011 ElseStatementPtr elseStatement; // 'else'-branch statement. May be null.
1012 };
1013
1014 // 'else' statement.
1015 struct ElseStatement : public Statement {
1017
1018 StatementPtr bodyStatement; // 'else'-branch body statement.
1019 };
1020
1021 // 'switch' statement.
1022 struct SwitchStatement : public Statement {
1024
1025 ExpressionPtr selector; // Switch selector expression.
1026 Vector<SwitchCasePtr> cases; // Switch case list.
1027 };
1028
1029 // Arbitrary expression statement.
1035
1036 // Returns statement.
1037 struct ReturnStatement : public Statement {
1039
1040 FLAG_ENUM{
1042 // This return statement is at the end of its function body.
1043 };
1044
1045 ExpressionPtr expression; // Return statement expression. May be null.
1046 };
1047
1048 // Control transfer statement.
1051
1052 CtrlTransfer transfer = CtrlTransfer::Undefined; // Control transfer type (break, continue, discard). Must not be undefined.
1053 };
1054
1055 struct LayoutStatement : public Statement {
1057
1058 bool isInput = false; // Input modifier 'in'.
1059 bool isOutput = false; // Input modifier 'out'.
1060 };
1061
1062 // MARK: - Expressions -
1063
1064 // Null expression (used for dynamic array dimensions).
1070
1071 // List expression ( expression (',' expression)+ ).
1074
1075 Vector<ExpressionPtr> expressions; // Sub expression list. Must have at least two elements.
1076
1078
1080
1081 // Appens the specified expression to the sub expressions ('SequenceExpression' will be flattened).
1082 void append(const ExpressionPtr& expression);
1083 };
1084
1085 // Literal expression.
1088
1089 String value; // Literal expression value.
1090 DataType dataType = DataType::Undefined; // Valid data types: String, Bool, Int, UInt, Half, Float, Double. Undefined for 'NULL'.
1091
1093
1094 // Converts the data type of this literal expression, resets the buffered type denoter (see ResetTypeDenoter), and modifies the value string.
1095 void convertDataType(const DataType type);
1096
1097 // Returns the value of this literal if it is a string literal (excluding the quotation marks). Otherwise an empty string is returned.
1099
1100 // Returns the value either with or without suffixes (e.g. "1.0f" or "1.0").
1102
1103 // Returns true if this is a NULL literal.
1104 [[nodiscard]] bool isNull() const;
1105
1106 // Returns true if this literal needs a space after the literal, when a vector subscript is used as postfix.
1108 };
1109
1110 // Type name expression (used for simpler cast-expression parsing).
1118
1119 // Ternary expression.
1122
1123 ExpressionPtr condExpression; // Ternary condition expression.
1124 ExpressionPtr thenExpression; // 'then'-branch expression.
1125 ExpressionPtr elseExpression; // 'else'-branch expression.
1126
1129
1130 // Returns true if the conditional expression is a vector type.
1132 };
1133
1134 // Binary expression.
1137
1138 ExpressionPtr lhsExpression; // Left-hand-side expression.
1139 BinaryOp op = BinaryOp::Undefined; // Binary operator. Must not be undefined.
1140 ExpressionPtr rhsExpression; // Right-hand-side expression.
1141
1144 };
1145
1146 // (Pre-) Unary expression.
1147 struct UnaryExpression : public Expression {
1149
1150 UnaryOp op = UnaryOp::Undefined; // Unary operator. Must not be undefined.
1151 ExpressionPtr expression; // Right-hand-side expression.
1152
1156 };
1157
1158 // Post unary expression (e.g. x++, x--)
1161
1162 ExpressionPtr expression; // Left-hand-side expression.
1163 UnaryOp op = UnaryOp::Undefined; // Unary operator. Must not be undefined.
1164
1167 };
1168
1169 // Function call expression (e.g. "foo()" or "foo().bar()" or "foo()[0].bar()").
1170 struct CallExpression : public Expression {
1172
1173 FLAG_ENUM{
1174 // If this function call is an intrinsic, it's wrapper function can be inlined (i.e. no wrapper function must be generated)
1175 // e.g. "clip(a), clip(b);" can not be inlined, due to the list expression.
1177
1178 // This is a call expression to a wrapper function (use expression identifier, not from a function reference).
1180 };
1181
1182 ExpressionPtr prefixExpression; // Optional prefix expression. May be null.
1183 bool isStatic = false; // Specifies whether this function is a static member.
1184 String ident; // Function name identifier. Empty for type constructors.
1185 TypeDenoterPtr typeDenoter; // Null, if the function call is NOT a type constructor (e.g. "float2(0, 0)").
1186 Vector<ExpressionPtr> arguments; // Argument expression list.
1187
1188 FunctionDeclaration* funcDeclarationRef = nullptr; // Reference to the function declaration. May be null.
1189 Intrinsic intrinsic = Intrinsic::Undefined; // Intrinsic ID (if this is an intrinsic).
1190 Vector<VarDeclaration*> defaultParamRefs; // Reference to parameters that have a default argument.
1191
1193
1195
1197
1198#if 0 //UNUSED
1199 // Returns a list of all argument expressions (including the default arguments).
1201#endif
1202
1203 // Returns the reference to the function declaration of this call expression, or null if not set.
1205
1206 // Returns the reference to the function implementation of this call expression, or null if not set.
1208
1209 // Iterates over each argument expression that is assigned to an output parameter.
1211
1212 // Iterates over each argument expression together with its associated parameter.
1214
1215 // Inserts the specified argument expression at the front of the argument list.
1216 void pushArgumentFront(const ExpressionPtr& expression);
1217
1218 // Moves the prefix expression into the argument list as first argument.
1220
1221 // Moves the first argument out of the argument list as prefix expression.
1223
1224 // Merges the argument with index 'firstArgIndex' and the next argument with the merge function callback.
1226
1227 // Returns the expression which denotes the member function class instance (either the prefix expression or the first argument); see PushPrefixToArguments.
1229 };
1230
1231 // Bracket expression.
1242
1243 // Assignment expression.
1246
1247 ExpressionPtr lvalueExpression; // L-value expression.
1248 AssignOp op = AssignOp::Undefined; // Assignment operator. Must not be undefined.
1249 ExpressionPtr rvalueExpression; // R-value expression.
1250
1254 };
1255
1256 // Object access expression.
1259
1260 FLAG_ENUM{
1262 // This object identifier must be written out as it is.
1264 // This expression is a base structure namespace expression.
1265 };
1266
1267 ExpressionPtr prefixExpression; // Optional prefix expression. May be null.
1268 bool isStatic = false; // Specifies whether this object is a static member.
1269 String ident; // Object identifier.
1270 Declaration* symbolRef = nullptr; // Optional symbol reference to the object declaration. May be null (e.g. for vector subscripts).
1271
1276 [[nodiscard]] bool isTrivialCopyable(UInt32 maxTreeDepth = 3) const override;
1277
1278 // Returns a type denoter for the vector subscript of this object expression or throws an runtime error on failure.
1280
1281 // Returns this object expression as a static namespace, i.e. only for prefix expression that are also from type ObjectExpression.
1283
1284 // Replaces the old symbol and identifier by the new symbol.
1286
1287 // Returns the specified type of AST node from the symbol (if the symbol refers to one).
1288 template<typename T> [[nodiscard]] T* fetchSymbol() const {
1289 if(symbolRef) {
1290 if(auto ast = symbolRef->as<T>()) {
1291 return ast;
1292 }
1293 }
1294 return nullptr;
1295 }
1296
1297 // Returns the variable AST node (if the symbol refers to one).
1299 };
1300
1301 // Array-access expression (e.g. "foo()[arrayAccess]").
1302 struct ArrayExpression : public Expression {
1304
1305 ExpressionPtr prefixExpression; // Prefix expression.
1306 Vector<ExpressionPtr> arrayIndices; // Array index expression list (right hand side).
1307
1309
1311
1313
1314 // Returns the number of array indices (shortcut for "arrayIndices.size()").
1315 [[nodiscard]] std::size_t numIndices() const;
1316 };
1317
1318 // Cast expression.
1329
1330 // Initializer list expression.
1333
1334 Vector<ExpressionPtr> expressions; // Sub expression list.
1335
1337
1339
1340 // Returns the number of elements with all sub initializers being unrollwed (e.g. { 1, { 2, 3 } } has 3 'unrolled' elements just like { 1, 2, 3 }).
1341 [[nodiscard]] std::size_t numElementsUnrolled() const;
1342
1343 // Collects all elements from the sub expressions without initializer lists (e.g. { 1, { 2, 3 } } --> { 1, 2, 3 }).
1345
1346 // Resolves all initializer lists in the sub expression.
1348
1349 // Fetches the sub expression with the specified array indices and throws an ASTRuntimeError on failure.
1351
1352 // Returns the next array indices for a sub expression.
1353 [[nodiscard]] bool nextArrayIndices(Vector<int>& arrayIndices) const;
1354 };
1355
1356#undef AST_INTERFACE
1357#undef DECLARATION_AST_ALIAS
1358#undef FLAG_ENUM
1359#undef FLAG
1360} // namespace CeresEngine::ShaderCompiler
#define FLAG_ENUM
Definition AST.hpp:72
#define FLAG(IDENT, INDEX)
Definition AST.hpp:74
#define AST_INTERFACE(CLASS_NAME)
Definition AST.hpp:61
Definition Flags.hpp:235
Class to manage identifiers that can be renamed (maybe several times), to keep track of the original ...
Definition Identifier.hpp:18
Definition SourceArea.hpp:20
Definition Variant.hpp:20
Definition Visitor.hpp:92
Definition AST.hpp:33
SPtr< TypeSpecifier > TypeSpecifierPtr
Definition Visitor.hpp:37
UniqueFunction< void(VarDeclarationPtr &varDeclaration) const > VarDeclarationIteratorFunctor
Definition AST.hpp:47
TypeModifier
Definition ASTEnums.hpp:471
SPtr< Expression > ExpressionPtr
Definition Visitor.hpp:26
SPtr< ObjectExpression > ObjectExpressionPtr
Definition Visitor.hpp:76
SPtr< PackOffset > PackOffsetPtr
Definition Visitor.hpp:35
AttributeValue
Definition ASTEnums.hpp:948
UniqueFunction< ExpressionPtr(const ExpressionPtr &expression0, const ExpressionPtr &expression1) const > MergeExpressionFunctor
Definition AST.hpp:59
bool isExpressionAST(const AST::Types t)
ShaderTarget
Shader target enumeration.
Definition Targets.hpp:16
@ Undefined
Undefined shader target.
bool isDeclarationAST(const AST::Types t)
UnaryOp
Definition ASTEnums.hpp:119
SPtr< SourceCode > SourceCodePtr
Definition SourceCode.hpp:66
SPtr< BaseTypeDenoter > BaseTypeDenoterPtr
Definition TypeDenoter.hpp:32
SPtr< StructDeclaration > StructDeclarationPtr
Definition Visitor.hpp:42
BinaryOp
Definition ASTEnums.hpp:58
SPtr< VarDeclaration > VarDeclarationPtr
Definition Visitor.hpp:39
RegisterType
Definition ASTEnums.hpp:741
SPtr< BufferTypeDenoter > BufferTypeDenoterPtr
Definition TypeDenoter.hpp:33
UniqueFunction< bool(const Expression &expression) const > FindPredicateConstFunctor
Definition AST.hpp:56
SPtr< CodeBlock > CodeBlockPtr
Definition Visitor.hpp:30
CtrlTransfer
Definition ASTEnums.hpp:147
UniqueFunction< void(ExpressionPtr &expression, VarDeclaration *param) const > ExpressionIteratorFunctor
Definition AST.hpp:50
SPtr< Statement > StatementPtr
Definition Visitor.hpp:25
Intrinsic
Intrinsics function enumeration (currently only HLSL intrinsics).
Definition ASTEnums.hpp:980
SPtr< TypeDenoter > TypeDenoterPtr
Definition TypeDenoter.hpp:29
UniformBufferType
Definition ASTEnums.hpp:482
DataType
Definition ASTEnums.hpp:159
SPtr< SamplerTypeDenoter > SamplerTypeDenoterPtr
Definition TypeDenoter.hpp:34
bool isStatementAST(const AST::Types t)
bool isDeclarationStatementAST(const AST::Types t)
UniqueFunction< void(ExpressionPtr &argument, const TypeDenoter &paramTypeDen) const > ArgumentParameterTypeFunctor
Definition AST.hpp:53
BufferType
Definition ASTEnums.hpp:492
SPtr< ElseStatement > ElseStatementPtr
Definition Visitor.hpp:59
SPtr< Declaration > DeclarationPtr
Definition Visitor.hpp:27
SearchFlags
Definition AST.hpp:40
@ SearchRValue
Definition AST.hpp:42
@ SearchAll
Definition AST.hpp:43
@ SearchLValue
Definition AST.hpp:41
SPtr< Attribute > AttributePtr
Definition Visitor.hpp:31
PrimitiveType
Definition ASTEnums.hpp:425
AssignOp
Definition ASTEnums.hpp:24
SamplerType
Definition ASTEnums.hpp:571
AttributeType
Definition ASTEnums.hpp:766
std::initializer_list< T > InitializerList
An object of type InitializerList<T> is a lightweight proxy object that provides access to an array o...
Definition InitializerList.hpp:40
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
std::int32_t Int32
Definition DataTypes.hpp:21
FunctionBase< false, true, fu2::capacity_default, true, false, Signatures... > FunctionView
A non owning copyable function wrapper for arbitrary callable types.
Definition Function.hpp:64
constexpr auto predicate(Callable &&callable) noexcept
Helper function to create a new predicate from a lambda.
Definition Predicate.hpp:390
std::uint32_t UInt32
Definition DataTypes.hpp:23
FunctionBase< true, false, fu2::capacity_default, true, false, Signatures... > UniqueFunction
An owning non copyable function wrapper for arbitrary callable types.
Definition Function.hpp:59
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
std::set< Key, Compare, ScopedAllocatorAdaptor< StdAllocator< Key, RawAllocator > > > Set
Set is an associative container that contains a sorted set of unique objects of type Key.
Definition Set.hpp:21
std::map< Key, T, Compare, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > Map
Map is a sorted associative container that contains key-value pairs with unique keys.
Definition Map.hpp:24
virtual void visit(Visitor *visitor, void *args=nullptr)=0
Types
Definition AST.hpp:79
@ isDeadCode
Definition AST.hpp:166
@ isReachable
Definition AST.hpp:164
@ isBuiltin
Definition AST.hpp:168
SourceArea area
Definition AST.hpp:172
static const T * getAs(const AST *ast)
Definition AST.hpp:189
const T * as() const
Definition AST.hpp:197
T * as()
Definition AST.hpp:194
RawFlags flags
Definition AST.hpp:173
static T * getAs(AST *ast)
Definition AST.hpp:184
virtual Types getType() const =0
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
AliasDeclarationStatement * declarationStatementRef
Definition AST.hpp:739
TypeDenoterPtr typeDenoter
Definition AST.hpp:738
StructDeclarationPtr structDeclaration
Definition AST.hpp:961
Vector< AliasDeclarationPtr > aliasDeclarations
Definition AST.hpp:962
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
ExpressionPtr expression
Definition AST.hpp:456
Vector< ExpressionPtr > arrayIndices
Definition AST.hpp:1306
const ObjectExpression * fetchLValueExpression() const override
Returns the first node in the expression tree that is an l-value (may also be constant!...
ExpressionPtr prefixExpression
Definition AST.hpp:1305
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
ExpressionPtr lvalueExpression
Definition AST.hpp:1247
ExpressionPtr rvalueExpression
Definition AST.hpp:1249
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
const ObjectExpression * fetchLValueExpression() const override
Returns the first node in the expression tree that is an l-value (may also be constant!...
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
AssignOp op
Definition AST.hpp:1248
Vector< ExpressionPtr > arguments
Definition AST.hpp:408
AttributeType attributeType
Definition AST.hpp:407
static AttributePtr findAttribute(const Vector< AttributePtr > &attributes, AttributeType type)
Definition TypeDenoter.hpp:238
DeclarationPtr declarationObject
Definition AST.hpp:889
BinaryOp op
Definition AST.hpp:1139
ExpressionPtr rhsExpression
Definition AST.hpp:1140
ExpressionPtr lhsExpression
Definition AST.hpp:1138
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
const ObjectExpression * fetchLValueExpression() const override
Returns the first node in the expression tree that is an l-value (may also be constant!...
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
IndexedSemantic fetchSemantic() const override
ExpressionPtr expression
Definition AST.hpp:1235
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
Vector< VarDeclarationStatementPtr > annotations
Definition AST.hpp:607
Vector< ArrayDimensionPtr > arrayDimensions
Definition AST.hpp:605
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
Vector< RegisterPtr > slotRegisters
Definition AST.hpp:606
BufferDeclarationStatement * declarationStatementRef
Definition AST.hpp:609
BufferTypeDenoterPtr typeDenoter
Definition AST.hpp:867
Vector< BufferDeclarationPtr > bufferDeclarations
Definition AST.hpp:868
void collectDeclarationIdents(Map< const AST *, String > &declarationASTIdents) const override
IndexedSemantic fetchSemantic() const override
void forEachOutputArgument(const ExpressionIteratorFunctor &iterator)
void forEachArgumentWithParameterType(const ArgumentParameterTypeFunctor &iterator)
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
TypeDenoterPtr typeDenoter
Definition AST.hpp:1185
Vector< VarDeclaration * > defaultParamRefs
Definition AST.hpp:1190
Intrinsic intrinsic
Definition AST.hpp:1189
@ canInlineIntrinsicWrapper
Definition AST.hpp:1176
FunctionDeclaration * funcDeclarationRef
Definition AST.hpp:1188
Vector< ExpressionPtr > arguments
Definition AST.hpp:1186
bool mergeArguments(std::size_t firstArgIndex, const MergeExpressionFunctor &mergeFunctor)
FunctionDeclaration * getFunctionImpl() const
Expression * getMemberFuncObjectExpression() const
String ident
Definition AST.hpp:1184
FunctionDeclaration * getFunctionDeclaration() const
ExpressionPtr prefixExpression
Definition AST.hpp:1182
void pushArgumentFront(const ExpressionPtr &expression)
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
bool isStatic
Definition AST.hpp:1183
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
TypeSpecifierPtr typeSpecifier
Definition AST.hpp:1322
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
ExpressionPtr expression
Definition AST.hpp:1323
Vector< StatementPtr > statements
Definition AST.hpp:391
CodeBlockPtr codeBlock
Definition AST.hpp:976
CtrlTransfer transfer
Definition AST.hpp:1052
Identifier ident
Definition AST.hpp:290
virtual TypeSpecifier * fetchTypeSpecifier() const
ExpressionPtr condition
Definition AST.hpp:1002
StatementPtr bodyStatement
Definition AST.hpp:1001
StatementPtr bodyStatement
Definition AST.hpp:1018
virtual const ObjectExpression * fetchLValueExpression() const
Returns the first node in the expression tree that is an l-value (may also be constant!...
Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll)
const Expression * findFirstOf(const Types expressionType, UInt32 flags=SearchAll) const
virtual bool isTrivialCopyable(UInt32 maxTreeDepth=3) const
virtual const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const
Expression * findFirstOf(const Types expressionType, UInt32 flags=SearchAll)
ObjectExpression * fetchLValueExpression()
@ wasConverted
Definition AST.hpp:243
Expression * findFirstNotOf(const Types expressionType, UInt32 flags=SearchAll)
const Expression * findFirstNotOf(const Types expressionType, UInt32 flags=SearchAll) const
VarDeclaration * fetchVarDeclaration() const
virtual IndexedSemantic fetchSemantic() const
ExpressionPtr expression
Definition AST.hpp:1033
ExpressionPtr condition
Definition AST.hpp:984
StatementPtr initStatement
Definition AST.hpp:983
StatementPtr bodyStatement
Definition AST.hpp:986
ExpressionPtr iteration
Definition AST.hpp:985
Vector< VarDeclaration * > varDeclarationRefs
Definition AST.hpp:751
bool contains(const VarDeclaration *varDeclaration) const
Vector< VarDeclaration * > varDeclarationRefsSV
Definition AST.hpp:752
FunctionView< void(VarDeclaration *varDeclaration) const > IteratorFunc
Definition AST.hpp:749
StructDeclaration * structDeclaration
Definition AST.hpp:768
bool matchParameterWithTypeDenoter(std::size_t paramIndex, const TypeDenoter &argType, bool implicitConversion) const
void setFuncImplRef(FunctionDeclaration *funcDeclaration)
static FunctionDeclaration * fetchFunctionDeclarationFromList(const Vector< FunctionDeclaration * > &funcDeclarationList, const String &ident, const Vector< TypeDenoterPtr > &argTypeDenoters, bool throwErrorIfNoMatch=true)
Vector< VarDeclarationStatementPtr > annotations
Definition AST.hpp:783
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
String toString(bool useParamNames) const
FunctionDeclaration * funcImplRef
Definition AST.hpp:790
IndexedSemantic semantic
Definition AST.hpp:782
ParameterSemantics inputSemantics
Definition AST.hpp:786
Vector< ParameterStructure > paramStructs
Definition AST.hpp:794
TypeSpecifierPtr returnType
Definition AST.hpp:780
BasicDeclarationStatement * declarationStatementRef
Definition AST.hpp:789
Vector< FunctionDeclaration * > funcForwardDeclarationRefs
Definition AST.hpp:791
Vector< VarDeclarationStatementPtr > parameters
Definition AST.hpp:781
ParameterSemantics outputSemantics
Definition AST.hpp:787
bool equalsSignature(const FunctionDeclaration &rhs, const RawFlags &compareFlags=0) const
CodeBlockPtr codeBlock
Definition AST.hpp:784
StructDeclaration * structDeclarationRef
Definition AST.hpp:792
StatementPtr bodyStatement
Definition AST.hpp:1010
ExpressionPtr condition
Definition AST.hpp:1009
ElseStatementPtr elseStatement
Definition AST.hpp:1011
Vector< ExpressionPtr > expressions
Definition AST.hpp:1334
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
void collectElements(Vector< ExpressionPtr > &elements) const
ExpressionPtr fetchSubExpression(const Vector< int > &arrayIndices) const
bool nextArrayIndices(Vector< int > &arrayIndices) const
bool isOutput
Definition AST.hpp:1059
String getLiteralValue(bool enableSuffix=true) const
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
DataType dataType
Definition AST.hpp:1090
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
T * fetchSymbol() const
Definition AST.hpp:1288
Declaration * symbolRef
Definition AST.hpp:1270
bool isTrivialCopyable(UInt32 maxTreeDepth=3) const override
String ident
Definition AST.hpp:1269
BaseTypeDenoterPtr getTypeDenoterFromSubscript() const
VarDeclaration * fetchVarDeclaration() const
IndexedSemantic fetchSemantic() const override
@ isBaseStructNamespace
Definition AST.hpp:1263
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
const ObjectExpression * fetchLValueExpression() const override
Returns the first node in the expression tree that is an l-value (may also be constant!...
ExpressionPtr prefixExpression
Definition AST.hpp:1267
String vectorComponent
Definition AST.hpp:447
String registerName
Definition AST.hpp:446
Definition AST.hpp:1159
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
UnaryOp op
Definition AST.hpp:1163
ExpressionPtr expression
Definition AST.hpp:1162
PrimitiveType inputPrimitive
Definition AST.hpp:322
FunctionDeclaration * patchConstFunctionRef
Definition AST.hpp:310
LayoutTessControlShader layoutTessControl
Global program layout attributes for a tessellation-control shader.
Definition AST.hpp:363
const IntrinsicUsage * fetchIntrinsicUsage(const Intrinsic intrinsic) const
LayoutFragmentShader layoutFragment
Global program layout attributes for a fragment shader.
Definition AST.hpp:372
LayoutGeometryShader layoutGeometry
Global program layout attributes for a geometry shader.
Definition AST.hpp:369
void registerIntrinsicUsage(const Intrinsic intrinsic, const Vector< DataType > &argumentDataTypes)
FunctionDeclaration * entryPointRef
Reference to the entry point function declaration.
Definition AST.hpp:354
Set< MatrixSubscriptUsage > usedMatrixSubscripts
Set of all used matrix subscripts (filled by the reference analyzer).
Definition AST.hpp:360
SourceCodePtr sourceCode
Preprocessed source code.
Definition AST.hpp:351
LayoutComputeShader layoutCompute
Global program layout attributes for a compute shader.
Definition AST.hpp:375
LayoutTessEvaluationShader layoutTessEvaluation
Global program layout attributes for a tessellation-evaluation shader.
Definition AST.hpp:366
Map< Intrinsic, IntrinsicUsage > usedIntrinsics
Set of all used intrinsic (filled by the reference analyzer).
Definition AST.hpp:357
void registerIntrinsicUsage(const Intrinsic intrinsic, const Vector< ExpressionPtr > &arguments)
Vector< StatementPtr > globalStatements
Global declaration statements.
Definition AST.hpp:345
Vector< ASTPtr > disabledAST
AST nodes that have been disabled for code generation (not part of the default visitor).
Definition AST.hpp:348
Int32 set
Definition AST.hpp:432
ShaderTarget shaderTarget
Definition AST.hpp:430
static Register * getForTarget(const Vector< RegisterPtr > &registers, const ShaderTarget shaderTarget)
Int32 slot
Definition AST.hpp:433
RegisterType registerType
Definition AST.hpp:431
ExpressionPtr expression
Definition AST.hpp:1045
Vector< RegisterPtr > slotRegisters
Definition AST.hpp:622
SamplerDeclarationStatement * declarationStatementRef
Definition AST.hpp:626
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
Vector< ArrayDimensionPtr > arrayDimensions
Definition AST.hpp:621
String textureIdent
Definition AST.hpp:623
Vector< SamplerValuePtr > samplerValues
Definition AST.hpp:624
SamplerTypeDenoterPtr typeDenoter
Definition AST.hpp:878
Vector< SamplerDeclarationPtr > samplerDeclarations
Definition AST.hpp:879
void collectDeclarationIdents(Map< const AST *, String > &declarationASTIdents) const override
String name
Definition AST.hpp:399
ExpressionPtr value
Definition AST.hpp:400
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
Vector< ExpressionPtr > expressions
Definition AST.hpp:1075
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
void append(const ExpressionPtr &expression)
String comment
Definition AST.hpp:216
virtual void collectDeclarationIdents(Map< const AST *, String > &declarationASTIdents) const
Vector< AttributePtr > attributes
Definition AST.hpp:217
void forEachVarDeclaration(const VarDeclarationIteratorFunctor &iterator, bool includeBaseStructs=true)
StructDeclaration * compatibleStructRef
Definition AST.hpp:661
bool isCastableTo(const BaseTypeDenoter &rhs) const
Vector< FunctionDeclarationPtr > funcMembers
Definition AST.hpp:657
Set< StructDeclaration * > parentStructDeclarationRefs
Definition AST.hpp:663
StructDeclaration * baseStructRef
Definition AST.hpp:660
String baseStructName
Definition AST.hpp:652
StructDeclaration * fetchBaseStructDeclaration(const String &ident)
VarDeclaration * fetchVarDeclaration(const String &ident, const StructDeclaration **owner=nullptr) const
Vector< VarDeclarationStatementPtr > varMembers
Definition AST.hpp:656
void addFlagsRecursiveParents(UInt32 structFlags)
Map< String, VarDeclaration * > systemValuesRef
Definition AST.hpp:662
Set< VarDeclaration * > shaderOutputVarDeclarationRefs
Definition AST.hpp:664
String fetchSimilar(const String &ident)
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
bool equalsMemberTypes(const StructDeclaration &rhs, const RawFlags &compareFlags=0) const
void collectMemberTypeDenoters(Vector< TypeDenoterPtr > &memberTypeDens, bool includeBaseStructs=true) const
Vector< StatementPtr > localStatements
Definition AST.hpp:653
VarDeclaration * indexToMemberVar(std::size_t idx, bool includeBaseStructs=true) const
BasicDeclarationStatement * declarationStatementRef
Definition AST.hpp:659
std::size_t memberVarToIndex(const VarDeclaration *varDeclaration, bool includeBaseStructs=true) const
bool accumulateAlignedVectorSize(UInt32 &size, UInt32 &padding, UInt32 *offset=nullptr)
bool isBaseOf(const StructDeclaration *subStructDeclaration, bool includeSelf=false) const
std::size_t numMemberVariables(bool onlyNonStaticMembers=false) const
FunctionDeclaration * fetchFunctionDeclaration(const String &ident, const Vector< TypeDenoterPtr > &argTypeDenoters, const StructDeclaration **owner=nullptr, bool throwErrorIfNoMatch=false) const
std::size_t numMemberFunctions(bool onlyNonStaticMembers=false) const
void addShaderOutputInstance(VarDeclaration *varDeclaration)
ExpressionPtr expression
Definition AST.hpp:419
Vector< StatementPtr > statements
Definition AST.hpp:420
ExpressionPtr selector
Definition AST.hpp:1025
Vector< SwitchCasePtr > cases
Definition AST.hpp:1026
ExpressionPtr condExpression
Definition AST.hpp:1123
ExpressionPtr thenExpression
Definition AST.hpp:1124
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
ExpressionPtr elseExpression
Definition AST.hpp:1125
Definition TypeDenoter.hpp:82
TypeSpecifierPtr typeSpecifier
Definition AST.hpp:1114
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
void swapMatrixStorageLayout(const TypeModifier defaultStorgeLayout)
bool hasAnyStorageClassOf(const InitializerList< StorageClass > &modifiers) const
Set< StorageClass > storageClasses
Definition AST.hpp:483
StructDeclarationPtr structDeclaration
Definition AST.hpp:487
bool hasAnyTypeModifierOf(const InitializerList< TypeModifier > &modifiers) const
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
bool isUniform
Definition AST.hpp:481
Set< TypeModifier > typeModifiers
Definition AST.hpp:485
TypeDenoterPtr typeDenoter
Definition AST.hpp:489
StructDeclaration * getStructDeclarationRef()
bool isOutput
Definition AST.hpp:480
PrimitiveType primitiveType
Definition AST.hpp:486
void setTypeModifier(const TypeModifier modifier)
bool isInput
Definition AST.hpp:479
Set< InterpModifier > interpModifiers
Definition AST.hpp:484
TypeDenoterPtr mBufferedTypeDenoter
Definition AST.hpp:237
virtual TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter)=0
const TypeDenoterPtr & getTypeDenoter(const TypeDenoter *expectedTypeDenoter=nullptr)
UnaryOp op
Definition AST.hpp:1150
const ObjectExpression * fetchLValueExpression() const override
Returns the first node in the expression tree that is an l-value (may also be constant!...
ExpressionPtr expression
Definition AST.hpp:1151
const Expression * find(const FindPredicateConstFunctor &predicate, UInt32 flags=SearchAll) const override
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
TypeModifier commonStorageLayout
Definition AST.hpp:847
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
bool accumulateAlignedVectorSize(UInt32 &size, UInt32 &padding, UInt32 *offset=nullptr)
UniformBufferType bufferType
Definition AST.hpp:843
Vector< RegisterPtr > slotRegisters
Definition AST.hpp:844
Vector< StatementPtr > localStatements
Definition AST.hpp:845
BasicDeclarationStatement * declarationStatementRef
Definition AST.hpp:848
Vector< VarDeclarationStatementPtr > varMembers
Definition AST.hpp:846
TypeModifier deriveCommonStorageLayout(const TypeModifier defaultStorgeLayout=TypeModifier::Undefined)
Vector< RegisterPtr > slotRegisters
Definition AST.hpp:546
Vector< VarDeclarationStatementPtr > annotations
Definition AST.hpp:549
TypeDenoterPtr deriveTypeDenoter(const TypeDenoter *expectedTypeDenoter) override
TypeSpecifier * fetchTypeSpecifier() const override
ExpressionPtr initializer
Definition AST.hpp:550
PackOffsetPtr packOffset
Definition AST.hpp:548
ObjectExpressionPtr namespaceExpression
Definition AST.hpp:544
bool accumulateAlignedVectorSize(UInt32 &size, UInt32 &padding, UInt32 *offset=nullptr)
@ isEntryPointOutput
Definition AST.hpp:533
Vector< ArrayDimensionPtr > arrayDimensions
Definition AST.hpp:545
VarDeclaration * fetchStaticVarDefRef() const
UniformBufferDeclaration * bufferDeclarationRef
Definition AST.hpp:556
VarDeclaration * fetchStaticVarDeclarationRef() const
StructDeclaration * structDeclarationRef
Definition AST.hpp:557
Variant initializerValue
Definition AST.hpp:553
VarDeclaration * staticMemberVarRef
Definition AST.hpp:558
TypeDenoterPtr customTypeDenoter
Definition AST.hpp:552
VarDeclarationStatement * declarationStatementRef
Definition AST.hpp:555
void setCustomTypeDenoter(const TypeDenoterPtr &typeDenoter)
IndexedSemantic semantic
Definition AST.hpp:547
bool hasAnyTypeModifierOf(const InitializerList< TypeModifier > &modifiers) const
void forEachVarDeclaration(const VarDeclarationIteratorFunctor &iterator)
void collectDeclarationIdents(Map< const AST *, String > &declarationASTIdents) const override
VarDeclaration * fetchVarDeclaration(const String &ident) const
StructDeclaration * fetchStructDeclarationRef() const
String toString(bool useVarNames=true) const
bool accumulateAlignedVectorSize(UInt32 &size, UInt32 &padding, UInt32 *offset=nullptr)
void setTypeModifier(const TypeModifier modifier)
TypeSpecifierPtr typeSpecifier
Definition AST.hpp:911
Vector< VarDeclarationPtr > varDeclarations
Definition AST.hpp:912
ExpressionPtr condition
Definition AST.hpp:993
StatementPtr bodyStatement
Definition AST.hpp:994