Search in sources :

Example 11 with BLangArrayLiteral

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

the class Desugar method createArrayLiteralExprNode.

private BLangArrayLiteral createArrayLiteralExprNode() {
    BLangArrayLiteral expr = (BLangArrayLiteral) TreeBuilder.createArrayLiteralNode();
    expr.exprs = new ArrayList<>();
    expr.type = symTable.anyType;
    return expr;
}
Also used : BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)

Example 12 with BLangArrayLiteral

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

the class Desugar method addFunctionPointersToArgs.

private void addFunctionPointersToArgs(List<BLangExpression> args, List<StreamingQueryStatementNode> streamingStmts) {
    BLangArrayLiteral funcPointers = createArrayLiteralExprNode();
    for (StreamingQueryStatementNode stmt : streamingStmts) {
        funcPointers.exprs.add(rewrite((BLangExpression) stmt.getStreamingAction().getInvokableBody(), env));
    }
    args.add(funcPointers);
}
Also used : StreamingQueryStatementNode(org.ballerinalang.model.tree.statements.StreamingQueryStatementNode) BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 13 with BLangArrayLiteral

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

the class Desugar method visit.

@Override
public void visit(BLangArrayLiteral arrayLiteral) {
    arrayLiteral.exprs = rewriteExprs(arrayLiteral.exprs);
    if (arrayLiteral.type.tag == TypeTags.JSON || getElementType(arrayLiteral.type).tag == TypeTags.JSON) {
        result = new BLangJSONArrayLiteral(arrayLiteral.exprs, arrayLiteral.type);
        return;
    }
    result = arrayLiteral;
}
Also used : BLangJSONArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral.BLangJSONArrayLiteral)

Example 14 with BLangArrayLiteral

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

the class Desugar method reorderArguments.

/**
 * Reorder the invocation arguments to match the original function signature.
 *
 * @param iExpr Function invocation expressions to reorder the arguments
 */
private void reorderArguments(BLangInvocation iExpr) {
    BSymbol symbol = iExpr.symbol;
    if (symbol == null || symbol.type.tag != TypeTags.INVOKABLE) {
        return;
    }
    BInvokableSymbol invocableSymbol = (BInvokableSymbol) symbol;
    if (invocableSymbol.defaultableParams != null && !invocableSymbol.defaultableParams.isEmpty()) {
        // Re-order the named args
        reorderNamedArgs(iExpr, invocableSymbol);
    }
    if (invocableSymbol.restParam == null) {
        return;
    }
    // leave it as is.
    if (iExpr.restArgs.size() == 1 && iExpr.restArgs.get(0).getKind() == NodeKind.REST_ARGS_EXPR) {
        return;
    }
    BLangArrayLiteral arrayLiteral = (BLangArrayLiteral) TreeBuilder.createArrayLiteralNode();
    arrayLiteral.exprs = iExpr.restArgs;
    arrayLiteral.type = invocableSymbol.restParam.type;
    iExpr.restArgs = new ArrayList<>();
    iExpr.restArgs.add(arrayLiteral);
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)

Example 15 with BLangArrayLiteral

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

the class Desugar method getSQLStatementParameters.

private BLangArrayLiteral getSQLStatementParameters(BLangTableQueryExpression tableQueryExpression) {
    BLangArrayLiteral expr = createArrayLiteralExprNode();
    List<BLangExpression> params = tableQueryExpression.getParams();
    params.stream().map(param -> (BLangLiteral) param).forEach(literal -> {
        Object value = literal.getValue();
        int type = TypeTags.STRING;
        if (value instanceof Integer || value instanceof Long) {
            type = TypeTags.INT;
        } else if (value instanceof Double || value instanceof Float) {
            type = TypeTags.FLOAT;
        } else if (value instanceof Boolean) {
            type = TypeTags.BOOLEAN;
        } else if (value instanceof Byte[]) {
            type = TypeTags.BLOB;
        } else if (value instanceof Object[]) {
            type = TypeTags.ARRAY;
        }
        literal.type = symTable.getTypeFromTag(type);
        types.setImplicitCastExpr(literal, new BType(type, null), symTable.anyType);
        expr.exprs.add(literal.impConversionExpr);
    });
    return expr;
}
Also used : Arrays(java.util.Arrays) BLangMapLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangMapLiteral) BLangStreamLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStreamLiteral) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) BLangTableLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangTableLiteral) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangBreak(org.wso2.ballerinalang.compiler.tree.statements.BLangBreak) BLangXMLTextLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLTextLiteral) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally) BLangTupleDestructure(org.wso2.ballerinalang.compiler.tree.statements.BLangTupleDestructure) Map(java.util.Map) SymbolResolver(org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BLangWhile(org.wso2.ballerinalang.compiler.tree.statements.BLangWhile) BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr) BLangEnumeratorAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangEnumeratorAccessExpr) CompilerPhase(org.ballerinalang.compiler.CompilerPhase) BLangCompoundAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangCompoundAssignment) JoinStreamingInput(org.ballerinalang.model.tree.clauses.JoinStreamingInput) Set(java.util.Set) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BLangMatchStmtPatternClause(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BLangLambdaFunction(org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction) BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement) BLangArrayAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangArrayAccessExpr) BLangStructLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStructLiteral) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) BLangInvokableNode(org.wso2.ballerinalang.compiler.tree.BLangInvokableNode) NamedArgNode(org.ballerinalang.model.tree.expressions.NamedArgNode) BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) StreamingQueryStatementNode(org.ballerinalang.model.tree.statements.StreamingQueryStatementNode) BLangXMLAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute) BLangNamedArgsExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangNamedArgsExpression) BLangAbort(org.wso2.ballerinalang.compiler.tree.statements.BLangAbort) BLangTypeInit(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit) BLangLocalXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangLocalXMLNS) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) Types(org.wso2.ballerinalang.compiler.semantics.analyzer.Types) BLangIndexBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess) BLangXMLCommentLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLCommentLiteral) BLangPackageVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangPackageVarRef) BLangPostIncrement(org.wso2.ballerinalang.compiler.tree.statements.BLangPostIncrement) ArrayList(java.util.ArrayList) BLangFunctionVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFunctionVarRef) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) TreeBuilder(org.ballerinalang.model.TreeBuilder) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral) BLangUnaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangUnaryExpr) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) BLangPackageXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangPackageXMLNS) BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangStructFieldAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangStructFieldAccessExpr) BLangXMLProcInsLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLProcInsLiteral) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangForever(org.wso2.ballerinalang.compiler.tree.statements.BLangForever) GEN_VAR_PREFIX(org.wso2.ballerinalang.compiler.util.Names.GEN_VAR_PREFIX) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) BLangThrow(org.wso2.ballerinalang.compiler.tree.statements.BLangThrow) 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) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BLangXMLAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangXMLAccessExpr) 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) BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr) BLangStatementLink(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement.BLangStatementLink) BLangXMLAttributeAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttributeAccess) BLangWorkerReceive(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerReceive) Lists(org.wso2.ballerinalang.util.Lists) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) OperatorKind(org.ballerinalang.model.tree.OperatorKind) PackageCache(org.wso2.ballerinalang.compiler.PackageCache) BOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol) Names(org.wso2.ballerinalang.compiler.util.Names) BLangFail(org.wso2.ballerinalang.compiler.tree.statements.BLangFail) BLangJSONLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangJSONLiteral) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangLock(org.wso2.ballerinalang.compiler.tree.statements.BLangLock) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BConversionOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol) 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) BLangTypeCastExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeCastExpr) Collectors(java.util.stream.Collectors) BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) BLangFieldBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess) List(java.util.List) NodeKind(org.ballerinalang.model.tree.NodeKind) InstructionCodes(org.wso2.ballerinalang.programfile.InstructionCodes) BLangActionInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangActionInvocation) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangXMLSequenceLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLSequenceLiteral) BLangBind(org.wso2.ballerinalang.compiler.tree.statements.BLangBind) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) BLangTableQueryExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangTableQueryExpression) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BFunctionPointerInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BFunctionPointerInvocation) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) HashMap(java.util.HashMap) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) BLangTypeofExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeofExpr) BLangTransaction(org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction) Stack(java.util.Stack) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) HashSet(java.util.HashSet) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) BLangLocalVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef) BLangStringTemplateLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangStringTemplateLiteral) BLangJSONArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral.BLangJSONArrayLiteral) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangTernaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTernaryExpr) BLangIntRangeExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangIntRangeExpression) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) BLangMapAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangMapAccessExpr) Iterator(java.util.Iterator) BLangFieldVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFieldVarRef) BLangNext(org.wso2.ballerinalang.compiler.tree.statements.BLangNext) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) Name(org.wso2.ballerinalang.compiler.util.Name) BLangAwaitExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangAwaitExpr) BLangRestArgsExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangRestArgsExpression) 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) BTableType(org.wso2.ballerinalang.compiler.semantics.model.types.BTableType) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) Collections(java.util.Collections) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Aggregations

BLangArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)12 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)6 HashSet (java.util.HashSet)5 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)5 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)4 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 StreamingQueryStatementNode (org.ballerinalang.model.tree.statements.StreamingQueryStatementNode)2 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)2 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)2 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)2 BArrayType (org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 BLangJSONArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral.BLangJSONArrayLiteral)2 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)2 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1