mirror of
https://github.com/mirror/make.git
synced 2025-03-29 21:50:30 +08:00
Create helper functions for pushing file contexts
* src/variable.h (install_file_context, restore_file_context): Add declarations for new functions. * src/variable.c (install_file_context, restore_file_context): Define the new functions. (lookup_variable_for_file): Call them. * src/expand.c (recursively_expand_for_file): Ditto. (allocated_expand_variable_for_file): Ditto. (expand_string_for_file): Ditto.
This commit is contained in:
parent
78c8c44326
commit
23f70b0cb8
33
src/expand.c
33
src/expand.c
@ -145,7 +145,7 @@ recursively_expand_for_file (struct variable *v, struct file *file)
|
|||||||
char *value;
|
char *value;
|
||||||
const floc *this_var;
|
const floc *this_var;
|
||||||
const floc **saved_varp;
|
const floc **saved_varp;
|
||||||
struct variable_set_list *save = 0;
|
struct variable_set_list *savev = 0;
|
||||||
int set_reading = 0;
|
int set_reading = 0;
|
||||||
|
|
||||||
/* If we're expanding to put into the environment of a shell function then
|
/* If we're expanding to put into the environment of a shell function then
|
||||||
@ -198,10 +198,7 @@ recursively_expand_for_file (struct variable *v, struct file *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (file)
|
if (file)
|
||||||
{
|
install_file_context (file, &savev, NULL);
|
||||||
save = current_variable_set_list;
|
|
||||||
current_variable_set_list = file->variables;
|
|
||||||
}
|
|
||||||
|
|
||||||
v->expanding = 1;
|
v->expanding = 1;
|
||||||
if (v->append)
|
if (v->append)
|
||||||
@ -214,7 +211,7 @@ recursively_expand_for_file (struct variable *v, struct file *file)
|
|||||||
reading_file = 0;
|
reading_file = 0;
|
||||||
|
|
||||||
if (file)
|
if (file)
|
||||||
current_variable_set_list = save;
|
restore_file_context (savev, NULL);
|
||||||
|
|
||||||
expanding_var = saved_varp;
|
expanding_var = saved_varp;
|
||||||
|
|
||||||
@ -297,19 +294,11 @@ allocated_expand_variable_for_file (const char *name, size_t length, struct file
|
|||||||
if (!file)
|
if (!file)
|
||||||
return allocated_expand_variable (name, length);
|
return allocated_expand_variable (name, length);
|
||||||
|
|
||||||
savev = current_variable_set_list;
|
install_file_context (file, &savev, &savef);
|
||||||
current_variable_set_list = file->variables;
|
|
||||||
|
|
||||||
savef = reading_file;
|
|
||||||
if (file->cmds && file->cmds->fileinfo.filenm)
|
|
||||||
reading_file = &file->cmds->fileinfo;
|
|
||||||
else
|
|
||||||
reading_file = NULL;
|
|
||||||
|
|
||||||
result = allocated_expand_variable (name, length);
|
result = allocated_expand_variable (name, length);
|
||||||
|
|
||||||
current_variable_set_list = savev;
|
restore_file_context (savev, savef);
|
||||||
reading_file = savef;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -585,19 +574,11 @@ expand_string_for_file (const char *string, struct file *file)
|
|||||||
if (!file)
|
if (!file)
|
||||||
return expand_string (string);
|
return expand_string (string);
|
||||||
|
|
||||||
savev = current_variable_set_list;
|
install_file_context (file, &savev, &savef);
|
||||||
current_variable_set_list = file->variables;
|
|
||||||
|
|
||||||
savef = reading_file;
|
|
||||||
if (file->cmds && file->cmds->fileinfo.filenm)
|
|
||||||
reading_file = &file->cmds->fileinfo;
|
|
||||||
else
|
|
||||||
reading_file = NULL;
|
|
||||||
|
|
||||||
result = expand_string (string);
|
result = expand_string (string);
|
||||||
|
|
||||||
current_variable_set_list = savev;
|
restore_file_context (savev, savef);
|
||||||
reading_file = savef;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -552,12 +552,11 @@ lookup_variable_for_file (const char *name, size_t length, struct file *file)
|
|||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
return lookup_variable (name, length);
|
return lookup_variable (name, length);
|
||||||
|
|
||||||
savev = current_variable_set_list;
|
install_file_context (file, &savev, NULL);
|
||||||
current_variable_set_list = file->variables;
|
|
||||||
|
|
||||||
var = lookup_variable (name, length);
|
var = lookup_variable (name, length);
|
||||||
|
|
||||||
current_variable_set_list = savev;
|
restore_file_context (savev, NULL);
|
||||||
|
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
@ -733,7 +732,7 @@ push_new_variable_scope (void)
|
|||||||
global_setlist.next = current_variable_set_list;
|
global_setlist.next = current_variable_set_list;
|
||||||
current_variable_set_list = &global_setlist;
|
current_variable_set_list = &global_setlist;
|
||||||
}
|
}
|
||||||
return (current_variable_set_list);
|
return current_variable_set_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -770,6 +769,39 @@ pop_variable_scope (void)
|
|||||||
hash_free (&set->table, 1);
|
hash_free (&set->table, 1);
|
||||||
free (set);
|
free (set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Install a new global context for FILE so that errors/warnings are shown
|
||||||
|
in that context. Sets OLDLIST to the previous list, and if not NULL sets
|
||||||
|
OLDFLOC to reading_file and changes reading_file to the current FILE.
|
||||||
|
Use restore_file_context() to undo this. */
|
||||||
|
|
||||||
|
void
|
||||||
|
install_file_context (struct file *file, struct variable_set_list **oldlist, const floc **oldfloc)
|
||||||
|
{
|
||||||
|
*oldlist = current_variable_set_list;
|
||||||
|
current_variable_set_list = file->variables;
|
||||||
|
|
||||||
|
if (oldfloc)
|
||||||
|
{
|
||||||
|
*oldfloc = reading_file;
|
||||||
|
if (file->cmds && file->cmds->fileinfo.filenm)
|
||||||
|
reading_file = &file->cmds->fileinfo;
|
||||||
|
else
|
||||||
|
reading_file = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Restore a saved global context from OLDLIST. If OLDFLOC is not NULL,
|
||||||
|
set reading_file back to that value. */
|
||||||
|
|
||||||
|
void
|
||||||
|
restore_file_context (struct variable_set_list *oldlist, const floc *oldfloc)
|
||||||
|
{
|
||||||
|
current_variable_set_list = oldlist;
|
||||||
|
if (oldfloc)
|
||||||
|
reading_file = oldfloc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Merge FROM_SET into TO_SET, freeing unused storage in FROM_SET. */
|
/* Merge FROM_SET into TO_SET, freeing unused storage in FROM_SET. */
|
||||||
|
|
||||||
|
@ -160,6 +160,8 @@ struct variable_set_list *create_new_variable_set (void);
|
|||||||
void free_variable_set (struct variable_set_list *);
|
void free_variable_set (struct variable_set_list *);
|
||||||
struct variable_set_list *push_new_variable_scope (void);
|
struct variable_set_list *push_new_variable_scope (void);
|
||||||
void pop_variable_scope (void);
|
void pop_variable_scope (void);
|
||||||
|
void install_file_context (struct file *file, struct variable_set_list **oldlist, const floc **oldfloc);
|
||||||
|
void restore_file_context (struct variable_set_list *oldlist, const floc *oldfloc);
|
||||||
void define_automatic_variables (void);
|
void define_automatic_variables (void);
|
||||||
void initialize_file_variables (struct file *file, int reading);
|
void initialize_file_variables (struct file *file, int reading);
|
||||||
void print_file_variables (const struct file *file);
|
void print_file_variables (const struct file *file);
|
||||||
|
Loading…
Reference in New Issue
Block a user