Skip to content

Commit 147b210

Browse files
authored
Merge pull request #73 from goblint/input_filelist
Maintain a list of all input files that CIL encountered during lexing
2 parents d8f77a6 + 908790c commit 147b210

File tree

15 files changed

+85
-67
lines changed

15 files changed

+85
-67
lines changed

.merlin

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ B _build/src/ext/
99
B _build/src/ext/pta/
1010
B _build/src/frontc/
1111
B _build/src/ocamlutil/
12-
PKG findlib, zarith
12+
PKG findlib
13+
PKG zarith

src/cil.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ type file =
156156
should always be false if there is no global initializer. When
157157
you create a global initialization CIL will try to insert code in
158158
main to call it. *)
159+
files: (string * bool) list;
160+
(** A list of those files that were encountered during parsing of this CIL file,
161+
and whether they are system header files *)
159162
}
160163

161164
and comment = location * string
@@ -5001,7 +5004,8 @@ let dummyFile =
50015004
{ globals = [];
50025005
fileName = "<dummy>";
50035006
globinit = None;
5004-
globinitcalled = false;}
5007+
globinitcalled = false;
5008+
files = []; }
50055009

50065010
(***** Load and store files as unmarshalled Ocaml binary data. ****)
50075011
type savedFile =

src/cil.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ type file =
9393
* create a global initialization CIL will try to insert code in main
9494
* to call it. This will not happen if your file does not contain a
9595
* function called "main" *)
96+
files: (string * bool) list;
97+
(** A list of those files that were encountered during parsing of this CIL file,
98+
* and whether they are system header files *)
9699
}
97100
(** Top-level representation of a C source file *)
98101

src/formatcil.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ let doParse (prog: string)
8080
Formatparse.initialize Formatlex.initial lexbuf;
8181
let res = theParser Formatlex.initial lexbuf in
8282
H.add memoTable prog res;
83-
Formatlex.finish ();
83+
ignore @@ Formatlex.finish ();
8484
res
8585
with Parsing.Parse_error -> begin
86-
Formatlex.finish ();
86+
ignore @@ Formatlex.finish ();
8787
E.s (E.error "Parsing error: %s" prog)
8888
end
8989
| e -> begin
9090
ignore (E.log "Caught %s while parsing\n" (Printexc.to_string e));
91-
Formatlex.finish ();
91+
ignore @@ Formatlex.finish ();
9292
raise e
9393
end
9494
end

src/frontc/cabs.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ and definition =
189189
| STATIC_ASSERT of expression * string * cabsloc
190190

191191

192-
(* the string is a file name, and then the list of toplevel forms *)
193-
and file = string * definition list
192+
(* the string is a file name, then the list of toplevel forms, and finally a list of filenames
193+
encountered during parsing and whether they are system headers *)
194+
and file = string * definition list * (string * bool) list
194195

195196

196197
(*

src/frontc/cabs2cil.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5996,7 +5996,7 @@ and doDecl (isglobal: bool) : A.definition -> chunk = function
59965996
sformals = []; (* Not final yet *)
59975997
smaxid = 0;
59985998
sbody = dummyFunDec.sbody; (* Not final yet *)
5999-
smaxstmtid = None;
5999+
smaxstmtid = None;
60006000
sallstmts = [];
60016001
};
60026002
!currentFunctionFDEC.svar.vdecl <- funloc;
@@ -6899,7 +6899,7 @@ let convFile (f : A.file) : Cil.file =
68996899
Cil.initCIL (); (* make sure we have initialized CIL *)
69006900

69016901
(* remove parentheses from the Cabs *)
6902-
let fname,dl = stripParenFile f in
6902+
let fname,dl,files = stripParenFile f in
69036903

69046904
(* Clean up the global types *)
69056905
initGlobals();
@@ -6988,4 +6988,5 @@ let convFile (f : A.file) : Cil.file =
69886988
globals = !globals;
69896989
globinit = None;
69906990
globinitcalled = false;
6991+
files = files;
69916992
}

src/frontc/cabsvisit.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ and childrenAttribute vis ((n, el) as input) =
582582
and visitCabsAttributes vis (al: attribute list) : attribute list =
583583
mapNoCopyList (visitCabsAttribute vis) al
584584

585-
let visitCabsFile (vis: cabsVisitor) ((fname, f): file) : file =
586-
(fname, mapNoCopyList (visitCabsDefinition vis) f)
585+
let visitCabsFile (vis: cabsVisitor) ((fname, f, files): file) : file =
586+
(fname, mapNoCopyList (visitCabsDefinition vis) f, files)
587587

588588
(* end of file *)

src/frontc/clexer.mli

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
(*
22
*
3-
* Copyright (c) 2001-2002,
3+
* Copyright (c) 2001-2002,
44
* George C. Necula <necula@cs.berkeley.edu>
55
* Scott McPeak <smcpeak@cs.berkeley.edu>
66
* Wes Weimer <weimer@cs.berkeley.edu>
77
* All rights reserved.
8-
*
8+
*
99
* Redistribution and use in source and binary forms, with or without
1010
* modification, are permitted provided that the following conditions are
1111
* met:
@@ -36,14 +36,15 @@
3636
*)
3737

3838

39-
(* This interface is generated manually. The corresponding .ml file is
40-
* generated automatically and is placed in ../obj/clexer.ml. The reason we
41-
* want this interface is to avoid confusing make with freshly generated
39+
(* This interface is generated manually. The corresponding .ml file is
40+
* generated automatically and is placed in ../obj/clexer.ml. The reason we
41+
* want this interface is to avoid confusing make with freshly generated
4242
* interface files *)
4343

4444

4545
val init: filename:string -> Lexing.lexbuf
46-
val finish: unit -> unit
46+
val finish: unit -> (string * bool) list (* Return the list of filenames encountered during lexing
47+
and whether they are system headers *)
4748

4849
(* This is the main parser function *)
4950
val initial: Lexing.lexbuf -> Cparser.token
@@ -59,4 +60,3 @@ val get_extra_lexeme: unit -> string
5960
val clear_white: unit -> unit
6061
val clear_lexeme: unit -> unit
6162
val currentLoc : unit -> Cabs.cabsloc
62-

src/frontc/clexer.mll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,9 @@ and hash = parse
634634
and file = parse
635635
'\n' {addWhite lexbuf; E.newline (); initial lexbuf}
636636
| blank {addWhite lexbuf; file lexbuf}
637-
| '"' [^ '\012' '\t' '"']* '"' { addWhite lexbuf; (* '"' *)
638-
let n = Lexing.lexeme lexbuf in
639-
let n1 = String.sub n 1
640-
((String.length n) - 2) in
641-
E.setCurrentFile n1;
637+
| '"' ([^ '\012' '\t' '"']* as filename) '"' ((' ' ['1' -'4'])* as flags)
638+
{ addWhite lexbuf; (* '"' *)
639+
E.setCurrentFile filename (String.contains flags '3');
642640
endline lexbuf}
643641

644642
| _ {addWhite lexbuf; endline lexbuf}

src/frontc/cprint.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ end
933933
(* print abstrac_syntax -> ()
934934
** Pretty printing the given abstract syntax program.
935935
*)
936-
let printFile (result : out_channel) ((fname, defs) : file) =
936+
let printFile (result : out_channel) ((fname, defs, _) : file) =
937937
Whitetrack.setOutput result;
938938
print_defs defs;
939939
Whitetrack.printEOF ();

0 commit comments

Comments
 (0)