OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / java / parse.y
index 9985c73..2ea7af0 100644 (file)
@@ -1888,7 +1888,7 @@ catch_clause_parameter:
                  tree ccpb = enter_block ();
                  tree init = build_assignment
                    (ASSIGN_TK, $2.location, TREE_PURPOSE ($3), 
-                    build_exception_object_ref (ptr_type_node));
+                    build (JAVA_EXC_OBJ_EXPR, ptr_type_node));
                  declare_local_variables (0, TREE_VALUE ($3),
                                           build_tree_list (TREE_PURPOSE ($3),
                                                            init));
@@ -1954,9 +1954,12 @@ type_literals:
 |      array_type DOT_TK CLASS_TK
                { $$ = build_incomplete_class_ref ($2.location, $1); }
 |      primitive_type DOT_TK CLASS_TK
-               { $$ = build_class_ref ($1); }
+                { $$ = build_incomplete_class_ref ($2.location, $1); }
 |      VOID_TK DOT_TK CLASS_TK
-               { $$ = build_class_ref (void_type_node); }
+                { 
+                   $$ = build_incomplete_class_ref ($2.location,
+                                                   void_type_node);
+                }
 ;
 
 class_instance_creation_expression:
@@ -4079,7 +4082,7 @@ lookup_field_wrapper (class, name)
   /* Last chance: if we're within the context of an inner class, we
      might be trying to access a local variable defined in an outer
      context. We try to look for it now. */
-  if (INNER_CLASS_TYPE_P (class))
+  if (INNER_CLASS_TYPE_P (class) && TREE_CODE (name) == IDENTIFIER_NODE)
     {
       tree new_name;
       MANGLE_OUTER_LOCAL_VARIABLE_NAME (new_name, name);
@@ -5522,13 +5525,14 @@ tree
 do_resolve_class (enclosing, class_type, decl, cl)
      tree enclosing, class_type, decl, cl;
 {
-  tree new_class_decl;
+  tree new_class_decl, super, start;
 
   /* Do not try to replace TYPE_NAME (class_type) by a variable, since
      it is changed by find_in_imports{_on_demand} and (but it doesn't
      really matter) qualify_and_find */
 
   /* 0- Search in the current class as an inner class */
+  start = enclosing;
 
   /* Maybe some code here should be added to load the class or
      something, at least if the class isn't an inner class and ended
@@ -5551,14 +5555,28 @@ do_resolve_class (enclosing, class_type, decl, cl)
        }
 
       /* Now go to the upper classes, bail out if necessary. */
-      enclosing = CLASSTYPE_SUPER (TREE_TYPE (enclosing));
-      if (!enclosing || enclosing == object_type_node)
+      super = CLASSTYPE_SUPER (TREE_TYPE (enclosing));
+      if (!super || super == object_type_node)
         break;
 
-      if (TREE_CODE (enclosing) == POINTER_TYPE)
-       enclosing = do_resolve_class (NULL, enclosing, NULL, NULL);
+      if (TREE_CODE (super) == POINTER_TYPE)
+        super = do_resolve_class (NULL, super, NULL, NULL);
       else
-        enclosing = TYPE_NAME (enclosing);
+       super = TYPE_NAME (super);
+      /* We may not have checked for circular inheritance yet, so do so
+         here to prevent an infinite loop. */
+      if (super == start)
+        {
+          if (!cl)
+            cl = lookup_cl (decl);
+         
+          parse_error_context
+            (cl, "Cyclic inheritance involving %s",
+            IDENTIFIER_POINTER (DECL_NAME (enclosing)));
+          break;
+        }
+      enclosing = super;
     }
 
   /* 1- Check for the type in single imports. This will change
@@ -8415,7 +8433,7 @@ build_dot_class_method (class)
   
   /* We initialize the variable with the exception handler. */
   catch = build (MODIFY_EXPR, NULL_TREE, catch_clause_param,
-                build_exception_object_ref (ptr_type_node));
+                build (JAVA_EXC_OBJ_EXPR, ptr_type_node));
   add_stmt_to_block (catch_block, NULL_TREE, catch);
 
   /* We add the statement throwing the new exception */
@@ -9206,7 +9224,8 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
       previous_call_static = 0;
 
       /* It can be the keyword THIS */
-      if (EXPR_WFL_NODE (qual_wfl) == this_identifier_node)
+      if (TREE_CODE (qual_wfl) == EXPR_WITH_FILE_LOCATION
+         && EXPR_WFL_NODE (qual_wfl) == this_identifier_node)
        {
          if (!current_this)
            {
@@ -9257,7 +9276,8 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
        }
 
       /* 15.10.2 Accessing Superclass Members using SUPER */
-      if (EXPR_WFL_NODE (qual_wfl) == super_identifier_node)
+      if (TREE_CODE (qual_wfl) == EXPR_WITH_FILE_LOCATION
+         && EXPR_WFL_NODE (qual_wfl) == super_identifier_node)
        {
          tree node;
          /* Check on the restricted use of SUPER */
@@ -10829,6 +10849,10 @@ qualify_ambiguous_name (id)
     else if (code == INTEGER_CST)
       name = qual_wfl;
     
+    else if (code == CONVERT_EXPR &&
+            TREE_CODE (TREE_OPERAND (qual_wfl, 0)) == EXPR_WITH_FILE_LOCATION)
+      name = TREE_OPERAND (qual_wfl, 0);
+    
     else if ((code == ARRAY_REF || code == CALL_EXPR || code == MODIFY_EXPR) &&
             TREE_CODE (TREE_OPERAND (qual_wfl, 0)) == EXPR_WITH_FILE_LOCATION)
       name = EXPR_WFL_NODE (TREE_OPERAND (qual_wfl, 0));
@@ -10843,7 +10867,7 @@ qualify_ambiguous_name (id)
        qual_wfl = QUAL_WFL (qual);
        again = 1;
       }
-    else 
+    else
       {
        name = EXPR_WFL_NODE (qual_wfl);
        if (!name)
@@ -10871,8 +10895,10 @@ qualify_ambiguous_name (id)
        qual_wfl = QUAL_WFL (qual);
        if (TREE_CODE (qual_wfl) == CALL_EXPR)
          again = 1;
-       else
+       else if (TREE_CODE (qual_wfl) == EXPR_WITH_FILE_LOCATION)
          name = EXPR_WFL_NODE (qual_wfl);
+       else if (TREE_CODE (qual_wfl) == NEW_CLASS_EXPR)
+         name = TREE_OPERAND (qual_wfl, 0);
        this_found = 1;
       }
     /* If we have a SUPER, we set the context accordingly */
@@ -12393,6 +12419,7 @@ maybe_build_primttype_type_ref (rhs, wfl)
       if (TREE_CODE (n) == VAR_DECL 
          && DECL_NAME (n) == TYPE_identifier_node
          && rhs_type == class_ptr_type
+         && TREE_CODE (wfl) == EXPR_WITH_FILE_LOCATION
          && TREE_CODE (EXPR_WFL_NODE (wfl)) == IDENTIFIER_NODE)
        {
          const char *self_name = IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl));
@@ -12541,12 +12568,15 @@ patch_assignment (node, wfl_op1, wfl_op2)
        base = TREE_OPERAND (lvalue, 0);
       else
        {
-         base = TREE_OPERAND (base, 0);
-         if (flag_bounds_check)
-           base = TREE_OPERAND (base, 1);
-         if (flag_check_references)
-           base = TREE_OPERAND (base, 1);
-         base = TREE_OPERAND (base, 0);        
+          tree op = TREE_OPERAND (base, 0);
+         
+          /* We can have a SAVE_EXPR here when doing String +=.  */
+          if (TREE_CODE (op) == SAVE_EXPR)
+            op = TREE_OPERAND (op, 0);
+          if (flag_bounds_check)
+            base = TREE_OPERAND (TREE_OPERAND (op, 1), 0);
+          else
+            base = TREE_OPERAND (op, 0);
        }
 
       /* Build the invocation of _Jv_CheckArrayStore */
@@ -12572,16 +12602,31 @@ patch_assignment (node, wfl_op1, wfl_op2)
            TREE_OPERAND (lvalue, 1) = build (COMPOUND_EXPR, lhs_type,
                                              check, TREE_OPERAND (lvalue, 1));
        }
-      else 
+      else if (flag_bounds_check)
        {
+          tree hook = lvalue;
+          tree compound = TREE_OPERAND (lvalue, 0);
+          tree bound_check, new_compound;
+
+          if (TREE_CODE (compound) == SAVE_EXPR)
+            {
+              compound = TREE_OPERAND (compound, 0);
+              hook = TREE_OPERAND (hook, 0);
+            }
+
+          /* Find the array bound check, hook the original array access. */
+          bound_check = TREE_OPERAND (compound, 0);
+          TREE_OPERAND (hook, 0) = TREE_OPERAND (compound, 1);
+
          /* Make sure the bound check will happen before the store check */
-         if (flag_bounds_check)
-           TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0) =
-             build (COMPOUND_EXPR, void_type_node,
-                    TREE_OPERAND (TREE_OPERAND (lvalue, 0), 0), check);
-         else
-           lvalue = build (COMPOUND_EXPR, lhs_type, check, lvalue);
-       }
+          new_compound =
+            build (COMPOUND_EXPR, void_type_node, bound_check, check);
+
+          /* Re-assemble the augmented array access. */
+          lvalue = build (COMPOUND_EXPR, lhs_type, new_compound, lvalue);
+        }
+      else
+        lvalue = build (COMPOUND_EXPR, lhs_type, check, lvalue);
     }
 
   /* Final locals can be used as case values in switch
@@ -12624,7 +12669,7 @@ try_reference_assignconv (lhs_type, rhs)
       else if (valid_ref_assignconv_cast_p (rhs_type, lhs_type, 0))
        new_rhs = rhs;
       /* This is a magic assignment that we process differently */
-      else if (TREE_CODE (rhs) == EXC_PTR_EXPR)
+      else if (TREE_CODE (rhs) == JAVA_EXC_OBJ_EXPR)
        new_rhs = rhs;
     }
   return new_rhs;
@@ -13749,8 +13794,11 @@ patch_incomplete_class_ref (node)
 
   if (!flag_emit_class_files || JPRIMITIVE_TYPE_P (ref_type))
     {
+      tree dot = build_class_ref (ref_type);
       /* A class referenced by `foo.class' is initialized.  */
-      return build_class_init (ref_type, build_class_ref (ref_type));
+      if (!flag_emit_class_files)
+       dot = build_class_init (ref_type, dot);
+      return java_complete_tree (dot);
     }
 
   /* If we're emitting class files and we have to deal with non