Ticket #5: bcdgen.patch
File bcdgen.patch, 29.4 kB (added by MrSunshine, 15 years ago) |
---|
-
bcd/gen/bcdgen.d
old new 29 29 version (Windows) { 30 30 import common.path; 31 31 } else { 32 import std.path;32 // import std.path; 33 33 } 34 import tango.stdc.string; 35 import tango.util.PathUtil; 36 import tango.stdc.stringz; 37 import tango.stdc.stdlib; 38 import tango.sys.Process; 39 import tango.sys.Environment; 40 import tango.io.FilePath; 41 import tango.io.File; 42 import tango.io.Stdout; 43 import tango.text.Util; 44 import Integer = tango.text.convert.Integer; 45 import tango.core.Exception; 46 import tango.io.stream.FileStream; 47 import tango.io.stream.LineStream; 48 //import std.file; 49 //import std.process; 50 //import std.stdio; 51 //import std.stream; 52 //import std.string; 34 53 35 import std.file; 36 import std.process; 37 import std.stdio; 38 import std.stream; 39 import std.string; 54 //import std.c.stdlib; 55 //alias std.string.atoi atoi; 56 //alias std.c.stdlib.free free; 57 //alias std.process.system system; 40 58 41 import std.c.stdlib;42 alias std.string.atoi atoi;43 alias std.c.stdlib.free free;44 alias std.process.system system;45 46 59 private import bcd.gen.libxml2; 47 60 61 char [] getName(char [] name) { 62 Stdout.formatln("path: {}, filename: {}", ((new FilePath(name)).path()), (new FilePath(name)).name()); 63 return ((new FilePath(name)).path()) ~ (new FilePath(name)).name().dup; 64 } 65 48 66 extern (C) char* getenv(char*); 49 67 extern (C) int system(char *); 50 68 // some global variables (yay) 51 69 private { 52 70 /** The full path to the current file */ … … 126 144 } 127 145 128 146 if (args.length < 3) { 129 writefln("Use:");130 writefln("bcdgen <.h file> <D namespace> [options]");131 writefln("Options:");132 writefln(" -I<include prefix>");133 writefln(" -C");134 writefln(" Read/write C instead of C++");135 writefln(" -A");136 writefln(" Include all symbols provided by headers in the same");137 writefln(" directory as the provided one, regardless of whether");138 writefln(" they are actually provded by the included file.");139 writefln(" -F<forced import>");140 writefln(" -R<include directory>=<BCD/D namespace>");141 writefln(" Depend upon other BCD namespaces.");142 writefln(" -r");143 writefln(" Reflect C++ classes such that D classes can derive from");144 writefln(" them.");145 writefln(" -E");146 writefln(" Generate const int's for unnamed enum values");147 writefln(" -T<template class>[=<count>]");148 writefln(" Make the given template class accessable from D. If the");149 writefln(" class has more than one template parameter, also provide");150 writefln(" the count.");151 writefln(" -N<symbol to ignore>");152 writefln(" -P");153 writefln(" Pollute namespaces (make named enum values public)");154 writefln(" -b");155 writefln(" Do not prepend 'bcd.' to the D namespace.");156 writefln(" -DV");157 writefln(" Generate default values for function arguments.");147 Stdout.formatln("Use:"); 148 Stdout.formatln("bcdgen <.h file> <D namespace> [options]"); 149 Stdout.formatln("Options:"); 150 Stdout.formatln(" -I<include prefix>"); 151 Stdout.formatln(" -C"); 152 Stdout.formatln(" Read/write C instead of C++"); 153 Stdout.formatln(" -A"); 154 Stdout.formatln(" Include all symbols provided by headers in the same"); 155 Stdout.formatln(" directory as the provided one, regardless of whether"); 156 Stdout.formatln(" they are actually provded by the included file."); 157 Stdout.formatln(" -F<forced import>"); 158 Stdout.formatln(" -R<include directory>=<BCD/D namespace>"); 159 Stdout.formatln(" Depend upon other BCD namespaces."); 160 Stdout.formatln(" -r"); 161 Stdout.formatln(" Reflect C++ classes such that D classes can derive from"); 162 Stdout.formatln(" them."); 163 Stdout.formatln(" -E"); 164 Stdout.formatln(" Generate const int's for unnamed enum values"); 165 Stdout.formatln(" -T<template class>[=<count>]"); 166 Stdout.formatln(" Make the given template class accessable from D. If the"); 167 Stdout.formatln(" class has more than one template parameter, also provide"); 168 Stdout.formatln(" the count."); 169 Stdout.formatln(" -N<symbol to ignore>"); 170 Stdout.formatln(" -P"); 171 Stdout.formatln(" Pollute namespaces (make named enum values public)"); 172 Stdout.formatln(" -b"); 173 Stdout.formatln(" Do not prepend 'bcd.' to the D namespace."); 174 Stdout.formatln(" -DV"); 175 Stdout.formatln(" Generate default values for function arguments."); 158 176 return 1; 159 177 } 160 178 … … 166 184 curFile = args[1]; 167 185 version (Windows) { 168 186 // get*Name only works with \, but gccxml only works with / 169 curFile = replace(curFile, "\\", "/");187 curFile = substitute(curFile, "\\", "/"); 170 188 char[] backslashName = replace(args[1], "/", "\\"); 171 baseDir = replace(getDirName(backslashName), "\\", "/");172 shortName = getBaseName(backslashName);189 baseDir = substitute((new FilePath(backslashName)).path(), "\\", "/"); 190 shortName = (new FilePath(backslashName)).file(); 173 191 } else { 174 baseDir = getDirName(args[1]);175 shortName = getBaseName(args[1]);192 baseDir = (new FilePath(args[1])).path(); 193 shortName = (new FilePath(args[1])).file(); 176 194 } 177 if ( find(shortName, '.') != -1) {178 195 if (locate(shortName, '.') != shortName.length) { 196 shortName = getName(shortName); 179 197 } 180 198 shortName = safeName(shortName); 181 199 … … 192 210 193 211 } else if (args[i][0..2] == "-R") { 194 212 char[] req = args[i][2..args[i].length]; 195 int eqloc = find(req, '=');196 if (eqloc == -1) {197 writefln("Argument %s not recognized.", args[i]);213 int eqloc = locate(req, '='); 214 if (eqloc == req.length) { 215 Stdout.formatln("Argument %s not recognized.", args[i]); 198 216 continue; 199 217 } 200 218 reqDependencies[req[0..eqloc]] = req[eqloc + 1 .. req.length]; … … 209 227 char[] temp = args[i][2..args[i].length]; 210 228 int count = 1, eqloc; 211 229 212 eqloc = find(temp, '=');213 if (eqloc != -1) {214 count = atoi(temp[eqloc + 1 .. temp.length]);230 eqloc = locate(temp, '='); 231 if (eqloc != temp.length) { 232 count = Integer.parse(temp[eqloc + 1 .. temp.length]); 215 233 temp = temp[0..eqloc]; 216 234 } 217 235 … … 234 252 } else if (args[i] == "-DV") { 235 253 defaultValues = true; 236 254 } else { 237 writefln("Argument %s not recognized.", args[i]);255 Stdout.formatln("Argument %s not recognized.", args[i]); 238 256 } 239 257 } 240 258 … … 253 271 cout ~= "#include <stdlib.h>\n"; 254 272 cout ~= "#include <string.h>\n"; 255 273 cout ~= "#include \"../bind.h\"\n"; 256 cout ~= "#include \"" ~ incPrefix ~ getBaseName(args[1]) ~ "\"\n";274 cout ~= "#include \"" ~ incPrefix ~ (new FilePath(args[1])).file() ~ "\"\n"; 257 275 if (!outputC) cout ~= "extern \"C\" {\n"; 258 276 259 277 // make the directories 260 278 try { 261 mkdir("bcd"); 262 } catch (FileException e) {} // ignore errors 263 try { 264 mkdir("bcd/" ~ dNamespace); 265 } catch (FileException e) {} // ignore errors 279 (new FilePath("bcd/" ~ dNamespace)).create(); 280 } catch (IOException e) { 281 Stdout.formatln("hora"); 282 } // ignore errors 266 283 267 284 // make the template file if requested 268 285 if (templates != "") { 269 write("bcd/" ~ dNamespace ~ "/template_D.h",286 (new File("bcd/" ~ dNamespace ~ "/template_D.h")).write( 270 287 "#include \"../bind.h\"\n" ~ 271 "#include \"" ~ incPrefix ~ getBaseName(args[1]) ~ "\"\n" ~288 "#include \"" ~ incPrefix ~ (new FilePath(args[1])).file() ~ "\"\n" ~ 272 289 templates); 273 290 templates = "-include bcd/" ~ dNamespace ~ "/template_D.h "; 274 291 } 275 292 276 293 // gccxml options 277 char[] gccxmlopts = templates ~ 278 toString(getenv(toStringz(outputC ? "CFLAGS" : "CXXFLAGS"))); 294 char[] gccxmlopts = templates ~ Environment.get(outputC ? "CFLAGS" : "CXXFLAGS"); 295 296 // toString(getenv(toStringz(outputC ? "CFLAGS" : "CXXFLAGS"))); 279 297 280 298 // preprocess it 281 if (system(gccxmlExe ~ " -E -dD " ~ gccxmlopts ~ " -o out.i " ~ args[1])) {299 if(system(toStringz(gccxmlExe ~ " -E -dD " ~ gccxmlopts ~ " -o out.i " ~ args[1])) == -1) 282 300 return 2; 283 }284 301 285 302 parse_Defines(); 286 303 287 304 // xml-ize it 288 if (system(gccxmlExe ~ " " ~ gccxmlopts ~ 289 " -fxml=out.xml " ~ args[1])) { 290 return 2; 291 } 305 system(toStringz(gccxmlExe ~ " " ~ gccxmlopts ~" -fxml=out.xml " ~ args[1])); 292 306 293 307 // then initialize libxml2 294 308 xmlDoc *doc = null; … … 300 314 doc = xmlReadFile("out.xml", null, 0); 301 315 302 316 if (doc == null) { 303 writefln("Failed to parse the GCCXML-produced XML file!");317 Stdout.formatln("Failed to parse the GCCXML-produced XML file!"); 304 318 return 3; 305 319 } 306 320 … … 314 328 if (!outputC) cout ~= "}\n"; 315 329 316 330 // write out the files 317 write("bcd/" ~ dNamespace ~ "/" ~ shortName ~ ".d", 318 dhead ~ dtail); 331 (new File("bcd/" ~ dNamespace ~ "/" ~ shortName ~ ".d")).write(dhead ~ dtail); 319 332 if (!outputC) { 320 write("bcd/" ~ dNamespace ~ "/" ~ shortName ~ ".cc", 321 cout); 333 (new File("bcd/" ~ dNamespace ~ "/" ~ shortName ~ ".cc")).write(cout); 322 334 } 323 335 324 336 // get rid of the files we no longer need 325 337 if (templates != "") { 326 std.file.remove("bcd/" ~ dNamespace ~ "/template_D.h");338 (new FilePath("bcd/" ~ dNamespace ~ "/template_D.h")).remove(); 327 339 } 328 340 //std.file.remove("out.i"); 329 341 //std.file.remove("out.xml"); … … 398 410 ret ~= "_"; 399 411 } 400 412 401 ret = replace(ret, ".", "_");402 ret = replace(ret, "-", "_");413 ret = substitute(ret, ".", "_"); 414 ret = substitute(ret, "-", "_"); 403 415 404 416 // drop any template info 405 int tloc = find(ret, '<');406 if (tloc != -1) {417 int tloc = locate(ret, '<'); 418 if (tloc != ret.length) { 407 419 ret = ret[0..tloc] ~ "_D"; 408 420 } 409 421 … … 431 443 char[] toStringFree(char* from) 432 444 { 433 445 char[] ret; 434 ret ~= toString(from);446 ret ~= fromStringz(from); 435 447 free(from); 436 448 return ret; 437 449 } … … 474 486 // if it's not in a file we should be parsing, don't output it 475 487 if (outputAll) { 476 488 if (files[sfile].length <= baseDir.length || 477 ! fnmatch(files[sfile][0..baseDir.length], baseDir)) return false;489 !patternMatch(files[sfile][0..baseDir.length], baseDir)) return false; 478 490 } else { 479 491 if (files[sfile] != curFile) return false; 480 492 } … … 522 534 if (!members) return; 523 535 524 536 char[] smembers = toStringFree(members); 525 char[][] memberList = split(smembers);537 char[][] memberList = delimit(smembers, " "); 526 538 527 539 // parse each member in the memberList 528 540 foreach (m; memberList) { … … 541 553 // first parse for files and fundamental types 542 554 for (curNode = gccxml.children; curNode; curNode = curNode.next) { 543 555 if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 544 char[] nname = toString(curNode.name);556 char[] nname = fromStringz(curNode.name); 545 557 546 558 //writefln(" %s", nname); 547 559 … … 554 566 // then parse for namespaces, typedefs, enums (all of which can be top-level) 555 567 for (curNode = gccxml.children; curNode; curNode = curNode.next) { 556 568 if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 557 char[] nname = toString(curNode.name);569 char[] nname = fromStringz(curNode.name); 558 570 559 571 //writefln(" %s", nname); 560 572 … … 567 579 } else if (nname == "Class") { 568 580 // special case for template classes 569 581 char[] sname = toStringFree(xmlGetProp(curNode, "name")); 570 if ( find(sname, "<DReflectedClass>") != -1) {582 if (locatePattern(sname, "<DReflectedClass>") != sname.length) { 571 583 parse_Class(curNode); 572 584 } 573 585 } … … 585 597 586 598 for (curNode = gccxml.children; curNode; curNode = curNode.next) { 587 599 if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 588 char[] nname = toString(curNode.name);589 600 char[] nname = fromStringz(curNode.name); 601 590 602 char *id = xmlGetProp(curNode, "id"); 591 if (parseFor != toStringFree(id)) continue; 603 604 if (parseFor != toStringFree(id)) continue; 592 605 593 606 if (nname == "Constructor") { 594 607 // this may be private or otherwise unparsable, but we do have one 595 608 hasConstructor = true; 596 609 } 597 610 598 611 // types that can be nameless: 599 612 if (!parseThis(curNode, true)) continue; 600 613 601 614 if (nname == "Struct" || nname == "Class") { 602 615 // structs and classes are the same in C[++] 603 616 if (outputC) { 604 617 if (types) parse_Struct(curNode); … … 633 646 } else if (nname == "Enumeration") { 634 647 if (types && !reflection) parse_Enumeration(curNode); 635 648 } else { 636 writefln("I don't know how to parse %s!", nname);649 Stdout.formatln("I don't know how to parse %s!", nname); 637 650 } 638 651 } 639 652 } … … 649 662 id = xmlGetProp(node, "id"); 650 663 name = xmlGetProp(node, "name"); 651 664 if (id && name) { 652 char[] sname = toString(name);665 char[] sname = fromStringz(name); 653 666 654 667 files[toStringFree(id)] = sname; 655 668 656 669 // import it in D 657 670 658 671 // first try our own namespace if we didn't use -A 659 if (!outputAll && getDirName(sname) == baseDir) {660 char[] baseName = sname[baseDir.length + 1.. sname.length];661 if ( find(baseName, '.') != -1) {672 if (!outputAll && (new FilePath(sname)).path() == baseDir) { 673 char[] baseName = sname[baseDir.length .. sname.length]; 674 if (locate(baseName, '.') != baseName.length) { 662 675 baseName = getName(baseName); 663 676 } 664 677 678 Stdout.formatln("dNamespaceBase: {}, dNamespace: {}, safeName(baseName): {}, baseName: {}", dNamespaceBase, dNamespace, safeName(baseName), baseName); 665 679 if (baseName != shortName) 666 680 dhead ~= "public import " ~ dNamespaceBase ~ dNamespace ~ "." ~ safeName(baseName) ~ ";\n"; 667 681 } 668 682 669 683 // then others 670 684 foreach (req; reqDependencies.keys) { 671 if ( getDirName(sname) == req) {672 char[] baseName = sname[req.length + 1.. sname.length];673 if ( find(baseName, '.') != -1) {685 if ((new FilePath(sname)).path() == req) { 686 char[] baseName = sname[req.length .. sname.length]; 687 if (locate(baseName, '.') != baseName.length) { 674 688 baseName = getName(baseName); 675 689 } 676 690 … … 718 732 xmlNode *curNode = null; 719 733 for (curNode = node.children; curNode; curNode = curNode.next) { 720 734 if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 721 if ( toString(curNode.name) == "Base") {735 if (fromStringz(curNode.name) == "Base") { 722 736 ParsedType pt = parseType(toStringFree(xmlGetProp(curNode, "type"))); 723 737 base = pt.DType; 724 738 break; … … 727 741 } 728 742 729 743 // if this is derived from a template, the derivation is worthless from D 730 if ( find(base, '<') != -1) base = "bcd.bind.BoundClass";744 if (locate(base, '<') != base.length) base = "bcd.bind.BoundClass"; 731 745 732 746 dtail ~= "class " ~ safeName(name) ~ " : " ~ base ~ " {\n"; 733 747 … … 846 860 xmlNode *curNode = null; 847 861 for (curNode = node.children; curNode; curNode = curNode.next) { 848 862 if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 849 if ( toString(curNode.name) == "Base") {863 if (fromStringz(curNode.name) == "Base") { 850 864 851 865 // find the base class 852 866 char[] type = toStringFree(xmlGetProp(curNode, "type")); … … 873 887 */ 874 888 void parse_Struct(xmlNode *node) 875 889 { 876 char[] type = toString(node.name);890 char[] type = fromStringz(node.name); 877 891 char[] name = getNName(node); 878 892 char[] mangled = toStringFree(getMangled(node)); 879 893 char[] demangled = toStringFree(getDemangled(node)); 880 894 char[] prevCurClass = curClass; 881 895 896 Stdout.formatln("parse struct"); 882 897 parseMembers(node, true, true); 883 898 884 899 if (type == "Union") { … … 991 1006 992 1007 for (curNode = node.children; curNode; curNode = curNode.next) { 993 1008 if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 994 char[] nname = toString(curNode.name);995 char[] def = toString(xmlGetProp(curNode, "default"));1009 char[] nname = fromStringz(curNode.name); 1010 char[] def = fromStringz(xmlGetProp(curNode, "default")); 996 1011 997 1012 if(def == "NULL") 998 1013 def = "null"; … … 1000 1015 if (nname == "Argument") { 1001 1016 ParsedType atype = parseType(toStringFree(xmlGetProp(curNode, "type"))); 1002 1017 char[] aname = getNName(curNode); 1003 if (aname == "") aname = "_" ~ toString(onParam);1018 if (aname == "") aname = "_" ~ Integer.toString(onParam); 1004 1019 aname = safeName(aname); 1005 1020 1006 1021 if(def == "0" && 1007 ( find(atype.DType, "*") != -1||1022 (locate(atype.DType, '*') != atype.DType.length || 1008 1023 atype.isFunctionPtr)) 1009 1024 def = "null"; 1010 1025 … … 1052 1067 if (atype.isClass) { 1053 1068 Dcall ~= "new " ~ atype.className ~ "(cast(ifloat) 0, " ~ aname ~ ")"; 1054 1069 } else if (atype.isClassPtr) { 1055 Dcall ~= "cast(" ~ atype.DType ~ ") new " ~ replace(atype.DType, " *", "") ~ "(cast(ifloat) 0, " ~ aname ~ ")";1070 Dcall ~= "cast(" ~ atype.DType ~ ") new " ~ substitute(atype.DType, " *", "") ~ "(cast(ifloat) 0, " ~ aname ~ ")"; 1056 1071 } else { 1057 1072 Dcall ~= aname; 1058 1073 } … … 1104 1119 Ccall ~= "..."; 1105 1120 1106 1121 } else { 1107 writefln("I don't know how to parse %s!", nname);1122 Stdout.formatln("I don't know how to parse %s!", nname); 1108 1123 } 1109 1124 1110 1125 onParam++; … … 1435 1450 char[] Ccall; 1436 1451 1437 1452 // the demangled name includes () 1438 int demparen = find(demangled, '(');1439 if (demparen != -1) {1453 int demparen = locate(demangled, '('); 1454 if (demparen != demangled.length) { 1440 1455 demangled = demangled[0..demparen]; 1441 1456 } 1442 1457 … … 1457 1472 char[] mangled = toStringFree(getMangled(node)); 1458 1473 if (reflection) mangled ~= "_R"; 1459 1474 1460 while ( find(mangled, "*INTERNAL*") != -1) {1461 mangled = replace(mangled, " *INTERNAL* ", "");1475 while (locatePattern(mangled, "*INTERNAL*") != mangled.length) { 1476 mangled = substitute(mangled, " *INTERNAL* ", ""); 1462 1477 } 1463 1478 1464 1479 // no artificial constructors … … 1581 1596 1582 1597 for (curNode = node.children; curNode; curNode = curNode.next) { 1583 1598 if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 1584 char[] nname = toString(curNode.name);1599 char[] nname = fromStringz(curNode.name); 1585 1600 1586 1601 if (nname == "EnumValue") { 1587 1602 dhead ~= safeName(getNName(curNode)) ~ "=" ~ 1588 1603 toStringFree(xmlGetProp(curNode, "init")) ~ ",\n"; 1589 1604 } else { 1590 writefln("I don't know how to parse %s!", nname);1605 Stdout.formatln("I don't know how to parse %s!", nname); 1591 1606 } 1592 1607 } 1593 1608 } … … 1598 1613 { 1599 1614 for (curNode = node.children; curNode; curNode = curNode.next) { 1600 1615 if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 1601 char[] nname = toString(curNode.name);1616 char[] nname = fromStringz(curNode.name); 1602 1617 1603 1618 if (nname == "EnumValue") { 1604 1619 dhead ~= "alias " ~ safeName(aname) ~ "." ~ safeName(getNName(curNode)) ~ " " ~ 1605 1620 safeName(getNName(curNode)) ~ ";\n"; 1606 1621 } else { 1607 writefln("I don't know how to parse %s!", nname);1622 Stdout.formatln("I don't know how to parse %s!", nname); 1608 1623 } 1609 1624 } 1610 1625 } … … 1614 1629 if (outputEnumConst && !realName) { 1615 1630 for (curNode = node.children; curNode; curNode = curNode.next) { 1616 1631 if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 1617 char[] nname = toString(curNode.name);1632 char[] nname = fromStringz(curNode.name); 1618 1633 1619 1634 if (nname == "EnumValue") { 1620 1635 dhead ~= "const int " ~ safeName(getNName(curNode)) ~ " = " ~ 1621 1636 toStringFree(xmlGetProp(curNode, "init")) ~ ";\n"; 1622 1637 } else { 1623 writefln("I don't know how to parse %s!", nname);1638 Stdout.formatln("I don't know how to parse %s!", nname); 1624 1639 } 1625 1640 } 1626 1641 } … … 1674 1689 ParsedType t = parseType(type); 1675 1690 if (t.isStaticArray) { 1676 1691 // can't return a static array, convert it into a pointer 1677 int bloc = rfind(t.DType, '[');1678 if (bloc != -1) {1692 int bloc = locatePrior(t.DType, '['); 1693 if (bloc != t.DType.length) { 1679 1694 // cut off the [...] 1680 1695 t.DType = t.DType[0..bloc] ~ "*"; 1681 1696 t.isStaticArray = false; … … 1708 1723 1709 1724 for (curNode = gccxml.children; curNode; curNode = curNode.next) { 1710 1725 if (curNode.type == xmlElementType.XML_ELEMENT_NODE) { 1711 char[] nname = toString(curNode.name);1726 char[] nname = fromStringz(curNode.name); 1712 1727 1713 1728 char[] id = toStringFree(xmlGetProp(curNode, "id")); 1714 1729 if (id != type) continue; … … 1794 1809 1795 1810 default: 1796 1811 parsedCache[type] = new ParsedType("void", "void"); 1797 writefln("I don't know how translate %s to D.", ctype);1812 Stdout.formatln("I don't know how translate %s to D.", ctype); 1798 1813 } 1799 1814 1800 1815 } else if (nname == "PointerType") { … … 1827 1842 } else if (nname == "ArrayType") { 1828 1843 ParsedType baseType = 1829 1844 parseType(toStringFree(xmlGetProp(curNode, "type"))); 1830 int size = atoi(toStringFree(xmlGetProp(curNode, "max"))) + 1;1845 int size = Integer.parse(toStringFree(xmlGetProp(curNode, "max"))) + 1; 1831 1846 1832 1847 // make a typedef and an alias 1833 1848 static bool[char[]] handledArrays; … … 1836 1851 handledArrays[type] = true; 1837 1852 1838 1853 cout ~= "typedef " ~ baseType.CType ~ " _BCD_array_" ~ type ~ 1839 "[" ~ toString(size) ~ "];\n";1854 "[" ~ Integer.toString(size) ~ "];\n"; 1840 1855 } 1841 1856 1842 1857 baseType.CType = "_BCD_array_" ~ type; 1843 baseType.DType ~= " [" ~ toString(size) ~ "]";1858 baseType.DType ~= " [" ~ Integer.toString(size) ~ "]"; 1844 1859 1845 1860 ParsedType pt = new ParsedType(baseType); 1846 1861 pt.isStaticArray = true; … … 1863 1878 // we need to treat this as a pointer in D, but a reference in C 1864 1879 1865 1880 // 1) cut off the * 1866 int l = rfind(baseType.CType, '*');1867 if (l != -1) baseType.CType[l] = ' ';1881 int l = locatePrior(baseType.CType, '*'); 1882 if (l != baseType.CType.length) baseType.CType[l] = ' '; 1868 1883 1869 1884 // 2) add the & 1870 1885 if (outputC) { … … 1995 2010 xmlNode *curArg; 1996 2011 for (curArg = curNode.children; curArg; curArg = curArg.next) { 1997 2012 if (curArg.type == xmlElementType.XML_ELEMENT_NODE) { 1998 char[] aname = toString(curArg.name);2013 char[] aname = fromStringz(curArg.name); 1999 2014 2000 2015 if (aname == "Argument") { 2001 2016 ParsedType argType = … … 2033 2048 pt = new ParsedType("_BCD_func_" ~ type, "_BCD_func_" ~ type); 2034 2049 pt.isFunction = true; 2035 2050 } else { 2036 writefln("WARNING: method types/delegates are not yet supported");2051 Stdout.formatln("WARNING: method types/delegates are not yet supported"); 2037 2052 pt = new ParsedType("_BCD_func_" ~ type, "bcd.bind.CXXDelegate"); 2038 2053 pt.isFunction = true; 2039 2054 } … … 2058 2073 if (context != "") { 2059 2074 ParsedType pt = parseType(context); 2060 2075 2061 pt.CType = replace(pt.CType, " *", "");2076 pt.CType = substitute(pt.CType, " *", ""); 2062 2077 2063 2078 if (pt.CType == "") { 2064 2079 pt.CType = "enum " ~ aname; … … 2081 2096 2082 2097 } else { 2083 2098 parsedCache[type] = new ParsedType("void", "void"); 2084 writefln("I don't know how to parse the type %s.", nname);2099 Stdout.formatln("I don't know how to parse the type %s.", nname); 2085 2100 } 2086 2101 2087 2102 break; … … 2090 2105 2091 2106 if (!(type in parsedCache)) { 2092 2107 parsedCache[type] = new ParsedType("void", "void"); 2093 writefln("Type %s not found!", type);2108 Stdout.formatln("Type %s not found!", type); 2094 2109 } 2095 2110 } 2096 2111 … … 2102 2117 */ 2103 2118 void parse_Defines() 2104 2119 { 2105 File f = new File("out.i", FileMode.In); 2120 LineInput ls = new LineInput(new FileInput("out.i")); 2121 2106 2122 bool inOurFile = false; 2107 2123 2108 2124 bool[char[]] curDefines; 2109 2125 2110 while (!f.eof()) { 2111 char[] ln = f.readLine(); 2112 char[][] lns = split(ln); 2126 foreach(ln; ls) { 2127 char[][] lns = delimit(ln, " "); 2113 2128 2114 2129 if (lns.length >= 1 && 2115 2130 lns[0].length >= 1 && 2116 2131 lns[0][0] == '#') { 2117 2132 if (lns[0] == "#") { 2118 2133 // this is a file specification 2119 2134 if (lns.length >= 3 && … … 2124 2139 inOurFile = true; 2125 2140 if (outputAll) { 2126 2141 if (fname.length <= baseDir.length || 2127 ! fnmatch(fname[0..baseDir.length], baseDir)) inOurFile = false;2142 !patternMatch(fname[0..baseDir.length], baseDir)) inOurFile = false; 2128 2143 } else { 2129 2144 if (fname != curFile) inOurFile = false; 2130 2145 } 2131 2146 } 2132 2147 2133 2148 } else if (lns[0] == "#define" && inOurFile) { 2149 foreach(line; lns) Stdout.formatln("line [{}]", line); 2134 2150 // turn the #define into a const int or const double 2135 2151 if (lns.length >= 3) { 2152 if(lns[2].length >= 1) { 2136 2153 if (isNumeric(lns[2])) { 2137 2154 curDefines[lns[1]] = true; 2138 2155 … … 2141 2158 if (lns[2][$-1] == 'L') lns[2] = lns[2][0..$-1]; 2142 2159 2143 2160 // int or double? 2144 if ( find(lns[2], '.') != -1||2145 find(lns[2], 'e') != -1||2146 find(lns[2], 'E') != -1) {2161 if (locate(lns[2], '.') != lns[2].length || 2162 locate(lns[2], 'e') != lns[2].length || 2163 locate(lns[2], 'E') != lns[2].length) { 2147 2164 dhead ~= "const double " ~ safeName(lns[1]) ~ 2148 2165 " = " ~ lns[2] ~ ";\n"; 2149 2166 } else { … … 2165 2182 // could be #define'ing to something already #defined 2166 2183 dhead ~= "alias " ~ safeName(lns[2]) ~ " " ~ safeName(lns[1]) ~ ";\n"; 2167 2184 } 2185 } 2168 2186 } 2169 2187 } 2170 2188 } 2171 2189 } 2172 2190 2173 f.close();2191 ls.close(); 2174 2192 }