• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024 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,bool etsWerror)24     ETSWarningAnalyzer(const ir::AstNode *node, parser::Program *program, const ETSWarnings warning, bool etsWerror)
25         : program_(program), etsWerror_(etsWerror)
26     {
27         if (node == nullptr) {
28             return;
29         }
30 
31         switch (warning) {
32             case ETSWarnings::SUGGEST_FINAL:
33                 ETSWarningSuggestFinal(node);
34                 break;
35             case ETSWarnings::PROHIBIT_TOP_LEVEL_STATEMENTS:
36                 ETSWarningsProhibitTopLevelStatements(node);
37                 break;
38             case ETSWarnings::BOOST_EQUALITY_STATEMENT:
39                 ETSWarningBoostEqualityStatement(node);
40                 break;
41             case ETSWarnings::REMOVE_ASYNC_FUNCTIONS:
42                 ETSWarningRemoveAsync(node);
43                 break;
44             case ETSWarnings::REMOVE_LAMBDA:
45                 ETSWarningRemoveLambda(node);
46                 break;
47             case ETSWarnings::IMPLICIT_BOXING_UNBOXING:
48                 ETSWarningImplicitBoxingUnboxing(node);
49                 break;
50             default:
51                 break;
52         }
53     }
54 
55 private:
56     void ETSThrowWarning(const std::string &message, const lexer::SourcePosition &position);
57 
58     void AnalyzeClassDefForFinalModifier(const ir::ClassDefinition *classDef);
59     void AnalyzeClassMethodForFinalModifier(const ir::MethodDefinition *methodDef, const ir::ClassDefinition *classDef);
60     void CheckTypeOfBoxing(const ir::AstNode *node);
61     void CheckTypeOfUnboxing(const ir::AstNode *node);
62     void CheckTopLevelExpressions(const ir::Expression *expression);
63     void CheckProhibitedTopLevelStatements(const ir::Statement *statement);
64     std::string GetBoxingUnboxingType(const ir::AstNode *node);
65     void CheckTypeOfBoxingUnboxing(const ir::AstNode *node);
66 
67     void ETSWarningSuggestFinal(const ir::AstNode *node);
68     void ETSWarningsProhibitTopLevelStatements(const ir::AstNode *node);
69     void ETSWarningBoostEqualityStatement(const ir::AstNode *node);
70     void ETSWarningRemoveAsync(const ir::AstNode *node);
71     void ETSWarningRemoveLambda(const ir::AstNode *node);
72     void ETSWarningImplicitBoxingUnboxing(const ir::AstNode *node);
73 
74     parser::Program *program_;
75     bool etsWerror_;
76 };
77 }  // namespace ark::es2panda::checker
78 
79 #endif
80