From 48f0a8ad429ae2ccef4a652bcba9a96759c8f642 Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Sun, 11 Aug 2024 22:17:38 +0200 Subject: [PATCH] Fix static method accessed via instance reference and remove references to `Names` variables --- .../compiler/BIRPackageSymbolEnter.java | 6 +- .../compiler/SourceDirectoryManager.java | 2 - .../ballerinalang/compiler/bir/BIRGen.java | 118 ++++++------ .../ballerinalang/compiler/bir/BIRGenEnv.java | 8 +- .../compiler/desugar/ASTBuilderUtil.java | 7 +- .../compiler/desugar/AnnotationDesugar.java | 4 +- .../compiler/desugar/ClassClosureDesugar.java | 2 - .../compiler/desugar/ClosureDesugar.java | 2 - .../desugar/DeclarativeAuthDesugar.java | 4 +- .../compiler/desugar/Desugar.java | 33 ++-- .../compiler/desugar/LargeMethodSplitter.java | 8 +- .../compiler/desugar/QueryDesugar.java | 2 - .../compiler/desugar/ServiceDesugar.java | 8 +- .../compiler/desugar/TransactionDesugar.java | 2 - .../semantics/analyzer/CodeAnalyzer.java | 8 +- .../analyzer/CompilerPluginRunner.java | 2 - .../semantics/analyzer/ConstantAnalyzer.java | 4 +- .../analyzer/ConstantTypeChecker.java | 39 ++-- .../analyzer/ConstantValueResolver.java | 8 +- .../semantics/analyzer/DataflowAnalyzer.java | 2 - .../analyzer/DocumentationAnalyzer.java | 2 - .../analyzer/EffectiveTypePopulator.java | 4 +- .../semantics/analyzer/IsolationAnalyzer.java | 6 +- .../semantics/analyzer/QueryTypeChecker.java | 14 +- .../analyzer/ReachabilityAnalyzer.java | 4 +- .../semantics/analyzer/SemanticAnalyzer.java | 30 ++- .../semantics/analyzer/SymbolEnter.java | 94 +++++----- .../semantics/analyzer/SymbolResolver.java | 16 +- .../semantics/analyzer/TypeChecker.java | 73 ++++---- .../semantics/analyzer/TypeParamAnalyzer.java | 4 +- .../semantics/analyzer/TypeResolver.java | 46 +++-- .../compiler/semantics/analyzer/Types.java | 8 +- .../compiler/semantics/model/SymbolTable.java | 4 +- .../compiler/util/ImmutableTypeCloner.java | 171 +++++++++--------- .../compiler/util/NodeUtils.java | 12 +- .../compiler/util/TypeDefBuilderHelper.java | 16 +- .../compiler/SourceDirectoryManagerTest.java | 4 - 37 files changed, 348 insertions(+), 429 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/BIRPackageSymbolEnter.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/BIRPackageSymbolEnter.java index eefda2a6da58..318b9bb49e24 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/BIRPackageSymbolEnter.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/BIRPackageSymbolEnter.java @@ -135,7 +135,6 @@ public class BIRPackageSymbolEnter { private final PackageCache packageCache; private final SymbolResolver symbolResolver; private final SymbolTable symTable; - private final Names names; private final TypeParamAnalyzer typeParamAnalyzer; private final Types types; private BIRTypeReader typeReader; @@ -167,7 +166,6 @@ private BIRPackageSymbolEnter(CompilerContext context) { this.packageCache = PackageCache.getInstance(context); this.symbolResolver = SymbolResolver.getInstance(context); this.symTable = SymbolTable.getInstance(context); - this.names = Names.getInstance(context); this.typeParamAnalyzer = TypeParamAnalyzer.getInstance(context); this.types = Types.getInstance(context); } @@ -1945,11 +1943,11 @@ private boolean isImmutable(long flags) { private BType getEffectiveImmutableType(BType type) { return ImmutableTypeCloner.getEffectiveImmutableType(null, types, type, type.tsymbol.pkgID, type.tsymbol.owner, - symTable, null, names); + symTable, null); } private BType getEffectiveImmutableType(BType type, PackageID pkgID, BSymbol owner) { return ImmutableTypeCloner.getEffectiveImmutableType(null, types, type, pkgID, owner, symTable, - null, names); + null); } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/SourceDirectoryManager.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/SourceDirectoryManager.java index 9e5b9ab7a4b3..4673f6f1f0a6 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/SourceDirectoryManager.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/SourceDirectoryManager.java @@ -53,7 +53,6 @@ public class SourceDirectoryManager implements Project { new CompilerContext.Key<>(); private final CompilerOptions options; - private final Names names; private final SourceDirectory sourceDirectory; private Manifest manifest; @@ -71,7 +70,6 @@ private SourceDirectoryManager(CompilerContext context) { // This has to be further refactored with ProjectAPI Implementation context.put(PROJECT_KEY, this); - this.names = Names.getInstance(context); this.options = CompilerOptions.getInstance(context); // Check whether the compilation is initiated by the project API. diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java index 9d74da3a22a2..9186c3a0bfbf 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java @@ -237,7 +237,6 @@ public class BIRGen extends BLangNodeVisitor { public static final String DEFAULT_WORKER_NAME = "function"; private BIRGenEnv env; - private final Names names; private final SymbolTable symTable; private final BIROptimizer birOptimizer; private final Types types; @@ -271,7 +270,6 @@ public static BIRGen getInstance(CompilerContext context) { private BIRGen(CompilerContext context) { context.put(BIR_GEN, this); - this.names = Names.getInstance(context); this.symTable = SymbolTable.getInstance(context); this.birOptimizer = BIROptimizer.getInstance(context); this.unifier = new Unifier(); @@ -451,7 +449,7 @@ public void visit(BLangTypeDefinition astTypeDefinition) { } birFunc.returnVariable = new BIRVariableDcl(astTypeDefinition.pos, funcSymbol.retType, - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.RETURN, null); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.RETURN, null); birFunc.localVars.add(0, birFunc.returnVariable); typeDef.attachedFuncs.add(birFunc); @@ -512,7 +510,7 @@ public void visit(BLangClassDefinition classDefinition) { } birFunc.returnVariable = new BIRVariableDcl(classDefinition.pos, funcSymbol.retType, - this.env.nextLocalVarId(names), VarScope.FUNCTION, + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.RETURN, null); birFunc.localVars.add(0, birFunc.returnVariable); @@ -576,7 +574,7 @@ public void visit(BLangFunction astFunc) { boolean isTypeAttachedFunction = astFunc.flagSet.contains(Flag.ATTACHED) && !typeDefs.containsKey(astFunc.receiver.getBType().tsymbol); - Name workerName = names.fromIdNode(astFunc.defaultWorkerName); + Name workerName = Names.fromIdNode(astFunc.defaultWorkerName); this.env.unlockVars.push(new BIRLockDetailsHolder()); Name funcName; @@ -591,7 +589,7 @@ public void visit(BLangFunction astFunc) { this.currentScope = new BirScope(0, null); if (astFunc.receiver != null) { BIRFunctionParameter birVarDcl = new BIRFunctionParameter(astFunc.pos, astFunc.receiver.getBType(), - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.ARG, astFunc.receiver.name.value, + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.ARG, astFunc.receiver.name.value, false, false); this.env.symbolVarMap.put(astFunc.receiver.symbol, birVarDcl); birFunc.receiver = getSelf(astFunc.receiver.symbol); @@ -635,7 +633,7 @@ public void visit(BLangFunction astFunc) { // TODO: Return variable with NIL type should be written to BIR // Special %0 location for storing return values BType retType = unifier.build(astFunc.symbol.type.getReturnType()); - birFunc.returnVariable = new BIRVariableDcl(astFunc.pos, retType, this.env.nextLocalVarId(names), + birFunc.returnVariable = new BIRVariableDcl(astFunc.pos, retType, this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.RETURN, null); birFunc.localVars.add(0, birFunc.returnVariable); @@ -716,7 +714,7 @@ public void visit(BLangFunction astFunc) { } private BIRVariableDcl createBIRVarDeclForPathParam(BVarSymbol pathParamSym) { - return new BIRVariableDcl(pathParamSym.pos, pathParamSym.type, this.env.nextLocalVarId(names), + return new BIRVariableDcl(pathParamSym.pos, pathParamSym.type, this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.ARG, pathParamSym.name.value); } @@ -811,7 +809,7 @@ private boolean isWorkerSend(String chnlName, String workerName) { public void visit(BLangLambdaFunction lambdaExpr) { //fpload instruction BIRVariableDcl tempVarLambda = new BIRVariableDcl(lambdaExpr.pos, lambdaExpr.getBType(), - this.env.nextLocalVarId(names), VarScope.FUNCTION, + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP, null); this.env.enclFunc.localVars.add(tempVarLambda); BIROperand lhsOp = new BIROperand(tempVarLambda); @@ -822,14 +820,14 @@ public void visit(BLangLambdaFunction lambdaExpr) { lambdaExpr.function.requiredParams.forEach(param -> { BIRVariableDcl birVarDcl = new BIRVariableDcl(param.pos, param.symbol.type, - this.env.nextLambdaVarId(names), VarScope.FUNCTION, VarKind.ARG, param.name.value); + this.env.nextLambdaVarId(), VarScope.FUNCTION, VarKind.ARG, param.name.value); params.add(birVarDcl); }); BLangSimpleVariable restParam = lambdaExpr.function.restParam; if (restParam != null) { BIRVariableDcl birVarDcl = new BIRVariableDcl(restParam.pos, restParam.symbol.type, - this.env.nextLambdaVarId(names), VarScope.FUNCTION, VarKind.ARG, null); + this.env.nextLambdaVarId(), VarScope.FUNCTION, VarKind.ARG, null); params.add(birVarDcl); } @@ -913,7 +911,7 @@ private void addParam(BIRFunction birFunc, BVarSymbol paramSymbol, BLangExpressi boolean isPathParam = paramSymbol.kind == SymbolKind.PATH_PARAMETER || paramSymbol.kind == SymbolKind.PATH_REST_PARAMETER; BIRFunctionParameter birVarDcl = new BIRFunctionParameter(pos, paramSymbol.type, - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.ARG, + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.ARG, paramSymbol.name.value, defaultValExpr != null, isPathParam); birFunc.localVars.add(birVarDcl); @@ -930,7 +928,7 @@ private void addParam(BIRFunction birFunc, BVarSymbol paramSymbol, BLangExpressi private void addRestParam(BIRFunction birFunc, BVarSymbol paramSymbol, Location pos) { BIRFunctionParameter birVarDcl = new BIRFunctionParameter(pos, paramSymbol.type, - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.ARG, paramSymbol.name.value, false, + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.ARG, paramSymbol.name.value, false, paramSymbol.kind == SymbolKind.PATH_REST_PARAMETER); birFunc.parameters.add(birVarDcl); birFunc.localVars.add(birVarDcl); @@ -948,7 +946,7 @@ private void addRequiredParam(BIRFunction birFunc, BVarSymbol paramSymbol, Locat boolean isPathParam = paramSymbol.kind == SymbolKind.PATH_PARAMETER || paramSymbol.kind == SymbolKind.PATH_REST_PARAMETER; BIRFunctionParameter birVarDcl = new BIRFunctionParameter(pos, paramSymbol.type, - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.ARG, paramSymbol.name.value, + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.ARG, paramSymbol.name.value, false, isPathParam); birFunc.parameters.add(birVarDcl); birFunc.localVars.add(birVarDcl); @@ -1076,7 +1074,7 @@ public void visit(BLangSimpleVariableDef astVarDefStmt) { kind = VarKind.LOCAL; } BIRVariableDcl birVarDcl = new BIRVariableDcl(astVarDefStmt.pos, astVarDefStmt.var.symbol.type, - this.env.nextLocalVarId(names), VarScope.FUNCTION, kind, astVarDefStmt.var.name.value); + this.env.nextLocalVarId(), VarScope.FUNCTION, kind, astVarDefStmt.var.name.value); birVarDcl.startBB = this.env.enclBB; this.env.varDclsByBlock.get(this.currentBlock).add(birVarDcl); this.env.enclFunc.localVars.add(birVarDcl); @@ -1179,7 +1177,7 @@ public void visit(BLangForkJoin forkJoin) { public void visit(BLangAlternateWorkerReceive altWorkerReceive) { BIRBasicBlock thenBB = new BIRBasicBlock(this.env.nextBBId()); addToTrapStack(thenBB); - BIRVariableDcl tempVarDcl = new BIRVariableDcl(altWorkerReceive.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(altWorkerReceive.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand lhsOp = new BIROperand(tempVarDcl); @@ -1215,7 +1213,7 @@ private List getChannelList( public void visit(BLangMultipleWorkerReceive multipleWorkerReceive) { BIRBasicBlock thenBB = new BIRBasicBlock(this.env.nextBBId()); addToTrapStack(thenBB); - BIRVariableDcl tempVarDcl = new BIRVariableDcl(multipleWorkerReceive.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(multipleWorkerReceive.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand lhsOp = new BIROperand(tempVarDcl); @@ -1233,7 +1231,7 @@ public void visit(BLangWorkerReceive workerReceive) { BIRBasicBlock thenBB = new BIRBasicBlock(this.env.nextBBId()); addToTrapStack(thenBB); - BIRVariableDcl tempVarDcl = new BIRVariableDcl(workerReceive.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(workerReceive.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand lhsOp = new BIROperand(tempVarDcl); @@ -1257,7 +1255,7 @@ public void visit(BLangWorkerAsyncSendExpr asyncSendExpr) { asyncSendExpr.expr.accept(this); BIROperand dataOp = this.env.targetOperand; BIRVariableDcl tempVarDcl = new BIRVariableDcl(asyncSendExpr.receive.matchingSendsError, - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand lhsOp = new BIROperand(tempVarDcl); this.env.targetOperand = lhsOp; @@ -1279,7 +1277,7 @@ public void visit(BLangWorkerSyncSendExpr syncSend) { BIROperand dataOp = this.env.targetOperand; BIRVariableDcl tempVarDcl = new BIRVariableDcl(syncSend.receive.matchingSendsError, - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand lhsOp = new BIROperand(tempVarDcl); this.env.targetOperand = lhsOp; @@ -1307,7 +1305,7 @@ public void visit(BLangWorkerFlushExpr flushExpr) { channels[i] = new BIRNode.ChannelDetails(sendStmt.getChannel().channelId(), isOnSameStrand, true); i++; } - BIRVariableDcl tempVarDcl = new BIRVariableDcl(flushExpr.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(flushExpr.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand lhsOp = new BIROperand(tempVarDcl); @@ -1331,7 +1329,7 @@ private void createWait(BLangWaitExpr waitExpr) { exprList.add(this.env.targetOperand); }); - BIRVariableDcl tempVarDcl = new BIRVariableDcl(waitExpr.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(waitExpr.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand lhsOp = new BIROperand(tempVarDcl); @@ -1346,7 +1344,7 @@ private void createWait(BLangWaitExpr waitExpr) { @Override public void visit(BLangErrorConstructorExpr errorConstructorExpr) { BIRVariableDcl tempVarError = new BIRVariableDcl(errorConstructorExpr.getBType(), - this.env.nextLocalVarId(names), VarScope.FUNCTION, + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarError); @@ -1400,7 +1398,7 @@ private void createCall(BLangInvocation invocationExpr, boolean isVirtual) { } // Create a temporary variable to store the return operation result. - BIRVariableDcl tempVarDcl = new BIRVariableDcl(invocationExpr.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(invocationExpr.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand lhsOp = new BIROperand(tempVarDcl); @@ -1603,14 +1601,14 @@ public void visit(BLangWhile astWhileStmt) { @Override public void visit(BLangIgnoreExpr ignoreExpr) { BIRVariableDcl tempVarDcl = new BIRVariableDcl(ignoreExpr.getBType(), - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); } @Override public void visit(BLangLiteral astLiteralExpr) { BIRVariableDcl tempVarDcl = new BIRVariableDcl(astLiteralExpr.getBType(), - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); setScopeAndEmit(new BIRNonTerminator.ConstantLoad(astLiteralExpr.pos, @@ -1627,7 +1625,7 @@ public void visit(BLangMapLiteral astMapLiteralExpr) { visitTypedesc(astMapLiteralExpr.pos, type, Collections.emptyList(), getAnnotations(type.tsymbol, this.env)); BIRVariableDcl tempVarDcl = - new BIRVariableDcl(astMapLiteralExpr.getBType(), this.env.nextLocalVarId(names), + new BIRVariableDcl(astMapLiteralExpr.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -1641,7 +1639,7 @@ public void visit(BLangMapLiteral astMapLiteralExpr) { @Override public void visit(BLangTypeConversionExpr astTypeConversionExpr) { BIRVariableDcl tempVarDcl = new BIRVariableDcl(astTypeConversionExpr.getBType(), - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -1661,7 +1659,7 @@ public void visit(BLangStructLiteral astStructLiteralExpr) { visitTypedesc(astStructLiteralExpr.pos, type, Collections.emptyList(), getAnnotations(type.tsymbol, this.env)); BIRVariableDcl tempVarDcl = new BIRVariableDcl(astStructLiteralExpr.getBType(), - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -1678,7 +1676,7 @@ public void visit(BLangStructLiteral astStructLiteralExpr) { @Override public void visit(BLangTypeInit connectorInitExpr) { BType exprType = connectorInitExpr.getBType(); - BIRVariableDcl tempVarDcl = new BIRVariableDcl(exprType, this.env.nextLocalVarId(names), VarScope.FUNCTION, + BIRVariableDcl tempVarDcl = new BIRVariableDcl(exprType, this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -1752,7 +1750,7 @@ public void visit(BLangMapAccessExpr astMapAccessExpr) { keyRegIndex, rhsOp, astMapAccessExpr.isStoreOnCreation)); return; } - BIRVariableDcl tempVarDcl = new BIRVariableDcl(astMapAccessExpr.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(astMapAccessExpr.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand tempVarRef = new BIROperand(tempVarDcl); @@ -1780,7 +1778,7 @@ public void visit(BLangTableAccessExpr astTableAccessExpr) { varRefRegIndex, keyRegIndex, rhsOp)); return; } - BIRVariableDcl tempVarDcl = new BIRVariableDcl(astTableAccessExpr.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(astTableAccessExpr.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand tempVarRef = new BIROperand(tempVarDcl); @@ -1814,7 +1812,7 @@ public void visit(BLangDynamicArgExpr dynamicParamExpr) { @Override public void visit(BLangStringAccessExpr stringAccessExpr) { - BIRVariableDcl tempVarDcl = new BIRVariableDcl(stringAccessExpr.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(stringAccessExpr.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand tempVarRef = new BIROperand(tempVarDcl); @@ -1843,7 +1841,7 @@ public void visit(BLangIndexBasedAccess.BLangTupleAccessExpr tupleAccessExpr) { @Override public void visit(BLangIsLikeExpr isLikeExpr) { BIRVariableDcl tempVarDcl = new BIRVariableDcl(symTable.booleanType, - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -1859,7 +1857,7 @@ public void visit(BLangIsLikeExpr isLikeExpr) { @Override public void visit(BLangTypeTestExpr typeTestExpr) { BIRVariableDcl tempVarDcl = new BIRVariableDcl(symTable.booleanType, - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -1885,7 +1883,7 @@ public void visit(BLangLocalVarRef astVarRefExpr) { } } else { BIRVariableDcl tempVarDcl = new BIRVariableDcl(varSymbol.type, - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand tempVarRef = new BIROperand(tempVarDcl); @@ -1912,7 +1910,7 @@ public void visit(BLangPackageVarRef astPackageVarRefExpr) { } else { if (this.env.isInArrayOrStructure > 0) { BIRVariableDcl tempVarDcl = new BIRVariableDcl(astPackageVarRefExpr.getBType(), - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand tempVarRef = new BIROperand(tempVarDcl); BIROperand fromVarRef = new BIROperand(getVarRef(astPackageVarRefExpr)); @@ -1952,7 +1950,7 @@ public void visit(BLangBinaryExpr astBinaryExpr) { // Create a temporary variable to store the binary operation result. BIRVariableDcl tempVarDcl = new BIRVariableDcl(astBinaryExpr.getBType(), - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand lhsOp = new BIROperand(tempVarDcl); this.env.targetOperand = lhsOp; @@ -1970,7 +1968,7 @@ public void visit(BLangUnaryExpr unaryExpr) { // Create a temporary variable to store the unary operation result. BIRVariableDcl tempVarDcl = new BIRVariableDcl(unaryExpr.getBType(), - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand lhsOp = new BIROperand(tempVarDcl); @@ -2024,7 +2022,7 @@ public void visit(BLangWaitForAllExpr.BLangWaitLiteral waitLiteral) { addToTrapStack(thenBB); BIRVariableDcl tempVarDcl = new BIRVariableDcl(waitLiteral.getBType(), - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); setScopeAndEmit(new BIRNonTerminator.NewStructure(waitLiteral.pos, toVarRef, this.env.targetOperand)); @@ -2049,7 +2047,7 @@ public void visit(BLangWaitForAllExpr.BLangWaitLiteral waitLiteral) { @Override public void visit(BLangIsAssignableExpr assignableExpr) { - BIRVariableDcl tempVarDcl = new BIRVariableDcl(symTable.booleanType, this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(symTable.booleanType, this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -2065,7 +2063,7 @@ public void visit(BLangIsAssignableExpr assignableExpr) { @Override public void visit(BLangXMLQName xmlQName) { BIRVariableDcl tempVarDcl = - new BIRVariableDcl(symTable.anyType, this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + new BIRVariableDcl(symTable.anyType, this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -2089,7 +2087,7 @@ public void visit(BLangXMLQName xmlQName) { @Override public void visit(BLangXMLElementLiteral xmlElementLiteral) { - BIRVariableDcl tempVarDcl = new BIRVariableDcl(xmlElementLiteral.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(xmlElementLiteral.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -2134,7 +2132,7 @@ public void visit(BLangXMLAttribute attribute) { @Override public void visit(BLangXMLSequenceLiteral xmlSequenceLiteral) { - BIRVariableDcl tempVarDcl = new BIRVariableDcl(xmlSequenceLiteral.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(xmlSequenceLiteral.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); @@ -2150,7 +2148,7 @@ public void visit(BLangXMLSequenceLiteral xmlSequenceLiteral) { @Override public void visit(BLangXMLTextLiteral xmlTextLiteral) { - BIRVariableDcl tempVarDcl = new BIRVariableDcl(xmlTextLiteral.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(xmlTextLiteral.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -2166,7 +2164,7 @@ public void visit(BLangXMLTextLiteral xmlTextLiteral) { @Override public void visit(BLangXMLCommentLiteral xmlCommentLiteral) { - BIRVariableDcl tempVarDcl = new BIRVariableDcl(xmlCommentLiteral.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(xmlCommentLiteral.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -2184,7 +2182,7 @@ public void visit(BLangXMLCommentLiteral xmlCommentLiteral) { @Override public void visit(BLangXMLProcInsLiteral xmlProcInsLiteral) { - BIRVariableDcl tempVarDcl = new BIRVariableDcl(xmlProcInsLiteral.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(xmlProcInsLiteral.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -2236,7 +2234,7 @@ public void visit(BLangXMLAccessExpr xmlAccessExpr) { @Override public void visit(BLangTypedescExpr accessExpr) { BIRVariableDcl tempVarDcl = - new BIRVariableDcl(accessExpr.getBType(), this.env.nextLocalVarId(names), VarScope.FUNCTION, + new BIRVariableDcl(accessExpr.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -2247,7 +2245,7 @@ public void visit(BLangTypedescExpr accessExpr) { @Override public void visit(BLangTableConstructorExpr tableConstructorExpr) { - BIRVariableDcl tempVarDcl = new BIRVariableDcl(tableConstructorExpr.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(tableConstructorExpr.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); @@ -2303,7 +2301,7 @@ private void visitTypedesc(Location pos, BType type, BIROperand annotations) { } private void visitTypedesc(Location pos, BType type, List varDcls, BIROperand annotations) { - BIRVariableDcl tempVarDcl = new BIRVariableDcl(symTable.typeDesc, this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(symTable.typeDesc, this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); BIRGenEnv env = this.env; env.enclFunc.localVars.add(tempVarDcl); @@ -2648,7 +2646,7 @@ public void visit(BLangReFlagsOnOff reFlagsOnOff) { } private BIROperand createVarRefOperand(BType type) { - BIRVariableDcl tempVarDcl = new BIRVariableDcl(type, this.env.nextLocalVarId(names), VarScope.FUNCTION, + BIRVariableDcl tempVarDcl = new BIRVariableDcl(type, this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); return new BIROperand(tempVarDcl); @@ -2702,7 +2700,7 @@ private InstructionKind getUnaryInstructionKind(OperatorKind opKind) { private void generateListConstructorExpr(BLangListConstructorExpr listConstructorExpr) { this.env.isInArrayOrStructure++; // Emit create array instruction - BIRVariableDcl tempVarDcl = new BIRVariableDcl(listConstructorExpr.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(listConstructorExpr.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); @@ -2770,7 +2768,7 @@ private void generateArrayAccess(BLangIndexBasedAccess astArrayAccessExpr) { varRefRegIndex, keyRegIndex, rhsOp)); return; } - BIRVariableDcl tempVarDcl = new BIRVariableDcl(astArrayAccessExpr.getBType(), this.env.nextLocalVarId(names), + BIRVariableDcl tempVarDcl = new BIRVariableDcl(astArrayAccessExpr.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand tempVarRef = new BIROperand(tempVarDcl); @@ -2813,7 +2811,7 @@ private void generateMappingAccess(BLangIndexBasedAccess astIndexBasedAccessExpr rhsOp, astIndexBasedAccessExpr.isStoreOnCreation)); } else { BIRVariableDcl tempVarDcl = new BIRVariableDcl(astIndexBasedAccessExpr.getBType(), - this.env.nextLocalVarId(names), + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarDcl); BIROperand tempVarRef = new BIROperand(tempVarDcl); @@ -2876,7 +2874,7 @@ private BIROperand generateStringLiteral(String value) { private void generateXMLNamespace(BLangXMLNS xmlnsNode) { BIRVariableDcl birVarDcl = new BIRVariableDcl(xmlnsNode.pos, symTable.stringType, - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.LOCAL, null); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.LOCAL, null); this.env.enclFunc.localVars.add(birVarDcl); this.env.symbolVarMap.put(xmlnsNode.symbol, birVarDcl); @@ -2902,7 +2900,7 @@ private BIROperand generateNamespaceRef(BXMLNSSymbol nsSymbol, Location pos) { return generateStringLiteral(nsSymbol.namespaceURI); } - BIRVariableDcl nsURIVarDcl = new BIRVariableDcl(symTable.stringType, this.env.nextLocalVarId(names), + BIRVariableDcl nsURIVarDcl = new BIRVariableDcl(symTable.stringType, this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(nsURIVarDcl); BIROperand nsURIVarRef = new BIROperand(nsURIVarDcl); @@ -2955,7 +2953,7 @@ private BIROperand getQNameOP(BLangExpression qnameExpr, BIROperand keyRegIndex) } BIRVariableDcl tempQNameVarDcl = new BIRVariableDcl(symTable.anyType, - this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); + this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempQNameVarDcl); BIROperand qnameVarRef = new BIROperand(tempQNameVarDcl); setScopeAndEmit(new BIRNonTerminator.NewStringXMLQName(qnameExpr.pos, qnameVarRef, keyRegIndex)); @@ -2984,7 +2982,7 @@ private void generateXMLAccess(BLangXMLAccessExpr xmlAccessExpr, BIROperand temp private void generateFPVarRef(BLangExpression fpVarRef, BInvokableSymbol funcSymbol) { // fpload instruction BIRVariableDcl tempVarLambda = - new BIRVariableDcl(fpVarRef.getBType(), this.env.nextLocalVarId(names), VarScope.FUNCTION, + new BIRVariableDcl(fpVarRef.getBType(), this.env.nextLocalVarId(), VarScope.FUNCTION, VarKind.TEMP); this.env.enclFunc.localVars.add(tempVarLambda); BIROperand lhsOp = new BIROperand(tempVarLambda); @@ -2993,14 +2991,14 @@ private void generateFPVarRef(BLangExpression fpVarRef, BInvokableSymbol funcSym List params = new ArrayList<>(); funcSymbol.params.forEach(param -> { - BIRVariableDcl birVarDcl = new BIRVariableDcl(fpVarRef.pos, param.type, this.env.nextLambdaVarId(names), + BIRVariableDcl birVarDcl = new BIRVariableDcl(fpVarRef.pos, param.type, this.env.nextLambdaVarId(), VarScope.FUNCTION, VarKind.ARG, null); params.add(birVarDcl); }); BVarSymbol restParam = funcSymbol.restParam; if (restParam != null) { - BIRVariableDcl birVarDcl = new BIRVariableDcl(fpVarRef.pos, restParam.type, this.env.nextLambdaVarId(names), + BIRVariableDcl birVarDcl = new BIRVariableDcl(fpVarRef.pos, restParam.type, this.env.nextLambdaVarId(), VarScope.FUNCTION, VarKind.ARG, null); params.add(birVarDcl); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenEnv.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenEnv.java index 655cbb12ca82..1f4d03ecb5b3 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenEnv.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenEnv.java @@ -84,14 +84,14 @@ int nextBBId() { return ++currentBBId; } - Name nextLocalVarId(Names names) { + Name nextLocalVarId() { currentLocalVarId++; - return names.merge(Names.BIR_LOCAL_VAR_PREFIX, Names.fromString(Integer.toString(currentLocalVarId))); + return Names.merge(Names.BIR_LOCAL_VAR_PREFIX, Names.fromString(Integer.toString(currentLocalVarId))); } - Name nextLambdaVarId(Names names) { + Name nextLambdaVarId() { currentLambdaVarId++; - return names.merge(Names.BIR_LOCAL_VAR_PREFIX, Names.fromString(Integer.toString(currentLambdaVarId))); + return Names.merge(Names.BIR_LOCAL_VAR_PREFIX, Names.fromString(Integer.toString(currentLambdaVarId))); } void clear() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java index be7720ed29b5..3b7544ac9d26 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java @@ -165,9 +165,9 @@ static void appendStatement(BLangStatement stmt, BLangBlockStmt target) { target.stmts.add(index, stmt); } - static void defineVariable(BLangSimpleVariable variable, BSymbol targetSymbol, Names names) { - variable.symbol = new BVarSymbol(0, names.fromIdNode(variable.name), - names.originalNameFromIdNode(variable.name), + static void defineVariable(BLangSimpleVariable variable, BSymbol targetSymbol) { + variable.symbol = new BVarSymbol(0, Names.fromIdNode(variable.name), + Names.originalNameFromIdNode(variable.name), targetSymbol.pkgID, variable.getBType(), targetSymbol, variable.pos, VIRTUAL); targetSymbol.scope.define(variable.symbol.name, variable.symbol); } @@ -626,7 +626,6 @@ static BLangIsAssignableExpr createIsAssignableExpr(Location pos, BLangExpression lhsExpr, BType targetType, BType type, - Names names, Location opSymPos) { final BLangIsAssignableExpr assignableExpr = new BLangIsAssignableExpr(); assignableExpr.pos = pos; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/AnnotationDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/AnnotationDesugar.java index 8f96d18a6718..49240053b1dd 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/AnnotationDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/AnnotationDesugar.java @@ -136,7 +136,6 @@ public class AnnotationDesugar { private final Desugar desugar; private final SymbolTable symTable; private final Types types; - private final Names names; private SymbolResolver symResolver; private ConstantValueResolver constantValueResolver; private ClosureGenerator closureGenerator; @@ -154,7 +153,6 @@ private AnnotationDesugar(CompilerContext context) { this.desugar = Desugar.getInstance(context); this.symTable = SymbolTable.getInstance(context); this.types = Types.getInstance(context); - this.names = Names.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); this.constantValueResolver = ConstantValueResolver.getInstance(context); this.closureGenerator = ClosureGenerator.getInstance(context); @@ -926,7 +924,7 @@ private BLangSimpleVariable createGlobalAnnotationMapVar(BLangPackage pkgNode) { symTable.mapType, ASTBuilderUtil.createEmptyRecordLiteral( pkgNode.pos, symTable.mapType), null); - ASTBuilderUtil.defineVariable(annotationMap, pkgNode.symbol, names); + ASTBuilderUtil.defineVariable(annotationMap, pkgNode.symbol); pkgNode.globalVars.add(0, annotationMap); // TODO fix this pkgNode.topLevelNodes.add(0, annotationMap); return annotationMap; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClassClosureDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClassClosureDesugar.java index c57c896e92c3..24a64871fccf 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClassClosureDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClassClosureDesugar.java @@ -178,7 +178,6 @@ public class ClassClosureDesugar extends BLangNodeVisitor { private final SymbolTable symTable; private final Desugar desugar; - private final Names names; private final BLangDiagnosticLog dlog; static { @@ -197,7 +196,6 @@ private ClassClosureDesugar(CompilerContext context) { context.put(CLASS_CLOSURE_DESUGAR_KEY, this); this.symTable = SymbolTable.getInstance(context); this.desugar = Desugar.getInstance(context); - this.names = Names.getInstance(context); this.dlog = BLangDiagnosticLog.getInstance(context); CLOSURE_MAP_NOT_FOUND.pos = this.symTable.builtinPos; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureDesugar.java index f3c4aa6328c0..c85f340ff2e9 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureDesugar.java @@ -210,7 +210,6 @@ public class ClosureDesugar extends BLangNodeVisitor { private BLangNode result; private Types types; private Desugar desugar; - private Names names; private ClassClosureDesugar classClosureDesugar; private int funClosureMapCount = 1; private int blockClosureMapCount = 1; @@ -233,7 +232,6 @@ private ClosureDesugar(CompilerContext context) { this.symTable = SymbolTable.getInstance(context); this.types = Types.getInstance(context); this.desugar = Desugar.getInstance(context); - this.names = Names.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); this.classClosureDesugar = ClassClosureDesugar.getInstance(context); CLOSURE_MAP_NOT_FOUND.pos = this.symTable.builtinPos; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/DeclarativeAuthDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/DeclarativeAuthDesugar.java index 2b8533ea8cf3..7ef6d9d61217 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/DeclarativeAuthDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/DeclarativeAuthDesugar.java @@ -70,7 +70,6 @@ public class DeclarativeAuthDesugar { private final SymbolTable symTable; private final SymbolResolver symResolver; - private final Names names; private static final String ORG_NAME = "ballerina"; private static final String HTTP_PACKAGE_NAME = "http"; @@ -94,7 +93,6 @@ private DeclarativeAuthDesugar(CompilerContext context) { context.put(DECLARATIVE_AUTH_DESUGAR_KEY, this); this.symTable = SymbolTable.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); - this.names = Names.getInstance(context); } void desugarFunction(BLangFunction functionNode, SymbolEnv env, List expressionTypes) { @@ -181,7 +179,7 @@ void addAuthDesugarFunctionInvocation(BLangFunction functionNode, SymbolEnv env, List statements = getFunctionBodyStatementList(functionNode); statements.add(0, result); - BVarSymbol resultSymbol = new BVarSymbol(0, names.fromIdNode(result.var.name), env.enclPkg.packageID, + BVarSymbol resultSymbol = new BVarSymbol(0, Names.fromIdNode(result.var.name), env.enclPkg.packageID, result.var.getBType(), functionNode.symbol, pos, VIRTUAL); functionNode.symbol.scope.define(resultSymbol.name, resultSymbol); result.var.symbol = resultSymbol; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java index 1e9308685081..d8f242e51e69 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java @@ -386,7 +386,6 @@ public class Desugar extends BLangNodeVisitor { private Code2CloudDesugar code2CloudDesugar; private AnnotationDesugar annotationDesugar; private Types types; - private Names names; private ServiceDesugar serviceDesugar; private BLangNode result; private NodeCloner nodeCloner; @@ -464,8 +463,6 @@ private Desugar(CompilerContext context) { this.annotationDesugar = AnnotationDesugar.getInstance(context); this.largeMethodSplitter = LargeMethodSplitter.getInstance(context); this.types = Types.getInstance(context); - this.names = Names.getInstance(context); - this.names = Names.getInstance(context); this.serviceDesugar = ServiceDesugar.getInstance(context); this.nodeCloner = NodeCloner.getInstance(context); this.semanticAnalyzer = SemanticAnalyzer.getInstance(context); @@ -1639,7 +1636,7 @@ private void createRestFieldVarDefStmts(BLangTupleVariable parentTupleVariable, final BLangSimpleVariable foreachVariable = ASTBuilderUtil.createVariable(pos, "$foreach$i", foreach.varType); - foreachVariable.symbol = new BVarSymbol(0, names.fromIdNode(foreachVariable.name), + foreachVariable.symbol = new BVarSymbol(0, Names.fromIdNode(foreachVariable.name), this.env.scope.owner.pkgID, foreachVariable.getBType(), this.env.scope.owner, pos, VIRTUAL); BLangSimpleVarRef foreachVarRef = ASTBuilderUtil.createVariableRef(pos, foreachVariable.symbol); @@ -1885,7 +1882,7 @@ private void createVarDefStmts(BLangErrorVariable parentErrorVariable, BLangBloc parentErrorVariable.message.getBType(), convertedErrorVarSymbol, null); - if (names.fromIdNode(parentErrorVariable.message.name) == Names.IGNORE) { + if (Names.fromIdNode(parentErrorVariable.message.name) == Names.IGNORE) { parentErrorVariable.message = null; } else { BLangSimpleVariableDef messageVariableDef = @@ -1932,7 +1929,7 @@ private void createVarDefStmts(BLangErrorVariable parentErrorVariable, BLangBloc detailTempVarDef.setBType(parentErrorVariable.detailExpr.getBType()); parentBlockStmt.addStatement(detailTempVarDef); - this.env.scope.define(names.fromIdNode(detailTempVarDef.var.name), detailTempVarDef.var.symbol); + this.env.scope.define(Names.fromIdNode(detailTempVarDef.var.name), detailTempVarDef.var.symbol); for (BLangErrorVariable.BLangErrorDetailEntry detailEntry : parentErrorVariable.detail) { BLangExpression detailEntryVar = createErrorDetailVar(detailEntry, detailTempVarDef.var.symbol); @@ -2464,7 +2461,7 @@ private void createSimpleVarDefStmt(BLangSimpleVariable simpleVariable, BLangBlo BLangLiteral indexExpr, BVarSymbol tupleVarSymbol, BLangIndexBasedAccess parentArrayAccessExpr) { - Name varName = names.fromIdNode(simpleVariable.name); + Name varName = Names.fromIdNode(simpleVariable.name); if (varName == Names.IGNORE) { return; } @@ -2608,7 +2605,7 @@ private void createRestFieldAssignmentStmt(BLangTupleVarRef tupleVarRef, BLangBl final BLangSimpleVariable foreachVariable = ASTBuilderUtil.createVariable(pos, "$foreach$i", foreach.varType); - foreachVariable.symbol = new BVarSymbol(0, names.fromIdNode(foreachVariable.name), + foreachVariable.symbol = new BVarSymbol(0, Names.fromIdNode(foreachVariable.name), this.env.scope.owner.pkgID, foreachVariable.getBType(), this.env.scope.owner, pos, VIRTUAL); BLangSimpleVarRef foreachVarRef = ASTBuilderUtil.createVariableRef(pos, foreachVariable.symbol); @@ -2734,7 +2731,7 @@ private void createAssignmentStmt(BLangExpression accessibleExpression, BLangBlo BLangIndexBasedAccess parentArrayAccessExpr) { if (accessibleExpression.getKind() == NodeKind.SIMPLE_VARIABLE_REF) { - Name varName = names.fromIdNode(((BLangSimpleVarRef) accessibleExpression).variableName); + Name varName = Names.fromIdNode(((BLangSimpleVarRef) accessibleExpression).variableName); if (varName == Names.IGNORE) { return; } @@ -2917,7 +2914,7 @@ private void createVarRefAssignmentStmts(BLangRecordVarRef parentRecordVarRef, B private void createVarRefAssignmentStmts(BLangErrorVarRef parentErrorVarRef, BLangBlockStmt parentBlockStmt, BVarSymbol errorVarySymbol, BLangIndexBasedAccess parentIndexAccessExpr) { if (parentErrorVarRef.message != null && - names.fromIdNode(((BLangSimpleVarRef) parentErrorVarRef.message).variableName) != Names.IGNORE) { + Names.fromIdNode(((BLangSimpleVarRef) parentErrorVarRef.message).variableName) != Names.IGNORE) { BLangAssignment message = ASTBuilderUtil.createAssignmentStmt(parentBlockStmt.pos, parentBlockStmt); message.expr = generateErrorMessageBuiltinFunction(parentErrorVarRef.message.pos, symTable.stringType, errorVarySymbol, parentIndexAccessExpr); @@ -2926,7 +2923,7 @@ private void createVarRefAssignmentStmts(BLangErrorVarRef parentErrorVarRef, BLa } if (parentErrorVarRef.cause != null && (parentErrorVarRef.cause.getKind() != NodeKind.SIMPLE_VARIABLE_REF || - names.fromIdNode(((BLangSimpleVarRef) parentErrorVarRef.cause).variableName) != Names.IGNORE)) { + Names.fromIdNode(((BLangSimpleVarRef) parentErrorVarRef.cause).variableName) != Names.IGNORE)) { BLangAssignment cause = ASTBuilderUtil.createAssignmentStmt(parentBlockStmt.pos, parentBlockStmt); cause.expr = generateErrorCauseLanglibFunction(parentErrorVarRef.cause.pos, symTable.errorType, errorVarySymbol, parentIndexAccessExpr); @@ -2948,7 +2945,7 @@ private void createVarRefAssignmentStmts(BLangErrorVarRef parentErrorVarRef, BLa parentErrorVarRef.pos); detailTempVarDef.setBType(symTable.detailType); parentBlockStmt.addStatement(detailTempVarDef); - this.env.scope.define(names.fromIdNode(detailTempVarDef.var.name), detailTempVarDef.var.symbol); + this.env.scope.define(Names.fromIdNode(detailTempVarDef.var.name), detailTempVarDef.var.symbol); List extractedKeys = new ArrayList<>(); for (BLangNamedArgsExpression detail : parentErrorVarRef.detail) { @@ -4929,7 +4926,7 @@ private BType createMatchingRecordType(BLangErrorFieldMatchPatterns errorFieldMa BRecordType detailRecordType = createAnonRecordType(errorFieldMatchPatterns.pos); List typeDefFields = new ArrayList<>(); for (BLangNamedArgMatchPattern bindingPattern : errorFieldMatchPatterns.namedArgMatchPatterns) { - Name fieldName = names.fromIdNode(bindingPattern.argName); + Name fieldName = Names.fromIdNode(bindingPattern.argName); BVarSymbol declaredVarSym = bindingPattern.declaredVars.get(fieldName.value); if (declaredVarSym == null) { // constant match pattern expr, not needed for detail record type @@ -5018,7 +5015,7 @@ private BType createMatchingRecordType(BLangErrorFieldBindingPatterns errorField BRecordType detailRecordType = createAnonRecordType(errorFieldBindingPatterns.pos); List typeDefFields = new ArrayList<>(); for (BLangNamedArgBindingPattern bindingPattern : errorFieldBindingPatterns.namedArgBindingPatterns) { - Name fieldName = names.fromIdNode(bindingPattern.argName); + Name fieldName = Names.fromIdNode(bindingPattern.argName); BVarSymbol declaredVarSym = bindingPattern.declaredVars.get(fieldName.value); if (declaredVarSym == null) { // constant match pattern expr, not needed for detail record type @@ -8397,7 +8394,7 @@ private BLangClassDefinition desugarTemplateLiteralObjectTypedef(List de } for (BLangErrorVariable.BLangErrorDetailEntry detailEntry : detail) { - Name fieldName = names.fromIdNode(detailEntry.key); + Name fieldName = Names.fromIdNode(detailEntry.key); BType fieldType = getStructuredBindingPatternType(detailEntry.valueBindingPattern); BVarSymbol fieldSym = new BVarSymbol(Flags.PUBLIC, fieldName, detailRecordType.tsymbol.pkgID, fieldType, detailRecordType.tsymbol, detailEntry.key.pos, VIRTUAL); @@ -10453,7 +10450,7 @@ private BLangFunction createInitFunctionForClassDefn(BLangClassDefinition classD } BLangFunction initFunction = - TypeDefBuilderHelper.createInitFunctionForStructureType(classDefinition.symbol, env, names, + TypeDefBuilderHelper.createInitFunctionForStructureType(classDefinition.symbol, env, GENERATED_INIT_SUFFIX, classDefinition.getBType(), returnType); BObjectTypeSymbol typeSymbol = ((BObjectTypeSymbol) classDefinition.getBType().tsymbol); typeSymbol.generatedInitializerFunc = new BAttachedFunction(GENERATED_INIT_SUFFIX, initFunction.symbol, diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/LargeMethodSplitter.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/LargeMethodSplitter.java index 59d2083cc87e..25f9bdb3d24e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/LargeMethodSplitter.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/LargeMethodSplitter.java @@ -62,7 +62,6 @@ public class LargeMethodSplitter { private final Desugar desugar; private final SymbolTable symTable; - private final Names names; private final SymbolResolver symResolver; private static final CompilerContext.Key LARGE_METHOD_SPLITTER_KEY = @@ -80,7 +79,6 @@ private LargeMethodSplitter(CompilerContext context) { context.put(LARGE_METHOD_SPLITTER_KEY, this); this.desugar = Desugar.getInstance(context); this.symTable = SymbolTable.getInstance(context); - this.names = Names.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); } @@ -142,7 +140,7 @@ private BLangFunction splitInitFunction(BLangPackage packageNode, SymbolEnv env) } newFunc.pos = newFuncPos; newFuncBody = (BLangBlockFunctionBody) newFunc.body; - symTable.rootScope.define(names.fromIdNode(newFunc.name), newFunc.symbol); + symTable.rootScope.define(Names.fromIdNode(newFunc.name), newFunc.symbol); } newFuncBody.stmts.add(stmts.get(i)); } @@ -209,7 +207,7 @@ private BLangFunction splitStartFunction(BLangPackage packageNode, SymbolEnv env generatedFunctions.add(newFunc); newFunc = createIntermediateStartFunction(packageNode, env); newFuncBody = (BLangBlockFunctionBody) newFunc.body; - symTable.rootScope.define(names.fromIdNode(newFunc.name), newFunc.symbol); + symTable.rootScope.define(Names.fromIdNode(newFunc.name), newFunc.symbol); } newFuncBody.stmts.add(stmts.get(i)); } @@ -271,7 +269,7 @@ private BLangFunction splitStopFunction(BLangPackage packageNode, SymbolEnv env) generatedFunctions.add(newFunc); newFunc = createIntermediateStopFunction(packageNode, env); newFuncBody = (BLangBlockFunctionBody) newFunc.body; - symTable.rootScope.define(names.fromIdNode(newFunc.name), newFunc.symbol); + symTable.rootScope.define(Names.fromIdNode(newFunc.name), newFunc.symbol); } newFuncBody.stmts.add(stmts.get(i)); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java index c292edb3a4c1..6ce9ddc09ecf 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java @@ -250,7 +250,6 @@ public class QueryDesugar extends BLangNodeVisitor { private final Desugar desugar; private final SymbolTable symTable; private final SymbolResolver symResolver; - private final Names names; private final Types types; private SymbolEnv env; private SymbolEnv queryEnv; @@ -264,7 +263,6 @@ private QueryDesugar(CompilerContext context) { context.put(QUERY_DESUGAR_KEY, this); this.symTable = SymbolTable.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); - this.names = Names.getInstance(context); this.types = Types.getInstance(context); this.desugar = Desugar.getInstance(context); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ServiceDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ServiceDesugar.java index 1a811140783b..83e5d8eeedde 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ServiceDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ServiceDesugar.java @@ -77,7 +77,6 @@ public class ServiceDesugar { private final SymbolTable symTable; private final SymbolResolver symResolver; - private final Names names; private DeclarativeAuthDesugar declarativeAuthDesugar; private TransactionDesugar transactionDesugar; private final Types types; @@ -95,7 +94,6 @@ private ServiceDesugar(CompilerContext context) { context.put(SERVICE_DESUGAR_KEY, this); this.symTable = SymbolTable.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); - this.names = Names.getInstance(context); this.declarativeAuthDesugar = DeclarativeAuthDesugar.getInstance(context); this.transactionDesugar = TransactionDesugar.getInstance(context); this.types = Types.getInstance(context); @@ -155,7 +153,7 @@ void rewriteServiceVariable(BLangService service, SymbolEnv env, BLangBlockStmt final Location pos = service.pos; - ASTBuilderUtil.defineVariable(service.serviceVariable, env.enclPkg.symbol, names); + ASTBuilderUtil.defineVariable(service.serviceVariable, env.enclPkg.symbol); env.enclPkg.globalVars.add(service.serviceVariable); int count = 0; @@ -170,7 +168,7 @@ void rewriteServiceVariable(BLangService service, SymbolEnv env, BLangBlockStmt .createVariable(pos, generateServiceListenerVarName(service) + count, attachExpr.getBType(), attachExpr, null); - ASTBuilderUtil.defineVariable(listenerVar, env.enclPkg.symbol, names); + ASTBuilderUtil.defineVariable(listenerVar, env.enclPkg.symbol); listenerVar.symbol.flags |= Flags.LISTENER; env.enclPkg.globalVars.add(listenerVar); listenerVarRef = ASTBuilderUtil.createVariableRef(pos, listenerVar.symbol); @@ -185,7 +183,7 @@ void rewriteServiceVariable(BLangService service, SymbolEnv env, BLangBlockStmt getListenerTypeWithoutError(listenerVarRef.getBType()), listenerCheckExpr, null); - ASTBuilderUtil.defineVariable(listenerWithoutErrors, env.enclPkg.symbol, names); + ASTBuilderUtil.defineVariable(listenerWithoutErrors, env.enclPkg.symbol); env.enclPkg.globalVars.add(listenerWithoutErrors); BLangSimpleVarRef checkedRef = ASTBuilderUtil.createVariableRef(pos, listenerWithoutErrors.symbol); listenerVarRef = checkedRef; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/TransactionDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/TransactionDesugar.java index d81adba0d815..cefcef868423 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/TransactionDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/TransactionDesugar.java @@ -94,7 +94,6 @@ public class TransactionDesugar extends BLangNodeVisitor { private final Desugar desugar; private final SymbolTable symTable; private final SymbolResolver symResolver; - private final Names names; private final PackageCache packageCache; private BSymbol transactionError; @@ -115,7 +114,6 @@ private TransactionDesugar(CompilerContext context) { context.put(TRANSACTION_DESUGAR_KEY, this); this.symTable = SymbolTable.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); - this.names = Names.getInstance(context); this.desugar = Desugar.getInstance(context); this.packageCache = PackageCache.getInstance(context); this.types = Types.getInstance(context); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java index 38ea11405b35..c6f4ecb3d5f8 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java @@ -293,7 +293,6 @@ public class CodeAnalyzer extends SimpleBLangNodeAnalyzer(); private final BLangMissingNodesHelper missingNodesHelper; - private final Names names; private final SymbolTable symTable; private final SymbolResolver symResolver; private BLangDiagnosticLog dlog; @@ -65,7 +64,6 @@ private ConstantAnalyzer(CompilerContext context) { context.put(CONSTANT_ANALYZER_KEY, this); this.missingNodesHelper = BLangMissingNodesHelper.getInstance(context); - this.names = Names.getInstance(context); this.symTable = SymbolTable.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); this.dlog = BLangDiagnosticLog.getInstance(context); @@ -105,7 +103,7 @@ public void visit(BLangSimpleVarRef varRef) { if (varRef.pkgSymbol != symTable.notFoundSymbol && symbol == symTable.notFoundSymbol) { SymbolEnv pkgEnv = symTable.pkgEnvMap.get(varRef.pkgSymbol); symbol = pkgEnv == null ? symbol : symResolver.lookupMainSpaceSymbolInPackage(varRef.pos, pkgEnv, - names.fromIdNode(varRef.pkgAlias), names.fromIdNode(varRef.variableName)); + Names.fromIdNode(varRef.pkgAlias), Names.fromIdNode(varRef.variableName)); } if (symbol == symTable.notFoundSymbol) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java index e2060205f45f..0c73f7056a83 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java @@ -126,7 +126,6 @@ public class ConstantTypeChecker extends SimpleBLangNodeAnalyzer(); private final SymbolTable symTable; - private final Names names; private final NodeCloner nodeCloner; private final SymbolResolver symResolver; private final BLangDiagnosticLog dlog; @@ -140,7 +139,6 @@ public ConstantTypeChecker(CompilerContext context) { context.put(CONSTANT_TYPE_CHECKER_KEY, this); this.symTable = SymbolTable.getInstance(context); - this.names = Names.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); this.nodeCloner = NodeCloner.getInstance(context); this.dlog = BLangDiagnosticLog.getInstance(context); @@ -292,13 +290,13 @@ public void visit(BLangSimpleVarRef varRefExpr, AnalyzerData data) { // Set error type as the actual type. BType actualType = symTable.semanticError; - Name varName = names.fromIdNode(varRefExpr.variableName); + Name varName = Names.fromIdNode(varRefExpr.variableName); if (varName == Names.IGNORE) { varRefExpr.setBType(this.symTable.anyType); // If the variable name is a wildcard('_'), the symbol should be ignorable. varRefExpr.symbol = new BVarSymbol(0, true, varName, - names.originalNameFromIdNode(varRefExpr.variableName), + Names.originalNameFromIdNode(varRefExpr.variableName), data.env.enclPkg.symbol.pkgID, varRefExpr.getBType(), data.env.scope.owner, varRefExpr.pos, VIRTUAL); @@ -308,13 +306,13 @@ public void visit(BLangSimpleVarRef varRefExpr, AnalyzerData data) { Name compUnitName = typeChecker.getCurrentCompUnit(varRefExpr); varRefExpr.pkgSymbol = - symResolver.resolvePrefixSymbol(data.env, names.fromIdNode(varRefExpr.pkgAlias), compUnitName); + symResolver.resolvePrefixSymbol(data.env, Names.fromIdNode(varRefExpr.pkgAlias), compUnitName); if (varRefExpr.pkgSymbol == symTable.notFoundSymbol) { varRefExpr.symbol = symTable.notFoundSymbol; dlog.error(varRefExpr.pos, DiagnosticErrorCode.UNDEFINED_MODULE, varRefExpr.pkgAlias); } else { BSymbol symbol = - typeResolver.getSymbolOfVarRef(varRefExpr.pos, data.env, names.fromIdNode(varRefExpr.pkgAlias), + typeResolver.getSymbolOfVarRef(varRefExpr.pos, data.env, Names.fromIdNode(varRefExpr.pkgAlias), varName); if (symbol == symTable.notFoundSymbol) { @@ -352,13 +350,13 @@ public void visit(BLangListConstructorExpr listConstructor, AnalyzerData data) { public void visit(BLangRecordLiteral.BLangRecordVarNameField varRefExpr, AnalyzerData data) { BType actualType = symTable.semanticError; - Name varName = names.fromIdNode(varRefExpr.variableName); + Name varName = Names.fromIdNode(varRefExpr.variableName); if (varName == Names.IGNORE) { varRefExpr.setBType(this.symTable.anyType); // If the variable name is a wildcard('_'), the symbol should be ignorable. varRefExpr.symbol = new BVarSymbol(0, true, varName, - names.originalNameFromIdNode(varRefExpr.variableName), + Names.originalNameFromIdNode(varRefExpr.variableName), data.env.enclPkg.symbol.pkgID, varRefExpr.getBType(), data.env.scope.owner, varRefExpr.pos, VIRTUAL); @@ -368,7 +366,7 @@ public void visit(BLangRecordLiteral.BLangRecordVarNameField varRefExpr, Analyze Name compUnitName = typeChecker.getCurrentCompUnit(varRefExpr); varRefExpr.pkgSymbol = - symResolver.resolvePrefixSymbol(data.env, names.fromIdNode(varRefExpr.pkgAlias), compUnitName); + symResolver.resolvePrefixSymbol(data.env, Names.fromIdNode(varRefExpr.pkgAlias), compUnitName); if (varRefExpr.pkgSymbol == symTable.notFoundSymbol) { varRefExpr.symbol = symTable.notFoundSymbol; dlog.error(varRefExpr.pos, DiagnosticErrorCode.UNDEFINED_MODULE, varRefExpr.pkgAlias); @@ -376,7 +374,7 @@ public void visit(BLangRecordLiteral.BLangRecordVarNameField varRefExpr, Analyze if (varRefExpr.pkgSymbol != symTable.notFoundSymbol) { BSymbol symbol = - typeResolver.getSymbolOfVarRef(varRefExpr.pos, data.env, names.fromIdNode(varRefExpr.pkgAlias), + typeResolver.getSymbolOfVarRef(varRefExpr.pos, data.env, Names.fromIdNode(varRefExpr.pkgAlias), varName); if (symbol == symTable.notFoundSymbol) { @@ -518,8 +516,7 @@ private BRecordType createNewRecordType(BRecordTypeSymbol symbol, LinkedHashMap< symbol.type = recordType; recordType.tsymbol = symbol; recordType.sealed = true; - TypeDefBuilderHelper.createTypeDefinition(recordType, data.constantSymbol.pos, names, types, - symTable, data.env); + TypeDefBuilderHelper.createTypeDefinition(recordType, data.constantSymbol.pos, types, symTable, data.env); return recordType; } @@ -643,15 +640,15 @@ private BType getMappingConstructorCompatibleNonUnionType(BType type, AnalyzerDa case TypeTags.JSON: return !Symbols.isFlagOn(type.flags, Flags.READONLY) ? symTable.mapJsonType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.mapJsonType, data.env, - symTable, anonymousModelHelper, names); + symTable, anonymousModelHelper); case TypeTags.ANYDATA: return !Symbols.isFlagOn(type.flags, Flags.READONLY) ? symTable.mapAnydataType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.mapAnydataType, - data.env, symTable, anonymousModelHelper, names); + data.env, symTable, anonymousModelHelper); case TypeTags.ANY: return !Symbols.isFlagOn(type.flags, Flags.READONLY) ? symTable.mapAllType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.mapAllType, data.env, - symTable, anonymousModelHelper, names); + symTable, anonymousModelHelper); case TypeTags.INTERSECTION: return ((BIntersectionType) type).effectiveType; case TypeTags.TYPEREFDESC: @@ -1394,15 +1391,15 @@ private BType getListConstructorCompatibleNonUnionType(BType type, AnalyzerData case TypeTags.JSON: return !Symbols.isFlagOn(type.flags, Flags.READONLY) ? symTable.arrayJsonType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.arrayJsonType, - data.env, symTable, anonymousModelHelper, names); + data.env, symTable, anonymousModelHelper); case TypeTags.ANYDATA: return !Symbols.isFlagOn(type.flags, Flags.READONLY) ? symTable.arrayAnydataType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.arrayAnydataType, - data.env, symTable, anonymousModelHelper, names); + data.env, symTable, anonymousModelHelper); case TypeTags.ANY: return !Symbols.isFlagOn(type.flags, Flags.READONLY) ? symTable.arrayAllType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.arrayAllType, data.env, - symTable, anonymousModelHelper, names); + symTable, anonymousModelHelper); case TypeTags.INTERSECTION: return ((BIntersectionType) type).effectiveType; default: @@ -2185,7 +2182,6 @@ public static class FillMembers implements TypeVisitor { private final SymbolTable symTable; private final Types types; private final ConstantTypeChecker constantTypeChecker; - private final Names names; private final BLangDiagnosticLog dlog; private AnalyzerData data; @@ -2196,7 +2192,6 @@ public FillMembers(CompilerContext context) { this.symTable = SymbolTable.getInstance(context); this.types = Types.getInstance(context); this.constantTypeChecker = ConstantTypeChecker.getInstance(context); - this.names = Names.getInstance(context); this.dlog = BLangDiagnosticLog.getInstance(context); } @@ -2346,7 +2341,7 @@ public void visit(BMapType bMapType) { resultRecordType.tsymbol = recordSymbol; resultRecordType.sealed = true; resultRecordType.restFieldType = symTable.neverType; - TypeDefBuilderHelper.createTypeDefinition(resultRecordType, data.constantSymbol.pos, names, types, + TypeDefBuilderHelper.createTypeDefinition(resultRecordType, data.constantSymbol.pos, types, symTable, data.env); data.resultType = resultRecordType; } @@ -2464,7 +2459,7 @@ public void visit(BRecordType recordType) { resultRecordType.tsymbol = recordSymbol; resultRecordType.sealed = true; resultRecordType.restFieldType = symTable.neverType; - TypeDefBuilderHelper.createTypeDefinition(resultRecordType, data.constantSymbol.pos, names, types, + TypeDefBuilderHelper.createTypeDefinition(resultRecordType, data.constantSymbol.pos, types, symTable, data.env); data.resultType = resultRecordType; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantValueResolver.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantValueResolver.java index a98793bd9716..f8686820cec3 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantValueResolver.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantValueResolver.java @@ -102,7 +102,6 @@ public class ConstantValueResolver extends BLangNodeVisitor { private Location currentPos; private BLangAnonymousModelHelper anonymousModelHelper; private SymbolEnv symEnv; - private Names names; private SymbolTable symTable; private Types types; private PackageID pkgID; @@ -117,7 +116,6 @@ private ConstantValueResolver(CompilerContext context) { context.put(CONSTANT_VALUE_RESOLVER_KEY, this); this.dlog = BLangDiagnosticLog.getInstance(context); this.symTable = SymbolTable.getInstance(context); - this.names = Names.getInstance(context); this.anonymousModelHelper = BLangAnonymousModelHelper.getInstance(context); this.types = Types.getInstance(context); } @@ -798,7 +796,7 @@ private void createTypeDefinition(BRecordType type, Location pos, SymbolEnv env) BLangRecordTypeNode recordTypeNode = TypeDefBuilderHelper.createRecordTypeNode(new ArrayList<>(), type, pos); - TypeDefBuilderHelper.populateStructureFieldsAndTypeInclusions(types, symTable, null, names, + TypeDefBuilderHelper.populateStructureFieldsAndTypeInclusions(types, symTable, null, recordTypeNode, type, type, pos, env, pkgID, null, 0, false); recordTypeNode.sealed = true; type.restFieldType = new BNoType(TypeTags.NONE); @@ -872,7 +870,7 @@ private void updateRecordFields(BRecordType recordType, Location pos, SymbolEnv BTypeSymbol structureSymbol = recordType.tsymbol; for (BField field : recordType.fields.values()) { field.type = ImmutableTypeCloner.getImmutableType(pos, types, field.type, env, - env.enclPkg.packageID, env.scope.owner, symTable, anonymousModelHelper, names, + env.enclPkg.packageID, env.scope.owner, symTable, anonymousModelHelper, new HashSet<>()); Name fieldName = field.symbol.name; field.symbol = new BVarSymbol(field.symbol.flags | Flags.READONLY, fieldName, @@ -1031,7 +1029,7 @@ private BType createTupleType(BLangExpression expr, BConstantSymbol constantSymb env.scope.owner, pos, VIRTUAL); return ImmutableTypeCloner.getImmutableIntersectionType(pos, types, new BTupleType(tupleTypeSymbol, tupleTypes), - env, symTable, anonymousModelHelper, names, + env, symTable, anonymousModelHelper, new HashSet<>()); } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java index cc99e2f6e7ec..d507125f2999 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java @@ -259,7 +259,6 @@ public class DataflowAnalyzer extends BLangNodeVisitor { private final SymbolResolver symResolver; - private final Names names; private SymbolEnv env; private SymbolTable symTable; private BLangDiagnosticLog dlog; @@ -285,7 +284,6 @@ private DataflowAnalyzer(CompilerContext context) { this.dlog = BLangDiagnosticLog.getInstance(context); this.types = Types.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); - this.names = Names.getInstance(context); this.currDependentSymbolDeque = new ArrayDeque<>(); this.globalVariableRefAnalyzer = GlobalVariableRefAnalyzer.getInstance(context); this.unusedLocalVariables = new HashMap<>(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DocumentationAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DocumentationAnalyzer.java index 8be47bd45013..e42aeb63271a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DocumentationAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DocumentationAnalyzer.java @@ -84,7 +84,6 @@ public class DocumentationAnalyzer extends SimpleBLangNodeAnalyzer UPDATE_IMMUTABLE_TYPE_KEY = new CompilerContext.Key<>(); private final SymbolTable symTable; - private final Names names; private final Types types; private final BLangAnonymousModelHelper anonymousModelHelper; private Location loc; @@ -100,7 +99,6 @@ public class EffectiveTypePopulator implements TypeVisitor { public EffectiveTypePopulator(CompilerContext context) { context.put(UPDATE_IMMUTABLE_TYPE_KEY, this); this.symTable = SymbolTable.getInstance(context); - this.names = Names.getInstance(context); this.types = Types.getInstance(context); this.anonymousModelHelper = BLangAnonymousModelHelper.getInstance(context); } @@ -144,7 +142,7 @@ public void visit(BArrayType bArrayType) { if (origArrayType != null) { if (bArrayType.eType.tag == TypeTags.NEVER || bArrayType.eType == symTable.semanticError) { bArrayType.eType = ImmutableTypeCloner.getImmutableType(loc, types, origArrayType.eType, env, - pkgID, env.scope.owner, symTable, anonymousModelHelper, names, new HashSet<>()); + pkgID, env.scope.owner, symTable, anonymousModelHelper, new HashSet<>()); } updateType(bArrayType.eType, loc, pkgID, typeNode, env); bArrayType.mutableType = null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/IsolationAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/IsolationAnalyzer.java index 9b63f21d67f0..d1d1c3bab7bc 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/IsolationAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/IsolationAnalyzer.java @@ -289,7 +289,6 @@ public class IsolationAnalyzer extends BLangNodeVisitor { private SymbolEnv env; private final SymbolTable symTable; private final SymbolResolver symResolver; - private final Names names; private final Types types; private final BLangDiagnosticLog dlog; @@ -305,7 +304,6 @@ private IsolationAnalyzer(CompilerContext context) { context.put(ISOLATION_ANALYZER_KEY, this); this.symTable = SymbolTable.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); - this.names = Names.getInstance(context); this.types = Types.getInstance(context); this.dlog = BLangDiagnosticLog.getInstance(context); } @@ -3252,7 +3250,7 @@ private boolean hasRefDefinedOutsideLock(BLangExpression variableReference) { switch (variableReference.getKind()) { case SIMPLE_VARIABLE_REF: BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) variableReference; - return isDefinedOutsideLock(names.fromIdNode(simpleVarRef.variableName), simpleVarRef.symbol.tag, + return isDefinedOutsideLock(Names.fromIdNode(simpleVarRef.variableName), simpleVarRef.symbol.tag, env); case RECORD_VARIABLE_REF: BLangRecordVarRef recordVarRef = (BLangRecordVarRef) variableReference; @@ -3365,7 +3363,7 @@ private boolean isFunction(BLangNode enclNode) { } private boolean isInvalidCopyIn(BLangSimpleVarRef varRefExpr, SymbolEnv currentEnv) { - return isInvalidCopyIn(varRefExpr, names.fromIdNode(varRefExpr.variableName), varRefExpr.symbol.tag, + return isInvalidCopyIn(varRefExpr, Names.fromIdNode(varRefExpr.variableName), varRefExpr.symbol.tag, currentEnv); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java index 0905aaafbd7e..3b902992a62c 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java @@ -116,7 +116,6 @@ public class QueryTypeChecker extends TypeChecker { private final TypeParamAnalyzer typeParamAnalyzer; private final TypeNarrower typeNarrower; private final BLangAnonymousModelHelper anonymousModelHelper; - private final Names names; private final BLangDiagnosticLog dlog; private final NodeCloner nodeCloner; @@ -132,7 +131,6 @@ public QueryTypeChecker(CompilerContext context) { super(context, new CompilerContext.Key<>()); context.put(QUERY_TYPE_CHECKER_KEY, this); - this.names = Names.getInstance(context); this.symTable = SymbolTable.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); this.types = Types.getInstance(context); @@ -969,7 +967,7 @@ public void visit(BLangInvocation iExpr, TypeChecker.AnalyzerData data) { super.visit(iExpr, data); return; } - Name pkgAlias = names.fromIdNode(iExpr.pkgAlias); + Name pkgAlias = Names.fromIdNode(iExpr.pkgAlias); BSymbol pkgSymbol = symResolver.resolvePrefixSymbol(data.env, pkgAlias, getCurrentCompUnit(iExpr)); if (pkgSymbol == symTable.notFoundSymbol) { dlog.error(iExpr.pos, DiagnosticErrorCode.UNDEFINED_MODULE, pkgAlias); @@ -983,7 +981,7 @@ public void visit(BLangInvocation iExpr, TypeChecker.AnalyzerData data) { invocationType = firstArgType.tag == TypeTags.SEQUENCE ? ((BSequenceType) firstArgType).elementType : firstArgType; } - Name funcName = names.fromIdNode(iExpr.name); + Name funcName = Names.fromIdNode(iExpr.name); BSymbol symbol = symResolver.lookupLangLibMethod(invocationType, funcName, data.env); if (symbol == symTable.notFoundSymbol) { symbol = symResolver.lookupMainSpaceSymbolInPackage(iExpr.pos, data.env, pkgAlias, funcName); @@ -1091,13 +1089,13 @@ public void visit(BLangSimpleVarRef varRefExpr, TypeChecker.AnalyzerData data) { BType actualType = symTable.semanticError; BLangIdentifier identifier = varRefExpr.variableName; - Name varName = names.fromIdNode(identifier); + Name varName = Names.fromIdNode(identifier); if (varName == Names.IGNORE) { varRefExpr.setBType(this.symTable.anyType); // If the variable name is a wildcard('_'), the symbol should be ignorable. varRefExpr.symbol = new BVarSymbol(0, true, varName, - names.originalNameFromIdNode(identifier), + Names.originalNameFromIdNode(identifier), data.env.enclPkg.symbol.pkgID, varRefExpr.getBType(), data.env.scope.owner, varRefExpr.pos, VIRTUAL); @@ -1106,7 +1104,7 @@ public void visit(BLangSimpleVarRef varRefExpr, TypeChecker.AnalyzerData data) { } Name compUnitName = getCurrentCompUnit(varRefExpr); - BSymbol pkgSymbol = symResolver.resolvePrefixSymbol(data.env, names.fromIdNode(varRefExpr.pkgAlias), + BSymbol pkgSymbol = symResolver.resolvePrefixSymbol(data.env, Names.fromIdNode(varRefExpr.pkgAlias), compUnitName); varRefExpr.pkgSymbol = pkgSymbol; if (pkgSymbol == symTable.notFoundSymbol) { @@ -1118,7 +1116,7 @@ public void visit(BLangSimpleVarRef varRefExpr, TypeChecker.AnalyzerData data) { actualType = symTable.stringType; } else if (pkgSymbol != symTable.notFoundSymbol) { BSymbol symbol = symResolver.lookupMainSpaceSymbolInPackage(varRefExpr.pos, data.env, - names.fromIdNode(varRefExpr.pkgAlias), varName); + Names.fromIdNode(varRefExpr.pkgAlias), varName); // if no symbol, check same for object attached function BLangType enclType = data.env.enclType; if (symbol == symTable.notFoundSymbol && enclType != null && enclType.getBType().tsymbol.scope != null) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ReachabilityAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ReachabilityAnalyzer.java index 1b180e6fd9e8..aac4e4d34f10 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ReachabilityAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ReachabilityAnalyzer.java @@ -123,14 +123,12 @@ public class ReachabilityAnalyzer extends SimpleBLangNodeAnalyzer()); + lhsType, currentEnv, symTable, anonModelHelper, new HashSet<>()); varNode.setBType(lhsType); varNode.symbol.type = lhsType; } @@ -2130,8 +2128,8 @@ void handleDeclaredVarInForeach(BLangVariable variable, BType rhsType, SymbolEnv private void recursivelyDefineVariables(BLangVariable variable, SymbolEnv blockEnv) { switch (variable.getKind()) { case VARIABLE: - Name name = names.fromIdNode(((BLangSimpleVariable) variable).name); - Name origName = names.originalNameFromIdNode(((BLangSimpleVariable) variable).name); + Name name = Names.fromIdNode(((BLangSimpleVariable) variable).name); + Name origName = Names.originalNameFromIdNode(((BLangSimpleVariable) variable).name); variable.setBType(symTable.semanticError); symbolEnter.defineVarSymbol(variable.pos, variable.flagSet, variable.getBType(), name, origName, blockEnv, variable.internal); @@ -2396,7 +2394,7 @@ public void visit(BLangRecordDestructure recordDeStmt, AnalyzerData data) { public void visit(BLangErrorDestructure errorDeStmt, AnalyzerData data) { BLangErrorVarRef varRef = errorDeStmt.varRef; if (varRef.message != null) { - if (names.fromIdNode(((BLangSimpleVarRef) varRef.message).variableName) != Names.IGNORE) { + if (Names.fromIdNode(((BLangSimpleVarRef) varRef.message).variableName) != Names.IGNORE) { setTypeOfVarRefInErrorBindingAssignment(varRef.message, data); checkInvalidTypeDef(varRef.message); } else { @@ -2407,7 +2405,7 @@ public void visit(BLangErrorDestructure errorDeStmt, AnalyzerData data) { if (varRef.cause != null) { if (varRef.cause.getKind() != NodeKind.SIMPLE_VARIABLE_REF || - names.fromIdNode(((BLangSimpleVarRef) varRef.cause).variableName) != Names.IGNORE) { + Names.fromIdNode(((BLangSimpleVarRef) varRef.cause).variableName) != Names.IGNORE) { setTypeOfVarRefInErrorBindingAssignment(varRef.cause, data); checkInvalidTypeDef(varRef.cause); } else { @@ -2483,7 +2481,7 @@ private void checkRecordVarRefEquivalency(Location pos, BLangRecordVarRef lhsVar } else if (variableReference.getKind() == NodeKind.ERROR_VARIABLE_REF) { checkErrorVarRefEquivalency((BLangErrorVarRef) variableReference, rhsField.type, rhsPos, data); } else if (variableReference.getKind() == NodeKind.SIMPLE_VARIABLE_REF) { - Name varName = names.fromIdNode(((BLangSimpleVarRef) variableReference).variableName); + Name varName = Names.fromIdNode(((BLangSimpleVarRef) variableReference).variableName); if (varName == Names.IGNORE) { continue; } @@ -2545,7 +2543,7 @@ private void checkArrayVarRefEquivalency(Location pos, BLangTupleVarRef target, checkErrorVarRefEquivalency(errorVarRef, souceElementType, rhsPos, data); } else if (expression.getKind() == NodeKind.SIMPLE_VARIABLE_REF) { BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) expression; - Name varName = names.fromIdNode(simpleVarRef.variableName); + Name varName = Names.fromIdNode(simpleVarRef.variableName); if (varName == Names.IGNORE) { continue; } @@ -2613,7 +2611,7 @@ private void checkTupleVarRefEquivalency(Location pos, BLangTupleVarRef target, checkErrorVarRefEquivalency(errorVarRef, sourceType, rhsPos, data); } else if (varRefExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) { BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) varRefExpr; - Name varName = names.fromIdNode(simpleVarRef.variableName); + Name varName = Names.fromIdNode(simpleVarRef.variableName); if (varName == Names.IGNORE) { continue; } @@ -2768,7 +2766,7 @@ private void checkConstantAssignment(BLangExpression varRef, AnalyzerData data) return; } - Name varName = names.fromIdNode(simpleVarRef.variableName); + Name varName = Names.fromIdNode(simpleVarRef.variableName); if (!Names.IGNORE.equals(varName) && currentEnv.enclInvokable != currentEnv.enclPkg.initFunction) { if ((simpleVarRef.symbol.flags & Flags.FINAL) == Flags.FINAL) { if ((simpleVarRef.symbol.flags & Flags.SERVICE) == Flags.SERVICE) { @@ -3048,9 +3046,9 @@ public void visit(BLangMappingMatchPattern mappingMatchPattern, AnalyzerData dat for (BLangFieldMatchPattern fieldMatchPattern : mappingMatchPattern.fieldMatchPatterns) { analyzeNode(fieldMatchPattern, data); - Name fieldName = names.fromIdNode(fieldMatchPattern.fieldName); + Name fieldName = Names.fromIdNode(fieldMatchPattern.fieldName); BVarSymbol fieldSymbol = new BVarSymbol(0, fieldName, - names.originalNameFromIdNode(fieldMatchPattern.fieldName), + Names.originalNameFromIdNode(fieldMatchPattern.fieldName), currentEnv.enclPkg.symbol.pkgID, fieldMatchPattern.matchPattern.getBType(), recordSymbol, fieldMatchPattern.pos, COMPILED_SOURCE); @@ -3340,7 +3338,7 @@ public void visit(BLangListBindingPattern listBindingPattern, AnalyzerData data) public void visit(BLangRestBindingPattern restBindingPattern, AnalyzerData data) { SymbolEnv currentEnv = data.env; Name name = new Name(restBindingPattern.variableName.value); - Name origName = names.originalNameFromIdNode(restBindingPattern.variableName); + Name origName = Names.originalNameFromIdNode(restBindingPattern.variableName); BSymbol symbol = symResolver.lookupSymbolInMainSpace(currentEnv, name); if (symbol == symTable.notFoundSymbol) { symbol = new BVarSymbol(0, name, origName, currentEnv.enclPkg.packageID, restBindingPattern.getBType(), @@ -3584,9 +3582,9 @@ public void visit(BLangMappingBindingPattern mappingBindingPattern, AnalyzerData for (BLangFieldBindingPattern fieldBindingPattern : mappingBindingPattern.fieldBindingPatterns) { fieldBindingPattern.accept(this, data); - Name fieldName = names.fromIdNode(fieldBindingPattern.fieldName); + Name fieldName = Names.fromIdNode(fieldBindingPattern.fieldName); BVarSymbol fieldSymbol = new BVarSymbol(0, fieldName, - names.originalNameFromIdNode(fieldBindingPattern.fieldName), + Names.originalNameFromIdNode(fieldBindingPattern.fieldName), currentEnv.enclPkg.symbol.pkgID, fieldBindingPattern.bindingPattern.getBType(), recordSymbol, fieldBindingPattern.pos, COMPILED_SOURCE); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java index 8772c4ca4f0b..19867718be5f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java @@ -222,7 +222,6 @@ public class SymbolEnter extends BLangNodeVisitor { private static final CompilerContext.Key SYMBOL_ENTER_KEY = new CompilerContext.Key<>(); private final SymbolTable symTable; - private final Names names; private final SymbolResolver symResolver; private final BLangDiagnosticLog dlog; private final Types types; @@ -261,7 +260,6 @@ public SymbolEnter(CompilerContext context) { context.put(SYMBOL_ENTER_KEY, this); this.symTable = SymbolTable.getInstance(context); - this.names = Names.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); this.dlog = BLangDiagnosticLog.getInstance(context); this.types = Types.getInstance(context); @@ -388,12 +386,12 @@ private void defineConstructs(BLangPackage pkgNode, SymbolEnv pkgEnv) { for (BLangImportPackage unresolvedPkg : importHolder.unresolved) { BPackageSymbol importSymbol = importHolder.resolved.symbol; - Name resolvedPkgAlias = names.fromIdNode(importHolder.resolved.alias); - Name unresolvedPkgAlias = names.fromIdNode(unresolvedPkg.alias); + Name resolvedPkgAlias = Names.fromIdNode(importHolder.resolved.alias); + Name unresolvedPkgAlias = Names.fromIdNode(unresolvedPkg.alias); // check if its the same import or has the same alias. if (!Names.IGNORE.equals(unresolvedPkgAlias) && unresolvedPkgAlias.equals(resolvedPkgAlias) - && importSymbol.compUnit.equals(names.fromIdNode(unresolvedPkg.compUnit))) { + && importSymbol.compUnit.equals(Names.fromIdNode(unresolvedPkg.compUnit))) { if (isSameImport(unresolvedPkg, importSymbol)) { dlog.error(unresolvedPkg.pos, DiagnosticErrorCode.REDECLARED_IMPORT_MODULE, unresolvedPkg.getQualifiedPackageName()); @@ -406,7 +404,7 @@ private void defineConstructs(BLangPackage pkgNode, SymbolEnv pkgEnv) { unresolvedPkg.symbol = pkgSymbol; // and define it in the current package scope BPackageSymbol symbol = dupPackageSymbolAndSetCompUnit(pkgSymbol, - names.fromIdNode(unresolvedPkg.compUnit)); + Names.fromIdNode(unresolvedPkg.compUnit)); symbol.scope = pkgSymbol.scope; unresolvedPkg.symbol = symbol; pkgEnv.scope.define(unresolvedPkgAlias, symbol); @@ -836,7 +834,7 @@ private void defineReferencedClassFields(BLangClassDefinition classDefinition, S if (field.symbol.type == symTable.semanticError) { continue; } - objType.fields.put(field.name.value, new BField(names.fromIdNode(field.name), field.pos, field.symbol)); + objType.fields.put(field.name.value, new BField(Names.fromIdNode(field.name), field.pos, field.symbol)); } classDefinition.referencedFields.addAll(referencedFields); @@ -862,8 +860,8 @@ public void visit(BLangObjectConstructorExpression objectCtorExpression) { public void visit(BLangClassDefinition classDefinition) { EnumSet flags = EnumSet.copyOf(classDefinition.flagSet); boolean isPublicType = flags.contains(Flag.PUBLIC); - Name className = names.fromIdNode(classDefinition.name); - Name classOrigName = names.originalNameFromIdNode(classDefinition.name); + Name className = Names.fromIdNode(classDefinition.name); + Name classOrigName = Names.originalNameFromIdNode(classDefinition.name); BClassSymbol tSymbol = Symbols.createClassSymbol(Flags.asMask(flags), className, env.enclPkg.symbol.pkgID, null, @@ -936,8 +934,8 @@ public void visit(BLangClassDefinition classDefinition) { @Override public void visit(BLangAnnotation annotationNode) { - Name annotName = names.fromIdNode(annotationNode.name); - Name annotOrigName = names.originalNameFromIdNode(annotationNode.name); + Name annotName = Names.fromIdNode(annotationNode.name); + Name annotOrigName = Names.originalNameFromIdNode(annotationNode.name); BAnnotationSymbol annotationSymbol = Symbols.createAnnotationSymbol(Flags.asMask(annotationNode.flagSet), annotationNode.getAttachPoints(), annotName, annotOrigName, @@ -978,10 +976,10 @@ private boolean isNullOrEmpty(String s) { @Override public void visit(BLangImportPackage importPkgNode) { - Name pkgAlias = names.fromIdNode(importPkgNode.alias); + Name pkgAlias = Names.fromIdNode(importPkgNode.alias); if (!Names.IGNORE.equals(pkgAlias)) { BSymbol importSymbol = - symResolver.resolvePrefixSymbol(env, pkgAlias, names.fromIdNode(importPkgNode.compUnit)); + symResolver.resolvePrefixSymbol(env, pkgAlias, Names.fromIdNode(importPkgNode.compUnit)); if (importSymbol != symTable.notFoundSymbol) { if (isSameImport(importPkgNode, (BPackageSymbol) importSymbol)) { dlog.error(importPkgNode.pos, DiagnosticErrorCode.REDECLARED_IMPORT_MODULE, @@ -1007,9 +1005,9 @@ public void visit(BLangImportPackage importPkgNode) { // 2b. different project // 3. import module-name if (!isNullOrEmpty(importPkgNode.orgName.value)) { - orgName = names.fromIdNode(importPkgNode.orgName); + orgName = Names.fromIdNode(importPkgNode.orgName); if (!isNullOrEmpty(importPkgNode.version.value)) { - version = names.fromIdNode(importPkgNode.version); + version = Names.fromIdNode(importPkgNode.version); } else { // TODO We are removing the version in the import declaration anyway if (projectAPIInitiatedCompilation) { @@ -1033,7 +1031,7 @@ public void visit(BLangImportPackage importPkgNode) { } List nameComps = importPkgNode.pkgNameComps.stream() - .map(identifier -> names.fromIdNode(identifier)) + .map(identifier -> Names.fromIdNode(identifier)) .toList(); Name moduleName = new Name(nameComps.stream().map(Name::getValue).collect(Collectors.joining("."))); @@ -1123,7 +1121,7 @@ public void visit(BLangImportPackage importPkgNode) { // get a copy of the package symbol, add compilation unit info to it, // and define it in the current package scope - BPackageSymbol symbol = dupPackageSymbolAndSetCompUnit(pkgSymbol, names.fromIdNode(importPkgNode.compUnit)); + BPackageSymbol symbol = dupPackageSymbolAndSetCompUnit(pkgSymbol, Names.fromIdNode(importPkgNode.compUnit)); if (!Names.IGNORE.equals(pkgAlias)) { symbol.importPrefix = pkgAlias; } @@ -1192,12 +1190,12 @@ public void defineXMLNS(SymbolEnv symEnv, BLangXMLNS xmlnsNode) { xmlnsNode.prefix.value = XMLConstants.DEFAULT_NS_PREFIX; } - Name prefix = names.fromIdNode(xmlnsNode.prefix); + Name prefix = Names.fromIdNode(xmlnsNode.prefix); Location nsSymbolPos = prefix.value.isEmpty() ? xmlnsNode.pos : xmlnsNode.prefix.pos; BLangIdentifier compUnit = xmlnsNode.compUnit; BXMLNSSymbol xmlnsSymbol = Symbols.createXMLNSSymbol(prefix, nsURI, symEnv.enclPkg.symbol.pkgID, symEnv.scope.owner, nsSymbolPos, - getOrigin(prefix), compUnit != null ? names.fromIdNode(compUnit) : null); + getOrigin(prefix), compUnit != null ? Names.fromIdNode(compUnit) : null); xmlnsNode.symbol = xmlnsSymbol; // First check for package-imports with the same alias. @@ -1648,7 +1646,7 @@ public void visit(BLangTypeDefinition typeDefinition) { typeDefinition.setPrecedence(this.typePrecedence++); BSymbol typeDefSymbol = Symbols.createTypeDefinitionSymbol(Flags.asMask(typeDefinition.flagSet), - names.fromIdNode(typeDefinition.name), env.enclPkg.packageID, definedType, env.scope.owner, + Names.fromIdNode(typeDefinition.name), env.enclPkg.packageID, definedType, env.scope.owner, typeDefinition.name.pos, getOrigin(typeDefinition.name.value)); typeDefSymbol.markdownDocumentation = getMarkdownDocAttachment(typeDefinition.markdownDocumentationAttachment); BTypeSymbol typeSymbol = new BTypeSymbol(SymTag.TYPE_REF, typeDefSymbol.flags, typeDefSymbol.name, @@ -1661,8 +1659,8 @@ public void visit(BLangTypeDefinition typeDefinition) { //todo remove after type ref introduced to runtime if (definedType.tsymbol.name == Names.EMPTY) { isLabel = false; - definedType.tsymbol.name = names.fromIdNode(typeDefinition.name); - definedType.tsymbol.originalName = names.originalNameFromIdNode(typeDefinition.name); + definedType.tsymbol.name = Names.fromIdNode(typeDefinition.name); + definedType.tsymbol.originalName = Names.originalNameFromIdNode(typeDefinition.name); definedType.tsymbol.flags |= typeDefSymbol.flags; definedType.tsymbol.markdownDocumentation = typeDefSymbol.markdownDocumentation; @@ -1838,12 +1836,12 @@ private BEnumSymbol createEnumSymbol(BLangTypeDefinition typeDefinition, BType d } BEnumSymbol enumSymbol = new BEnumSymbol(enumMembers, Flags.asMask(typeDefinition.flagSet), - names.fromIdNode(typeDefinition.name), names.fromIdNode(typeDefinition.name), + Names.fromIdNode(typeDefinition.name), Names.fromIdNode(typeDefinition.name), env.enclPkg.symbol.pkgID, definedType, env.scope.owner, typeDefinition.pos, SOURCE); - enumSymbol.name = names.fromIdNode(typeDefinition.name); - enumSymbol.originalName = names.fromIdNode(typeDefinition.name); + enumSymbol.name = Names.fromIdNode(typeDefinition.name); + enumSymbol.originalName = Names.fromIdNode(typeDefinition.name); enumSymbol.flags |= Flags.asMask(typeDefinition.flagSet); enumSymbol.markdownDocumentation = getMarkdownDocAttachment(typeDefinition.markdownDocumentationAttachment); @@ -1878,7 +1876,7 @@ private void defineTypeInMainScope(BTypeSymbol typeDefSymbol, BLangTypeDefinitio } private BType defineSymbolForCyclicTypeDefinition(BLangTypeDefinition typeDef, SymbolEnv env) { - Name newTypeDefName = names.fromIdNode(typeDef.name); + Name newTypeDefName = Names.fromIdNode(typeDef.name); BTypeSymbol typeDefSymbol; BType newTypeNode; @@ -1904,7 +1902,7 @@ private BType defineSymbolForCyclicTypeDefinition(BLangTypeDefinition typeDef, S private BType getCyclicDefinedType(BLangTypeDefinition typeDef, SymbolEnv env) { // Get cyclic type reference from main scope - BSymbol foundSym = symResolver.lookupSymbolInMainSpace(env, names.fromIdNode(typeDef.name)); + BSymbol foundSym = symResolver.lookupSymbolInMainSpace(env, Names.fromIdNode(typeDef.name)); BType newTypeNode = foundSym.type; // Resolver only manages to resolve members as they are defined as user defined types. @@ -2302,9 +2300,9 @@ public void visit(BLangConstant constant) { public BConstantSymbol getConstantSymbol(BLangConstant constant) { // Create a new constant symbol. - Name name = names.fromIdNode(constant.name); + Name name = Names.fromIdNode(constant.name); PackageID pkgID = env.enclPkg.symbol.pkgID; - return new BConstantSymbol(Flags.asMask(constant.flagSet), name, names.originalNameFromIdNode(constant.name), + return new BConstantSymbol(Flags.asMask(constant.flagSet), name, Names.originalNameFromIdNode(constant.name), pkgID, symTable.semanticError, symTable.noType, env.scope.owner, constant.name.pos, getOrigin(name)); } @@ -2324,8 +2322,8 @@ public void visit(BLangSimpleVariable varNode) { } } - Name varName = names.fromIdNode(varNode.name); - Name varOrigName = names.originalNameFromIdNode(varNode.name); + Name varName = Names.fromIdNode(varNode.name); + Name varOrigName = Names.originalNameFromIdNode(varNode.name); if (varName == Names.IGNORE || varNode.symbol != null) { return; } @@ -2563,7 +2561,7 @@ boolean checkTypeAndVarCountConsistency(BLangTupleVariable varNode, BTupleType t if (var.getKind() == NodeKind.VARIABLE) { // '_' is allowed in tuple variables. Not allowed if all variables are named as '_' BLangSimpleVariable simpleVar = (BLangSimpleVariable) var; - Name varName = names.fromIdNode(simpleVar.name); + Name varName = Names.fromIdNode(simpleVar.name); if (varName == Names.IGNORE) { ignoredCount++; simpleVar.setBType(symTable.anyType); @@ -2907,9 +2905,9 @@ private BRecordType createSameTypedFieldsRecordType(BLangRecordVariable recordVa //TODO check below field position LinkedHashMap fields = new LinkedHashMap<>(); for (BLangRecordVariable.BLangRecordVariableKeyValue bLangRecordVariableKeyValue : recordVar.variableList) { - Name fieldName = names.fromIdNode(bLangRecordVariableKeyValue.key); + Name fieldName = Names.fromIdNode(bLangRecordVariableKeyValue.key); BField bField = new BField(fieldName, recordVar.pos, - new BVarSymbol(0, fieldName, names.originalNameFromIdNode(bLangRecordVariableKeyValue.key), + new BVarSymbol(0, fieldName, Names.originalNameFromIdNode(bLangRecordVariableKeyValue.key), env.enclPkg.symbol.pkgID, fieldType, recordSymbol, recordVar.pos, SOURCE)); fields.put(fieldName.getValue(), bField); } @@ -2939,7 +2937,7 @@ private boolean defineVariableList(BLangRecordVariable recordVar, BRecordType re if (value.getKind() == NodeKind.VARIABLE) { // '_' is allowed in record variables. Not allowed if all variables are named as '_' BLangSimpleVariable simpleVar = (BLangSimpleVariable) value; - Name varName = names.fromIdNode(simpleVar.name); + Name varName = Names.fromIdNode(simpleVar.name); if (varName == Names.IGNORE) { ignoredCount++; simpleVar.setBType(symTable.anyType); @@ -3308,7 +3306,7 @@ boolean validateErrorVariable(BLangErrorVariable errorVariable, SymbolEnv env) { BLangVariable errorCause = errorVariable.cause; if (errorCause != null) { if (errorCause.getKind() == NodeKind.VARIABLE && - names.fromIdNode(((BLangSimpleVariable) errorCause).name) == Names.IGNORE) { + Names.fromIdNode(((BLangSimpleVariable) errorCause).name) == Names.IGNORE) { dlog.error(errorCause.pos, DiagnosticErrorCode.CANNOT_USE_WILDCARD_BINDING_PATTERN_FOR_ERROR_CAUSE); return false; @@ -3871,7 +3869,7 @@ public void defineFieldsOfClassDef(BLangClassDefinition classDefinition, SymbolE if (field.symbol.type == symTable.semanticError) { continue; } - objType.fields.put(field.name.value, new BField(names.fromIdNode(field.name), field.pos, field.symbol)); + objType.fields.put(field.name.value, new BField(Names.fromIdNode(field.name), field.pos, field.symbol)); } } @@ -3911,7 +3909,7 @@ private void resolveFields(BStructureType structureType, BLangStructureTypeNode .filter(field -> field.symbol.type != symTable.semanticError) // filter out erroneous fields .map((BLangSimpleVariable field) -> { field.symbol.isDefaultable = field.expr != null; - return new BField(names.fromIdNode(field.name), field.pos, field.symbol); + return new BField(Names.fromIdNode(field.name), field.pos, field.symbol); }) .collect(getFieldCollector()); } @@ -4016,7 +4014,7 @@ private void defineReferencedFields(BStructureType structureType, BLangStructure if (field.symbol.type == symTable.semanticError) { continue; } - structureType.fields.put(field.name.value, new BField(names.fromIdNode(field.name), field.pos, + structureType.fields.put(field.name.value, new BField(Names.fromIdNode(field.name), field.pos, field.symbol)); } } @@ -4228,7 +4226,7 @@ private void populateImmutableTypeFieldsAndMembers(List typ SymbolEnv typeDefEnv = SymbolEnv.createTypeEnv(typeDef.typeNode, typeDef.symbol.scope, pkgEnv); ImmutableTypeCloner.defineUndefinedImmutableFields(typeDef, types, typeDefEnv, symTable, - anonymousModelHelper, names); + anonymousModelHelper); if (nodeKind != NodeKind.OBJECT_TYPE) { continue; @@ -4238,7 +4236,7 @@ private void populateImmutableTypeFieldsAndMembers(List typ BObjectType mutableObjectType = immutableObjectType.mutableType; ImmutableTypeCloner.defineObjectFunctions((BObjectTypeSymbol) immutableObjectType.tsymbol, - (BObjectTypeSymbol) mutableObjectType.tsymbol, names, symTable); + (BObjectTypeSymbol) mutableObjectType.tsymbol, symTable); } } @@ -4302,7 +4300,7 @@ private void validateFieldsAndSetReadOnlyType(List typeDefNodes, Symb if (!types.isInherentlyImmutableType(type)) { field.type = field.symbol.type = ImmutableTypeCloner.getImmutableIntersectionType( pos, types, type, typeDefEnv, symTable, - anonymousModelHelper, names, flagSet); + anonymousModelHelper, flagSet); } @@ -4374,7 +4372,7 @@ private void setReadOnlynessOfClassDef(BLangClassDefinition classDef, SymbolEnv } ImmutableTypeCloner.markFieldsAsImmutable(classDef, pkgEnv, objectType, types, anonymousModelHelper, - symTable, names, pos); + symTable, pos); } else if (classDef.isObjectContructorDecl) { Collection fields = objectType.fields.values(); if (fields.isEmpty()) { @@ -4835,7 +4833,7 @@ private void validateFunctionsAttachedToObject(BLangFunction funcNode, BInvokabl if (funcNode.getKind() == NodeKind.RESOURCE_FUNC) { attachedFunc = createResourceFunction(funcNode, funcSymbol, funcType); } else { - attachedFunc = new BAttachedFunction(names.fromIdNode(funcNode.name), funcSymbol, funcType, funcNode.pos); + attachedFunc = new BAttachedFunction(Names.fromIdNode(funcNode.name), funcSymbol, funcType, funcNode.pos); } validateRemoteFunctionAttachedToObject(funcNode, objectSymbol); @@ -4855,7 +4853,7 @@ private BAttachedFunction createResourceFunction(BLangFunction funcNode, BInvoka BInvokableType funcType) { BObjectTypeSymbol objectTypeSymbol = (BObjectTypeSymbol) funcNode.receiver.getBType().tsymbol; BLangResourceFunction resourceFunction = (BLangResourceFunction) funcNode; - Name accessor = names.fromIdNode(resourceFunction.methodName); + Name accessor = Names.fromIdNode(resourceFunction.methodName); List pathParamSymbols = resourceFunction.pathParams.stream() .map(p -> { @@ -4870,7 +4868,7 @@ private BAttachedFunction createResourceFunction(BLangFunction funcNode, BInvoka restPathParamSym.kind = SymbolKind.PATH_REST_PARAMETER; } - BResourceFunction bResourceFunction = new BResourceFunction(names.fromIdNode(funcNode.name), funcSymbol, + BResourceFunction bResourceFunction = new BResourceFunction(Names.fromIdNode(funcNode.name), funcSymbol, funcType, accessor, pathParamSymbols, restPathParamSym, funcNode.pos); List pathSegments = resourceFunction.resourcePathSegments; @@ -4989,11 +4987,11 @@ private Name getFuncSymbolName(BLangFunction funcNode) { return Names.fromString(Symbols.getAttachedFuncSymbolName( funcNode.receiver.getBType().tsymbol.name.value, funcNode.name.value)); } - return names.fromIdNode(funcNode.name); + return Names.fromIdNode(funcNode.name); } private Name getFuncSymbolOriginalName(BLangFunction funcNode) { - return names.originalNameFromIdNode(funcNode.name); + return Names.originalNameFromIdNode(funcNode.name); } private Name getFieldSymbolName(BLangSimpleVariable receiver, BLangSimpleVariable variable) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolResolver.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolResolver.java index d4c568973ab1..92ad8e9d7423 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolResolver.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolResolver.java @@ -152,7 +152,6 @@ public class SymbolResolver extends BLangNodeTransformer(); private final SymbolTable symTable; - private final Names names; private final BLangDiagnosticLog dlog; private final Types types; @@ -177,7 +176,6 @@ public SymbolResolver(CompilerContext context) { context.put(SYMBOL_RESOLVER_KEY, this); this.symTable = SymbolTable.getInstance(context); - this.names = Names.getInstance(context); this.dlog = BLangDiagnosticLog.getInstance(context); this.types = Types.getInstance(context); this.symbolEnter = SymbolEnter.getInstance(context); @@ -1198,8 +1196,8 @@ public BType transform(BLangArrayType arrayTypeNode, AnalyzerData data) { } BLangSimpleVarRef sizeReference = (BLangSimpleVarRef) size; - Name pkgAlias = names.fromIdNode(sizeReference.pkgAlias); - Name typeName = names.fromIdNode(sizeReference.variableName); + Name pkgAlias = Names.fromIdNode(sizeReference.pkgAlias); + Name typeName = Names.fromIdNode(sizeReference.variableName); BSymbol sizeSymbol = lookupMainSpaceSymbolInPackage(size.pos, data.env, pkgAlias, typeName); sizeReference.symbol = sizeSymbol; @@ -1599,9 +1597,9 @@ public BType transform(BLangUserDefinedType userDefinedTypeNode, AnalyzerData da // 3) If the symbol is not found, then lookup in the root scope. e.g. for types such as 'error' BLangIdentifier pkgAliasIdentifier = userDefinedTypeNode.pkgAlias; - Name pkgAlias = names.fromIdNode(pkgAliasIdentifier); + Name pkgAlias = Names.fromIdNode(pkgAliasIdentifier); BLangIdentifier typeNameIdentifier = userDefinedTypeNode.typeName; - Name typeName = names.fromIdNode(typeNameIdentifier); + Name typeName = Names.fromIdNode(typeNameIdentifier); BSymbol symbol = symTable.notFoundSymbol; SymbolEnv env = data.env; @@ -1767,7 +1765,7 @@ public ParameterizedTypeInfo getTypedescParamValueType(List } if (defaultValueExprKind == NodeKind.SIMPLE_VARIABLE_REF) { - Name varName = names.fromIdNode(((BLangSimpleVarRef) param.expr).variableName); + Name varName = Names.fromIdNode(((BLangSimpleVarRef) param.expr).variableName); BSymbol typeRefSym = lookupSymbolInMainSpace(data.env, varName); if (typeRefSym != symTable.notFoundSymbol) { return new ParameterizedTypeInfo(typeRefSym.type, i); @@ -2214,7 +2212,7 @@ private BSymbol resolveOperator(ScopeEntry entry, List typeList) { } public BType visitBuiltInTypeNode(BLangType typeNode, AnalyzerData data, TypeKind typeKind) { - Name typeName = names.fromTypeKind(typeKind); + Name typeName = Names.fromTypeKind(typeKind); BSymbol typeSymbol = lookupMemberSymbol(typeNode.pos, symTable.rootScope, data.env, typeName, SymTag.TYPE); if (typeSymbol == symTable.notFoundSymbol) { dlog.error(typeNode.pos, data.diagCode, typeName); @@ -2406,7 +2404,7 @@ private BType computeIntersectionType(BLangIntersectionTypeNode intersectionType } return ImmutableTypeCloner.getImmutableIntersectionType(intersectionTypeNode.pos, types, potentialIntersectionType, - data.env, symTable, anonymousModelHelper, names, flagSet); + data.env, symTable, anonymousModelHelper, flagSet); } public BIntersectionType createIntersectionErrorType(BErrorType intersectionErrorType, diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java index 78f9d04fde2e..4dbe6f2d82c2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java @@ -238,7 +238,6 @@ public class TypeChecker extends SimpleBLangNodeAnalyzer key) { context.put(key, this); - this.names = Names.getInstance(context); this.symTable = SymbolTable.getInstance(context); this.symbolEnter = SymbolEnter.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); @@ -915,7 +912,7 @@ public BType setLiteralValueAndGetType(BLangLiteral literalExpr, BType expType, BArrayState.CLOSED); if (Symbols.isFlagOn(expectedType.flags, Flags.READONLY)) { literalType = ImmutableTypeCloner.getEffectiveImmutableType(literalExpr.pos, types, - literalType, data.env, symTable, anonymousModelHelper, names); + literalType, data.env, symTable, anonymousModelHelper); } if (expectedType.tag == TypeTags.ARRAY) { @@ -1960,15 +1957,15 @@ private BType getListConstructorCompatibleNonUnionType(BType type, AnalyzerData case TypeTags.JSON: return !Symbols.isFlagOn(referredType.flags, Flags.READONLY) ? symTable.arrayJsonType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.arrayJsonType, - data.env, symTable, anonymousModelHelper, names); + data.env, symTable, anonymousModelHelper); case TypeTags.ANYDATA: return !Symbols.isFlagOn(referredType.flags, Flags.READONLY) ? symTable.arrayAnydataType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.arrayAnydataType, - data.env, symTable, anonymousModelHelper, names); + data.env, symTable, anonymousModelHelper); case TypeTags.ANY: return !Symbols.isFlagOn(referredType.flags, Flags.READONLY) ? symTable.arrayAllType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.arrayAllType, data.env, - symTable, anonymousModelHelper, names); + symTable, anonymousModelHelper); } return symTable.semanticError; } @@ -2649,15 +2646,15 @@ private BType getMappingConstructorCompatibleNonUnionType(BType type, AnalyzerDa case TypeTags.JSON: return !Symbols.isFlagOn(type.flags, Flags.READONLY) ? symTable.mapJsonType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.mapJsonType, data.env, - symTable, anonymousModelHelper, names); + symTable, anonymousModelHelper); case TypeTags.ANYDATA: return !Symbols.isFlagOn(type.flags, Flags.READONLY) ? symTable.mapAnydataType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.mapAnydataType, - data.env, symTable, anonymousModelHelper, names); + data.env, symTable, anonymousModelHelper); case TypeTags.ANY: return !Symbols.isFlagOn(type.flags, Flags.READONLY) ? symTable.mapAllType : ImmutableTypeCloner.getEffectiveImmutableType(null, types, symTable.mapAllType, data.env, - symTable, anonymousModelHelper, names); + symTable, anonymousModelHelper); case TypeTags.INTERSECTION: return ((BIntersectionType) type).effectiveType; case TypeTags.TYPEREFDESC: @@ -2893,7 +2890,7 @@ public void visit(BLangWorkerFlushExpr workerFlushExpr, AnalyzerData data) { @Override public void visit(BLangWorkerSyncSendExpr syncSendExpr, AnalyzerData data) { - BSymbol symbol = symResolver.lookupSymbolInMainSpace(data.env, names.fromIdNode(syncSendExpr.workerIdentifier)); + BSymbol symbol = symResolver.lookupSymbolInMainSpace(data.env, Names.fromIdNode(syncSendExpr.workerIdentifier)); if (symTable.notFoundSymbol.equals(symbol)) { syncSendExpr.workerType = symTable.semanticError; @@ -2927,7 +2924,7 @@ public void visit(BLangWorkerSyncSendExpr syncSendExpr, AnalyzerData data) { @Override public void visit(BLangWorkerAsyncSendExpr asyncSendExpr, AnalyzerData data) { BSymbol symbol = - symResolver.lookupSymbolInMainSpace(data.env, names.fromIdNode(asyncSendExpr.workerIdentifier)); + symResolver.lookupSymbolInMainSpace(data.env, Names.fromIdNode(asyncSendExpr.workerIdentifier)); if (symTable.notFoundSymbol.tag == symbol.tag) { asyncSendExpr.workerType = symTable.semanticError; @@ -3091,7 +3088,7 @@ private boolean fieldsCompatibleWithRecord(HashSet fieldNames, BRecordTy @Override public void visit(BLangWorkerReceive workerReceiveExpr, AnalyzerData data) { BSymbol symbol = - symResolver.lookupSymbolInMainSpace(data.env, names.fromIdNode(workerReceiveExpr.workerIdentifier)); + symResolver.lookupSymbolInMainSpace(data.env, Names.fromIdNode(workerReceiveExpr.workerIdentifier)); // TODO Need to remove this cached env workerReceiveExpr.env = data.env; @@ -3127,7 +3124,7 @@ private boolean workerExists(SymbolEnv env, String workerName) { @Override public void visit(BLangConstRef constRef, AnalyzerData data) { constRef.symbol = symResolver.lookupMainSpaceSymbolInPackage(constRef.pos, data.env, - names.fromIdNode(constRef.pkgAlias), names.fromIdNode(constRef.variableName)); + Names.fromIdNode(constRef.pkgAlias), Names.fromIdNode(constRef.variableName)); types.setImplicitCastExpr(constRef, constRef.getBType(), data.expType); data.resultType = constRef.getBType(); @@ -3139,13 +3136,13 @@ public void visit(BLangSimpleVarRef varRefExpr, AnalyzerData data) { BType actualType = symTable.semanticError; BLangIdentifier identifier = varRefExpr.variableName; - Name varName = names.fromIdNode(identifier); + Name varName = Names.fromIdNode(identifier); if (varName == Names.IGNORE) { varRefExpr.setBType(this.symTable.anyType); // If the variable name is a wildcard('_'), the symbol should be ignorable. varRefExpr.symbol = new BVarSymbol(0, true, varName, - names.originalNameFromIdNode(identifier), + Names.originalNameFromIdNode(identifier), data.env.enclPkg.symbol.pkgID, varRefExpr.getBType(), data.env.scope.owner, varRefExpr.pos, VIRTUAL); @@ -3154,7 +3151,7 @@ public void visit(BLangSimpleVarRef varRefExpr, AnalyzerData data) { } Name compUnitName = getCurrentCompUnit(varRefExpr); - BSymbol pkgSymbol = symResolver.resolvePrefixSymbol(data.env, names.fromIdNode(varRefExpr.pkgAlias), + BSymbol pkgSymbol = symResolver.resolvePrefixSymbol(data.env, Names.fromIdNode(varRefExpr.pkgAlias), compUnitName); varRefExpr.pkgSymbol = pkgSymbol; if (pkgSymbol == symTable.notFoundSymbol) { @@ -3166,7 +3163,7 @@ public void visit(BLangSimpleVarRef varRefExpr, AnalyzerData data) { actualType = symTable.stringType; } else if (pkgSymbol != symTable.notFoundSymbol) { BSymbol symbol = symResolver.lookupMainSpaceSymbolInPackage(varRefExpr.pos, data.env, - names.fromIdNode(varRefExpr.pkgAlias), varName); + Names.fromIdNode(varRefExpr.pkgAlias), varName); // if no symbol, check same for object attached function BLangType enclType = data.env.enclType; if (symbol == symTable.notFoundSymbol && enclType != null && enclType.getBType().tsymbol.scope != null) { @@ -3265,9 +3262,9 @@ public void visit(BLangRecordVarRef varRefExpr, AnalyzerData data) { continue; } BVarSymbol bVarSymbol = (BVarSymbol) bLangVarReference.symbol; - BField field = new BField(names.fromIdNode(recordRefField.variableName), varRefExpr.pos, - new BVarSymbol(0, names.fromIdNode(recordRefField.variableName), - names.originalNameFromIdNode(recordRefField.variableName), + BField field = new BField(Names.fromIdNode(recordRefField.variableName), varRefExpr.pos, + new BVarSymbol(0, Names.fromIdNode(recordRefField.variableName), + Names.originalNameFromIdNode(recordRefField.variableName), data.env.enclPkg.symbol.pkgID, bVarSymbol.type, recordSymbol, varRefExpr.pos, SOURCE)); fields.put(field.name.value, field); @@ -3559,9 +3556,9 @@ private void checkFieldBasedAccess(BLangFieldBasedAccess fieldAccessExpr, boolea return; } actualType = checkOptionalFieldAccessExpr(fieldAccessExpr, varRefType, - names.fromIdNode(fieldAccessExpr.field), data); + Names.fromIdNode(fieldAccessExpr.field), data); } else { - actualType = checkFieldAccessExpr(fieldAccessExpr, varRefType, names.fromIdNode(fieldAccessExpr.field), + actualType = checkFieldAccessExpr(fieldAccessExpr, varRefType, Names.fromIdNode(fieldAccessExpr.field), data); if (actualType != symTable.semanticError && @@ -4203,7 +4200,7 @@ private void checkActionInvocation(BLangInvocation.BLangActionInvocation aInv, B } private boolean invalidModuleAliasUsage(BLangInvocation invocation) { - Name pkgAlias = names.fromIdNode(invocation.pkgAlias); + Name pkgAlias = Names.fromIdNode(invocation.pkgAlias); if (pkgAlias != Names.EMPTY) { dlog.error(invocation.pos, DiagnosticErrorCode.PKG_ALIAS_NOT_ALLOWED_HERE); return true; @@ -4933,13 +4930,13 @@ private BRecordType getWaitForAllExprReturnType(BLangWaitForAllExpr waitExpr, fieldName = ((BLangSimpleVarRef) keyVal.valueExpr).variableName; } - BSymbol symbol = symResolver.lookupSymbolInMainSpace(data.env, names.fromIdNode(fieldName)); + BSymbol symbol = symResolver.lookupSymbolInMainSpace(data.env, Names.fromIdNode(fieldName)); BType referredSymType = Types.getImpliedType(symbol.type); BType fieldType = referredSymType.tag == TypeTags.FUTURE ? ((BFutureType) referredSymType).constraint : symbol.type; - BField field = new BField(names.fromIdNode(keyVal.key), null, - new BVarSymbol(0, names.fromIdNode(keyVal.key), - names.originalNameFromIdNode(keyVal.key), + BField field = new BField(Names.fromIdNode(keyVal.key), null, + new BVarSymbol(0, Names.fromIdNode(keyVal.key), + Names.originalNameFromIdNode(keyVal.key), data.env.enclPkg.packageID, fieldType, null, keyVal.pos, VIRTUAL)); retType.fields.put(field.name.value, field); @@ -5044,7 +5041,7 @@ private void checkMissingReqFieldsForWait(BRecordType type, List()); + matchingBoundNonReadOnlyType, env, symTable, anonymousModelHelper, new HashSet<>()); } private BTupleType getMatchingTupleBoundType(BTupleType expType, SymbolEnv env, HashSet resolvedTypes) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeResolver.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeResolver.java index f104c90dfaaf..81b0c63c2891 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeResolver.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeResolver.java @@ -143,7 +143,6 @@ public class TypeResolver { private static final CompilerContext.Key TYPE_RESOLVER_KEY = new CompilerContext.Key<>(); private final SymbolTable symTable; - private final Names names; private final SymbolResolver symResolver; private final SymbolEnter symEnter; private final BLangDiagnosticLog dlog; @@ -175,7 +174,6 @@ public TypeResolver(CompilerContext context) { this.symTable = SymbolTable.getInstance(context); this.symEnter = SymbolEnter.getInstance(context); - this.names = Names.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); this.dlog = BLangDiagnosticLog.getInstance(context); this.types = Types.getInstance(context); @@ -318,7 +316,7 @@ public void defineFieldsOfClassDef(BLangClassDefinition classDefinition, SymbolE if (field.symbol.type == symTable.semanticError) { continue; } - objType.fields.put(field.name.value, new BField(names.fromIdNode(field.name), field.pos, field.symbol)); + objType.fields.put(field.name.value, new BField(Names.fromIdNode(field.name), field.pos, field.symbol)); } } @@ -348,8 +346,8 @@ private void defineRestFields(BLangTypeDefinition typeDef) { public void defineClassDef(BLangClassDefinition classDefinition, SymbolEnv env) { EnumSet flags = EnumSet.copyOf(classDefinition.flagSet); boolean isPublicType = flags.contains(Flag.PUBLIC); - Name className = names.fromIdNode(classDefinition.name); - Name classOrigName = names.originalNameFromIdNode(classDefinition.name); + Name className = Names.fromIdNode(classDefinition.name); + Name classOrigName = Names.originalNameFromIdNode(classDefinition.name); BClassSymbol tSymbol = Symbols.createClassSymbol(Flags.asMask(flags), className, env.enclPkg.symbol.pkgID, null, env.scope.owner, classDefinition.name.pos, @@ -925,8 +923,8 @@ private BType resolveTypeDesc(BLangArrayType td, ResolverData data) { } BLangSimpleVarRef sizeReference = (BLangSimpleVarRef) size; - Name pkgAlias = names.fromIdNode(sizeReference.pkgAlias); - Name typeName = names.fromIdNode(sizeReference.variableName); + Name pkgAlias = Names.fromIdNode(sizeReference.pkgAlias); + Name typeName = Names.fromIdNode(sizeReference.variableName); BSymbol sizeSymbol = symResolver.lookupMainSpaceSymbolInPackage(size.pos, symEnv, pkgAlias, typeName); @@ -1193,8 +1191,8 @@ public BType createInvokableType(List paramVars, for (BLangVariable paramNode : paramVars) { BLangSimpleVariable param = (BLangSimpleVariable) paramNode; - Name paramName = names.fromIdNode(param.name); - Name paramOrigName = names.originalNameFromIdNode(param.name); + Name paramName = Names.fromIdNode(param.name); + Name paramOrigName = Names.originalNameFromIdNode(param.name); if (paramName != Names.EMPTY) { if (paramNames.contains(paramName.value)) { dlog.error(param.name.pos, DiagnosticErrorCode.REDECLARED_SYMBOL, paramName.value); @@ -1232,7 +1230,7 @@ public BType createInvokableType(List paramVars, BLangIdentifier id = ((BLangSimpleVariable) restVariable).name; restVariable.setBType(restType); restParam = new BVarSymbol(Flags.asMask(restVariable.flagSet), - names.fromIdNode(id), names.originalNameFromIdNode(id), + Names.fromIdNode(id), Names.originalNameFromIdNode(id), env.enclPkg.symbol.pkgID, restType, env.scope.owner, restVariable.pos, BUILTIN); restVariable.symbol = restParam; } @@ -1503,7 +1501,7 @@ private void fillEffectiveType(BIntersectionType intersectionType, BIntersectionType immutableIntersectionType = ImmutableTypeCloner.getImmutableIntersectionType(intersectionType.tsymbol.pos, types, - intersectionType.effectiveType, env, symTable, anonymousModelHelper, names, + intersectionType.effectiveType, env, symTable, anonymousModelHelper, new HashSet<>()); intersectionType.effectiveType = immutableIntersectionType.effectiveType; } @@ -1523,8 +1521,8 @@ private BType resolveTypeDesc(BLangUserDefinedType td, ResolverData data) { // 3) If the symbol is not found, then lookup in the root scope. e.g. for types such as 'error' SymbolResolver.AnalyzerData analyzerData = new SymbolResolver.AnalyzerData(symEnv); - Name pkgAlias = names.fromIdNode(td.pkgAlias); - Name typeName = names.fromIdNode(td.typeName); + Name pkgAlias = Names.fromIdNode(td.pkgAlias); + Name typeName = Names.fromIdNode(td.typeName); BSymbol symbol = symTable.notFoundSymbol; // 1) Resolve ANNOTATION type if and only current scope inside ANNOTATION definition. @@ -1821,7 +1819,7 @@ private BType resolveTypeDesc(BLangStreamType td, ResolverData data) { } public BType visitBuiltInTypeNode(BLangType typeNode, SymbolResolver.AnalyzerData data, TypeKind typeKind) { - Name typeName = names.fromTypeKind(typeKind); + Name typeName = Names.fromTypeKind(typeKind); BSymbol typeSymbol = symResolver.lookupMemberSymbol(typeNode.pos, symTable.rootScope, data.env, typeName, SymTag.TYPE); if (typeSymbol == symTable.notFoundSymbol) { @@ -1852,7 +1850,7 @@ public BType defineTypeDefinition(BLangTypeDefinition typeDefinition, BType reso typeDefinition.setPrecedence(this.typePrecedence++); BSymbol typeDefSymbol = Symbols.createTypeDefinitionSymbol(Flags.asMask(typeDefinition.flagSet), - names.fromIdNode(typeDefinition.name), env.enclPkg.packageID, resolvedType, env.scope.owner, + Names.fromIdNode(typeDefinition.name), env.enclPkg.packageID, resolvedType, env.scope.owner, typeDefinition.name.pos, symEnter.getOrigin(typeDefinition.name.value)); typeDefSymbol.markdownDocumentation = symEnter.getMarkdownDocAttachment(typeDefinition.markdownDocumentationAttachment); @@ -1869,8 +1867,8 @@ public BType defineTypeDefinition(BLangTypeDefinition typeDefinition, BType reso //todo remove after type ref introduced to runtime if (resolvedType.tsymbol.name == Names.EMPTY) { - resolvedType.tsymbol.name = names.fromIdNode(typeDefinition.name); - resolvedType.tsymbol.originalName = names.originalNameFromIdNode(typeDefinition.name); + resolvedType.tsymbol.name = Names.fromIdNode(typeDefinition.name); + resolvedType.tsymbol.originalName = Names.originalNameFromIdNode(typeDefinition.name); resolvedType.tsymbol.flags |= typeDefSymbol.flags; resolvedType.tsymbol.markdownDocumentation = typeDefSymbol.markdownDocumentation; @@ -1955,12 +1953,12 @@ private BEnumSymbol createEnumSymbol(BLangTypeDefinition typeDefinition, BType d } BEnumSymbol enumSymbol = new BEnumSymbol(enumMembers, Flags.asMask(typeDefinition.flagSet), - names.fromIdNode(typeDefinition.name), names.fromIdNode(typeDefinition.name), + Names.fromIdNode(typeDefinition.name), Names.fromIdNode(typeDefinition.name), env.enclPkg.symbol.pkgID, definedType, env.scope.owner, typeDefinition.pos, SOURCE); - enumSymbol.name = names.fromIdNode(typeDefinition.name); - enumSymbol.originalName = names.fromIdNode(typeDefinition.name); + enumSymbol.name = Names.fromIdNode(typeDefinition.name); + enumSymbol.originalName = Names.fromIdNode(typeDefinition.name); enumSymbol.flags |= Flags.asMask(typeDefinition.flagSet); enumSymbol.markdownDocumentation = @@ -1991,8 +1989,8 @@ public void resolveConstant(SymbolEnv symEnv, Map modTable, B public void resolveXMLNS(SymbolEnv symEnv, BLangXMLNS xmlnsNode) { if (xmlnsNode.namespaceURI.getKind() == NodeKind.SIMPLE_VARIABLE_REF) { BLangSimpleVarRef varRef = (BLangSimpleVarRef) xmlnsNode.namespaceURI; - varRef.symbol = getSymbolOfVarRef(varRef.pos, symEnv, names.fromIdNode(varRef.pkgAlias), - names.fromIdNode(varRef.variableName)); + varRef.symbol = getSymbolOfVarRef(varRef.pos, symEnv, Names.fromIdNode(varRef.pkgAlias), + Names.fromIdNode(varRef.variableName)); } symEnter.defineXMLNS(symEnv, xmlnsNode); } @@ -2083,12 +2081,12 @@ private void defineConstant(SymbolEnv symEnv, Map modTable, B } if (resolvedType.tag == TypeTags.FINITE) { - resolvedType.tsymbol.originalName = names.originalNameFromIdNode(constant.name); + resolvedType.tsymbol.originalName = Names.originalNameFromIdNode(constant.name); } // Get immutable type for the narrowed type. BType intersectionType = ImmutableTypeCloner.getImmutableType(constant.pos, types, resolvedType, symEnv, - symEnv.scope.owner.pkgID, symEnv.scope.owner, symTable, anonymousModelHelper, names, + symEnv.scope.owner.pkgID, symEnv.scope.owner, symTable, anonymousModelHelper, new HashSet<>()); // Fix the constant expr types due to tooling requirements. diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java index 52a3c913ddbb..d926d7a70cb5 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java @@ -166,7 +166,6 @@ public class Types { private SymbolTable symTable; private SymbolResolver symResolver; private BLangDiagnosticLog dlog; - private Names names; private int finiteTypeCount = 0; private BUnionType expandedXMLBuiltinSubtypes; private final BLangAnonymousModelHelper anonymousModelHelper; @@ -199,7 +198,6 @@ public Types(CompilerContext context) { this.symTable = SymbolTable.getInstance(context); this.symResolver = SymbolResolver.getInstance(context); this.dlog = BLangDiagnosticLog.getInstance(context); - this.names = Names.getInstance(context); this.expandedXMLBuiltinSubtypes = BUnionType.create(null, symTable.xmlElementType, symTable.xmlCommentType, symTable.xmlPIType, symTable.xmlTextType); @@ -5187,7 +5185,7 @@ private BType getIntersection(IntersectionContext intersectionContext, BType lhs } return ImmutableTypeCloner.getEffectiveImmutableType(intersectionContext.pos, this, bType, - env, symTable, anonymousModelHelper, names); + env, symTable, anonymousModelHelper); } } @@ -5337,7 +5335,7 @@ private BMapType getMapTypeForAnydataOrJson(BType type, SymbolEnv env) { if (isImmutable(type)) { return (BMapType) ImmutableTypeCloner.getEffectiveImmutableType(null, this, mapType, env, symTable, - anonymousModelHelper, names); + anonymousModelHelper); } return mapType; } @@ -5348,7 +5346,7 @@ private BArrayType getArrayTypeForAnydataOrJson(BType type, SymbolEnv env) { if (isImmutable(type)) { return (BArrayType) ImmutableTypeCloner.getEffectiveImmutableType(null, this, arrayType, env, symTable, - anonymousModelHelper, names); + anonymousModelHelper); } return arrayType; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SymbolTable.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SymbolTable.java index 2700a855b958..fb53371d69a3 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SymbolTable.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SymbolTable.java @@ -223,7 +223,6 @@ public class SymbolTable { public BPackageSymbol langRegexpModuleSymbol; - private Names names; private Types types; public Map pkgEnvMap = new HashMap<>(); public Map predeclaredModules = new HashMap<>(); @@ -241,7 +240,6 @@ public static SymbolTable getInstance(CompilerContext context) { private SymbolTable(CompilerContext context) { context.put(SYM_TABLE_KEY, this); - this.names = Names.getInstance(context); this.types = Types.getInstance(context); this.rootPkgNode = (BLangPackage) TreeBuilder.createPackageNode(); @@ -314,7 +312,7 @@ private SymbolTable(CompilerContext context) { }}); this.anyAndReadonly = - ImmutableTypeCloner.getImmutableIntersectionType(this.anyType, this, names, this.types, + ImmutableTypeCloner.getImmutableIntersectionType(this.anyType, this, this.types, rootPkgSymbol.pkgID); initializeType(this.anyAndReadonly, this.anyAndReadonly.effectiveType.name.getValue(), BUILTIN); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ImmutableTypeCloner.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ImmutableTypeCloner.java index d4b4d17d8789..c8fcec62ff90 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ImmutableTypeCloner.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ImmutableTypeCloner.java @@ -92,19 +92,19 @@ public class ImmutableTypeCloner { public static BType getEffectiveImmutableType(Location pos, Types types, BType type, SymbolEnv env, - SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names) { + SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper + ) { return getImmutableIntersectionType(pos, types, type, env, env.enclPkg.packageID, env.scope.owner, - symTable, anonymousModelHelper, names, new HashSet<>(), + symTable, anonymousModelHelper, new HashSet<>(), new HashSet<>()).effectiveType; } public static BType getEffectiveImmutableType(Location pos, Types types, BType type, PackageID pkgId, BSymbol owner, SymbolTable symTable, - BLangAnonymousModelHelper anonymousModelHelper, Names names) { + BLangAnonymousModelHelper anonymousModelHelper) { return getImmutableIntersectionType(pos, types, type, null, pkgId, owner, - symTable, anonymousModelHelper, names, new HashSet<>(), + symTable, anonymousModelHelper, new HashSet<>(), new HashSet<>()).effectiveType; } @@ -112,20 +112,20 @@ public static BIntersectionType getImmutableIntersectionType(Location pos, Types BType type, SymbolEnv env, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set origObjFlagSet) { + Set origObjFlagSet) { return getImmutableIntersectionType(pos, types, type, env, env.enclPkg.packageID, env.scope.owner, - symTable, anonymousModelHelper, names, origObjFlagSet, new HashSet<>()); + symTable, anonymousModelHelper, origObjFlagSet, new HashSet<>()); } - public static BIntersectionType getImmutableIntersectionType(BType type, SymbolTable symbolTable, Names names, + public static BIntersectionType getImmutableIntersectionType(BType type, SymbolTable symbolTable, Types types, PackageID pkgId) { return getImmutableIntersectionType(null, types, type, null, pkgId, null, symbolTable, - null, names, null, new HashSet<>()); + null, null, new HashSet<>()); } public static void markFieldsAsImmutable(BLangClassDefinition classDef, SymbolEnv pkgEnv, BObjectType objectType, Types types, BLangAnonymousModelHelper anonymousModelHelper, - SymbolTable symbolTable, Names names, Location pos) { + SymbolTable symbolTable, Location pos) { SymbolEnv typeDefEnv = SymbolEnv.createClassEnv(classDef, objectType.tsymbol.scope, pkgEnv); Iterator objectTypeFieldIterator = objectType.fields.values().iterator(); @@ -148,7 +148,7 @@ public static void markFieldsAsImmutable(BLangClassDefinition classDef, SymbolEn if (!types.isInherentlyImmutableType(type)) { BType immutableFieldType = typeField.symbol.type = ImmutableTypeCloner.getImmutableIntersectionType( - pos, types, type, typeDefEnv, symbolTable, anonymousModelHelper, names, classDef.flagSet); + pos, types, type, typeDefEnv, symbolTable, anonymousModelHelper, classDef.flagSet); classField.setBType(typeField.type = immutableFieldType); } @@ -160,7 +160,7 @@ public static void markFieldsAsImmutable(BLangClassDefinition classDef, SymbolEn public static BType getImmutableType(Location pos, Types types, BType type, SymbolEnv env, PackageID pkgId, BSymbol owner, SymbolTable symTable, - BLangAnonymousModelHelper anonymousModelHelper, Names names, + BLangAnonymousModelHelper anonymousModelHelper, Set unresolvedTypes) { if (type == null) { return symTable.semanticError; @@ -175,7 +175,7 @@ public static BType getImmutableType(Location pos, Types types, BType type, Symb } return getImmutableIntersectionType(pos, types, type, env, pkgId, - owner, symTable, anonymousModelHelper, names, new HashSet<>(), + owner, symTable, anonymousModelHelper, new HashSet<>(), unresolvedTypes); } @@ -184,7 +184,6 @@ private static BIntersectionType getImmutableIntersectionType(Location pos, SymbolEnv env, PackageID pkgId, BSymbol owner, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set origObjFlagSet, Set unresolvedTypes) { BType refType = Types.getReferredType(bType); @@ -199,7 +198,7 @@ private static BIntersectionType getImmutableIntersectionType(Location pos, } return ImmutableTypeCloner.setImmutableType(pos, types, type, bType, env, pkgId, owner, symTable, - anonymousModelHelper, names, origObjFlagSet, unresolvedTypes); + anonymousModelHelper, origObjFlagSet, unresolvedTypes); } private static BIntersectionType setImmutableType(Location pos, Types types, @@ -208,7 +207,6 @@ private static BIntersectionType setImmutableType(Location pos, Types types, SymbolEnv env, PackageID pkgId, BSymbol owner, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set origObjFlagSet, Set unresolvedTypes) { BType type = (BType) selectivelyImmutableRefType; switch (type.tag) { @@ -228,33 +226,33 @@ private static BIntersectionType setImmutableType(Location pos, Types types, Types.addImmutableType(symTable, pkgId, origXmlSubType, immutableXmlSubTypeIntersectionType); return immutableXmlSubTypeIntersectionType; case TypeTags.XML: - return defineImmutableXMLType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, names, + return defineImmutableXMLType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, unresolvedTypes, (BXMLType) type, originalType); case TypeTags.ARRAY: case TypeTags.BYTE_ARRAY: - return defineImmutableArrayType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, names, + return defineImmutableArrayType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, unresolvedTypes, (BArrayType) type, originalType); case TypeTags.TUPLE: - return defineImmutableTupleType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, names, + return defineImmutableTupleType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, unresolvedTypes, (BTupleType) type, originalType); case TypeTags.MAP: - return defineImmutableMapType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, names, + return defineImmutableMapType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, unresolvedTypes, (BMapType) type, originalType); case TypeTags.RECORD: BRecordType origRecordType = (BRecordType) type; return defineImmutableRecordType(pos, origRecordType, originalType, env, symTable, - anonymousModelHelper, names, types, unresolvedTypes); + anonymousModelHelper, types, unresolvedTypes); case TypeTags.OBJECT: BObjectType origObjectType = (BObjectType) type; return defineImmutableObjectType(pos, origObjectType, originalType, env, symTable, - anonymousModelHelper, names, types, origObjFlagSet, unresolvedTypes); + anonymousModelHelper, types, origObjFlagSet, unresolvedTypes); case TypeTags.TABLE: - return defineImmutableTableType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, names, + return defineImmutableTableType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, unresolvedTypes, (BTableType) type, originalType); case TypeTags.ANY: BAnyType origAnyType = (BAnyType) type; - BTypeSymbol immutableAnyTSymbol = getReadonlyTSymbol(names, origAnyType.tsymbol, env, pkgId, owner); + BTypeSymbol immutableAnyTSymbol = getReadonlyTSymbol(origAnyType.tsymbol, env, pkgId, owner); BAnyType immutableAnyType; if (immutableAnyTSymbol != null) { @@ -263,7 +261,7 @@ private static BIntersectionType setImmutableType(Location pos, Types types, immutableAnyTSymbol.type = immutableAnyType; } else { immutableAnyType = new BAnyType(origAnyType.tag, immutableAnyTSymbol, - getImmutableTypeName(names, TypeKind.ANY.typeName()), + getImmutableTypeName(TypeKind.ANY.typeName()), origAnyType.flags | Flags.READONLY, origAnyType.isNullable()); } @@ -276,11 +274,11 @@ private static BIntersectionType setImmutableType(Location pos, Types types, case TypeTags.ANYDATA: case TypeTags.JSON: return defineImmutableBuiltInUnionType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, - names, unresolvedTypes, (BUnionType) type, originalType); + unresolvedTypes, (BUnionType) type, originalType); case TypeTags.INTERSECTION: return (BIntersectionType) type; default: - return defineImmutableUnionType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, names, + return defineImmutableUnionType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, unresolvedTypes, (BUnionType) type, originalType); } } @@ -288,10 +286,10 @@ private static BIntersectionType setImmutableType(Location pos, Types types, private static BIntersectionType defineImmutableTableType(Location pos, Types types, SymbolEnv env, PackageID pkgId, BSymbol owner, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set unresolvedTypes, + Set unresolvedTypes, BTableType type, BType originalType) { - BTypeSymbol immutableTableTSymbol = getReadonlyTSymbol(names, type.tsymbol, env, pkgId, owner); + BTypeSymbol immutableTableTSymbol = getReadonlyTSymbol(type.tsymbol, env, pkgId, owner); Optional immutableType = Types.getImmutableType(symTable, pkgId, type); if (immutableType.isPresent()) { return immutableType.get(); @@ -304,13 +302,13 @@ originalType, new BTableType(TypeTags.TABLE, null, immutableTableTSymbol, BIntersectionType immutableTableType = Types.getImmutableType(symTable, pkgId, type).orElseThrow(); BTableType tableEffectiveImmutableType = (BTableType) immutableTableType.effectiveType; tableEffectiveImmutableType.constraint = getImmutableType(pos, types, type.constraint, env, pkgId, owner, - symTable, anonymousModelHelper, names, unresolvedTypes); + symTable, anonymousModelHelper, unresolvedTypes); BType origKeyTypeConstraint = type.keyTypeConstraint; if (origKeyTypeConstraint != null) { tableEffectiveImmutableType.keyTypeConstraint = getImmutableType(pos, types, origKeyTypeConstraint, env, pkgId, owner, symTable, - anonymousModelHelper, names, + anonymousModelHelper, unresolvedTypes); } @@ -330,10 +328,10 @@ originalType, new BTableType(TypeTags.TABLE, null, immutableTableTSymbol, private static BIntersectionType defineImmutableXMLType(Location pos, Types types, SymbolEnv env, PackageID pkgId, BSymbol owner, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set unresolvedTypes, + Set unresolvedTypes, BXMLType type, BType originalType) { - BTypeSymbol immutableXmlTSymbol = getReadonlyTSymbol(names, type.tsymbol, env, pkgId, owner); + BTypeSymbol immutableXmlTSymbol = getReadonlyTSymbol(type.tsymbol, env, pkgId, owner); Optional immutableType = Types.getImmutableType(symTable, pkgId, type); if (immutableType.isPresent()) { return immutableType.get(); @@ -347,17 +345,17 @@ originalType, new BXMLType(null, immutableXmlTSymbol, type.flags | Flags.READONL BXMLType xmlEffectiveImmutableType = (BXMLType) immutableXMLType.effectiveType; xmlEffectiveImmutableType.mutableType = type; xmlEffectiveImmutableType.constraint = getImmutableType(pos, types, type.constraint, env, pkgId, owner, - symTable, anonymousModelHelper, names, unresolvedTypes); + symTable, anonymousModelHelper, unresolvedTypes); return immutableXMLType; } private static BIntersectionType defineImmutableArrayType(Location pos, Types types, SymbolEnv env, PackageID pkgId, BSymbol owner, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set unresolvedTypes, + Set unresolvedTypes, BArrayType type, BType originalType) { - BTypeSymbol immutableArrayTSymbol = getReadonlyTSymbol(names, type.tsymbol, env, pkgId, owner); + BTypeSymbol immutableArrayTSymbol = getReadonlyTSymbol(type.tsymbol, env, pkgId, owner); Optional immutableType = Types.getImmutableType(symTable, pkgId, type); if (immutableType.isPresent()) { return immutableType.get(); @@ -371,17 +369,17 @@ originalType, new BArrayType(null, immutableArrayTSymbol, type.size, type.state, BArrayType arrayEffectiveImmutableType = (BArrayType) immutableArrayType.effectiveType; arrayEffectiveImmutableType.mutableType = type; arrayEffectiveImmutableType.eType = getImmutableType(pos, types, type.eType, env, pkgId, owner, - symTable, anonymousModelHelper, names, unresolvedTypes); + symTable, anonymousModelHelper, unresolvedTypes); return immutableArrayType; } private static BIntersectionType defineImmutableMapType(Location pos, Types types, SymbolEnv env, PackageID pkgId, BSymbol owner, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set unresolvedTypes, + Set unresolvedTypes, BMapType type, BType originalType) { - BTypeSymbol immutableMapTSymbol = getReadonlyTSymbol(names, type.tsymbol, env, pkgId, owner); + BTypeSymbol immutableMapTSymbol = getReadonlyTSymbol(type.tsymbol, env, pkgId, owner); Optional immutableType = Types.getImmutableType(symTable, pkgId, type); if (immutableType.isPresent()) { return immutableType.get(); @@ -396,7 +394,7 @@ originalType, new BMapType(TypeTags.MAP, null, immutableMapTSymbol, BMapType mapEffectiveImmutableType = (BMapType) immutableMapType.effectiveType; mapEffectiveImmutableType.mutableType = type; mapEffectiveImmutableType.constraint = getImmutableType(pos, types, type.constraint, env, pkgId, owner, - symTable, anonymousModelHelper, names, + symTable, anonymousModelHelper, unresolvedTypes); return immutableMapType; } @@ -404,7 +402,7 @@ originalType, new BMapType(TypeTags.MAP, null, immutableMapTSymbol, private static BIntersectionType defineImmutableTupleType(Location pos, Types types, SymbolEnv env, PackageID pkgId, BSymbol owner, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set unresolvedTypes, + Set unresolvedTypes, BTupleType type, BType originalType) { BTypeSymbol origTupleTypeSymbol = type.tsymbol; @@ -429,7 +427,7 @@ private static BIntersectionType defineImmutableTupleType(Location pos, Types ty Name origTupleTypeSymbolName = Names.EMPTY; if (!originalTypeName.isEmpty()) { origTupleTypeSymbolName = origTupleTypeSymbol.name.value.isEmpty() ? Names.EMPTY : - getImmutableTypeName(names, getSymbolFQN(origTupleTypeSymbol)); + getImmutableTypeName(getSymbolFQN(origTupleTypeSymbol)); tupleEffectiveImmutableType.name = origTupleTypeSymbolName; } @@ -442,7 +440,7 @@ private static BIntersectionType defineImmutableTupleType(Location pos, Types ty continue; } BType newType = getImmutableType(pos, types, origTupleMemType.type, env, - pkgId, owner, symTable, anonymousModelHelper, names, unresolvedTypes); + pkgId, owner, symTable, anonymousModelHelper, unresolvedTypes); BVarSymbol varSymbol = Symbols.createVarSymbolForTupleMember(newType); BTupleMember member = new BTupleMember(newType, varSymbol); tupleEffectiveImmutableType.addMembers(member); @@ -450,7 +448,7 @@ private static BIntersectionType defineImmutableTupleType(Location pos, Types ty if (type.restType != null) { tupleEffectiveImmutableType.addRestType(getImmutableType(pos, types, type.restType, env, pkgId, - owner, symTable, anonymousModelHelper, names, unresolvedTypes)); + owner, symTable, anonymousModelHelper, unresolvedTypes)); } BIntersectionType immutableTupleIntersectionType = Types.getImmutableType(symTable, pkgId, type).get(); @@ -487,8 +485,7 @@ private static BIntersectionType defineImmutableTupleType(Location pos, Types ty public static void defineUndefinedImmutableFields(BLangTypeDefinition immutableTypeDefinition, Types types, SymbolEnv pkgEnv, SymbolTable symTable, - BLangAnonymousModelHelper anonymousModelHelper, - Names names) { + BLangAnonymousModelHelper anonymousModelHelper) { Location pos = immutableTypeDefinition.pos; SymbolEnv env = SymbolEnv.createTypeEnv(immutableTypeDefinition.typeNode, immutableTypeDefinition.symbol.scope, pkgEnv); @@ -497,11 +494,11 @@ public static void defineUndefinedImmutableFields(BLangTypeDefinition immutableT BType immutableType = Types.getImpliedType(immutableTypeDefinition.getBType()); if (immutableType.tag == TypeTags.RECORD) { defineUndefinedImmutableRecordFields((BRecordType) immutableType, pos, pkgID, immutableTypeDefinition, - types, env, symTable, anonymousModelHelper, names); + types, env, symTable, anonymousModelHelper); return; } defineUndefinedImmutableObjectFields((BObjectType) immutableType, pos, pkgID, immutableTypeDefinition, - types, env, symTable, anonymousModelHelper, names); + types, env, symTable, anonymousModelHelper); } private static void defineUndefinedImmutableRecordFields(BRecordType immutableRecordType, @@ -509,12 +506,11 @@ private static void defineUndefinedImmutableRecordFields(BRecordType immutableRe PackageID pkgID, BLangTypeDefinition immutableTypeDefinition, Types types, SymbolEnv env, SymbolTable symTable, - BLangAnonymousModelHelper anonymousModelHelper, - Names names) { + BLangAnonymousModelHelper anonymousModelHelper) { BRecordType origRecordType = immutableRecordType.mutableType; if (origRecordType != null && (origRecordType.fields.size() != immutableRecordType.fields.size())) { - populateImmutableStructureFields(types, symTable, anonymousModelHelper, names, + populateImmutableStructureFields(types, symTable, anonymousModelHelper, (BLangRecordTypeNode) immutableTypeDefinition.typeNode, immutableRecordType, origRecordType, loc, env, pkgID, new HashSet<>()); } @@ -524,7 +520,7 @@ private static void defineUndefinedImmutableRecordFields(BRecordType immutableRe return; } - setRestType(types, symTable, anonymousModelHelper, names, immutableRecordType, origRecordType, loc, env, + setRestType(types, symTable, anonymousModelHelper, immutableRecordType, origRecordType, loc, env, new HashSet<>()); } @@ -533,30 +529,29 @@ private static void defineUndefinedImmutableObjectFields(BObjectType immutableOb PackageID pkgID, BLangTypeDefinition immutableTypeDefinition, Types types, SymbolEnv env, SymbolTable symTable, - BLangAnonymousModelHelper anonymousModelHelper, - Names names) { + BLangAnonymousModelHelper anonymousModelHelper) { BObjectType origObjectType = immutableObjectType.mutableType; if (origObjectType.fields.size() != immutableObjectType.fields.size()) { - TypeDefBuilderHelper.populateStructureFieldsAndTypeInclusions(types, symTable, anonymousModelHelper, names, + TypeDefBuilderHelper.populateStructureFieldsAndTypeInclusions(types, symTable, anonymousModelHelper, (BLangObjectTypeNode) immutableTypeDefinition.typeNode, immutableObjectType, origObjectType, location, env, pkgID, new HashSet<>(), Flags.FINAL, true); } } private static void populateImmutableStructureFields(Types types, SymbolTable symTable, - BLangAnonymousModelHelper anonymousModelHelper, Names names, + BLangAnonymousModelHelper anonymousModelHelper, BLangStructureTypeNode immutableStructureTypeNode, BStructureType immutableStructureType, BStructureType origStructureType, Location pos, SymbolEnv env, PackageID pkgID, Set unresolvedTypes) { - TypeDefBuilderHelper.populateStructureFieldsAndTypeInclusions(types, symTable, anonymousModelHelper, names, + TypeDefBuilderHelper.populateStructureFieldsAndTypeInclusions(types, symTable, anonymousModelHelper, immutableStructureTypeNode, immutableStructureType, origStructureType, pos, env, pkgID, unresolvedTypes, Flags.READONLY, true); } private static void setRestType(Types types, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, BRecordType immutableRecordType, BRecordType origRecordType, + BRecordType immutableRecordType, BRecordType origRecordType, Location pos, SymbolEnv env, Set unresolvedTypes) { immutableRecordType.sealed = origRecordType.sealed; @@ -567,7 +562,7 @@ private static void setRestType(Types types, SymbolTable symTable, BLangAnonymou return; } BType restFieldImmutableType = getImmutableType(pos, types, origRestFieldType, env, env.enclPkg.packageID, - env.scope.owner, symTable, anonymousModelHelper, names, + env.scope.owner, symTable, anonymousModelHelper, unresolvedTypes); immutableRecordType.restFieldType = restFieldImmutableType == symTable.semanticError ? symTable.neverType : restFieldImmutableType; @@ -577,12 +572,12 @@ private static BIntersectionType defineImmutableRecordType(Location pos, BRecord BType originalType, SymbolEnv env, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Types types, Set unresolvedTypes) { + Types types, Set unresolvedTypes) { PackageID pkgID = env.enclPkg.symbol.pkgID; BTypeSymbol recordTypeSymbol = origRecordType.tsymbol; BRecordTypeSymbol recordSymbol = Symbols.createRecordSymbol(recordTypeSymbol.flags | Flags.READONLY, - getImmutableTypeName(names, getSymbolFQN(recordTypeSymbol)), + getImmutableTypeName(getSymbolFQN(recordTypeSymbol)), pkgID, null, env.scope.owner, pos, VIRTUAL); BInvokableType bInvokableType = new BInvokableType(new ArrayList<>(), symTable.nilType, null); @@ -608,10 +603,10 @@ private static BIntersectionType defineImmutableRecordType(Location pos, BRecord BLangRecordTypeNode recordTypeNode = TypeDefBuilderHelper.createRecordTypeNode(new ArrayList<>(), immutableRecordType, pos); - populateImmutableStructureFields(types, symTable, anonymousModelHelper, names, recordTypeNode, + populateImmutableStructureFields(types, symTable, anonymousModelHelper, recordTypeNode, immutableRecordType, origRecordType, pos, env, pkgID, unresolvedTypes); - setRestType(types, symTable, anonymousModelHelper, names, immutableRecordType, origRecordType, pos, env, + setRestType(types, symTable, anonymousModelHelper, immutableRecordType, origRecordType, pos, env, unresolvedTypes); TypeDefBuilderHelper.addTypeDefinition(immutableRecordType, recordSymbol, recordTypeNode, env); @@ -622,7 +617,7 @@ private static BIntersectionType defineImmutableObjectType(Location pos, BObjectType origObjectType, BType originalType, SymbolEnv env, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Types types, + Types types, Set flagSet, Set unresolvedTypes) { PackageID pkgID = env.enclPkg.symbol.pkgID; BObjectTypeSymbol origObjectTSymbol = (BObjectTypeSymbol) origObjectType.tsymbol; @@ -631,13 +626,13 @@ private static BIntersectionType defineImmutableObjectType(Location pos, flags &= ~Flags.CLASS; BObjectTypeSymbol objectSymbol = Symbols.createObjectSymbol(flags, - getImmutableTypeName(names, + getImmutableTypeName( getSymbolFQN(origObjectTSymbol)), pkgID, null, env.scope.owner, pos, VIRTUAL); objectSymbol.scope = new Scope(objectSymbol); - defineObjectFunctions(objectSymbol, origObjectTSymbol, names, symTable); + defineObjectFunctions(objectSymbol, origObjectTSymbol, symTable); BObjectType immutableObjectType = new BObjectType(objectSymbol, origObjectType.flags | Flags.READONLY); @@ -656,7 +651,7 @@ private static BIntersectionType defineImmutableObjectType(Location pos, immutableObjectType, pos); objectTypeNode.flagSet.addAll(flagSet); - TypeDefBuilderHelper.populateStructureFieldsAndTypeInclusions(types, symTable, anonymousModelHelper, names, + TypeDefBuilderHelper.populateStructureFieldsAndTypeInclusions(types, symTable, anonymousModelHelper, objectTypeNode, immutableObjectType, origObjectType, pos, env, pkgID, unresolvedTypes, Flags.FINAL, true); @@ -668,7 +663,7 @@ private static BIntersectionType defineImmutableObjectType(Location pos, } public static void defineObjectFunctions(BObjectTypeSymbol immutableObjectSymbol, - BObjectTypeSymbol originalObjectSymbol, Names names, + BObjectTypeSymbol originalObjectSymbol, SymbolTable symTable) { List originalObjectAttachedFuncs = originalObjectSymbol.attachedFuncs; List immutableObjectAttachedFuncs = immutableObjectSymbol.attachedFuncs; @@ -696,7 +691,7 @@ public static void defineObjectFunctions(BObjectTypeSymbol immutableObjectSymbol private static BIntersectionType defineImmutableUnionType(Location pos, Types types, SymbolEnv env, PackageID pkgId, BSymbol owner, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set unresolvedTypes, + Set unresolvedTypes, BUnionType type, BType originalType) { BTypeSymbol origUnionTypeSymbol = type.tsymbol; @@ -712,7 +707,7 @@ private static BIntersectionType defineImmutableUnionType(Location pos, Types ty } BIntersectionType immutableType = handleImmutableUnionType(pos, types, env, pkgId, owner, symTable, - anonymousModelHelper, names, + anonymousModelHelper, unresolvedTypes, type, origUnionTypeSymbol, originalMemberList); BType effectiveType = immutableType.effectiveType; @@ -735,7 +730,7 @@ private static BIntersectionType defineImmutableBuiltInUnionType(Location pos, T PackageID pkgId, BSymbol owner, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set unresolvedTypes, + Set unresolvedTypes, BUnionType type, BType originalType) { BTypeSymbol origBuiltInUnionTypeSymbol = type.tsymbol; @@ -746,22 +741,22 @@ private static BIntersectionType defineImmutableBuiltInUnionType(Location pos, T BUnionType effectiveType; if (type.tag == TypeTags.JSON) { - effectiveType = defineImmutableJsonType(env, pkgId, owner, names, (BJSONType) type); + effectiveType = defineImmutableJsonType(env, pkgId, owner, (BJSONType) type); } else { - effectiveType = defineImmutableAnydataType(env, pkgId, owner, names, (BAnydataType) type); + effectiveType = defineImmutableAnydataType(env, pkgId, owner, (BAnydataType) type); } BIntersectionType immutableBuiltInUnionIntersectionType = createImmutableIntersectionType(pkgId, owner, originalType, effectiveType, symTable); Types.addImmutableType(symTable, pkgId, type, immutableBuiltInUnionIntersectionType); - return handleImmutableUnionType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, names, + return handleImmutableUnionType(pos, types, env, pkgId, owner, symTable, anonymousModelHelper, unresolvedTypes, type, origBuiltInUnionTypeSymbol, type.getMemberTypes()); } - private static BAnydataType defineImmutableAnydataType(SymbolEnv env, PackageID pkgId, BSymbol owner, Names names, + private static BAnydataType defineImmutableAnydataType(SymbolEnv env, PackageID pkgId, BSymbol owner, BAnydataType type) { - BTypeSymbol immutableAnydataTSymbol = getReadonlyTSymbol(names, type.tsymbol, env, pkgId, owner); + BTypeSymbol immutableAnydataTSymbol = getReadonlyTSymbol(type.tsymbol, env, pkgId, owner); if (immutableAnydataTSymbol != null) { BAnydataType immutableAnydataType = @@ -772,13 +767,13 @@ private static BAnydataType defineImmutableAnydataType(SymbolEnv env, PackageID return immutableAnydataType; } return new BAnydataType(immutableAnydataTSymbol, - getImmutableTypeName(names, TypeKind.ANYDATA.typeName()), + getImmutableTypeName(TypeKind.ANYDATA.typeName()), type.flags | Flags.READONLY, type.isNullable()); } - private static BJSONType defineImmutableJsonType(SymbolEnv env, PackageID pkgId, BSymbol owner, Names names, + private static BJSONType defineImmutableJsonType(SymbolEnv env, PackageID pkgId, BSymbol owner, BJSONType type) { - BTypeSymbol immutableJsonTSymbol = getReadonlyTSymbol(names, type.tsymbol, env, pkgId, owner); + BTypeSymbol immutableJsonTSymbol = getReadonlyTSymbol(type.tsymbol, env, pkgId, owner); BJSONType immutableJsonType = new BJSONType(immutableJsonTSymbol, type.isNullable(), type.flags | Flags.READONLY); @@ -791,7 +786,7 @@ private static BJSONType defineImmutableJsonType(SymbolEnv env, PackageID pkgId, private static BIntersectionType handleImmutableUnionType(Location pos, Types types, SymbolEnv env, PackageID pkgId, BSymbol owner, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set unresolvedTypes, BUnionType type, + Set unresolvedTypes, BUnionType type, BTypeSymbol origUnionTypeSymbol, LinkedHashSet originalMemberList) { BIntersectionType immutableType = Types.getImmutableType(symTable, pkgId, type).get(); @@ -803,7 +798,7 @@ private static BIntersectionType handleImmutableUnionType(Location pos, Types ty String originalTypeName = origUnionTypeSymbol == null ? "" : origUnionTypeSymbol.name.getValue(); if (!originalTypeName.isEmpty()) { - unionEffectiveImmutableType.name = getImmutableTypeName(names, getSymbolFQN(origUnionTypeSymbol)); + unionEffectiveImmutableType.name = getImmutableTypeName(getSymbolFQN(origUnionTypeSymbol)); } for (BType memberType : originalMemberList) { @@ -817,7 +812,7 @@ private static BIntersectionType handleImmutableUnionType(Location pos, Types ty } BType immutableMemberType = getImmutableType(pos, types, memberType, env, pkgId, owner, symTable, - anonymousModelHelper, names, unresolvedTypes); + anonymousModelHelper, unresolvedTypes); unionEffectiveImmutableType.add(immutableMemberType); } @@ -828,7 +823,7 @@ private static BIntersectionType handleImmutableUnionType(Location pos, Types ty BTypeSymbol immutableUnionTSymbol = getReadonlyTSymbol(origUnionTypeSymbol, env, pkgId, owner, origUnionTypeSymbol.name.value.isEmpty() ? Names.EMPTY : - getImmutableTypeName(names, getSymbolFQN(origUnionTypeSymbol))); + getImmutableTypeName(getSymbolFQN(origUnionTypeSymbol))); immutableType.effectiveType.tsymbol = immutableUnionTSymbol; immutableType.effectiveType.flags |= (type.flags | Flags.READONLY); @@ -842,13 +837,13 @@ private static BIntersectionType handleImmutableUnionType(Location pos, Types ty return immutableType; } - private static BTypeSymbol getReadonlyTSymbol(Names names, BTypeSymbol originalTSymbol, SymbolEnv env, + private static BTypeSymbol getReadonlyTSymbol(BTypeSymbol originalTSymbol, SymbolEnv env, PackageID pkgId, BSymbol owner) { if (originalTSymbol == null) { return null; } - return getReadonlyTSymbol(originalTSymbol, env, pkgId, owner, getImmutableTypeName(names, originalTSymbol)); + return getReadonlyTSymbol(originalTSymbol, env, pkgId, owner, getImmutableTypeName(originalTSymbol)); } private static BTypeSymbol getReadonlyTSymbol(BTypeSymbol originalTSymbol, SymbolEnv env, PackageID pkgId, @@ -878,11 +873,11 @@ private static String getSymbolFQN(BTypeSymbol originalTSymbol) { getMajorVersion(pkgID.version.value) + ":" + originalTSymbol.name; } - private static Name getImmutableTypeName(Names names, BTypeSymbol originalTSymbol) { - return getImmutableTypeName(names, originalTSymbol.name.getValue()); + private static Name getImmutableTypeName(BTypeSymbol originalTSymbol) { + return getImmutableTypeName(originalTSymbol.name.getValue()); } - private static Name getImmutableTypeName(Names names, String origName) { + private static Name getImmutableTypeName(String origName) { if (origName.isEmpty()) { return Names.EMPTY; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/NodeUtils.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/NodeUtils.java index b668dd0fee5e..69c996c0cf8a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/NodeUtils.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/NodeUtils.java @@ -31,12 +31,10 @@ public class NodeUtils { /** * Return the {@code Name} from the give package name components. * - * @param names utility class which manages all the names used - * in the Ballerina compiler. * @param pkgNameComps components of the given package name. * @return returns the name from the given package name components. */ - public static Name getName(Names names, List pkgNameComps) { + public static Name getName(List pkgNameComps) { String pkgName = String.join(".", pkgNameComps.stream() .map(id -> id.value) .toList()); @@ -48,14 +46,14 @@ public static Name getName(String localname, String namespaceURI) { return new Name(qname); } - public static PackageID getPackageID(Names names, BLangIdentifier orgNameNode, + public static PackageID getPackageID(BLangIdentifier orgNameNode, List pkgNameComps, BLangIdentifier versionNode) { - List nameList = pkgNameComps.stream().map(names::fromIdNode).collect(Collectors.toList()); + List nameList = pkgNameComps.stream().map(Names::fromIdNode).collect(Collectors.toList()); Name orgName = null; if (orgNameNode != null) { - orgName = names.fromIdNode(orgNameNode); + orgName = Names.fromIdNode(orgNameNode); } - Name version = names.fromIdNode(versionNode); + Name version = Names.fromIdNode(versionNode); if (version == Names.EMPTY) { version = Names.DEFAULT_VERSION; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/TypeDefBuilderHelper.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/TypeDefBuilderHelper.java index a13f8f34bd71..bc698c6a2e23 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/TypeDefBuilderHelper.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/TypeDefBuilderHelper.java @@ -135,16 +135,14 @@ public static BLangObjectTypeNode createObjectTypeNode(List public static BLangFunction createInitFunctionForStructureType(BSymbol symbol, SymbolEnv env, - Names names, Name suffix, SymbolTable symTable, BType type) { - return createInitFunctionForStructureType(symbol, env, names, suffix, type, symTable.nilType); + return createInitFunctionForStructureType(symbol, env, suffix, type, symTable.nilType); } public static BLangFunction createInitFunctionForStructureType(BSymbol symbol, SymbolEnv env, - Names names, Name suffix, BType type, BType returnType) { @@ -154,8 +152,8 @@ public static BLangFunction createInitFunctionForStructureType(BSymbol symbol, // Create the receiver and add receiver details to the node initFunction.receiver = ASTBuilderUtil.createReceiver(null, type); BVarSymbol receiverSymbol = new BVarSymbol(Flags.asMask(EnumSet.noneOf(Flag.class)), - names.fromIdNode(initFunction.receiver.name), - names.originalNameFromIdNode(initFunction.receiver.name), + Names.fromIdNode(initFunction.receiver.name), + Names.originalNameFromIdNode(initFunction.receiver.name), env.enclPkg.symbol.pkgID, type, null, null, VIRTUAL); initFunction.receiver.symbol = receiverSymbol; initFunction.attachedFunction = true; @@ -296,7 +294,7 @@ public static String getPackageAlias(SymbolEnv env, String compUnitName, Package public static void populateStructureFieldsAndTypeInclusions(Types types, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, - Names names, BLangStructureTypeNode structureTypeNode, + BLangStructureTypeNode structureTypeNode, BStructureType structureType, BStructureType origStructureType, Location pos, SymbolEnv env, PackageID pkgID, @@ -309,7 +307,7 @@ public static void populateStructureFieldsAndTypeInclusions(Types types, SymbolT BType fieldType; if (isImmutable) { fieldType = ImmutableTypeCloner.getImmutableType(pos, types, origField.type, env, - env.enclPkg.packageID, env.scope.owner, symTable, anonymousModelHelper, names, unresolvedTypes); + env.enclPkg.packageID, env.scope.owner, symTable, anonymousModelHelper, unresolvedTypes); } else { fieldType = origField.type; } @@ -361,7 +359,7 @@ public static void populateStructureFieldsAndTypeInclusions(Types types, SymbolT } } - public static void createTypeDefinition(BRecordType type, Location pos, Names names, + public static void createTypeDefinition(BRecordType type, Location pos, Types types, SymbolTable symTable, SymbolEnv env) { BRecordTypeSymbol recordSymbol = (BRecordTypeSymbol) type.tsymbol; @@ -383,7 +381,7 @@ public static void createTypeDefinition(BRecordType type, Location pos, Names na BLangRecordTypeNode recordTypeNode = TypeDefBuilderHelper.createRecordTypeNode(new ArrayList<>(), type, pos); - TypeDefBuilderHelper.populateStructureFieldsAndTypeInclusions(types, symTable, null, names, recordTypeNode, + TypeDefBuilderHelper.populateStructureFieldsAndTypeInclusions(types, symTable, null, recordTypeNode, type, type, pos, env, env.scope.owner.pkgID, null, Flags.REQUIRED, false); recordTypeNode.sealed = true; diff --git a/compiler/ballerina-lang/src/test/java/org/wso2/ballerinalang/compiler/SourceDirectoryManagerTest.java b/compiler/ballerina-lang/src/test/java/org/wso2/ballerinalang/compiler/SourceDirectoryManagerTest.java index fd3c49271a47..4573477dd889 100644 --- a/compiler/ballerina-lang/src/test/java/org/wso2/ballerinalang/compiler/SourceDirectoryManagerTest.java +++ b/compiler/ballerina-lang/src/test/java/org/wso2/ballerinalang/compiler/SourceDirectoryManagerTest.java @@ -51,7 +51,6 @@ public void init() { @Test(description = "Return modules list should be equivalence to the expected module list") public void testListSourceFilesAndPackages() { - Names names = Names.getInstance(context); List expectedPackageIds = new ArrayList<>(); expectedPackageIds.add(new PackageID(Names.fromString("abc"), Names.fromString("fruits"), @@ -65,7 +64,6 @@ public void testListSourceFilesAndPackages() { @Test(description = "Return module should be equivalence to the expected module") public void testGetPackageID() { PackageID fruits = directoryManager.getPackageID("fruits"); - Names names = Names.getInstance(context); PackageID expectedPackageId = new PackageID(Names.fromString("abc"), Names.fromString("fruits"), Names.fromString("0.0.1")); @@ -75,7 +73,6 @@ public void testGetPackageID() { @Test(description = "Test if module exist in the project") public void testIsModuleExists() { Project project = context.get(Project.PROJECT_KEY); - Names names = Names.getInstance(context); PackageID expectedPackageId = new PackageID(Names.fromString("abc"), Names.fromString("fruits"), Names.fromString("0.0.1")); @@ -97,7 +94,6 @@ public void testIsModuleExists() { @Test(description = "Test if get bala path") public void getBalaPath() throws InvalidModuleException { Project project = context.get(Project.PROJECT_KEY); - Names names = Names.getInstance(context); PackageID moduleId = new PackageID(Names.fromString("abc"), Names.fromString("fruits"), Names.fromString("0.0.1"));