cython
changeset 1149:7b8970eb4837
Option to emit #line directives, ticket #53
| author | Robert Bradshaw <robertwb@math.washington.edu> |
|---|---|
| date | Sat Sep 13 12:48:45 2008 -0700 (22 months ago) |
| parents | f4b39b81687b |
| children | 0877af7865fc |
| files | Cython/Compiler/CmdLine.py Cython/Compiler/Code.py Cython/Compiler/Main.py Cython/Compiler/ModuleNode.py |
line diff
1.1 --- a/Cython/Compiler/CmdLine.py Wed Sep 03 18:24:45 2008 +0200
1.2 +++ b/Cython/Compiler/CmdLine.py Sat Sep 13 12:48:45 2008 -0700
1.3 @@ -36,7 +36,7 @@
1.4
1.5 -D, --no-docstrings Remove docstrings.
1.6 -a, --annotate Produce a colorized HTML version of the source.
1.7 - --convert-range Convert for loops using range() function to for...from loops.
1.8 + --line-directives Produce #line directives pointing to the .pyx source
1.9 --cplus Output a c++ rather than c file.
1.10 -X, --directive <name>=<value>[,<name=value,...] Overrides a compiler directive
1.11 """
1.12 @@ -114,6 +114,8 @@
1.13 Options.annotate = True
1.14 elif option == "--convert-range":
1.15 Options.convert_range = True
1.16 + elif option == "--line-directives":
1.17 + options.emit_linenums = True
1.18 elif option in ("-X", "--directive"):
1.19 try:
1.20 options.pragma_overrides = Options.parse_option_list(pop_arg())
2.1 --- a/Cython/Compiler/Code.py Wed Sep 03 18:24:45 2008 +0200
2.2 +++ b/Cython/Compiler/Code.py Sat Sep 13 12:48:45 2008 -0700
2.3 @@ -161,13 +161,14 @@
2.4 # interned_nums
2.5 # cached_builtins
2.6
2.7 - def __init__(self, rootwriter):
2.8 + def __init__(self, rootwriter, emit_linenums=False):
2.9 self.filename_table = {}
2.10 self.filename_list = []
2.11 self.input_file_contents = {}
2.12 self.used_utility_code = set()
2.13 self.declared_cnames = {}
2.14 self.pystring_table_needed = False
2.15 + self.emit_linenums = emit_linenums
2.16
2.17 def initwriters(self, rootwriter):
2.18 self.utilprotowriter = rootwriter.new_writer()
2.19 @@ -378,6 +379,8 @@
2.20 writer.insert(self.utilprotowriter)
2.21
2.22 def put_utility_code_defs(self, writer):
2.23 + if self.emit_linenums:
2.24 + writer.write('\n#line 1 "cython_utility"\n')
2.25 writer.insert(self.utildefwriter)
2.26
2.27
2.28 @@ -403,7 +406,7 @@
2.29 - marker: Not copied to insertion point
2.30 - filename_table, filename_list, input_file_contents: All codewriters
2.31 coming from the same root share the same instances simultaneously.
2.32 - """
2.33 + """
2.34
2.35 # f file output file
2.36 # buffer StringIOTree
2.37 @@ -415,19 +418,21 @@
2.38 # generation (labels and temps state etc.)
2.39 # globalstate GlobalState contains state global for a C file (input file info,
2.40 # utility code, declared constants etc.)
2.41 + # emit_linenums boolean whether or not to write #line pragmas
2.42
2.43 - def __init__(self, create_from=None, buffer=None, copy_formatting=False):
2.44 + def __init__(self, create_from=None, buffer=None, copy_formatting=False, emit_linenums=None):
2.45 if buffer is None: buffer = StringIOTree()
2.46 self.buffer = buffer
2.47 self.marker = None
2.48 self.last_marker_line = 0
2.49 + self.source_desc = ""
2.50
2.51 self.funcstate = None
2.52 self.level = 0
2.53 self.bol = 1
2.54 if create_from is None:
2.55 # Root CCodeWriter
2.56 - self.globalstate = GlobalState(self)
2.57 + self.globalstate = GlobalState(self, emit_linenums=emit_linenums)
2.58 self.globalstate.initwriters(self)
2.59 # ^^^ need seperate step because this will reference self.globalstate
2.60 else:
2.61 @@ -437,6 +442,10 @@
2.62 if copy_formatting:
2.63 self.level = create_from.level
2.64 self.bol = create_from.bol
2.65 + if emit_linenums is None:
2.66 + self.emit_linenums = self.globalstate.emit_linenums
2.67 + else:
2.68 + self.emit_linenums = emit_linenums
2.69
2.70 def create_new(self, create_from, buffer, copy_formatting):
2.71 # polymorphic constructor -- very slightly more versatile
2.72 @@ -504,6 +513,8 @@
2.73 def putln(self, code = ""):
2.74 if self.marker and self.bol:
2.75 self.emit_marker()
2.76 + if self.emit_linenums and self.last_marker_line != 0:
2.77 + self.write('\n#line %s "%s"\n' % (self.last_marker_line, self.source_desc))
2.78 if code:
2.79 self.put(code)
2.80 self.write("\n");
2.81 @@ -580,7 +591,8 @@
2.82 marker = u'"%s":%d\n%s\n' % (
2.83 source_desc.get_escaped_description(), line, u'\n'.join(lines))
2.84 self.marker = (line, marker)
2.85 -
2.86 + if self.emit_linenums:
2.87 + self.source_desc = source_desc.get_escaped_description()
2.88
2.89 def put_label(self, lbl):
2.90 if lbl in self.funcstate.labels_used:
3.1 --- a/Cython/Compiler/Main.py Wed Sep 03 18:24:45 2008 +0200
3.2 +++ b/Cython/Compiler/Main.py Sat Sep 13 12:48:45 2008 -0700
3.3 @@ -727,7 +727,8 @@
3.4 timestamps = None,
3.5 verbose = 0,
3.6 quiet = 0,
3.7 - pragma_overrides = {}
3.8 + pragma_overrides = {},
3.9 + emit_linenums = False,
3.10 )
3.11 if sys.platform == "mac":
3.12 from Cython.Mac.MacSystem import c_compile, c_link, CCompilerError
4.1 --- a/Cython/Compiler/ModuleNode.py Wed Sep 03 18:24:45 2008 +0200
4.2 +++ b/Cython/Compiler/ModuleNode.py Sat Sep 13 12:48:45 2008 -0700
4.3 @@ -3,7 +3,6 @@
4.4 #
4.5
4.6 import os, time
4.7 -from cStringIO import StringIO
4.8 from PyrexTypes import CPtrType
4.9 import Future
4.10
4.11 @@ -240,7 +239,7 @@
4.12 if Options.annotate or options.annotate:
4.13 code = Annotate.AnnotationCCodeWriter()
4.14 else:
4.15 - code = Code.CCodeWriter()
4.16 + code = Code.CCodeWriter(emit_linenums=options.emit_linenums)
4.17 h_code = code.insertion_point()
4.18 self.generate_module_preamble(env, modules, h_code)
4.19
