From 96fc3c18c0cb118ec273947590e27114bfd7970d Mon Sep 17 00:00:00 2001 From: Lars / EbiDK Date: Sat, 25 Feb 2012 13:13:58 +0100 Subject: [PATCH 1/3] Changing the prototype generator to only generate prototypes that are not already in the source, thus allowing custom datatypes as function arguments and returntypes. --- .../app/preproc/PdePreprocessor.java | 55 ++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) 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; } } From f9ba687cff3bbc4fca0bfb2ab3a4fe456a1dc15c Mon Sep 17 00:00:00 2001 From: Lars / EbiDK Date: Sat, 25 Feb 2012 21:00:45 +0100 Subject: [PATCH 2/3] Fix issue 279. --- app/src/processing/app/EditorListener.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/processing/app/EditorListener.java b/app/src/processing/app/EditorListener.java index 58c3fc9a14b..12806b4ce78 100644 --- a/app/src/processing/app/EditorListener.java +++ b/app/src/processing/app/EditorListener.java @@ -122,6 +122,14 @@ public boolean keyPressed(KeyEvent event) { } } + if ((event.getModifiers() & KeyEvent.CTRL_MASK) != 0) { + // Consume ctrl-m(carriage return) keypresses + if (code == KeyEvent.VK_M) { + event.consume(); // does nothing + return false; + } + } + if ((event.getModifiers() & KeyEvent.META_MASK) != 0) { //event.consume(); // does nothing return false; From b4b78c1716fd4c772762ae6bd0f0c471ed38ed74 Mon Sep 17 00:00:00 2001 From: Lars / EbiDK Date: Sat, 3 Mar 2012 19:10:48 +0100 Subject: [PATCH 3/3] Clear statusNotice text, when the sketch is modified, to avoid confusion when debugging. http://arduino.cc/forum/index.php/topic,93732.0.html --- app/src/processing/app/Sketch.java | 4 ++++ 1 file changed, 4 insertions(+) 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(""); }