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 117 private: 118 String name_; 119 String license_; 120 std::vector<AutoPtr<ASTNamespace>> namespaces_; 121 std::vector<AutoPtr<ASTInterfaceType>> interfaces_; 122 std::vector<AutoPtr<ASTSequenceableType>> sequenceables_; 123 TypeStringMap types_; 124 125 AutoPtr<ASTBooleanType> booleanType_; 126 AutoPtr<ASTByteType> byteType_; 127 AutoPtr<ASTShortType> shortType_; 128 AutoPtr<ASTIntegerType> integerType_; 129 AutoPtr<ASTLongType> longType_; 130 AutoPtr<ASTFloatType> floatType_; 131 AutoPtr<ASTDoubleType> doubleType_; 132 AutoPtr<ASTCharType> charType_; 133 AutoPtr<ASTStringType> stringType_; 134 AutoPtr<ASTVoidType> voidType_; 135 136 String idlFilePath_; 137 }; 138 } // namespace Idl 139 } // namespace OHOS 140 #endif // OHOS_IDL_ASTMODULE_H 141