Improving the preprocessor and parallel programmer.

This commit is contained in:
David A. Mellis 2008-02-20 02:27:23 +00:00
parent f7ea3cbeb1
commit 249f16678e
6 changed files with 65 additions and 24 deletions

View File

@ -85,6 +85,10 @@ public class AvrdudeUploader extends Uploader {
// XXX: add support for specifying the port address for parallel
// programmers, although avrdude has a default that works in most cases.
if (Preferences.get("programmers." + programmer + ".force") != null &&
Preferences.getBoolean("programmers." + programmer + ".force"))
params.add("-F");
if (Preferences.get("programmers." + programmer + ".delay") != null)
params.add("-i" + Preferences.get("programmers." + programmer + ".delay"));

View File

@ -83,6 +83,41 @@ public class PdePreprocessor {
*/
//public static TokenStreamCopyingHiddenTokenFilter filter;
/**
* Returns the index of the first character that's not whitespace, a comment
* or a pre-processor directive.
*/
public int firstStatement(String in) {
PatternMatcherInput input = new PatternMatcherInput(in);
PatternCompiler compiler = new Perl5Compiler();
PatternMatcher matcher = new Perl5Matcher();
Pattern pattern = null;
try {
pattern = compiler.compile(
// XXX: doesn't properly handle special single-quoted characters
// whitespace
"\\s+" + "|" +
// multi-line comment
"(/\\*(?:.|\\n)*?\\*/)" + "|" +
// single-line comment
"(//.*?$)" + "|" +
// pre-processor directive
"(#(?:\\\\\\n|.)*)",
Perl5Compiler.MULTILINE_MASK);
} catch (MalformedPatternException e) {
throw new RuntimeException("Internal error in firstStatement()", e);
}
int i = 0;
while (matcher.matchesPrefix(input, pattern)) {
i = matcher.getMatch().endOffset(0);
input.setCurrentOffset(i);
}
return i;
}
/**
* Strips comments, pre-processor directives, single- and double-quoted
* strings from a string.
@ -272,9 +307,9 @@ public class PdePreprocessor {
File streamFile = new File(buildPath, name + ".cpp");
PrintStream stream = new PrintStream(new FileOutputStream(streamFile));
writeHeader(stream, name, prototypes);
writeHeader(stream);
//added to write the pde code to the cpp file
writeProgram(stream, name, program);
writeProgram(stream, program, prototypes);
writeFooter(stream, target);
stream.close();
@ -282,8 +317,17 @@ public class PdePreprocessor {
}
// Write the pde program to the cpp file
void writeProgram(PrintStream out, String className, String program) {
out.print(program);
void writeProgram(PrintStream out, String program, List prototypes) {
int prototypeInsertionPoint = firstStatement(program);
out.print(program.substring(0, prototypeInsertionPoint));
// print user defined prototypes
for (int i = 0; i < prototypes.size(); i++) {
out.print(prototypes.get(i) + "\n");
}
out.print(program.substring(prototypeInsertionPoint));
}
@ -291,24 +335,10 @@ public class PdePreprocessor {
* Write any required header material (eg imports, class decl stuff)
*
* @param out PrintStream to write it to.
* @param exporting Is this being exported from PDE?
* @param name Name of the class being created.
*/
void writeHeader(PrintStream out, String className, List prototypes)
void writeHeader(PrintStream out)
throws IOException {
out.print("#include \"WProgram.h\"\n");
// print user defined prototypes
for (int i = 0; i < prototypes.size(); i++) {
out.print(prototypes.get(i) + "\n");
}
// // emit emports that are needed for classes from the code folder
// if (extraImports != null) {
// for (int i = 0; i < extraImports.length; i++) {
// out.print("#include \"" + extraImports[i] + "\"\n");
// }
// }
out.print("#include \"WProgram.h\"\n");
}
/**

View File

@ -151,6 +151,7 @@
<string>$JAVAROOT/registry.jar</string>
<string>$JAVAROOT/RXTXcomm.jar</string>
<string>$JAVAROOT/quaqua.jar</string>
<string>/System/Library/Java</string>
</array>
<key>JVMVersion</key>
<string>1.4+</string>

View File

@ -11,4 +11,5 @@ usbtinyisp.protocol=usbtiny
parallel.name=Parallel Programmer
parallel.protocol=dapa
parallel.delay=800
parallel.force=true
# parallel.delay=200

View File

@ -54,6 +54,9 @@ UPDATES
* Added interrupts() and noInterrupts() functions.
* Added degrees() and radians() functions.
* Support for uploading sketch using a programmer (upload.using preference).
* Improved detection of functions that need prototyping.
* Placing function prototypes after #include's and #define's.
* No longer moving #include statements to the top of the sketch.
* Including a working version of the Firmata firmware.
* New script for downloading the reference from Tom Pollard. Thanks Tom!
* Miscellaneous Mac OS X and other patches from Wim Lewis. Thanks Wim!

View File

@ -3,16 +3,16 @@
0011
Improve preprocessing of sketches:
- Don't move #include statements.
- Insert prototypes as a better spot in the code (after pre-processor directives).
- Better determine which header files are included (not commented out).
- Remember the original locations of function prototypes to highlight the correct line on error.
- [done] Insert prototypes at a better spot in the code (after pre-processor directives).
- [done] Don't move #include statements.
- [done] Better determine which functions need prototypes
Update version of the FTDI drivers.
Floating point support in the map() function.
Modify parallel port programmer burning (add -F, lower or remove delay).
Incorporate ladyada's new SoftwareSerial library.
Add timeout parameter to pulseIn().
[done] Modify parallel port programmer burning (add -F, lower or remove delay).
[done] Allow uploading using a hardware programmer.
[done] Add analogReference() function.
[done] Add miscellaneous #defines (interrupts(), int(), etc.)
@ -28,6 +28,8 @@ Add pulseOut(), etc. functions from Wiring.
Add String library.
Create Encoder library (but don't include in the distribution).
Create Ping library (but don't include in the distribution).
Add highByte(), lowByte(), and word(high, low) functions.
Add bitRead() and bitWrite() functions.
Include Arduino as AVR-ISP sketch in hardware/firmwares.
COMPUTER