This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: functions to automate handling of input_file_stack



This patch adds functions for pushing and popping things off the
input_file_stack.  These functions can be used to avoid duplicating
code in various places in the front-ends -- I'll soon check in a C++
patch that makes use of them.

BTW, in the not-too-distrant future, input_file_name and lineno should
become semantically equivalent (by macros, or via elimination) to
input_file_stack->name and input_file_stack->line.  Bernd has already
eliminated a lot of global variables that just get copied back and
forth from various stacks, and that has simplified life considerably.
We should do this one too.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2000-02-24  Mark Mitchell  <mark@codesourcery.com>

	* input.h (push_srcloc): New function.
	(pop_srcloc): Likewise.
	* toplev.c (push_srcloc): Define it.
	(pop_srcloc): Likewise.

Index: input.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/input.h,v
retrieving revision 1.4
diff -c -p -r1.4 input.h
*** input.h	1999/01/06 20:44:38	1.4
--- input.h	2000/02/25 01:06:09
***************
*** 1,6 ****
  /* Declarations for variables relating to reading the source file.
     Used by parsers, lexical analyzers, and error message routines.
!    Copyright (C) 1993, 1997, 1998 Free Software Foundation, Inc.
  
  This file is part of GNU CC.
  
--- 1,6 ----
  /* Declarations for variables relating to reading the source file.
     Used by parsers, lexical analyzers, and error message routines.
!    Copyright (C) 1993, 1997, 1998, 2000 Free Software Foundation, Inc.
  
  This file is part of GNU CC.
  
*************** extern struct file_stack *input_file_sta
*** 45,47 ****
--- 45,50 ----
  
  /* Incremented on each change to input_file_stack.  */
  extern int input_file_stack_tick;
+ 
+ extern void push_srcloc PARAMS ((char *name, int line));
+ extern void pop_srcloc PARAMS ((void));
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.c,v
retrieving revision 1.291
diff -c -p -r1.291 toplev.c
*** toplev.c	2000/02/20 03:49:14	1.291
--- toplev.c	2000/02/25 01:06:14
*************** check_global_declarations (vec, len)
*** 1996,2001 ****
--- 1996,2047 ----
      }
  }
  
+ /* Save the current INPUT_FILENAME and LINENO on the top entry in the
+    INPUT_FILE_STACK.  Push a new entry for FILE and LINE, and set the
+    INPUT_FILENAME and LINENO accordingly.  */
+ 
+ void
+ push_srcloc (file, line)
+      char *file;
+      int line;
+ {
+   struct file_stack *fs;
+ 
+   if (input_file_stack)
+     {
+       input_file_stack->name = input_filename;
+       input_file_stack->line = lineno;
+     }
+ 
+   fs = (struct file_stack *) xmalloc (sizeof (struct file_stack));
+   fs->name = input_filename = file;
+   fs->line = lineno = line;
+   fs->indent_level = 0;
+   fs->next = input_file_stack;
+   input_file_stack = fs;
+   input_file_stack_tick++;
+ }
+ 
+ /* Pop the top entry off the stack of presently open source files.
+    Restore the INPUT_FILENAME and LINENO from the new topmost entry on
+    the stack.  */
+ 
+ void
+ pop_srcloc ()
+ {
+   struct file_stack *fs;
+   
+   fs = input_file_stack;
+   input_file_stack = fs->next;
+   free (fs);
+   input_file_stack_tick++;
+   /* The initial souce file is never popped.  */
+   if (!input_file_stack)
+     abort ();
+   input_filename = input_file_stack->name;
+   lineno = input_file_stack->line;
+ }
+ 
  /* Compile an entire file of output from cpp, named NAME.
     Write a file of assembly output and various debugging dumps.  */
  
*************** compile_file (name)
*** 2257,2266 ****
    input_filename = name;
  
    /* Put an entry on the input file stack for the main input file.  */
!   input_file_stack
!     = (struct file_stack *) xmalloc (sizeof (struct file_stack));
!   input_file_stack->next = 0;
!   input_file_stack->name = input_filename;
  
    /* Perform language-specific initialization.
       This may set main_input_filename.  */
--- 2303,2309 ----
    input_filename = name;
  
    /* Put an entry on the input file stack for the main input file.  */
!   push_srcloc (input_filename, 0);
  
    /* Perform language-specific initialization.
       This may set main_input_filename.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]