Search in sources :

Example 31 with BLangVariable

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

the class BLangPackageBuilder method addReturnParam.

public BLangVariable addReturnParam(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean exprAvailable, int annotCount) {
    BLangVariable var = (BLangVariable) this.generateBasicVarNode(pos, ws, identifier, exprAvailable);
    attachAnnotations(var, annotCount);
    var.pos = pos;
    this.varStack.push(var);
    return var;
}
Also used : BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 32 with BLangVariable

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

the class BLangPackageBuilder method addCatchClause.

public void addCatchClause(DiagnosticPos poc, Set<Whitespace> ws, String paramName) {
    BLangVariable variableNode = (BLangVariable) TreeBuilder.createVariableNode();
    variableNode.typeNode = (BLangType) this.typeNodeStack.pop();
    variableNode.name = (BLangIdentifier) createIdentifier(paramName);
    variableNode.pos = variableNode.typeNode.pos;
    variableNode.addWS(removeNthFromLast(ws, 3));
    BLangCatch catchNode = (BLangCatch) TreeBuilder.createCatchNode();
    catchNode.pos = poc;
    catchNode.addWS(ws);
    catchNode.body = (BLangBlockStmt) this.blockNodeStack.pop();
    catchNode.param = variableNode;
    tryCatchFinallyNodesStack.peek().catchBlocks.add(catchNode);
}
Also used : BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 33 with BLangVariable

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

the class BLangPackageBuilder method endTypeDefinition.

public void endTypeDefinition(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean publicStruct) {
    // TODO only adding object type for now
    if (!this.objectStack.isEmpty()) {
        BLangObject objectNode = (BLangObject) this.objectStack.pop();
        objectNode.pos = pos;
        objectNode.setName(this.createIdentifier(identifier));
        if (publicStruct) {
            objectNode.flagSet.add(Flag.PUBLIC);
        }
        objectNode.isAnonymous = false;
        // Create an user defined type with object type
        TypeNode objectType = createUserDefinedType(pos, ws, (BLangIdentifier) TreeBuilder.createIdentifierNode(), objectNode.name);
        // Create and add receiver to attached functions
        BLangVariable receiver = (BLangVariable) TreeBuilder.createVariableNode();
        receiver.pos = pos;
        IdentifierNode name = createIdentifier(Names.SELF.getValue());
        receiver.setName(name);
        receiver.addWS(ws);
        receiver.docTag = DocTag.RECEIVER;
        receiver.setTypeNode(objectType);
        // Cache receiver to add to init function in symbolEnter
        objectNode.receiver = receiver;
        objectNode.functions.forEach(f -> f.setReceiver(receiver));
        this.compUnit.addTopLevelNode(objectNode);
    }
}
Also used : BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) BLangTupleTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangTupleTypeNode) TypeNode(org.ballerinalang.model.tree.types.TypeNode) BLangUnionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangUnionTypeNode) BLangFunctionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangFunctionTypeNode) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 34 with BLangVariable

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

the class BLangPackageBuilder method addVariableDefStatement.

public void addVariableDefStatement(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean exprAvailable, boolean endpoint, boolean safeAssignment) {
    BLangVariable var = (BLangVariable) TreeBuilder.createVariableNode();
    BLangVariableDef varDefNode = (BLangVariableDef) TreeBuilder.createVariableDefinitionNode();
    // TODO : Remove endpoint logic from here.
    Set<Whitespace> wsOfSemiColon = null;
    if (endpoint) {
        var.addWS(endpointVarWs);
        var.addWS(endpointKeywordWs);
        endpointVarWs = null;
        endpointKeywordWs = null;
    } else {
        wsOfSemiColon = removeNthFromLast(ws, 0);
    }
    var.pos = pos;
    var.addWS(ws);
    var.setName(this.createIdentifier(identifier));
    var.setTypeNode(this.typeNodeStack.pop());
    var.safeAssignment = safeAssignment;
    if (exprAvailable) {
        var.setInitialExpression(this.exprNodeStack.pop());
    }
    varDefNode.pos = pos;
    varDefNode.setVariable(var);
    varDefNode.addWS(wsOfSemiColon);
    addStmtToCurrentBlock(varDefNode);
}
Also used : BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Whitespace(org.ballerinalang.model.Whitespace)

Example 35 with BLangVariable

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

the class BLangPackageBuilder method addVar.

public BLangVariable addVar(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean exprAvailable, int annotCount) {
    BLangVariable var = (BLangVariable) this.generateBasicVarNode(pos, ws, 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)

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