• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 - 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_LOWERING_UTIL_H
17 #define ES2PANDA_COMPILER_LOWERING_UTIL_H
18 
19 #include "varbinder/ETSBinder.h"
20 
21 namespace ark::es2panda::compiler {
22 
23 class PhaseManager;
24 
25 inline constexpr std::string_view const GENSYM_CORE = "gensym%%_";
26 inline constexpr std::string_view const DUMMY_ID = "_";
27 ir::AstNode *RefineSourceRanges(ir::AstNode *node);
28 bool HasGlobalClassParent(const ir::AstNode *node);
29 varbinder::Scope *NearestScope(const ir::AstNode *ast);
30 checker::ETSObjectType const *ContainingClass(const ir::AstNode *ast);
31 ir::Identifier *Gensym(ArenaAllocator *allocator);
32 util::UString GenName(ArenaAllocator *allocator);
33 void ClearTypesVariablesAndScopes(ir::AstNode *node) noexcept;
34 ArenaSet<varbinder::Variable *> FindCaptured(ArenaAllocator *allocator, ir::AstNode *scopeBearer) noexcept;
35 void SetSourceRangesRecursively(ir::AstNode *node, const lexer::SourceRange &range);
36 
37 // Rerun varbinder on the node.
38 varbinder::Scope *Rebind(PhaseManager *phaseManager, varbinder::ETSBinder *varBinder, ir::AstNode *node);
39 // Rerun varbinder and checker on the node.
40 void Recheck(PhaseManager *phaseManager, varbinder::ETSBinder *varBinder, checker::ETSChecker *checker,
41              ir::AstNode *node);
42 
43 // NOTE: used to get the declaration from identifier in Plugin API and LSP
44 ir::AstNode *DeclarationFromIdentifier(const ir::Identifier *node);
45 
46 // Note: run varbinder and checker on the new node generated in lowering phases
47 void CheckLoweredNode(varbinder::ETSBinder *varBinder, checker::ETSChecker *checker, ir::AstNode *node);
48 bool IsAnonymousClassType(const checker::Type *type);
49 bool ClassDefinitionIsEnumTransformed(const ir::AstNode *node);
50 }  // namespace ark::es2panda::compiler
51 
52 #endif  // ES2PANDA_COMPILER_LOWERING_UTIL_H
53