cppinit.c (merge_include_chains): Use remove_dup_dir, remove_dup_dirs.
authorNeil Booth <neilb@earthling.net>
Thu, 17 Aug 2000 18:03:59 +0000 (18:03 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Thu, 17 Aug 2000 18:03:59 +0000 (18:03 +0000)
* (cppinit.c) merge_include_chains: Use remove_dup_dir,
remove_dup_dirs.  If qtail == brack, remove brack not
qtail.
(remove_dup_dir, remove_dup_dirs): New functions.

From-SVN: r35766

gcc/ChangeLog
gcc/cppinit.c

index 9b8739b6fc5b5ac4da9bfa7d0afc680a08f472be..b2c4cceadc02fcc356e39812d454bcf7bfe4534e 100644 (file)
@@ -1,3 +1,10 @@
+2000-08-17  Neil Booth  <NeilB@earthling.net>
+
+       * (cppinit.c) merge_include_chains: Use remove_dup_dir,
+       remove_dup_dirs.  If qtail == brack, remove brack not
+       qtail.
+       (remove_dup_dir, remove_dup_dirs): New functions.
+
 2000-08-17  Neil Booth  <NeilB@earthling.net>
 
        * cppinit.c (cpp_cleanup): Free include dir chains.
index e91f1bea4c520993fe9ac7ae37473de723e11b61..6280b0afe39259d11e404febfb71e307498325b6 100644 (file)
@@ -100,6 +100,10 @@ static void path_include           PARAMS ((cpp_reader *,
 static void initialize_builtins                PARAMS ((cpp_reader *));
 static void append_include_chain       PARAMS ((cpp_reader *,
                                                 char *, int, int));
+struct file_name_list * remove_dup_dir PARAMS ((cpp_reader *,
+                                                struct file_name_list *));
+struct file_name_list * remove_dup_dirs PARAMS ((cpp_reader *,
+                                                struct file_name_list *));
 static void merge_include_chains       PARAMS ((cpp_reader *));
 
 static void initialize_dependency_output PARAMS ((cpp_reader *));
@@ -267,6 +271,51 @@ append_include_chain (pfile, dir, path, cxx_aware)
     }
 }
 
+/* Handle a duplicated include path.  PREV is the link in the chain
+   before the duplicate.  The duplicate is removed from the chain and
+   freed.  Returns PREV.  */
+struct file_name_list *
+remove_dup_dir (pfile, prev)
+     cpp_reader *pfile;
+     struct file_name_list *prev;
+{
+  struct file_name_list *cur = prev->next;
+
+  if (CPP_OPTION (pfile, verbose))
+    fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name);
+
+  prev->next = cur->next;
+  free (cur->name);
+  free (cur);
+
+  return prev;
+}
+
+/* Remove duplicate directories from a chain.  Returns the tail of the
+   chain, or NULL if the chain is empty.  This algorithm is quadratic
+   in the number of -I switches, which is acceptable since there
+   aren't usually that many of them.  */
+struct file_name_list *
+remove_dup_dirs (pfile, head)
+     cpp_reader *pfile;
+     struct file_name_list *head;
+{
+  struct file_name_list *prev = NULL, *cur, *other;
+
+  for (cur = head; cur; cur = cur->next)
+    {
+      for (other = head; other != cur; other = other->next)
+        if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
+         {
+           cur = remove_dup_dir (pfile, prev);
+           break;
+         }
+      prev = cur;
+    }
+
+  return prev;
+}
+
 /* Merge the four include chains together in the order quote, bracket,
    system, after.  Remove duplicate dirs (as determined by
    INO_T_EQ()).  The system_include and after_include chains are never
@@ -280,116 +329,47 @@ static void
 merge_include_chains (pfile)
      cpp_reader *pfile;
 {
-  struct file_name_list *prev, *cur, *other;
-  struct file_name_list *quote, *brack, *systm, *after;
-  struct file_name_list *qtail, *btail, *stail, *atail;
+  struct file_name_list *quote, *brack, *systm, *qtail;
 
   struct cpp_pending *pend = CPP_OPTION (pfile, pending);
 
-  qtail = pend->quote_tail;
-  btail = pend->brack_tail;
-  stail = pend->systm_tail;
-  atail = pend->after_tail;
-
   quote = pend->quote_head;
   brack = pend->brack_head;
   systm = pend->systm_head;
-  after = pend->after_head;
+  qtail = pend->quote_tail;
 
-  /* Paste together bracket, system, and after include chains. */
-  if (stail)
-    stail->next = after;
+  /* Paste together bracket, system, and after include chains.  */
+  if (systm)
+    pend->systm_tail->next = pend->after_head;
   else
-    systm = after;
-  if (btail)
-    btail->next = systm;
+    systm = pend->after_head;
+
+  if (brack)
+    pend->brack_tail->next = systm;
   else
     brack = systm;
 
-  /* This is a bit tricky.
-     First we drop dupes from the quote-include list.
-     Then we drop dupes from the bracket-include list.
-     Finally, if qtail and brack are the same directory,
-     we cut out qtail.
+  /* This is a bit tricky.  First we drop dupes from the quote-include
+     list.  Then we drop dupes from the bracket-include list.
+     Finally, if qtail and brack are the same directory, we cut out
+     brack.
 
      We can't just merge the lists and then uniquify them because
      then we may lose directories from the <> search path that should
      be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
      safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
-     -Ibar -I- -Ifoo -Iquux.
-
-     Note that this algorithm is quadratic in the number of -I switches,
-     which is acceptable since there aren't usually that many of them.  */
+     -Ibar -I- -Ifoo -Iquux.  */
 
-  for (cur = quote, prev = NULL; cur; cur = cur->next)
-    {
-      for (other = quote; other != cur; other = other->next)
-        if (INO_T_EQ (cur->ino, other->ino)
-           && cur->dev == other->dev)
-          {
-           if (CPP_OPTION (pfile, verbose))
-             fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"),
-                      cur->name);
-
-           prev->next = cur->next;
-           free (cur->name);
-           free (cur);
-           cur = prev;
-           break;
-         }
-      prev = cur;
-    }
-  qtail = prev;
-
-  for (cur = brack; cur; cur = cur->next)
-    {
-      for (other = brack; other != cur; other = other->next)
-        if (INO_T_EQ (cur->ino, other->ino)
-           && cur->dev == other->dev)
-          {
-           if (CPP_OPTION (pfile, verbose))
-             fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"),
-                      cur->name);
-
-           prev->next = cur->next;
-           free (cur->name);
-           free (cur);
-           cur = prev;
-           break;
-         }
-      prev = cur;
-    }
+  remove_dup_dirs (pfile, brack);
+  qtail = remove_dup_dirs (pfile, quote);
 
   if (quote)
     {
-      if (INO_T_EQ (qtail->ino, brack->ino) && qtail->dev == brack->dev)
-        {
-         if (quote == qtail)
-           {
-             if (CPP_OPTION (pfile, verbose))
-               fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"),
-                        quote->name);
+      qtail->next = brack;
 
-             free (quote->name);
-             free (quote);
-             quote = brack;
-           }
-         else
-           {
-             cur = quote;
-             while (cur->next != qtail)
-                 cur = cur->next;
-             cur->next = brack;
-             if (CPP_OPTION (pfile, verbose))
-               fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"),
-                        qtail->name);
-
-             free (qtail->name);
-             free (qtail);
-           }
-       }
-      else
-         qtail->next = brack;
+      /* If brack == qtail, remove brack as it's simpler.  */
+      if (INO_T_EQ (qtail->ino, brack->ino) && qtail->dev == brack->dev)
+       brack = remove_dup_dir (pfile, qtail);
     }
   else
       quote = brack;