Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 15, 2012 preprocessor pass equivalent? | ||||
---|---|---|---|---|
| ||||
Is there some option, similar to -E gcc option, that would generate the analogous listing for D? What I mean is that I'd like to see all the code in version blocks gone, all the mixin strings expanded. It is probably too much to wish for having the infered auto's expanded... |
March 15, 2012 Re: preprocessor pass equivalent? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jay Norwood | On 15.03.2012 12:35, Jay Norwood wrote: > Is there some option, similar to -E gcc option, that would generate the > analogous listing for D? What I mean is that I'd like to see all the > code in version blocks gone, all the mixin strings expanded. > > It is probably too much to wish for having the infered auto's expanded... > Not every auto could be expanded, even simple stuff like: auto add(T1,T2)(T1 t1, T2 t2){ return t1+t2; } Expanding mixins could be useful, yet in certain circumstances I'd rather not see the resulting code :) -- Dmitry Olshansky |
March 15, 2012 Re: preprocessor pass equivalent? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jay Norwood | On 2012-03-15 09:35, Jay Norwood wrote: > Is there some option, similar to -E gcc option, that would generate the > analogous listing for D? What I mean is that I'd like to see all the > code in version blocks gone, all the mixin strings expanded. > > It is probably too much to wish for having the infered auto's expanded... > The Eclipse plugin, Descent, has a view that does something like this. Although I don't know how well it works for D2. -- /Jacob Carlborg |
March 15, 2012 Re: preprocessor pass equivalent? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 2012-03-15 11:04, Jacob Carlborg wrote: > On 2012-03-15 09:35, Jay Norwood wrote: >> Is there some option, similar to -E gcc option, that would generate the >> analogous listing for D? What I mean is that I'd like to see all the >> code in version blocks gone, all the mixin strings expanded. >> >> It is probably too much to wish for having the infered auto's expanded... >> > > The Eclipse plugin, Descent, has a view that does something like this. > Although I don't know how well it works for D2. > It expands mixins, string mixins, replaces scope statements with try/catch/finally and other things. It also has a compile time debugger. -- /Jacob Carlborg |
March 15, 2012 Re: preprocessor pass equivalent? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jay Norwood | On Thursday, March 15, 2012 09:35:46 Jay Norwood wrote: > Is there some option, similar to -E gcc option, that would generate the analogous listing for D? What I mean is that I'd like to see all the code in version blocks gone, all the mixin strings expanded. > > It is probably too much to wish for having the infered auto's expanded... http://d.puremagic.com/issues/show_bug.cgi?id=5051 - Jonathan M Davis |
March 15, 2012 Re: preprocessor pass equivalent? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Thursday, 15 March 2012 at 10:09:25 UTC, Jacob Carlborg wrote: >> The Eclipse plugin, Descent, has a view that does something like this. >> Although I don't know how well it works for D2. >> > > It expands mixins, string mixins, replaces scope statements with try/catch/finally and other things. It also has a compile time debugger. Wow, that's pretty impressive. Does it do aliases also? I read a little more last night and saw that there is an option for json output from dmd, and tried it out. Is that meant to serve the purpose of the gccxml program? I also found mention of a c++ compiler that someone states can compile c++ and output C. Kind of weird, but maybe compiling D to expanded D would not be such a stretch. http://stackoverflow.com/questions/1139793/c-template-preprocessor-tool |
March 15, 2012 Re: preprocessor pass equivalent? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jay Norwood | On Thursday, 15 March 2012 at 08:35:48 UTC, Jay Norwood wrote:
> Is there some option, similar to -E gcc option, that would generate the analogous listing for D?
You could add one to the compiler in just
a few lines; there's already a function that
does it, but it isn't called from anywhere.
Open up mars.c, and find this comment:
"Do not attempt to generate output files if errors"
It is line 1358 in my copy.
Right under that if(), add this:
for (size_t i = 0; i < modules.dim; i++)
{
m = modules[i];
m->gensymfile();
}
compile your new compiler.
BACK UP YOUR FILES because this function overwrites
the original .d file!
$ cat test10.d
void main() {
auto a = 0;
}
# we have to backup because otherwise our original source will be lost!
$ cp test10.d test10_original.d
# you'll have to pass the paths for phobos and druntime unless you bring in a dmd.conf...
$ d/dmd2/src/dmd/dmd -Id/dmd2/src/druntime/import -Id/dmd2/src/phobos -L-Ld/dmd2/linux/lib32/ test10.d
$ cat test10.d
// Sym file generated from 'test10.d'
import object;
void main()
{
int a = 0;
return 0;
}
It gets ugly if you use a lot of features because this
outputs the dmd translations - so foreach becomes for
and other lowerings.
But you can see basically what the compiler is going
to generate for final code.
|
March 15, 2012 Re: preprocessor pass equivalent? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Thu, Mar 15, 2012 at 02:51:33PM +0100, Adam D. Ruppe wrote: > On Thursday, 15 March 2012 at 08:35:48 UTC, Jay Norwood wrote: > >Is there some option, similar to -E gcc option, that would generate the analogous listing for D? > > You could add one to the compiler in just > a few lines; there's already a function that > does it, but it isn't called from anywhere. [...] > $ cat test10.d > void main() { > auto a = 0; > } > > # we have to backup because otherwise our original source will be > lost! > $ cp test10.d test10_original.d > > # you'll have to pass the paths for phobos and druntime unless you > bring in a dmd.conf... > $ d/dmd2/src/dmd/dmd -Id/dmd2/src/druntime/import > -Id/dmd2/src/phobos -L-Ld/dmd2/linux/lib32/ test10.d > > $ cat test10.d > // Sym file generated from 'test10.d' > import object; > void main() > { > int a = 0; > return 0; > } [...] Whoa! This is cool. I might take a stab at making this a compiler option (and writing the output to stdout instead of overwriting the original source). I think this will be VERY useful when learning the language, and also when debugging a compiler bug. T -- EMACS = Extremely Massive And Cumbersome System |
March 15, 2012 Re: preprocessor pass equivalent? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jay Norwood | On Thu, 15 Mar 2012 14:34:19 +0100, Jay Norwood <jayn@prismnet.com> wrote:
> I also found mention of a c++ compiler that someone states can compile c++ and output C. Kind of weird, but maybe compiling D to expanded D would not be such a stretch.
That's how early C++ compilers worked. Actually, many compilers work/have
worked that way due to the ease of finding a C compiler for just about
any given platform.
|
March 15, 2012 Re: preprocessor pass equivalent? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jay Norwood | On 2012-03-15 14:34, Jay Norwood wrote: > On Thursday, 15 March 2012 at 10:09:25 UTC, Jacob Carlborg wrote: >>> The Eclipse plugin, Descent, has a view that does something like this. >>> Although I don't know how well it works for D2. >>> >> >> It expands mixins, string mixins, replaces scope statements with >> try/catch/finally and other things. It also has a compile time debugger. > > Wow, that's pretty impressive. Does it do aliases also? I think so and showing the actual type for type inference as well. > I read a little more last night and saw that there is an option for json > output from dmd, and tried it out. Is that meant to serve the purpose of > the gccxml program? > > > I also found mention of a c++ compiler that someone states can compile > c++ and output C. Kind of weird, but maybe compiling D to expanded D > would not be such a stretch. I think LLVM can do this, convert C++ to C, via its byte code. -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation