From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,87077e61d6b3095b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-21 10:00:26 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: cl1motorsports Newsgroups: comp.lang.ada Subject: Re: how do i implement double-dispatching? Date: Sun, 21 Dec 2003 11:40:55 -0600 Organization: Posted via Supernews, http://www.supernews.com Message-Id: User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity. (Debian GNU/Linux)) References: <18484099.QgktZUUZ8s@linux1.krischik.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:3672 Date: 2003-12-21T11:40:55-06:00 List-Id: On Sun, 21 Dec 2003 08:39:59 -0500, Stephen Leake wrote: > cl1motorsports writes: > >> On Sat, 20 Dec 2003 10:56:07 +0100, Martin Krischik wrote: >> >> > Have you considered to send the C file thrue the C preprocessors >> > and convert the output? #if #define etc. pp. will be cone by then. >> >> What's the fun in that? Seriously though, the most common preprocessor is >> the one that comes with gcc, and it puts alot of non standard C stuff in >> its output. > > Hmm. I never noticed anything that was not in the ANSI C standard. Are > you sure it is truly not in that standard? Or is it just something you > are not familiar with? In any case, you can disable any non-standard > stuff by specifying -ansi. extern int vsnprintf (char * __s, size_t __maxlen, __const char * __format, __gnuc_va_list __arg) __attribute__ ((__format__ (__printf__, 3, 0))); the __attribute__ keyword gets processed even when -ansi is used. But from what i can tell, that is only used in the system header files. I mean it is not created by the preprocessor. I have a newer version of GCC since i last checked this. so maybe it was only in one version or something like that *shrugs*. > >> That is one reason I didn't want to do that. Another reason is because >> some people may want to convert a whole project and want to keep the >> preprocessed code. > > I think you mean "translate the preprocessor statements into Ada, to > preserve structure". That is a good idea. yes that's exactly what i meant. I also want a user to be able to select any given #define statement in the C code and specify how that statement is translated. This will help when the default choice chosen by the translator is ambiguous or not what the user intended. > >> I already have some ideas on this >> >> #define FOO >> Foo : constant Boolean := True >> >> #define FOO "i'm a string" >> Foo : constant String(1..12") := "i'm a string"; >> >> #define FOO 12 >> Foo : constant := 12; >> >> #define MAX(a,b) (a < b) b ? a; >> generic >> type blah is <>; >> function Max(a : blah; b : blah) return blah is begin >> if (a < b) then >> return b; >> else >> return a; >> end if; >> end Max; >> function >> >> that's just a few examples. > > This will work for many common uses of the preprocessor. Of course, it > will not be possible for _all_ uses of the preprocessor. But then your > translator can either run the C preprocessor and use the output, or > issue an error about untranslatable code. Actually i plan on having it preprocess the C code as a C preprocessor normally would when the translator doesn't have a known way to convert the #define statement to ada code directly. > >> I also want to use the define statements to be able to produce generic >> packages. I've got a direct conversion for most types of #define >> statements (i think) except ones with the stringize and concatination >> operators, and the ones that are just down right messy (garbage in >> garbage out). > > Right. Those should be re-written anyway :).