mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
Fixing placement of error messages. (Paul Stoffregen)
This patch places #line preprocessor directives into the generated code file so that the compiler reports the correct location for error messages. http://code.google.com/p/arduino/issues/detail?id=907
This commit is contained in:
@ -1373,6 +1373,9 @@ public class Sketch {
|
|||||||
for (SketchCode sc : code) {
|
for (SketchCode sc : code) {
|
||||||
if (sc.isExtension("ino") || sc.isExtension("pde")) {
|
if (sc.isExtension("ino") || sc.isExtension("pde")) {
|
||||||
sc.setPreprocOffset(bigCount);
|
sc.setPreprocOffset(bigCount);
|
||||||
|
// These #line directives help the compiler report errors with
|
||||||
|
// correct the filename and line number (issue 281 & 907)
|
||||||
|
bigCode.append("#line 1 \"" + sc.getFileName() + "\"\n");
|
||||||
bigCode.append(sc.getProgram());
|
bigCode.append(sc.getProgram());
|
||||||
bigCode.append('\n');
|
bigCode.append('\n');
|
||||||
bigCount += sc.getLineCount();
|
bigCount += sc.getLineCount();
|
||||||
@ -1542,54 +1545,16 @@ public class Sketch {
|
|||||||
public RunnerException placeException(String message,
|
public RunnerException placeException(String message,
|
||||||
String dotJavaFilename,
|
String dotJavaFilename,
|
||||||
int dotJavaLine) {
|
int dotJavaLine) {
|
||||||
int codeIndex = 0; //-1;
|
// Placing errors is simple, because we inserted #line directives
|
||||||
int codeLine = -1;
|
// into the preprocessed source. The compiler gives us correct
|
||||||
|
// the file name and line number. :-)
|
||||||
// System.out.println("placing " + dotJavaFilename + " " + dotJavaLine);
|
for (int codeIndex = 0; codeIndex < getCodeCount(); codeIndex++) {
|
||||||
// System.out.println("code count is " + getCodeCount());
|
SketchCode code = getCode(codeIndex);
|
||||||
|
if (dotJavaFilename.equals(code.getFileName())) {
|
||||||
// first check to see if it's a .java file
|
return new RunnerException(message, codeIndex, dotJavaLine);
|
||||||
for (int i = 0; i < getCodeCount(); i++) {
|
}
|
||||||
SketchCode code = getCode(i);
|
}
|
||||||
if (!code.isExtension(getDefaultExtension())) {
|
return null;
|
||||||
if (dotJavaFilename.equals(code.getFileName())) {
|
|
||||||
codeIndex = i;
|
|
||||||
codeLine = dotJavaLine;
|
|
||||||
return new RunnerException(message, codeIndex, codeLine);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If not the preprocessed file at this point, then need to get out
|
|
||||||
if (!dotJavaFilename.equals(name + ".cpp")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if it's not a .java file, codeIndex will still be 0
|
|
||||||
// this section searches through the list of .pde files
|
|
||||||
codeIndex = 0;
|
|
||||||
for (int i = 0; i < getCodeCount(); i++) {
|
|
||||||
SketchCode code = getCode(i);
|
|
||||||
|
|
||||||
if (code.isExtension(getDefaultExtension())) {
|
|
||||||
// System.out.println("preproc offset is " + code.getPreprocOffset());
|
|
||||||
// System.out.println("looking for line " + dotJavaLine);
|
|
||||||
if (code.getPreprocOffset() <= dotJavaLine) {
|
|
||||||
codeIndex = i;
|
|
||||||
// System.out.println("i'm thinkin file " + i);
|
|
||||||
codeLine = dotJavaLine - code.getPreprocOffset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// could not find a proper line number, so deal with this differently.
|
|
||||||
// but if it was in fact the .java file we're looking for, though,
|
|
||||||
// send the error message through.
|
|
||||||
// this is necessary because 'import' statements will be at a line
|
|
||||||
// that has a lower number than the preproc offset, for instance.
|
|
||||||
// if (codeLine == -1 && !dotJavaFilename.equals(name + ".java")) {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
return new RunnerException(message, codeIndex, codeLine);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
String buildPath;
|
String buildPath;
|
||||||
String primaryClassName;
|
String primaryClassName;
|
||||||
boolean verbose;
|
boolean verbose;
|
||||||
|
boolean sketchIsCompiled;
|
||||||
|
|
||||||
RunnerException exception;
|
RunnerException exception;
|
||||||
|
|
||||||
@ -68,6 +69,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
this.buildPath = buildPath;
|
this.buildPath = buildPath;
|
||||||
this.primaryClassName = primaryClassName;
|
this.primaryClassName = primaryClassName;
|
||||||
this.verbose = verbose;
|
this.verbose = verbose;
|
||||||
|
this.sketchIsCompiled = false;
|
||||||
|
|
||||||
// the pms object isn't used for anything but storage
|
// the pms object isn't used for anything but storage
|
||||||
MessageStream pms = new MessageStream(this);
|
MessageStream pms = new MessageStream(this);
|
||||||
@ -130,6 +132,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
findFilesInPath(buildPath, "c", false),
|
findFilesInPath(buildPath, "c", false),
|
||||||
findFilesInPath(buildPath, "cpp", false),
|
findFilesInPath(buildPath, "cpp", false),
|
||||||
boardPreferences));
|
boardPreferences));
|
||||||
|
sketchIsCompiled = true;
|
||||||
|
|
||||||
// 2. compile the libraries, outputting .o files to: <buildPath>/<library>/
|
// 2. compile the libraries, outputting .o files to: <buildPath>/<library>/
|
||||||
|
|
||||||
@ -513,14 +516,20 @@ public class Compiler implements MessageConsumer {
|
|||||||
//msg = _("\nThe 'Keyboard' class is only supported on the Arduino Leonardo.\n\n");
|
//msg = _("\nThe 'Keyboard' class is only supported on the Arduino Leonardo.\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
RunnerException e = sketch.placeException(error, pieces[1], PApplet.parseInt(pieces[2]) - 1);
|
RunnerException e = null;
|
||||||
|
if (!sketchIsCompiled) {
|
||||||
|
// Place errors when compiling the sketch, but never while compiling libraries
|
||||||
|
// or the core. The user's sketch might contain the same filename!
|
||||||
|
e = sketch.placeException(error, pieces[1], PApplet.parseInt(pieces[2]) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
// replace full file path with the name of the sketch tab (unless we're
|
// replace full file path with the name of the sketch tab (unless we're
|
||||||
// in verbose mode, in which case don't modify the compiler output)
|
// in verbose mode, in which case don't modify the compiler output)
|
||||||
if (e != null && !verbose) {
|
if (e != null && !verbose) {
|
||||||
SketchCode code = sketch.getCode(e.getCodeIndex());
|
SketchCode code = sketch.getCode(e.getCodeIndex());
|
||||||
String fileName = code.isExtension(sketch.getDefaultExtension()) ? code.getPrettyName() : code.getFileName();
|
String fileName = (code.isExtension("ino") || code.isExtension("pde")) ? code.getPrettyName() : code.getFileName();
|
||||||
s = fileName + ":" + e.getCodeLine() + ": error: " + pieces[3] + msg;
|
int lineNum = e.getCodeLine() + 1;
|
||||||
|
s = fileName + ":" + lineNum + ": error: " + pieces[3] + msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exception == null && e != null) {
|
if (exception == null && e != null) {
|
||||||
|
@ -205,7 +205,7 @@ public class PdePreprocessor {
|
|||||||
for (int i = 0; i < prototypes.size(); i++) {
|
for (int i = 0; i < prototypes.size(); i++) {
|
||||||
out.print(prototypes.get(i) + "\n");
|
out.print(prototypes.get(i) + "\n");
|
||||||
}
|
}
|
||||||
|
out.println("#line 1");
|
||||||
out.print(program.substring(prototypeInsertionPoint));
|
out.print(program.substring(prototypeInsertionPoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user