Skip to content

Commit

Permalink
Merge pull request #2220 from lf-lang/windows-c11
Browse files Browse the repository at this point in the history
Fixed `#line` directives on Windows
  • Loading branch information
petervdonovan authored Feb 24, 2024
2 parents 00aa195 + 7441330 commit e2d06f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions core/src/main/java/org/lflang/generator/CodeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public void prSourceLineNumber(EObject eObject, boolean suppress) {
}
}
// Extract the filename from eResource, an astonishingly difficult thing to do.
String filePath = CommonPlugin.resolve(eObject.eResource().getURI()).path();
String filePath =
CommonPlugin.resolve(eObject.eResource().getURI()).path().replace("\\", "\\\\");
pr("#line " + (node.getStartLine() + offset) + " \"" + filePath + "\"");
}
}
Expand Down Expand Up @@ -558,7 +559,11 @@ public CodeMap writeToFile(String path) throws IOException {
for (var line : (Iterable<String>) () -> s.lines().iterator()) {
lineNumber++;
if (line.contains(END_SOURCE_LINE_NUMBER_TAG) && !path.endsWith(".ino")) {
out.append("#line ").append(lineNumber).append(" \"").append(path).append("\"");
out.append("#line ")
.append(lineNumber)
.append(" \"")
.append(path.replace("\\", "\\\\"))
.append("\"");
} else {
out.append(line);
}
Expand Down

0 comments on commit e2d06f3

Please sign in to comment.