Search in sources :

Example 21 with BLangLiteral

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

the class BLangPackageBuilder method addXMLNSDeclaration.

public void addXMLNSDeclaration(DiagnosticPos pos, Set<Whitespace> ws, String namespaceUri, String prefix, boolean isTopLevel) {
    BLangXMLNS xmlns = (BLangXMLNS) TreeBuilder.createXMLNSNode();
    BLangIdentifier prefixIdentifer = (BLangIdentifier) TreeBuilder.createIdentifierNode();
    prefixIdentifer.pos = pos;
    prefixIdentifer.value = prefix;
    addLiteralValue(pos, removeNthFromStart(ws, 1), TypeTags.STRING, namespaceUri);
    xmlns.namespaceURI = (BLangLiteral) exprNodeStack.pop();
    xmlns.prefix = prefixIdentifer;
    xmlns.pos = pos;
    xmlns.addWS(ws);
    if (isTopLevel) {
        this.compUnit.addTopLevelNode(xmlns);
        return;
    }
    BLangXMLNSStatement xmlnsStmt = (BLangXMLNSStatement) TreeBuilder.createXMLNSDeclrStatementNode();
    xmlnsStmt.xmlnsDecl = xmlns;
    xmlnsStmt.pos = pos;
    addStmtToCurrentBlock(xmlnsStmt);
}
Also used : BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier)

Example 22 with BLangLiteral

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method getDataForSecret.

private Map<String, String> getDataForSecret(List<BLangExpression> data) throws KubernetesPluginException {
    Map<String, String> dataMap = new HashMap<>();
    for (BLangExpression bLangExpression : data) {
        Path dataFilePath = Paths.get(((BLangLiteral) bLangExpression).getValue().toString());
        String key = String.valueOf(dataFilePath.getFileName());
        String content = Base64.encodeBase64String(KubernetesUtils.readFileContent(dataFilePath));
        dataMap.put(key, content);
    }
    return dataMap;
}
Also used : Path(java.nio.file.Path) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) HashMap(java.util.HashMap) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 23 with BLangLiteral

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method getDataForConfigMap.

private Map<String, String> getDataForConfigMap(List<BLangExpression> data) throws KubernetesPluginException {
    Map<String, String> dataMap = new HashMap<>();
    for (BLangExpression bLangExpression : data) {
        Path dataFilePath = Paths.get(((BLangLiteral) bLangExpression).getValue().toString());
        String key = String.valueOf(dataFilePath.getFileName());
        String content = new String(KubernetesUtils.readFileContent(dataFilePath), StandardCharsets.UTF_8);
        dataMap.put(key, content);
    }
    return dataMap;
}
Also used : Path(java.nio.file.Path) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) HashMap(java.util.HashMap) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 24 with BLangLiteral

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

the class TypeChecker method visit.

// Expressions
public void visit(BLangLiteral literalExpr) {
    BType literalType = symTable.getTypeFromTag(literalExpr.typeTag);
    resultTypes = types.checkTypes(literalExpr, Lists.of(literalType), expTypes);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType)

Example 25 with BLangLiteral

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

the class CodeGenerator method visit.

@Override
public void visit(BLangArrayLiteral arrayLiteral) {
    BType etype;
    if (arrayLiteral.type.tag == TypeTags.ANY) {
        etype = arrayLiteral.type;
    } else {
        etype = ((BArrayType) arrayLiteral.type).eType;
    }
    // Emit create array instruction
    int opcode = getOpcode(etype.tag, InstructionCodes.INEWARRAY);
    Operand arrayVarRegIndex = calcAndGetExprRegIndex(arrayLiteral);
    Operand typeCPIndex = getTypeCPIndex(arrayLiteral.type);
    emit(opcode, arrayVarRegIndex, typeCPIndex);
    // Emit instructions populate initial array values;
    for (int i = 0; i < arrayLiteral.exprs.size(); i++) {
        BLangExpression argExpr = arrayLiteral.exprs.get(i);
        genNode(argExpr, this.env);
        BLangLiteral indexLiteral = new BLangLiteral();
        indexLiteral.pos = arrayLiteral.pos;
        indexLiteral.value = (long) i;
        indexLiteral.type = symTable.intType;
        genNode(indexLiteral, this.env);
        opcode = getOpcode(argExpr.type.tag, InstructionCodes.IASTORE);
        emit(opcode, arrayVarRegIndex, indexLiteral.regIndex, argExpr.regIndex);
    }
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)23 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)15 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)11 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)8 HashMap (java.util.HashMap)4 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)4 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)4 ArrayList (java.util.ArrayList)3 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)3 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)3 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)3 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)3 Path (java.nio.file.Path)2 NodeKind (org.ballerinalang.model.tree.NodeKind)2 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)2 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)2 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)2 DefaultValue (org.wso2.ballerinalang.programfile.DefaultValue)2 ParamDefaultValueAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo)2 FloatCPEntry (org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry)2