/*----------------------------------------------------------------------------- * get section by name, creates a new section if new name; * make it the current section *----------------------------------------------------------------------------*/ Section *new_section( char *name ) { int last_id; init_module(); g_cur_section = SectionHash_get( g_sections, name ); if ( g_cur_section == NULL ) { g_cur_section = OBJ_NEW( Section ); g_cur_section->name = strpool_add( name ); SectionHash_set( & g_sections, name, g_cur_section ); /* set first and last sections */ if ( g_default_section == NULL ) g_default_section = g_cur_section; g_last_section = g_cur_section; /* define start address of all existing modules = 0, except for default section */ if ( g_default_section != NULL && *name != '\0' ) { last_id = intArray_size( g_default_section->module_start ) - 1; if ( last_id >= 0 ) intArray_item( g_cur_section->module_start, last_id ); /* init [0..module_id] to zero */ } } return g_cur_section; }
/*{{{ static ProfTabEntry *proftab_add_sourcepos_count(ProfTab * table, */ static ProfTabEntry *proftab_add_sourcepos_count (ProfTab * table, ProfTabEntryTag tag, const char *name, INT32 line, treenode * tptr) { ProfTabEntry *new_entry = add_proftab_entry (table, tag, tptr); const StrPoolI file_name = (name == NULL) ? 0 : strpool_add (table->strpool, name); proftab_file_name_ (new_entry) = file_name; proftab_line_number_ (new_entry) = line; return new_entry; }
/*----------------------------------------------------------------------------- * Open file to receive all errors / warnings from now on * File is appended, to allow assemble and link errors to be joined in the same file. *----------------------------------------------------------------------------*/ void open_error_file( char *src_filename ) { char *filename = get_err_filename( src_filename ); init_module(); /* close current file if any */ close_error_file(); error_file.filename = strpool_add( filename ); error_file.file = myfopen(error_file.filename, "a"); }
/*----------------------------------------------------------------------------- * return new auto-label in strpool *----------------------------------------------------------------------------*/ char *autolabel(void) { STR_DEFINE(label, STR_SIZE); static int n; char *ret; str_sprintf(label, "__autolabel_%04d", ++n); ret = strpool_add(str_data(label)); STR_DELETE(label); return ret; }
static char* parse_find_add_str(Parse *p, char *s) { char *r = NULL; assert(DEREF(p,pool)); if(s) { r = strpool_add(p->pool,s); p; str_replacechar(r,'\n',' '); str_replacechar(r,'\"','\''); } return r; }
int strpool_test(void) { StrPool pool = {0}; char *p; int i; printf("testing strpool..."); TEST(!strpool_find(&pool,"abc")); p=strpool_add(&pool,"abc"); TEST(p); TEST(0==strcmp("abc",strpool_add(&pool,"abc"))); TEST(p == strpool_add(&pool,"abc")); for(i = 0; i < 100; ++i) { int j; char tmp[128]; sprintf(tmp,"%i",i); strpool_add(&pool,tmp); for(j = 0; j <= i; ++j) { sprintf(tmp,"%i",j); TEST(strpool_find(&pool,tmp)); } } strpool_cleanup(&pool); #define TEST_S(A,B) TEST(0==strcmp(A,B)) p = NULL; str_cat(&p,"a"); TEST_S(p,"a"); str_cat(&p,"b"); TEST_S(p,"ab"); str_catf(&p,"%i%s%i",1,"foo",2); TEST_S(p,"ab1foo2"); free(p); printf("done.\n"); return 0; }
/*----------------------------------------------------------------------------- * create a new symbol, needs to be deleted by OBJ_DELETE() * adds a reference to the page were referred to *----------------------------------------------------------------------------*/ Symbol *Symbol_create(char *name, long value, sym_type_t type, sym_scope_t scope, Module *module, Section *section ) { Symbol *self = OBJ_NEW( Symbol ); self->name = strpool_add(name); /* name in strpool, not freed */ self->value = value; self->type = type; self->scope = scope; self->module = module; self->section = section; /* add reference */ add_symbol_ref( self->references, list_get_page_nr(), FALSE ); return self; /* pointer to new symbol */ }
/*----------------------------------------------------------------------------- * return full symbol name NAME@MODULE stored in strpool *----------------------------------------------------------------------------*/ char *Symbol_fullname( Symbol *sym ) { STR_DEFINE(name, STR_SIZE); char *ret; str_set( name, sym->name ); if ( sym->module && sym->module->modname ) { str_append_char( name, '@' ); str_append( name, sym->module->modname ); } ret = strpool_add( str_data(name) ); STR_DELETE(name); return ret; }
void set_error_file( char *filename ) { init_module(); errors.filename = strpool_add( filename ); /* may be NULL */ }
void set_error_module( char *modulename ) { init_module(); errors.module = strpool_add( modulename ); /* may be NULL */ }