Search in sources :

Example 91 with BLangVariable

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

the class BLangPackageBuilder method addMatchStmtPattern.

public void addMatchStmtPattern(DiagnosticPos pos, Set<Whitespace> ws, String identifier) {
    BLangMatchStmtPatternClause patternClause = (BLangMatchStmtPatternClause) TreeBuilder.createMatchStatementPattern();
    patternClause.pos = pos;
    Set<Whitespace> varDefWS = removeNthFromStart(ws, 0);
    patternClause.addWS(ws);
    // Create a variable node
    identifier = identifier == null ? Names.IGNORE.value : identifier;
    BLangVariable var = (BLangVariable) TreeBuilder.createVariableNode();
    var.pos = pos;
    var.setName(this.createIdentifier(identifier));
    var.setTypeNode(this.typeNodeStack.pop());
    var.addWS(varDefWS);
    patternClause.variable = var;
    patternClause.body = (BLangBlockStmt) blockNodeStack.pop();
    patternClause.body.pos = pos;
    this.matchStmtStack.peekFirst().patternClauses.add(patternClause);
}
Also used : BLangMatchStmtPatternClause(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause) Whitespace(org.ballerinalang.model.Whitespace) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 92 with BLangVariable

use of org.wso2.ballerinalang.compiler.tree.BLangVariable 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 93 with BLangVariable

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

the class BLangPackageBuilder method addObjectParameter.

BLangVariable addObjectParameter(DiagnosticPos pos, Set<Whitespace> ws, boolean isField, String identifier, boolean exprAvailable, int annotCount) {
    BLangVariable var = (BLangVariable) this.generateObjectVarNode(pos, ws, isField, identifier, exprAvailable);
    attachAnnotations(var, annotCount);
    var.pos = pos;
    if (this.varListStack.empty()) {
        this.varStack.push(var);
    } else {
        this.varListStack.peek().add(var);
    }
    return var;
}
Also used : BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 94 with BLangVariable

use of org.wso2.ballerinalang.compiler.tree.BLangVariable 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 95 with BLangVariable

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

the class BLangPackageBuilder method endTransformerDef.

public void endTransformerDef(DiagnosticPos pos, Set<Whitespace> ws, boolean publicFunc, String name, boolean paramsAvailable) {
    BLangTransformer transformer = (BLangTransformer) this.invokableNodeStack.pop();
    transformer.pos = pos;
    transformer.addWS(ws);
    transformer.setName(this.createIdentifier(name));
    if (paramsAvailable) {
        this.varListStack.pop().forEach(variableNode -> {
            ((BLangVariable) variableNode).docTag = DocTag.PARAM;
            transformer.addParameter(variableNode);
        });
    }
    // get the source and the target params
    List<VariableNode> mappingParams = this.varListStack.pop();
    // set the first mapping-param as the source for transformer
    VariableNode source = mappingParams.remove(0);
    ((BLangVariable) source).docTag = DocTag.RECEIVER;
    transformer.setSource(source);
    mappingParams.forEach(variableNode -> {
        ((BLangVariable) variableNode).docTag = DocTag.RECEIVER;
        transformer.addReturnParameter(variableNode);
    });
    if (publicFunc) {
        transformer.flagSet.add(Flag.PUBLIC);
    }
    this.compUnit.addTopLevelNode(transformer);
}
Also used : BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) VariableNode(org.ballerinalang.model.tree.VariableNode)

Aggregations

BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)77 ArrayList (java.util.ArrayList)21 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)20 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)18 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)18 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)16 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)15 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)14 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)11 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)10 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)10 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)10 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)9 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)8 Whitespace (org.ballerinalang.model.Whitespace)7 BLangObject (org.wso2.ballerinalang.compiler.tree.BLangObject)7 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)7 Name (org.wso2.ballerinalang.compiler.util.Name)7 HashMap (java.util.HashMap)6 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)6