• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CALL_EXPRESSION_H_
16 #define SRC_AST_CALL_EXPRESSION_H_
17 
18 #include "src/ast/expression.h"
19 
20 namespace tint {
21 namespace ast {
22 
23 // Forward declarations.
24 class Type;
25 class IdentifierExpression;
26 
27 /// A call expression - represents either a:
28 /// * sem::Function
29 /// * sem::Intrinsic
30 /// * sem::TypeConstructor
31 /// * sem::TypeConversion
32 class CallExpression : public Castable<CallExpression, Expression> {
33  public:
34   /// Constructor
35   /// @param program_id the identifier of the program that owns this node
36   /// @param source the call expression source
37   /// @param name the function or type name
38   /// @param args the arguments
39   CallExpression(ProgramID program_id,
40                  const Source& source,
41                  const IdentifierExpression* name,
42                  ExpressionList args);
43 
44   /// Constructor
45   /// @param program_id the identifier of the program that owns this node
46   /// @param source the call expression source
47   /// @param type the type
48   /// @param args the arguments
49   CallExpression(ProgramID program_id,
50                  const Source& source,
51                  const Type* type,
52                  ExpressionList args);
53 
54   /// Move constructor
55   CallExpression(CallExpression&&);
56   ~CallExpression() override;
57 
58   /// Clones this node and all transitive child nodes using the `CloneContext`
59   /// `ctx`.
60   /// @param ctx the clone context
61   /// @return the newly cloned node
62   const CallExpression* Clone(CloneContext* ctx) const override;
63 
64   /// Target is either an identifier, or a Type.
65   /// One of these must be nullptr and the other a non-nullptr.
66   struct Target {
67     /// name is a function or intrinsic to call, or type name to construct or
68     /// cast-to
69     const IdentifierExpression* name = nullptr;
70     /// type to construct or cast-to
71     const Type* type = nullptr;
72   };
73 
74   /// The target function
75   const Target target;
76 
77   /// The arguments
78   const ExpressionList args;
79 };
80 
81 }  // namespace ast
82 }  // namespace tint
83 
84 #endif  // SRC_AST_CALL_EXPRESSION_H_
85