1 /* 2 * Copyright (c) 2024 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 OHOS_IDL_AST_EXPRE_H 17 #define OHOS_IDL_AST_EXPRE_H 18 19 #include "ast/ast_node.h" 20 #include "util/autoptr.h" 21 22 namespace OHOS { 23 namespace Idl { 24 class ASTExpr : public ASTNode { 25 public: EmitCode()26 inline std::string EmitCode() 27 { 28 return Dump(""); 29 } 30 31 bool isParenExpr = false; 32 }; 33 34 enum class UnaryOpKind { 35 PLUS, // + 36 MINUS, // - 37 TILDE, // ~ 38 }; 39 40 class ASTUnaryExpr : public ASTExpr { 41 public: 42 std::string Dump(const std::string &prefix) override; 43 std::string UnaryOpToString(UnaryOpKind op) const; 44 45 public: 46 UnaryOpKind op_; 47 AutoPtr<ASTExpr> expr_; 48 }; 49 50 enum class BinaryOpKind { 51 MUL, // * 52 DIV, // / 53 MOD, // % 54 ADD, // + 55 SUB, // - 56 LSHIFT, // << 57 RSHIFT, // >> 58 AND, // & 59 XOR, // ^ 60 OR, // | 61 }; 62 63 class ASTBinaryExpr : public ASTExpr { 64 public: 65 std::string Dump(const std::string &prefix) override; 66 std::string BinaryOpToString(BinaryOpKind op) const; 67 68 public: 69 BinaryOpKind op_; 70 AutoPtr<ASTExpr> lExpr_; 71 AutoPtr<ASTExpr> rExpr_; 72 }; 73 74 class ASTNumExpr : public ASTExpr { 75 public: 76 std::string Dump(const std::string &prefix) override; 77 std::string value_; 78 }; 79 80 /** 81 * @brief Defines the enumeration object structure in expression. 82 * 83 * This structure includes the enumeration information when using enum nesting identify in idl. 84 * 85 * @since 5.0 86 */ 87 class ASTEnumExpr : public ASTExpr { 88 public: 89 std::string Dump(const std::string &prefix) override; 90 std::string value_; 91 }; 92 } // namespace Idl 93 } // namespace OHOS 94 95 #endif // OHOS_IDL_AST_EXPRE_H