Changeset 8
- Timestamp:
- 06/07/04 09:17:27 (8 years ago)
- Files:
-
- trunk/h2d/h2d_struct.h (modified) (5 diffs)
- trunk/h2d/h2d_xlat.h (modified) (1 diff)
- trunk/h2d/patches/expat.diff (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/h2d/h2d_struct.h
r6 r8 34 34 // 35 35 // 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. 36 39 // 37 40 … … 99 102 // we can just gobble it up. 100 103 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>[...]]; 104 126 // 'typedef' will have been translated to 'alias' 105 127 rule_1_ = … … 122 144 ch_p(';')[boost::bind(&definition<T>::emitGlobal, boost::ref(rule_2_))]; 123 145 124 // Remove any instance of the struct keyword that is not followed125 // 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. 126 148 // 'struct <name>;' is also allowed 127 149 rule_3_ = 128 (((type_ ) >> +space_p >>150 (((type_ | "enum") >> +space_p >> 129 151 *(alnum_p | '_') >> *space_p >> chset_p("{;"))[boost::bind(&definition<T>::emit, _1, _2)]) 130 152 | 131 ((type_ ) >> +space_p);153 ((type_ | "enum") >> +space_p); 132 154 133 155 // The full rule set 134 rule_ = rule_ 1_ | rule_2_ | rule_3_;156 rule_ = rule_0_ | rule_1_ | rule_2_ | rule_3_; 135 157 } 136 158 … … 151 173 crule_t nested_; 152 174 crule_t reference_; 175 crule_t rule_0_; 153 176 crule_t rule_1_; 154 177 crule_t rule_2_; … … 245 268 #endif 246 269 } 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 } 247 277 }; 248 278 }; trunk/h2d/h2d_xlat.h
r6 r8 62 62 | 63 63 (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"))]) 64 66 | 65 67 (str_p("new")[boost::bind(&definition<T>::keywordS, this, std::string("New"))]))
