use of org.wso2.ballerinalang.compiler.tree.statements.BLangWhile in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangWhile whileNode) {
SymbolEnv blockEnv = SymbolEnv.createBlockEnv(whileNode.body, env);
analyzeNode(whileNode.body, blockEnv);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangWhile in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addWhileStmt.
public void addWhileStmt(DiagnosticPos pos, Set<Whitespace> ws) {
BLangWhile whileNode = (BLangWhile) TreeBuilder.createWhileNode();
whileNode.setCondition(exprNodeStack.pop());
whileNode.pos = pos;
whileNode.addWS(ws);
BLangBlockStmt whileBlock = (BLangBlockStmt) this.blockNodeStack.pop();
whileBlock.pos = pos;
whileNode.setBody(whileBlock);
addStmtToCurrentBlock(whileNode);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangWhile in project ballerina by ballerina-lang.
the class ServiceProtoUtils method getInvocationExpression.
private static BLangInvocation getInvocationExpression(BlockNode body) {
if (body == null) {
return null;
}
for (StatementNode statementNode : body.getStatements()) {
BLangExpression expression = null;
// example : conn.send inside while block.
if (statementNode instanceof BLangWhile) {
BLangWhile langWhile = (BLangWhile) statementNode;
BLangInvocation invocExp = getInvocationExpression(langWhile.getBody());
if (invocExp != null) {
return invocExp;
}
}
// example : conn.send inside for block.
if (statementNode instanceof BLangForeach) {
BLangForeach langForeach = (BLangForeach) statementNode;
BLangInvocation invocExp = getInvocationExpression(langForeach.getBody());
if (invocExp != null) {
return invocExp;
}
}
// example : conn.send inside if block.
if (statementNode instanceof BLangIf) {
BLangIf langIf = (BLangIf) statementNode;
BLangInvocation invocExp = getInvocationExpression(langIf.getBody());
if (invocExp != null) {
return invocExp;
}
invocExp = getInvocationExpression((BLangBlockStmt) langIf.getElseStatement());
if (invocExp != null) {
return invocExp;
}
}
// example : _ = conn.send(msg);
if (statementNode instanceof BLangAssignment) {
BLangAssignment assignment = (BLangAssignment) statementNode;
expression = assignment.getExpression();
}
// example : grpc:HttpConnectorError err = conn.send(msg);
if (statementNode instanceof BLangVariableDef) {
BLangVariableDef variableDef = (BLangVariableDef) statementNode;
BLangVariable variable = variableDef.getVariable();
expression = variable.getInitialExpression();
}
if (expression != null && expression instanceof BLangInvocation) {
BLangInvocation invocation = (BLangInvocation) expression;
if ("send".equals(invocation.getName().getValue())) {
return invocation;
}
}
}
return null;
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangWhile in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangWhile whileNode) {
Instruction gotoTopJumpInstr = InstructionFactory.get(InstructionCodes.GOTO, getOperand(this.nextIP()));
this.genNode(whileNode.expr, this.env);
Operand exitLoopJumpAddr = getOperand(-1);
Instruction exitLoopJumpInstr = InstructionFactory.get(InstructionCodes.GOTO, exitLoopJumpAddr);
emit(InstructionCodes.BR_FALSE, whileNode.expr.regIndex, exitLoopJumpAddr);
this.loopResetInstructionStack.push(gotoTopJumpInstr);
this.loopExitInstructionStack.push(exitLoopJumpInstr);
this.genNode(whileNode.body, this.env);
this.loopResetInstructionStack.pop();
this.loopExitInstructionStack.pop();
this.emit(gotoTopJumpInstr);
exitLoopJumpAddr.value = nextIP();
}
Aggregations