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_TYPE_CONSTRUCTOR_EXPRESSION_H_ 16 #define SRC_AST_TYPE_CONSTRUCTOR_EXPRESSION_H_ 17 18 #include <memory> 19 #include <utility> 20 21 #include "src/ast/constructor_expression.h" 22 #include "src/ast/type/type.h" 23 24 namespace tint { 25 namespace ast { 26 27 /// A type specific constructor 28 class TypeConstructorExpression : public ConstructorExpression { 29 public: 30 TypeConstructorExpression(); 31 /// Constructor 32 /// @param type the type 33 /// @param values the values 34 explicit TypeConstructorExpression(type::Type* type, ExpressionList values); 35 /// Constructor 36 /// @param source the constructor source 37 /// @param type the type 38 /// @param values the constructor values 39 TypeConstructorExpression(const Source& source, 40 type::Type* type, 41 ExpressionList values); 42 /// Move constructor 43 TypeConstructorExpression(TypeConstructorExpression&&); 44 ~TypeConstructorExpression() override; 45 46 /// @returns true if this is a type constructor 47 bool IsTypeConstructor() const override; 48 49 /// Set the type 50 /// @param type the type set_type(type::Type * type)51 void set_type(type::Type* type) { type_ = type; } 52 /// @returns the type type()53 type::Type* type() const { return type_; } 54 55 /// Set the values 56 /// @param values the values set_values(ExpressionList values)57 void set_values(ExpressionList values) { values_ = std::move(values); } 58 /// @returns the values values()59 const ExpressionList& values() const { return values_; } 60 61 /// @returns true if the node is valid 62 bool IsValid() const override; 63 64 /// Writes a representation of the node to the output stream 65 /// @param out the stream to write to 66 /// @param indent number of spaces to indent the node when writing 67 void to_str(std::ostream& out, size_t indent) const override; 68 69 private: 70 TypeConstructorExpression(const TypeConstructorExpression&) = delete; 71 72 type::Type* type_ = nullptr; 73 ExpressionList values_; 74 }; 75 76 } // namespace ast 77 } // namespace tint 78 79 #endif // SRC_AST_TYPE_CONSTRUCTOR_EXPRESSION_H_ 80