예제 #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
  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);
  }
예제 #4
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);
  }
예제 #5
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);
  }
예제 #6
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());
  }