| 171 | | toks = filt_code(toks, /^D i(ai)? ?;/, "commentout_deleteop") |
| 172 | | toks = change_variable_declaration_nstype(toks) |
| 173 | | toks = change_variable_declaration(toks) |
| 174 | | toks = change_arrow_to_dot(toks) |
| 175 | | toks = change_namespace_to_class(toks) |
| 176 | | puts toks.map{|t| t.body}.join('') |
| | 181 | toks = filt_code(toks, /^(v ?= ?)d/, "change_zeronull") |
| | 182 | toks = filt_code(toks, /^t<(i\*?)>\(i(\.i)?\)/,"change_static_cast") |
| | 183 | toks = filt_code(toks, /^D i(ai)? ?;/, "commentout_deleteop") |
| | 184 | toks = filt_code(toks, /^(ini ?)i ?=/, "change_variable_declaration_nstype") |
| | 185 | toks = filt_code(toks, /^(i ?\* ?)i ?=/, "change_variable_declaration") |
| | 186 | toks = filt_code(toks, /^P i ?=/, "change_p_variable_declaration") |
| | 187 | toks = filt_arrow_to_dot(toks) |
| | 188 | toks = filt_code(toks, /^ini/, "change_namespace_to_class") |
| | 189 | |
| | 190 | toks |
| | 214 | def change_zeronull(outtoks, intoks, keys, match) |
| | 215 | |
| | 216 | |
| | 217 | tokcount = match[0].length |
| | 218 | pvarname = intoks[0].body |
| | 219 | val = intoks[match[1].length].body |
| | 220 | |
| | 221 | return nil if pvarname != '$$' || val != '0' |
| | 222 | |
| | 223 | new_toks = generate_token("#{pvarname} = null /* 0 */") |
| | 224 | |
| | 225 | keys = keys[tokcount,keys.length] |
| | 226 | tokcount.times do |
| | 227 | intoks.shift |
| | 228 | end |
| | 229 | |
| | 230 | new_toks.each{|t| outtoks << t} |
| | 231 | |
| | 232 | return keys |
| | 233 | end |
| | 234 | |
| | 235 | def change_static_cast(outtoks, intoks, keys, match) |
| | 236 | tokcount = match[0].length |
| | 237 | |
| | 238 | casttype = intoks[2].body |
| | 239 | varname = intoks[match[1].length+4].body |
| | 240 | |
| | 241 | cmt = "" |
| | 242 | if TYPE_MAP.key?(casttype) |
| | 243 | cmt = " /* original: #{casttype} */" |
| | 244 | casttype = TYPE_MAP[casttype] |
| | 245 | end |
| | 246 | |
| | 247 | new_toks = generate_token("(#{varname} as #{casttype}#{cmt})") |
| | 248 | |
| | 249 | keys = keys[tokcount,keys.length] |
| | 250 | tokcount.times do |
| | 251 | intoks.shift |
| | 252 | end |
| | 253 | |
| | 254 | new_toks.each{|t| outtoks << t} |
| | 255 | |
| | 256 | return keys |
| | 257 | end |
| | 258 | |
| 210 | | def change_variable_declaration_nstype(toks) |
| 211 | | ret = [] |
| 212 | | keys = make_tokkey_string(toks) |
| 213 | | |
| 214 | | loop do |
| 215 | | if keys =~ /^(ini ?)i ?=/ |
| 216 | | tokcount = $&.length |
| 217 | | |
| 218 | | vartype = toks[2].body |
| 219 | | varname = toks[$1.length].body |
| 220 | | |
| 221 | | cmt = "" |
| 222 | | if TYPE_MAP.key?(vartype) |
| 223 | | cmt = "/* typedefed #{vartype} */ " |
| 224 | | vartype = TYPE_MAP[vartype] |
| 225 | | end |
| 226 | | |
| 227 | | new_toks = generate_token("var #{varname}:#{vartype} #{cmt}=") |
| 228 | | |
| 229 | | keys = keys[tokcount,keys.length] |
| 230 | | tokcount.times do |
| 231 | | toks.shift |
| 232 | | end |
| 233 | | |
| 234 | | new_toks.each{|t| ret << t} |
| 235 | | else |
| 236 | | ret << toks.shift |
| 237 | | keys = keys[1,keys.length] |
| 238 | | end |
| 239 | | break if keys.length < 1 |
| 240 | | end |
| 241 | | |
| 242 | | ret |
| 243 | | end |
| 244 | | |
| 245 | | def change_variable_declaration(toks) |
| 246 | | ret = [] |
| 247 | | keys = make_tokkey_string(toks) |
| 248 | | |
| 249 | | loop do |
| 250 | | if keys =~ /^(i ?\* ?)i ?=/ |
| 251 | | tokcount = $&.length |
| 252 | | |
| 253 | | vartype = toks[0].body |
| 254 | | varname = toks[$1.length].body |
| 255 | | new_toks = generate_token("var #{varname}:#{vartype} =") |
| 256 | | |
| 257 | | keys = keys[tokcount,keys.length] |
| 258 | | tokcount.times do |
| 259 | | toks.shift |
| 260 | | end |
| 261 | | |
| 262 | | new_toks.each{|t| ret << t} |
| 263 | | else |
| 264 | | ret << toks.shift |
| 265 | | keys = keys[1,keys.length] |
| 266 | | end |
| 267 | | break if keys.length < 1 |
| 268 | | end |
| 269 | | |
| 270 | | ret |
| 271 | | end |
| 272 | | |
| 273 | | def change_arrow_to_dot(toks) |
| | 274 | def change_variable_declaration_nstype(outtoks, intoks, keys, match) |
| | 275 | tokcount = match[0].length |
| | 276 | |
| | 277 | vartype = intoks[2].body |
| | 278 | varname = intoks[match[1].length].body |
| | 279 | |
| | 280 | cmt = "" |
| | 281 | if TYPE_MAP.key?(vartype) |
| | 282 | cmt = "/* original: #{vartype} */ " |
| | 283 | vartype = TYPE_MAP[vartype] |
| | 284 | end |
| | 285 | |
| | 286 | new_toks = generate_token("var #{varname}:#{vartype} #{cmt}=") |
| | 287 | |
| | 288 | keys = keys[tokcount,keys.length] |
| | 289 | tokcount.times do |
| | 290 | intoks.shift |
| | 291 | end |
| | 292 | |
| | 293 | new_toks.each{|t| outtoks << t} |
| | 294 | |
| | 295 | return keys |
| | 296 | end |
| | 297 | |
| | 298 | def change_variable_declaration(outtoks, intoks, keys, match) |
| | 299 | tokcount = match[0].length |
| | 300 | |
| | 301 | vartype = intoks[0].body |
| | 302 | varname = intoks[match[1].length].body |
| | 303 | |
| | 304 | cmt = "" |
| | 305 | if TYPE_MAP.key?(vartype) |
| | 306 | cmt = "/* original: #{vartype} */ " |
| | 307 | vartype = TYPE_MAP[vartype] |
| | 308 | end |
| | 309 | |
| | 310 | new_toks = generate_token("var #{varname}:#{vartype} #{cmt}=") |
| | 311 | |
| | 312 | keys = keys[tokcount,keys.length] |
| | 313 | tokcount.times do |
| | 314 | intoks.shift |
| | 315 | end |
| | 316 | |
| | 317 | new_toks.each{|t| outtoks << t} |
| | 318 | |
| | 319 | return keys |
| | 320 | end |
| | 321 | |
| | 322 | def change_p_variable_declaration(outtoks, intoks, keys, match) |
| | 323 | tokcount = match[0].length |
| | 324 | |
| | 325 | vartype = intoks[0].body |
| | 326 | varname = intoks[2].body |
| | 327 | |
| | 328 | new_toks = generate_token("var #{varname}:#{vartype} =") |
| | 329 | |
| | 330 | keys = keys[tokcount,keys.length] |
| | 331 | tokcount.times do |
| | 332 | intoks.shift |
| | 333 | end |
| | 334 | |
| | 335 | new_toks.each{|t| outtoks << t} |
| | 336 | |
| | 337 | return keys |
| | 338 | end |
| | 339 | |
| | 340 | def filt_arrow_to_dot(toks) |
| 277 | | def change_namespace_to_class(toks) |
| 278 | | ret = [] |
| 279 | | |
| 280 | | keys = make_tokkey_string(toks) |
| 281 | | loop do |
| 282 | | if keys =~ /^ini/ |
| 283 | | ret << toks.shift |
| 284 | | |
| 285 | | ret << Token.new(nil, '.', "single_char") |
| 286 | | toks.shift # ignore '::' |
| 287 | | |
| 288 | | ret << toks.shift |
| 289 | | keys = keys[3,keys.length] |
| 290 | | else |
| 291 | | ret << toks.shift |
| 292 | | keys = keys[1,keys.length] |
| 293 | | end |
| 294 | | |
| 295 | | break if keys.length < 1 |
| 296 | | end |
| 297 | | |
| 298 | | ret |
| | 344 | def change_namespace_to_class(outtoks, intoks, keys, match) |
| | 345 | outtoks << intoks.shift |
| | 346 | |
| | 347 | outtoks << Token.new(nil, '.', "single_char") |
| | 348 | intoks.shift # ignore '::' |
| | 349 | |
| | 350 | outtoks << intoks.shift |
| | 351 | |
| | 352 | return keys[3,keys.length] |