Search in sources :

Example 1 with BLangAssignment

use of org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment 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;
}
Also used : BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) BLangWhile(org.wso2.ballerinalang.compiler.tree.statements.BLangWhile) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 2 with BLangAssignment

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

the class SemanticAnalyzer method handleAssignNodeWithVar.

private void handleAssignNodeWithVar(BLangAssignment assignNode) {
    int ignoredCount = 0;
    int createdSymbolCount = 0;
    List<Name> newVariables = new ArrayList<Name>();
    List<BType> expTypes = new ArrayList<>();
    // Check each LHS expression.
    for (int i = 0; i < assignNode.varRefs.size(); i++) {
        BLangExpression varRef = assignNode.varRefs.get(i);
        // If the assignment is declared with "var", then lhs supports only simpleVarRef expressions only.
        if (varRef.getKind() != NodeKind.SIMPLE_VARIABLE_REF) {
            dlog.error(varRef.pos, DiagnosticCode.INVALID_VARIABLE_ASSIGNMENT, varRef);
            expTypes.add(symTable.errType);
            continue;
        }
        // Check variable symbol if exists.
        BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) varRef;
        ((BLangVariableReference) varRef).lhsVar = true;
        Name varName = names.fromIdNode(simpleVarRef.variableName);
        if (varName == Names.IGNORE) {
            ignoredCount++;
            simpleVarRef.type = this.symTable.noType;
            expTypes.add(symTable.noType);
            typeChecker.checkExpr(simpleVarRef, env);
            continue;
        }
        BSymbol symbol = symResolver.lookupSymbol(env, varName, SymTag.VARIABLE);
        if (symbol == symTable.notFoundSymbol) {
            createdSymbolCount++;
            newVariables.add(varName);
            expTypes.add(symTable.noType);
        } else {
            expTypes.add(symbol.type);
        }
    }
    if (ignoredCount == assignNode.varRefs.size() || createdSymbolCount == 0) {
        dlog.error(assignNode.pos, DiagnosticCode.NO_NEW_VARIABLES_VAR_ASSIGNMENT);
    }
    // Check RHS expressions with expected type list.
    if (assignNode.getKind() == NodeKind.TUPLE_DESTRUCTURE) {
        expTypes = Lists.of(symTable.noType);
    }
    List<BType> rhsTypes = typeChecker.checkExpr(assignNode.expr, this.env, expTypes);
    if (assignNode.safeAssignment) {
        rhsTypes = Lists.of(handleSafeAssignmentWithVarDeclaration(assignNode.pos, rhsTypes.get(0)));
    }
    if (assignNode.getKind() == NodeKind.TUPLE_DESTRUCTURE) {
        if (rhsTypes.get(0) != symTable.errType && rhsTypes.get(0).tag == TypeTags.TUPLE) {
            BTupleType tupleType = (BTupleType) rhsTypes.get(0);
            rhsTypes = tupleType.tupleTypes;
        } else if (rhsTypes.get(0) != symTable.errType && rhsTypes.get(0).tag != TypeTags.TUPLE) {
            dlog.error(assignNode.pos, DiagnosticCode.INCOMPATIBLE_TYPES_EXP_TUPLE, rhsTypes.get(0));
            rhsTypes = typeChecker.getListWithErrorTypes(assignNode.varRefs.size());
        }
    }
    // visit all lhs expressions
    for (int i = 0; i < assignNode.varRefs.size(); i++) {
        BLangExpression varRef = assignNode.varRefs.get(i);
        if (varRef.getKind() != NodeKind.SIMPLE_VARIABLE_REF) {
            continue;
        }
        BType actualType = rhsTypes.get(i);
        BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) varRef;
        Name varName = names.fromIdNode(simpleVarRef.variableName);
        if (newVariables.contains(varName)) {
            // define new variables
            this.symbolEnter.defineVarSymbol(simpleVarRef.pos, Collections.emptySet(), actualType, varName, env);
        }
        typeChecker.checkExpr(simpleVarRef, env);
    }
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 3 with BLangAssignment

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

the class SemanticAnalyzer method visit.

public void visit(BLangAssignment assignNode) {
    if (assignNode.isDeclaredWithVar()) {
        handleAssignNodeWithVar(assignNode);
        return;
    }
    // Check each LHS expression.
    List<BType> expTypes = new ArrayList<>();
    for (BLangExpression expr : assignNode.varRefs) {
        // In assignment, lhs supports only simpleVarRef, indexBasedAccess, filedBasedAccess expressions.
        if (expr.getKind() != NodeKind.SIMPLE_VARIABLE_REF && expr.getKind() != NodeKind.INDEX_BASED_ACCESS_EXPR && expr.getKind() != NodeKind.FIELD_BASED_ACCESS_EXPR && expr.getKind() != NodeKind.XML_ATTRIBUTE_ACCESS_EXPR) {
            dlog.error(expr.pos, DiagnosticCode.INVALID_VARIABLE_ASSIGNMENT, expr);
            expTypes.add(symTable.errType);
            continue;
        }
        // Evaluate the variable reference expression.
        BLangVariableReference varRef = (BLangVariableReference) expr;
        varRef.lhsVar = true;
        typeChecker.checkExpr(varRef, env);
        // Check whether we've got an enumerator access expression here.
        if (varRef.getKind() == NodeKind.FIELD_BASED_ACCESS_EXPR && ((BLangFieldBasedAccess) varRef).expr.type.tag == TypeTags.ENUM) {
            dlog.error(varRef.pos, DiagnosticCode.INVALID_VARIABLE_ASSIGNMENT, varRef);
            expTypes.add(symTable.errType);
            continue;
        }
        expTypes.add(varRef.type);
        checkConstantAssignment(varRef);
    }
    if (assignNode.getKind() == NodeKind.TUPLE_DESTRUCTURE) {
        BTupleType tupleType = new BTupleType(expTypes);
        expTypes = Lists.of(tupleType);
    }
    if (!assignNode.safeAssignment) {
        typeChecker.checkExpr(assignNode.expr, this.env, expTypes);
        return;
    }
    // Assume that there is only one variable reference in LHS
    // Continue the validate if this is a safe assignment operator
    handleSafeAssignment(assignNode.pos, assignNode.varRefs.get(0).type, assignNode.expr, this.env);
}
Also used : BLangFieldBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) ArrayList(java.util.ArrayList) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 4 with BLangAssignment

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

the class CodeGenerator method visit.

public void visit(BLangAssignment assignNode) {
    List<BLangExpression> lhrExprs = assignNode.varRefs;
    if (assignNode.declaredWithVar) {
        lhrExprs.stream().filter(lhsExr -> lhsExr.type.tag != TypeTags.NONE).map(lhsExr -> (BLangVariableReference) lhsExr).forEach(varRef -> {
            visitVarSymbol(varRef.symbol, lvIndexes, localVarAttrInfo);
        });
    }
    // Calculate the register indexes of lhs expressions.
    int nLHSExpr = lhrExprs.size();
    RegIndex[] regIndexes = new RegIndex[nLHSExpr];
    for (int i = 0; i < nLHSExpr; i++) {
        BLangExpression lExpr = lhrExprs.get(i);
        if (lExpr.type.tag == TypeTags.NONE) {
            continue;
        }
        if (lExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF && lExpr instanceof BLangLocalVarRef) {
            lExpr.regIndex = ((BLangVariableReference) lExpr).symbol.varIndex;
            regIndexes[i] = lExpr.regIndex;
        }
    }
    // Set calculated reg indexes and visit rhs expression
    BLangExpression rhsExpr = assignNode.expr;
    rhsExpr.regIndex = regIndexes[0];
    genNode(rhsExpr, this.env);
    // Set the reg indexes generated by visiting rhs expression to lhs expression
    regIndexes[0] = rhsExpr.regIndex;
    for (int i = 0; i < lhrExprs.size(); i++) {
        BLangExpression lExpr = lhrExprs.get(i);
        if (lExpr.type.tag == TypeTags.NONE) {
            continue;
        }
        if (lExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF && lExpr instanceof BLangLocalVarRef) {
            continue;
        }
        varAssignment = true;
        lExpr.regIndex = regIndexes[i];
        genNode(lExpr, this.env);
        varAssignment = false;
    }
}
Also used : BLangMapLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangMapLiteral) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) REF_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.REF_OFFSET) UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) FloatCPEntry(org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangXMLTextLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLTextLiteral) Map(java.util.Map) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex) SymbolKind(org.ballerinalang.model.symbols.SymbolKind) BLangWhile(org.wso2.ballerinalang.compiler.tree.statements.BLangWhile) PackageVarInfo(org.wso2.ballerinalang.programfile.PackageVarInfo) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType) LocalVariableInfo(org.wso2.ballerinalang.programfile.LocalVariableInfo) AttributeInfo(org.wso2.ballerinalang.programfile.attributes.AttributeInfo) TypeDescriptor(org.wso2.ballerinalang.compiler.util.TypeDescriptor) PackageID(org.ballerinalang.model.elements.PackageID) ImportPackageInfo(org.wso2.ballerinalang.programfile.ImportPackageInfo) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement) BLangArrayAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangArrayAccessExpr) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) BLangInvokableNode(org.wso2.ballerinalang.compiler.tree.BLangInvokableNode) ForkJoinCPEntry(org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry) BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) BLangTypeInit(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit) BLangAnnotAttachmentAttributeValue(org.wso2.ballerinalang.compiler.tree.expressions.BLangAnnotAttachmentAttributeValue) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangXMLCommentLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLCommentLiteral) StructureRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry) BLangFunctionVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFunctionVarRef) LineNumberTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LineNumberTableAttributeInfo) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) TreeBuilder(org.ballerinalang.model.TreeBuilder) ErrorTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo) ActionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.ActionRefCPEntry) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangUnaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangUnaryExpr) PackageFile(org.wso2.ballerinalang.programfile.CompiledBinaryFile.PackageFile) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) REG(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.REG) BLangPackageXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangPackageXMLNS) BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) BLangStructFieldAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangStructFieldAccessExpr) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) BLangThrow(org.wso2.ballerinalang.compiler.tree.statements.BLangThrow) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) FIELD(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD) BOOL_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.BOOL_OFFSET) BLangBracedOrTupleExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBracedOrTupleExpr) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BLangAttachedFunctionInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangAttachedFunctionInvocation) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) ForkjoinInfo(org.wso2.ballerinalang.programfile.ForkjoinInfo) Name(org.ballerinalang.model.Name) BAttachedFunction(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction) BLangWorkerReceive(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerReceive) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) PACKAGE(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BLangTransformerInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangTransformerInvocation) BLangIsAssignableExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIsAssignableExpr) IntegerCPEntry(org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry) Collectors(java.util.stream.Collectors) BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) ProgramFile(org.wso2.ballerinalang.programfile.CompiledBinaryFile.ProgramFile) BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) NodeKind(org.ballerinalang.model.tree.NodeKind) InstructionCodes(org.wso2.ballerinalang.programfile.InstructionCodes) BLangActionInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangActionInvocation) Instruction(org.wso2.ballerinalang.programfile.Instruction) Entry(java.util.Map.Entry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangXMLSequenceLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLSequenceLiteral) AttributeInfoPool(org.wso2.ballerinalang.programfile.attributes.AttributeInfoPool) TransformerRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TransformerRefCPEntry) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) BLangTransaction(org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction) Stack(java.util.Stack) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) BLangJSONArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral.BLangJSONArrayLiteral) BLangTernaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTernaryExpr) InstructionFactory(org.wso2.ballerinalang.programfile.InstructionFactory) BLangRecordKeyValue(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) WorkerDataChannelRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry) BLangFieldVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFieldVarRef) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) FieldType(org.wso2.ballerinalang.compiler.util.FieldType) AttachedFunctionInfo(org.wso2.ballerinalang.programfile.AttachedFunctionInfo) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) ConnectorInfo(org.wso2.ballerinalang.programfile.ConnectorInfo) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) StringCPEntry(org.wso2.ballerinalang.programfile.cpentries.StringCPEntry) Arrays(java.util.Arrays) BLangStreamLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStreamLiteral) BMapType(org.wso2.ballerinalang.compiler.semantics.model.types.BMapType) BLangTableLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangTableLiteral) BLangBreak(org.wso2.ballerinalang.compiler.tree.statements.BLangBreak) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BLangAnnotAttachmentAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangAnnotAttachmentAttribute) StructInfo(org.wso2.ballerinalang.programfile.StructInfo) BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr) BLangEnumeratorAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangEnumeratorAccessExpr) CompilerPhase(org.ballerinalang.compiler.CompilerPhase) STRING_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.STRING_OFFSET) BLangAnnotAttribute(org.wso2.ballerinalang.compiler.tree.BLangAnnotAttribute) ErrorTableEntry(org.wso2.ballerinalang.programfile.ErrorTableEntry) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BLangLambdaFunction(org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction) BLangStructLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStructLiteral) ConstantPool(org.wso2.ballerinalang.programfile.cpentries.ConstantPool) ResourceInfo(org.wso2.ballerinalang.programfile.ResourceInfo) CodeAttributeInfo(org.wso2.ballerinalang.programfile.attributes.CodeAttributeInfo) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) BLangXMLAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute) BLangAbort(org.wso2.ballerinalang.compiler.tree.statements.BLangAbort) BLangLocalXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangLocalXMLNS) ServiceInfo(org.wso2.ballerinalang.programfile.ServiceInfo) BLangPackageVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangPackageVarRef) ArrayList(java.util.ArrayList) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral) StructFieldInfo(org.wso2.ballerinalang.programfile.StructFieldInfo) BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangXMLProcInsLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLProcInsLiteral) EnumInfo(org.wso2.ballerinalang.programfile.EnumInfo) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangForever(org.wso2.ballerinalang.compiler.tree.statements.BLangForever) ActionInfo(org.wso2.ballerinalang.programfile.ActionInfo) BLangJSONAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangJSONAccessExpr) SymTag(org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) EnumeratorInfo(org.wso2.ballerinalang.programfile.EnumeratorInfo) BLangXMLAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangXMLAccessExpr) PackageInfo(org.wso2.ballerinalang.programfile.PackageInfo) INT_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.INT_OFFSET) BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr) WorkerDataChannelInfo(org.wso2.ballerinalang.programfile.WorkerDataChannelInfo) FunctionFlags(org.ballerinalang.util.FunctionFlags) BLangXMLAttributeAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttributeAccess) LineNumberInfo(org.wso2.ballerinalang.programfile.LineNumberInfo) TransactionStatus(org.ballerinalang.util.TransactionStatus) TransformerInfo(org.wso2.ballerinalang.programfile.TransformerInfo) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) OperatorKind(org.ballerinalang.model.tree.OperatorKind) BLangFail(org.wso2.ballerinalang.compiler.tree.statements.BLangFail) BLangJSONLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangJSONLiteral) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangLock(org.wso2.ballerinalang.compiler.tree.statements.BLangLock) BLangRecordKey(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKey) DefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo) BLOB_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.BLOB_OFFSET) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) List(java.util.List) FLOAT_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.FLOAT_OFFSET) DefaultValue(org.wso2.ballerinalang.programfile.DefaultValue) Optional(java.util.Optional) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) FunctionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.FunctionRefCPEntry) LOCAL(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BFunctionPointerInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BFunctionPointerInvocation) BLangTypeofExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeofExpr) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) CallableUnitInfo(org.wso2.ballerinalang.programfile.CallableUnitInfo) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangLocalVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef) PackageRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.PackageRefCPEntry) BLangStringTemplateLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangStringTemplateLiteral) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangIntRangeExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangIntRangeExpression) FunctionInfo(org.wso2.ballerinalang.programfile.FunctionInfo) XMLConstants(javax.xml.XMLConstants) BLangMapAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangMapAccessExpr) VarTypeCountAttributeInfo(org.wso2.ballerinalang.programfile.attributes.VarTypeCountAttributeInfo) BLangNext(org.wso2.ballerinalang.compiler.tree.statements.BLangNext) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangAwaitExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangAwaitExpr) BLangXMLElementLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLElementLiteral) BLangWorkerSend(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) TypeRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry) BLangLocalVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 5 with BLangAssignment

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

the class ASTBuilderUtil method createAssignmentStmt.

static BLangAssignment createAssignmentStmt(DiagnosticPos pos, BLangBlockStmt target) {
    final BLangAssignment assignment = (BLangAssignment) TreeBuilder.createAssignmentNode();
    assignment.pos = pos;
    target.addStatement(assignment);
    return assignment;
}
Also used : BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)

Aggregations

BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)29 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)13 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)11 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)10 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)9 BLangBinaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)7 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)7 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)7 ArrayList (java.util.ArrayList)6 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)6 BLangVariableReference (org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference)6 BLangIndexBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess)5 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)4 BLangForeach (org.wso2.ballerinalang.compiler.tree.statements.BLangForeach)4 BLangIf (org.wso2.ballerinalang.compiler.tree.statements.BLangIf)4 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)3 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)3 BLangReturn (org.wso2.ballerinalang.compiler.tree.statements.BLangReturn)3 BLangStatement (org.wso2.ballerinalang.compiler.tree.statements.BLangStatement)3 Arrays (java.util.Arrays)2