Java Code Examples for org.antlr.runtime.tree.CommonTree#getText()

The following examples show how to use org.antlr.runtime.tree.CommonTree#getText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        } else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 2
Source File: PathNode.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected EntityPath createEntityPath() {
    List treeItems = getChildren();
    if (treeItems == null) {
        treeItems = Collections.emptyList();
    }
    String[] parts = new String[treeItems.size()];
    for (int i = 0; i < treeItems.size(); i++) {
        CommonTree treeItem = (CommonTree) treeItems.get(i);
        parts[i] = treeItem.getText();
    }

    EntityPath path = new EntityPath();
    path.topEntityVariableName = entityVariableName;
    path.lastEntityFieldPattern = null;
    path.traversedFields = parts;
    return path;
}
 
Example 3
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
	String name = id.getText();
	if ( impl.formalArguments!=null && impl.formalArguments.get(name)!=null ) {
		FormalArgument arg = impl.formalArguments.get(name);
		int index = arg.index;
		emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
	}
	else {
		if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
			errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE,
									templateToken, id.token);
			emit(id, Bytecode.INSTR_NULL);
		}
		else {
			emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
		}
	}
}
 
Example 4
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        } else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 5
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments!=null && impl.formalArguments.get(name)!=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        }
        else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 6
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        } else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 7
Source File: DebuggerMemoryExpressionParser.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Converts an ANTRL tree into a memory expression tree.
 *
 * @param ast The ANTLR tree.
 *
 * @return The converted memory tree.
 */
private static MemoryExpressionElement convert(final CommonTree ast) {
  if (ast.getType() == MemoryExpressionParser.REGISTER) {
    return new Register(ast.getText());
  } else if (ast.getType() == MemoryExpressionParser.NUMBER) {
    return new NumericalValue(new BigInteger(ast.getText()));
  } else if (ast.getType() == MemoryExpressionParser.HEX_NUMBER) {
    return new NumericalValue(new BigInteger(ast.getText().substring(2), 16));
  } else if (ast.getType() == MemoryExpressionParser.MEM_EXPRESSION) {
    return new MemoryExpression(convert((CommonTree) ast.getChild(0)));
  } else if (ast.getType() == MemoryExpressionParser.OPERAND_PLUS) {
    return new PlusExpression(convertChildren(ast));
  } else if (ast.getType() == MemoryExpressionParser.OPERAND_MINUS) {
    return new MinusExpression(convertChildren(ast));
  } else if (ast.getType() == MemoryExpressionParser.OPERAND_MULT) {
    return new MultiplicationExpression(convertChildren(ast));
  } else if (ast.getType() == MemoryExpressionParser.SUB_EXPRESSION) {
    return new SubExpression(convert((CommonTree) ast.getChild(0)));
  } else if (ast.getType() == 0) {
    return convert((CommonTree) ast.getChild(0));
  }

  throw new IllegalStateException("IE00360: Not yet implemented (" + ast.getType() + ")");
}
 
Example 8
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        } else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 9
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments!=null && impl.formalArguments.get(name)!=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        }
        else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 10
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        } else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 11
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments !=null && impl.formalArguments.get(name)!=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE,
                                    templateToken,
                                    id.token);
            emit(id, Bytecode.INSTR_NULL);
        }
        else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 12
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments !=null && impl.formalArguments.get(name)!=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        }
        else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 13
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments !=null && impl.formalArguments.get(name)!=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE,
                                    templateToken,
                                    id.token);
            emit(id, Bytecode.INSTR_NULL);
        }
        else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 14
Source File: TestAstValidator.java    From spork with Apache License 2.0 6 votes vote down vote up
private void validateDataTypePresent(CommonTree tree) {
    if( tree != null ) {
        if( tree.getText().equals( "TUPLE_DEF" ) ) {
            for ( int i = 0; i < tree.getChildCount(); i++ ) {
                CommonTree child = (CommonTree)tree.getChild( i ); // FIELD node
                Assert.assertTrue( "FIELD_DEF".equals( child.getText() ) );
                CommonTree datatype = (CommonTree)child.getChild( 1 );
                Assert.assertTrue( datatype != null );
                String typeName = datatype.getText();
                Assert.assertTrue( !typeName.isEmpty() );
                validateDataTypePresent( child );
            }
        } else {
            for ( int i = 0; i < tree.getChildCount(); i++ ) {
                validateDataTypePresent( (CommonTree)tree.getChild( i ) );
            }
        }
    }
}
 
Example 15
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments !=null && impl.formalArguments.get(name)!=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        }
        else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 16
Source File: CompilationState.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments !=null && impl.formalArguments.get(name)!=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE,
                                    templateToken,
                                    id.token);
            emit(id, Bytecode.INSTR_NULL);
        }
        else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 17
Source File: CMISFTSQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
static private Constraint buildFTSTest(CommonTree argNode, QueryModelFactory factory, FunctionEvaluationContext functionEvaluationContext,
        Selector selector, Map<String, Column> columnMap, String defaultField)
{
    CommonTree testNode = argNode;
    switch (testNode.getType())
    {
    case CMIS_FTSParser.DISJUNCTION:
    case CMIS_FTSParser.CONJUNCTION:
        return buildFTSConnective(testNode, factory, functionEvaluationContext, selector, columnMap, defaultField);
    case CMIS_FTSParser.TERM:
        return buildTerm(testNode, factory, functionEvaluationContext, selector, columnMap);
    case CMIS_FTSParser.PHRASE:
        return buildPhrase(testNode, factory, functionEvaluationContext, selector, columnMap);
    default:
        throw new FTSQueryException("Unsupported FTS option " + testNode.getText());
    }
}
 
Example 18
Source File: ClockParser.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CTFClock parse(CommonTree clock, ICommonTreeParserParameter unused) throws ParseException {
    List<CommonTree> children = clock.getChildren();
    CTFClock ctfClock = new CTFClock();
    for (CommonTree child : children) {
        final String key = child.getChild(0).getChild(0).getChild(0).getText();
        final CommonTree value = (CommonTree) child.getChild(1).getChild(0).getChild(0);
        final int type = value.getType();
        final String text = value.getText();
        switch (type) {
        case CTFParser.INTEGER:
        case CTFParser.DECIMAL_LITERAL:
            /*
             * Not a pretty hack, this is to make sure that there is no
             * number overflow due to 63 bit integers. The offset should
             * only really be an issue in the year 2262. the tracer in C/ASM
             * can write an offset in an unsigned 64 bit long. In java, the
             * last bit, being set to 1 will be read as a negative number,
             * but since it is too big a positive it will throw an
             * exception. this will happen in 2^63 ns from 1970. Therefore
             * 293 years from 1970
             */
            Long numValue;
            try {
                numValue = Long.parseLong(text);
            } catch (NumberFormatException e) {
                Activator.log(IStatus.WARNING, "Number conversion issue with " + text + ". Assigning " + key + " = 0."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                numValue = Long.valueOf(0L);
            }
            ctfClock.addAttribute(key, numValue);
            break;
        default:
            ctfClock.addAttribute(key, text);
        }

    }
    return ctfClock;

}
 
Example 19
Source File: FilterExpressionCu.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Compile a filter expression from a tree
 *
 * @param treeNode
 *            The root node used to build this compilation unit
 * @return a filter expression compilation unit
 */
public static @Nullable FilterExpressionCu compile(CommonTree treeNode) {
    int childCount = treeNode.getChildCount();

    // We can only have an odd number of parameter at this point
    if (childCount % 2 != 1) {
        return null;
    }

    List<Object> elements = new ArrayList<>();
    for (int i = 0; i < childCount; i++) {
        if (i % 2 == 0) {
            CommonTree nodeTree = (CommonTree) treeNode.getChild(i);
            int subChildCount = nodeTree.getChildCount();

            if (nodeTree.getType() == FilterParserParser.ROOT1) {
                boolean negate = nodeTree.getChild(0).getText().equals(IFilterStrings.NOT);
                // The logical part is the penultimate child
                CommonTree logical = Objects.requireNonNull((CommonTree) nodeTree.getChild(subChildCount - 2));
                FilterExpressionCu cu = negate ? FilterExpressionNotCu.compile(logical) : FilterExpressionCu.compile(logical);

                if (cu == null) {
                    return null;
                }

                elements.add(cu);

            } else if (nodeTree.getType() == FilterParserParser.ROOT2) {
                FilterSimpleExpressionCu node = FilterSimpleExpressionCu.compile(nodeTree);
                if (node == null) {
                    return null;
                }

                elements.add(node);
            }
        } else {
            CommonTree opTree = (CommonTree) treeNode.getChild(i);
            String op = opTree.getText();
            elements.add(Objects.requireNonNull(op));
        }
    }

    return new FilterExpressionCu(elements);
}
 
Example 20
Source File: FunctionBody.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
public void setBody(CommonTree s) {
	strBody = s.getText();
}