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 #include "TypedBinder.h" 17 #include "ir/base/tsSignatureDeclaration.h" 18 #include "ir/base/tsMethodSignature.h" 19 #include "ir/ts/tsFunctionType.h" 20 #include "ir/ts/tsConstructorType.h" 21 #include "ir/ets/etsFunctionType.h" 22 23 namespace ark::es2panda::varbinder { 24 BuildSignatureDeclarationBaseParams(ir::AstNode *typeNode)25void TypedBinder::BuildSignatureDeclarationBaseParams(ir::AstNode *typeNode) 26 { 27 if (typeNode == nullptr) { 28 return; 29 } 30 31 Scope *scope = nullptr; 32 33 switch (typeNode->Type()) { 34 case ir::AstNodeType::ETS_FUNCTION_TYPE: { 35 scope = typeNode->AsETSFunctionType()->Scope(); 36 break; 37 } 38 case ir::AstNodeType::TS_FUNCTION_TYPE: { 39 scope = typeNode->AsTSFunctionType()->Scope(); 40 break; 41 } 42 case ir::AstNodeType::TS_CONSTRUCTOR_TYPE: { 43 scope = typeNode->AsTSConstructorType()->Scope(); 44 break; 45 } 46 case ir::AstNodeType::TS_SIGNATURE_DECLARATION: { 47 scope = typeNode->AsTSSignatureDeclaration()->Scope(); 48 break; 49 } 50 case ir::AstNodeType::TS_METHOD_SIGNATURE: { 51 scope = typeNode->AsTSMethodSignature()->Scope(); 52 break; 53 } 54 default: { 55 ResolveReference(typeNode); 56 return; 57 } 58 } 59 60 ASSERT(scope && scope->IsFunctionParamScope()); 61 62 auto scopeCtx = LexicalScope<FunctionParamScope>::Enter(this, scope->AsFunctionParamScope(), false); 63 ResolveReferences(typeNode); 64 } 65 HandleCustomNodes(ir::AstNode *childNode)66void TypedBinder::HandleCustomNodes(ir::AstNode *childNode) 67 { 68 switch (childNode->Type()) { 69 case ir::AstNodeType::TS_FUNCTION_TYPE: 70 case ir::AstNodeType::TS_CONSTRUCTOR_TYPE: 71 case ir::AstNodeType::TS_METHOD_SIGNATURE: 72 case ir::AstNodeType::TS_SIGNATURE_DECLARATION: { 73 BuildSignatureDeclarationBaseParams(childNode); 74 break; 75 } 76 default: { 77 ResolveReferences(childNode); 78 break; 79 } 80 } 81 } 82 } // namespace ark::es2panda::varbinder 83