OSDN Git Service

[gcc/ChangeLog]
[pf3gnuchains/gcc-fork.git] / gcc / c-parse.in
index 1317889..d45ff5e 100644 (file)
@@ -127,6 +127,10 @@ do {                                                                       \
    yylval contains an IDENTIFIER_NODE which indicates which one.  */
 %token TYPE_QUAL
 
+/* Objective-C protocol qualifiers.  These acquire their magic powers
+   only in certain contexts.  */
+%token OBJC_TYPE_QUAL
+
 /* Character or numeric constants.
    yylval is the node for the constant.  */
 %token CONSTANT
@@ -271,6 +275,9 @@ static GTY(()) tree all_prefix_attributes;
    all_prefix_attributes.  */
 static GTY(()) tree declspec_stack;
 
+/* INDIRECT_REF with a TREE_TYPE of the type being queried for offsetof.  */
+static tree offsetof_base;
+
 /* PUSH_DECLSPEC_STACK is called from setspecs; POP_DECLSPEC_STACK
    should be called from the productions making use of setspecs.  */
 #define PUSH_DECLSPEC_STACK                                             \
@@ -677,8 +684,15 @@ primary:
                { $$.value = build_va_arg ($3.value, groktypename ($5));
                  $$.original_code = ERROR_MARK; }
 
-       | OFFSETOF '(' typename ',' offsetof_member_designator ')'
-               { $$.value = build_offsetof (groktypename ($3), $5);
+       | OFFSETOF '(' typename ','
+               { tree type = groktypename ($3);
+                 if (type == error_mark_node)
+                   offsetof_base = error_mark_node;
+                 else
+                   offsetof_base = build1 (INDIRECT_REF, type, NULL);
+               }
+         offsetof_member_designator ')'
+               { $$.value = fold_offsetof ($6);
                  $$.original_code = ERROR_MARK; }
        | OFFSETOF '(' error ')'
                { $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
@@ -704,7 +718,8 @@ primary:
                  e2 = TYPE_MAIN_VARIANT (groktypename ($5));
 
                  $$.value = comptypes (e1, e2)
-                   ? build_int_2 (1, 0) : build_int_2 (0, 0);
+                   ? build_int_cst (NULL_TREE, 1)
+                   : build_int_cst (NULL_TREE, 0);
                  $$.original_code = ERROR_MARK;
                }
        | TYPES_COMPATIBLE_P '(' error ')'
@@ -729,36 +744,34 @@ primary:
                  $$.original_code = ERROR_MARK; }
 @@ifobjc
        | objcmessageexpr
-               { $$.value = build_message_expr ($1);
+               { $$.value = objc_build_message_expr ($1);
                  $$.original_code = ERROR_MARK; }
        | objcselectorexpr
-               { $$.value = build_selector_expr ($1);
+               { $$.value = objc_build_selector_expr ($1);
                  $$.original_code = ERROR_MARK; }
        | objcprotocolexpr
-               { $$.value = build_protocol_expr ($1);
+               { $$.value = objc_build_protocol_expr ($1);
                  $$.original_code = ERROR_MARK; }
        | objcencodeexpr
-               { $$.value = build_encode_expr ($1);
+               { $$.value = objc_build_encode_expr ($1);
                  $$.original_code = ERROR_MARK; }
        | OBJC_STRING
-               { $$.value = build_objc_string_object ($1);
+               { $$.value = objc_build_string_object ($1);
                  $$.original_code = ERROR_MARK; }
 @@end_ifobjc
        ;
 
 /* This is the second argument to __builtin_offsetof.  We must have one
    identifier, and beyond that we want to accept sub structure and sub
-   array references.  We return tree list where each element has
-   PURPOSE set for component refs or VALUE set for array refs.  We'll
-   turn this into something real inside build_offsetof.  */
+   array references.  */
 
 offsetof_member_designator:
          identifier
-               { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
+               { $$ = build_component_ref (offsetof_base, $1); }
        | offsetof_member_designator '.' identifier
-               { $$ = tree_cons ($3, NULL_TREE, $1); }
+               { $$ = build_component_ref ($1, $3); }
        | offsetof_member_designator '[' expr ']'
-               { $$ = tree_cons (NULL_TREE, $3.value, $1); }
+               { $$ = build_array_ref ($1, $3.value); }
        ;
 
 old_style_parm_decls:
@@ -1388,7 +1401,7 @@ notype_initdecls:
 
 initdcl:
          declarator maybeasm maybe_attribute '='
-               { $<ttype>$ = start_decl ($1, current_declspecs, 1,
+               { $<ttype>$ = start_decl ($1, current_declspecs, true,
                                          chainon ($3, all_prefix_attributes));
                  start_init ($<ttype>$, $2, global_bindings_p ()); }
          init
@@ -1397,7 +1410,7 @@ initdcl:
                  maybe_warn_string_init (TREE_TYPE ($<ttype>5), $6);
                  finish_decl ($<ttype>5, $6.value, $2); }
        | declarator maybeasm maybe_attribute
-               { tree d = start_decl ($1, current_declspecs, 0,
+               { tree d = start_decl ($1, current_declspecs, false,
                                       chainon ($3, all_prefix_attributes));
                  finish_decl (d, NULL_TREE, $2);
                 }
@@ -1405,7 +1418,7 @@ initdcl:
 
 notype_initdcl:
          notype_declarator maybeasm maybe_attribute '='
-               { $<ttype>$ = start_decl ($1, current_declspecs, 1,
+               { $<ttype>$ = start_decl ($1, current_declspecs, true,
                                          chainon ($3, all_prefix_attributes));
                  start_init ($<ttype>$, $2, global_bindings_p ()); }
          init
@@ -1414,7 +1427,7 @@ notype_initdcl:
                  maybe_warn_string_init (TREE_TYPE ($<ttype>5), $6);
                  finish_decl ($<ttype>5, $6.value, $2); }
        | notype_declarator maybeasm maybe_attribute
-               { tree d = start_decl ($1, current_declspecs, 0,
+               { tree d = start_decl ($1, current_declspecs, false,
                                       chainon ($3, all_prefix_attributes));
                  finish_decl (d, NULL_TREE, $2); }
        ;
@@ -1619,11 +1632,11 @@ declarator:
 
 after_type_declarator:
          '(' maybe_attribute after_type_declarator ')'
-               { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
+               { $$ = $2 ? build_attrs_declarator ($2, $3) : $3; }
        | after_type_declarator '(' parmlist_or_identifiers  %prec '.'
-               { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
+               { $$ = build_function_declarator ($3, $1); }
        | after_type_declarator array_declarator  %prec '.'
-               { $$ = set_array_declarator_type ($2, $1, 0); }
+               { $$ = set_array_declarator_inner ($2, $1, false); }
        | '*' maybe_type_quals_attrs after_type_declarator  %prec UNARY
                { $$ = make_pointer_declarator ($2, $3); }
        | TYPENAME
@@ -1643,9 +1656,9 @@ parm_declarator:
 
 parm_declarator_starttypename:
          parm_declarator_starttypename '(' parmlist_or_identifiers  %prec '.'
-               { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
+               { $$ = build_function_declarator ($3, $1); }
        | parm_declarator_starttypename array_declarator  %prec '.'
-               { $$ = set_array_declarator_type ($2, $1, 0); }
+               { $$ = set_array_declarator_inner ($2, $1, false); }
        | TYPENAME
 @@ifobjc
        | OBJECTNAME
@@ -1654,15 +1667,15 @@ parm_declarator_starttypename:
 
 parm_declarator_nostarttypename:
          parm_declarator_nostarttypename '(' parmlist_or_identifiers  %prec '.'
-               { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
+               { $$ = build_function_declarator ($3, $1); }
        | parm_declarator_nostarttypename array_declarator  %prec '.'
-               { $$ = set_array_declarator_type ($2, $1, 0); }
+               { $$ = set_array_declarator_inner ($2, $1, false); }
        | '*' maybe_type_quals_attrs parm_declarator_starttypename  %prec UNARY
                { $$ = make_pointer_declarator ($2, $3); }
        | '*' maybe_type_quals_attrs parm_declarator_nostarttypename  %prec UNARY
                { $$ = make_pointer_declarator ($2, $3); }
        | '(' maybe_attribute parm_declarator_nostarttypename ')'
-               { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
+               { $$ = $2 ? build_attrs_declarator ($2, $3) : $3; }
        ;
 
 /* A declarator allowed whether or not there has been
@@ -1670,13 +1683,13 @@ parm_declarator_nostarttypename:
 
 notype_declarator:
          notype_declarator '(' parmlist_or_identifiers  %prec '.'
-               { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
+               { $$ = build_function_declarator ($3, $1); }
        | '(' maybe_attribute notype_declarator ')'
-               { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
+               { $$ = $2 ? build_attrs_declarator ($2, $3) : $3; }
        | '*' maybe_type_quals_attrs notype_declarator  %prec UNARY
                { $$ = make_pointer_declarator ($2, $3); }
        | notype_declarator array_declarator  %prec '.'
-               { $$ = set_array_declarator_type ($2, $1, 0); }
+               { $$ = set_array_declarator_inner ($2, $1, false); }
        | IDENTIFIER
        ;
 
@@ -1795,7 +1808,7 @@ component_decl_list2:     /* empty */
 @@ifobjc
        /* foo(sizeof(struct{ @defs(ClassName)})); */
        | AT_DEFS '(' CLASSNAME ')'
-               { $$ = nreverse (get_class_ivars_from_name ($3)); }
+               { $$ = nreverse (objc_get_class_ivars ($3)); }
 @@end_ifobjc
        ;
 
@@ -1908,17 +1921,15 @@ absdcl:   /* an absolute declarator */
 
 absdcl_maybe_attribute:   /* absdcl maybe_attribute, but not just attributes */
        /* empty */
-               { $$ = build_tree_list (build_tree_list (current_declspecs,
-                                                        NULL_TREE),
-                                       all_prefix_attributes); }
+               { $$ = build_c_parm (current_declspecs, all_prefix_attributes,
+                                    NULL_TREE); }
        | absdcl1
-               { $$ = build_tree_list (build_tree_list (current_declspecs,
-                                                        $1),
-                                       all_prefix_attributes); }
+               { $$ = build_c_parm (current_declspecs, all_prefix_attributes,
+                                    $1); }
        | absdcl1_noea attributes
-               { $$ = build_tree_list (build_tree_list (current_declspecs,
-                                                        $1),
-                                       chainon ($2, all_prefix_attributes)); }
+               { $$ = build_c_parm (current_declspecs,
+                                    chainon ($2, all_prefix_attributes),
+                                    $1); }
        ;
 
 absdcl1:  /* a nonempty absolute declarator */
@@ -1941,31 +1952,31 @@ absdcl1_ea:
 
 direct_absdcl1:
          '(' maybe_attribute absdcl1 ')'
-               { $$ = $2 ? tree_cons ($2, $3, NULL_TREE) : $3; }
+               { $$ = $2 ? build_attrs_declarator ($2, $3) : $3; }
        | direct_absdcl1 '(' parmlist
-               { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
+               { $$ = build_function_declarator ($3, $1); }
        | direct_absdcl1 array_declarator
-               { $$ = set_array_declarator_type ($2, $1, 1); }
+               { $$ = set_array_declarator_inner ($2, $1, true); }
        | '(' parmlist
-               { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
+               { $$ = build_function_declarator ($2, NULL_TREE); }
        | array_declarator
-               { $$ = set_array_declarator_type ($1, NULL_TREE, 1); }
+               { $$ = set_array_declarator_inner ($1, NULL_TREE, true); }
        ;
 
 /* The [...] part of a declarator for an array type.  */
 
 array_declarator:
        '[' maybe_type_quals_attrs expr_no_commas ']'
-               { $$ = build_array_declarator ($3.value, $2, 0, 0); }
+               { $$ = build_array_declarator ($3.value, $2, false, false); }
        | '[' maybe_type_quals_attrs ']'
-               { $$ = build_array_declarator (NULL_TREE, $2, 0, 0); }
+               { $$ = build_array_declarator (NULL_TREE, $2, false, false); }
        | '[' maybe_type_quals_attrs '*' ']'
-               { $$ = build_array_declarator (NULL_TREE, $2, 0, 1); }
+               { $$ = build_array_declarator (NULL_TREE, $2, false, true); }
        | '[' STATIC maybe_type_quals_attrs expr_no_commas ']'
-               { $$ = build_array_declarator ($4.value, $3, 1, 0); }
+               { $$ = build_array_declarator ($4.value, $3, true, false); }
        /* declspecs_nosc_nots is a synonym for type_quals_attrs.  */
        | '[' declspecs_nosc_nots STATIC expr_no_commas ']'
-               { $$ = build_array_declarator ($4.value, $2, 1, 0); }
+               { $$ = build_array_declarator ($4.value, $2, true, false); }
        ;
 
 /* A nonempty series of declarations and statements (possibly followed by
@@ -2525,22 +2536,19 @@ parms:
    as found in a parmlist.  */
 parm:
          declspecs_ts setspecs parm_declarator maybe_attribute
-               { $$ = build_tree_list (build_tree_list (current_declspecs,
-                                                        $3),
-                                       chainon ($4, all_prefix_attributes));
+               { $$ = build_c_parm (current_declspecs,
+                                    chainon ($4, all_prefix_attributes), $3);
                  POP_DECLSPEC_STACK; }
        | declspecs_ts setspecs notype_declarator maybe_attribute
-               { $$ = build_tree_list (build_tree_list (current_declspecs,
-                                                        $3),
-                                       chainon ($4, all_prefix_attributes));
+               { $$ = build_c_parm (current_declspecs,
+                                    chainon ($4, all_prefix_attributes), $3);
                  POP_DECLSPEC_STACK; }
        | declspecs_ts setspecs absdcl_maybe_attribute
                { $$ = $3;
                  POP_DECLSPEC_STACK; }
        | declspecs_nots setspecs notype_declarator maybe_attribute
-               { $$ = build_tree_list (build_tree_list (current_declspecs,
-                                                        $3),
-                                       chainon ($4, all_prefix_attributes));
+               { $$ = build_c_parm (current_declspecs,
+                                    chainon ($4, all_prefix_attributes), $3);
                  POP_DECLSPEC_STACK; }
 
        | declspecs_nots setspecs absdcl_maybe_attribute
@@ -2552,22 +2560,19 @@ parm:
    stack.  */
 firstparm:
          declspecs_ts_nosa setspecs_fp parm_declarator maybe_attribute
-               { $$ = build_tree_list (build_tree_list (current_declspecs,
-                                                        $3),
-                                       chainon ($4, all_prefix_attributes));
+               { $$ = build_c_parm (current_declspecs,
+                                    chainon ($4, all_prefix_attributes), $3);
                  POP_DECLSPEC_STACK; }
        | declspecs_ts_nosa setspecs_fp notype_declarator maybe_attribute
-               { $$ = build_tree_list (build_tree_list (current_declspecs,
-                                                        $3),
-                                       chainon ($4, all_prefix_attributes));
+               { $$ = build_c_parm (current_declspecs,
+                                    chainon ($4, all_prefix_attributes), $3);
                  POP_DECLSPEC_STACK; }
        | declspecs_ts_nosa setspecs_fp absdcl_maybe_attribute
                { $$ = $3;
                  POP_DECLSPEC_STACK; }
        | declspecs_nots_nosa setspecs_fp notype_declarator maybe_attribute
-               { $$ = build_tree_list (build_tree_list (current_declspecs,
-                                                        $3),
-                                       chainon ($4, all_prefix_attributes));
+               { $$ = build_c_parm (current_declspecs,
+                                    chainon ($4, all_prefix_attributes), $3);
                  POP_DECLSPEC_STACK; }
 
        | declspecs_nots_nosa setspecs_fp absdcl_maybe_attribute
@@ -2596,17 +2601,10 @@ parmlist_or_identifiers:
 parmlist_or_identifiers_1:
          parmlist_1
        | identifiers ')'
-               { tree t;
-                 for (t = $1; t; t = TREE_CHAIN (t))
-                   if (TREE_VALUE (t) == NULL_TREE)
-                     error ("`...' in old-style identifier list");
-                 $$ = tree_cons (NULL_TREE, NULL_TREE, $1);
+               { $$ = tree_cons (NULL_TREE, NULL_TREE, $1);
 
                  /* Make sure we have a parmlist after attributes.  */
-                 if ($<ttype>-1 != 0
-                     && (TREE_CODE ($$) != TREE_LIST
-                         || TREE_PURPOSE ($$) == 0
-                         || TREE_CODE (TREE_PURPOSE ($$)) != PARM_DECL))
+                 if ($<ttype>-1 != 0)
                    YYERROR1;
                }
        ;
@@ -3049,22 +3047,22 @@ reservedwords:
 keyworddecl:
          selector ':' '(' typename ')' identifier
                {
-                 $$ = build_keyword_decl ($1, $4, $6);
+                 $$ = objc_build_keyword_decl ($1, $4, $6);
                }
 
        | selector ':' identifier
                {
-                 $$ = build_keyword_decl ($1, NULL_TREE, $3);
+                 $$ = objc_build_keyword_decl ($1, NULL_TREE, $3);
                }
 
        | ':' '(' typename ')' identifier
                {
-                 $$ = build_keyword_decl (NULL_TREE, $3, $5);
+                 $$ = objc_build_keyword_decl (NULL_TREE, $3, $5);
                }
 
        | ':' identifier
                {
-                 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
+                 $$ = objc_build_keyword_decl (NULL_TREE, NULL_TREE, $2);
                }
        ;
 
@@ -3110,11 +3108,11 @@ receiver:
                { $$ = $1.value; }
        | CLASSNAME
                {
-                 $$ = get_class_reference ($1);
+                 $$ = objc_get_class_reference ($1);
                }
        | TYPENAME
                {
-                 $$ = get_class_reference ($1);
+                 $$ = objc_get_class_reference ($1);
                }
        ;
 
@@ -3273,6 +3271,7 @@ static const struct resword reswords[] =
   { "void",            RID_VOID,       0 },
   { "volatile",                RID_VOLATILE,   0 },
   { "while",           RID_WHILE,      0 },
+
 @@ifobjc
   { "id",              RID_ID,                 D_OBJC },
 
@@ -3517,7 +3516,7 @@ yylexname (void)
 @@ifobjc
   else
     {
-      tree objc_interface_decl = is_class_name (yylval.ttype);
+      tree objc_interface_decl = objc_is_class_name (yylval.ttype);
       /* ObjC class names are in the same namespace as variables and
         typedefs, and hence are shadowed by local declarations.  */
       if (objc_interface_decl