Search in sources :

Example 76 with DiagnosticPos

use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addThrowStmt.

public void addThrowStmt(DiagnosticPos poc, Set<Whitespace> ws) {
    ExpressionNode throwExpr = this.exprNodeStack.pop();
    BLangThrow throwNode = (BLangThrow) TreeBuilder.createThrowNode();
    throwNode.pos = poc;
    throwNode.addWS(ws);
    throwNode.expr = (BLangExpression) throwExpr;
    addStmtToCurrentBlock(throwNode);
}
Also used : BLangThrow(org.wso2.ballerinalang.compiler.tree.statements.BLangThrow) ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) SelectExpressionNode(org.ballerinalang.model.tree.clauses.SelectExpressionNode)

Example 77 with DiagnosticPos

use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addExpressionStmt.

public void addExpressionStmt(DiagnosticPos pos, Set<Whitespace> ws) {
    BLangExpressionStmt exprStmt = (BLangExpressionStmt) TreeBuilder.createExpressionStatementNode();
    exprStmt.pos = pos;
    exprStmt.addWS(ws);
    exprStmt.expr = (BLangExpression) exprNodeStack.pop();
    addStmtToCurrentBlock(exprStmt);
}
Also used : BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)

Example 78 with DiagnosticPos

use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.

the class BLangParserListener method exitSimpleLiteral.

/**
 * {@inheritDoc}
 */
@Override
public void exitSimpleLiteral(BallerinaParser.SimpleLiteralContext ctx) {
    if (ctx.exception != null) {
        return;
    }
    TerminalNode node;
    DiagnosticPos pos = getCurrentPos(ctx);
    Set<Whitespace> ws = getWS(ctx);
    Long longObject;
    BallerinaParser.IntegerLiteralContext integerLiteralContext = ctx.integerLiteral();
    if (integerLiteralContext != null && (longObject = getIntegerLiteral(ctx, ctx.integerLiteral())) != null) {
        this.pkgBuilder.addLiteralValue(pos, ws, TypeTags.INT, longObject);
    } else if ((node = ctx.FloatingPointLiteral()) != null) {
        this.pkgBuilder.addLiteralValue(pos, ws, TypeTags.FLOAT, Double.parseDouble(getNodeValue(ctx, node)));
    } else if ((node = ctx.BooleanLiteral()) != null) {
        this.pkgBuilder.addLiteralValue(pos, ws, TypeTags.BOOLEAN, Boolean.parseBoolean(node.getText()));
    } else if ((node = ctx.QuotedStringLiteral()) != null) {
        String text = node.getText();
        text = text.substring(1, text.length() - 1);
        text = StringEscapeUtils.unescapeJava(text);
        this.pkgBuilder.addLiteralValue(pos, ws, TypeTags.STRING, text);
    } else if (ctx.NullLiteral() != null) {
        this.pkgBuilder.addLiteralValue(pos, ws, TypeTags.NULL, null);
    }
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) Whitespace(org.ballerinalang.model.Whitespace) BallerinaParser(org.wso2.ballerinalang.compiler.parser.antlr4.BallerinaParser)

Example 79 with DiagnosticPos

use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.

the class BLangParserListener method getCurrentPos.

private DiagnosticPos getCurrentPos(ParserRuleContext ctx) {
    int startLine = ctx.getStart().getLine();
    int startCol = ctx.getStart().getCharPositionInLine() + 1;
    int endLine = -1;
    int endCol = -1;
    Token stop = ctx.getStop();
    if (stop != null) {
        endLine = stop.getLine();
        endCol = stop.getCharPositionInLine() + 1;
    }
    return new DiagnosticPos(diagnosticSrc, startLine, endLine, startCol, endCol);
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) Token(org.antlr.v4.runtime.Token) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Example 80 with DiagnosticPos

use of org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos in project ballerina by ballerina-lang.

the class BLangParserListener method exitObjectFieldDefinition.

/**
 * {@inheritDoc}
 *
 * <p>The default implementation does nothing.</p>
 */
@Override
public void exitObjectFieldDefinition(BallerinaParser.ObjectFieldDefinitionContext ctx) {
    if (ctx.exception != null) {
        return;
    }
    DiagnosticPos currentPos = getCurrentPos(ctx);
    Set<Whitespace> ws = getWS(ctx);
    String name = ctx.Identifier().getText();
    boolean exprAvailable = ctx.expression() != null;
    if (ctx.parent instanceof BallerinaParser.PublicObjectFieldsContext) {
        this.pkgBuilder.addFieldToObject(currentPos, ws, name, exprAvailable, 0, false);
    } else if (ctx.parent instanceof BallerinaParser.PrivateObjectFieldsContext) {
        this.pkgBuilder.addFieldToObject(currentPos, ws, name, exprAvailable, 0, true);
    }
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) Whitespace(org.ballerinalang.model.Whitespace) BallerinaParser(org.wso2.ballerinalang.compiler.parser.antlr4.BallerinaParser)

Aggregations

DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)56 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)33 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)22 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)17 ArrayList (java.util.ArrayList)15 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)14 Whitespace (org.ballerinalang.model.Whitespace)13 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)12 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)11 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)11 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)9 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)9 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)9 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)9 BLangBinaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)9 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)9 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)8 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)8 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)8 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)8