Skip to content

Commit 628b718

Browse files
ExtractAPI: use zero-based indices for line/column in symbol graph
Other implementations of the symbol graph format use zero-based indices for source locations, which causes problems when combined with clang's current one-based indices. This commit sets ExtractAPI's symbol graph output to use zero-based indices to align with other implementations. Cherry-picked from llvm#71753. rdar://107639783
1 parent bc9289f commit 628b718

25 files changed

+298
-298
lines changed

clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ Object serializeSourcePosition(const PresumedLoc &Loc) {
101101
assert(Loc.isValid() && "invalid source position");
102102

103103
Object SourcePosition;
104-
SourcePosition["line"] = Loc.getLine();
105-
SourcePosition["character"] = Loc.getColumn();
104+
SourcePosition["line"] = Loc.getLine() - 1;
105+
SourcePosition["character"] = Loc.getColumn() - 1;
106106

107107
return SourcePosition;
108108
}

clang/test/ExtractAPI/anonymous_record_no_typedef.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ struct Vehicle {
105105
{
106106
"range": {
107107
"end": {
108-
"character": 29,
109-
"line": 3
108+
"character": 28,
109+
"line": 2
110110
},
111111
"start": {
112-
"character": 9,
113-
"line": 3
112+
"character": 8,
113+
"line": 2
114114
}
115115
},
116116
"text": "The type of vehicle."
@@ -127,8 +127,8 @@ struct Vehicle {
127127
},
128128
"location": {
129129
"position": {
130-
"character": 5,
131-
"line": 4
130+
"character": 4,
131+
"line": 3
132132
},
133133
"uri": "file://INPUT_DIR/input.h"
134134
},
@@ -163,8 +163,8 @@ struct Vehicle {
163163
},
164164
"location": {
165165
"position": {
166-
"character": 9,
167-
"line": 5
166+
"character": 8,
167+
"line": 4
168168
},
169169
"uri": "file://INPUT_DIR/input.h"
170170
},
@@ -206,8 +206,8 @@ struct Vehicle {
206206
},
207207
"location": {
208208
"position": {
209-
"character": 9,
210-
"line": 6
209+
"character": 8,
210+
"line": 5
211211
},
212212
"uri": "file://INPUT_DIR/input.h"
213213
},
@@ -256,12 +256,12 @@ struct Vehicle {
256256
{
257257
"range": {
258258
"end": {
259-
"character": 14,
260-
"line": 1
259+
"character": 13,
260+
"line": 0
261261
},
262262
"start": {
263-
"character": 5,
264-
"line": 1
263+
"character": 4,
264+
"line": 0
265265
}
266266
},
267267
"text": "A Vehicle"
@@ -278,8 +278,8 @@ struct Vehicle {
278278
},
279279
"location": {
280280
"position": {
281-
"character": 8,
282-
"line": 2
281+
"character": 7,
282+
"line": 1
283283
},
284284
"uri": "file://INPUT_DIR/input.h"
285285
},
@@ -328,8 +328,8 @@ struct Vehicle {
328328
},
329329
"location": {
330330
"position": {
331-
"character": 7,
332-
"line": 7
331+
"character": 6,
332+
"line": 6
333333
},
334334
"uri": "file://INPUT_DIR/input.h"
335335
},
@@ -379,8 +379,8 @@ struct Vehicle {
379379
},
380380
"location": {
381381
"position": {
382-
"character": 7,
383-
"line": 13
382+
"character": 6,
383+
"line": 12
384384
},
385385
"uri": "file://INPUT_DIR/input.h"
386386
},

clang/test/ExtractAPI/availability.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ void e(void) __attribute__((availability(tvos, unavailable)));
9898
},
9999
"location": {
100100
"position": {
101-
"character": 6,
102-
"line": 1
101+
"character": 5,
102+
"line": 0
103103
},
104104
"uri": "file://INPUT_DIR/input.h"
105105
},
@@ -172,8 +172,8 @@ void e(void) __attribute__((availability(tvos, unavailable)));
172172
},
173173
"location": {
174174
"position": {
175-
"character": 6,
176-
"line": 3
175+
"character": 5,
176+
"line": 2
177177
},
178178
"uri": "file://INPUT_DIR/input.h"
179179
},
@@ -256,8 +256,8 @@ void e(void) __attribute__((availability(tvos, unavailable)));
256256
},
257257
"location": {
258258
"position": {
259-
"character": 6,
260-
"line": 5
259+
"character": 5,
260+
"line": 4
261261
},
262262
"uri": "file://INPUT_DIR/input.h"
263263
},
@@ -356,8 +356,8 @@ void e(void) __attribute__((availability(tvos, unavailable)));
356356
},
357357
"location": {
358358
"position": {
359-
"character": 6,
360-
"line": 7
359+
"character": 5,
360+
"line": 6
361361
},
362362
"uri": "file://INPUT_DIR/input.h"
363363
},
@@ -438,8 +438,8 @@ void e(void) __attribute__((availability(tvos, unavailable)));
438438
},
439439
"location": {
440440
"position": {
441-
"character": 6,
442-
"line": 9
441+
"character": 5,
442+
"line": 8
443443
},
444444
"uri": "file://INPUT_DIR/input.h"
445445
},

clang/test/ExtractAPI/emit-symbol-graph/multi_file.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ int main ()
183183
},
184184
"location": {
185185
"position": {
186-
"character": 5,
187-
"line": 7
186+
"character": 4,
187+
"line": 6
188188
},
189189
"uri": "file://INPUT_DIR/test.h"
190190
},
@@ -247,8 +247,8 @@ int main ()
247247
},
248248
"location": {
249249
"position": {
250-
"character": 6,
251-
"line": 8
250+
"character": 5,
251+
"line": 7
252252
},
253253
"uri": "file://INPUT_DIR/test.h"
254254
},
@@ -311,8 +311,8 @@ int main ()
311311
},
312312
"location": {
313313
"position": {
314-
"character": 5,
315-
"line": 3
314+
"character": 4,
315+
"line": 2
316316
},
317317
"uri": "file://INPUT_DIR/main.c"
318318
},
@@ -361,8 +361,8 @@ int main ()
361361
},
362362
"location": {
363363
"position": {
364-
"character": 9,
365-
"line": 4
364+
"character": 8,
365+
"line": 3
366366
},
367367
"uri": "file://INPUT_DIR/test.h"
368368
},
@@ -411,8 +411,8 @@ int main ()
411411
},
412412
"location": {
413413
"position": {
414-
"character": 9,
415-
"line": 5
414+
"character": 8,
415+
"line": 4
416416
},
417417
"uri": "file://INPUT_DIR/test.h"
418418
},
@@ -571,8 +571,8 @@ int main ()
571571
},
572572
"location": {
573573
"position": {
574-
"character": 5,
575-
"line": 7
574+
"character": 4,
575+
"line": 6
576576
},
577577
"uri": "file://INPUT_DIR/test.h"
578578
},
@@ -635,8 +635,8 @@ int main ()
635635
},
636636
"location": {
637637
"position": {
638-
"character": 6,
639-
"line": 8
638+
"character": 5,
639+
"line": 7
640640
},
641641
"uri": "file://INPUT_DIR/test.h"
642642
},
@@ -685,8 +685,8 @@ int main ()
685685
},
686686
"location": {
687687
"position": {
688-
"character": 9,
689-
"line": 4
688+
"character": 8,
689+
"line": 3
690690
},
691691
"uri": "file://INPUT_DIR/test.h"
692692
},
@@ -735,8 +735,8 @@ int main ()
735735
},
736736
"location": {
737737
"position": {
738-
"character": 9,
739-
"line": 5
738+
"character": 8,
739+
"line": 4
740740
},
741741
"uri": "file://INPUT_DIR/test.h"
742742
},

clang/test/ExtractAPI/emit-symbol-graph/single_file.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ int main ()
8585
},
8686
"location": {
8787
"position": {
88-
"character": 5,
89-
"line": 4
88+
"character": 4,
89+
"line": 3
9090
},
9191
"uri": "file://INPUT_DIR/main.c"
9292
},
@@ -135,8 +135,8 @@ int main ()
135135
},
136136
"location": {
137137
"position": {
138-
"character": 9,
139-
"line": 1
138+
"character": 8,
139+
"line": 0
140140
},
141141
"uri": "file://INPUT_DIR/main.c"
142142
},
@@ -185,8 +185,8 @@ int main ()
185185
},
186186
"location": {
187187
"position": {
188-
"character": 9,
189-
"line": 2
188+
"character": 8,
189+
"line": 1
190190
},
191191
"uri": "file://INPUT_DIR/main.c"
192192
},

0 commit comments

Comments
 (0)