Search in sources :

Example 11 with BLangLiteral

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

the class CodeGenerator method getIntLiteral.

private BLangLiteral getIntLiteral(long value) {
    BLangLiteral literal = (BLangLiteral) TreeBuilder.createLiteralExpression();
    literal.value = value;
    literal.typeTag = TypeTags.INT;
    literal.type = symTable.intType;
    return literal;
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)

Example 12 with BLangLiteral

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

the class CodeGenerator method getStringLiteral.

private BLangLiteral getStringLiteral(String value) {
    BLangLiteral literal = (BLangLiteral) TreeBuilder.createLiteralExpression();
    literal.value = value;
    literal.typeTag = TypeTags.STRING;
    literal.type = symTable.stringType;
    return literal;
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)

Example 13 with BLangLiteral

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

the class CodeGenerator method getDefaultValueAttributeInfo.

private DefaultValueAttributeInfo getDefaultValueAttributeInfo(BLangLiteral literalExpr) {
    DefaultValue defaultValue = getDefaultValue(literalExpr);
    UTF8CPEntry defaultValueAttribUTF8CPEntry = new UTF8CPEntry(AttributeInfo.Kind.DEFAULT_VALUE_ATTRIBUTE.toString());
    int defaultValueAttribNameIndex = currentPkgInfo.addCPEntry(defaultValueAttribUTF8CPEntry);
    return new DefaultValueAttributeInfo(defaultValueAttribNameIndex, defaultValue);
}
Also used : DefaultValue(org.wso2.ballerinalang.programfile.DefaultValue) UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) DefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 14 with BLangLiteral

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

the class CodeGenerator method addParameterDefaultValues.

private void addParameterDefaultValues(BLangInvokableNode invokableNode, CallableUnitInfo callableUnitInfo) {
    int paramDefaultsAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE.value());
    ParamDefaultValueAttributeInfo paramDefaulValAttrInfo = new ParamDefaultValueAttributeInfo(paramDefaultsAttrNameIndex);
    // Only named parameters can have default values.
    for (BLangVariableDef param : invokableNode.defaultableParams) {
        DefaultValue defaultVal = getDefaultValue((BLangLiteral) param.var.expr);
        paramDefaulValAttrInfo.addParamDefaultValueInfo(defaultVal);
    }
    callableUnitInfo.addAttributeInfo(AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE, paramDefaulValAttrInfo);
}
Also used : DefaultValue(org.wso2.ballerinalang.programfile.DefaultValue) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 15 with BLangLiteral

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

the class Desugar method createPatternMatchBinaryExpr.

private BLangExpression createPatternMatchBinaryExpr(DiagnosticPos pos, BVarSymbol varSymbol, BType patternType) {
    if (patternType == symTable.nullType) {
        BLangSimpleVarRef varRef = ASTBuilderUtil.createVariableRef(pos, varSymbol);
        BLangLiteral bLangLiteral = ASTBuilderUtil.createLiteral(pos, symTable.nullType, null);
        return ASTBuilderUtil.createBinaryExpr(pos, varRef, bLangLiteral, symTable.booleanType, OperatorKind.EQUAL, (BOperatorSymbol) symResolver.resolveBinaryOperator(OperatorKind.EQUAL, symTable.anyType, symTable.nullType));
    } else {
        return createIsAssignableExpression(pos, varSymbol, patternType);
    }
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)

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