diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 1d540c3741c..f87286209ed 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -678,6 +678,10 @@ public void setModified(boolean state) { //new Exception().printStackTrace(); current.setModified(state); calcModified(); + // Remove any status notice, fx. done saving or done uploading, + // to avoid confusion about if the current code is the version + //in the board or not while debugging. + editor.statusNotice(""); } diff --git a/app/src/processing/app/preproc/PdePreprocessor.java b/app/src/processing/app/preproc/PdePreprocessor.java index 2b4f03e85a6..e15f1087081 100644 --- a/app/src/processing/app/preproc/PdePreprocessor.java +++ b/app/src/processing/app/preproc/PdePreprocessor.java @@ -43,14 +43,14 @@ Processing version Copyright (c) 2004-05 Ben Fry and Casey Reas */ public class PdePreprocessor { // stores number of built user-defined function prototypes - public int prototypeCount = 0; + public int generatedPrototypeCount = 0; // stores number of included library headers written // we always write one header: Arduino.h public int headerCount = 1; // the prototypes that are generated by the preprocessor - List prototypes; + List generatedPrototypes; // these ones have the .* at the end, since a class name might be at the end // instead of .* which would make trouble other classes using this can lop @@ -126,10 +126,10 @@ public int writePrefix(String program, String buildPath, // } // } - prototypes = prototypes(program); + generatedPrototypes = generatePrototypes(program); // store # of prototypes so that line number reporting can be adjusted - prototypeCount = prototypes.size(); + generatedPrototypeCount = generatedPrototypes.size(); // do this after the program gets re-combobulated this.program = program; @@ -138,7 +138,7 @@ public int writePrefix(String program, String buildPath, File streamFile = new File(buildPath, name + ".cpp"); stream = new PrintStream(new FileOutputStream(streamFile)); - return headerCount + prototypeCount; + return headerCount + generatedPrototypeCount; } @@ -187,7 +187,7 @@ static String substituteUnicode(String program) { //public String write(String program, String buildPath, String name, // String extraImports[]) throws java.lang.Exception { public String write() throws java.lang.Exception { - writeProgram(stream, program, prototypes); + writeProgram(stream, program, generatedPrototypes); writeFooter(stream); stream.close(); @@ -195,18 +195,18 @@ public String write() throws java.lang.Exception { } // Write the pde program to the cpp file - protected void writeProgram(PrintStream out, String program, List prototypes) { - int prototypeInsertionPoint = firstStatement(program); + protected void writeProgram(PrintStream out, String program, List generatedPrototypes) { + int generatedPrototypeInsertionPoint = firstStatement(program); - out.print(program.substring(0, prototypeInsertionPoint)); + out.print(program.substring(0, generatedPrototypeInsertionPoint)); out.print("#include \"Arduino.h\"\n"); // print user defined prototypes - for (int i = 0; i < prototypes.size(); i++) { - out.print(prototypes.get(i) + "\n"); + for (int i = 0; i < generatedPrototypes.size(); i++) { + out.print(generatedPrototypes.get(i) + "\n"); } - out.print(program.substring(prototypeInsertionPoint)); + out.print(program.substring(generatedPrototypeInsertionPoint)); } @@ -311,18 +311,35 @@ private String collapseBraces(String in) { return buffer.toString(); } - public ArrayList prototypes(String in) { + public ArrayList generatePrototypes(String in) { in = collapseBraces(strip(in)); // XXX: doesn't handle ... varargs // XXX: doesn't handle function pointers - Pattern pattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)"); + Pattern prototypePattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*;)"); + Pattern functionPattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)"); - ArrayList matches = new ArrayList(); - Matcher matcher = pattern.matcher(in); - while (matcher.find()) - matches.add(matcher.group(0) + ";"); + // Find already declared prototypes + ArrayList prototypeMatches = new ArrayList(); + Matcher prototypeMatcher = prototypePattern.matcher(in); + while (prototypeMatcher.find()) + prototypeMatches.add(prototypeMatcher.group(0) + ";"); + + // Find all functions and generate prototypes for them + ArrayList functionMatches = new ArrayList(); + Matcher functionMatcher = functionPattern.matcher(in); + while (functionMatcher.find()) + functionMatches.add(functionMatcher.group(0) + ";"); + + // Remove generated prototypes that exactly match ones found in the source file + for (int functionIndex=0; functionIndex < functionMatches.size(); functionIndex++) { + for (int prototypeIndex=0; prototypeIndex < prototypeMatches.size(); prototypeIndex++) { + if ((functionMatches.get(functionIndex)).equals(prototypeMatches.get(prototypeIndex))) { + functionMatches.remove(functionIndex); + } + } + } - return matches; + return functionMatches; } }