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]
Other format: [Raw text]

Re: [patch] support for -fdump-ada-spec


> Unless the [] are literally part of the option name, they should be @r{[}
> and @r{]} so they are not typeset in a fixed-width font.

Fixed.

> > +Ada spec (via the -fdump-ada-spec switch).
> 
> @option{-fdump-ada-spec}.

Fixed.

> > +@item -fdump-ada-spec[-slim]
> 
> Same point as above on [].

Fixed.

> You may as well handle 'u' as well here, even if you don't want to handle
> hex floats and "float" literals ending 'f' or 'F'.

Done.

> > +	      if (token->flags & STRINGIFY_ARG || token->flags & PASTE_LEFT)
> > +		{
> > +		  supported = 0;
> 
> Weren't those cases detected earlier as unsupported when you calculated
> the length?

Yes, but I decided to make the two algortihms usable independently, so that
if one part is modified, it might not invalidate the other.

If you think it would be better to remove the extra test, that can be done
easily though.

> Do you need to insert spaces before and after these strings?  The C tokens
> could be adjacent to identifiers with no spaces in between, but you don't
> want "a&b" to become "aandb".

Indeed, fixed.

> Although better than the previous code, you'd still get correct results
> for more cases if you interpret the value of the token rather than the
> spelling - for example, that way you could handle escape sequences
> appearing in strings and convert them appropriately for Ada without any
> need to know about the exact semantics of C escape sequences.

OK, See updated patch below. If this is not what you had in mind, could
you clarify what you mean by 'interpret the value of the token'?

> And 'u', similarly.

Done.

> And 'B'.

Done.

> And 'u'.

Done.

> > +		  default:
> > +		    if (!macro->fun_like)
> > +		      supported = 0;
> 
> I'm not clear on the logic of saying these things are supported for
> function-like macros but not otherwise.  Are there actually cases where
> respelling these C tokens will produce valid Ada, or should these tokens
> just make the whole macro expansion unsupported for Ada, or are you
> hoping a partial conversion, though not valid Ada, will still be useful
> to the users of this feature?

For function-like macros, we do not attempt to convert them to valid Ada, but
instead we generate a possible conversion in the form of comments that can
help the user to manually edit the file and create real inline functions.

In other words, for fun_like, we only generate comments, so it does not
really matter if the syntax used is C syntax, or a mix of Ada and C.

For example, the following fun-like macro:

#define FOO(A,B)  call (a, b)

will generate the following Ada comments:

   --  arg-macro: procedure FOO (A, B)
   --    call (a, b)

> XALLOCAVEC already does the multiplication by the size of the type passed,
> so it seems suspicious for the second argument to this call to be doing
> the multiplication itself.

Indeed, fixed.

> I note that there are no testcases included with this patch - it would
> seem desirable to have testsuite coverage for this feature.

Agreed. We do have several tests, but not being familiar with dejagnu, that's
why I didn't include them in my initial patch.

Now that we're apparently converging and are getting close to inclusion (at
least I hope so!), I've investigated how to add such tests in the current
framework and came up with the attached patch which adds 18 tests with most
difficult/tricky issues that we've had to deal with as well as some simple
tests. The tests behave as you suggested indeed: first we generate .ads files
using -fdump-ada-spec, and then we compile the .ads files using the Ada
compiler and make sure that no errors are generated, which works nicely
in our experience (that's how we've been testing this capability at AdaCore
for the past 2 years).

Updated ChangeLog and patch attached, thanks in advance!

gcc/

2010-05-06  Arnaud Charlet  <charlet@adacore.com>
            Matthew Gingell  <gingell@adacore.com>

	* doc/invoke.texi: Mention -fdump-ada-spec.
	* tree-dump.c (dump_files): Add ada-spec.
	(FIRST_AUTO_NUMBERED_DUMP): Bump to 8.
	* tree-pass.h (tree_dump_index): Add TDI_ada.
	* gcc.c: Add support for -C without -E and for -fdump-ada-spec.
	(cpp_unique_options): Do not reject -C or -CC when -E isn't present.
	(default_compilers) <@c-header>: Allow -fdump-ada-spec on header files.
	* c-decl.c: Include c-ada-spec.h.
	(collect_source_ref_cb, collect_all_refs, for_each_global_decl): New
	functions.
	(c_write_global_declarations): Add handling of -fdump-ada-spec.
	* c-lex.c (c_lex_with_flags): Add handling of CPP_COMMENT.
	* Makefile.in (C_AND_OBJC_OBJS): Add c-ada-spec.o.
	* c-ada-spec.h, c-ada-spec.c: New files.

gcc/ada

	* gnat_ugn.texi: Improve doc on -fdump-ada-spec, mention limitations.

gcc/cp/

	* Make-lang.in (CXX_C_OBJS): Add c-ada-spec.o.
	* decl2.c: Include langhooks.h and c-ada-spec.h.
	(cpp_check, collect_source_refs, collect_ada_namespace,
	collect_all_refs): New functions.
	(cp_write_global_declarations): Add handling of -fdump-ada-spec.
	* lang-specs.h: Ditto.

gcc/testsuite

	* gnat.dg/c-specs: New directory with initial set of -fdump-ada-spec
	tests.
	* lib/gcc-dg.exp (gcc-dg-test-1): Add support for -fdump-ada-spec tests.
	* lib/gnat-dg.exp (gnat-dg-test): Ditto.

Attachment: difs
Description: Text document


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