• 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_INT_LITERAL_EXPRESSION_H_
16 #define SRC_AST_INT_LITERAL_EXPRESSION_H_
17 
18 #include "src/ast/literal_expression.h"
19 
20 namespace tint {
21 namespace ast {
22 
23 /// An integer literal. This could be either signed or unsigned.
24 class IntLiteralExpression
25     : public Castable<IntLiteralExpression, LiteralExpression> {
26  public:
27   ~IntLiteralExpression() override;
28 
29   /// @returns the literal value as a u32
30   virtual uint32_t ValueAsU32() const = 0;
31 
32   /// @returns the literal value as an i32
ValueAsI32()33   int32_t ValueAsI32() const { return static_cast<int32_t>(ValueAsU32()); }
34 
35  protected:
36   /// Constructor
37   /// @param pid the identifier of the program that owns this node
38   /// @param src the source of this node
39   IntLiteralExpression(ProgramID pid, const Source& src);
40 };  // namespace ast
41 
42 }  // namespace ast
43 }  // namespace tint
44 
45 #endif  // SRC_AST_INT_LITERAL_EXPRESSION_H_
46