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_NODE_H_ 16 #define SRC_AST_NODE_H_ 17 18 #include <string> 19 20 #include "src/clone_context.h" 21 22 namespace tint { 23 24 // Forward declarations 25 class CloneContext; 26 namespace sem { 27 class Type; 28 } 29 namespace sem { 30 class Info; 31 } 32 33 namespace ast { 34 35 /// AST base class node 36 class Node : public Castable<Node, Cloneable> { 37 public: 38 ~Node() override; 39 40 /// The identifier of the program that owns this node 41 const ProgramID program_id; 42 43 /// The node source data 44 const Source source; 45 46 protected: 47 /// Create a new node 48 /// @param pid the identifier of the program that owns this node 49 /// @param src the input source for the node 50 Node(ProgramID pid, const Source& src); 51 /// Move constructor 52 Node(Node&&); 53 54 private: 55 Node(const Node&) = delete; 56 }; 57 58 } // namespace ast 59 60 /// @param node a pointer to an AST node 61 /// @returns the ProgramID of the given AST node. ProgramIDOf(const ast::Node * node)62inline ProgramID ProgramIDOf(const ast::Node* node) { 63 return node ? node->program_id : ProgramID(); 64 } 65 66 } // namespace tint 67 68 #endif // SRC_AST_NODE_H_ 69