• Home
  • Raw
  • Download

Lines Matching +full:checker +full:-

2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
7 * http://www.apache.org/licenses/LICENSE-2.0
19 #include "checker/ETSchecker.h"
20 #include "checker/ets/conversion.h"
21 #include "checker/ets/boxingConverter.h"
22 #include "checker/ets/unboxingConverter.h"
43 static ir::ClassDefinition *GetUnionFieldClass(checker::ETSChecker *checker, varbinder::VarBinder *… in GetUnionFieldClass() argument
46 …util::UString unionFieldClassName(util::StringView(panda_file::GetDummyClassName()), checker->Allo… in GetUnionFieldClass()
48 if ((foundVar = checker->Scope()->FindLocal(unionFieldClassName.View(), in GetUnionFieldClass()
50 return foundVar->Declaration()->Node()->AsClassDeclaration()->Definition(); in GetUnionFieldClass()
52 …auto *ident = checker->AllocNode<ir::Identifier>(unionFieldClassName.View(), checker->Allocator()); in GetUnionFieldClass()
53 auto [decl, var] = varbinder->NewVarDecl<varbinder::ClassDecl>(ident->Start(), ident->Name()); in GetUnionFieldClass()
54 ident->SetVariable(var); in GetUnionFieldClass()
58checker->AllocNode<ir::ClassDefinition>(checker->Allocator(), ident, ir::ClassDefinitionModifiers:… in GetUnionFieldClass()
60 classDef->SetScope(classCtx.GetScope()); in GetUnionFieldClass()
61 auto *classDecl = checker->AllocNode<ir::ClassDeclaration>(classDef, checker->Allocator()); in GetUnionFieldClass()
62 classDef->Scope()->BindNode(classDecl); in GetUnionFieldClass()
63 classDef->SetTsType(checker->GlobalETSObjectType()); in GetUnionFieldClass()
64 decl->BindNode(classDecl); in GetUnionFieldClass()
65 var->SetScope(classDef->Scope()); in GetUnionFieldClass()
67 varbinder->AsETSBinder()->BuildClassDefinition(classDef); in GetUnionFieldClass()
71 static varbinder::LocalVariable *CreateUnionFieldClassProperty(checker::ETSChecker *checker, in CreateUnionFieldClassProperty() argument
73 checker::Type *fieldType, in CreateUnionFieldClassProperty()
76 auto *const allocator = checker->Allocator(); in CreateUnionFieldClassProperty()
77 auto *const dummyClass = GetUnionFieldClass(checker, varbinder); in CreateUnionFieldClassProperty()
78 auto *classScope = dummyClass->Scope()->AsClassScope(); in CreateUnionFieldClassProperty()
81 …auto fieldCtx = varbinder::LexicalScope<varbinder::LocalScope>::Enter(varbinder, classScope->Insta… in CreateUnionFieldClassProperty()
83 …if (auto *var = classScope->FindLocal(propName, varbinder::ResolveBindingOptions::VARIABLES); var … in CreateUnionFieldClassProperty()
84 return var->AsLocalVariable(); in CreateUnionFieldClassProperty()
88 auto *fieldIdent = checker->AllocNode<ir::Identifier>(propName, allocator); in CreateUnionFieldClassProperty()
92checker->AllocNode<ir::ClassProperty>(fieldIdent, nullptr, nullptr, ir::ModifierFlags::NONE, alloc… in CreateUnionFieldClassProperty()
95 …auto [decl, var] = varbinder->NewVarDecl<varbinder::LetDecl>(fieldIdent->Start(), fieldIdent->Name… in CreateUnionFieldClassProperty()
96 var->AddFlag(varbinder::VariableFlags::PROPERTY); in CreateUnionFieldClassProperty()
97 var->SetTsType(fieldType); in CreateUnionFieldClassProperty()
98 fieldIdent->SetVariable(var); in CreateUnionFieldClassProperty()
99 field->SetTsType(fieldType); in CreateUnionFieldClassProperty()
100 decl->BindNode(field); in CreateUnionFieldClassProperty()
102 ArenaVector<ir::AstNode *> fieldDecl {allocator->Adapter()}; in CreateUnionFieldClassProperty()
104 dummyClass->AddProperties(std::move(fieldDecl)); in CreateUnionFieldClassProperty()
105 return var->AsLocalVariable(); in CreateUnionFieldClassProperty()
108 static void HandleUnionPropertyAccess(checker::ETSChecker *checker, varbinder::VarBinder *vbind, in HandleUnionPropertyAccess() argument
111 if (expr->PropVar() != nullptr) { in HandleUnionPropertyAccess()
114 [[maybe_unused]] auto parent = expr->Parent(); in HandleUnionPropertyAccess()
115 ASSERT(!(parent->IsCallExpression() && parent->AsCallExpression()->Callee() == expr && in HandleUnionPropertyAccess()
116 … parent->AsCallExpression()->Signature()->HasSignatureFlag(checker::SignatureFlags::TYPE))); in HandleUnionPropertyAccess()
117 expr->SetPropVar( in HandleUnionPropertyAccess()
118 …CreateUnionFieldClassProperty(checker, vbind, expr->TsType(), expr->Property()->AsIdentifier()->Na… in HandleUnionPropertyAccess()
119 ASSERT(expr->PropVar() != nullptr); in HandleUnionPropertyAccess()
122 static ir::TSAsExpression *GenAsExpression(checker::ETSChecker *checker, checker::Type *const opaqu… in GenAsExpression() argument
125 auto *const typeNode = checker->AllocNode<ir::OpaqueTypeNode>(opaqueType); in GenAsExpression()
126 auto *const asExpression = checker->AllocNode<ir::TSAsExpression>(node, typeNode, false); in GenAsExpression()
127 asExpression->SetParent(parent); in GenAsExpression()
128 asExpression->Check(checker); in GenAsExpression()
138 static ir::TSAsExpression *UnionCastToPrimitive(checker::ETSChecker *checker, checker::ETSObjectTyp… in UnionCastToPrimitive() argument
139checker::Type *unboxedPrim, ir::Expression *unionNode) in UnionCastToPrimitive()
141 auto *const unionAsRefExpression = GenAsExpression(checker, unboxableRef, unionNode, nullptr); in UnionCastToPrimitive()
142 return GenAsExpression(checker, unboxedPrim, unionAsRefExpression, unionNode->Parent()); in UnionCastToPrimitive()
145 static ir::TSAsExpression *HandleUnionCastToPrimitive(checker::ETSChecker *checker, ir::TSAsExpress… in HandleUnionCastToPrimitive() argument
147 auto *const unionType = expr->Expr()->TsType()->AsETSUnionType(); in HandleUnionCastToPrimitive()
148 auto *sourceType = unionType->FindExactOrBoxedType(checker, expr->TsType()); in HandleUnionCastToPrimitive()
150 …sourceType = unionType->AsETSUnionType()->FindTypeIsCastableToSomeType(expr->Expr(), checker->Rela… in HandleUnionCastToPrimitive()
151 expr->TsType()); in HandleUnionCastToPrimitive()
153 …if (sourceType != nullptr && expr->Expr()->GetBoxingUnboxingFlags() != ir::BoxingUnboxingFlags::NO… in HandleUnionCastToPrimitive()
154 if (expr->TsType()->IsETSPrimitiveType()) { in HandleUnionCastToPrimitive()
155 auto *const asExpr = GenAsExpression(checker, sourceType, expr->Expr(), expr); in HandleUnionCastToPrimitive()
156 …asExpr->SetBoxingUnboxingFlags(checker->GetUnboxingFlag(checker->MaybeUnboxInRelation(sourceType))… in HandleUnionCastToPrimitive()
157 expr->Expr()->SetBoxingUnboxingFlags(ir::BoxingUnboxingFlags::NONE); in HandleUnionCastToPrimitive()
158 expr->SetExpr(asExpr); in HandleUnionCastToPrimitive()
162 …auto *const unboxableUnionType = sourceType != nullptr ? sourceType : unionType->FindUnboxableType… in HandleUnionCastToPrimitive()
163 auto *const unboxedUnionType = checker->MaybeUnboxInRelation(unboxableUnionType); in HandleUnionCastToPrimitive()
165 …UnionCastToPrimitive(checker, unboxableUnionType->AsETSObjectType(), unboxedUnionType, expr->Expr(… in HandleUnionCastToPrimitive()
166 node->SetParent(expr->Parent()); in HandleUnionCastToPrimitive()
173 for (auto &[_, ext_programs] : program->ExternalSources()) { in Perform()
180 checker::ETSChecker *checker = ctx->checker->AsETSChecker(); in Perform() local
182 program->Ast()->TransformChildrenRecursively( in Perform()
183 // CC-OFFNXT(G.FMT.14-CPP) project code style in Perform()
184 [checker](ir::AstNode *ast) -> ir::AstNode * { in Perform()
185 … if (ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr) { in Perform()
187checker->GetApparentType(checker->GetNonNullishType(ast->AsMemberExpression()->Object()->TsType())… in Perform()
188 if (objType->IsETSUnionType()) { in Perform()
189 … HandleUnionPropertyAccess(checker, checker->VarBinder(), ast->AsMemberExpression()); in Perform()
194 if (ast->IsTSAsExpression() && ast->AsTSAsExpression()->Expr()->TsType() != nullptr && in Perform()
195 ast->AsTSAsExpression()->Expr()->TsType()->IsETSUnionType() && in Perform()
196 ast->AsTSAsExpression()->TsType() != nullptr && in Perform()
197 ast->AsTSAsExpression()->TsType()->IsETSPrimitiveType()) { in Perform()
198 return HandleUnionCastToPrimitive(checker, ast->AsTSAsExpression()); in Perform()
210 …bool current = !program->Ast()->IsAnyChild([checker = ctx->checker->AsETSChecker()](ir::AstNode *a… in Postcondition()
211 … if (!ast->IsMemberExpression() || ast->AsMemberExpression()->Object()->TsType() == nullptr) { in Postcondition()
215checker->GetApparentType(checker->GetNonNullishType(ast->AsMemberExpression()->Object()->TsType())… in Postcondition()
216 auto *parent = ast->Parent(); in Postcondition()
217 if (!(parent->IsCallExpression() && in Postcondition()
218 … parent->AsCallExpression()->Signature()->HasSignatureFlag(checker::SignatureFlags::TYPE))) { in Postcondition()
221 return objType->IsETSUnionType() && ast->AsMemberExpression()->PropVar() == nullptr; in Postcondition()
223 …if (!current || ctx->config->options->CompilerOptions().compilationMode != CompilationMode::GEN_ST… in Postcondition()
227 for (auto &[_, ext_programs] : program->ExternalSources()) { in Postcondition()