Ejemplo n.º 1
0
void sequence(struct obj *i)
{
//	printf("Last Phase %d\n", last_phase);
//	printf("1:Processing %s %d\n", i->name, i->type);
	if (i->type == TYPE_S) {
		convert_S_to_s(i->name);
		i->type = TYPE_s;
		i->used = 1;
	}
	if (i->type == TYPE_C) {
		preprocess_c(i->name);
		i->type = TYPE_C_pp;
		i->used = 1;
	}
	if (last_phase == 1)
		return;
//	printf("2:Processing %s %d\n", i->name, i->type);
	if (i->type == TYPE_C_pp) {
		convert_c_to_s(i->name);
		i->type = TYPE_s;
		i->used = 1;
	}
	if (last_phase == 2)
		return;
//	printf("3:Processing %s %d\n", i->name, i->type);
	if (i->type == TYPE_s) {
		convert_s_to_o(i->name);
		i->type = TYPE_O;
		i->used = 1;
	}
}
Ejemplo n.º 2
0
/*--------------------------------------------------------------------
 * output_viewer::print_output
 *
 */
bool
output_viewer::print_output(String file)
{
  const char* filename = file.c_str();
  post_progress(this, "Loading output file ...", 0);

  text->clear();

  FILE *fd = fopen( filename, "r" );
  if (!fd) {
    text->fout() << "Cannot open file " << filename << endl;
    text->update();
    unpost_progress( this );
    return false;
  }

  /* read the file */
  fseek(fd, 0, SEEK_END);
  long length = ftell(fd);
  fseek(fd, 0, SEEK_SET);
  char *buffer = new char[length];
  int l = fread(buffer, 1, length, fd);
  buffer[l] = 0;
  fclose(fd);

  int current_line = 1;
  int current_src_line = -1;
  bool new_src_line = false;
  bool parse_error = false;
  int scope = 0;
  scope_node *current_scope = 0;
  int state = NORMAL_STATE;

  erase_mappings();		// erase previous mappings

  char *next_line;
  char *current_src_file = 0;
  for (char *line = buffer; line; line = next_line) {
    next_line = strchr(line, '\n');
    if (next_line) {
      *next_line++ = 0;
    }

    /*
     * Preprocess C
     */
    bool found_line_num;
    char *ppc = preprocess_c(line, state, current_src_file,
			     current_src_line, found_line_num);
    /*
     * Scan for "{" and "}" to determine current scope.
     */
    for (char *p = ppc; *p; p++) {
      if (*p == '{') {
	if (scope == 0) {
	  current_scope = new scope_node;
	  current_scope->first_line = current_line;
	  current_scope->proc = 0;
	  proc_scopes->push_back(current_scope);
	}
	scope++;

      } else if (*p == '}') {
	scope--;
	if (scope < 0) {
	  parse_error = true;
	}
	if (scope == 0) {
	  current_scope->last_line = current_line;
	}
      }
    }
    delete (ppc);

    /* Check if current line has line number annotation */
    if (found_line_num) {
      new_src_line = true;
      continue;			// don't print it out
    }

    /*
     * Record the line, if nec.
     */
    if (new_src_line) {
      /* enter this line as a node */
      output_node *node = new output_node(current_src_line,
					  current_src_file,
					  current_line);
      if (current_scope) {
	current_scope->nodes.push_back(node);
	
	/* match current scope to procedure */
	if (current_scope->proc == 0) {
	  SuifObject *tn =
	     map_line_to_tree_node( find_file_block(String(current_src_file)),
					            current_src_line);
	  if (tn) {
	    current_scope->proc = get_procedure_definition( tn );
	  }
	}
      }

      new_src_line = false;
    }

    /* print the line out */
    text->fout() << line << endl;
    current_line++;
  }

  delete (buffer);
  text->update();

  if (scope != 0 || parse_error) {
    display_message(this, "Warning: unable to parse the file `%s'.", filename);
  }

  if ( proc_scopes->empty()) {
    display_message(this, "Warning: cannot find line number information in "
		    "the file `%s'.",
		    filename);
    unpost_progress( this );
    return false;
  }

  /*
   * Get the file set entry of this file
   */
  if (!current_fse) {
    if ( current_src_file ) {
      current_fse = find_file_block(current_src_file);
    }
    if (!current_fse) {
      display_message(this,
      	      "Warning: cannot find the corresponding file set entry.");
      unpost_progress(this);
      return false;
    }
  }
  /*
   * Create new output tree
   */
  delete outtree;
  outtree = new code_tree;
  outtree->set_map_fn( (map_tn_fn) &map_tree_node, this );


  // iterate over the procedures
  DefinitionBlock *def_block = current_fse->get_definition_block();
  int num_procs = def_block->get_procedure_definition_count();
  for (int i = 0; i < num_procs; ++i) {

    ProcedureDefinition *proc = def_block->get_procedure_definition(i);

    ExecutionObject *body = proc->get_body();
    if ( body ) {
      outtree->build( proc );
    }

    post_progress(this, "Loading output file..",
		  ((float) (i+1))/num_procs*100);
  }


  /* create tags */
  outtree->create_tags(text);

  unpost_progress(this);

  return true;
}