1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-30 19:52:13 +01:00

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
This commit is contained in:
David A. Mellis 2009-06-01 09:28:41 +00:00
parent 2fa8deb92d
commit ae98fbfee8
3 changed files with 30 additions and 33 deletions

View File

@ -1275,7 +1275,7 @@ public class Sketch {
name, name,
codeFolderPackages, codeFolderPackages,
target); target);
headerOffset = preprocessor.headerCount; headerOffset = preprocessor.headerCount + preprocessor.prototypeCount;
if (className == null) { if (className == null) {
throw new RunnerException("Could not find main class"); throw new RunnerException("Could not find main class");

View File

@ -133,14 +133,14 @@ public class Compiler implements MessageConsumer {
for (int i = 0; i < sketch.getCodeCount(); i++) { for (int i = 0; i < sketch.getCodeCount(); i++) {
//if (sketch.getCode(i).preprocName != null) { //if (sketch.getCode(i).preprocName != null) {
if (sketch.getCode(i).isExtension(".c")) { if (sketch.getCode(i).isExtension("c")) {
sourceNames.add(buildPath + File.separator + sketch.getCode(i).getPrettyName()); sourceNames.add(buildPath + File.separator + sketch.getCode(i).getFileName());
objectNames.add(buildPath + File.separator + sketch.getCode(i).getPrettyName() + ".o"); objectNames.add(buildPath + File.separator + sketch.getCode(i).getFileName() + ".o");
sketchObjectNames.add(buildPath + File.separator + sketch.getCode(i).getPrettyName() + ".o"); sketchObjectNames.add(buildPath + File.separator + sketch.getCode(i).getFileName() + ".o");
} else if (sketch.getCode(i).isExtension(".cpp")) { } else if (sketch.getCode(i).isExtension("cpp")) {
sourceNamesCPP.add(buildPath + File.separator + sketch.getCode(i).getPrettyName()); sourceNamesCPP.add(buildPath + File.separator + sketch.getCode(i).getFileName());
objectNamesCPP.add(buildPath + File.separator + sketch.getCode(i).getPrettyName() + ".o"); objectNamesCPP.add(buildPath + File.separator + sketch.getCode(i).getFileName() + ".o");
sketchObjectNames.add(buildPath + File.separator + sketch.getCode(i).getPrettyName() + ".o"); sketchObjectNames.add(buildPath + File.separator + sketch.getCode(i).getFileName() + ".o");
} }
//} //}
} }
@ -280,10 +280,10 @@ public class Compiler implements MessageConsumer {
boolean compiling = true; boolean compiling = true;
while (compiling) { while (compiling) {
try { try {
if (in.thread != null) if (in.thread != null)
in.thread.join(); in.thread.join();
if (err.thread != null) if (err.thread != null)
err.thread.join(); err.thread.join();
result = process.waitFor(); result = process.waitFor();
//System.out.println("result is " + result); //System.out.println("result is " + result);
compiling = false; compiling = false;
@ -337,16 +337,16 @@ public class Compiler implements MessageConsumer {
// wasn't there, check the other (non-pde) files in the sketch. // wasn't there, check the other (non-pde) files in the sketch.
// iterate through the project files to see who's causing the trouble // iterate through the project files to see who's causing the trouble
for (int i = 0; i < sketch.getCodeCount(); i++) { 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(); partialTempPath = buildPathSubst + sketch.getCode(i).getFileName();
System.out.println(partialTempPath); System.out.println(partialTempPath);
partialStartIndex = s.indexOf(partialTempPath); partialStartIndex = s.indexOf(partialTempPath);
if (partialStartIndex != -1) { if (partialStartIndex != -1) {
fileIndex = i; fileIndex = i;
System.out.println("fileIndex is " + fileIndex); System.out.println("fileIndex is " + fileIndex);
break; break;
} }
} }
//+ className + ".java"; //+ className + ".java";
} }
@ -377,27 +377,23 @@ public class Compiler implements MessageConsumer {
return; 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); //System.out.println("pde / line number: " + lineNumber);
if (fileIndex == 0) { // main class, figure out which tab if (fileIndex == 0) { // main class, figure out which tab
for (int i = 1; i < sketch.getCodeCount(); i++) { for (int i = 1; i < sketch.getCodeCount(); i++) {
if (sketch.getCode(i).isExtension("pde")) { 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) { if (sketch.getCode(i).getPreprocOffset() < lineNumber) {
fileIndex = i; fileIndex = i;
//System.out.println("i'm thinkin file " + i); //System.out.println("i'm thinkin file " + i);
} }
} }
} }
if (fileIndex != 0) { // if found another culprit // XXX: DAM: if the lineNumber is less than sketch.getCode(0).getPreprocOffset()
lineNumber -= sketch.getCode(fileIndex).getPreprocOffset(); // we shouldn't subtract anything from it, as the error is above the
//System.out.println("i'm sayin line " + lineNumber); // location where the function prototypes and #include "WProgram.h"
} // were inserted.
lineNumber -= sketch.getCode(fileIndex).getPreprocOffset();
} }
//String s2 = s1.substring(colon + 2); //String s2 = s1.substring(colon + 2);

View File

@ -72,7 +72,8 @@ public class PdePreprocessor {
public int prototypeCount = 0; public int prototypeCount = 0;
// stores number of included library headers written // 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) * These may change in-between (if the prefs panel adds this option)