1/** 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 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 16#ifndef ES2PANDA_IR_EXPRESSION_H 17#define ES2PANDA_IR_EXPRESSION_H 18 19#include <ir/astNode.h> 20 21namespace panda::es2panda::ir { 22 23class Literal; 24class TypeNode; 25 26class Expression : public AstNode { 27public: 28 bool IsGrouped() const 29 { 30 return grouped_; 31 } 32 33 void SetGrouped() 34 { 35 grouped_ = true; 36 } 37 38 const Literal *AsLiteral() const 39 { 40 ASSERT(IsLiteral()); 41 return reinterpret_cast<const Literal *>(this); 42 } 43 44 Literal *AsLiteral() 45 { 46 ASSERT(IsLiteral()); 47 return reinterpret_cast<Literal *>(this); 48 } 49 50 virtual void SetTsTypeAnnotation([[maybe_unused]] Expression *typeAnnotation) 51 { 52 UNREACHABLE(); 53 } 54 55 virtual bool IsLiteral() const 56 { 57 return false; 58 } 59 60 bool IsExpression() const override 61 { 62 return true; 63 } 64 65 TypeNode *AsTypeNode() 66 { 67 return reinterpret_cast<TypeNode *>(this); 68 } 69 70 const TypeNode *AsTypeNode() const 71 { 72 return reinterpret_cast<const TypeNode *>(this); 73 } 74 75protected: 76 explicit Expression(AstNodeType type) : AstNode(type) {} 77 78private: 79 bool grouped_ {false}; 80}; 81 82} // namespace panda::es2panda::ir 83 84#endif /* ES2PANDA_IR_EXPRESSION_H */ 85