From ae98fbfee8f3a3e1ecdf6179c7f2127129f1ed0d Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 1 Jun 2009 09:28:41 +0000 Subject: [PATCH] Fixing some compilations bugs: - including .cpp and .c files from sketch - adjusting error line highlighted according to the number of function prototypes generated - taking into account preprocessor offset on the first .pde file --- app/src/processing/app/Sketch.java | 2 +- app/src/processing/app/debug/Compiler.java | 58 +++++++++---------- .../app/preproc/PdePreprocessor.java | 3 +- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 6af10d1b6..e92a2e7e7 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1275,7 +1275,7 @@ public class Sketch { name, codeFolderPackages, target); - headerOffset = preprocessor.headerCount; + headerOffset = preprocessor.headerCount + preprocessor.prototypeCount; if (className == null) { throw new RunnerException("Could not find main class"); diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index fa9c8e0c1..16e9b4515 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -133,14 +133,14 @@ public class Compiler implements MessageConsumer { for (int i = 0; i < sketch.getCodeCount(); i++) { //if (sketch.getCode(i).preprocName != null) { - if (sketch.getCode(i).isExtension(".c")) { - sourceNames.add(buildPath + File.separator + sketch.getCode(i).getPrettyName()); - objectNames.add(buildPath + File.separator + sketch.getCode(i).getPrettyName() + ".o"); - sketchObjectNames.add(buildPath + File.separator + sketch.getCode(i).getPrettyName() + ".o"); - } else if (sketch.getCode(i).isExtension(".cpp")) { - sourceNamesCPP.add(buildPath + File.separator + sketch.getCode(i).getPrettyName()); - objectNamesCPP.add(buildPath + File.separator + sketch.getCode(i).getPrettyName() + ".o"); - sketchObjectNames.add(buildPath + File.separator + sketch.getCode(i).getPrettyName() + ".o"); + if (sketch.getCode(i).isExtension("c")) { + sourceNames.add(buildPath + File.separator + sketch.getCode(i).getFileName()); + objectNames.add(buildPath + File.separator + sketch.getCode(i).getFileName() + ".o"); + sketchObjectNames.add(buildPath + File.separator + sketch.getCode(i).getFileName() + ".o"); + } else if (sketch.getCode(i).isExtension("cpp")) { + sourceNamesCPP.add(buildPath + File.separator + sketch.getCode(i).getFileName()); + objectNamesCPP.add(buildPath + File.separator + sketch.getCode(i).getFileName() + ".o"); + sketchObjectNames.add(buildPath + File.separator + sketch.getCode(i).getFileName() + ".o"); } //} } @@ -280,10 +280,10 @@ public class Compiler implements MessageConsumer { boolean compiling = true; while (compiling) { try { - if (in.thread != null) - in.thread.join(); - if (err.thread != null) - err.thread.join(); + if (in.thread != null) + in.thread.join(); + if (err.thread != null) + err.thread.join(); result = process.waitFor(); //System.out.println("result is " + result); compiling = false; @@ -337,16 +337,16 @@ public class Compiler implements MessageConsumer { // wasn't there, check the other (non-pde) files in the sketch. // iterate through the project files to see who's causing the trouble for (int i = 0; i < sketch.getCodeCount(); i++) { - if (sketch.getCode(i).isExtension("pde")) continue; + if (sketch.getCode(i).isExtension("pde")) continue; - partialTempPath = buildPathSubst + sketch.getCode(i).getFileName(); - System.out.println(partialTempPath); - partialStartIndex = s.indexOf(partialTempPath); - if (partialStartIndex != -1) { - fileIndex = i; - System.out.println("fileIndex is " + fileIndex); - break; - } + partialTempPath = buildPathSubst + sketch.getCode(i).getFileName(); + System.out.println(partialTempPath); + partialStartIndex = s.indexOf(partialTempPath); + if (partialStartIndex != -1) { + fileIndex = i; + System.out.println("fileIndex is " + fileIndex); + break; + } } //+ className + ".java"; } @@ -377,27 +377,23 @@ public class Compiler implements MessageConsumer { return; } - // the "1" corresponds to the amount of lines written to the main code - // file by PdePreprocessor's writeHeader() routine before prototypes - if (fileIndex == 0) - lineNumber -= 1; - //System.out.println("pde / line number: " + lineNumber); if (fileIndex == 0) { // main class, figure out which tab for (int i = 1; i < sketch.getCodeCount(); i++) { if (sketch.getCode(i).isExtension("pde")) { - //System.out.println("preprocOffset "+ sketch.code[i].preprocOffset); + //System.out.println("preprocOffset "+ sketch.getCode(i).getPreprocOffset()); if (sketch.getCode(i).getPreprocOffset() < lineNumber) { fileIndex = i; //System.out.println("i'm thinkin file " + i); } } } - if (fileIndex != 0) { // if found another culprit - lineNumber -= sketch.getCode(fileIndex).getPreprocOffset(); - //System.out.println("i'm sayin line " + lineNumber); - } + // XXX: DAM: if the lineNumber is less than sketch.getCode(0).getPreprocOffset() + // we shouldn't subtract anything from it, as the error is above the + // location where the function prototypes and #include "WProgram.h" + // were inserted. + lineNumber -= sketch.getCode(fileIndex).getPreprocOffset(); } //String s2 = s1.substring(colon + 2); diff --git a/app/src/processing/app/preproc/PdePreprocessor.java b/app/src/processing/app/preproc/PdePreprocessor.java index 2e50a1b06..e0ba89681 100644 --- a/app/src/processing/app/preproc/PdePreprocessor.java +++ b/app/src/processing/app/preproc/PdePreprocessor.java @@ -72,7 +72,8 @@ public class PdePreprocessor { public int prototypeCount = 0; // stores number of included library headers written - public int headerCount = 0; + // we always write one header: WProgram.h + public int headerCount = 1; /** * These may change in-between (if the prefs panel adds this option)