From e084377c11eca530ca9d36dd09e08d22083e12dd Mon Sep 17 00:00:00 2001 From: chiranSachintha Date: Thu, 10 Nov 2022 11:48:25 +0530 Subject: [PATCH] fix review suggestions --- .../internal/values/TypedescValueImpl.java | 5 +---- .../wso2/ballerinalang/compiler/bir/BIRGen.java | 17 +++++++++++++---- .../compiler/bir/model/BIRNonTerminator.java | 10 +++++++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java index f38ebcbc7694..feccd6b1e7d6 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java @@ -68,13 +68,10 @@ public TypedescValueImpl(Type describingType, MapValue[] closures) { @Deprecated public TypedescValueImpl(Type describingType, MapValue[] closures, MapValue annotations) { - this.type = new BTypedescType(describingType); - this.describingType = describingType; - this.closures = closures; + this(describingType, closures); this.annotations = annotations; } - /** * Returns the {@code BType} of the value describe by this type descriptor. * @return describing type 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 f9d3ebd99a3c..1fce3f1ed5d2 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 @@ -1551,7 +1551,7 @@ public void visit(BLangLiteral astLiteralExpr) { @Override public void visit(BLangMapLiteral astMapLiteralExpr) { - visitTypedesc(astMapLiteralExpr.pos, astMapLiteralExpr.getBType(), Collections.emptyList(), null); + visitTypedesc(astMapLiteralExpr.pos, astMapLiteralExpr.getBType(), Collections.emptyList()); BIRVariableDcl tempVarDcl = new BIRVariableDcl(astMapLiteralExpr.getBType(), this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); @@ -1951,7 +1951,7 @@ public void visit(BLangWaitExpr waitExpr) { @Override public void visit(BLangWaitForAllExpr.BLangWaitLiteral waitLiteral) { - visitTypedesc(waitLiteral.pos, waitLiteral.getBType(), Collections.emptyList(), null); + visitTypedesc(waitLiteral.pos, waitLiteral.getBType(), Collections.emptyList()); BIRBasicBlock thenBB = new BIRBasicBlock(this.env.nextBBId(names)); addToTrapStack(thenBB); BIRVariableDcl tempVarDcl = new BIRVariableDcl(waitLiteral.getBType(), @@ -2179,7 +2179,7 @@ public void visit(BLangTypedescExpr accessExpr) { this.env.enclFunc.localVars.add(tempVarDcl); BIROperand toVarRef = new BIROperand(tempVarDcl); setScopeAndEmit(new BIRNonTerminator.NewTypeDesc(accessExpr.pos, toVarRef, accessExpr.resolvedType, - Collections.emptyList(), null)); + Collections.emptyList())); this.env.targetOperand = toVarRef; } @@ -2228,7 +2228,7 @@ public void visit(BLangTableConstructorExpr tableConstructorExpr) { public void visit(BLangSimpleVarRef.BLangTypeLoad typeLoad) { BType type = typeLoad.symbol.tag == SymTag.TYPE_DEF ? ((BTypeDefinitionSymbol) typeLoad.symbol).referenceType : typeLoad.symbol.type; - visitTypedesc(typeLoad.pos, type, Collections.emptyList(), null); + visitTypedesc(typeLoad.pos, type, Collections.emptyList()); } private void visitTypedesc(Location pos, BType type, List varDcls, BIROperand annotations) { @@ -2240,6 +2240,15 @@ private void visitTypedesc(Location pos, BType type, List varDcls, B this.env.targetOperand = toVarRef; } + private void visitTypedesc(Location pos, BType type, List varDcls) { + BIRVariableDcl tempVarDcl = new BIRVariableDcl(symTable.typeDesc, this.env.nextLocalVarId(names), + VarScope.FUNCTION, VarKind.TEMP); + this.env.enclFunc.localVars.add(tempVarDcl); + BIROperand toVarRef = new BIROperand(tempVarDcl); + setScopeAndEmit(new BIRNonTerminator.NewTypeDesc(pos, toVarRef, type, varDcls)); + this.env.targetOperand = toVarRef; + } + @Override public void visit(BLangBreak breakStmt) { BIRLockDetailsHolder toUnlock = this.env.unlockVars.peek(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java index 218a1b0ecb4f..1481d7a60c8b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java @@ -808,14 +808,18 @@ public BIROperand[] getRhsOperands() { public static class NewTypeDesc extends BIRNonTerminator { public final List closureVars; public BType type; - public final BIROperand annotations; + public BIROperand annotations; - public NewTypeDesc(Location pos, BIROperand lhsOp, BType type, List closureVars, - BIROperand annotations) { + public NewTypeDesc(Location pos, BIROperand lhsOp, BType type, List closureVars) { super(pos, InstructionKind.NEW_TYPEDESC); this.closureVars = closureVars; this.lhsOp = lhsOp; this.type = type; + } + + public NewTypeDesc(Location pos, BIROperand lhsOp, BType type, List closureVars, + BIROperand annotations) { + this(pos, lhsOp, type, closureVars); this.annotations = annotations; }