Beispiel #1
0
 private void reportError(String message, CommonTree ast) {
   // Print an error message relating to the given
   // (sub)AST.
   int line = ast.getLine(), column = ast.getCharPositionInLine();
   System.err.println("line " + line + ":" + column + " " + message);
   errorCount++;
 }
 /**
  * @see org.coode.parsers.ErrorListener#incompatibleSymbols(org.antlr.runtime.tree.CommonTree,
  *     org.antlr.runtime.tree.CommonTree[])
  */
 public void incompatibleSymbols(CommonTree parentExpression, CommonTree... trees) {
   List<String> symbols = new ArrayList<String>(trees.length);
   for (CommonTree commonTree : trees) {
     symbols.add(commonTree.getText());
   }
   throw new IncompatibleSymbolsParsingException(
       parentExpression.getText(),
       parentExpression.getLine(),
       parentExpression.getCharPositionInLine(),
       symbols.toArray(new String[symbols.size()]));
 }
 /**
  * @see org.coode.parsers.ErrorListener#illegalToken(org.antlr.runtime.tree.CommonTree,
  *     java.lang.String)
  */
 public void illegalToken(CommonTree t, String message) {
   throw new IllegalTokenParsingException(
       t.getText(), t.getLine(), t.getCharPositionInLine(), message);
 }
 /**
  * @see org.coode.parsers.ErrorListener#incompatibleSymbolType(org.antlr.runtime.tree.CommonTree,
  *     org.coode.parsers.Type, org.antlr.runtime.tree.CommonTree)
  */
 public void incompatibleSymbolType(CommonTree t, Type type, CommonTree expression) {
   throw new IncompatibleSymbolTypeParsingException(
       t.getText(), type, expression.getText(), t.getLine(), t.getCharPositionInLine());
 }
 /** @see org.coode.parsers.ErrorListener#unrecognisedSymbol(org.antlr.runtime.tree.CommonTree) */
 public void unrecognisedSymbol(CommonTree t) {
   throw new UnrecognisedSymbolParsingException(
       t.getText(), t.getLine(), t.getCharPositionInLine());
 }
Beispiel #6
0
 public static String getStartPosition(CommonTree node) {
   int pos = node.getCharPositionInLine();
   return node.getLine() + ":" + pos;
 }
  public static DataNode buildDataNode(CommonTree t, MetaData meta, int type) {
    DataNode dNode = new DataNode();

    // the type drives what data i want to pull
    switch (type) {
      case GraphConstants.TYPE_DIRECTORY:
        break;

      case GraphConstants.TYPE_FILE_INCLUDE:
        dNode.setFileName(meta.getFileName());
        dNode.setFileInclude(getOneLevel(t));
        break;

      case GraphConstants.TYPE_FILE:
        dNode.setFileName(meta.getFileName());
        break;
      case GraphConstants.TYPE_CLASS:
        dNode.setClassName(getOneLevel(t));
        dNode.setFileName(meta.getFileName());
        dNode.setLine(t.getLine());
        dNode.setLocation(Integer.toString(t.getCharPositionInLine()));
        break;
      case GraphConstants.TYPE_FUNCTION:
        dNode.setClassName(meta.getClassName());
        dNode.setFileName(meta.getFileName());

        dNode.setFunctionName(getOneLevel(t));
        dNode.setLine(t.getLine());
        dNode.setLocation(Integer.toString(t.getCharPositionInLine()));
        break;
      case GraphConstants.TYPE_FUNCTION_CALL:
        dNode.setClassName(meta.getClassName());
        dNode.setFileName(meta.getFileName());
        dNode.setFunctionCall(getOneLevel(t));
        dNode.setLine(t.getLine());
        dNode.setLocation(Integer.toString(t.getCharPositionInLine()));
        break;
      case GraphConstants.TYPE_VARIABLE:
        // set the var name
        StringBuilder sb = new StringBuilder();
        String varName = getVariableName(t, sb);
        dNode.setVariableName(varName);

        dNode.setClassName(meta.getClassName());
        dNode.setFileName(meta.getFileName());
        dNode.setFunctionName(meta.getFunctionName());
        dNode.setLine(t.getLine());
        dNode.setLocation(Integer.toString(t.getCharPositionInLine()));
        dNode.setModified(meta.isModified());
        dNode.setModifier(meta.isModifier());

        dNode.setPossibleAttackVector(SurfaceVectorUtil.isPossibleSurfaceVector(varName));

        break;
      default:
    }

    // pull global stuff no matter what
    dNode.setType(type);
    dNode.setRelativePath(meta.getRelativePath());

    return dNode;
  }