• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef ES2PANDA_CHECKER_ISOLATED_DECLGEN_CHECKER_H
16 #define ES2PANDA_CHECKER_ISOLATED_DECLGEN_CHECKER_H
17 
18 #include <string>
19 #include "macros.h"
20 #include "checker/checker.h"
21 
22 namespace ark::es2panda::checker {
23 class IsolatedDeclgenChecker {
24 public:
IsolatedDeclgenChecker(util::DiagnosticEngine & diagnosticEngine,parser::Program & program)25     explicit IsolatedDeclgenChecker(util::DiagnosticEngine &diagnosticEngine, parser::Program &program)
26         : diagnosticEngine_(diagnosticEngine), program_(program)
27     {
28     }
29     ~IsolatedDeclgenChecker() = default;
30 
31     NO_COPY_SEMANTIC(IsolatedDeclgenChecker);
32     NO_MOVE_SEMANTIC(IsolatedDeclgenChecker);
33 
34     void CheckBeforeChecker();
35     void CheckAfterChecker();
36 
37     void Check(ir::ClassProperty *ast);
38     void Check(ir::ObjectExpression *ast);
39     void Check(ir::ArrayExpression *ast);
40     void Check(ir::ETSParameterExpression *ast);
41     void Check(ir::ExportDefaultDeclaration *ast);
42 
43     std::string Check(ir::ScriptFunction *ast);
44 
45 private:
46     std::string InferReturnTypeForArgument(ir::ReturnStatement *returnStatement);
47 
48     std::string ProcessLiteralArgument(ir::Literal *literal, ir::ReturnStatement *returnStatement);
49     std::string ProcessIdentifierArgument(ir::Identifier *identifier, ir::ReturnStatement *returnStatement);
50     std::string ProcessConstArrayArgument(ir::ArrayExpression *array, ir::ReturnStatement *returnStatement);
51     std::string ProcessNewClassInstanceExpressionArgument(ir::ETSNewClassInstanceExpression *newClassInstanceExpression,
52                                                           ir::ReturnStatement *returnStatement);
53 
54     void LogError(const diagnostic::DiagnosticKind &diagnostic, const util::DiagnosticMessageParams &diagnosticParams,
55                   const lexer::SourcePosition &pos);
56 
57 private:
58     util::DiagnosticEngine &diagnosticEngine_;
59     parser::Program &program_;
60 };
61 }  // namespace ark::es2panda::checker
62 
63 #endif  // ES2PANDA_CHECKER_ISOLATED_DECLGEN_CHECKER_H