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 cppflags
"--std=c++11 --bind"
34 intrude import core
::stream
40 using namespace emscripten;
42 EMSCRIPTEN_BINDINGS(my_module) {
43 function("run_analysis", &CString_run_analysis, allow_raw_pointers());
47 redef class AnalysisManager
49 fun run_web
(src
: String)
51 sys
.suggest_garbage_collection
53 var stream
= new StringReader(src
)
54 var ast
= build_ast
("web", stream
)
55 if ast
== null then return
57 sys
.suggest_garbage_collection
62 var model
= build_model
(ast
)
65 if model
.lines
.is_empty
then
66 fatal_error
( ast
, "This programs appears empty" )
70 sys
.suggest_garbage_collection
73 var cfg
= build_cfg
(model
)
78 sys
.suggest_garbage_collection
81 do_reaching_defs_analysis
(cfg
)
83 sys
.suggest_garbage_collection
86 do_range_analysis
(ast
, cfg
)
88 sys
.suggest_garbage_collection
91 do_types_analysis
(ast
, cfg
)
93 sys
.suggest_garbage_collection
96 if notes
.is_empty
then print
"Success: Nothing wrong detected"
98 var of
= new StringWriter
99 cfg
.print_dot
(of
, false)
108 fun show_graph
(content
: String) do "show_graph('{content.escape_to_c}');".run_js
112 fun run_analysis
do manager
.run_web to_s
115 fun dummy_set_callbacks
import CString.run_analysis
in "C++" `{