use of org.wso2.ballerinalang.compiler.tree.statements.BLangReturn in project ballerina by ballerina-lang.
the class SymbolEnter method addInitReturnStatement.
private void addInitReturnStatement(BLangBlockStmt bLangBlockStmt) {
// Add return statement to the init function
BLangReturn returnStmt = (BLangReturn) TreeBuilder.createReturnNode();
returnStmt.pos = bLangBlockStmt.pos;
bLangBlockStmt.addStatement(returnStmt);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangReturn in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangReturn returnNode) {
List<Boolean> returnTaintedStatus = new ArrayList<>();
if (returnNode.namedReturnVariables == null) {
// If named returns are not used, evaluate each expression to identify the tainted status.
for (BLangExpression expr : returnNode.exprs) {
expr.accept(this);
returnTaintedStatus.addAll(taintedStatusList);
}
} else {
// If named returns are used, report back the tainted status of each variable.
for (BLangVariable var : returnNode.namedReturnVariables) {
returnTaintedStatus.add(var.symbol.tainted);
}
}
if (returnTaintedStatusList == null) {
returnTaintedStatusList = returnTaintedStatus;
} else {
// collective tainted status of returns.
for (int i = 0; i < returnTaintedStatusList.size(); i++) {
if (returnTaintedStatus.size() > i && returnTaintedStatus.get(i)) {
returnTaintedStatusList.set(i, true);
}
}
}
taintedStatusList = returnTaintedStatusList;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangReturn in project ballerina by ballerina-lang.
the class SemanticAnalyzer method checkReturnValueCounts.
private boolean checkReturnValueCounts(BLangReturn returnNode) {
boolean success = false;
int expRetCount = this.env.enclInvokable.getReturnParameters().size();
int actualRetCount = returnNode.exprs.size();
if (expRetCount > 1 && actualRetCount <= 1) {
this.dlog.error(returnNode.pos, DiagnosticCode.MULTI_VALUE_RETURN_EXPECTED);
} else if (expRetCount == 1 && actualRetCount > 1) {
this.dlog.error(returnNode.pos, DiagnosticCode.SINGLE_VALUE_RETURN_EXPECTED);
} else if (expRetCount == 0 && actualRetCount >= 1) {
this.dlog.error(returnNode.pos, DiagnosticCode.RETURN_VALUE_NOT_EXPECTED);
} else if (expRetCount > actualRetCount) {
this.dlog.error(returnNode.pos, DiagnosticCode.NOT_ENOUGH_RETURN_VALUES);
} else if (expRetCount < actualRetCount) {
this.dlog.error(returnNode.pos, DiagnosticCode.TOO_MANY_RETURN_VALUES);
} else {
success = true;
}
return success;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangReturn in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangReturn returnNode) {
if (returnNode.namedReturnVariables != null) {
// Handled named returns.
for (BLangVariable variable : returnNode.namedReturnVariables) {
BLangSimpleVarRef varRef = (BLangSimpleVarRef) TreeBuilder.createSimpleVariableReferenceNode();
varRef.variableName = variable.name;
varRef.symbol = variable.symbol;
varRef.type = variable.type;
varRef.pos = returnNode.pos;
returnNode.exprs.add(varRef);
}
}
returnNode.exprs = rewriteExprs(returnNode.exprs);
result = returnNode;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangReturn in project ballerina by ballerina-lang.
the class Desugar method addReturnIfNotPresent.
private void addReturnIfNotPresent(BLangInvokableNode invokableNode) {
if (Symbols.isNative(invokableNode.symbol)) {
return;
}
// This will only check whether last statement is a return and just add a return statement.
// This won't analyse if else blocks etc to see whether return statements are present
BLangBlockStmt blockStmt = invokableNode.body;
if (invokableNode.workers.size() == 0 && invokableNode.retParams.isEmpty() && (blockStmt.stmts.size() < 1 || blockStmt.stmts.get(blockStmt.stmts.size() - 1).getKind() != NodeKind.RETURN)) {
BLangReturn returnStmt = (BLangReturn) TreeBuilder.createReturnNode();
DiagnosticPos invPos = invokableNode.pos;
DiagnosticPos pos = new DiagnosticPos(invPos.src, invPos.eLine, invPos.eLine, invPos.sCol, invPos.sCol);
returnStmt.pos = pos;
blockStmt.addStatement(returnStmt);
}
}
Aggregations