OSDN Git Service

2001-12-13 Aldy Hernandez <aldyh@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / c-parse.in
index 28ac2b5..4967a09 100644 (file)
@@ -50,7 +50,6 @@ end ifc
 #include "output.h"
 #include "toplev.h"
 #include "ggc.h"
-#include "diagnostic.h"  
   
 #ifdef MULTIBYTE_CHARS
 #include <locale.h>
@@ -60,15 +59,6 @@ ifobjc
 #include "objc-act.h"
 end ifobjc
 
-/* Since parsers are distinct for each language, put the language string
-   definition here.  */
-ifobjc
-const char * const language_string = "GNU Objective-C";
-end ifobjc
-ifc
-const char * const language_string = "GNU C";
-end ifc
-
 /* Like YYERROR but do call yyerror.  */
 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
 
@@ -121,7 +111,7 @@ end ifc
 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
 %token ATTRIBUTE EXTENSION LABEL
-%token REALPART IMAGPART VA_ARG
+%token REALPART IMAGPART VA_ARG CHOOSE_EXPR TYPES_COMPATIBLE_P
 %token PTR_VALUE PTR_BASE PTR_EXTENT
 
 /* function name can be a string const or a var decl. */
@@ -313,6 +303,8 @@ static void init_reswords PARAMS ((void));
 void
 c_parse_init ()
 {
+  init_reswords ();
+
   ggc_add_tree_root (&declspec_stack, 1);
   ggc_add_tree_root (&current_declspecs, 1);
   ggc_add_tree_root (&prefix_attributes, 1);
@@ -605,8 +597,7 @@ expr_no_commas:
                { char class;
                  $$ = build_modify_expr ($1, NOP_EXPR, $3);
                  class = TREE_CODE_CLASS (TREE_CODE ($$));
-                 if (class == 'e' || class == '1'
-                     || class == '2' || class == '<')
+                 if (IS_EXPR_CODE_CLASS (class))
                    C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
                }
        | expr_no_commas ASSIGN expr_no_commas
@@ -614,8 +605,7 @@ expr_no_commas:
                  $$ = build_modify_expr ($1, $2, $3);
                  /* This inhibits warnings in truthvalue_conversion.  */
                  class = TREE_CODE_CLASS (TREE_CODE ($$));
-                 if (class == 'e' || class == '1'
-                     || class == '2' || class == '<')
+                 if (IS_EXPR_CODE_CLASS (class))
                    C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
                }
        ;
@@ -637,34 +627,17 @@ primary:
                  $2 = groktypename ($2);
                  really_start_incremental_init ($2); }
          initlist_maybe_comma '}'  %prec UNARY
-               { const char *name;
-                 tree result = pop_init_level (0);
+               { tree constructor = pop_init_level (0);
                  tree type = $2;
                  finish_init ();
 
                  if (pedantic && ! flag_isoc99)
                    pedwarn ("ISO C89 forbids compound literals");
-                 if (TYPE_NAME (type) != 0)
-                   {
-                     if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
-                       name = IDENTIFIER_POINTER (TYPE_NAME (type));
-                     else
-                       name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
-                   }
-                 else
-                   name = "";
-                 $$ = result;
-                 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
-                   {
-                     int failure = complete_array_type (type, $$, 1);
-                     if (failure)
-                       abort ();
-                   }
+                 $$ = build_compound_literal (type, constructor);
                }
        | '(' expr ')'
                { char class = TREE_CODE_CLASS (TREE_CODE ($2));
-                 if (class == 'e' || class == '1'
-                     || class == '2' || class == '<')
+                 if (IS_EXPR_CODE_CLASS (class))
                    C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
                  $$ = $2; }
        | '(' error ')'
@@ -696,6 +669,26 @@ primary:
                { $$ = build_function_call ($1, $3); }
        | VA_ARG '(' expr_no_commas ',' typename ')'
                { $$ = build_va_arg ($3, groktypename ($5)); }
+      | CHOOSE_EXPR '(' expr_no_commas ',' expr_no_commas ',' expr_no_commas ')'
+               {
+                  tree c;
+
+                  c = fold ($3);
+                  STRIP_NOPS (c);
+                  if (TREE_CODE (c) != INTEGER_CST)
+                    error ("first argument to __builtin_choose_expr not a constant");
+                  $$ = integer_zerop (c) ? $7 : $5;
+               }
+      | TYPES_COMPATIBLE_P '(' typename ',' typename ')'
+               {
+                 tree e1, e2;
+
+                 e1 = TYPE_MAIN_VARIANT (groktypename ($3));
+                 e2 = TYPE_MAIN_VARIANT (groktypename ($5));
+
+                 $$ = comptypes (e1, e2)
+                   ? build_int_2 (1, 0) : build_int_2 (0, 0);
+               }
        | primary '[' expr ']'   %prec '.'
                { $$ = build_array_ref ($1, $3); }
        | primary '.' identifier
@@ -1812,7 +1805,7 @@ ifobjc
                    $$ = get_class_ivars (interface);
                  else
                    {
-                     error ("Cannot find interface declaration for `%s'",
+                     error ("cannot find interface declaration for `%s'",
                             IDENTIFIER_POINTER ($3));
                      $$ = NULL_TREE;
                    }
@@ -2256,7 +2249,7 @@ lineno_stmt:
                      /* ??? We currently have no way of recording
                         the filename for a statement.  This probably
                         matters little in practice at the moment,
-                        but I suspect that problems will ocurr when
+                        but I suspect that problems will occur when
                         doing inlining at the tree level.  */
                    }
                }
@@ -2454,7 +2447,9 @@ nonnull_asm_operands:
 
 asm_operand:
          STRING '(' expr ')'
-               { $$ = build_tree_list ($1, $3); }
+               { $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $3); }
+       | '[' identifier ']' STRING '(' expr ')'
+               { $$ = build_tree_list (build_tree_list ($2, $4), $6); }
        ;
 
 asm_clobbers:
@@ -3274,6 +3269,8 @@ static const struct resword reswords[] =
   { "__attribute__",   RID_ATTRIBUTE,  0 },
   { "__bounded",       RID_BOUNDED,    0 },
   { "__bounded__",     RID_BOUNDED,    0 },
+  { "__builtin_choose_expr", RID_CHOOSE_EXPR, 0 },
+  { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, 0 },
   { "__builtin_va_arg",        RID_VA_ARG,     0 },
   { "__complex",       RID_COMPLEX,    0 },
   { "__complex__",     RID_COMPLEX,    0 },
@@ -3446,6 +3443,9 @@ static const short rid_to_yy[RID_MAX] =
   /* RID_PTREXTENT */  PTR_EXTENT,
   /* RID_PTRVALUE */   PTR_VALUE,
 
+  /* RID_CHOOSE_EXPR */                        CHOOSE_EXPR,
+  /* RID_TYPES_COMPATIBLE_P */         TYPES_COMPATIBLE_P,
+
   /* RID_FUNCTION_NAME */              STRING_FUNC_NAME,
   /* RID_PRETTY_FUNCTION_NAME */       STRING_FUNC_NAME,
   /* RID_C99_FUNCTION_NAME */          VAR_FUNC_NAME,
@@ -3538,29 +3538,6 @@ init_reswords ()
     }
 }
 
-const char *
-init_parse (filename)
-     const char *filename;
-{
-  add_c_tree_codes ();
-
-  /* Make identifier nodes long enough for the language-specific slots.  */
-  set_identifier_size (sizeof (struct lang_identifier));
-
-  init_reswords ();
-  init_pragma ();
-
-  return init_c_lex (filename);
-}
-
-void
-finish_parse ()
-{
-  cpp_finish (parse_in);
-  /* Call to cpp_destroy () omitted for performance reasons.  */
-  errorcount += cpp_errors (parse_in);
-}
-
 #define NAME(type) cpp_type2name (type)
 
 static void
@@ -3627,6 +3604,7 @@ end ifobjc
            const char *name = fname_string (rid_code);
          
            yylval.ttype = build_string (strlen (name) + 1, name);
+           C_ARTIFICIAL_STRING_P (yylval.ttype) = 1;
            last_token = CPP_STRING;  /* so yyerror won't choke */
            return STRING;
          }
@@ -3798,13 +3776,13 @@ yylex()
    in order to build the compiler.  */
 
 void
-set_yydebug (value)
+c_set_yydebug (value)
      int value;
 {
 #if YYDEBUG != 0
   yydebug = value;
 #else
-  warning ("YYDEBUG not defined.");
+  warning ("YYDEBUG not defined");
 #endif
 }