Skip to content

Commit 208d2a2

Browse files
Merge pull request cil-project#42 from goblint/line-offset
Add column to location
2 parents 305aa3b + 48b3b19 commit 208d2a2

File tree

13 files changed

+38
-22
lines changed

13 files changed

+38
-22
lines changed

src/cil.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ and location = {
878878
line: int; (** The line number. -1 means "do not know" *)
879879
file: string; (** The name of the source file*)
880880
byte: int; (** The byte position in the source file *)
881+
column: int; (** The column number *)
881882
}
882883

883884
(* Type signatures. Two types are identical iff they have identical
@@ -892,7 +893,8 @@ and typsig =
892893

893894
let locUnknown = { line = -1;
894895
file = "";
895-
byte = -1;}
896+
byte = -1;
897+
column = -1}
896898

897899
(* A reference to the current location *)
898900
let currentLoc : location ref = ref locUnknown
@@ -909,7 +911,11 @@ let compareLoc (a: location) (b: location) : int =
909911
let linecmp = a.line - b.line in
910912
if linecmp != 0
911913
then linecmp
912-
else a.byte - b.byte
914+
else
915+
let columncmp = a.column - b.column in
916+
if columncmp != 0
917+
then columncmp
918+
else a.byte - b.byte
913919

914920
let argsToList : (string * typ * attributes) list option
915921
-> (string * typ * attributes) list
@@ -3289,7 +3295,8 @@ let initMsvcBuiltins () : unit =
32893295
(** This is used as the location of the prototypes of builtin functions. *)
32903296
let builtinLoc: location = { line = 1;
32913297
file = "<compiler builtins>";
3292-
byte = 0;}
3298+
byte = 0;
3299+
column = 0}
32933300

32943301

32953302

src/cil.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ and location = {
11121112
line: int; (** The line number. -1 means "do not know" *)
11131113
file: string; (** The name of the source file*)
11141114
byte: int; (** The byte position in the source file *)
1115+
column: int; (** The column number *)
11151116
}
11161117

11171118

src/ext/syntacticsearch/funcFunction.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ let find_uses_in_fun_all funstrucname file =
215215
Some (find_uses_in_fun "" fundec.svar.vid funstrucname file)))
216216
file.globals
217217

218-
let loc_default = { line = -1; file = ""; byte = -1 }
218+
let loc_default = { line = -1; file = ""; byte = -1; column = -1 }
219219

220220
class fun_find_usesvar_in_fun fundec funstrucname varname varid file result :
221221
nopCilVisitor =

src/ext/syntacticsearch/queryMapping.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ open Cil
22
open CodeQuery
33

44
(* Default output if the input-query is not supported *)
5-
let loc_default = { line = -1; file = ""; byte = -1 }
5+
let loc_default = { line = -1; file = ""; byte = -1; column = -1 }
66

77
let rec delete_elem (name1, loc1, typ1, id1) list =
88
match list with
99
| (name2, loc2, typ2, id2) :: xs ->
1010
if
1111
String.compare name1 name2 = 0
12-
&& loc1.line = loc2.line && loc1.byte = loc2.byte
12+
&& loc1.line = loc2.line && loc1.byte = loc2.byte && loc1.column = loc2.column
1313
&& String.compare loc1.file loc2.file = 0
1414
&& String.compare typ1 typ2 = 0
1515
&& id1 = id2

src/ext/zrapp/zrapp.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ let loc_comp l1 l2 =
5757
then Some(1)
5858
else if l2.A.byteno > l1.A.byteno
5959
then Some(-1)
60+
else if l1.A.columnno > l2.A.columnno
61+
then Some(1)
62+
else if l2.A.columnno > l1.A.columnno
63+
then Some(-1)
6064
else Some(0)
6165

6266
let simpleGaSearch l =
@@ -78,6 +82,7 @@ let get_comments l =
7882
let cabsl = {A.lineno = l.line;
7983
A.filename = l.file;
8084
A.byteno = l.byte;
85+
A.columnno = l.column;
8186
A.ident = 0;} in
8287
let s = simpleGaSearch cabsl in
8388

src/frontc/cabs.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type cabsloc = {
5050
lineno : int;
5151
filename: string;
5252
byteno: int;
53+
columnno: int;
5354
ident : int;
5455
}
5556

src/frontc/cabs2cil.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ let attrsForCombinedArg: ((string, string) H.t ->
124124
let lu = locUnknown
125125
let cabslu = {lineno = -10;
126126
filename = "cabs lu";
127-
byteno = -10;
127+
byteno = -10; columnno = -10;
128128
ident = 0;}
129129

130130

@@ -194,8 +194,8 @@ let transparentUnionArgs : (int * typ) list ref = ref []
194194
let debugLoc = false
195195
let convLoc (l : cabsloc) =
196196
if debugLoc then
197-
ignore (E.log "convLoc at %s: line %d, byte %d\n" l.filename l.lineno l.byteno);
198-
{line = l.lineno; file = l.filename; byte = l.byteno;}
197+
ignore (E.log "convLoc at %s: line %d, byte %d, column %d\n" l.filename l.lineno l.byteno l.columnno);
198+
{line = l.lineno; file = l.filename; byte = l.byteno; column = l.columnno}
199199

200200

201201
let isOldStyleVarArgName n =

src/frontc/cabshelper.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ let getident () =
77
!nextident
88

99
let currentLoc () =
10-
let l, f, c = Errormsg.getPosition () in
11-
{ lineno = l;
12-
filename = f;
10+
let l, f, c, lc = Errormsg.getPosition () in
11+
{ lineno = l;
12+
filename = f;
1313
byteno = c;
14+
columnno = c - lc;
1415
ident = getident ();}
1516

1617
let cabslu = {lineno = -10;
1718
filename = "cabs loc unknown";
18-
byteno = -10;
19+
byteno = -10; columnno = -10;
1920
ident = 0}
2021

2122
(* clexer puts comments here *)

src/frontc/cabsvisit.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ end
9393

9494
let visitorLocation = ref { filename = "";
9595
lineno = -1;
96-
byteno = -1;
96+
byteno = -1; columnno = -1;
9797
ident = 0}
9898

9999
(* a default visitor which does nothing to the tree *)

src/frontc/cparser.mly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ let getComments () =
6363

6464
let cabslu = {lineno = -10;
6565
filename = "cabs loc unknown";
66-
byteno = -10;
66+
byteno = -10; columnno = -10;
6767
ident = 0;}
6868

6969
(* cabsloc -> cabsloc *)

0 commit comments

Comments
 (0)