예제 #1
0
  private static Statement convertAstToAssignStatement(ASTStatement ast, Path prefix)
      throws SyntaxException {

    // Sanity check. Ensure that this is a assignment statement.
    assert (ast.getStatementType() == StatementType.ASSIGN);

    AssignmentStatement statement = null;

    // Get the identifier and create the path. Resolve this against the
    // prefix if the given path is relative.
    Path path = createPathFromIdentifier(ast);
    path = Path.resolve(prefix, path);

    // Create the assignment statement.
    assert (ast.jjtGetNumChildren() <= 1);
    if (ast.jjtGetNumChildren() == 0) {

      // This is a delete statement.
      Element element = Null.VALUE;
      statement =
          AssignmentStatement.createAssignmentStatement(
              ast.getSourceRange(), path, element, ast.getConditionalFlag(), !ast.getFinalFlag());
    } else {

      // This is a normal assignment statement.
      ASTOperation child = (ASTOperation) ast.jjtGetChild(0);
      Operation dml = astToDml(child, true);
      statement =
          AssignmentStatement.createAssignmentStatement(
              ast.getSourceRange(), path, dml, ast.getConditionalFlag(), !ast.getFinalFlag());
    }

    return statement;
  }
예제 #2
0
  private static Statement convertAstToBindStatement(String source, ASTStatement ast)
      throws SyntaxException {

    // Sanity check. Ensure that this is a bind statement.
    assert (ast.getStatementType() == StatementType.BIND);

    // Get identifier and create path.
    Path path = createPathFromIdentifier(ast);

    // Verify that there is exactly one child.
    assert (ast.jjtGetNumChildren() == 1);

    // Now check to see if the node is a FullTypeSpec or DML.
    SimpleNode child = (SimpleNode) ast.jjtGetChild(0);
    FullType fullType = null;
    if (child instanceof ASTFullTypeSpec) {
      fullType = astToFullType(source, (ASTFullTypeSpec) child);
    } else if (child instanceof ASTOperation) {
      Operation dml = astToDml((ASTOperation) child, true);
      AliasType elementType = new AliasType(null, child.getSourceRange(), "element", null);
      fullType = new FullType(source, child.getSourceRange(), elementType, null, dml);
    } else {
      assert (false);
    }

    return new BindStatement(ast.getSourceRange(), path, fullType);
  }
예제 #3
0
  public static Template convertAstToTemplate(File file, ASTTemplate ast) throws SyntaxException {

    // Create a list containing all of the statements.
    LinkedList<Statement> statements = new LinkedList<Statement>();

    // By default the prefix for paths is empty.
    Path prefix = null;

    // Loop over all of the children, convert them to Statements, and add
    // them to the list.
    int nchild = ast.jjtGetNumChildren();
    for (int i = 0; i < nchild; i++) {
      Node n = ast.jjtGetChild(i);

      assert (n instanceof ASTStatement);

      ASTStatement snode = (ASTStatement) n;
      StatementType stype = snode.getStatementType();
      switch (stype) {
        case NOOP:
          // Empty statement. Do nothing.
          break;
        case BIND:
          statements.add(convertAstToBindStatement(file.getAbsolutePath(), snode));
          break;
        case ASSIGN:
          statements.add(convertAstToAssignStatement(snode, prefix));
          break;
        case VARIABLE:
          statements.add(convertAstToVariableStatement(snode));
          break;
        case TYPE:
          statements.add(convertAstToTypeStatement(file.getAbsolutePath(), snode));
          break;
        case FUNCTION:
          statements.add(convertAstToFunctionStatement(snode));
          break;
        case INCLUDE:
          Statement stmt = convertAstToIncludeStatement(snode);
          if (stmt != null) {
            statements.add(stmt);
          }
          break;
        case PREFIX:
          prefix = convertAstToPrefixStatement(snode);
          break;
        default:
          assert (false);
          break;
      }
    }

    Template t =
        new Template(
            file, ast.getSourceRange(), ast.getTemplateType(), ast.getIdentifier(), statements);
    return t;
  }
예제 #4
0
  private static Statement convertAstToIncludeStatement(ASTStatement ast) throws SyntaxException {

    // Sanity check.
    assert (ast.getStatementType() == StatementType.INCLUDE);

    // Include statement must always have an associated DML block. If it
    // evaluates to a compile time constant, then the operation will be
    // optimized into a static include statement.
    assert (ast.jjtGetNumChildren() == 1);

    ASTOperation child = (ASTOperation) ast.jjtGetChild(0);
    Operation dml = astToDml(child, true);

    return IncludeStatement.newIncludeStatement(ast.getSourceRange(), dml);
  }
예제 #5
0
  private static Statement convertAstToFunctionStatement(ASTStatement ast) throws SyntaxException {

    // Sanity check.
    assert (ast.getStatementType() == StatementType.FUNCTION);

    // Get identifier and verify it isn't null.
    String fname = ast.getIdentifier();
    assert (fname != null);
    assert (ast.jjtGetNumChildren() == 1);

    // Create the assignment statement.
    ASTOperation child = (ASTOperation) ast.jjtGetChild(0);
    Operation dml = astToDml(child, true);
    return new FunctionStatement(ast.getSourceRange(), fname, dml);
  }
예제 #6
0
  private static Statement convertAstToTypeStatement(String source, ASTStatement ast)
      throws SyntaxException {

    // Sanity check.
    assert (ast.getStatementType() == StatementType.TYPE);

    // Verify that the identifier is not null.
    String tname = ast.getIdentifier();
    assert (tname != null);
    assert (ast.jjtGetNumChildren() == 1);

    // Create the assignment statement.
    ASTFullTypeSpec child = (ASTFullTypeSpec) ast.jjtGetChild(0);
    FullType fullType = astToFullType(source, child);
    return new TypeStatement(ast.getSourceRange(), tname, fullType);
  }
예제 #7
0
  private static Statement convertAstToVariableStatement(ASTStatement ast) throws SyntaxException {

    // Sanity check.
    assert (ast.getStatementType() == StatementType.VARIABLE);

    // Verify that the identifier is not null.
    String vname = ast.getIdentifier();
    assert (vname != null);
    assert (ast.jjtGetNumChildren() == 1);

    // Create the assignment statement.
    ASTOperation child = (ASTOperation) ast.jjtGetChild(0);
    Operation dml = astToDml(child, true);
    return VariableStatement.getInstance(
        ast.getSourceRange(), vname, dml, ast.getConditionalFlag(), !ast.getFinalFlag());
  }
예제 #8
0
  private static Path convertAstToPrefixStatement(ASTStatement ast) throws SyntaxException {

    // Sanity check.
    assert (ast.getStatementType() == StatementType.PREFIX);

    if (!"".equals(ast.getIdentifier())) {

      // Normal path was given check that it is absolute.
      Path path = createPathFromIdentifier(ast);
      if (!path.isAbsolute()) {
        throw SyntaxException.create(
            ast.getSourceRange(), MessageUtils.MSG_PREFIX_MUST_BE_ABSOLUTE_PATH, path.toString());
      }
      return path;

    } else {

      // Empty path was given so just return null to indicate there is no
      // prefix.
      return null;
    }
  }