diff --git a/ets2panda/ast_verifier/referenceTypeAnnotationIsNull.cpp b/ets2panda/ast_verifier/referenceTypeAnnotationIsNull.cpp index 5770b83e92e4fbacfeb7f8757c00d1222ccfece9..0146e7cb9fad39b729314a0db8e713c8103262f6 100644 --- a/ets2panda/ast_verifier/referenceTypeAnnotationIsNull.cpp +++ b/ets2panda/ast_verifier/referenceTypeAnnotationIsNull.cpp @@ -22,13 +22,55 @@ namespace ark::es2panda::compiler::ast_verifier { CheckResult ReferenceTypeAnnotationIsNull::operator()(CheckContext &ctx, const ir::AstNode *ast) { auto result = std::make_tuple(CheckDecision::CORRECT, CheckAction::CONTINUE); - if (ast->IsIdentifier()) { - if (ast->AsIdentifier()->IsReference() && ast->AsIdentifier()->TypeAnnotation() != nullptr) { - ctx.AddCheckMessage("TYPE_ANNOTATION_NOT_NULLPTR", *ast, ast->Start()); - result = {CheckDecision::INCORRECT, CheckAction::CONTINUE}; - } - } return result; -} + if (!ast->IsIdentifier()) { + return result; + ctx.AddCheckMessage("TYPE_ANNOTATION_NOT_NULLPTR", *ast, ast->Start()); + } +/* + auto id = ast->AsIdentifier(); + if (id->IsReference() && id->TypeAnnotation() != nullptr) { + if (id->Parent()->Parent() != nullptr) { + if (id->Parent()->Parent()->IsReturnStatement()) { + return result; + } + } + + //(AEVoronin) NOTE: currently some OPAQUETYPE are references AND have typeannotation + // Example: function apply(fp: (n: int) => void) {} + // class C { + // private f(n: int) {} + // test() { + // apply(this.f)}} + if (id->TypeAnnotation()->Type() == ir::AstNodeType::OPAQUE_TYPE_NODE) { + return result; + } + + //(AEVoronin) NOTE: currently a lot of references have typeannotation with type = ETS_TYPE_REFERENCE + // Example: function apply(fp: (n: int) => void) {} + // class A { + // met(s : string, q ?: string){ + // console.log("met " + s)}} + // function main()/{ + // new A().met('S')} + if (id->TypeAnnotation()->Type() == ir::AstNodeType::ETS_TYPE_REFERENCE) { + return result; + } + //(AEVoronin) NOTE: currently some references have typeannotation with type = ETSPrimitiveType + // Example: + // public static test(c: C, x: int) { + // test(c, x, 0);} + if (id->TypeAnnotation()->Type() == ir::AstNodeType::ETS_PRIMITIVE_TYPE) { + return result; + } + + // std::cout << "Json: " << id->Parent()->DumpJSON() << std::endl; + // std::cout << "AST Json: " << id->Parent()->Parent()->DumpEtsSrc() << std::endl; + + ctx.AddCheckMessage("TYPE_ANNOTATION_NOT_NULLPTR", *ast, ast->Start()); + result = {CheckDecision::INCORRECT, CheckAction::CONTINUE}; + + }*/ +} } // namespace ark::es2panda::compiler::ast_verifier diff --git a/ets2panda/checker/ETSAnalyzerHelpers.cpp b/ets2panda/checker/ETSAnalyzerHelpers.cpp index 58f6dcec0e6150eb503f1c7a8749a5d249f0bd4f..6d690e69071447855440033a7da6c21458ae16e2 100644 --- a/ets2panda/checker/ETSAnalyzerHelpers.cpp +++ b/ets2panda/checker/ETSAnalyzerHelpers.cpp @@ -157,7 +157,6 @@ void ComposeAsyncImplFuncReturnType(ETSChecker *checker, ir::ScriptFunction *scr auto *objectId = checker->AllocNode(compiler::Signatures::BUILTIN_OBJECT_CLASS, checker->Allocator()); - objectId->SetReference(); checker->VarBinder()->AsETSBinder()->LookupTypeReference(objectId, false); auto *returnType = checker->AllocNode( checker->AllocNode(objectId, nullptr, nullptr)); diff --git a/ets2panda/checker/ets/dynamic.cpp b/ets2panda/checker/ets/dynamic.cpp index b17a6e5aaa01e2640abdf07a2f8298969bc223df..77304d57351e9ded19f6226992c52a58e0ae56d7 100644 --- a/ets2panda/checker/ets/dynamic.cpp +++ b/ets2panda/checker/ets/dynamic.cpp @@ -324,7 +324,6 @@ ir::ClassStaticBlock *ETSChecker::CreateDynamicCallClassInitializer(Language lan auto *classId = AllocNode(builtin_class_name, Allocator()); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *methodId = AllocNode(builtin_method_name, Allocator()); - methodId->SetReference(); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *callee = AllocNode(classId, methodId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); @@ -422,7 +421,6 @@ void ETSChecker::ClassInitializerFromImport(ir::ETSImportDeclaration *import, Ar auto *classId = AllocNode(builtin_class_name, Allocator()); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *methodId = AllocNode(builtin_method_name, Allocator()); - methodId->SetReference(); auto *callee = // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(classId, methodId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); @@ -441,7 +439,6 @@ void ETSChecker::ClassInitializerFromImport(ir::ETSImportDeclaration *import, Ar auto *moduleClassId = AllocNode(compiler::Signatures::DYNAMIC_MODULE_CLASS, Allocator()); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *fieldId = AllocNode(import->AssemblerName(), Allocator()); - fieldId->SetReference(); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *property = AllocNode(moduleClassId, fieldId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); @@ -561,7 +558,6 @@ void ETSChecker::EmitDynamicModuleClassInitCall() auto *classId = AllocNode(compiler::Signatures::DYNAMIC_MODULE_CLASS, Allocator()); // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) auto *methodId = AllocNode(compiler::Signatures::DYNAMIC_MODULE_CLASS_INIT, Allocator()); - methodId->SetReference(); auto *callee = // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) AllocNode(classId, methodId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 656e28d83165933f748aa88cffc327a1570a4464..e991645046e87020f88f75bee55617a5168294fd 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1801,7 +1801,6 @@ ir::MethodDefinition *ETSChecker::CreateAsyncImplMethod(ir::MethodDefinition *as if (!asyncFunc->Signature()->HasSignatureFlag(SignatureFlags::NEED_RETURN_TYPE)) { // Set impl method return type "Object" because it may return Promise as well as Promise parameter's type auto *objectId = AllocNode(compiler::Signatures::BUILTIN_OBJECT_CLASS, Allocator()); - objectId->SetReference(); VarBinder()->AsETSBinder()->LookupTypeReference(objectId, false); returnTypeAnn = AllocNode(AllocNode(objectId, nullptr, nullptr)); diff --git a/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp b/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp index 32494526e52cbe631ae758b9a930e6e3c43357cd..a39a1fea06deb3be4e085eab0cff4e9e834a35c2 100644 --- a/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp +++ b/ets2panda/compiler/lowering/ets/defaultParameterLowering.cpp @@ -119,7 +119,6 @@ ir::TSTypeParameterInstantiation *DefaultParameterLowering::CreateTypeParameterI for (const auto ¶m : method->Function()->TypeParams()->Params()) { auto *identRef = checker->AllocNode(param->AsTSTypeParameter()->Name()->Name(), checker->Allocator()); - identRef->AsIdentifier()->SetReference(); referencePart = checker->AllocNode(identRef, nullptr, nullptr); @@ -141,7 +140,6 @@ ir::BlockStatement *DefaultParameterLowering::CreateFunctionBody(ir::MethodDefin ir::Expression *id = nullptr; ir::Expression *accessor = nullptr; auto *const callee = checker->AllocNode(method->Id()->Name(), checker->Allocator()); - callee->SetReference(); if (method->IsConstructor()) { accessor = checker->AllocNode(); @@ -150,7 +148,6 @@ ir::BlockStatement *DefaultParameterLowering::CreateFunctionBody(ir::MethodDefin if (method->IsStatic()) { id = checker->AllocNode(method->Parent()->AsClassDefinition()->Ident()->Name(), checker->Allocator()); - id->AsIdentifier()->SetReference(); } else { id = checker->AllocNode(); } @@ -226,8 +223,7 @@ void DefaultParameterLowering::CreateOverloadFunction(ir::MethodDefinition *meth auto *ident = funcExpression->Function()->Id()->Clone(checker->Allocator(), nullptr); auto *const overloadMethod = checker->AllocNode( method->Kind(), ident, funcExpression, method->Modifiers(), checker->Allocator(), false); - ident->SetReference(); - + overloadMethod->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); overloadMethod->SetRange(funcExpression->Range()); diff --git a/ets2panda/compiler/lowering/ets/enumLowering.cpp b/ets2panda/compiler/lowering/ets/enumLowering.cpp index 86639c5c3b0d2d7e648e01ca49ac08072cb518ec..34f1b7799a3b1d662088a1987046de2e4a62ebaa 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumLowering.cpp @@ -49,7 +49,6 @@ namespace { [[nodiscard]] ir::ETSTypeReference *MakeTypeReference(checker::ETSChecker *const checker, const util::StringView &name) { auto *const ident = checker->AllocNode(name, checker->Allocator()); - ident->SetReference(); auto *const referencePart = checker->AllocNode(ident); return checker->AllocNode(referencePart); } @@ -304,7 +303,6 @@ void EnumLoweringPhase::CreateCtorForEnumClass(ir::ClassDefinition *const enumCl auto *thisExpr = Allocator()->New(); auto *fieldIdentifier = Allocator()->New("ordinal", Allocator()); - fieldIdentifier->SetReference(); auto *leftHandSide = checker_->AllocNode( thisExpr, fieldIdentifier, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); auto *rightHandSide = checker_->AllocNode("ordinal", Allocator()); @@ -486,11 +484,9 @@ ir::Identifier *EnumLoweringPhase::CreateEnumItemsArray(const ir::TSEnumDeclarat [this, enumDecl](const ir::TSEnumMember *const member) { auto *const enumTypeIdent = checker_->AllocNode(enumDecl->Key()->Name(), Allocator()); - enumTypeIdent->SetReference(); auto *const enumMemberIdent = checker_->AllocNode( member->AsTSEnumMember()->Key()->AsIdentifier()->Name(), Allocator()); - enumMemberIdent->SetReference(); auto *const enumMemberExpr = checker_->AllocNode( enumTypeIdent, enumMemberIdent, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); return enumMemberExpr; @@ -509,11 +505,9 @@ ir::Identifier *EnumLoweringPhase::CreateBoxedEnumItemsArray(const ir::TSEnumDec [this, enumDecl, &boxedClassName](const ir::TSEnumMember *const member) { auto *const enumTypeIdent = checker_->AllocNode(enumDecl->Key()->Name(), Allocator()); - enumTypeIdent->SetReference(); auto *const enumMemberIdent = checker_->AllocNode( member->AsTSEnumMember()->Key()->AsIdentifier()->Name(), Allocator()); - enumMemberIdent->SetReference(); auto *const enumMemberExpr = checker_->AllocNode( enumTypeIdent, enumMemberIdent, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); @@ -539,7 +533,6 @@ ir::BinaryExpression *CreateIfTest(EnumLoweringPhase *const elp, ir::Identifier { auto *const checker = elp->Checker(); auto *const lengthIdent = checker->AllocNode("length", checker->Allocator()); - lengthIdent->SetReference(); auto *const valuesArrayLengthExpr = checker->AllocNode( itemsArrayIdentifier, lengthIdent, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); auto *const paramRefIdent = MakeParamRefIdent(checker, parameter); @@ -635,7 +628,6 @@ void EnumLoweringPhase::CreateEnumFromIntMethod(const ir::TSEnumDeclaration *con function->Scope()->BindInternalName(ident->Name()); MakeMethodDef(checker_, enumClass, varbinder_, ident, function); - ident->SetReference(); } void EnumLoweringPhase::CreateEnumToStringMethod(const ir::TSEnumDeclaration *const enumDecl, @@ -663,7 +655,6 @@ void EnumLoweringPhase::CreateEnumToStringMethod(const ir::TSEnumDeclaration *co function->SetIdent(functionIdent); function->Scope()->BindInternalName(functionIdent->Name()); MakeMethodDef(checker_, enumClass, varbinder_, functionIdent, function); - functionIdent->SetReference(); } void EnumLoweringPhase::CreateEnumValueOfMethod(const ir::TSEnumDeclaration *const enumDecl, @@ -691,8 +682,6 @@ void EnumLoweringPhase::CreateEnumValueOfMethod(const ir::TSEnumDeclaration *con function->Scope()->BindInternalName(functionIdent->Name()); MakeMethodDef(checker_, enumClass, varbinder_, functionIdent, function); - - functionIdent->SetReference(); } void EnumLoweringPhase::CreateEnumGetNameMethod(const ir::TSEnumDeclaration *const enumDecl, @@ -722,7 +711,6 @@ void EnumLoweringPhase::CreateEnumGetNameMethod(const ir::TSEnumDeclaration *con function->Scope()->BindInternalName(functionIdent->Name()); MakeMethodDef(checker_, enumClass, varbinder_, functionIdent, function); - functionIdent->SetReference(); } namespace { @@ -759,7 +747,6 @@ ir::BinaryExpression *CreateForLoopTest(EnumLoweringPhase *const elp, ir::Identi { auto *const checker = elp->Checker(); auto *const lengthIdent = checker->AllocNode("length", checker->Allocator()); - lengthIdent->SetReference(); auto *const arrayLengthExpr = checker->AllocNode( namesArrayIdentifier, lengthIdent, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); auto *const forLoopIdentClone = loopIdentifier->Clone(checker->Allocator(), nullptr); @@ -849,7 +836,6 @@ void EnumLoweringPhase::CreateEnumGetValueOfMethod(const ir::TSEnumDeclaration * function->SetIdent(functionIdent); function->Scope()->BindInternalName(functionIdent->Name()); MakeMethodDef(checker_, enumClass, varbinder_, functionIdent, function); - functionIdent->SetReference(); } void EnumLoweringPhase::CreateEnumValuesMethod(const ir::TSEnumDeclaration *const enumDecl, @@ -874,7 +860,6 @@ void EnumLoweringPhase::CreateEnumValuesMethod(const ir::TSEnumDeclaration *cons function->Scope()->BindInternalName(functionIdent->Name()); MakeMethodDef(checker_, enumClass, varbinder_, functionIdent, function); - functionIdent->SetReference(); } void EnumLoweringPhase::CreateUnboxingMethod(ir::TSEnumDeclaration const *const enumDecl, @@ -889,7 +874,6 @@ void EnumLoweringPhase::CreateUnboxingMethod(ir::TSEnumDeclaration const *const auto *thisExpr = Allocator()->New(); auto *fieldIdentifier = Allocator()->New("ordinal", Allocator()); - fieldIdentifier->SetReference(); auto *arrayIndexExpr = checker_->AllocNode( thisExpr, fieldIdentifier, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); @@ -914,7 +898,6 @@ void EnumLoweringPhase::CreateUnboxingMethod(ir::TSEnumDeclaration const *const function->Scope()->BindInternalName(functionIdent->Name()); MakeMethodDef(checker_, enumClass, varbinder_, functionIdent, function); - functionIdent->SetReference(); } ArenaAllocator *EnumLoweringPhase::Allocator() diff --git a/ets2panda/compiler/lowering/ets/enumPostCheckLowering.cpp b/ets2panda/compiler/lowering/ets/enumPostCheckLowering.cpp index a90b5deee1fb3ea6f81c9e913285d37b60ab56d1..fcfded93e156790677f96a72f89b0fe2bc3b6bf3 100644 --- a/ets2panda/compiler/lowering/ets/enumPostCheckLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumPostCheckLowering.cpp @@ -29,7 +29,6 @@ ir::CallExpression *EnumPostCheckLoweringPhase::CreateCall( auto *classId = checker->AllocNode(classDef->Ident()->Name(), checker->Allocator()); auto *methodId = checker->AllocNode( (argument->TsType()->AsETSEnumType()->*getMethod)().memberProxyType->Name(), checker->Allocator()); - methodId->SetReference(); auto *callee = checker->AllocNode(classId, methodId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); diff --git a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp index 40b43ce759c578b41161b434b59d9d347965b5da..6792cd457ef44641e86fa0c8e111133ecbef63d7 100644 --- a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp +++ b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp @@ -465,13 +465,11 @@ static ir::BlockStatement *CreateFunctionBody(public_lib::Context *ctx, ir::Arro ir::Expression *id = nullptr; ir::Expression *accessor = nullptr; auto *const callee = checker->AllocNode(defaultMethod->Id()->Name(), checker->Allocator()); - callee->SetReference(); if (defaultMethod->IsStatic() && defaultMethod->Parent()->IsClassDefinition() && (!defaultMethod->Parent()->AsClassDefinition()->IsGlobal())) { id = checker->AllocNode(defaultMethod->Parent()->AsClassDefinition()->Ident()->Name(), checker->Allocator()); - id->AsIdentifier()->SetReference(); accessor = checker->AllocNode(id, callee, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); callee->SetParent(accessor); diff --git a/ets2panda/compiler/lowering/ets/localClassLowering.cpp b/ets2panda/compiler/lowering/ets/localClassLowering.cpp index c79dfda9afe4a6dda481a60e8e82e6f11512b480..59e581d280842c7f99b8d0f0cf27c518855cd582 100644 --- a/ets2panda/compiler/lowering/ets/localClassLowering.cpp +++ b/ets2panda/compiler/lowering/ets/localClassLowering.cpp @@ -68,7 +68,6 @@ static ir::Statement *CreateCtorFieldInit(checker::ETSChecker *checker, util::St auto *thisExpr = allocator->New(); auto *fieldAccessExpr = allocator->New(name, allocator); - fieldAccessExpr->SetReference(); auto *leftHandSide = util::NodeAllocator::ForceSetParent( allocator, thisExpr, fieldAccessExpr, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); auto *rightHandSide = allocator->New(name, allocator); diff --git a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp index 43a72da7c9067eb076d64f67e6cf51b7bcfd08b7..b5f1c99034146c1100cc467ee208d652227ad843 100644 --- a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp +++ b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp @@ -217,6 +217,8 @@ bool ObjectLiteralLowering::Perform(public_lib::Context *ctx, parser::Program *p return ast; }, Name()); +// std::cout << "ETS: " << program->Ast()->DumpEtsSrc() << std::endl; +// std::cout << "AST: " << program->Ast()->DumpJSON() << std::endl; return true; } diff --git a/ets2panda/compiler/lowering/ets/optionalLowering.cpp b/ets2panda/compiler/lowering/ets/optionalLowering.cpp index 3ecf31d07dd8c9e5cb980792ac5489f75db80ffc..b91d0f213f65687a718ef89d8473292428dfe918 100644 --- a/ets2panda/compiler/lowering/ets/optionalLowering.cpp +++ b/ets2panda/compiler/lowering/ets/optionalLowering.cpp @@ -57,7 +57,6 @@ static ir::AstNode *LowerOptionalExpr(GetSource const &getSource, SetSource cons auto expressionCtx = varbinder::LexicalScope::Enter(varbinder, NearestScope(expr)); auto *tmpIdent = Gensym(allocator); auto *tmpIdentClone = tmpIdent->Clone(allocator, nullptr); - tmpIdentClone->SetReference(); // '0's act as placeholders auto *sequenceExpr = parser->CreateFormattedExpression( diff --git a/ets2panda/compiler/lowering/ets/promiseVoid.cpp b/ets2panda/compiler/lowering/ets/promiseVoid.cpp index 30de0dbe7a9f6cc2cdb42a2614b5c5119f8ed074..ca9ce6bc2143c34641ef9f437ac3cc544d91435a 100644 --- a/ets2panda/compiler/lowering/ets/promiseVoid.cpp +++ b/ets2panda/compiler/lowering/ets/promiseVoid.cpp @@ -71,7 +71,6 @@ ir::TypeNode *PromiseVoidInferencePhase::CreatePromiseVoidType(checker::ETSCheck auto *voidParam = [checker]() { auto paramsVector = ArenaVector(checker->Allocator()->Adapter()); auto *voidId = checker->AllocNode(compiler::Signatures::UNDEFINED, checker->Allocator()); - voidId->SetReference(); auto *part = checker->AllocNode(voidId); paramsVector.push_back(checker->AllocNode(part)); auto *params = checker->AllocNode(std::move(paramsVector)); @@ -81,7 +80,6 @@ ir::TypeNode *PromiseVoidInferencePhase::CreatePromiseVoidType(checker::ETSCheck auto *promiseVoidType = [checker, voidParam]() { auto *promiseId = checker->AllocNode(compiler::Signatures::BUILTIN_PROMISE_CLASS, checker->Allocator()); - promiseId->SetReference(); auto *part = checker->AllocNode(promiseId, voidParam, nullptr); auto *type = checker->AllocNode(part); return type; diff --git a/ets2panda/compiler/lowering/ets/stringComparison.cpp b/ets2panda/compiler/lowering/ets/stringComparison.cpp index 2ee5393c7112d50bf9d1ceca30286c5718f071f5..94c31f638c242e1caf3493feb11582360feb681e 100644 --- a/ets2panda/compiler/lowering/ets/stringComparison.cpp +++ b/ets2panda/compiler/lowering/ets/stringComparison.cpp @@ -85,7 +85,6 @@ void StringComparisonLowering::ProcessBinaryExpression(ir::BinaryExpression *exp auto *const callee = checker->AllocNode("compareTo", checker->Allocator()); accessor = checker->AllocNode(expr->Left(), callee, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - callee->SetReference(); callArgs.push_back(expr->Right()); auto callExpression = checker->AllocNode(accessor, std::move(callArgs), nullptr, false, false); diff --git a/ets2panda/compiler/lowering/ets/structLowering.cpp b/ets2panda/compiler/lowering/ets/structLowering.cpp index 16524732f55d825f096275c117f4b5e04324315f..d60c7cb547a96976eeabd51f35a564b0da04e8fd 100644 --- a/ets2panda/compiler/lowering/ets/structLowering.cpp +++ b/ets2panda/compiler/lowering/ets/structLowering.cpp @@ -45,7 +45,6 @@ ir::ETSTypeReference *CreateStructTypeReference(checker::ETSChecker *checker, for (const auto ¶m : etsStrucDeclaration->Definition()->TypeParams()->Params()) { auto *identRef = checker->AllocNode(param->AsTSTypeParameter()->Name()->Name(), allocator); - identRef->AsIdentifier()->SetReference(); referencePart = checker->AllocNode(identRef, nullptr, nullptr); @@ -59,7 +58,6 @@ ir::ETSTypeReference *CreateStructTypeReference(checker::ETSChecker *checker, auto *identSelfRef = checker->AllocNode(etsStrucDeclaration->Definition()->Ident()->Name(), allocator); - identSelfRef->AsIdentifier()->SetReference(); auto *referenceSelfPart = checker->AllocNode(identSelfRef, typeParamSelfInst, nullptr); @@ -70,7 +68,7 @@ ir::ETSTypeReference *CreateStructTypeReference(checker::ETSChecker *checker, auto *typeParamInst = checker->AllocNode(std::move(params)); auto *identRef = checker->AllocNode(util::StringView(STRUCT_CLASS_NAME), allocator); - identRef->AsIdentifier()->SetReference(); + auto *referencePart = checker->AllocNode(identRef, typeParamInst, nullptr); auto *typeReference = checker->AllocNode(referencePart); diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp index 5b6a0629a0ebe24e97c2a4e99bcbe597f0b1743c..883c2a797f3a2a0b11d6ecf276d2bafd2bc6a274 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalClassHandler.cpp @@ -163,7 +163,6 @@ void GlobalClassHandler::AddInitCall(ir::ClassDefinition *globalClass, ir::Metho ir::Identifier *GlobalClassHandler::RefIdent(const util::StringView &name) { auto *const callee = NodeAllocator::Alloc(allocator_, name, allocator_); - callee->SetReference(); return callee; } diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp index a19c606ce5950b87a34e4be42e84e6ed71d8e58a..faa4a6d90498e2513075e8d067db8a5b6fc63319 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp @@ -86,7 +86,6 @@ void GlobalDeclTransformer::VisitVariableDeclaration(ir::VariableDeclaration *va ir::Identifier *GlobalDeclTransformer::RefIdent(const util::StringView &name) { auto *const callee = util::NodeAllocator::Alloc(allocator_, name, allocator_); - callee->SetReference(); return callee; } diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index 33ae22c066a3660b326d20a4c7210ab431abec87..d7cac762ecf26757f9686a11b2e99f2569c55613 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -42,10 +42,6 @@ Identifier *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const pa clone->SetParent(parent); } - if (this->IsReference()) { - clone->SetReference(); - } - clone->SetRange(Range()); return clone; @@ -134,4 +130,211 @@ checker::Type *Identifier::Check(checker::ETSChecker *checker) { return checker->GetAnalyzer()->Check(this); } + +bool Identifier::CommonDeclarationCheck(const ir::Identifier *id) const +{ + if (id->Parent() != nullptr) { + auto parent = id->Parent(); + // We need two Parts because check is too long to fit in one function + if (CheckDeclarationsPart1(parent) || CheckDeclarationsPart2(parent)) { + return true; + } + + // Parameters in methods are not references + // Example: + // function foo(a: int) + if (parent->IsETSParameterExpression()) { + return true; + } + + // Class Properties are not references + if (parent->IsClassProperty()) { + return true; + } + + // Identifier in catch is not a reference + // Example: + // + // _try_{ + // _throw_new_Exception();}_catch_(e)_{} + if (parent->IsCatchClause()) { + return true; + } + + // Type Parameter is not a reference + // Example: + // interface X {} + if (parent->IsTSTypeParameter()) { + return true; + } + + // Rest Parameter is not a reference + // Example: + // class A { + // constructor(... items :Object[]){} + // } + if (parent->IsRestElement()) { + return true; + } + + // Script function identifiers are not references + // Example: + // public static foo() + if (parent->IsScriptFunction()) { + return true; + } + + // New methods are not references + if (parent->IsMethodDefinition()) { + return true; + } + + // New classes are not references + if (parent->IsClassDefinition()) { + return true; + } + } + + // if (CheckNameRelated(id)) { + // return true; + // } + + return false; +} + + +bool Identifier::CheckDeclarationsPart1(const ir::AstNode *parentNode) const +{ + // All declarations are not references + if (parentNode->IsVariableDeclaration()) { + return true; + } + + if (parentNode->IsClassDeclaration()) { + return true; + } + + if (parentNode->IsETSPackageDeclaration()) { + return true; + } + + // if (parentNode->IsVariableDeclarator()) { + // return true; + // } + + if (parentNode->IsFunctionDeclaration()) { + return true; + } + + if (parentNode->IsImportDeclaration()) { + return true; + } + + if (parentNode->IsETSImportDeclaration()) { + return true; + } + + if (parentNode->IsETSStructDeclaration()) { + return true; + } + + if (parentNode->IsExportAllDeclaration()) { + return true; + } + + if (parentNode->IsExportDefaultDeclaration()) { + return true; + } + + return false; +} + +bool Identifier::CheckDeclarationsPart2(const ir::AstNode *parentNode) const +{ + // All declarations are not references + if (parentNode->IsExportNamedDeclaration()) { + return true; + } + + if (parentNode->IsTSEnumDeclaration()) { + return true; + } + + if (parentNode->IsTSInterfaceDeclaration()) { + return true; + } + + if (parentNode->IsTSModuleDeclaration()) { + return true; + } + + if (parentNode->IsTSSignatureDeclaration()) { + return true; + } + + if (parentNode->IsETSReExportDeclaration()) { + return true; + } + + if (parentNode->IsTSImportEqualsDeclaration()) { + return true; + } + + if (parentNode->IsTSTypeAliasDeclaration()) { + return true; + } + + if (parentNode->IsTSTypeParameterDeclaration()) { + return true; + } + + if (parentNode->IsDeclare()) { + return true; + } + + if (parentNode->Parent() != nullptr) { + auto parent = parentNode->Parent(); + if (parent->IsTSEnumDeclaration()) { + return true; + } + } + + return false; +} + +bool Identifier::CheckNameRelated(const ir::Identifier *id) const +{ + auto name = id->Name(); + // NOTE: skip $dynmodule and JSRuntime identifiers that are not references + if (name == "$dynmodule" || name == "JSRuntime") { + return true; + } + + // NOTE: skip identifiers that are not references + if (name.Utf8().find("") == 0) { + return true; + } + + // NOTE: should be deleted as soon as issue with Identifiers with no name is fixed + if (name.Empty()) { + return true; + } + + // NOTE: some lambda identifiers are not references + if (name.Utf8().find("lambda$invoke") == 0) { + return true; + } + // NOTE: currently some generated gensym identifiers are not references + if (name.Utf8().find("gensym") == 0) { + return true; + } + + // NOTE: currently some generated field identifiers are not references + if (name.Utf8().find("field") == 0) { + return true; + } + + return false; +} + } // namespace ark::es2panda::ir diff --git a/ets2panda/ir/expressions/identifier.h b/ets2panda/ir/expressions/identifier.h index f25252a1b87743f3641e70a28e7db08f0bd72313..ed412231a9baff7f3280874837288830709e4dc9 100644 --- a/ets2panda/ir/expressions/identifier.h +++ b/ets2panda/ir/expressions/identifier.h @@ -31,12 +31,11 @@ using ENUMBITOPS_OPERATORS; enum class IdentifierFlags : uint32_t { NONE = 0U, OPTIONAL = 1U << 0U, - REFERENCE = 1U << 1U, - TDZ = 1U << 2U, - PRIVATE = 1U << 3U, - GET = 1U << 4U, - SET = 1U << 5U, - IGNORE_BOX = 1U << 6U, + TDZ = 1U << 1U, + PRIVATE = 1U << 2U, + GET = 1U << 3U, + SET = 1U << 4U, + IGNORE_BOX = 1U << 5U, }; } // namespace ark::es2panda::ir @@ -113,16 +112,16 @@ public: [[nodiscard]] bool IsReference() const noexcept { - return (flags_ & IdentifierFlags::REFERENCE) != 0; - } - - void SetReference(bool const isReference = true) noexcept - { - if (isReference) { - flags_ |= IdentifierFlags::REFERENCE; - } else { - flags_ &= ~IdentifierFlags::REFERENCE; + // GLOBAL class is not a reference + if (Name() == "ETSGLOBAL") { + return false; } + // Checking most of the cases + if (CommonDeclarationCheck(this)) { + return false; + } + + return true; } [[nodiscard]] bool IsTdz() const noexcept @@ -202,6 +201,11 @@ public: checker::Type *Check(checker::TSChecker *checker) override; checker::Type *Check(checker::ETSChecker *checker) override; + bool CheckNameRelated(const ir::Identifier *id) const; + bool CheckDeclarationsPart2(const ir::AstNode *parentNode) const; + bool CheckDeclarationsPart1(const ir::AstNode *parentNode) const; + bool CommonDeclarationCheck(const ir::Identifier *id) const; + void Accept(ASTVisitorT *v) override { v->Accept(this); diff --git a/ets2panda/parser/ASparser.cpp b/ets2panda/parser/ASparser.cpp index bed6e27bc7555604942c3b50b100cb51becb21a4..e6aa085c9fa66b8f9515cf77e4acad5082f92cff 100644 --- a/ets2panda/parser/ASparser.cpp +++ b/ets2panda/parser/ASparser.cpp @@ -345,7 +345,6 @@ std::tuple ASParser::ParsePatternElementToken(E } case lexer::TokenType::LITERAL_IDENT: { returnNode = AllocNode(Lexer()->GetToken().Ident(), Allocator()); - returnNode->AsIdentifier()->SetReference(); returnNode->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); @@ -846,7 +845,6 @@ ir::Expression *ASParser::ParsePotentialAsExpression(ir::Expression *primaryExpr ir::Identifier *ASParser::ParsePrimaryExpressionIdent([[maybe_unused]] ExpressionParseFlags flags) { auto *identNode = AllocNode(Lexer()->GetToken().Ident(), Allocator()); - identNode->SetReference(); identNode->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index adc578920a0cef90534ccc2896b7df461c9c2de1..9c3599e4a8b8e1a035b31401de2e3274176d1307 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -500,7 +500,6 @@ ir::AstNode *ETSParser::ParseInnerRest(const ArenaVector &propert util::StringView tokenName = util::StringView {compiler::Signatures::STATIC_INVOKE_METHOD}; memberModifiers |= ir::ModifierFlags::STATIC; auto *ident = AllocNode(tokenName, Allocator()); - ident->SetReference(false); ident->SetRange({Lexer()->GetToken().Start(), Lexer()->GetToken().End()}); return parseClassMethod(ident); } @@ -1150,7 +1149,6 @@ ir::ExportNamedDeclaration *ETSParser::ParseSingleExport(ir::ModifierFlags modif { lexer::Token token = Lexer()->GetToken(); auto *exported = AllocNode(token.Ident(), Allocator()); - exported->SetReference(); exported->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); // eat exported variable name @@ -1206,7 +1204,6 @@ std::pair ETSParser::ParseN lexer::Token importedToken = Lexer()->GetToken(); auto *imported = AllocNode(importedToken.Ident(), Allocator()); ir::Identifier *local = nullptr; - imported->SetReference(); imported->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); @@ -1226,7 +1223,6 @@ std::pair ETSParser::ParseN result.emplace_back(specifier); } else { auto *imported = AllocNode(Lexer()->GetToken().Ident(), Allocator()); - imported->SetReference(); imported->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); auto *specifier = AllocNode(imported); @@ -1266,7 +1262,6 @@ void ETSParser::ParseNameSpaceSpecifier(ArenaVector *specifiers, auto *local = AllocNode(util::StringView(""), Allocator()); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA || Lexer()->GetToken().KeywordType() == lexer::TokenType::KEYW_FROM || isReExport) { - local->SetReference(); auto *specifier = AllocNode(local); specifier->SetRange({namespaceStart, Lexer()->GetToken().End()}); specifiers->push_back(specifier); @@ -1290,7 +1285,6 @@ ir::AstNode *ETSParser::ParseImportDefaultSpecifier(ArenaVector * } auto *imported = AllocNode(Lexer()->GetToken().Ident(), Allocator()); - imported->SetReference(); imported->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); // Eat import specifier. @@ -1424,7 +1418,6 @@ ir::Expression *ETSParser::CreateParameterThis(const util::StringView className) paramIdent->SetRange(Lexer()->GetToken().Loc()); ir::Expression *classTypeName = AllocNode(className, Allocator()); - classTypeName->AsIdentifier()->SetReference(); classTypeName->SetRange(Lexer()->GetToken().Loc()); auto typeRefPart = AllocNode(classTypeName, nullptr, nullptr); diff --git a/ets2panda/parser/ETSparserClasses.cpp b/ets2panda/parser/ETSparserClasses.cpp index de667232677dc558f48c698e5eb82c4fe2c1aaa8..04aad25a10e5ee80408fbe7e406b81b3d4f91568 100644 --- a/ets2panda/parser/ETSparserClasses.cpp +++ b/ets2panda/parser/ETSparserClasses.cpp @@ -470,7 +470,6 @@ ir::MethodDefinition *ETSParser::ParseClassMethodDefinition(ir::Identifier *meth auto *method = AllocNode(methodKind, methodName->Clone(Allocator(), nullptr)->AsExpression(), funcExpr, modifiers, Allocator(), false); method->SetRange(funcExpr->Range()); - func->Id()->SetReference(); return method; } @@ -486,7 +485,6 @@ ir::MethodDefinition *ETSParser::ParseClassMethod(ClassElementDescriptor *desc, ir::ScriptFunction *func = ParseFunction(desc->newStatus); if (propName->IsIdentifier()) { func->SetIdent(propName->AsIdentifier()->Clone(Allocator(), nullptr)); - func->Id()->SetReference(); } auto *funcExpr = AllocNode(func); @@ -911,8 +909,6 @@ ir::MethodDefinition *ETSParser::ParseInterfaceMethod(ir::ModifierFlags flags, i Allocator(), false); method->SetRange(funcExpr->Range()); - func->Id()->SetReference(); - ConsumeSemicolon(method); return method; diff --git a/ets2panda/parser/TSparser.cpp b/ets2panda/parser/TSparser.cpp index 0173a3725255616a40a9d257196fca94054c65ed..9de7d59ebc25e40a3331984dc916cddf49554acc 100644 --- a/ets2panda/parser/TSparser.cpp +++ b/ets2panda/parser/TSparser.cpp @@ -689,7 +689,6 @@ ir::TypeNode *TSParser::ParseTypeReferenceOrQuery(bool parseQuery) ir::Expression *typeName = AllocNode(Lexer()->GetToken().Ident(), Allocator()); typeName->SetRange(Lexer()->GetToken().Loc()); - typeName->AsIdentifier()->SetReference(); if (Lexer()->Lookahead() == lexer::LEX_CHAR_LESS_THAN) { Lexer()->ForwardToken(lexer::TokenType::PUNCTUATOR_LESS_THAN, 1); @@ -1465,7 +1464,6 @@ bool TSParser::IsNamedFunctionExpression() ir::Identifier *TSParser::ParsePrimaryExpressionIdent([[maybe_unused]] ExpressionParseFlags flags) { auto *identNode = AllocNode(Lexer()->GetToken().Ident(), Allocator()); - identNode->SetReference(); identNode->SetRange(Lexer()->GetToken().Loc()); Lexer()->NextToken(); diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index 7bec130afae097f0dfa0f9b89603de7b6f0fd052..b54e00f3ede72f5755482639d8281fdae544fdc5 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -1165,8 +1165,6 @@ ir::Expression *TypedParser::ParseQualifiedName(ExpressionParseFlags flags) ThrowSyntaxError("Identifier expected"); } - expr->AsIdentifier()->SetReference(); - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { expr = ParseQualifiedReference(expr, flags); } @@ -1210,7 +1208,6 @@ ir::Expression *TypedParser::ParseQualifiedReference(ir::Expression *typeName, E propName = AllocNode(Lexer()->GetToken().Ident(), Allocator()); } - propName->SetReference(); propName->SetRange(Lexer()->GetToken().Loc()); typeName = AllocNode(typeName, propName); diff --git a/ets2panda/parser/expressionParser.cpp b/ets2panda/parser/expressionParser.cpp index 39e4dc506d4485056db588fe703b0140a1520edc..2e8fcfa1c69177322ea9195a817ab215885ff59f 100644 --- a/ets2panda/parser/expressionParser.cpp +++ b/ets2panda/parser/expressionParser.cpp @@ -852,7 +852,6 @@ ir::MetaProperty *ParserImpl::ParsePotentialNewTarget() ir::Identifier *ParserImpl::ParsePrimaryExpressionIdent([[maybe_unused]] ExpressionParseFlags flags) { auto *identNode = AllocNode(lexer_->GetToken().Ident(), Allocator()); - identNode->SetReference(); identNode->SetRange(lexer_->GetToken().Loc()); lexer_->NextToken(); @@ -1024,7 +1023,6 @@ ir::Expression *ParserImpl::ParseHashMaskOperator() ValidatePrivateIdentifier(); auto *privateIdent = AllocNode(lexer_->GetToken().Ident(), Allocator()); privateIdent->SetPrivate(true); - privateIdent->SetReference(); lexer_->NextToken(); if (lexer_->GetToken().Type() != lexer::TokenType::KEYW_IN) { @@ -1450,7 +1448,6 @@ ir::Expression *ParserImpl::ParseOptionalChain(ir::Expression *leftSideExpr) const auto tokenType = lexer_->GetToken().Type(); if (tokenType == lexer::TokenType::LITERAL_IDENT) { auto *identNode = AllocNode(lexer_->GetToken().Ident(), Allocator()); - identNode->SetReference(); identNode->SetPrivate(isPrivate); identNode->SetRange(lexer_->GetToken().Loc()); @@ -1582,7 +1579,6 @@ ir::MemberExpression *ParserImpl::ParsePrivatePropertyAccess(ir::Expression *pri auto *privateIdent = AllocNode(lexer_->GetToken().Ident(), Allocator()); privateIdent->SetRange({memberStart, lexer_->GetToken().End()}); privateIdent->SetPrivate(true); - privateIdent->SetReference(); lexer_->NextToken(); auto *memberExpr = AllocNode(primaryExpr, privateIdent, @@ -1803,7 +1799,6 @@ ir::Expression *ParserImpl::ParsePatternElement(ExpressionParseFlags flags, bool } case lexer::TokenType::LITERAL_IDENT: { returnNode = AllocNode(lexer_->GetToken().Ident(), Allocator()); - returnNode->AsIdentifier()->SetReference(); returnNode->SetRange(lexer_->GetToken().Loc()); lexer_->NextToken(); break; @@ -1931,7 +1926,6 @@ ir::Property *ParserImpl::ParseShorthandProperty(const lexer::LexerPosition *sta key->SetRange(lexer_->GetToken().Loc()); ir::Expression *value = AllocNode(ident, Allocator()); - value->AsIdentifier()->SetReference(); value->SetRange(lexer_->GetToken().Loc()); lexer::SourcePosition end; diff --git a/ets2panda/parser/expressionTSParser.cpp b/ets2panda/parser/expressionTSParser.cpp index 006a4b5fd0ff07741356108e18eff13f68ebe796..304ad429739a54afb450b71672d041c40c6dcdab 100644 --- a/ets2panda/parser/expressionTSParser.cpp +++ b/ets2panda/parser/expressionTSParser.cpp @@ -169,7 +169,6 @@ ir::AnnotatedExpression *TSParser::ParsePatternElementGetReturnNode(ExpressionPa } case lexer::TokenType::LITERAL_IDENT: { ir::AnnotatedExpression *returnNode = AllocNode(Lexer()->GetToken().Ident(), Allocator()); - returnNode->AsIdentifier()->SetReference(); if (returnNode->AsIdentifier()->Decorators().empty()) { returnNode->SetRange(Lexer()->GetToken().Loc()); @@ -354,7 +353,6 @@ ir::Expression *TSParser::ParseModuleReference() ir::TSTypeReference *TSParser::ParseConstExpression() { auto *identRef = AllocNode(Lexer()->GetToken().Ident(), Allocator()); - identRef->SetReference(); identRef->SetRange(Lexer()->GetToken().Loc()); auto *typeReference = AllocNode(identRef, nullptr); diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index d9f83bfac9286d75a9a90f67f89342e7a1465ac3..9d3049f2a38944fb4df65467aefb712aa63b1f9c 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -1172,6 +1172,10 @@ ir::Identifier *ParserImpl::ExpectIdentifier(bool isReference, bool isUserDefine if (token.IsDefinableTypeName() && isUserDefinedType) { ThrowSyntaxError("Cannot be used as user-defined type."); } + if(isReference) + { + + } auto const &tokenStart = token.Start(); util::StringView tokenName {}; @@ -1188,7 +1192,6 @@ ir::Identifier *ParserImpl::ExpectIdentifier(bool isReference, bool isUserDefine } auto *ident = AllocNode(tokenName, Allocator()); - ident->SetReference(isReference); // NOTE: here actual token can be changed! ident->SetRange({tokenStart, lexer_->GetToken().End()}); diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index 127d808c12e5bec82de96c0c71f20ee11d76e7ec..f52d65a2e1e59f86ca1d2dd70512a4516605a256 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -467,7 +467,6 @@ ir::BreakStatement *ParserImpl::ParseBreakStatement() } auto *identNode = AllocNode(label, Allocator()); - identNode->SetReference(); identNode->SetRange(lexer_->GetToken().Loc()); auto *breakStatement = AllocNode(identNode); @@ -521,7 +520,6 @@ ir::ContinueStatement *ParserImpl::ParseContinueStatement() } auto *identNode = AllocNode(label, Allocator()); - identNode->SetReference(); identNode->SetRange(lexer_->GetToken().Loc()); auto *continueStatement = AllocNode(identNode); @@ -1018,7 +1016,6 @@ ir::LabelledStatement *ParserImpl::ParseLabelledStatement(const lexer::LexerPosi SavedParserContext newCtx(this, ParserStatus::IN_LABELED, actualLabel); auto *identNode = AllocNode(actualLabel, Allocator()); - identNode->SetReference(); identNode->SetRange(pos.GetToken().Loc()); lexer_->NextToken(); @@ -1720,7 +1717,6 @@ ir::Identifier *ParserImpl::ParseNamedImport(const lexer::Token &importedToken) CheckRestrictedBinding(importedToken.KeywordType()); auto *local = AllocNode(importedToken.Ident(), Allocator()); - local->SetReference(); local->SetRange(importedToken.Loc()); return local; @@ -1738,7 +1734,6 @@ void ParserImpl::ParseNamedImportSpecifiers(ArenaVector *specifie lexer::Token importedToken = lexer_->GetToken(); auto *imported = AllocNode(importedToken.Ident(), Allocator()); ir::Identifier *local = nullptr; - imported->SetReference(); imported->SetRange(lexer_->GetToken().Loc()); lexer_->NextToken(); // eat import name diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 988ffb856c463e57cc1380344b2948a94ea5107a..051b0ecb44f797885ff0dc6c296cb79c17029da8 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -60,6 +60,8 @@ #include "util/ustring.h" #include "checker/types/type.h" #include "checker/types/ets/types.h" +#include "variable.h" +#include "variableFlags.h" namespace ark::es2panda::varbinder { @@ -207,8 +209,34 @@ void ETSBinder::LookupIdentReference(ir::Identifier *ident) return; } + // if(name.Mutf8() == "p") + // { + // std::cout << "bingo" << std::endl; + // } + + auto ref = ident->IsReference(); + auto dec = res.variable->Declaration()->IsLetOrConstDecl(); + auto flag = res.variable->HasFlag(VariableFlags::INITIALIZED); + if(ref && dec && flag) + { + + } + if (ident->IsReference() && res.variable->Declaration()->IsLetOrConstDecl() && !res.variable->HasFlag(VariableFlags::INITIALIZED)) { +// std::cout << "Prog " << Program()->Ast()->DumpEtsSrc() << std::endl; +// std::cout << "Parent: " << ident->Parent()->Parent()->Parent()->Parent()->DumpEtsSrc() << std::endl; +// std::cout << "id " << ident->DumpEtsSrc() << std::endl; +// auto type = res.variable->Type(); +// if(res.variable->IsLocalVariable() /*&& res.variable->AsLocalVariable()->GetScope()->Node()->AsClassElement()->Value() != nullptr*/) +// { +// std::cout << "this is nightmare" << std::endl; +// res.variable->AddFlag(VariableFlags::INITIALIZED); +// return; +// } + +// std::cout << "ts type " << type << std::endl; + ThrowTDZ(ident->Start(), name); } } diff --git a/ets2panda/varbinder/varbinder.cpp b/ets2panda/varbinder/varbinder.cpp index b9c9c3e1ef22764b6ce4dddfcc4d6002a195380c..03450626a410db15c06330d6a8c39d2ae8c055b0 100644 --- a/ets2panda/varbinder/varbinder.cpp +++ b/ets2panda/varbinder/varbinder.cpp @@ -14,7 +14,6 @@ */ #include "varbinder.h" - #include "varbinder/privateBinding.h" #include "parser/program/program.h" #include "util/helpers.h" @@ -246,7 +245,10 @@ void VarBinder::InstantiatePrivateContext(const ir::Identifier *ident) const void VarBinder::LookupIdentReference(ir::Identifier *ident) { + auto res = scope_->Find(ident->Name(), BindingOptions()); + if (!ident->IsReference()) { + ident->SetVariable(res.variable); return; } @@ -259,7 +261,6 @@ void VarBinder::LookupIdentReference(ir::Identifier *ident) return; } - auto res = scope_->Find(ident->Name(), BindingOptions()); if (res.level != 0) { ASSERT(res.variable); res.variable->SetLexical(res.scope);