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]

Extending DECL_CONTEXT


There is a need to determine the namespace that a particular
declaration is in, especially when it is a type declaration. I have
studied three options:

1. use the in_namespace field of the C++ lang_decl
2. use a new field in the type itself
3. use the DECL_CONTEXT to store namespace information

The first option fails because not all declarations have lang_decls.
In particular, the shadow decls for some of the types don't.  Option 2
fails because not all types have lang_types. Applying either of the
two solutions would increase the memory consumption.

Instead, I decided to go for option 3, and dropping the in_namespace
field. Unfortunately, this clashes with decl_function_context of
tree.c.

I propose a new interface to allow lang specific nodes to be processed
in decl_function_context. The patch below modifies all of the egcs
front-ends.

Martin

P.S. This patch was produced with Andreas Jaeger's perl script,
which seems to work well. Thanks!

Index: ChangeLog
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/ChangeLog,v
retrieving revision 1.933
diff -u -p -L/dev/null -r1.933 ChangeLog
--- /dev/null
+++ ChangeLog	1998/03/22 18:43:18
@@ -1,3 +1,10 @@
+1998-03-21  Martin von Loewis  <loewis@informatik.hu-berlin.de>
+
+	* c-lang.c (lang_function_decl_context): New function.
+	* objc/c-act.c (lang_function_decl_context): New function.
+	* tree.c (decl_function_context): Call it.
+	* tree.h (lang_function_decl_context): Declare.
+
 Fri Mar 20 17:36:23 1998  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
 	* Makefile.in (alias.o, bitmap.o, c-aux-info.o, c-common.o,
Index: c-lang.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-lang.c,v
retrieving revision 1.7
diff -u -p -L/dev/null -r1.7 c-lang.c
--- /dev/null
+++ c-lang.c	1998/03/22 18:43:31
@@ -186,4 +196,15 @@ finish_file ()
       assemble_destructor (IDENTIFIER_POINTER (fnname));
     }
 #endif
+}
+
+/* Complain, as there are no nodes which are not already handled in
+   decl_function_context. */
+
+tree
+lang_function_decl_context (node)
+     tree node;
+{
+  abort ();
+  return NULL_TREE;
 }
Index: tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/tree.c,v
retrieving revision 1.18
diff -u -p -L/dev/null -r1.18 tree.c
--- /dev/null
+++ tree.c	1998/03/22 18:43:53
@@ -4634,8 +4634,8 @@ decl_function_context (decl)
       else if (TREE_CODE (context) == BLOCK)
 	context = BLOCK_SUPERCONTEXT (context);
       else
-	/* Unhandled CONTEXT !?  */
-	abort ();
+	/* Call abort() on nodes with unknown function contexts */
+	context = lang_function_decl_context (context);
     }
 
   return context;
Index: tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/tree.h,v
retrieving revision 1.16
diff -u -p -L/dev/null -r1.16 tree.h
--- /dev/null
+++ tree.h	1998/03/22 18:43:56
@@ -1868,6 +1868,9 @@ extern char *lang_identify			PROTO((void
 
 /* Function to replace the DECL_LANG_SPECIFIC field of a DECL with a copy.  */
 extern void copy_lang_decl			PROTO((tree));
+
+/* Function to compute the function context of an unidentified node.  */
+extern tree lang_function_decl_context          PROTO((tree));
 
 /* Function called with no arguments to parse and compile the input.  */
 extern int yyparse				PROTO((void));
Index: f/ChangeLog
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/f/ChangeLog,v
retrieving revision 1.16
diff -u -p -L/dev/null -r1.16 ChangeLog
--- /dev/null
+++ f/ChangeLog	1998/03/22 18:47:12
@@ -1,3 +1,7 @@
+1998-03-21  Martin von Loewis  <loewis@informatik.hu-berlin.de>
+
+	* com.c (lang_function_decl_context): New function.
+
 Fri Feb 20 12:45:53 1998  Craig Burley  <burley@gnu.org>
 
 	* expr.c (ffeexpr_token_arguments_): Make sure
Index: f/com.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/f/com.c,v
retrieving revision 1.18
diff -u -p -L/dev/null -r1.18 com.c
--- /dev/null
+++ f/com.c	1998/03/22 18:47:41
@@ -14759,6 +14759,14 @@ copy_lang_decl (node)
 {
 }
 
+tree
+lang_function_decl_context (node)
+     tree node UNUSED;
+{
+  abort ();
+  return NULL_TREE;
+}
+
 /* Return the list of declarations of the current level.
    Note that this list is in reverse order unless/until
    you nreverse it; and when you do nreverse it, you must
Index: objc/objc-act.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/objc/objc-act.c,v
retrieving revision 1.5
diff -u -p -L/dev/null -r1.5 objc-act.c
--- /dev/null
+++ objc/objc-act.c	1998/03/22 18:47:52
@@ -8414,4 +8425,12 @@ objc_debug (fp)
 void
 print_lang_statistics ()
 {
+}
+
+tree
+lang_function_decl_context (node)
+     tree node;
+{
+  abort ();
+  return NULL_TREE;
 }
Index: cp/ChangeLog
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/ChangeLog,v
retrieving revision 1.276
diff -u -p -L/dev/null -r1.276 ChangeLog
--- /dev/null
+++ cp/ChangeLog	1998/03/23 00:09:29
@@ -1,3 +1,7 @@
+Mon Mar 23 01:09:43 1998  Martin von Loewis  <loewis@informatik.hu-berlin.de>
+
+	* lex.c (lang_function_decl_context): New function.
+
 Fri Mar 20 18:07:39 1998  Kriang Lerdsuwanakij  <lerdsuwa@scf.usc.edu>
 
 	* pt.c (tsubst, TEMPLATE_TEMPLATE_PARM): Simplify.
Index: cp/lex.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/lex.c,v
retrieving revision 1.32
diff -u -p -L/dev/null -r1.32 lex.c
--- /dev/null
+++ cp/lex.c	1998/03/23 00:09:49
@@ -4452,6 +4451,15 @@ copy_lang_decl (node)
   pi = (int *)obstack_alloc (&permanent_obstack, size);
   bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)pi, size);
   DECL_LANG_SPECIFIC (node) = (struct lang_decl *)pi;
+}
+
+tree
+lang_function_decl_context (node)
+     tree node;
+{
+  if (TREE_CODE (node) == NAMESPACE_DECL)
+    return 0;
+  abort ();
 }
 
 tree



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