• 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 
16 #ifndef ES2PANDA_LSP_GET_ADJUSTED_LOCATION_H
17 #define ES2PANDA_LSP_GET_ADJUSTED_LOCATION_H
18 
19 #include <optional>
20 #include <string>
21 #include <vector>
22 #include "ir/astNode.h"
23 #include "ir/astNodeFlags.h"
24 #include "es2panda.h"
25 #include "public/es2panda_lib.h"
26 
27 namespace ark::es2panda::lsp {
28 
29 // Main location adjustment functions
30 std::optional<ir::AstNode *> GetAdjustedLocation(ir::AstNode *node, bool forRename, ArenaAllocator *allocator);
31 std::optional<ir::AstNode *> GetAdjustedLocationForClass(ir::AstNode *node, ArenaAllocator *allocator);
32 std::optional<ir::AstNode *> GetAdjustedLocationForFunction(ir::AstNode *node, ArenaAllocator *allocator);
33 std::optional<ir::AstNode *> GetAdjustedLocationForDeclaration(ir::AstNode *node, bool forRename,
34                                                                const ArenaVector<ir::AstNode *> &children,
35                                                                ArenaAllocator *allocator);
36 std::optional<ir::AstNode *> GetAdjustedLocationForImportDeclaration(ir::AstNode *node, bool forRename,
37                                                                      const ArenaVector<ir::AstNode *> &children);
38 std::optional<ir::AstNode *> GetAdjustedLocationForExportDeclaration(ir::AstNode *node, bool forRename,
39                                                                      const ArenaVector<ir::AstNode *> &children);
40 std::optional<ir::AstNode *> GetAdjustedLocationForHeritageClause(ir::AstNode *node);
41 ir::AstNode *GetTouchingPropertyName(es2panda_Context *context, size_t pos);
42 // Expression handlers
43 std::optional<ir::AstNode *> HandleBasicExpressions(ir::AstNode *node, ir::AstNode *parent,
44                                                     const ArenaVector<ir::AstNode *> &parentChildren);
45 std::optional<ir::AstNode *> HandleBinaryExpressions(ir::AstNode *node, ir::AstNode *parent,
46                                                      const ArenaVector<ir::AstNode *> &parentChildren);
47 std::optional<ir::AstNode *> HandleForStatements(ir::AstNode *node, ir::AstNode *parent,
48                                                  const ArenaVector<ir::AstNode *> &parentChildren);
49 std::optional<ir::AstNode *> HandleNonRenameExpressions(ir::AstNode *node, ir::AstNode *parent,
50                                                         const ArenaVector<ir::AstNode *> &parentChildren,
51                                                         bool forRename);
52 
53 // Node type handlers
54 inline std::optional<ir::AstNode *> HandleTSAsExpression(ir::AstNode *node, ir::AstNode *parent,
55                                                          const ArenaVector<ir::AstNode *> &parentChildren);
56 inline std::optional<ir::AstNode *> HandleImportDeclaration(ir::AstNode *node, ir::AstNode *parent,
57                                                             const ArenaVector<ir::AstNode *> &parentChildren,
58                                                             bool forRename);
59 inline std::optional<ir::AstNode *> HandleTSImportType(ir::AstNode *node, ir::AstNode *parent,
60                                                        const ArenaVector<ir::AstNode *> &parentChildren, bool forRename,
61                                                        ArenaAllocator *allocator);
62 
63 // Node finding functions
64 ir::AstNode *FindFirstIdentifier(ir::AstNode *node, bool skipModifiers, const ArenaVector<ir::AstNode *> &children);
65 ir::AstNode *FindFirstExpression(ir::AstNode *node, const ArenaVector<ir::AstNode *> &children);
66 ir::AstNode *FindFirstExpressionAfter(ir::AstNode *node, ir::AstNode *after,
67                                       const ArenaVector<ir::AstNode *> &children);
68 ir::AstNode *FindNodeOfType(ir::AstNode *node, ir::AstNodeType type, const ArenaVector<ir::AstNode *> &children);
69 ir::AstNode *FindTypeReference(ir::AstNode *node, const ArenaVector<ir::AstNode *> &children);
70 ir::AstNode *FindTypeParameter(ir::AstNode *node, const ArenaVector<ir::AstNode *> &children);
71 ir::AstNode *FindArrayType(ir::AstNode *node, const ArenaVector<ir::AstNode *> &children);
72 
73 // Node property checkers
74 bool IsModifier(const ir::AstNode *node);
75 bool CanHaveModifiers(const ir::AstNode &node);
76 bool IsOuterExpression(const ir::AstNode *node);
77 bool IsDeclarationOrModifier(ir::AstNode *node, ir::AstNode *parent, bool forRename);
78 
79 // Node manipulation functions
80 ir::AstNode *SkipOuterExpressions(ir::AstNode *node);
81 
82 // Child node functions
83 ArenaVector<ir::AstNode *> GetChildren(ir::AstNode *node, ArenaAllocator *allocator);
84 
85 }  // namespace ark::es2panda::lsp
86 
87 #endif  // ES2PANDA_LSP_GET_ADJUSTED_LOCATION_H
88