Example usage for org.antlr.v4.runtime.tree TerminalNodeImpl getChild

List of usage examples for org.antlr.v4.runtime.tree TerminalNodeImpl getChild

Introduction

In this page you can find the example usage for org.antlr.v4.runtime.tree TerminalNodeImpl getChild.

Prototype

@Override
    public ParseTree getChild(int i) 

Source Link

Usage

From source file:info.fulloo.trygve.parser.Pass1Listener.java

License:Open Source License

private void processIdentifierListRecursive(final Identifier_listContext identifier_list, final Type type,
        final int lineNumber, final AccessQualifier accessQualifier) {
    final List<ParseTree> children = identifier_list.children;
    Token tok;/*from   www.ja  v a  2 s  .  c  om*/
    ObjectDeclaration objDecl = null;
    for (ParseTree pt : children) {
        if (pt instanceof TerminalNodeImpl) {
            final TerminalNodeImpl tnpt = (TerminalNodeImpl) pt;
            if (tnpt.getChildCount() == 0) {
                tok = tnpt.getSymbol();
                final String tokAsText = tok.getText();
                if (tokAsText.equals("=") == true) {
                    ; // we pick it up under the ExprContext check below
                } else if (tokAsText.equals(",") == true) {
                    ; // skip it; it separates elements
                } else {
                    this.nameCheck(tokAsText, lineNumber);
                    objDecl = this.pass1InitialDeclarationCheck(tokAsText, lineNumber);
                    if (null == objDecl) {
                        objDecl = new ObjectDeclaration(tokAsText, type, lineNumber);
                        declareObjectSuitableToPass(currentScope_, objDecl);
                        objDecl.setAccess(accessQualifier, currentScope_, lineNumber);
                    } else {
                        // Doesn't hurt to update type
                        objDecl.updateType(type);
                    }
                }
            } else {
                for (int i = 0; i < tnpt.getChildCount(); i++) {
                    final ParseTree pt2 = tnpt.getChild(i);
                    assert pt2 instanceof TerminalNodeImpl;
                    final TerminalNodeImpl tnpt2 = (TerminalNodeImpl) pt2;
                    tok = tnpt2.getSymbol();
                    final String tokAsText = tok.getText();
                    this.nameCheck(tokAsText, lineNumber);
                    if (tokAsText.equals("=") == true) {
                        ; // we get it with the ExprContext catch below
                    } else if (tokAsText.equals(",") == true) {
                        ; // skip it; it separates elements
                    } else {
                        objDecl = this.pass1InitialDeclarationCheck(tokAsText, lineNumber);
                        if (null == objDecl) {
                            objDecl = new ObjectDeclaration(tokAsText, type, lineNumber);
                            declareObjectSuitableToPass(currentScope_, objDecl);
                            objDecl.setAccess(accessQualifier, currentScope_, lineNumber);
                        } else {
                            // Doesn't hurt to update type
                            objDecl.updateType(type);
                        }
                    }
                }
            }
        } else if (pt instanceof Identifier_listContext) {
            this.processIdentifierListRecursive((Identifier_listContext) pt, type, lineNumber, accessQualifier);
            // System.err.print("Alert: ");
            // System.err.println(pt.getText());
        } else if (pt instanceof ExprContext) {
            if (parsingData_.currentExpressionExists()) {
                final Expression initializationExpr = parsingData_.popExpression();
                assert initializationExpr != null;
                assert objDecl != null;
                updateInitializationLists(initializationExpr, objDecl);
            }
        } else {
            assert false;
        }
    }
}