1 // Copyright 2020 The Tint Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef SRC_AST_ARRAY_H_ 16 #define SRC_AST_ARRAY_H_ 17 18 #include <string> 19 20 #include "src/ast/decoration.h" 21 #include "src/ast/type.h" 22 23 namespace tint { 24 namespace ast { 25 26 // Forward declarations. 27 class Expression; 28 29 /// An array type. If size is zero then it is a runtime array. 30 class Array : public Castable<Array, Type> { 31 public: 32 /// Constructor 33 /// @param pid the identifier of the program that owns this node 34 /// @param src the source of this node 35 /// @param subtype the type of the array elements 36 /// @param count the number of elements in the array. nullptr represents a 37 /// runtime-sized array. 38 /// @param decorations the array decorations 39 Array(ProgramID pid, 40 const Source& src, 41 const Type* subtype, 42 const Expression* count, 43 DecorationList decorations); 44 /// Move constructor 45 Array(Array&&); 46 ~Array() override; 47 48 /// @returns true if this is a runtime array. 49 /// i.e. the size is determined at runtime IsRuntimeArray()50 bool IsRuntimeArray() const { return count == nullptr; } 51 52 /// @param symbols the program's symbol table 53 /// @returns the name for this type that closely resembles how it would be 54 /// declared in WGSL. 55 std::string FriendlyName(const SymbolTable& symbols) const override; 56 57 /// Clones this type and all transitive types using the `CloneContext` `ctx`. 58 /// @param ctx the clone context 59 /// @return the newly cloned type 60 const Array* Clone(CloneContext* ctx) const override; 61 62 /// the array element type 63 const Type* const type; 64 65 /// the array size in elements, or nullptr for a runtime array 66 const Expression* const count; 67 68 /// the array decorations 69 const DecorationList decorations; 70 }; 71 72 } // namespace ast 73 } // namespace tint 74 75 #endif // SRC_AST_ARRAY_H_ 76