Walker::ApplyStatus fssp_scope_statement_walker::operator () (SuifObject *x){
    ScopeStatement *scope_stmt = to<ScopeStatement>(x); 
    
    Statement *scope_stmt_body = scope_stmt->get_body();
    SymbolTable *scope_stmt_sym_table = scope_stmt->get_symbol_table();
    DefinitionBlock *scope_stmt_def_block = scope_stmt->get_definition_block();

    ProcedureDefinition *enclosing_proc_def = get_procedure_definition(scope_stmt);
    SymbolTable *enclosing_proc_def_sym_table = enclosing_proc_def->get_symbol_table();
    DefinitionBlock *enclosing_proc_def_def_block = enclosing_proc_def->get_definition_block();

    while(scope_stmt_sym_table->get_symbol_table_object_count() > 0){
        SymbolTableObject *sym_tab_obj = scope_stmt_sym_table->remove_symbol_table_object(0);
	rename_symbol(sym_tab_obj, "" ); //  String("renamed_") + String(sym_tab_obj->get_name()));
 	enclosing_proc_def_sym_table->append_symbol_table_object(sym_tab_obj);
    }

    while(scope_stmt_def_block->get_variable_definition_count() > 0){
        VariableDefinition *var_def = scope_stmt_def_block->remove_variable_definition(0);
 	enclosing_proc_def_def_block->append_variable_definition(var_def);
    }

    scope_stmt->set_body(0); 
    scope_stmt->get_parent()->replace(scope_stmt, scope_stmt_body);
 
    set_address(scope_stmt_body);
    return Walker::Replaced;
};
Ejemplo n.º 2
0
void AvoidLabelCollisions::do_procedure_definition( ProcedureDefinition *proc_def ) {
  // get a list of all of the Labels in the procedure.
  list<CodeLabelSymbol*>* l = collect_objects<CodeLabelSymbol>(proc_def);

  suif_hash_map<LString, int> label_defined;
  // It's an n^2 algorithm.  If this ever becomes
  // a problem, we can use a hash map.
  while (!l->empty()) {
    CodeLabelSymbol *lab = l->front();
    l->pop_front();
    LString name = lab->get_name();
    if (name == emptyLString) continue;
    if (label_defined.find(name) != label_defined.end()) {
      rename_symbol(lab, emptyLString);
      continue;
    }
    label_defined.enter_value(name, 1);
  }
  delete l;
}
Ejemplo n.º 3
0
Walker::ApplyStatus CollisionAvoider::operator () (SuifObject *x) {
    Symbol *symbol = to<Symbol>(x);

    // delete names which mask externals. If we end up with a name that does
    // not, just return, otherwise create a new name

    // printf("next symbol is ");printobj(symbol);
    LString sname = symbol->get_name();
    //    bool is_key = is_keyword(sname);

    if (sname == emptyLString) {
        if (name_all_symbols)
            name_variable(symbol,& source_file_name);
        return Walker::Continue;
        }

    SymbolTable *scope = symbol->get_symbol_table();
    if (!is_keyword(sname)) {
      bool conflicts = is_var_name_crashd_locally(symbol);
      if (scope != external_symbol_table) {
	// if it doesn't conflict in the external symbol table
	if (external_symbol_table->has_lookup_table_member(sname)) {
	  conflicts = true;
	} else {
	  if (file_scope_symbol_tables) {
	    // or the file scope tables
	    for (list<SymbolTable*>::iterator iter = 
		   file_scope_symbol_tables->begin();
		 iter != file_scope_symbol_tables->end();  iter++)
	        {
		SymbolTable *symtab = *iter;
		if (symtab == scope) continue;
		if (symtab->has_lookup_table_member(sname))
		    {
		    conflicts = true;
		    break;
		    }
	        }
	  }
   
	  if (!conflicts)
	      {
              SymbolTable *curr_scope =
                             symbol->get_symbol_table()->get_explicit_super_scope();
              while (curr_scope &&
                     curr_scope->get_explicit_super_scope() != external_symbol_table)
                  {
                  if (curr_scope->has_lookup_table_member(sname ))
                      {
                      conflicts = true;
                      break;
                      }
                  curr_scope = curr_scope->get_explicit_super_scope();
                  }
              }
         }
      }

      if (!conflicts)
	return Walker::Continue;
    }

    // TBD:
    // Actually, we may have to check 
    // for ANY conflict.  I.e. for machsuif,
    // labels conflict with procedures

    // Added July 29 for Fortran
    // Make sure names are not common "reserved words" from C
    // This is lsightly bogus - should be configurable somehow
    // We only need this because we are generating C out. If we
    // are going to a code gen, or outputting some other language
    // this is not needed or needs changing

    //	int no = symbol->num_name_with_key(sname);
    //	while (no > 0) {
    // printf("conflict found\n");
    //    	    symbol->remove_name(sname,--no);
    //	    }
    //}
    rename_symbol(symbol, emptyLString);
    //    if (name_all_symbols)
    name_variable(symbol,& source_file_name);
    return Walker::Continue;
    }