]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Replace target_var boolean with enum variable_scope
authorDmitry Goncharov <dgoncharov@users.sf.net>
Sun, 28 Jan 2024 19:46:55 +0000 (14:46 -0500)
committerPaul Smith <psmith@gnu.org>
Sun, 4 Feb 2024 16:32:50 +0000 (11:32 -0500)
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.

src/load.c
src/main.c
src/read.c
src/variable.c
src/variable.h

index 626c34f0665f1960a7b81a87da1bdb2e53c857e9..8fb5d3abb1197ccc8bdcc3072ba32e297e16f408 100644 (file)
@@ -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;
 }
index d07f561a208b1e4ce32130373d579e0142f19327..99011d9e8d2eca3bb0bdb3ea174f80cdf729fece 100644 (file)
@@ -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
index 069f9c3032361c0ae6120b20f112539d285a15fa..0fb783a286bfcceb8abd55052373ed178ccc65b6 100644 (file)
@@ -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;
index 5cd28bf73a0955bc923a5e84b425fc81896d1a73..9d44cd4ad6da43976dacb69f3708294ba8f0db2b 100644 (file)
@@ -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);
 
index 0b84c2e5a563f8b54ce563d2274e538f42c1af9b..f6f0cb32088e052771bd6d0ed445079eb74760ab 100644 (file)
@@ -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,