mirror of
https://git.savannah.gnu.org/git/make.git
synced 2024-11-24 12:19:02 +00:00
Replace target_var boolean with enum variable_scope
Replace the target_var boolean with an enum to distinguish between global, target-specific, and pattern-specific variables when defining. * src/variable.h (enum variable_scope): Introduce enum variable_scope. Replace parameter target_var of type int with enum variable_scope. * src/load.c (load_file): Ditto. * src/main.c (handle_non_switch_argument): Ditto. * src/read.c (eval_makefile): Ditto. (eval): Ditto. (do_define): Ditto. (record_target_var): Ditto. (construct_include_path): Ditto. * src/variable.c (initialize_file_variables): Ditto. (shell_result): Ditto. (try_variable_definition): Ditto. (do_variable_definition): Ditto.
This commit is contained in:
parent
51e56a028e
commit
ec348f51d0
5 changed files with 34 additions and 24 deletions
|
@ -230,7 +230,8 @@ load_file (const floc *flocp, struct file *file, int noerror)
|
|||
|
||||
/* If the load didn't fail, add the file to the .LOADED variable. */
|
||||
if (r)
|
||||
do_variable_definition(flocp, ".LOADED", ldname, o_file, f_append_value, 0, 0);
|
||||
do_variable_definition(flocp, ".LOADED", ldname, o_file, f_append_value, 0,
|
||||
s_global);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -3011,7 +3011,7 @@ handle_non_switch_argument (const char *arg, enum variable_origin origin)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
v = try_variable_definition (0, arg, origin, 0);
|
||||
v = try_variable_definition (0, arg, origin, s_global);
|
||||
if (v != 0)
|
||||
{
|
||||
/* It is indeed a variable definition. If we don't already have this
|
||||
|
|
17
src/read.c
17
src/read.c
|
@ -413,7 +413,7 @@ eval_makefile (const char *filename, unsigned short flags)
|
|||
|
||||
/* Add this makefile to the list. */
|
||||
do_variable_definition (&ebuf.floc, "MAKEFILE_LIST", filename, o_file,
|
||||
f_append_value, 0, 0);
|
||||
f_append_value, 0, s_global);
|
||||
|
||||
/* Evaluate the makefile */
|
||||
|
||||
|
@ -740,7 +740,7 @@ eval (struct ebuffer *ebuf, int set_default)
|
|||
if (vmod.define_v)
|
||||
v = do_define (p, origin, ebuf);
|
||||
else
|
||||
v = try_variable_definition (fstart, p, origin, 0);
|
||||
v = try_variable_definition (fstart, p, origin, s_global);
|
||||
|
||||
assert (v != NULL);
|
||||
|
||||
|
@ -1483,8 +1483,8 @@ do_define (char *name, enum variable_origin origin, struct ebuffer *ebuf)
|
|||
else
|
||||
definition[idx - 1] = '\0';
|
||||
|
||||
v = do_variable_definition (&defstart, name, definition,
|
||||
origin, var.flavor, var.conditional, 0);
|
||||
v = do_variable_definition (&defstart, name, definition, origin, var.flavor,
|
||||
var.conditional, s_global);
|
||||
free (definition);
|
||||
free (n);
|
||||
return (v);
|
||||
|
@ -1822,7 +1822,7 @@ record_target_var (struct nameseq *filenames, char *defn,
|
|||
initialize_file_variables (f, 1);
|
||||
|
||||
current_variable_set_list = f->variables;
|
||||
v = try_variable_definition (flocp, defn, origin, 1);
|
||||
v = try_variable_definition (flocp, defn, origin, s_target);
|
||||
if (!v)
|
||||
O (fatal, flocp, _("malformed target-specific variable definition"));
|
||||
current_variable_set_list = global;
|
||||
|
@ -2957,10 +2957,11 @@ construct_include_path (const char **arg_dirs)
|
|||
|
||||
/* Now add each dir to the .INCLUDE_DIRS variable. */
|
||||
|
||||
do_variable_definition (NILF, ".INCLUDE_DIRS", "", o_default, f_simple, 0, 0);
|
||||
do_variable_definition (NILF, ".INCLUDE_DIRS", "", o_default, f_simple, 0,
|
||||
s_global);
|
||||
for (cpp = dirs; *cpp != 0; ++cpp)
|
||||
do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp,
|
||||
o_default, f_append, 0, 0);
|
||||
do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp, o_default, f_append,
|
||||
0, s_global);
|
||||
|
||||
free ((void *) include_directories);
|
||||
include_directories = dirs;
|
||||
|
|
|
@ -706,9 +706,9 @@ initialize_file_variables (struct file *file, int reading)
|
|||
else
|
||||
{
|
||||
v = do_variable_definition (
|
||||
&p->variable.fileinfo, p->variable.name,
|
||||
p->variable.value, p->variable.origin,
|
||||
p->variable.flavor, p->variable.conditional, 1);
|
||||
&p->variable.fileinfo, p->variable.name, p->variable.value,
|
||||
p->variable.origin, p->variable.flavor,
|
||||
p->variable.conditional, s_pattern);
|
||||
}
|
||||
|
||||
/* Also mark it as a per-target and copy export status. */
|
||||
|
@ -1372,7 +1372,7 @@ shell_result (const char *p)
|
|||
struct variable *
|
||||
do_variable_definition (const floc *flocp, const char *varname, const char *value,
|
||||
enum variable_origin origin, enum variable_flavor flavor,
|
||||
int conditional, int target_var)
|
||||
int conditional, enum variable_scope scope)
|
||||
{
|
||||
const char *newval;
|
||||
char *alloc_value = NULL;
|
||||
|
@ -1438,7 +1438,7 @@ do_variable_definition (const floc *flocp, const char *varname, const char *valu
|
|||
{
|
||||
/* If we have += but we're in a target variable context, we want to
|
||||
append only with other variables in the context of this target. */
|
||||
if (target_var)
|
||||
if (scope)
|
||||
{
|
||||
append = 1;
|
||||
v = lookup_variable_in_set (varname, strlen (varname),
|
||||
|
@ -1615,7 +1615,7 @@ do_variable_definition (const floc *flocp, const char *varname, const char *valu
|
|||
{
|
||||
v = define_variable_in_set (varname, strlen (varname), default_shell,
|
||||
origin, flavor == f_recursive,
|
||||
(target_var
|
||||
(specificity
|
||||
? current_variable_set_list->set
|
||||
: NULL),
|
||||
flocp);
|
||||
|
@ -1631,7 +1631,7 @@ do_variable_definition (const floc *flocp, const char *varname, const char *valu
|
|||
{
|
||||
v = define_variable_in_set (varname, strlen (varname), newval,
|
||||
origin, flavor == f_recursive,
|
||||
(target_var
|
||||
(specificity
|
||||
? current_variable_set_list->set
|
||||
: NULL),
|
||||
flocp);
|
||||
|
@ -1659,8 +1659,8 @@ do_variable_definition (const floc *flocp, const char *varname, const char *valu
|
|||
|
||||
v = define_variable_in_set (varname, strlen (varname), newval, origin,
|
||||
flavor == f_recursive || flavor == f_expand,
|
||||
(target_var
|
||||
? current_variable_set_list->set : NULL),
|
||||
(scope == s_global
|
||||
? NULL : current_variable_set_list->set),
|
||||
flocp);
|
||||
v->append = append;
|
||||
v->conditional = conditional;
|
||||
|
@ -1850,7 +1850,7 @@ assign_variable_definition (struct variable *v, const char *line)
|
|||
|
||||
struct variable *
|
||||
try_variable_definition (const floc *flocp, const char *line,
|
||||
enum variable_origin origin, int target_var)
|
||||
enum variable_origin origin, enum variable_scope scope)
|
||||
{
|
||||
struct variable v;
|
||||
struct variable *vp;
|
||||
|
@ -1863,8 +1863,8 @@ try_variable_definition (const floc *flocp, const char *line,
|
|||
if (!assign_variable_definition (&v, line))
|
||||
return 0;
|
||||
|
||||
vp = do_variable_definition (flocp, v.name, v.value,
|
||||
origin, v.flavor, v.conditional, target_var);
|
||||
vp = do_variable_definition (flocp, v.name, v.value, origin, v.flavor,
|
||||
v.conditional, scope);
|
||||
|
||||
free (v.name);
|
||||
|
||||
|
|
|
@ -51,6 +51,13 @@ enum variable_export
|
|||
v_ifset /* Export it if it has a non-default value. */
|
||||
};
|
||||
|
||||
enum variable_scope
|
||||
{
|
||||
s_global = 0, /* Global variable. */
|
||||
s_target, /* Target-specific variable. */
|
||||
s_pattern /* Pattern-specific variable. */
|
||||
};
|
||||
|
||||
/* Structure that represents one variable definition.
|
||||
Each bucket of the hash table is a chain of these,
|
||||
chained through 'next'. */
|
||||
|
@ -171,13 +178,14 @@ struct variable *do_variable_definition (const floc *flocp,
|
|||
const char *name, const char *value,
|
||||
enum variable_origin origin,
|
||||
enum variable_flavor flavor,
|
||||
int conditional, int target_var);
|
||||
int conditional,
|
||||
enum variable_scope scope);
|
||||
char *parse_variable_definition (const char *line,
|
||||
struct variable *v);
|
||||
struct variable *assign_variable_definition (struct variable *v, const char *line);
|
||||
struct variable *try_variable_definition (const floc *flocp, const char *line,
|
||||
enum variable_origin origin,
|
||||
int target_var);
|
||||
enum variable_scope scope);
|
||||
void init_hash_global_variable_set (void);
|
||||
void hash_init_function_table (void);
|
||||
void define_new_function(const floc *flocp, const char *name,
|
||||
|
|
Loading…
Reference in a new issue