Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
2ce60b9a
Commit
2ce60b9a
authored
Mar 03, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coverage: cache parsed C files to avoid parsing them again
parent
7d0e4def
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
36 deletions
+45
-36
Cython/Coverage.py
Cython/Coverage.py
+45
-36
No files found.
Cython/Coverage.py
View file @
2ce60b9a
...
...
@@ -37,10 +37,12 @@ def _find_dep_file_path(main_file, file_path):
class
Plugin
(
CoveragePlugin
):
# map from traced file paths to corresponding C files
_c_files_map
=
None
# map from traced file paths to absolute file paths
_file_path_map
=
None
# map from traced file paths to corresponding C files
_c_files_map
=
None
# map from parsed C files to their content
_parsed_c_files
=
None
def
sys_info
(
self
):
return
[(
'Cython version'
,
__version__
)]
...
...
@@ -155,48 +157,55 @@ class Plugin(CoveragePlugin):
Each executable line starts with a comment header that states source file
and line number, as well as the surrounding range of source code lines.
"""
match_source_path_line
=
re
.
compile
(
r' */[*] +"(.*)":([0-9]+)$'
).
match
match_current_code_line
=
re
.
compile
(
r' *[*] (.*) # <<<<<<+$'
).
match
match_comment_end
=
re
.
compile
(
r' *[*]/$'
).
match
not_executable
=
re
.
compile
(
r'\
s*c(?:
type)?def\
s+
'
r'
(
?
:(
?
:
public
|
external
)
\
s
+
)
?
'
r'
(
?
:
struct
|
union
|
enum
|
class
)
'
r'
(
\
s
+
[
^
:]
+|
)
\
s
*
:
'
).match
code_lines = defaultdict(dict)
filenames = set()
with open(c_file) as lines:
lines = iter(lines)
for line in lines:
match = match_source_path_line(line)
if not match:
continue
filename, lineno = match.groups()
filenames.add(filename)
lineno = int(lineno)
for comment_line in lines:
match = match_current_code_line(comment_line)
if match:
code_line = match.group(1).rstrip()
if not_executable(code_line):
if
self
.
_parsed_c_files
is
None
:
self
.
_parsed_c_files
=
{}
if
c_file
in
self
.
_parsed_c_files
:
code_lines
=
self
.
_parsed_c_files
[
c_file
]
else
:
match_source_path_line
=
re
.
compile
(
r' */[*] +"(.*)":([0-9]+)$'
).
match
match_current_code_line
=
re
.
compile
(
r' *[*] (.*) # <<<<<<+$'
).
match
match_comment_end
=
re
.
compile
(
r' *[*]/$'
).
match
not_executable
=
re
.
compile
(
r'\
s*c(?:
type)?def\
s+
'
r'
(
?
:(
?
:
public
|
external
)
\
s
+
)
?
'
r'
(
?
:
struct
|
union
|
enum
|
class
)
'
r'
(
\
s
+
[
^
:]
+|
)
\
s
*
:
'
).match
code_lines = defaultdict(dict)
filenames = set()
with open(c_file) as lines:
lines = iter(lines)
for line in lines:
match = match_source_path_line(line)
if not match:
continue
filename, lineno = match.groups()
filenames.add(filename)
lineno = int(lineno)
for comment_line in lines:
match = match_current_code_line(comment_line)
if match:
code_line = match.group(1).rstrip()
if not_executable(code_line):
break
code_lines[filename][lineno] = code_line
break
elif match_comment_end(comment_line):
# unexpected comment format - false positive?
break
code_lines[filename][lineno] = code_line
break
elif match_comment_end(comment_line):
# unexpected comment format - false positive?
break
self._parsed_c_files[c_file] = code_lines
if self._c_files_map is None:
self._c_files_map = {}
for filename
in filenames
:
for filename
, code in code_lines.iteritems()
:
abs_path = _find_dep_file_path(c_file, filename)
self._c_files_map[abs_path] = (c_file, filename, code
_lines[filename]
)
self._c_files_map[abs_path] = (c_file, filename, code)
if sourcefile not in self._c_files_map:
return (None,) * 2 #
shouldn'
t
happen
...
return (None,) * 2 #
e.g. shared library file
return self._c_files_map[sourcefile][1:]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment