Skip to content

Commit 3dfc697

Browse files
authored
Merge pull request github#1642 from xiemaisi/json_locations
Approved by asger-semmle
2 parents 904c94e + fcf35dc commit 3dfc697

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+7386
-136
lines changed

javascript/extractor/src/com/semmle/js/extractor/JSONExtractor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public LoCInfo extract(final TextualExtractor textualExtractor) {
4343
throw recoverableErrors.get(0).asUserError();
4444

4545
Label fileLabel = locationManager.getFileLabel();
46+
locationManager.setHasLocationTable("json_locations");
4647
v.accept(
4748
new Visitor<Context, Label>() {
4849
private Label emit(JSONValue nd, int kind, Context c) {

javascript/extractor/src/com/semmle/js/extractor/LocationManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class LocationManager {
2020
private int startColumn;
2121
private int startLine;
2222
private final Set<String> locationDefaultEmitted = new LinkedHashSet<String>();
23+
private String hasLocation = "hasLocation";
2324

2425
public LocationManager(File sourceFile, TrapWriter trapWriter, Label fileLabel) {
2526
this.sourceFile = sourceFile;
@@ -58,6 +59,10 @@ public void setStart(int line, int column) {
5859
startColumn = column;
5960
}
6061

62+
public void setHasLocationTable(String hasLocation) {
63+
this.hasLocation = hasLocation;
64+
}
65+
6166
/**
6267
* Emit ___location information for an AST node. The node's ___location is translated from the parser's
6368
* 0-based column numbering scheme into our 1-based scheme and then emitted as a snippet ___location.
@@ -91,7 +96,7 @@ public void emitSnippetLocation(Label lbl, int sl, int sc, int el, int ec) {
9196
/** Emit an absolute ___location in the current file. No line or column adjustment is performed. */
9297
public void emitFileLocation(Label lbl, int sl, int sc, int el, int ec) {
9398
Label locLabel = emitLocationsDefault(sl, sc, el, ec);
94-
trapWriter.addTuple("hasLocation", lbl, locLabel);
99+
trapWriter.addTuple(hasLocation, lbl, locLabel);
95100
}
96101

97102
/**

javascript/extractor/src/com/semmle/js/extractor/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class Main {
3737
* A version identifier that should be updated every time the extractor changes in such a way that
3838
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
3939
*/
40-
public static final String EXTRACTOR_VERSION = "2019-04-17";
40+
public static final String EXTRACTOR_VERSION = "2019-07-25";
4141

4242
public static final Pattern NEWLINE = Pattern.compile("\n");
4343

javascript/extractor/src/com/semmle/js/extractor/YAMLExtractor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public LoCInfo extract(TextualExtractor textualExtractor) {
9999
trapWriter = textualExtractor.getTrapwriter();
100100

101101
Label fileLabel = locationManager.getFileLabel();
102+
locationManager.setHasLocationTable("yaml_locations");
102103
try {
103104
parser = new ParserImpl(new StreamReader(textualExtractor.getSource()));
104105
resolver = new Resolver();

javascript/extractor/tests/errors/output/trap/json.js.trap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ scopes(#20000,0)
1212
json(#20001,5,#10000,0,"{\n ""a"": 42\n}")
1313
#20002=@"loc,{#10000},1,1,3,1"
1414
locations_default(#20002,#10000,1,1,3,1)
15-
hasLocation(#20001,#20002)
15+
json_locations(#20001,#20002)
1616
#20003=*
1717
json(#20003,2,#20001,0,"42")
1818
#20004=@"loc,{#10000},2,8,2,9"
1919
locations_default(#20004,#10000,2,8,2,9)
20-
hasLocation(#20003,#20004)
20+
json_locations(#20003,#20004)
2121
json_literals("42","42",#20003)
2222
json_properties(#20001,"a",#20003)
2323
numlines(#10000,3,0,0)

javascript/extractor/tests/excludes/output/trap/empty.json.trap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ hasLocation(#10000,#10003)
1313
json(#20000,5,#10000,0,"{}")
1414
#20001=@"loc,{#10000},1,1,1,2"
1515
locations_default(#20001,#10000,1,1,1,2)
16-
hasLocation(#20000,#20001)
16+
json_locations(#20000,#20001)
1717
numlines(#10000,1,0,0)
1818
filetype(#10000,"json")

javascript/extractor/tests/json/output/trap/array.json.trap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ hasLocation(#10000,#10002)
1010
json(#20000,4,#10000,0,"[]")
1111
#20001=@"loc,{#10000},1,1,1,2"
1212
locations_default(#20001,#10000,1,1,1,2)
13-
hasLocation(#20000,#20001)
13+
json_locations(#20000,#20001)
1414
numlines(#10000,1,0,0)
1515
filetype(#10000,"json")

javascript/extractor/tests/json/output/trap/comments.json.trap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ hasLocation(#10000,#10002)
1010
json(#20000,5,#10000,0,"{\n // ... ts */\n}")
1111
#20001=@"loc,{#10000},1,1,5,1"
1212
locations_default(#20001,#10000,1,1,5,1)
13-
hasLocation(#20000,#20001)
13+
json_locations(#20000,#20001)
1414
#20002=*
1515
json(#20002,3,#20000,0,"""world""")
1616
#20003=@"loc,{#10000},3,12,3,18"
1717
locations_default(#20003,#10000,3,12,3,18)
18-
hasLocation(#20002,#20003)
18+
json_locations(#20002,#20003)
1919
json_literals("world","""world""",#20002)
2020
json_properties(#20000,"hello",#20002)
2121
#20004=*
2222
json_errors(#20004,"Error: Comments are not legal in JSON.")
2323
#20005=@"loc,{#10000},2,3,2,3"
2424
locations_default(#20005,#10000,2,3,2,3)
25-
hasLocation(#20004,#20005)
25+
json_locations(#20004,#20005)
2626
#20006=*
2727
json_errors(#20006,"Error: Comments are not legal in JSON.")
2828
#20007=@"loc,{#10000},4,3,4,3"
2929
locations_default(#20007,#10000,4,3,4,3)
30-
hasLocation(#20006,#20007)
30+
json_locations(#20006,#20007)
3131
numlines(#10000,5,0,0)
3232
filetype(#10000,"json")

javascript/extractor/tests/json/output/trap/duplicate-keys.json.trap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ hasLocation(#10000,#10002)
1010
json(#20000,5,#10000,0,"{\n "" ... "": 42\n}")
1111
#20001=@"loc,{#10000},1,1,4,1"
1212
locations_default(#20001,#10000,1,1,4,1)
13-
hasLocation(#20000,#20001)
13+
json_locations(#20000,#20001)
1414
#20002=*
1515
json(#20002,2,#20000,0,"23")
1616
#20003=@"loc,{#10000},2,10,2,11"
1717
locations_default(#20003,#10000,2,10,2,11)
18-
hasLocation(#20002,#20003)
18+
json_locations(#20002,#20003)
1919
json_literals("23","23",#20002)
2020
json_properties(#20000,"x",#20002)
2121
#20004=*
2222
json(#20004,2,#20000,1,"42")
2323
#20005=@"loc,{#10000},3,10,3,11"
2424
locations_default(#20005,#10000,3,10,3,11)
25-
hasLocation(#20004,#20005)
25+
json_locations(#20004,#20005)
2626
json_literals("42","42",#20004)
2727
json_properties(#20000,"x",#20004)
2828
numlines(#10000,4,0,0)

javascript/extractor/tests/json/output/trap/neg.json.trap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ hasLocation(#10000,#10002)
1010
json(#20000,2,#10000,0,"-1")
1111
#20001=@"loc,{#10000},1,1,1,2"
1212
locations_default(#20001,#10000,1,1,1,2)
13-
hasLocation(#20000,#20001)
13+
json_locations(#20000,#20001)
1414
json_literals("-1","-1",#20000)
1515
numlines(#10000,1,0,0)
1616
filetype(#10000,"json")

0 commit comments

Comments
 (0)