/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_IDL_ASTMODULE_H #define OHOS_IDL_ASTMODULE_H #include #include #include "ast/ast_boolean_type.h" #include "ast/ast_byte_type.h" #include "ast/ast_char_type.h" #include "ast/ast_double_type.h" #include "ast/ast_float_type.h" #include "ast/ast_integer_type.h" #include "ast/ast_interface_type.h" #include "ast/ast_long_type.h" #include "ast/ast_namespace.h" #include "ast/ast_node.h" #include "ast/ast_sequenceable_type.h" #include "ast/ast_short_type.h" #include "ast/ast_string_type.h" #include "ast/ast_void_type.h" #include "util/autoptr.h" namespace OHOS { namespace Idl { class ASTModule : public ASTNode { public: ASTModule(); void SetIdlFile(const String& idlFile); String GetName() { return name_; } void SetLicense(const String& license) { license_ = license; } String GetLicense() { return license_; } AutoPtr ParseNamespace(const String& nspaceStr); void AddNamespace(ASTNamespace* nspace); AutoPtr FindNamespace(const String& nspaceStr); AutoPtr GetNamespace(size_t index); size_t GetNamespaceNumber() { return namespaces_.size(); } void AddInterface(ASTInterfaceType* interface); AutoPtr GetInterface(size_t index); size_t GetInterfaceNumber() { return interfaces_.size(); } int IndexOf(ASTInterfaceType* interface); void AddSequenceable(ASTSequenceableType* sequenceable); AutoPtr GetSequenceable(size_t index); size_t GetSequenceableNumber() { return sequenceables_.size(); } int IndexOf(ASTSequenceableType* sequenceable); void AddType(ASTType* type); AutoPtr FindType(const String& typeName); using TypeStringMap = std::unordered_map, StringHashFunc, StringEqualFunc>; const TypeStringMap& GetTypes() { return types_; } size_t GetTypeNumber() { return types_.size(); } int IndexOf(ASTType* type); bool IsValid(); String Dump(const String& prefix) override; void SetHasCacheableProxyMethods(const bool cacheableProxyMethod) { hasCacheableProxyMethods_ = cacheableProxyMethod; } bool GetHasCacheableProxyMethods() const { return hasCacheableProxyMethods_; } private: String name_; String license_; std::vector> namespaces_; std::vector> interfaces_; std::vector> sequenceables_; TypeStringMap types_; AutoPtr booleanType_; AutoPtr byteType_; AutoPtr shortType_; AutoPtr integerType_; AutoPtr longType_; AutoPtr floatType_; AutoPtr doubleType_; AutoPtr charType_; AutoPtr stringType_; AutoPtr voidType_; String idlFilePath_; bool hasCacheableProxyMethods_ = false; }; } // namespace Idl } // namespace OHOS #endif // OHOS_IDL_ASTMODULE_H