Skip to content

Commit

Permalink
Update use of position in desugar
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Jul 21, 2024
1 parent ea1cbba commit ab2f29f
Showing 1 changed file with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10668,7 +10668,7 @@ public BLangLambdaFunction createArrowFunctionForNavigation(Location pos, List<B
expression = rewriteExpr(expression);
}

expression = createExpressionForExtensions(pos, extensions, arrowFunction, expression);
expression = createExpressionForExtensions(extensions, arrowFunction, expression);

arrowFunction.body = new BLangExprFunctionBody();
arrowFunction.body.expr = expression;
Expand All @@ -10677,18 +10677,18 @@ public BLangLambdaFunction createArrowFunctionForNavigation(Location pos, List<B
return (BLangLambdaFunction) result;
}

private BLangExpression createExpressionForExtensions(Location pos, List<BLangXMLStepExtend> extensions,
private BLangExpression createExpressionForExtensions(List<BLangXMLStepExtend> extensions,
BLangArrowFunction arrowFunction,
BLangExpression expression) {
for (BLangXMLStepExtend extension : extensions) {
switch (extension.getKind()) {
case XML_STEP_INDEXED_EXTEND ->
expression = createExpressionForIndexedStepExtend(pos, arrowFunction, expression,
case XML_STEP_INDEXED_EXTEND -> expression =
createExpressionForIndexedStepExtend(arrowFunction, expression,
(BLangXMLIndexedStepExtend) extension);
case XML_STEP_FILTER_EXTEND -> expression =
createExpressionForFilterStepExtend(pos, expression, (BLangXMLFilterStepExtend) extension);
createExpressionForFilterStepExtend(expression, (BLangXMLFilterStepExtend) extension);
case XML_STEP_METHOD_CALL_EXTEND ->
expression = createExpressionForMethodCallStepExtend(pos, arrowFunction, expression,
expression = createExpressionForMethodCallStepExtend(arrowFunction, expression,
(BLangXMLMethodCallStepExtend) extension);
default -> throw new IllegalStateException("Invalid xml step extension: " + extension.getKind());
}
Expand All @@ -10697,36 +10697,36 @@ private BLangExpression createExpressionForExtensions(Location pos, List<BLangXM
return expression;
}

private BLangExpression createExpressionForMethodCallStepExtend(Location pos, BLangArrowFunction arrowFunction,
private BLangExpression createExpressionForMethodCallStepExtend(BLangArrowFunction arrowFunction,
BLangExpression expression,
BLangXMLMethodCallStepExtend methodCallStepExtend) {
BLangInvocation invocation = methodCallStepExtend.invocation;
if (invocation.requiredArgs.size() > 0) {
invocation.requiredArgs.remove(0);
}

for (BLangExpression arg: invocation.requiredArgs) {
markAndAddPossibleClosureVarsToArrowFunction(pos, arrowFunction, arg);
for (BLangExpression arg : invocation.requiredArgs) {
markAndAddPossibleClosureVarsToArrowFunction(arrowFunction, arg);
}
expression = createLanglibXMLInvocation(pos, invocation.name.value, expression, invocation.requiredArgs,
invocation.restArgs);
expression = createLanglibXMLInvocation(methodCallStepExtend.pos, invocation.name.value, expression,
invocation.requiredArgs, invocation.restArgs);
expression = rewrite(expression, env);
return types.addConversionExprIfRequired(expression, symTable.xmlType);
}

private BLangExpression createExpressionForFilterStepExtend(Location pos, BLangExpression expression,
private BLangExpression createExpressionForFilterStepExtend(BLangExpression expression,
BLangXMLFilterStepExtend filterStepExtend) {
ArrayList<BLangExpression> filterExtensions = expandFilters(filterStepExtend.filters);
return createLanglibXMLInvocation(pos, XML_INTERNAL_GET_ELEMENTS, expression, Collections.emptyList(),
filterExtensions);
return createLanglibXMLInvocation(filterStepExtend.pos, XML_INTERNAL_GET_ELEMENTS, expression,
Collections.emptyList(), filterExtensions);
}

private BLangExpression createExpressionForIndexedStepExtend(Location pos, BLangArrowFunction arrowFunction,
private BLangExpression createExpressionForIndexedStepExtend(BLangArrowFunction arrowFunction,
BLangExpression expression,
BLangXMLIndexedStepExtend indexedStepExtend) {
BLangExpression indexExpr = indexedStepExtend.indexExpr;
markAndAddPossibleClosureVarsToArrowFunction(pos, arrowFunction, indexExpr);
return createIndexBasedAccessNode(pos, indexExpr, expression);
markAndAddPossibleClosureVarsToArrowFunction(arrowFunction, indexExpr);
return createIndexBasedAccessNode(indexedStepExtend.pos, indexExpr, expression);
}

private BLangIndexBasedAccess createIndexBasedAccessNode(Location pos, BLangExpression indexExpr,
Expand All @@ -10738,13 +10738,13 @@ private BLangIndexBasedAccess createIndexBasedAccessNode(Location pos, BLangExpr
return indexBasedAccess;
}

private static void markAndAddPossibleClosureVarsToArrowFunction(Location pos, BLangArrowFunction arrFunction,
private static void markAndAddPossibleClosureVarsToArrowFunction(BLangArrowFunction arrFunction,
BLangExpression expression) {
if (expression.getKind() != NodeKind.SIMPLE_VARIABLE_REF) {
return;
}
BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) expression;
simpleVarRef.symbol.closure = true;
arrFunction.closureVarSymbols.add(new ClosureVarSymbol(simpleVarRef.symbol, pos));
arrFunction.closureVarSymbols.add(new ClosureVarSymbol(simpleVarRef.symbol, simpleVarRef.pos));
}
}

0 comments on commit ab2f29f

Please sign in to comment.