Bug in HTOD handling <<

BCS BCS at pathlink.com
Fri Jul 28 15:15:55 PDT 2006


Walter Bright wrote:
> Kenneth Bogert wrote:
> 
>> HTOD does not handle a #define whose value contains a << operator
> 
> 
> That's right, it doesn't recognized anything beyond simple literals.


Doesn't DMD do constant folding on things like (1<<3)?

IIRC D expressions are trivially convertible to D (often no convention 
is needed). Couldn't htod just convert

	"#define" identifier Expression EOL

to

	"const" "auto" identifier "=" Expression;

?

With a few conventions to Expression (cast conventions, etc.) this would 
cover a lot of ground. Even without the convention (just copy things 
that don't need convention) this would be fantastic.


<code name="foo.h">

#define value 3
#define name ("BCS")
#define mask3 (0x01<3)
#define mask5 (0x01<5)
#define mask35 (mask3 | mask5)

</code>

  |
  v
htod
  |
  v

<code name="foo.d">

auto value = 3;
auto name = ("BCS");
auto mask3 = (0x01<3);
auto mask5 = (0x01<5);
auto mask35 = (mask3 | mask5);

</code>



More information about the Digitalmars-d-bugs mailing list