Search in sources :

Example 96 with BLangVariable

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

the class BLangPackageBuilder method addRestParam.

public void addRestParam(DiagnosticPos pos, Set<Whitespace> ws, String identifier, int annotCount) {
    BLangVariable restParam = (BLangVariable) this.generateBasicVarNode(pos, ws, identifier, false);
    attachAnnotations(restParam, annotCount);
    restParam.pos = pos;
    BLangArrayType typeNode = (BLangArrayType) TreeBuilder.createArrayTypeNode();
    typeNode.elemtype = restParam.typeNode;
    typeNode.dimensions = 1;
    restParam.typeNode = typeNode;
    this.restParamStack.push(restParam);
}
Also used : BLangArrayType(org.wso2.ballerinalang.compiler.tree.types.BLangArrayType) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 97 with BLangVariable

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

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

the class BLangPackageBuilder method addVarToStruct.

public void addVarToStruct(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean exprAvailable, int annotCount, boolean isPrivate) {
    Set<Whitespace> wsForSemiColon = removeNthFromLast(ws, 0);
    BLangStruct structNode = (BLangStruct) this.structStack.peek();
    structNode.addWS(wsForSemiColon);
    BLangVariable field = addVar(pos, ws, identifier, exprAvailable, annotCount);
    if (!isPrivate) {
        field.flagSet.add(Flag.PUBLIC);
    }
}
Also used : BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) Whitespace(org.ballerinalang.model.Whitespace) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 99 with BLangVariable

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

the class BLangPackageBuilder method endResourceDef.

public void endResourceDef(DiagnosticPos pos, Set<Whitespace> ws, String resourceName, boolean docExists, boolean isDeprecated, boolean hasParameters) {
    BLangResource resourceNode = (BLangResource) invokableNodeStack.pop();
    endEndpointDeclarationScope();
    resourceNode.pos = pos;
    resourceNode.addWS(ws);
    resourceNode.setName(createIdentifier(resourceName));
    if (docExists) {
        attachDocumentations(resourceNode);
    }
    if (isDeprecated) {
        attachDeprecatedNode(resourceNode);
    }
    if (hasParameters) {
        BLangVariable firstParam = (BLangVariable) varListStack.peek().get(0);
        if (firstParam.name.value.startsWith("$")) {
            // This is an endpoint variable
            Set<Whitespace> wsBeforeComma = removeNthFromLast(firstParam.getWS(), 0);
            resourceNode.addWS(wsBeforeComma);
        }
        varListStack.pop().forEach(variableNode -> {
            ((BLangVariable) variableNode).docTag = DocTag.PARAM;
            resourceNode.addParameter(variableNode);
        });
    }
    serviceNodeStack.peek().addResource(resourceNode);
}
Also used : BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Whitespace(org.ballerinalang.model.Whitespace)

Example 100 with BLangVariable

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

the class Desugar method generateIfElseStmt.

private BLangStatement generateIfElseStmt(BLangMatch matchStmt, BLangVariable matchExprVar) {
    List<BLangMatchStmtPatternClause> patterns = matchStmt.patternClauses;
    if (patterns.size() == 1) {
        return getMatchPatternBody(patterns.get(0), matchExprVar);
    }
    BLangIf parentIfNode = generateIfElseStmt(patterns.get(0), matchExprVar);
    BLangIf currentIfNode = parentIfNode;
    for (int i = 1; i < patterns.size(); i++) {
        if (i == patterns.size() - 1) {
            // This is the last pattern
            currentIfNode.elseStmt = getMatchPatternBody(patterns.get(i), matchExprVar);
        } else {
            currentIfNode.elseStmt = generateIfElseStmt(patterns.get(i), matchExprVar);
            currentIfNode = (BLangIf) currentIfNode.elseStmt;
        }
    }
    // 
    return parentIfNode;
}
Also used : BLangMatchStmtPatternClause(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

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