Skip to content

Commit

Permalink
Merge pull request #41201 from ballerina-platform/master
Browse files Browse the repository at this point in the history
Sync with master
  • Loading branch information
MaryamZi authored Aug 14, 2023
2 parents d185a95 + 446f250 commit 9a9c189
Show file tree
Hide file tree
Showing 186 changed files with 10,200 additions and 621 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ public Optional<TypeSymbol> typeOf(LineRange range) {
}

private BType getDeterminedType(BLangNode node, LineRange range) {
if (node.getKind() == NodeKind.INVOCATION && node.getDeterminedType().getKind() == TypeKind.FUTURE) {
if (node.getKind() == NodeKind.INVOCATION && node.getDeterminedType() != null
&& node.getDeterminedType().getKind() == TypeKind.FUTURE) {
BLangInvocation invocationNode = (BLangInvocation) node;
if (invocationNode.isAsync()
&& PositionUtil.withinBlock(range.startLine(), invocationNode.getName().getPosition())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Map<String, List<String>> getPackages() {
}
String orgName = file.getName();
File[] filesList = this.bala.resolve(orgName).toFile().listFiles();
if (filesList == null) {
if (filesList == null || filesList.length == 0) {
continue;
}
List<String> pkgList = new ArrayList<>();
Expand All @@ -178,23 +178,24 @@ public Map<String, List<String>> getPackages() {
if (pkgs == null) {
continue;
}
String version = null;
List<String> versions = new ArrayList<>();
for (File listFile : pkgs) {
if (listFile.isHidden() || !listFile.isDirectory()) {
continue;
}
version = listFile.getName();
break;
versions.add(listFile.getName());
}
if (version == null) {
if (versions.isEmpty()) {
continue;
}
try {
PackageVersion.from(version);
} catch (ProjectException ignored) {
continue;
for (String version : versions) {
try {
PackageVersion.from(version);
} catch (ProjectException ignored) {
continue;
}
pkgList.add(pkgDir.getName() + ":" + version);
}
pkgList.add(pkgDir.getName() + ":" + version);
}
packagesMap.put(orgName, pkgList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1631,41 +1631,27 @@ public BType readType(int cpI) throws IOException {
}
return finiteType;
case TypeTags.OBJECT:
boolean service = inputStream.readByte() == 1;

pkgCpIndex = inputStream.readInt();
pkgId = getPackageId(pkgCpIndex);

String objName = getStringCPEntryValue(inputStream);
var objFlags = (inputStream.readBoolean() ? Flags.CLASS : 0) | Flags.PUBLIC;
objFlags = inputStream.readBoolean() ? objFlags | Flags.CLIENT : objFlags;
long objSymFlags = inputStream.readLong();
BObjectTypeSymbol objectSymbol;

if (Symbols.isFlagOn(objFlags, Flags.CLASS)) {
objectSymbol = Symbols.createClassSymbol(objFlags, names.fromString(objName),
env.pkgSymbol.pkgID, null, env.pkgSymbol,
symTable.builtinPos, COMPILED_SOURCE, false);
if (Symbols.isFlagOn(objSymFlags, Flags.CLASS)) {
objectSymbol = Symbols.createClassSymbol(objSymFlags, names.fromString(objName),
env.pkgSymbol.pkgID, null, env.pkgSymbol,
symTable.builtinPos, COMPILED_SOURCE, false);
} else {
objectSymbol = Symbols.createObjectSymbol(objFlags, names.fromString(objName),
env.pkgSymbol.pkgID, null, env.pkgSymbol,
symTable.builtinPos, COMPILED_SOURCE);
objectSymbol = Symbols.createObjectSymbol(objSymFlags, names.fromString(objName),
env.pkgSymbol.pkgID, null, env.pkgSymbol,
symTable.builtinPos, COMPILED_SOURCE);
}

objectSymbol.scope = new Scope(objectSymbol);
BObjectType objectType;
// Below is a temporary fix, need to fix this properly by using the type tag
objectType = new BObjectType(objectSymbol);

if (service) {
objectType.flags |= Flags.SERVICE;
objectSymbol.flags |= Flags.SERVICE;
}
if (isImmutable(flags)) {
objectSymbol.flags |= Flags.READONLY;
}
if (Symbols.isFlagOn(flags, Flags.ANONYMOUS)) {
objectSymbol.flags |= Flags.ANONYMOUS;
}
objectType.flags = flags;
objectSymbol.type = objectType;
addShapeCP(objectType, cpI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,7 @@ public void visit(BLangLiteral astLiteralExpr) {

@Override
public void visit(BLangMapLiteral astMapLiteralExpr) {
this.env.isInArrayOrStructure++;
visitTypedesc(astMapLiteralExpr.pos, astMapLiteralExpr.getBType(), Collections.emptyList());
BIRVariableDcl tempVarDcl =
new BIRVariableDcl(astMapLiteralExpr.getBType(), this.env.nextLocalVarId(names),
Expand All @@ -1552,6 +1553,7 @@ public void visit(BLangMapLiteral astMapLiteralExpr) {
setScopeAndEmit(new BIRNonTerminator.NewStructure(astMapLiteralExpr.pos, toVarRef, this.env.targetOperand,
generateMappingConstructorEntries(astMapLiteralExpr.fields)));
this.env.targetOperand = toVarRef;
this.env.isInArrayOrStructure--;
}

@Override
Expand All @@ -1572,6 +1574,7 @@ public void visit(BLangTypeConversionExpr astTypeConversionExpr) {

@Override
public void visit(BLangStructLiteral astStructLiteralExpr) {
this.env.isInArrayOrStructure++;
List<BIROperand> varDcls = mapToVarDcls(astStructLiteralExpr.enclMapSymbols);
BType type = astStructLiteralExpr.getBType();
visitTypedesc(astStructLiteralExpr.pos, type, varDcls);
Expand All @@ -1588,6 +1591,7 @@ public void visit(BLangStructLiteral astStructLiteralExpr) {
setScopeAndEmit(instruction);

this.env.targetOperand = toVarRef;
this.env.isInArrayOrStructure--;
}

private List<BIROperand> mapToVarDcls(TreeMap<Integer, BVarSymbol> enclMapSymbols) {
Expand Down Expand Up @@ -1838,14 +1842,17 @@ public void visit(BLangPackageVarRef astPackageVarRefExpr) {
setScopeAndEmit(new Move(astPackageVarRefExpr.pos, this.env.targetOperand, varRef));
}
} else {
BIRVariableDcl tempVarDcl = new BIRVariableDcl(astPackageVarRefExpr.getBType(),
this.env.nextLocalVarId(names), VarScope.FUNCTION,
VarKind.TEMP);
this.env.enclFunc.localVars.add(tempVarDcl);
BIROperand tempVarRef = new BIROperand(tempVarDcl);
BIROperand fromVarRef = new BIROperand(getVarRef(astPackageVarRefExpr));
setScopeAndEmit(new Move(astPackageVarRefExpr.pos, fromVarRef, tempVarRef));
this.env.targetOperand = tempVarRef;
if (this.env.isInArrayOrStructure > 0) {
BIRVariableDcl tempVarDcl = new BIRVariableDcl(astPackageVarRefExpr.getBType(),
this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP);
this.env.enclFunc.localVars.add(tempVarDcl);
BIROperand tempVarRef = new BIROperand(tempVarDcl);
BIROperand fromVarRef = new BIROperand(getVarRef(astPackageVarRefExpr));
setScopeAndEmit(new Move(astPackageVarRefExpr.pos, fromVarRef, tempVarRef));
this.env.targetOperand = tempVarRef;
} else {
this.env.targetOperand = new BIROperand(getVarRef(astPackageVarRefExpr));
}
}
this.varAssignment = variableStore;
}
Expand Down Expand Up @@ -1942,6 +1949,7 @@ public void visit(BLangWaitExpr waitExpr) {

@Override
public void visit(BLangWaitForAllExpr.BLangWaitLiteral waitLiteral) {
this.env.isInArrayOrStructure++;
visitTypedesc(waitLiteral.pos, waitLiteral.getBType(), Collections.emptyList());
BIRBasicBlock thenBB = new BIRBasicBlock(this.env.nextBBId());
addToTrapStack(thenBB);
Expand All @@ -1966,6 +1974,7 @@ public void visit(BLangWaitForAllExpr.BLangWaitLiteral waitLiteral) {
this.env.targetOperand = toVarRef;
this.env.enclFunc.basicBlocks.add(thenBB);
this.env.enclBB = thenBB;
this.env.isInArrayOrStructure--;
}

@Override
Expand Down Expand Up @@ -2646,6 +2655,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),
VarScope.FUNCTION, VarKind.TEMP);
Expand Down Expand Up @@ -2695,6 +2705,7 @@ private void generateListConstructorExpr(BLangListConstructorExpr listConstructo
initialValues));
}
this.env.targetOperand = toVarRef;
this.env.isInArrayOrStructure--;
}

private void generateArrayAccess(BLangIndexBasedAccess astArrayAccessExpr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class BIRGenEnv {
// A function can have only one basic block that has a return instruction.
BIRBasicBlock returnBB;

// This is to hold whether a NewArray or NewStructure instruction is being constructed
int isInArrayOrStructure = 0;

BIRGenEnv(BIRPackage birPkg) {
this.enclPkg = birPkg;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.SIMPLE_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STREAM_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STRING_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TABLE_VALUE_IMPL;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TABLE_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TYPEDESC_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TYPE_CHECKER;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TYPE_CONVERTER;
Expand Down Expand Up @@ -1361,7 +1361,7 @@ static String getTargetClass(BType targetType) {
targetTypeClass = MAP_VALUE;
break;
case TypeTags.TABLE:
targetTypeClass = TABLE_VALUE_IMPL;
targetTypeClass = TABLE_VALUE;
break;
case TypeTags.STREAM:
targetTypeClass = STREAM_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_RUNTIME;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_STRAND_METADATA;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_STREAM_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TABLE_VALUE_IMPL;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TABLE_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TYPEDESC;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_XML;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.HANDLE_DESCRIPTOR_FOR_STRING_CONCAT;
Expand All @@ -144,7 +144,7 @@
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_MAP_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_REGEX_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_STREAM_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_TABLE_VALUE_IMPL;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_TABLE_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_TYPEDESC_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.RETURN_XML_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.STRING_BUILDER_APPEND;
Expand Down Expand Up @@ -243,7 +243,7 @@ public static String getFieldTypeSignature(BType bType) {
case TypeTags.STREAM:
return GET_STREAM_VALUE;
case TypeTags.TABLE:
return GET_TABLE_VALUE_IMPL;
return GET_TABLE_VALUE;
case TypeTags.ARRAY:
case TypeTags.TUPLE:
return GET_ARRAY_VALUE;
Expand Down Expand Up @@ -434,7 +434,7 @@ public static String getArgTypeSignature(BType bType) {
case TypeTags.STREAM:
return GET_STREAM_VALUE;
case TypeTags.TABLE:
return GET_TABLE_VALUE_IMPL;
return GET_TABLE_VALUE;
case TypeTags.INVOKABLE:
return GET_FUNCTION_POINTER;
case TypeTags.TYPEDESC:
Expand Down Expand Up @@ -489,7 +489,7 @@ public static String generateReturnType(BType bType) {
case TypeTags.STREAM:
return RETURN_STREAM_VALUE;
case TypeTags.TABLE:
return RETURN_TABLE_VALUE_IMPL;
return RETURN_TABLE_VALUE;
case TypeTags.FUTURE:
return RETURN_FUTURE_VALUE;
case TypeTags.TYPEDESC:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STRING_TYPE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STRING_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TABLE_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TABLE_VALUE_IMPL;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.THROWABLE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TOML_DETAILS;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TRANSACTION_CONTEXT_CLASS;
Expand Down Expand Up @@ -253,7 +252,7 @@ public class JvmSignatures {
public static final String GET_STRING = "L" + STRING_VALUE + ";";
public static final String GET_STRING_AT = "(L" + B_STRING_VALUE + ";J)L" + B_STRING_VALUE + ";";
public static final String GET_STRING_FROM_ARRAY = "(J)L" + OBJECT + ";";
public static final String GET_TABLE_VALUE_IMPL = "L" + TABLE_VALUE_IMPL + ";";
public static final String GET_TABLE_VALUE = "L" + TABLE_VALUE + ";";
public static final String GET_THROWABLE = "L" + THROWABLE + ";";
public static final String GET_TUPLE_TYPE_IMPL = "L" + TUPLE_TYPE_IMPL + ";";
public static final String GET_TYPE = "L" + TYPE + ";";
Expand Down Expand Up @@ -418,7 +417,7 @@ public class JvmSignatures {
public static final String RETURN_MAP_VALUE = ")L" + MAP_VALUE + ";";
public static final String RETURN_OBJECT = "()L" + OBJECT + ";";
public static final String RETURN_STREAM_VALUE = ")L" + STREAM_VALUE + ";";
public static final String RETURN_TABLE_VALUE_IMPL = ")L" + TABLE_VALUE_IMPL + ";";
public static final String RETURN_TABLE_VALUE = ")L" + TABLE_VALUE + ";";
public static final String RETURN_TYPEDESC_VALUE = ")L" + TYPEDESC_VALUE + ";";
public static final String RETURN_XML_VALUE = ")L" + XML_VALUE + ";";
public static final String SCHEDULE_LOCAL = "([L" + OBJECT + ";L" + B_FUNCTION_POINTER + ";L" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_OBJECT;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_REGEXP;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_STREAM_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TABLE_VALUE_IMPL;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TABLE_VALUE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TYPE;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TYPEDESC;
import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.GET_TYPE_REF_TYPE_IMPL;
Expand Down Expand Up @@ -985,7 +985,8 @@ private void populateFunctionParameters(MethodVisitor mv, BInvokableTypeSymbol i
} else {
mv.visitInsn(ICONST_0);
}
BInvokableSymbol bInvokableSymbol = invokableSymbol.defaultValues.get(paramSymbol.originalName.value);
BInvokableSymbol bInvokableSymbol = invokableSymbol.defaultValues.get(
Utils.decodeIdentifier(paramSymbol.name.value));
if (bInvokableSymbol == null) {
mv.visitInsn(ACONST_NULL);
} else {
Expand Down Expand Up @@ -1086,7 +1087,7 @@ public static String getTypeDesc(BType bType) {
case TypeTags.STREAM:
return GET_STREAM_VALUE;
case TypeTags.TABLE:
return GET_TABLE_VALUE_IMPL;
return GET_TABLE_VALUE;
case TypeTags.DECIMAL:
return GET_BDECIMAL;
case TypeTags.OBJECT:
Expand Down
Loading

0 comments on commit 9a9c189

Please sign in to comment.