Skip to content

Commit

Permalink
Fix failing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Nov 7, 2023
1 parent 28fbbb8 commit 2491ece
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.wso2.ballerinalang.compiler.bir.codegen;

import io.ballerina.identifier.Utils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.ballerinalang.compiler.BLangCompilerException;
import org.ballerinalang.model.elements.PackageID;
import org.ballerinalang.model.symbols.SymbolKind;
Expand Down Expand Up @@ -653,7 +652,7 @@ private void loadTableType(MethodVisitor mv, BTableType bType) {
mv.visitInsn(DUP);
mv.visitLdcInsn((long) i);
mv.visitInsn(L2I);
mv.visitLdcInsn(StringEscapeUtils.unescapeJava(fieldName));
mv.visitLdcInsn(fieldName);
mv.visitInsn(AASTORE);
i += 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.wso2.ballerinalang.compiler.desugar;

import io.ballerina.identifier.Utils;
import io.ballerina.tools.diagnostics.Location;
import org.ballerinalang.model.TreeBuilder;
import org.ballerinalang.model.elements.Flag;
Expand Down Expand Up @@ -556,7 +555,7 @@ private BLangExpression createClosureForDefaultValue(String closureName, String
env.enclPkg.symbol.scope.define(function.symbol.name, function.symbol);
env.enclPkg.functions.add(function);
env.enclPkg.topLevelNodes.add(function);
symbol.defaultValues.put(Utils.unescapeBallerina(paramName), varSymbol);
symbol.defaultValues.put(paramName, varSymbol);
return returnStmt.expr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
*/
package org.wso2.ballerinalang.compiler.desugar;

import io.ballerina.identifier.Utils;
import io.ballerina.runtime.api.constants.RuntimeConstants;
import io.ballerina.tools.diagnostics.Location;
import org.apache.commons.lang3.StringEscapeUtils;
import org.ballerinalang.compiler.CompilerPhase;
import org.ballerinalang.model.TreeBuilder;
import org.ballerinalang.model.elements.AttachPoint;
Expand Down Expand Up @@ -1819,9 +1817,8 @@ private void createVarDefStmts(BLangRecordVariable parentRecordVariable, BLangBl
List<BLangRecordVariableKeyValue> variableList = parentRecordVariable.variableList;
for (BLangRecordVariableKeyValue recordFieldKeyValue : variableList) {
BLangVariable variable = recordFieldKeyValue.valueBindingPattern;
BLangLiteral indexExpr = ASTBuilderUtil.createLiteral(variable.pos, symTable.stringType,
StringEscapeUtils.unescapeJava(
recordFieldKeyValue.key.value));
BLangLiteral indexExpr =
ASTBuilderUtil.createLiteral(variable.pos, symTable.stringType, recordFieldKeyValue.key.value);

if (recordFieldKeyValue.valueBindingPattern.getKind() == NodeKind.VARIABLE) {
createSimpleVarDefStmt((BLangSimpleVariable) recordFieldKeyValue.valueBindingPattern, parentBlockStmt,
Expand Down Expand Up @@ -2864,8 +2861,7 @@ private void createVarRefAssignmentStmts(BLangRecordVarRef parentRecordVarRef, B
for (BLangRecordVarRefKeyValue varRefKeyValue : variableRefList) {
BLangExpression expression = varRefKeyValue.variableReference;
BLangLiteral indexExpr = ASTBuilderUtil.createLiteral(expression.pos, symTable.stringType,
StringEscapeUtils.unescapeJava(
varRefKeyValue.variableName.getValue()));
varRefKeyValue.variableName.getValue());

if (NodeKind.SIMPLE_VARIABLE_REF == expression.getKind() ||
NodeKind.FIELD_BASED_ACCESS_EXPR == expression.getKind() ||
Expand Down Expand Up @@ -6055,8 +6051,7 @@ private void rewriteFieldBasedAccess(BLangFieldBasedAccess fieldAccessExpr) {
fieldAccessExpr.expr = addConversionExprIfRequired(fieldAccessExpr.expr, varRefType);
}

BLangLiteral stringLit = createStringLiteral(fieldAccessExpr.field.pos,
StringEscapeUtils.unescapeJava(fieldAccessExpr.field.value));
BLangLiteral stringLit = createStringLiteral(fieldAccessExpr.field.pos, fieldAccessExpr.field.value);
BType refType = Types.getImpliedType(varRefType);
int varRefTypeTag = refType.tag;
if (varRefTypeTag == TypeTags.OBJECT ||
Expand Down Expand Up @@ -6481,7 +6476,7 @@ private BLangStatementExpression createStmtExpr(BLangInvocation invocation) {
continue;
}

BInvokableSymbol invokableSymbol = defaultValues.get(Utils.unescapeBallerina(paramName));
BInvokableSymbol invokableSymbol = defaultValues.get(paramName);
BLangInvocation closureInvocation = getInvocation(invokableSymbol);
for (int m = 0; m < invokableSymbol.params.size(); m++) {
String langLibFuncParam = invokableSymbol.params.get(m).name.value;
Expand Down Expand Up @@ -6530,8 +6525,8 @@ public void visit(BLangErrorConstructorExpr errorConstructorExpr) {
} else {
for (BLangNamedArgsExpression namedArg : errorConstructorExpr.namedArgs) {
BLangRecordLiteral.BLangRecordKeyValueField member = new BLangRecordLiteral.BLangRecordKeyValueField();
member.key = new BLangRecordLiteral.BLangRecordKey(ASTBuilderUtil.createLiteral(namedArg.name.pos,
symTable.stringType, StringEscapeUtils.unescapeJava(namedArg.name.value)));
member.key = new BLangRecordLiteral.BLangRecordKey(
ASTBuilderUtil.createLiteral(namedArg.name.pos, symTable.stringType, namedArg.name.value));

if (Types.getImpliedType(recordLiteral.getBType()).tag == TypeTags.RECORD) {
member.valueExpr = addConversionExprIfRequired(namedArg.expr, symTable.anyType);
Expand Down Expand Up @@ -10347,8 +10342,8 @@ private BLangRecordLiteral rewriteMappingConstructor(BLangRecordLiteral mappingC
if (key.computedKey) {
keyExpr = origKey;
} else {
keyExpr = origKey.getKind() == NodeKind.SIMPLE_VARIABLE_REF ? createStringLiteral(pos,
StringEscapeUtils.unescapeJava(((BLangSimpleVarRef) origKey).variableName.value)) :
keyExpr = origKey.getKind() == NodeKind.SIMPLE_VARIABLE_REF ?
createStringLiteral(pos, ((BLangSimpleVarRef) origKey).variableName.value) :
((BLangLiteral) origKey);
}

Expand All @@ -10361,8 +10356,7 @@ private BLangRecordLiteral rewriteMappingConstructor(BLangRecordLiteral mappingC
} else if (field.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
BLangSimpleVarRef varRefField = (BLangSimpleVarRef) field;
rewrittenFields.add(ASTBuilderUtil.createBLangRecordKeyValue(
rewriteExpr(createStringLiteral(pos,
StringEscapeUtils.unescapeJava(varRefField.variableName.value))),
rewriteExpr(createStringLiteral(pos, varRefField.variableName.value)),
rewriteExpr(varRefField)));
} else {
BLangRecordLiteral.BLangRecordSpreadOperatorField spreadOpField =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ private void createAnonymousTypeDefForConstantDeclaration(BLangConstant constant

// Create a new anonymous type definition.
BLangTypeDefinition typeDef = (BLangTypeDefinition) TreeBuilder.createTypeDefinition();
this.anonTypeNameSuffixes.push(constantNode.name.value);
this.anonTypeNameSuffixes.push(constantNode.name.originalValue);
String genName = anonymousModelHelper.getNextAnonymousTypeKey(packageID, anonTypeNameSuffixes);
this.anonTypeNameSuffixes.pop();
IdentifierNode anonTypeGenName = createIdentifier(symTable.builtinPos, genName, constantNode.name.value);
Expand Down Expand Up @@ -967,7 +967,7 @@ public BLangNode transform(TypeDefinitionNode typeDefNode) {
typeDef.markdownDocumentationAttachment =
createMarkdownDocumentationAttachment(getDocumentationString(typeDefNode.metadata()));

this.anonTypeNameSuffixes.push(typeDef.name.value);
this.anonTypeNameSuffixes.push(typeDef.name.originalValue);
typeDef.typeNode = createTypeNode(typeDefNode.typeDescriptor());
this.anonTypeNameSuffixes.pop();

Expand Down Expand Up @@ -1569,7 +1569,7 @@ private void populateFunctionNode(BLangIdentifier name, NodeList<Token> qualifie
//Set method qualifiers
setFunctionQualifiers(bLFunction, qualifierList);
// Set function signature
this.anonTypeNameSuffixes.push(name.value);
this.anonTypeNameSuffixes.push(name.originalValue);
populateFuncSignature(bLFunction, functionSignature);
this.anonTypeNameSuffixes.pop();

Expand Down Expand Up @@ -1765,10 +1765,10 @@ public BLangNode transform(NamedWorkerDeclarationNode namedWorkerDeclNode) {
String workerOriginalName = workerName;
if (workerName.startsWith(IDENTIFIER_LITERAL_PREFIX)) {
bLFunction.defaultWorkerName.setOriginalValue(workerName);
workerName = Utils.unescapeUnicodeCodepoints(workerName.substring(1));
workerName = workerName.substring(1);
}

bLFunction.defaultWorkerName.value = workerName;
bLFunction.defaultWorkerName.value = Utils.unescapeBallerina(workerName);
bLFunction.defaultWorkerName.pos = getPosition(namedWorkerDeclNode.workerName());

NodeList<AnnotationNode> annotations = namedWorkerDeclNode.annotations();
Expand Down Expand Up @@ -3843,7 +3843,7 @@ public BLangConstant transformEnumMember(EnumMemberNode member, Boolean publicQu

BLangIdentifier memberName = (BLangIdentifier) transform(member.identifier());
bLangConstant.setName(memberName);
this.anonTypeNameSuffixes.push(memberName.value);
this.anonTypeNameSuffixes.push(memberName.originalValue);

BLangExpression deepLiteral;
if (member.constExprNode().isPresent()) {
Expand All @@ -3868,7 +3868,7 @@ public BLangConstant transformEnumMember(EnumMemberNode member, Boolean publicQu
literal.originalValue = null;
typeNodeAssociated.addValue(deepLiteral);
bLangConstant.associatedTypeDefinition = createTypeDefinitionWithTypeNode(typeNodeAssociated,
memberName.value);
memberName.originalValue);
} else {
bLangConstant.associatedTypeDefinition = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.wso2.ballerinalang.compiler.semantics.analyzer;

import io.ballerina.identifier.Utils;
import io.ballerina.tools.diagnostics.Location;
import org.ballerinalang.compiler.CompilerPhase;
import org.ballerinalang.model.elements.Flag;
Expand Down Expand Up @@ -2326,8 +2325,7 @@ public void visit(BLangRecordLiteral recordLiteral, AnalyzerData data) {
}
}

LinkedHashMap<String, BField> fieldsInRecordType = getUnescapedFieldList(spreadExprRecordType.fields);

LinkedHashMap<String, BField> fieldsInRecordType = spreadExprRecordType.fields;
for (Object fieldName : names) {
if (!fieldsInRecordType.containsKey(fieldName) && !isSpreadExprRecordTypeSealed) {
this.dlog.error(spreadOpExpr.pos,
Expand Down Expand Up @@ -2378,24 +2376,21 @@ public void visit(BLangRecordLiteral recordLiteral, AnalyzerData data) {

if (keyExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
String name = ((BLangSimpleVarRef) keyExpr).variableName.value;
String unescapedName = Utils.unescapeJava(name);
if (names.contains(unescapedName)) {
if (names.contains(name)) {
this.dlog.error(keyExpr.pos, DiagnosticErrorCode.DUPLICATE_KEY_IN_MAPPING_CONSTRUCTOR,
Types.getImpliedType(recordLiteral.expectedType).getKind().typeName(),
unescapedName);
} else if (inclusiveTypeSpreadField != null && !neverTypedKeys.contains(unescapedName)) {
Types.getImpliedType(recordLiteral.expectedType).getKind().typeName(), name);
} else if (inclusiveTypeSpreadField != null && !neverTypedKeys.contains(name)) {
this.dlog.error(keyExpr.pos,
DiagnosticErrorCode.POSSIBLE_DUPLICATE_OF_FIELD_SPECIFIED_VIA_SPREAD_OP,
unescapedName, inclusiveTypeSpreadField);
DiagnosticErrorCode.POSSIBLE_DUPLICATE_OF_FIELD_SPECIFIED_VIA_SPREAD_OP, name,
inclusiveTypeSpreadField);
}

if (!isInferredRecordForMapCET && isOpenRecord
&& !((BRecordType) referredType).fields.containsKey(name)) {
dlog.error(keyExpr.pos, DiagnosticErrorCode.INVALID_RECORD_LITERAL_IDENTIFIER_KEY,
unescapedName);
dlog.error(keyExpr.pos, DiagnosticErrorCode.INVALID_RECORD_LITERAL_IDENTIFIER_KEY, name);
}

names.add(unescapedName);
names.add(name);
} else if (keyExpr.getKind() == NodeKind.LITERAL || keyExpr.getKind() == NodeKind.NUMERIC_LITERAL) {
Object name = ((BLangLiteral) keyExpr).value;
if (names.contains(name)) {
Expand All @@ -2421,16 +2416,7 @@ public void visit(BLangRecordLiteral recordLiteral, AnalyzerData data) {
public void visit(BLangRecordLiteral.BLangRecordVarNameField node, AnalyzerData data) {
visit((BLangSimpleVarRef) node, data);
}

private LinkedHashMap<String, BField> getUnescapedFieldList(LinkedHashMap<String, BField> fieldMap) {
LinkedHashMap<String, BField> newMap = new LinkedHashMap<>();
for (String key : fieldMap.keySet()) {
newMap.put(Utils.unescapeJava(key), fieldMap.get(key));
}

return newMap;
}


@Override
public void visit(BLangSimpleVarRef varRefExpr, AnalyzerData data) {
switch (varRefExpr.parent.getKind()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ public BType transform(BLangUserDefinedType userDefinedTypeNode, AnalyzerData da
if (!missingNodesHelper.isMissingNode(pkgAlias) && !missingNodesHelper.isMissingNode(typeName) &&
!symbolEnter.isUnknownTypeRef(userDefinedTypeNode)
&& typeResolver.isNotUnknownTypeRef(userDefinedTypeNode)) {
dlog.error(userDefinedTypeNode.pos, data.diagCode, typeName);
dlog.error(userDefinedTypeNode.pos, data.diagCode, names.originalNameFromIdNode(typeNameIdentifier));
}
return symTable.semanticError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.wso2.ballerinalang.compiler.semantics.analyzer;

import io.ballerina.identifier.Utils;
import io.ballerina.tools.diagnostics.DiagnosticCode;
import io.ballerina.tools.diagnostics.Location;
import org.ballerinalang.model.TreeBuilder;
Expand Down Expand Up @@ -2990,7 +2989,7 @@ public void visit(BLangSimpleVarRef varRefExpr, AnalyzerData data) {
}
} else {
varRefExpr.symbol = symbol; // Set notFoundSymbol
logUndefinedSymbolError(varRefExpr.pos, varName.value);
logUndefinedSymbolError(varRefExpr.pos, names.originalNameFromIdNode(identifier).value);
}
}

Expand Down Expand Up @@ -8893,7 +8892,7 @@ private BType checkRecordIndexBasedAccess(BLangIndexBasedAccess accessExpr, BRec
case TypeTags.STRING:
case TypeTags.CHAR_STRING:
if (isConstExpr(indexExpr)) {
String fieldName = Utils.escapeSpecialCharacters(getConstFieldName(indexExpr));
String fieldName = getConstFieldName(indexExpr);
actualType = checkRecordRequiredFieldAccess(accessExpr, names.fromString(fieldName), record, data);
if (actualType != symTable.semanticError) {
return actualType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1840,10 +1840,15 @@ public BType defineTypeDefinition(BLangTypeDefinition typeDefinition, BType reso
BSymbol typeDefSymbol = Symbols.createTypeDefinitionSymbol(Flags.asMask(typeDefinition.flagSet),
names.fromIdNode(typeDefinition.name), env.enclPkg.packageID, resolvedType, env.scope.owner,
typeDefinition.name.pos, symEnter.getOrigin(typeDefinition.name.value));
if (!PackageID.isLangLibPackageID(env.enclPkg.packageID)) {
typeDefSymbol.originalName = names.originalNameFromIdNode(typeDefinition.name);
}
typeDefSymbol.markdownDocumentation =
symEnter.getMarkdownDocAttachment(typeDefinition.markdownDocumentationAttachment);
BTypeSymbol typeSymbol = new BTypeSymbol(SymTag.TYPE_REF, typeDefSymbol.flags, typeDefSymbol.name,
typeDefSymbol.pkgID, typeDefSymbol.type, typeDefSymbol.owner, typeDefSymbol.pos, typeDefSymbol.origin);
BTypeSymbol typeSymbol =
new BTypeSymbol(SymTag.TYPE_REF, typeDefSymbol.flags, typeDefSymbol.name, typeDefSymbol.originalName,
typeDefSymbol.pkgID, typeDefSymbol.type, typeDefSymbol.owner, typeDefSymbol.pos,
typeDefSymbol.origin);
typeSymbol.markdownDocumentation = typeDefSymbol.markdownDocumentation;
((BTypeDefinitionSymbol) typeDefSymbol).referenceType = new BTypeReferenceType(resolvedType, typeSymbol,
typeDefSymbol.type.flags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import io.ballerina.compiler.syntax.tree.TreeModifier;
import io.ballerina.identifier.Utils;

import static io.ballerina.identifier.Utils.unescapeUnicodeCodepoints;

/**
* Identifier specific expression modifier implementation.
*/
Expand All @@ -39,7 +37,7 @@ public IdentifierToken transform(IdentifierToken identifier) {
identifierText = identifierText.substring(1);
}
// Processes escaped unicode codepoints.
String unescapedIdentifier = unescapeUnicodeCodepoints(identifierText);
String unescapedIdentifier = Utils.unescapeBallerina(identifierText);

// Encodes the user provided identifier in order to be aligned with JVM runtime identifiers.
NonTerminalNode parent = identifier.parent();
Expand All @@ -58,7 +56,7 @@ public static String encodeIdentifier(String identifier, IdentifierType type) {
if (identifier.startsWith(QUOTED_IDENTIFIER_PREFIX)) {
identifier = identifier.substring(1);
}
identifier = Utils.unescapeUnicodeCodepoints(identifier);
identifier = Utils.unescapeBallerina(identifier);
return type == IdentifierType.METHOD_NAME ? Utils.encodeFunctionIdentifier(identifier) :
Utils.encodeNonFunctionIdentifier(identifier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public Value getChildByName(String name) throws DebugVariableException {
}

if (!namedChildVariables.containsKey(name)) {
for (Map.Entry<String, Value> childVariable : namedChildVariables.entrySet()) {
String escaped = childVariable.getKey().replaceAll("\\$0092(\\$0092)?", "$1");
if (escaped.equals(name)) {
return childVariable.getValue();
}
}
throw new DebugVariableException("No child variables found with name: '" + name + "'");
}
return namedChildVariables.get(name);
Expand Down
Loading

0 comments on commit 2491ece

Please sign in to comment.