-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathwhitetrack.ml
54 lines (37 loc) · 1.47 KB
/
whitetrack.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
open Cabs
open Cabshelper
(* This isn't the most efficient way to do things.
* It would probably be better to not reparse rather
* than keep the tokens in memory *)
(* In particular, most of the tokens we hold will be
header files that we don't need *)
(* map cabslocs to token indexes *)
(* TODO: gather until end of line, then decide where to split *)
(* NOTE: If you find yourself getting lots of nomatch errors with
* parens in them, then that may mean you are printing
* a cabs file that has had it's parens removed *)
let tokenmap : ((string * int),int) Hashtbl.t = Hashtbl.create 1000
let nextidx = ref 0
let gonebad = ref false
(* array of tokens and whitespace *)
let tokens = GrowArray.make 0 (GrowArray.Elem ("",""))
let cabsloc_to_str cabsloc =
cabsloc.filename ^ ":" ^ string_of_int cabsloc.lineno ^ ":" ^
string_of_int cabsloc.byteno ^ ":" ^
string_of_int cabsloc.ident
let lastline = ref 0
let wraplexer_enabled lexer lexbuf =
let white,lexeme,token,cabsloc = lexer lexbuf in
GrowArray.setg tokens !nextidx (white,lexeme);
Hashtbl.add tokenmap (cabsloc.filename,cabsloc.byteno) !nextidx;
nextidx := !nextidx + 1;
token
let wraplexer_disabled lexer lexbuf =
let white,lexeme,token,cabsloc = lexer lexbuf in
token
let enabled = ref false
let wraplexer lexer =
if !enabled then wraplexer_enabled lexer
else wraplexer_disabled lexer
let finalwhite = ref "\n"
let setFinalWhite w = finalwhite := w