[ctypes-commit] ctypes/sandbox/tools/codegen _makexml.py,1.5,1.6
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-01-17 14:08:19
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26076 Modified Files: _makexml.py Log Message: Final version, but obsolete anyway. Will be replaced asap. Index: _makexml.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/_makexml.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** _makexml.py 14 Jan 2005 14:44:36 -0000 1.5 --- _makexml.py 17 Jan 2005 14:08:07 -0000 1.6 *************** *** 1,4 **** import os, re ! from gccxmlparser import parse import typedesc --- 1,4 ---- import os, re ! import gccxmlparser import typedesc *************** *** 113,119 **** name, value = items ! reason = is_excluded(name, value) ! if reason: ! log.write("%s: #define %s %s\n" % (reason, name, value)) continue --- 113,119 ---- name, value = items ! why = is_excluded(name, value) ! if why: ! log.write("%s: #define %s %s\n" % (why, name, value)) continue *************** *** 154,160 **** raise TypeError, type(tp).__name__ ! ################################################################ def create_file(): ! ofi = open("glut.cpp", "w") ## ofi.write('#include <gl/glut.h>\n') # ofi.write("#define WIN32_LEAN_AND_MEAN\n") --- 154,160 ---- raise TypeError, type(tp).__name__ ! ################################ def create_file(): ! ofi = open("xxx.cpp", "w") ## ofi.write('#include <gl/glut.h>\n') # ofi.write("#define WIN32_LEAN_AND_MEAN\n") *************** *** 175,187 **** ################################################################ ! # parse a C header file, and dump the preprocessor symbols log = open("skipped.txt", "w") ! create_file() # find the preprocessor defined symbols print "... finding preprocessor symbol names" ! defs = gccxml_get_defines("glut.cpp") print "%d '#define' symbols found" % len(defs) --- 175,192 ---- ################################################################ ! # ! # script section ! # ! ################################################################ ! # find the preprocessor symbols from a C header file log = open("skipped.txt", "w") ! ofi = create_file() ! ofi.close() # find the preprocessor defined symbols print "... finding preprocessor symbol names" ! defs = gccxml_get_defines(ofi.name) print "%d '#define' symbols found" % len(defs) *************** *** 193,217 **** # The function name can later be used to retrieve the symbol name again, # and the function's return type is the symbols's type. ! ofi = create_file() ! MAGIC = """ #define DECLARE(sym) template <typename T> T symbol_##sym(T) {} #define DEFINE(sym) symbol_##sym(sym) """ ! ofi.write(MAGIC) ! for name in defs: ! ofi.write("// #define %s %s\n" % (name, defs[name])) ! ofi.write("DECLARE(%s)\n" % name); ! ofi.write("int main() {\n") ! for name in defs: ! ofi.write(" DEFINE(%s);\n" % name); ! ofi.write("}\n") ! ofi.close() print "... finding preprocessor symbol types" # compile the file ! os.system("gccxml glut.cpp -fxml=glut.xml") ! # parse the result ! items = parse("glut.xml") # create a new C++ file which will later allow to retrieve the name, --- 198,227 ---- # The function name can later be used to retrieve the symbol name again, # and the function's return type is the symbols's type. ! ! CPPMAGIC = """ #define DECLARE(sym) template <typename T> T symbol_##sym(T) {} #define DEFINE(sym) symbol_##sym(sym) """ ! ! def invoke_templates(ofi, defs): ! ofi.write(CPPMAGIC) ! for name in defs: ! ofi.write("// #define %s %s\n" % (name, defs[name])) ! ofi.write("DECLARE(%s)\n" % name); ! ofi.write("int main() {\n") ! for name in defs: ! ofi.write(" DEFINE(%s);\n" % name); ! ofi.write("}\n") ! ofi.close() ! os.system("gccxml %s -fxml=glut.xml" % ofi.name) ! # parse the result ! items = gccxmlparser.parse("glut.xml") ! return items print "... finding preprocessor symbol types" # compile the file ! ofi = create_file() ! items = invoke_templates(ofi, defs) # create a new C++ file which will later allow to retrieve the name, *************** *** 228,238 **** # HWNDNOTOPMOST: ((HWND) -2), HWND is a structure continue ! codelines.append("const %s cpp_sym_%s = %s;" % (symtype, symname, symname)) print "created %d definitions" % len(codelines) ofi = create_file() for c in codelines: ! ofi.write("%s\n" % c) ofi.close() --- 238,250 ---- # HWNDNOTOPMOST: ((HWND) -2), HWND is a structure continue ! codelines.append("const %s cpp_sym_%s = %s;\n" % (symtype, symname, symname)) print "created %d definitions" % len(codelines) ofi = create_file() + ofi.write("namespace cpp_symbols {\n") for c in codelines: ! ofi.write(c) ! ofi.write("}\n") ofi.close() *************** *** 241,246 **** # will be used to generate Python code print "... finding preprocessor symbol values" ! os.system("gccxml glut.cpp -fxml=glut.xml") ! # now we should reinsert the aliases list again --- 253,258 ---- # will be used to generate Python code print "... finding preprocessor symbol values" ! os.system("gccxml %s -fxml=glut.xml" % ofi.name) ! os.remove(ofi.name) # now we should reinsert the aliases list again |