Search in sources :

Example 11 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.

the class CodeGenerator method createQNameWithoutPrefix.

private void createQNameWithoutPrefix(RegIndex localNameRegIndex, RegIndex uriRegIndex, RegIndex targetQNameRegIndex) {
    RegIndex prefixIndex = createStringLiteral(null, null, env);
    emit(InstructionCodes.NEWQNAME, localNameRegIndex, uriRegIndex, prefixIndex, targetQNameRegIndex);
}
Also used : RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 12 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

@Override
public void visit(BLangXMLAccessExpr xmlIndexAccessExpr) {
    boolean variableStore = this.varAssignment;
    this.varAssignment = false;
    genNode(xmlIndexAccessExpr.expr, this.env);
    RegIndex varRefRegIndex = xmlIndexAccessExpr.expr.regIndex;
    genNode(xmlIndexAccessExpr.indexExpr, this.env);
    RegIndex indexRegIndex = xmlIndexAccessExpr.indexExpr.regIndex;
    RegIndex elementRegIndex = calcAndGetExprRegIndex(xmlIndexAccessExpr);
    if (xmlIndexAccessExpr.fieldType == FieldType.ALL) {
        emit(InstructionCodes.XMLLOADALL, varRefRegIndex, elementRegIndex);
    } else if (xmlIndexAccessExpr.indexExpr.type.tag == TypeTags.STRING) {
        emit(InstructionCodes.XMLLOAD, varRefRegIndex, indexRegIndex, elementRegIndex);
    } else {
        emit(InstructionCodes.XMLSEQLOAD, varRefRegIndex, indexRegIndex, elementRegIndex);
    }
    this.varAssignment = variableStore;
}
Also used : RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 13 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangUnaryExpr unaryExpr) {
    RegIndex exprIndex = calcAndGetExprRegIndex(unaryExpr);
    if (OperatorKind.ADD.equals(unaryExpr.operator) || OperatorKind.UNTAINT.equals(unaryExpr.operator)) {
        unaryExpr.expr.regIndex = createLHSRegIndex(unaryExpr.regIndex);
        genNode(unaryExpr.expr, this.env);
        return;
    }
    int opcode;
    genNode(unaryExpr.expr, this.env);
    if (OperatorKind.TYPEOF.equals(unaryExpr.operator)) {
        opcode = unaryExpr.opSymbol.opcode;
        if (opcode == InstructionCodes.TYPEOF) {
            emit(opcode, unaryExpr.expr.regIndex, exprIndex);
        } else {
            Operand typeCPIndex = getTypeCPIndex(unaryExpr.expr.type);
            emit(opcode, typeCPIndex, exprIndex);
        }
    } else if (OperatorKind.LENGTHOF.equals(unaryExpr.operator)) {
        Operand typeCPIndex = getTypeCPIndex(unaryExpr.expr.type);
        opcode = unaryExpr.opSymbol.opcode;
        emit(opcode, unaryExpr.expr.regIndex, typeCPIndex, exprIndex);
    } else {
        opcode = unaryExpr.opSymbol.opcode;
        emit(opcode, unaryExpr.expr.regIndex, exprIndex);
    }
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 14 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.

the class CodeGenerator method generateURILookupInstructions.

private void generateURILookupInstructions(Map<Name, BXMLNSSymbol> namespaces, RegIndex localNameRegIndex, RegIndex uriRegIndex, RegIndex targetQNameRegIndex, DiagnosticPos pos, SymbolEnv symbolEnv) {
    if (namespaces.isEmpty()) {
        createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
        return;
    }
    Stack<Operand> endJumpInstrStack = new Stack<>();
    String prefix;
    for (Entry<Name, BXMLNSSymbol> keyValues : namespaces.entrySet()) {
        prefix = keyValues.getKey().getValue();
        // skip the default namespace
        if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
            continue;
        }
        // Below section creates the condition to compare the namespace URIs
        // store the comparing uri as string
        BXMLNSSymbol nsSymbol = keyValues.getValue();
        int opcode = getOpcode(TypeTags.STRING, InstructionCodes.IEQ);
        RegIndex conditionExprIndex = getRegIndex(TypeTags.BOOLEAN);
        emit(opcode, uriRegIndex, getNamespaceURIIndex(nsSymbol, symbolEnv), conditionExprIndex);
        Operand ifCondJumpAddr = getOperand(-1);
        emit(InstructionCodes.BR_FALSE, conditionExprIndex, ifCondJumpAddr);
        // Below section creates instructions to be executed, if the above condition succeeds (then body)
        // create the prefix literal
        RegIndex prefixIndex = createStringLiteral(prefix, null, env);
        // create a qname
        emit(InstructionCodes.NEWQNAME, localNameRegIndex, uriRegIndex, prefixIndex, targetQNameRegIndex);
        Operand endJumpAddr = getOperand(-1);
        emit(InstructionCodes.GOTO, endJumpAddr);
        endJumpInstrStack.add(endJumpAddr);
        ifCondJumpAddr.value = nextIP();
    }
    // else part. create a qname with empty prefix
    createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
    while (!endJumpInstrStack.isEmpty()) {
        endJumpInstrStack.pop().value = nextIP();
    }
}
Also used : BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) Stack(java.util.Stack) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.ballerinalang.model.Name) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 15 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

@Override
public void visit(BLangXMLAttribute xmlAttribute) {
    SymbolEnv xmlAttributeEnv = SymbolEnv.getXMLAttributeEnv(xmlAttribute, env);
    BLangExpression attrNameExpr = xmlAttribute.name;
    attrNameExpr.regIndex = calcAndGetExprRegIndex(attrNameExpr);
    genNode(attrNameExpr, xmlAttributeEnv);
    RegIndex attrQNameRegIndex = attrNameExpr.regIndex;
    // If the attribute name is a string representation of qname
    if (attrNameExpr.getKind() != NodeKind.XML_QNAME) {
        RegIndex localNameRegIndex = getRegIndex(TypeTags.STRING);
        RegIndex uriRegIndex = getRegIndex(TypeTags.STRING);
        emit(InstructionCodes.S2QNAME, attrQNameRegIndex, localNameRegIndex, uriRegIndex);
        attrQNameRegIndex = getRegIndex(TypeTags.XML);
        generateURILookupInstructions(((BLangXMLElementLiteral) env.node).namespacesInScope, localNameRegIndex, uriRegIndex, attrQNameRegIndex, xmlAttribute.pos, xmlAttributeEnv);
        attrNameExpr.regIndex = attrQNameRegIndex;
    }
    BLangExpression attrValueExpr = xmlAttribute.value;
    genNode(attrValueExpr, env);
    if (xmlAttribute.isNamespaceDeclr) {
        ((BXMLNSSymbol) xmlAttribute.symbol).nsURIIndex = attrValueExpr.regIndex;
    }
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Aggregations

RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)37 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)22 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)20 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)13 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)6 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)5 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)4 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)4 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)3 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)3 Stack (java.util.Stack)2 Name (org.ballerinalang.model.Name)2 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)2 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)2 BMapType (org.wso2.ballerinalang.compiler.semantics.model.types.BMapType)2 BLangEnumerator (org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator)2 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)2 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)2 BLangRecordKeyValue (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue)2 EnumInfo (org.wso2.ballerinalang.programfile.EnumInfo)2