Phil Deets wrote: > Hello, I looked over the language specification, and I could not find > any statement which says where version conditions are permitted. I > assumed that they would be permitted most places that #if would be > reasonable in C, but evidently that is not true as they do not work > within enumerations. I would definitely like the following code to work. > > enum Tag > { > A, B, C, > version (5) { > D, E, > } > version (7) { > F, G, > } > // ... > } > > Added enumerated values based on versions seems like something that > would be desirable. I ran into this need when converting a header file > to D. > > Does anyone know where version conditions are and are not allowed > currently? > Would version conditions within enumerations be a good feature to add to > D2? > > If people like the idea, but the implementation is prevented due to > manpower issues, I can possibly try to implement it if you give me a > pointer on potential issues and where to look within the source code.
They be allowed at declaration level and statement level (which is just about everywhere except in enum bodies). If you want to change this, have a look in parse.c, Parser::parseEnum your enum body cc blocks will of course have to only allow enum members in their bodies + more cc blocks, which might be a bit of work, depending on how flexible the relevant structs are. you'll also have to muck around with semantic analysis so it can see the conditionals and expand them correctly. I don't stray outside parse.c much, but I bet enum.c, EnumDeclaration::semantic would be the place to start. And the subject has been brought up before (probably more than once). http://www.digitalmars.com/d/archives/digitalmars/D/Conditional_compilation_inside_asm_and_enum_declarations_93200.html I thought the reason we don't have them is because Walter hates them (read: knows they are evil) and actively seeks to discourage their use. However, she'd be a dandy feature to have, and I wouldn't mind adding her to my local collection of patches (which is almost empty since the last release:) if nothing else.