This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C attribute parsing patch


Jeff asked for further analysis of Mumit's patch below.  Here's
some.


Mumit's proposed change addresses the following, where in the first
declaration, a syntax error is generated, in the second (with a parameter
name present) one is not.  (Since function declarations in headers
should not have parameter names, this presents a problem.)


/* Syntax error, line 4 (par name absent) */
extern int  __attribute__((__cdecl_))
      atexit6(
         void (__attribute__((__cdecl_)) *)(void))
         ;

/* No error (par name present) */
extern int  __attribute__((__cdecl_))
      atexit7(
         void (__attribute__((__cdecl_)) *foo)(void))
         ;


Grammar change analysis.

In the notes below, references to rules and states are in the run I
made using bison and the new grammar.  I may also refer to corresponding
rules/states for the old grammar, which difffers by the one production.

1)  The new rule allows attributes to be inserted as needed in an absdcl1.

2)  an absdecl1 just the non-empty case of an absdcl.  This us used
    in declarations without parameter names.

3)  an absdcl is a modifier on a typename, such as *, () or [], used
    in the context of a function declaration parameters.

4)  the symbol setattrs always derives null, and is used in code
    generation; from C language (user) point of view, it's not there.

5)  The effect of the change is to allow (syntatically) attributes in the
    same places they are allowed in after_type_declarator, notype_declarator,
    and param_declarator, which are similar rules in other contexts.

6)  In the current grammar, attributes appear to account for a significant
    fraction of the existing conflicts.  It's unsurprising that a change
    involving attributes introduces more.


In terms of the additional ambiguities: the new rule introduces 4
new states (a reasonable number, given the change) and 5 conflicts
in those 4 states (a VERY reasonable number, given the conficts
surrounding attributes already!).

As far as the actual conflicts, they are all in the states below;
they all parallel existing conflicts very directly (given the
slightly different context in which the new rule allows attributes).


In 181: a S/R conflict between reduce on absdcl1 and to shift in the attribute:
Resolved in favor of the shift (correctly), exactly as in state 363
(for parm, which has a similar sub-grammar) (state 360 in old grammar).

In 183: a S/R conflict on null, exactly corresponding to 46, 119 and others
for other similar sub-grammars.

In 353 (2 conflicts): directly analogous to the similar conflict for the
similar sub-grammar for after_type_declarator in state 317.

In 411: another rule similar to 183, with a direct analog of 119 for
after_type_declarator.


Fixing up this grammar (particularly the attributes sub-grammar) to
be less tangled may be possible.  This is a perfect Master's project.
(No, I don't have a problem with having conflicts; in fact they're often
good things.  However, the number of similar rules associated with
attributes indicates that there's a good chance that either fewer
(with better use of conflicts) or cleaner rules may be possible.)



Mumit Khan wrote:
> 
> Initially submitted as part of the Interix batch on 1/27/99, but the patch
> wasn't correct (was to gcc/c-parse.y instead of to gcc/c-parse.in).
> 
> This is a general fix for parsing the following declaration:
> 
>   extern int  __attribute__((__cdecl_))
>     atexit(void (__attribute__((__cdecl_)) *)(void));
> 
> Diff against egcs-19990410 CVS. Essential for bootstrapping on Interix.
> Bootstrap sanity checked on i686-pc-linux-gnu and hppa1.1-hp-hpux10.20.
> 
> Sun Apr 11 14:39:26 1999  Mumit Khan  <khan@xraylith.wisc.edu>
>                           Donn Terry  <donn@interix.com>
> 
>         * c-parse.in (absdcl1): Allow attributes in explicit typespecs.
>         (%expect): Update.
>         * c-parse.y: Regenerate.
>         * c-parse.c: Likewise.
>         * objc/objc-parse.c: Likewise.
>         * objc/objc-parse.y: Likewise.
> 
> Regards,
> Mumit
> 
>   ----------------------------------------------------------------------------------------------------
> 
>                              Name: c-parse.diff.bz2
>    c-parse.diff.bz2          Type: unspecified type (APPLICATION/octet-stream)
>                          Encoding: BASE64
>                       Description: c-parse.diff.bz2

-- 

===================================================
Donn Terry                  mailto:donn@interix.com
Softway Systems, Inc.        http://www.interix.com
2850 McClelland Dr, Ste. 1800   Ft.Collins CO 80525
Tel: +1-970-204-9900           Fax: +1-970-204-9951
===================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]