Changeset 8

Show
Ignore:
Timestamp:
06/07/04 09:17:27 (8 years ago)
Author:
Cabal
Message:

Added support for altering 'version' to 'Version'.
Added expat.h patch.
Added support for C: 'struct XXX; typedef struct XXX *pXXX;'

previously this would have resulted in a extra D error due to 'struct XXX' being forward declared twice.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/h2d/h2d_struct.h

    r6 r8  
    3434// 
    3535// Stuff to deal with struct definitions and 'typedef struct's 
     36// Also strips out extraneous enum definitions - the rules for these follow 
     37// the same for as for struct/union. They may have to be stripped out into  
     38// a separate header at some point. 
    3639// 
    3740 
     
    99102        // we can just gobble it up. 
    100103        reference_ =  
    101           (type_ >> ~chset_p("a-zA-Z0-9_")); 
    102  
    103         // typedef struct [name] { ... } <typedef>[, <typedef>[...]]; 
     104          ((type_ | "enum") >> ~chset_p("a-zA-Z0-9_")); 
     105 
     106        // Sometimes a C header will forward declare a struct type and then 
     107        // immediately typedef it. Without this rule we would end up with  
     108        // the orginal forward decl plus another one for the typedef which 
     109        // would then have to be patched (as D doesn't allow multiple declarations) 
     110        rule_0_ =  
     111          type_[boost::bind(&definition<T>::type, boost::ref(rule_0_), _1, _2, "rule0")] >> +space_p >> 
     112          ((+(alnum_p | '_'))[boost::bind(&definition<T>::name, boost::ref(rule_0_), _1, _2)]) >> *space_p >> 
     113          ';' >> *space_p >> 
     114          // Now for detecting the typedef... 
     115          str_p("alias") >> mws_ >> 
     116          // type - assume that the type in the typedef will match the forward decl 
     117          type_ >> mws_ >>  
     118          // name - must match the one from the forward decl 
     119          f_str_p(boost::bind(&definition<T>::nameBegin, boost::ref(rule_0_)),  
     120                  boost::bind(&definition<T>::nameEnd, boost::ref(rule_0_))) >> mws_ >>  
     121          types_[boost::bind(&definition<T>::types, boost::ref(rule_0_), _1, _2, true)] >> ows_ >> 
     122          (*(ch_p(',') >> ows_ >> types_[boost::bind(&definition<T>::types, boost::ref(rule_0_), _1, _2, false)] >> ows_)) >> 
     123          ch_p(';')[boost::bind(&definition<T>::emitGlobal, boost::ref(rule_0_))];  
     124 
     125        // typedef struct [name] [{ ... }] <typedef>[, <typedef>[...]]; 
    104126        // 'typedef' will have been translated to 'alias' 
    105127        rule_1_ =  
     
    122144          ch_p(';')[boost::bind(&definition<T>::emitGlobal, boost::ref(rule_2_))];  
    123145           
    124         // Remove any instance of the struct keyword that is not followed 
    125         // by a definition block '{...}' - with an optional tag. 
     146        // Remove any instance of the struct/union/enum keywords that is not 
     147        // followed by a definition block '{...}' - with an optional tag. 
    126148        // 'struct <name>;' is also allowed 
    127149        rule_3_ =  
    128           (((type_) >> +space_p >>  
     150          (((type_ | "enum") >> +space_p >>  
    129151            *(alnum_p | '_') >> *space_p >> chset_p("{;"))[boost::bind(&definition<T>::emit, _1, _2)])  
    130152          | 
    131           ((type_) >> +space_p); 
     153          ((type_ | "enum") >> +space_p); 
    132154 
    133155        // The full rule set 
    134         rule_ = rule_1_ | rule_2_ | rule_3_; 
     156        rule_ = rule_0_ | rule_1_ | rule_2_ | rule_3_; 
    135157      } 
    136158       
     
    151173      crule_t nested_; 
    152174      crule_t reference_; 
     175      crule_t rule_0_; 
    153176      crule_t rule_1_; 
    154177      crule_t rule_2_; 
     
    245268#endif 
    246269      } 
     270 
     271      static std::string::iterator nameBegin(crule_t const& rule) { 
     272        return rule.name_().begin(); 
     273      } 
     274      static std::string::iterator nameEnd(crule_t const& rule) { 
     275        return rule.name_().end(); 
     276      } 
    247277    }; 
    248278  }; 
  • trunk/h2d/h2d_xlat.h

    r6 r8  
    6262           |  
    6363           (str_p("class")[boost::bind(&definition<T>::keywordS, this, std::string("Class"))]) 
     64           | 
     65           (str_p("version")[boost::bind(&definition<T>::keywordS, this, std::string("Version"))]) 
    6466           | 
    6567           (str_p("new")[boost::bind(&definition<T>::keywordS, this, std::string("New"))]))