• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_CHECKER_ETSANALYZER_H
17 #define ES2PANDA_CHECKER_ETSANALYZER_H
18 
19 #include "checker/SemanticAnalyzer.h"
20 
21 namespace panda::es2panda::checker {
22 
23 class ETSAnalyzer final : public SemanticAnalyzer {
24 public:
ETSAnalyzer(Checker * checker)25     explicit ETSAnalyzer(Checker *checker) : SemanticAnalyzer(checker) {};
26 
27 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
28 #define DECLARE_ETSANALYZER_CHECK_METHOD(_, nodeType) checker::Type *Check(ir::nodeType *node) const override;
29     AST_NODE_MAPPING(DECLARE_ETSANALYZER_CHECK_METHOD)
30 #undef DECLARE_ETSANALYZER_CHECK_METHOD
31 
32 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
33 #define DECLARE_ETSANALYZER_CHECK_METHOD(_, __, nodeType, ___) \
34     virtual checker::Type *Check(ir::nodeType *node) const override;
35     AST_NODE_REINTERPRET_MAPPING(DECLARE_ETSANALYZER_CHECK_METHOD)
36 #undef DECLARE_ETSANALYZER_CHECK_METHOD
37     checker::Type *PreferredType(ir::ObjectExpression *expr) const;
38     checker::Type *GetPreferredType(ir::ArrayExpression *expr) const;
39 
40 private:
41     ETSChecker *GetETSChecker() const;
42     void CheckMethodModifiers(ir::MethodDefinition *node) const;
43     checker::Signature *ResolveSignature(ETSChecker *checker, ir::CallExpression *expr, checker::Type *calleeType,
44                                          bool isFunctionalInterface, bool isUnionTypeWithFunctionalInterface) const;
45     checker::Type *GetReturnType(ir::CallExpression *expr, checker::Type *calleeType) const;
46     checker::Type *GetFunctionReturnType(ir::ReturnStatement *st, ir::ScriptFunction *containingFunc) const;
47 };
48 
49 }  // namespace panda::es2panda::checker
50 
51 #endif  // ES2PANDA_CHECKER_ETSANALYZER_H
52