1 # This file is part of the pep8analysis project (http://xymus.net/pep8/)
3 # Copyright 2013-2014 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Web version of the pep8analysis tool
19 # Takes the entire Pep/8 source code as argument and prints out the
20 # analysis results. The result graph will be sent to the JavaScript function
21 # `show_graph` with the source of the graph in Graphviz's dot.
22 module pep8analysis_web
is
23 cpp_compiler_option
("--std=c++11 --bind")
24 c_linker_option
("--bind")
34 intrude import standard
::stream
39 using namespace emscripten;
41 EMSCRIPTEN_BINDINGS(my_module) {
42 function("run_analysis", &NativeString_run_analysis, allow_raw_pointers());
46 redef class AnalysisManager
50 sys
.suggest_garbage_collection
52 var stream
= new StringIStream(src
)
53 var ast
= build_ast
("web", stream
)
54 if ast
== null then return
56 sys
.suggest_garbage_collection
61 var model
= build_model
(ast
)
64 if model
.lines
.is_empty
then
65 fatal_error
( ast
, "This programs appears empty" )
69 sys
.suggest_garbage_collection
72 var cfg
= build_cfg
(model
)
77 sys
.suggest_garbage_collection
80 do_reaching_defs_analysis
(cfg
)
82 sys
.suggest_garbage_collection
85 do_range_analysis
(ast
, cfg
)
87 sys
.suggest_garbage_collection
90 do_types_analysis
(ast
, cfg
)
92 sys
.suggest_garbage_collection
95 if notes
.is_empty
then print
"Success: Nothing wrong detected"
97 var of
= new StringOStream
98 cfg
.print_dot
(of
, false)
107 fun show_graph
(content
: String) do "show_graph('{content.escape_to_c}');".run_js
111 super BufferedIStream
113 init(str
: String) do _buffer
= new FlatBuffer.from
(str
)
115 redef fun fill_buffer
do end_reached
= true
116 redef var end_reached
: Bool = false
119 redef class NativeString
120 fun run_analysis
do manager
.run to_s
123 fun dummy_set_callbacks
import NativeString.run_analysis
in "C++" `{