• 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_EXPRESSION_H_
16 #define SRC_SEM_EXPRESSION_H_
17 
18 #include "src/ast/expression.h"
19 #include "src/sem/behavior.h"
20 #include "src/sem/constant.h"
21 #include "src/sem/node.h"
22 
23 namespace tint {
24 namespace sem {
25 // Forward declarations
26 class Statement;
27 class Type;
28 
29 /// Expression holds the semantic information for expression nodes.
30 class Expression : public Castable<Expression, Node> {
31  public:
32   /// Constructor
33   /// @param declaration the AST node
34   /// @param type the resolved type of the expression
35   /// @param statement the statement that owns this expression
36   /// @param constant the constant value of the expression. May be invalid
37   Expression(const ast::Expression* declaration,
38              const sem::Type* type,
39              const Statement* statement,
40              Constant constant);
41 
42   /// Destructor
43   ~Expression() override;
44 
45   /// @returns the AST node
Declaration()46   const ast::Expression* Declaration() const { return declaration_; }
47 
48   /// @return the resolved type of the expression
Type()49   const sem::Type* Type() const { return type_; }
50 
51   /// @return the statement that owns this expression
Stmt()52   const Statement* Stmt() const { return statement_; }
53 
54   /// @return the constant value of this expression
ConstantValue()55   const Constant& ConstantValue() const { return constant_; }
56 
57   /// @return the behaviors of this statement
Behaviors()58   const sem::Behaviors& Behaviors() const { return behaviors_; }
59 
60   /// @return the behaviors of this statement
Behaviors()61   sem::Behaviors& Behaviors() { return behaviors_; }
62 
63  protected:
64   /// The AST expression node for this semantic expression
65   const ast::Expression* const declaration_;
66 
67  private:
68   const sem::Type* const type_;
69   const Statement* const statement_;
70   const Constant constant_;
71   sem::Behaviors behaviors_{sem::Behavior::kNext};
72 };
73 
74 }  // namespace sem
75 }  // namespace tint
76 
77 #endif  // SRC_SEM_EXPRESSION_H_
78