• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PARSER_H
17 #define OHOS_IDL_PARSER_H
18 
19 #include "ast/ast_interface_type.h"
20 #include "ast/ast_method.h"
21 #include "ast/ast_module.h"
22 #include "ast/ast_type.h"
23 #include "parser/lexer.h"
24 #include "parser/token.h"
25 #include "util/autoptr.h"
26 #include "util/light_refcount_base.h"
27 #include "util/options.h"
28 #include "util/string.h"
29 
30 namespace OHOS {
31 namespace Idl {
32 class Parser {
33 public:
34     explicit Parser(const Options& options);
35 
36     ~Parser() = default;
37 
38     bool Parse(const String& sourceFile);
39 
GetModule()40     AutoPtr<ASTModule> GetModule() const
41     {
42         return module_;
43     }
44 
45 private:
46     class ErrorInfo : public LightRefCountBase {
47     public:
48         String file_;
49         Token token_;
50         int lineNo_;
51         int columnNo_;
52         String message_;
53         AutoPtr<ErrorInfo> next_;
54     };
55 
56     bool ParseFile();
57 
58     bool ParseLicense();
59 
60     bool ParseInterface();
61 
62     bool ParseMethod(ASTInterfaceType* interface);
63 
64     bool ParseParameter(ASTMethod* method);
65 
66     AutoPtr<ASTNamespace> NameSpaceEmpty();
67 
68     AutoPtr<ASTType> ParseType();
69 
70     AutoPtr<ASTType> ParseList();
71 
72     AutoPtr<ASTType> ParseMap();
73 
74     bool ParseSequenceable();
75 
76     bool CheckIntegrity();
77 
78     bool IsValidTypeName(const String& typeName);
79 
IsPrimitiveType(Token token)80     static bool IsPrimitiveType(Token token)
81     {
82         return token >= Token::BOOLEAN && token <= Token::STRING;
83     }
84 
85     void LogError(Token token, const String& message);
86 
87     void ShowError();
88 
89     static const char* TAG;
90 
91     const Options& options_;
92     AutoPtr<ASTModule> module_;
93     AutoPtr<ASTInterfaceType> parsingInterface_;
94     Lexer lexer_;
95     AutoPtr<ErrorInfo> errors_;
96 };
97 } // namespace Idl
98 } // namespace OHOS
99 #endif // OHOS_IDL_PARSER_H
100