Search in sources :

Example 21 with BLangVariableDef

use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.

the class IterableCodeDesugar method defineRequiredVariables.

private void defineRequiredVariables(IterableContext ctx, LinkedList<Operation> streamOperations, List<BLangVariable> foreachVariables, BLangFunction funcNode) {
    Set<BLangVariable> notDefinedVars = new HashSet<>();
    streamOperations.forEach(operation -> {
        notDefinedVars.add(operation.argVar);
        if (operation.kind != IterableKind.FILTER && operation.retVar != null) {
            notDefinedVars.add(operation.retVar);
        }
    });
    notDefinedVars.addAll(ctx.iteratorResultVariables);
    notDefinedVars.removeAll(foreachVariables);
    notDefinedVars.forEach(var -> defineVariable(var, ctx.env.enclPkg.symbol.pkgID, funcNode));
    notDefinedVars.forEach(var -> {
        BLangVariableDef variableDefStmt = ASTBuilderUtil.createVariableDefStmt(funcNode.pos, funcNode.body);
        variableDefStmt.var = var;
    });
}
Also used : BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) HashSet(java.util.HashSet)

Example 22 with BLangVariableDef

use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addDefaultableParam.

public void addDefaultableParam(DiagnosticPos pos, Set<Whitespace> ws) {
    BLangVariableDef defaultableParam = (BLangVariableDef) TreeBuilder.createVariableDefinitionNode();
    defaultableParam.pos = pos;
    defaultableParam.addWS(ws);
    List<VariableNode> params = this.varListStack.peek();
    BLangVariable var = (BLangVariable) params.remove(params.size() - 1);
    var.expr = (BLangExpression) this.exprNodeStack.pop();
    defaultableParam.var = var;
    this.defaultableParamsList.add(defaultableParam);
}
Also used : VariableNode(org.ballerinalang.model.tree.VariableNode) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 23 with BLangVariableDef

use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.

the class BLangPackageBuilder method endObjectInitParamList.

void endObjectInitParamList(Set<Whitespace> ws, boolean paramsAvail, boolean restParamAvail) {
    InvokableNode invNode = this.invokableNodeStack.peek();
    invNode.addWS(ws);
    if (paramsAvail) {
        this.varListStack.pop().forEach(variableNode -> {
            ((BLangVariable) variableNode).docTag = DocTag.PARAM;
            invNode.addParameter(variableNode);
        });
        this.defaultableParamsList.forEach(variableDef -> {
            BLangVariableDef varDef = (BLangVariableDef) variableDef;
            varDef.var.docTag = DocTag.PARAM;
            invNode.addDefaultableParameter(varDef);
        });
        this.defaultableParamsList = new ArrayList<>();
        if (restParamAvail) {
            invNode.setRestParameter(this.restParamStack.pop());
        }
    }
}
Also used : InvokableNode(org.ballerinalang.model.tree.InvokableNode) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)

Example 24 with BLangVariableDef

use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.

the class BLangPackageBuilder method endCallableUnitSignature.

public void endCallableUnitSignature(Set<Whitespace> ws, String identifier, boolean paramsAvail, boolean retParamsAvail, boolean restParamAvail) {
    InvokableNode invNode = this.invokableNodeStack.peek();
    invNode.setName(this.createIdentifier(identifier));
    invNode.addWS(ws);
    if (retParamsAvail) {
        BLangVariable variableNode = (BLangVariable) this.varStack.pop();
        variableNode.docTag = DocTag.RETURN;
        invNode.addReturnParameter(variableNode);
    }
    if (paramsAvail) {
        this.varListStack.pop().forEach(variableNode -> {
            ((BLangVariable) variableNode).docTag = DocTag.PARAM;
            invNode.addParameter(variableNode);
        });
        this.defaultableParamsList.forEach(variableDef -> {
            BLangVariableDef varDef = (BLangVariableDef) variableDef;
            varDef.var.docTag = DocTag.PARAM;
            invNode.addDefaultableParameter(varDef);
        });
        this.defaultableParamsList = new ArrayList<>();
        if (restParamAvail) {
            invNode.setRestParameter(this.restParamStack.pop());
        }
    }
}
Also used : InvokableNode(org.ballerinalang.model.tree.InvokableNode) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 25 with BLangVariableDef

use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.

the class ConnectorScopeResolver method isWithinScopeAfterLastChildNode.

/**
 * Check whether the given node is within the scope and located after the last child node.
 * @param node          Current Node to evaluate
 * @param treeVisitor   Operation Tree Visitor
 * @param curLine       line of the cursor
 * @param curCol        column of the cursor
 * @return              {@link Boolean} whether the last child node or not
 */
protected boolean isWithinScopeAfterLastChildNode(Node node, TreeVisitor treeVisitor, int curLine, int curCol) {
    BLangConnector bLangConnector = (BLangConnector) treeVisitor.getBlockOwnerStack().peek();
    List<BLangAction> actions = bLangConnector.actions;
    List<BLangVariableDef> variableDefs = bLangConnector.varDefs;
    int connectorEndLine = bLangConnector.pos.getEndLine();
    int connectorEndCol = bLangConnector.pos.getEndColumn();
    int nodeEndLine = node.getPosition().getEndLine();
    int nodeEndCol = node.getPosition().getEndColumn();
    boolean isLastChildNode;
    if (actions.isEmpty()) {
        isLastChildNode = variableDefs.indexOf(node) == (variableDefs.size() - 1);
    } else {
        isLastChildNode = actions.indexOf(node) == (actions.size() - 1);
    }
    boolean isWithinScope = (isLastChildNode && (curLine < connectorEndLine || (curLine == connectorEndLine && curCol < connectorEndCol)) && (nodeEndLine < curLine || (nodeEndLine == curLine && nodeEndCol < curCol)));
    if (isWithinScope) {
        treeVisitor.setPreviousNode((BLangNode) node);
    }
    return isWithinScope;
}
Also used : BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction)

Aggregations

BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)27 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)14 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)10 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)5 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)5 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)4 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)4 CompletionItem (org.eclipse.lsp4j.CompletionItem)3 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)3 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)3 InvokableNode (org.ballerinalang.model.tree.InvokableNode)2 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)2 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)2 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)2 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)2 BLangMatch (org.wso2.ballerinalang.compiler.tree.statements.BLangMatch)2 BLangMatchStmtPatternClause (org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause)2 BLangStatement (org.wso2.ballerinalang.compiler.tree.statements.BLangStatement)2