Skip to content

Commit

Permalink
Merge pull request #41984 from poorna2152/xml_access
Browse files Browse the repository at this point in the history
Fix module constant usage in xml attribute access
  • Loading branch information
gimantha authored Oct 1, 2024
2 parents 9079d46 + 1136cda commit d93ec61
Show file tree
Hide file tree
Showing 28 changed files with 332 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ public void visit(BLangFieldBasedAccess fieldAccessExpr) {
}

@Override
public void visit(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess nsPrefixedFieldBasedAccess) {
public void visit(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess prefixedFieldBasedAccess) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
import org.wso2.ballerinalang.compiler.tree.expressions.BLangErrorVarRef;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangGroupExpr;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation;
Expand Down Expand Up @@ -862,9 +862,9 @@ public void visit(BLangFieldBasedAccess fieldAccessExpr) {
}

@Override
public void visit(BLangNSPrefixedFieldBasedAccess nsPrefixedFieldBasedAccess) {
find(nsPrefixedFieldBasedAccess.expr);
addIfSameSymbol(nsPrefixedFieldBasedAccess.nsSymbol, nsPrefixedFieldBasedAccess.nsPrefix.pos);
public void visit(BLangPrefixedFieldBasedAccess prefixedFieldBasedAccess) {
find(prefixedFieldBasedAccess.expr);
addIfSameSymbol(prefixedFieldBasedAccess.symbol, prefixedFieldBasedAccess.prefix.pos);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,12 +920,12 @@ public void visit(BLangFieldBasedAccess fieldAccessExpr) {
}

@Override
public void visit(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess nsPrefixedFieldBasedAccess) {
if (setEnclosingNode(nsPrefixedFieldBasedAccess.nsSymbol, nsPrefixedFieldBasedAccess.nsPrefix.pos)) {
public void visit(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess prefixedFieldBasedAccess) {
if (setEnclosingNode(prefixedFieldBasedAccess.symbol, prefixedFieldBasedAccess.prefix.pos)) {
return;
}

lookupNode(nsPrefixedFieldBasedAccess.expr);
lookupNode(prefixedFieldBasedAccess.expr);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ public static FieldBasedAccessNode createFieldBasedAccessNode() {
}

public static FieldBasedAccessNode createFieldBasedAccessWithPrefixNode() {
return new BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess();
return new BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess();
}

public static TableKeySpecifierNode createTableKeySpecifierNode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public enum DiagnosticErrorCode implements DiagnosticCode {
INVALID_NAMESPACE_DECLARATION("BCE2624", "invalid.namespace.declaration"),
CANNOT_UPDATE_XML_SEQUENCE("BCE2625", "cannot.update.xml.sequence"),
INVALID_XML_NS_INTERPOLATION("BCE2626", "invalid.xml.ns.interpolation"),
CANNOT_FIND_XML_NAMESPACE("BCE2627", "cannot.find.xml.namespace.prefix"),
CANNOT_FIND_XML_NAMESPACE("BCE2627", "cannot.find.xml.prefix"),
UNSUPPORTED_METHOD_INVOCATION_XML_NAV("BCE2628", "method.invocation.in.xml.navigation.expressions.not.supported"),
DEPRECATED_XML_ATTRIBUTE_ACCESS("BCE2629", "deprecated.xml.attribute.access.expression"),
UNSUPPORTED_MEMBER_ACCESS_IN_XML_NAVIGATION("BCE2630",
Expand Down Expand Up @@ -424,6 +424,7 @@ public enum DiagnosticErrorCode implements DiagnosticCode {
"invalid.field.binding.pattern.with.non.required.field"),
INFER_SIZE_ONLY_SUPPORTED_IN_FIRST_DIMENSION("BCE2654", "infer.size.only.supported.in.the.first.dimension"),
FUNCTION_CALL_SYNTAX_NOT_DEFINED("BCE2655", "function.call.syntax.not.defined"),
UNDEFINED_CONSTANT_SYMBOL("BCE2656", "undefined.constant.symbol"),

// Error codes related to iteration.
ITERABLE_NOT_SUPPORTED_COLLECTION("BCE2800", "iterable.not.supported.collection"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1506,9 +1506,8 @@ public void visit(BLangIsLikeExpr isLikeExpr) {
result = isLikeExpr;
}

@Override
public void visit(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess nsPrefixedFieldBasedAccess) {
result = nsPrefixedFieldBasedAccess;
public void visit(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess prefixedFieldBasedAccess) {
result = prefixedFieldBasedAccess;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,9 @@ public void visit(BLangFieldBasedAccess fieldAccessExpr) {
}

@Override
public void visit(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess nsPrefixedFieldBasedAccess) {
nsPrefixedFieldBasedAccess.expr = rewrite(nsPrefixedFieldBasedAccess.expr);
result = nsPrefixedFieldBasedAccess;
public void visit(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess prefixedFieldBasedAccess) {
prefixedFieldBasedAccess.expr = rewrite(prefixedFieldBasedAccess.expr);
result = prefixedFieldBasedAccess;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6329,8 +6329,8 @@ public void visit(BLangSimpleVarRef varRefExpr) {
}

@Override
public void visit(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess nsPrefixedFieldBasedAccess) {
rewriteFieldBasedAccess(nsPrefixedFieldBasedAccess);
public void visit(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess prefixedFieldBasedAccess) {
rewriteFieldBasedAccess(prefixedFieldBasedAccess);
}

private void rewriteFieldBasedAccess(BLangFieldBasedAccess fieldAccessExpr) {
Expand Down Expand Up @@ -6624,9 +6624,13 @@ private BLangInvocation rewriteXMLAttributeOrElemNameAccess(BLangFieldBasedAcces

String fieldName = fieldAccessExpr.field.value;
if (fieldAccessExpr.fieldKind == FieldKind.WITH_NS) {
BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess nsPrefixAccess =
(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess) fieldAccessExpr;
fieldName = createExpandedQName(nsPrefixAccess.nsSymbol.namespaceURI, fieldName);
BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess prefixAccess =
(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess) fieldAccessExpr;
if (prefixAccess.symbol.getKind() == SymbolKind.CONSTANT) {
fieldName = (String) ((BConstantSymbol) prefixAccess.symbol).value.value;
} else {
fieldName = createExpandedQName(((BXMLNSSymbol) prefixAccess.symbol).namespaceURI, fieldName);
}
}

// Handle element name access.
Expand Down Expand Up @@ -10310,9 +10314,9 @@ private BLangMatchClause getSuccessPatternClause(BType type, BLangExpression mat
if (accessExpr.getKind() == NodeKind.INDEX_BASED_ACCESS_EXPR) {
((BLangIndexBasedAccess) tempAccessExpr).indexExpr = ((BLangIndexBasedAccess) accessExpr).indexExpr;
}
if (accessExpr instanceof BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess) {
((BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess) tempAccessExpr).nsSymbol =
((BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess) accessExpr).nsSymbol;
if (accessExpr instanceof BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess) {
((BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess) tempAccessExpr).symbol =
((BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess) accessExpr).symbol;
}

tempAccessExpr.expr = types.addConversionExprIfRequired(successPatternVarRef, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1713,9 +1713,9 @@ public void visit(BLangFieldBasedAccess fieldAccessExpr) {
}

@Override
public void visit(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess nsPrefixedFieldBasedAccess) {
nsPrefixedFieldBasedAccess.expr = rewrite(nsPrefixedFieldBasedAccess.expr);
result = nsPrefixedFieldBasedAccess;
public void visit(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess prefixedFieldBasedAccess) {
prefixedFieldBasedAccess.expr = rewrite(prefixedFieldBasedAccess.expr);
result = prefixedFieldBasedAccess;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2175,10 +2175,10 @@ public BLangNode transform(FieldAccessExpressionNode fieldAccessExprNode) {
Node fieldName = fieldAccessExprNode.fieldName();
if (fieldName.kind() == SyntaxKind.QUALIFIED_NAME_REFERENCE) {
QualifiedNameReferenceNode qualifiedFieldName = (QualifiedNameReferenceNode) fieldName;
BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess accessWithPrefixNode =
(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess)
BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess accessWithPrefixNode =
(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess)
TreeBuilder.createFieldBasedAccessWithPrefixNode();
accessWithPrefixNode.nsPrefix = createIdentifier(qualifiedFieldName.modulePrefix());
accessWithPrefixNode.prefix = createIdentifier(qualifiedFieldName.modulePrefix());
accessWithPrefixNode.field = createIdentifier(qualifiedFieldName.identifier());
bLFieldBasedAccess = accessWithPrefixNode;
bLFieldBasedAccess.fieldKind = FieldKind.WITH_NS;
Expand Down Expand Up @@ -2209,10 +2209,10 @@ public BLangNode transform(OptionalFieldAccessExpressionNode optionalFieldAccess

if (fieldName.kind() == SyntaxKind.QUALIFIED_NAME_REFERENCE) {
QualifiedNameReferenceNode qualifiedFieldName = (QualifiedNameReferenceNode) fieldName;
BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess accessWithPrefixNode =
(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess) TreeBuilder
BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess accessWithPrefixNode =
(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess) TreeBuilder
.createFieldBasedAccessWithPrefixNode();
accessWithPrefixNode.nsPrefix = createIdentifier(qualifiedFieldName.modulePrefix());
accessWithPrefixNode.prefix = createIdentifier(qualifiedFieldName.modulePrefix());
accessWithPrefixNode.field = createIdentifier(qualifiedFieldName.identifier());
bLFieldBasedAccess = accessWithPrefixNode;
bLFieldBasedAccess.fieldKind = FieldKind.WITH_NS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1171,13 +1171,13 @@ public void visit(BLangFieldBasedAccess source) {
}

@Override
public void visit(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess source) {
public void visit(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess source) {

BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess clone =
new BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess();
BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess clone =
new BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess();

source.cloneRef = clone;
clone.nsPrefix = source.nsPrefix;
clone.prefix = source.prefix;
clone.field = source.field;
clone.fieldKind = source.fieldKind;
cloneBLangAccessExpression(source, clone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2577,9 +2577,9 @@ public void visit(BLangFieldBasedAccess fieldAccessExpr, AnalyzerData data) {
}

@Override
public void visit(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess nsPrefixedFieldBasedAccess,
public void visit(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess prefixedFieldBasedAccess,
AnalyzerData data) {
analyzeFieldBasedAccessExpr(nsPrefixedFieldBasedAccess, data);
analyzeFieldBasedAccessExpr(prefixedFieldBasedAccess, data);
}

private void analyzeFieldBasedAccessExpr(BLangFieldBasedAccess fieldAccessExpr, AnalyzerData data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1621,11 +1621,11 @@ public void visit(BLangFieldBasedAccess fieldAccessExpr) {
}

@Override
public void visit(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess nsPrefixedFieldBasedAccess) {
if (!nsPrefixedFieldBasedAccess.isLValue && isObjectMemberAccessWithSelf(nsPrefixedFieldBasedAccess)) {
checkVarRef(nsPrefixedFieldBasedAccess.symbol, nsPrefixedFieldBasedAccess.pos);
public void visit(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess prefixedFieldBasedAccess) {
if (!prefixedFieldBasedAccess.isLValue && isObjectMemberAccessWithSelf(prefixedFieldBasedAccess)) {
checkVarRef(prefixedFieldBasedAccess.symbol, prefixedFieldBasedAccess.pos);
}
analyzeNode(nsPrefixedFieldBasedAccess.expr, env);
analyzeNode(prefixedFieldBasedAccess.expr, env);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,8 @@ public void visit(BLangFieldBasedAccess fieldAccessExpr) {
}

@Override
public void visit(BLangFieldBasedAccess.BLangNSPrefixedFieldBasedAccess nsPrefixedFieldBasedAccess) {
analyzeFieldBasedAccess(nsPrefixedFieldBasedAccess);
public void visit(BLangFieldBasedAccess.BLangPrefixedFieldBasedAccess prefixedFieldBasedAccess) {
analyzeFieldBasedAccess(prefixedFieldBasedAccess);
}

private void analyzeFieldBasedAccess(BLangFieldBasedAccess fieldAccessExpr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,27 @@ public BSymbol lookupMemberSymbol(Location pos,
return symTable.notFoundSymbol;
}

/**
* Return the symbol with the given name even with a different package.
*
* @param scope current scope
* @param name symbol name
* @param expSymTag expected symbol type/tag
* @return resolved symbol
*/
public BSymbol lookupPossibleMemberSymbol(Scope scope, Name name, long expSymTag) {
ScopeEntry entry = scope.lookup(name);
while (entry != NOT_FOUND_ENTRY) {
if ((entry.symbol.tag & expSymTag) != expSymTag) {
entry = entry.next;
continue;
}
return entry.symbol;
}

return symTable.notFoundSymbol;
}

/**
* Resolve and return the namespaces visible to the given environment, as a map.
*
Expand Down
Loading

0 comments on commit d93ec61

Please sign in to comment.