bug-indent
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

indent -vs- GCC-specific declaration macros


From: Tom Tromey
Subject: indent -vs- GCC-specific declaration macros
Date: Thu, 20 Dec 2007 10:41:08 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.990 (gnu/linux)

I'm using GNU indent 2.2.9 on Fedora 8.

I'm investigating using indent to set the canonical style for GCC.

GCC has several macros that it uses widely which confuse indent.
Before we could use indent we would need some solution to this
problem.


First, GCC has a function-like macro named "GTY" which is applied to
certain variable and type declarations.  (It is used as part of the
garbage collector and is defined to be empty in ordinary compilation.)
Sample uses:

/* A variable definition.  */
static GTY (()) tree something;

/* A type.  */
struct hunk_binding_entry GTY (())
{
  /* The identifier.  */
  tree name;
  /* The enum/union/struct tag binding.  */
  tree tag_binding;
  /* The variable/function/etc binding.  */
  tree GTY(()) symbol_binding;
};

(Note that it can also appear on field declarations, see above for
example.)


GTY seems to confuse indent and we end up with weird output.  For
instance for variables I see:

static
GTY (())
    tree something;

For structures I see:

struct hunk_binding_entry
GTY (())
{
  ...
};

After a GTY'd variable, sometimes the indentation for following
declarations is messed up -- they are indented.


A related problem is attributes.  GCC makes extensive use of its own
__attribute__ extension.  However, instead of using plain
__attribute__, each kind that is used is wrapped in a macro.  (This
lets us conditionally define the attribute based on the gcc version in
which it was introduced.)

Attributes on function parameters don't seem to cause any problems,
but attributes on function declarations do.  E.g.:

static void usage (void) ATTRIBUTE_NORETURN;

is formatted as:

static void
usage (void)
  ATTRIBUTE_NORETURN;

... and then subsequent function declarations are indented oddly.


I don't know the indent internals, but as a user I'd be satisfied with
a flag along the lines of "XXX is an ignorable macro".  Then we could
pass '-M ATTRIBUTE_NORETURN -M GTY' (or whatever ... maybe different
flags for function-like and object-like macros).


Finally, GCC uses a macro called VEC to declare variables which are
expandable arrays.  This is a function-like macro, but we'd like to
format it as a type.

Right now we get:

    VEC (foo, gc) * v = something;

but I think we'd prefer:

    VEC (foo, gc) *v = something;

(GCC itself seems inconsistent on whether there is a space before the
open paren with VEC and GTY ... maybe a future feature request here :-)

Tom




reply via email to

[Prev in Thread] Current Thread [Next in Thread]