Search in sources :

Example 11 with BLangInvocation

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

the class TypeChecker method checkFunctionInvocationExpr.

private void checkFunctionInvocationExpr(BLangInvocation iExpr, BType bType) {
    Name funcName = names.fromString(Symbols.getAttachedFuncSymbolName(bType.toString(), iExpr.name.value));
    BPackageSymbol packageSymbol = (BPackageSymbol) bType.tsymbol.owner;
    BSymbol funcSymbol = symResolver.lookupMemberSymbol(iExpr.pos, packageSymbol.scope, this.env, funcName, SymTag.FUNCTION);
    if (funcSymbol == symTable.notFoundSymbol) {
        dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_FUNCTION, funcName);
        resultTypes = getListWithErrorTypes(expTypes.size());
        return;
    }
    iExpr.symbol = funcSymbol;
    checkInvocationParamAndReturnType(iExpr);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 12 with BLangInvocation

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

the class Desugar method visit.

@Override
public void visit(BLangTypeConversionExpr conversionExpr) {
    conversionExpr.expr = rewriteExpr(conversionExpr.expr);
    // Built-in conversion
    if (conversionExpr.conversionSymbol.tag != SymTag.TRANSFORMER) {
        result = conversionExpr;
        return;
    }
    // Named transformer invocation
    BLangInvocation transformerInvoc = conversionExpr.transformerInvocation;
    if (transformerInvoc != null) {
        transformerInvoc = rewriteExpr(transformerInvoc);
        // Add the rExpr as the first argument
        conversionExpr.transformerInvocation.requiredArgs.add(0, conversionExpr.expr);
        result = new BLangTransformerInvocation(conversionExpr.pos, transformerInvoc.requiredArgs, transformerInvoc.namedArgs, transformerInvoc.restArgs, transformerInvoc.symbol, conversionExpr.types);
        conversionExpr.transformerInvocation = transformerInvoc;
        return;
    }
    // Unnamed transformer invocation
    BConversionOperatorSymbol transformerSym = conversionExpr.conversionSymbol;
    transformerInvoc = new BLangTransformerInvocation(conversionExpr.pos, Lists.of(conversionExpr.expr), transformerSym, conversionExpr.types);
    transformerInvoc.types = transformerSym.type.getReturnTypes();
    result = transformerInvoc;
}
Also used : BLangTransformerInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangTransformerInvocation) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BConversionOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConversionOperatorSymbol)

Example 13 with BLangInvocation

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

the class Desugar method reorderNamedArgs.

private void reorderNamedArgs(BLangInvocation iExpr, BInvokableSymbol invocableSymbol) {
    Map<String, BLangExpression> namedArgs = new HashMap<>();
    iExpr.namedArgs.forEach(expr -> namedArgs.put(((NamedArgNode) expr).getName().value, expr));
    // Re-order the named arguments
    List<BLangExpression> args = new ArrayList<>();
    for (BVarSymbol param : invocableSymbol.defaultableParams) {
        args.add(namedArgs.get(param.name.value));
    }
    iExpr.namedArgs = args;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 14 with BLangInvocation

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

the class Desugar method createInvocationForForeverBlock.

private BLangInvocation createInvocationForForeverBlock(BLangForever forever) {
    List<BLangExpression> args = new ArrayList<>();
    List<BType> retTypes = new ArrayList<>();
    retTypes.add(symTable.noType);
    BLangLiteral streamingQueryLiteral = ASTBuilderUtil.createLiteral(forever.pos, symTable.stringType, forever.getSiddhiQuery());
    args.add(streamingQueryLiteral);
    addReferenceVariablesToArgs(args, siddhiQueryBuilder.getInStreamRefs());
    addReferenceVariablesToArgs(args, siddhiQueryBuilder.getInTableRefs());
    addReferenceVariablesToArgs(args, siddhiQueryBuilder.getOutStreamRefs());
    addReferenceVariablesToArgs(args, siddhiQueryBuilder.getOutTableRefs());
    addFunctionPointersToArgs(args, forever.gettreamingQueryStatements());
    return createInvocationNode(CREATE_FOREVER, args, retTypes);
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 15 with BLangInvocation

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

the class EndpointDesugar method generateEndpointStartOrStop.

private BLangBlockStmt generateEndpointStartOrStop(BLangEndpoint endpoint, BInvokableSymbol funSymbol, SymbolEnv env, BSymbol encSymbol) {
    BLangBlockStmt temp = new BLangBlockStmt();
    if (funSymbol == null || endpoint.configurationExpr == null || endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
        // 2: If endpoint in initialized
        return temp;
    }
    final DiagnosticPos pos = endpoint.pos;
    final String epName = endpoint.name.value;
    final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
    final Name name = names.fromIdNode(endpoint.name);
    epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, name, SymTag.VARIABLE);
    List<BLangVariable> args = new ArrayList<>();
    if (funSymbol.params.size() == 1) {
        // Endpoint is already desugared. Fix this correctly.
        args.add(0, epVariable);
    }
    final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
    final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, funSymbol, args, symResolver);
    if (funSymbol.params.size() != 1) {
        iExpr.expr = ASTBuilderUtil.createVariableRef(epVariable.pos, epVariable.symbol);
    }
    expressionStmt.expr = iExpr;
    return temp;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) ArrayList(java.util.ArrayList) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Name(org.wso2.ballerinalang.compiler.util.Name)

Aggregations

BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)22 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)12 ArrayList (java.util.ArrayList)11 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)9 Name (org.wso2.ballerinalang.compiler.util.Name)8 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)6 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)5 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 List (java.util.List)4 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)4 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)4 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)4 Paths (java.nio.file.Paths)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)3 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)3