コード例 #1
0
  /**
   * Creates as output the tree-like intermediate representation of the target code for the command
   * line arguments.
   *
   * @param operator - a "parameter definition" operator.
   * @return Returns the produced tree-like intermediate representation of the target code.
   */
  @SuppressWarnings("unchecked")
  private AST<ASTs> __parameter_definition(Symtable<SYMs> symtable, APT_native_model operator) {

    final AST<ASTs> retval = new AST_comma();
    try {

      APT_parameter_definition definition = operator.parameter_defs();
      if (null != definition) {

        for (int i = 0; i < definition.size(); ++i) {

          APT_parameter parameter;
          AST<ASTs> tree;
          parameter = (APT_parameter) definition.getChild(i);
          tree = (1 >= parameter.size()) ? retval : retval.addChild(new AST_plus());
          for (int n = 0; n < parameter.size(); ++n) {

            APT<APTs> operand = parameter.getChild(n);
            switch (operand.identifier()) {
              case APT_VARIABLE:
                APT_variable __variable = (APT_variable) operand;
                tree.addChild(new AST_identifier(__variable.variable_name()));
                break;

              case APT_LITERAL:
              default:
                tree.addChild(new AST_literal(operand.expression()));
            }
          }
        }
      }

      retval.addChild(
          0,
          new AST_plus(
              new AST_literal(
                  projectSpace().getArgVerbValue(Projectspace.ARG_VERB_BINARY_PATH)
                      + File.separator),
              new AST_literal(operator.token().expression())));
    } catch (Exception e) {

      if (true == Projectspace.isErrorEnabled()) projectSpace().err.println(e);

      e.printStackTrace();
    }

    return retval;
  } // __parameter_definition
コード例 #2
0
  /**
   * Translates a <i>GRASS</i> command - "native_model" - into the tree-like intermediate
   * representation of the target code.
   *
   * @param symtable - the symbol table.
   * @param root - the root of the syntax tree.
   * @param operator - a "java_model" operator.
   */
  @SuppressWarnings("unchecked")
  private void __native_model(Symtable<SYMs> symtable, AST_root root, APT_native_model operator) {

    final SYM_type_class __typedef_filewriter = new SYM_type_class("FileWriter"); // $NON-NLS-1$
    final SYM_type_class __typedef_writer = new SYM_type_class("Writer"); // $NON-NLS-1$
    final String __variable_writer;
    symtable.register(
        __variable_writer =
            symtable.autoCreateIdentifier(
                "__writer_" //$NON-NLS-1$
                ),
        __typedef_writer);
    final SYM_type_class __typedef_gisrc = new SYM_type_class("File"); // $NON-NLS-1$
    final String __variable_gisrc;
    symtable.register(
        __variable_gisrc =
            symtable.autoCreateIdentifier(
                "__tempfile_" //$NON-NLS-1$
                ),
        __typedef_gisrc);
    final SYM_type_array __typedef_argv = new SYM_type_array("String"); // $NON-NLS-1$
    final String __variable_argv;
    symtable.register(
        __variable_argv =
            symtable.autoCreateIdentifier(
                "__argv_" //$NON-NLS-1$
                ),
        __typedef_argv);
    final SYM_type_class __typedef_processbuilder =
        new SYM_type_class("ProcessBuilder"); // $NON-NLS-1$
    final String __variable_pb;
    symtable.register(
        __variable_pb =
            symtable.autoCreateIdentifier(
                "__pb_" //$NON-NLS-1$
                ),
        __typedef_processbuilder);
    final SYM_type_class __typedef_map = new SYM_type_class("Map"); // $NON-NLS-1$
    final String __variable_map;
    symtable.register(
        __variable_map =
            symtable.autoCreateIdentifier(
                "__map_" //$NON-NLS-1$
                ),
        __typedef_map);
    final SYM_type_class __typedef_instance = new SYM_type_class("Process"); // $NON-NLS-1$
    final String __variable_instance;
    symtable.register(
        __variable_instance =
            symtable.autoCreateIdentifier(
                "__instance_" //$NON-NLS-1$
                ),
        __typedef_processbuilder);
    final SYM_type_class __typedef_interruptedexception =
        new SYM_type_class("InterruptedException"); // $NON-NLS-1$
    final SYM_type_class __typedef_ioexception = new SYM_type_class("IOException"); // $NON-NLS-1$
    final String __variable_e = "e"; // $NON-NLS-1$
    final SYM_type_class __typedef_istreamreader =
        new SYM_type_class("InputStreamReader"); // $NON-NLS-1$
    final SYM_type_class __typedef_bufferedreader =
        new SYM_type_class("BufferedReader"); // $NON-NLS-1$
    final String __variable_reader;
    symtable.register(
        __variable_reader =
            symtable.autoCreateIdentifier(
                "__reader_" //$NON-NLS-1$
                ),
        __typedef_bufferedreader);
    final SYM_type_class __typedef_string = new SYM_type_class("String"); // $NON-NLS-1$
    final String __variable_string;
    symtable.register(
        __variable_string =
            symtable.autoCreateIdentifier(
                "__string_" //$NON-NLS-1$
                ),
        __typedef_string);
    final SYM_type_array __typedef_argument = new SYM_type_array("String"); // $NON-NLS-1$

    root.__native_call_seg()
        .addChild(
            new AST_slist(
                new AST_expression(
                    new AST_variable_definition(
                        new AST_type(__typedef_gisrc.type()),
                        new AST_identifier(__variable_gisrc),
                        new AST_assign_statement(new AST_null()))),
                new AST_try(
                    new AST_block(
                        new AST_slist(
                            new AST_expression(
                                new AST_assign_statement(
                                    new AST_identifier(__variable_gisrc),
                                    new AST_dot(
                                        new AST_identifier(__typedef_gisrc.type()),
                                        new AST_method_call(
                                            new AST_identifier(
                                                "createTempFile" //$NON-NLS-1$
                                                ),
                                            new AST_elist(
                                                new AST_literal(
                                                    Projectspace.ARG_VERB_GISRC.toLowerCase()),
                                                new AST_null(),
                                                new AST_null()))))),
                            new AST_expression(
                                new AST_variable_definition(
                                    new AST_type(__typedef_writer.type()),
                                    new AST_identifier(__variable_writer),
                                    new AST_assign_statement(
                                        new AST_ctor_call(
                                            new AST_identifier(__typedef_filewriter.type()),
                                            new AST_elist(new AST_identifier(__variable_gisrc)))))),
                            new AST_try(
                                new AST_block(
                                    new AST_slist(
                                        new AST_expression(
                                            new AST_dot(
                                                new AST_identifier(__variable_writer),
                                                new AST_method_call(
                                                    new AST_identifier(
                                                        "append" //$NON-NLS-1$
                                                        ),
                                                    new AST_elist(
                                                        new AST_literal(
                                                            Projectspace.ARG_VERB_GISDBASE
                                                                    .toUpperCase()
                                                                + ": " //$NON-NLS-1$
                                                                + projectSpace()
                                                                    .getArgVerbValue(
                                                                        Projectspace
                                                                            .ARG_VERB_GISDBASE)
                                                                + System.getProperty(
                                                                    "line.separator") //$NON-NLS-1$
                                                            ))))),
                                        new AST_expression(
                                            new AST_dot(
                                                new AST_identifier(__variable_writer),
                                                new AST_method_call(
                                                    new AST_identifier(
                                                        "append" //$NON-NLS-1$
                                                        ),
                                                    new AST_elist(
                                                        new AST_literal(
                                                            Projectspace.ARG_VERB_DEBUG
                                                                    .toUpperCase()
                                                                + ": " //$NON-NLS-1$
                                                                + projectSpace()
                                                                    .getArgVerbValue(
                                                                        Projectspace.ARG_VERB_DEBUG)
                                                                + System.getProperty(
                                                                    "line.separator") //$NON-NLS-1$
                                                            ))))),
                                        new AST_expression(
                                            new AST_dot(
                                                new AST_identifier(__variable_writer),
                                                new AST_method_call(
                                                    new AST_identifier(
                                                        "append" //$NON-NLS-1$
                                                        ),
                                                    new AST_elist(
                                                        new AST_literal(
                                                            Projectspace.ARG_VERB_MONITOR
                                                                    .toUpperCase()
                                                                + ": " //$NON-NLS-1$
                                                                + projectSpace()
                                                                    .getArgVerbValue(
                                                                        Projectspace
                                                                            .ARG_VERB_MONITOR)
                                                                + System.getProperty(
                                                                    "line.separator") //$NON-NLS-1$
                                                            ))))),
                                        new AST_expression(
                                            new AST_dot(
                                                new AST_identifier(__variable_writer),
                                                new AST_method_call(
                                                    new AST_identifier(
                                                        "append" //$NON-NLS-1$
                                                        ),
                                                    new AST_elist(
                                                        new AST_literal(
                                                            Projectspace.ARG_VERB_MAPSET
                                                                    .toUpperCase()
                                                                + ": " //$NON-NLS-1$
                                                                + projectSpace()
                                                                    .getArgVerbValue(
                                                                        Projectspace
                                                                            .ARG_VERB_MAPSET)
                                                                + System.getProperty(
                                                                    "line.separator") //$NON-NLS-1$
                                                            ))))),
                                        new AST_expression(
                                            new AST_dot(
                                                new AST_identifier(__variable_writer),
                                                new AST_method_call(
                                                    new AST_identifier(
                                                        "append" //$NON-NLS-1$
                                                        ),
                                                    new AST_elist(
                                                        new AST_literal(
                                                            Projectspace.ARG_VERB_LOCATION_NAME
                                                                    .toUpperCase()
                                                                + ": " //$NON-NLS-1$
                                                                + projectSpace()
                                                                    .getArgVerbValue(
                                                                        Projectspace
                                                                            .ARG_VERB_LOCATION_NAME)
                                                                + System.getProperty(
                                                                    "line.separator") //$NON-NLS-1$
                                                            ))))),
                                        new AST_expression(
                                            new AST_dot(
                                                new AST_identifier(__variable_writer),
                                                new AST_method_call(
                                                    new AST_identifier(
                                                        "append" //$NON-NLS-1$
                                                        ),
                                                    new AST_elist(
                                                        new AST_literal(
                                                            Projectspace.ARG_VERB_GRASS_GUI
                                                                    .toUpperCase()
                                                                + ": " //$NON-NLS-1$
                                                                + projectSpace()
                                                                    .getArgVerbValue(
                                                                        Projectspace
                                                                            .ARG_VERB_GRASS_GUI)))))),
                                        new AST_expression(
                                            new AST_dot(
                                                new AST_identifier(__variable_writer),
                                                new AST_method_call(
                                                    new AST_identifier(
                                                        "flush" //$NON-NLS-1$
                                                        ),
                                                    new AST_elist())))))),
                            new AST_finally(
                                new AST_block(
                                    new AST_slist(
                                        new AST_expression(
                                            new AST_dot(
                                                new AST_identifier(__variable_writer),
                                                new AST_method_call(
                                                    new AST_identifier(
                                                        "close" //$NON-NLS-1$
                                                        ),
                                                    new AST_elist()))))))),
                        new AST_slist(
                            // the array of arguments
                            // new AST_expression(
                            new AST_variable_definition(
                                new AST_type(__typedef_argv.type()),
                                new AST_identifier(__variable_argv),
                                new AST_assign_statement(
                                    new AST_array(
                                        __parameter_definition(symtable, operator),
                                        new AST_type(__typedef_argument.type()),
                                        new AST_identifier(__variable_argv))))
                            // )
                            ,
                            // new AST_block(
                            // __parameter_definition(
                            // symtable,
                            // operator))
                            // ))),
                            new AST_expression(
                                new AST_variable_definition(
                                    new AST_type(__typedef_processbuilder.type()),
                                    new AST_identifier(__variable_pb),
                                    new AST_assign_statement(
                                        new AST_ctor_call(
                                            new AST_identifier(__typedef_processbuilder.type()),
                                            new AST_elist(new AST_identifier(__variable_argv)))))),
                            // new AST_block(
                            new AST_slist(
                                new AST_expression(
                                    new AST_variable_definition(
                                        new AST_type(__typedef_map.type()),
                                        new AST_identifier(__variable_map),
                                        new AST_assign_statement(
                                            new AST_method_call(
                                                new AST_dot(
                                                    new AST_identifier(__variable_pb),
                                                    new AST_identifier("environment") // $NON-NLS-1$
                                                    ),
                                                new AST_elist())))),
                                new AST_expression(
                                    new AST_method_call(
                                        new AST_dot(
                                            new AST_identifier(__variable_map),
                                            new AST_identifier("put") // $NON-NLS-1$
                                            ),
                                        new AST_elist(
                                            new AST_literal(Projectspace.ARG_VERB_GISRC),
                                            new AST_dot(
                                                new AST_identifier(__variable_gisrc),
                                                new AST_method_call(
                                                    new AST_identifier(
                                                        "getAbsolutePath" //$NON-NLS-1$
                                                        ),
                                                    new AST_elist()))))),
                                new AST_expression(
                                    new AST_method_call(
                                        new AST_dot(
                                            new AST_identifier(__variable_map),
                                            new AST_identifier("put") // $NON-NLS-1$
                                            ),
                                        new AST_elist(
                                            new AST_literal(Projectspace.ARG_VERB_GISBASE),
                                            new AST_literal(
                                                projectSpace()
                                                    .getArgVerbValue(
                                                        Projectspace.ARG_VERB_GISBASE))))),
                                new AST_expression(
                                    new AST_method_call(
                                        new AST_dot(
                                            new AST_identifier(__variable_map),
                                            new AST_identifier("put") // $NON-NLS-1$
                                            ),
                                        new AST_elist(
                                            new AST_literal(
                                                Projectspace.ARG_VERB_GRASS_LD_LIBRARY_PATH),
                                            new AST_literal(
                                                projectSpace()
                                                    .getArgVerbValue(
                                                        Projectspace
                                                            .ARG_VERB_GRASS_LD_LIBRARY_PATH))))),
                                new AST_expression(
                                    new AST_method_call(
                                        new AST_dot(
                                            new AST_identifier(__variable_map),
                                            new AST_identifier("put") // $NON-NLS-1$
                                            ),
                                        new AST_elist(
                                            new AST_literal(Projectspace.ARG_VERB_LD_LIBRARY_PATH),
                                            new AST_literal(
                                                projectSpace()
                                                    .getArgVerbValue(
                                                        Projectspace.ARG_VERB_LD_LIBRARY_PATH))))),
                                new AST_expression(
                                    new AST_method_call(
                                        new AST_dot(
                                            new AST_identifier(__variable_map),
                                            new AST_identifier("put") // $NON-NLS-1$
                                            ),
                                        new AST_elist(
                                            new AST_literal(
                                                Projectspace.ARG_VERB_DYLD_LIBRARY_PATH),
                                            new AST_literal(
                                                projectSpace()
                                                    .getArgVerbValue(
                                                        Projectspace
                                                            .ARG_VERB_DYLD_LIBRARY_PATH))))),
                                new AST_expression(
                                    new AST_method_call(
                                        new AST_dot(
                                            new AST_identifier(__variable_map),
                                            new AST_identifier("put") // $NON-NLS-1$
                                            ),
                                        new AST_elist(
                                            new AST_literal(Projectspace.ARG_VERB_GRASS_SH),
                                            new AST_literal(
                                                projectSpace()
                                                    .getArgVerbValue(
                                                        Projectspace.ARG_VERB_GRASS_SH))))),
                                new AST_expression(
                                    new AST_method_call(
                                        new AST_dot(
                                            new AST_identifier(__variable_map),
                                            new AST_identifier("put") // $NON-NLS-1$
                                            ),
                                        new AST_elist(
                                            new AST_literal(Projectspace.ARG_VERB_USER_HOME),
                                            new AST_literal(
                                                projectSpace()
                                                    .getArgVerbValue(
                                                        Projectspace.ARG_VERB_USER_HOME))))),
                                new AST_expression(
                                    new AST_method_call(
                                        new AST_dot(
                                            new AST_identifier(__variable_map),
                                            new AST_identifier("put") // $NON-NLS-1$
                                            ),
                                        new AST_elist(
                                            new AST_literal(Projectspace.ARG_VERB_USER_NAME),
                                            new AST_literal(
                                                projectSpace()
                                                    .getArgVerbValue(
                                                        Projectspace.ARG_VERB_USER_NAME))))),
                                new AST_expression(
                                    new AST_method_call(
                                        new AST_dot(
                                            new AST_identifier(__variable_map),
                                            new AST_identifier("put") // $NON-NLS-1$
                                            ),
                                        new AST_elist(
                                            new AST_literal(Projectspace.ARG_VERB_PATH),
                                            new AST_plus(
                                                new AST_literal(
                                                    projectSpace()
                                                        .getArgVerbValue(
                                                            Projectspace.ARG_VERB_PATH)),
                                                new AST_method_call(
                                                    new AST_dot(
                                                        new AST_identifier("System") // $NON-NLS-1$
                                                        ,
                                                        new AST_identifier(
                                                            "getProperty") //$NON-NLS-1$
                                                        ),
                                                    new AST_elist(
                                                        new AST_literal(
                                                            "java.library.path" //$NON-NLS-1$
                                                            ))))))))
                            // )
                            ,
                            new AST_expression(
                                new AST_dot(
                                    new AST_identifier(__variable_pb),
                                    new AST_method_call(
                                        new AST_identifier(
                                            "redirectErrorStream" //$NON-NLS-1$
                                            ),
                                        new AST_elist(new AST_bool_true())))),
                            new AST_expression(
                                new AST_variable_definition(
                                    new AST_type(__typedef_instance.type()),
                                    new AST_identifier(__variable_instance),
                                    new AST_assign_statement(new AST_null()))),
                            new AST_try(
                                new AST_block(
                                    new AST_slist(
                                        new AST_expression(
                                            new AST_assign_statement(
                                                new AST_identifier(__variable_instance),
                                                new AST_method_call(
                                                    new AST_dot(
                                                        new AST_identifier(__variable_pb),
                                                        new AST_identifier("start") // $NON-NLS-1$
                                                        ),
                                                    new AST_elist()))),
                                        new AST_expression(
                                            new AST_variable_definition(
                                                new AST_type(__typedef_bufferedreader.type()),
                                                new AST_identifier(__variable_reader),
                                                new AST_assign_statement(
                                                    new AST_ctor_call(
                                                        new AST_identifier(
                                                            __typedef_bufferedreader.type()),
                                                        new AST_elist(
                                                            new AST_ctor_call(
                                                                new AST_identifier(
                                                                    __typedef_istreamreader.type()),
                                                                new AST_elist(
                                                                    new AST_method_call(
                                                                        new AST_dot(
                                                                            new AST_identifier(
                                                                                __variable_instance),
                                                                            new AST_identifier(
                                                                                "getInputStream") //$NON-NLS-1$
                                                                            ),
                                                                        new AST_elist())))))))),
                                        new AST_expression(
                                            new AST_variable_definition(
                                                new AST_type(__typedef_string.type()),
                                                new AST_identifier(__variable_string))),
                                        new AST_while(
                                            new AST_condition(
                                                new AST_logical_unequal(
                                                    new AST_null(),
                                                    new AST_elist(
                                                        new AST_assign_statement(
                                                            new AST_identifier(__variable_string),
                                                            new AST_method_call(
                                                                new AST_dot(
                                                                    new AST_identifier(
                                                                        __variable_reader),
                                                                    new AST_identifier(
                                                                        "readLine") //$NON-NLS-1$
                                                                    ),
                                                                new AST_elist()))))),
                                            new AST_block(
                                                new AST_slist(
                                                    new AST_expression(
                                                        new AST_method_call(
                                                            new AST_identifier(
                                                                "println") //$NON-NLS-1$
                                                            ,
                                                            new AST_elist(
                                                                new AST_identifier(
                                                                    __variable_string))))))),
                                        new AST_expression(
                                            new AST_method_call(
                                                new AST_dot(
                                                    new AST_identifier(__variable_instance),
                                                    new AST_identifier("waitFor") // $NON-NLS-1$
                                                    ),
                                                new AST_elist()))))),
                            new AST_finally(
                                new AST_block(
                                    new AST_slist(
                                        new AST_if(
                                            new AST_condition(
                                                new AST_conditional_and(
                                                    new AST_logical_unequal(
                                                        new AST_null(),
                                                        new AST_identifier(__variable_instance)),
                                                    new AST_logical_unequal(
                                                        new AST_number_integer("0") // $NON-NLS-1$
                                                        ,
                                                        new AST_method_call(
                                                            new AST_dot(
                                                                new AST_identifier(
                                                                    __variable_instance),
                                                                new AST_identifier(
                                                                    "exitValue") //$NON-NLS-1$
                                                                ),
                                                            new AST_elist())))),
                                            new AST_then(
                                                new AST_slist(
                                                    new AST_expression(
                                                        new AST_method_call(
                                                            new AST_identifier(
                                                                "println") //$NON-NLS-1$
                                                            ,
                                                            new AST_elist(
                                                                new AST_plus(
                                                                    new AST_literal(
                                                                        operator.expression()),
                                                                    new AST_literal(
                                                                        " : exit code: ") //$NON-NLS-1$
                                                                    ,
                                                                    new AST_method_call(
                                                                        new AST_dot(
                                                                            new AST_identifier(
                                                                                __variable_instance),
                                                                            new AST_identifier(
                                                                                "exitValue") //$NON-NLS-1$
                                                                            ),
                                                                        new AST_elist())))))))))))))),
                new AST_catch(
                    new AST_elist(
                        new AST_variable_definition(
                            new AST_type(__typedef_interruptedexception.type()),
                            new AST_identifier(__variable_e))),
                    new AST_block(
                        new AST_slist(
                            new AST_expression(
                                new AST_method_call(
                                    new AST_identifier("println") // $NON-NLS-1$
                                    ,
                                    new AST_elist(new AST_identifier(__variable_e))))))),
                new AST_catch(
                    new AST_elist(
                        new AST_variable_definition(
                            new AST_type(__typedef_ioexception.type()),
                            new AST_identifier(__variable_e))),
                    new AST_block(
                        new AST_slist(
                            new AST_expression(
                                new AST_method_call(
                                    new AST_identifier("println") // $NON-NLS-1$
                                    ,
                                    new AST_elist(new AST_identifier(__variable_e))))))),
                new AST_finally(
                    new AST_block(
                        new AST_slist(
                            new AST_if(
                                new AST_condition(
                                    new AST_logical_unequal(
                                        new AST_null(), new AST_identifier(__variable_gisrc))),
                                new AST_then(
                                    new AST_slist(
                                        new AST_expression(
                                            new AST_dot(
                                                new AST_identifier(__variable_gisrc),
                                                new AST_method_call(
                                                    new AST_identifier(
                                                        "delete" //$NON-NLS-1$
                                                        ),
                                                    new AST_elist())))))))))));
  } // __native_model