lib/standard/stream: Renamed streams for more explicit denomination
[nit.git] / contrib / pep8analysis / src / pep8analysis.nit
index 17e2232..abacc8b 100644 (file)
@@ -29,7 +29,7 @@ redef class AnalysisManager
                var files = opts.rest
 
                if files.is_empty or opt_help.value then
-                       print "Usage: {sys.program_name} [options] file.pep [other_file.pep [...]]"
+                       print "Usage: pep8analysis [options] file.pep [other_file.pep [...]]"
                        print "Options:"
                        opts.usage
                        return
@@ -48,11 +48,20 @@ redef class AnalysisManager
                                        print "Target file \"{filename}\" does not exist."
                                        exit 1
                        end
-                       var ast = build_ast( filename )
+                       var ast = build_ast_from_file( filename )
                        assert ast != null
 
                        if failed then continue
 
+                       var mangled_filename = filename.replace("/","-").replace("..","up")
+                       if opt_ast.value then
+                               var printer = new ASTPrinter
+                               printer.enter_visit(ast)
+                               var of = new FileWriter.open("{dir}/{mangled_filename.replace(".pep", ".ast.dot")}")
+                               of.write printer.str
+                               of.close
+                       end
+
                        # Build program model
                        var model = build_model(ast)
 
@@ -66,6 +75,12 @@ redef class AnalysisManager
                        # Create CFG
                        var cfg = build_cfg(model)
 
+                       if opt_cfg.value or opt_cfg_long.value then
+                               var of = new FileWriter.open("{dir}/{mangled_filename.replace(".pep", ".cfg.dot")}")
+                               cfg.print_dot(of, opt_cfg_long.value)
+                               of.close
+                       end
+
                        if failed then continue
 
                        # Run analyses
@@ -80,7 +95,7 @@ redef class AnalysisManager
                        do_types_analysis(ast, cfg)
 
                        # Print results
-                       var of = new OFStream.open("{dir}/{filename.replace("/","-").replace(".pep",".dot")}")
+                       var of = new FileWriter.open("{dir}/{mangled_filename.replace(".pep",".analysis.dot")}")
                        cfg.print_dot(of, true)
                        of.close
                end
@@ -90,8 +105,4 @@ redef class AnalysisManager
        end
 end
 
-redef class Object
-       redef fun manager do return once new AnalysisManager
-end
-
 manager.run