Permalink
Browse files

clean lang_js/ remove avik's code, remove NotParsedCorrectly, FinalDef

  • Loading branch information...
1 parent 0d95646 commit 0560f1f26afa9e13174fa029cc12b77bb6b00111 @aryx aryx committed Mar 8, 2014
View
@@ -157,13 +157,17 @@ type ('ast, 'token) for_helper = {
let tokens_with_categ_of_file_helper
{parse; highlight_visit; info_of_tok} file prefs hentities =
- let h = Hashtbl.create 101 in
if !Flag.verbose_visual then pr2 (spf "Parsing: %s" file);
let ast2 = parse file in
if !Flag.verbose_visual then pr2 (spf "Highlighting: %s" file);
+ (* todo: ast2 should not be a list, should just be (ast, toks)
+ * but right now only a few parsers will satisfy this interface
+ *)
ast2 +> List.map (fun (ast, toks) ->
+ let h = Hashtbl.create 101 in
+
(* computing the token attributes *)
highlight_visit ~tag_hook:(fun info categ -> Hashtbl.add h info categ)
prefs (ast, toks);
@@ -230,7 +234,7 @@ let tokens_with_categ_of_file file hentities =
)
(function
| ML (astopt, toks) ->
- let ast = match astopt with None -> [] | Some xs -> xs in
+ let ast = astopt ||| [] in
[ast, toks]
| _ -> raise Impossible));
highlight_visit = (fun ~tag_hook prefs (ast, toks) ->
@@ -350,7 +354,12 @@ let tokens_with_categ_of_file file hentities =
Common.save_excursion Flag_parsing_js.error_recovery true (fun () ->
Js (Parse_js.parse file +> fst))
)
- (function Js (ast, toks) -> [ast, toks] | _ -> raise Impossible));
+ (function
+ | Js (astopt, toks) ->
+ let ast = astopt ||| [] in
+ [ast, toks]
+ | _ -> raise Impossible
+ ));
highlight_visit = Highlight_js.visit_program;
(* TODO?
let s = Token_helpers_js.str_of_tok tok in
View
@@ -9,7 +9,7 @@ SRC= \
highlight_js.ml \
database_light_js.ml \
tags_js.ml \
- utils_js.ml module_js.ml toplevel_js.ml link_js.ml stats_js.ml \
+ utils_js.ml module_js.ml \
test_analyze_js.ml unit_analyze_js.ml
-include $(TOP)/Makefile.config
@@ -118,7 +118,8 @@ let compute_database ?(verbose=false) files_or_dirs =
files +> List.iter (fun file ->
if verbose then pr2 (spf "PHASE 1: %s" file);
- let ((ast, toks), _stat) = Parse_js.parse file in
+ let ((astopt, toks), _stat) = Parse_js.parse file in
+ let ast = astopt ||| [] in
let hcomplete_name_of_info =
Class_js.extract_complete_name_of_info ast
View
@@ -1,126 +0,0 @@
-
-open Common
-open Module_js
-
-(*******************)
-(* name resolution *)
-(*******************)
-
-let rec resolve_ stack modules shape =
- match shape with
-
- | FunctionShape (_,shape) -> resolve_ stack modules shape
-
- | ObjectShape {contents = (id,map,maps)} ->
- if (List.mem id stack) then () else
- map +> SMap.iter (fun _ -> resolve_ (id::stack) modules);
- maps +> List.iter (resolve_ (id::stack) modules)
-
- | ClassShape (instance, static) ->
- resolve_ stack modules instance; resolve_ stack modules static
-
- | RequireShape (m) ->
- if SMap.mem m modules
- then ()
- else failwith ("\n\nUNRESOLVED LINK " ^ m ^ "!")
-
- | PropertyShape (shape,_) -> resolve_ stack modules shape
-
- | NewShape _class -> resolve_ stack modules _class
-
- | MixinShape map -> resolve_ stack modules map
-
- | ClassWithMixinShape (_class, mixin) ->
- resolve_ stack modules _class; resolve_ stack modules mixin
-
- | ApplyShape _function -> resolve_ stack modules _function
-
- | LiteralShape
- | ArrayShape
- | UnknownShape _
- | ElementShape _ -> ()
-
-let resolve modules shape = resolve_ [] modules shape
-
-(*******************************************)
-(* topological sort of module dependencies *)
-(*******************************************)
-
-let missing_imports modules =
- prerr_newline();
- let unbound_modules = ref SMap.empty in
- modules +> SMap.iter
- (fun _ -> fun local -> local.local_requires +> List.iter
- (fun require ->
- if (SMap.mem require modules)
- then ()
- else unbound_modules := !unbound_modules +> SMap.add require ()
- )
- );
- !unbound_modules +> SMap.iter
- (fun m -> fun _ -> prerr_endline (spf "MISSING %s" m))
-
-type topsort_state = {
- mutable ordering: int smap;
- mutable visited: moduleinfo_map;
- mutable norder: int;
- mutable stack: string list;
-}
-
-let tsort = {
- ordering = SMap.empty;
- visited = SMap.empty;
- norder = 0;
- stack = [];
-}
-
-let rec topsort modules =
- tsort.visited <- modules;
- loop()
-
-and loop () =
- try
- let (m,_) = SMap.choose tsort.visited in
- visit m;
- loop()
- with _ -> ()
-
-and visit m =
- if (SMap.mem m tsort.visited) then (
- let local = SMap.find m tsort.visited in
- tsort.stack <- m :: tsort.stack;
- tsort.visited <- SMap.remove m tsort.visited;
- List.iter visit local.local_requires;
- tsort.ordering <- tsort.ordering +>
- SMap.add m (tsort.norder <- tsort.norder + 1; tsort.norder);
- tsort.stack <- List.tl tsort.stack
- )
- else if (List.mem m tsort.stack) then (
- prerr_endline (spf "CYCLE %s" m);
- List.iter (fun m -> prerr_endline (spf "\t%s" m)) tsort.stack
- )
- else ()
-
-let index m =
- try SMap.find m tsort.ordering
- with _ -> 0
-
-let validate_dependency m_from m_to =
- try
- assert ((index m_from) >= (index m_to))
- with _ ->
- prerr_endline (spf "Inconsistent index: %s[%d] -> %s[%d]"
- m_from
- (index m_from)
- m_to
- (index m_to)
- )
-
-
-let validate_topsort modules =
- modules +> SMap.iter (
- fun m -> fun local ->
- local.local_requires +> List.iter (validate_dependency m)
- )
-
-
@@ -1,12 +0,0 @@
-
-(** resolve references to extenal modules from a local shape **)
-val resolve : Module_js.moduleinfo_map -> Module_js.shape -> unit
-
-(** report missing dependencies **)
-val missing_imports : Module_js.moduleinfo_map -> unit
-
-(** topologically sort dependencies **)
-val topsort : Module_js.moduleinfo_map -> unit
-
-(** validate topological order **)
-val validate_topsort : Module_js.moduleinfo_map -> unit
@@ -1,17 +0,0 @@
-html/js/modules/Alice.js
-html/js/third_party/selection/DOMSelection.js
-html/js/third_party/tinymce/TinyMCE.js
-html/js/ufi/modules/OneClickSpamEducation.js
-html/js/desktop/client/socialfox/worker/mqttbridge/MqttWebsocketBridgeManager.js
-html/js/ads/lib/AdsClusterUploadHandler.js
-html/js/downstream/data/compat/bolt_compat_model.js
-html/js/mobile/downstream/data/compat/bolt_compat_model.js
-html/js/mobile/privacy/MComposerAudienceButton.js
-html/js/swfobject.js
-html/js/cavalry/logger-detailed.js
-html/js/giftcredits/giftcredits-dealspot.js
-html/js/mobile/platform/dialog/jsdialog/MPlatformJSDialogRuntime.js
-html/js/support/FusionCharts.js
-html/js/third_party/raphael/raphael.js
-html/js/third_party/wysihtml5/wysihtml5-0.3.0.min.js
-html/js/brands/components/BrandRoleSelector.brands.js
View
@@ -1,147 +0,0 @@
-
-open Common
-open Module_js
-
-(********)
-(* main *)
-(********)
-
-type special_paths = {
- modules_db: string;
- trees_db: string;
- ignore_list: string;
-}
-
-let paths = {
- modules_db = "/dev/shm/js_modules.db";
- trees_db = "/dev/shm/js_trees.db";
- ignore_list = "lang_js/analyze/stats_js.ignore";
-}
-
-let load_trees xs =
- Utils_js.load paths.trees_db (fun () ->
- let files = Lib_parsing_js.find_source_files_of_dir_or_files xs in
- let prefix = Sys.getenv "STATS_JS_PREFIX" in
- let ignore_files =
- cat paths.ignore_list +>
- List.map (fun s -> Filename.concat prefix s)
- in
- files
- +> exclude (fun file ->
- (List.mem file ignore_files) ||
- (file =~ ".*tests__.*") ||
- (file =~ ".*benchmarks__.*") ||
- (file =~ ".*mocks__.*")
- )
- +> List.fold_left (fun trees -> fun file ->
- try
- let (parseinfo,_) = Parse_js.parse file in
- print_endline file;
- trees +> SMap.add file parseinfo
- with exc ->
- prerr_endline (spf "\n###\n%s\n\n%s\n###\n"
- file
- (Printexc.to_string(exc))
- );
- trees
- ) SMap.empty
- )
-
-let load_modules xs =
- Utils_js.load paths.modules_db (fun () ->
- let trees = load_trees xs in
- SMap.fold (fun file -> fun parseinfo -> fun modules ->
- try
- let shape = Toplevel_js.analyze file parseinfo in
- modules +> Toplevel_js.export_module shape
- with exc ->
- prerr_endline (spf "\n###\n%s\n\n%s\n###\n"
- file
- (Printexc.to_string(exc))
- );
- Printexc.print_backtrace stderr;
- raise Exit
- ) trees SMap.empty
- )
-
-let print_info m modules =
- let local = SMap.find m modules in
- let shape = SMap.find "exports" local.local_bindings in
- print_endline (string_of_shape 1 shape);
- print_endline "REQUIRES";
- List.iter (fun s -> print_endline(spf "\t%s" s)) local.local_requires
-
-let main xs =
-
- let modules = load_modules xs in
-
- Link_js.missing_imports modules;
-
- let (nclasses,nfunctions,nobjects) = (ref 0, ref 0, ref 0) in
- modules +> SMap.iter
- (fun m -> function local -> match SMap.find "exports" local.local_bindings with
- | ClassShape _ ->
- nclasses := !nclasses + 1
-
- | FunctionShape _ ->
- nfunctions := !nfunctions + 1;
-
- | ObjectShape _ ->
- nobjects := !nobjects + 1;
- ()
-
- | UnknownShape s ->
- print_endline (spf "UNKNOWN %s: %s" m s);
- ()
-
- | LiteralShape
- | NewShape _
- | ApplyShape _
- | RequireShape _
- | PropertyShape _
- | ArrayShape -> ()
-
- | shape ->
- failwith (string_of_shape 0 shape)
- );
- print_newline();
- print_endline (spf "Classes: %d; Functions: %d; Objects: %d"
- !nclasses
- !nfunctions
- !nobjects
- );
-
- print_newline();
- Link_js.topsort modules;
- Link_js.validate_topsort modules;
-
- modules +> SMap.iter (fun m -> fun local ->
- let shape = SMap.find "exports" local.local_bindings in
- try
- Link_js.resolve modules shape
- with exc ->
- prerr_endline (spf "MODULE %s\n\t%s"
- m
- (Printexc.to_string exc)
- )
- );
-
-
- let rec loop () =
- print_endline "\nInspect module?";
- let m = read_line() in
- (try print_info m modules with _ -> ());
- loop ()
- in
- loop()
-
-(********)
-(* TODO *)
-(********)
-
-(* global *)
-
-
-
-
-
@@ -1,7 +0,0 @@
-
-val load_trees : Common.path list -> Module_js.parseinfo_map
-val load_modules : Common.path list -> Module_js.moduleinfo_map
-
-(** build a data structure describing module signatures for a set of JS files **)
-(** and run a sequence of analyses on that data structure **)
-val main : Common.path list -> unit
Oops, something went wrong.

0 comments on commit 0560f1f

Please sign in to comment.