[ctypes-commit] ctypes/ctypes/wrap h2xml.py,1.2,1.3 cparser.py,1.2,1.3
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-03-17 19:01:37
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28279 Modified Files: h2xml.py cparser.py Log Message: Implement adding excluded and excluded_re from the h2xml.cfg config file. Index: cparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/cparser.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cparser.py 17 Mar 2005 13:54:23 -0000 1.2 --- cparser.py 17 Mar 2005 19:01:26 -0000 1.3 *************** *** 6,9 **** --- 6,13 ---- except ImportError: subprocess = None + try: + set + except NameError: + from sets import Set as set if sys.platform == "win32": *************** *** 29,33 **** --- 33,57 ---- class IncludeParser(object): + def __init__(self, options): + """ + options must be an object having these attributes: + verbose - integer + flags - sequence of strings + keep_temporary_files - true if temporary files should not be deleted + cpp_symbols - whether to include preprocessor symbols in the XML file + excluded_symbols - collection of names for additional preprocessor symbols to exclude + excluded_symbols_re - collection of regular expressions for names to exclude + xml_file - pathname of output file (may be None) + """ + self.options = options + self.excluded = set() + self.excluded.update(EXCLUDED) + self.excluded.update(self.options.excluded_symbols) + self.excluded_re = set() + self.excluded_re.update(EXCLUDED_RE) + self.excluded_re.update(self.options.excluded_symbols_re) + + def create_source_file(self, lines, ext=".cpp"): "Create a temporary file, write lines to it, and return the filename" *************** *** 63,67 **** os.remove(fname) else: ! print >> sys.stderr, "file '%s' not removed" % fname return [line[len("#define "):] for line in data.splitlines() --- 87,91 ---- os.remove(fname) else: ! print >> sys.stderr, "Info: file '%s' not removed" % fname return [line[len("#define "):] for line in data.splitlines() *************** *** 87,91 **** if retcode: self.display_compiler_errors(err.splitlines()) - raise SystemExit(1) else: retcode = os.system(" ".join(args)) --- 111,114 ---- *************** *** 96,103 **** os.remove(fname) else: ! print >> sys.stderr, "file '%s' not removed" % fname def display_compiler_errors(self, lines): ! print "Compiler errors on these source lines:" import re, linecache pat = re.compile(r"(.*\.cpp):(\d+):(.*)") --- 119,126 ---- os.remove(fname) else: ! print >> sys.stderr, "Info: file '%s' not removed" % fname def display_compiler_errors(self, lines): ! print >> sys.stderr, "Compiler errors on these source lines:" import re, linecache pat = re.compile(r"(.*\.cpp):(\d+):(.*)") *************** *** 114,118 **** output[-1] = output[-1] + line.strip() for line in output: ! print line def get_defines(self, include_files): --- 137,141 ---- output[-1] = output[-1] + line.strip() for line in output: ! print >> sys.stderr, line def get_defines(self, include_files): *************** *** 143,149 **** if value in C_KEYWORDS: return "value is keyword" ! if name in EXCLUDED: return "excluded" ! for pat in EXCLUDED_RE: if pat.match(name): return "excluded (regex)" --- 166,172 ---- if value in C_KEYWORDS: return "value is keyword" ! if name in self.excluded: return "excluded" ! for pat in self.excluded_re: if pat.match(name): return "excluded (regex)" *************** *** 202,206 **** os.remove(fname) else: ! print >> sys.stderr, "file '%s' not removed" % fname types = {} --- 225,229 ---- os.remove(fname) else: ! print >> sys.stderr, "Info: file '%s' not removed" % fname types = {} *************** *** 253,265 **** ################################################################ ! def parse(self, include_files, options): ! """Main method. ! ! The options object must have these attribuites: ! verbose - integer ! flags - sequence of strings ! """ ! self.options = options ! if options.cpp_symbols: if options.verbose: --- 276,283 ---- ################################################################ ! def parse(self, include_files): ! """Parse include files.""" ! options = self.options ! if options.cpp_symbols: if options.verbose: Index: h2xml.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/h2xml.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** h2xml.py 17 Mar 2005 13:54:47 -0000 1.2 --- h2xml.py 17 Mar 2005 19:01:25 -0000 1.3 *************** *** 1,4 **** """h2xml - convert C include file(s) into an xml file by running gccxml.""" ! import sys, os, tempfile import cparser from optparse import OptionParser --- 1,4 ---- """h2xml - convert C include file(s) into an xml file by running gccxml.""" ! import sys, os, tempfile, re, ConfigParser import cparser from optparse import OptionParser *************** *** 29,32 **** --- 29,53 ---- parser.values.gccxml_options.extend((opt, value)) + # Hm, should there be a way to disable the config file? + # And then, this should be done AFTER the parameters are processed. + config = ConfigParser.ConfigParser() + try: + config.read("h2xml.cfg") + except ConfigParser.ParsingError, detail: + print >> sys.stderr, detail + return 1 + + def get_option(option, default_value): + # return an option from the platform specific section of the + # config file, or return the default_value if either the + # section or the option is not present. + try: + return config.get(sys.platform, option) + except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): + return default_value + + excluded = get_option("excluded", "").split() + excluded_re = get_option("excluded_re", "").split() + parser = OptionParser("usage: %prog includefile ... [options]") parser.add_option("-q", "--quiet", *************** *** 78,81 **** --- 99,114 ---- default=False) + parser.add_option("-s", + dest="excluded_symbols", + action="append", + help="specify preprocessor symbol name to exclude", + default=excluded) + + parser.add_option("-r", + dest="excluded_symbols_re", + action="append", + help="regular expression for preprocessor symbol names to exclude", + default=[]) + options, files = parser.parse_args() *************** *** 89,100 **** options.verbose = not options.quiet try: ! parser = cparser.IncludeParser() ! parser.parse(files, options) except cparser.CompilerError, detail: ! import traceback ! traceback.print_exc() ! ## print detail ! sys.exit(1) if __name__ == "__main__": --- 122,133 ---- options.verbose = not options.quiet + options.excluded_symbols_re = [re.compile(pat) for pat in options.excluded_symbols_re] + try: ! parser = cparser.IncludeParser(options) ! parser.parse(files) except cparser.CompilerError, detail: ! print >> sys.stderr, "CompilerError:", detail ! return 1 if __name__ == "__main__": |