1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef OHOS_HDI_AST_EXPRE_H 10 #define OHOS_HDI_AST_EXPRE_H 11 12 #include "ast/ast_node.h" 13 #include "util/autoptr.h" 14 15 namespace OHOS { 16 namespace HDI { 17 class ASTExpr : public ASTNode { 18 public: EmitCode()19 inline std::string EmitCode() 20 { 21 return Dump(""); 22 } 23 24 bool isParenExpr = false; 25 }; 26 27 enum class UnaryOpKind { 28 PLUS, // + 29 MINUS, // - 30 TILDE, // ~ 31 }; 32 33 class ASTUnaryExpr : public ASTExpr { 34 public: 35 std::string Dump(const std::string &prefix) override; 36 std::string UnaryOpToString(UnaryOpKind op) const; 37 38 public: 39 UnaryOpKind op_; 40 AutoPtr<ASTExpr> expr_; 41 }; 42 43 enum class BinaryOpKind { 44 MUL, // * 45 DIV, // / 46 MOD, // % 47 ADD, // + 48 SUB, // - 49 LSHIFT, // << 50 RSHIFT, // >> 51 AND, // & 52 XOR, // ^ 53 OR, // | 54 }; 55 56 class ASTBinaryExpr : public ASTExpr { 57 public: 58 std::string Dump(const std::string &prefix) override; 59 std::string BinaryOpToString(BinaryOpKind op) const; 60 61 public: 62 BinaryOpKind op_; 63 AutoPtr<ASTExpr> lExpr_; 64 AutoPtr<ASTExpr> rExpr_; 65 }; 66 67 class ASTNumExpr : public ASTExpr { 68 public: 69 std::string Dump(const std::string &prefix) override; 70 std::string value_; 71 }; 72 } // namespace HDI 73 } // namespace OHOS 74 75 #endif // OHOS_HDI_AST_EXPRE_H