Skip to content

Commit

Permalink
Add language-specific search paths
Browse files Browse the repository at this point in the history
NOTE: Needs clean up.
  • Loading branch information
positively-charged committed Jan 27, 2017
1 parent 13da8e9 commit 0af947b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/cache/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void cache_add( struct cache* cache, struct library* lib ) {
while ( ! list_end( &i ) ) {
struct import_dirc* dirc = list_data( &i );
struct file_query query;
t_init_file_query( &query, cache->task->library_main->file,
t_init_file_query( &query, NULL, cache->task->library_main->file,
dirc->file_path );
t_find_file( cache->task, &query );
if ( ! query.file ) {
Expand Down
2 changes: 1 addition & 1 deletion src/cache/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ void restore_file_map( struct restorer* restorer ) {
restorer->file_map_size );
for ( int i = 0; i < restorer->file_map_size; ++i ) {
struct file_query query;
t_init_file_query( &query, NULL, RS( restorer, F_FILEPATH ) );
t_init_file_query( &query, NULL, NULL, RS( restorer, F_FILEPATH ) );
t_find_file( restorer->task, &query );
restorer->file_map[ i ] = query.file;
list_append( &restorer->lib->files, query.file );
Expand Down
10 changes: 6 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ static bool read_options( struct options*, char** );
static void strip_rslash( char* );
static bool source_object_files_same( struct options* );
static void print_usage( char* );
static bool perform_action( struct options* options, jmp_buf* root_bail );
static bool perform_action( struct options* options, jmp_buf* root_bail,
struct str* compiler_dir );
static void perform_task( struct task* task );
static void perform_selected_task( struct task* task, struct cache* cache );
static void print_cache( struct task* task, struct cache* cache );
Expand Down Expand Up @@ -88,7 +89,7 @@ int main( int argc, char* argv[] ) {
}
jmp_buf bail;
if ( setjmp( bail ) == 0 ) {
if ( perform_action( &options, &bail ) ) {
if ( perform_action( &options, &bail, &compiler_dir ) ) {
result = EXIT_SUCCESS;
}
}
Expand Down Expand Up @@ -353,10 +354,11 @@ void print_usage( char* path ) {
path );
}

bool perform_action( struct options* options, jmp_buf* root_bail ) {
bool perform_action( struct options* options, jmp_buf* root_bail,
struct str* compiler_dir ) {
bool success = false;
struct task task;
t_init( &task, options, root_bail );
t_init( &task, options, root_bail, compiler_dir );
jmp_buf bail;
if ( setjmp( bail ) == 0 ) {
task.bail = &bail;
Expand Down
4 changes: 2 additions & 2 deletions src/parse/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,8 @@ void read_imported_libs( struct parse* parse ) {

void import_lib( struct parse* parse, struct import_dirc* dirc ) {
struct file_query query;
t_init_file_query( &query, parse->task->library_main->file,
dirc->file_path );
t_init_file_query( &query, t_get_lang_lib_dir( parse->task, parse->lang ),
parse->task->library_main->file, dirc->file_path );
t_find_file( parse->task, &query );
if ( ! query.file ) {
p_diag( parse, DIAG_POS_ERR, &dirc->pos,
Expand Down
7 changes: 5 additions & 2 deletions src/parse/token/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ void p_load_source( struct parse* parse, struct request* request ) {
str_append( &path, request->given_path );
str_append( &path, ".bcs" );
struct file_query query;
t_init_file_query( &query, request->offset_file, path.value );
t_init_file_query( &query,
t_get_lang_lib_dir( parse->task, parse->lang ), request->offset_file,
path.value );
t_find_file( parse->task, &query );
if ( query.success ) {
request->file = query.file;
Expand All @@ -167,7 +169,8 @@ void p_load_source( struct parse* parse, struct request* request ) {
}
}
struct file_query query;
t_init_file_query( &query, request->offset_file, request->given_path );
t_init_file_query( &query, t_get_lang_lib_dir( parse->task, parse->lang ),
request->offset_file, request->given_path );
t_find_file( parse->task, &query );
if ( query.success ) {
request->file = query.file;
Expand Down
32 changes: 30 additions & 2 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ static struct indexed_string* intern_string( struct task* task,
struct str_table* table, const char* value, int length, bool copy_value );
static void init_ref( struct ref* ref, int type );

void t_init( struct task* task, struct options* options, jmp_buf* bail ) {
void t_init( struct task* task, struct options* options, jmp_buf* bail,
struct str* compiler_dir ) {
task->options = options;
task->err_file = NULL;
task->bail = bail;
Expand Down Expand Up @@ -119,6 +120,12 @@ void t_init( struct task* task, struct options* options, jmp_buf* bail ) {
add_internal_file( task, "<none>" );
add_internal_file( task, "<compiler>" );
add_internal_file( task, "<command-line>" );
task->compiler_dir = compiler_dir;
// Setup language-specific directories.
str_init( &task->acs_lib_dir );
str_append( &task->acs_lib_dir, compiler_dir->value );
str_append( &task->acs_lib_dir, OS_PATHSEP );
str_append( &task->acs_lib_dir, "lib/acs" );
}

struct ns* t_alloc_ns( struct name* name ) {
Expand Down Expand Up @@ -502,13 +509,14 @@ bool t_same_pos( struct pos* a, struct pos* b ) {
a->column == b->column );
}

void t_init_file_query( struct file_query* query,
void t_init_file_query( struct file_query* query, const char* lang_dir,
struct file_entry* offset_file, const char* path ) {
query->given_path = path;
query->path = NULL;
// NOTE: .fileid NOT initialized.
query->file = NULL;
query->offset_file = offset_file;
query->lang_dir = lang_dir;
query->success = false;
}

Expand Down Expand Up @@ -570,6 +578,16 @@ bool identify_file_relative( struct task* task, struct file_query* query ) {
}
list_next( &i );
}
// Try language-specific directories.
if ( query->lang_dir ) {
str_clear( query->path );
str_append( query->path, query->lang_dir );
str_append( query->path, OS_PATHSEP );
str_append( query->path, query->given_path );
if ( c_read_fileid( &query->fileid, query->path->value ) ) {
return true;
}
}
return false;
}

Expand Down Expand Up @@ -1106,4 +1124,14 @@ void t_update_err_file_dir( struct task* task, const char* path ) {
dir->value[ dir->length - 1 ] = 0;
--dir->length;
}
}

const char* t_get_lang_lib_dir( struct task* task, int lang ) {
switch ( lang ) {
case LANG_ACS:
case LANG_ACS95:
return task->acs_lib_dir.value;
default:
return NULL;
}
}
9 changes: 7 additions & 2 deletions src/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct file_query {
struct fileid fileid;
struct file_entry* file;
struct file_entry* offset_file;
const char* lang_dir;
bool success;
};

Expand Down Expand Up @@ -1190,6 +1191,8 @@ struct task {
struct ns* upmost_ns;
struct str err_file_dir;
struct list include_history;
struct str* compiler_dir;
struct str acs_lib_dir;
};

#define DIAG_NONE 0
Expand All @@ -1204,7 +1207,8 @@ struct task {
#define DIAG_POS DIAG_FILE | DIAG_LINE | DIAG_COLUMN
#define DIAG_POS_ERR DIAG_POS | DIAG_ERR

void t_init( struct task*, struct options*, jmp_buf* );
void t_init( struct task* task, struct options* options, jmp_buf* bail,
struct str* compiler_dir );
void t_copy_name( struct name*, bool full, struct str* buffer );
int t_full_name_length( struct name* );
void t_print_name( struct name* );
Expand All @@ -1217,7 +1221,7 @@ void t_decode_pos( struct task* task, struct pos* pos, const char** file,
int* line, int* column );
const char* t_decode_pos_file( struct task* task, struct pos* pos );
void t_init_object( struct object* object, int node_type );
void t_init_file_query( struct file_query* query,
void t_init_file_query( struct file_query* query, const char* lang_dir,
struct file_entry* offset_file, const char* path );
void t_find_file( struct task* task, struct file_query* query );
struct library* t_add_library( struct task* task );
Expand Down Expand Up @@ -1268,5 +1272,6 @@ struct include_history_entry* t_alloc_include_history_entry(
struct task* task );
struct include_history_entry* t_decode_include_history_entry(
struct task* task, int id );
const char* t_get_lang_lib_dir( struct task* task, int lang );

#endif

0 comments on commit 0af947b

Please sign in to comment.