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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
1ccf0b8e
Commit
1ccf0b8e
authored
Jun 19, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More Main refactoring cleanup
parent
e6429bcd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
43 deletions
+30
-43
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+30
-43
No files found.
Cython/Compiler/Main.py
View file @
1ccf0b8e
...
@@ -25,22 +25,6 @@ from Cython import Utils
...
@@ -25,22 +25,6 @@ from Cython import Utils
module_name_pattern
=
re
.
compile
(
r"[A-Za-z_][A-Za-z0-9_]*(\
.[A-Z
a-z_][A-Za-z0-9_]*)*$"
)
module_name_pattern
=
re
.
compile
(
r"[A-Za-z_][A-Za-z0-9_]*(\
.[A-Z
a-z_][A-Za-z0-9_]*)*$"
)
# Note: PHASES and TransformSet should be removed soon; but that's for
# another day and another commit.
PHASES
=
[
'before_analyse_function'
,
# run in FuncDefNode.generate_function_definitions
'after_analyse_function'
# run in FuncDefNode.generate_function_definitions
]
class
TransformSet
(
dict
):
def
__init__
(
self
):
for
name
in
PHASES
:
self
[
name
]
=
[]
def
run
(
self
,
name
,
node
,
**
options
):
assert
name
in
self
,
"Transform phase %s not defined"
%
name
for
transform
in
self
[
name
]:
transform
(
node
,
phase
=
name
,
**
options
)
verbose
=
0
verbose
=
0
class
Context
:
class
Context
:
...
@@ -295,7 +279,10 @@ class Context:
...
@@ -295,7 +279,10 @@ class Context:
else
:
else
:
Errors
.
open_listing_file
(
None
)
Errors
.
open_listing_file
(
None
)
def
teardown_errors
(
self
,
errors_occurred
,
options
,
result
,
source_desc
):
def
teardown_errors
(
self
,
errors_occurred
,
options
,
result
):
source_desc
=
result
.
compilation_source
.
source_desc
if
not
isinstance
(
source_desc
,
FileSourceDescriptor
):
raise
RuntimeError
(
"Only file sources for code supported"
)
Errors
.
close_listing_file
()
Errors
.
close_listing_file
()
result
.
num_errors
=
Errors
.
num_errors
result
.
num_errors
=
Errors
.
num_errors
if
result
.
num_errors
>
0
:
if
result
.
num_errors
>
0
:
...
@@ -315,17 +302,16 @@ class Context:
...
@@ -315,17 +302,16 @@ class Context:
extra_objects
=
options
.
objects
,
extra_objects
=
options
.
objects
,
verbose_flag
=
options
.
show_version
,
verbose_flag
=
options
.
show_version
,
cplus
=
options
.
cplus
)
cplus
=
options
.
cplus
)
class
CompilationSource
(
object
):
def
run_pipeline
(
self
,
pipeline
,
source
):
"""
errors_occurred
=
False
Contains the data necesarry to start up a compilation pipeline for
data
=
source
a single compilation source (= file, usually).
try
:
"""
for
phase
in
pipeline
:
def
__init__
(
self
,
source_desc
,
full_module_name
,
cwd
):
data
=
phase
(
data
)
self
.
source_desc
=
source_desc
except
CompileError
:
self
.
full_module_name
=
full_module_nam
e
errors_occurred
=
Tru
e
self
.
cwd
=
cwd
return
(
errors_occurred
,
data
)
def
create_parse
(
context
):
def
create_parse
(
context
):
def
parse
(
compsrc
):
def
parse
(
compsrc
):
...
@@ -365,6 +351,7 @@ def create_default_pipeline(context, options):
...
@@ -365,6 +351,7 @@ def create_default_pipeline(context, options):
def
create_default_resultobj
(
compilation_source
,
options
):
def
create_default_resultobj
(
compilation_source
,
options
):
result
=
CompilationResult
()
result
=
CompilationResult
()
result
.
main_source_file
=
compilation_source
.
source_desc
.
filename
result
.
main_source_file
=
compilation_source
.
source_desc
.
filename
result
.
compilation_source
=
compilation_source
source_desc
=
compilation_source
.
source_desc
source_desc
=
compilation_source
.
source_desc
if
options
.
output_file
:
if
options
.
output_file
:
result
.
c_file
=
os
.
path
.
join
(
compilation_source
.
cwd
,
options
.
output_file
)
result
.
c_file
=
os
.
path
.
join
(
compilation_source
.
cwd
,
options
.
output_file
)
...
@@ -383,13 +370,9 @@ def create_default_resultobj(compilation_source, options):
...
@@ -383,13 +370,9 @@ def create_default_resultobj(compilation_source, options):
pass
pass
return
result
return
result
def
run_pipeline
(
source
,
options
=
None
,
full_module_name
=
None
):
def
run_pipeline
(
source
,
options
,
full_module_name
=
None
):
if
not
options
:
options
=
default_options
# Set up context
# Set up context
context
=
Context
(
options
.
include_path
)
context
=
Context
(
options
.
include_path
)
context
.
setup_errors
(
options
)
# Set up source object
# Set up source object
cwd
=
os
.
getcwd
()
cwd
=
os
.
getcwd
()
...
@@ -400,15 +383,9 @@ def run_pipeline(source, options = None, full_module_name = None):
...
@@ -400,15 +383,9 @@ def run_pipeline(source, options = None, full_module_name = None):
# Get pipeline
# Get pipeline
pipeline
=
create_default_pipeline
(
context
,
options
)
pipeline
=
create_default_pipeline
(
context
,
options
)
data
=
source
context
.
setup_errors
(
options
)
errors_occurred
=
False
errors_occurred
,
result
=
context
.
run_pipeline
(
pipeline
,
source
)
try
:
context
.
teardown_errors
(
errors_occurred
,
options
,
result
)
for
phase
in
pipeline
:
data
=
phase
(
data
)
except
CompileError
:
errors_occurred
=
True
result
=
data
context
.
teardown_errors
(
errors_occurred
,
options
,
result
,
source_desc
)
return
result
return
result
#------------------------------------------------------------------------
#------------------------------------------------------------------------
...
@@ -417,6 +394,16 @@ def run_pipeline(source, options = None, full_module_name = None):
...
@@ -417,6 +394,16 @@ def run_pipeline(source, options = None, full_module_name = None):
#
#
#------------------------------------------------------------------------
#------------------------------------------------------------------------
class
CompilationSource
(
object
):
"""
Contains the data necesarry to start up a compilation pipeline for
a single compilation unit.
"""
def
__init__
(
self
,
source_desc
,
full_module_name
,
cwd
):
self
.
source_desc
=
source_desc
self
.
full_module_name
=
full_module_name
self
.
cwd
=
cwd
class
CompilationOptions
:
class
CompilationOptions
:
"""
"""
Options to the Cython compiler:
Options to the Cython compiler:
...
@@ -432,7 +419,6 @@ class CompilationOptions:
...
@@ -432,7 +419,6 @@ class CompilationOptions:
defaults to true when recursive is true.
defaults to true when recursive is true.
verbose boolean Always print source names being compiled
verbose boolean Always print source names being compiled
quiet boolean Don't print source names in recursive mode
quiet boolean Don't print source names in recursive mode
transforms Transform.TransformSet Transforms to use on the parse tree
Following options are experimental and only used on MacOSX:
Following options are experimental and only used on MacOSX:
...
@@ -470,6 +456,7 @@ class CompilationResult:
...
@@ -470,6 +456,7 @@ class CompilationResult:
object_file string or None Result of compiling the C file
object_file string or None Result of compiling the C file
extension_file string or None Result of linking the object file
extension_file string or None Result of linking the object file
num_errors integer Number of compilation errors
num_errors integer Number of compilation errors
compilation_source CompilationSource
"""
"""
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -619,9 +606,9 @@ default_options = dict(
...
@@ -619,9 +606,9 @@ default_options = dict(
output_file
=
None
,
output_file
=
None
,
annotate
=
False
,
annotate
=
False
,
generate_pxi
=
0
,
generate_pxi
=
0
,
transforms
=
TransformSet
(),
working_path
=
""
,
working_path
=
""
,
recursive
=
0
,
recursive
=
0
,
transforms
=
None
,
# deprecated
timestamps
=
None
,
timestamps
=
None
,
verbose
=
0
,
verbose
=
0
,
quiet
=
0
)
quiet
=
0
)
...
...
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