• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024-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 
16 #ifndef ES2PANDA_COMPILER_CHECKER_ETS_ETS_WARNING_ANALYZER_H
17 #define ES2PANDA_COMPILER_CHECKER_ETS_ETS_WARNING_ANALYZER_H
18 
19 #include "checker/ETSchecker.h"
20 
21 namespace ark::es2panda::checker {
22 class ETSWarningAnalyzer {
23 public:
ETSWarningAnalyzer(const ir::AstNode * node,parser::Program * program,const ETSWarnings warning,util::DiagnosticEngine & diagnosticEngine)24     ETSWarningAnalyzer(const ir::AstNode *node, parser::Program *program, const ETSWarnings warning,
25                        util::DiagnosticEngine &diagnosticEngine)
26         : program_(program), diagnosticEngine_(diagnosticEngine)
27     {
28         if (node == nullptr) {
29             return;
30         }
31 
32         switch (warning) {
33             case ETSWarnings::ETS_SUGGEST_FINAL:
34                 ETSWarningSuggestFinal(node);
35                 break;
36             case ETSWarnings::ETS_PROHIBIT_TOP_LEVEL_STATEMENTS:
37                 ETSWarningsProhibitTopLevelStatements(node);
38                 break;
39             case ETSWarnings::ETS_ANNOTATION_UNUSED_GENERIC_ALIAS_WARN:
40                 ETSWarningAnnotationUnusedGenericAliasWarn(node);
41                 break;
42             case ETSWarnings::ETS_BOOST_EQUALITY_STATEMENT:
43                 ETSWarningBoostEqualityStatement(node);
44                 break;
45             case ETSWarnings::ETS_REMOVE_ASYNC:
46                 ETSWarningRemoveAsync(node);
47                 break;
48             case ETSWarnings::ETS_REMOVE_LAMBDA:
49                 ETSWarningRemoveLambda(node);
50                 break;
51             case ETSWarnings::ETS_IMPLICIT_BOXING_UNBOXING:
52                 ETSWarningImplicitBoxingUnboxing(node);
53                 break;
54             default:
55                 break;
56         }
57     }
58 
59 private:
60     void LogWarning(const diagnostic::DiagnosticKind &diagnostic, const util::DiagnosticMessageParams &diagnosticParams,
61                     const lexer::SourcePosition &position) const;
62     void LogWarning(const diagnostic::DiagnosticKind &diagnostic, const lexer::SourcePosition &position) const;
63 
64     void AnalyzeClassDefForFinalModifier(const ir::ClassDefinition *classDef);
65     void AnalyzeClassMethodForFinalModifier(const ir::MethodDefinition *methodDef, const ir::ClassDefinition *classDef);
66     void CheckTypeOfBoxing(const ir::AstNode *node);
67     void CheckTypeOfUnboxing(const ir::AstNode *node);
68     void CheckTopLevelExpressions(const ir::Expression *expression);
69     void CheckProhibitedTopLevelStatements(const ir::Statement *statement);
70     std::string GetBoxingUnboxingType(const ir::AstNode *node);
71     void CheckTypeOfBoxingUnboxing(const ir::AstNode *node);
72 
73     void ETSWarningAnnotationUnusedGenericAliasWarn(const ir::AstNode *node);
74     void ETSWarningSuggestFinal(const ir::AstNode *node);
75     void ETSWarningsProhibitTopLevelStatements(const ir::AstNode *node);
76     void ETSWarningBoostEqualityStatement(const ir::AstNode *node);
77     void ETSWarningRemoveAsync(const ir::AstNode *node);
78     void ETSWarningRemoveLambda(const ir::AstNode *node);
79     void ETSWarningImplicitBoxingUnboxing(const ir::AstNode *node);
80 
81     parser::Program *program_;
82     util::DiagnosticEngine &diagnosticEngine_;
83 };
84 }  // namespace ark::es2panda::checker
85 
86 #endif
87