Skip to content

Commit

Permalink
Refactor: add static keyword to function definitions that have inte…
Browse files Browse the repository at this point in the history
…rnal linkage
  • Loading branch information
positively-charged committed May 5, 2017
1 parent e12b726 commit ffc2e21
Show file tree
Hide file tree
Showing 34 changed files with 1,079 additions and 987 deletions.
20 changes: 10 additions & 10 deletions src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void t_create_builtins( struct task* task, int lang ) {
}
}

void init_setup( struct setup* setup, struct task* task, int lang ) {
static void init_setup( struct setup* setup, struct task* task, int lang ) {
setup->task = task;
setup->func = NULL;
setup->param = NULL;
Expand All @@ -380,7 +380,7 @@ void init_setup( struct setup* setup, struct task* task, int lang ) {
setup->lang = lang;
}

void setup_func( struct setup* setup, int entry ) {
static void setup_func( struct setup* setup, int entry ) {
struct func* func = t_alloc_func();
t_init_pos_id( &func->object.pos, INTERNALFILE_COMPILER );
func->object.resolved = true;
Expand Down Expand Up @@ -420,7 +420,7 @@ void setup_func( struct setup* setup, int entry ) {
}
}

void setup_return_type( struct setup* setup ) {
static void setup_return_type( struct setup* setup ) {
int spec = SPEC_VOID;
if ( ! (
setup->format[ 0 ] == '\0' ||
Expand Down Expand Up @@ -451,7 +451,7 @@ void setup_return_type( struct setup* setup ) {
setup->func->return_spec = spec;
}

void setup_param_list( struct setup* setup ) {
static void setup_param_list( struct setup* setup ) {
switch ( setup->lang ) {
case LANG_ACS:
case LANG_ACS95:
Expand All @@ -462,7 +462,7 @@ void setup_param_list( struct setup* setup ) {
}
}

void setup_param_list_acs( struct setup* setup ) {
static void setup_param_list_acs( struct setup* setup ) {
// In ACS and ACS95, we're just interested in the parameter count.
bool optional = false;
while ( setup->format[ 0 ] ) {
Expand All @@ -479,7 +479,7 @@ void setup_param_list_acs( struct setup* setup ) {
}
}

void setup_param_list_bcs( struct setup* setup ) {
static void setup_param_list_bcs( struct setup* setup ) {
const char* format = setup->format;
bool optional = false;
while ( format[ 0 ] ) {
Expand Down Expand Up @@ -516,7 +516,7 @@ void setup_param_list_bcs( struct setup* setup ) {
setup->param_tail = NULL;
}

void setup_default_value( struct setup* setup, struct param* param,
static void setup_default_value( struct setup* setup, struct param* param,
int param_number ) {
switch ( setup->func->type ) {
struct func_ded* ded;
Expand All @@ -536,7 +536,7 @@ void setup_default_value( struct setup* setup, struct param* param,
param->default_value = setup->task->dummy_expr;
}

void setup_empty_string_default_value( struct setup* setup,
static void setup_empty_string_default_value( struct setup* setup,
struct param* param ) {
if ( ! setup->empty_string_expr ) {
struct indexed_string* string = t_intern_string( setup->task, "", 0 );
Expand All @@ -554,12 +554,12 @@ void setup_empty_string_default_value( struct setup* setup,
param->default_value = setup->empty_string_expr;
}

void append_param( struct setup* setup, struct param* param ) {
static void append_param( struct setup* setup, struct param* param ) {
if ( setup->param ) {
setup->param_tail->next = param;
}
else {
setup->param = param;
}
setup->param_tail = param;
}
}
21 changes: 11 additions & 10 deletions src/cache/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ void cache_save_archive( struct cache* cache, struct field_writer* writer ) {
save_archive( &saver );
}

void save_archive( struct saver* saver ) {
static void save_archive( struct saver* saver ) {
WF( saver, F_ARCHIVE );
save_table( saver );
WF( saver, F_END );
}

void save_table( struct saver* saver ) {
static void save_table( struct saver* saver ) {
struct cache_entry* entry = saver->cache->entries.head;
while ( entry ) {
save_entry( saver, entry );
entry = entry->next;
}
}

void save_entry( struct saver* saver, struct cache_entry* entry ) {
static void save_entry( struct saver* saver, struct cache_entry* entry ) {
WF( saver, F_ENTRY );
WS( saver, F_PATH, entry->path.value );
WV( saver, F_COMPILETIME, &entry->compile_time );
Expand All @@ -61,7 +61,8 @@ void save_entry( struct saver* saver, struct cache_entry* entry ) {
WF( saver, F_END );
}

void save_dependency_list( struct saver* saver, struct cache_entry* entry ) {
static void save_dependency_list( struct saver* saver,
struct cache_entry* entry ) {
struct cache_dependency* dep = entry->dependency;
while ( dep ) {
WF( saver, F_DEPENDENCY );
Expand Down Expand Up @@ -102,19 +103,19 @@ void cache_restore_archive( struct cache* cache,
restore_archive( &restorer );
}

void restore_archive( struct restorer* restorer ) {
static void restore_archive( struct restorer* restorer ) {
RF( restorer, F_ARCHIVE );
restore_table( restorer );
RF( restorer, F_END );
}

void restore_table( struct restorer* restorer ) {
static void restore_table( struct restorer* restorer ) {
while ( f_peek( restorer->r ) == F_ENTRY ) {
restore_entry( restorer );
}
}

void restore_entry( struct restorer* restorer ) {
static void restore_entry( struct restorer* restorer ) {
RF( restorer, F_ENTRY );
struct cache_entry* entry = cache_alloc_entry();
str_append( &entry->path, RS( restorer, F_PATH ) );
Expand All @@ -125,18 +126,18 @@ void restore_entry( struct restorer* restorer ) {
cache_append_entry( &restorer->cache->entries, entry );
}

void restore_dependency_list( struct restorer* restorer,
static void restore_dependency_list( struct restorer* restorer,
struct cache_entry* entry ) {
while ( f_peek( restorer->r ) == F_DEPENDENCY ) {
restore_dependency( restorer, entry );
}
}

void restore_dependency( struct restorer* restorer,
static void restore_dependency( struct restorer* restorer,
struct cache_entry* entry ) {
RF( restorer, F_DEPENDENCY );
struct cache_dependency* dep = cache_alloc_dependency( restorer->cache,
RS( restorer, F_PATH ) );
cache_append_dependency( entry, dep );
RF( restorer, F_END );
}
}
55 changes: 28 additions & 27 deletions src/cache/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void cache_init( struct cache* cache, struct task* task ) {

// NOTE: The ID is only regenerated when this file is compiled. Compiling the
// other source files of the cache will not cause the ID to be regenerated.
void generate_header_id( struct str* id ) {
static void generate_header_id( struct str* id ) {
char text[] = __DATE__ " " __TIME__;
int i = 0;
int length = 0;
Expand All @@ -94,7 +94,7 @@ void generate_header_id( struct str* id ) {
str_append_sub( id, text, length );
}

void init_cache_entry_list( struct cache_entry_list* entries ) {
static void init_cache_entry_list( struct cache_entry_list* entries ) {
entries->head = NULL;
entries->tail = NULL;
}
Expand All @@ -104,7 +104,7 @@ void cache_load( struct cache* cache ) {
restore_archive( cache );
}

void prepare_dir( struct cache* cache ) {
static void prepare_dir( struct cache* cache ) {
if ( cache->task->options->cache.dir_path ) {
str_append( &cache->dir_path, cache->task->options->cache.dir_path );
fs_strip_trailing_pathsep( &cache->dir_path );
Expand All @@ -114,7 +114,7 @@ void prepare_dir( struct cache* cache ) {
}
}

void prepare_tempdir( struct cache* cache ) {
static void prepare_tempdir( struct cache* cache ) {
// Use temporary directory of the system.
str_append( &cache->dir_path, fs_get_tempdir() );
str_append( &cache->dir_path, OS_PATHSEP );
Expand All @@ -132,7 +132,7 @@ void prepare_tempdir( struct cache* cache ) {
}
}

void restore_archive( struct cache* cache ) {
static void restore_archive( struct cache* cache ) {
struct str path;
str_init( &path );
append_archive_path( cache, &path );
Expand All @@ -142,20 +142,20 @@ void restore_archive( struct cache* cache ) {
str_deinit( &path );
}

void append_archive_path( struct cache* cache, struct str* path ) {
static void append_archive_path( struct cache* cache, struct str* path ) {
str_append( path, cache->dir_path.value );
str_append( path, OS_PATHSEP );
str_append( path, "archive.o" );
}

void init_restore_request( struct restore_request* request, int type,
static void init_restore_request( struct restore_request* request, int type,
struct str* path ) {
request->path = path;
request->lib = NULL;
request->type = type;
}

void restore( struct cache* cache, struct restore_request* request ) {
static void restore( struct cache* cache, struct restore_request* request ) {
struct file_contents contents;
fs_get_file_contents( request->path->value, &contents );
if ( ! contents.obtained ) {
Expand All @@ -182,8 +182,8 @@ void restore( struct cache* cache, struct restore_request* request ) {
mem_free( contents.data );
}

void restore_file( struct cache* cache, struct restore_request* request,
struct field_reader* reader ) {
static void restore_file( struct cache* cache,
struct restore_request* request, struct field_reader* reader ) {
f_rf( reader, F_HEADER );
const char* id = f_rs( reader, F_ID );
if ( strcmp( id, cache->header_id.value ) != 0 ) {
Expand Down Expand Up @@ -264,7 +264,7 @@ struct cache_entry* cache_alloc_entry( void ) {
return entry;
}

int generate_id( struct cache* cache ) {
static int generate_id( struct cache* cache ) {
// Search for an unused ID between entries.
int id = 0;
struct cache_entry* entry = cache->entries.head;
Expand All @@ -288,7 +288,7 @@ void cache_append_entry( struct cache_entry_list* entries,
}

// Appends the entry into the list, sorted by ID.
void append_entry_sorted( struct cache_entry_list* entries,
static void append_entry_sorted( struct cache_entry_list* entries,
struct cache_entry* latest_entry ) {
struct cache_entry* prev_entry = NULL;
struct cache_entry* entry = entries->head;
Expand Down Expand Up @@ -357,15 +357,16 @@ struct library* cache_get( struct cache* cache, struct file_entry* file ) {
return entry->lib;
}

struct cache_entry* find_entry( struct cache* cache, const char* path ) {
static struct cache_entry* find_entry( struct cache* cache,
const char* path ) {
struct cache_entry* entry = cache->entries.head;
while ( entry && strcmp( entry->path.value, path ) != 0 ) {
entry = entry->next;
}
return entry;
}

bool timestamp_entry( struct cache_entry* entry ) {
static bool timestamp_entry( struct cache_entry* entry ) {
struct cache_dependency* dep = entry->dependency;
while ( dep ) {
struct fs_query query;
Expand All @@ -380,15 +381,15 @@ bool timestamp_entry( struct cache_entry* entry ) {
return true;
}

bool fresh_entry( struct cache_entry* entry ) {
static bool fresh_entry( struct cache_entry* entry ) {
struct cache_dependency* dep = entry->dependency;
while ( dep && dep->mtime <= entry->compile_time ) {
dep = dep->next;
}
return ( dep == NULL );
}

bool restore_lib( struct cache* cache, struct cache_entry* entry ) {
static bool restore_lib( struct cache* cache, struct cache_entry* entry ) {
struct str path;
str_init( &path );
append_entry_path( cache, entry, &path );
Expand All @@ -399,7 +400,7 @@ bool restore_lib( struct cache* cache, struct cache_entry* entry ) {
return ( entry->lib != NULL );
}

void append_entry_path( struct cache* cache, struct cache_entry* entry,
static void append_entry_path( struct cache* cache, struct cache_entry* entry,
struct str* path ) {
str_append( path, cache->dir_path.value );
str_append( path, OS_PATHSEP );
Expand All @@ -419,7 +420,7 @@ void cache_clear( struct cache* cache ) {
}
}

void unlink_entry( struct cache_entry_list* entries,
static void unlink_entry( struct cache_entry_list* entries,
struct cache_entry* selected_entry ) {
struct cache_entry* prev_entry = NULL;
struct cache_entry* entry = entries->head;
Expand Down Expand Up @@ -453,11 +454,11 @@ void cache_close( struct cache* cache ) {
save_cache( cache );
}

bool lifetime_enabled( struct cache* cache ) {
static bool lifetime_enabled( struct cache* cache ) {
return ( cache->lifetime > 0 );
}

void remove_outdated_entries( struct cache* cache ) {
static void remove_outdated_entries( struct cache* cache ) {
struct cache_entry* entry = cache->entries.head;
while ( entry ) {
struct cache_entry* next_entry = entry->next;
Expand All @@ -470,12 +471,12 @@ void remove_outdated_entries( struct cache* cache ) {
}
}

time_t lifetime_seconds( struct cache* cache ) {
static time_t lifetime_seconds( struct cache* cache ) {
return ( 60 * 60 * cache->lifetime );
}

// Writes cache contents into permanent storage.
void save_cache( struct cache* cache ) {
static void save_cache( struct cache* cache ) {
bool archive_updated = false;
// Remove files of removed entries.
struct cache_entry* entry = cache->removed_entries.head;
Expand Down Expand Up @@ -504,7 +505,7 @@ void save_cache( struct cache* cache ) {
}
}

void save_lib( struct cache* cache, struct cache_entry* entry ) {
static void save_lib( struct cache* cache, struct cache_entry* entry ) {
struct field_writer writer;
gbuf_reset( &cache->task->growing_buffer );
f_init_writer( &writer, &cache->task->growing_buffer );
Expand All @@ -519,13 +520,13 @@ void save_lib( struct cache* cache, struct cache_entry* entry ) {
str_deinit( &path );
}

void save_header( struct cache* cache, struct field_writer* writer ) {
static void save_header( struct cache* cache, struct field_writer* writer ) {
f_wf( writer, F_HEADER );
f_ws( writer, F_ID, cache->header_id.value );
f_wf( writer, F_END );
}

void save_archive( struct cache* cache ) {
static void save_archive( struct cache* cache ) {
struct field_writer writer;
gbuf_reset( &cache->task->growing_buffer );
f_init_writer( &writer, &cache->task->growing_buffer );
Expand Down Expand Up @@ -561,7 +562,7 @@ void cache_print( struct cache* cache ) {
}
}

void print_entry( struct cache* cache, struct cache_entry* entry ) {
static void print_entry( struct cache* cache, struct cache_entry* entry ) {
printf( "library=%s\n", entry->path.value );
struct str path;
str_init( &path );
Expand All @@ -583,7 +584,7 @@ void print_entry( struct cache* cache, struct cache_entry* entry ) {
}
}

void print_lifetime( struct cache* cache, struct cache_entry* entry ) {
static void print_lifetime( struct cache* cache, struct cache_entry* entry ) {
time_t expire_time = entry->compile_time + lifetime_seconds( cache );
struct tm* tm_time = localtime( &expire_time );
char time_text[ 100 ];
Expand Down
Loading

0 comments on commit ffc2e21

Please sign in to comment.