]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Refactor the formatstring code.
authorBruno Haible <bruno@clisp.org>
Thu, 30 Nov 2023 08:02:29 +0000 (09:02 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 30 Nov 2023 11:18:13 +0000 (12:18 +0100)
Use "regions" instead of "contexts" to keep track of the flags and data that is
specific to a (usually parenthesized) block in an input file.

* gettext-tools/src/xg-arglist-context.h (null_context, passthrough_context,
inherited_context): Remove declarations.
(struct formatstring_region_ty, struct flag_region_ty): New types.
(null_context_region, inheriting_region, ref_region, unref_region): New
declarations.
(assign_region, assign_new_region): New macros.
* gettext-tools/src/xg-arglist-context.c: Include attribute.h.
(null_context): Make static.
(passthrough_context): Make static. Mark as MAYBE_UNUSED.
(inherited_context): Remove function.
(the_null_context_region): New variable.
(null_context_region, inheriting_region, ref_region, unref_region): New
functions.
* gettext-tools/src/xg-arglist-parser.h (struct partial_call,
arglist_parser_remember, arglist_parser_remember_msgctxt): Use
'flag_region_ty *' instead of flag_context_ty.
* gettext-tools/src/xg-arglist-parser.c (arglist_parser_alloc,
arglist_parser_clone, arglist_parser_remember): Update.
(arglist_parser_remember_msgctxt, arglist_parser_done): Use 'flag_region_ty *'
instead of flag_context_ty.
* gettext-tools/src/xg-message.h (remember_a_message,
remember_a_message_plural): Use 'flag_region_ty *' instead of flag_context_ty.
* gettext-tools/src/xg-message.c (set_format_flags_from_context,
remember_a_message, remember_a_message_plural): Use 'flag_region_ty *' instead
of flag_context_ty.
* gettext-tools/src/x-awk.c (extract_parenthesized): Use 'flag_region_ty *'
instead of flag_context_ty.
(extract_awk): Update.
* gettext-tools/src/x-c.c (extract_parenthesized): Use 'flag_region_ty *'
instead of flag_context_ty.
(extract_whole_file): Update.
* gettext-tools/src/x-csharp.c (extract_parenthesized): Use 'flag_region_ty *'
instead of flag_context_ty.
(extract_csharp): Update.
* gettext-tools/src/x-desktop.c (extract_desktop_handle_pair): Update.
* gettext-tools/src/x-elisp.c (read_object): Use 'flag_region_ty *' instead of
flag_context_ty.
(extract_elisp): Update.
* gettext-tools/src/x-java.c (extract_parenthesized): Use 'flag_region_ty *'
instead of flag_context_ty.
(extract_java): Update.
* gettext-tools/src/x-javascript.c (extract_balanced): Use 'flag_region_ty *'
instead of flag_context_ty.
(extract_javascript): Update.
* gettext-tools/src/x-librep.c (read_object): Use 'flag_region_ty *' instead of
flag_context_ty.
(extract_librep): Update.
* gettext-tools/src/x-lisp.c (read_object): Use 'flag_region_ty *' instead of
flag_context_ty.
(extract_lisp): Update.
* gettext-tools/src/x-lua.c (extract_balanced): Use 'flag_region_ty *' instead
of flag_context_ty.
(extract_lua): Update.
* gettext-tools/src/x-perl.c (extract_variable, interpolate_keywords,
extract_balanced): Use 'flag_region_ty *' instead of flag_context_ty.
(extract_perl): Update.
* gettext-tools/src/x-php.c (extract_balanced): Use 'flag_region_ty *' instead
of flag_context_ty.
(extract_php): Update.
* gettext-tools/src/x-python.c (extract_balanced): Use 'flag_region_ty *'
instead of flag_context_ty.
(extract_python): Update.
* gettext-tools/src/x-rst.c (extract_rst, extract_rsj): Update.
* gettext-tools/src/x-scheme.c (read_object): Use 'flag_region_ty *' instead of
flag_context_ty.
(extract_scheme): Update.
* gettext-tools/src/x-sh.c (read_word, read_command, read_command_list): Use
'flag_region_ty *' instead of flag_context_ty.
(extract_sh): Update.
* gettext-tools/src/x-smalltalk.c (extract_smalltalk): Update.
* gettext-tools/src/x-tcl.c (accumulate_word, read_word, read_command,
read_command_list): Use 'flag_region_ty *' instead of flag_context_ty.
(extract_tcl): Update.
* gettext-tools/src/x-vala.c (extract_balanced): Use 'flag_region_ty *' instead
of flag_context_ty.
(extract_vala): Update.
* gettext-tools/src/x-ycp.c (extract_parenthesized): Use 'flag_region_ty *'
instead of flag_context_ty.
(extract_ycp): Update.
* gettext-tools/src/xgettext.c (xgettext_its_extract_callback): Update.

27 files changed:
gettext-tools/src/x-awk.c
gettext-tools/src/x-c.c
gettext-tools/src/x-csharp.c
gettext-tools/src/x-desktop.c
gettext-tools/src/x-elisp.c
gettext-tools/src/x-java.c
gettext-tools/src/x-javascript.c
gettext-tools/src/x-librep.c
gettext-tools/src/x-lisp.c
gettext-tools/src/x-lua.c
gettext-tools/src/x-perl.c
gettext-tools/src/x-php.c
gettext-tools/src/x-python.c
gettext-tools/src/x-rst.c
gettext-tools/src/x-scheme.c
gettext-tools/src/x-sh.c
gettext-tools/src/x-smalltalk.c
gettext-tools/src/x-tcl.c
gettext-tools/src/x-vala.c
gettext-tools/src/x-ycp.c
gettext-tools/src/xg-arglist-context.c
gettext-tools/src/xg-arglist-context.h
gettext-tools/src/xg-arglist-parser.c
gettext-tools/src/xg-arglist-parser.h
gettext-tools/src/xg-message.c
gettext-tools/src/xg-message.h
gettext-tools/src/xgettext.c

index ef21967f69111a9ac7b6654c14195d62684ae167..52165bfc577a1b0db3ff66797d9f8e210d2f1f98 100644 (file)
@@ -692,7 +692,7 @@ static int nesting_depth;
    Return true upon eof, false upon closing parenthesis.  */
 static bool
 extract_parenthesized (message_list_ty *mlp,
-                       flag_context_ty outer_context,
+                       flag_region_ty *outer_region,
                        flag_context_list_iterator_ty context_iter,
                        struct arglist_parser *argparser)
 {
@@ -708,9 +708,9 @@ extract_parenthesized (message_list_ty *mlp,
   /* Context iterator that will be used if the next token is a '('.  */
   flag_context_list_iterator_ty next_context_iter =
     passthrough_context_list_iterator;
-  /* Current context.  */
-  flag_context_ty inner_context =
-    inherited_context (outer_context,
+  /* Current region.  */
+  flag_region_ty *inner_region =
+    inheriting_region (outer_region,
                        flag_context_list_iterator_advance (&context_iter));
 
   /* Start state is 0.  */
@@ -726,9 +726,9 @@ extract_parenthesized (message_list_ty *mlp,
         {
           /* An argument list starts, even though there is no '('.  */
           context_iter = next_context_iter;
-          outer_context = inner_context;
-          inner_context =
-            inherited_context (outer_context,
+          assign_region (outer_region, inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
         }
@@ -765,11 +765,12 @@ extract_parenthesized (message_list_ty *mlp,
             if_error (IF_SEVERITY_FATAL_ERROR,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open parentheses"));
-          if (extract_parenthesized (mlp, inner_context, next_context_iter,
+          if (extract_parenthesized (mlp, inner_region, next_context_iter,
                                      arglist_parser_alloc (mlp,
                                                            state ? next_shapes : NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           nesting_depth--;
@@ -780,12 +781,14 @@ extract_parenthesized (message_list_ty *mlp,
 
         case token_type_rparen:
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return false;
 
         case token_type_comma:
           arg++;
-          inner_context =
-            inherited_context (outer_context,
+          unref_region (inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
           next_is_argument = false;
@@ -801,7 +804,7 @@ extract_parenthesized (message_list_ty *mlp,
 
             if (extract_all)
               remember_a_message (mlp, NULL, token.string, false, false,
-                                  inner_context, &pos,
+                                  inner_region, &pos,
                                   NULL, savable_comment, false);
             else
               {
@@ -810,7 +813,7 @@ extract_parenthesized (message_list_ty *mlp,
                                              pos.file_name, pos.line_number);
                 free (token.string);
                 arglist_parser_remember (argparser, arg, ms,
-                                         inner_context,
+                                         inner_region,
                                          pos.file_name, pos.line_number,
                                          savable_comment, false);
               }
@@ -827,7 +830,7 @@ extract_parenthesized (message_list_ty *mlp,
             pos.line_number = token.line_number;
 
             remember_a_message (mlp, NULL, token.string, false, false,
-                                inner_context, &pos,
+                                inner_region, &pos,
                                 NULL, savable_comment, false);
           }
           next_is_argument = false;
@@ -839,15 +842,16 @@ extract_parenthesized (message_list_ty *mlp,
           /* An argument list ends, and a new statement begins.  */
           /* FIXME: Should handle newline that acts as statement separator
              in the same way.  */
-          /* FIXME: Instead of resetting outer_context here, it may be better
+          /* FIXME: Instead of resetting outer_region here, it may be better
              to recurse in the next_is_argument handling above, waiting for
              the next semicolon or other statement terminator.  */
-          outer_context = null_context;
+          outer_region = null_context_region ();
           context_iter = null_context_list_iterator;
           next_is_argument = false;
           next_context_iter = passthrough_context_list_iterator;
-          inner_context =
-            inherited_context (outer_context,
+          unref_region (inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
           state = 0;
@@ -855,6 +859,7 @@ extract_parenthesized (message_list_ty *mlp,
 
         case token_type_eof:
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return true;
 
         case token_type_other:
@@ -895,7 +900,7 @@ extract_awk (FILE *f,
 
   /* Eat tokens until eof is seen.  When extract_parenthesized returns
      due to an unbalanced closing parenthesis, just restart it.  */
-  while (!extract_parenthesized (mlp, null_context, null_context_list_iterator,
+  while (!extract_parenthesized (mlp, null_context_region (), null_context_list_iterator,
                                  arglist_parser_alloc (mlp, NULL)))
     ;
 
index 1698e3df3fcb95246a5c7867b7dd19ba729277fe..13aaf81d1d00a0d788bdc35397efcac1179d74e8 100644 (file)
@@ -2269,7 +2269,7 @@ static int nesting_depth;
    Return true upon eof, false upon closing parenthesis.  */
 static bool
 extract_parenthesized (message_list_ty *mlp,
-                       flag_context_ty outer_context,
+                       flag_region_ty *outer_region,
                        flag_context_list_iterator_ty context_iter,
                        struct arglist_parser *argparser)
 {
@@ -2286,9 +2286,9 @@ extract_parenthesized (message_list_ty *mlp,
      (Objective C selector syntax.)  */
   flag_context_list_iterator_ty selectorcall_context_iter =
     passthrough_context_list_iterator;
-  /* Current context.  */
-  flag_context_ty inner_context =
-    inherited_context (outer_context,
+  /* Current region.  */
+  flag_region_ty *inner_region =
+    inheriting_region (outer_region,
                        flag_context_list_iterator_advance (&context_iter));
 
   /* Start state is 0.  */
@@ -2334,11 +2334,12 @@ extract_parenthesized (message_list_ty *mlp,
             if_error (IF_SEVERITY_FATAL_ERROR,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open parentheses"));
-          if (extract_parenthesized (mlp, inner_context, next_context_iter,
+          if (extract_parenthesized (mlp, inner_region, next_context_iter,
                                      arglist_parser_alloc (mlp,
                                                            state ? next_shapes : NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           nesting_depth--;
@@ -2349,12 +2350,14 @@ extract_parenthesized (message_list_ty *mlp,
 
         case xgettext_token_type_rparen:
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return false;
 
         case xgettext_token_type_comma:
           arg++;
-          inner_context =
-            inherited_context (outer_context,
+          unref_region (inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
           next_context_iter = passthrough_context_list_iterator;
@@ -2366,10 +2369,10 @@ extract_parenthesized (message_list_ty *mlp,
           if (objc_extensions)
             {
               context_iter = selectorcall_context_iter;
-              inner_context =
-                inherited_context (inner_context,
+              assign_new_region (inner_region,
+                inheriting_region (inner_region,
                                    flag_context_list_iterator_advance (
-                                     &context_iter));
+                                     &context_iter)));
               next_context_iter = passthrough_context_list_iterator;
               selectorcall_context_iter = passthrough_context_list_iterator;
             }
@@ -2388,12 +2391,12 @@ extract_parenthesized (message_list_ty *mlp,
                 char *string = mixed_string_contents (token.mixed_string);
                 mixed_string_free (token.mixed_string);
                 remember_a_message (mlp, NULL, string, true, false,
-                                    inner_context, &token.pos,
+                                    inner_region, &token.pos,
                                     NULL, token.comment, false);
               }
             else
               arglist_parser_remember (argparser, arg, token.mixed_string,
-                                       inner_context,
+                                       inner_region,
                                        token.pos.file_name,
                                        token.pos.line_number,
                                        token.comment, false);
@@ -2412,6 +2415,7 @@ extract_parenthesized (message_list_ty *mlp,
 
         case xgettext_token_type_eof:
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return true;
 
         default:
@@ -2452,7 +2456,7 @@ extract_whole_file (FILE *f,
 
   /* Eat tokens until eof is seen.  When extract_parenthesized returns
      due to an unbalanced closing parenthesis, just restart it.  */
-  while (!extract_parenthesized (mlp, null_context, null_context_list_iterator,
+  while (!extract_parenthesized (mlp, null_context_region (), null_context_list_iterator,
                                  arglist_parser_alloc (mlp, NULL)))
     ;
 
index 9dd385ca6db29e1e8923ccf66e937fa2773cefb1..47e53120ab0768077fc93b7222d13ce873fafd0c 100644 (file)
@@ -1825,7 +1825,7 @@ static int brace_nesting_depth;
    Return true upon eof, false upon closing parenthesis or brace.  */
 static bool
 extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
-                       flag_context_ty outer_context,
+                       flag_region_ty *outer_region,
                        flag_context_list_iterator_ty context_iter,
                        struct arglist_parser *argparser)
 {
@@ -1838,9 +1838,9 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
   /* Context iterator that will be used if the next token is a '('.  */
   flag_context_list_iterator_ty next_context_iter =
     passthrough_context_list_iterator;
-  /* Current context.  */
-  flag_context_ty inner_context =
-    inherited_context (outer_context,
+  /* Current region.  */
+  flag_region_ty *inner_region =
+    inheriting_region (outer_region,
                        flag_context_list_iterator_advance (&context_iter));
 
   /* Start state is 0.  */
@@ -1944,11 +1944,12 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open parentheses"));
           if (extract_parenthesized (mlp, token_type_rparen,
-                                     inner_context, next_context_iter,
+                                     inner_region, next_context_iter,
                                      arglist_parser_alloc (mlp,
                                                            state ? next_shapes : NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           paren_nesting_depth--;
@@ -1960,6 +1961,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
           if (terminator == token_type_rparen)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           if (terminator == token_type_rbrace)
@@ -1976,10 +1978,12 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open braces"));
           if (extract_parenthesized (mlp, token_type_rbrace,
-                                     null_context, null_context_list_iterator,
+                                     null_context_region (),
+                                     null_context_list_iterator,
                                      arglist_parser_alloc (mlp, NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           brace_nesting_depth--;
@@ -1991,6 +1995,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
           if (terminator == token_type_rbrace)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           if (terminator == token_type_rparen)
@@ -2003,8 +2008,9 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
 
         case token_type_comma:
           arg++;
-          inner_context =
-            inherited_context (outer_context,
+          unref_region (inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
           next_context_iter = passthrough_context_list_iterator;
@@ -2023,12 +2029,12 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                 char *string = mixed_string_contents (token.mixed_string);
                 mixed_string_free (token.mixed_string);
                 remember_a_message (mlp, NULL, string, true, false,
-                                    inner_context, &pos,
+                                    inner_region, &pos,
                                     NULL, token.comment, true);
               }
             else
               arglist_parser_remember (argparser, arg, token.mixed_string,
-                                       inner_context,
+                                       inner_region,
                                        pos.file_name, pos.line_number,
                                        token.comment, true);
           }
@@ -2039,6 +2045,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
 
         case token_type_eof:
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return true;
 
         case token_type_dot:
@@ -2095,7 +2102,8 @@ extract_csharp (FILE *f,
   /* Eat tokens until eof is seen.  When extract_parenthesized returns
      due to an unbalanced closing parenthesis, just restart it.  */
   while (!extract_parenthesized (mlp, token_type_eof,
-                                 null_context, null_context_list_iterator,
+                                 null_context_region (),
+                                 null_context_list_iterator,
                                  arglist_parser_alloc (mlp, NULL)))
     ;
 
index dc989d159859d37c9da7170cb11dbe320a32f2ae..761c83cadd4ab8c3316b8eb78f1e3d06b148f7b0 100644 (file)
@@ -126,7 +126,7 @@ extract_desktop_handle_pair (struct desktop_reader_ty *reader,
 
       remember_a_message (extract_reader->mlp, NULL,
                           desktop_unescape_string (value, is_list), false,
-                          false, null_context, key_pos,
+                          false, null_context_region (), key_pos,
                           NULL, savable_comment, false);
     }
   savable_comment_reset ();
index a98c26ed7ad4889c9dd71b915526858a466bb07a..edf697a646ea29c7743b32c96b47f4aa89fb768c 100644 (file)
@@ -639,7 +639,7 @@ do_getc_escaped (int c, bool in_string)
    backquote syntax and new backquote syntax.  */
 static void
 read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
-             flag_context_ty outer_context)
+             flag_region_ty *outer_region)
 {
   if (nesting_depth > MAX_NESTING_DEPTH)
     if_error (IF_SEVERITY_FATAL_ERROR,
@@ -675,19 +675,19 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
             for (;; arg++)
               {
                 struct object inner;
-                flag_context_ty inner_context;
+                flag_region_ty *inner_region;
 
                 if (arg == 0)
-                  inner_context = null_context;
+                  inner_region = null_context_region ();
                 else
-                  inner_context =
-                    inherited_context (outer_context,
+                  inner_region =
+                    inheriting_region (outer_region,
                                        flag_context_list_iterator_advance (
                                          &context_iter));
 
                 ++nesting_depth;
                 read_object (&inner, arg == 0, new_backquote_flag,
-                             inner_context);
+                             inner_region);
                 nesting_depth--;
 
                 /* Recognize end of list.  */
@@ -698,6 +698,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                     last_non_comment_line = line_number;
                     if (argparser != NULL)
                       arglist_parser_done (argparser, arg);
+                    unref_region (inner_region);
                     return;
                   }
 
@@ -747,13 +748,14 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                                                      inner.line_number_at_start);
                         free (s);
                         arglist_parser_remember (argparser, arg, ms,
-                                                 inner_context,
+                                                 inner_region,
                                                  logical_file_name,
                                                  inner.line_number_at_start,
                                                  savable_comment, false);
                       }
                   }
 
+                unref_region (inner_region);
                 free_object (&inner);
               }
 
@@ -778,7 +780,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                 struct object inner;
 
                 ++nesting_depth;
-                read_object (&inner, false, new_backquote_flag, null_context);
+                read_object (&inner, false, new_backquote_flag,
+                             null_context_region ());
                 nesting_depth--;
 
                 /* Recognize end of vector.  */
@@ -814,7 +817,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
             struct object inner;
 
             ++nesting_depth;
-            read_object (&inner, false, new_backquote_flag, null_context);
+            read_object (&inner, false, new_backquote_flag,
+                         null_context_region ());
             nesting_depth--;
 
             /* Dots and EOF are not allowed here.  But be tolerant.  */
@@ -833,7 +837,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
             struct object inner;
 
             ++nesting_depth;
-            read_object (&inner, false, true, null_context);
+            read_object (&inner, false, true, null_context_region ());
             nesting_depth--;
 
             /* Dots and EOF are not allowed here.  But be tolerant.  */
@@ -859,7 +863,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
             struct object inner;
 
             ++nesting_depth;
-            read_object (&inner, false, false, null_context);
+            read_object (&inner, false, false, null_context_region ());
             nesting_depth--;
 
             /* Dots and EOF are not allowed here.  But be tolerant.  */
@@ -942,7 +946,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                 pos.file_name = logical_file_name;
                 pos.line_number = op->line_number_at_start;
                 remember_a_message (mlp, NULL, string_of_object (op), false,
-                                    false, null_context, &pos,
+                                    false, null_context_region (), &pos,
                                     NULL, savable_comment, false);
               }
             last_non_comment_line = line_number;
@@ -1002,7 +1006,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
 
                           ++nesting_depth;
                           read_object (&inner, false, new_backquote_flag,
-                                       null_context);
+                                       null_context_region ());
                           nesting_depth--;
 
                           /* Recognize end of vector.  */
@@ -1041,7 +1045,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                   struct object length;
                   ++nesting_depth;
                   read_object (&length, first_in_list, new_backquote_flag,
-                               null_context);
+                               null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
                      But be tolerant.  */
@@ -1054,7 +1058,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                       struct object string;
                       ++nesting_depth;
                       read_object (&string, first_in_list, new_backquote_flag,
-                                   null_context);
+                                   null_context_region ());
                       nesting_depth--;
                       free_object (&string);
                     }
@@ -1074,7 +1078,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                   struct object inner;
                   do_ungetc (dmc);
                   ++nesting_depth;
-                  read_object (&inner, false, new_backquote_flag, null_context);
+                  read_object (&inner, false, new_backquote_flag,
+                               null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
                      But be tolerant.  */
@@ -1118,7 +1123,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                 {
                   struct object inner;
                   ++nesting_depth;
-                  read_object (&inner, false, new_backquote_flag, null_context);
+                  read_object (&inner, false, new_backquote_flag,
+                               null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
                      But be tolerant.  */
@@ -1149,7 +1155,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                   if (c == '=')
                     {
                       ++nesting_depth;
-                      read_object (op, false, new_backquote_flag, outer_context);
+                      read_object (op, false, new_backquote_flag, outer_region);
                       nesting_depth--;
                       last_non_comment_line = line_number;
                       return;
@@ -1224,7 +1230,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                 {
                   struct object inner;
                   ++nesting_depth;
-                  read_object (&inner, false, new_backquote_flag, null_context);
+                  read_object (&inner, false, new_backquote_flag,
+                               null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
                      But be tolerant.  */
@@ -1316,7 +1323,7 @@ extract_elisp (FILE *f,
     {
       struct object toplevel_object;
 
-      read_object (&toplevel_object, false, false, null_context);
+      read_object (&toplevel_object, false, false, null_context_region ());
 
       if (toplevel_object.type == t_eof)
         break;
index 84af9754039a6f15c5e85f0a7457c6850d57ef78..37a9f54ddd6a4affe96f2bdbc33dade7d5349a6d 100644 (file)
@@ -1458,7 +1458,7 @@ static int brace_nesting_depth;
    Return true upon eof, false upon closing parenthesis or brace.  */
 static bool
 extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
-                       flag_context_ty outer_context,
+                       flag_region_ty *outer_region,
                        flag_context_list_iterator_ty context_iter,
                        struct arglist_parser *argparser)
 {
@@ -1471,9 +1471,9 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
   /* Context iterator that will be used if the next token is a '('.  */
   flag_context_list_iterator_ty next_context_iter =
     passthrough_context_list_iterator;
-  /* Current context.  */
-  flag_context_ty inner_context =
-    inherited_context (outer_context,
+  /* Current region.  */
+  flag_region_ty *inner_region =
+    inheriting_region (outer_region,
                        flag_context_list_iterator_advance (&context_iter));
 
   /* Start state is 0.  */
@@ -1577,11 +1577,12 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open parentheses"));
           if (extract_parenthesized (mlp, token_type_rparen,
-                                     inner_context, next_context_iter,
+                                     inner_region, next_context_iter,
                                      arglist_parser_alloc (mlp,
                                                            state ? next_shapes : NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           paren_nesting_depth--;
@@ -1593,6 +1594,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
           if (terminator == token_type_rparen)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           if (terminator == token_type_rbrace)
@@ -1609,10 +1611,12 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open braces"));
           if (extract_parenthesized (mlp, token_type_rbrace,
-                                     null_context, null_context_list_iterator,
+                                     null_context_region (),
+                                     null_context_list_iterator,
                                      arglist_parser_alloc (mlp, NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           brace_nesting_depth--;
@@ -1624,6 +1628,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
           if (terminator == token_type_rbrace)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           if (terminator == token_type_rparen)
@@ -1636,8 +1641,9 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
 
         case token_type_comma:
           arg++;
-          inner_context =
-            inherited_context (outer_context,
+          unref_region (inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
           next_context_iter = passthrough_context_list_iterator;
@@ -1656,12 +1662,12 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                 char *string = mixed_string_contents (token.mixed_string);
                 mixed_string_free (token.mixed_string);
                 remember_a_message (mlp, NULL, string, true, false,
-                                    inner_context, &pos,
+                                    inner_region, &pos,
                                     NULL, token.comment, true);
               }
             else
               arglist_parser_remember (argparser, arg, token.mixed_string,
-                                       inner_context,
+                                       inner_region,
                                        pos.file_name, pos.line_number,
                                        token.comment, true);
           }
@@ -1672,6 +1678,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
 
         case token_type_eof:
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return true;
 
         case token_type_dot:
@@ -1722,7 +1729,8 @@ extract_java (FILE *f,
   /* Eat tokens until eof is seen.  When extract_parenthesized returns
      due to an unbalanced closing parenthesis, just restart it.  */
   while (!extract_parenthesized (mlp, token_type_eof,
-                                 null_context, null_context_list_iterator,
+                                 null_context_region (),
+                                 null_context_list_iterator,
                                  arglist_parser_alloc (mlp, NULL)))
     ;
 
index 8c6883fc2c4145533e7bcf77edb09d973310986e..c3ca0a82d10a901fc70afa1d13f4cd4a767f20b0 100644 (file)
@@ -1622,7 +1622,7 @@ static int xml_element_nesting_depth;
 static bool
 extract_balanced (message_list_ty *mlp,
                   token_type_ty delim,
-                  flag_context_ty outer_context,
+                  flag_region_ty *outer_region,
                   flag_context_list_iterator_ty context_iter,
                   struct arglist_parser *argparser)
 {
@@ -1635,9 +1635,9 @@ extract_balanced (message_list_ty *mlp,
   /* Context iterator that will be used if the next token is a '('.  */
   flag_context_list_iterator_ty next_context_iter =
     passthrough_context_list_iterator;
-  /* Current context.  */
-  flag_context_ty inner_context =
-    inherited_context (outer_context,
+  /* Current region.  */
+  flag_region_ty *inner_region =
+    inheriting_region (outer_region,
                        flag_context_list_iterator_advance (&context_iter));
 
   /* Start state is 0.  */
@@ -1678,11 +1678,12 @@ extract_balanced (message_list_ty *mlp,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open parentheses"));
           if (extract_balanced (mlp, token_type_rparen,
-                                inner_context, next_context_iter,
+                                inner_region, next_context_iter,
                                 arglist_parser_alloc (mlp,
                                                       state ? next_shapes : NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           paren_nesting_depth--;
@@ -1694,6 +1695,7 @@ extract_balanced (message_list_ty *mlp,
           if (delim == token_type_rparen || delim == token_type_eof)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           next_context_iter = null_context_list_iterator;
@@ -1702,8 +1704,9 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_comma:
           arg++;
-          inner_context =
-            inherited_context (outer_context,
+          unref_region (inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
           next_context_iter = passthrough_context_list_iterator;
@@ -1716,10 +1719,12 @@ extract_balanced (message_list_ty *mlp,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open brackets"));
           if (extract_balanced (mlp, token_type_rbracket,
-                                null_context, null_context_list_iterator,
+                                null_context_region (),
+                                null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           bracket_nesting_depth--;
@@ -1731,6 +1736,7 @@ extract_balanced (message_list_ty *mlp,
           if (delim == token_type_rbracket || delim == token_type_eof)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           next_context_iter = null_context_list_iterator;
@@ -1743,10 +1749,12 @@ extract_balanced (message_list_ty *mlp,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open braces"));
           if (extract_balanced (mlp, token_type_rbrace,
-                                null_context, null_context_list_iterator,
+                                null_context_region (),
+                                null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           brace_nesting_depth--;
@@ -1758,6 +1766,7 @@ extract_balanced (message_list_ty *mlp,
           if (delim == token_type_rbrace || delim == token_type_eof)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           next_context_iter = null_context_list_iterator;
@@ -1777,12 +1786,12 @@ extract_balanced (message_list_ty *mlp,
                 char *string = mixed_string_contents (token.mixed_string);
                 mixed_string_free (token.mixed_string);
                 remember_a_message (mlp, NULL, string, true, false,
-                                    inner_context, &pos,
+                                    inner_region, &pos,
                                     NULL, token.comment, true);
               }
             else
               arglist_parser_remember (argparser, arg, token.mixed_string,
-                                       inner_context,
+                                       inner_region,
                                        pos.file_name, pos.line_number,
                                        token.comment, true);
           }
@@ -1797,10 +1806,12 @@ extract_balanced (message_list_ty *mlp,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open XML elements"));
           if (extract_balanced (mlp, token_type_xml_element_end,
-                                null_context, null_context_list_iterator,
+                                null_context_region (),
+                                null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           xml_element_nesting_depth--;
@@ -1812,6 +1823,7 @@ extract_balanced (message_list_ty *mlp,
           if (delim == token_type_xml_element_end || delim == token_type_eof)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           next_context_iter = null_context_list_iterator;
@@ -1820,6 +1832,7 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_eof:
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return true;
 
         case token_type_ltemplate:
@@ -1901,7 +1914,7 @@ extract_javascript (FILE *f,
   /* Eat tokens until eof is seen.  When extract_balanced returns
      due to an unbalanced closing parenthesis, just restart it.  */
   while (!extract_balanced (mlp, token_type_eof,
-                            null_context, null_context_list_iterator,
+                            null_context_region (), null_context_list_iterator,
                             arglist_parser_alloc (mlp, NULL)))
     ;
 
index a333b109ff5fa799ba46ec0f2063f895828547a0..af7a44c0cd38d1d349c7ce7bca91ccce0362218c 100644 (file)
@@ -598,7 +598,7 @@ do_getc_escaped (int c)
 
 /* Read the next object.  */
 static void
-read_object (struct object *op, flag_context_ty outer_context)
+read_object (struct object *op, flag_region_ty *outer_region)
 {
   if (nesting_depth > MAX_NESTING_DEPTH)
     if_error (IF_SEVERITY_FATAL_ERROR,
@@ -637,18 +637,18 @@ read_object (struct object *op, flag_context_ty outer_context)
             for (;; arg++)
               {
                 struct object inner;
-                flag_context_ty inner_context;
+                flag_region_ty *inner_region;
 
                 if (arg == 0)
-                  inner_context = null_context;
+                  inner_region = null_context_region ();
                 else
-                  inner_context =
-                    inherited_context (outer_context,
+                  inner_region =
+                    inheriting_region (outer_region,
                                        flag_context_list_iterator_advance (
                                          &context_iter));
 
                 ++nesting_depth;
-                read_object (&inner, inner_context);
+                read_object (&inner, inner_region);
                 nesting_depth--;
 
                 /* Recognize end of list.  */
@@ -659,6 +659,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                     last_non_comment_line = line_number;
                     if (argparser != NULL)
                       arglist_parser_done (argparser, arg);
+                    unref_region (inner_region);
                     return;
                   }
 
@@ -708,13 +709,14 @@ read_object (struct object *op, flag_context_ty outer_context)
                                                      inner.line_number_at_start);
                         free (s);
                         arglist_parser_remember (argparser, arg, ms,
-                                                 inner_context,
+                                                 inner_region,
                                                  logical_file_name,
                                                  inner.line_number_at_start,
                                                  savable_comment, false);
                       }
                   }
 
+                unref_region (inner_region);
                 free_object (&inner);
               }
 
@@ -732,7 +734,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                 struct object inner;
 
                 ++nesting_depth;
-                read_object (&inner, null_context);
+                read_object (&inner, null_context_region ());
                 nesting_depth--;
 
                 /* Recognize end of vector.  */
@@ -778,7 +780,7 @@ read_object (struct object *op, flag_context_ty outer_context)
             struct object inner;
 
             ++nesting_depth;
-            read_object (&inner, null_context);
+            read_object (&inner, null_context_region ());
             nesting_depth--;
 
             /* Dots and EOF are not allowed here.  But be tolerant.  */
@@ -861,7 +863,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                 pos.file_name = logical_file_name;
                 pos.line_number = op->line_number_at_start;
                 remember_a_message (mlp, NULL, string_of_object (op), false,
-                                    false, null_context, &pos,
+                                    false, null_context_region (), &pos,
                                     NULL, savable_comment, false);
               }
             last_non_comment_line = line_number;
@@ -940,7 +942,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                 {
                   struct object inner;
                   ++nesting_depth;
-                  read_object (&inner, null_context);
+                  read_object (&inner, null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
                      But be tolerant.  */
@@ -956,7 +958,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                   struct object inner;
                   do_ungetc (dmc);
                   ++nesting_depth;
-                  read_object (&inner, null_context);
+                  read_object (&inner, null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
                      But be tolerant.  */
@@ -1161,7 +1163,7 @@ extract_librep (FILE *f,
     {
       struct object toplevel_object;
 
-      read_object (&toplevel_object, null_context);
+      read_object (&toplevel_object, null_context_region ());
 
       if (toplevel_object.type == t_eof)
         break;
index f184f6127914b3e0c2e23cfcdffaa6efe4160ed8..420bd4c5061e28820db053960f400f9986ce275b 100644 (file)
@@ -941,7 +941,7 @@ static int nesting_depth;
 
 /* Read the next object.  */
 static void
-read_object (struct object *op, flag_context_ty outer_context)
+read_object (struct object *op, flag_region_ty *outer_region)
 {
   if (nesting_depth > MAX_NESTING_DEPTH)
     if_error (IF_SEVERITY_FATAL_ERROR,
@@ -1029,18 +1029,18 @@ read_object (struct object *op, flag_context_ty outer_context)
                 for (;; arg++)
                   {
                     struct object inner;
-                    flag_context_ty inner_context;
+                    flag_region_ty *inner_region;
 
                     if (arg == 0)
-                      inner_context = null_context;
+                      inner_region = null_context_region ();
                     else
-                      inner_context =
-                        inherited_context (outer_context,
+                      inner_region =
+                        inheriting_region (outer_region,
                                            flag_context_list_iterator_advance (
                                              &context_iter));
 
                     ++nesting_depth;
-                    read_object (&inner, inner_context);
+                    read_object (&inner, inner_region);
                     nesting_depth--;
 
                     /* Recognize end of list.  */
@@ -1051,6 +1051,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                         last_non_comment_line = line_number;
                         if (argparser != NULL)
                           arglist_parser_done (argparser, arg);
+                        unref_region (inner_region);
                         return;
                       }
 
@@ -1111,13 +1112,14 @@ read_object (struct object *op, flag_context_ty outer_context)
                                                          inner.line_number_at_start);
                             free (s);
                             arglist_parser_remember (argparser, arg, ms,
-                                                     inner_context,
+                                                     inner_region,
                                                      logical_file_name,
                                                      inner.line_number_at_start,
                                                      savable_comment, false);
                           }
                       }
 
+                    unref_region (inner_region);
                     free_object (&inner);
                   }
 
@@ -1151,7 +1153,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                 struct object inner;
 
                 ++nesting_depth;
-                read_object (&inner, null_context);
+                read_object (&inner, null_context_region ());
                 nesting_depth--;
 
                 /* Dots and EOF are not allowed here.  But be tolerant.  */
@@ -1219,7 +1221,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                     pos.file_name = logical_file_name;
                     pos.line_number = op->line_number_at_start;
                     remember_a_message (mlp, NULL, string_of_object (op), false,
-                                        false, null_context, &pos,
+                                        false, null_context_region (), &pos,
                                         NULL, savable_comment, false);
                   }
                 last_non_comment_line = line_number;
@@ -1261,7 +1263,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                     {
                       struct object inner;
                       ++nesting_depth;
-                      read_object (&inner, null_context);
+                      read_object (&inner, null_context_region ());
                       nesting_depth--;
                       /* Dots and EOF are not allowed here.
                          But be tolerant.  */
@@ -1381,7 +1383,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                     {
                       struct object inner;
                       ++nesting_depth;
-                      read_object (&inner, null_context);
+                      read_object (&inner, null_context_region ());
                       nesting_depth--;
                       /* Dots and EOF are not allowed here.
                          But be tolerant.  */
@@ -1438,7 +1440,7 @@ extract_lisp (FILE *f,
     {
       struct object toplevel_object;
 
-      read_object (&toplevel_object, null_context);
+      read_object (&toplevel_object, null_context_region ());
 
       if (toplevel_object.type == t_eof)
         break;
index 17acde94b81ca3645ad9328432153bd9d79bc555..cff6c7016b70dc94a922a9a63caba5f4474b2a37 100644 (file)
@@ -1041,7 +1041,7 @@ static int bracket_nesting_depth;
    Return true upon eof, false upon closing parenthesis or bracket.  */
 static bool
 extract_balanced (message_list_ty *mlp, token_type_ty delim,
-                  flag_context_ty outer_context,
+                  flag_region_ty *outer_region,
                   flag_context_list_iterator_ty context_iter,
                   struct arglist_parser *argparser)
 {
@@ -1054,9 +1054,9 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
   /* Context iterator that will be used if the next token is a '('.  */
   flag_context_list_iterator_ty next_context_iter =
     passthrough_context_list_iterator;
-  /* Current context.  */
-  flag_context_ty inner_context =
-    inherited_context (outer_context,
+  /* Current region.  */
+  flag_region_ty *inner_region =
+    inheriting_region (outer_region,
                        flag_context_list_iterator_advance (&context_iter));
 
   /* Start state is 0.  */
@@ -1098,11 +1098,12 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open parentheses"));
           if (extract_balanced (mlp, token_type_rparen,
-                                inner_context, next_context_iter,
+                                inner_region, next_context_iter,
                                 arglist_parser_alloc (mlp,
                                                       state ? next_shapes : NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           paren_nesting_depth--;
@@ -1114,6 +1115,7 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
           if (delim == token_type_rparen || delim == token_type_eof)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
 
@@ -1127,10 +1129,12 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open brackets"));
           if (extract_balanced (mlp, token_type_rbracket,
-                                null_context, null_context_list_iterator,
+                                null_context_region (),
+                                null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           bracket_nesting_depth--;
@@ -1142,6 +1146,7 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
           if (delim == token_type_rbracket || delim == token_type_eof)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
 
@@ -1151,8 +1156,9 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
 
         case token_type_comma:
           arg++;
-          inner_context =
-            inherited_context (outer_context,
+          unref_region (inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
           next_context_iter = passthrough_context_list_iterator;
@@ -1161,6 +1167,7 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
 
         case token_type_eof:
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return true;
 
         case token_type_string:
@@ -1171,7 +1178,7 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
 
             if (extract_all)
               remember_a_message (mlp, NULL, token.string, false, false,
-                                  inner_context, &pos,
+                                  inner_region, &pos,
                                   NULL, token.comment, false);
             else
               {
@@ -1186,14 +1193,14 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
                     tmp_argparser = arglist_parser_alloc (mlp, next_shapes);
 
                     arglist_parser_remember (tmp_argparser, 1, ms,
-                                             inner_context,
+                                             inner_region,
                                              pos.file_name, pos.line_number,
                                              token.comment, false);
                     arglist_parser_done (tmp_argparser, 1);
                   }
                 else
                   arglist_parser_remember (argparser, arg, ms,
-                                           inner_context,
+                                           inner_region,
                                            pos.file_name, pos.line_number,
                                            token.comment, false);
               }
@@ -1252,7 +1259,7 @@ extract_lua (FILE *f,
   /* Eat tokens until eof is seen.  When extract_parenthesized returns
      due to an unbalanced closing parenthesis, just restart it.  */
   while (!extract_balanced (mlp, token_type_eof,
-                            null_context, null_context_list_iterator,
+                            null_context_region (), null_context_list_iterator,
                             arglist_parser_alloc (mlp, NULL)))
     ;
 
index 182d5674a9a14c14f30aa2fcfbb31040dc44da5d..194bf5ae9dcb07dbc94d84bf8c4004fb2840883f 100644 (file)
@@ -809,7 +809,7 @@ static bool extract_balanced (message_list_ty *mlp,
                               token_type_ty delim, bool eat_delim,
                               bool semicolon_delim, bool eat_semicolon_delim,
                               bool comma_delim,
-                              flag_context_ty outer_context,
+                              flag_region_ty *outer_region,
                               flag_context_list_iterator_ty context_iter,
                               int arg, struct arglist_parser *argparser);
 
@@ -1416,7 +1416,7 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first)
         if (extract_balanced (mlp,
                               token_type_rbrace, true,
                               false, false, false,
-                              null_context, null_context_list_iterator,
+                              null_context_region (), null_context_list_iterator,
                               1, arglist_parser_alloc (mlp, NULL)))
           {
             tp->type = token_type_eof;
@@ -1590,11 +1590,11 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first)
                     token_ty *t2 = x_perl_lex (mlp);
                     if (t2->type == token_type_rbrace)
                       {
-                        flag_context_ty context;
+                        flag_region_ty *region;
                         lex_pos_ty pos;
 
-                        context =
-                          inherited_context (null_context,
+                        region =
+                          inheriting_region (null_context_region (),
                                              flag_context_list_iterator_advance (
                                                &context_iter));
 
@@ -1602,7 +1602,7 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first)
                         pos.file_name = logical_file_name;
 
                         remember_a_message (mlp, NULL, xstrdup (t1->string),
-                                            true, false, context, &pos,
+                                            true, false, region, &pos,
                                             NULL, savable_comment, true);
                         free_token (t2);
                         free_token (t1);
@@ -1618,7 +1618,7 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first)
                     if (extract_balanced (mlp,
                                           token_type_rbrace, true,
                                           false, false, false,
-                                          null_context, context_iter,
+                                          null_context_region (), context_iter,
                                           1, arglist_parser_alloc (mlp, &shapes)))
                       return;
                   }
@@ -1651,7 +1651,7 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first)
           extract_balanced (mlp,
                             token_type_rbrace, true,
                             false, false, false,
-                            null_context, null_context_list_iterator,
+                            null_context_region (), null_context_list_iterator,
                             1, arglist_parser_alloc (mlp, NULL));
           break;
 
@@ -1663,7 +1663,7 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first)
           extract_balanced (mlp,
                             token_type_rbracket, true,
                             false, false, false,
-                            null_context, null_context_list_iterator,
+                            null_context_region (), null_context_list_iterator,
                             1, arglist_parser_alloc (mlp, NULL));
           break;
 
@@ -1707,7 +1707,7 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
   static char *buffer;
   static int bufmax = 0;
   int bufpos = 0;
-  flag_context_ty context;
+  flag_region_ty *region;
   size_t length;
   size_t index;
   char c;
@@ -1751,12 +1751,12 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
    * barekey:      an bareword character has been seen in state WAIT_QUOTE
    * wait_rbrace:  closing quote has been seen in state DQUOTE or SQUOTE
    *
-   * In the states initial...identifier the context is null_context; in the
-   * states minus...wait_rbrace the context is the one suitable for the first
-   * argument of the last seen identifier.
+   * In the states initial...identifier the context is null_context_region ();
+   * in the states minus...wait_rbrace the context is the one suitable for the
+   * first argument of the last seen identifier.
    */
   state = initial;
-  context = null_context;
+  region = null_context_region ();
 
   length = string_desc_length (string);
   index = 0;
@@ -1861,8 +1861,8 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
                       flag_context_list_table_lookup (
                         flag_context_list_table,
                         buffer, bufpos));
-                  context =
-                    inherited_context (null_context,
+                  region =
+                    inheriting_region (null_context_region (),
                                        flag_context_list_iterator_advance (
                                          &context_iter));
                   state = minus;
@@ -1881,8 +1881,8 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
                       flag_context_list_table_lookup (
                         flag_context_list_table,
                         buffer, bufpos));
-                  context =
-                    inherited_context (null_context,
+                  region =
+                    inheriting_region (null_context_region (),
                                        flag_context_list_iterator_advance (
                                          &context_iter));
                   state = wait_quote;
@@ -1911,7 +1911,7 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
               state = wait_lbrace;
               break;
             default:
-              context = null_context;
+              region = null_context_region ();
               state = initial;
               break;
             }
@@ -1923,7 +1923,7 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
               state = wait_quote;
               break;
             default:
-              context = null_context;
+              region = null_context_region ();
               state = initial;
               break;
             }
@@ -1955,7 +1955,7 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
                 }
               else
                 {
-                  context = null_context;
+                  region = null_context_region ();
                   state = initial;
                 }
               break;
@@ -1980,7 +1980,7 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
             case '\\':
               if (index == length)
                 {
-                  context = null_context;
+                  region = null_context_region ();
                   state = initial;
                 }
               else
@@ -2011,7 +2011,7 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
             case '\\':
               if (index == length)
                 {
-                  context = null_context;
+                  region = null_context_region ();
                   state = initial;
                 }
               else
@@ -2048,7 +2048,7 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
             }
           else if (c != '}')
             {
-              context = null_context;
+              region = null_context_region ();
               state = initial;
               break;
             }
@@ -2063,11 +2063,11 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
               buffer[bufpos] = '\0';
               token.string = xstrdup (buffer);
               extract_quotelike_pass3 (&token, IF_SEVERITY_FATAL_ERROR);
-              remember_a_message (mlp, NULL, token.string, true, false, context,
+              remember_a_message (mlp, NULL, token.string, true, false, region,
                                   &pos, NULL, savable_comment, true);
               FALLTHROUGH;
             default:
-              context = null_context;
+              region = null_context_region ();
               state = initial;
               break;
             }
@@ -3098,7 +3098,7 @@ extract_balanced (message_list_ty *mlp,
                   token_type_ty delim, bool eat_delim,
                   bool semicolon_delim, bool eat_semicolon_delim,
                   bool comma_delim,
-                  flag_context_ty outer_context,
+                  flag_region_ty *outer_region,
                   flag_context_list_iterator_ty context_iter,
                   int arg, struct arglist_parser *argparser)
 {
@@ -3121,9 +3121,9 @@ extract_balanced (message_list_ty *mlp,
   /* Context iterator that will be used if the next token is a '('.  */
   flag_context_list_iterator_ty next_context_iter =
     passthrough_context_list_iterator;
-  /* Current context.  */
-  flag_context_ty inner_context =
-    inherited_context (outer_context,
+  /* Current region.  */
+  flag_region_ty *inner_region =
+    inheriting_region (outer_region,
                        flag_context_list_iterator_advance (&context_iter));
 
   #if DEBUG_PERL
@@ -3157,6 +3157,7 @@ extract_balanced (message_list_ty *mlp,
                   || tp->type == token_type_rbracket)))
         {
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           if (next_argparser != NULL)
             free (next_argparser);
           #if DEBUG_PERL
@@ -3174,6 +3175,7 @@ extract_balanced (message_list_ty *mlp,
       if (semicolon_delim && tp->type == token_type_semicolon)
         {
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           if (next_argparser != NULL)
             free (next_argparser);
           #if DEBUG_PERL
@@ -3191,6 +3193,7 @@ extract_balanced (message_list_ty *mlp,
       if (comma_delim && tp->type == token_type_comma)
         {
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           if (next_argparser != NULL)
             free (next_argparser);
           #if DEBUG_PERL
@@ -3243,10 +3246,11 @@ extract_balanced (message_list_ty *mlp,
           if (extract_balanced (mlp,
                                 delim, false,
                                 true, false, next_comma_delim,
-                                inner_context, next_context_iter,
+                                inner_region, next_context_iter,
                                 1, next_argparser))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           #if DEBUG_NESTING_DEPTH
@@ -3340,10 +3344,11 @@ extract_balanced (message_list_ty *mlp,
                   if (extract_balanced (mlp,
                                         token_type_rparen, true,
                                         false, false, false,
-                                        inner_context, next_context_iter,
+                                        inner_region, next_context_iter,
                                         1, next_argparser))
                     {
                       arglist_parser_done (argparser, arg);
+                      unref_region (inner_region);
                       return true;
                     }
                   #if DEBUG_NESTING_DEPTH
@@ -3363,10 +3368,11 @@ extract_balanced (message_list_ty *mlp,
                   if (extract_balanced (mlp,
                                         token_type_rparen, true,
                                         false, false, false,
-                                        inner_context, next_context_iter,
+                                        inner_region, next_context_iter,
                                         arg, arglist_parser_clone (argparser)))
                     {
                       arglist_parser_done (argparser, arg);
+                      unref_region (inner_region);
                       if (next_argparser != NULL)
                         free (next_argparser);
                       free_token (tp);
@@ -3416,8 +3422,9 @@ extract_balanced (message_list_ty *mlp,
               fprintf (stderr, "%s:%d: arg: %d\n",
                        real_file_name, tp->line_number, arg);
               #endif
-              inner_context =
-                inherited_context (outer_context,
+              unref_region (inner_region);
+              inner_region =
+                inheriting_region (outer_region,
                                    flag_context_list_iterator_advance (
                                      &context_iter));
               next_is_argument = false;
@@ -3442,7 +3449,7 @@ extract_balanced (message_list_ty *mlp,
 
                   pos.file_name = logical_file_name;
                   pos.line_number = tp->line_number;
-                  remember_a_message (mlp, NULL, string, true, false, inner_context,
+                  remember_a_message (mlp, NULL, string, true, false, inner_region,
                                       &pos, NULL, tp->comment, true);
                 }
               else if (!skip_until_comma)
@@ -3471,7 +3478,7 @@ extract_balanced (message_list_ty *mlp,
                         mixed_string_alloc_utf8 (string, lc_string,
                                                  logical_file_name, tp->line_number);
                       free (string);
-                      arglist_parser_remember (argparser, arg, ms, inner_context,
+                      arglist_parser_remember (argparser, arg, ms, inner_region,
                                                logical_file_name, tp->line_number,
                                                tp->comment, true);
                     }
@@ -3508,6 +3515,7 @@ extract_balanced (message_list_ty *mlp,
                        logical_file_name, tp->line_number, nesting_level);
               #endif
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               if (next_argparser != NULL)
                 free (next_argparser);
               next_argparser = NULL;
@@ -3526,10 +3534,12 @@ extract_balanced (message_list_ty *mlp,
               if (extract_balanced (mlp,
                                     token_type_rbrace, true,
                                     false, false, false,
-                                    null_context, null_context_list_iterator,
+                                    null_context_region (),
+                                    null_context_list_iterator,
                                     1, arglist_parser_alloc (mlp, NULL)))
                 {
                   arglist_parser_done (argparser, arg);
+                  unref_region (inner_region);
                   if (next_argparser != NULL)
                     free (next_argparser);
                   free_token (tp);
@@ -3548,6 +3558,7 @@ extract_balanced (message_list_ty *mlp,
                   /* Go back to the caller.  We don't want to recurse each time we
                      parsed a    sub name... { ... }    definition.  */
                   arglist_parser_done (argparser, arg);
+                  unref_region (inner_region);
                   free_token (tp);
                   return false;
                 }
@@ -3578,10 +3589,12 @@ extract_balanced (message_list_ty *mlp,
               if (extract_balanced (mlp,
                                     token_type_rbracket, true,
                                     false, false, false,
-                                    null_context, null_context_list_iterator,
+                                    null_context_region (),
+                                    null_context_list_iterator,
                                     1, arglist_parser_alloc (mlp, NULL)))
                 {
                   arglist_parser_done (argparser, arg);
+                  unref_region (inner_region);
                   if (next_argparser != NULL)
                     free (next_argparser);
                   free_token (tp);
@@ -3623,15 +3636,16 @@ extract_balanced (message_list_ty *mlp,
               /* FIXME: Instead of resetting outer_context here, it may be better
                  to recurse in the next_is_argument handling above, waiting for
                  the next semicolon or other statement terminator.  */
-              outer_context = null_context;
+              outer_region = null_context_region ();
               context_iter = null_context_list_iterator;
               next_is_argument = false;
               if (next_argparser != NULL)
                 free (next_argparser);
               next_argparser = NULL;
               next_context_iter = passthrough_context_list_iterator;
-              inner_context =
-                inherited_context (outer_context,
+              unref_region (inner_region);
+              inner_region =
+                inheriting_region (outer_region,
                                    flag_context_list_iterator_advance (
                                      &context_iter));
               break;
@@ -3750,7 +3764,7 @@ extract_perl (FILE *f, const char *real_filename, const char *logical_filename,
   while (!extract_balanced (mlp,
                             token_type_r_any, true,
                             true, true, false,
-                            null_context, null_context_list_iterator,
+                            null_context_region (), null_context_list_iterator,
                             1, arglist_parser_alloc (mlp, NULL)))
     ;
 
index d50617634b8f894bfd4311c7dcfbc15803c45e39..09ba59352a23bd727b21fd48523039a9f1c38b44 100644 (file)
@@ -1430,7 +1430,7 @@ static int bracket_nesting_depth;
 static bool
 extract_balanced (message_list_ty *mlp,
                   token_type_ty delim,
-                  flag_context_ty outer_context,
+                  flag_region_ty *outer_region,
                   flag_context_list_iterator_ty context_iter,
                   struct arglist_parser *argparser)
 {
@@ -1443,9 +1443,9 @@ extract_balanced (message_list_ty *mlp,
   /* Context iterator that will be used if the next token is a '('.  */
   flag_context_list_iterator_ty next_context_iter =
     passthrough_context_list_iterator;
-  /* Current context.  */
-  flag_context_ty inner_context =
-    inherited_context (outer_context,
+  /* Current region.  */
+  flag_region_ty *inner_region =
+    inheriting_region (outer_region,
                        flag_context_list_iterator_advance (&context_iter));
 
   /* Start state is 0.  */
@@ -1486,11 +1486,12 @@ extract_balanced (message_list_ty *mlp,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open parentheses"));
           if (extract_balanced (mlp, token_type_rparen,
-                                inner_context, next_context_iter,
+                                inner_region, next_context_iter,
                                 arglist_parser_alloc (mlp,
                                                       state ? next_shapes : NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           paren_nesting_depth--;
@@ -1502,6 +1503,7 @@ extract_balanced (message_list_ty *mlp,
           if (delim == token_type_rparen || delim == token_type_eof)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           next_context_iter = null_context_list_iterator;
@@ -1510,8 +1512,9 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_comma:
           arg++;
-          inner_context =
-            inherited_context (outer_context,
+          unref_region (inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
           next_context_iter = passthrough_context_list_iterator;
@@ -1524,10 +1527,12 @@ extract_balanced (message_list_ty *mlp,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open brackets"));
           if (extract_balanced (mlp, token_type_rbracket,
-                                null_context, null_context_list_iterator,
+                                null_context_region (),
+                                null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           bracket_nesting_depth--;
@@ -1539,6 +1544,7 @@ extract_balanced (message_list_ty *mlp,
           if (delim == token_type_rbracket || delim == token_type_eof)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           next_context_iter = null_context_list_iterator;
@@ -1553,7 +1559,7 @@ extract_balanced (message_list_ty *mlp,
 
             if (extract_all)
               remember_a_message (mlp, NULL, token.string, false, false,
-                                  inner_context, &pos,
+                                  inner_region, &pos,
                                   NULL, token.comment, false);
             else
               {
@@ -1561,7 +1567,7 @@ extract_balanced (message_list_ty *mlp,
                   mixed_string_alloc_simple (token.string, lc_string,
                                              pos.file_name, pos.line_number);
                 free (token.string);
-                arglist_parser_remember (argparser, arg, ms, inner_context,
+                arglist_parser_remember (argparser, arg, ms, inner_region,
                                          pos.file_name, pos.line_number,
                                          token.comment, false);
               }
@@ -1581,6 +1587,7 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_eof:
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return true;
 
         default:
@@ -1628,7 +1635,7 @@ extract_php (FILE *f,
   /* Eat tokens until eof is seen.  When extract_balanced returns
      due to an unbalanced closing parenthesis, just restart it.  */
   while (!extract_balanced (mlp, token_type_eof,
-                            null_context, null_context_list_iterator,
+                            null_context_region (), null_context_list_iterator,
                             arglist_parser_alloc (mlp, NULL)))
     ;
 
index b5edb1ab74f528a638dbef1faaea9d2c039e3e1b..3873246de5175267b88f28f33c8f20431038613b 100644 (file)
@@ -1545,7 +1545,7 @@ static int bracket_nesting_depth;
 static bool
 extract_balanced (message_list_ty *mlp,
                   token_type_ty delim,
-                  flag_context_ty outer_context,
+                  flag_region_ty *outer_region,
                   flag_context_list_iterator_ty context_iter,
                   struct arglist_parser *argparser)
 {
@@ -1558,9 +1558,9 @@ extract_balanced (message_list_ty *mlp,
   /* Context iterator that will be used if the next token is a '('.  */
   flag_context_list_iterator_ty next_context_iter =
     passthrough_context_list_iterator;
-  /* Current context.  */
-  flag_context_ty inner_context =
-    inherited_context (outer_context,
+  /* Current region.  */
+  flag_region_ty *inner_region =
+    inheriting_region (outer_region,
                        flag_context_list_iterator_advance (&context_iter));
 
   /* Start state is 0.  */
@@ -1601,11 +1601,12 @@ extract_balanced (message_list_ty *mlp,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open parentheses"));
           if (extract_balanced (mlp, token_type_rparen,
-                                inner_context, next_context_iter,
+                                inner_region, next_context_iter,
                                 arglist_parser_alloc (mlp,
                                                       state ? next_shapes : NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           paren_nesting_depth--;
@@ -1617,6 +1618,7 @@ extract_balanced (message_list_ty *mlp,
           if (delim == token_type_rparen || delim == token_type_eof)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           next_context_iter = null_context_list_iterator;
@@ -1625,8 +1627,9 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_comma:
           arg++;
-          inner_context =
-            inherited_context (outer_context,
+          unref_region (inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
           next_context_iter = passthrough_context_list_iterator;
@@ -1639,10 +1642,12 @@ extract_balanced (message_list_ty *mlp,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open brackets"));
           if (extract_balanced (mlp, token_type_rbracket,
-                                null_context, null_context_list_iterator,
+                                null_context_region (),
+                                null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           bracket_nesting_depth--;
@@ -1654,6 +1659,7 @@ extract_balanced (message_list_ty *mlp,
           if (delim == token_type_rbracket || delim == token_type_eof)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
           next_context_iter = null_context_list_iterator;
@@ -1672,12 +1678,12 @@ extract_balanced (message_list_ty *mlp,
                 char *string = mixed_string_contents (token.mixed_string);
                 mixed_string_free (token.mixed_string);
                 remember_a_message (mlp, NULL, string, true, false,
-                                    inner_context, &pos,
+                                    inner_region, &pos,
                                     NULL, token.comment, true);
               }
             else
               arglist_parser_remember (argparser, arg, token.mixed_string,
-                                       inner_context,
+                                       inner_region,
                                        pos.file_name, pos.line_number,
                                        token.comment, true);
           }
@@ -1688,6 +1694,7 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_eof:
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return true;
 
         case token_type_plus:
@@ -1754,7 +1761,7 @@ extract_python (FILE *f,
   /* Eat tokens until eof is seen.  When extract_balanced returns
      due to an unbalanced closing parenthesis, just restart it.  */
   while (!extract_balanced (mlp, token_type_eof,
-                            null_context, null_context_list_iterator,
+                            null_context_region (), null_context_list_iterator,
                             arglist_parser_alloc (mlp, NULL)))
     ;
 
index 25252d63123715e949c0f4a04323cf310a98239f..4502860c7d23d82d18c3bb376830b796fbead5f7 100644 (file)
@@ -219,7 +219,8 @@ extract_rst (FILE *f,
       pos.file_name = location;
       pos.line_number = (size_t)(-1);
 
-      remember_a_message (mlp, NULL, msgid, false, false, null_context, &pos,
+      remember_a_message (mlp, NULL, msgid, false, false,
+                          null_context_region (), &pos,
                           NULL, NULL, false);
 
       /* Here c is the last read character: EOF or '\n'.  */
@@ -627,7 +628,7 @@ extract_rsj (FILE *f,
                       pos.line_number = (size_t)(-1);
 
                       remember_a_message (mlp, NULL, msgid, true, false,
-                                          null_context, &pos,
+                                          null_context_region (), &pos,
                                           NULL, NULL, false);
 
                       /* Parse a comma.  */
index 386e080ca322460763f3b127c45fd044a298ef1a..0709ecb21028739fa78e7f4dafd85eb3f64898bb 100644 (file)
@@ -682,7 +682,7 @@ static int nesting_depth;
 
 /* Read the next object.  */
 static void
-read_object (struct object *op, flag_context_ty outer_context)
+read_object (struct object *op, flag_region_ty *outer_region)
 {
   if (nesting_depth > MAX_NESTING_DEPTH)
     if_error (IF_SEVERITY_FATAL_ERROR,
@@ -741,21 +741,21 @@ read_object (struct object *op, flag_context_ty outer_context)
             const struct callshapes *shapes = NULL;
             struct arglist_parser *argparser = NULL;
 
-             for (;; arg++)
-               {
+            for (;; arg++)
+              {
                 struct object inner;
-                flag_context_ty inner_context;
+                flag_region_ty *inner_region;
 
                 if (arg == 0)
-                  inner_context = null_context;
+                  inner_region = null_context_region ();
                 else
-                  inner_context =
-                    inherited_context (outer_context,
+                  inner_region =
+                    inheriting_region (outer_region,
                                        flag_context_list_iterator_advance (
                                          &context_iter));
 
                 ++nesting_depth;
-                read_object (&inner, inner_context);
+                read_object (&inner, inner_region);
                 nesting_depth--;
 
                 /* Recognize end of list.  */
@@ -765,6 +765,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                     last_non_comment_line = line_number;
                     if (argparser != NULL)
                       arglist_parser_done (argparser, arg);
+                    unref_region (inner_region);
                     return;
                   }
 
@@ -815,13 +816,14 @@ read_object (struct object *op, flag_context_ty outer_context)
                                                      inner.line_number_at_start);
                         free (s);
                         arglist_parser_remember (argparser, arg, ms,
-                                                 inner_context,
+                                                 inner_region,
                                                  logical_file_name,
                                                  inner.line_number_at_start,
                                                  savable_comment, false);
                       }
                   }
 
+                unref_region (inner_region);
                 free_object (&inner);
               }
             if (argparser != NULL)
@@ -854,7 +856,7 @@ read_object (struct object *op, flag_context_ty outer_context)
             struct object inner;
 
             ++nesting_depth;
-            read_object (&inner, null_context);
+            read_object (&inner, null_context_region ());
             nesting_depth--;
 
             /* Dots and EOF are not allowed here.  But be tolerant.  */
@@ -884,7 +886,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                 {
                   struct object inner;
                   ++nesting_depth;
-                  read_object (&inner, null_context);
+                  read_object (&inner, null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
                      But be tolerant.  */
@@ -966,7 +968,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                            */
                           struct object inner;
                           ++nesting_depth;
-                          read_object (&inner, null_context);
+                          read_object (&inner, null_context_region ());
                           nesting_depth--;
                           /* Dots and EOF are not allowed here.
                              But be tolerant.  */
@@ -1018,7 +1020,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                                */
                               struct object inner;
                               ++nesting_depth;
-                              read_object (&inner, null_context);
+                              read_object (&inner, null_context_region ());
                               nesting_depth--;
                               /* Dots and EOF are not allowed here.
                                  But be tolerant.  */
@@ -1255,7 +1257,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                 {
                   struct object inner;
                   ++nesting_depth;
-                  read_object (&inner, null_context);
+                  read_object (&inner, null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
                      But be tolerant.  */
@@ -1362,7 +1364,7 @@ read_object (struct object *op, flag_context_ty outer_context)
                 pos.file_name = logical_file_name;
                 pos.line_number = op->line_number_at_start;
                 remember_a_message (mlp, NULL, string_of_object (op), false,
-                                    false, null_context, &pos,
+                                    false, null_context_region (), &pos,
                                     NULL, savable_comment, false);
               }
             last_non_comment_line = line_number;
@@ -1436,7 +1438,7 @@ extract_scheme (FILE *f,
     {
       struct object toplevel_object;
 
-      read_object (&toplevel_object, null_context);
+      read_object (&toplevel_object, null_context_region ());
 
       if (toplevel_object.type == t_eof)
         break;
index 397358da3427ffe1313bc883fcad5e1af2e210d1..28766108a87f421ba8deb8ee7a0d7380ede05087 100644 (file)
@@ -743,7 +743,7 @@ static int nesting_depth;
 
 /* Forward declaration of local functions.  */
 static enum word_type read_command_list (int looking_for,
-                                         flag_context_ty outer_context);
+                                         flag_region_ty *outer_region);
 
 
 
@@ -751,7 +751,7 @@ static enum word_type read_command_list (int looking_for,
    'looking_for' denotes a parse terminator, either CLOSING_BACKQUOTE, ')'
    or '\0'.  */
 static void
-read_word (struct word *wp, int looking_for, flag_context_ty context)
+read_word (struct word *wp, int looking_for, flag_region_ty *region)
 {
   int c;
   bool all_unquoted_digits;
@@ -972,7 +972,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
                   /* Command substitution (Bash syntax).  */
                   phase2_ungetc (c3);
                   ++nesting_depth;
-                  read_command_list (')', context);
+                  read_command_list (')', region);
                   nesting_depth--;
                 }
 
@@ -1143,7 +1143,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
                       string.chars[string.charcount++] = (unsigned char) c;
                     }
                   remember_a_message (mlp, NULL, string_of_token (&string),
-                                      false, false, context, &pos,
+                                      false, false, region, &pos,
                                       NULL, savable_comment, false);
                   free_token (&string);
 
@@ -1202,7 +1202,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
           saw_opening_backquote ();
 
           ++nesting_depth;
-          read_command_list (CLOSING_BACKQUOTE, context);
+          read_command_list (CLOSING_BACKQUOTE, region);
           nesting_depth--;
 
           wp->type = t_other;
@@ -1224,7 +1224,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
             {
               /* Process substitution (Bash syntax).  */
               ++nesting_depth;
-              read_command_list (')', context);
+              read_command_list (')', region);
               nesting_depth--;
 
               wp->type = t_other;
@@ -1261,7 +1261,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
    or '\0'.
    Returns the type of the word that terminated the command.  */
 static enum word_type
-read_command (int looking_for, flag_context_ty outer_context)
+read_command (int looking_for, flag_region_ty *outer_region)
 {
   /* Read the words that make up the command.
      Here we completely ignore field splitting at whitespace and wildcard
@@ -1284,17 +1284,17 @@ read_command (int looking_for, flag_context_ty outer_context)
   for (;;)
     {
       struct word inner;
-      flag_context_ty inner_context;
+      flag_region_ty *inner_region;
 
       if (arg == 0)
-        inner_context = null_context;
+        inner_region = null_context_region ();
       else
-        inner_context =
-          inherited_context (outer_context,
+        inner_region =
+          inheriting_region (outer_region,
                              flag_context_list_iterator_advance (
                                &context_iter));
 
-      read_word (&inner, looking_for, inner_context);
+      read_word (&inner, looking_for, inner_region);
 
       /* Recognize end of command.  */
       if (inner.type == t_separator
@@ -1303,6 +1303,7 @@ read_command (int looking_for, flag_context_ty outer_context)
         {
           if (argparser != NULL)
             arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return inner.type;
         }
 
@@ -1315,7 +1316,7 @@ read_command (int looking_for, flag_context_ty outer_context)
               pos.file_name = logical_file_name;
               pos.line_number = inner.line_number_at_start;
               remember_a_message (mlp, NULL, string_of_word (&inner), false,
-                                  false, inner_context, &pos,
+                                  false, inner_region, &pos,
                                   NULL, savable_comment, false);
             }
         }
@@ -1406,7 +1407,7 @@ read_command (int looking_for, flag_context_ty outer_context)
                       free (s);
                       argparser->next_is_msgctxt = false;
                       arglist_parser_remember_msgctxt (argparser, ms,
-                                                       inner_context,
+                                                       inner_region,
                                                        logical_file_name,
                                                        inner.line_number_at_start);
                       matters_for_argparser = false;
@@ -1432,7 +1433,7 @@ read_command (int looking_for, flag_context_ty outer_context)
                       free (s);
                       argparser->next_is_msgctxt = false;
                       arglist_parser_remember_msgctxt (argparser, ms,
-                                                       inner_context,
+                                                       inner_region,
                                                        logical_file_name,
                                                        inner.line_number_at_start);
                       matters_for_argparser = false;
@@ -1471,7 +1472,7 @@ read_command (int looking_for, flag_context_ty outer_context)
                                                       inner.line_number_at_start);
                       free (s);
                       arglist_parser_remember (argparser, arg, ms,
-                                               inner_context,
+                                               inner_region,
                                                logical_file_name,
                                                inner.line_number_at_start,
                                                savable_comment, false);
@@ -1493,6 +1494,7 @@ read_command (int looking_for, flag_context_ty outer_context)
             arg++;
         }
 
+      unref_region (inner_region);
       free_word (&inner);
     }
 }
@@ -1503,7 +1505,7 @@ read_command (int looking_for, flag_context_ty outer_context)
    or '\0'.
    Returns the type of the word that terminated the command list.  */
 static enum word_type
-read_command_list (int looking_for, flag_context_ty outer_context)
+read_command_list (int looking_for, flag_region_ty *outer_region)
 {
   if (nesting_depth > MAX_NESTING_DEPTH)
     if_error (IF_SEVERITY_FATAL_ERROR,
@@ -1513,7 +1515,7 @@ read_command_list (int looking_for, flag_context_ty outer_context)
     {
       enum word_type terminator;
 
-      terminator = read_command (looking_for, outer_context);
+      terminator = read_command (looking_for, outer_region);
       if (terminator != t_separator)
         return terminator;
     }
@@ -1551,7 +1553,7 @@ extract_sh (FILE *f,
   init_keywords ();
 
   /* Eat tokens until eof is seen.  */
-  read_command_list ('\0', null_context);
+  read_command_list ('\0', null_context_region ());
 
   fp = NULL;
   real_file_name = NULL;
index 86f6a4ba403566d4991f0a186759c4bb28285a01..4b5a33facebe538688a45b028a9caa289c4931d1 100644 (file)
@@ -561,8 +561,8 @@ extract_smalltalk (FILE *f,
                 pos.file_name = logical_file_name;
                 pos.line_number = token.line_number;
                 remember_a_message (mlp, NULL, token.string, false, false,
-                                    null_context, &pos, NULL, savable_comment,
-                                    false);
+                                    null_context_region (), &pos,
+                                    NULL, savable_comment, false);
                 state = 0;
                 break;
               }
@@ -580,7 +580,7 @@ extract_smalltalk (FILE *f,
                   remember_a_message (mlp, NULL, token.string, false,
                                       token2.type == token_type_symbol
                                       && strcmp (token.string, "plural:") == 0,
-                                      null_context, &pos,
+                                      null_context_region (), &pos,
                                       NULL, savable_comment, false);
 
                 phase3_unget (&token2);
@@ -595,7 +595,7 @@ extract_smalltalk (FILE *f,
                 pos.line_number = token.line_number;
                 if (plural_mp != NULL)
                   remember_a_message_plural (plural_mp, token.string, false,
-                                             null_context, &pos,
+                                             null_context_region (), &pos,
                                              savable_comment, false);
                 state = 0;
                 break;
index 9542ac25a710a1fe2e0018ad9f50377e5fb7a4e4..f79ff643e85cda579db7534bc8e556209d9c4b6c 100644 (file)
@@ -662,14 +662,14 @@ enum terminator
 
 /* Forward declaration of local functions.  */
 static enum word_type read_command_list (int looking_for,
-                                         flag_context_ty outer_context);
+                                         flag_region_ty *outer_region);
 
 /* Accumulate tokens into the given word.
    'looking_for' denotes a parse terminator combination.
    Return the first character past the token.  */
 static int
 accumulate_word (struct word *wp, enum terminator looking_for,
-                 flag_context_ty context)
+                 flag_region_ty *region)
 {
   int c;
 
@@ -739,7 +739,8 @@ accumulate_word (struct word *wp, enum terminator looking_for,
                   struct word index_word;
 
                   index_word.type = t_other;
-                  c = accumulate_word (&index_word, te_paren, null_context);
+                  c = accumulate_word (&index_word, te_paren,
+                                       null_context_region ());
                   if (c != EOF && c != ')')
                     phase2_ungetc (c);
                   wp->type = t_other;
@@ -770,7 +771,7 @@ accumulate_word (struct word *wp, enum terminator looking_for,
             if_error (IF_SEVERITY_FATAL_ERROR,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open brackets"));
-          read_command_list (']', context);
+          read_command_list (']', region);
           bracket_nesting_depth--;
           wp->type = t_other;
         }
@@ -833,7 +834,7 @@ accumulate_word (struct word *wp, enum terminator looking_for,
 /* Read the next word.
    'looking_for' denotes a parse terminator, either ']' or '\0'.  */
 static void
-read_word (struct word *wp, int looking_for, flag_context_ty context)
+read_word (struct word *wp, int looking_for, flag_region_ty *region)
 {
   int c;
 
@@ -893,7 +894,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
         if_error (IF_SEVERITY_FATAL_ERROR,
                   logical_file_name, line_number, (size_t)(-1), false,
                   _("too many open braces"));
-      terminator = read_command_list ('\0', null_context);
+      terminator = read_command_list ('\0', null_context_region ());
       brace_nesting_depth--;
 
       if (terminator == t_brace)
@@ -911,7 +912,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
 
   if (c == '"')
     {
-      c = accumulate_word (wp, te_quote, context);
+      c = accumulate_word (wp, te_quote, region);
       if (c != EOF && c != '"')
         phase2_ungetc (c);
     }
@@ -922,7 +923,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
                            looking_for == ']'
                            ? te_space_separator_bracket
                            : te_space_separator,
-                           context);
+                           region);
       if (c != EOF)
         phase2_ungetc (c);
     }
@@ -941,7 +942,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
    Returns the type of the word that terminated the command: t_separator or
    t_bracket (only if looking_for is ']') or t_brace or t_eof.  */
 static enum word_type
-read_command (int looking_for, flag_context_ty outer_context)
+read_command (int looking_for, flag_region_ty *outer_region)
 {
   int c;
 
@@ -984,17 +985,17 @@ read_command (int looking_for, flag_context_ty outer_context)
     for (;; arg++)
       {
         struct word inner;
-        flag_context_ty inner_context;
+        flag_region_ty *inner_region;
 
         if (arg == 0)
-          inner_context = null_context;
+          inner_region = null_context_region ();
         else
-          inner_context =
-            inherited_context (outer_context,
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
 
-        read_word (&inner, looking_for, inner_context);
+        read_word (&inner, looking_for, inner_region);
 
         /* Recognize end of command.  */
         if (inner.type == t_separator || inner.type == t_bracket
@@ -1002,6 +1003,7 @@ read_command (int looking_for, flag_context_ty outer_context)
           {
             if (argparser != NULL)
               arglist_parser_done (argparser, arg);
+            unref_region (inner_region);
             return inner.type;
           }
 
@@ -1014,7 +1016,7 @@ read_command (int looking_for, flag_context_ty outer_context)
                 pos.file_name = logical_file_name;
                 pos.line_number = inner.line_number_at_start;
                 remember_a_message (mlp, NULL, string_of_word (&inner), false,
-                                    false, inner_context, &pos,
+                                    false, inner_region, &pos,
                                     NULL, savable_comment, false);
               }
           }
@@ -1064,13 +1066,14 @@ read_command (int looking_for, flag_context_ty outer_context)
                                              inner.line_number_at_start);
                 free (s);
                 arglist_parser_remember (argparser, arg, ms,
-                                         inner_context,
+                                         inner_region,
                                          logical_file_name,
                                          inner.line_number_at_start,
                                          savable_comment, false);
               }
           }
 
+        unref_region (inner_region);
         free_word (&inner);
       }
   }
@@ -1082,13 +1085,13 @@ read_command (int looking_for, flag_context_ty outer_context)
    Returns the type of the word that terminated the command list:
    t_bracket (only if looking_for is ']') or t_brace or t_eof.  */
 static enum word_type
-read_command_list (int looking_for, flag_context_ty outer_context)
+read_command_list (int looking_for, flag_region_ty *outer_region)
 {
   for (;;)
     {
       enum word_type terminator;
 
-      terminator = read_command (looking_for, outer_context);
+      terminator = read_command (looking_for, outer_region);
       if (terminator != t_separator)
         return terminator;
     }
@@ -1127,7 +1130,7 @@ extract_tcl (FILE *f,
   init_keywords ();
 
   /* Eat tokens until eof is seen.  */
-  read_command_list ('\0', null_context);
+  read_command_list ('\0', null_context_region ());
 
   fp = NULL;
   real_file_name = NULL;
index 6aaba64f16e8de98ae73468ad63ac138c2f16259..cd55fca3310eaa760db4034aaebad93004577830 100644 (file)
@@ -1255,7 +1255,7 @@ static int nesting_depth;
    Return true upon eof, false upon closing parenthesis or bracket.  */
 static bool
 extract_balanced (message_list_ty *mlp, token_type_ty delim,
-                  flag_context_ty outer_context,
+                  flag_region_ty *outer_region,
                   flag_context_list_iterator_ty context_iter,
                   struct arglist_parser *argparser)
 {
@@ -1268,9 +1268,9 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
   /* Context iterator that will be used if the next token is a '('.  */
   flag_context_list_iterator_ty next_context_iter =
     passthrough_context_list_iterator;
-  /* Current context.  */
-  flag_context_ty inner_context =
-    inherited_context (outer_context,
+  /* Current region.  */
+  flag_region_ty *inner_region =
+    inheriting_region (outer_region,
                        flag_context_list_iterator_advance (&context_iter));
 
   /* Start state is 0.  */
@@ -1312,11 +1312,12 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open parentheses"));
           if (extract_balanced (mlp, token_type_rparen,
-                                inner_context, next_context_iter,
+                                inner_region, next_context_iter,
                                 arglist_parser_alloc (mlp,
                                                       state ? next_shapes : NULL)))
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return true;
             }
           nesting_depth--;
@@ -1328,6 +1329,7 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
           if (delim == token_type_rparen || delim == token_type_eof)
             {
               arglist_parser_done (argparser, arg);
+              unref_region (inner_region);
               return false;
             }
 
@@ -1337,8 +1339,9 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
 
         case token_type_comma:
           arg++;
-          inner_context =
-            inherited_context (outer_context,
+          unref_region (inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
           next_context_iter = passthrough_context_list_iterator;
@@ -1347,6 +1350,7 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
 
         case token_type_eof:
           arglist_parser_done (argparser, arg);
+          unref_region (inner_region);
           return true;
 
         case token_type_string_literal:
@@ -1361,7 +1365,7 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
                 char *string = mixed_string_contents (token.mixed_string);
                 mixed_string_free (token.mixed_string);
                 remember_a_message (mlp, NULL, string, true, false,
-                                    inner_context, &pos,
+                                    inner_region, &pos,
                                     NULL, token.comment, false);
               }
             else
@@ -1373,14 +1377,14 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
                     tmp_argparser = arglist_parser_alloc (mlp, next_shapes);
 
                     arglist_parser_remember (tmp_argparser, 1,
-                                             token.mixed_string, inner_context,
+                                             token.mixed_string, inner_region,
                                              pos.file_name, pos.line_number,
                                              token.comment, false);
                     arglist_parser_done (tmp_argparser, 1);
                   }
                 else
                   arglist_parser_remember (argparser, arg,
-                                           token.mixed_string, inner_context,
+                                           token.mixed_string, inner_region,
                                            pos.file_name, pos.line_number,
                                            token.comment, false);
               }
@@ -1444,7 +1448,7 @@ extract_vala (FILE *f,
   /* Eat tokens until eof is seen.  When extract_parenthesized returns
      due to an unbalanced closing parenthesis, just restart it.  */
   while (!extract_balanced (mlp, token_type_eof,
-                            null_context, null_context_list_iterator,
+                            null_context_region (), null_context_list_iterator,
                             arglist_parser_alloc (mlp, NULL)))
     ;
 
index dd548508bc7d2f0ef9c17c64d7afb57fe9cf4a9f..203b6b24ed393182a78cc5812a7a6e39f4babc8a 100644 (file)
@@ -662,7 +662,7 @@ static int nesting_depth;
    Return true upon eof, false upon closing parenthesis.  */
 static bool
 extract_parenthesized (message_list_ty *mlp,
-                       flag_context_ty outer_context,
+                       flag_region_ty *outer_region,
                        flag_context_list_iterator_ty context_iter,
                        bool in_i18n)
 {
@@ -672,9 +672,9 @@ extract_parenthesized (message_list_ty *mlp,
   /* Context iterator that will be used if the next token is a '('.  */
   flag_context_list_iterator_ty next_context_iter =
     passthrough_context_list_iterator;
-  /* Current context.  */
-  flag_context_ty inner_context =
-    inherited_context (outer_context,
+  /* Current region.  */
+  flag_region_ty *inner_region =
+    inheriting_region (outer_region,
                        flag_context_list_iterator_advance (&context_iter));
 
   /* Start state is 0 or 1.  */
@@ -696,9 +696,12 @@ extract_parenthesized (message_list_ty *mlp,
             if_error (IF_SEVERITY_FATAL_ERROR,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open parentheses"));
-          if (extract_parenthesized (mlp, inner_context, next_context_iter,
+          if (extract_parenthesized (mlp, inner_region, next_context_iter,
                                      true))
-            return true;
+            {
+              unref_region (inner_region);
+              return true;
+            }
           nesting_depth--;
           next_context_iter = null_context_list_iterator;
           state = 0;
@@ -724,7 +727,7 @@ extract_parenthesized (message_list_ty *mlp,
                   plural_mp =
                     remember_a_message (mlp, NULL, token.string, false,
                                         token2.type == token_type_comma,
-                                        inner_context, &pos,
+                                        inner_region, &pos,
                                         NULL, token.comment, false);
 
                   if (in_i18n)
@@ -740,7 +743,7 @@ extract_parenthesized (message_list_ty *mlp,
                   /* Seen an msgid_plural.  */
                   if (plural_mp != NULL)
                     remember_a_message_plural (plural_mp, token.string, false,
-                                               inner_context, &pos,
+                                               inner_region, &pos,
                                                token.comment, false);
                   state = 0;
                 }
@@ -769,15 +772,19 @@ extract_parenthesized (message_list_ty *mlp,
             if_error (IF_SEVERITY_FATAL_ERROR,
                       logical_file_name, line_number, (size_t)(-1), false,
                       _("too many open parentheses"));
-          if (extract_parenthesized (mlp, inner_context, next_context_iter,
+          if (extract_parenthesized (mlp, inner_region, next_context_iter,
                                      false))
-            return true;
+            {
+              unref_region (inner_region);
+              return true;
+            }
           nesting_depth--;
           next_context_iter = null_context_list_iterator;
           state = 0;
           continue;
 
         case token_type_rparen:
+          unref_region (inner_region);
           return false;
 
         case token_type_comma:
@@ -785,8 +792,9 @@ extract_parenthesized (message_list_ty *mlp,
             state = 1;
           else
             state = 0;
-          inner_context =
-            inherited_context (outer_context,
+          unref_region (inner_region);
+          inner_region =
+            inheriting_region (outer_region,
                                flag_context_list_iterator_advance (
                                  &context_iter));
           next_context_iter = passthrough_context_list_iterator;
@@ -798,6 +806,7 @@ extract_parenthesized (message_list_ty *mlp,
           continue;
 
         case token_type_eof:
+          unref_region (inner_region);
           return true;
 
         default:
@@ -833,8 +842,8 @@ extract_ycp (FILE *f,
 
   /* Eat tokens until eof is seen.  When extract_parenthesized returns
      due to an unbalanced closing parenthesis, just restart it.  */
-  while (!extract_parenthesized (mlp, null_context, null_context_list_iterator,
-                                 false))
+  while (!extract_parenthesized (mlp, null_context_region (),
+                                 null_context_list_iterator, false))
     ;
 
   fp = NULL;
index d31d077181335938b84087f41a270ddd4a0d21df..ff181d1c8975c3e4499812244853319287780ef8 100644 (file)
 
 #include <stdlib.h>
 
+#include "attribute.h"
 #include "xalloc.h"
 #include "xmalloca.h"
 #include "verify.h"
 
 
 /* Null context.  */
-flag_context_ty null_context =
+static flag_context_ty null_context =
   {
     {
       { undecided, false },
@@ -41,7 +42,7 @@ flag_context_ty null_context =
   };
 
 /* Transparent context.  */
-flag_context_ty passthrough_context =
+MAYBE_UNUSED static flag_context_ty passthrough_context =
   {
     {
       { undecided, true },
@@ -52,22 +53,6 @@ flag_context_ty passthrough_context =
   };
 
 
-flag_context_ty
-inherited_context (flag_context_ty outer_context,
-                   flag_context_ty modifier_context)
-{
-  flag_context_ty result = modifier_context;
-
-  for (size_t fi = 0; fi < NXFORMATS; fi++)
-    if (result.for_formatstring[fi].pass_format)
-      {
-        result.for_formatstring[fi].is_format = outer_context.for_formatstring[fi].is_format;
-        result.for_formatstring[fi].pass_format = false;
-      }
-  return result;
-}
-
-
 /* Null context list iterator.  */
 flag_context_list_iterator_ty null_context_list_iterator = { 1, NULL };
 
@@ -221,3 +206,65 @@ flag_context_list_table_add (flag_context_list_table_ty *table,
       }
   }
 }
+
+
+/* We don't need to remember messages that were processed in the null context
+   region.  Therefore the null context region can be a singleton.  This
+   reduces the number of needed calls to unref_region.  */
+static flag_region_ty const the_null_context_region =
+  {
+    1,
+    {
+      { undecided },
+      { undecided },
+      { undecided },
+      { undecided }
+    }
+  };
+
+flag_region_ty *
+null_context_region ()
+{
+  return (flag_region_ty *) &the_null_context_region;
+}
+
+
+flag_region_ty *
+inheriting_region (flag_region_ty *outer_region,
+                   flag_context_ty modifier_context)
+{
+  flag_region_ty *region = XMALLOC (flag_region_ty);
+
+  region->refcount = 1;
+  for (size_t fi = 0; fi < NXFORMATS; fi++)
+    {
+      if (modifier_context.for_formatstring[fi].pass_format)
+        region->for_formatstring[fi].is_format = outer_region->for_formatstring[fi].is_format;
+      else
+        region->for_formatstring[fi].is_format = modifier_context.for_formatstring[fi].is_format;
+    }
+
+  return region;
+}
+
+
+flag_region_ty *
+ref_region (flag_region_ty *region)
+{
+  if (region != NULL && region != &the_null_context_region)
+    region->refcount++;
+  return region;
+}
+
+
+void
+unref_region (flag_region_ty *region)
+{
+  if (region != NULL && region != &the_null_context_region)
+    {
+      if (region->refcount > 1)
+        region->refcount--;
+      else
+        free (region);
+    }
+}
index 8c32cac497f47f3aa37496a2ddbacd8249232425..4127d7b64fdcc187ab1b81914dd480803d70eeb1 100644 (file)
@@ -42,16 +42,6 @@ struct flag_context_ty
 {
   struct formatstring_context_ty for_formatstring[NXFORMATS];
 };
-/* Null context.  */
-extern flag_context_ty null_context;
-/* Transparent context.  */
-extern flag_context_ty passthrough_context;
-/* Compute an inherited context.
-   The outer_context is assumed to have all pass_format flags = false.
-   The result will then also have all pass_format flags = false.  */
-extern flag_context_ty
-       inherited_context (flag_context_ty outer_context,
-                          flag_context_ty modifier_context);
 
 /* Context representing some flags, for each possible argument number.
    This is a linked list, sorted according to the argument number.  */
@@ -77,6 +67,7 @@ extern flag_context_list_iterator_ty
 extern flag_context_ty
        flag_context_list_iterator_advance (flag_context_list_iterator_ty *iter);
 
+
 /* For nearly each backend, we have a separate table mapping a keyword to
    a flag_context_list_ty *.  */
 typedef hash_table /* char[] -> flag_context_list_ty * */
@@ -94,6 +85,60 @@ extern void
                                     int argnum, enum is_format value, bool pass);
 
 
+/* Context representing some flags w.r.t. a specific format string type,
+   as effective in a region of the input file.  */
+struct formatstring_region_ty
+{
+  enum is_format is_format;
+};
+
+/* A region of the input file, in which a given context is in effect, together
+   with the messages that were remembered while processing this region.  */
+typedef struct flag_region_ty flag_region_ty;
+struct flag_region_ty
+{
+  unsigned int refcount;
+  struct formatstring_region_ty for_formatstring[NXFORMATS];
+};
+
+/* Creates a region in which the null context is in effect.  */
+extern flag_region_ty *
+       null_context_region ();
+
+/* Creates a sub-region that inherits from an outer region.  */
+extern flag_region_ty *
+       inheriting_region (flag_region_ty *outer_region,
+                          flag_context_ty modifier_context);
+
+/* Adds a reference to a region.  Returns the region.  */
+extern flag_region_ty *
+       ref_region (flag_region_ty *region);
+
+/* Drops a reference to a region.
+   When the last reference is dropped, the region is freed.  */
+extern void
+       unref_region (flag_region_ty *region);
+
+/* Assigns the value of B to the variable A.
+   Both are of type 'flag_region_ty *'.  B is *not* freshly created.  */
+#define assign_region(a, b) \
+  do {                             \
+    flag_region_ty *_prev_a = (a); \
+    (a) = (b);                     \
+    ref_region (a);                \
+    unref_region (_prev_a);        \
+  } while (0)
+
+/* Assigns the value of B to the variable A.
+   Both are of type 'flag_region_ty *'.  B is freshly created.  */
+#define assign_new_region(a, b) \
+  do {                             \
+    flag_region_ty *_prev_a = (a); \
+    (a) = (b);                     \
+    unref_region (_prev_a);        \
+  } while (0)
+
+
 #ifdef __cplusplus
 }
 #endif
index 42bc2c11b654112cd28330466e73da79e45708f8..b5cb67a0d319f96f9b0f2dd3c476b30614b66ae6 100644 (file)
@@ -82,13 +82,13 @@ arglist_parser_alloc (message_list_ty *mlp, const struct callshapes *shapes)
           ap->alternative[i].msgctxt_pos.file_name = NULL;
           ap->alternative[i].msgctxt_pos.line_number = (size_t)(-1);
           ap->alternative[i].msgid = NULL;
-          ap->alternative[i].msgid_context = null_context;
+          ap->alternative[i].msgid_region = null_context_region ();
           ap->alternative[i].msgid_pos.file_name = NULL;
           ap->alternative[i].msgid_pos.line_number = (size_t)(-1);
           ap->alternative[i].msgid_comment = NULL;
           ap->alternative[i].msgid_comment_is_utf8 = false;
           ap->alternative[i].msgid_plural = NULL;
-          ap->alternative[i].msgid_plural_context = null_context;
+          ap->alternative[i].msgid_plural_region = null_context_region ();
           ap->alternative[i].msgid_plural_pos.file_name = NULL;
           ap->alternative[i].msgid_plural_pos.line_number = (size_t)(-1);
         }
@@ -128,13 +128,13 @@ arglist_parser_clone (struct arglist_parser *ap)
         (cp->msgctxt != NULL ? mixed_string_clone (cp->msgctxt) : NULL);
       ccp->msgctxt_pos = cp->msgctxt_pos;
       ccp->msgid = (cp->msgid != NULL ? mixed_string_clone (cp->msgid) : NULL);
-      ccp->msgid_context = cp->msgid_context;
+      ccp->msgid_region = ref_region (cp->msgid_region);
       ccp->msgid_pos = cp->msgid_pos;
       ccp->msgid_comment = add_reference (cp->msgid_comment);
       ccp->msgid_comment_is_utf8 = cp->msgid_comment_is_utf8;
       ccp->msgid_plural =
         (cp->msgid_plural != NULL ? mixed_string_clone (cp->msgid_plural) : NULL);
-      ccp->msgid_plural_context = cp->msgid_plural_context;
+      ccp->msgid_plural_region = ref_region (cp->msgid_plural_region);
       ccp->msgid_plural_pos = cp->msgid_plural_pos;
     }
 
@@ -145,7 +145,7 @@ arglist_parser_clone (struct arglist_parser *ap)
 void
 arglist_parser_remember (struct arglist_parser *ap,
                          int argnum, mixed_string_ty *string,
-                         flag_context_ty context,
+                         flag_region_ty *region,
                          const char *file_name, size_t line_number,
                          refcounted_string_list_ty *comment,
                          bool comment_is_utf8)
@@ -174,7 +174,7 @@ arglist_parser_remember (struct arglist_parser *ap,
           if (argnum == cp->argnum1)
             {
               cp->msgid = string;
-              cp->msgid_context = context;
+              cp->msgid_region = ref_region (region);
               cp->msgid_pos.file_name = file_name;
               cp->msgid_pos.line_number = line_number;
               cp->msgid_comment = add_reference (comment);
@@ -186,7 +186,7 @@ arglist_parser_remember (struct arglist_parser *ap,
           if (argnum == cp->argnum2)
             {
               cp->msgid_plural = string;
-              cp->msgid_plural_context = context;
+              cp->msgid_plural_region = ref_region (region);
               cp->msgid_plural_pos.file_name = file_name;
               cp->msgid_plural_pos.line_number = line_number;
               stored_string = true;
@@ -205,7 +205,7 @@ arglist_parser_remember (struct arglist_parser *ap,
 void
 arglist_parser_remember_msgctxt (struct arglist_parser *ap,
                                  mixed_string_ty *string,
-                                 flag_context_ty context,
+                                 flag_region_ty *region,
                                  const char *file_name, size_t line_number)
 {
   bool stored_string = false;
@@ -390,15 +390,15 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
         {
           /* best_cp indicates the best found complete call.
              Now call remember_a_message.  */
-          flag_context_ty msgid_context;
-          flag_context_ty msgid_plural_context;
+          flag_region_ty *msgid_region;
+          flag_region_ty *msgid_plural_region;
           char *best_msgctxt;
           char *best_msgid;
           char *best_msgid_plural;
           message_ty *mp;
 
-          msgid_context = best_cp->msgid_context;
-          msgid_plural_context = best_cp->msgid_plural_context;
+          msgid_region = best_cp->msgid_region;
+          msgid_plural_region = best_cp->msgid_plural_region;
 
           /* Special support for the 3-argument tr operator in Qt:
              When --qt and --keyword=tr:1,1,2c,3t are specified, add to the
@@ -407,8 +407,8 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
           if (recognize_qt_formatstrings ()
               && best_cp->msgid_plural == best_cp->msgid)
             {
-              msgid_context.for_formatstring[XFORMAT_FOURTH].is_format = yes_according_to_context;
-              msgid_plural_context.for_formatstring[XFORMAT_FOURTH].is_format = yes_according_to_context;
+              msgid_region->for_formatstring[XFORMAT_FOURTH].is_format = yes_according_to_context;
+              msgid_plural_region->for_formatstring[XFORMAT_FOURTH].is_format = yes_according_to_context;
             }
 
           best_msgctxt =
@@ -491,13 +491,13 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
 
           mp = remember_a_message (ap->mlp, best_msgctxt, best_msgid, true,
                                    best_msgid_plural != NULL,
-                                   msgid_context,
+                                   msgid_region,
                                    &best_cp->msgid_pos,
                                    NULL, best_cp->msgid_comment,
                                    best_cp->msgid_comment_is_utf8);
           if (mp != NULL && best_msgid_plural != NULL)
             remember_a_message_plural (mp, best_msgid_plural, true,
-                                       msgid_plural_context,
+                                       msgid_plural_region,
                                        &best_cp->msgid_plural_pos,
                                        NULL, false);
 
@@ -547,6 +547,10 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
     }
 
   for (i = 0; i < ap->nalternatives; i++)
-    drop_reference (ap->alternative[i].msgid_comment);
+    {
+      drop_reference (ap->alternative[i].msgid_comment);
+      unref_region (ap->alternative[i].msgid_region);
+      unref_region (ap->alternative[i].msgid_plural_region);
+    }
   free (ap);
 }
index 4c813e983c281b5d7f5844d950e81af893dee6b0..352a0fb9c22d17d0330693e2fde6e675a2af3de4 100644 (file)
@@ -48,12 +48,12 @@ struct partial_call
   mixed_string_ty *msgctxt;     /* context - owned mixed_string, or NULL */
   lex_pos_ty msgctxt_pos;
   mixed_string_ty *msgid;       /* msgid - owned mixed_string, or NULL */
-  flag_context_ty msgid_context;
+  flag_region_ty *msgid_region;
   lex_pos_ty msgid_pos;
   refcounted_string_list_ty *msgid_comment;
   bool msgid_comment_is_utf8;
   mixed_string_ty *msgid_plural; /* msgid_plural - owned mixed_string, or NULL */
-  flag_context_ty msgid_plural_context;
+  flag_region_ty *msgid_plural_region;
   lex_pos_ty msgid_plural_pos;
 };
 
@@ -85,7 +85,7 @@ extern struct arglist_parser * arglist_parser_clone (struct arglist_parser *ap);
  */
 extern void arglist_parser_remember (struct arglist_parser *ap,
                                      int argnum, mixed_string_ty *string,
-                                     flag_context_ty context,
+                                     flag_region_ty *region,
                                      const char *file_name, size_t line_number,
                                      refcounted_string_list_ty *comment,
                                      bool comment_is_utf8);
@@ -95,7 +95,7 @@ extern void arglist_parser_remember (struct arglist_parser *ap,
    FILE_NAME must be allocated with indefinite extent.  */
 extern void arglist_parser_remember_msgctxt (struct arglist_parser *ap,
                                              mixed_string_ty *string,
-                                             flag_context_ty context,
+                                             flag_region_ty *region,
                                              const char *file_name, size_t line_number);
 /* Tests whether an arglist_parser has is not waiting for more arguments after
    argument ARGNUM.  */
index 7b3b9830b1c22ea4a908c9ca0adeb7d6750e0dc1..8c7aad83f566d28b9d4a3f94f8dc1a2ae1defab1 100644 (file)
 
 
 /* Update the is_format[] flags depending on the information given in the
-   context.  */
+   region's context.  */
 static void
 set_format_flags_from_context (enum is_format is_format[NFORMATS],
-                               flag_context_ty context, const char *string,
+                               flag_region_ty const *region, const char *string,
                                lex_pos_ty *pos, const char *pretty_msgstr)
 {
   bool some_undecided;
 
   some_undecided = false;
   for (size_t fi = 0; fi < NXFORMATS; fi++)
-    some_undecided |= (context.for_formatstring[fi].is_format != undecided);
+    some_undecided |= (region->for_formatstring[fi].is_format != undecided);
 
   if (some_undecided)
     for (size_t i = 0; i < NFORMATS; i++)
@@ -63,8 +63,8 @@ set_format_flags_from_context (enum is_format is_format[NFORMATS],
         if (is_format[i] == undecided)
           for (size_t fi = 0; fi < NXFORMATS; fi++)
             if (formatstring_parsers[i] == current_formatstring_parser[fi]
-                && context.for_formatstring[fi].is_format != undecided)
-              is_format[i] = (enum is_format) context.for_formatstring[fi].is_format;
+                && region->for_formatstring[fi].is_format != undecided)
+              is_format[i] = region->for_formatstring[fi].is_format;
         if (possible_format_p (is_format[i]))
           {
             struct formatstring_parser *parser = formatstring_parsers[i];
@@ -224,7 +224,7 @@ and a mapping instead of a tuple for the arguments.\n"),
 
 message_ty *
 remember_a_message (message_list_ty *mlp, char *msgctxt, char *msgid,
-                    bool is_utf8, bool pluralp, flag_context_ty context,
+                    bool is_utf8, bool pluralp, flag_region_ty *region,
                     lex_pos_ty *pos,
                     const char *extracted_comment,
                     refcounted_string_list_ty *comment, bool comment_is_utf8)
@@ -336,7 +336,7 @@ meta information, not the empty string.\n"));
 
   /* Determine whether the context specifies that the msgid is a format
      string.  */
-  set_format_flags_from_context (mp->is_format, context, mp->msgid, pos, "msgid");
+  set_format_flags_from_context (mp->is_format, region, mp->msgid, pos, "msgid");
 
   /* Ask the lexer for the comments it has seen.  */
   {
@@ -513,7 +513,7 @@ meta information, not the empty string.\n"));
 
 void
 remember_a_message_plural (message_ty *mp, char *string, bool is_utf8,
-                           flag_context_ty context, lex_pos_ty *pos,
+                           flag_region_ty *region, lex_pos_ty *pos,
                            refcounted_string_list_ty *comment,
                            bool comment_is_utf8)
 {
@@ -559,7 +559,7 @@ remember_a_message_plural (message_ty *mp, char *string, bool is_utf8,
 
       /* Determine whether the context specifies that the msgid_plural is a
          format string.  */
-      set_format_flags_from_context (mp->is_format, context, mp->msgid_plural,
+      set_format_flags_from_context (mp->is_format, region, mp->msgid_plural,
                                      pos, "msgid_plural");
 
       /* If it is not already decided, through programmer comments or
index eedc9202a8318362c268c5489b627c2192feb754..5ed5385771d06b2cea48d4523817f778ababebce 100644 (file)
@@ -1,5 +1,5 @@
 /* Extracting a message.  Accumulating the message list.
-   Copyright (C) 2001-2020 Free Software Foundation, Inc.
+   Copyright (C) 2001-2023 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -52,7 +52,7 @@ extern message_ty *remember_a_message (message_list_ty *mlp,
                                        char *msgid,
                                        bool is_utf8,
                                        bool pluralp,
-                                       flag_context_ty context,
+                                       flag_region_ty *region,
                                        lex_pos_ty *pos,
                                        const char *extracted_comment,
                                        refcounted_string_list_ty *comment,
@@ -71,7 +71,7 @@ extern message_ty *remember_a_message (message_list_ty *mlp,
 extern void remember_a_message_plural (message_ty *mp,
                                        char *string,
                                        bool is_utf8,
-                                       flag_context_ty context,
+                                       flag_region_ty *region,
                                        lex_pos_ty *pos,
                                        refcounted_string_list_ty *comment,
                                        bool comment_is_utf8);
index 083ccb08a62eca8af1d95289aa25da3d7925d7b0..2401b7f503c0838b53a2ee48f8d6446b05e927c9 100644 (file)
@@ -1980,7 +1980,7 @@ xgettext_its_extract_callback (message_list_ty *mlp,
                                 msgctxt == NULL ? NULL : xstrdup (msgctxt),
                                 xstrdup (msgid),
                                 false, false,
-                                null_context, pos,
+                                null_context_region (), pos,
                                 extracted_comment, NULL, false);
 
   if (add_itstool_comments)