home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / objc-parse.y-diffs < prev    next >
Text File  |  1991-06-19  |  33KB  |  1,250 lines

  1. *** c-parse.y    Wed Jun 12 15:26:45 1991
  2. --- objc-parse.y    Wed Jun 19 13:26:42 1991
  3. ***************
  4. *** 1,5 ****
  5. --- 1,6 ----
  6.   /* YACC parser for C syntax.
  7.      Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  8. +    Objective-C extensions by s.naroff.
  9.   
  10.   This file is part of GNU CC.
  11.   
  12. ***************
  13. *** 48,53 ****
  14. --- 49,56 ----
  15.   #include "c-tree.h"
  16.   #include "flags.h"
  17.   
  18. + #include "objc-actions.h"
  19.   #ifdef MULTIBYTE_CHARS
  20.   #include <stdlib.h>
  21.   #include <locale.h>
  22. ***************
  23. *** 117,122 ****
  24. --- 120,129 ----
  25.   %token BREAK CONTINUE RETURN GOTO ASM TYPEOF ALIGNOF ALIGN
  26.   %token ATTRIBUTE EXTENSION LABEL
  27.   
  28. + /* the Objective-C keywords */
  29. + %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
  30. + %token CLASSNAME PUBLIC
  31.   /* Add precedence rules to solve dangling else s/r conflict */
  32.   %nonassoc IF
  33.   %nonassoc ELSE
  34. ***************
  35. *** 174,179 ****
  36. --- 181,196 ----
  37.   %type <filename> save_filename
  38.   %type <lineno> save_lineno
  39.   
  40. + /* the Objective-C nonterminals */
  41. + %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
  42. + %type <ttype> methoddecl unaryselector keywordselector selector
  43. + %type <ttype> keyworddecl receiver objcmessageexpr messageargs
  44. + %type <ttype> keywordexpr keywordarglist keywordarg
  45. + %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
  46. + %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
  47. + %type <ttype> CLASSNAME
  48.   %{
  49.   /* the declaration found for the last IDENTIFIER token read in.
  50.      yylex must look this up to detect typedefs, which get token type TYPENAME,
  51. ***************
  52. *** 202,207 ****
  53. --- 219,238 ----
  54.   
  55.   static int yylex ();
  56.   
  57. + /* Objective-C specific information */
  58. + static tree objc_interface_context;
  59. + static tree objc_implementation_context;
  60. + static tree objc_method_context;
  61. + static tree objc_ivar_chain;
  62. + static tree objc_ivar_context;
  63. + static enum tree_code objc_inherit_code;
  64. + static int objc_receiver_context;
  65. + static int objc_public_flag;
  66. + static char *token_buffer;    /* Pointer to token buffer.
  67. +                    Actual allocated length is maxtoken + 2.  */
  68.   /* Tell yyparse how to print a token's value, if yydebug is set.  */
  69.   
  70.   #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
  71. ***************
  72. *** 250,257 ****
  73.   %%
  74.   program: /* empty */
  75.           { if (pedantic)
  76. !             pedwarn ("ANSI C forbids an empty source file"); }
  77.       | extdefs
  78.       ;
  79.   
  80.   /* the reason for the strange actions in this rule
  81. --- 281,290 ----
  82.   %%
  83.   program: /* empty */
  84.           { if (pedantic)
  85. !             pedwarn ("ANSI C forbids an empty source file");
  86. !           objc_finish (); }
  87.       | extdefs
  88. +         { objc_finish (); }
  89.       ;
  90.   
  91.   /* the reason for the strange actions in this rule
  92. ***************
  93. *** 266,271 ****
  94. --- 299,305 ----
  95.   extdef:
  96.       fndef
  97.       | datadef
  98. +     | objcdef
  99.       | ASM '(' string ')' ';'
  100.           { if (pedantic)
  101.               pedwarn ("ANSI C forbids use of `asm' keyword");
  102. ***************
  103. *** 330,335 ****
  104. --- 364,371 ----
  105.   identifier:
  106.       IDENTIFIER
  107.       | TYPENAME
  108. +         | CLASSNAME
  109. +         { $$ = CLASS_NAME ($1); }
  110.       ;
  111.   
  112.   unop:     '&'
  113. ***************
  114. *** 480,488 ****
  115.               yychar = YYLEX;
  116.                 if (yychar == '(')
  117.               {
  118. !               $$ = implicitly_declare ($1);
  119. !               assemble_external ($$);
  120. !               TREE_USED ($$) = 1;
  121.               }
  122.                 else if (current_function_decl == 0)
  123.               {
  124. --- 516,536 ----
  125.               yychar = YYLEX;
  126.                 if (yychar == '(')
  127.               {
  128. !               if (objc_receiver_context
  129. !                   && ! (objc_receiver_context
  130. !                     && strcmp (IDENTIFIER_POINTER ($1), "super")))
  131. !                 /* we have a message to super */
  132. !                 $$ = get_super_receiver ();
  133. !               else if (objc_method_context
  134. !                    && is_ivar (objc_ivar_chain, $1))
  135. !                 $$ = build_ivar_reference ($1);
  136. !               else
  137. !                 {
  138. !                   /* Ordinary implicit function declaration.  */
  139. !                   $$ = implicitly_declare ($1);
  140. !                   assemble_external ($$);
  141. !                   TREE_USED ($$) = 1;
  142. !                 }
  143.               }
  144.                 else if (current_function_decl == 0)
  145.               {
  146. ***************
  147. *** 492,521 ****
  148.               }
  149.                 else
  150.               {
  151. !               if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
  152. !                   || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
  153.                   {
  154. !                   error ("`%s' undeclared (first use this function)",
  155. !                      IDENTIFIER_POINTER ($1));
  156. !                   if (! undeclared_variable_notice)
  157.                   {
  158. !                   error ("(Each undeclared identifier is reported only once");
  159. !                   error ("for each function it appears in.)");
  160. !                   undeclared_variable_notice = 1;
  161.                   }
  162. !                 }
  163. !               $$ = error_mark_node;
  164. !               /* Prevent repeated error messages.  */
  165. !               IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
  166. !               IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
  167.               }
  168.               }
  169. !           else if (! TREE_USED ($$))
  170.               {
  171. !               if (TREE_EXTERNAL ($$))
  172. !             assemble_external ($$);
  173. !               TREE_USED ($$) = 1;
  174.               }
  175.             if (TREE_CODE ($$) == CONST_DECL)
  176.               $$ = DECL_INITIAL ($$);
  177. --- 540,601 ----
  178.               }
  179.                 else
  180.               {
  181. !                   if (objc_receiver_context
  182. !                   && ! (objc_receiver_context
  183. !                     && strcmp (IDENTIFIER_POINTER ($1), "super")))
  184. !                 /* we have a message to super */
  185. !                 $$ = get_super_receiver ();
  186. !               else if (objc_method_context
  187. !                    && is_ivar (objc_ivar_chain, $1))
  188. !                 $$ = build_ivar_reference ($1);
  189. !               else
  190.                   {
  191. !                   if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
  192. !                   || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
  193.                   {
  194. !                   error ("`%s' undeclared (first use this function)",
  195. !                      IDENTIFIER_POINTER ($1));
  196. !                   if (! undeclared_variable_notice)
  197. !                     {
  198. !                       error ("(Each undeclared identifier is reported only once");
  199. !                       error ("for each function it appears in.)");
  200. !                       undeclared_variable_notice = 1;
  201. !                     }
  202.                   }
  203. !                   $$ = error_mark_node;
  204. !                   /* Prevent repeated error messages.  */
  205. !                   IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
  206. !                   IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
  207. !                     }
  208.               }
  209.               }
  210. !           else
  211.               {
  212. !               if (! TREE_USED ($$))
  213. !             {
  214. !               if (TREE_EXTERNAL ($$))
  215. !                 assemble_external ($$);
  216. !               TREE_USED ($$) = 1;
  217. !             }
  218. !               /* we have a definition - still check if iVariable */
  219. !               if (!objc_receiver_context
  220. !               || (objc_receiver_context
  221. !                   && strcmp (IDENTIFIER_POINTER ($1), "super")))
  222. !                         {
  223. !               if (objc_method_context
  224. !                   && is_ivar (objc_ivar_chain, $1))
  225. !                             {
  226. !                               if (IDENTIFIER_LOCAL_VALUE ($1))
  227. !                                 warning ("local declaration of `%s' hides instance variable",
  228. !                                      IDENTIFIER_POINTER ($1));
  229. !                               else
  230. !                                 $$ = build_ivar_reference ($1);
  231. !                             }
  232. !             }
  233. !                       else /* we have a message to super */
  234. !                 $$ = get_super_receiver ();
  235.               }
  236.             if (TREE_CODE ($$) == CONST_DECL)
  237.               $$ = DECL_INITIAL ($$);
  238. ***************
  239. *** 562,574 ****
  240.       | primary '[' expr ']'   %prec '.'
  241.           { $$ = build_array_ref ($1, $3); }
  242.       | primary '.' identifier
  243. !         { $$ = build_component_ref ($1, $3); }
  244.       | primary POINTSAT identifier
  245. !         { $$ = build_component_ref (build_indirect_ref ($1, "->"), $3); }
  246.       | primary PLUSPLUS
  247.           { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
  248.       | primary MINUSMINUS
  249.           { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
  250.       ;
  251.   
  252.   /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
  253. --- 642,682 ----
  254.       | primary '[' expr ']'   %prec '.'
  255.           { $$ = build_array_ref ($1, $3); }
  256.       | primary '.' identifier
  257. !         {
  258. !                   if (doing_objc_thang)
  259. !                     {
  260. !               if (is_public ($1, $3))
  261. !             $$ = build_component_ref ($1, $3);
  262. !               else
  263. !             $$ = error_mark_node;
  264. !             }
  265. !                   else
  266. !                     $$ = build_component_ref ($1, $3);
  267. !         }
  268.       | primary POINTSAT identifier
  269. !         {
  270. !                   tree anExpr = build_indirect_ref ($1, "->");
  271. !                   if (doing_objc_thang)
  272. !                     {
  273. !               if (is_public (anExpr, $3))
  274. !             $$ = build_component_ref (anExpr, $3);
  275. !               else
  276. !             $$ = error_mark_node;
  277. !             }
  278. !                   else
  279. !                     $$ = build_component_ref (anExpr, $3);
  280. !         }
  281.       | primary PLUSPLUS
  282.           { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
  283.       | primary MINUSMINUS
  284.           { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
  285. +     | objcmessageexpr
  286. +         { $$ = build_message_expr ($1); }
  287. +     | objcselectorexpr
  288. +         { $$ = build_selector_expr ($1); }
  289. +     | objcencodeexpr
  290. +         { $$ = build_encode_expr ($1); }
  291.       ;
  292.   
  293.   /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
  294. ***************
  295. *** 701,706 ****
  296. --- 809,816 ----
  297.           { /* For a typedef name, record the meaning, not the name.
  298.                In case of `foo foo, bar;'.  */
  299.             $$ = lookup_name ($1); }
  300. +         | CLASSNAME
  301. +         { $$ = get_static_reference ($1); }
  302.       | TYPEOF '(' expr ')'
  303.           { $$ = TREE_TYPE ($3);
  304.             if (pedantic)
  305. ***************
  306. *** 1016,1021 ****
  307. --- 1126,1134 ----
  308.       | component_decl_list2 ';'
  309.           { if (pedantic)
  310.               warning ("extra semicolon in struct or union specified"); }
  311. +     /* foo(sizeof(struct{ @defs(ClassName)})); */
  312. +     | DEFS '(' CLASSNAME ')'
  313. +         { $$ = get_class_ivars ($3); }
  314.       ;
  315.   
  316.   /* There is a shift-reduce conflict here, because `components' may
  317. ***************
  318. *** 1161,1167 ****
  319.             pushlevel (0);
  320.             clear_last_expr ();
  321.             push_momentary ();
  322. !           expand_start_bindings (0); }
  323.       ;
  324.   
  325.   /* Read zero or more forward-declarations for labels
  326. --- 1274,1282 ----
  327.             pushlevel (0);
  328.             clear_last_expr ();
  329.             push_momentary ();
  330. !           expand_start_bindings (0);
  331. !           if (objc_method_context)
  332. !             add_objc_decls (); }
  333.       ;
  334.   
  335.   /* Read zero or more forward-declarations for labels
  336. ***************
  337. *** 1567,1572 ****
  338. --- 1682,2248 ----
  339.       | identifiers ',' IDENTIFIER
  340.           { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  341.       ;
  342. + /*
  343. +  *    Objective-C productions.
  344. +  */
  345. + objcdef:
  346. +       classdef
  347. +     | methoddef
  348. +     | END
  349. +         {
  350. +           if (objc_implementation_context)
  351. +                     {
  352. +               finish_class (objc_implementation_context);
  353. +               objc_ivar_chain = NULL_TREE;
  354. +               objc_implementation_context = NULL_TREE;
  355. +             }
  356. +           else
  357. +             warning ("`@end' must appear in an implementation context");
  358. +         }
  359. +     ;
  360. + classdef:
  361. +       INTERFACE identifier '{'
  362. +         {
  363. +           objc_interface_context = objc_ivar_context
  364. +             = start_class (INTERFACE_TYPE, $2, NULL_TREE);
  365. +                   objc_public_flag = 0;
  366. +         }
  367. +       ivar_decl_list '}'
  368. +         {
  369. +                   continue_class (objc_interface_context);
  370. +         }
  371. +       methodprotolist
  372. +       END
  373. +         {
  374. +           finish_class (objc_interface_context);
  375. +           objc_interface_context = NULL_TREE;
  376. +         }
  377. +     | INTERFACE identifier
  378. +         {
  379. +           objc_interface_context
  380. +             = start_class (INTERFACE_TYPE, $2, NULL_TREE);
  381. +                   continue_class (objc_interface_context);
  382. +         }
  383. +       methodprotolist
  384. +       END
  385. +         {
  386. +           finish_class (objc_interface_context);
  387. +           objc_interface_context = NULL_TREE;
  388. +         }
  389. +     | INTERFACE identifier ':' identifier '{'
  390. +         {
  391. +           objc_interface_context = objc_ivar_context
  392. +             = start_class (INTERFACE_TYPE, $2, $4);
  393. +                   objc_public_flag = 0;
  394. +         }
  395. +       ivar_decl_list '}'
  396. +         {
  397. +                   continue_class (objc_interface_context);
  398. +         }
  399. +       methodprotolist
  400. +       END
  401. +         {
  402. +           finish_class (objc_interface_context);
  403. +           objc_interface_context = NULL_TREE;
  404. +         }
  405. +     | INTERFACE identifier ':' identifier
  406. +         {
  407. +           objc_interface_context
  408. +             = start_class (INTERFACE_TYPE, $2, $4);
  409. +                   continue_class (objc_interface_context);
  410. +         }
  411. +       methodprotolist
  412. +       END
  413. +         {
  414. +           finish_class (objc_interface_context);
  415. +           objc_interface_context = NULL_TREE;
  416. +         }
  417. +     | IMPLEMENTATION identifier '{'
  418. +         {
  419. +           objc_implementation_context = objc_ivar_context
  420. +             = start_class (IMPLEMENTATION_TYPE, $2, NULL_TREE);
  421. +                   objc_public_flag = 0;
  422. +         }
  423. +       ivar_decl_list '}'
  424. +         {
  425. +                   objc_ivar_chain
  426. +             = continue_class (objc_implementation_context);
  427. +         }
  428. +     | IMPLEMENTATION identifier
  429. +         {
  430. +           objc_implementation_context
  431. +             = start_class (IMPLEMENTATION_TYPE, $2, NULL_TREE);
  432. +                   objc_ivar_chain
  433. +             = continue_class (objc_implementation_context);
  434. +         }
  435. +     | IMPLEMENTATION identifier ':' identifier '{'
  436. +         {
  437. +           objc_implementation_context = objc_ivar_context
  438. +             = start_class (IMPLEMENTATION_TYPE, $2, $4);
  439. +                   objc_public_flag = 0;
  440. +         }
  441. +       ivar_decl_list '}'
  442. +         {
  443. +                   objc_ivar_chain
  444. +             = continue_class (objc_implementation_context);
  445. +         }
  446. +     | IMPLEMENTATION identifier ':' identifier
  447. +         {
  448. +           objc_implementation_context
  449. +             = start_class (IMPLEMENTATION_TYPE, $2, $4);
  450. +                   objc_ivar_chain
  451. +             = continue_class (objc_implementation_context);
  452. +         }
  453. +     | INTERFACE identifier '(' identifier ')'
  454. +         {
  455. +           objc_interface_context
  456. +             = start_class (PROTOCOL_TYPE, $2, $4);
  457. +                   continue_class (objc_interface_context);
  458. +         }
  459. +       methodprotolist
  460. +       END
  461. +         {
  462. +           finish_class (objc_interface_context);
  463. +           objc_interface_context = NULL_TREE;
  464. +         }
  465. +     | IMPLEMENTATION identifier '(' identifier ')'
  466. +         {
  467. +           objc_implementation_context
  468. +             = start_class (CATEGORY_TYPE, $2, $4);
  469. +                   objc_ivar_chain
  470. +             = continue_class (objc_implementation_context);
  471. +         }
  472. +     ;
  473. + ivar_decl_list:
  474. +           ivar_decls PUBLIC { objc_public_flag = 1; } ivar_decls
  475. +         | ivar_decls
  476. +         ;
  477. + ivar_decls:
  478. +           /* empty */
  479. +         {
  480. +                   $$ = NULL_TREE;
  481. +                 }
  482. +     | ivar_decls ivar_decl ';'
  483. +     | ivar_decls ';'
  484. +         {
  485. +                   if (pedantic)
  486. +             warning ("extra semicolon in struct or union specified");
  487. +                 }
  488. +     ;
  489. + /* There is a shift-reduce conflict here, because `components' may
  490. +    start with a `typename'.  It happens that shifting (the default resolution)
  491. +    does the right thing, because it treats the `typename' as part of
  492. +    a `typed_typespecs'.
  493. +    It is possible that this same technique would allow the distinction
  494. +    between `notype_initdecls' and `initdecls' to be eliminated.
  495. +    But I am being cautious and not trying it.  */
  496. + ivar_decl:
  497. +     typed_typespecs setspecs ivars
  498. +             {
  499. +                   $$ = $3;
  500. +           resume_momentary ($2);
  501. +                 }
  502. +     | nonempty_type_quals setspecs ivars
  503. +         {
  504. +                   $$ = $3;
  505. +           resume_momentary ($2);
  506. +                 }
  507. +     | error
  508. +         { $$ = NULL_TREE; }
  509. +     ;
  510. + ivars:
  511. +       /* empty */
  512. +         { $$ = NULL_TREE; }
  513. +     | ivar_declarator
  514. +     | ivars ',' ivar_declarator
  515. +     ;
  516. + ivar_declarator:
  517. +       declarator
  518. +         {
  519. +           $$ = add_instance_variable (objc_ivar_context,
  520. +                           objc_public_flag,
  521. +                           $1, current_declspecs,
  522. +                           NULL_TREE);
  523. +                 }
  524. +     | declarator ':' expr_no_commas
  525. +         {
  526. +           $$ = add_instance_variable (objc_ivar_context,
  527. +                           objc_public_flag,
  528. +                           $1, current_declspecs, $3);
  529. +                 }
  530. +     | ':' expr_no_commas
  531. +         {
  532. +           $$ = add_instance_variable (objc_ivar_context,
  533. +                           objc_public_flag,
  534. +                           NULL_TREE,
  535. +                           current_declspecs, $2);
  536. +                 }
  537. +     ;
  538. + methoddef:
  539. +       '+'
  540. +         {
  541. +           if (objc_implementation_context)
  542. +             objc_inherit_code = CLASS_METHOD_DECL;
  543. +                   else
  544. +             fatal ("method definition not in class context");
  545. +         }
  546. +       methoddecl
  547. +         {
  548. +           add_class_method (objc_implementation_context, $3);
  549. +           start_method_def ($3);
  550. +           objc_method_context = $3;
  551. +         }
  552. +       optarglist
  553. +         {
  554. +           continue_method_def ();
  555. +         }
  556. +       compstmt_or_error
  557. +         {
  558. +           finish_method_def ();
  559. +           objc_method_context = NULL_TREE;
  560. +         }
  561. +     | '-'
  562. +         {
  563. +           if (objc_implementation_context)
  564. +             objc_inherit_code = INSTANCE_METHOD_DECL;
  565. +                   else
  566. +             fatal ("method definition not in class context");
  567. +         }
  568. +       methoddecl
  569. +         {
  570. +           add_instance_method (objc_implementation_context, $3);
  571. +           start_method_def ($3);
  572. +           objc_method_context = $3;
  573. +         }
  574. +       optarglist
  575. +         {
  576. +           continue_method_def ();
  577. +         }
  578. +       compstmt_or_error
  579. +         {
  580. +           finish_method_def ();
  581. +           objc_method_context = NULL_TREE;
  582. +         }
  583. +     ;
  584. + /* the reason for the strange actions in this rule
  585. +  is so that notype_initdecls when reached via datadef
  586. +  can find a valid list of type and sc specs in $0. */
  587. + methodprotolist:
  588. +       /* empty  */
  589. +     | {$<ttype>$ = NULL_TREE; } methodprotolist2
  590. +     ;
  591. + methodprotolist2:         /* eliminates a shift/reduce conflict */
  592. +        methodproto
  593. +     |  datadef
  594. +     | methodprotolist2 methodproto
  595. +     | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
  596. +     ;
  597. + semi_or_error:
  598. +       ';'
  599. +     | error
  600. +     ;
  601. + methodproto:
  602. +       '+'
  603. +         {
  604. +           objc_inherit_code = CLASS_METHOD_DECL;
  605. +         }
  606. +       methoddecl
  607. +         {
  608. +           add_class_method (objc_interface_context, $3);
  609. +         }
  610. +       semi_or_error
  611. +     | '-'
  612. +         {
  613. +           objc_inherit_code = INSTANCE_METHOD_DECL;
  614. +         }
  615. +       methoddecl
  616. +         {
  617. +           add_instance_method (objc_interface_context, $3);
  618. +         }
  619. +       semi_or_error
  620. +     ;
  621. + methoddecl:
  622. +       '(' typename ')' unaryselector
  623. +         {
  624. +           $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
  625. +         }
  626. +     | unaryselector
  627. +         {
  628. +           $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
  629. +         }
  630. +     | '(' typename ')' keywordselector optparmlist
  631. +         {
  632. +           $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
  633. +         }
  634. +     | keywordselector optparmlist
  635. +         {
  636. +           $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
  637. +         }
  638. +     ;
  639. + /* "optarglist" assumes that start_method_def has already been called...
  640. +    if it is not, the "xdecls" will not be placed in the proper scope */
  641. + optarglist:
  642. +       /* empty */
  643. +     | ';' myxdecls
  644. +     ;
  645. + /* to get around the following situation: "int foo (int a) int b; {}" that
  646. +    is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
  647. + myxdecls:
  648. +       /* empty */
  649. +     | mydecls
  650. +     ;
  651. + mydecls:
  652. +     mydecl
  653. +     | errstmt
  654. +     | mydecls mydecl
  655. +     | mydecl errstmt
  656. +     ;
  657. + mydecl:
  658. +     typed_declspecs setspecs myparms ';'
  659. +         { resume_momentary ($2); }
  660. +     | typed_declspecs ';'
  661. +         { shadow_tag ($1); }
  662. +     | declmods ';'
  663. +         { warning ("empty declaration"); }
  664. +     ;
  665. + myparms:
  666. +     myparm
  667. +         { push_parm_decl ($1); }
  668. +     | myparms ',' myparm
  669. +         { push_parm_decl ($3); }
  670. +     ;
  671. + /* A single parameter declaration or parameter type name,
  672. +    as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
  673. + myparm:
  674. +       parm_declarator
  675. +         { $$ = build_tree_list (current_declspecs, $1)    ; }
  676. +     | notype_declarator
  677. +         { $$ = build_tree_list (current_declspecs, $1)    ; }
  678. +     | absdcl
  679. +         { $$ = build_tree_list (current_declspecs, $1)    ; }
  680. +     ;
  681. + optparmlist:
  682. +       /* empty */
  683. +         {
  684. +               $$ = NULL_TREE;
  685. +         }
  686. +     | ',' ELLIPSIS
  687. +         {
  688. +           /* oh what a kludge! */
  689. +           $$ = (tree)1;
  690. +         }
  691. +     | ','
  692. +         {
  693. +           pushlevel (0);
  694. +         }
  695. +       parmlist_2
  696. +         {
  697. +             /* returns a tree list node generated by get_parm_info */
  698. +           $$ = $3;
  699. +           poplevel (0, 0, 0);
  700. +         }
  701. +     ;
  702. + unaryselector:
  703. +       selector
  704. +     ;
  705. + keywordselector:
  706. +       keyworddecl
  707. +     | keywordselector keyworddecl
  708. +         {
  709. +           $$ = chainon ($1, $2);
  710. +         }
  711. +     ;
  712. + selector:
  713. +       IDENTIFIER
  714. +         | TYPENAME
  715. +     | reservedwords
  716. +     ;
  717. + reservedwords:
  718. +       ENUM { $$ = get_identifier (token_buffer); }
  719. +     | STRUCT { $$ = get_identifier (token_buffer); }
  720. +     | UNION { $$ = get_identifier (token_buffer); }
  721. +     | IF { $$ = get_identifier (token_buffer); }
  722. +     | ELSE { $$ = get_identifier (token_buffer); }
  723. +     | WHILE { $$ = get_identifier (token_buffer); }
  724. +     | DO { $$ = get_identifier (token_buffer); }
  725. +     | FOR { $$ = get_identifier (token_buffer); }
  726. +     | SWITCH { $$ = get_identifier (token_buffer); }
  727. +     | CASE { $$ = get_identifier (token_buffer); }
  728. +     | DEFAULT { $$ = get_identifier (token_buffer); }
  729. +     | BREAK { $$ = get_identifier (token_buffer); }
  730. +     | CONTINUE { $$ = get_identifier (token_buffer); }
  731. +     | RETURN  { $$ = get_identifier (token_buffer); }
  732. +     | GOTO { $$ = get_identifier (token_buffer); }
  733. +     | ASM { $$ = get_identifier (token_buffer); }
  734. +         | SIZEOF { $$ = get_identifier (token_buffer); }
  735. +     | TYPEOF { $$ = get_identifier (token_buffer); }
  736. +     | ALIGNOF { $$ = get_identifier (token_buffer); }
  737. +     | TYPESPEC | TYPE_QUAL
  738. +     ;
  739. + keyworddecl:
  740. +       selector ':' '(' typename ')' identifier
  741. +         {
  742. +           $$ = build_keyword_decl ($1, $4, $6);
  743. +         }
  744. +     | selector ':' identifier
  745. +         {
  746. +           $$ = build_keyword_decl ($1, NULL_TREE, $3);
  747. +         }
  748. +     | ':' '(' typename ')' identifier
  749. +         {
  750. +           $$ = build_keyword_decl (NULL_TREE, $3, $5);
  751. +         }
  752. +     | ':' identifier
  753. +         {
  754. +           $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
  755. +         }
  756. +     ;
  757. + messageargs:
  758. +       selector
  759. +         | keywordarglist
  760. +     ;
  761. + keywordarglist:
  762. +       keywordarg
  763. +     | keywordarglist keywordarg
  764. +         {
  765. +           $$ = chainon ($1, $2);
  766. +         }
  767. +     ;
  768. + keywordexpr:
  769. +       nonnull_exprlist
  770. +         {
  771. +           if (TREE_CHAIN ($1) == NULL_TREE)
  772. +             /* just return the expr., remove a level of indirection */
  773. +             $$ = TREE_VALUE ($1);
  774. +                   else
  775. +             /* we have a comma expr., we will collapse later */
  776. +             $$ = $1;
  777. +         }
  778. +     ;
  779. + keywordarg:
  780. +       selector ':' keywordexpr
  781. +         {
  782. +           $$ = build_tree_list ($1, $3);
  783. +         }
  784. +     | ':' keywordexpr
  785. +         {
  786. +           $$ = build_tree_list (NULL_TREE, $2);
  787. +         }
  788. +     ;
  789. + receiver:
  790. +       expr
  791. +     | CLASSNAME
  792. +         {
  793. +           $$ = get_class_reference ($1);
  794. +         }
  795. +     ;
  796. + objcmessageexpr:
  797. +       '['
  798. +         { objc_receiver_context = 1; }
  799. +       receiver
  800. +         { objc_receiver_context = 0; }
  801. +       messageargs ']'
  802. +         {
  803. +           $$ = build_tree_list ($3, $5);
  804. +         }
  805. +     ;
  806. + selectorarg:
  807. +       selector
  808. +         | keywordnamelist
  809. +     ;
  810. + keywordnamelist:
  811. +       keywordname
  812. +     | keywordnamelist keywordname
  813. +         {
  814. +           $$ = chainon ($1, $2);
  815. +         }
  816. +     ;
  817. + keywordname:
  818. +       selector ':'
  819. +         {
  820. +           $$ = build_tree_list ($1, NULL_TREE);
  821. +         }
  822. +     | ':'
  823. +         {
  824. +           $$ = build_tree_list (NULL_TREE, NULL_TREE);
  825. +         }
  826. +     ;
  827. + objcselectorexpr:
  828. +       SELECTOR '(' selectorarg ')'
  829. +         {
  830. +           $$ = $3;
  831. +         }
  832. +     ;
  833. + /* extension to support C-structures in the archiver */
  834. + objcencodeexpr:
  835. +       ENCODE '(' typename ')'
  836. +         {
  837. +           $$ = groktypename ($3);
  838. +         }
  839. +     ;
  840.   %%
  841.   
  842.   /* Return something to represent absolute declarators containing a *.
  843. ***************
  844. *** 1608,1660 ****
  845.   
  846.   int check_newline ();
  847.   
  848. ! /* C code produced by gperf version 2.5 (GNU C++ version) */
  849. ! /* Command-line: gperf -p -j1 -i 1 -g -o -t -N is_reserved_word -k1,3,$ c-parse.gperf  */ 
  850.   struct resword { char *name; short token; enum rid rid; };
  851.   
  852. - #define TOTAL_KEYWORDS 53
  853.   #define MIN_WORD_LENGTH 2
  854. ! #define MAX_WORD_LENGTH 13
  855. ! #define MIN_HASH_VALUE 7
  856. ! #define MAX_HASH_VALUE 102
  857. ! /* maximum key range = 96, duplicates = 0 */
  858.   
  859.   #ifdef __GNUC__
  860.   __inline
  861.   #endif
  862. ! static unsigned int
  863.   hash (str, len)
  864.        register char *str;
  865.        register int unsigned len;
  866.   {
  867. !   static unsigned char asso_values[] =
  868.       {
  869. !      103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  870. !      103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  871. !      103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  872. !      103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  873. !      103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  874. !      103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  875. !      103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  876. !      103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  877. !      103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  878. !      103, 103, 103, 103, 103,   1, 103,   2,   1,  24,
  879. !        1,   5,  19,  39,  16,  13, 103,   1,  25,   1,
  880. !       34,  34,  24, 103,  13,  12,   1,  45,  24,   7,
  881. !      103, 103,   2, 103, 103, 103, 103, 103,
  882.       };
  883. !   register int hval = len;
  884.   
  885.     switch (hval)
  886.       {
  887. !       default:
  888. !       case 3:
  889. !         hval += asso_values[str[2]];
  890. !       case 2:
  891. !       case 1:
  892. !         hval += asso_values[str[0]];
  893.       }
  894. !   return hval + asso_values[str[len - 1]];
  895.   }
  896.   
  897.   #ifdef __GNUC__
  898. --- 2284,2333 ----
  899.   
  900.   int check_newline ();
  901.   
  902. ! /* Data type that represents the GNU C reserved words. */
  903.   struct resword { char *name; short token; enum rid rid; };
  904.   
  905.   #define MIN_WORD_LENGTH 2
  906. ! #define MAX_WORD_LENGTH     15     /* maximum size for C keyword */
  907. ! #define MIN_HASH_VALUE      9      /* range of the hash keys values  */
  908. ! #define MAX_HASH_VALUE      95     /* for the perfect hash generator */
  909.   
  910.   #ifdef __GNUC__
  911.   __inline
  912.   #endif
  913. ! static int
  914.   hash (str, len)
  915.        register char *str;
  916.        register int unsigned len;
  917.   {
  918. !   static unsigned char hash_table[] =
  919.       {
  920. !      95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
  921. !      95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
  922. !      95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
  923. !      95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
  924. !      95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
  925. !      95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
  926. !      95, 95, 95, 95, 44, 95, 95, 95, 95, 95,
  927. !      95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
  928. !      95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
  929. !      95, 95, 95, 95, 95,  1, 95, 28,  3, 35,
  930. !       8,  7, 18, 20, 19, 13, 95,  1, 13, 18,
  931. !       1, 62,  1, 95,  1,  2,  1,  3, 35,  6,
  932. !      95, 95,  9, 95, 95, 95, 95, 95,
  933.       };
  934. !   register int hval = len ;
  935.   
  936.     switch (hval)
  937.       {
  938. !     default:
  939. !     case 3:
  940. !       hval += hash_table[str[2]];
  941. !     case 2:
  942. !     case 1:
  943. !       hval += hash_table[str[0]];
  944.       }
  945. !   return hval + hash_table[str[len - 1]] ;
  946.   }
  947.   
  948.   #ifdef __GNUC__
  949. ***************
  950. *** 1665,1744 ****
  951.        register char *str;
  952.        register unsigned int len;
  953.   {
  954. !   static struct resword wordlist[] =
  955.       {
  956. !       {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, 
  957. !       {"asm",  ASM, NORID},
  958. !       {"",}, 
  959. !       {"__asm",  ASM, NORID},
  960. !       {"",}, 
  961. !       {"__asm__",  ASM, NORID},
  962. !       {"break",  BREAK, NORID},
  963. !       {"__typeof__",  TYPEOF, NORID},
  964. !       {"",}, 
  965. !       {"__alignof__",  ALIGNOF, NORID},
  966. !       {"",}, 
  967. !       {"__attribute__",  ATTRIBUTE, NORID},
  968. !       {"int",  TYPESPEC, RID_INT},
  969. !       {"__attribute",  ATTRIBUTE, NORID},
  970. !       {"__extension__",  EXTENSION, NORID},
  971. !       {"",}, 
  972. !       {"__signed",  TYPESPEC, RID_SIGNED},
  973. !       {"",}, 
  974. !       {"__signed__",  TYPESPEC, RID_SIGNED},
  975. !       {"__inline__",  SCSPEC, RID_INLINE},
  976. !       {"else",  ELSE, NORID},
  977. !       {"__inline",  SCSPEC, RID_INLINE},
  978. !       {"default",  DEFAULT, NORID},
  979. !       {"__typeof",  TYPEOF, NORID},
  980. !       {"while",  WHILE, NORID},
  981. !       {"__alignof",  ALIGNOF, NORID},
  982. !       {"struct",  STRUCT, NORID},
  983. !       {"__const",  TYPE_QUAL, RID_CONST},
  984. !       {"if",  IF, NORID},
  985. !       {"__const__",  TYPE_QUAL, RID_CONST},
  986. !       {"__label__",  LABEL, NORID},
  987. !       {"do",  DO, NORID},
  988. !       {"__volatile__",  TYPE_QUAL, RID_VOLATILE},
  989. !       {"sizeof",  SIZEOF, NORID},
  990. !       {"__volatile",  TYPE_QUAL, RID_VOLATILE},
  991. !       {"auto",  SCSPEC, RID_AUTO},
  992. !       {"void",  TYPESPEC, RID_VOID},
  993. !       {"char",  TYPESPEC, RID_CHAR},
  994. !       {"static",  SCSPEC, RID_STATIC},
  995. !       {"case",  CASE, NORID},
  996. !       {"extern",  SCSPEC, RID_EXTERN},
  997. !       {"switch",  SWITCH, NORID},
  998. !       {"for",  FOR, NORID},
  999. !       {"inline",  SCSPEC, RID_INLINE},
  1000. !       {"typeof",  TYPEOF, NORID},
  1001. !       {"typedef",  SCSPEC, RID_TYPEDEF},
  1002. !       {"short",  TYPESPEC, RID_SHORT},
  1003. !       {"",}, 
  1004. !       {"return",  RETURN, NORID},
  1005. !       {"enum",  ENUM, NORID},
  1006. !       {"",}, 
  1007. !       {"double",  TYPESPEC, RID_DOUBLE},
  1008. !       {"signed",  TYPESPEC, RID_SIGNED},
  1009. !       {"float",  TYPESPEC, RID_FLOAT},
  1010. !       {"",}, {"",}, 
  1011. !       {"volatile",  TYPE_QUAL, RID_VOLATILE},
  1012. !       {"",}, 
  1013. !       {"const",  TYPE_QUAL, RID_CONST},
  1014. !       {"",}, 
  1015. !       {"unsigned",  TYPESPEC, RID_UNSIGNED},
  1016. !       {"",}, {"",}, {"",}, {"",}, 
  1017. !       {"continue",  CONTINUE, NORID},
  1018. !       {"",}, 
  1019. !       {"register",  SCSPEC, RID_REGISTER},
  1020. !       {"",}, {"",}, {"",}, {"",}, 
  1021. !       {"goto",  GOTO, NORID},
  1022. !       {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, 
  1023. !       {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, 
  1024. !       
  1025. !       {"union",  UNION, NORID},
  1026. !       {"",}, {"",}, {"",}, {"",}, 
  1027. !       {"long",  TYPESPEC, RID_LONG},
  1028.       };
  1029.   
  1030.     if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
  1031. --- 2338,2416 ----
  1032.        register char *str;
  1033.        register unsigned int len;
  1034.   {
  1035. !   static struct resword  wordlist[] =
  1036.       {
  1037. !       { "",},{ "",},{ "",},{ "",},{ "",},{ "",},{ "",},{ "",},{ "",},
  1038. !       { "return", RETURN, NORID },
  1039. !       { "struct", STRUCT, NORID },
  1040. !       { "",},{ "",},
  1041. !       { "__typeof__", TYPEOF, NORID },
  1042. !       { "__signed__", TYPESPEC, RID_SIGNED },
  1043. !       { "extern", SCSPEC, RID_EXTERN },
  1044. !       { "break", BREAK, NORID },
  1045. !       { "",},
  1046. !       { "int", TYPESPEC, RID_INT },
  1047. !       { "__signed", TYPESPEC, RID_SIGNED },
  1048. !       { "else", ELSE, NORID },
  1049. !       { "unsigned", TYPESPEC, RID_UNSIGNED },
  1050. !       { "union", UNION, NORID },
  1051. !       { "for", FOR, NORID },
  1052. !       { "double", TYPESPEC, RID_DOUBLE },
  1053. !       { "__inline__", SCSPEC, RID_INLINE },
  1054. !       { "typeof", TYPEOF, NORID },
  1055. !       { "typedef", SCSPEC, RID_TYPEDEF },
  1056. !       { "__typeof", TYPEOF, NORID },
  1057. !       { "__inline", SCSPEC, RID_INLINE },
  1058. !       { "register", SCSPEC, RID_REGISTER },
  1059. !       { "while", WHILE, NORID },
  1060. !       { "enum", ENUM, NORID },
  1061. !       { "if", IF, NORID },
  1062. !       { "default", DEFAULT, NORID },
  1063. !       { "sizeof", SIZEOF, NORID },
  1064. !       { "signed", TYPESPEC, RID_SIGNED },
  1065. !       { "__asm__", ASM, NORID },
  1066. !       { "long", TYPESPEC, RID_LONG },
  1067. !       { "inline", SCSPEC, RID_INLINE },
  1068. !       { "switch", SWITCH, NORID },
  1069. !       { "__alignof__", ALIGNOF, NORID },
  1070. !       { "const", TYPE_QUAL, RID_CONST },
  1071. !       { "__attribute__", ATTRIBUTE, NORID },
  1072. !       { "__const", TYPE_QUAL, RID_CONST },
  1073. !       { "",},
  1074. !       { "__const__", TYPE_QUAL, RID_CONST },
  1075. !       { "__attribute", ATTRIBUTE, NORID },
  1076. !       { "case", CASE, NORID },
  1077. !       { "__volatile__", TYPE_QUAL, RID_VOLATILE },
  1078. !       { "",},
  1079. !       { "continue", CONTINUE, NORID },
  1080. !       { "__asm", ASM, NORID },
  1081. !       { "__volatile", TYPE_QUAL, RID_VOLATILE },
  1082. !       { "",},{ "",},
  1083. !       { "__alignof", ALIGNOF, NORID },
  1084. !       { "@end", END, NORID },
  1085. !       { "@defs", DEFS, NORID },
  1086. !       { "@encode", ENCODE, NORID },
  1087. !       { "void", TYPESPEC, RID_VOID },
  1088. !       { "@selector", SELECTOR, NORID },
  1089. !       { "@interface", INTERFACE, NORID },
  1090. !       { "volatile", TYPE_QUAL, RID_VOLATILE },
  1091. !       { "",},{ "",},{ "",},
  1092. !       { "asm", ASM, NORID },
  1093. !       { "char", TYPESPEC, RID_CHAR },
  1094. !       { "",},
  1095. !       { "short", TYPESPEC, RID_SHORT },
  1096. !       { "static", SCSPEC, RID_STATIC },
  1097. !       { "do", DO, NORID },
  1098. !       { "",},{ "",},{ "",},{ "",},{ "",},
  1099. !       { "@implementation", IMPLEMENTATION, NORID },
  1100. !       { "",},{ "",},{ "",},{ "",},{ "",},{ "",},{ "",},
  1101. !       { "float", TYPESPEC, RID_FLOAT },
  1102. !       { "goto", GOTO, NORID },
  1103. !       { "",},
  1104. !       { "@public", PUBLIC, NORID },
  1105. !       { "",},{ "",},{ "",},{ "",},{ "",},
  1106. !       { "auto", SCSPEC, RID_AUTO },
  1107.       };
  1108.   
  1109.     if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
  1110. ***************
  1111. *** 1745,1751 ****
  1112.       {
  1113.         register int key = hash (str, len);
  1114.   
  1115. !       if (key <= MAX_HASH_VALUE && key >= 0)
  1116.           {
  1117.             register char *s = wordlist[key].name;
  1118.   
  1119. --- 2417,2423 ----
  1120.       {
  1121.         register int key = hash (str, len);
  1122.   
  1123. !       if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
  1124.           {
  1125.             register char *s = wordlist[key].name;
  1126.   
  1127. ***************
  1128. *** 2385,2393 ****
  1129.       case 'u':  case 'v':  case 'w':  case 'x':  case 'y':
  1130.       case 'z':
  1131.       case '_':
  1132.       letter:
  1133.         p = token_buffer;
  1134. !       while (isalnum (c) || c == '_' || c == '$')
  1135.       {
  1136.         if (p >= token_buffer + maxtoken)
  1137.           p = extend_token_buffer (p);
  1138. --- 3057,3066 ----
  1139.       case 'u':  case 'v':  case 'w':  case 'x':  case 'y':
  1140.       case 'z':
  1141.       case '_':
  1142. +     case '@':
  1143.       letter:
  1144.         p = token_buffer;
  1145. !       while (isalnum (c) || c == '_' || c == '$' || c == '@')
  1146.       {
  1147.         if (p >= token_buffer + maxtoken)
  1148.           p = extend_token_buffer (p);
  1149. ***************
  1150. *** 2422,2432 ****
  1151. --- 3095,3117 ----
  1152.   
  1153.         if (value == IDENTIFIER)
  1154.       {
  1155. +       if (token_buffer[0] == '@')
  1156. +         error ("invalid identifier `%s'", token_buffer);
  1157.             yylval.ttype = get_identifier (token_buffer);
  1158.         lastiddecl = lookup_name (yylval.ttype);
  1159.   
  1160.         if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
  1161.           value = TYPENAME;
  1162. +           else if (doing_objc_thang)
  1163. +             {
  1164. +           tree objc_interface_decl = lookup_interface (yylval.ttype);
  1165. +           if (objc_interface_decl)
  1166. +         {
  1167. +           value = CLASSNAME;
  1168. +           yylval.ttype = objc_interface_decl;
  1169. +         }
  1170. +         }
  1171.       }
  1172.   
  1173.         break;
  1174.