@@ -1373,6 +1373,9 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws
1373
1373
for (SketchCode sc : code ) {
1374
1374
if (sc .isExtension ("ino" ) || sc .isExtension ("pde" )) {
1375
1375
sc .setPreprocOffset (bigCount );
1376
+ // These #line directives help the compiler report errors with
1377
+ // correct the filename and line number (issue 281 & 907)
1378
+ bigCode .append ("#line 1 \" " + sc .getFileName () + "\" \n " );
1376
1379
bigCode .append (sc .getProgram ());
1377
1380
bigCode .append ('\n' );
1378
1381
bigCount += sc .getLineCount ();
@@ -1542,54 +1545,16 @@ public ArrayList<File> getImportedLibraries() {
1542
1545
public RunnerException placeException (String message ,
1543
1546
String dotJavaFilename ,
1544
1547
int dotJavaLine ) {
1545
- int codeIndex = 0 ; //-1;
1546
- int codeLine = -1 ;
1547
-
1548
- // System.out.println("placing " + dotJavaFilename + " " + dotJavaLine);
1549
- // System.out.println("code count is " + getCodeCount());
1550
-
1551
- // first check to see if it's a .java file
1552
- for (int i = 0 ; i < getCodeCount (); i ++) {
1553
- SketchCode code = getCode (i );
1554
- if (!code .isExtension (getDefaultExtension ())) {
1555
- if (dotJavaFilename .equals (code .getFileName ())) {
1556
- codeIndex = i ;
1557
- codeLine = dotJavaLine ;
1558
- return new RunnerException (message , codeIndex , codeLine );
1559
- }
1560
- }
1561
- }
1562
-
1563
- // If not the preprocessed file at this point, then need to get out
1564
- if (!dotJavaFilename .equals (name + ".cpp" )) {
1565
- return null ;
1566
- }
1567
-
1568
- // if it's not a .java file, codeIndex will still be 0
1569
- // this section searches through the list of .pde files
1570
- codeIndex = 0 ;
1571
- for (int i = 0 ; i < getCodeCount (); i ++) {
1572
- SketchCode code = getCode (i );
1573
-
1574
- if (code .isExtension (getDefaultExtension ())) {
1575
- // System.out.println("preproc offset is " + code.getPreprocOffset());
1576
- // System.out.println("looking for line " + dotJavaLine);
1577
- if (code .getPreprocOffset () <= dotJavaLine ) {
1578
- codeIndex = i ;
1579
- // System.out.println("i'm thinkin file " + i);
1580
- codeLine = dotJavaLine - code .getPreprocOffset ();
1581
- }
1582
- }
1583
- }
1584
- // could not find a proper line number, so deal with this differently.
1585
- // but if it was in fact the .java file we're looking for, though,
1586
- // send the error message through.
1587
- // this is necessary because 'import' statements will be at a line
1588
- // that has a lower number than the preproc offset, for instance.
1589
- // if (codeLine == -1 && !dotJavaFilename.equals(name + ".java")) {
1590
- // return null;
1591
- // }
1592
- return new RunnerException (message , codeIndex , codeLine );
1548
+ // Placing errors is simple, because we inserted #line directives
1549
+ // into the preprocessed source. The compiler gives us correct
1550
+ // the file name and line number. :-)
1551
+ for (int codeIndex = 0 ; codeIndex < getCodeCount (); codeIndex ++) {
1552
+ SketchCode code = getCode (codeIndex );
1553
+ if (dotJavaFilename .equals (code .getFileName ())) {
1554
+ return new RunnerException (message , codeIndex , dotJavaLine );
1555
+ }
1556
+ }
1557
+ return null ;
1593
1558
}
1594
1559
1595
1560
0 commit comments