OSDN Git Service

* g++.old-deja/g++.other/dwarf2-1.C: Move...
[pf3gnuchains/gcc-fork.git] / gcc / java / parse.h
index b19edbe..1d8bb05 100644 (file)
@@ -1,5 +1,5 @@
 /* Language parser definitions for the GNU compiler for the Java(TM) language.
-   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
 
 This file is part of GNU CC.
@@ -23,8 +23,8 @@ Java and all Java-based marks are trademarks or registered trademarks
 of Sun Microsystems, Inc. in the United States and other countries.
 The Free Software Foundation is independent of Sun Microsystems, Inc.  */
 
-#ifndef JV_LANG_H
-#define JV_LANG_H
+#ifndef GCC_JAVA_PARSE_H
+#define GCC_JAVA_PARSE_H
 
 #include "lex.h"
 
@@ -73,12 +73,14 @@ extern tree stabilize_reference PARAMS ((tree));
 #define YYNOT_TWICE if (ctxp->prevent_ese != lineno)
 
 /* Accepted modifiers */
-#define CLASS_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT|ACC_FINAL
+#define CLASS_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT|ACC_FINAL|ACC_STRICT
 #define FIELD_MODIFIERS ACC_PUBLIC|ACC_PROTECTED|ACC_PRIVATE|ACC_FINAL| \
                         ACC_STATIC|ACC_TRANSIENT|ACC_VOLATILE
 #define METHOD_MODIFIERS ACC_PUBLIC|ACC_PROTECTED|ACC_PRIVATE|ACC_ABSTRACT| \
-                        ACC_STATIC|ACC_FINAL|ACC_SYNCHRONIZED|ACC_NATIVE
-#define INTERFACE_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT
+                        ACC_STATIC|ACC_FINAL|ACC_SYNCHRONIZED|ACC_NATIVE| \
+                        ACC_STRICT
+#define INTERFACE_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT|ACC_STRICT
+#define INTERFACE_INNER_MODIFIERS ACC_PUBLIC|ACC_PROTECTED|ACC_ABSTRACT|ACC_STATIC
 #define INTERFACE_METHOD_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT
 #define INTERFACE_FIELD_MODIFIERS ACC_PUBLIC|ACC_STATIC|ACC_FINAL
 
@@ -110,7 +112,6 @@ extern tree stabilize_reference PARAMS ((tree));
 /* Misc. */
 #define exit_java_complete_class()             \
   {                                            \
-    pop_obstacks ();                           \
     return;                                    \
   }
 
@@ -125,10 +126,6 @@ extern tree stabilize_reference PARAMS ((tree));
 #define GET_REAL_TYPE(TYPE)                                    \
   (TREE_CODE (TYPE) == TREE_LIST ? TREE_PURPOSE (TYPE) : TYPE)
 
-#define GET_METHOD_NAME(METHOD)                                        \
-  (TREE_CODE (DECL_NAME (METHOD)) == EXPR_WITH_FILE_LOCATION ? \
-   EXPR_WFL_NODE (DECL_NAME (METHOD)) : DECL_NAME (METHOD))
-
 /* Get TYPE name string, regardless whether TYPE is a class or an
    array. */
 #define GET_TYPE_NAME(TYPE)                            \
@@ -155,10 +152,10 @@ extern tree stabilize_reference PARAMS ((tree));
 
 /* Quickly build a temporary pointer on hypothetical type NAME. */
 #define BUILD_PTR_FROM_NAME(ptr, name)         \
-  {                                            \
+  do {                                         \
     ptr = build (POINTER_TYPE, NULL_TREE);     \
     TYPE_NAME (ptr) = name;                    \
-  }
+  } while (0)
 
 #define INCOMPLETE_TYPE_P(NODE)                                \
   ((TREE_CODE (NODE) == POINTER_TYPE)                  \
@@ -228,31 +225,40 @@ extern tree stabilize_reference PARAMS ((tree));
    scope local variables.  */
 #define MANGLE_OUTER_LOCAL_VARIABLE_NAME(N, O)                         \
   {                                                                    \
+    char *mangled_name;                                                        \
     obstack_grow (&temporary_obstack, "val$", 4);                      \
-    obstack_grow (&temporary_obstack,                                  \
+    obstack_grow (&temporary_obstack,                                  \
                  IDENTIFIER_POINTER ((O)), IDENTIFIER_LENGTH ((O)));   \
     obstack_1grow (&temporary_obstack, '\0');                          \
-    (N) = obstack_finish (&temporary_obstack);                         \
+    mangled_name = obstack_finish (&temporary_obstack);                        \
+    (N) = get_identifier (mangled_name);                               \
+    obstack_free (&temporary_obstack, mangled_name);                   \
   }
 
 /* Build the string parm$<O> and store in into the identifier N. This
-   is used to contruct the name of hidden parameters used to
+   is used to construct the name of hidden parameters used to
    initialize outer scope aliases.  */
 #define MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_ID(N, O)               \
   {                                                                    \
+    char *mangled_name;                                                        \
     obstack_grow (&temporary_obstack, "parm$", 5);                     \
     obstack_grow (&temporary_obstack,                                  \
                  IDENTIFIER_POINTER ((O)), IDENTIFIER_LENGTH ((O)));   \
     obstack_1grow (&temporary_obstack, '\0');                          \
-    (N) = obstack_finish (&temporary_obstack);                         \
+    mangled_name = obstack_finish (&temporary_obstack);                        \
+    (N) = get_identifier (mangled_name);                               \
+    obstack_free (&temporary_obstack, mangled_name);                   \
   }
 
 #define MANGLE_ALIAS_INITIALIZER_PARAMETER_NAME_STR(N, S)      \
   {                                                            \
+    char *mangled_name;                                                        \
     obstack_grow (&temporary_obstack, "parm$", 5);             \
     obstack_grow (&temporary_obstack, (S), strlen ((S)));      \
     obstack_1grow (&temporary_obstack, '\0');                  \
-    (N) = obstack_finish (&temporary_obstack);                 \
+    mangled_name = obstack_finish (&temporary_obstack);                        \
+    (N) = get_identifier (mangled_name);                               \
+    obstack_free (&temporary_obstack, mangled_name);                   \
   }
 
 /* Skip THIS and artificial parameters found in function decl M and
@@ -285,7 +291,7 @@ extern tree stabilize_reference PARAMS ((tree));
         current = TREE_CHAIN (current), list = TREE_CHAIN (list))      \
       ARG_FINAL_P (current) = ARG_FINAL_P (list);                      \
     if (current != list)                                               \
-      fatal ("MARK_FINAL_PARMS");                                      \
+      abort ();                                                                \
   }
 
 /* Reset the ARG_FINAL_P that might have been set in method M args.  */
@@ -473,11 +479,7 @@ enum jdep_code {
 };
 
 typedef struct _jdep {
-#ifdef ONLY_INT_FIELDS
-  int  kind : 8;               /* Type of patch */
-#else
-  enum jdep_code kind : 8;
-#endif
+  ENUM_BITFIELD(jdep_code) kind : 8; /* Type of patch */
 
   int  flag0 : 1;              /* Some flags */
   tree decl;                   /* Tied decl/or WFL */
@@ -493,7 +495,6 @@ typedef struct _jdep {
 #define JDEP_DECL(J)          ((J)->decl)
 #define JDEP_DECL_WFL(J)      ((J)->decl)
 #define JDEP_KIND(J)          ((J)->kind)
-#define JDEP_SOLV(J)          ((J)->solv)
 #define JDEP_WFL(J)           ((J)->wfl)
 #define JDEP_MISC(J)          ((J)->misc)
 #define JDEP_ENCLOSING(J)     ((J)->enclosing)
@@ -538,27 +539,60 @@ typedef struct _jdeplist {
    java.lang.Object.  */
 #define SET_TYPE_FOR_RESOLUTION(TYPE, SAVE, CHAIN)                     \
   {                                                                    \
-    tree returned_type;                                                        \
+    tree _returned_type;                                               \
     (CHAIN) = 0;                                                       \
-    if (TREE_TYPE (ctxp->current_parsed_class) == object_type_node     \
-       && TREE_CODE (TYPE) == EXPR_WITH_FILE_LOCATION                  \
+    if (TREE_TYPE (GET_CPC ()) == object_type_node                     \
+       && TREE_CODE (TYPE) == EXPR_WITH_FILE_LOCATION                  \
        && EXPR_WFL_NODE (TYPE) == unqualified_object_id_node)          \
       (TYPE) = object_type_node;                                       \
     else                                                               \
       {                                                                        \
-       if (unresolved_type_p (type, &returned_type))                   \
+       if (unresolved_type_p (type, &_returned_type))                  \
          {                                                             \
-           if (returned_type)                                          \
-             (TYPE) = returned_type;                                   \
+           if (_returned_type)                                         \
+             (TYPE) = _returned_type;                                  \
            else                                                        \
              {                                                         \
-               (SAVE) = (TYPE);                                        \
+               tree _type;                                             \
+                WFL_STRIP_BRACKET (_type, TYPE);                       \
+               (SAVE) = (_type);                                       \
                (TYPE) = obtain_incomplete_type (TYPE);                 \
                CHAIN = 1;                                              \
              }                                                         \
          }                                                             \
       }                                                                        \
   }
+
+#define WFL_STRIP_BRACKET(TARGET, TYPE)                                          \
+{                                                                        \
+  tree __type = (TYPE);                                                          \
+  if (TYPE && TREE_CODE (TYPE) == EXPR_WITH_FILE_LOCATION)               \
+    {                                                                    \
+      tree _node;                                                        \
+      if (build_type_name_from_array_name (EXPR_WFL_NODE (TYPE), &_node)) \
+        {                                                                \
+          tree _new = copy_node (TYPE);                                          \
+          EXPR_WFL_NODE (_new) = _node;                                          \
+          __type = _new;                                                 \
+        }                                                                \
+    }                                                                    \
+  (TARGET) = __type;                                                     \
+}
+
+/* If NAME contains one or more trailing []s, NAMELEN will be the
+   adjusted to be the index of the last non bracket character in
+   NAME. ARRAY_DIMS will contain the number of []s found.  */
+
+#define STRING_STRIP_BRACKETS(NAME, NAMELEN, ARRAY_DIMS)                  \
+{                                                                        \
+  ARRAY_DIMS = 0;                                                        \
+  while (NAMELEN >= 2 && (NAME)[NAMELEN - 1] == ']')                     \
+    {                                                                    \
+      NAMELEN -= 2;                                                      \
+      (ARRAY_DIMS)++;                                                    \
+    }                                                                    \
+}
+
 /* Promote a type if it won't be registered as a patch */
 #define PROMOTE_RECORD_IF_COMPLETE(TYPE, IS_INCOMPLETE)                \
   {                                                            \
@@ -579,10 +613,6 @@ typedef struct _jdeplist {
 #define GET_CURRENT_BLOCK(F) ((F) ? DECL_FUNCTION_BODY ((F)) : \
                             current_static_block)
 
-/* For an artificial BLOCK (created to house a local variable declaration not
-   at the start of an existing block), the parent block;  otherwise NULL. */
-#define BLOCK_EXPR_ORIGIN(NODE) BLOCK_ABSTRACT_ORIGIN(NODE)
-
 /* Merge an other line to the source line number of a decl. Used to
    remember function's end. */
 #define DECL_SOURCE_LINE_MERGE(DECL,NO) DECL_SOURCE_LINE(DECL) |= (NO << 16)
@@ -642,21 +672,13 @@ typedef struct _jdeplist {
   build_new_invocation (wfl_string_buffer,                                   \
                        (ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE))
 
-/* For exception handling, build diverse function calls */
-#define BUILD_ASSIGN_EXCEPTION_INFO(WHERE, TO)         \
-  {                                                    \
-    (WHERE) = build (MODIFY_EXPR, void_type_node, (TO),        \
-                    soft_exceptioninfo_call_node);     \
-    TREE_SIDE_EFFECTS (WHERE) = 1;                     \
-  }
-
-#define BUILD_THROW(WHERE, WHAT)                                           \
-  {                                                                        \
-    (WHERE) =                                                              \
-      build (CALL_EXPR, void_type_node,                                            \
-            build_address_of (throw_node[exceptions_via_longjmp ? 1 : 0]), \
-            build_tree_list (NULL_TREE, (WHAT)), NULL_TREE);               \
-    TREE_SIDE_EFFECTS ((WHERE)) = 1;                                       \
+#define BUILD_THROW(WHERE, WHAT)                               \
+  {                                                            \
+    (WHERE) =                                                  \
+      build (CALL_EXPR, void_type_node,                                \
+            build_address_of (throw_node),                     \
+            build_tree_list (NULL_TREE, (WHAT)), NULL_TREE);   \
+    TREE_SIDE_EFFECTS ((WHERE)) = 1;                           \
   }
 
 /* Set wfl_operator for the most accurate error location */
@@ -690,32 +712,29 @@ typedef struct _jdeplist {
   }
 
 /* Register an import */
-#define REGISTER_IMPORT(WHOLE, NAME)                   \
-{                                                      \
-  IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P ((NAME)) = 1;    \
-  node = build_tree_list ((WHOLE), (NAME));            \
-  TREE_CHAIN (node) = ctxp->import_list;               \
-  ctxp->import_list = node;                            \
+#define REGISTER_IMPORT(WHOLE, NAME)                                   \
+{                                                                      \
+  IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P ((NAME)) = 1;                    \
+  ctxp->import_list = tree_cons ((WHOLE), (NAME), ctxp->import_list);  \
 }
 
 /* Macro to access the osb (opening square bracket) count */
 #define CURRENT_OSB(C) (C)->osb_number [(C)->osb_depth]
 
 /* Macro for the xreferencer */
-#define DECL_END_SOURCE_LINE(DECL)       DECL_FRAME_SIZE (DECL)
+#define DECL_END_SOURCE_LINE(DECL)       (DECL_CHECK (DECL)->decl.u1.i)
 #define DECL_INHERITED_SOURCE_LINE(DECL) (DECL_CHECK (DECL)->decl.u2.i)
      
 /* Parser context data structure. */
 struct parser_ctxt {
 
-  char *filename;                  /* Current filename */
-  FILE *finput;                            /* Current file input stream */
+  const char *filename;                    /* Current filename */
   struct parser_ctxt *next;
 
+  java_lexer *lexer;                /* Current lexer state */
   char marker_begining;                     /* Marker. Should be a sub-struct */
   struct java_line *p_line, *c_line; /* Previous and current line */
   java_lc elc;                      /* Error's line column info */
-  unicode_t unget_utf8_value;        /* An unget utf8 value */
   int ccb_indent;                   /* Keep track of {} indent, lexer */
   int first_ccb_indent1;            /* First { at ident level 1 */
   int last_ccb_indent1;                     /* Last } at ident level 1 */
@@ -734,8 +753,6 @@ struct parser_ctxt {
   /* Indicates that a context already contains saved data and that the
      next save operation will require a new context to be created. */
   unsigned saved_data:1;
-  /* Integral literal overflow */
-  unsigned minus_seen:1;
   /* Report error when true */
   unsigned java_error_flag:1;
   /* @deprecated tag seen */
@@ -746,8 +763,8 @@ struct parser_ctxt {
   /* This section is defined only if we compile jc1 */
 #ifndef JC1_LITE
   tree modifier_ctx [11];          /* WFL of modifiers */
-  tree current_class;              /* Current class */
-  tree current_function_decl;      /* Current function decl, save/restore */
+  tree class_type;                 /* Current class */
+  tree function_decl;              /* Current function decl, save/restore */
 
   struct JCF *current_jcf;         /* CU jcf */
 
@@ -758,10 +775,6 @@ struct parser_ctxt {
 
   tree package;                            /* Defined package ID */
 
-  /* Those two list are saved accross file traversal */
-  tree  incomplete_class;          /* List of non-complete classes */
-  tree  gclass_list;               /* All classes seen from source code */
-
   /* These two lists won't survive file traversal */
   tree  class_list;                /* List of classes in a CU */
   jdeplist *classd_list;           /* Classe dependencies in a CU */
@@ -771,7 +784,7 @@ struct parser_ctxt {
 
   tree non_static_initialized;     /* List of non static initialized fields */
   tree static_initialized;         /* List of static non final initialized */
-  tree instance_initializers;      /* List of instancei initializers stmts */
+  tree instance_initializers;      /* List of instance initializers stmts */
 
   tree import_list;                /* List of import */
   tree import_demand_list;         /* List of import on demand */
@@ -825,14 +838,26 @@ struct parser_ctxt {
 
 /* Make sure that innerclass T sits in an appropriate enclosing
    context.  */
-#define INNER_ENCLOSING_SCOPE_CHECK(T)                                 \
-  (INNER_CLASS_TYPE_P ((T)) && !ANONYMOUS_CLASS_P ((T))                        \
-   /* We have a this and it's not the right one */                     \
-   && ((current_this                                                   \
-       && (DECL_CONTEXT (TYPE_NAME ((T)))                              \
-           != TYPE_NAME (TREE_TYPE (TREE_TYPE (current_this)))))       \
-       /* We don't have a this. */                                     \
-       || !current_this))
+#define INNER_ENCLOSING_SCOPE_CHECK(T)                                       \
+  (INNER_CLASS_TYPE_P ((T)) && !ANONYMOUS_CLASS_P ((T))                              \
+   && ((current_this                                                         \
+       /* We have a this and it's not the right one */                       \
+       && (DECL_CONTEXT (TYPE_NAME ((T)))                                    \
+           != TYPE_NAME (TREE_TYPE (TREE_TYPE (current_this))))              \
+       && !inherits_from_p (TREE_TYPE (TREE_TYPE (current_this)),            \
+                            TREE_TYPE (DECL_CONTEXT (TYPE_NAME (T))))        \
+        && !common_enclosing_context_p (TREE_TYPE (TREE_TYPE (current_this)), \
+                                       (T))                                  \
+       && INNER_CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (current_this)))          \
+       && !inherits_from_p                                                   \
+             (TREE_TYPE (DECL_CONTEXT                                        \
+                         (TYPE_NAME (TREE_TYPE (TREE_TYPE (current_this))))),\
+              TREE_TYPE (DECL_CONTEXT (TYPE_NAME (T)))))                     \
+       /* We don't have a this, which is OK if the current function is        \
+         static. */                                                          \
+       || (!current_this                                                     \
+          && current_function_decl                                           \
+           && ! METHOD_STATIC (current_function_decl))))
 
 /* Push macro. First argument to PUSH_CPC is a DECL_TYPE, second
    argument is the unqualified currently parsed class name.  */
@@ -888,6 +913,11 @@ struct parser_ctxt {
   if (CPC_INSTANCE_INITIALIZER_LIST(C))                                \
     TREE_PURPOSE (CPC_INSTANCE_INITIALIZER_LIST (C)) = (S);
 
+/* This is used by the lexer to communicate with the parser.  It is
+   set on an integer constant if the radix is 10, so that the parser
+   can correctly diagnose a numeric overflow.  */
+#define JAVA_RADIX10_FLAG(NODE) TREE_LANG_FLAG_0(NODE)
+
 #ifndef JC1_LITE
 void java_complete_class PARAMS ((void));
 void java_check_circular_reference PARAMS ((void));
@@ -895,21 +925,28 @@ void java_fix_constructors PARAMS ((void));
 void java_layout_classes PARAMS ((void));
 void java_reorder_fields PARAMS ((void));
 tree java_method_add_stmt PARAMS ((tree, tree));
-void java_expand_switch PARAMS ((tree));
 int java_report_errors PARAMS ((void));
 extern tree do_resolve_class PARAMS ((tree, tree, tree, tree));
 #endif
-char *java_get_line_col PARAMS ((char *, int, int));
+char *java_get_line_col PARAMS ((const char *, int, int));
 extern void reset_report PARAMS ((void));
 
 /* Always in use, no matter what you compile */
 void java_push_parser_context PARAMS ((void));
 void java_pop_parser_context PARAMS ((int));
-void java_init_lex PARAMS ((void));
+void java_init_lex PARAMS ((FILE *, const char *));
 extern void java_parser_context_save_global PARAMS ((void));
 extern void java_parser_context_restore_global PARAMS ((void));
 int yyparse PARAMS ((void));
 extern int java_parse PARAMS ((void));
-void yyerror PARAMS ((const char *));
-extern void java_expand_classes PARAMS ((void));
+extern void yyerror PARAMS ((const char *))
+#ifdef JC1_LITE
+ATTRIBUTE_NORETURN
 #endif
+;
+extern void java_expand_classes PARAMS ((void));
+
+extern struct parser_ctxt *ctxp;
+extern struct parser_ctxt *ctxp_for_generation;
+
+#endif /* ! GCC_JAVA_PARSE_H */