Thread overview
Bug in HTOD handling <<
Jul 28, 2006
Kenneth Bogert
Jul 28, 2006
Walter Bright
Jul 28, 2006
BCS
Jul 29, 2006
Walter Bright
Jul 31, 2006
Andrei Khropov
Jul 31, 2006
BCS
July 28, 2006
HTOD does not handle a #define whose value contains a << operator

example .h file:

    #define CURL_VERSION_IPV6      (1<<0)  /* IPv6-enabled */
    #define CURL_VERSION_KERBEROS4 (1<<1)  /* kerberos auth is supported */
    #define CURL_VERSION_SSL       (1<<2)  /* SSL options are present */
    #define CURL_VERSION_LIBZ      (1<<3)  /* libz features are present */
    #define CURL_VERSION_NTLM      (1<<4)  /* NTLM auth is supported */
    #define CURL_VERSION_GSSNEGOTIATE (1<<5) /* Negotiate auth support */
    #define CURL_VERSION_DEBUG     (1<<6)  /* built with debug
    capabilities */ #define CURL_VERSION_ASYNCHDNS (1<<7)  /* asynchronous
    dns resolves */ #define CURL_VERSION_SPNEGO    (1<<8)  /* SPNEGO auth
    */ #define CURL_VERSION_LARGEFILE (1<<9)  /* supports files bigger
    than 2GB */ #define CURL_VERSION_IDN       (1<<10) /* International
    Domain Names support */ #define CURL_VERSION_SSPI      (1<<11) /* SSPI
    is supported */ #define CURL_VERSION_CONV      (1<<12)

output from htod:

/* Converted to D from curl.h by htod */ module curl;
//C         #define CURL_VERSION_IPV6      (1<<0)  /* IPv6-enabled */
//C         #define CURL_VERSION_KERBEROS4 (1<<1)  /* kerberos auth is
supported */
//C         #define CURL_VERSION_SSL       (1<<2)  /* SSL
options are present */
//C         #define CURL_VERSION_LIBZ      (1<<3)
/* libz features are present */
//C         #define CURL_VERSION_NTLM
(1<<4)  /* NTLM auth is supported */
//C         #define
CURL_VERSION_GSSNEGOTIATE (1<<5) /* Negotiate auth support */
//C         #define CURL_VERSION_DEBUG     (1<<6)  /* built with debug
capabilities */
//C         #define CURL_VERSION_ASYNCHDNS (1<<7)  /*
asynchronous dns resolves */
//C         #define CURL_VERSION_SPNEGO
(1<<8)  /* SPNEGO auth */
//C         #define CURL_VERSION_LARGEFILE
(1<<9)  /* supports files bigger than 2GB */
//C         #define CURL_VERSION_IDN (1<<10) /* International Domain Names
support */ //C         #define CURL_VERSION_SSPI      (1<<11) /* SSPI is
supported */ //C         #define CURL_VERSION_CONV      (1<<12)

I've tried removing the parenthesis with the same results.

kdb
July 28, 2006
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.
July 28, 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>
July 29, 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.
July 31, 2006
BCS wrote:

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

Not 'auto' but 'const' is more appropriate here:

>  |
>  v
> htod
>  |
>  v
> 
> <code name="foo.d">
> 
> const value = 3;
> const name = ("BCS");
> const mask3 = (0x01<3);
> const mask5 = (0x01<5);
> const mask35 = (mask3 | mask5);
> 
> </code>



-- 

July 31, 2006
Andrei Khropov wrote:
> BCS wrote:
>[...]
> Not 'auto' but 'const' is more appropriate here:
> 

Me stupid, that would be better