9 redef class AnalysisManager
10 var opt_help
= new OptionBool("Display this help message", "--help","-h")
11 var opt_quiet
= new OptionBool("Do not show notes", "--quiet","-q")
12 fun quiet
: Bool do return opt_quiet
.value
13 fun verbose
: Bool do return not opt_quiet
.value
15 var opt_output
= new OptionString("Output directory", "--output", "-o")
21 opts
.add_option
(opt_help
)
22 opts
.add_option
(opt_quiet
)
23 opts
.add_option
(opt_output
)
31 if files
.is_empty
or opt_help
.value
then
32 print
"Usage: pep8analysis [options] file.pep [other_file.pep [...]]"
38 var dir
= opt_output
.value
39 if dir
== null then dir
= "out"
40 if not dir
.file_exists
then dir
.mkdir
43 for filename
in files
do
46 if verbose
then print
"Analyzing {filename}"
47 if not filename
.file_exists
then
48 print
"Target file \"{filename}\
" does not exist."
51 var ast
= build_ast_from_file
( filename
)
54 if failed
then continue
56 var mangled_filename
= filename
.replace
("/","-").replace
("..","up")
58 var printer
= new ASTPrinter
59 printer
.enter_visit
(ast
)
60 var of
= new OFStream.open
("{dir}/{mangled_filename.replace(".pep", ".ast.dot")}")
66 var model
= build_model
(ast
)
68 if failed
then continue
70 if model
.lines
.is_empty
then
71 fatal_error
( ast
, "This programs appears empty" )
76 var cfg
= build_cfg
(model
)
78 if opt_cfg
.value
or opt_cfg_long
.value
then
79 var of
= new OFStream.open
("{dir}/{mangled_filename.replace(".pep", ".cfg.dot")}")
80 cfg
.print_dot
(of
, opt_cfg_long
.value
)
84 if failed
then continue
89 do_reaching_defs_analysis
(cfg
)
92 do_range_analysis
(ast
, cfg
)
95 do_types_analysis
(ast
, cfg
)
98 var of
= new OFStream.open
("{dir}/{mangled_filename.replace(".pep",".analysis.dot")}")
99 cfg
.print_dot
(of
, true)
102 if not opt_quiet
.value
then
109 redef fun manager
do return once
new AnalysisManager