• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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_SEM_TYPE_MAPPINGS_H_
16 #define SRC_SEM_TYPE_MAPPINGS_H_
17 
18 #include <type_traits>
19 
20 namespace tint {
21 
22 // Forward declarations
23 namespace ast {
24 class CallExpression;
25 class Expression;
26 class Function;
27 class MemberAccessorExpression;
28 class Node;
29 class Statement;
30 class Struct;
31 class StructMember;
32 class Type;
33 class TypeDecl;
34 class Variable;
35 }  // namespace ast
36 
37 namespace sem {
38 // Forward declarations
39 class Array;
40 class Call;
41 class Expression;
42 class Function;
43 class MemberAccessorExpression;
44 class Node;
45 class Statement;
46 class Struct;
47 class StructMember;
48 class Type;
49 class Variable;
50 
51 /// TypeMappings is a struct that holds undefined `operator()` methods that's
52 /// used by SemanticNodeTypeFor to map AST / type node types to their
53 /// corresponding semantic node types. The standard operator overload resolving
54 /// rules will be used to infer the return type based on the argument type.
55 struct TypeMappings {
56   //! @cond Doxygen_Suppress
57   Call* operator()(ast::CallExpression*);
58   Expression* operator()(ast::Expression*);
59   Function* operator()(ast::Function*);
60   MemberAccessorExpression* operator()(ast::MemberAccessorExpression*);
61   Node* operator()(ast::Node*);
62   Statement* operator()(ast::Statement*);
63   Struct* operator()(ast::Struct*);
64   StructMember* operator()(ast::StructMember*);
65   Type* operator()(ast::Type*);
66   Type* operator()(ast::TypeDecl*);
67   Variable* operator()(ast::Variable*);
68   //! @endcond
69 };
70 
71 /// SemanticNodeTypeFor resolves to the appropriate sem::Node type for the
72 /// AST or type node `AST_OR_TYPE`.
73 template <typename AST_OR_TYPE>
74 using SemanticNodeTypeFor = typename std::remove_pointer<decltype(
75     TypeMappings()(std::declval<AST_OR_TYPE*>()))>::type;
76 
77 }  // namespace sem
78 }  // namespace tint
79 
80 #endif  // SRC_SEM_TYPE_MAPPINGS_H_
81