Bug in HTOD handling <<

Walter Bright newshound at digitalmars.com
Fri Jul 28 17:10:19 PDT 2006


BCS wrote:
> 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)?

Yes. But HTOD doesn't. Macro replacement text is seen as ... text.


> 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;
> 
> ?

The problem is reliably identifying an Expression out of a j-random 
sequence of characters.

> 
> 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>

I'm not saying it's impossible, and I agree it would be a nice addition. 
But it's a lot of work.



More information about the Digitalmars-d-bugs mailing list