use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class TypeChecker method concatSimilarKindXMLNodes.
/**
* Concatenate the consecutive text type nodes, and get the reduced set of children.
*
* @param exprs Child nodes
* @param xmlElementEnv
* @return Reduced set of children
*/
private List<BLangExpression> concatSimilarKindXMLNodes(List<BLangExpression> exprs, SymbolEnv xmlElementEnv) {
List<BLangExpression> newChildren = new ArrayList<BLangExpression>();
BLangExpression strConcatExpr = null;
for (BLangExpression expr : exprs) {
BType exprType = checkExpr((BLangExpression) expr, xmlElementEnv).get(0);
if (exprType == symTable.xmlType) {
if (strConcatExpr != null) {
newChildren.add(getXMLTextLiteral(strConcatExpr));
strConcatExpr = null;
}
newChildren.add(expr);
continue;
}
BSymbol opSymbol = symResolver.resolveBinaryOperator(OperatorKind.ADD, symTable.stringType, exprType);
if (opSymbol == symTable.notFoundSymbol && exprType != symTable.errType) {
dlog.error(expr.pos, DiagnosticCode.INCOMPATIBLE_TYPES, symTable.xmlType, exprType);
}
if (strConcatExpr == null) {
strConcatExpr = expr;
continue;
}
strConcatExpr = getBinaryAddExpr(strConcatExpr, expr, opSymbol);
}
// Add remaining concatenated text nodes as children
if (strConcatExpr != null) {
newChildren.add(getXMLTextLiteral(strConcatExpr));
}
return newChildren;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangJSONArrayLiteral arrayLiteral) {
arrayLiteral.regIndex = calcAndGetExprRegIndex(arrayLiteral);
List<BLangExpression> argExprs = arrayLiteral.exprs;
BLangLiteral arraySizeLiteral = new BLangLiteral();
arraySizeLiteral.pos = arrayLiteral.pos;
arraySizeLiteral.value = (long) argExprs.size();
arraySizeLiteral.type = symTable.intType;
genNode(arraySizeLiteral, this.env);
emit(InstructionCodes.JSONNEWARRAY, arrayLiteral.regIndex, arraySizeLiteral.regIndex);
for (int i = 0; i < argExprs.size(); i++) {
BLangExpression argExpr = argExprs.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);
emit(InstructionCodes.JSONASTORE, arrayLiteral.regIndex, indexLiteral.regIndex, argExpr.regIndex);
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class CodeGenerator method visitFunctionPointerLoad.
private void visitFunctionPointerLoad(BLangExpression fpExpr, BInvokableSymbol funcSymbol) {
int pkgRefCPIndex = addPackageRefCPEntry(currentPkgInfo, funcSymbol.pkgID);
int funcNameCPIndex = addUTF8CPEntry(currentPkgInfo, funcSymbol.name.value);
FunctionRefCPEntry funcRefCPEntry = new FunctionRefCPEntry(pkgRefCPIndex, funcNameCPIndex);
int funcRefCPIndex = currentPkgInfo.addCPEntry(funcRefCPEntry);
RegIndex nextIndex = calcAndGetExprRegIndex(fpExpr);
emit(InstructionCodes.FPLOAD, getOperand(funcRefCPIndex), nextIndex);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class CodeGenerator method visitXMLTagName.
/**
* Visit XML tag name and return the index of the tag name in the reference registry.
*
* @param tagName Tag name expression
* @param xmlElementEnv Environment of the XML element of the tag
* @param xmlElementLiteral XML element literal to which the tag name belongs to
* @return Index of the tag name, in the reference registry
*/
private RegIndex visitXMLTagName(BLangExpression tagName, SymbolEnv xmlElementEnv, BLangXMLElementLiteral xmlElementLiteral) {
genNode(tagName, xmlElementEnv);
RegIndex startTagNameRegIndex = tagName.regIndex;
// If this is a string representation of element name, generate the namespace lookup instructions
if (tagName.getKind() != NodeKind.XML_QNAME) {
RegIndex localNameRegIndex = getRegIndex(TypeTags.STRING);
RegIndex uriRegIndex = getRegIndex(TypeTags.STRING);
emit(InstructionCodes.S2QNAME, startTagNameRegIndex, localNameRegIndex, uriRegIndex);
startTagNameRegIndex = getRegIndex(TypeTags.XML);
generateURILookupInstructions(xmlElementLiteral.namespacesInScope, localNameRegIndex, uriRegIndex, startTagNameRegIndex, xmlElementLiteral.pos, xmlElementEnv);
tagName.regIndex = startTagNameRegIndex;
}
return startTagNameRegIndex;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangBinaryExpr binaryExpr) {
if (OperatorKind.AND.equals(binaryExpr.opKind)) {
visitAndExpression(binaryExpr);
} else if (OperatorKind.OR.equals(binaryExpr.opKind)) {
visitOrExpression(binaryExpr);
} else if (binaryExpr.opSymbol.opcode == InstructionCodes.REQ_NULL || binaryExpr.opSymbol.opcode == InstructionCodes.RNE_NULL || binaryExpr.opSymbol.opcode == InstructionCodes.SEQ_NULL || binaryExpr.opSymbol.opcode == InstructionCodes.SNE_NULL) {
BLangExpression expr = (binaryExpr.lhsExpr.type.tag == TypeTags.NULL) ? binaryExpr.rhsExpr : binaryExpr.lhsExpr;
genNode(expr, this.env);
emit(binaryExpr.opSymbol.opcode, expr.regIndex, calcAndGetExprRegIndex(binaryExpr));
} else {
genNode(binaryExpr.lhsExpr, this.env);
genNode(binaryExpr.rhsExpr, this.env);
RegIndex regIndex = calcAndGetExprRegIndex(binaryExpr);
emit(binaryExpr.opSymbol.opcode, binaryExpr.lhsExpr.regIndex, binaryExpr.rhsExpr.regIndex, regIndex);
}
}
Aggregations