1 /* 2 * Copyright (c) 2022 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_ASTMODULE_H 17 #define OHOS_IDL_ASTMODULE_H 18 19 #include <unordered_map> 20 #include <vector> 21 #include "ast/ast_boolean_type.h" 22 #include "ast/ast_byte_type.h" 23 #include "ast/ast_char_type.h" 24 #include "ast/ast_double_type.h" 25 #include "ast/ast_float_type.h" 26 #include "ast/ast_integer_type.h" 27 #include "ast/ast_interface_type.h" 28 #include "ast/ast_long_type.h" 29 #include "ast/ast_namespace.h" 30 #include "ast/ast_node.h" 31 #include "ast/ast_sequenceable_type.h" 32 #include "ast/ast_short_type.h" 33 #include "ast/ast_string_type.h" 34 #include "ast/ast_void_type.h" 35 #include "util/autoptr.h" 36 37 namespace OHOS { 38 namespace Idl { 39 class ASTModule : public ASTNode { 40 public: 41 ASTModule(); 42 43 void SetIdlFile(const String& idlFile); 44 GetName()45 String GetName() 46 { 47 return name_; 48 } 49 SetLicense(const String & license)50 void SetLicense(const String& license) 51 { 52 license_ = license; 53 } 54 GetLicense()55 String GetLicense() 56 { 57 return license_; 58 } 59 60 AutoPtr<ASTNamespace> ParseNamespace(const String& nspaceStr); 61 62 void AddNamespace(ASTNamespace* nspace); 63 64 AutoPtr<ASTNamespace> FindNamespace(const String& nspaceStr); 65 66 AutoPtr<ASTNamespace> GetNamespace(size_t index); 67 GetNamespaceNumber()68 size_t GetNamespaceNumber() 69 { 70 return namespaces_.size(); 71 } 72 73 void AddInterface(ASTInterfaceType* interface); 74 75 AutoPtr<ASTInterfaceType> GetInterface(size_t index); 76 GetInterfaceNumber()77 size_t GetInterfaceNumber() 78 { 79 return interfaces_.size(); 80 } 81 82 int IndexOf(ASTInterfaceType* interface); 83 84 void AddSequenceable(ASTSequenceableType* sequenceable); 85 86 AutoPtr<ASTSequenceableType> GetSequenceable(size_t index); 87 GetSequenceableNumber()88 size_t GetSequenceableNumber() 89 { 90 return sequenceables_.size(); 91 } 92 93 int IndexOf(ASTSequenceableType* sequenceable); 94 95 void AddType(ASTType* type); 96 97 AutoPtr<ASTType> FindType(const String& typeName); 98 99 using TypeStringMap = std::unordered_map<String, AutoPtr<ASTType>, StringHashFunc, StringEqualFunc>; 100 GetTypes()101 const TypeStringMap& GetTypes() 102 { 103 return types_; 104 } 105 GetTypeNumber()106 size_t GetTypeNumber() 107 { 108 return types_.size(); 109 } 110 111 int IndexOf(ASTType* type); 112 113 bool IsValid(); 114 115 String Dump(const String& prefix) override; 116 SetHasCacheableProxyMethods(const bool cacheableProxyMethod)117 void SetHasCacheableProxyMethods(const bool cacheableProxyMethod) 118 { 119 hasCacheableProxyMethods_ = cacheableProxyMethod; 120 } 121 GetHasCacheableProxyMethods()122 bool GetHasCacheableProxyMethods() const 123 { 124 return hasCacheableProxyMethods_; 125 } 126 private: 127 String name_; 128 String license_; 129 std::vector<AutoPtr<ASTNamespace>> namespaces_; 130 std::vector<AutoPtr<ASTInterfaceType>> interfaces_; 131 std::vector<AutoPtr<ASTSequenceableType>> sequenceables_; 132 TypeStringMap types_; 133 134 AutoPtr<ASTBooleanType> booleanType_; 135 AutoPtr<ASTByteType> byteType_; 136 AutoPtr<ASTShortType> shortType_; 137 AutoPtr<ASTIntegerType> integerType_; 138 AutoPtr<ASTLongType> longType_; 139 AutoPtr<ASTFloatType> floatType_; 140 AutoPtr<ASTDoubleType> doubleType_; 141 AutoPtr<ASTCharType> charType_; 142 AutoPtr<ASTStringType> stringType_; 143 AutoPtr<ASTVoidType> voidType_; 144 145 String idlFilePath_; 146 bool hasCacheableProxyMethods_ = false; 147 }; 148 } // namespace Idl 149 } // namespace OHOS 150 #endif // OHOS_IDL_ASTMODULE_H 151