/* * Copyright (c) 2021 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. * See the LICENSE file in the root of this repository for complete details. */ #ifndef OHOS_HDI_PARSER_H #define OHOS_HDI_PARSER_H #include #include #include "ast/ast_module.h" #include "ast/ast_interface_type.h" #include "ast/ast_method.h" #include "ast/ast.h" #include "ast/ast_type.h" #include "parser/lexer.h" #include "parser/token.h" #include "parser/file_detail.h" #include "util/autoptr.h" #include "util/light_refcount_base.h" #include "util/options.h" #include "util/string.h" namespace OHOS { namespace HDI { class Parser { public: Parser(const Options& options, const AutoPtr& module = nullptr); ~Parser() = default; bool Parse(const String& sourceFile); bool Parse(const String& sourceFile, std::shared_ptr& fileDetailPtr); inline AutoPtr GetAst() const { return ast_; } private: class Attribute : public LightRefCountBase { public: bool isOneWay = false; bool isCallback = false; bool isFull = false; bool isLite = false; }; class ErrorInfo : public LightRefCountBase { public: String file_; Token token_; int lineNo_; int columnNo_; String message_; AutoPtr next_; }; bool ParseIdlDetail(std::shared_ptr& fileDetailPtr); bool ParseIdlPackage(std::shared_ptr& fileDetailPtr); bool ParseIdlImport(std::shared_ptr& fileDetailPtr); bool ParseFile(); bool ParseLicense(); bool ParsePackageName(); bool ParserPackageInfo(const String& packageFullName); bool ParseImport(); bool ParseSequenceable(); bool ParseAttribute(); bool ParseInterface(const AutoPtr& attributes = nullptr); bool ParseInterfaceBody(const AutoPtr& interface); bool ParseMethod(const AutoPtr& interface); void SetVersionInterfaceMethod(const AutoPtr& interface); bool ParseAttributeBody(AutoPtr& attributes); bool ParseAttributeParam(AutoPtr& attributes); bool ParseParameterList(AutoPtr& method); bool ParseParameter(const AutoPtr& method); bool ParseParamAttr(const AutoPtr& parameter); AutoPtr ParseType(); AutoPtr ParseUnsignedType(int typeLineNo, int typeColumnNo); AutoPtr ParseList(); AutoPtr ParseMap(); AutoPtr ParseSharedMemQueueMetaType(); AutoPtr ParseArrayType(const AutoPtr& elementType); AutoPtr ParseCustomType(); bool ParseEnumDefine(const AutoPtr& attributes = nullptr); bool ParseEnumBaseType(const AutoPtr& type); bool ParseEnumMember(const AutoPtr& type); bool ParseStructDefine(const AutoPtr& attributes = nullptr); bool ParseStructMember(const AutoPtr& type); bool ParseUnionDefine(const AutoPtr& attributes = nullptr); bool ParseUnionMember(const AutoPtr& type); bool CheckType(int lineNo, int columnNo, const AutoPtr& type); void SetAstFileType(); bool CheckIntegrity(); bool CheckInterfaceAst(); bool CheckCallbackAst(); bool IsValidTypeName(const String& typeName); bool CheckPackageName(const String& filePath, const String& packageName); inline static bool IsPrimitiveType(Token token) { return token >= Token::BOOLEAN && token <= Token::FILEDESCRIPTOR; } bool AddAst(); void LogError(const String& message); void LogError(int lineNo, int columnNo, const String& message); void ShowError(); static const char* TAG; const Options& options_; std::shared_ptr lexer_; AutoPtr errors_; AutoPtr ast_; AutoPtr astModule_; }; } // namespace HDI } // namespace OHOS #endif // OHOS_HDI_PARSER_H