Skip to content

Commit eb16383

Browse files
authored
Merge pull request #14 from goblint/location-ranges
Gobpie uses location ranges provided by Goblint #12
2 parents 104dccd + 8aebe3a commit eb16383

File tree

3 files changed

+21
-36
lines changed

3 files changed

+21
-36
lines changed

src/main/java/GoblintAnalysis.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public ProcessResult runCommand(File dirPath) throws IOException, InvalidExitVal
118118
* to let goblint generate the json file with analysis results.
119119
*
120120
* @param file the file on which to run the analysis.
121-
* @return returns true if goblint finished the analyse and json was generated sucessfully, false otherwise
121+
* @return returns true if goblint finished the analysis and json was generated sucessfully, false otherwise
122122
*/
123123
private boolean generateJson(Module file) {
124124
SourceFileModule sourcefile = (SourceFileModule) file;
@@ -175,14 +175,12 @@ private Collection<GoblintAnalysisResult> readResultsFromJson() {
175175
for (int i = 0; i < resultArray.size(); i++) {
176176
// Deserailize them into GoblintResult objects
177177
GoblintResult goblintResult = gson.fromJson(resultArray.get(i), GoblintResult.class);
178-
// Add sourcefileURL to object for generationg the position
179-
goblintResult.sourcefileURL = this.sourcefileURL;
180178
// Convert GoblintResult object to a list of GoblintAnalysisResults
181179
results.addAll(goblintResult.convert());
182180
}
183181
log.debug("Analysis results read from json");
184182

185-
} catch (JsonIOException | JsonSyntaxException | FileNotFoundException e) {
183+
} catch (JsonIOException | JsonSyntaxException | FileNotFoundException | MalformedURLException e) {
186184
throw new RuntimeException(e);
187185
}
188186

src/main/java/GoblintAnalysisResult.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import magpiebridge.core.AnalysisResult;
77
import magpiebridge.core.Kind;
8-
import magpiebridge.util.SourceCodeReader;
8+
// import magpiebridge.util.SourceCodeReader;
99

1010
import org.eclipse.lsp4j.DiagnosticSeverity;
1111

@@ -89,13 +89,14 @@ public Pair<Position, String> repair() {
8989

9090
@Override
9191
public String code() {
92-
String code;
93-
try {
94-
code = SourceCodeReader.getLinesInString(pos);
95-
} catch (Exception e) {
96-
throw new RuntimeException(e);
97-
}
98-
return code;
92+
// String code;
93+
// try {
94+
// code = SourceCodeReader.getLinesInString(pos);
95+
// } catch (Exception e) {
96+
// throw new RuntimeException(e);
97+
// }
98+
// return code;
99+
return null;
99100
}
100101

101102
}

src/main/java/GoblintResult.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
22
import com.ibm.wala.util.collections.Pair;
33

4-
import java.io.File;
4+
import java.net.MalformedURLException;
55
import java.net.URL;
66
import java.util.ArrayList;
77
import java.util.List;
88
import java.util.stream.Collectors;
99

10-
import magpiebridge.util.SourceCodeInfo;
11-
import magpiebridge.util.SourceCodePositionFinder;
12-
1310
public class GoblintResult {
1411

1512
private List<tag> tags = new ArrayList<>();
1613
private String severity;
1714
private multipiece multipiece;
18-
URL sourcefileURL;
1915

2016
public static interface tag {
2117

@@ -50,8 +46,11 @@ static class multipiece {
5046

5147
static class loc {
5248

49+
private String file;
5350
private int line;
5451
private int column;
52+
private int endLine;
53+
private int endColumn;
5554

5655
}
5756

@@ -62,27 +61,29 @@ static class pieces {
6261

6362
static class loc {
6463

64+
private String file;
6565
private int line;
6666
private int column;
67+
private int endLine;
68+
private int endColumn;
6769
}
6870
}
6971

7072
}
7173

72-
public List<GoblintAnalysisResult> convert() {
74+
public List<GoblintAnalysisResult> convert() throws MalformedURLException {
7375
List<GoblintAnalysisResult> results = new ArrayList<>();
7476

7577
if (multipiece.group_text == null) {
7678
String message = tags.stream().map(tag -> tag.toString()).collect(Collectors.joining("")) + " " + multipiece.text;
77-
GoblintPosition pos = new GoblintPosition(multipiece.loc.line, multipiece.loc.column - 1, findColumnEnd(multipiece.loc.line, multipiece.loc.column), sourcefileURL);
79+
GoblintPosition pos = new GoblintPosition(multipiece.loc.line, multipiece.loc.endLine, multipiece.loc.column - 1, multipiece.loc.endColumn - 1, new URL("file:" + multipiece.loc.file));
7880
GoblintAnalysisResult result = new GoblintAnalysisResult(pos, message, severity);
7981
results.add(result);
8082
} else {
8183
List<GoblintAnalysisResult> intermresults = new ArrayList<>();
8284
List<multipiece.pieces> pieces = multipiece.pieces;
8385
for (multipiece.pieces piece : pieces) {
84-
GoblintPosition pos = new GoblintPosition(piece.loc.line, piece.loc.column - 1,
85-
findColumnEnd(piece.loc.line, piece.loc.column), sourcefileURL);
86+
GoblintPosition pos = new GoblintPosition(piece.loc.line, piece.loc.endLine, piece.loc.column - 1, piece.loc.endColumn - 1, new URL("file:" + piece.loc.file));
8687
GoblintAnalysisResult result = new GoblintAnalysisResult(pos,
8788
tags.stream().map(tag -> tag.toString()).collect(Collectors.joining("")) + " Group: " + multipiece.group_text,
8889
piece.text, severity);
@@ -105,20 +106,5 @@ public List<GoblintAnalysisResult> convert() {
105106
return results;
106107
}
107108

108-
public int findColumnEnd(int lineStart, int columnStart) {
109-
110-
// get source code of the specified line
111-
SourceCodeInfo sourceCodeInfo = SourceCodePositionFinder.findCode(new File(sourcefileURL.getPath()), lineStart);
112-
// get the source code substring starting from the relevant assert statement.
113-
// as the source code is given without the leading whitespace, but the column
114-
// numbers take whitespace into account
115-
// the offset must be subtracted from the original starting column which does
116-
// include the leading whitespace
117-
String sourceCode = sourceCodeInfo.code.substring(columnStart - sourceCodeInfo.range.getStart().getCharacter());
118-
// find the index of the next semicolon
119-
int indexOfNextSemicolon = sourceCode.indexOf(";") + 1;
120-
121-
return columnStart + indexOfNextSemicolon;
122-
}
123109

124110
}

0 commit comments

Comments
 (0)