mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Reworked build system: makefiles replaced with in-program logic; core replaced with targets; preproc/ replaced with Wiring's; now prepend "#include "WProgram.h" instead of wiringlite.inc; new entries in preferences.txt; bundled Wiring libs.
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Compiler - default compiler class that connects to the external compiler
|
||||
Compiler - default compiler class that connects to avr-gcc
|
||||
Part of the Arduino project - http://arduino.berlios.de/
|
||||
|
||||
Part of the Arduino project - http://arduino.berlios.de
|
||||
Copyright (c) 2004-05 Hernando Barragan
|
||||
|
||||
Derived from the Processing project - http://processing.org
|
||||
|
||||
Copyleft 2005 Massimo Banzi (arduino modifications)
|
||||
Processing version
|
||||
Copyright (c) 2004-05 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
@ -22,6 +23,8 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id:$
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
@ -32,8 +35,10 @@ import java.util.zip.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Compiler implements MessageConsumer {
|
||||
static final String BUGS_URL = "http://arduino.berlios.de";
|
||||
static final String SUPER_BADNESS = "Compiler error, please submit this code to " + BUGS_URL;
|
||||
static final String BUGS_URL =
|
||||
"https://developer.berlios.de/bugs/?group_id=3590";
|
||||
static final String SUPER_BADNESS =
|
||||
"Compiler error, please submit this code to " + BUGS_URL;
|
||||
|
||||
Sketch sketch;
|
||||
String buildPath;
|
||||
@ -57,9 +62,10 @@ public class Compiler implements MessageConsumer {
|
||||
public boolean compile(PrintStream leechErr) {
|
||||
*/
|
||||
|
||||
public Compiler() { } // null constructor
|
||||
public Compiler() { } // consider this a warning, you werkin soon.
|
||||
|
||||
public boolean compile(Sketch sketch, String buildPath)
|
||||
|
||||
public boolean compile(Sketch sketch, String buildPath, Target target)
|
||||
throws RunnerException {
|
||||
|
||||
this.sketch = sketch;
|
||||
@ -70,45 +76,401 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
String userdir = System.getProperty("user.dir") + File.separator;
|
||||
|
||||
System.out.println("Compiling Arduino program");
|
||||
Process process;
|
||||
String commandLine = "";
|
||||
//TODO test this in windows
|
||||
// FIXME: this is really nasty, it seems that MACOS is making the
|
||||
// compilation inside the lib folder, while windows is doing it
|
||||
// inside the work folder ... why why why --DojoDave
|
||||
if (Base.isWindows()) {
|
||||
commandLine = userdir + "tools\\gnumake.exe -C " + userdir + ". compile";
|
||||
} else if (Base.isMacOS()) {
|
||||
commandLine = userdir + "tools/gnumake -C " + userdir + "lib compile";
|
||||
String baseCommandCompiler[] = new String[] {
|
||||
((!Base.isMacOS()) ? "tools/avr/bin/avr-gcc" :
|
||||
userdir + "tools/avr/bin/avr-gcc"),
|
||||
"-c", // compile, don't link
|
||||
"-g", // include debugging info (so errors include line numbers)
|
||||
"-Os", // optimize for size
|
||||
"-I" + target.getPath(),
|
||||
"-w", // surpress all warnings
|
||||
"-mmcu=" + Preferences.get("build.mcu"),
|
||||
"-DF_CPU=" + Preferences.get("build.f_cpu"),
|
||||
" ",
|
||||
" "
|
||||
};
|
||||
|
||||
String baseCommandCompilerCPP[] = new String[] {
|
||||
((!Base.isMacOS()) ? "tools/avr/bin/avr-g++" :
|
||||
userdir + "tools/avr/bin/avr-g++"),
|
||||
"-c", // compile, don't link
|
||||
"-g", // include debugging info (so errors include line numbers)
|
||||
"-Os", // optimize for size
|
||||
"-I" + target.getPath(),
|
||||
"-w", // surpress all warnings
|
||||
"-fno-exceptions",
|
||||
"-mmcu=" + Preferences.get("build.mcu"),
|
||||
"-DF_CPU=" + Preferences.get("build.f_cpu"),
|
||||
" ",
|
||||
" "
|
||||
};
|
||||
|
||||
String baseCommandLinker[] = new String[] {
|
||||
((!Base.isMacOS()) ? "tools/avr/bin/avr-gcc" :
|
||||
userdir + "tools/avr/bin/avr-gcc"),
|
||||
" ",
|
||||
"-mmcu=" + Preferences.get("build.mcu"),
|
||||
"-o",
|
||||
" ",
|
||||
// ((!Base.isMacOS()) ? "" : userdir) + "lib/uart.o",
|
||||
// ((!Base.isMacOS()) ? "" : userdir) + "lib/buffer.o",
|
||||
// ((!Base.isMacOS()) ? "" : userdir) + "lib/timer.o",
|
||||
// ((!Base.isMacOS()) ? "" : userdir) + "lib/wiring.o",
|
||||
// ((!Base.isMacOS()) ? "" : userdir) + "lib/pins_arduino.o",
|
||||
//((!Base.isMacOS()) ? "lib/WApplet.o" :
|
||||
//userdir + "lib/WApplet.o"),
|
||||
//((!Base.isMacOS()) ? "lib/WSerial.o" :
|
||||
//userdir + "lib/WSerial.o"),
|
||||
//((!Base.isMacOS()) ? "lib/WTimer.o" :
|
||||
//userdir + "lib/WTimer.o"),
|
||||
//((!Base.isMacOS()) ? "lib/Servo.o" :
|
||||
//userdir + "lib/Servo.o"),
|
||||
////((!Base.isMacOS()) ? "lib/Wire.o" :
|
||||
//// userdir + "lib/Wire.o"),
|
||||
////((!Base.isMacOS()) ? "lib/WServo.o" :
|
||||
//// userdir + "lib/WServo.o"),
|
||||
//((!Base.isMacOS()) ? "lib/WDisplay.o" :
|
||||
//userdir + "lib/WDisplay.o"),
|
||||
//((!Base.isMacOS()) ? "lib/WEncoder.o" :
|
||||
//userdir + "lib/WEncoder.o"),
|
||||
//((!Base.isMacOS()) ? "lib/WInterrupts.o" :
|
||||
//userdir + "lib/WInterrupts.o"),
|
||||
//((!Base.isMacOS()) ? "lib/WCounter.o" :
|
||||
//userdir + "lib/WCounter.o"),
|
||||
//((!Base.isMacOS()) ? "tools/avr/avr/lib/libm.a" :
|
||||
//userdir + "tools/avr/avr/lib/libm.a")
|
||||
};
|
||||
|
||||
String baseCommandObjcopy[] = new String[] {
|
||||
((!Base.isMacOS()) ? "tools/avr/bin/avr-objcopy" :
|
||||
userdir + "tools/avr/bin/avr-objcopy"),
|
||||
"-O",
|
||||
" ",
|
||||
"-R",
|
||||
" ",
|
||||
" ",
|
||||
" "
|
||||
};
|
||||
|
||||
/*String baseCommand[] = new String[] {
|
||||
// user.dir is folder containing P5 (and therefore jikes)
|
||||
// macosx needs the extra path info. linux doesn't like it, though
|
||||
// windows doesn't seem to care. write once, headache anywhere.
|
||||
((!Base.isMacOS()) ? "jikes" :
|
||||
System.getProperty("user.dir") + File.separator + "jikes"),
|
||||
|
||||
// this doesn't help much.. also java 1.4 seems to not support
|
||||
// -source 1.1 for javac, and jikes seems to also have dropped it.
|
||||
// for versions of jikes that don't complain, "final int" inside
|
||||
// a function doesn't throw an error, so it could just be a
|
||||
// ms jvm error that this sort of thing doesn't work. blech.
|
||||
//"-source",
|
||||
//"1.1",
|
||||
|
||||
// necessary to make output classes compatible with 1.1
|
||||
// i.e. so that exported applets can work with ms jvm on the web
|
||||
"-target",
|
||||
Preferences.get("preproc.jdk_version"), //"1.1",
|
||||
// let the incompatability headache begin
|
||||
|
||||
// used when run without a vm ("expert" mode)
|
||||
"-bootclasspath",
|
||||
calcBootClassPath(),
|
||||
|
||||
// needed for macosx so that the classpath is set properly
|
||||
// also for windows because qtjava will most likely be here
|
||||
// and for linux, it just doesn't hurt
|
||||
"-classpath",
|
||||
sketch.classPath, //calcClassPath(includeFolder),
|
||||
|
||||
"-nowarn", // we're not currently interested in warnings
|
||||
"+E", // output errors in machine-parsable format
|
||||
"-d", buildPath // output the classes in the buildPath
|
||||
//buildPath + File.separator + className + ".java" // file to compile
|
||||
};*/
|
||||
|
||||
// make list of code files that need to be compiled and the object files
|
||||
// that they will be compiled to (includes code from the sketch and the
|
||||
// library for the target platform)
|
||||
String sourceNames[] = new String[sketch.codeCount + target.getSourceFilenames().size()];
|
||||
String sourceNamesCPP[] = new String[sketch.codeCount + target.getSourceFilenames().size()];
|
||||
String objectNames[] = new String[sketch.codeCount + target.getSourceFilenames().size()];
|
||||
String objectNamesCPP[] = new String[sketch.codeCount + target.getSourceFilenames().size()];
|
||||
int fileCount = 0;
|
||||
int fileCountCPP = 0;
|
||||
for (int i = 0; i < sketch.codeCount; i++) {
|
||||
if (sketch.code[i].preprocName != null) {
|
||||
if (sketch.code[i].preprocName.endsWith(".c")) {
|
||||
sourceNames[fileCount] = buildPath + File.separator + sketch.code[i].preprocName;
|
||||
objectNames[fileCount++] = buildPath + File.separator + sketch.code[i].preprocName + ".o";
|
||||
} else if (sketch.code[i].preprocName.endsWith(".cpp")) {
|
||||
sourceNamesCPP[fileCountCPP] = buildPath + File.separator + sketch.code[i].preprocName;
|
||||
objectNamesCPP[fileCountCPP++] = buildPath + File.separator + sketch.code[i].preprocName + ".o";
|
||||
}
|
||||
int result = 0;
|
||||
}
|
||||
}
|
||||
for (Iterator iter = target.getSourceFilenames().iterator(); iter.hasNext(); ) {
|
||||
String filename = (String) iter.next();
|
||||
if (filename != null) {
|
||||
if (filename.endsWith(".c")) {
|
||||
sourceNames[fileCount] = target.getPath() + File.separator + filename;
|
||||
objectNames[fileCount++] = buildPath + File.separator + filename + ".o";
|
||||
} else if (filename.endsWith(".cpp")) {
|
||||
sourceNamesCPP[fileCountCPP] = target.getPath() + File.separator + filename;
|
||||
objectNamesCPP[fileCountCPP++] = buildPath + File.separator + filename + ".o";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
String commandCompiler[] = new String[baseCommandCompiler.length + preprocCount];
|
||||
System.arraycopy(baseCommandCompiler, 0, commandCompiler, 0, baseCommandCompiler.length);
|
||||
// append each of the files to the command string
|
||||
for (int i = 0; i < preprocCount; i++) {
|
||||
commandCompiler[baseCommandCompiler.length + i] =
|
||||
buildPath + File.separator + preprocNames[i];
|
||||
}
|
||||
|
||||
String commandCompilerCPP[] = new String[baseCommandCompilerCPP.length + preprocCountCPP];
|
||||
System.arraycopy(baseCommandCompilerCPP, 0, commandCompilerCPP, 0, baseCommandCompilerCPP.length);
|
||||
for (int i = 0; i < preprocCountCPP; i++) {
|
||||
commandCompilerCPP[baseCommandCompilerCPP.length + i] =
|
||||
buildPath + File.separator + preprocNamesCPP[i];
|
||||
}
|
||||
*/
|
||||
//PApplet.printarr(command);
|
||||
|
||||
baseCommandLinker[1] = "-Os -Wl,-u,vfprintf -lprintf_flt -lm,-Map=" +
|
||||
((!Base.isMacOS()) ? buildPath : userdir + buildPath)
|
||||
+ File.separator + sketch.name + ".map,--cref";
|
||||
baseCommandLinker[4] = ((!Base.isMacOS()) ? buildPath
|
||||
: buildPath) + File.separator + sketch.name + ".elf";
|
||||
String commandLinker[] = new String[baseCommandLinker.length + fileCount +
|
||||
fileCountCPP + target.getObjectFilenames().size()];
|
||||
System.arraycopy(baseCommandLinker, 0, commandLinker, 0, baseCommandLinker.length);
|
||||
int idx = 0;
|
||||
for(int i = 0; i < fileCount; i++, idx++) {
|
||||
commandLinker[baseCommandLinker.length + idx] = objectNames[i];
|
||||
}
|
||||
for(int i = 0; i < fileCountCPP; i++, idx++) {
|
||||
commandLinker[baseCommandLinker.length + idx] = objectNamesCPP[i];
|
||||
}
|
||||
for(Iterator iter = target.getObjectFilenames().iterator(); iter.hasNext(); idx++) {
|
||||
commandLinker[baseCommandLinker.length + idx] = target.getPath() + File.separator + iter.next(); //already ends in ".o"
|
||||
}
|
||||
|
||||
/*String command[] = new String[baseCommand.length + preprocCount];
|
||||
System.arraycopy(baseCommand, 0, command, 0, baseCommand.length);
|
||||
// append each of the files to the command string
|
||||
for (int i = 0; i < preprocCount; i++) {
|
||||
command[baseCommand.length + i] =
|
||||
buildPath + File.separator + preprocNames[i];
|
||||
}
|
||||
//PApplet.printarr(command);
|
||||
*/
|
||||
/*
|
||||
String command[] = new String[baseCommand.length + sketch.codeCount];
|
||||
System.arraycopy(baseCommand, 0, command, 0, baseCommand.length);
|
||||
// append each of the files to the command string
|
||||
for (int i = 0; i < sketch.codeCount; i++) {
|
||||
command[baseCommand.length + i] =
|
||||
buildPath + File.separator + sketch.code[i].preprocName;
|
||||
}
|
||||
*/
|
||||
|
||||
//for (int i = 0; i < command.length; i++) {
|
||||
//System.out.println("cmd " + i + " " + command[i]);
|
||||
//}
|
||||
|
||||
firstErrorFound = false; // haven't found any errors yet
|
||||
secondErrorFound = false;
|
||||
|
||||
int result = 0; // pre-initialized to quiet a bogus warning from jikes
|
||||
try {
|
||||
// System.out.println(commandLine);
|
||||
process = Runtime.getRuntime().exec(commandLine);
|
||||
|
||||
// execute the compiler, and create threads to deal
|
||||
// with the input and error streams
|
||||
//
|
||||
|
||||
Process process;
|
||||
boolean compiling = true;
|
||||
for(int i = 0; i < fileCount; i++) {
|
||||
baseCommandCompiler[8] = sourceNames[i];
|
||||
baseCommandCompiler[9] = "-o"+ objectNames[i];
|
||||
//System.arraycopy(baseCommandCompiler.length
|
||||
//for(int j = 0; j < baseCommandCompiler.length; j++) {
|
||||
// System.out.println(baseCommandCompiler[j]);
|
||||
//}
|
||||
process = Runtime.getRuntime().exec(baseCommandCompiler);
|
||||
new MessageSiphon(process.getInputStream(), this);
|
||||
new MessageSiphon(process.getErrorStream(), this);
|
||||
|
||||
// wait for the process to finish. if interrupted
|
||||
// before waitFor returns, continue waiting
|
||||
//
|
||||
compiling = true;
|
||||
while (compiling) {
|
||||
try {
|
||||
result = process.waitFor();
|
||||
//System.out.println("result is " + result);
|
||||
compiling = false;
|
||||
} catch (InterruptedException ignored) { }
|
||||
}
|
||||
if (exception != null) {
|
||||
exception.hideStackTrace = true;
|
||||
throw exception;
|
||||
}
|
||||
if(result!=0)
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int i = 0; i < fileCountCPP; i++) {
|
||||
baseCommandCompilerCPP[9] = sourceNamesCPP[i];
|
||||
baseCommandCompilerCPP[10] = "-o"+ objectNamesCPP[i];
|
||||
//for(int j = 0; j < baseCommandCompilerCPP.length; j++) {
|
||||
// System.out.println(baseCommandCompilerCPP[j]);
|
||||
//}
|
||||
process = Runtime.getRuntime().exec(baseCommandCompilerCPP);
|
||||
new MessageSiphon(process.getInputStream(), this);
|
||||
new MessageSiphon(process.getErrorStream(), this);
|
||||
|
||||
// wait for the process to finish. if interrupted
|
||||
// before waitFor returns, continue waiting
|
||||
//
|
||||
compiling = true;
|
||||
while (compiling) {
|
||||
try {
|
||||
result = process.waitFor();
|
||||
//System.out.println("result is " + result);
|
||||
compiling = false;
|
||||
} catch (InterruptedException ignored) { }
|
||||
}
|
||||
if (exception != null) {
|
||||
exception.hideStackTrace = true;
|
||||
throw exception;
|
||||
}
|
||||
if(result!=0)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//for(int j = 0; j < commandLinker.length; j++) {
|
||||
// System.out.println(commandLinker[j]);
|
||||
//}
|
||||
process = Runtime.getRuntime().exec(commandLinker);
|
||||
new MessageSiphon(process.getInputStream(), this);
|
||||
new MessageSiphon(process.getErrorStream(), this);
|
||||
compiling = true;
|
||||
while(compiling) {
|
||||
try {
|
||||
result = process.waitFor();
|
||||
compiling = false;
|
||||
} catch (InterruptedException intExc) { }
|
||||
}
|
||||
if (exception != null) {
|
||||
exception.hideStackTrace = true;
|
||||
throw exception;
|
||||
}
|
||||
if(result!=0)
|
||||
return false;
|
||||
|
||||
/*for(int j = 0; j < baseCommandObjcopy.length; j++) {
|
||||
System.out.println(baseCommandObjcopy[j]);
|
||||
}*/
|
||||
baseCommandObjcopy[2] = "srec";
|
||||
baseCommandObjcopy[4] = ".eeprom";
|
||||
baseCommandObjcopy[5] = buildPath + File.separator + sketch.name + ".elf";
|
||||
baseCommandObjcopy[6] = buildPath + File.separator + sketch.name + ".rom";
|
||||
process = Runtime.getRuntime().exec(baseCommandObjcopy);
|
||||
new MessageSiphon(process.getInputStream(), this);
|
||||
new MessageSiphon(process.getErrorStream(), this);
|
||||
compiling = true;
|
||||
while(compiling) {
|
||||
try {
|
||||
result = process.waitFor();
|
||||
compiling = false;
|
||||
} catch (InterruptedException intExc) { }
|
||||
}
|
||||
if (exception != null) {
|
||||
exception.hideStackTrace = true;
|
||||
throw exception;
|
||||
}
|
||||
if(result!=0)
|
||||
return false;
|
||||
|
||||
baseCommandObjcopy[2] = "ihex";
|
||||
baseCommandObjcopy[4] = ".flash";
|
||||
baseCommandObjcopy[5] = buildPath + File.separator + sketch.name + ".elf";
|
||||
baseCommandObjcopy[6] = buildPath + File.separator + sketch.name + ".hex";
|
||||
process = Runtime.getRuntime().exec(baseCommandObjcopy);
|
||||
new MessageSiphon(process.getInputStream(), this);
|
||||
new MessageSiphon(process.getErrorStream(), this);
|
||||
compiling = true;
|
||||
while(compiling) {
|
||||
try {
|
||||
result = process.waitFor();
|
||||
compiling = false;
|
||||
} catch (InterruptedException intExc) { }
|
||||
}
|
||||
if (exception != null) {
|
||||
exception.hideStackTrace = true;
|
||||
throw exception;
|
||||
}
|
||||
if(result!=0)
|
||||
return false;
|
||||
|
||||
/*Process process = Runtime.getRuntime().exec(command);
|
||||
new MessageSiphon(process.getInputStream(), this);
|
||||
new MessageSiphon(process.getErrorStream(), this);
|
||||
|
||||
// wait for the process to finish. if interrupted
|
||||
// before waitFor returns, continue waiting
|
||||
//
|
||||
boolean compiling = true;
|
||||
while (compiling) {
|
||||
try {
|
||||
result = process.waitFor();
|
||||
//System.out.println("result is " + result);
|
||||
compiling = false;
|
||||
} catch (InterruptedException ignored) { }
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Error: GNUMake probably couldn't be found");
|
||||
result = 99;
|
||||
}
|
||||
if(0 == result){
|
||||
System.out.println("Arduino Compilation Successful");
|
||||
}else{
|
||||
System.out.println("Arduino Compilation Unsuccessful (error: " + result + ")");
|
||||
}
|
||||
return (result == 0);
|
||||
}*/
|
||||
|
||||
} catch (Exception e) {
|
||||
String msg = e.getMessage();
|
||||
if ((msg != null) && (msg.indexOf("avr-gcc: not found") != -1)) {
|
||||
//System.err.println("jikes is missing");
|
||||
Base.showWarning("Compiler error",
|
||||
"Could not find the compiler.\n" +
|
||||
"avr-gcc is missing from your PATH,\n" +
|
||||
"see readme.txt for help.", null);
|
||||
return false;
|
||||
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// an error was queued up by message(), barf this back to build()
|
||||
// which will barf it back to Editor. if you're having trouble
|
||||
// discerning the imagery, consider how cows regurgitate their food
|
||||
// to digest it, and the fact that they have five stomaches.
|
||||
//
|
||||
//System.out.println("throwing up " + exception);
|
||||
if (exception != null) throw exception;
|
||||
|
||||
// if the result isn't a known, expected value it means that something
|
||||
// is fairly wrong, one possibility is that jikes has crashed.
|
||||
//
|
||||
if (result != 0 && result != 1 ) {
|
||||
//exception = new RunnerException(SUPER_BADNESS);
|
||||
//editor.error(exception); // this will instead be thrown
|
||||
Base.openURL(BUGS_URL);
|
||||
throw new RunnerException(SUPER_BADNESS);
|
||||
}
|
||||
|
||||
// success would mean that 'result' is set to zero
|
||||
return (result == 0); // ? true : false;
|
||||
}
|
||||
|
||||
|
||||
@ -120,49 +482,21 @@ public class Compiler implements MessageConsumer {
|
||||
* whenever a piece (usually a line) of error message is spewed
|
||||
* out from the compiler. The errors are parsed for their contents
|
||||
* and line number, which is then reported back to Editor.
|
||||
* In Arduino v1 this is very very crude
|
||||
*/
|
||||
public void message(String s) {
|
||||
// This receives messages as full lines, so a newline needs
|
||||
// to be added as they're printed to the console.
|
||||
//System.out.print(s);
|
||||
|
||||
|
||||
//if ((s.indexOf("warning:") != -1) && (s.indexOf("prog.c:") != -1) ) {
|
||||
// String[] result = s.split(":");
|
||||
// for (int x=0; x<result.length; x++)
|
||||
// System.out.println(x + " " +result[x]);
|
||||
// //System.out.print(s);
|
||||
// //totalErrors++;
|
||||
//}
|
||||
if (((s.indexOf("error:") != -1) || (s.indexOf("warning:") != -1)) && (s.indexOf("prog.c:") != -1) ) {
|
||||
String[] result = s.split(":");
|
||||
// 0 = prog.c
|
||||
// 1 = line number
|
||||
// 2 = error or warning
|
||||
// 3 = message
|
||||
// TODO put the length of the header file into a Preference!!!
|
||||
//if ((s.indexOf("(Each undeclared") == 0) && (s.indexOf("for each function it appears in") == 0)) {
|
||||
int lineNum = Integer.parseInt(result[1]) - 15;
|
||||
System.out.print( result[2] + " at line " + lineNum + " " + result[3]);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void processing_message(String s) {
|
||||
//System.err.print(s);
|
||||
|
||||
// ignore cautions
|
||||
if (s.indexOf("Caution") != -1) return;
|
||||
if (s.indexOf("warning") != -1) return;
|
||||
|
||||
// jikes always uses a forward slash character as its separator,
|
||||
// so replace any platform-specific separator characters before
|
||||
// attemping to compare
|
||||
//
|
||||
String buildPathSubst = buildPath.replace(File.separatorChar, '/') + "/";
|
||||
//String buildPathSubst = buildPath.replace(File.separatorChar, '/') + "/";
|
||||
String buildPathSubst = buildPath.replace(File.separatorChar,File.separatorChar) + File.separatorChar;
|
||||
|
||||
String partialTempPath = null;
|
||||
int partialStartIndex = -1; //s.indexOf(partialTempPath);
|
||||
@ -191,13 +525,28 @@ public class Compiler implements MessageConsumer {
|
||||
//
|
||||
String s1 = s.substring(partialStartIndex +
|
||||
partialTempPath.length() + 1);
|
||||
//System.out.println(s1);
|
||||
if (s1.indexOf("In function")!= -1) {
|
||||
System.err.print(s1);
|
||||
//firstErrorFound = true;
|
||||
return;
|
||||
}
|
||||
|
||||
int colon = s1.indexOf(':');
|
||||
|
||||
int lineNumber = Integer.parseInt(s1.substring(0, colon));
|
||||
|
||||
// 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.codeCount; i++) {
|
||||
if (sketch.code[i].flavor == Sketch.PDE) {
|
||||
//System.out.println("preprocOffset "+ sketch.code[i].preprocOffset);
|
||||
if (sketch.code[i].preprocOffset < lineNumber) {
|
||||
fileIndex = i;
|
||||
//System.out.println("i'm thinkin file " + i);
|
||||
@ -211,7 +560,7 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
|
||||
//String s2 = s1.substring(colon + 2);
|
||||
int err = s1.indexOf("Error:");
|
||||
int err = s1.indexOf(":");
|
||||
if (err != -1) {
|
||||
|
||||
// if the first error has already been found, then this must be
|
||||
@ -224,32 +573,33 @@ public class Compiler implements MessageConsumer {
|
||||
// if executing at this point, this is *at least* the first error
|
||||
firstErrorFound = true;
|
||||
|
||||
//err += "error:".length();
|
||||
String description = s1.substring(err + "Error:".length());
|
||||
err += ":".length();
|
||||
String description = s1.substring(err);
|
||||
description = description.trim();
|
||||
System.err.print(description);
|
||||
|
||||
String hasLoop = "The method \"void loop();\" with default access";
|
||||
/* String hasLoop = "The method \"void loop();\" with default access";
|
||||
if (description.indexOf(hasLoop) != -1) {
|
||||
description =
|
||||
"Rename loop() to draw() in Processing 0070 and higher";
|
||||
}
|
||||
|
||||
String constructorProblem =
|
||||
*/
|
||||
/* String constructorProblem =
|
||||
"No applicable overload was found for a constructor of type";
|
||||
if (description.indexOf(constructorProblem) != -1) {
|
||||
//"simong.particles.ParticleSystem". Perhaps you wanted the overloaded version "ParticleSystem();" instead?
|
||||
int nextSentence = description.indexOf("\".") + 3;
|
||||
description = description.substring(nextSentence);
|
||||
}
|
||||
|
||||
String overloadProblem = "No applicable overload";
|
||||
*/
|
||||
/* String overloadProblem = "No applicable overload";
|
||||
if (description.indexOf(overloadProblem) != -1) {
|
||||
int nextSentence = description.indexOf("\".") + 3;
|
||||
description = description.substring(nextSentence);
|
||||
}
|
||||
|
||||
*/
|
||||
// c:/fry/processing/build/windows/work/lib/build/Temporary_6858_2476.java:1:34:1:41: Semantic Error: You need to modify your classpath, sourcepath, bootclasspath, and/or extdirs setup. Package "poo/shoe" could not be found in:
|
||||
String classpathProblem = "You need to modify your classpath";
|
||||
/* String classpathProblem = "You need to modify your classpath";
|
||||
if (description.indexOf(classpathProblem) != -1) {
|
||||
if (description.indexOf("quicktime/std") != -1) {
|
||||
// special case for the quicktime libraries
|
||||
@ -264,7 +614,7 @@ public class Compiler implements MessageConsumer {
|
||||
" the code folder or in any libraries.";
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
//System.out.println("description = " + description);
|
||||
//System.out.println("creating exception " + exception);
|
||||
exception = new RunnerException(description, fileIndex, lineNumber-1, -1);
|
||||
@ -292,7 +642,7 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
static String bootClassPath;
|
||||
|
||||
static public String calcBootClassPath() {
|
||||
@ -307,7 +657,7 @@ public class Compiler implements MessageConsumer {
|
||||
return bootClassPath;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
///
|
||||
|
||||
|
||||
@ -340,8 +690,8 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
String list[] = folder.list();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i].toLowerCase().endsWith(".jar") ||
|
||||
list[i].toLowerCase().endsWith(".zip")) {
|
||||
if (list[i].toLowerCase().endsWith(".o") ||
|
||||
list[i].toLowerCase().endsWith(".a")) {
|
||||
abuffer.append(sep);
|
||||
abuffer.append(path);
|
||||
abuffer.append(list[i]);
|
||||
@ -364,7 +714,7 @@ public class Compiler implements MessageConsumer {
|
||||
* @param path the input classpath
|
||||
* @return array of possible package names
|
||||
*/
|
||||
static public String[] packageListFromClassPath(String path) {
|
||||
/* static public String[] packageListFromClassPath(String path) {
|
||||
Hashtable table = new Hashtable();
|
||||
String pieces[] =
|
||||
Base.split(path, File.pathSeparatorChar);
|
||||
@ -373,8 +723,8 @@ public class Compiler implements MessageConsumer {
|
||||
//System.out.println("checking piece '" + pieces[i] + "'");
|
||||
if (pieces[i].length() == 0) continue;
|
||||
|
||||
if (pieces[i].toLowerCase().endsWith(".jar") ||
|
||||
pieces[i].toLowerCase().endsWith(".zip")) {
|
||||
if (pieces[i].toLowerCase().endsWith(".o") ||
|
||||
pieces[i].toLowerCase().endsWith(".a")) {
|
||||
packageListFromZip(pieces[i], table);
|
||||
|
||||
} else { // it's another type of file or directory
|
||||
@ -398,7 +748,7 @@ public class Compiler implements MessageConsumer {
|
||||
//PApplet.printarr(output);
|
||||
return output;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
static private void packageListFromZip(String filename, Hashtable table) {
|
||||
try {
|
||||
|
@ -1,323 +0,0 @@
|
||||
/*
|
||||
Downloader - default downloader class that connects to uisp
|
||||
|
||||
Part of the Arduino project http://arduino.berlios.de
|
||||
|
||||
Based on PdeDownloader by
|
||||
Copyright (c) 2005
|
||||
Hernando Barragan, Interaction Design Institute Ivrea
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
package processing.app;
|
||||
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import gnu.io.*;
|
||||
|
||||
|
||||
|
||||
public class Downloader implements MessageConsumer {
|
||||
static final String BUGS_URL =
|
||||
"http://arduino.berlios.de";
|
||||
static final String SUPER_BADNESS =
|
||||
"Compiler error, please submit this code to " + BUGS_URL;
|
||||
|
||||
String buildPath;
|
||||
String className;
|
||||
File includeFolder;
|
||||
RunnerException exception;
|
||||
Sketch sketch;
|
||||
//Preferences preferences;
|
||||
|
||||
//static SerialPort serialPort;
|
||||
static InputStream serialInput;
|
||||
static OutputStream serialOutput;
|
||||
//int serial; // last byte of data received
|
||||
|
||||
private String serial_port = "COM1";
|
||||
private int serial_rate = 9600;
|
||||
private char serial_parity = 'N';
|
||||
private int serial_databits = 8;
|
||||
private float serial_stopbits = 1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Downloader() {
|
||||
serial_port = Preferences.get("serial.port");
|
||||
|
||||
}
|
||||
|
||||
// Calls the makefile with the "program" option
|
||||
// TODO Windows paths!
|
||||
private boolean downloadMake(String userdir) {
|
||||
System.out.println("Downloading - makefile");
|
||||
Process process;
|
||||
int result = 0;
|
||||
String command = "";
|
||||
try {
|
||||
serial_port = Preferences.get("serial.port");
|
||||
//TODO test this in windows
|
||||
// FIXME: this is really nasty, it seems that MACOS is making the
|
||||
// compilation inside the lib folder, while windows is doing it
|
||||
// inside the work folder ... why why why --DojoDave
|
||||
if (Base.isWindows()) {
|
||||
command = userdir + "tools\\gnumake.exe SERIAL=" + serial_port + " -C " + userdir + ". program";
|
||||
} else if (Base.isMacOS()) {
|
||||
command = userdir + "tools/gnumake SERIAL=" + serial_port + " -C " + "lib program";
|
||||
}
|
||||
// String command = userdir + "lib/wiringlite/bin/gnumake SERIAL=" + serial_port + " -C " + userdir + "lib/wiringlite program";
|
||||
System.out.println(command);
|
||||
process = Runtime.getRuntime().exec(command);
|
||||
new MessageSiphon(process.getInputStream(), this);
|
||||
new MessageSiphon(process.getErrorStream(), this);
|
||||
|
||||
|
||||
boolean compiling = true;
|
||||
while (compiling) {
|
||||
try {
|
||||
result = process.waitFor();
|
||||
compiling = false;
|
||||
} catch (InterruptedException ignored) { }
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Error: GNUMake probably couldn't be found");
|
||||
result = 99;
|
||||
}
|
||||
if(0 == result){
|
||||
System.out.println("Arduino Download Successful");
|
||||
}else{
|
||||
System.out.println("Arduino Download Unsuccessful (error: " + result + ")");
|
||||
}
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
public boolean downloadJava() {
|
||||
String userdir = System.getProperty("user.dir") + File.separator;
|
||||
|
||||
|
||||
//return downloadNative(userdir);
|
||||
return downloadNew(userdir);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Calls UISP directly, skipping the makefile
|
||||
//
|
||||
// TODO Windows paths!!
|
||||
public boolean downloadNative(String userdir) {
|
||||
System.out.println("Downloading code");
|
||||
|
||||
|
||||
// FIXME: this is really nasty, it seems that MACOS is making the
|
||||
// compilation inside the lib folder, while windows is doing it
|
||||
// inside the work folder ... why why why --DojoDave
|
||||
if (Base.isWindows()) {
|
||||
buildPath = userdir + "tmp";
|
||||
} else if (Base.isMacOS()) {
|
||||
buildPath = userdir + "lib/tmp";
|
||||
}
|
||||
|
||||
String commandDownloader[] = new String[] {
|
||||
userdir + "tools/avr/bin/uisp",
|
||||
//[2] Serial port
|
||||
//[6] hex class file
|
||||
"-dprog=stk500",
|
||||
" ",
|
||||
"-dspeed=9600",
|
||||
"-dpart=atmega8",
|
||||
"--upload",
|
||||
" "
|
||||
};
|
||||
|
||||
firstErrorFound = false; // haven't found any errors yet
|
||||
secondErrorFound = false;
|
||||
|
||||
int result=0; // pre-initialized to quiet a bogus warning from gcc
|
||||
try {
|
||||
|
||||
serial_port = Preferences.get("serial.port");
|
||||
commandDownloader[2] = "-dserial=" + serial_port;
|
||||
commandDownloader[6] = "if=" + buildPath + File.separator + "prog.hex";
|
||||
|
||||
// for(int i = 0; i < commandDownloader.length; i++) {
|
||||
// System.out.print(commandDownloader[i] + " ");
|
||||
//}
|
||||
|
||||
Process process = Runtime.getRuntime().exec(commandDownloader);
|
||||
new processing.app.MessageSiphon(process.getInputStream(), this);
|
||||
new processing.app.MessageSiphon(process.getErrorStream(), this);
|
||||
|
||||
|
||||
// wait for the process to finish. if interrupted
|
||||
// before waitFor returns, continue waiting
|
||||
//
|
||||
boolean compiling = true;
|
||||
while (compiling) {
|
||||
try {
|
||||
result = process.waitFor();
|
||||
compiling = false;
|
||||
} catch (InterruptedException intExc) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String msg = e.getMessage();
|
||||
if ((msg != null) && (msg.indexOf("uisp: not found") != -1)) {
|
||||
//System.err.println("gcc is missing");
|
||||
//JOptionPane.showMessageDialog(editor.base,
|
||||
// "Could not find the downloader.\n" +
|
||||
// "uisp is missing from your PATH,\n" +
|
||||
// "see readme.txt for help.",
|
||||
// "Downloade error",
|
||||
// JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
e.printStackTrace();
|
||||
result = -1;
|
||||
}
|
||||
|
||||
// if the result isn't a known, expected value it means that something
|
||||
// is fairly wrong, one possibility is that gcc has crashed.
|
||||
//
|
||||
if (result != 0 && result != 1 ) {
|
||||
exception = new RunnerException(SUPER_BADNESS);
|
||||
//editor.error(exception);
|
||||
//Base.openURL(BUGS_URL);
|
||||
}
|
||||
|
||||
return (result == 0) ? true : false;
|
||||
|
||||
}
|
||||
|
||||
boolean firstErrorFound;
|
||||
boolean secondErrorFound;
|
||||
|
||||
// part of the MessageConsumer interface
|
||||
//
|
||||
// at the moment we are pretty happy just to see the error messages coming back
|
||||
public void message(String s) {
|
||||
//System.err.println("MSG: " + s);
|
||||
System.err.print(s);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean downloadNew(String userdir) {
|
||||
|
||||
serial_port = Preferences.get("serial.port");
|
||||
|
||||
// TODO must manage this flag from the editor
|
||||
boolean alreadyCompiled = true;
|
||||
|
||||
// TODO must manage this flag from global prefs
|
||||
boolean debug = false;
|
||||
|
||||
String verbose = " -s ";
|
||||
|
||||
if (alreadyCompiled) {
|
||||
if (serial_port == "") {
|
||||
System.out.println("The serial port is not set!");
|
||||
System.out.println("Use the Options -> Serial menu to select");
|
||||
System.out.println("where you have connected your arduino board");
|
||||
return false;
|
||||
};
|
||||
|
||||
String commandLine = "";
|
||||
|
||||
|
||||
if (debug) System.out.println("userdir is "+userdir);
|
||||
|
||||
int result = -1;
|
||||
|
||||
|
||||
// TODO make this code more portable using File.separator
|
||||
if (Base.isMacOS()) {
|
||||
commandLine = userdir + "tools/avr/bin/uisp ";
|
||||
commandLine += " -dprog=stk500 -dspeed=9600 ";
|
||||
commandLine += " -dserial=" + serial_port;
|
||||
commandLine += " -dpart=ATmega8";
|
||||
commandLine += " if=" +userdir + "lib/tmp/prog.hex --upload";
|
||||
} else {
|
||||
commandLine = userdir + "tools\\gnumake.exe" + " SERIAL=" + serial_port + verbose + " -C " + userdir + ". program";
|
||||
}
|
||||
if (debug) System.out.println(commandLine);
|
||||
|
||||
// Launch the command as a thread (this way we can kill it
|
||||
// in the case it times out)
|
||||
Command command = new Command(commandLine, true);
|
||||
command.setName("theDownloader");
|
||||
command.start();
|
||||
|
||||
// TODO move this to Preferences
|
||||
// Default timeout when calling a command (in seconds)
|
||||
final int maxTimeOut = 30; // 10 secs
|
||||
|
||||
|
||||
// Start timer to monitor buffer timeout ==> deadlock in process
|
||||
int timeCount = 0;
|
||||
|
||||
while ((timeCount <= maxTimeOut) && (result == -1) && command.isAlive()) {
|
||||
try {
|
||||
result = command.waitResult;
|
||||
Thread.currentThread().sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
timeCount++;
|
||||
}
|
||||
result = command.waitResult;
|
||||
|
||||
if ((result != 0) && (command.errorResult == -1)) {
|
||||
// result = 94;
|
||||
System.out.println("Time out error when trying to upload the program");
|
||||
System.out.println("Board not present, bootloader not installed or processor's failure");
|
||||
System.out.println("Arduino download unsuccessful (error: " + result + ")");
|
||||
} else if (result == 0) {
|
||||
System.out.println(command.errorMsg);
|
||||
System.out.println("OK - Arduino download successful");
|
||||
} else if ((result != 0) && (49 == command.errorResult)) {
|
||||
System.out.println(command.errorMsg);
|
||||
System.out.println("Bootloader not responding");
|
||||
System.out.println("Arduino download unsuccessful (error: " + result + ")");
|
||||
} else {
|
||||
System.out.println(command.errorMsg);
|
||||
System.out.println("Arduino download unsuccessful (error: " + result + ")");
|
||||
}
|
||||
if (command.isAlive()) command.process.destroy();
|
||||
} else {
|
||||
System.out.println("You have to compile the code first");
|
||||
System.out.println("Arduino download unsuccessful");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id:$
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
@ -1135,57 +1137,51 @@ public class Editor extends JFrame
|
||||
doClose();
|
||||
running = true;
|
||||
buttons.run();
|
||||
|
||||
message("Compiling...");
|
||||
// do this for the terminal window / dos prompt / etc
|
||||
for (int i = 0; i < 10; i++) System.out.println();
|
||||
|
||||
// clear the console on each run, unless the user doesn't want to
|
||||
//if (Base.getBoolean("console.auto_clear", true)) {
|
||||
//if (Preferences.getBoolean("console.auto_clear", true)) {
|
||||
if (Preferences.getBoolean("console.auto_clear")) {
|
||||
console.clear();
|
||||
}
|
||||
|
||||
presenting = present;
|
||||
// console.message("Arduino compiling\n", false,true);
|
||||
|
||||
String cfilename = System.getProperty("user.dir") + File.separator + "lib/build/arduino.c";
|
||||
//console.message(" file = " + cfilename, false,true);
|
||||
try {
|
||||
Writer out = new FileWriter(cfilename);
|
||||
out.write(textarea.getText());
|
||||
out.flush();
|
||||
out.close();
|
||||
if (presenting && Base.isMacOS()) {
|
||||
// check to see if osx 10.2, if so, show a warning
|
||||
String osver = System.getProperty("os.version").substring(0, 4);
|
||||
if (osver.equals("10.2")) {
|
||||
Base.showWarning("Time for an OS Upgrade",
|
||||
"The \"Present\" feature may not be available on\n" +
|
||||
"Mac OS X 10.2, because of what appears to be\n" +
|
||||
"a bug in the Java 1.4 implementation on 10.2.\n" +
|
||||
"In case it works on your machine, present mode\n" +
|
||||
"will start, but if you get a flickering white\n" +
|
||||
"window, using Command-Q to quit the sketch", null);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
error(e);
|
||||
}
|
||||
|
||||
Compiler compiler = new Compiler();
|
||||
String buildPath = Preferences.get("build.path");
|
||||
//console.message(" buildpath = " + buildPath, false,true);
|
||||
try {
|
||||
boolean success = compiler.compile(sketch, buildPath);
|
||||
if (!sketch.handleRun(new Target(
|
||||
System.getProperty("user.dir") + File.separator + "lib" +
|
||||
File.separator + "targets", Preferences.get("build.target"))))
|
||||
return;
|
||||
|
||||
//runtime = new Runner(sketch, Editor.this);
|
||||
//runtime.start(appletLocation);
|
||||
watcher = new RunButtonWatcher();
|
||||
message("Done compiling.");
|
||||
if(watcher != null) watcher.stop();
|
||||
|
||||
} catch (RunnerException e) {
|
||||
message("Error compiling...");
|
||||
error(e);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// FIXED: 20050902 - DojoDave
|
||||
// the clear button requires a the clearRun method instead of only clear!!
|
||||
buttons.clearRun();
|
||||
|
||||
|
||||
//- if (!sketch.handleRun()) return;
|
||||
|
||||
//- runtime = new Runner(sketch, Editor.this);
|
||||
//- runtime.start(appletLocation);
|
||||
//- watcher = new RunButtonWatcher();
|
||||
|
||||
//- } catch (RunnerException e) {
|
||||
//- error(e);
|
||||
|
||||
//- } catch (Exception e) {
|
||||
//- e.printStackTrace();
|
||||
//- }
|
||||
|
||||
// this doesn't seem to help much or at all
|
||||
/*
|
||||
@ -1197,8 +1193,10 @@ public class Editor extends JFrame
|
||||
runtime = new Runner(sketch, Editor.this);
|
||||
runtime.start(presenting ? presentLocation : appletLocation);
|
||||
watcher = new RunButtonWatcher();
|
||||
message("Done compiling.");
|
||||
|
||||
} catch (RunnerException e) {
|
||||
message("Error compiling...");
|
||||
error(e);
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -1210,6 +1208,7 @@ public class Editor extends JFrame
|
||||
worker.start();
|
||||
*/
|
||||
//sketch.cleanup(); // where does this go?
|
||||
buttons.clear();
|
||||
}
|
||||
|
||||
|
||||
@ -1661,9 +1660,30 @@ public class Editor extends JFrame
|
||||
* hitting export twice, quickly, and horking things up.
|
||||
*/
|
||||
synchronized public void handleExport() {
|
||||
//if(debugging)
|
||||
//doStop();
|
||||
console.clear();
|
||||
//String what = sketch.isLibrary() ? "Applet" : "Library";
|
||||
//message("Exporting " + what + "...");
|
||||
Downloader d = new Downloader();
|
||||
d.downloadJava();
|
||||
message("Uploading to I/O Board...");
|
||||
try {
|
||||
//boolean success = sketch.isLibrary() ?
|
||||
//sketch.exportLibrary() : sketch.exportApplet();
|
||||
boolean success = sketch.exportApplet(new Target(
|
||||
System.getProperty("user.dir") + File.separator + "lib" +
|
||||
File.separator + "targets", Preferences.get("build.target")));
|
||||
if (success) {
|
||||
message("Done uploading.");
|
||||
} else {
|
||||
// error message will already be visible
|
||||
}
|
||||
} catch (RunnerException e) {
|
||||
message("Error during upload.");
|
||||
//e.printStackTrace();
|
||||
error(e);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
buttons.clear();
|
||||
}
|
||||
|
||||
|
462
app/Sketch.java
462
app/Sketch.java
@ -1,7 +1,7 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
Part of the Arduino project - http://arduino.berlios.de/
|
||||
|
||||
Copyright (c) 2004-05 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
@ -19,6 +19,8 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id:$
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
@ -100,10 +102,11 @@ public class Sketch {
|
||||
// off of the main file name
|
||||
if (mainFilename.endsWith(".pde")) {
|
||||
name = mainFilename.substring(0, mainFilename.length() - 4);
|
||||
} else if (mainFilename.endsWith(".java")) {
|
||||
name = mainFilename.substring(0, mainFilename.length() - 5);
|
||||
} else if (mainFilename.endsWith(".c")) {
|
||||
name = mainFilename.substring(0, mainFilename.length() - 2);
|
||||
} else if (mainFilename.endsWith(".cpp")) {
|
||||
name = mainFilename.substring(0, mainFilename.length() - 4);
|
||||
}
|
||||
|
||||
// lib/build must exist when the application is started
|
||||
// it is added to the CLASSPATH by default, but if it doesn't
|
||||
// exist when the application is started, then java will remove
|
||||
@ -132,15 +135,15 @@ public class Sketch {
|
||||
|
||||
/**
|
||||
* Build the list of files.
|
||||
* <P>
|
||||
*
|
||||
* Generally this is only done once, rather than
|
||||
* each time a change is made, because otherwise it gets to be
|
||||
* a nightmare to keep track of what files went where, because
|
||||
* not all the data will be saved to disk.
|
||||
* <P>
|
||||
*
|
||||
* This also gets called when the main sketch file is renamed,
|
||||
* because the sketch has to be reloaded from a different folder.
|
||||
* <P>
|
||||
*
|
||||
* Another exception is when an external editor is in use,
|
||||
* in which case the load happens each time "run" is hit.
|
||||
*/
|
||||
@ -153,9 +156,11 @@ public class Sketch {
|
||||
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i].endsWith(".pde")) codeCount++;
|
||||
else if (list[i].endsWith(".java")) codeCount++;
|
||||
else if (list[i].endsWith(".c")) codeCount++;
|
||||
else if (list[i].endsWith(".cpp")) codeCount++;
|
||||
else if (list[i].endsWith(".pde.x")) hiddenCount++;
|
||||
else if (list[i].endsWith(".java.x")) hiddenCount++;
|
||||
else if (list[i].endsWith(".c.x")) hiddenCount++;
|
||||
else if (list[i].endsWith(".cpp.x")) hiddenCount++;
|
||||
}
|
||||
|
||||
code = new SketchCode[codeCount];
|
||||
@ -171,9 +176,15 @@ public class Sketch {
|
||||
new File(folder, list[i]),
|
||||
PDE);
|
||||
|
||||
} else if (list[i].endsWith(".java")) {
|
||||
} else if (list[i].endsWith(".c")) {
|
||||
code[codeCounter++] =
|
||||
new SketchCode(list[i].substring(0, list[i].length() - 5),
|
||||
new SketchCode(list[i].substring(0, list[i].length() - 2),
|
||||
new File(folder, list[i]),
|
||||
JAVA);
|
||||
|
||||
} else if (list[i].endsWith(".cpp")) {
|
||||
code[codeCounter++] =
|
||||
new SketchCode(list[i].substring(0, list[i].length() - 4),
|
||||
new File(folder, list[i]),
|
||||
JAVA);
|
||||
|
||||
@ -183,9 +194,14 @@ public class Sketch {
|
||||
new File(folder, list[i]),
|
||||
PDE);
|
||||
|
||||
} else if (list[i].endsWith(".java.x")) {
|
||||
} else if (list[i].endsWith(".c.x")) {
|
||||
hidden[hiddenCounter++] =
|
||||
new SketchCode(list[i].substring(0, list[i].length() - 7),
|
||||
new SketchCode(list[i].substring(0, list[i].length() - 4),
|
||||
new File(folder, list[i]),
|
||||
JAVA);
|
||||
} else if (list[i].endsWith(".cpp.x")) {
|
||||
hidden[hiddenCounter++] =
|
||||
new SketchCode(list[i].substring(0, list[i].length() - 6),
|
||||
new File(folder, list[i]),
|
||||
JAVA);
|
||||
}
|
||||
@ -299,7 +315,7 @@ public class Sketch {
|
||||
String prompt = (current == code[0]) ?
|
||||
"New name for sketch:" : "New name for file:";
|
||||
String oldName =
|
||||
(current.flavor == PDE) ? current.name : current.name + ".java";
|
||||
(current.flavor == PDE) ? current.name : current.name + ".cpp";
|
||||
editor.status.edit(prompt, oldName);
|
||||
}
|
||||
|
||||
@ -331,8 +347,9 @@ public class Sketch {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newName.trim().equals(".java") ||
|
||||
newName.trim().equals(".pde")) {
|
||||
if (newName.trim().equals(".c") ||
|
||||
newName.trim().equals(".pde") ||
|
||||
newName.trim().equals(".cpp")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -346,18 +363,21 @@ public class Sketch {
|
||||
newName = newName.substring(0, newName.length() - 4);
|
||||
newFlavor = PDE;
|
||||
|
||||
} else if (newName.endsWith(".java")) {
|
||||
} else if (newName.endsWith(".c") || newName.endsWith(".cpp")) {
|
||||
// don't show this error if creating a new tab
|
||||
if (renamingCode && (code[0] == current)) {
|
||||
Base.showWarning("Problem with rename",
|
||||
"The main .pde file cannot be .java file.\n" +
|
||||
"The main .pde file cannot be .c or .cpp file.\n" +
|
||||
"(It may be time for your to graduate to a\n" +
|
||||
"\"real\" programming environment)", null);
|
||||
return;
|
||||
}
|
||||
|
||||
newFilename = newName;
|
||||
newName = newName.substring(0, newName.length() - 5);
|
||||
if(newName.endsWith(".c"))
|
||||
newName = newName.substring(0, newName.length() - 2);
|
||||
else if(newName.endsWith(".cpp"))
|
||||
newName = newName.substring(0, newName.length() - 4);
|
||||
newFlavor = JAVA;
|
||||
|
||||
} else {
|
||||
@ -370,7 +390,7 @@ public class Sketch {
|
||||
// or something like that (nothing against poo time)
|
||||
if (newName.indexOf('.') != -1) {
|
||||
newName = Sketchbook.sanitizedName(newName);
|
||||
newFilename = newName + ((newFlavor == PDE) ? ".pde" : ".java");
|
||||
newFilename = newName + ((newFlavor == PDE) ? ".pde" : ".cpp");
|
||||
}
|
||||
|
||||
// create the new file, new SketchCode object and load it
|
||||
@ -522,6 +542,7 @@ public class Sketch {
|
||||
|
||||
// update the tabs
|
||||
//editor.header.repaint();
|
||||
|
||||
editor.header.rebuild();
|
||||
|
||||
// force the update on the mac?
|
||||
@ -658,7 +679,6 @@ public class Sketch {
|
||||
// update the tabs
|
||||
setCurrent(0);
|
||||
editor.header.repaint();
|
||||
//editor.header.rebuild();
|
||||
}
|
||||
|
||||
|
||||
@ -981,17 +1001,18 @@ public class Sketch {
|
||||
|
||||
// if the file appears to be code related, drop it
|
||||
// into the code folder, instead of the data folder
|
||||
if (filename.toLowerCase().endsWith(".class") ||
|
||||
if (filename.toLowerCase().endsWith(".o") /*||
|
||||
filename.toLowerCase().endsWith(".jar") ||
|
||||
filename.toLowerCase().endsWith(".dll") ||
|
||||
filename.toLowerCase().endsWith(".jnilib") ||
|
||||
filename.toLowerCase().endsWith(".so")) {
|
||||
filename.toLowerCase().endsWith(".so") */ ) {
|
||||
//File codeFolder = new File(this.folder, "code");
|
||||
if (!codeFolder.exists()) codeFolder.mkdirs();
|
||||
destFile = new File(codeFolder, filename);
|
||||
|
||||
} else if (filename.toLowerCase().endsWith(".pde") ||
|
||||
filename.toLowerCase().endsWith(".java")) {
|
||||
filename.toLowerCase().endsWith(".c") ||
|
||||
filename.toLowerCase().endsWith(".cpp")) {
|
||||
destFile = new File(this.folder, filename);
|
||||
addingCode = true;
|
||||
|
||||
@ -1030,7 +1051,7 @@ public class Sketch {
|
||||
newName = newName.substring(0, newName.length() - 4);
|
||||
newFlavor = PDE;
|
||||
} else {
|
||||
newName = newName.substring(0, newName.length() - 5);
|
||||
newName = newName.substring(0, newName.length() - 2);
|
||||
newFlavor = JAVA;
|
||||
}
|
||||
|
||||
@ -1045,7 +1066,8 @@ public class Sketch {
|
||||
|
||||
|
||||
public void importLibrary(String jarPath) {
|
||||
// make sure the user didn't hide the sketch folder
|
||||
System.out.println(jarPath);
|
||||
/* // make sure the user didn't hide the sketch folder
|
||||
ensureExistence();
|
||||
|
||||
String list[] = Compiler.packageListFromClassPath(jarPath);
|
||||
@ -1068,7 +1090,7 @@ public class Sketch {
|
||||
buffer.append(editor.getText());
|
||||
editor.setText(buffer.toString(), 0, 0); // scroll to start
|
||||
setModified();
|
||||
}
|
||||
*/ }
|
||||
|
||||
|
||||
/**
|
||||
@ -1174,7 +1196,7 @@ public class Sketch {
|
||||
* X. afterwards, some of these steps need a cleanup function
|
||||
* </PRE>
|
||||
*/
|
||||
public boolean handleRun() throws RunnerException {
|
||||
public boolean handleRun(Target target) throws RunnerException {
|
||||
// make sure the user didn't hide the sketch folder
|
||||
ensureExistence();
|
||||
|
||||
@ -1210,7 +1232,7 @@ public class Sketch {
|
||||
// handle preprocessing the main file's code
|
||||
//mainClassName = build(TEMP_BUILD_PATH, suggestedClassName);
|
||||
mainClassName =
|
||||
build(tempBuildFolder.getAbsolutePath(), suggestedClassName);
|
||||
build(target, tempBuildFolder.getAbsolutePath(), suggestedClassName);
|
||||
// externalPaths is magically set by build()
|
||||
|
||||
if (!externalRuntime) { // only if not running externally already
|
||||
@ -1240,7 +1262,7 @@ public class Sketch {
|
||||
*
|
||||
* @return null if compilation failed, main class name if not
|
||||
*/
|
||||
protected String build(String buildPath, String suggestedClassName)
|
||||
protected String build(Target target, String buildPath, String suggestedClassName)
|
||||
throws RunnerException {
|
||||
// make sure the user didn't hide the sketch folder
|
||||
ensureExistence();
|
||||
@ -1279,8 +1301,8 @@ public class Sketch {
|
||||
String codeFolderClassPath =
|
||||
Compiler.contentsToClassPath(codeFolder);
|
||||
// get list of packages found in those jars
|
||||
codeFolderPackages =
|
||||
Compiler.packageListFromClassPath(codeFolderClassPath);
|
||||
// codeFolderPackages =
|
||||
// Compiler.packageListFromClassPath(codeFolderClassPath);
|
||||
//PApplet.println(libraryPath);
|
||||
//PApplet.println("packages:");
|
||||
//PApplet.printarr(codeFolderPackages);
|
||||
@ -1329,11 +1351,11 @@ public class Sketch {
|
||||
|
||||
// since using the special classloader,
|
||||
// run externally whenever there are extra classes defined
|
||||
if ((bigCode.indexOf(" class ") != -1) ||
|
||||
/* if ((bigCode.indexOf(" class ") != -1) ||
|
||||
(bigCode.indexOf("\nclass ") != -1)) {
|
||||
externalRuntime = true;
|
||||
}
|
||||
|
||||
*/
|
||||
// if running in opengl mode, this is gonna be external
|
||||
//if (Preferences.get("renderer").equals("opengl")) {
|
||||
//externalRuntime = true;
|
||||
@ -1360,7 +1382,7 @@ public class Sketch {
|
||||
//System.out.println();
|
||||
|
||||
} else {
|
||||
code[0].preprocName = className + ".java";
|
||||
code[0].preprocName = className + "." + Preferences.get("build.extension");
|
||||
}
|
||||
|
||||
// store this for the compiler and the runtime
|
||||
@ -1384,6 +1406,7 @@ public class Sketch {
|
||||
}
|
||||
}
|
||||
errorLine -= code[errorFile].preprocOffset;
|
||||
//errorLine -= preprocessor.prototypeCount;
|
||||
|
||||
throw new RunnerException(re.getMessage(), errorFile,
|
||||
errorLine, re.getColumn());
|
||||
@ -1404,7 +1427,9 @@ public class Sketch {
|
||||
Base.showWarning("Internal Problem",
|
||||
"An internal error occurred while trying\n" +
|
||||
"to compile the sketch. Please report\n" +
|
||||
"this online at http://processing.org/bugs", e);
|
||||
"this online at " +
|
||||
"https://developer.berlios.de/bugs/?group_id=3590",
|
||||
e);
|
||||
}
|
||||
|
||||
PatternMatcherInput input =
|
||||
@ -1422,6 +1447,7 @@ public class Sketch {
|
||||
}
|
||||
}
|
||||
errorLine -= code[errorFile].preprocOffset;
|
||||
//errorLine -= preprocessor.prototypeCount;
|
||||
|
||||
throw new RunnerException(tsre.getMessage(),
|
||||
errorFile, errorLine, errorColumn);
|
||||
@ -1485,7 +1511,7 @@ public class Sketch {
|
||||
// just write the the contents of 'program' to a .java file
|
||||
// into the build directory. uses byte stream and reader/writer
|
||||
// shtuff so that unicode bunk is properly handled
|
||||
String filename = code[i].name + ".java";
|
||||
String filename = code[i].name + "." + Preferences.get("build.extension");
|
||||
try {
|
||||
Base.saveFile(code[i].program, new File(buildPath, filename));
|
||||
} catch (IOException e) {
|
||||
@ -1500,12 +1526,53 @@ public class Sketch {
|
||||
// compile the program. errors will happen as a RunnerException
|
||||
// that will bubble up to whomever called build().
|
||||
//
|
||||
// note: this has been changed to catch build exceptions, adjust
|
||||
// line number for number of included prototypes, and rethrow
|
||||
|
||||
Compiler compiler = new Compiler();
|
||||
boolean success = compiler.compile(this, buildPath);
|
||||
boolean success;
|
||||
try {
|
||||
success = compiler.compile(this, buildPath, target);
|
||||
} catch (RunnerException re) {
|
||||
throw new RunnerException(re.getMessage(),
|
||||
re.file,
|
||||
re.line,// - preprocessor.prototypeCount,
|
||||
re.column);
|
||||
} catch (Exception ex) {
|
||||
// TODO better method for handling this?
|
||||
throw new RunnerException(ex.toString());
|
||||
}
|
||||
//System.out.println("success = " + success + " ... " + primaryClassName);
|
||||
return success ? primaryClassName : null;
|
||||
}
|
||||
|
||||
protected String upload(String buildPath, String suggestedClassName)
|
||||
throws RunnerException {
|
||||
|
||||
// download the program
|
||||
//
|
||||
Uploader downloader =
|
||||
new Uploader(buildPath, suggestedClassName, this);
|
||||
// macos9 now officially broken.. see PdeCompilerJavac
|
||||
//PdeCompiler compiler =
|
||||
// ((PdeBase.platform == PdeBase.MACOS9) ?
|
||||
// new PdeCompilerJavac(buildPath, className, this) :
|
||||
// new PdeCompiler(buildPath, className, this));
|
||||
|
||||
// run the compiler, and funnel errors to the leechErr
|
||||
// which is a wrapped around
|
||||
// (this will catch and parse errors during compilation
|
||||
// the messageStream will call message() for 'compiler')
|
||||
MessageStream messageStream = new MessageStream(downloader);
|
||||
//PrintStream leechErr = new PrintStream(messageStream);
|
||||
//boolean result = compiler.compileJava(leechErr);
|
||||
//return compiler.compileJava(leechErr);
|
||||
boolean success =
|
||||
downloader.downloadJava(new PrintStream(messageStream));
|
||||
|
||||
return success ? suggestedClassName : null;
|
||||
}
|
||||
|
||||
|
||||
protected int countLines(String what) {
|
||||
char c[] = what.toCharArray();
|
||||
@ -1546,7 +1613,306 @@ public class Sketch {
|
||||
* +-------------------------------------------------------+
|
||||
* </PRE>
|
||||
*/
|
||||
public boolean exportApplet() throws Exception {
|
||||
public boolean exportApplet(Target target) throws RunnerException {
|
||||
// make sure the user didn't hide the sketch folder
|
||||
ensureExistence();
|
||||
|
||||
zipFileContents = new Hashtable();
|
||||
|
||||
// nuke the old applet folder because it can cause trouble
|
||||
File appletFolder = new File(folder, "applet");
|
||||
Base.removeDir(appletFolder);
|
||||
appletFolder.mkdirs();
|
||||
|
||||
// build the sketch
|
||||
String foundName = build(target, appletFolder.getPath(), name);
|
||||
foundName = upload(appletFolder.getPath(), name);
|
||||
// (already reported) error during export, exit this function
|
||||
if (foundName == null) return false;
|
||||
|
||||
// if name != exportSketchName, then that's weirdness
|
||||
// BUG unfortunately, that can also be a bug in the preproc :(
|
||||
if (!name.equals(foundName)) {
|
||||
Base.showWarning("Error during export",
|
||||
"Sketch name is " + name + " but the sketch\n" +
|
||||
"name in the code was " + foundName, null);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* int wide = PApplet.DEFAULT_WIDTH;
|
||||
int high = PApplet.DEFAULT_HEIGHT;
|
||||
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
PatternCompiler compiler = new Perl5Compiler();
|
||||
|
||||
// this matches against any uses of the size() function,
|
||||
// whether they contain numbers of variables or whatever.
|
||||
// this way, no warning is shown if size() isn't actually
|
||||
// used in the applet, which is the case especially for
|
||||
// beginners that are cutting/pasting from the reference.
|
||||
// modified for 83 to match size(XXX, ddd so that it'll
|
||||
// properly handle size(200, 200) and size(200, 200, P3D)
|
||||
String sizing =
|
||||
"[\\s\\;]size\\s*\\(\\s*(\\S+)\\s*,\\s*(\\d+)";
|
||||
Pattern pattern = compiler.compile(sizing);
|
||||
|
||||
// adds a space at the beginning, in case size() is the very
|
||||
// first thing in the program (very common), since the regexp
|
||||
// needs to check for things in front of it.
|
||||
PatternMatcherInput input =
|
||||
new PatternMatcherInput(" " + code[0].program);
|
||||
if (matcher.contains(input, pattern)) {
|
||||
MatchResult result = matcher.getMatch();
|
||||
try {
|
||||
wide = Integer.parseInt(result.group(1).toString());
|
||||
high = Integer.parseInt(result.group(2).toString());
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
// found a reference to size, but it didn't
|
||||
// seem to contain numbers
|
||||
final String message =
|
||||
"The size of this applet could not automatically be\n" +
|
||||
"determined from your code. You'll have to edit the\n" +
|
||||
"HTML file to set the size of the applet.";
|
||||
|
||||
Base.showWarning("Could not find applet size", message, null);
|
||||
}
|
||||
} // else no size() command found
|
||||
|
||||
// originally tried to grab this with a regexp matcher,
|
||||
// but it wouldn't span over multiple lines for the match.
|
||||
// this could prolly be forced, but since that's the case
|
||||
// better just to parse by hand.
|
||||
StringBuffer dbuffer = new StringBuffer();
|
||||
String lines[] = PApplet.split(code[0].program, '\n');
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
if (lines[i].trim().startsWith("/**")) { // this is our comment
|
||||
*/ // some smartass put the whole thing on the same line
|
||||
//if (lines[j].indexOf("*/") != -1) break;
|
||||
|
||||
// for (int j = i+1; j < lines.length; j++) {
|
||||
// if (lines[j].trim().endsWith("*/")) {
|
||||
// remove the */ from the end, and any extra *s
|
||||
// in case there's also content on this line
|
||||
// nah, don't bother.. make them use the three lines
|
||||
// break;
|
||||
// }
|
||||
|
||||
/* int offset = 0;
|
||||
while ((offset < lines[j].length()) &&
|
||||
((lines[j].charAt(offset) == '*') ||
|
||||
(lines[j].charAt(offset) == ' '))) {
|
||||
offset++;
|
||||
}
|
||||
// insert the return into the html to help w/ line breaks
|
||||
dbuffer.append(lines[j].substring(offset) + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
String description = dbuffer.toString();
|
||||
|
||||
StringBuffer sources = new StringBuffer();
|
||||
for (int i = 0; i < codeCount; i++) {
|
||||
sources.append("<a href=\"" + code[i].file.getName() + "\">" +
|
||||
code[i].name + "</a> ");
|
||||
}
|
||||
|
||||
File htmlOutputFile = new File(appletFolder, "index.html");
|
||||
FileOutputStream fos = new FileOutputStream(htmlOutputFile);
|
||||
PrintStream ps = new PrintStream(fos);
|
||||
|
||||
// @@sketch@@, @@width@@, @@height@@, @@archive@@, @@source@@
|
||||
// and now @@description@@
|
||||
|
||||
InputStream is = null;
|
||||
// if there is an applet.html file in the sketch folder, use that
|
||||
File customHtml = new File(folder, "applet.html");
|
||||
if (customHtml.exists()) {
|
||||
is = new FileInputStream(customHtml);
|
||||
}
|
||||
if (is == null) {
|
||||
is = Base.getStream("applet.html");
|
||||
}
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.indexOf("@@") != -1) {
|
||||
StringBuffer sb = new StringBuffer(line);
|
||||
int index = 0;
|
||||
while ((index = sb.indexOf("@@sketch@@")) != -1) {
|
||||
sb.replace(index, index + "@@sketch@@".length(),
|
||||
name);
|
||||
}
|
||||
while ((index = sb.indexOf("@@source@@")) != -1) {
|
||||
sb.replace(index, index + "@@source@@".length(),
|
||||
sources.toString());
|
||||
}
|
||||
while ((index = sb.indexOf("@@archive@@")) != -1) {
|
||||
sb.replace(index, index + "@@archive@@".length(),
|
||||
name + ".jar");
|
||||
}
|
||||
while ((index = sb.indexOf("@@width@@")) != -1) {
|
||||
sb.replace(index, index + "@@width@@".length(),
|
||||
String.valueOf(wide));
|
||||
}
|
||||
while ((index = sb.indexOf("@@height@@")) != -1) {
|
||||
sb.replace(index, index + "@@height@@".length(),
|
||||
String.valueOf(high));
|
||||
}
|
||||
while ((index = sb.indexOf("@@description@@")) != -1) {
|
||||
sb.replace(index, index + "@@description@@".length(),
|
||||
description);
|
||||
}
|
||||
line = sb.toString();
|
||||
}
|
||||
ps.println(line);
|
||||
}
|
||||
|
||||
reader.close();
|
||||
ps.flush();
|
||||
ps.close();
|
||||
|
||||
// copy the loading gif to the applet
|
||||
String LOADING_IMAGE = "loading.gif";
|
||||
File loadingImage = new File(folder, LOADING_IMAGE);
|
||||
if (!loadingImage.exists()) {
|
||||
loadingImage = new File("lib", LOADING_IMAGE);
|
||||
}
|
||||
Base.copyFile(loadingImage, new File(appletFolder, LOADING_IMAGE));
|
||||
*/
|
||||
// copy the source files to the target, since we like
|
||||
// to encourage people to share their code
|
||||
for (int i = 0; i < codeCount; i++) {
|
||||
try {
|
||||
Base.copyFile(code[i].file,
|
||||
new File(appletFolder, code[i].file.getName()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/* // create new .jar file
|
||||
FileOutputStream zipOutputFile =
|
||||
new FileOutputStream(new File(appletFolder, name + ".jar"));
|
||||
ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
|
||||
ZipEntry entry;
|
||||
|
||||
// add the manifest file
|
||||
addManifest(zos);
|
||||
|
||||
// add the contents of the code folder to the jar
|
||||
// unpacks all jar files
|
||||
//File codeFolder = new File(folder, "code");
|
||||
if (codeFolder.exists()) {
|
||||
String includes = Compiler.contentsToClassPath(codeFolder);
|
||||
packClassPathIntoZipFile(includes, zos);
|
||||
}
|
||||
|
||||
// add contents of 'library' folders to the jar file
|
||||
// if a file called 'export.txt' is in there, it contains
|
||||
// a list of the files that should be exported.
|
||||
// otherwise, all files are exported.
|
||||
Enumeration en = importedLibraries.elements();
|
||||
while (en.hasMoreElements()) {
|
||||
// in the list is a File object that points the
|
||||
// library sketch's "library" folder
|
||||
File libraryFolder = (File)en.nextElement();
|
||||
File exportSettings = new File(libraryFolder, "export.txt");
|
||||
String exportList[] = null;
|
||||
if (exportSettings.exists()) {
|
||||
String info[] = Base.loadStrings(exportSettings);
|
||||
for (int i = 0; i < info.length; i++) {
|
||||
if (info[i].startsWith("applet")) {
|
||||
int idx = info[i].indexOf('='); // get applet= or applet =
|
||||
String commas = info[i].substring(idx+1).trim();
|
||||
exportList = PApplet.split(commas, ", ");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
exportList = libraryFolder.list();
|
||||
}
|
||||
for (int i = 0; i < exportList.length; i++) {
|
||||
if (exportList[i].equals(".") ||
|
||||
exportList[i].equals("..")) continue;
|
||||
|
||||
exportList[i] = PApplet.trim(exportList[i]);
|
||||
if (exportList[i].equals("")) continue;
|
||||
|
||||
File exportFile = new File(libraryFolder, exportList[i]);
|
||||
if (!exportFile.exists()) {
|
||||
System.err.println("File " + exportList[i] + " does not exist");
|
||||
|
||||
} else if (exportFile.isDirectory()) {
|
||||
System.err.println("Ignoring sub-folder \"" + exportList[i] + "\"");
|
||||
|
||||
} else if (exportFile.getName().toLowerCase().endsWith(".zip") ||
|
||||
exportFile.getName().toLowerCase().endsWith(".jar")) {
|
||||
packClassPathIntoZipFile(exportFile.getAbsolutePath(), zos);
|
||||
|
||||
} else { // just copy the file over.. prolly a .dll or something
|
||||
Base.copyFile(exportFile,
|
||||
new File(appletFolder, exportFile.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
/* String bagelJar = "lib/core.jar";
|
||||
packClassPathIntoZipFile(bagelJar, zos);
|
||||
|
||||
// files to include from data directory
|
||||
// TODO this needs to be recursive
|
||||
if (dataFolder.exists()) {
|
||||
String dataFiles[] = dataFolder.list();
|
||||
for (int i = 0; i < dataFiles.length; i++) {
|
||||
// don't export hidden files
|
||||
// skipping dot prefix removes all: . .. .DS_Store
|
||||
if (dataFiles[i].charAt(0) == '.') continue;
|
||||
|
||||
entry = new ZipEntry(dataFiles[i]);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(Base.grabFile(new File(dataFolder, dataFiles[i])));
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
// add the project's .class files to the jar
|
||||
// just grabs everything from the build directory
|
||||
// since there may be some inner classes
|
||||
// (add any .class files from the applet dir, then delete them)
|
||||
// TODO this needs to be recursive (for packages)
|
||||
String classfiles[] = appletFolder.list();
|
||||
for (int i = 0; i < classfiles.length; i++) {
|
||||
if (classfiles[i].endsWith(".class")) {
|
||||
entry = new ZipEntry(classfiles[i]);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(Base.grabFile(new File(appletFolder, classfiles[i])));
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
*/
|
||||
String classfiles[] = appletFolder.list();
|
||||
// remove the .class files from the applet folder. if they're not
|
||||
// removed, the msjvm will complain about an illegal access error,
|
||||
// since the classes are outside the jar file.
|
||||
for (int i = 0; i < classfiles.length; i++) {
|
||||
if (classfiles[i].endsWith(".class")) {
|
||||
File deadguy = new File(appletFolder, classfiles[i]);
|
||||
if (!deadguy.delete()) {
|
||||
Base.showWarning("Could not delete",
|
||||
classfiles[i] + " could not \n" +
|
||||
"be deleted from the applet folder. \n" +
|
||||
"You'll need to remove it by hand.", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// close up the jar file
|
||||
/* zos.flush();
|
||||
zos.close();
|
||||
*/
|
||||
if(Preferences.getBoolean("uploader.open_folder"))
|
||||
Base.openFolder(appletFolder);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1603,7 +1969,7 @@ public class Sketch {
|
||||
}
|
||||
|
||||
|
||||
public void addManifest(ZipOutputStream zos) throws IOException {
|
||||
/* public void addManifest(ZipOutputStream zos) throws IOException {
|
||||
ZipEntry entry = new ZipEntry("META-INF/MANIFEST.MF");
|
||||
zos.putNextEntry(entry);
|
||||
|
||||
@ -1613,7 +1979,7 @@ public class Sketch {
|
||||
"Main-Class: " + name + "\n"; // TODO not package friendly
|
||||
zos.write(contents.getBytes());
|
||||
zos.closeEntry();
|
||||
|
||||
*/
|
||||
/*
|
||||
for (int i = 0; i < bagelClasses.length; i++) {
|
||||
if (!bagelClasses[i].endsWith(".class")) continue;
|
||||
@ -1623,17 +1989,17 @@ public class Sketch {
|
||||
zos.closeEntry();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Slurps up .class files from a colon (or semicolon on windows)
|
||||
* separated list of paths and adds them to a ZipOutputStream.
|
||||
*/
|
||||
public void packClassPathIntoZipFile(String path,
|
||||
/* public void packClassPathIntoZipFile(String path,
|
||||
ZipOutputStream zos)
|
||||
throws IOException {
|
||||
String pieces[] = Base.split(path, File.pathSeparatorChar);
|
||||
String pieces[] = PApplet.split(path, File.pathSeparatorChar);
|
||||
|
||||
for (int i = 0; i < pieces.length; i++) {
|
||||
if (pieces[i].length() == 0) continue;
|
||||
@ -1692,14 +2058,14 @@ public class Sketch {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Continue the process of magical exporting. This function
|
||||
* can be called recursively to walk through folders looking
|
||||
* for more goodies that will be added to the ZipOutputStream.
|
||||
*/
|
||||
static public void packClassPathIntoZipFileRecursive(File dir,
|
||||
/* static public void packClassPathIntoZipFileRecursive(File dir,
|
||||
String sofar,
|
||||
ZipOutputStream zos)
|
||||
throws IOException {
|
||||
@ -1729,7 +2095,7 @@ public class Sketch {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Make sure the sketch hasn't been moved or deleted by some
|
||||
|
@ -565,8 +565,8 @@ public class Sketchbook {
|
||||
librariesClassPath +=
|
||||
File.pathSeparatorChar + libraryClassPath;
|
||||
// need to associate each import with a library folder
|
||||
String packages[] =
|
||||
Compiler.packageListFromClassPath(libraryClassPath);
|
||||
String packages[] = new String[0];
|
||||
//Compiler.packageListFromClassPath(libraryClassPath);
|
||||
for (int k = 0; k < packages.length; k++) {
|
||||
importToLibraryTable.put(packages[k], exported);
|
||||
}
|
||||
|
79
app/Target.java
Normal file
79
app/Target.java
Normal file
@ -0,0 +1,79 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Target - represents a target platform
|
||||
Part of the Arduino project - http://arduino.berlios.de/
|
||||
|
||||
Copyright (c) 2005
|
||||
David A. Mellis
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id:$
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Represents a target platform (e.g. Wiring board, Arduino board).
|
||||
*/
|
||||
public class Target {
|
||||
String path;
|
||||
List sources = new ArrayList();
|
||||
List objects = new ArrayList();
|
||||
|
||||
/**
|
||||
* Create a Target.
|
||||
* @param path the directory containing config, source, and object files for
|
||||
* the target platform.
|
||||
*/
|
||||
public Target(String base, String target) throws IOException {
|
||||
path = base + File.separator + target;
|
||||
String[] files = (new File(path)).list();
|
||||
|
||||
if (files == null)
|
||||
throw new IOException("Target platform: \"" + target + "\" not found.\n" +
|
||||
"Make sure that \"build.target\" in the \n" +
|
||||
"preferences file points to a subdirectory of \n" +
|
||||
base);
|
||||
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].endsWith(".c") || files[i].endsWith(".cpp"))
|
||||
sources.add(files[i]);
|
||||
if (files[i].endsWith(".o"))
|
||||
objects.add(files[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public String getPath() { return path; }
|
||||
|
||||
/**
|
||||
* The source files in the library for the target platform.
|
||||
* @return A read-only collection of strings containing the name of each source file.
|
||||
*/
|
||||
public Collection getSourceFilenames() {
|
||||
return Collections.unmodifiableList(sources);
|
||||
}
|
||||
|
||||
/**
|
||||
* The object files in the library for the target platform.
|
||||
* @return A read-only collection of strings containing the name of each object file.
|
||||
*/
|
||||
public Collection getObjectFilenames() {
|
||||
return Collections.unmodifiableList(objects);
|
||||
}
|
||||
}
|
230
app/Uploader.java
Executable file
230
app/Uploader.java
Executable file
@ -0,0 +1,230 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Uploader - default downloader class that connects to uisp
|
||||
Part of the Arduino project - http://arduino.berlios.de/
|
||||
|
||||
Copyright (c) 2004-05
|
||||
Hernando Barragan
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
$Id:$
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import javax.swing.*;
|
||||
//#ifndef RXTX
|
||||
//import javax.comm.*;
|
||||
//#else
|
||||
// rxtx uses package gnu.io, but all the class names
|
||||
// are the same as those used by javax.comm
|
||||
import gnu.io.*;
|
||||
//#endif
|
||||
|
||||
|
||||
public class Uploader implements MessageConsumer {
|
||||
static final String BUGS_URL =
|
||||
"https://developer.berlios.de/bugs/?group_id=3590";
|
||||
static final String SUPER_BADNESS =
|
||||
"Compiler error, please submit this code to " + BUGS_URL;
|
||||
|
||||
String buildPath;
|
||||
String className;
|
||||
File includeFolder;
|
||||
RunnerException exception;
|
||||
Sketch sketch;
|
||||
//PdePreferences preferences;
|
||||
|
||||
//Serial serialPort;
|
||||
static InputStream serialInput;
|
||||
static OutputStream serialOutput;
|
||||
//int serial; // last byte of data received
|
||||
|
||||
private String serial_port = "COM1";
|
||||
private int serial_rate = 9600;
|
||||
private char serial_parity = 'N';
|
||||
private int serial_databits = 8;
|
||||
private float serial_stopbits = 1;
|
||||
|
||||
public void serialPreferences() {
|
||||
//System.out.println("setting serial properties");
|
||||
serial_port = Preferences.get("serial.port");
|
||||
serial_rate = Preferences.getInteger("serial.download_rate");
|
||||
serial_parity = Preferences.get("serial.parity").charAt(0);
|
||||
serial_databits = Preferences.getInteger("serial.databits");
|
||||
serial_stopbits = new Float(Preferences.get("serial.stopbits")).floatValue();
|
||||
}
|
||||
|
||||
public Uploader(String buildPath, String className,
|
||||
Sketch sketch) {
|
||||
this.buildPath = buildPath;
|
||||
this.includeFolder = includeFolder;
|
||||
this.className = className;
|
||||
this.sketch = sketch;
|
||||
}
|
||||
|
||||
public boolean downloadJava(PrintStream leechErr) throws RunnerException {
|
||||
String userdir = System.getProperty("user.dir") + File.separator;
|
||||
// String commandDownloader[] = new String[] {
|
||||
// ((!Base.isMacOS()) ? "tools/avr/bin/uisp" :
|
||||
// userdir + "tools/avr/bin/uisp"),
|
||||
// //[2] Serial port
|
||||
// //[3] Serial download rate
|
||||
// //[6] hex class file
|
||||
// "-dprog=stk500",
|
||||
// " ",
|
||||
// " ",
|
||||
// "-dpart=" + Preferences.get("build.mcu"),
|
||||
// "--upload",
|
||||
// " "
|
||||
// };
|
||||
|
||||
firstErrorFound = false; // haven't found any errors yet
|
||||
secondErrorFound = false;
|
||||
notFoundError = false;
|
||||
int result=0; // pre-initialized to quiet a bogus warning from jikes
|
||||
try {
|
||||
serialPreferences();
|
||||
List commandDownloader = new ArrayList();
|
||||
commandDownloader.add((!Base.isMacOS() ? "" : userdir) + "tools/avr/bin/uisp");
|
||||
commandDownloader.add("-dprog=" + Preferences.get("upload.programmer"));
|
||||
commandDownloader.add("-dpart=" + Preferences.get("build.mcu"));
|
||||
if (Preferences.get("upload.programmer").equals("dapa"))
|
||||
commandDownloader.add("-dlpt=" + Preferences.get("parallel.port"));
|
||||
else {
|
||||
commandDownloader.add("-dserial=" + (!Base.isMacOS() ? "/dev/" + serial_port.toLowerCase() : serial_port));
|
||||
commandDownloader.add("-dspeed=" + serial_rate);
|
||||
}
|
||||
if (Preferences.getBoolean("upload.erase"))
|
||||
commandDownloader.add("--erase");
|
||||
commandDownloader.add("--upload");
|
||||
if (Preferences.getBoolean("upload.verify"))
|
||||
commandDownloader.add("--verify");
|
||||
commandDownloader.add("if=" + buildPath + File.separator + className + ".hex");
|
||||
|
||||
// commandDownloader[2] = ((!Base.isMacOS()) ? "-dserial=/dev/" + serial_port.toLowerCase() : "-dserial=" + serial_port );
|
||||
// commandDownloader[3] = "-dspeed=" + serial_rate;
|
||||
// commandDownloader[6] = "if=" + buildPath + File.separator + className + ".hex";
|
||||
/*for(int i = 0; i < commandDownloader.length; i++) {
|
||||
System.out.println(commandDownloader[i]);
|
||||
}*/
|
||||
|
||||
// Cleanup the serial buffer
|
||||
/*serialPort = new Serial();
|
||||
byte[] readBuffer;
|
||||
while(serialPort.available() > 0) {
|
||||
readBuffer = serialPort.readBytes();
|
||||
Thread.sleep(100);
|
||||
}
|
||||
serialPort.dispose(); */
|
||||
|
||||
String[] commandArray = new String[commandDownloader.size()];
|
||||
Process process = Runtime.getRuntime().exec((String[]) commandDownloader.toArray(commandArray));
|
||||
new MessageSiphon(process.getInputStream(), this);
|
||||
new MessageSiphon(process.getErrorStream(), this);
|
||||
|
||||
// wait for the process to finish. if interrupted
|
||||
// before waitFor returns, continue waiting
|
||||
//
|
||||
boolean compiling = true;
|
||||
while (compiling) {
|
||||
try {
|
||||
result = process.waitFor();
|
||||
compiling = false;
|
||||
} catch (InterruptedException intExc) {
|
||||
}
|
||||
}
|
||||
if(exception!=null) {
|
||||
exception.hideStackTrace = true;
|
||||
throw exception;
|
||||
}
|
||||
if(result!=0)
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
String msg = e.getMessage();
|
||||
if ((msg != null) && (msg.indexOf("uisp: not found") != -1)) {
|
||||
//System.err.println("uisp is missing");
|
||||
//JOptionPane.showMessageDialog(editor.base,
|
||||
// "Could not find the compiler.\n" +
|
||||
// "uisp is missing from your PATH,\n" +
|
||||
// "see readme.txt for help.",
|
||||
// "Compiler error",
|
||||
// JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
//System.out.println("result2 is "+result);
|
||||
// if the result isn't a known, expected value it means that something
|
||||
// is fairly wrong, one possibility is that jikes has crashed.
|
||||
//
|
||||
if (exception != null) throw exception;
|
||||
|
||||
if ((result != 0) && (result != 1 )) {
|
||||
exception = new RunnerException(SUPER_BADNESS);
|
||||
//editor.error(exception);
|
||||
//PdeBase.openURL(BUGS_URL);
|
||||
//throw new PdeException(SUPER_BADNESS);
|
||||
}
|
||||
|
||||
return (result == 0); // ? true : false;
|
||||
|
||||
}
|
||||
|
||||
boolean firstErrorFound;
|
||||
boolean secondErrorFound;
|
||||
|
||||
// part of the PdeMessageConsumer interface
|
||||
//
|
||||
boolean notFoundError;
|
||||
|
||||
public void message(String s) {
|
||||
//System.err.println("MSG: " + s);
|
||||
System.err.print(s);
|
||||
|
||||
// ignore cautions
|
||||
if (s.indexOf("Error") != -1) {
|
||||
//exception = new RunnerException(s+" Check the serial port selected or your Board is connected");
|
||||
//System.out.println(s);
|
||||
notFoundError = true;
|
||||
return;
|
||||
}
|
||||
if(notFoundError) {
|
||||
//System.out.println("throwing something");
|
||||
exception = new RunnerException("the selected serial port "+s+" does not exist or your board is not connected");
|
||||
return;
|
||||
}
|
||||
// jikes always uses a forward slash character as its separator, so
|
||||
// we need to replace any platform-specific separator characters before
|
||||
// attemping to compare
|
||||
//
|
||||
if (s.indexOf("Device is not responding") != -1 ) {
|
||||
exception = new RunnerException("Device is not responding, check the right serial port is selected or RESET the board right before exporting");
|
||||
return;
|
||||
}
|
||||
if (s.indexOf("Programmer is not responding") != -1) {
|
||||
exception = new RunnerException("Programmer is not responding, RESET the board right before exporting");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
*Lexer.java
|
||||
*Recognizer.java
|
||||
*TokenTypes.java
|
||||
*TokenTypes.txt
|
||||
*TreeParser.java
|
||||
*TreeParserTokenTypes.java
|
||||
*TreeParserTokenTypes.txt
|
||||
expanded*.g
|
||||
|
133
app/preproc/CSymbolTable.java
Executable file
133
app/preproc/CSymbolTable.java
Executable file
@ -0,0 +1,133 @@
|
||||
package processing.app.preproc;
|
||||
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
|
||||
|
||||
|
||||
public class CSymbolTable {
|
||||
|
||||
/** holds list of scopes */
|
||||
private Vector scopeStack;
|
||||
|
||||
/** table where all defined names are mapped to TNode tree nodes */
|
||||
private Hashtable symTable;
|
||||
|
||||
public CSymbolTable() {
|
||||
scopeStack = new Vector(10);
|
||||
symTable = new Hashtable(533);
|
||||
}
|
||||
|
||||
|
||||
/** push a new scope onto the scope stack.
|
||||
*/
|
||||
public void pushScope(String s) {
|
||||
//System.out.println("push scope:" + s);
|
||||
scopeStack.addElement(s);
|
||||
}
|
||||
|
||||
/** pop the last scope off the scope stack.
|
||||
*/
|
||||
public void popScope() {
|
||||
//System.out.println("pop scope");
|
||||
int size = scopeStack.size();
|
||||
if(size > 0)
|
||||
scopeStack.removeElementAt(size - 1);
|
||||
}
|
||||
|
||||
/** return the current scope as a string
|
||||
*/
|
||||
public String currentScopeAsString() {
|
||||
StringBuffer buf = new StringBuffer(100);
|
||||
boolean first = true;
|
||||
Enumeration e = scopeStack.elements();
|
||||
while(e.hasMoreElements()) {
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
buf.append("::");
|
||||
buf.append(e.nextElement().toString());
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/** given a name for a type, append it with the
|
||||
current scope.
|
||||
*/
|
||||
public String addCurrentScopeToName(String name) {
|
||||
String currScope = currentScopeAsString();
|
||||
return addScopeToName(currScope, name);
|
||||
}
|
||||
|
||||
/** given a name for a type, append it with the
|
||||
given scope. MBZ
|
||||
*/
|
||||
public String addScopeToName(String scope, String name) {
|
||||
if(scope == null || scope.length() > 0)
|
||||
return scope + "::" + name;
|
||||
else
|
||||
return name;
|
||||
}
|
||||
|
||||
/** remove one level of scope from name MBZ*/
|
||||
public String removeOneLevelScope(String scopeName) {
|
||||
int index = scopeName.lastIndexOf("::");
|
||||
if (index > 0) {
|
||||
return scopeName.substring(0,index);
|
||||
}
|
||||
if (scopeName.length() > 0) {
|
||||
return "";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** add a node to the table with it's key as
|
||||
the current scope and the name */
|
||||
public TNode add(String name, TNode node) {
|
||||
return (TNode)symTable.put(addCurrentScopeToName(name),node);
|
||||
}
|
||||
|
||||
|
||||
/** lookup a fully scoped name in the symbol table */
|
||||
public TNode lookupScopedName(String scopedName) {
|
||||
return (TNode)symTable.get(scopedName);
|
||||
}
|
||||
|
||||
/** lookup an unscoped name in the table by prepending
|
||||
the current scope.
|
||||
MBZ -- if not found, pop scopes and look again
|
||||
*/
|
||||
public TNode lookupNameInCurrentScope(String name) {
|
||||
String scope = currentScopeAsString();
|
||||
String scopedName;
|
||||
TNode tnode = null;
|
||||
|
||||
//System.out.println( "\n"+ this.toString() );
|
||||
|
||||
while (tnode == null && scope != null) {
|
||||
scopedName = addScopeToName(scope, name);
|
||||
//System.out.println("lookup trying " + scopedName);
|
||||
tnode = (TNode)symTable.get(scopedName);
|
||||
scope = removeOneLevelScope(scope);
|
||||
}
|
||||
return tnode;
|
||||
}
|
||||
|
||||
/** convert this table to a string */
|
||||
public String toString() {
|
||||
StringBuffer buff = new StringBuffer(300);
|
||||
buff.append("CSymbolTable { \nCurrentScope: " + currentScopeAsString() +
|
||||
"\nDefinedSymbols:\n");
|
||||
Enumeration ke = symTable.keys();
|
||||
Enumeration ve = symTable.elements();
|
||||
while(ke.hasMoreElements()) {
|
||||
buff.append(ke.nextElement().toString() + " (" +
|
||||
TNode.getNameForType(((TNode)ve.nextElement()).getType()) + ")\n");
|
||||
}
|
||||
buff.append("}\n");
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
};
|
32
app/preproc/CToken.java
Executable file
32
app/preproc/CToken.java
Executable file
@ -0,0 +1,32 @@
|
||||
package processing.app.preproc;
|
||||
|
||||
import antlr.CommonToken;
|
||||
|
||||
public class CToken extends antlr.CommonToken {
|
||||
String source = "";
|
||||
int tokenNumber;
|
||||
|
||||
public String getSource()
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(String src)
|
||||
{
|
||||
source = src;
|
||||
}
|
||||
|
||||
public int getTokenNumber()
|
||||
{
|
||||
return tokenNumber;
|
||||
}
|
||||
|
||||
public void setTokenNumber(int i)
|
||||
{
|
||||
tokenNumber = i;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "CToken:" +"(" + hashCode() + ")" + "[" + getType() + "] "+ getText() + " line:" + getLine() + " source:" + source ;
|
||||
}
|
||||
}
|
15
app/preproc/CVS/Entries
Normal file
15
app/preproc/CVS/Entries
Normal file
@ -0,0 +1,15 @@
|
||||
/CSymbolTable.java/1.1.1.1/Thu Sep 22 15:32:54 2005//
|
||||
/CToken.java/1.1.1.1/Thu Sep 22 15:32:54 2005//
|
||||
/ExtendedCommonASTWithHiddenTokens.java/1.1.1.1/Thu Sep 22 15:32:55 2005//
|
||||
/LineObject.java/1.1.1.1/Thu Sep 22 15:32:55 2005//
|
||||
/Makefile/1.1.1.1/Thu Sep 22 15:32:55 2005//
|
||||
/PreprocessorInfoChannel.java/1.1.1.1/Thu Sep 22 15:32:55 2005//
|
||||
/StdCParser.g/1.1.1.1/Thu Sep 22 15:32:56 2005//
|
||||
/TNode.java/1.1.1.1/Thu Sep 22 15:32:56 2005//
|
||||
/TNodeFactory.java/1.1.1.1/Thu Sep 22 15:32:56 2005//
|
||||
/WEmitter.g/1.4/Thu Sep 22 15:32:56 2005//
|
||||
/WParser.g/1.4/Thu Sep 22 15:32:57 2005//
|
||||
/WTreeParser.g/1.2/Thu Sep 22 15:32:57 2005//
|
||||
/whitespace_test.pde/1.1.1.1/Thu Sep 22 15:32:56 2005//
|
||||
/PdePreprocessor.java/1.13/Sat Sep 24 11:26:19 2005//
|
||||
D
|
1
app/preproc/CVS/Repository
Normal file
1
app/preproc/CVS/Repository
Normal file
@ -0,0 +1 @@
|
||||
wiring/app/preproc
|
1
app/preproc/CVS/Root
Normal file
1
app/preproc/CVS/Root
Normal file
@ -0,0 +1 @@
|
||||
:ext:dmellis@wcvs.uniandes.edu.co:/home/cvs/cvsrep
|
2
app/preproc/ExtendedCommonASTWithHiddenTokens.java
Normal file → Executable file
2
app/preproc/ExtendedCommonASTWithHiddenTokens.java
Normal file → Executable file
@ -4,7 +4,7 @@ package antlr;
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/RIGHTS.html
|
||||
*
|
||||
* $Id: ExtendedCommonASTWithHiddenTokens.java,v 1.1 2005/04/09 02:30:36 benfry Exp $
|
||||
* $Id: ExtendedCommonASTWithHiddenTokens.java,v 1.1.1.1 2005/06/22 22:18:14 h Exp $
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,157 +0,0 @@
|
||||
// $ANTLR 2.7.2: "java.g" -> "JavaLexer.java"$
|
||||
|
||||
package antlr.java;
|
||||
|
||||
public interface JavaTokenTypes {
|
||||
int EOF = 1;
|
||||
int NULL_TREE_LOOKAHEAD = 3;
|
||||
int BLOCK = 4;
|
||||
int MODIFIERS = 5;
|
||||
int OBJBLOCK = 6;
|
||||
int SLIST = 7;
|
||||
int CTOR_DEF = 8;
|
||||
int METHOD_DEF = 9;
|
||||
int VARIABLE_DEF = 10;
|
||||
int INSTANCE_INIT = 11;
|
||||
int STATIC_INIT = 12;
|
||||
int TYPE = 13;
|
||||
int CLASS_DEF = 14;
|
||||
int INTERFACE_DEF = 15;
|
||||
int PACKAGE_DEF = 16;
|
||||
int ARRAY_DECLARATOR = 17;
|
||||
int EXTENDS_CLAUSE = 18;
|
||||
int IMPLEMENTS_CLAUSE = 19;
|
||||
int PARAMETERS = 20;
|
||||
int PARAMETER_DEF = 21;
|
||||
int LABELED_STAT = 22;
|
||||
int TYPECAST = 23;
|
||||
int INDEX_OP = 24;
|
||||
int POST_INC = 25;
|
||||
int POST_DEC = 26;
|
||||
int METHOD_CALL = 27;
|
||||
int EXPR = 28;
|
||||
int ARRAY_INIT = 29;
|
||||
int IMPORT = 30;
|
||||
int UNARY_MINUS = 31;
|
||||
int UNARY_PLUS = 32;
|
||||
int CASE_GROUP = 33;
|
||||
int ELIST = 34;
|
||||
int FOR_INIT = 35;
|
||||
int FOR_CONDITION = 36;
|
||||
int FOR_ITERATOR = 37;
|
||||
int EMPTY_STAT = 38;
|
||||
int FINAL = 39;
|
||||
int ABSTRACT = 40;
|
||||
int STRICTFP = 41;
|
||||
int SUPER_CTOR_CALL = 42;
|
||||
int CTOR_CALL = 43;
|
||||
int LITERAL_package = 44;
|
||||
int SEMI = 45;
|
||||
int LITERAL_import = 46;
|
||||
int LBRACK = 47;
|
||||
int RBRACK = 48;
|
||||
int LITERAL_void = 49;
|
||||
int LITERAL_boolean = 50;
|
||||
int LITERAL_byte = 51;
|
||||
int LITERAL_char = 52;
|
||||
int LITERAL_short = 53;
|
||||
int LITERAL_int = 54;
|
||||
int LITERAL_float = 55;
|
||||
int LITERAL_long = 56;
|
||||
int LITERAL_double = 57;
|
||||
int IDENT = 58;
|
||||
int DOT = 59;
|
||||
int STAR = 60;
|
||||
int LITERAL_private = 61;
|
||||
int LITERAL_public = 62;
|
||||
int LITERAL_protected = 63;
|
||||
int LITERAL_static = 64;
|
||||
int LITERAL_transient = 65;
|
||||
int LITERAL_native = 66;
|
||||
int LITERAL_threadsafe = 67;
|
||||
int LITERAL_synchronized = 68;
|
||||
int LITERAL_volatile = 69;
|
||||
int LITERAL_class = 70;
|
||||
int LITERAL_extends = 71;
|
||||
int LITERAL_interface = 72;
|
||||
int LCURLY = 73;
|
||||
int RCURLY = 74;
|
||||
int COMMA = 75;
|
||||
int LITERAL_implements = 76;
|
||||
int LPAREN = 77;
|
||||
int RPAREN = 78;
|
||||
int LITERAL_this = 79;
|
||||
int LITERAL_super = 80;
|
||||
int ASSIGN = 81;
|
||||
int LITERAL_throws = 82;
|
||||
int COLON = 83;
|
||||
int LITERAL_if = 84;
|
||||
int LITERAL_else = 85;
|
||||
int LITERAL_for = 86;
|
||||
int LITERAL_while = 87;
|
||||
int LITERAL_do = 88;
|
||||
int LITERAL_break = 89;
|
||||
int LITERAL_continue = 90;
|
||||
int LITERAL_return = 91;
|
||||
int LITERAL_switch = 92;
|
||||
int LITERAL_throw = 93;
|
||||
int LITERAL_assert = 94;
|
||||
int LITERAL_case = 95;
|
||||
int LITERAL_default = 96;
|
||||
int LITERAL_try = 97;
|
||||
int LITERAL_finally = 98;
|
||||
int LITERAL_catch = 99;
|
||||
int PLUS_ASSIGN = 100;
|
||||
int MINUS_ASSIGN = 101;
|
||||
int STAR_ASSIGN = 102;
|
||||
int DIV_ASSIGN = 103;
|
||||
int MOD_ASSIGN = 104;
|
||||
int SR_ASSIGN = 105;
|
||||
int BSR_ASSIGN = 106;
|
||||
int SL_ASSIGN = 107;
|
||||
int BAND_ASSIGN = 108;
|
||||
int BXOR_ASSIGN = 109;
|
||||
int BOR_ASSIGN = 110;
|
||||
int QUESTION = 111;
|
||||
int LOR = 112;
|
||||
int LAND = 113;
|
||||
int BOR = 114;
|
||||
int BXOR = 115;
|
||||
int BAND = 116;
|
||||
int NOT_EQUAL = 117;
|
||||
int EQUAL = 118;
|
||||
int LT = 119;
|
||||
int GT = 120;
|
||||
int LE = 121;
|
||||
int GE = 122;
|
||||
int LITERAL_instanceof = 123;
|
||||
int SL = 124;
|
||||
int SR = 125;
|
||||
int BSR = 126;
|
||||
int PLUS = 127;
|
||||
int MINUS = 128;
|
||||
int DIV = 129;
|
||||
int MOD = 130;
|
||||
int INC = 131;
|
||||
int DEC = 132;
|
||||
int BNOT = 133;
|
||||
int LNOT = 134;
|
||||
int LITERAL_true = 135;
|
||||
int LITERAL_false = 136;
|
||||
int LITERAL_null = 137;
|
||||
int LITERAL_new = 138;
|
||||
int NUM_INT = 139;
|
||||
int CHAR_LITERAL = 140;
|
||||
int STRING_LITERAL = 141;
|
||||
int NUM_FLOAT = 142;
|
||||
int NUM_LONG = 143;
|
||||
int NUM_DOUBLE = 144;
|
||||
int WS = 145;
|
||||
int SL_COMMENT = 146;
|
||||
int ML_COMMENT = 147;
|
||||
int ESC = 148;
|
||||
int HEX_DIGIT = 149;
|
||||
int VOCAB = 150;
|
||||
int EXPONENT = 151;
|
||||
int FLOAT_SUFFIX = 152;
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
// $ANTLR 2.7.2: java.g -> JavaTokenTypes.txt$
|
||||
Java // output token vocab name
|
||||
BLOCK=4
|
||||
MODIFIERS=5
|
||||
OBJBLOCK=6
|
||||
SLIST=7
|
||||
CTOR_DEF=8
|
||||
METHOD_DEF=9
|
||||
VARIABLE_DEF=10
|
||||
INSTANCE_INIT=11
|
||||
STATIC_INIT=12
|
||||
TYPE=13
|
||||
CLASS_DEF=14
|
||||
INTERFACE_DEF=15
|
||||
PACKAGE_DEF=16
|
||||
ARRAY_DECLARATOR=17
|
||||
EXTENDS_CLAUSE=18
|
||||
IMPLEMENTS_CLAUSE=19
|
||||
PARAMETERS=20
|
||||
PARAMETER_DEF=21
|
||||
LABELED_STAT=22
|
||||
TYPECAST=23
|
||||
INDEX_OP=24
|
||||
POST_INC=25
|
||||
POST_DEC=26
|
||||
METHOD_CALL=27
|
||||
EXPR=28
|
||||
ARRAY_INIT=29
|
||||
IMPORT=30
|
||||
UNARY_MINUS=31
|
||||
UNARY_PLUS=32
|
||||
CASE_GROUP=33
|
||||
ELIST=34
|
||||
FOR_INIT=35
|
||||
FOR_CONDITION=36
|
||||
FOR_ITERATOR=37
|
||||
EMPTY_STAT=38
|
||||
FINAL="final"=39
|
||||
ABSTRACT="abstract"=40
|
||||
STRICTFP="strictfp"=41
|
||||
SUPER_CTOR_CALL=42
|
||||
CTOR_CALL=43
|
||||
LITERAL_package="package"=44
|
||||
SEMI=45
|
||||
LITERAL_import="import"=46
|
||||
LBRACK=47
|
||||
RBRACK=48
|
||||
LITERAL_void="void"=49
|
||||
LITERAL_boolean="boolean"=50
|
||||
LITERAL_byte="byte"=51
|
||||
LITERAL_char="char"=52
|
||||
LITERAL_short="short"=53
|
||||
LITERAL_int="int"=54
|
||||
LITERAL_float="float"=55
|
||||
LITERAL_long="long"=56
|
||||
LITERAL_double="double"=57
|
||||
IDENT=58
|
||||
DOT=59
|
||||
STAR=60
|
||||
LITERAL_private="private"=61
|
||||
LITERAL_public="public"=62
|
||||
LITERAL_protected="protected"=63
|
||||
LITERAL_static="static"=64
|
||||
LITERAL_transient="transient"=65
|
||||
LITERAL_native="native"=66
|
||||
LITERAL_threadsafe="threadsafe"=67
|
||||
LITERAL_synchronized="synchronized"=68
|
||||
LITERAL_volatile="volatile"=69
|
||||
LITERAL_class="class"=70
|
||||
LITERAL_extends="extends"=71
|
||||
LITERAL_interface="interface"=72
|
||||
LCURLY=73
|
||||
RCURLY=74
|
||||
COMMA=75
|
||||
LITERAL_implements="implements"=76
|
||||
LPAREN=77
|
||||
RPAREN=78
|
||||
LITERAL_this="this"=79
|
||||
LITERAL_super="super"=80
|
||||
ASSIGN=81
|
||||
LITERAL_throws="throws"=82
|
||||
COLON=83
|
||||
LITERAL_if="if"=84
|
||||
LITERAL_else="else"=85
|
||||
LITERAL_for="for"=86
|
||||
LITERAL_while="while"=87
|
||||
LITERAL_do="do"=88
|
||||
LITERAL_break="break"=89
|
||||
LITERAL_continue="continue"=90
|
||||
LITERAL_return="return"=91
|
||||
LITERAL_switch="switch"=92
|
||||
LITERAL_throw="throw"=93
|
||||
LITERAL_assert="assert"=94
|
||||
LITERAL_case="case"=95
|
||||
LITERAL_default="default"=96
|
||||
LITERAL_try="try"=97
|
||||
LITERAL_finally="finally"=98
|
||||
LITERAL_catch="catch"=99
|
||||
PLUS_ASSIGN=100
|
||||
MINUS_ASSIGN=101
|
||||
STAR_ASSIGN=102
|
||||
DIV_ASSIGN=103
|
||||
MOD_ASSIGN=104
|
||||
SR_ASSIGN=105
|
||||
BSR_ASSIGN=106
|
||||
SL_ASSIGN=107
|
||||
BAND_ASSIGN=108
|
||||
BXOR_ASSIGN=109
|
||||
BOR_ASSIGN=110
|
||||
QUESTION=111
|
||||
LOR=112
|
||||
LAND=113
|
||||
BOR=114
|
||||
BXOR=115
|
||||
BAND=116
|
||||
NOT_EQUAL=117
|
||||
EQUAL=118
|
||||
LT=119
|
||||
GT=120
|
||||
LE=121
|
||||
GE=122
|
||||
LITERAL_instanceof="instanceof"=123
|
||||
SL=124
|
||||
SR=125
|
||||
BSR=126
|
||||
PLUS=127
|
||||
MINUS=128
|
||||
DIV=129
|
||||
MOD=130
|
||||
INC=131
|
||||
DEC=132
|
||||
BNOT=133
|
||||
LNOT=134
|
||||
LITERAL_true="true"=135
|
||||
LITERAL_false="false"=136
|
||||
LITERAL_null="null"=137
|
||||
LITERAL_new="new"=138
|
||||
NUM_INT=139
|
||||
CHAR_LITERAL=140
|
||||
STRING_LITERAL=141
|
||||
NUM_FLOAT=142
|
||||
NUM_LONG=143
|
||||
NUM_DOUBLE=144
|
||||
WS=145
|
||||
SL_COMMENT=146
|
||||
ML_COMMENT=147
|
||||
ESC=148
|
||||
HEX_DIGIT=149
|
||||
VOCAB=150
|
||||
EXPONENT=151
|
||||
FLOAT_SUFFIX=152
|
126
app/preproc/LineObject.java
Executable file
126
app/preproc/LineObject.java
Executable file
@ -0,0 +1,126 @@
|
||||
package processing.app.preproc;
|
||||
|
||||
class LineObject {
|
||||
LineObject parent = null;
|
||||
String source = "";
|
||||
int line = 1;
|
||||
boolean enteringFile = false;
|
||||
boolean returningToFile = false;
|
||||
boolean systemHeader = false;
|
||||
boolean treatAsC = false;
|
||||
|
||||
public LineObject()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public LineObject( LineObject lobj )
|
||||
{
|
||||
parent = lobj.getParent();
|
||||
source = lobj.getSource();
|
||||
line = lobj.getLine();
|
||||
enteringFile = lobj.getEnteringFile();
|
||||
returningToFile = lobj.getReturningToFile();
|
||||
systemHeader = lobj.getSystemHeader();
|
||||
treatAsC = lobj.getTreatAsC();
|
||||
}
|
||||
|
||||
public LineObject( String src)
|
||||
{
|
||||
source = src;
|
||||
}
|
||||
|
||||
public void setSource(String src)
|
||||
{
|
||||
source = src;
|
||||
}
|
||||
|
||||
public String getSource()
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setParent(LineObject par)
|
||||
{
|
||||
parent = par;
|
||||
}
|
||||
|
||||
public LineObject getParent()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setLine(int l)
|
||||
{
|
||||
line = l;
|
||||
}
|
||||
|
||||
public int getLine()
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
||||
public void newline()
|
||||
{
|
||||
line++;
|
||||
}
|
||||
|
||||
public void setEnteringFile(boolean v)
|
||||
{
|
||||
enteringFile = v;
|
||||
}
|
||||
|
||||
public boolean getEnteringFile()
|
||||
{
|
||||
return enteringFile;
|
||||
}
|
||||
|
||||
public void setReturningToFile(boolean v)
|
||||
{
|
||||
returningToFile = v;
|
||||
}
|
||||
|
||||
public boolean getReturningToFile()
|
||||
{
|
||||
return returningToFile;
|
||||
}
|
||||
|
||||
public void setSystemHeader(boolean v)
|
||||
{
|
||||
systemHeader = v;
|
||||
}
|
||||
|
||||
public boolean getSystemHeader()
|
||||
{
|
||||
return systemHeader;
|
||||
}
|
||||
|
||||
public void setTreatAsC(boolean v)
|
||||
{
|
||||
treatAsC = v;
|
||||
}
|
||||
|
||||
public boolean getTreatAsC()
|
||||
{
|
||||
return treatAsC;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer ret;
|
||||
ret = new StringBuffer("# " + line + " \"" + source + "\"");
|
||||
if (enteringFile) {
|
||||
ret.append(" 1");
|
||||
}
|
||||
if (returningToFile) {
|
||||
ret.append(" 2");
|
||||
}
|
||||
if (systemHeader) {
|
||||
ret.append(" 3");
|
||||
}
|
||||
if (treatAsC) {
|
||||
ret.append(" 4");
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
}
|
||||
|
36
app/preproc/Makefile
Executable file
36
app/preproc/Makefile
Executable file
@ -0,0 +1,36 @@
|
||||
classfiles = LineObject.class PreprocessorInfoChannel.class StdCParser.class StdCLexer.class WParser.class WLexer.class WTreeParser.class WEmitter.class
|
||||
javafiles = CSymbolTable.java TNode.java TNodeFactory.java CToken.java LineObject.java PreprocessorInfoChannel.java StdCParser.java StdCLexer.java WParser.java WLexer.java WTreeParser.java WEmitter.java
|
||||
|
||||
|
||||
all : $(javafiles) $(classfiles)
|
||||
|
||||
|
||||
|
||||
clean :
|
||||
|
||||
|
||||
|
||||
StdCParser.java StdCLexer.java : StdCParser.g
|
||||
java -cp "..\\..\\build\\windows\\work\\lib\\antlr.jar" antlr.Tool StdCParser.g
|
||||
|
||||
|
||||
WParser.java WLexer.java : WParser.g WParser.g
|
||||
java -cp "..\\..\\build\\windows\\work\\lib\\antlr.jar" antlr.Tool -glib "StdCParser.g" WParser.g
|
||||
|
||||
|
||||
WTreeParser.java : WTreeParser.g
|
||||
java -cp "..\\..\\build\\windows\\work\\lib\\antlr.jar" antlr.Tool WTreeParser.g
|
||||
|
||||
|
||||
WEmitter.java : WEmitter.g WTreeParser.g
|
||||
java -cp "..\\..\\build\\windows\\work\\lib\\antlr.jar" antlr.Tool -glib "WTreeParser.g" WEmitter.g
|
||||
|
||||
|
||||
|
||||
.SUFFIXES: .java .class
|
||||
|
||||
.java.class :
|
||||
../../build/windows/work/jikes -cp "..\\..\\build\\windows\\work\\java\\lib\\rt.jar;..\\..\\build\\windows\\work\\lib\\mrj.jar;..\\..\\build\\windows\\work\\lib\\antlr.jar;." $<
|
||||
|
||||
|
||||
|
@ -1,922 +0,0 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
package processing.app.preproc;
|
||||
|
||||
import processing.app.*;
|
||||
|
||||
|
||||
/* Based on original code copyright (c) 2003 Andy Tripp <atripp@comcast.net>.
|
||||
* shipped under GPL with permission.
|
||||
*/
|
||||
|
||||
import antlr.*;
|
||||
import antlr.collections.*;
|
||||
import antlr.collections.impl.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* PDEEmitter: A class that can take an ANTLR Java AST and produce
|
||||
* reasonably formatted Java code from it. To use it, create a
|
||||
* PDEEmitter object, call setOut() if you want to print to something
|
||||
* other than System.out, and then call print(), passing the
|
||||
* AST. Typically, the AST node that you pass would be the root of a
|
||||
* tree - the ROOT_ID node that represents a Java file.
|
||||
*/
|
||||
|
||||
public class PdeEmitter implements PdeTokenTypes
|
||||
{
|
||||
private PrintStream out = System.out;
|
||||
private PrintStream debug = System.err;
|
||||
private static int ALL = -1;
|
||||
private java.util.Stack stack = new java.util.Stack();
|
||||
private static String[] tokenNames;
|
||||
private final static int ROOT_ID = 0;
|
||||
static {
|
||||
setupTokenNames();
|
||||
}
|
||||
|
||||
/*
|
||||
private static Hashtable publicMethods;
|
||||
private static final String publicMethodList[] = {
|
||||
"setup", "draw", //"loop",
|
||||
"mousePressed", "mouseReleased", "mouseClicked",
|
||||
"mouseEntered", "mouseExited",
|
||||
"mouseMoved", "mouseDragged",
|
||||
"keyPressed", "keyReleased", "keyTyped"
|
||||
};
|
||||
|
||||
static {
|
||||
publicMethods = new Hashtable();
|
||||
for (int i = 0; i < publicMethodList.length; i++) {
|
||||
publicMethods.put(publicMethodList[i], new Object());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Map each AST token type to a String
|
||||
private static void setupTokenNames() {
|
||||
tokenNames = new String[200];
|
||||
for (int i=0; i<tokenNames.length; i++) {
|
||||
tokenNames[i] = "ERROR:" + i;
|
||||
}
|
||||
|
||||
tokenNames[POST_INC]="++";
|
||||
tokenNames[POST_DEC]="--";
|
||||
tokenNames[UNARY_MINUS]="-";
|
||||
tokenNames[UNARY_PLUS]="+";
|
||||
tokenNames[STAR]="*";
|
||||
tokenNames[ASSIGN]="=";
|
||||
tokenNames[PLUS_ASSIGN]="+=";
|
||||
tokenNames[MINUS_ASSIGN]="-=";
|
||||
tokenNames[STAR_ASSIGN]="*=";
|
||||
tokenNames[DIV_ASSIGN]="/=";
|
||||
tokenNames[MOD_ASSIGN]="%=";
|
||||
tokenNames[SR_ASSIGN]=">>=";
|
||||
tokenNames[BSR_ASSIGN]=">>>=";
|
||||
tokenNames[SL_ASSIGN]="<<=";
|
||||
tokenNames[BAND_ASSIGN]="&=";
|
||||
tokenNames[BXOR_ASSIGN]="^=";
|
||||
tokenNames[BOR_ASSIGN]="|=";
|
||||
tokenNames[QUESTION]="?";
|
||||
tokenNames[LOR]="||";
|
||||
tokenNames[LAND]="&&";
|
||||
tokenNames[BOR]="|";
|
||||
tokenNames[BXOR]="^";
|
||||
tokenNames[BAND]="&";
|
||||
tokenNames[NOT_EQUAL]="!=";
|
||||
tokenNames[EQUAL]="==";
|
||||
tokenNames[LT]="<";
|
||||
tokenNames[GT]=">";
|
||||
tokenNames[LE]="<=";
|
||||
tokenNames[GE]=">=";
|
||||
tokenNames[SL]="<<";
|
||||
tokenNames[SR]=">>";
|
||||
tokenNames[BSR]=">>>";
|
||||
tokenNames[PLUS]="+";
|
||||
tokenNames[MINUS]="-";
|
||||
tokenNames[DIV]="/";
|
||||
tokenNames[MOD]="%";
|
||||
tokenNames[INC]="++";
|
||||
tokenNames[DEC]="--";
|
||||
tokenNames[BNOT]="~";
|
||||
tokenNames[LNOT]="!";
|
||||
tokenNames[FINAL]="final";
|
||||
tokenNames[ABSTRACT]="abstract";
|
||||
tokenNames[LITERAL_package]="package";
|
||||
tokenNames[LITERAL_import]="import";
|
||||
tokenNames[LITERAL_void]="void";
|
||||
tokenNames[LITERAL_boolean]="boolean";
|
||||
tokenNames[LITERAL_byte]="byte";
|
||||
tokenNames[LITERAL_char]="char";
|
||||
tokenNames[LITERAL_short]="short";
|
||||
tokenNames[LITERAL_int]="int";
|
||||
tokenNames[LITERAL_float]="float";
|
||||
tokenNames[LITERAL_long]="long";
|
||||
tokenNames[LITERAL_double]="double";
|
||||
tokenNames[LITERAL_private]="private";
|
||||
tokenNames[LITERAL_public]="public";
|
||||
tokenNames[LITERAL_protected]="protected";
|
||||
tokenNames[LITERAL_static]="static";
|
||||
tokenNames[LITERAL_transient]="transient";
|
||||
tokenNames[LITERAL_native]="native";
|
||||
tokenNames[LITERAL_threadsafe]="threadsafe";
|
||||
tokenNames[LITERAL_synchronized]="synchronized";
|
||||
tokenNames[LITERAL_volatile]="volatile";
|
||||
tokenNames[LITERAL_class]="class";
|
||||
tokenNames[LITERAL_extends]="extends";
|
||||
tokenNames[LITERAL_interface]="interface";
|
||||
tokenNames[LITERAL_implements]="implements";
|
||||
tokenNames[LITERAL_throws]="throws";
|
||||
tokenNames[LITERAL_if]="if";
|
||||
tokenNames[LITERAL_else]="else";
|
||||
tokenNames[LITERAL_for]="for";
|
||||
tokenNames[LITERAL_while]="while";
|
||||
tokenNames[LITERAL_do]="do";
|
||||
tokenNames[LITERAL_break]="break";
|
||||
tokenNames[LITERAL_continue]="continue";
|
||||
tokenNames[LITERAL_return]="return";
|
||||
tokenNames[LITERAL_switch]="switch";
|
||||
tokenNames[LITERAL_throw]="throw";
|
||||
tokenNames[LITERAL_case]="case";
|
||||
tokenNames[LITERAL_default]="default";
|
||||
tokenNames[LITERAL_try]="try";
|
||||
tokenNames[LITERAL_finally]="finally";
|
||||
tokenNames[LITERAL_catch]="catch";
|
||||
tokenNames[LITERAL_instanceof]="instanceof";
|
||||
tokenNames[LITERAL_this]="this";
|
||||
tokenNames[LITERAL_super]="super";
|
||||
tokenNames[LITERAL_true]="true";
|
||||
tokenNames[LITERAL_false]="false";
|
||||
tokenNames[LITERAL_null]="null";
|
||||
tokenNames[LITERAL_new]="new";
|
||||
tokenNames[LITERAL_color]="int"; // PDE specific alias
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a PrintStream to print to. System.out is the default.
|
||||
* @param out the PrintStream to print to
|
||||
*/
|
||||
public void setOut(PrintStream out) {
|
||||
this.out = out;
|
||||
}
|
||||
private String name(AST ast) {
|
||||
return tokenNames[ast.getType()];
|
||||
}
|
||||
private String name(int type) {
|
||||
return tokenNames[type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a child of the given AST that has the given type
|
||||
* @returns a child AST of the given type. If it can't find a child of the
|
||||
* given type, return null.
|
||||
*/
|
||||
private AST getChild(AST ast, int childType) {
|
||||
AST child = ast.getFirstChild();
|
||||
while (child != null) {
|
||||
if (child.getType() == childType) {
|
||||
// debug.println("getChild: found:" + name(ast));
|
||||
return child;
|
||||
}
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump the list of hidden tokens linked to after the AST node passed in.
|
||||
* Most hidden tokens are dumped from this function.
|
||||
*/
|
||||
private void dumpHiddenAfter(AST ast) {
|
||||
dumpHiddenTokens(((antlr.CommonASTWithHiddenTokens)ast).getHiddenAfter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump the list of hidden tokens linked to before the AST node passed in.
|
||||
* The only time hidden tokens need to be dumped with this function is when
|
||||
* dealing parts of the tree where automatic tree construction was
|
||||
* turned off with the ! operator in the grammar file and the nodes were
|
||||
* manually constructed in such a way that the usual tokens don't have the
|
||||
* necessary hiddenAfter links.
|
||||
*/
|
||||
private void dumpHiddenBefore(AST ast) {
|
||||
|
||||
antlr.CommonHiddenStreamToken
|
||||
child = null,
|
||||
parent = ((antlr.CommonASTWithHiddenTokens)ast).getHiddenBefore();
|
||||
|
||||
// if there aren't any hidden tokens here, quietly return
|
||||
//
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// traverse back to the head of the list of tokens before this node
|
||||
do {
|
||||
child = parent;
|
||||
parent = child.getHiddenBefore();
|
||||
} while (parent != null);
|
||||
|
||||
// dump that list
|
||||
dumpHiddenTokens(child);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump the list of hidden tokens linked to from the token passed in.
|
||||
*/
|
||||
private void dumpHiddenTokens(antlr.CommonHiddenStreamToken t) {
|
||||
for ( ; t != null ; t=PdePreprocessor.filter.getHiddenAfter(t) ) {
|
||||
out.print(t.getText());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the children of the given AST
|
||||
* @param ast The AST to print
|
||||
* @returns true iff anything was printed
|
||||
*/
|
||||
private boolean printChildren(AST ast) throws RunnerException {
|
||||
boolean ret = false;
|
||||
AST child = ast.getFirstChild();
|
||||
while (child != null) {
|
||||
ret = true;
|
||||
print(child);
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether an AST has any children or not.
|
||||
* @return true iff the AST has at least one child
|
||||
*/
|
||||
private boolean hasChildren(AST ast) {
|
||||
return (ast.getFirstChild() != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the best node in the subtree for printing. This really means
|
||||
* the next node which could potentially have hiddenBefore data. It's
|
||||
* usually the first printable leaf, but not always.
|
||||
*
|
||||
* @param includeThisNode Should this node be included in the search?
|
||||
* If false, only descendants are searched.
|
||||
*
|
||||
* @return the first printable leaf node in an AST
|
||||
*/
|
||||
private AST getBestPrintableNode(AST ast, boolean includeThisNode) {
|
||||
AST child;
|
||||
|
||||
if (includeThisNode) {
|
||||
child = ast;
|
||||
} else {
|
||||
child = ast.getFirstChild();
|
||||
}
|
||||
|
||||
if (child != null) {
|
||||
|
||||
switch (child.getType()) {
|
||||
|
||||
// the following node types are printing nodes that print before
|
||||
// any children, but then also recurse over children. So they
|
||||
// may have hiddenBefore chains that need to be printed first. Many
|
||||
// statements and all unary expression types qualify. Return these
|
||||
// nodes directly
|
||||
case CLASS_DEF:
|
||||
case LITERAL_if:
|
||||
case LITERAL_for:
|
||||
case LITERAL_while:
|
||||
case LITERAL_do:
|
||||
case LITERAL_break:
|
||||
case LITERAL_continue:
|
||||
case LITERAL_return:
|
||||
case LITERAL_switch:
|
||||
case LITERAL_try:
|
||||
case LITERAL_throw:
|
||||
case LITERAL_synchronized:
|
||||
case LITERAL_assert:
|
||||
case BNOT:
|
||||
case LNOT:
|
||||
case INC:
|
||||
case DEC:
|
||||
case UNARY_MINUS:
|
||||
case UNARY_PLUS:
|
||||
return child;
|
||||
|
||||
// Some non-terminal node types (at the moment, I only know of
|
||||
// MODIFIERS, but there may be other such types), can be
|
||||
// leaves in the tree but not have any children. If this is
|
||||
// such a node, move on to the next sibling.
|
||||
case MODIFIERS:
|
||||
if (child.getFirstChild() == null ) {
|
||||
return getBestPrintableNode(child.getNextSibling(), false);
|
||||
}
|
||||
// new jikes doesn't like fallthrough, so just duplicated here:
|
||||
return getBestPrintableNode(child, false);
|
||||
|
||||
default:
|
||||
return getBestPrintableNode(child, false);
|
||||
}
|
||||
}
|
||||
|
||||
return ast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a binary operator
|
||||
*/
|
||||
private void printBinaryOperator(AST ast) throws RunnerException {
|
||||
print(ast.getFirstChild());
|
||||
out.print(name(ast));
|
||||
dumpHiddenAfter(ast);
|
||||
print(ast.getFirstChild().getNextSibling());
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the given AST. Call this function to print your PDE code.
|
||||
*
|
||||
* It works by making recursive calls to print children.
|
||||
* So the code below is one big "switch" statement on the passed AST type.
|
||||
*/
|
||||
public void print (AST ast) throws RunnerException {
|
||||
if (ast == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AST parent = null;
|
||||
if (!stack.isEmpty()) {
|
||||
parent = (AST) stack.peek();
|
||||
}
|
||||
stack.push(ast);
|
||||
|
||||
AST child1 = ast.getFirstChild();
|
||||
AST child2 = null;
|
||||
AST child3 = null;
|
||||
if (child1 != null) {
|
||||
child2 = child1.getNextSibling();
|
||||
if (child2 != null) {
|
||||
child3 = child2.getNextSibling();
|
||||
}
|
||||
}
|
||||
|
||||
switch(ast.getType()) {
|
||||
// The top of the tree looks like this:
|
||||
// ROOT_ID "Whatever.java"
|
||||
// package
|
||||
// imports
|
||||
// class definition
|
||||
case ROOT_ID:
|
||||
dumpHiddenTokens(PdePreprocessor.filter.getInitialHiddenToken());
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
// supporting a "package" statement in a PDE program has
|
||||
// a bunch of issues with it that need to dealt in the compilation
|
||||
// code too, so this isn't actually tested.
|
||||
case PACKAGE_DEF:
|
||||
out.print("package");
|
||||
dumpHiddenAfter(ast);
|
||||
print(ast.getFirstChild());
|
||||
break;
|
||||
|
||||
// IMPORT has exactly one child
|
||||
case IMPORT:
|
||||
out.print("import");
|
||||
dumpHiddenAfter(ast);
|
||||
print(ast.getFirstChild());
|
||||
break;
|
||||
|
||||
case CLASS_DEF:
|
||||
case INTERFACE_DEF:
|
||||
print(getChild(ast, MODIFIERS));
|
||||
if (ast.getType() == CLASS_DEF) {
|
||||
out.print("class");
|
||||
} else {
|
||||
out.print("interface");
|
||||
}
|
||||
dumpHiddenBefore(getChild(ast, IDENT));
|
||||
print(getChild(ast, IDENT));
|
||||
print(getChild(ast, EXTENDS_CLAUSE));
|
||||
print(getChild(ast, IMPLEMENTS_CLAUSE));
|
||||
print(getChild(ast, OBJBLOCK));
|
||||
break;
|
||||
|
||||
case EXTENDS_CLAUSE:
|
||||
if (hasChildren(ast)) {
|
||||
out.print("extends");
|
||||
dumpHiddenBefore(getBestPrintableNode(ast, false));
|
||||
printChildren(ast);
|
||||
}
|
||||
break;
|
||||
|
||||
case IMPLEMENTS_CLAUSE:
|
||||
if (hasChildren(ast)) {
|
||||
out.print("implements");
|
||||
dumpHiddenBefore(getBestPrintableNode(ast, false));
|
||||
printChildren(ast);
|
||||
}
|
||||
break;
|
||||
|
||||
// DOT always has exactly two children.
|
||||
case DOT:
|
||||
print(child1);
|
||||
out.print(".");
|
||||
dumpHiddenAfter(ast);
|
||||
print(child2);
|
||||
break;
|
||||
|
||||
case MODIFIERS:
|
||||
case OBJBLOCK:
|
||||
case CTOR_DEF:
|
||||
//case METHOD_DEF:
|
||||
case PARAMETERS:
|
||||
case PARAMETER_DEF:
|
||||
case VARIABLE_DEF:
|
||||
case TYPE:
|
||||
case SLIST:
|
||||
case ELIST:
|
||||
case ARRAY_DECLARATOR:
|
||||
case TYPECAST:
|
||||
case EXPR:
|
||||
case ARRAY_INIT:
|
||||
case FOR_INIT:
|
||||
case FOR_CONDITION:
|
||||
case FOR_ITERATOR:
|
||||
case METHOD_CALL:
|
||||
case INSTANCE_INIT:
|
||||
case INDEX_OP:
|
||||
case SUPER_CTOR_CALL:
|
||||
case CTOR_CALL:
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
case METHOD_DEF:
|
||||
// kids seem to be: MODIFIERS TYPE setup PARAMETERS
|
||||
//AST parent = (AST) stack.peek();
|
||||
AST modifiersChild = ast.getFirstChild();
|
||||
AST typeChild = modifiersChild.getNextSibling();
|
||||
AST methodNameChild = typeChild.getNextSibling();
|
||||
AST parametersChild = methodNameChild.getNextSibling();
|
||||
|
||||
// to output, use print(child) on each of the four
|
||||
|
||||
/*
|
||||
// 1. figure out if this is setup, draw, or loop
|
||||
String methodName = methodNameChild.getText();
|
||||
if (publicMethods.get(methodName) != null) {
|
||||
// make sure this feller is public
|
||||
boolean foundPublic = false;
|
||||
AST child = modifiersChild.getFirstChild();
|
||||
while (child != null) {
|
||||
if (child.getText().equals("public")) {
|
||||
foundPublic = true;
|
||||
child = null;
|
||||
} else {
|
||||
//out.print("." + child.getText() + ".");
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
}
|
||||
if (!foundPublic) {
|
||||
out.print("public ");
|
||||
}
|
||||
*/
|
||||
|
||||
// if this method doesn't have a specifier, make it public
|
||||
// (useful for setup/keyPressed/etc)
|
||||
boolean foundSpecifier = false;
|
||||
AST child = modifiersChild.getFirstChild();
|
||||
while (child != null) {
|
||||
String childText = child.getText();
|
||||
if (childText.equals("public") ||
|
||||
childText.equals("protected") ||
|
||||
childText.equals("private")) {
|
||||
foundSpecifier = true;
|
||||
child = null;
|
||||
} else {
|
||||
//out.print("." + child.getText() + ".");
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
}
|
||||
if (!foundSpecifier) {
|
||||
out.print("public ");
|
||||
}
|
||||
printChildren(ast); // everything is fine
|
||||
break;
|
||||
|
||||
// if we have two children, it's of the form "a=0"
|
||||
// if just one child, it's of the form "=0" (where the
|
||||
// lhs is above this AST).
|
||||
case ASSIGN:
|
||||
if (child2 != null) {
|
||||
print(child1);
|
||||
out.print("=");
|
||||
dumpHiddenAfter(ast);
|
||||
print(child2);
|
||||
}
|
||||
else {
|
||||
out.print("=");
|
||||
dumpHiddenAfter(ast);
|
||||
print(child1);
|
||||
}
|
||||
break;
|
||||
|
||||
// binary operators:
|
||||
case PLUS:
|
||||
case MINUS:
|
||||
case DIV:
|
||||
case MOD:
|
||||
case NOT_EQUAL:
|
||||
case EQUAL:
|
||||
case LT:
|
||||
case GT:
|
||||
case LE:
|
||||
case GE:
|
||||
case LOR:
|
||||
case LAND:
|
||||
case BOR:
|
||||
case BXOR:
|
||||
case BAND:
|
||||
case SL:
|
||||
case SR:
|
||||
case BSR:
|
||||
case LITERAL_instanceof:
|
||||
case PLUS_ASSIGN:
|
||||
case MINUS_ASSIGN:
|
||||
case STAR_ASSIGN:
|
||||
case DIV_ASSIGN:
|
||||
case MOD_ASSIGN:
|
||||
case SR_ASSIGN:
|
||||
case BSR_ASSIGN:
|
||||
case SL_ASSIGN:
|
||||
case BAND_ASSIGN:
|
||||
case BXOR_ASSIGN:
|
||||
case BOR_ASSIGN:
|
||||
printBinaryOperator(ast);
|
||||
break;
|
||||
|
||||
|
||||
case LITERAL_for:
|
||||
out.print(name(ast));
|
||||
dumpHiddenAfter(ast);
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
case POST_INC:
|
||||
case POST_DEC:
|
||||
print(child1);
|
||||
out.print(name(ast));
|
||||
dumpHiddenAfter(ast);
|
||||
break;
|
||||
|
||||
// unary operators:
|
||||
case BNOT:
|
||||
case LNOT:
|
||||
case INC:
|
||||
case DEC:
|
||||
case UNARY_MINUS:
|
||||
case UNARY_PLUS:
|
||||
out.print(name(ast));
|
||||
dumpHiddenAfter(ast);
|
||||
print(child1);
|
||||
break;
|
||||
|
||||
case LITERAL_new:
|
||||
out.print("new");
|
||||
dumpHiddenAfter(ast);
|
||||
print(child1);
|
||||
print(child2);
|
||||
// "new String[] {...}": the stuff in {} is child3
|
||||
if (child3 != null) {
|
||||
print(child3);
|
||||
}
|
||||
break;
|
||||
|
||||
case LITERAL_return:
|
||||
out.print("return");
|
||||
dumpHiddenAfter(ast);
|
||||
print(child1);
|
||||
break;
|
||||
|
||||
case STATIC_INIT:
|
||||
out.print("static");
|
||||
dumpHiddenBefore(getBestPrintableNode(ast, false));
|
||||
print(child1);
|
||||
break;
|
||||
|
||||
case LITERAL_switch:
|
||||
out.print("switch");
|
||||
dumpHiddenAfter(ast);
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
case CASE_GROUP:
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
case LITERAL_case:
|
||||
out.print("case");
|
||||
dumpHiddenAfter(ast);
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
case LITERAL_default:
|
||||
out.print("default");
|
||||
dumpHiddenAfter(ast);
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
case NUM_INT:
|
||||
case CHAR_LITERAL:
|
||||
case STRING_LITERAL:
|
||||
case NUM_FLOAT:
|
||||
out.print(ast.getText());
|
||||
dumpHiddenAfter(ast);
|
||||
break;
|
||||
|
||||
case LITERAL_private:
|
||||
case LITERAL_public:
|
||||
case LITERAL_protected:
|
||||
case LITERAL_static:
|
||||
case LITERAL_transient:
|
||||
case LITERAL_native:
|
||||
case LITERAL_threadsafe:
|
||||
case LITERAL_synchronized:
|
||||
case LITERAL_volatile:
|
||||
case FINAL:
|
||||
case ABSTRACT:
|
||||
case LITERAL_package:
|
||||
case LITERAL_void:
|
||||
case LITERAL_boolean:
|
||||
case LITERAL_byte:
|
||||
case LITERAL_char:
|
||||
case LITERAL_short:
|
||||
case LITERAL_int:
|
||||
case LITERAL_float:
|
||||
case LITERAL_long:
|
||||
case LITERAL_double:
|
||||
case LITERAL_true:
|
||||
case LITERAL_false:
|
||||
case LITERAL_null:
|
||||
case SEMI:
|
||||
case LITERAL_this:
|
||||
case LITERAL_super:
|
||||
case LITERAL_continue:
|
||||
case LITERAL_break:
|
||||
out.print(name(ast));
|
||||
dumpHiddenAfter(ast);
|
||||
break;
|
||||
|
||||
case EMPTY_STAT:
|
||||
case EMPTY_FIELD:
|
||||
break;
|
||||
|
||||
// yuck: Distinguish between "import x.y.*" and "x = 1 * 3"
|
||||
case STAR:
|
||||
if (hasChildren(ast)) { // the binary mult. operator
|
||||
printBinaryOperator(ast);
|
||||
}
|
||||
else { // the special "*" in import:
|
||||
out.print("*");
|
||||
dumpHiddenAfter(ast);
|
||||
}
|
||||
break;
|
||||
|
||||
case LITERAL_throws:
|
||||
out.print("throws");
|
||||
dumpHiddenAfter(ast);
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
case LITERAL_if:
|
||||
out.print("if");
|
||||
dumpHiddenAfter(ast);
|
||||
print(child1); // the "if" condition: an EXPR
|
||||
print(child2); // the "then" clause is an SLIST
|
||||
if (child3 != null) {
|
||||
out.print("else");
|
||||
dumpHiddenBefore(getBestPrintableNode(child3, true));
|
||||
print(child3); // optional "else" clause: an SLIST
|
||||
}
|
||||
break;
|
||||
|
||||
case LITERAL_while:
|
||||
out.print("while");
|
||||
dumpHiddenAfter(ast);
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
case LITERAL_do:
|
||||
out.print("do");
|
||||
dumpHiddenAfter(ast);
|
||||
print(child1); // an SLIST
|
||||
out.print("while");
|
||||
dumpHiddenBefore(getBestPrintableNode(child2, false));
|
||||
print(child2); // an EXPR
|
||||
break;
|
||||
|
||||
case LITERAL_try:
|
||||
out.print("try");
|
||||
dumpHiddenAfter(ast);
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
case LITERAL_catch:
|
||||
out.print("catch");
|
||||
dumpHiddenAfter(ast);
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
// the first child is the "try" and the second is the SLIST
|
||||
case LITERAL_finally:
|
||||
out.print("finally");
|
||||
dumpHiddenAfter(ast);
|
||||
printChildren(ast);
|
||||
break;
|
||||
|
||||
case LITERAL_throw:
|
||||
out.print("throw");
|
||||
dumpHiddenAfter(ast);
|
||||
print(child1);
|
||||
break;
|
||||
|
||||
// the dreaded trinary operator
|
||||
case QUESTION:
|
||||
print(child1);
|
||||
out.print("?");
|
||||
dumpHiddenAfter(ast);
|
||||
print(child2);
|
||||
print(child3);
|
||||
break;
|
||||
|
||||
// pde specific or modified tokens start here
|
||||
|
||||
// Image -> BImage, Font -> BFont as appropriate
|
||||
case IDENT:
|
||||
/*
|
||||
if (ast.getText().equals("Image") &&
|
||||
Preferences.getBoolean("preproc.substitute_image")) { //, true)) {
|
||||
out.print("BImage");
|
||||
} else if (ast.getText().equals("Font") &&
|
||||
Preferences.getBoolean("preproc.substitute_font")) { //, true)) {
|
||||
out.print("BFont");
|
||||
} else {
|
||||
*/
|
||||
out.print(ast.getText());
|
||||
//}
|
||||
dumpHiddenAfter(ast);
|
||||
break;
|
||||
|
||||
// the color datatype is just an alias for int
|
||||
case LITERAL_color:
|
||||
out.print("int");
|
||||
dumpHiddenAfter(ast);
|
||||
break;
|
||||
|
||||
case WEBCOLOR_LITERAL:
|
||||
if (ast.getText().length() != 6) {
|
||||
System.err.println("Internal error: incorrect length of webcolor " +
|
||||
"literal should have been detected sooner.");
|
||||
break;
|
||||
}
|
||||
out.print("0xff" + ast.getText());
|
||||
dumpHiddenAfter(ast);
|
||||
break;
|
||||
|
||||
// allow for stuff like int(43.2).
|
||||
case CONSTRUCTOR_CAST:
|
||||
|
||||
AST nonTerminalTypeNode = child1;
|
||||
AST terminalTypeNode = child1.getFirstChild();
|
||||
AST exprToCast = child2;
|
||||
|
||||
/*
|
||||
// if this is a string type, add .valueOf()
|
||||
if (nonTerminalTypeNode.getType() == PdeRecognizer.TYPE &&
|
||||
terminalTypeNode.getText().equals("String")) {
|
||||
|
||||
out.print(terminalTypeNode.getText() + ".valueOf");
|
||||
dumpHiddenAfter(terminalTypeNode);
|
||||
print(exprToCast);
|
||||
|
||||
// if the expresion to be cast is a string literal, try and parse it.
|
||||
//
|
||||
// ideally, we'd be able to do this for all expressions with a
|
||||
// string type, not just string literals. however, the parser
|
||||
// doesn't currently track expression type, and for full
|
||||
// functionality, we'd need to do semantic analysis to handle
|
||||
// imports so that we could know the return types of method calls.
|
||||
//
|
||||
} else if (exprToCast.getFirstChild().getType() == STRING_LITERAL ) {
|
||||
|
||||
switch (terminalTypeNode.getType()) {
|
||||
|
||||
case PdeRecognizer.LITERAL_byte:
|
||||
out.print("Byte.parseByte");
|
||||
dumpHiddenAfter(terminalTypeNode);
|
||||
print(exprToCast);
|
||||
break;
|
||||
|
||||
case PdeRecognizer.LITERAL_double:
|
||||
out.print("(new Double");
|
||||
dumpHiddenAfter(terminalTypeNode);
|
||||
out.print(exprToCast.getFirstChild().getText() + ").doubleValue()");
|
||||
dumpHiddenAfter(exprToCast.getFirstChild());
|
||||
break;
|
||||
|
||||
case PdeRecognizer.LITERAL_float:
|
||||
out.print("(new Float");
|
||||
dumpHiddenAfter(terminalTypeNode);
|
||||
out.print(exprToCast.getFirstChild().getText() + ").floatValue()");
|
||||
dumpHiddenAfter(exprToCast.getFirstChild());
|
||||
break;
|
||||
|
||||
case PdeRecognizer.LITERAL_int:
|
||||
case PdeRecognizer.LITERAL_color:
|
||||
out.print("Integer.parseInt");
|
||||
dumpHiddenAfter(terminalTypeNode);
|
||||
print(exprToCast);
|
||||
break;
|
||||
|
||||
case PdeRecognizer.LITERAL_long:
|
||||
out.print("Long.parseLong");
|
||||
break;
|
||||
|
||||
case PdeRecognizer.LITERAL_short:
|
||||
out.print("Short.parseShort");
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RunnerException(Compiler.SUPER_BADNESS);
|
||||
}
|
||||
|
||||
// for builtin types, use regular casting syntax
|
||||
} else {
|
||||
*/
|
||||
|
||||
// result of below is (int)(4.0
|
||||
//out.print("(");
|
||||
//out.print(terminalTypeNode.getText() + ")"); // typename
|
||||
//dumpHiddenAfter(terminalTypeNode);
|
||||
//print(exprToCast);
|
||||
//}
|
||||
|
||||
//out.print("(");
|
||||
String pooType = terminalTypeNode.getText();
|
||||
out.print("PApplet.to" +
|
||||
Character.toUpperCase(pooType.charAt(0)) +
|
||||
pooType.substring(1));
|
||||
dumpHiddenAfter(terminalTypeNode); // the left paren
|
||||
print(exprToCast);
|
||||
//out.print("x)");
|
||||
|
||||
break;
|
||||
|
||||
|
||||
// making floating point literals default to floats, not doubles
|
||||
case NUM_DOUBLE:
|
||||
out.print(ast.getText());
|
||||
if (Preferences.getBoolean("preproc.substitute_floats")) { //, true) ) {
|
||||
out.print("f");
|
||||
}
|
||||
dumpHiddenAfter(ast);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
debug.println("Invalid type:" + ast.getType());
|
||||
break;
|
||||
|
||||
|
||||
/* The following are tokens, but I don't think JavaRecognizer
|
||||
ever produces an AST with one of these types:
|
||||
case COMMA:
|
||||
case LITERAL_implements:
|
||||
case LITERAL_class:
|
||||
case LITERAL_extends:
|
||||
case EOF:
|
||||
case NULL_TREE_LOOKAHEAD:
|
||||
case BLOCK:
|
||||
case LABELED_STAT: // refuse to implement on moral grounds :)
|
||||
case LITERAL_import:
|
||||
case LBRACK:
|
||||
case RBRACK:
|
||||
case LCURLY:
|
||||
case RCURLY:
|
||||
case LPAREN:
|
||||
case RPAREN:
|
||||
case LITERAL_else: // else is a child of "if" AST
|
||||
case COLON: // part of the trinary operator
|
||||
case WS: // whitespace
|
||||
case ESC:
|
||||
case HEX_DIGIT:
|
||||
case VOCAB:
|
||||
|
||||
case EXPONENT: // exponents and float suffixes are left in the NUM_FLOAT
|
||||
case FLOAT_SUFFIX
|
||||
*/
|
||||
}
|
||||
|
||||
stack.pop();
|
||||
}
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
// $ANTLR 2.7.2: "expandedpde.g" -> "PdeRecognizer.java"$
|
||||
|
||||
package processing.app.preproc;
|
||||
|
||||
import processing.app.*;
|
||||
|
||||
public interface PdePartialTokenTypes {
|
||||
int EOF = 1;
|
||||
int NULL_TREE_LOOKAHEAD = 3;
|
||||
int BLOCK = 4;
|
||||
int MODIFIERS = 5;
|
||||
int OBJBLOCK = 6;
|
||||
int SLIST = 7;
|
||||
int CTOR_DEF = 8;
|
||||
int METHOD_DEF = 9;
|
||||
int VARIABLE_DEF = 10;
|
||||
int INSTANCE_INIT = 11;
|
||||
int STATIC_INIT = 12;
|
||||
int TYPE = 13;
|
||||
int CLASS_DEF = 14;
|
||||
int INTERFACE_DEF = 15;
|
||||
int PACKAGE_DEF = 16;
|
||||
int ARRAY_DECLARATOR = 17;
|
||||
int EXTENDS_CLAUSE = 18;
|
||||
int IMPLEMENTS_CLAUSE = 19;
|
||||
int PARAMETERS = 20;
|
||||
int PARAMETER_DEF = 21;
|
||||
int LABELED_STAT = 22;
|
||||
int TYPECAST = 23;
|
||||
int INDEX_OP = 24;
|
||||
int POST_INC = 25;
|
||||
int POST_DEC = 26;
|
||||
int METHOD_CALL = 27;
|
||||
int EXPR = 28;
|
||||
int ARRAY_INIT = 29;
|
||||
int IMPORT = 30;
|
||||
int UNARY_MINUS = 31;
|
||||
int UNARY_PLUS = 32;
|
||||
int CASE_GROUP = 33;
|
||||
int ELIST = 34;
|
||||
int FOR_INIT = 35;
|
||||
int FOR_CONDITION = 36;
|
||||
int FOR_ITERATOR = 37;
|
||||
int EMPTY_STAT = 38;
|
||||
int FINAL = 39;
|
||||
int ABSTRACT = 40;
|
||||
int STRICTFP = 41;
|
||||
int SUPER_CTOR_CALL = 42;
|
||||
int CTOR_CALL = 43;
|
||||
int LITERAL_package = 44;
|
||||
int SEMI = 45;
|
||||
int LITERAL_import = 46;
|
||||
int LBRACK = 47;
|
||||
int RBRACK = 48;
|
||||
int LITERAL_void = 49;
|
||||
int LITERAL_boolean = 50;
|
||||
int LITERAL_byte = 51;
|
||||
int LITERAL_char = 52;
|
||||
int LITERAL_short = 53;
|
||||
int LITERAL_int = 54;
|
||||
int LITERAL_float = 55;
|
||||
int LITERAL_long = 56;
|
||||
int LITERAL_double = 57;
|
||||
int IDENT = 58;
|
||||
int DOT = 59;
|
||||
int STAR = 60;
|
||||
int LITERAL_private = 61;
|
||||
int LITERAL_public = 62;
|
||||
int LITERAL_protected = 63;
|
||||
int LITERAL_static = 64;
|
||||
int LITERAL_transient = 65;
|
||||
int LITERAL_native = 66;
|
||||
int LITERAL_threadsafe = 67;
|
||||
int LITERAL_synchronized = 68;
|
||||
int LITERAL_volatile = 69;
|
||||
int LITERAL_class = 70;
|
||||
int LITERAL_extends = 71;
|
||||
int LITERAL_interface = 72;
|
||||
int LCURLY = 73;
|
||||
int RCURLY = 74;
|
||||
int COMMA = 75;
|
||||
int LITERAL_implements = 76;
|
||||
int LPAREN = 77;
|
||||
int RPAREN = 78;
|
||||
int LITERAL_this = 79;
|
||||
int LITERAL_super = 80;
|
||||
int ASSIGN = 81;
|
||||
int LITERAL_throws = 82;
|
||||
int COLON = 83;
|
||||
int LITERAL_if = 84;
|
||||
int LITERAL_else = 85;
|
||||
int LITERAL_for = 86;
|
||||
int LITERAL_while = 87;
|
||||
int LITERAL_do = 88;
|
||||
int LITERAL_break = 89;
|
||||
int LITERAL_continue = 90;
|
||||
int LITERAL_return = 91;
|
||||
int LITERAL_switch = 92;
|
||||
int LITERAL_throw = 93;
|
||||
int LITERAL_assert = 94;
|
||||
int LITERAL_case = 95;
|
||||
int LITERAL_default = 96;
|
||||
int LITERAL_try = 97;
|
||||
int LITERAL_finally = 98;
|
||||
int LITERAL_catch = 99;
|
||||
int PLUS_ASSIGN = 100;
|
||||
int MINUS_ASSIGN = 101;
|
||||
int STAR_ASSIGN = 102;
|
||||
int DIV_ASSIGN = 103;
|
||||
int MOD_ASSIGN = 104;
|
||||
int SR_ASSIGN = 105;
|
||||
int BSR_ASSIGN = 106;
|
||||
int SL_ASSIGN = 107;
|
||||
int BAND_ASSIGN = 108;
|
||||
int BXOR_ASSIGN = 109;
|
||||
int BOR_ASSIGN = 110;
|
||||
int QUESTION = 111;
|
||||
int LOR = 112;
|
||||
int LAND = 113;
|
||||
int BOR = 114;
|
||||
int BXOR = 115;
|
||||
int BAND = 116;
|
||||
int NOT_EQUAL = 117;
|
||||
int EQUAL = 118;
|
||||
int LT = 119;
|
||||
int GT = 120;
|
||||
int LE = 121;
|
||||
int GE = 122;
|
||||
int LITERAL_instanceof = 123;
|
||||
int SL = 124;
|
||||
int SR = 125;
|
||||
int BSR = 126;
|
||||
int PLUS = 127;
|
||||
int MINUS = 128;
|
||||
int DIV = 129;
|
||||
int MOD = 130;
|
||||
int INC = 131;
|
||||
int DEC = 132;
|
||||
int BNOT = 133;
|
||||
int LNOT = 134;
|
||||
int LITERAL_true = 135;
|
||||
int LITERAL_false = 136;
|
||||
int LITERAL_null = 137;
|
||||
int LITERAL_new = 138;
|
||||
int NUM_INT = 139;
|
||||
int CHAR_LITERAL = 140;
|
||||
int STRING_LITERAL = 141;
|
||||
int NUM_FLOAT = 142;
|
||||
int NUM_LONG = 143;
|
||||
int NUM_DOUBLE = 144;
|
||||
int WS = 145;
|
||||
int SL_COMMENT = 146;
|
||||
int ML_COMMENT = 147;
|
||||
int ESC = 148;
|
||||
int HEX_DIGIT = 149;
|
||||
int VOCAB = 150;
|
||||
int EXPONENT = 151;
|
||||
int FLOAT_SUFFIX = 152;
|
||||
int CONSTRUCTOR_CAST = 153;
|
||||
int EMPTY_FIELD = 154;
|
||||
int WEBCOLOR_LITERAL = 155;
|
||||
int LITERAL_color = 156;
|
||||
}
|
@ -1,155 +0,0 @@
|
||||
// $ANTLR 2.7.2: expandedpde.g -> PdePartialTokenTypes.txt$
|
||||
PdePartial // output token vocab name
|
||||
BLOCK=4
|
||||
MODIFIERS=5
|
||||
OBJBLOCK=6
|
||||
SLIST=7
|
||||
CTOR_DEF=8
|
||||
METHOD_DEF=9
|
||||
VARIABLE_DEF=10
|
||||
INSTANCE_INIT=11
|
||||
STATIC_INIT=12
|
||||
TYPE=13
|
||||
CLASS_DEF=14
|
||||
INTERFACE_DEF=15
|
||||
PACKAGE_DEF=16
|
||||
ARRAY_DECLARATOR=17
|
||||
EXTENDS_CLAUSE=18
|
||||
IMPLEMENTS_CLAUSE=19
|
||||
PARAMETERS=20
|
||||
PARAMETER_DEF=21
|
||||
LABELED_STAT=22
|
||||
TYPECAST=23
|
||||
INDEX_OP=24
|
||||
POST_INC=25
|
||||
POST_DEC=26
|
||||
METHOD_CALL=27
|
||||
EXPR=28
|
||||
ARRAY_INIT=29
|
||||
IMPORT=30
|
||||
UNARY_MINUS=31
|
||||
UNARY_PLUS=32
|
||||
CASE_GROUP=33
|
||||
ELIST=34
|
||||
FOR_INIT=35
|
||||
FOR_CONDITION=36
|
||||
FOR_ITERATOR=37
|
||||
EMPTY_STAT=38
|
||||
FINAL="final"=39
|
||||
ABSTRACT="abstract"=40
|
||||
STRICTFP="strictfp"=41
|
||||
SUPER_CTOR_CALL=42
|
||||
CTOR_CALL=43
|
||||
LITERAL_package="package"=44
|
||||
SEMI=45
|
||||
LITERAL_import="import"=46
|
||||
LBRACK=47
|
||||
RBRACK=48
|
||||
LITERAL_void="void"=49
|
||||
LITERAL_boolean="boolean"=50
|
||||
LITERAL_byte="byte"=51
|
||||
LITERAL_char="char"=52
|
||||
LITERAL_short="short"=53
|
||||
LITERAL_int="int"=54
|
||||
LITERAL_float="float"=55
|
||||
LITERAL_long="long"=56
|
||||
LITERAL_double="double"=57
|
||||
IDENT=58
|
||||
DOT=59
|
||||
STAR=60
|
||||
LITERAL_private="private"=61
|
||||
LITERAL_public="public"=62
|
||||
LITERAL_protected="protected"=63
|
||||
LITERAL_static="static"=64
|
||||
LITERAL_transient="transient"=65
|
||||
LITERAL_native="native"=66
|
||||
LITERAL_threadsafe="threadsafe"=67
|
||||
LITERAL_synchronized="synchronized"=68
|
||||
LITERAL_volatile="volatile"=69
|
||||
LITERAL_class="class"=70
|
||||
LITERAL_extends="extends"=71
|
||||
LITERAL_interface="interface"=72
|
||||
LCURLY=73
|
||||
RCURLY=74
|
||||
COMMA=75
|
||||
LITERAL_implements="implements"=76
|
||||
LPAREN=77
|
||||
RPAREN=78
|
||||
LITERAL_this="this"=79
|
||||
LITERAL_super="super"=80
|
||||
ASSIGN=81
|
||||
LITERAL_throws="throws"=82
|
||||
COLON=83
|
||||
LITERAL_if="if"=84
|
||||
LITERAL_else="else"=85
|
||||
LITERAL_for="for"=86
|
||||
LITERAL_while="while"=87
|
||||
LITERAL_do="do"=88
|
||||
LITERAL_break="break"=89
|
||||
LITERAL_continue="continue"=90
|
||||
LITERAL_return="return"=91
|
||||
LITERAL_switch="switch"=92
|
||||
LITERAL_throw="throw"=93
|
||||
LITERAL_assert="assert"=94
|
||||
LITERAL_case="case"=95
|
||||
LITERAL_default="default"=96
|
||||
LITERAL_try="try"=97
|
||||
LITERAL_finally="finally"=98
|
||||
LITERAL_catch="catch"=99
|
||||
PLUS_ASSIGN=100
|
||||
MINUS_ASSIGN=101
|
||||
STAR_ASSIGN=102
|
||||
DIV_ASSIGN=103
|
||||
MOD_ASSIGN=104
|
||||
SR_ASSIGN=105
|
||||
BSR_ASSIGN=106
|
||||
SL_ASSIGN=107
|
||||
BAND_ASSIGN=108
|
||||
BXOR_ASSIGN=109
|
||||
BOR_ASSIGN=110
|
||||
QUESTION=111
|
||||
LOR=112
|
||||
LAND=113
|
||||
BOR=114
|
||||
BXOR=115
|
||||
BAND=116
|
||||
NOT_EQUAL=117
|
||||
EQUAL=118
|
||||
LT=119
|
||||
GT=120
|
||||
LE=121
|
||||
GE=122
|
||||
LITERAL_instanceof="instanceof"=123
|
||||
SL=124
|
||||
SR=125
|
||||
BSR=126
|
||||
PLUS=127
|
||||
MINUS=128
|
||||
DIV=129
|
||||
MOD=130
|
||||
INC=131
|
||||
DEC=132
|
||||
BNOT=133
|
||||
LNOT=134
|
||||
LITERAL_true="true"=135
|
||||
LITERAL_false="false"=136
|
||||
LITERAL_null="null"=137
|
||||
LITERAL_new="new"=138
|
||||
NUM_INT=139
|
||||
CHAR_LITERAL=140
|
||||
STRING_LITERAL=141
|
||||
NUM_FLOAT=142
|
||||
NUM_LONG=143
|
||||
NUM_DOUBLE=144
|
||||
WS=145
|
||||
SL_COMMENT=146
|
||||
ML_COMMENT=147
|
||||
ESC=148
|
||||
HEX_DIGIT=149
|
||||
VOCAB=150
|
||||
EXPONENT=151
|
||||
FLOAT_SUFFIX=152
|
||||
CONSTRUCTOR_CAST=153
|
||||
EMPTY_FIELD=154
|
||||
WEBCOLOR_LITERAL=155
|
||||
LITERAL_color="color"=156
|
133
app/preproc/PdePreprocessor.java
Normal file → Executable file
133
app/preproc/PdePreprocessor.java
Normal file → Executable file
@ -2,9 +2,11 @@
|
||||
|
||||
/*
|
||||
PdePreprocessor - wrapper for default ANTLR-generated parser
|
||||
Part of the Processing project - http://processing.org
|
||||
Part of the Wiring project - http://wiring.org.co
|
||||
|
||||
Copyright (c) 2004-05 Ben Fry and Casey Reas
|
||||
Copyright (c) 2004-05 Hernando Barragan
|
||||
|
||||
Processing version Copyright (c) 2004-05 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
ANTLR-generated parser and several supporting classes written
|
||||
@ -69,25 +71,27 @@ public class PdePreprocessor {
|
||||
// used for calling the ASTFactory to get the root node
|
||||
private static final int ROOT_ID = 0;
|
||||
|
||||
// stores number of built user-defined function prototypes
|
||||
public int prototypeCount = 0;
|
||||
|
||||
/**
|
||||
* These may change in-between (if the prefs panel adds this option)
|
||||
* so grab them here on construction.
|
||||
*/
|
||||
public PdePreprocessor() {
|
||||
defaultImports[JDK11] =
|
||||
/* defaultImports[JDK11] =
|
||||
Base.split(Preferences.get("preproc.imports.jdk11"), ',');
|
||||
defaultImports[JDK13] =
|
||||
Base.split(Preferences.get("preproc.imports.jdk13"), ',');
|
||||
defaultImports[JDK14] =
|
||||
Base.split(Preferences.get("preproc.imports.jdk14"), ',');
|
||||
}
|
||||
*/ }
|
||||
|
||||
|
||||
/**
|
||||
* Used by PdeEmitter.dumpHiddenTokens()
|
||||
*/
|
||||
public static TokenStreamCopyingHiddenTokenFilter filter;
|
||||
//public static TokenStreamCopyingHiddenTokenFilter filter;
|
||||
|
||||
|
||||
/**
|
||||
@ -159,6 +163,7 @@ public class PdePreprocessor {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
do {
|
||||
PatternMatcherInput input = new PatternMatcherInput(program);
|
||||
if (!matcher.contains(input, pattern)) break;
|
||||
@ -179,6 +184,7 @@ public class PdePreprocessor {
|
||||
//System.out.println("removing " + piece);
|
||||
|
||||
} while (true);
|
||||
*/
|
||||
|
||||
extraImports = new String[imports.size()];
|
||||
imports.copyInto(extraImports);
|
||||
@ -216,42 +222,84 @@ public class PdePreprocessor {
|
||||
this.programReader = new StringReader(program);
|
||||
this.buildPath = buildPath;
|
||||
|
||||
// create function prototypes
|
||||
mess = "^(\\w+)\\s+(\\w+)\\s*\\(([^)]*)\\)\\s*{";
|
||||
pattern = null;
|
||||
try {
|
||||
pattern = compiler.compile(mess);
|
||||
} catch (MalformedPatternException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
PatternMatcherInput input = new PatternMatcherInput(program);
|
||||
MatchResult result;
|
||||
String returntype, functioname, parameterlist, prototype;
|
||||
java.util.LinkedList prototypes = new java.util.LinkedList();
|
||||
//System.out.println("prototypes:");
|
||||
if (Preferences.get("build.extension").equals("cpp")) {
|
||||
while(matcher.contains(input, pattern)){
|
||||
result = matcher.getMatch();
|
||||
//System.out.println(result);
|
||||
returntype = result.group(1).toString();
|
||||
functioname = result.group(2).toString();
|
||||
parameterlist = result.group(3).toString().replace('\n', ' ');
|
||||
prototype = returntype + " " + functioname + "(" + parameterlist + ");";
|
||||
if(0 == functioname.compareTo("setup")){
|
||||
continue;
|
||||
}
|
||||
if(0 == functioname.compareTo("loop")){
|
||||
continue;
|
||||
}
|
||||
prototypes.add(prototype);
|
||||
//System.out.println(prototype);
|
||||
}
|
||||
}
|
||||
// store # of prototypes so that line number reporting can be adjusted
|
||||
prototypeCount = prototypes.size();
|
||||
|
||||
|
||||
// create a lexer with the stream reader, and tell it to handle
|
||||
// hidden tokens (eg whitespace, comments) since we want to pass these
|
||||
// through so that the line numbers when the compiler reports errors
|
||||
// match those that will be highlighted in the PDE IDE
|
||||
//
|
||||
PdeLexer lexer = new PdeLexer(programReader);
|
||||
lexer.setTokenObjectClass("antlr.CommonHiddenStreamToken");
|
||||
WLexer lexer = new WLexer(programReader);
|
||||
//lexer.setTokenObjectClass("antlr.CommonHiddenStreamToken");
|
||||
lexer.setTokenObjectClass("processing.app.preproc.CToken");
|
||||
lexer.initialize();
|
||||
|
||||
// create the filter for hidden tokens and specify which tokens to
|
||||
// hide and which to copy to the hidden text
|
||||
//
|
||||
filter = new TokenStreamCopyingHiddenTokenFilter(lexer);
|
||||
filter.hide(PdeRecognizer.SL_COMMENT);
|
||||
filter.hide(PdeRecognizer.ML_COMMENT);
|
||||
filter.hide(PdeRecognizer.WS);
|
||||
filter.copy(PdeRecognizer.SEMI);
|
||||
filter.copy(PdeRecognizer.LPAREN);
|
||||
filter.copy(PdeRecognizer.RPAREN);
|
||||
filter.copy(PdeRecognizer.LCURLY);
|
||||
filter.copy(PdeRecognizer.RCURLY);
|
||||
filter.copy(PdeRecognizer.COMMA);
|
||||
filter.copy(PdeRecognizer.RBRACK);
|
||||
filter.copy(PdeRecognizer.LBRACK);
|
||||
filter.copy(PdeRecognizer.COLON);
|
||||
|
||||
/*filter = new TokenStreamCopyingHiddenTokenFilter(lexer);
|
||||
filter.hide(WParser.CPPComment);
|
||||
filter.hide(WParser.Comment);
|
||||
filter.hide(WParser.Whitespace);
|
||||
filter.copy(WParser.SEMI);
|
||||
filter.copy(WParser.LPAREN);
|
||||
filter.copy(WParser.RPAREN);
|
||||
filter.copy(WParser.LCURLY);
|
||||
filter.copy(WParser.RCURLY);
|
||||
filter.copy(WParser.COMMA);
|
||||
filter.copy(WParser.RBRACK);
|
||||
filter.copy(WParser.LBRACK);
|
||||
filter.copy(WParser.COLON);
|
||||
*/
|
||||
// create a parser and set what sort of AST should be generated
|
||||
//
|
||||
PdeRecognizer parser = new PdeRecognizer(filter);
|
||||
//PdeRecognizer parser = new PdeRecognizer(filter);
|
||||
WParser parser = new WParser(lexer);
|
||||
|
||||
// use our extended AST class
|
||||
//
|
||||
parser.setASTNodeClass("antlr.ExtendedCommonASTWithHiddenTokens");
|
||||
//parser.setASTNodeClass("antlr.ExtendedCommonASTWithHiddenTokens");
|
||||
parser.setASTNodeType(TNode.class.getName());
|
||||
TNode.setTokenVocabulary("processing.app.preproc.WTokenTypes");
|
||||
|
||||
// start parsing at the compilationUnit non-terminal
|
||||
//
|
||||
parser.pdeProgram();
|
||||
//parser.pdeProgram();
|
||||
parser.translationUnit();
|
||||
|
||||
// set up the AST for traversal by PdeEmitter
|
||||
//
|
||||
@ -280,15 +328,17 @@ public class PdePreprocessor {
|
||||
|
||||
// output the code
|
||||
//
|
||||
PdeEmitter emitter = new PdeEmitter();
|
||||
File streamFile = new File(buildPath, name + ".java");
|
||||
WEmitter emitter = new WEmitter(lexer.getPreprocessorInfoChannel());
|
||||
File streamFile = new File(buildPath, name + "." + Preferences.get("build.extension"));
|
||||
PrintStream stream = new PrintStream(new FileOutputStream(streamFile));
|
||||
|
||||
//writeHeader(stream, extraImports, name);
|
||||
writeHeader(stream, name);
|
||||
|
||||
writeHeader(stream, name, prototypes);
|
||||
emitter.setASTNodeType(TNode.class.getName());
|
||||
emitter.setOut(stream);
|
||||
emitter.print(rootNode);
|
||||
emitter.printDeclarations(rootNode);
|
||||
//emitter.print(rootNode);
|
||||
emitter.translationUnit(parser.getAST());
|
||||
|
||||
writeFooter(stream);
|
||||
stream.close();
|
||||
@ -313,7 +363,6 @@ public class PdePreprocessor {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write any required header material (eg imports, class decl stuff)
|
||||
*
|
||||
@ -321,15 +370,18 @@ public class PdePreprocessor {
|
||||
* @param exporting Is this being exported from PDE?
|
||||
* @param name Name of the class being created.
|
||||
*/
|
||||
void writeHeader(PrintStream out, String className) {
|
||||
void writeHeader(PrintStream out, String className, java.util.LinkedList prototypes) {
|
||||
out.print("#include \"WProgram.h\"\n");
|
||||
|
||||
// must include processing.core
|
||||
out.print("import processing.core.*; ");
|
||||
// print user defined prototypes
|
||||
while(0 < prototypes.size()){
|
||||
out.print(prototypes.removeFirst() + "\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("import " + extraImports[i] + "; ");
|
||||
out.print("#include \"" + extraImports[i] + "\"\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,7 +393,7 @@ public class PdePreprocessor {
|
||||
|
||||
// emit standard imports (read from pde.properties)
|
||||
// for each language level that's being used.
|
||||
String jdkVersionStr = Preferences.get("preproc.jdk_version");
|
||||
/* String jdkVersionStr = Preferences.get("preproc.jdk_version");
|
||||
|
||||
int jdkVersion = JDK11; // default
|
||||
if (jdkVersionStr.equals("1.3")) { jdkVersion = JDK13; };
|
||||
@ -357,8 +409,8 @@ public class PdePreprocessor {
|
||||
//if (opengl) {
|
||||
//out.println("import processing.opengl.*; ");
|
||||
//}
|
||||
|
||||
if (programType < JAVA) {
|
||||
*/
|
||||
/* if (programType < JAVA) {
|
||||
// open the class definition
|
||||
out.print("public class " + className + " extends ");
|
||||
//if (opengl) {
|
||||
@ -377,7 +429,7 @@ public class PdePreprocessor {
|
||||
out.print("public void setup() {");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/ }
|
||||
|
||||
/**
|
||||
* Write any necessary closing text.
|
||||
@ -385,8 +437,9 @@ public class PdePreprocessor {
|
||||
* @param out PrintStream to write it to.
|
||||
*/
|
||||
void writeFooter(PrintStream out) {
|
||||
//out.print("}");
|
||||
|
||||
if (programType == STATIC) {
|
||||
/* if (programType == STATIC) {
|
||||
// close off draw() definition
|
||||
out.print("noLoop(); ");
|
||||
out.print("}");
|
||||
@ -396,7 +449,7 @@ public class PdePreprocessor {
|
||||
// close off the class definition
|
||||
out.print("}");
|
||||
}
|
||||
}
|
||||
*/ }
|
||||
|
||||
|
||||
static String advClassName = "";
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,163 +0,0 @@
|
||||
// $ANTLR 2.7.2: "expandedpde.g" -> "PdeRecognizer.java"$
|
||||
|
||||
package processing.app.preproc;
|
||||
|
||||
import processing.app.*;
|
||||
|
||||
public interface PdeTokenTypes {
|
||||
int EOF = 1;
|
||||
int NULL_TREE_LOOKAHEAD = 3;
|
||||
int BLOCK = 4;
|
||||
int MODIFIERS = 5;
|
||||
int OBJBLOCK = 6;
|
||||
int SLIST = 7;
|
||||
int CTOR_DEF = 8;
|
||||
int METHOD_DEF = 9;
|
||||
int VARIABLE_DEF = 10;
|
||||
int INSTANCE_INIT = 11;
|
||||
int STATIC_INIT = 12;
|
||||
int TYPE = 13;
|
||||
int CLASS_DEF = 14;
|
||||
int INTERFACE_DEF = 15;
|
||||
int PACKAGE_DEF = 16;
|
||||
int ARRAY_DECLARATOR = 17;
|
||||
int EXTENDS_CLAUSE = 18;
|
||||
int IMPLEMENTS_CLAUSE = 19;
|
||||
int PARAMETERS = 20;
|
||||
int PARAMETER_DEF = 21;
|
||||
int LABELED_STAT = 22;
|
||||
int TYPECAST = 23;
|
||||
int INDEX_OP = 24;
|
||||
int POST_INC = 25;
|
||||
int POST_DEC = 26;
|
||||
int METHOD_CALL = 27;
|
||||
int EXPR = 28;
|
||||
int ARRAY_INIT = 29;
|
||||
int IMPORT = 30;
|
||||
int UNARY_MINUS = 31;
|
||||
int UNARY_PLUS = 32;
|
||||
int CASE_GROUP = 33;
|
||||
int ELIST = 34;
|
||||
int FOR_INIT = 35;
|
||||
int FOR_CONDITION = 36;
|
||||
int FOR_ITERATOR = 37;
|
||||
int EMPTY_STAT = 38;
|
||||
int FINAL = 39;
|
||||
int ABSTRACT = 40;
|
||||
int STRICTFP = 41;
|
||||
int SUPER_CTOR_CALL = 42;
|
||||
int CTOR_CALL = 43;
|
||||
int LITERAL_package = 44;
|
||||
int SEMI = 45;
|
||||
int LITERAL_import = 46;
|
||||
int LBRACK = 47;
|
||||
int RBRACK = 48;
|
||||
int LITERAL_void = 49;
|
||||
int LITERAL_boolean = 50;
|
||||
int LITERAL_byte = 51;
|
||||
int LITERAL_char = 52;
|
||||
int LITERAL_short = 53;
|
||||
int LITERAL_int = 54;
|
||||
int LITERAL_float = 55;
|
||||
int LITERAL_long = 56;
|
||||
int LITERAL_double = 57;
|
||||
int IDENT = 58;
|
||||
int DOT = 59;
|
||||
int STAR = 60;
|
||||
int LITERAL_private = 61;
|
||||
int LITERAL_public = 62;
|
||||
int LITERAL_protected = 63;
|
||||
int LITERAL_static = 64;
|
||||
int LITERAL_transient = 65;
|
||||
int LITERAL_native = 66;
|
||||
int LITERAL_threadsafe = 67;
|
||||
int LITERAL_synchronized = 68;
|
||||
int LITERAL_volatile = 69;
|
||||
int LITERAL_class = 70;
|
||||
int LITERAL_extends = 71;
|
||||
int LITERAL_interface = 72;
|
||||
int LCURLY = 73;
|
||||
int RCURLY = 74;
|
||||
int COMMA = 75;
|
||||
int LITERAL_implements = 76;
|
||||
int LPAREN = 77;
|
||||
int RPAREN = 78;
|
||||
int LITERAL_this = 79;
|
||||
int LITERAL_super = 80;
|
||||
int ASSIGN = 81;
|
||||
int LITERAL_throws = 82;
|
||||
int COLON = 83;
|
||||
int LITERAL_if = 84;
|
||||
int LITERAL_else = 85;
|
||||
int LITERAL_for = 86;
|
||||
int LITERAL_while = 87;
|
||||
int LITERAL_do = 88;
|
||||
int LITERAL_break = 89;
|
||||
int LITERAL_continue = 90;
|
||||
int LITERAL_return = 91;
|
||||
int LITERAL_switch = 92;
|
||||
int LITERAL_throw = 93;
|
||||
int LITERAL_assert = 94;
|
||||
int LITERAL_case = 95;
|
||||
int LITERAL_default = 96;
|
||||
int LITERAL_try = 97;
|
||||
int LITERAL_finally = 98;
|
||||
int LITERAL_catch = 99;
|
||||
int PLUS_ASSIGN = 100;
|
||||
int MINUS_ASSIGN = 101;
|
||||
int STAR_ASSIGN = 102;
|
||||
int DIV_ASSIGN = 103;
|
||||
int MOD_ASSIGN = 104;
|
||||
int SR_ASSIGN = 105;
|
||||
int BSR_ASSIGN = 106;
|
||||
int SL_ASSIGN = 107;
|
||||
int BAND_ASSIGN = 108;
|
||||
int BXOR_ASSIGN = 109;
|
||||
int BOR_ASSIGN = 110;
|
||||
int QUESTION = 111;
|
||||
int LOR = 112;
|
||||
int LAND = 113;
|
||||
int BOR = 114;
|
||||
int BXOR = 115;
|
||||
int BAND = 116;
|
||||
int NOT_EQUAL = 117;
|
||||
int EQUAL = 118;
|
||||
int LT = 119;
|
||||
int GT = 120;
|
||||
int LE = 121;
|
||||
int GE = 122;
|
||||
int LITERAL_instanceof = 123;
|
||||
int SL = 124;
|
||||
int SR = 125;
|
||||
int BSR = 126;
|
||||
int PLUS = 127;
|
||||
int MINUS = 128;
|
||||
int DIV = 129;
|
||||
int MOD = 130;
|
||||
int INC = 131;
|
||||
int DEC = 132;
|
||||
int BNOT = 133;
|
||||
int LNOT = 134;
|
||||
int LITERAL_true = 135;
|
||||
int LITERAL_false = 136;
|
||||
int LITERAL_null = 137;
|
||||
int LITERAL_new = 138;
|
||||
int NUM_INT = 139;
|
||||
int CHAR_LITERAL = 140;
|
||||
int STRING_LITERAL = 141;
|
||||
int NUM_FLOAT = 142;
|
||||
int NUM_LONG = 143;
|
||||
int NUM_DOUBLE = 144;
|
||||
int WS = 145;
|
||||
int SL_COMMENT = 146;
|
||||
int ML_COMMENT = 147;
|
||||
int ESC = 148;
|
||||
int HEX_DIGIT = 149;
|
||||
int VOCAB = 150;
|
||||
int EXPONENT = 151;
|
||||
int FLOAT_SUFFIX = 152;
|
||||
int CONSTRUCTOR_CAST = 153;
|
||||
int EMPTY_FIELD = 154;
|
||||
int WEBCOLOR_LITERAL = 155;
|
||||
int LITERAL_color = 156;
|
||||
}
|
@ -1,155 +0,0 @@
|
||||
// $ANTLR 2.7.2: expandedpde.g -> PdeTokenTypes.txt$
|
||||
Pde // output token vocab name
|
||||
BLOCK=4
|
||||
MODIFIERS=5
|
||||
OBJBLOCK=6
|
||||
SLIST=7
|
||||
CTOR_DEF=8
|
||||
METHOD_DEF=9
|
||||
VARIABLE_DEF=10
|
||||
INSTANCE_INIT=11
|
||||
STATIC_INIT=12
|
||||
TYPE=13
|
||||
CLASS_DEF=14
|
||||
INTERFACE_DEF=15
|
||||
PACKAGE_DEF=16
|
||||
ARRAY_DECLARATOR=17
|
||||
EXTENDS_CLAUSE=18
|
||||
IMPLEMENTS_CLAUSE=19
|
||||
PARAMETERS=20
|
||||
PARAMETER_DEF=21
|
||||
LABELED_STAT=22
|
||||
TYPECAST=23
|
||||
INDEX_OP=24
|
||||
POST_INC=25
|
||||
POST_DEC=26
|
||||
METHOD_CALL=27
|
||||
EXPR=28
|
||||
ARRAY_INIT=29
|
||||
IMPORT=30
|
||||
UNARY_MINUS=31
|
||||
UNARY_PLUS=32
|
||||
CASE_GROUP=33
|
||||
ELIST=34
|
||||
FOR_INIT=35
|
||||
FOR_CONDITION=36
|
||||
FOR_ITERATOR=37
|
||||
EMPTY_STAT=38
|
||||
FINAL="final"=39
|
||||
ABSTRACT="abstract"=40
|
||||
STRICTFP="strictfp"=41
|
||||
SUPER_CTOR_CALL=42
|
||||
CTOR_CALL=43
|
||||
LITERAL_package="package"=44
|
||||
SEMI=45
|
||||
LITERAL_import="import"=46
|
||||
LBRACK=47
|
||||
RBRACK=48
|
||||
LITERAL_void="void"=49
|
||||
LITERAL_boolean="boolean"=50
|
||||
LITERAL_byte="byte"=51
|
||||
LITERAL_char="char"=52
|
||||
LITERAL_short="short"=53
|
||||
LITERAL_int="int"=54
|
||||
LITERAL_float="float"=55
|
||||
LITERAL_long="long"=56
|
||||
LITERAL_double="double"=57
|
||||
IDENT=58
|
||||
DOT=59
|
||||
STAR=60
|
||||
LITERAL_private="private"=61
|
||||
LITERAL_public="public"=62
|
||||
LITERAL_protected="protected"=63
|
||||
LITERAL_static="static"=64
|
||||
LITERAL_transient="transient"=65
|
||||
LITERAL_native="native"=66
|
||||
LITERAL_threadsafe="threadsafe"=67
|
||||
LITERAL_synchronized="synchronized"=68
|
||||
LITERAL_volatile="volatile"=69
|
||||
LITERAL_class="class"=70
|
||||
LITERAL_extends="extends"=71
|
||||
LITERAL_interface="interface"=72
|
||||
LCURLY=73
|
||||
RCURLY=74
|
||||
COMMA=75
|
||||
LITERAL_implements="implements"=76
|
||||
LPAREN=77
|
||||
RPAREN=78
|
||||
LITERAL_this="this"=79
|
||||
LITERAL_super="super"=80
|
||||
ASSIGN=81
|
||||
LITERAL_throws="throws"=82
|
||||
COLON=83
|
||||
LITERAL_if="if"=84
|
||||
LITERAL_else="else"=85
|
||||
LITERAL_for="for"=86
|
||||
LITERAL_while="while"=87
|
||||
LITERAL_do="do"=88
|
||||
LITERAL_break="break"=89
|
||||
LITERAL_continue="continue"=90
|
||||
LITERAL_return="return"=91
|
||||
LITERAL_switch="switch"=92
|
||||
LITERAL_throw="throw"=93
|
||||
LITERAL_assert="assert"=94
|
||||
LITERAL_case="case"=95
|
||||
LITERAL_default="default"=96
|
||||
LITERAL_try="try"=97
|
||||
LITERAL_finally="finally"=98
|
||||
LITERAL_catch="catch"=99
|
||||
PLUS_ASSIGN=100
|
||||
MINUS_ASSIGN=101
|
||||
STAR_ASSIGN=102
|
||||
DIV_ASSIGN=103
|
||||
MOD_ASSIGN=104
|
||||
SR_ASSIGN=105
|
||||
BSR_ASSIGN=106
|
||||
SL_ASSIGN=107
|
||||
BAND_ASSIGN=108
|
||||
BXOR_ASSIGN=109
|
||||
BOR_ASSIGN=110
|
||||
QUESTION=111
|
||||
LOR=112
|
||||
LAND=113
|
||||
BOR=114
|
||||
BXOR=115
|
||||
BAND=116
|
||||
NOT_EQUAL=117
|
||||
EQUAL=118
|
||||
LT=119
|
||||
GT=120
|
||||
LE=121
|
||||
GE=122
|
||||
LITERAL_instanceof="instanceof"=123
|
||||
SL=124
|
||||
SR=125
|
||||
BSR=126
|
||||
PLUS=127
|
||||
MINUS=128
|
||||
DIV=129
|
||||
MOD=130
|
||||
INC=131
|
||||
DEC=132
|
||||
BNOT=133
|
||||
LNOT=134
|
||||
LITERAL_true="true"=135
|
||||
LITERAL_false="false"=136
|
||||
LITERAL_null="null"=137
|
||||
LITERAL_new="new"=138
|
||||
NUM_INT=139
|
||||
CHAR_LITERAL=140
|
||||
STRING_LITERAL=141
|
||||
NUM_FLOAT=142
|
||||
NUM_LONG=143
|
||||
NUM_DOUBLE=144
|
||||
WS=145
|
||||
SL_COMMENT=146
|
||||
ML_COMMENT=147
|
||||
ESC=148
|
||||
HEX_DIGIT=149
|
||||
VOCAB=150
|
||||
EXPONENT=151
|
||||
FLOAT_SUFFIX=152
|
||||
CONSTRUCTOR_CAST=153
|
||||
EMPTY_FIELD=154
|
||||
WEBCOLOR_LITERAL=155
|
||||
LITERAL_color="color"=156
|
73
app/preproc/PreprocessorInfoChannel.java
Executable file
73
app/preproc/PreprocessorInfoChannel.java
Executable file
@ -0,0 +1,73 @@
|
||||
package processing.app.preproc;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PreprocessorInfoChannel
|
||||
{
|
||||
Hashtable lineLists = new Hashtable(); // indexed by Token number
|
||||
int firstValidTokenNumber = 0;
|
||||
int maxTokenNumber = 0;
|
||||
|
||||
public void addLineForTokenNumber( Object line, Integer toknum )
|
||||
{
|
||||
if ( lineLists.containsKey( toknum ) ) {
|
||||
Vector lines = (Vector) lineLists.get( toknum );
|
||||
lines.addElement(line);
|
||||
}
|
||||
else {
|
||||
Vector lines = new Vector();
|
||||
lines.addElement(line);
|
||||
lineLists.put(toknum, lines);
|
||||
if ( maxTokenNumber < toknum.intValue() ) {
|
||||
maxTokenNumber = toknum.intValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getMaxTokenNumber()
|
||||
{
|
||||
return maxTokenNumber;
|
||||
}
|
||||
|
||||
public Vector extractLinesPrecedingTokenNumber( Integer toknum )
|
||||
{
|
||||
Vector lines = new Vector();
|
||||
if (toknum == null) return lines;
|
||||
for (int i = firstValidTokenNumber; i < toknum.intValue(); i++){
|
||||
Integer inti = new Integer(i);
|
||||
if ( lineLists.containsKey( inti ) ) {
|
||||
Vector tokenLineVector = (Vector) lineLists.get( inti );
|
||||
if ( tokenLineVector != null) {
|
||||
Enumeration tokenLines = tokenLineVector.elements();
|
||||
while ( tokenLines.hasMoreElements() ) {
|
||||
lines.addElement( tokenLines.nextElement() );
|
||||
}
|
||||
lineLists.remove(inti);
|
||||
}
|
||||
}
|
||||
}
|
||||
firstValidTokenNumber = toknum.intValue();
|
||||
return lines;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("PreprocessorInfoChannel:\n");
|
||||
for (int i = 0; i <= maxTokenNumber + 1; i++){
|
||||
Integer inti = new Integer(i);
|
||||
if ( lineLists.containsKey( inti ) ) {
|
||||
Vector tokenLineVector = (Vector) lineLists.get( inti );
|
||||
if ( tokenLineVector != null) {
|
||||
Enumeration tokenLines = tokenLineVector.elements();
|
||||
while ( tokenLines.hasMoreElements() ) {
|
||||
sb.append(inti + ":" + tokenLines.nextElement() + '\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,106 +0,0 @@
|
||||
The PDE Preprocessor is based on the Java Grammar that comes with
|
||||
ANTLR 2.7.2. Moving it forward to a new version of the grammar
|
||||
shouldn't be too difficult.
|
||||
|
||||
Here's some info about the various files in this directory:
|
||||
|
||||
java.g: this is the ANTLR grammar for Java 1.3/1.4 from the ANTLR
|
||||
distribution. It is in the public domain. The only change to this
|
||||
file from the original this file is the uncommenting of the clauses
|
||||
required to support assert().
|
||||
|
||||
java.tree.g: this describes the Abstract Syntax Tree (AST) generated
|
||||
by java.g. It is only here as a reference for coders hacking on the
|
||||
preprocessor, it is not built or used at all. Note that pde.g
|
||||
overrides some of the java.g rules so that in PDE ASTs, there are a
|
||||
few minor differences. Also in the public domain.
|
||||
|
||||
pde.g: this is the grammar and lexer for the PDE language itself. It
|
||||
subclasses the java.g grammar and lexer. There are a couple of
|
||||
overrides to java.g that I hope to convince the ANTLR folks to fold
|
||||
back into their grammar, but most of this file is highly specific to
|
||||
PDE itself.
|
||||
|
||||
PdeEmitter.java: this class traverses the AST generated by the PDE
|
||||
Recognizer, and emits it as Java code, doing any necessary
|
||||
transformations along the way. It is based on JavaEmitter.java,
|
||||
available from antlr.org, written by Andy Tripp <atripp@comcast.net>,
|
||||
who has given permission for it to be distributed under the GPL.
|
||||
|
||||
ExtendedCommonASTWithHiddenTokens.java: this adds a necessary
|
||||
initialize() method, as well as a number of methods to allow for XML
|
||||
serialization of the parse tree in a such a way that the hidden tokens
|
||||
are visible. Much of the code is taken from the original
|
||||
CommonASTWithHiddenTokens class. I hope to convince the ANTLR folks
|
||||
to fold these changes back into that class so that this file will be
|
||||
unnecessary.
|
||||
|
||||
TokenStreamCopyingHiddenTokenFilter.java: this class provides
|
||||
TokenStreamHiddenTokenFilters with the concept of tokens which can be
|
||||
copied so that they are seen by both the hidden token stream as well
|
||||
as the parser itself. This is useful when one wants to use an
|
||||
existing parser (like the Java parser included with ANTLR) that throws
|
||||
away some tokens to create a parse tree which can be used to spit out
|
||||
a copy of the code with only minor modifications. Partially derived
|
||||
from ANTLR code. I hope to convince the ANTLR folks to fold this
|
||||
functionality back into ANTLR proper as well.
|
||||
|
||||
whitespace_test.pde: a torture test to ensure that the preprocessor is
|
||||
correctly preserving whitespace, comments, and other hidden tokens
|
||||
correctly. See the comments in the code for details about how to run
|
||||
the test.
|
||||
|
||||
All other files in this directory are generated at build time by ANTLR
|
||||
itself. The ANTLR manual goes into a fair amount of detail about the
|
||||
what each type of file is for.
|
||||
|
||||
|
||||
....
|
||||
|
||||
|
||||
Current Preprocessor Subsitutions:
|
||||
|
||||
"compiler.substitute_floats" (currently "substitute_f")
|
||||
- treat doubles as floats, i.e. 12.3 becomes 12.3f so that people
|
||||
don't have to add f after their numbers all the time. this is
|
||||
confusing for beginners.
|
||||
|
||||
"compiler.enhanced_casting"
|
||||
- byte(), char(), int(), float() works for casting. this is basic in
|
||||
the current implementation, but should be expanded as described
|
||||
above. color() works similarly to int(), however there is also a
|
||||
*function* called color(r, g, b) in p5. will this cause trouble?
|
||||
|
||||
"compiler.color_datattype"
|
||||
- 'color' is aliased to 'int' as a datatype to represent ARGB packed
|
||||
into a single int, commonly used in p5 for pixels[] and other color
|
||||
operations. this is just a search/replace type thing, and it can be
|
||||
used interchangeably with int.
|
||||
|
||||
"compiler.web_colors" (currently "inline_web_colors")
|
||||
- color c = #cc0080; should unpack to 0xffcc0080 (the ff at the top is
|
||||
so that the color is opaque), which is just an int.
|
||||
|
||||
Other preprocessor functionality
|
||||
|
||||
- detects what 'mode' the program is in: static (no function brackets
|
||||
at all, just assumes everything is in draw), active (setup plus draw
|
||||
or loop), and java mode (full java support).
|
||||
http://proce55ing.net/reference/environment/index.html
|
||||
|
||||
- size and background are pulled from draw mode programs and placed
|
||||
into setup(). this has a problem if size() is based on a variable,
|
||||
which we try to avoid people doing, but would like to be able to
|
||||
support it (perhaps by requiring the size() to be final?)
|
||||
|
||||
- currently does a godawful scrambling of the comments so that the
|
||||
substitution doesn't try to run on them. this also causes lots of
|
||||
bizarro bugs.
|
||||
|
||||
Possible?
|
||||
|
||||
- would be nice to just type code wherever, mixing a 'static' style
|
||||
app with a few functions. would be simpler for starting out. but it
|
||||
seems that the declarations would have to be pulled out, but that
|
||||
all seems problematic. or maybe it could all be inside a static { }
|
||||
block. but that wouldn't seem to work either.
|
149
app/preproc/STDCTokenTypes.java
Normal file
149
app/preproc/STDCTokenTypes.java
Normal file
@ -0,0 +1,149 @@
|
||||
// $ANTLR 2.7.2: "StdCParser.g" -> "StdCLexer.java"$
|
||||
|
||||
package processing.app.preproc;
|
||||
import java.io.*;
|
||||
|
||||
import antlr.CommonAST;
|
||||
import antlr.DumpASTVisitor;
|
||||
|
||||
public interface STDCTokenTypes {
|
||||
int EOF = 1;
|
||||
int NULL_TREE_LOOKAHEAD = 3;
|
||||
int LITERAL_typedef = 4;
|
||||
int LITERAL_asm = 5;
|
||||
int LITERAL_volatile = 6;
|
||||
int LCURLY = 7;
|
||||
int RCURLY = 8;
|
||||
int SEMI = 9;
|
||||
int LITERAL_struct = 10;
|
||||
int LITERAL_union = 11;
|
||||
int LITERAL_enum = 12;
|
||||
int LITERAL_auto = 13;
|
||||
int LITERAL_register = 14;
|
||||
int LITERAL_extern = 15;
|
||||
int LITERAL_static = 16;
|
||||
int LITERAL_const = 17;
|
||||
int LITERAL_void = 18;
|
||||
int LITERAL_char = 19;
|
||||
int LITERAL_short = 20;
|
||||
int LITERAL_int = 21;
|
||||
int LITERAL_long = 22;
|
||||
int LITERAL_float = 23;
|
||||
int LITERAL_double = 24;
|
||||
int LITERAL_signed = 25;
|
||||
int LITERAL_unsigned = 26;
|
||||
int ID = 27;
|
||||
int COMMA = 28;
|
||||
int COLON = 29;
|
||||
int ASSIGN = 30;
|
||||
int STAR = 31;
|
||||
int LPAREN = 32;
|
||||
int RPAREN = 33;
|
||||
int LBRACKET = 34;
|
||||
int RBRACKET = 35;
|
||||
int VARARGS = 36;
|
||||
int LITERAL_while = 37;
|
||||
int LITERAL_do = 38;
|
||||
int LITERAL_for = 39;
|
||||
int LITERAL_goto = 40;
|
||||
int LITERAL_continue = 41;
|
||||
int LITERAL_break = 42;
|
||||
int LITERAL_return = 43;
|
||||
int LITERAL_case = 44;
|
||||
int LITERAL_default = 45;
|
||||
int LITERAL_if = 46;
|
||||
int LITERAL_else = 47;
|
||||
int LITERAL_switch = 48;
|
||||
int DIV_ASSIGN = 49;
|
||||
int PLUS_ASSIGN = 50;
|
||||
int MINUS_ASSIGN = 51;
|
||||
int STAR_ASSIGN = 52;
|
||||
int MOD_ASSIGN = 53;
|
||||
int RSHIFT_ASSIGN = 54;
|
||||
int LSHIFT_ASSIGN = 55;
|
||||
int BAND_ASSIGN = 56;
|
||||
int BOR_ASSIGN = 57;
|
||||
int BXOR_ASSIGN = 58;
|
||||
int QUESTION = 59;
|
||||
int LOR = 60;
|
||||
int LAND = 61;
|
||||
int BOR = 62;
|
||||
int BXOR = 63;
|
||||
int BAND = 64;
|
||||
int EQUAL = 65;
|
||||
int NOT_EQUAL = 66;
|
||||
int LT = 67;
|
||||
int LTE = 68;
|
||||
int GT = 69;
|
||||
int GTE = 70;
|
||||
int LSHIFT = 71;
|
||||
int RSHIFT = 72;
|
||||
int PLUS = 73;
|
||||
int MINUS = 74;
|
||||
int DIV = 75;
|
||||
int MOD = 76;
|
||||
int INC = 77;
|
||||
int DEC = 78;
|
||||
int LITERAL_sizeof = 79;
|
||||
int BNOT = 80;
|
||||
int LNOT = 81;
|
||||
int PTR = 82;
|
||||
int DOT = 83;
|
||||
int CharLiteral = 84;
|
||||
int StringLiteral = 85;
|
||||
int IntOctalConst = 86;
|
||||
int LongOctalConst = 87;
|
||||
int UnsignedOctalConst = 88;
|
||||
int IntIntConst = 89;
|
||||
int LongIntConst = 90;
|
||||
int UnsignedIntConst = 91;
|
||||
int IntHexConst = 92;
|
||||
int LongHexConst = 93;
|
||||
int UnsignedHexConst = 94;
|
||||
int FloatDoubleConst = 95;
|
||||
int DoubleDoubleConst = 96;
|
||||
int LongDoubleConst = 97;
|
||||
int NTypedefName = 98;
|
||||
int NInitDecl = 99;
|
||||
int NDeclarator = 100;
|
||||
int NStructDeclarator = 101;
|
||||
int NDeclaration = 102;
|
||||
int NCast = 103;
|
||||
int NPointerGroup = 104;
|
||||
int NExpressionGroup = 105;
|
||||
int NFunctionCallArgs = 106;
|
||||
int NNonemptyAbstractDeclarator = 107;
|
||||
int NInitializer = 108;
|
||||
int NStatementExpr = 109;
|
||||
int NEmptyExpression = 110;
|
||||
int NParameterTypeList = 111;
|
||||
int NFunctionDef = 112;
|
||||
int NCompoundStatement = 113;
|
||||
int NParameterDeclaration = 114;
|
||||
int NCommaExpr = 115;
|
||||
int NUnaryExpr = 116;
|
||||
int NLabel = 117;
|
||||
int NPostfixExpr = 118;
|
||||
int NRangeExpr = 119;
|
||||
int NStringSeq = 120;
|
||||
int NInitializerElementLabel = 121;
|
||||
int NLcurlyInitializer = 122;
|
||||
int NAsmAttribute = 123;
|
||||
int NGnuAsmExpr = 124;
|
||||
int NTypeMissing = 125;
|
||||
int Vocabulary = 126;
|
||||
int Whitespace = 127;
|
||||
int Comment = 128;
|
||||
int CPPComment = 129;
|
||||
int PREPROC_DIRECTIVE = 130;
|
||||
int Space = 131;
|
||||
int LineDirective = 132;
|
||||
int BadStringLiteral = 133;
|
||||
int Escape = 134;
|
||||
int Digit = 135;
|
||||
int LongSuffix = 136;
|
||||
int UnsignedSuffix = 137;
|
||||
int FloatSuffix = 138;
|
||||
int Exponent = 139;
|
||||
int Number = 140;
|
||||
}
|
139
app/preproc/STDCTokenTypes.txt
Normal file
139
app/preproc/STDCTokenTypes.txt
Normal file
@ -0,0 +1,139 @@
|
||||
// $ANTLR 2.7.2: StdCParser.g -> STDCTokenTypes.txt$
|
||||
STDC // output token vocab name
|
||||
LITERAL_typedef="typedef"=4
|
||||
LITERAL_asm="asm"=5
|
||||
LITERAL_volatile="volatile"=6
|
||||
LCURLY=7
|
||||
RCURLY=8
|
||||
SEMI=9
|
||||
LITERAL_struct="struct"=10
|
||||
LITERAL_union="union"=11
|
||||
LITERAL_enum="enum"=12
|
||||
LITERAL_auto="auto"=13
|
||||
LITERAL_register="register"=14
|
||||
LITERAL_extern="extern"=15
|
||||
LITERAL_static="static"=16
|
||||
LITERAL_const="const"=17
|
||||
LITERAL_void="void"=18
|
||||
LITERAL_char="char"=19
|
||||
LITERAL_short="short"=20
|
||||
LITERAL_int="int"=21
|
||||
LITERAL_long="long"=22
|
||||
LITERAL_float="float"=23
|
||||
LITERAL_double="double"=24
|
||||
LITERAL_signed="signed"=25
|
||||
LITERAL_unsigned="unsigned"=26
|
||||
ID=27
|
||||
COMMA=28
|
||||
COLON=29
|
||||
ASSIGN=30
|
||||
STAR=31
|
||||
LPAREN=32
|
||||
RPAREN=33
|
||||
LBRACKET=34
|
||||
RBRACKET=35
|
||||
VARARGS=36
|
||||
LITERAL_while="while"=37
|
||||
LITERAL_do="do"=38
|
||||
LITERAL_for="for"=39
|
||||
LITERAL_goto="goto"=40
|
||||
LITERAL_continue="continue"=41
|
||||
LITERAL_break="break"=42
|
||||
LITERAL_return="return"=43
|
||||
LITERAL_case="case"=44
|
||||
LITERAL_default="default"=45
|
||||
LITERAL_if="if"=46
|
||||
LITERAL_else="else"=47
|
||||
LITERAL_switch="switch"=48
|
||||
DIV_ASSIGN=49
|
||||
PLUS_ASSIGN=50
|
||||
MINUS_ASSIGN=51
|
||||
STAR_ASSIGN=52
|
||||
MOD_ASSIGN=53
|
||||
RSHIFT_ASSIGN=54
|
||||
LSHIFT_ASSIGN=55
|
||||
BAND_ASSIGN=56
|
||||
BOR_ASSIGN=57
|
||||
BXOR_ASSIGN=58
|
||||
QUESTION=59
|
||||
LOR=60
|
||||
LAND=61
|
||||
BOR=62
|
||||
BXOR=63
|
||||
BAND=64
|
||||
EQUAL=65
|
||||
NOT_EQUAL=66
|
||||
LT=67
|
||||
LTE=68
|
||||
GT=69
|
||||
GTE=70
|
||||
LSHIFT=71
|
||||
RSHIFT=72
|
||||
PLUS=73
|
||||
MINUS=74
|
||||
DIV=75
|
||||
MOD=76
|
||||
INC=77
|
||||
DEC=78
|
||||
LITERAL_sizeof="sizeof"=79
|
||||
BNOT=80
|
||||
LNOT=81
|
||||
PTR=82
|
||||
DOT=83
|
||||
CharLiteral=84
|
||||
StringLiteral=85
|
||||
IntOctalConst=86
|
||||
LongOctalConst=87
|
||||
UnsignedOctalConst=88
|
||||
IntIntConst=89
|
||||
LongIntConst=90
|
||||
UnsignedIntConst=91
|
||||
IntHexConst=92
|
||||
LongHexConst=93
|
||||
UnsignedHexConst=94
|
||||
FloatDoubleConst=95
|
||||
DoubleDoubleConst=96
|
||||
LongDoubleConst=97
|
||||
NTypedefName=98
|
||||
NInitDecl=99
|
||||
NDeclarator=100
|
||||
NStructDeclarator=101
|
||||
NDeclaration=102
|
||||
NCast=103
|
||||
NPointerGroup=104
|
||||
NExpressionGroup=105
|
||||
NFunctionCallArgs=106
|
||||
NNonemptyAbstractDeclarator=107
|
||||
NInitializer=108
|
||||
NStatementExpr=109
|
||||
NEmptyExpression=110
|
||||
NParameterTypeList=111
|
||||
NFunctionDef=112
|
||||
NCompoundStatement=113
|
||||
NParameterDeclaration=114
|
||||
NCommaExpr=115
|
||||
NUnaryExpr=116
|
||||
NLabel=117
|
||||
NPostfixExpr=118
|
||||
NRangeExpr=119
|
||||
NStringSeq=120
|
||||
NInitializerElementLabel=121
|
||||
NLcurlyInitializer=122
|
||||
NAsmAttribute=123
|
||||
NGnuAsmExpr=124
|
||||
NTypeMissing=125
|
||||
Vocabulary=126
|
||||
Whitespace=127
|
||||
Comment=128
|
||||
CPPComment=129
|
||||
PREPROC_DIRECTIVE("a line directive")=130
|
||||
Space=131
|
||||
LineDirective=132
|
||||
BadStringLiteral=133
|
||||
Escape=134
|
||||
Digit=135
|
||||
LongSuffix=136
|
||||
UnsignedSuffix=137
|
||||
FloatSuffix=138
|
||||
Exponent=139
|
||||
Number=140
|
File diff suppressed because it is too large
Load Diff
1358
app/preproc/StdCParser.g
Executable file
1358
app/preproc/StdCParser.g
Executable file
File diff suppressed because it is too large
Load Diff
5886
app/preproc/StdCParser.java
Normal file
5886
app/preproc/StdCParser.java
Normal file
File diff suppressed because it is too large
Load Diff
434
app/preproc/TNode.java
Executable file
434
app/preproc/TNode.java
Executable file
@ -0,0 +1,434 @@
|
||||
package processing.app.preproc;
|
||||
|
||||
import antlr.collections.AST;
|
||||
import antlr.CommonAST;
|
||||
import antlr.Token;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
//import CToken;
|
||||
|
||||
/**
|
||||
Class TNode is an implementation of the AST interface
|
||||
and adds many useful features:
|
||||
|
||||
It is double-linked for reverse searching.
|
||||
(this is currently incomplete, in that method doubleLink() must
|
||||
be called after any changes to the tree to maintain the
|
||||
reverse links).
|
||||
|
||||
It can store a definition node (defNode), so that nodes such
|
||||
as scoped names can refer to the node that defines the name.
|
||||
|
||||
It stores line numbers for nodes.
|
||||
|
||||
Searches for parents and children of a tree can be done
|
||||
based on their type.
|
||||
|
||||
The tree can be printed to System.out using a lisp-style syntax.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
public class TNode extends CommonAST {
|
||||
protected int ttype;
|
||||
protected String text;
|
||||
protected int lineNum = 0;
|
||||
protected TNode defNode;
|
||||
protected TNode up;
|
||||
protected TNode left;
|
||||
protected boolean marker = false;
|
||||
protected Hashtable attributes = null;
|
||||
static String tokenVocabulary;
|
||||
|
||||
|
||||
|
||||
|
||||
/** Set the token vocabulary to a tokentypes class
|
||||
generated by antlr.
|
||||
*/
|
||||
public static void setTokenVocabulary(String s) {
|
||||
tokenVocabulary = s;
|
||||
}
|
||||
|
||||
|
||||
public void initialize(Token token) {
|
||||
CToken tok = (CToken) token;
|
||||
setText(tok.getText());
|
||||
setType(tok.getType());
|
||||
setLineNum(tok.getLine());
|
||||
setAttribute("source", tok.getSource());
|
||||
setAttribute("tokenNumber", new Integer(tok.getTokenNumber()));
|
||||
}
|
||||
public void initialize(AST tr) {
|
||||
TNode t = (TNode) tr;
|
||||
setText(t.getText());
|
||||
setType(t.getType());
|
||||
setLineNum(t.getLineNum());
|
||||
setDefNode(t.getDefNode());
|
||||
this.attributes = t.getAttributesTable();
|
||||
}
|
||||
|
||||
|
||||
/** Get the token type for this node */
|
||||
public int getType() { return ttype; }
|
||||
|
||||
/** Set the token type for this node */
|
||||
public void setType(int ttype_) {
|
||||
ttype = ttype_;
|
||||
}
|
||||
|
||||
/** Get the marker value for this node.
|
||||
This member is a general-use marker.
|
||||
*/
|
||||
public boolean getMarker() { return marker; }
|
||||
|
||||
/** Set the marker value for this node.
|
||||
This property is a general-use boolean marker.
|
||||
*/
|
||||
public void setMarker(boolean marker_) {
|
||||
marker = marker_;
|
||||
}
|
||||
|
||||
/** get the hashtable that holds attribute values.
|
||||
*/
|
||||
public Hashtable getAttributesTable() {
|
||||
if(attributes == null)
|
||||
attributes = new Hashtable(7);
|
||||
return attributes;
|
||||
}
|
||||
|
||||
/** set an attribute in the attribute table.
|
||||
*/
|
||||
public void setAttribute(String attrName, Object value) {
|
||||
if(attributes == null)
|
||||
attributes = new Hashtable(7);
|
||||
attributes.put(attrName,value);
|
||||
}
|
||||
|
||||
/** lookup the attribute name in the attribute table.
|
||||
If the value does not exist, it returns null.
|
||||
*/
|
||||
public Object getAttribute(String attrName) {
|
||||
if(attributes == null)
|
||||
return null;
|
||||
else
|
||||
return attributes.get(attrName);
|
||||
}
|
||||
|
||||
/** Get the line number for this node.
|
||||
If the line number is 0, search for a non-zero line num among children */
|
||||
public int getLineNum() {
|
||||
if(lineNum != 0)
|
||||
return lineNum;
|
||||
else
|
||||
if(down == null)
|
||||
return lineNum;
|
||||
else
|
||||
return ((TNode)down).getLocalLineNum();
|
||||
}
|
||||
|
||||
public int getLocalLineNum() {
|
||||
if(lineNum != 0)
|
||||
return lineNum;
|
||||
else
|
||||
if(down == null)
|
||||
if(right == null)
|
||||
return lineNum;
|
||||
else
|
||||
return ((TNode)right).getLocalLineNum();
|
||||
else
|
||||
return ((TNode)down).getLocalLineNum();
|
||||
}
|
||||
|
||||
/** Set the line number for this node */
|
||||
public void setLineNum(int lineNum_) {
|
||||
lineNum = lineNum_;
|
||||
}
|
||||
|
||||
/** Get the token text for this node */
|
||||
public String getText() { return text; }
|
||||
|
||||
/** Set the token text for this node */
|
||||
public void setText(String text_) {
|
||||
text = text_;
|
||||
}
|
||||
|
||||
/** return the last child of this node, or null if there is none */
|
||||
public TNode getLastChild() {
|
||||
TNode down = (TNode)getFirstChild();
|
||||
if(down != null)
|
||||
return down.getLastSibling();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/** return the last sibling of this node, which is
|
||||
this if the next sibling is null */
|
||||
public TNode getLastSibling() {
|
||||
TNode next = (TNode)getNextSibling();
|
||||
if(next != null)
|
||||
return next.getLastSibling();
|
||||
else
|
||||
return this;
|
||||
}
|
||||
|
||||
/** return the first sibling of this node, which is
|
||||
this if the prev sibling is null */
|
||||
public TNode getFirstSibling() {
|
||||
TNode prev = (TNode)left;
|
||||
if(prev != null)
|
||||
return prev.getFirstSibling();
|
||||
else
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/** return the parent node of this node */
|
||||
public TNode getParent() {
|
||||
return (TNode)getFirstSibling().up;
|
||||
}
|
||||
|
||||
|
||||
/** add the new node as a new sibling, inserting it ahead of any
|
||||
existing next sibling. This method maintains double-linking.
|
||||
if node is null, nothing happens. If the node has siblings,
|
||||
then they are added in as well.
|
||||
*/
|
||||
public void addSibling(AST node) {
|
||||
if(node == null) return;
|
||||
TNode next = (TNode)right;
|
||||
right = (TNode)node;
|
||||
((TNode)node).left = this;
|
||||
TNode nodeLastSib = ((TNode)node).getLastSibling();
|
||||
nodeLastSib.right = next;
|
||||
if(next != null)
|
||||
next.left = nodeLastSib;
|
||||
}
|
||||
|
||||
|
||||
/** return the number of children of this node */
|
||||
public int numberOfChildren() {
|
||||
int count = 0;
|
||||
AST child = getFirstChild();
|
||||
while(child != null) {
|
||||
count++;
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/** remove this node from the tree, resetting sibling and parent
|
||||
pointers as necessary. This method maintains double-linking */
|
||||
public void removeSelf() {
|
||||
TNode parent = (TNode)up;
|
||||
TNode prev = (TNode)left;
|
||||
TNode next = (TNode)right;
|
||||
|
||||
if(parent != null) {
|
||||
parent.down = next;
|
||||
if(next != null) {
|
||||
next.up = parent;
|
||||
next.left = prev; // which should be null
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(prev != null)
|
||||
prev.right = next;
|
||||
if(next != null)
|
||||
next.left = prev;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** return the def node for this node */
|
||||
public TNode getDefNode() {
|
||||
return defNode;
|
||||
}
|
||||
|
||||
/** set the def node for this node */
|
||||
public void setDefNode(TNode n) {
|
||||
defNode = n;
|
||||
}
|
||||
|
||||
|
||||
/** return a deep copy of this node, and all sub nodes.
|
||||
New tree is doubleLinked, with no parent or siblings.
|
||||
Marker value is not copied!
|
||||
*/
|
||||
public TNode deepCopy() {
|
||||
TNode copy = new TNode();
|
||||
copy.ttype = ttype;
|
||||
copy.text = text;
|
||||
copy.lineNum = lineNum;
|
||||
copy.defNode = defNode;
|
||||
if(attributes != null)
|
||||
copy.attributes = (Hashtable)attributes.clone();
|
||||
if(down != null)
|
||||
copy.down = ((TNode)down).deepCopyWithRightSiblings();
|
||||
copy.doubleLink();
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
/** return a deep copy of this node, all sub nodes,
|
||||
and right siblings.
|
||||
New tree is doubleLinked, with no parent or left siblings.
|
||||
defNode is not copied */
|
||||
public TNode deepCopyWithRightSiblings() {
|
||||
TNode copy = new TNode();
|
||||
copy.ttype = ttype;
|
||||
copy.text = text;
|
||||
copy.lineNum = lineNum;
|
||||
copy.defNode = defNode;
|
||||
if(attributes != null)
|
||||
copy.attributes = (Hashtable)attributes.clone();
|
||||
if(down != null)
|
||||
copy.down = ((TNode)down).deepCopyWithRightSiblings();
|
||||
if(right != null)
|
||||
copy.right = ((TNode)right).deepCopyWithRightSiblings();
|
||||
copy.doubleLink();
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
/** return a short string representation of the node */
|
||||
public String toString() {
|
||||
StringBuffer str = new StringBuffer( getNameForType(getType()) +
|
||||
"[" + getText() + ", " + "]");
|
||||
|
||||
if(this.getLineNum() != 0)
|
||||
str.append(" line:" + (this.getLineNum() ) );
|
||||
|
||||
Enumeration keys = (this.getAttributesTable().keys());
|
||||
while (keys.hasMoreElements()) {
|
||||
String key = (String) keys.nextElement();
|
||||
str.append(" " + key + ":" + (this.getAttribute(key)));
|
||||
}
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
|
||||
/** print given tree to System.out */
|
||||
public static void printTree(AST t) {
|
||||
if (t == null) return;
|
||||
printASTNode(t,0);
|
||||
System.out.print("\n");
|
||||
}
|
||||
|
||||
|
||||
/** protected method that does the work of printing */
|
||||
protected static void printASTNode(AST t, int indent) {
|
||||
AST child1, next;
|
||||
child1 = t.getFirstChild();
|
||||
|
||||
System.out.print("\n");
|
||||
for(int i = 0; i < indent; i++)
|
||||
System.out.print(" ");
|
||||
|
||||
if(child1 != null)
|
||||
System.out.print("(");
|
||||
|
||||
String s = t.getText();
|
||||
if(s != null && s.length() > 0) {
|
||||
System.out.print(getNameForType(t.getType()));
|
||||
System.out.print(": \"" + s + "\"");
|
||||
}
|
||||
else
|
||||
System.out.print(getNameForType(t.getType()));
|
||||
if(((TNode)t).getLineNum() != 0)
|
||||
System.out.print(" line:" + ((TNode)t).getLineNum() );
|
||||
|
||||
Enumeration keys = ((TNode)t).getAttributesTable().keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
String key = (String) keys.nextElement();
|
||||
System.out.print(" " + key + ":" + ((TNode)t).getAttribute(key));
|
||||
}
|
||||
TNode def = ((TNode)t).getDefNode();
|
||||
if(def != null)
|
||||
System.out.print("[" + getNameForType(def.getType()) + "]");
|
||||
|
||||
|
||||
if(child1 != null) {
|
||||
printASTNode(child1,indent + 1);
|
||||
|
||||
System.out.print("\n");
|
||||
for(int i = 0; i < indent; i++)
|
||||
System.out.print(" ");
|
||||
System.out.print(")");
|
||||
}
|
||||
|
||||
next = t.getNextSibling();
|
||||
if(next != null) {
|
||||
printASTNode(next,indent);
|
||||
}
|
||||
}
|
||||
|
||||
/** converts an int tree token type to a name.
|
||||
Does this by reflecting on nsdidl.IDLTreeTokenTypes,
|
||||
and is dependent on how ANTLR 2.00 outputs that class. */
|
||||
public static String getNameForType(int t) {
|
||||
try{
|
||||
Class c = Class.forName(tokenVocabulary);
|
||||
Field[] fields = c.getDeclaredFields();
|
||||
if(t-2 < fields.length)
|
||||
return fields[t-2].getName();
|
||||
} catch (Exception e) { System.out.println(e); }
|
||||
return "unfoundtype: " + t;
|
||||
}
|
||||
|
||||
|
||||
/** set up reverse links between this node and its first
|
||||
child and its first sibling, and link those as well */
|
||||
public void doubleLink() {
|
||||
TNode right = (TNode)getNextSibling();
|
||||
if(right != null) {
|
||||
right.left = this;
|
||||
right.doubleLink();
|
||||
}
|
||||
TNode down = (TNode)getFirstChild();
|
||||
if(down != null) {
|
||||
down.up = this;
|
||||
down.doubleLink();
|
||||
}
|
||||
}
|
||||
|
||||
/** find first parent of the given type,
|
||||
return null on failure */
|
||||
public TNode parentOfType(int type) {
|
||||
if(up == null) {
|
||||
if(left == null)
|
||||
return null;
|
||||
else
|
||||
return left.parentOfType(type);
|
||||
}
|
||||
if(up.getType() == type)
|
||||
return up;
|
||||
return up.parentOfType(type);
|
||||
}
|
||||
|
||||
/** find the first child of the node
|
||||
of the given type, return null on failure */
|
||||
public TNode firstChildOfType(int type) {
|
||||
TNode down = (TNode)getFirstChild();
|
||||
if(down == null)
|
||||
return null;
|
||||
if(down.getType() == type)
|
||||
return down;
|
||||
return down.firstSiblingOfType(type);
|
||||
}
|
||||
|
||||
/** find the first sibling of the node
|
||||
of the given type, return null on failure */
|
||||
public TNode firstSiblingOfType(int type) {
|
||||
TNode right = (TNode)getNextSibling();
|
||||
if(right == null)
|
||||
return null;
|
||||
if(right.getType() == type)
|
||||
return right;
|
||||
return right.firstSiblingOfType(type);
|
||||
}
|
||||
|
||||
}
|
33
app/preproc/TNodeFactory.java
Executable file
33
app/preproc/TNodeFactory.java
Executable file
@ -0,0 +1,33 @@
|
||||
package processing.app.preproc;
|
||||
|
||||
import antlr.Token;
|
||||
import antlr.ASTFactory;
|
||||
import antlr.collections.AST;
|
||||
|
||||
/** This class extends ASTFactory to build instances
|
||||
of class TNode */
|
||||
public class TNodeFactory extends ASTFactory {
|
||||
|
||||
/** Create a new ampty AST node */
|
||||
public AST create() {
|
||||
return new TNode();
|
||||
}
|
||||
|
||||
/** Create a new AST node from type and text */
|
||||
public AST create(int ttype, String text) {
|
||||
AST ast = new TNode();
|
||||
ast.setType(ttype);
|
||||
ast.setText(text);
|
||||
return ast;
|
||||
}
|
||||
|
||||
/** Create a new AST node from an existing AST node */
|
||||
public AST create(AST ast) {
|
||||
AST newast = new TNode();
|
||||
newast.setType(ast.getType());
|
||||
newast.setText(ast.getText());
|
||||
return newast;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,221 +0,0 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
package antlr;
|
||||
//package processing.app.preproc;
|
||||
|
||||
|
||||
import antlr.*;
|
||||
import antlr.collections.impl.BitSet;
|
||||
|
||||
/**
|
||||
* This class provides TokenStreamHiddenTokenFilters with the concept of
|
||||
* tokens which can be copied so that they are seen by both the hidden token
|
||||
* stream as well as the parser itself. This is useful when one wants to use
|
||||
* an existing parser (like the Java parser included with ANTLR) that throws
|
||||
* away some tokens to create a parse tree which can be used to spit out
|
||||
* a copy of the code with only minor modifications.
|
||||
*
|
||||
* This code is partially derived from the public domain ANLTR TokenStream
|
||||
*/
|
||||
public class TokenStreamCopyingHiddenTokenFilter
|
||||
extends TokenStreamHiddenTokenFilter
|
||||
implements TokenStream {
|
||||
|
||||
protected BitSet copyMask;
|
||||
CommonHiddenStreamToken hiddenCopy = null;
|
||||
|
||||
public TokenStreamCopyingHiddenTokenFilter(TokenStream input) {
|
||||
super(input);
|
||||
copyMask = new BitSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that all tokens of type tokenType should be copied. The copy
|
||||
* is put in the stream of hidden tokens, and the original is returned in the
|
||||
* stream of normal tokens.
|
||||
*
|
||||
* @param tokenType integer representing the token type to copied
|
||||
*/
|
||||
public void copy(int tokenType) {
|
||||
copyMask.add(tokenType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a clone of the important parts of the given token. Note that this
|
||||
* does NOT copy the hiddenBefore and hiddenAfter fields.
|
||||
*
|
||||
* @param t token to partially clone
|
||||
* @return newly created partial clone
|
||||
*/
|
||||
public CommonHiddenStreamToken partialCloneToken(CommonHiddenStreamToken t) {
|
||||
|
||||
CommonHiddenStreamToken u = new CommonHiddenStreamToken(t.getType(),
|
||||
t.getText());
|
||||
u.setColumn(t.getColumn());
|
||||
u.setLine(t.getLine());
|
||||
u.setFilename(t.getFilename());
|
||||
|
||||
return u;
|
||||
}
|
||||
|
||||
public void linkAndCopyToken(CommonHiddenStreamToken prev,
|
||||
CommonHiddenStreamToken monitored) {
|
||||
// create a copy of the token in the lookahead for use as hidden token
|
||||
hiddenCopy = partialCloneToken(LA(1));
|
||||
|
||||
// attach copy to the previous token, whether hidden or monitored
|
||||
prev.setHiddenAfter(hiddenCopy);
|
||||
|
||||
// if previous token was hidden, set the hiddenBefore pointer of the
|
||||
// copy to point back to it
|
||||
if (prev != monitored) {
|
||||
hiddenCopy.setHiddenBefore(prev);
|
||||
}
|
||||
|
||||
// we don't want the non-hidden copy to link back to the hidden
|
||||
// copy on the next pass through this function, so we leave
|
||||
// lastHiddenToken alone
|
||||
|
||||
//System.err.println("hidden copy: " + hiddenCopy.toString());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private void consumeFirst() throws TokenStreamException {
|
||||
consume(); // get first token of input stream
|
||||
|
||||
// Handle situation where hidden or discarded tokens
|
||||
// appear first in input stream
|
||||
CommonHiddenStreamToken p=null;
|
||||
|
||||
// while hidden, copied, or discarded scarf tokens
|
||||
while ( hideMask.member(LA(1).getType()) ||
|
||||
discardMask.member(LA(1).getType()) ||
|
||||
copyMask.member(LA(1).getType()) ) {
|
||||
|
||||
// if we've hit one of the tokens that needs to be copied, we copy it
|
||||
// and then break out of the loop, because the parser needs to see it
|
||||
// too
|
||||
//
|
||||
if (copyMask.member(LA(1).getType())) {
|
||||
|
||||
// copy the token in the lookahead
|
||||
hiddenCopy = partialCloneToken(LA(1));
|
||||
|
||||
// if there's an existing token before this, link that and the
|
||||
// copy together
|
||||
if (p != null) {
|
||||
p.setHiddenAfter(hiddenCopy);
|
||||
hiddenCopy.setHiddenBefore(p); // double-link
|
||||
}
|
||||
|
||||
lastHiddenToken = hiddenCopy;
|
||||
if (firstHidden == null) {
|
||||
firstHidden = hiddenCopy;
|
||||
}
|
||||
|
||||
// we don't want to consume this token, because it also needs to
|
||||
// be passed through to the parser, so break out of the while look
|
||||
// entirely
|
||||
//
|
||||
break;
|
||||
} else if (hideMask.member(LA(1).getType())) {
|
||||
if (p != null) {
|
||||
p.setHiddenAfter(LA(1));
|
||||
LA(1).setHiddenBefore(p); // double-link
|
||||
}
|
||||
p = LA(1);
|
||||
|
||||
lastHiddenToken = p;
|
||||
if (firstHidden == null) {
|
||||
firstHidden = p; // record hidden token if first
|
||||
}
|
||||
}
|
||||
consume();
|
||||
}
|
||||
}
|
||||
|
||||
/** Return the next monitored token.
|
||||
* Test the token following the monitored token.
|
||||
* If following is another monitored token, save it
|
||||
* for the next invocation of nextToken (like a single
|
||||
* lookahead token) and return it then.
|
||||
* If following is unmonitored, nondiscarded (hidden)
|
||||
* channel token, add it to the monitored token.
|
||||
*
|
||||
* Note: EOF must be a monitored Token.
|
||||
*/
|
||||
public Token nextToken() throws TokenStreamException {
|
||||
// handle an initial condition; don't want to get lookahead
|
||||
// token of this splitter until first call to nextToken
|
||||
if (LA(1) == null) {
|
||||
consumeFirst();
|
||||
}
|
||||
|
||||
//System.err.println();
|
||||
|
||||
// we always consume hidden tokens after monitored, thus,
|
||||
// upon entry LA(1) is a monitored token.
|
||||
CommonHiddenStreamToken monitored = LA(1);
|
||||
|
||||
// point to hidden tokens found during last invocation
|
||||
monitored.setHiddenBefore(lastHiddenToken);
|
||||
lastHiddenToken = null;
|
||||
|
||||
// Look for hidden tokens, hook them into list emanating
|
||||
// from the monitored tokens.
|
||||
consume();
|
||||
CommonHiddenStreamToken prev = monitored;
|
||||
|
||||
// deal with as many not-purely-monitored tokens as possible
|
||||
while ( hideMask.member(LA(1).getType()) ||
|
||||
discardMask.member(LA(1).getType()) ||
|
||||
copyMask.member(LA(1).getType()) ) {
|
||||
|
||||
if (copyMask.member(LA(1).getType())) {
|
||||
|
||||
// copy the token and link it backwards
|
||||
if (hiddenCopy != null) {
|
||||
linkAndCopyToken(hiddenCopy, monitored);
|
||||
} else {
|
||||
linkAndCopyToken(prev, monitored);
|
||||
}
|
||||
|
||||
// we now need to parse it as a monitored token, so we return, which
|
||||
// avoids the consume() call at the end of this loop. the next call
|
||||
// will parse it as a monitored token.
|
||||
//System.err.println("returned: " + monitored.toString());
|
||||
return monitored;
|
||||
|
||||
} else if (hideMask.member(LA(1).getType())) {
|
||||
|
||||
// attach the hidden token to the monitored in a chain
|
||||
// link forwards
|
||||
prev.setHiddenAfter(LA(1));
|
||||
|
||||
// link backwards
|
||||
if (prev != monitored) { //hidden cannot point to monitored tokens
|
||||
LA(1).setHiddenBefore(prev);
|
||||
} else if (hiddenCopy != null) {
|
||||
hiddenCopy.setHiddenAfter(LA(1));
|
||||
LA(1).setHiddenBefore(hiddenCopy);
|
||||
hiddenCopy = null;
|
||||
}
|
||||
|
||||
//System.err.println("hidden: " + prev.getHiddenAfter().toString() + "\" after: " + prev.toString());
|
||||
prev = lastHiddenToken = LA(1);
|
||||
}
|
||||
|
||||
consume();
|
||||
}
|
||||
|
||||
// remember the last hidden token for next time around
|
||||
if (hiddenCopy != null) {
|
||||
lastHiddenToken = hiddenCopy;
|
||||
hiddenCopy = null;
|
||||
}
|
||||
|
||||
//System.err.println("returned: " + monitored.toString());
|
||||
return monitored;
|
||||
}
|
||||
}
|
1191
app/preproc/WEmitter.g
Executable file
1191
app/preproc/WEmitter.g
Executable file
File diff suppressed because it is too large
Load Diff
6689
app/preproc/WEmitter.java
Normal file
6689
app/preproc/WEmitter.java
Normal file
File diff suppressed because it is too large
Load Diff
163
app/preproc/WEmitterTokenTypes.java
Normal file
163
app/preproc/WEmitterTokenTypes.java
Normal file
@ -0,0 +1,163 @@
|
||||
// $ANTLR 2.7.2: "expandedWEmitter.g" -> "WEmitter.java"$
|
||||
|
||||
package processing.app.preproc;
|
||||
import processing.app.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import antlr.CommonAST;
|
||||
import antlr.DumpASTVisitor;
|
||||
|
||||
public interface WEmitterTokenTypes {
|
||||
int EOF = 1;
|
||||
int NULL_TREE_LOOKAHEAD = 3;
|
||||
int LITERAL_typedef = 4;
|
||||
int LITERAL_asm = 5;
|
||||
int LITERAL_volatile = 6;
|
||||
int LCURLY = 7;
|
||||
int RCURLY = 8;
|
||||
int SEMI = 9;
|
||||
int LITERAL_struct = 10;
|
||||
int LITERAL_union = 11;
|
||||
int LITERAL_enum = 12;
|
||||
int LITERAL_auto = 13;
|
||||
int LITERAL_register = 14;
|
||||
int LITERAL_extern = 15;
|
||||
int LITERAL_static = 16;
|
||||
int LITERAL_const = 17;
|
||||
int LITERAL_void = 18;
|
||||
int LITERAL_char = 19;
|
||||
int LITERAL_short = 20;
|
||||
int LITERAL_int = 21;
|
||||
int LITERAL_long = 22;
|
||||
int LITERAL_float = 23;
|
||||
int LITERAL_double = 24;
|
||||
int LITERAL_signed = 25;
|
||||
int LITERAL_unsigned = 26;
|
||||
int ID = 27;
|
||||
int COMMA = 28;
|
||||
int COLON = 29;
|
||||
int ASSIGN = 30;
|
||||
int STAR = 31;
|
||||
int LPAREN = 32;
|
||||
int RPAREN = 33;
|
||||
int LBRACKET = 34;
|
||||
int RBRACKET = 35;
|
||||
int VARARGS = 36;
|
||||
int LITERAL_while = 37;
|
||||
int LITERAL_do = 38;
|
||||
int LITERAL_for = 39;
|
||||
int LITERAL_goto = 40;
|
||||
int LITERAL_continue = 41;
|
||||
int LITERAL_break = 42;
|
||||
int LITERAL_return = 43;
|
||||
int LITERAL_case = 44;
|
||||
int LITERAL_default = 45;
|
||||
int LITERAL_if = 46;
|
||||
int LITERAL_else = 47;
|
||||
int LITERAL_switch = 48;
|
||||
int DIV_ASSIGN = 49;
|
||||
int PLUS_ASSIGN = 50;
|
||||
int MINUS_ASSIGN = 51;
|
||||
int STAR_ASSIGN = 52;
|
||||
int MOD_ASSIGN = 53;
|
||||
int RSHIFT_ASSIGN = 54;
|
||||
int LSHIFT_ASSIGN = 55;
|
||||
int BAND_ASSIGN = 56;
|
||||
int BOR_ASSIGN = 57;
|
||||
int BXOR_ASSIGN = 58;
|
||||
int QUESTION = 59;
|
||||
int LOR = 60;
|
||||
int LAND = 61;
|
||||
int BOR = 62;
|
||||
int BXOR = 63;
|
||||
int BAND = 64;
|
||||
int EQUAL = 65;
|
||||
int NOT_EQUAL = 66;
|
||||
int LT = 67;
|
||||
int LTE = 68;
|
||||
int GT = 69;
|
||||
int GTE = 70;
|
||||
int LSHIFT = 71;
|
||||
int RSHIFT = 72;
|
||||
int PLUS = 73;
|
||||
int MINUS = 74;
|
||||
int DIV = 75;
|
||||
int MOD = 76;
|
||||
int INC = 77;
|
||||
int DEC = 78;
|
||||
int LITERAL_sizeof = 79;
|
||||
int BNOT = 80;
|
||||
int LNOT = 81;
|
||||
int PTR = 82;
|
||||
int DOT = 83;
|
||||
int CharLiteral = 84;
|
||||
int StringLiteral = 85;
|
||||
int IntOctalConst = 86;
|
||||
int LongOctalConst = 87;
|
||||
int UnsignedOctalConst = 88;
|
||||
int IntIntConst = 89;
|
||||
int LongIntConst = 90;
|
||||
int UnsignedIntConst = 91;
|
||||
int IntHexConst = 92;
|
||||
int LongHexConst = 93;
|
||||
int UnsignedHexConst = 94;
|
||||
int FloatDoubleConst = 95;
|
||||
int DoubleDoubleConst = 96;
|
||||
int LongDoubleConst = 97;
|
||||
int NTypedefName = 98;
|
||||
int NInitDecl = 99;
|
||||
int NDeclarator = 100;
|
||||
int NStructDeclarator = 101;
|
||||
int NDeclaration = 102;
|
||||
int NCast = 103;
|
||||
int NPointerGroup = 104;
|
||||
int NExpressionGroup = 105;
|
||||
int NFunctionCallArgs = 106;
|
||||
int NNonemptyAbstractDeclarator = 107;
|
||||
int NInitializer = 108;
|
||||
int NStatementExpr = 109;
|
||||
int NEmptyExpression = 110;
|
||||
int NParameterTypeList = 111;
|
||||
int NFunctionDef = 112;
|
||||
int NCompoundStatement = 113;
|
||||
int NParameterDeclaration = 114;
|
||||
int NCommaExpr = 115;
|
||||
int NUnaryExpr = 116;
|
||||
int NLabel = 117;
|
||||
int NPostfixExpr = 118;
|
||||
int NRangeExpr = 119;
|
||||
int NStringSeq = 120;
|
||||
int NInitializerElementLabel = 121;
|
||||
int NLcurlyInitializer = 122;
|
||||
int NAsmAttribute = 123;
|
||||
int NGnuAsmExpr = 124;
|
||||
int NTypeMissing = 125;
|
||||
int Vocabulary = 126;
|
||||
int Whitespace = 127;
|
||||
int Comment = 128;
|
||||
int CPPComment = 129;
|
||||
int PREPROC_DIRECTIVE = 130;
|
||||
int Space = 131;
|
||||
int LineDirective = 132;
|
||||
int BadStringLiteral = 133;
|
||||
int Escape = 134;
|
||||
int Digit = 135;
|
||||
int LongSuffix = 136;
|
||||
int UnsignedSuffix = 137;
|
||||
int FloatSuffix = 138;
|
||||
int Exponent = 139;
|
||||
int Number = 140;
|
||||
int LITERAL___label__ = 141;
|
||||
int LITERAL_inline = 142;
|
||||
int LITERAL_byte = 143;
|
||||
int LITERAL_boolean = 144;
|
||||
int LITERAL_Servo = 145;
|
||||
int LITERAL_Wire = 146;
|
||||
int LITERAL_typeof = 147;
|
||||
int LITERAL___complex = 148;
|
||||
int LITERAL___attribute = 149;
|
||||
int LITERAL___alignof = 150;
|
||||
int LITERAL___real = 151;
|
||||
int LITERAL___imag = 152;
|
||||
}
|
151
app/preproc/WEmitterTokenTypes.txt
Normal file
151
app/preproc/WEmitterTokenTypes.txt
Normal file
@ -0,0 +1,151 @@
|
||||
// $ANTLR 2.7.2: expandedWEmitter.g -> WEmitterTokenTypes.txt$
|
||||
WEmitter // output token vocab name
|
||||
LITERAL_typedef="typedef"=4
|
||||
LITERAL_asm="asm"=5
|
||||
LITERAL_volatile="volatile"=6
|
||||
LCURLY=7
|
||||
RCURLY=8
|
||||
SEMI=9
|
||||
LITERAL_struct="struct"=10
|
||||
LITERAL_union="union"=11
|
||||
LITERAL_enum="enum"=12
|
||||
LITERAL_auto="auto"=13
|
||||
LITERAL_register="register"=14
|
||||
LITERAL_extern="extern"=15
|
||||
LITERAL_static="static"=16
|
||||
LITERAL_const="const"=17
|
||||
LITERAL_void="void"=18
|
||||
LITERAL_char="char"=19
|
||||
LITERAL_short="short"=20
|
||||
LITERAL_int="int"=21
|
||||
LITERAL_long="long"=22
|
||||
LITERAL_float="float"=23
|
||||
LITERAL_double="double"=24
|
||||
LITERAL_signed="signed"=25
|
||||
LITERAL_unsigned="unsigned"=26
|
||||
ID=27
|
||||
COMMA=28
|
||||
COLON=29
|
||||
ASSIGN=30
|
||||
STAR=31
|
||||
LPAREN=32
|
||||
RPAREN=33
|
||||
LBRACKET=34
|
||||
RBRACKET=35
|
||||
VARARGS=36
|
||||
LITERAL_while="while"=37
|
||||
LITERAL_do="do"=38
|
||||
LITERAL_for="for"=39
|
||||
LITERAL_goto="goto"=40
|
||||
LITERAL_continue="continue"=41
|
||||
LITERAL_break="break"=42
|
||||
LITERAL_return="return"=43
|
||||
LITERAL_case="case"=44
|
||||
LITERAL_default="default"=45
|
||||
LITERAL_if="if"=46
|
||||
LITERAL_else="else"=47
|
||||
LITERAL_switch="switch"=48
|
||||
DIV_ASSIGN=49
|
||||
PLUS_ASSIGN=50
|
||||
MINUS_ASSIGN=51
|
||||
STAR_ASSIGN=52
|
||||
MOD_ASSIGN=53
|
||||
RSHIFT_ASSIGN=54
|
||||
LSHIFT_ASSIGN=55
|
||||
BAND_ASSIGN=56
|
||||
BOR_ASSIGN=57
|
||||
BXOR_ASSIGN=58
|
||||
QUESTION=59
|
||||
LOR=60
|
||||
LAND=61
|
||||
BOR=62
|
||||
BXOR=63
|
||||
BAND=64
|
||||
EQUAL=65
|
||||
NOT_EQUAL=66
|
||||
LT=67
|
||||
LTE=68
|
||||
GT=69
|
||||
GTE=70
|
||||
LSHIFT=71
|
||||
RSHIFT=72
|
||||
PLUS=73
|
||||
MINUS=74
|
||||
DIV=75
|
||||
MOD=76
|
||||
INC=77
|
||||
DEC=78
|
||||
LITERAL_sizeof="sizeof"=79
|
||||
BNOT=80
|
||||
LNOT=81
|
||||
PTR=82
|
||||
DOT=83
|
||||
CharLiteral=84
|
||||
StringLiteral=85
|
||||
IntOctalConst=86
|
||||
LongOctalConst=87
|
||||
UnsignedOctalConst=88
|
||||
IntIntConst=89
|
||||
LongIntConst=90
|
||||
UnsignedIntConst=91
|
||||
IntHexConst=92
|
||||
LongHexConst=93
|
||||
UnsignedHexConst=94
|
||||
FloatDoubleConst=95
|
||||
DoubleDoubleConst=96
|
||||
LongDoubleConst=97
|
||||
NTypedefName=98
|
||||
NInitDecl=99
|
||||
NDeclarator=100
|
||||
NStructDeclarator=101
|
||||
NDeclaration=102
|
||||
NCast=103
|
||||
NPointerGroup=104
|
||||
NExpressionGroup=105
|
||||
NFunctionCallArgs=106
|
||||
NNonemptyAbstractDeclarator=107
|
||||
NInitializer=108
|
||||
NStatementExpr=109
|
||||
NEmptyExpression=110
|
||||
NParameterTypeList=111
|
||||
NFunctionDef=112
|
||||
NCompoundStatement=113
|
||||
NParameterDeclaration=114
|
||||
NCommaExpr=115
|
||||
NUnaryExpr=116
|
||||
NLabel=117
|
||||
NPostfixExpr=118
|
||||
NRangeExpr=119
|
||||
NStringSeq=120
|
||||
NInitializerElementLabel=121
|
||||
NLcurlyInitializer=122
|
||||
NAsmAttribute=123
|
||||
NGnuAsmExpr=124
|
||||
NTypeMissing=125
|
||||
Vocabulary=126
|
||||
Whitespace=127
|
||||
Comment=128
|
||||
CPPComment=129
|
||||
PREPROC_DIRECTIVE("a line directive")=130
|
||||
Space=131
|
||||
LineDirective=132
|
||||
BadStringLiteral=133
|
||||
Escape=134
|
||||
Digit=135
|
||||
LongSuffix=136
|
||||
UnsignedSuffix=137
|
||||
FloatSuffix=138
|
||||
Exponent=139
|
||||
Number=140
|
||||
LITERAL___label__="__label__"=141
|
||||
LITERAL_inline="inline"=142
|
||||
LITERAL_byte="byte"=143
|
||||
LITERAL_boolean="boolean"=144
|
||||
LITERAL_Servo="Servo"=145
|
||||
LITERAL_Wire="Wire"=146
|
||||
LITERAL_typeof="typeof"=147
|
||||
LITERAL___complex="__complex"=148
|
||||
LITERAL___attribute="__attribute"=149
|
||||
LITERAL___alignof="__alignof"=150
|
||||
LITERAL___real="__real"=151
|
||||
LITERAL___imag="__imag"=152
|
2810
app/preproc/WLexer.java
Normal file
2810
app/preproc/WLexer.java
Normal file
File diff suppressed because it is too large
Load Diff
168
app/preproc/WLexerTokenTypes.java
Normal file
168
app/preproc/WLexerTokenTypes.java
Normal file
@ -0,0 +1,168 @@
|
||||
// $ANTLR 2.7.2: "expandedWParser.g" -> "WLexer.java"$
|
||||
|
||||
package processing.app.preproc;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import antlr.CommonAST;
|
||||
import antlr.DumpASTVisitor;
|
||||
|
||||
public interface WLexerTokenTypes {
|
||||
int EOF = 1;
|
||||
int NULL_TREE_LOOKAHEAD = 3;
|
||||
int LITERAL_typedef = 4;
|
||||
int LITERAL_asm = 5;
|
||||
int LITERAL_volatile = 6;
|
||||
int LCURLY = 7;
|
||||
int RCURLY = 8;
|
||||
int SEMI = 9;
|
||||
int LITERAL_struct = 10;
|
||||
int LITERAL_union = 11;
|
||||
int LITERAL_enum = 12;
|
||||
int LITERAL_auto = 13;
|
||||
int LITERAL_register = 14;
|
||||
int LITERAL_extern = 15;
|
||||
int LITERAL_static = 16;
|
||||
int LITERAL_const = 17;
|
||||
int LITERAL_void = 18;
|
||||
int LITERAL_char = 19;
|
||||
int LITERAL_short = 20;
|
||||
int LITERAL_int = 21;
|
||||
int LITERAL_long = 22;
|
||||
int LITERAL_float = 23;
|
||||
int LITERAL_double = 24;
|
||||
int LITERAL_signed = 25;
|
||||
int LITERAL_unsigned = 26;
|
||||
int ID = 27;
|
||||
int COMMA = 28;
|
||||
int COLON = 29;
|
||||
int ASSIGN = 30;
|
||||
int STAR = 31;
|
||||
int LPAREN = 32;
|
||||
int RPAREN = 33;
|
||||
int LBRACKET = 34;
|
||||
int RBRACKET = 35;
|
||||
int VARARGS = 36;
|
||||
int LITERAL_while = 37;
|
||||
int LITERAL_do = 38;
|
||||
int LITERAL_for = 39;
|
||||
int LITERAL_goto = 40;
|
||||
int LITERAL_continue = 41;
|
||||
int LITERAL_break = 42;
|
||||
int LITERAL_return = 43;
|
||||
int LITERAL_case = 44;
|
||||
int LITERAL_default = 45;
|
||||
int LITERAL_if = 46;
|
||||
int LITERAL_else = 47;
|
||||
int LITERAL_switch = 48;
|
||||
int DIV_ASSIGN = 49;
|
||||
int PLUS_ASSIGN = 50;
|
||||
int MINUS_ASSIGN = 51;
|
||||
int STAR_ASSIGN = 52;
|
||||
int MOD_ASSIGN = 53;
|
||||
int RSHIFT_ASSIGN = 54;
|
||||
int LSHIFT_ASSIGN = 55;
|
||||
int BAND_ASSIGN = 56;
|
||||
int BOR_ASSIGN = 57;
|
||||
int BXOR_ASSIGN = 58;
|
||||
int QUESTION = 59;
|
||||
int LOR = 60;
|
||||
int LAND = 61;
|
||||
int BOR = 62;
|
||||
int BXOR = 63;
|
||||
int BAND = 64;
|
||||
int EQUAL = 65;
|
||||
int NOT_EQUAL = 66;
|
||||
int LT = 67;
|
||||
int LTE = 68;
|
||||
int GT = 69;
|
||||
int GTE = 70;
|
||||
int LSHIFT = 71;
|
||||
int RSHIFT = 72;
|
||||
int PLUS = 73;
|
||||
int MINUS = 74;
|
||||
int DIV = 75;
|
||||
int MOD = 76;
|
||||
int INC = 77;
|
||||
int DEC = 78;
|
||||
int LITERAL_sizeof = 79;
|
||||
int BNOT = 80;
|
||||
int LNOT = 81;
|
||||
int PTR = 82;
|
||||
int DOT = 83;
|
||||
int CharLiteral = 84;
|
||||
int StringLiteral = 85;
|
||||
int IntOctalConst = 86;
|
||||
int LongOctalConst = 87;
|
||||
int UnsignedOctalConst = 88;
|
||||
int IntIntConst = 89;
|
||||
int LongIntConst = 90;
|
||||
int UnsignedIntConst = 91;
|
||||
int IntHexConst = 92;
|
||||
int LongHexConst = 93;
|
||||
int UnsignedHexConst = 94;
|
||||
int FloatDoubleConst = 95;
|
||||
int DoubleDoubleConst = 96;
|
||||
int LongDoubleConst = 97;
|
||||
int NTypedefName = 98;
|
||||
int NInitDecl = 99;
|
||||
int NDeclarator = 100;
|
||||
int NStructDeclarator = 101;
|
||||
int NDeclaration = 102;
|
||||
int NCast = 103;
|
||||
int NPointerGroup = 104;
|
||||
int NExpressionGroup = 105;
|
||||
int NFunctionCallArgs = 106;
|
||||
int NNonemptyAbstractDeclarator = 107;
|
||||
int NInitializer = 108;
|
||||
int NStatementExpr = 109;
|
||||
int NEmptyExpression = 110;
|
||||
int NParameterTypeList = 111;
|
||||
int NFunctionDef = 112;
|
||||
int NCompoundStatement = 113;
|
||||
int NParameterDeclaration = 114;
|
||||
int NCommaExpr = 115;
|
||||
int NUnaryExpr = 116;
|
||||
int NLabel = 117;
|
||||
int NPostfixExpr = 118;
|
||||
int NRangeExpr = 119;
|
||||
int NStringSeq = 120;
|
||||
int NInitializerElementLabel = 121;
|
||||
int NLcurlyInitializer = 122;
|
||||
int NAsmAttribute = 123;
|
||||
int NGnuAsmExpr = 124;
|
||||
int NTypeMissing = 125;
|
||||
int Vocabulary = 126;
|
||||
int Whitespace = 127;
|
||||
int Comment = 128;
|
||||
int CPPComment = 129;
|
||||
int PREPROC_DIRECTIVE = 130;
|
||||
int Space = 131;
|
||||
int LineDirective = 132;
|
||||
int BadStringLiteral = 133;
|
||||
int Escape = 134;
|
||||
int Digit = 135;
|
||||
int LongSuffix = 136;
|
||||
int UnsignedSuffix = 137;
|
||||
int FloatSuffix = 138;
|
||||
int Exponent = 139;
|
||||
int Number = 140;
|
||||
int LITERAL___label__ = 141;
|
||||
int LITERAL_inline = 142;
|
||||
int LITERAL_byte = 143;
|
||||
int LITERAL_boolean = 144;
|
||||
int LITERAL_Servo = 145;
|
||||
int LITERAL_Wire = 146;
|
||||
int LITERAL_typeof = 147;
|
||||
int LITERAL___complex = 148;
|
||||
int LITERAL___attribute = 149;
|
||||
int LITERAL___alignof = 150;
|
||||
int LITERAL___real = 151;
|
||||
int LITERAL___imag = 152;
|
||||
int LITERAL___extension__ = 153;
|
||||
int IntSuffix = 154;
|
||||
int NumberSuffix = 155;
|
||||
int IDMEAT = 156;
|
||||
int WideCharLiteral = 157;
|
||||
int WideStringLiteral = 158;
|
||||
}
|
157
app/preproc/WLexerTokenTypes.txt
Normal file
157
app/preproc/WLexerTokenTypes.txt
Normal file
@ -0,0 +1,157 @@
|
||||
// $ANTLR 2.7.2: expandedWParser.g -> WLexerTokenTypes.txt$
|
||||
WLexer // output token vocab name
|
||||
LITERAL_typedef="typedef"=4
|
||||
LITERAL_asm="asm"=5
|
||||
LITERAL_volatile="volatile"=6
|
||||
LCURLY=7
|
||||
RCURLY=8
|
||||
SEMI=9
|
||||
LITERAL_struct="struct"=10
|
||||
LITERAL_union="union"=11
|
||||
LITERAL_enum="enum"=12
|
||||
LITERAL_auto="auto"=13
|
||||
LITERAL_register="register"=14
|
||||
LITERAL_extern="extern"=15
|
||||
LITERAL_static="static"=16
|
||||
LITERAL_const="const"=17
|
||||
LITERAL_void="void"=18
|
||||
LITERAL_char="char"=19
|
||||
LITERAL_short="short"=20
|
||||
LITERAL_int="int"=21
|
||||
LITERAL_long="long"=22
|
||||
LITERAL_float="float"=23
|
||||
LITERAL_double="double"=24
|
||||
LITERAL_signed="signed"=25
|
||||
LITERAL_unsigned="unsigned"=26
|
||||
ID=27
|
||||
COMMA=28
|
||||
COLON=29
|
||||
ASSIGN=30
|
||||
STAR=31
|
||||
LPAREN=32
|
||||
RPAREN=33
|
||||
LBRACKET=34
|
||||
RBRACKET=35
|
||||
VARARGS=36
|
||||
LITERAL_while="while"=37
|
||||
LITERAL_do="do"=38
|
||||
LITERAL_for="for"=39
|
||||
LITERAL_goto="goto"=40
|
||||
LITERAL_continue="continue"=41
|
||||
LITERAL_break="break"=42
|
||||
LITERAL_return="return"=43
|
||||
LITERAL_case="case"=44
|
||||
LITERAL_default="default"=45
|
||||
LITERAL_if="if"=46
|
||||
LITERAL_else="else"=47
|
||||
LITERAL_switch="switch"=48
|
||||
DIV_ASSIGN=49
|
||||
PLUS_ASSIGN=50
|
||||
MINUS_ASSIGN=51
|
||||
STAR_ASSIGN=52
|
||||
MOD_ASSIGN=53
|
||||
RSHIFT_ASSIGN=54
|
||||
LSHIFT_ASSIGN=55
|
||||
BAND_ASSIGN=56
|
||||
BOR_ASSIGN=57
|
||||
BXOR_ASSIGN=58
|
||||
QUESTION=59
|
||||
LOR=60
|
||||
LAND=61
|
||||
BOR=62
|
||||
BXOR=63
|
||||
BAND=64
|
||||
EQUAL=65
|
||||
NOT_EQUAL=66
|
||||
LT=67
|
||||
LTE=68
|
||||
GT=69
|
||||
GTE=70
|
||||
LSHIFT=71
|
||||
RSHIFT=72
|
||||
PLUS=73
|
||||
MINUS=74
|
||||
DIV=75
|
||||
MOD=76
|
||||
INC=77
|
||||
DEC=78
|
||||
LITERAL_sizeof="sizeof"=79
|
||||
BNOT=80
|
||||
LNOT=81
|
||||
PTR=82
|
||||
DOT=83
|
||||
CharLiteral=84
|
||||
StringLiteral=85
|
||||
IntOctalConst=86
|
||||
LongOctalConst=87
|
||||
UnsignedOctalConst=88
|
||||
IntIntConst=89
|
||||
LongIntConst=90
|
||||
UnsignedIntConst=91
|
||||
IntHexConst=92
|
||||
LongHexConst=93
|
||||
UnsignedHexConst=94
|
||||
FloatDoubleConst=95
|
||||
DoubleDoubleConst=96
|
||||
LongDoubleConst=97
|
||||
NTypedefName=98
|
||||
NInitDecl=99
|
||||
NDeclarator=100
|
||||
NStructDeclarator=101
|
||||
NDeclaration=102
|
||||
NCast=103
|
||||
NPointerGroup=104
|
||||
NExpressionGroup=105
|
||||
NFunctionCallArgs=106
|
||||
NNonemptyAbstractDeclarator=107
|
||||
NInitializer=108
|
||||
NStatementExpr=109
|
||||
NEmptyExpression=110
|
||||
NParameterTypeList=111
|
||||
NFunctionDef=112
|
||||
NCompoundStatement=113
|
||||
NParameterDeclaration=114
|
||||
NCommaExpr=115
|
||||
NUnaryExpr=116
|
||||
NLabel=117
|
||||
NPostfixExpr=118
|
||||
NRangeExpr=119
|
||||
NStringSeq=120
|
||||
NInitializerElementLabel=121
|
||||
NLcurlyInitializer=122
|
||||
NAsmAttribute=123
|
||||
NGnuAsmExpr=124
|
||||
NTypeMissing=125
|
||||
Vocabulary=126
|
||||
Whitespace=127
|
||||
Comment=128
|
||||
CPPComment=129
|
||||
PREPROC_DIRECTIVE("a line directive")=130
|
||||
Space=131
|
||||
LineDirective=132
|
||||
BadStringLiteral=133
|
||||
Escape=134
|
||||
Digit=135
|
||||
LongSuffix=136
|
||||
UnsignedSuffix=137
|
||||
FloatSuffix=138
|
||||
Exponent=139
|
||||
Number=140
|
||||
LITERAL___label__="__label__"=141
|
||||
LITERAL_inline="inline"=142
|
||||
LITERAL_byte="byte"=143
|
||||
LITERAL_boolean="boolean"=144
|
||||
LITERAL_Servo="Servo"=145
|
||||
LITERAL_Wire="Wire"=146
|
||||
LITERAL_typeof="typeof"=147
|
||||
LITERAL___complex="__complex"=148
|
||||
LITERAL___attribute="__attribute"=149
|
||||
LITERAL___alignof="__alignof"=150
|
||||
LITERAL___real="__real"=151
|
||||
LITERAL___imag="__imag"=152
|
||||
LITERAL___extension__="__extension__"=153
|
||||
IntSuffix=154
|
||||
NumberSuffix=155
|
||||
IDMEAT=156
|
||||
WideCharLiteral=157
|
||||
WideStringLiteral=158
|
856
app/preproc/WParser.g
Executable file
856
app/preproc/WParser.g
Executable file
@ -0,0 +1,856 @@
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
Copyright (c) Non, Inc. 1998 -- All Rights Reserved
|
||||
|
||||
PROJECT: C Compiler
|
||||
MODULE: WParser
|
||||
FILE: WParser.g
|
||||
|
||||
AUTHOR: Monty Zukowski (jamz@cdsnet.net) April 28, 1998
|
||||
MODIFICATIONS: Hernando Barragan added support for the Wiring language
|
||||
DESCRIPTION:
|
||||
This is a grammar for the GNU C compiler. It is a
|
||||
grammar subclass of StdCParser, overriding only those
|
||||
rules which are different from Standard C.
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
header {
|
||||
package processing.app.preproc;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import antlr.CommonAST;
|
||||
import antlr.DumpASTVisitor;
|
||||
}
|
||||
|
||||
|
||||
class WParser extends StdCParser;
|
||||
|
||||
options
|
||||
{
|
||||
k = 2;
|
||||
exportVocab = W;
|
||||
buildAST = true;
|
||||
ASTLabelType = "TNode";
|
||||
defaultErrorHandler = false;
|
||||
// Copied following options from java grammar.
|
||||
codeGenMakeSwitchThreshold = 2;
|
||||
codeGenBitsetTestThreshold = 3;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// Suppport C++-style single-line comments?
|
||||
public static boolean CPPComments = true;
|
||||
|
||||
// access to symbol table
|
||||
public CSymbolTable symbolTable = new CSymbolTable();
|
||||
|
||||
// source for names to unnamed scopes
|
||||
protected int unnamedScopeCounter = 0;
|
||||
|
||||
public boolean isTypedefName(String name) {
|
||||
boolean returnValue = false;
|
||||
TNode node = symbolTable.lookupNameInCurrentScope(name);
|
||||
for (; node != null; node = (TNode) node.getNextSibling() ) {
|
||||
if(node.getType() == LITERAL_typedef) {
|
||||
returnValue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
public String getAScopeName() {
|
||||
return "" + (unnamedScopeCounter++);
|
||||
}
|
||||
|
||||
public void pushScope(String scopeName) {
|
||||
symbolTable.pushScope(scopeName);
|
||||
}
|
||||
|
||||
public void popScope() {
|
||||
symbolTable.popScope();
|
||||
}
|
||||
|
||||
int traceDepth = 0;
|
||||
public void reportError(RecognitionException ex) {
|
||||
try {
|
||||
System.err.println("ANTLR Parsing Error: "+ex + " token name:" + tokenNames[LA(1)]);
|
||||
ex.printStackTrace(System.err);
|
||||
}
|
||||
catch (TokenStreamException e) {
|
||||
System.err.println("ANTLR Parsing Error: "+ex);
|
||||
ex.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
public void reportError(String s) {
|
||||
System.err.println("ANTLR Parsing Error from String: " + s);
|
||||
}
|
||||
public void reportWarning(String s) {
|
||||
System.err.println("ANTLR Parsing Warning from String: " + s);
|
||||
}
|
||||
public void match(int t) throws MismatchedTokenException {
|
||||
boolean debugging = false;
|
||||
|
||||
if ( debugging ) {
|
||||
for (int x=0; x<traceDepth; x++) System.out.print(" ");
|
||||
try {
|
||||
System.out.println("Match("+tokenNames[t]+") with LA(1)="+
|
||||
tokenNames[LA(1)] + ((inputState.guessing>0)?" [inputState.guessing "+ inputState.guessing + "]":""));
|
||||
}
|
||||
catch (TokenStreamException e) {
|
||||
System.out.println("Match("+tokenNames[t]+") " + ((inputState.guessing>0)?" [inputState.guessing "+ inputState.guessing + "]":""));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
try {
|
||||
if ( LA(1)!=t ) {
|
||||
if ( debugging ){
|
||||
for (int x=0; x<traceDepth; x++) System.out.print(" ");
|
||||
System.out.println("token mismatch: "+tokenNames[LA(1)]
|
||||
+ "!="+tokenNames[t]);
|
||||
}
|
||||
throw new MismatchedTokenException(tokenNames, LT(1), t, false, getFilename());
|
||||
|
||||
} else {
|
||||
// mark token as consumed -- fetch next token deferred until LA/LT
|
||||
consume();
|
||||
}
|
||||
}
|
||||
catch (TokenStreamException e) {
|
||||
}
|
||||
|
||||
}
|
||||
public void traceIn(String rname) {
|
||||
traceDepth += 1;
|
||||
for (int x=0; x<traceDepth; x++) System.out.print(" ");
|
||||
try {
|
||||
System.out.println("> "+rname+"; LA(1)==("+ tokenNames[LT(1).getType()]
|
||||
+ ") " + LT(1).getText() + " [inputState.guessing "+ inputState.guessing + "]");
|
||||
}
|
||||
catch (TokenStreamException e) {
|
||||
}
|
||||
}
|
||||
public void traceOut(String rname) {
|
||||
for (int x=0; x<traceDepth; x++) System.out.print(" ");
|
||||
try {
|
||||
System.out.println("< "+rname+"; LA(1)==("+ tokenNames[LT(1).getType()]
|
||||
+ ") "+LT(1).getText() + " [inputState.guessing "+ inputState.guessing + "]");
|
||||
}
|
||||
catch (TokenStreamException e) {
|
||||
}
|
||||
traceDepth -= 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
translationUnit
|
||||
: ( externalList )? /* Empty source files are allowed. */
|
||||
;
|
||||
asm_expr
|
||||
: "asm"^
|
||||
("volatile")? LCURLY expr RCURLY ( SEMI )+
|
||||
;
|
||||
|
||||
idList
|
||||
: ID ( options{warnWhenFollowAmbig=false;}: COMMA ID )*
|
||||
;
|
||||
|
||||
externalDef
|
||||
: ( "typedef" | declaration )=> declaration
|
||||
| ( functionPrefix )=> functionDef
|
||||
| typelessDeclaration
|
||||
| asm_expr
|
||||
| SEMI
|
||||
;
|
||||
|
||||
/* these two are here because GCC allows "cat = 13;" as a valid program! */
|
||||
functionPrefix
|
||||
{ String declName; }
|
||||
: ( (functionDeclSpecifiers)=> ds:functionDeclSpecifiers
|
||||
| //epsilon
|
||||
)
|
||||
declName = d:declarator[true]
|
||||
( declaration )* (VARARGS)? ( SEMI )*
|
||||
LCURLY
|
||||
;
|
||||
|
||||
typelessDeclaration
|
||||
{ AST typeMissing = #[NTypeMissing]; }
|
||||
: initDeclList[typeMissing] SEMI { ## = #( #[NTypeMissing], ##); }
|
||||
;
|
||||
|
||||
initializer
|
||||
: ( ( ( (initializerElementLabel)=> initializerElementLabel )?
|
||||
( assignExpr | lcurlyInitializer ) { ## = #( #[NInitializer], ## ); }
|
||||
)
|
||||
| lcurlyInitializer
|
||||
)
|
||||
;
|
||||
|
||||
// GCC allows more specific initializers
|
||||
initializerElementLabel
|
||||
: ( ( LBRACKET ((constExpr VARARGS)=> rangeExpr | constExpr) RBRACKET (ASSIGN)? )
|
||||
| ID COLON
|
||||
| DOT ID ASSIGN
|
||||
)
|
||||
{ ## = #( #[NInitializerElementLabel], ##) ; }
|
||||
;
|
||||
|
||||
// GCC allows empty initializer lists
|
||||
lcurlyInitializer
|
||||
:
|
||||
LCURLY^ (initializerList ( COMMA! )? )? RCURLY
|
||||
{ ##.setType( NLcurlyInitializer ); }
|
||||
;
|
||||
|
||||
initializerList
|
||||
: initializer ( options{warnWhenFollowAmbig=false;}:COMMA! initializer )*
|
||||
;
|
||||
|
||||
|
||||
declarator[boolean isFunctionDefinition] returns [String declName]
|
||||
{ declName = ""; }
|
||||
:
|
||||
( pointerGroup )?
|
||||
|
||||
( id:ID { declName = id.getText(); }
|
||||
| LPAREN declName = declarator[false] RPAREN
|
||||
)
|
||||
|
||||
( declaratorParamaterList[isFunctionDefinition, declName]
|
||||
| LBRACKET ( expr )? RBRACKET
|
||||
)*
|
||||
{ ## = #( #[NDeclarator], ## ); }
|
||||
;
|
||||
|
||||
declaratorParamaterList[boolean isFunctionDefinition, String declName]
|
||||
:
|
||||
LPAREN^
|
||||
{
|
||||
if (isFunctionDefinition) {
|
||||
pushScope(declName);
|
||||
}
|
||||
else {
|
||||
pushScope("!"+declName);
|
||||
}
|
||||
}
|
||||
(
|
||||
(declSpecifiers)=> parameterTypeList
|
||||
| (idList)?
|
||||
)
|
||||
{
|
||||
popScope();
|
||||
}
|
||||
( COMMA! )?
|
||||
RPAREN
|
||||
{ ##.setType(NParameterTypeList); }
|
||||
;
|
||||
|
||||
parameterTypeList
|
||||
: parameterDeclaration
|
||||
( options {
|
||||
warnWhenFollowAmbig = false;
|
||||
} :
|
||||
( COMMA | SEMI )
|
||||
parameterDeclaration
|
||||
)*
|
||||
( ( COMMA | SEMI )
|
||||
VARARGS
|
||||
)?
|
||||
;
|
||||
|
||||
|
||||
declarationList
|
||||
: ( options { // this loop properly aborts when
|
||||
// it finds a non-typedefName ID MBZ
|
||||
warnWhenFollowAmbig = false;
|
||||
} :
|
||||
|
||||
localLabelDeclaration
|
||||
| ( declarationPredictor )=> declaration
|
||||
)+
|
||||
;
|
||||
localLabelDeclaration
|
||||
: ( //GNU note: any __label__ declarations must come before regular declarations.
|
||||
"__label__"^ ID (options{warnWhenFollowAmbig=false;}: COMMA! ID)* ( COMMA! )? ( SEMI! )+
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
declaration
|
||||
{ AST ds1 = null; }
|
||||
: ds:declSpecifiers { ds1 = astFactory.dupList(#ds); }
|
||||
(
|
||||
initDeclList[ds1]
|
||||
)?
|
||||
( SEMI )+
|
||||
{ ## = #( #[NDeclaration], ##); }
|
||||
|
||||
;
|
||||
|
||||
functionStorageClassSpecifier
|
||||
: "extern"
|
||||
| "static"
|
||||
| "inline"
|
||||
;
|
||||
|
||||
typeSpecifier [int specCount] returns [int retSpecCount]
|
||||
{ retSpecCount = specCount + 1; }
|
||||
:
|
||||
( "void"
|
||||
| "char"
|
||||
| "short"
|
||||
| "int"
|
||||
| "long"
|
||||
| "float"
|
||||
| "double"
|
||||
| "signed"
|
||||
| "unsigned"
|
||||
| "byte"
|
||||
| "boolean"
|
||||
| "Servo"
|
||||
| "Wire"
|
||||
| structOrUnionSpecifier ( options{warnWhenFollowAmbig=false;}: attributeDecl )*
|
||||
| enumSpecifier
|
||||
| { specCount==0 }? typedefName
|
||||
| "typeof"^ LPAREN
|
||||
( ( typeName )=> typeName
|
||||
| expr
|
||||
)
|
||||
RPAREN
|
||||
| "__complex"
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
structOrUnionSpecifier
|
||||
{ String scopeName; }
|
||||
: sou:structOrUnion!
|
||||
( ( ID LCURLY )=> i:ID l:LCURLY
|
||||
{
|
||||
scopeName = #sou.getText() + " " + #i.getText();
|
||||
#l.setText(scopeName);
|
||||
pushScope(scopeName);
|
||||
}
|
||||
( structDeclarationList )?
|
||||
{ popScope();}
|
||||
RCURLY
|
||||
| l1:LCURLY
|
||||
{
|
||||
scopeName = getAScopeName();
|
||||
#l1.setText(scopeName);
|
||||
pushScope(scopeName);
|
||||
}
|
||||
( structDeclarationList )?
|
||||
{ popScope(); }
|
||||
RCURLY
|
||||
| ID
|
||||
)
|
||||
{
|
||||
## = #( #sou, ## );
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
structDeclaration
|
||||
: specifierQualifierList structDeclaratorList ( COMMA! )? ( SEMI! )+
|
||||
;
|
||||
|
||||
structDeclaratorList
|
||||
: structDeclarator ( options{warnWhenFollowAmbig=false;}: COMMA! structDeclarator )*
|
||||
;
|
||||
|
||||
structDeclarator
|
||||
: ( declarator[false] )?
|
||||
( COLON constExpr )?
|
||||
( attributeDecl )*
|
||||
{ ## = #( #[NStructDeclarator], ##); }
|
||||
;
|
||||
|
||||
|
||||
|
||||
enumSpecifier
|
||||
: "enum"^
|
||||
( ( ID LCURLY )=> i:ID LCURLY enumList[i.getText()] RCURLY
|
||||
| LCURLY enumList["anonymous"] RCURLY
|
||||
| ID
|
||||
)
|
||||
;
|
||||
enumList[String enumName]
|
||||
: enumerator[enumName] ( options{warnWhenFollowAmbig=false;}: COMMA! enumerator[enumName] )* ( COMMA! )?
|
||||
;
|
||||
|
||||
|
||||
initDeclList[AST declarationSpecifiers]
|
||||
: initDecl[declarationSpecifiers]
|
||||
( options{warnWhenFollowAmbig=false;}: COMMA! initDecl[declarationSpecifiers] )*
|
||||
( COMMA! )?
|
||||
;
|
||||
|
||||
initDecl[AST declarationSpecifiers]
|
||||
{ String declName = ""; }
|
||||
: declName = d:declarator[false]
|
||||
{ AST ds1, d1;
|
||||
ds1 = astFactory.dupList(declarationSpecifiers);
|
||||
d1 = astFactory.dupList(#d);
|
||||
symbolTable.add(declName, #(null, ds1, d1) );
|
||||
}
|
||||
( attributeDecl )*
|
||||
( ASSIGN initializer
|
||||
| COLON expr
|
||||
)?
|
||||
{ ## = #( #[NInitDecl], ## ); }
|
||||
;
|
||||
|
||||
attributeDecl
|
||||
: "__attribute"^ LPAREN LPAREN attributeList RPAREN RPAREN
|
||||
| "asm"^ LPAREN stringConst RPAREN { ##.setType( NAsmAttribute ); }
|
||||
;
|
||||
|
||||
attributeList
|
||||
: attribute ( options{warnWhenFollowAmbig=false;}: COMMA attribute)* ( COMMA )?
|
||||
;
|
||||
|
||||
attribute
|
||||
: ( ~(LPAREN | RPAREN | COMMA)
|
||||
| LPAREN attributeList RPAREN
|
||||
)*
|
||||
;
|
||||
compoundStatement[String scopeName]
|
||||
: LCURLY^
|
||||
|
||||
{
|
||||
pushScope(scopeName);
|
||||
}
|
||||
( //this ambiguity is ok, declarationList and nestedFunctionDef end properly
|
||||
options {
|
||||
warnWhenFollowAmbig = false;
|
||||
} :
|
||||
( "typedef" | "__label__" | declaration )=> declarationList
|
||||
| (nestedFunctionDef)=> nestedFunctionDef
|
||||
)*
|
||||
( statementList )?
|
||||
{ popScope(); }
|
||||
RCURLY
|
||||
{ ##.setType( NCompoundStatement ); ##.setAttribute( "scopeName", scopeName ); }
|
||||
;
|
||||
|
||||
nestedFunctionDef
|
||||
{ String declName; }
|
||||
: ( "auto" )? //only for nested functions
|
||||
( (functionDeclSpecifiers)=> ds:functionDeclSpecifiers
|
||||
)?
|
||||
declName = d:declarator[false]
|
||||
{
|
||||
AST d2, ds2;
|
||||
d2 = astFactory.dupList(#d);
|
||||
ds2 = astFactory.dupList(#ds);
|
||||
symbolTable.add(declName, #(null, ds2, d2));
|
||||
pushScope(declName);
|
||||
}
|
||||
( declaration )*
|
||||
{ popScope(); }
|
||||
compoundStatement[declName]
|
||||
{ ## = #( #[NFunctionDef], ## );}
|
||||
;
|
||||
|
||||
statement
|
||||
: SEMI // Empty statements
|
||||
|
||||
| compoundStatement[getAScopeName()] // Group of statements
|
||||
|
||||
| expr SEMI! { ## = #( #[NStatementExpr], ## );} // Expressions
|
||||
|
||||
// Iteration statements:
|
||||
|
||||
| "while"^ LPAREN! expr RPAREN! statement
|
||||
| "do"^ statement "while"! LPAREN! expr RPAREN! SEMI!
|
||||
|! "for"
|
||||
LPAREN ( e1:expr )? SEMI ( e2:expr )? SEMI ( e3:expr )? RPAREN
|
||||
s:statement
|
||||
{
|
||||
if ( #e1 == null) { #e1 = #[ NEmptyExpression ]; }
|
||||
if ( #e2 == null) { #e2 = #[ NEmptyExpression ]; }
|
||||
if ( #e3 == null) { #e3 = #[ NEmptyExpression ]; }
|
||||
## = #( #[LITERAL_for, "for"], #e1, #e2, #e3, #s );
|
||||
}
|
||||
|
||||
|
||||
// Jump statements:
|
||||
|
||||
| "goto"^ expr SEMI!
|
||||
| "continue" SEMI!
|
||||
| "break" SEMI!
|
||||
| "return"^ ( expr )? SEMI!
|
||||
|
||||
|
||||
| ID COLON! (options {warnWhenFollowAmbig=false;}: statement)? { ## = #( #[NLabel], ## ); }
|
||||
// GNU allows range expressions in case statements
|
||||
| "case"^ ((constExpr VARARGS)=> rangeExpr | constExpr) COLON! ( options{warnWhenFollowAmbig=false;}:statement )?
|
||||
| "default"^ COLON! ( options{warnWhenFollowAmbig=false;}: statement )?
|
||||
|
||||
// Selection statements:
|
||||
|
||||
| "if"^
|
||||
LPAREN! expr RPAREN! statement
|
||||
( //standard if-else ambiguity
|
||||
options {
|
||||
warnWhenFollowAmbig = false;
|
||||
} :
|
||||
"else" statement )?
|
||||
| "switch"^ LPAREN! expr RPAREN! statement
|
||||
;
|
||||
|
||||
|
||||
|
||||
conditionalExpr
|
||||
: logicalOrExpr
|
||||
( QUESTION^ (expr)? COLON conditionalExpr )?
|
||||
;
|
||||
|
||||
rangeExpr //used in initializers only
|
||||
: constExpr VARARGS constExpr
|
||||
{ ## = #(#[NRangeExpr], ##); }
|
||||
;
|
||||
|
||||
castExpr
|
||||
: ( LPAREN typeName RPAREN )=>
|
||||
LPAREN^ typeName RPAREN ( castExpr | lcurlyInitializer )
|
||||
{ ##.setType(NCast); }
|
||||
|
||||
| unaryExpr
|
||||
;
|
||||
nonemptyAbstractDeclarator
|
||||
: (
|
||||
pointerGroup
|
||||
( (LPAREN
|
||||
( nonemptyAbstractDeclarator
|
||||
| parameterTypeList
|
||||
)?
|
||||
( COMMA! )?
|
||||
RPAREN)
|
||||
| (LBRACKET (expr)? RBRACKET)
|
||||
)*
|
||||
|
||||
| ( (LPAREN
|
||||
( nonemptyAbstractDeclarator
|
||||
| parameterTypeList
|
||||
)?
|
||||
( COMMA! )?
|
||||
RPAREN)
|
||||
| (LBRACKET (expr)? RBRACKET)
|
||||
)+
|
||||
)
|
||||
{ ## = #( #[NNonemptyAbstractDeclarator], ## ); }
|
||||
|
||||
;
|
||||
|
||||
|
||||
|
||||
unaryExpr
|
||||
: postfixExpr
|
||||
| INC^ castExpr
|
||||
| DEC^ castExpr
|
||||
| u:unaryOperator castExpr { ## = #( #[NUnaryExpr], ## ); }
|
||||
|
||||
| "sizeof"^
|
||||
( ( LPAREN typeName )=> LPAREN typeName RPAREN
|
||||
| unaryExpr
|
||||
)
|
||||
| "__alignof"^
|
||||
( ( LPAREN typeName )=> LPAREN typeName RPAREN
|
||||
| unaryExpr
|
||||
)
|
||||
| gnuAsmExpr
|
||||
;
|
||||
|
||||
unaryOperator
|
||||
: BAND
|
||||
| STAR
|
||||
| PLUS
|
||||
| MINUS
|
||||
| BNOT //also stands for complex conjugation
|
||||
| LNOT
|
||||
| LAND //for label dereference (&&label)
|
||||
| "__real"
|
||||
| "__imag"
|
||||
;
|
||||
|
||||
gnuAsmExpr
|
||||
: "asm"^ ("volatile")?
|
||||
LPAREN stringConst
|
||||
( options { warnWhenFollowAmbig = false; }:
|
||||
COLON (strOptExprPair ( COMMA strOptExprPair)* )?
|
||||
( options { warnWhenFollowAmbig = false; }:
|
||||
COLON (strOptExprPair ( COMMA strOptExprPair)* )?
|
||||
)?
|
||||
)?
|
||||
( COLON stringConst ( COMMA stringConst)* )?
|
||||
RPAREN
|
||||
{ ##.setType(NGnuAsmExpr); }
|
||||
;
|
||||
|
||||
//GCC requires the PARENs
|
||||
strOptExprPair
|
||||
: stringConst ( LPAREN expr RPAREN )?
|
||||
;
|
||||
|
||||
|
||||
primaryExpr
|
||||
: ID
|
||||
| Number
|
||||
| charConst
|
||||
| stringConst
|
||||
// JTC:
|
||||
// ID should catch the enumerator
|
||||
// leaving it in gives ambiguous err
|
||||
// | enumerator
|
||||
| (LPAREN LCURLY) => LPAREN^ compoundStatement[getAScopeName()] RPAREN
|
||||
| LPAREN^ expr RPAREN { ##.setType(NExpressionGroup); }
|
||||
;
|
||||
|
||||
|
||||
{
|
||||
// import CToken;
|
||||
import java.io.*;
|
||||
// import LineObject;
|
||||
import antlr.*;
|
||||
}
|
||||
|
||||
class WLexer extends StdCLexer;
|
||||
options
|
||||
{
|
||||
k = 3;
|
||||
importVocab = W;
|
||||
testLiterals = false;
|
||||
}
|
||||
tokens {
|
||||
LITERAL___extension__ = "__extension__";
|
||||
}
|
||||
|
||||
{
|
||||
public void initialize(String src)
|
||||
{
|
||||
setOriginalSource(src);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public void initialize()
|
||||
{
|
||||
literals.put(new ANTLRHashString("__alignof__", this), new Integer(LITERAL___alignof));
|
||||
literals.put(new ANTLRHashString("__asm", this), new Integer(LITERAL_asm));
|
||||
literals.put(new ANTLRHashString("__asm__", this), new Integer(LITERAL_asm));
|
||||
literals.put(new ANTLRHashString("__attribute__", this), new Integer(LITERAL___attribute));
|
||||
literals.put(new ANTLRHashString("__complex__", this), new Integer(LITERAL___complex));
|
||||
literals.put(new ANTLRHashString("__const", this), new Integer(LITERAL_const));
|
||||
literals.put(new ANTLRHashString("__const__", this), new Integer(LITERAL_const));
|
||||
literals.put(new ANTLRHashString("__imag__", this), new Integer(LITERAL___imag));
|
||||
literals.put(new ANTLRHashString("__inline", this), new Integer(LITERAL_inline));
|
||||
literals.put(new ANTLRHashString("__inline__", this), new Integer(LITERAL_inline));
|
||||
literals.put(new ANTLRHashString("__real__", this), new Integer(LITERAL___real));
|
||||
literals.put(new ANTLRHashString("__signed", this), new Integer(LITERAL_signed));
|
||||
literals.put(new ANTLRHashString("__signed__", this), new Integer(LITERAL_signed));
|
||||
literals.put(new ANTLRHashString("__typeof", this), new Integer(LITERAL_typeof));
|
||||
literals.put(new ANTLRHashString("__typeof__", this), new Integer(LITERAL_typeof));
|
||||
literals.put(new ANTLRHashString("__volatile", this), new Integer(LITERAL_volatile));
|
||||
literals.put(new ANTLRHashString("__volatile__", this), new Integer(LITERAL_volatile));
|
||||
}
|
||||
|
||||
|
||||
LineObject lineObject = new LineObject();
|
||||
String originalSource = "";
|
||||
PreprocessorInfoChannel preprocessorInfoChannel = new PreprocessorInfoChannel();
|
||||
int tokenNumber = 0;
|
||||
boolean countingTokens = true;
|
||||
int deferredLineCount = 0;
|
||||
|
||||
public void setCountingTokens(boolean ct)
|
||||
{
|
||||
countingTokens = ct;
|
||||
if ( countingTokens ) {
|
||||
tokenNumber = 0;
|
||||
}
|
||||
else {
|
||||
tokenNumber = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void setOriginalSource(String src)
|
||||
{
|
||||
originalSource = src;
|
||||
lineObject.setSource(src);
|
||||
}
|
||||
public void setSource(String src)
|
||||
{
|
||||
lineObject.setSource(src);
|
||||
}
|
||||
|
||||
public PreprocessorInfoChannel getPreprocessorInfoChannel()
|
||||
{
|
||||
return preprocessorInfoChannel;
|
||||
}
|
||||
|
||||
public void setPreprocessingDirective(String pre)
|
||||
{
|
||||
preprocessorInfoChannel.addLineForTokenNumber( pre, new Integer(tokenNumber) );
|
||||
}
|
||||
|
||||
protected Token makeToken(int t)
|
||||
{
|
||||
if ( t != Token.SKIP && countingTokens) {
|
||||
tokenNumber++;
|
||||
}
|
||||
CToken tok = (CToken) super.makeToken(t);
|
||||
tok.setLine(lineObject.line);
|
||||
tok.setSource(lineObject.source);
|
||||
tok.setTokenNumber(tokenNumber);
|
||||
|
||||
lineObject.line += deferredLineCount;
|
||||
deferredLineCount = 0;
|
||||
return tok;
|
||||
}
|
||||
|
||||
public void deferredNewline() {
|
||||
deferredLineCount++;
|
||||
}
|
||||
|
||||
public void newline() {
|
||||
lineObject.newline();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Whitespace
|
||||
: ( ( ' ' | '\t' | '\014')
|
||||
| "\r\n" { newline(); }
|
||||
| ( '\n' | '\r' ) { newline(); }
|
||||
) { _ttype = Token.SKIP; }
|
||||
;
|
||||
|
||||
|
||||
protected
|
||||
Escape
|
||||
: '\\'
|
||||
( options{warnWhenFollowAmbig=false;}:
|
||||
~('0'..'7' | 'x')
|
||||
| ('0'..'3') ( options{warnWhenFollowAmbig=false;}: Digit )*
|
||||
| ('4'..'7') ( options{warnWhenFollowAmbig=false;}: Digit )*
|
||||
| 'x' ( options{warnWhenFollowAmbig=false;}: Digit | 'a'..'f' | 'A'..'F' )+
|
||||
)
|
||||
;
|
||||
|
||||
protected IntSuffix
|
||||
: 'L'
|
||||
| 'l'
|
||||
| 'U'
|
||||
| 'u'
|
||||
| 'I'
|
||||
| 'i'
|
||||
| 'J'
|
||||
| 'j'
|
||||
;
|
||||
protected NumberSuffix
|
||||
:
|
||||
IntSuffix
|
||||
| 'F'
|
||||
| 'f'
|
||||
;
|
||||
|
||||
Number
|
||||
: ( ( Digit )+ ( '.' | 'e' | 'E' ) )=> ( Digit )+
|
||||
( '.' ( Digit )* ( Exponent )?
|
||||
| Exponent
|
||||
)
|
||||
( NumberSuffix
|
||||
)*
|
||||
|
||||
| ( "..." )=> "..." { _ttype = VARARGS; }
|
||||
|
||||
| '.' { _ttype = DOT; }
|
||||
( ( Digit )+ ( Exponent )?
|
||||
{ _ttype = Number; }
|
||||
( NumberSuffix
|
||||
)*
|
||||
)?
|
||||
|
||||
| '0' ( '0'..'7' )*
|
||||
( NumberSuffix
|
||||
)*
|
||||
|
||||
| '1'..'9' ( Digit )*
|
||||
( NumberSuffix
|
||||
)*
|
||||
|
||||
| '0' ( 'x' | 'X' ) ( 'a'..'f' | 'A'..'F' | Digit )+
|
||||
( IntSuffix
|
||||
)*
|
||||
;
|
||||
|
||||
IDMEAT
|
||||
:
|
||||
i:ID {
|
||||
|
||||
if ( i.getType() == LITERAL___extension__ ) {
|
||||
$setType(Token.SKIP);
|
||||
}
|
||||
else {
|
||||
$setType(i.getType());
|
||||
}
|
||||
|
||||
}
|
||||
;
|
||||
|
||||
protected ID
|
||||
options
|
||||
{
|
||||
testLiterals = true;
|
||||
}
|
||||
: ( 'a'..'z' | 'A'..'Z' | '_' | '$')
|
||||
( 'a'..'z' | 'A'..'Z' | '_' | '$' | '0'..'9' )*
|
||||
;
|
||||
|
||||
WideCharLiteral
|
||||
:
|
||||
'L' CharLiteral
|
||||
{ $setType(CharLiteral); }
|
||||
;
|
||||
|
||||
|
||||
|
||||
WideStringLiteral
|
||||
:
|
||||
'L' StringLiteral
|
||||
{ $setType(StringLiteral); }
|
||||
;
|
||||
|
||||
StringLiteral
|
||||
:
|
||||
'"'
|
||||
( ('\\' ~('\n'))=> Escape
|
||||
| ( '\r' { newline(); }
|
||||
| '\n' {
|
||||
newline();
|
||||
}
|
||||
| '\\' '\n' {
|
||||
newline();
|
||||
}
|
||||
)
|
||||
| ~( '"' | '\r' | '\n' | '\\' )
|
||||
)*
|
||||
'"'
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
6718
app/preproc/WParser.java
Normal file
6718
app/preproc/WParser.java
Normal file
File diff suppressed because it is too large
Load Diff
162
app/preproc/WTokenTypes.java
Normal file
162
app/preproc/WTokenTypes.java
Normal file
@ -0,0 +1,162 @@
|
||||
// $ANTLR 2.7.2: "expandedWParser.g" -> "WLexer.java"$
|
||||
|
||||
package processing.app.preproc;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import antlr.CommonAST;
|
||||
import antlr.DumpASTVisitor;
|
||||
|
||||
public interface WTokenTypes {
|
||||
int EOF = 1;
|
||||
int NULL_TREE_LOOKAHEAD = 3;
|
||||
int LITERAL_typedef = 4;
|
||||
int LITERAL_asm = 5;
|
||||
int LITERAL_volatile = 6;
|
||||
int LCURLY = 7;
|
||||
int RCURLY = 8;
|
||||
int SEMI = 9;
|
||||
int LITERAL_struct = 10;
|
||||
int LITERAL_union = 11;
|
||||
int LITERAL_enum = 12;
|
||||
int LITERAL_auto = 13;
|
||||
int LITERAL_register = 14;
|
||||
int LITERAL_extern = 15;
|
||||
int LITERAL_static = 16;
|
||||
int LITERAL_const = 17;
|
||||
int LITERAL_void = 18;
|
||||
int LITERAL_char = 19;
|
||||
int LITERAL_short = 20;
|
||||
int LITERAL_int = 21;
|
||||
int LITERAL_long = 22;
|
||||
int LITERAL_float = 23;
|
||||
int LITERAL_double = 24;
|
||||
int LITERAL_signed = 25;
|
||||
int LITERAL_unsigned = 26;
|
||||
int ID = 27;
|
||||
int COMMA = 28;
|
||||
int COLON = 29;
|
||||
int ASSIGN = 30;
|
||||
int STAR = 31;
|
||||
int LPAREN = 32;
|
||||
int RPAREN = 33;
|
||||
int LBRACKET = 34;
|
||||
int RBRACKET = 35;
|
||||
int VARARGS = 36;
|
||||
int LITERAL_while = 37;
|
||||
int LITERAL_do = 38;
|
||||
int LITERAL_for = 39;
|
||||
int LITERAL_goto = 40;
|
||||
int LITERAL_continue = 41;
|
||||
int LITERAL_break = 42;
|
||||
int LITERAL_return = 43;
|
||||
int LITERAL_case = 44;
|
||||
int LITERAL_default = 45;
|
||||
int LITERAL_if = 46;
|
||||
int LITERAL_else = 47;
|
||||
int LITERAL_switch = 48;
|
||||
int DIV_ASSIGN = 49;
|
||||
int PLUS_ASSIGN = 50;
|
||||
int MINUS_ASSIGN = 51;
|
||||
int STAR_ASSIGN = 52;
|
||||
int MOD_ASSIGN = 53;
|
||||
int RSHIFT_ASSIGN = 54;
|
||||
int LSHIFT_ASSIGN = 55;
|
||||
int BAND_ASSIGN = 56;
|
||||
int BOR_ASSIGN = 57;
|
||||
int BXOR_ASSIGN = 58;
|
||||
int QUESTION = 59;
|
||||
int LOR = 60;
|
||||
int LAND = 61;
|
||||
int BOR = 62;
|
||||
int BXOR = 63;
|
||||
int BAND = 64;
|
||||
int EQUAL = 65;
|
||||
int NOT_EQUAL = 66;
|
||||
int LT = 67;
|
||||
int LTE = 68;
|
||||
int GT = 69;
|
||||
int GTE = 70;
|
||||
int LSHIFT = 71;
|
||||
int RSHIFT = 72;
|
||||
int PLUS = 73;
|
||||
int MINUS = 74;
|
||||
int DIV = 75;
|
||||
int MOD = 76;
|
||||
int INC = 77;
|
||||
int DEC = 78;
|
||||
int LITERAL_sizeof = 79;
|
||||
int BNOT = 80;
|
||||
int LNOT = 81;
|
||||
int PTR = 82;
|
||||
int DOT = 83;
|
||||
int CharLiteral = 84;
|
||||
int StringLiteral = 85;
|
||||
int IntOctalConst = 86;
|
||||
int LongOctalConst = 87;
|
||||
int UnsignedOctalConst = 88;
|
||||
int IntIntConst = 89;
|
||||
int LongIntConst = 90;
|
||||
int UnsignedIntConst = 91;
|
||||
int IntHexConst = 92;
|
||||
int LongHexConst = 93;
|
||||
int UnsignedHexConst = 94;
|
||||
int FloatDoubleConst = 95;
|
||||
int DoubleDoubleConst = 96;
|
||||
int LongDoubleConst = 97;
|
||||
int NTypedefName = 98;
|
||||
int NInitDecl = 99;
|
||||
int NDeclarator = 100;
|
||||
int NStructDeclarator = 101;
|
||||
int NDeclaration = 102;
|
||||
int NCast = 103;
|
||||
int NPointerGroup = 104;
|
||||
int NExpressionGroup = 105;
|
||||
int NFunctionCallArgs = 106;
|
||||
int NNonemptyAbstractDeclarator = 107;
|
||||
int NInitializer = 108;
|
||||
int NStatementExpr = 109;
|
||||
int NEmptyExpression = 110;
|
||||
int NParameterTypeList = 111;
|
||||
int NFunctionDef = 112;
|
||||
int NCompoundStatement = 113;
|
||||
int NParameterDeclaration = 114;
|
||||
int NCommaExpr = 115;
|
||||
int NUnaryExpr = 116;
|
||||
int NLabel = 117;
|
||||
int NPostfixExpr = 118;
|
||||
int NRangeExpr = 119;
|
||||
int NStringSeq = 120;
|
||||
int NInitializerElementLabel = 121;
|
||||
int NLcurlyInitializer = 122;
|
||||
int NAsmAttribute = 123;
|
||||
int NGnuAsmExpr = 124;
|
||||
int NTypeMissing = 125;
|
||||
int Vocabulary = 126;
|
||||
int Whitespace = 127;
|
||||
int Comment = 128;
|
||||
int CPPComment = 129;
|
||||
int PREPROC_DIRECTIVE = 130;
|
||||
int Space = 131;
|
||||
int LineDirective = 132;
|
||||
int BadStringLiteral = 133;
|
||||
int Escape = 134;
|
||||
int Digit = 135;
|
||||
int LongSuffix = 136;
|
||||
int UnsignedSuffix = 137;
|
||||
int FloatSuffix = 138;
|
||||
int Exponent = 139;
|
||||
int Number = 140;
|
||||
int LITERAL___label__ = 141;
|
||||
int LITERAL_inline = 142;
|
||||
int LITERAL_byte = 143;
|
||||
int LITERAL_boolean = 144;
|
||||
int LITERAL_Servo = 145;
|
||||
int LITERAL_Wire = 146;
|
||||
int LITERAL_typeof = 147;
|
||||
int LITERAL___complex = 148;
|
||||
int LITERAL___attribute = 149;
|
||||
int LITERAL___alignof = 150;
|
||||
int LITERAL___real = 151;
|
||||
int LITERAL___imag = 152;
|
||||
}
|
151
app/preproc/WTokenTypes.txt
Normal file
151
app/preproc/WTokenTypes.txt
Normal file
@ -0,0 +1,151 @@
|
||||
// $ANTLR 2.7.2: expandedWParser.g -> WTokenTypes.txt$
|
||||
W // output token vocab name
|
||||
LITERAL_typedef="typedef"=4
|
||||
LITERAL_asm="asm"=5
|
||||
LITERAL_volatile="volatile"=6
|
||||
LCURLY=7
|
||||
RCURLY=8
|
||||
SEMI=9
|
||||
LITERAL_struct="struct"=10
|
||||
LITERAL_union="union"=11
|
||||
LITERAL_enum="enum"=12
|
||||
LITERAL_auto="auto"=13
|
||||
LITERAL_register="register"=14
|
||||
LITERAL_extern="extern"=15
|
||||
LITERAL_static="static"=16
|
||||
LITERAL_const="const"=17
|
||||
LITERAL_void="void"=18
|
||||
LITERAL_char="char"=19
|
||||
LITERAL_short="short"=20
|
||||
LITERAL_int="int"=21
|
||||
LITERAL_long="long"=22
|
||||
LITERAL_float="float"=23
|
||||
LITERAL_double="double"=24
|
||||
LITERAL_signed="signed"=25
|
||||
LITERAL_unsigned="unsigned"=26
|
||||
ID=27
|
||||
COMMA=28
|
||||
COLON=29
|
||||
ASSIGN=30
|
||||
STAR=31
|
||||
LPAREN=32
|
||||
RPAREN=33
|
||||
LBRACKET=34
|
||||
RBRACKET=35
|
||||
VARARGS=36
|
||||
LITERAL_while="while"=37
|
||||
LITERAL_do="do"=38
|
||||
LITERAL_for="for"=39
|
||||
LITERAL_goto="goto"=40
|
||||
LITERAL_continue="continue"=41
|
||||
LITERAL_break="break"=42
|
||||
LITERAL_return="return"=43
|
||||
LITERAL_case="case"=44
|
||||
LITERAL_default="default"=45
|
||||
LITERAL_if="if"=46
|
||||
LITERAL_else="else"=47
|
||||
LITERAL_switch="switch"=48
|
||||
DIV_ASSIGN=49
|
||||
PLUS_ASSIGN=50
|
||||
MINUS_ASSIGN=51
|
||||
STAR_ASSIGN=52
|
||||
MOD_ASSIGN=53
|
||||
RSHIFT_ASSIGN=54
|
||||
LSHIFT_ASSIGN=55
|
||||
BAND_ASSIGN=56
|
||||
BOR_ASSIGN=57
|
||||
BXOR_ASSIGN=58
|
||||
QUESTION=59
|
||||
LOR=60
|
||||
LAND=61
|
||||
BOR=62
|
||||
BXOR=63
|
||||
BAND=64
|
||||
EQUAL=65
|
||||
NOT_EQUAL=66
|
||||
LT=67
|
||||
LTE=68
|
||||
GT=69
|
||||
GTE=70
|
||||
LSHIFT=71
|
||||
RSHIFT=72
|
||||
PLUS=73
|
||||
MINUS=74
|
||||
DIV=75
|
||||
MOD=76
|
||||
INC=77
|
||||
DEC=78
|
||||
LITERAL_sizeof="sizeof"=79
|
||||
BNOT=80
|
||||
LNOT=81
|
||||
PTR=82
|
||||
DOT=83
|
||||
CharLiteral=84
|
||||
StringLiteral=85
|
||||
IntOctalConst=86
|
||||
LongOctalConst=87
|
||||
UnsignedOctalConst=88
|
||||
IntIntConst=89
|
||||
LongIntConst=90
|
||||
UnsignedIntConst=91
|
||||
IntHexConst=92
|
||||
LongHexConst=93
|
||||
UnsignedHexConst=94
|
||||
FloatDoubleConst=95
|
||||
DoubleDoubleConst=96
|
||||
LongDoubleConst=97
|
||||
NTypedefName=98
|
||||
NInitDecl=99
|
||||
NDeclarator=100
|
||||
NStructDeclarator=101
|
||||
NDeclaration=102
|
||||
NCast=103
|
||||
NPointerGroup=104
|
||||
NExpressionGroup=105
|
||||
NFunctionCallArgs=106
|
||||
NNonemptyAbstractDeclarator=107
|
||||
NInitializer=108
|
||||
NStatementExpr=109
|
||||
NEmptyExpression=110
|
||||
NParameterTypeList=111
|
||||
NFunctionDef=112
|
||||
NCompoundStatement=113
|
||||
NParameterDeclaration=114
|
||||
NCommaExpr=115
|
||||
NUnaryExpr=116
|
||||
NLabel=117
|
||||
NPostfixExpr=118
|
||||
NRangeExpr=119
|
||||
NStringSeq=120
|
||||
NInitializerElementLabel=121
|
||||
NLcurlyInitializer=122
|
||||
NAsmAttribute=123
|
||||
NGnuAsmExpr=124
|
||||
NTypeMissing=125
|
||||
Vocabulary=126
|
||||
Whitespace=127
|
||||
Comment=128
|
||||
CPPComment=129
|
||||
PREPROC_DIRECTIVE("a line directive")=130
|
||||
Space=131
|
||||
LineDirective=132
|
||||
BadStringLiteral=133
|
||||
Escape=134
|
||||
Digit=135
|
||||
LongSuffix=136
|
||||
UnsignedSuffix=137
|
||||
FloatSuffix=138
|
||||
Exponent=139
|
||||
Number=140
|
||||
LITERAL___label__="__label__"=141
|
||||
LITERAL_inline="inline"=142
|
||||
LITERAL_byte="byte"=143
|
||||
LITERAL_boolean="boolean"=144
|
||||
LITERAL_Servo="Servo"=145
|
||||
LITERAL_Wire="Wire"=146
|
||||
LITERAL_typeof="typeof"=147
|
||||
LITERAL___complex="__complex"=148
|
||||
LITERAL___attribute="__attribute"=149
|
||||
LITERAL___alignof="__alignof"=150
|
||||
LITERAL___real="__real"=151
|
||||
LITERAL___imag="__imag"=152
|
857
app/preproc/WTreeParser.g
Executable file
857
app/preproc/WTreeParser.g
Executable file
@ -0,0 +1,857 @@
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
Copyright (c) Non, Inc. 1998 -- All Rights Reserved
|
||||
|
||||
PROJECT: C Compiler
|
||||
MODULE: WTreeParser
|
||||
FILE: WTreeParser.g
|
||||
|
||||
AUTHOR: Monty Zukowski (jamz@cdsnet.net) April 28, 1998
|
||||
MODIFICATIONS: Hernando Barragan added support for the Wiring language
|
||||
|
||||
DESCRIPTION:
|
||||
|
||||
This tree grammar is for a Gnu C AST. No actions in it,
|
||||
subclass to do something useful.
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
header {
|
||||
package processing.app.preproc;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import antlr.CommonAST;
|
||||
import antlr.DumpASTVisitor;
|
||||
}
|
||||
|
||||
|
||||
class WTreeParser extends TreeParser;
|
||||
|
||||
options
|
||||
{
|
||||
importVocab = W;
|
||||
buildAST = false;
|
||||
ASTLabelType = "TNode";
|
||||
|
||||
// Copied following options from java grammar.
|
||||
codeGenMakeSwitchThreshold = 2;
|
||||
codeGenBitsetTestThreshold = 3;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
int traceDepth = 0;
|
||||
public void reportError(RecognitionException ex) {
|
||||
if ( ex != null) {
|
||||
System.err.println("ANTLR Tree Parsing RecognitionException Error: " + ex.getClass().getName() + " " + ex );
|
||||
ex.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
public void reportError(NoViableAltException ex) {
|
||||
System.err.println("ANTLR Tree Parsing NoViableAltException Error: " + ex.toString());
|
||||
TNode.printTree( ex.node );
|
||||
ex.printStackTrace(System.err);
|
||||
}
|
||||
public void reportError(MismatchedTokenException ex) {
|
||||
if ( ex != null) {
|
||||
TNode.printTree( ex.node );
|
||||
System.err.println("ANTLR Tree Parsing MismatchedTokenException Error: " + ex );
|
||||
ex.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
public void reportError(String s) {
|
||||
System.err.println("ANTLR Error from String: " + s);
|
||||
}
|
||||
public void reportWarning(String s) {
|
||||
System.err.println("ANTLR Warning from String: " + s);
|
||||
}
|
||||
protected void match(AST t, int ttype) throws MismatchedTokenException {
|
||||
//System.out.println("match("+ttype+"); cursor is "+t);
|
||||
super.match(t, ttype);
|
||||
}
|
||||
public void match(AST t, BitSet b) throws MismatchedTokenException {
|
||||
//System.out.println("match("+b+"); cursor is "+t);
|
||||
super.match(t, b);
|
||||
}
|
||||
protected void matchNot(AST t, int ttype) throws MismatchedTokenException {
|
||||
//System.out.println("matchNot("+ttype+"); cursor is "+t);
|
||||
super.matchNot(t, ttype);
|
||||
}
|
||||
public void traceIn(String rname, AST t) {
|
||||
traceDepth += 1;
|
||||
for (int x=0; x<traceDepth; x++) System.out.print(" ");
|
||||
super.traceIn(rname, t);
|
||||
}
|
||||
public void traceOut(String rname, AST t) {
|
||||
for (int x=0; x<traceDepth; x++) System.out.print(" ");
|
||||
super.traceOut(rname, t);
|
||||
traceDepth -= 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
translationUnit options {
|
||||
defaultErrorHandler=false;
|
||||
}
|
||||
: ( externalList )?
|
||||
;
|
||||
|
||||
/*
|
||||
exception
|
||||
catch [RecognitionException ex]
|
||||
{
|
||||
reportError(ex);
|
||||
System.out.println("PROBLEM TREE:\n"
|
||||
+ _t.toStringList());
|
||||
if (_t!=null) {_t = _t.getNextSibling();}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
externalList
|
||||
: ( externalDef )+
|
||||
;
|
||||
|
||||
|
||||
externalDef
|
||||
: declaration
|
||||
| functionDef
|
||||
| asm_expr
|
||||
| SEMI
|
||||
| typelessDeclaration
|
||||
;
|
||||
|
||||
typelessDeclaration
|
||||
: #(NTypeMissing initDeclList SEMI)
|
||||
;
|
||||
|
||||
|
||||
|
||||
asm_expr
|
||||
: #( "asm" ( "volatile" )? LCURLY expr RCURLY ( SEMI )+ )
|
||||
;
|
||||
|
||||
|
||||
declaration
|
||||
: #( NDeclaration
|
||||
declSpecifiers
|
||||
(
|
||||
initDeclList
|
||||
)?
|
||||
( SEMI )+
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
declSpecifiers
|
||||
: ( storageClassSpecifier
|
||||
| typeQualifier
|
||||
| typeSpecifier
|
||||
)+
|
||||
;
|
||||
|
||||
storageClassSpecifier
|
||||
: "auto"
|
||||
| "register"
|
||||
| "typedef"
|
||||
| functionStorageClassSpecifier
|
||||
;
|
||||
|
||||
|
||||
functionStorageClassSpecifier
|
||||
: "extern"
|
||||
| "static"
|
||||
| "inline"
|
||||
;
|
||||
|
||||
|
||||
typeQualifier
|
||||
: "const"
|
||||
| "volatile"
|
||||
;
|
||||
|
||||
|
||||
typeSpecifier
|
||||
: "void"
|
||||
| "char"
|
||||
| "short"
|
||||
| "int"
|
||||
| "long"
|
||||
| "float"
|
||||
| "double"
|
||||
| "signed"
|
||||
| "unsigned"
|
||||
| "byte"
|
||||
| "boolean"
|
||||
| "Servo"
|
||||
| "Wire"
|
||||
| structSpecifier ( attributeDecl )*
|
||||
| unionSpecifier ( attributeDecl )*
|
||||
| enumSpecifier
|
||||
| typedefName
|
||||
| #("typeof" LPAREN
|
||||
( (typeName )=> typeName
|
||||
| expr
|
||||
)
|
||||
RPAREN
|
||||
)
|
||||
| "__complex"
|
||||
;
|
||||
|
||||
|
||||
typedefName
|
||||
: #(NTypedefName ID)
|
||||
;
|
||||
|
||||
|
||||
structSpecifier
|
||||
: #( "struct" structOrUnionBody )
|
||||
;
|
||||
|
||||
unionSpecifier
|
||||
: #( "union" structOrUnionBody )
|
||||
;
|
||||
|
||||
structOrUnionBody
|
||||
: ( (ID LCURLY) => ID LCURLY
|
||||
( structDeclarationList )?
|
||||
RCURLY
|
||||
| LCURLY
|
||||
( structDeclarationList )?
|
||||
RCURLY
|
||||
| ID
|
||||
)
|
||||
;
|
||||
/*
|
||||
exception
|
||||
catch [RecognitionException ex]
|
||||
{
|
||||
reportError(ex);
|
||||
System.out.println("PROBLEM TREE:\n"
|
||||
+ _t.toStringList());
|
||||
if (_t!=null) {_t = _t.getNextSibling();}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
structDeclarationList
|
||||
: ( structDeclaration )+
|
||||
;
|
||||
/*
|
||||
exception
|
||||
catch [RecognitionException ex]
|
||||
{
|
||||
reportError(ex);
|
||||
System.out.println("PROBLEM TREE:\n"
|
||||
+ _t.toStringList());
|
||||
if (_t!=null) {_t = _t.getNextSibling();}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
structDeclaration
|
||||
: specifierQualifierList structDeclaratorList
|
||||
;
|
||||
/*
|
||||
exception
|
||||
catch [RecognitionException ex]
|
||||
{
|
||||
reportError(ex);
|
||||
System.out.println("PROBLEM TREE:\n"
|
||||
+ _t.toStringList());
|
||||
if (_t!=null) {_t = _t.getNextSibling();}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
specifierQualifierList
|
||||
: (
|
||||
typeSpecifier
|
||||
| typeQualifier
|
||||
)+
|
||||
;
|
||||
/*
|
||||
exception
|
||||
catch [RecognitionException ex]
|
||||
{
|
||||
reportError(ex);
|
||||
System.out.println("PROBLEM TREE:\n"
|
||||
+ _t.toStringList());
|
||||
if (_t!=null) {_t = _t.getNextSibling();}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
structDeclaratorList
|
||||
: ( structDeclarator )+
|
||||
;
|
||||
/*
|
||||
exception
|
||||
catch [RecognitionException ex]
|
||||
{
|
||||
reportError(ex);
|
||||
System.out.println("PROBLEM TREE:\n"
|
||||
+ _t.toStringList());
|
||||
if (_t!=null) {_t = _t.getNextSibling();}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
structDeclarator
|
||||
:
|
||||
#( NStructDeclarator
|
||||
( declarator )?
|
||||
( COLON expr )?
|
||||
( attributeDecl )*
|
||||
)
|
||||
;
|
||||
/*
|
||||
exception
|
||||
catch [RecognitionException ex]
|
||||
{
|
||||
reportError(ex);
|
||||
System.out.println("PROBLEM TREE:\n"
|
||||
+ _t.toStringList());
|
||||
if (_t!=null) {_t = _t.getNextSibling();}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
enumSpecifier
|
||||
: #( "enum"
|
||||
( ID )?
|
||||
( LCURLY enumList RCURLY )?
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
enumList
|
||||
: ( enumerator )+
|
||||
;
|
||||
|
||||
|
||||
enumerator
|
||||
: ID ( ASSIGN expr )?
|
||||
;
|
||||
|
||||
|
||||
|
||||
attributeDecl:
|
||||
#( "__attribute" (.)* )
|
||||
| #( NAsmAttribute LPAREN expr RPAREN )
|
||||
;
|
||||
|
||||
initDeclList
|
||||
: ( initDecl )+
|
||||
;
|
||||
|
||||
|
||||
initDecl
|
||||
{ String declName = ""; }
|
||||
: #( NInitDecl
|
||||
declarator
|
||||
( attributeDecl )*
|
||||
( ASSIGN initializer
|
||||
| COLON expr
|
||||
)?
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
pointerGroup
|
||||
: #( NPointerGroup ( STAR ( typeQualifier )* )+ )
|
||||
;
|
||||
|
||||
|
||||
|
||||
idList
|
||||
: ID ( COMMA ID )*
|
||||
;
|
||||
|
||||
|
||||
|
||||
initializer
|
||||
: #( NInitializer (initializerElementLabel)? expr )
|
||||
| lcurlyInitializer
|
||||
;
|
||||
|
||||
initializerElementLabel
|
||||
: #( NInitializerElementLabel
|
||||
(
|
||||
( LBRACKET expr RBRACKET (ASSIGN)? )
|
||||
| ID COLON
|
||||
| DOT ID ASSIGN
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
lcurlyInitializer
|
||||
: #( NLcurlyInitializer
|
||||
initializerList
|
||||
RCURLY
|
||||
)
|
||||
;
|
||||
|
||||
initializerList
|
||||
: ( initializer )*
|
||||
;
|
||||
|
||||
|
||||
declarator
|
||||
: #( NDeclarator
|
||||
( pointerGroup )?
|
||||
|
||||
( id:ID
|
||||
| LPAREN declarator RPAREN
|
||||
)
|
||||
|
||||
( #( NParameterTypeList
|
||||
(
|
||||
parameterTypeList
|
||||
| (idList)?
|
||||
)
|
||||
RPAREN
|
||||
)
|
||||
| LBRACKET ( expr )? RBRACKET
|
||||
)*
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
|
||||
parameterTypeList
|
||||
: ( parameterDeclaration ( COMMA | SEMI )? )+ ( VARARGS )?
|
||||
;
|
||||
|
||||
|
||||
|
||||
parameterDeclaration
|
||||
: #( NParameterDeclaration
|
||||
declSpecifiers
|
||||
(declarator | nonemptyAbstractDeclarator)?
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
functionDef
|
||||
: #( NFunctionDef
|
||||
( functionDeclSpecifiers)?
|
||||
declarator
|
||||
(declaration | VARARGS)*
|
||||
compoundStatement
|
||||
)
|
||||
;
|
||||
/*
|
||||
exception
|
||||
catch [RecognitionException ex]
|
||||
{
|
||||
reportError(ex);
|
||||
System.out.println("PROBLEM TREE:\n"
|
||||
+ _t.toStringList());
|
||||
if (_t!=null) {_t = _t.getNextSibling();}
|
||||
}
|
||||
*/
|
||||
|
||||
functionDeclSpecifiers
|
||||
:
|
||||
( functionStorageClassSpecifier
|
||||
| typeQualifier
|
||||
| typeSpecifier
|
||||
)+
|
||||
;
|
||||
|
||||
declarationList
|
||||
:
|
||||
( //ANTLR doesn't know that declarationList properly eats all the declarations
|
||||
//so it warns about the ambiguity
|
||||
options {
|
||||
warnWhenFollowAmbig = false;
|
||||
} :
|
||||
localLabelDecl
|
||||
| declaration
|
||||
)+
|
||||
;
|
||||
|
||||
localLabelDecl
|
||||
: #("__label__" (ID)+ )
|
||||
;
|
||||
|
||||
|
||||
|
||||
compoundStatement
|
||||
: #( NCompoundStatement
|
||||
( declarationList
|
||||
| functionDef
|
||||
)*
|
||||
( statementList )?
|
||||
RCURLY
|
||||
)
|
||||
;
|
||||
|
||||
statementList
|
||||
: ( statement )+
|
||||
;
|
||||
|
||||
statement
|
||||
: statementBody
|
||||
;
|
||||
|
||||
statementBody
|
||||
: SEMI // Empty statements
|
||||
|
||||
| compoundStatement // Group of statements
|
||||
|
||||
| #(NStatementExpr expr) // Expressions
|
||||
|
||||
// Iteration statements:
|
||||
|
||||
| #( "while" expr statement )
|
||||
| #( "do" statement expr )
|
||||
| #( "for"
|
||||
expr expr expr
|
||||
statement
|
||||
)
|
||||
|
||||
|
||||
// Jump statements:
|
||||
|
||||
| #( "goto" expr )
|
||||
| "continue"
|
||||
| "break"
|
||||
| #( "return" ( expr )? )
|
||||
|
||||
|
||||
// Labeled statements:
|
||||
| #( NLabel ID (statement)? )
|
||||
| #( "case" expr (statement)? )
|
||||
| #( "default" (statement)? )
|
||||
|
||||
|
||||
|
||||
// Selection statements:
|
||||
|
||||
| #( "if"
|
||||
expr statement
|
||||
( "else" statement )?
|
||||
)
|
||||
| #( "switch" expr statement )
|
||||
|
||||
|
||||
|
||||
;
|
||||
/*
|
||||
exception
|
||||
catch [RecognitionException ex]
|
||||
{
|
||||
reportError(ex);
|
||||
System.out.println("PROBLEM TREE:\n"
|
||||
+ _t.toStringList());
|
||||
if (_t!=null) {_t = _t.getNextSibling();}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
expr
|
||||
: assignExpr
|
||||
| conditionalExpr
|
||||
| logicalOrExpr
|
||||
| logicalAndExpr
|
||||
| inclusiveOrExpr
|
||||
| exclusiveOrExpr
|
||||
| bitAndExpr
|
||||
| equalityExpr
|
||||
| relationalExpr
|
||||
| shiftExpr
|
||||
| additiveExpr
|
||||
| multExpr
|
||||
| castExpr
|
||||
| unaryExpr
|
||||
| postfixExpr
|
||||
| primaryExpr
|
||||
| commaExpr
|
||||
| emptyExpr
|
||||
| compoundStatementExpr
|
||||
| initializer
|
||||
| rangeExpr
|
||||
| gnuAsmExpr
|
||||
;
|
||||
|
||||
commaExpr
|
||||
: #(NCommaExpr expr expr)
|
||||
;
|
||||
|
||||
emptyExpr
|
||||
: NEmptyExpression
|
||||
;
|
||||
|
||||
compoundStatementExpr
|
||||
: #(LPAREN compoundStatement RPAREN)
|
||||
;
|
||||
|
||||
rangeExpr
|
||||
: #(NRangeExpr expr VARARGS expr)
|
||||
;
|
||||
|
||||
gnuAsmExpr
|
||||
: #(NGnuAsmExpr
|
||||
("volatile")?
|
||||
LPAREN stringConst
|
||||
( options { warnWhenFollowAmbig = false; }:
|
||||
COLON (strOptExprPair ( COMMA strOptExprPair)* )?
|
||||
( options { warnWhenFollowAmbig = false; }:
|
||||
COLON (strOptExprPair ( COMMA strOptExprPair)* )?
|
||||
)?
|
||||
)?
|
||||
( COLON stringConst ( COMMA stringConst)* )?
|
||||
RPAREN
|
||||
)
|
||||
;
|
||||
|
||||
strOptExprPair
|
||||
: stringConst ( LPAREN expr RPAREN )?
|
||||
;
|
||||
|
||||
assignExpr
|
||||
: #( ASSIGN expr expr)
|
||||
| #( DIV_ASSIGN expr expr)
|
||||
| #( PLUS_ASSIGN expr expr)
|
||||
| #( MINUS_ASSIGN expr expr)
|
||||
| #( STAR_ASSIGN expr expr)
|
||||
| #( MOD_ASSIGN expr expr)
|
||||
| #( RSHIFT_ASSIGN expr expr)
|
||||
| #( LSHIFT_ASSIGN expr expr)
|
||||
| #( BAND_ASSIGN expr expr)
|
||||
| #( BOR_ASSIGN expr expr)
|
||||
| #( BXOR_ASSIGN expr expr)
|
||||
;
|
||||
|
||||
|
||||
conditionalExpr
|
||||
: #( QUESTION expr (expr)? COLON expr )
|
||||
;
|
||||
|
||||
|
||||
logicalOrExpr
|
||||
: #( LOR expr expr)
|
||||
;
|
||||
|
||||
|
||||
logicalAndExpr
|
||||
: #( LAND expr expr )
|
||||
;
|
||||
|
||||
|
||||
inclusiveOrExpr
|
||||
: #( BOR expr expr )
|
||||
;
|
||||
|
||||
|
||||
exclusiveOrExpr
|
||||
: #( BXOR expr expr )
|
||||
;
|
||||
|
||||
|
||||
bitAndExpr
|
||||
: #( BAND expr expr )
|
||||
;
|
||||
|
||||
|
||||
|
||||
equalityExpr
|
||||
: #( EQUAL expr expr)
|
||||
| #( NOT_EQUAL expr expr)
|
||||
;
|
||||
|
||||
|
||||
relationalExpr
|
||||
: #( LT expr expr)
|
||||
| #( LTE expr expr)
|
||||
| #( GT expr expr)
|
||||
| #( GTE expr expr)
|
||||
;
|
||||
|
||||
|
||||
|
||||
shiftExpr
|
||||
: #( LSHIFT expr expr)
|
||||
| #( RSHIFT expr expr)
|
||||
;
|
||||
|
||||
|
||||
additiveExpr
|
||||
: #( PLUS expr expr)
|
||||
| #( MINUS expr expr)
|
||||
;
|
||||
|
||||
|
||||
multExpr
|
||||
: #( STAR expr expr)
|
||||
| #( DIV expr expr)
|
||||
| #( MOD expr expr)
|
||||
;
|
||||
|
||||
|
||||
|
||||
castExpr
|
||||
: #( NCast typeName RPAREN expr)
|
||||
;
|
||||
|
||||
|
||||
typeName
|
||||
: specifierQualifierList (nonemptyAbstractDeclarator)?
|
||||
;
|
||||
|
||||
nonemptyAbstractDeclarator
|
||||
: #( NNonemptyAbstractDeclarator
|
||||
( pointerGroup
|
||||
( (LPAREN
|
||||
( nonemptyAbstractDeclarator
|
||||
| parameterTypeList
|
||||
)?
|
||||
RPAREN)
|
||||
| (LBRACKET (expr)? RBRACKET)
|
||||
)*
|
||||
|
||||
| ( (LPAREN
|
||||
( nonemptyAbstractDeclarator
|
||||
| parameterTypeList
|
||||
)?
|
||||
RPAREN)
|
||||
| (LBRACKET (expr)? RBRACKET)
|
||||
)+
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
|
||||
unaryExpr
|
||||
: #( INC expr )
|
||||
| #( DEC expr )
|
||||
| #( NUnaryExpr unaryOperator expr)
|
||||
| #( "sizeof"
|
||||
( ( LPAREN typeName )=> LPAREN typeName RPAREN
|
||||
| expr
|
||||
)
|
||||
)
|
||||
| #( "__alignof"
|
||||
( ( LPAREN typeName )=> LPAREN typeName RPAREN
|
||||
| expr
|
||||
)
|
||||
)
|
||||
;
|
||||
/*
|
||||
exception
|
||||
catch [RecognitionException ex]
|
||||
{
|
||||
reportError(ex);
|
||||
System.out.println("PROBLEM TREE:\n"
|
||||
+ _t.toStringList());
|
||||
if (_t!=null) {_t = _t.getNextSibling();}
|
||||
}
|
||||
*/
|
||||
|
||||
unaryOperator
|
||||
: BAND
|
||||
| STAR
|
||||
| PLUS
|
||||
| MINUS
|
||||
| BNOT
|
||||
| LNOT
|
||||
| LAND
|
||||
| "__real"
|
||||
| "__imag"
|
||||
;
|
||||
|
||||
|
||||
postfixExpr
|
||||
: #( NPostfixExpr
|
||||
primaryExpr
|
||||
( PTR ID
|
||||
| DOT ID
|
||||
| #( NFunctionCallArgs (argExprList)? RPAREN )
|
||||
| LBRACKET expr RBRACKET
|
||||
| INC
|
||||
| DEC
|
||||
)+
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
|
||||
primaryExpr
|
||||
: ID
|
||||
| Number
|
||||
| charConst
|
||||
| stringConst
|
||||
|
||||
// JTC:
|
||||
// ID should catch the enumerator
|
||||
// leaving it in gives ambiguous err
|
||||
// | enumerator
|
||||
|
||||
| #( NExpressionGroup expr )
|
||||
;
|
||||
|
||||
|
||||
|
||||
argExprList
|
||||
: ( expr )+
|
||||
;
|
||||
|
||||
|
||||
|
||||
protected
|
||||
charConst
|
||||
: CharLiteral
|
||||
;
|
||||
|
||||
|
||||
protected
|
||||
stringConst
|
||||
: #(NStringSeq (StringLiteral)+)
|
||||
;
|
||||
|
||||
|
||||
protected
|
||||
intConst
|
||||
: IntOctalConst
|
||||
| LongOctalConst
|
||||
| UnsignedOctalConst
|
||||
| IntIntConst
|
||||
| LongIntConst
|
||||
| UnsignedIntConst
|
||||
| IntHexConst
|
||||
| LongHexConst
|
||||
| UnsignedHexConst
|
||||
;
|
||||
|
||||
|
||||
protected
|
||||
floatConst
|
||||
: FloatDoubleConst
|
||||
| DoubleDoubleConst
|
||||
| LongDoubleConst
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
5551
app/preproc/WTreeParser.java
Normal file
5551
app/preproc/WTreeParser.java
Normal file
File diff suppressed because it is too large
Load Diff
162
app/preproc/WTreeParserTokenTypes.java
Normal file
162
app/preproc/WTreeParserTokenTypes.java
Normal file
@ -0,0 +1,162 @@
|
||||
// $ANTLR 2.7.2: "WTreeParser.g" -> "WTreeParser.java"$
|
||||
|
||||
package processing.app.preproc;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import antlr.CommonAST;
|
||||
import antlr.DumpASTVisitor;
|
||||
|
||||
public interface WTreeParserTokenTypes {
|
||||
int EOF = 1;
|
||||
int NULL_TREE_LOOKAHEAD = 3;
|
||||
int LITERAL_typedef = 4;
|
||||
int LITERAL_asm = 5;
|
||||
int LITERAL_volatile = 6;
|
||||
int LCURLY = 7;
|
||||
int RCURLY = 8;
|
||||
int SEMI = 9;
|
||||
int LITERAL_struct = 10;
|
||||
int LITERAL_union = 11;
|
||||
int LITERAL_enum = 12;
|
||||
int LITERAL_auto = 13;
|
||||
int LITERAL_register = 14;
|
||||
int LITERAL_extern = 15;
|
||||
int LITERAL_static = 16;
|
||||
int LITERAL_const = 17;
|
||||
int LITERAL_void = 18;
|
||||
int LITERAL_char = 19;
|
||||
int LITERAL_short = 20;
|
||||
int LITERAL_int = 21;
|
||||
int LITERAL_long = 22;
|
||||
int LITERAL_float = 23;
|
||||
int LITERAL_double = 24;
|
||||
int LITERAL_signed = 25;
|
||||
int LITERAL_unsigned = 26;
|
||||
int ID = 27;
|
||||
int COMMA = 28;
|
||||
int COLON = 29;
|
||||
int ASSIGN = 30;
|
||||
int STAR = 31;
|
||||
int LPAREN = 32;
|
||||
int RPAREN = 33;
|
||||
int LBRACKET = 34;
|
||||
int RBRACKET = 35;
|
||||
int VARARGS = 36;
|
||||
int LITERAL_while = 37;
|
||||
int LITERAL_do = 38;
|
||||
int LITERAL_for = 39;
|
||||
int LITERAL_goto = 40;
|
||||
int LITERAL_continue = 41;
|
||||
int LITERAL_break = 42;
|
||||
int LITERAL_return = 43;
|
||||
int LITERAL_case = 44;
|
||||
int LITERAL_default = 45;
|
||||
int LITERAL_if = 46;
|
||||
int LITERAL_else = 47;
|
||||
int LITERAL_switch = 48;
|
||||
int DIV_ASSIGN = 49;
|
||||
int PLUS_ASSIGN = 50;
|
||||
int MINUS_ASSIGN = 51;
|
||||
int STAR_ASSIGN = 52;
|
||||
int MOD_ASSIGN = 53;
|
||||
int RSHIFT_ASSIGN = 54;
|
||||
int LSHIFT_ASSIGN = 55;
|
||||
int BAND_ASSIGN = 56;
|
||||
int BOR_ASSIGN = 57;
|
||||
int BXOR_ASSIGN = 58;
|
||||
int QUESTION = 59;
|
||||
int LOR = 60;
|
||||
int LAND = 61;
|
||||
int BOR = 62;
|
||||
int BXOR = 63;
|
||||
int BAND = 64;
|
||||
int EQUAL = 65;
|
||||
int NOT_EQUAL = 66;
|
||||
int LT = 67;
|
||||
int LTE = 68;
|
||||
int GT = 69;
|
||||
int GTE = 70;
|
||||
int LSHIFT = 71;
|
||||
int RSHIFT = 72;
|
||||
int PLUS = 73;
|
||||
int MINUS = 74;
|
||||
int DIV = 75;
|
||||
int MOD = 76;
|
||||
int INC = 77;
|
||||
int DEC = 78;
|
||||
int LITERAL_sizeof = 79;
|
||||
int BNOT = 80;
|
||||
int LNOT = 81;
|
||||
int PTR = 82;
|
||||
int DOT = 83;
|
||||
int CharLiteral = 84;
|
||||
int StringLiteral = 85;
|
||||
int IntOctalConst = 86;
|
||||
int LongOctalConst = 87;
|
||||
int UnsignedOctalConst = 88;
|
||||
int IntIntConst = 89;
|
||||
int LongIntConst = 90;
|
||||
int UnsignedIntConst = 91;
|
||||
int IntHexConst = 92;
|
||||
int LongHexConst = 93;
|
||||
int UnsignedHexConst = 94;
|
||||
int FloatDoubleConst = 95;
|
||||
int DoubleDoubleConst = 96;
|
||||
int LongDoubleConst = 97;
|
||||
int NTypedefName = 98;
|
||||
int NInitDecl = 99;
|
||||
int NDeclarator = 100;
|
||||
int NStructDeclarator = 101;
|
||||
int NDeclaration = 102;
|
||||
int NCast = 103;
|
||||
int NPointerGroup = 104;
|
||||
int NExpressionGroup = 105;
|
||||
int NFunctionCallArgs = 106;
|
||||
int NNonemptyAbstractDeclarator = 107;
|
||||
int NInitializer = 108;
|
||||
int NStatementExpr = 109;
|
||||
int NEmptyExpression = 110;
|
||||
int NParameterTypeList = 111;
|
||||
int NFunctionDef = 112;
|
||||
int NCompoundStatement = 113;
|
||||
int NParameterDeclaration = 114;
|
||||
int NCommaExpr = 115;
|
||||
int NUnaryExpr = 116;
|
||||
int NLabel = 117;
|
||||
int NPostfixExpr = 118;
|
||||
int NRangeExpr = 119;
|
||||
int NStringSeq = 120;
|
||||
int NInitializerElementLabel = 121;
|
||||
int NLcurlyInitializer = 122;
|
||||
int NAsmAttribute = 123;
|
||||
int NGnuAsmExpr = 124;
|
||||
int NTypeMissing = 125;
|
||||
int Vocabulary = 126;
|
||||
int Whitespace = 127;
|
||||
int Comment = 128;
|
||||
int CPPComment = 129;
|
||||
int PREPROC_DIRECTIVE = 130;
|
||||
int Space = 131;
|
||||
int LineDirective = 132;
|
||||
int BadStringLiteral = 133;
|
||||
int Escape = 134;
|
||||
int Digit = 135;
|
||||
int LongSuffix = 136;
|
||||
int UnsignedSuffix = 137;
|
||||
int FloatSuffix = 138;
|
||||
int Exponent = 139;
|
||||
int Number = 140;
|
||||
int LITERAL___label__ = 141;
|
||||
int LITERAL_inline = 142;
|
||||
int LITERAL_byte = 143;
|
||||
int LITERAL_boolean = 144;
|
||||
int LITERAL_Servo = 145;
|
||||
int LITERAL_Wire = 146;
|
||||
int LITERAL_typeof = 147;
|
||||
int LITERAL___complex = 148;
|
||||
int LITERAL___attribute = 149;
|
||||
int LITERAL___alignof = 150;
|
||||
int LITERAL___real = 151;
|
||||
int LITERAL___imag = 152;
|
||||
}
|
151
app/preproc/WTreeParserTokenTypes.txt
Normal file
151
app/preproc/WTreeParserTokenTypes.txt
Normal file
@ -0,0 +1,151 @@
|
||||
// $ANTLR 2.7.2: WTreeParser.g -> WTreeParserTokenTypes.txt$
|
||||
WTreeParser // output token vocab name
|
||||
LITERAL_typedef="typedef"=4
|
||||
LITERAL_asm="asm"=5
|
||||
LITERAL_volatile="volatile"=6
|
||||
LCURLY=7
|
||||
RCURLY=8
|
||||
SEMI=9
|
||||
LITERAL_struct="struct"=10
|
||||
LITERAL_union="union"=11
|
||||
LITERAL_enum="enum"=12
|
||||
LITERAL_auto="auto"=13
|
||||
LITERAL_register="register"=14
|
||||
LITERAL_extern="extern"=15
|
||||
LITERAL_static="static"=16
|
||||
LITERAL_const="const"=17
|
||||
LITERAL_void="void"=18
|
||||
LITERAL_char="char"=19
|
||||
LITERAL_short="short"=20
|
||||
LITERAL_int="int"=21
|
||||
LITERAL_long="long"=22
|
||||
LITERAL_float="float"=23
|
||||
LITERAL_double="double"=24
|
||||
LITERAL_signed="signed"=25
|
||||
LITERAL_unsigned="unsigned"=26
|
||||
ID=27
|
||||
COMMA=28
|
||||
COLON=29
|
||||
ASSIGN=30
|
||||
STAR=31
|
||||
LPAREN=32
|
||||
RPAREN=33
|
||||
LBRACKET=34
|
||||
RBRACKET=35
|
||||
VARARGS=36
|
||||
LITERAL_while="while"=37
|
||||
LITERAL_do="do"=38
|
||||
LITERAL_for="for"=39
|
||||
LITERAL_goto="goto"=40
|
||||
LITERAL_continue="continue"=41
|
||||
LITERAL_break="break"=42
|
||||
LITERAL_return="return"=43
|
||||
LITERAL_case="case"=44
|
||||
LITERAL_default="default"=45
|
||||
LITERAL_if="if"=46
|
||||
LITERAL_else="else"=47
|
||||
LITERAL_switch="switch"=48
|
||||
DIV_ASSIGN=49
|
||||
PLUS_ASSIGN=50
|
||||
MINUS_ASSIGN=51
|
||||
STAR_ASSIGN=52
|
||||
MOD_ASSIGN=53
|
||||
RSHIFT_ASSIGN=54
|
||||
LSHIFT_ASSIGN=55
|
||||
BAND_ASSIGN=56
|
||||
BOR_ASSIGN=57
|
||||
BXOR_ASSIGN=58
|
||||
QUESTION=59
|
||||
LOR=60
|
||||
LAND=61
|
||||
BOR=62
|
||||
BXOR=63
|
||||
BAND=64
|
||||
EQUAL=65
|
||||
NOT_EQUAL=66
|
||||
LT=67
|
||||
LTE=68
|
||||
GT=69
|
||||
GTE=70
|
||||
LSHIFT=71
|
||||
RSHIFT=72
|
||||
PLUS=73
|
||||
MINUS=74
|
||||
DIV=75
|
||||
MOD=76
|
||||
INC=77
|
||||
DEC=78
|
||||
LITERAL_sizeof="sizeof"=79
|
||||
BNOT=80
|
||||
LNOT=81
|
||||
PTR=82
|
||||
DOT=83
|
||||
CharLiteral=84
|
||||
StringLiteral=85
|
||||
IntOctalConst=86
|
||||
LongOctalConst=87
|
||||
UnsignedOctalConst=88
|
||||
IntIntConst=89
|
||||
LongIntConst=90
|
||||
UnsignedIntConst=91
|
||||
IntHexConst=92
|
||||
LongHexConst=93
|
||||
UnsignedHexConst=94
|
||||
FloatDoubleConst=95
|
||||
DoubleDoubleConst=96
|
||||
LongDoubleConst=97
|
||||
NTypedefName=98
|
||||
NInitDecl=99
|
||||
NDeclarator=100
|
||||
NStructDeclarator=101
|
||||
NDeclaration=102
|
||||
NCast=103
|
||||
NPointerGroup=104
|
||||
NExpressionGroup=105
|
||||
NFunctionCallArgs=106
|
||||
NNonemptyAbstractDeclarator=107
|
||||
NInitializer=108
|
||||
NStatementExpr=109
|
||||
NEmptyExpression=110
|
||||
NParameterTypeList=111
|
||||
NFunctionDef=112
|
||||
NCompoundStatement=113
|
||||
NParameterDeclaration=114
|
||||
NCommaExpr=115
|
||||
NUnaryExpr=116
|
||||
NLabel=117
|
||||
NPostfixExpr=118
|
||||
NRangeExpr=119
|
||||
NStringSeq=120
|
||||
NInitializerElementLabel=121
|
||||
NLcurlyInitializer=122
|
||||
NAsmAttribute=123
|
||||
NGnuAsmExpr=124
|
||||
NTypeMissing=125
|
||||
Vocabulary=126
|
||||
Whitespace=127
|
||||
Comment=128
|
||||
CPPComment=129
|
||||
PREPROC_DIRECTIVE("a line directive")=130
|
||||
Space=131
|
||||
LineDirective=132
|
||||
BadStringLiteral=133
|
||||
Escape=134
|
||||
Digit=135
|
||||
LongSuffix=136
|
||||
UnsignedSuffix=137
|
||||
FloatSuffix=138
|
||||
Exponent=139
|
||||
Number=140
|
||||
LITERAL___label__="__label__"=141
|
||||
LITERAL_inline="inline"=142
|
||||
LITERAL_byte="byte"=143
|
||||
LITERAL_boolean="boolean"=144
|
||||
LITERAL_Servo="Servo"=145
|
||||
LITERAL_Wire="Wire"=146
|
||||
LITERAL_typeof="typeof"=147
|
||||
LITERAL___complex="__complex"=148
|
||||
LITERAL___attribute="__attribute"=149
|
||||
LITERAL___alignof="__alignof"=150
|
||||
LITERAL___real="__real"=151
|
||||
LITERAL___imag="__imag"=152
|
@ -1,11 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -f *Lexer.java
|
||||
rm -f *Recognizer.java
|
||||
rm -f *TokenTypes.java
|
||||
rm -f *TokenTypes.txt
|
||||
rm -f *TreeParser.java
|
||||
rm -f *TreeParserTokenTypes.java
|
||||
rm -f *TreeParserTokenTypes.txt
|
||||
rm -f expanded*.g
|
||||
|
1057
app/preproc/expandedWEmitter.g
Normal file
1057
app/preproc/expandedWEmitter.g
Normal file
File diff suppressed because it is too large
Load Diff
1335
app/preproc/expandedWParser.g
Normal file
1335
app/preproc/expandedWParser.g
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1276
app/preproc/java.g
1276
app/preproc/java.g
File diff suppressed because it is too large
Load Diff
@ -1,326 +0,0 @@
|
||||
package antlr;
|
||||
|
||||
|
||||
/** Java 1.3 AST Recognizer Grammar
|
||||
*
|
||||
* Author: (see java.g preamble)
|
||||
*
|
||||
* This grammar is in the PUBLIC DOMAIN
|
||||
*/
|
||||
class JavaTreeParser extends TreeParser;
|
||||
|
||||
options {
|
||||
importVocab = Java;
|
||||
}
|
||||
|
||||
compilationUnit
|
||||
: (packageDefinition)?
|
||||
(importDefinition)*
|
||||
(typeDefinition)*
|
||||
;
|
||||
|
||||
packageDefinition
|
||||
: #( PACKAGE_DEF identifier )
|
||||
;
|
||||
|
||||
importDefinition
|
||||
: #( IMPORT identifierStar )
|
||||
;
|
||||
|
||||
typeDefinition
|
||||
: #(CLASS_DEF modifiers IDENT extendsClause implementsClause objBlock )
|
||||
| #(INTERFACE_DEF modifiers IDENT extendsClause interfaceBlock )
|
||||
;
|
||||
|
||||
typeSpec
|
||||
: #(TYPE typeSpecArray)
|
||||
;
|
||||
|
||||
typeSpecArray
|
||||
: #( ARRAY_DECLARATOR typeSpecArray )
|
||||
| type
|
||||
;
|
||||
|
||||
type: identifier
|
||||
| builtInType
|
||||
;
|
||||
|
||||
builtInType
|
||||
: "void"
|
||||
| "boolean"
|
||||
| "byte"
|
||||
| "char"
|
||||
| "short"
|
||||
| "int"
|
||||
| "float"
|
||||
| "long"
|
||||
| "double"
|
||||
;
|
||||
|
||||
modifiers
|
||||
: #( MODIFIERS (modifier)* )
|
||||
;
|
||||
|
||||
modifier
|
||||
: "private"
|
||||
| "public"
|
||||
| "protected"
|
||||
| "static"
|
||||
| "transient"
|
||||
| "final"
|
||||
| "abstract"
|
||||
| "native"
|
||||
| "threadsafe"
|
||||
| "synchronized"
|
||||
| "const"
|
||||
| "volatile"
|
||||
| "strictfp"
|
||||
;
|
||||
|
||||
extendsClause
|
||||
: #(EXTENDS_CLAUSE (identifier)* )
|
||||
;
|
||||
|
||||
implementsClause
|
||||
: #(IMPLEMENTS_CLAUSE (identifier)* )
|
||||
;
|
||||
|
||||
|
||||
interfaceBlock
|
||||
: #( OBJBLOCK
|
||||
( methodDecl
|
||||
| variableDef
|
||||
)*
|
||||
)
|
||||
;
|
||||
|
||||
objBlock
|
||||
: #( OBJBLOCK
|
||||
( ctorDef
|
||||
| methodDef
|
||||
| variableDef
|
||||
| typeDefinition
|
||||
| #(STATIC_INIT slist)
|
||||
| #(INSTANCE_INIT slist)
|
||||
)*
|
||||
)
|
||||
;
|
||||
|
||||
ctorDef
|
||||
: #(CTOR_DEF modifiers methodHead (slist)?)
|
||||
;
|
||||
|
||||
methodDecl
|
||||
: #(METHOD_DEF modifiers typeSpec methodHead)
|
||||
;
|
||||
|
||||
methodDef
|
||||
: #(METHOD_DEF modifiers typeSpec methodHead (slist)?)
|
||||
;
|
||||
|
||||
variableDef
|
||||
: #(VARIABLE_DEF modifiers typeSpec variableDeclarator varInitializer)
|
||||
;
|
||||
|
||||
parameterDef
|
||||
: #(PARAMETER_DEF modifiers typeSpec IDENT )
|
||||
;
|
||||
|
||||
objectinitializer
|
||||
: #(INSTANCE_INIT slist)
|
||||
;
|
||||
|
||||
variableDeclarator
|
||||
: IDENT
|
||||
| LBRACK variableDeclarator
|
||||
;
|
||||
|
||||
varInitializer
|
||||
: #(ASSIGN initializer)
|
||||
|
|
||||
;
|
||||
|
||||
initializer
|
||||
: expression
|
||||
| arrayInitializer
|
||||
;
|
||||
|
||||
arrayInitializer
|
||||
: #(ARRAY_INIT (initializer)*)
|
||||
;
|
||||
|
||||
methodHead
|
||||
: IDENT #( PARAMETERS (parameterDef)* ) (throwsClause)?
|
||||
;
|
||||
|
||||
throwsClause
|
||||
: #( "throws" (identifier)* )
|
||||
;
|
||||
|
||||
identifier
|
||||
: IDENT
|
||||
| #( DOT identifier IDENT )
|
||||
;
|
||||
|
||||
identifierStar
|
||||
: IDENT
|
||||
| #( DOT identifier (STAR|IDENT) )
|
||||
;
|
||||
|
||||
slist
|
||||
: #( SLIST (stat)* )
|
||||
;
|
||||
|
||||
stat: typeDefinition
|
||||
| variableDef
|
||||
| expression
|
||||
| #(LABELED_STAT IDENT stat)
|
||||
| #("if" expression stat (stat)? )
|
||||
| #( "for"
|
||||
#(FOR_INIT (variableDef | elist)?)
|
||||
#(FOR_CONDITION (expression)?)
|
||||
#(FOR_ITERATOR (elist)?)
|
||||
stat
|
||||
)
|
||||
| #("while" expression stat)
|
||||
| #("do" stat expression)
|
||||
| #("break" (IDENT)? )
|
||||
| #("continue" (IDENT)? )
|
||||
| #("return" (expression)? )
|
||||
| #("switch" expression (caseGroup)*)
|
||||
| #("throw" expression)
|
||||
| #("synchronized" expression stat)
|
||||
| tryBlock
|
||||
| slist // nested SLIST
|
||||
// uncomment to make assert JDK 1.4 stuff work
|
||||
| #("assert" expression (expression)?)
|
||||
| EMPTY_STAT
|
||||
;
|
||||
|
||||
caseGroup
|
||||
: #(CASE_GROUP (#("case" expression) | "default")+ slist)
|
||||
;
|
||||
|
||||
tryBlock
|
||||
: #( "try" slist (handler)* (#("finally" slist))? )
|
||||
;
|
||||
|
||||
handler
|
||||
: #( "catch" parameterDef slist )
|
||||
;
|
||||
|
||||
elist
|
||||
: #( ELIST (expression)* )
|
||||
;
|
||||
|
||||
expression
|
||||
: #(EXPR expr)
|
||||
;
|
||||
|
||||
expr: #(QUESTION expr expr expr) // trinary operator
|
||||
| #(ASSIGN expr expr) // binary operators...
|
||||
| #(PLUS_ASSIGN expr expr)
|
||||
| #(MINUS_ASSIGN expr expr)
|
||||
| #(STAR_ASSIGN expr expr)
|
||||
| #(DIV_ASSIGN expr expr)
|
||||
| #(MOD_ASSIGN expr expr)
|
||||
| #(SR_ASSIGN expr expr)
|
||||
| #(BSR_ASSIGN expr expr)
|
||||
| #(SL_ASSIGN expr expr)
|
||||
| #(BAND_ASSIGN expr expr)
|
||||
| #(BXOR_ASSIGN expr expr)
|
||||
| #(BOR_ASSIGN expr expr)
|
||||
| #(LOR expr expr)
|
||||
| #(LAND expr expr)
|
||||
| #(BOR expr expr)
|
||||
| #(BXOR expr expr)
|
||||
| #(BAND expr expr)
|
||||
| #(NOT_EQUAL expr expr)
|
||||
| #(EQUAL expr expr)
|
||||
| #(LT expr expr)
|
||||
| #(GT expr expr)
|
||||
| #(LE expr expr)
|
||||
| #(GE expr expr)
|
||||
| #(SL expr expr)
|
||||
| #(SR expr expr)
|
||||
| #(BSR expr expr)
|
||||
| #(PLUS expr expr)
|
||||
| #(MINUS expr expr)
|
||||
| #(DIV expr expr)
|
||||
| #(MOD expr expr)
|
||||
| #(STAR expr expr)
|
||||
| #(INC expr)
|
||||
| #(DEC expr)
|
||||
| #(POST_INC expr)
|
||||
| #(POST_DEC expr)
|
||||
| #(BNOT expr)
|
||||
| #(LNOT expr)
|
||||
| #("instanceof" expr expr)
|
||||
| #(UNARY_MINUS expr)
|
||||
| #(UNARY_PLUS expr)
|
||||
| primaryExpression
|
||||
;
|
||||
|
||||
primaryExpression
|
||||
: IDENT
|
||||
| #( DOT
|
||||
( expr
|
||||
( IDENT
|
||||
| arrayIndex
|
||||
| "this"
|
||||
| "class"
|
||||
| #( "new" IDENT elist )
|
||||
| "super"
|
||||
)
|
||||
| #(ARRAY_DECLARATOR typeSpecArray)
|
||||
| builtInType ("class")?
|
||||
)
|
||||
)
|
||||
| arrayIndex
|
||||
| #(METHOD_CALL primaryExpression elist)
|
||||
| ctorCall
|
||||
| #(TYPECAST typeSpec expr)
|
||||
| newExpression
|
||||
| constant
|
||||
| "super"
|
||||
| "true"
|
||||
| "false"
|
||||
| "this"
|
||||
| "null"
|
||||
| typeSpec // type name used with instanceof
|
||||
;
|
||||
|
||||
ctorCall
|
||||
: #( CTOR_CALL elist )
|
||||
| #( SUPER_CTOR_CALL
|
||||
( elist
|
||||
| primaryExpression elist
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
arrayIndex
|
||||
: #(INDEX_OP expr expression)
|
||||
;
|
||||
|
||||
constant
|
||||
: NUM_INT
|
||||
| CHAR_LITERAL
|
||||
| STRING_LITERAL
|
||||
| NUM_FLOAT
|
||||
| NUM_DOUBLE
|
||||
| NUM_LONG
|
||||
;
|
||||
|
||||
newExpression
|
||||
: #( "new" type
|
||||
( newArrayDeclarator (arrayInitializer)?
|
||||
| elist (objBlock)?
|
||||
)
|
||||
)
|
||||
|
||||
;
|
||||
|
||||
newArrayDeclarator
|
||||
: #( ARRAY_DECLARATOR (newArrayDeclarator)? (expression)? )
|
||||
;
|
@ -1,3 +0,0 @@
|
||||
java -cp ../../build/macosx/work/lib/antlr.jar antlr.Tool java.g
|
||||
# now build the pde stuff that extends the java classes
|
||||
java -cp ../../build/macosx/work/lib/antlr.jar antlr.Tool -glib java.g pde.g
|
@ -1,304 +0,0 @@
|
||||
/* -*- mode: antlr; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||
header {
|
||||
package processing.app.preproc;
|
||||
|
||||
import processing.app.*;
|
||||
}
|
||||
|
||||
class PdeRecognizer extends JavaRecognizer;
|
||||
|
||||
options {
|
||||
importVocab = Java;
|
||||
exportVocab = PdePartial;
|
||||
|
||||
codeGenMakeSwitchThreshold=10; // this is set high for debugging
|
||||
codeGenBitsetTestThreshold=10; // this is set high for debugging
|
||||
|
||||
// developers may to want to set this to true for better
|
||||
// debugging messages, however, doing so disables highlighting errors
|
||||
// in the editor.
|
||||
defaultErrorHandler = false; //true;
|
||||
}
|
||||
|
||||
tokens {
|
||||
CONSTRUCTOR_CAST; EMPTY_FIELD;
|
||||
}
|
||||
|
||||
pdeProgram
|
||||
// only java mode programs will have their own public classes or
|
||||
// imports (and they must have at least one)
|
||||
: ( "public" "class" | "import" ) => javaProgram
|
||||
{ PdePreprocessor.programType = PdePreprocessor.JAVA; }
|
||||
|
||||
// the syntactic predicate here looks for any minimal (thus
|
||||
// the non-greedy qualifier) number of fields, followed by
|
||||
// the tokens that represent the definition of loop() or
|
||||
// some other member function. java mode programs may have such
|
||||
// definitions, but they won't reach this point, having already been
|
||||
// selected in the previous alternative. static mode programs
|
||||
// don't have member functions.
|
||||
//
|
||||
| ( ( options {greedy=false;}: possiblyEmptyField)* "void" IDENT LPAREN )
|
||||
=> activeProgram
|
||||
{ PdePreprocessor.programType = PdePreprocessor.ACTIVE; }
|
||||
|
||||
| staticProgram
|
||||
{ PdePreprocessor.programType = PdePreprocessor.STATIC; }
|
||||
;
|
||||
|
||||
// advanced mode is really just a normal java file
|
||||
javaProgram
|
||||
: compilationUnit
|
||||
;
|
||||
|
||||
activeProgram
|
||||
: (possiblyEmptyField)+
|
||||
;
|
||||
|
||||
staticProgram
|
||||
: (statement)*
|
||||
;
|
||||
|
||||
// copy of the java.g rule with WEBCOLOR_LITERAL added
|
||||
constant
|
||||
: NUM_INT
|
||||
| CHAR_LITERAL
|
||||
| STRING_LITERAL
|
||||
| NUM_FLOAT
|
||||
| NUM_LONG
|
||||
| NUM_DOUBLE
|
||||
| webcolor_literal
|
||||
;
|
||||
|
||||
// of the form #cc008f in PDE
|
||||
webcolor_literal
|
||||
: w:WEBCOLOR_LITERAL
|
||||
{ Preferences.getBoolean("preproc.web_colors") &&
|
||||
w.getText().length() == 6 }? // must be exactly 6 hex digits
|
||||
;
|
||||
|
||||
// copy of the java.g builtInType rule
|
||||
builtInConsCastType
|
||||
: "void"
|
||||
| "boolean"
|
||||
| "byte"
|
||||
| "char"
|
||||
| "short"
|
||||
| "int"
|
||||
| "float"
|
||||
| "long"
|
||||
| "double"
|
||||
;
|
||||
|
||||
// our types include the java types and "color". this is separated into two
|
||||
// rules so that constructor casts can just use the original typelist, since
|
||||
// we don't want to support the color type as a constructor cast.
|
||||
//
|
||||
builtInType
|
||||
: builtInConsCastType
|
||||
| "color" // aliased to an int in PDE
|
||||
{ Preferences.getBoolean("preproc.color_datatype") }?
|
||||
;
|
||||
|
||||
// constructor style casts.
|
||||
constructorCast!
|
||||
: t:consCastTypeSpec[true]
|
||||
LPAREN!
|
||||
e:expression
|
||||
RPAREN!
|
||||
// if this is a string literal, make sure the type we're trying to cast
|
||||
// to is one of the supported ones
|
||||
//
|
||||
{ #e.getType() != STRING_LITERAL ||
|
||||
( #t.getType() == LITERAL_byte ||
|
||||
#t.getType() == LITERAL_double ||
|
||||
#t.getType() == LITERAL_float ||
|
||||
#t.getType() == LITERAL_int ||
|
||||
#t.getType() == LITERAL_long ||
|
||||
#t.getType() == LITERAL_short ) }?
|
||||
// create the node
|
||||
//
|
||||
{#constructorCast = #(#[CONSTRUCTOR_CAST,"CONSTRUCTOR_CAST"], t, e);}
|
||||
;
|
||||
|
||||
// A list of types that be used as the destination type in a constructor-style
|
||||
// cast. Ideally, this would include all class types, not just "String".
|
||||
// Unfortunately, it's not possible to tell whether Foo(5) is supposed to be
|
||||
// a method call or a constructor cast without have a table of all valid
|
||||
// types or methods, which requires semantic analysis (eg processing of import
|
||||
// statements). So we accept the set of built-in types plus "String".
|
||||
//
|
||||
consCastTypeSpec[boolean addImagNode]
|
||||
// : stringTypeSpec[addImagNode]
|
||||
// | builtInConsCastTypeSpec[addImagNode]
|
||||
: builtInConsCastTypeSpec[addImagNode]
|
||||
// trying to remove String() cast [fry]
|
||||
;
|
||||
|
||||
//stringTypeSpec[boolean addImagNode]
|
||||
// : id:IDENT { #id.getText().equals("String") }?
|
||||
// {
|
||||
// if ( addImagNode ) {
|
||||
// #stringTypeSpec = #(#[TYPE,"TYPE"],
|
||||
// #stringTypeSpec);
|
||||
// }
|
||||
// }
|
||||
// ;
|
||||
|
||||
builtInConsCastTypeSpec[boolean addImagNode]
|
||||
: builtInConsCastType
|
||||
{
|
||||
if ( addImagNode ) {
|
||||
#builtInConsCastTypeSpec = #(#[TYPE,"TYPE"],
|
||||
#builtInConsCastTypeSpec);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
// Since "color" tokens are lexed as LITERAL_color now, we need to have a rule
|
||||
// that can generate a method call from an expression that starts with this
|
||||
// token
|
||||
//
|
||||
colorMethodCall
|
||||
: c:"color" {#c.setType(IDENT);} // this would default to LITERAL_color
|
||||
lp:LPAREN^ {#lp.setType(METHOD_CALL);}
|
||||
argList
|
||||
RPAREN!
|
||||
;
|
||||
|
||||
// copy of the java.g rule with added constructorCast and colorMethodCall
|
||||
// alternatives
|
||||
primaryExpression
|
||||
: (consCastTypeSpec[false] LPAREN) => constructorCast
|
||||
{ Preferences.getBoolean("preproc.enhanced_casting") }?
|
||||
| identPrimary ( options {greedy=true;} : DOT^ "class" )?
|
||||
| constant
|
||||
| "true"
|
||||
| "false"
|
||||
| "null"
|
||||
| newExpression
|
||||
| "this"
|
||||
| "super"
|
||||
| LPAREN! assignmentExpression RPAREN!
|
||||
| colorMethodCall
|
||||
// look for int.class and int[].class
|
||||
| builtInType
|
||||
( lbt:LBRACK^ {#lbt.setType(ARRAY_DECLARATOR);} RBRACK! )*
|
||||
DOT^ "class"
|
||||
;
|
||||
|
||||
// the below variable rule hacks are needed so that it's possible for the
|
||||
// emitter to correctly output variable declarations of the form "float a, b"
|
||||
// from the AST. This means that our AST has a somewhat different form in
|
||||
// these rules than the java one does, and this new form may have its own
|
||||
// semantic issues. But it seems to fix the comma declaration issues.
|
||||
//
|
||||
variableDefinitions![AST mods, AST t]
|
||||
: vd:variableDeclarator[getASTFactory().dupTree(mods),
|
||||
getASTFactory().dupTree(t)]
|
||||
{#variableDefinitions = #(#[VARIABLE_DEF,"VARIABLE_DEF"], mods,
|
||||
t, vd);}
|
||||
;
|
||||
variableDeclarator[AST mods, AST t]
|
||||
: ( id:IDENT (lb:LBRACK^ {#lb.setType(ARRAY_DECLARATOR);} RBRACK!)*
|
||||
v:varInitializer (COMMA!)? )+
|
||||
;
|
||||
|
||||
// java.g builds syntax trees with an inconsistent structure. override one of
|
||||
// the rules there to fix this.
|
||||
//
|
||||
explicitConstructorInvocation!
|
||||
: t:"this" LPAREN a1:argList RPAREN SEMI
|
||||
{#explicitConstructorInvocation = #(#[CTOR_CALL, "CTOR_CALL"],
|
||||
#t, #a1);}
|
||||
| s:"super" LPAREN a2:argList RPAREN SEMI
|
||||
{#explicitConstructorInvocation = #(#[SUPER_CTOR_CALL,
|
||||
"SUPER_CTOR_CALL"],
|
||||
#s, #a2);}
|
||||
;
|
||||
|
||||
// quick-n-dirty hack to the get the advanced class name. we should
|
||||
// really be getting it from the AST and not forking this rule from
|
||||
// the java.g copy at all. Since this is a recursive descent parser, we get
|
||||
// the last class name in the file so that we don't end up with the classname
|
||||
// of an inner class. If there is more than one "outer" class in a file,
|
||||
// this heuristic will fail.
|
||||
//
|
||||
classDefinition![AST modifiers]
|
||||
: "class" i:IDENT
|
||||
// it _might_ have a superclass...
|
||||
sc:superClassClause
|
||||
// it might implement some interfaces...
|
||||
ic:implementsClause
|
||||
// now parse the body of the class
|
||||
cb:classBlock
|
||||
{#classDefinition = #(#[CLASS_DEF,"CLASS_DEF"],
|
||||
modifiers,i,sc,ic,cb);
|
||||
PdePreprocessor.advClassName = i.getText();}
|
||||
;
|
||||
|
||||
possiblyEmptyField
|
||||
: field
|
||||
| s:SEMI {#s.setType(EMPTY_FIELD);}
|
||||
;
|
||||
|
||||
class PdeLexer extends JavaLexer;
|
||||
|
||||
options {
|
||||
importVocab=PdePartial;
|
||||
exportVocab=Pde;
|
||||
}
|
||||
|
||||
// We need to preserve whitespace and commentary instead of ignoring
|
||||
// like the supergrammar does. Otherwise Jikes won't be able to give
|
||||
// us error messages that point to the equivalent PDE code.
|
||||
|
||||
// WS, SL_COMMENT, ML_COMMENT are copies of the original productions,
|
||||
// but with the SKIP assigment removed.
|
||||
|
||||
WS : ( ' '
|
||||
| '\t'
|
||||
| '\f'
|
||||
// handle newlines
|
||||
| ( options {generateAmbigWarnings=false;}
|
||||
: "\r\n" // Evil DOS
|
||||
| '\r' // Macintosh
|
||||
| '\n' // Unix (the right way)
|
||||
)
|
||||
{ newline(); }
|
||||
)+
|
||||
;
|
||||
|
||||
// Single-line comments
|
||||
SL_COMMENT
|
||||
: "//"
|
||||
(~('\n'|'\r'))* ('\n'|'\r'('\n')?)
|
||||
{newline();}
|
||||
;
|
||||
|
||||
// multiple-line comments
|
||||
ML_COMMENT
|
||||
: "/*"
|
||||
( /* '\r' '\n' can be matched in one alternative or by matching
|
||||
'\r' in one iteration and '\n' in another. I am trying to
|
||||
handle any flavor of newline that comes in, but the language
|
||||
that allows both "\r\n" and "\r" and "\n" to all be valid
|
||||
newline is ambiguous. Consequently, the resulting grammar
|
||||
must be ambiguous. I'm shutting this warning off.
|
||||
*/
|
||||
options {
|
||||
generateAmbigWarnings=false;
|
||||
}
|
||||
:
|
||||
{ LA(2)!='/' }? '*'
|
||||
| '\r' '\n' {newline();}
|
||||
| '\r' {newline();}
|
||||
| '\n' {newline();}
|
||||
| ~('*'|'\n'|'\r')
|
||||
)*
|
||||
"*/"
|
||||
;
|
||||
|
||||
WEBCOLOR_LITERAL
|
||||
: '#'! (HEX_DIGIT)+
|
||||
;
|
@ -33,6 +33,9 @@ else
|
||||
# cvs doesn't seem to want to honor the +x bit
|
||||
chmod +x work/Arduino.app/Contents/MacOS/JavaApplicationStub
|
||||
|
||||
echo Extracting examples...
|
||||
unzip -d work/examples ../shared/dist/examples.zip
|
||||
|
||||
# copy the avr-gcc distribution
|
||||
echo Copying tools \(this may take a minute\)...
|
||||
cp -pR dist/tools.zip work/
|
||||
@ -47,16 +50,15 @@ else
|
||||
chmod +x work/jikes
|
||||
fi
|
||||
|
||||
echo Copying shared and core files...
|
||||
echo Copying shared files...
|
||||
cp -r ../shared/* work
|
||||
cp -r ../../core work
|
||||
|
||||
echo Extracting examples...
|
||||
unzip -d work/examples ../shared/dist/examples.zip
|
||||
echo Copying targets...
|
||||
# make sure there's no cruft in the targets folder
|
||||
rm -rf work/lib/targets
|
||||
cp -r ../../targets work/lib/
|
||||
|
||||
echo Copying dist files...
|
||||
cp -r dist/lib work/
|
||||
cp -r dist/core work/
|
||||
cp -r dist/bootloader work/
|
||||
|
||||
### -- START BUILDING -------------------------------------------
|
||||
@ -85,17 +87,19 @@ cd app
|
||||
|
||||
### -- BUILD PARSER ---------------------------------------------
|
||||
|
||||
#BUILD_PREPROC=true
|
||||
|
||||
if $BUILD_PREPROC
|
||||
if test -f preproc/expandedpde.g
|
||||
then
|
||||
echo
|
||||
else
|
||||
cd preproc
|
||||
# build classes/grammar for preprocessor
|
||||
echo Building antlr grammar code...
|
||||
# first build the default java goop
|
||||
java -cp ../../build/macosx/work/lib/antlr.jar antlr.Tool java.g
|
||||
java -cp ../../build/macosx/work/lib/antlr.jar antlr.Tool StdCParser.g
|
||||
# now build the pde stuff that extends the java classes
|
||||
java -cp ../../build/macosx/work/lib/antlr.jar antlr.Tool -glib java.g pde.g
|
||||
java -cp ../../build/macosx/work/lib/antlr.jar antlr.Tool -glib StdCParser.g WParser.g
|
||||
java -cp ../../build/macosx/work/lib/antlr.jar antlr.Tool WTreeParser.g
|
||||
java -cp ../../build/macosx/work/lib/antlr.jar antlr.Tool -glib WTreeParser.g WEmitter.g
|
||||
cd ..
|
||||
fi
|
||||
|
||||
|
@ -262,3 +262,25 @@ linestatus.bgcolor = #66665a
|
||||
linestatus.font = SansSerif,plain,10
|
||||
linestatus.color = #ffffff
|
||||
linestatus.height = 20
|
||||
|
||||
# set the upload defaults
|
||||
upload.erase=false
|
||||
upload.verify=false
|
||||
upload.programmer=stk500
|
||||
|
||||
# set the parallel port defaults (used if upload.programmer=dapa)
|
||||
parallel.port=0x378
|
||||
|
||||
# set the serial port defaults
|
||||
serial.databits=8
|
||||
serial.stopbits=1
|
||||
serial.parity=N
|
||||
serial.port=COM1
|
||||
serial.download_rate=9600
|
||||
serial.debug_rate=9600
|
||||
|
||||
# set the build defaults
|
||||
build.mcu=atmega8
|
||||
build.f_cpu=16000000L
|
||||
build.extension=c
|
||||
build.target=arduino
|
||||
|
@ -69,10 +69,13 @@ else
|
||||
unzip -q -d work avr_tools.zip
|
||||
rm -f avr_tools.zip
|
||||
cp dist/tools/*.* work/tools
|
||||
cp dist/lib/makefile.win work/Makefile
|
||||
mkdir work/core
|
||||
cp ../../../core/*.* work/core
|
||||
cp dist/core/makefile.win work/core/Makefile
|
||||
|
||||
# core/ has been replaced by targets/ and we no longer use makefiles
|
||||
#cp dist/lib/makefile.win work/Makefile
|
||||
#mkdir work/core
|
||||
#cp ../../../core/*.* work/core
|
||||
#cp dist/core/makefile.win work/core/Makefile
|
||||
cp -r ../../targets work/lib/
|
||||
|
||||
# take care of the examples
|
||||
mkdir work/examples
|
||||
|
@ -1,17 +0,0 @@
|
||||
#define F_CPU 16000000UL
|
||||
#define CPU_FREQ 16000000L
|
||||
#define XTAL_CPU 16000000L
|
||||
#define UART_BAUD_RATE 9600
|
||||
|
||||
#ifndef __AVR_ATmega8__
|
||||
#define __AVR_ATmega8__
|
||||
#endif
|
||||
|
||||
#define __MCU_CLOCK_FREQUENCY__ _16.0000_MHz
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "wiring.h"
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/signal.h>
|
6
targets/arduino/WProgram.h
Executable file
6
targets/arduino/WProgram.h
Executable file
@ -0,0 +1,6 @@
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "wiring.h"
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/signal.h>
|
77
targets/arduino/avrlibdefs.h
Executable file
77
targets/arduino/avrlibdefs.h
Executable file
@ -0,0 +1,77 @@
|
||||
/*! \file avrlibdefs.h \brief AVRlib global defines and macros. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'avrlibdefs.h'
|
||||
// Title : AVRlib global defines and macros include file
|
||||
// Author : Pascal Stang
|
||||
// Created : 7/12/2001
|
||||
// Revised : 9/30/2002
|
||||
// Version : 1.1
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// Description : This include file is designed to contain items useful to all
|
||||
// code files and projects, regardless of specific implementation.
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
|
||||
#ifndef AVRLIBDEFS_H
|
||||
#define AVRLIBDEFS_H
|
||||
|
||||
// Code compatibility to new AVR-libc
|
||||
// outb(), inb(), BV(), sbi(), cbi(), sei(), cli()
|
||||
#ifndef outb
|
||||
#define outb(addr, data) addr = (data)
|
||||
#endif
|
||||
#ifndef inb
|
||||
#define inb(addr) (addr)
|
||||
#endif
|
||||
#ifndef BV
|
||||
#define BV(bit) (1<<(bit))
|
||||
#endif
|
||||
#ifndef cbi
|
||||
#define cbi(reg,bit) reg &= ~(BV(bit))
|
||||
#endif
|
||||
#ifndef sbi
|
||||
#define sbi(reg,bit) reg |= (BV(bit))
|
||||
#endif
|
||||
#ifndef cli
|
||||
#define cli() __asm__ __volatile__ ("cli" ::)
|
||||
#endif
|
||||
#ifndef sei
|
||||
#define sei() __asm__ __volatile__ ("sei" ::)
|
||||
#endif
|
||||
|
||||
// support for individual port pin naming in the mega128
|
||||
// see port128.h for details
|
||||
#ifdef __AVR_ATmega128__
|
||||
// not currently necessary due to inclusion
|
||||
// of these defines in newest AVR-GCC
|
||||
// do a quick test to see if include is needed
|
||||
#ifndef PD0
|
||||
#include "port128.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// use this for packed structures
|
||||
// (this is seldom necessary on an 8-bit architecture like AVR,
|
||||
// but can assist in code portability to AVR)
|
||||
#define GNUC_PACKED __attribute__((packed))
|
||||
|
||||
// port address helpers
|
||||
#define DDR(x) ((x)-1) // address of data direction register of port x
|
||||
#define PIN(x) ((x)-2) // address of input register of port x
|
||||
|
||||
// MIN/MAX/ABS macros
|
||||
#define MIN(a,b) ((a<b)?(a):(b))
|
||||
#define MAX(a,b) ((a>b)?(a):(b))
|
||||
#define ABS(x) ((x>0)?(x):(-x))
|
||||
|
||||
// constants
|
||||
#define PI 3.14159265359
|
||||
|
||||
#endif
|
84
targets/arduino/avrlibtypes.h
Executable file
84
targets/arduino/avrlibtypes.h
Executable file
@ -0,0 +1,84 @@
|
||||
/*! \file avrlibtypes.h \brief AVRlib global types and typedefines. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'avrlibtypes.h'
|
||||
// Title : AVRlib global types and typedefines include file
|
||||
// Author : Pascal Stang
|
||||
// Created : 7/12/2001
|
||||
// Revised : 9/30/2002
|
||||
// Version : 1.0
|
||||
// Target MCU : Atmel AVR series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// Description : Type-defines required and used by AVRlib. Most types are also
|
||||
// generally useful.
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
|
||||
#ifndef AVRLIBTYPES_H
|
||||
#define AVRLIBTYPES_H
|
||||
|
||||
#ifndef WIN32
|
||||
// true/false defines
|
||||
#define FALSE 0
|
||||
#define TRUE -1
|
||||
#endif
|
||||
|
||||
// datatype definitions macros
|
||||
typedef unsigned char u08;
|
||||
typedef signed char s08;
|
||||
typedef unsigned short u16;
|
||||
typedef signed short s16;
|
||||
typedef unsigned long u32;
|
||||
typedef signed long s32;
|
||||
typedef unsigned long long u64;
|
||||
typedef signed long long s64;
|
||||
|
||||
/* use inttypes.h instead
|
||||
// C99 standard integer type definitions
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef signed long int32_t;
|
||||
typedef unsigned long uint64_t;
|
||||
typedef signed long int64_t;
|
||||
*/
|
||||
// maximum value that can be held
|
||||
// by unsigned data types (8,16,32bits)
|
||||
#define MAX_U08 255
|
||||
#define MAX_U16 65535
|
||||
#define MAX_U32 4294967295
|
||||
|
||||
// maximum values that can be held
|
||||
// by signed data types (8,16,32bits)
|
||||
#define MIN_S08 -128
|
||||
#define MAX_S08 127
|
||||
#define MIN_S16 -32768
|
||||
#define MAX_S16 32767
|
||||
#define MIN_S32 -2147483648
|
||||
#define MAX_S32 2147483647
|
||||
|
||||
#ifndef WIN32
|
||||
// more type redefinitions
|
||||
typedef unsigned char BOOL;
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned int WORD;
|
||||
typedef unsigned long DWORD;
|
||||
|
||||
typedef unsigned char UCHAR;
|
||||
typedef unsigned int UINT;
|
||||
typedef unsigned short USHORT;
|
||||
typedef unsigned long ULONG;
|
||||
|
||||
typedef char CHAR;
|
||||
typedef int INT;
|
||||
typedef long LONG;
|
||||
#endif
|
||||
|
||||
#endif
|
110
targets/arduino/buffer.c
Executable file
110
targets/arduino/buffer.c
Executable file
@ -0,0 +1,110 @@
|
||||
/*! \file buffer.c \brief Multipurpose byte buffer structure and methods. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'buffer.c'
|
||||
// Title : Multipurpose byte buffer structure and methods
|
||||
// Author : Pascal Stang - Copyright (C) 2001-2002
|
||||
// Created : 9/23/2001
|
||||
// Revised : 9/23/2001
|
||||
// Version : 1.0
|
||||
// Target MCU : any
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include "buffer.h"
|
||||
|
||||
// global variables
|
||||
|
||||
// initialization
|
||||
|
||||
void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size)
|
||||
{
|
||||
// set start pointer of the buffer
|
||||
buffer->dataptr = start;
|
||||
buffer->size = size;
|
||||
// initialize index and length
|
||||
buffer->dataindex = 0;
|
||||
buffer->datalength = 0;
|
||||
}
|
||||
|
||||
// access routines
|
||||
unsigned char bufferGetFromFront(cBuffer* buffer)
|
||||
{
|
||||
unsigned char data = 0;
|
||||
|
||||
// check to see if there's data in the buffer
|
||||
if(buffer->datalength)
|
||||
{
|
||||
// get the first character from buffer
|
||||
data = buffer->dataptr[buffer->dataindex];
|
||||
// move index down and decrement length
|
||||
buffer->dataindex++;
|
||||
if(buffer->dataindex >= buffer->size)
|
||||
{
|
||||
buffer->dataindex %= buffer->size;
|
||||
}
|
||||
buffer->datalength--;
|
||||
}
|
||||
// return
|
||||
return data;
|
||||
}
|
||||
|
||||
void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes)
|
||||
{
|
||||
// dump numbytes from the front of the buffer
|
||||
// are we dumping less than the entire buffer?
|
||||
if(numbytes < buffer->datalength)
|
||||
{
|
||||
// move index down by numbytes and decrement length by numbytes
|
||||
buffer->dataindex += numbytes;
|
||||
if(buffer->dataindex >= buffer->size)
|
||||
{
|
||||
buffer->dataindex %= buffer->size;
|
||||
}
|
||||
buffer->datalength -= numbytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
// flush the whole buffer
|
||||
buffer->datalength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index)
|
||||
{
|
||||
// return character at index in buffer
|
||||
return buffer->dataptr[(buffer->dataindex+index)%(buffer->size)];
|
||||
}
|
||||
|
||||
unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data)
|
||||
{
|
||||
// make sure the buffer has room
|
||||
if(buffer->datalength < buffer->size)
|
||||
{
|
||||
// save data byte at end of buffer
|
||||
buffer->dataptr[(buffer->dataindex + buffer->datalength) % buffer->size] = data;
|
||||
// increment the length
|
||||
buffer->datalength++;
|
||||
// return success
|
||||
return -1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
unsigned char bufferIsNotFull(cBuffer* buffer)
|
||||
{
|
||||
// check to see if the buffer has room
|
||||
// return true if there is room
|
||||
return (buffer->datalength < buffer->size);
|
||||
}
|
||||
|
||||
void bufferFlush(cBuffer* buffer)
|
||||
{
|
||||
// flush contents of the buffer
|
||||
buffer->datalength = 0;
|
||||
}
|
||||
|
56
targets/arduino/buffer.h
Executable file
56
targets/arduino/buffer.h
Executable file
@ -0,0 +1,56 @@
|
||||
/*! \file buffer.h \brief Multipurpose byte buffer structure and methods. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'buffer.h'
|
||||
// Title : Multipurpose byte buffer structure and methods
|
||||
// Author : Pascal Stang - Copyright (C) 2001-2002
|
||||
// Created : 9/23/2001
|
||||
// Revised : 11/16/2002
|
||||
// Version : 1.1
|
||||
// Target MCU : any
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef BUFFER_H
|
||||
#define BUFFER_H
|
||||
|
||||
// structure/typdefs
|
||||
|
||||
// the cBuffer structure
|
||||
typedef struct struct_cBuffer
|
||||
{
|
||||
unsigned char *dataptr; // the physical memory address where the buffer is stored
|
||||
unsigned short size; // the allocated size of the buffer
|
||||
unsigned short datalength; // the length of the data currently in the buffer
|
||||
unsigned short dataindex; // the index into the buffer where the data starts
|
||||
} cBuffer;
|
||||
|
||||
// function prototypes
|
||||
|
||||
//! initialize a buffer to start at a given address and have given size
|
||||
void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size);
|
||||
|
||||
//! get the first byte from the front of the buffer
|
||||
unsigned char bufferGetFromFront(cBuffer* buffer);
|
||||
|
||||
//! dump (discard) the first numbytes from the front of the buffer
|
||||
void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes);
|
||||
|
||||
//! get a byte at the specified index in the buffer (kind of like array access)
|
||||
// ** note: this does not remove the byte that was read from the buffer
|
||||
unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index);
|
||||
|
||||
//! add a byte to the end of the buffer
|
||||
unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data);
|
||||
|
||||
//! check if the buffer is full/not full (returns non-zero value if not full)
|
||||
unsigned char bufferIsNotFull(cBuffer* buffer);
|
||||
|
||||
//! flush (clear) the contents of the buffer
|
||||
void bufferFlush(cBuffer* buffer);
|
||||
|
||||
#endif
|
390
targets/arduino/buffer.lst
Executable file
390
targets/arduino/buffer.lst
Executable file
@ -0,0 +1,390 @@
|
||||
1 .file "buffer.c"
|
||||
2 .arch atmega8
|
||||
3 __SREG__ = 0x3f
|
||||
4 __SP_H__ = 0x3e
|
||||
5 __SP_L__ = 0x3d
|
||||
6 __tmp_reg__ = 0
|
||||
7 __zero_reg__ = 1
|
||||
8 .global __do_copy_data
|
||||
9 .global __do_clear_bss
|
||||
12 .text
|
||||
13 .Ltext0:
|
||||
44 .global bufferInit
|
||||
46 bufferInit:
|
||||
1:../avrlib/buffer.c **** /*! \file buffer.c \brief Multipurpose byte buffer structure and methods. */
|
||||
2:../avrlib/buffer.c **** //*****************************************************************************
|
||||
3:../avrlib/buffer.c **** //
|
||||
4:../avrlib/buffer.c **** // File Name : 'buffer.c'
|
||||
5:../avrlib/buffer.c **** // Title : Multipurpose byte buffer structure and methods
|
||||
6:../avrlib/buffer.c **** // Author : Pascal Stang - Copyright (C) 2001-2002
|
||||
7:../avrlib/buffer.c **** // Created : 9/23/2001
|
||||
8:../avrlib/buffer.c **** // Revised : 9/23/2001
|
||||
9:../avrlib/buffer.c **** // Version : 1.0
|
||||
10:../avrlib/buffer.c **** // Target MCU : any
|
||||
11:../avrlib/buffer.c **** // Editor Tabs : 4
|
||||
12:../avrlib/buffer.c **** //
|
||||
13:../avrlib/buffer.c **** // This code is distributed under the GNU Public License
|
||||
14:../avrlib/buffer.c **** // which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
15:../avrlib/buffer.c **** //
|
||||
16:../avrlib/buffer.c **** //*****************************************************************************
|
||||
17:../avrlib/buffer.c ****
|
||||
18:../avrlib/buffer.c **** #include "buffer.h"
|
||||
19:../avrlib/buffer.c ****
|
||||
20:../avrlib/buffer.c **** // global variables
|
||||
21:../avrlib/buffer.c ****
|
||||
22:../avrlib/buffer.c **** // initialization
|
||||
23:../avrlib/buffer.c ****
|
||||
24:../avrlib/buffer.c **** void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size)
|
||||
25:../avrlib/buffer.c **** {
|
||||
48 .LM1:
|
||||
49 /* prologue: frame size=0 */
|
||||
50 /* prologue end (size=0) */
|
||||
51 0000 FC01 movw r30,r24
|
||||
26:../avrlib/buffer.c **** // set start pointer of the buffer
|
||||
27:../avrlib/buffer.c **** buffer->dataptr = start;
|
||||
53 .LM2:
|
||||
54 0002 6083 st Z,r22
|
||||
55 0004 7183 std Z+1,r23
|
||||
28:../avrlib/buffer.c **** buffer->size = size;
|
||||
57 .LM3:
|
||||
58 0006 4283 std Z+2,r20
|
||||
59 0008 5383 std Z+3,r21
|
||||
29:../avrlib/buffer.c **** // initialize index and length
|
||||
30:../avrlib/buffer.c **** buffer->dataindex = 0;
|
||||
61 .LM4:
|
||||
62 000a 1682 std Z+6,__zero_reg__
|
||||
63 000c 1782 std Z+7,__zero_reg__
|
||||
31:../avrlib/buffer.c **** buffer->datalength = 0;
|
||||
65 .LM5:
|
||||
66 000e 1482 std Z+4,__zero_reg__
|
||||
67 0010 1582 std Z+5,__zero_reg__
|
||||
68 /* epilogue: frame size=0 */
|
||||
69 0012 0895 ret
|
||||
70 /* epilogue end (size=1) */
|
||||
71 /* function bufferInit size 10 (9) */
|
||||
73 .Lscope0:
|
||||
77 .global bufferGetFromFront
|
||||
79 bufferGetFromFront:
|
||||
32:../avrlib/buffer.c **** }
|
||||
33:../avrlib/buffer.c ****
|
||||
34:../avrlib/buffer.c **** // access routines
|
||||
35:../avrlib/buffer.c **** unsigned char bufferGetFromFront(cBuffer* buffer)
|
||||
36:../avrlib/buffer.c **** {
|
||||
81 .LM6:
|
||||
82 /* prologue: frame size=0 */
|
||||
83 0014 CF93 push r28
|
||||
84 0016 DF93 push r29
|
||||
85 /* prologue end (size=2) */
|
||||
86 0018 EC01 movw r28,r24
|
||||
37:../avrlib/buffer.c **** unsigned char data = 0;
|
||||
88 .LM7:
|
||||
89 001a E0E0 ldi r30,lo8(0)
|
||||
38:../avrlib/buffer.c ****
|
||||
39:../avrlib/buffer.c **** // check to see if there's data in the buffer
|
||||
40:../avrlib/buffer.c **** if(buffer->datalength)
|
||||
91 .LM8:
|
||||
92 001c 2C81 ldd r18,Y+4
|
||||
93 001e 3D81 ldd r19,Y+5
|
||||
94 0020 2115 cp r18,__zero_reg__
|
||||
95 0022 3105 cpc r19,__zero_reg__
|
||||
96 0024 B1F0 breq .L3
|
||||
41:../avrlib/buffer.c **** {
|
||||
42:../avrlib/buffer.c **** // get the first character from buffer
|
||||
43:../avrlib/buffer.c **** data = buffer->dataptr[buffer->dataindex];
|
||||
98 .LM9:
|
||||
99 0026 E881 ld r30,Y
|
||||
100 0028 F981 ldd r31,Y+1
|
||||
101 002a 8E81 ldd r24,Y+6
|
||||
102 002c 9F81 ldd r25,Y+7
|
||||
103 002e E80F add r30,r24
|
||||
104 0030 F91F adc r31,r25
|
||||
105 0032 E081 ld r30,Z
|
||||
44:../avrlib/buffer.c **** // move index down and decrement length
|
||||
45:../avrlib/buffer.c **** buffer->dataindex++;
|
||||
107 .LM10:
|
||||
108 0034 0196 adiw r24,1
|
||||
109 0036 8E83 std Y+6,r24
|
||||
110 0038 9F83 std Y+7,r25
|
||||
46:../avrlib/buffer.c **** if(buffer->dataindex >= buffer->size)
|
||||
112 .LM11:
|
||||
113 003a 6A81 ldd r22,Y+2
|
||||
114 003c 7B81 ldd r23,Y+3
|
||||
115 003e 8617 cp r24,r22
|
||||
116 0040 9707 cpc r25,r23
|
||||
117 0042 18F0 brlo .L4
|
||||
47:../avrlib/buffer.c **** {
|
||||
48:../avrlib/buffer.c **** buffer->dataindex %= buffer->size;
|
||||
119 .LM12:
|
||||
120 0044 00D0 rcall __udivmodhi4
|
||||
121 0046 8E83 std Y+6,r24
|
||||
122 0048 9F83 std Y+7,r25
|
||||
123 .L4:
|
||||
49:../avrlib/buffer.c **** }
|
||||
50:../avrlib/buffer.c **** buffer->datalength--;
|
||||
125 .LM13:
|
||||
126 004a 2150 subi r18,lo8(-(-1))
|
||||
127 004c 3040 sbci r19,hi8(-(-1))
|
||||
128 004e 2C83 std Y+4,r18
|
||||
129 0050 3D83 std Y+5,r19
|
||||
130 .L3:
|
||||
51:../avrlib/buffer.c **** }
|
||||
52:../avrlib/buffer.c **** // return
|
||||
53:../avrlib/buffer.c **** return data;
|
||||
54:../avrlib/buffer.c **** }
|
||||
132 .LM14:
|
||||
133 0052 8E2F mov r24,r30
|
||||
134 0054 9927 clr r25
|
||||
135 /* epilogue: frame size=0 */
|
||||
136 0056 DF91 pop r29
|
||||
137 0058 CF91 pop r28
|
||||
138 005a 0895 ret
|
||||
139 /* epilogue end (size=3) */
|
||||
140 /* function bufferGetFromFront size 36 (31) */
|
||||
145 .Lscope1:
|
||||
150 .global bufferDumpFromFront
|
||||
152 bufferDumpFromFront:
|
||||
55:../avrlib/buffer.c ****
|
||||
56:../avrlib/buffer.c **** void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes)
|
||||
57:../avrlib/buffer.c **** {
|
||||
154 .LM15:
|
||||
155 /* prologue: frame size=0 */
|
||||
156 005c CF93 push r28
|
||||
157 005e DF93 push r29
|
||||
158 /* prologue end (size=2) */
|
||||
159 0060 FC01 movw r30,r24
|
||||
160 0062 EB01 movw r28,r22
|
||||
58:../avrlib/buffer.c **** // dump numbytes from the front of the buffer
|
||||
59:../avrlib/buffer.c **** // are we dumping less than the entire buffer?
|
||||
60:../avrlib/buffer.c **** if(numbytes < buffer->datalength)
|
||||
162 .LM16:
|
||||
163 0064 2481 ldd r18,Z+4
|
||||
164 0066 3581 ldd r19,Z+5
|
||||
165 0068 6217 cp r22,r18
|
||||
166 006a 7307 cpc r23,r19
|
||||
167 006c 98F4 brsh .L6
|
||||
61:../avrlib/buffer.c **** {
|
||||
62:../avrlib/buffer.c **** // move index down by numbytes and decrement length by numbytes
|
||||
63:../avrlib/buffer.c **** buffer->dataindex += numbytes;
|
||||
169 .LM17:
|
||||
170 006e 8681 ldd r24,Z+6
|
||||
171 0070 9781 ldd r25,Z+7
|
||||
172 0072 860F add r24,r22
|
||||
173 0074 971F adc r25,r23
|
||||
174 0076 8683 std Z+6,r24
|
||||
175 0078 9783 std Z+7,r25
|
||||
64:../avrlib/buffer.c **** if(buffer->dataindex >= buffer->size)
|
||||
177 .LM18:
|
||||
178 007a 6281 ldd r22,Z+2
|
||||
179 007c 7381 ldd r23,Z+3
|
||||
180 007e 8617 cp r24,r22
|
||||
181 0080 9707 cpc r25,r23
|
||||
182 0082 18F0 brlo .L7
|
||||
65:../avrlib/buffer.c **** {
|
||||
66:../avrlib/buffer.c **** buffer->dataindex %= buffer->size;
|
||||
184 .LM19:
|
||||
185 0084 00D0 rcall __udivmodhi4
|
||||
186 0086 8683 std Z+6,r24
|
||||
187 0088 9783 std Z+7,r25
|
||||
188 .L7:
|
||||
67:../avrlib/buffer.c **** }
|
||||
68:../avrlib/buffer.c **** buffer->datalength -= numbytes;
|
||||
190 .LM20:
|
||||
191 008a 2C1B sub r18,r28
|
||||
192 008c 3D0B sbc r19,r29
|
||||
193 008e 2483 std Z+4,r18
|
||||
194 0090 3583 std Z+5,r19
|
||||
195 0092 02C0 rjmp .L5
|
||||
196 .L6:
|
||||
69:../avrlib/buffer.c **** }
|
||||
70:../avrlib/buffer.c **** else
|
||||
71:../avrlib/buffer.c **** {
|
||||
72:../avrlib/buffer.c **** // flush the whole buffer
|
||||
73:../avrlib/buffer.c **** buffer->datalength = 0;
|
||||
198 .LM21:
|
||||
199 0094 1482 std Z+4,__zero_reg__
|
||||
200 0096 1582 std Z+5,__zero_reg__
|
||||
201 .L5:
|
||||
202 /* epilogue: frame size=0 */
|
||||
203 0098 DF91 pop r29
|
||||
204 009a CF91 pop r28
|
||||
205 009c 0895 ret
|
||||
206 /* epilogue end (size=3) */
|
||||
207 /* function bufferDumpFromFront size 33 (28) */
|
||||
209 .Lscope2:
|
||||
214 .global bufferGetAtIndex
|
||||
216 bufferGetAtIndex:
|
||||
74:../avrlib/buffer.c **** }
|
||||
75:../avrlib/buffer.c **** }
|
||||
76:../avrlib/buffer.c ****
|
||||
77:../avrlib/buffer.c **** unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index)
|
||||
78:../avrlib/buffer.c **** {
|
||||
218 .LM22:
|
||||
219 /* prologue: frame size=0 */
|
||||
220 /* prologue end (size=0) */
|
||||
221 009e FC01 movw r30,r24
|
||||
79:../avrlib/buffer.c **** // return character at index in buffer
|
||||
80:../avrlib/buffer.c **** return buffer->dataptr[(buffer->dataindex+index)%(buffer->size)];
|
||||
223 .LM23:
|
||||
224 00a0 8681 ldd r24,Z+6
|
||||
225 00a2 9781 ldd r25,Z+7
|
||||
226 00a4 2281 ldd r18,Z+2
|
||||
227 00a6 3381 ldd r19,Z+3
|
||||
228 00a8 860F add r24,r22
|
||||
229 00aa 971F adc r25,r23
|
||||
230 00ac B901 movw r22,r18
|
||||
231 00ae 00D0 rcall __udivmodhi4
|
||||
232 00b0 0190 ld __tmp_reg__,Z+
|
||||
233 00b2 F081 ld r31,Z
|
||||
234 00b4 E02D mov r30,__tmp_reg__
|
||||
235 00b6 E80F add r30,r24
|
||||
236 00b8 F91F adc r31,r25
|
||||
237 00ba 8081 ld r24,Z
|
||||
81:../avrlib/buffer.c **** }
|
||||
239 .LM24:
|
||||
240 00bc 9927 clr r25
|
||||
241 /* epilogue: frame size=0 */
|
||||
242 00be 0895 ret
|
||||
243 /* epilogue end (size=1) */
|
||||
244 /* function bufferGetAtIndex size 17 (16) */
|
||||
246 .Lscope3:
|
||||
251 .global bufferAddToEnd
|
||||
253 bufferAddToEnd:
|
||||
82:../avrlib/buffer.c ****
|
||||
83:../avrlib/buffer.c **** unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data)
|
||||
84:../avrlib/buffer.c **** {
|
||||
255 .LM25:
|
||||
256 /* prologue: frame size=0 */
|
||||
257 00c0 CF93 push r28
|
||||
258 00c2 DF93 push r29
|
||||
259 /* prologue end (size=2) */
|
||||
260 00c4 EC01 movw r28,r24
|
||||
261 00c6 462F mov r20,r22
|
||||
85:../avrlib/buffer.c **** // make sure the buffer has room
|
||||
86:../avrlib/buffer.c **** if(buffer->datalength < buffer->size)
|
||||
263 .LM26:
|
||||
264 00c8 2C81 ldd r18,Y+4
|
||||
265 00ca 3D81 ldd r19,Y+5
|
||||
266 00cc 6A81 ldd r22,Y+2
|
||||
267 00ce 7B81 ldd r23,Y+3
|
||||
268 00d0 2617 cp r18,r22
|
||||
269 00d2 3707 cpc r19,r23
|
||||
270 00d4 90F4 brsh .L11
|
||||
87:../avrlib/buffer.c **** {
|
||||
88:../avrlib/buffer.c **** // save data byte at end of buffer
|
||||
89:../avrlib/buffer.c **** buffer->dataptr[(buffer->dataindex + buffer->datalength) % buffer->size] = data;
|
||||
272 .LM27:
|
||||
273 00d6 8E81 ldd r24,Y+6
|
||||
274 00d8 9F81 ldd r25,Y+7
|
||||
275 00da 820F add r24,r18
|
||||
276 00dc 931F adc r25,r19
|
||||
277 00de 00D0 rcall __udivmodhi4
|
||||
278 00e0 E881 ld r30,Y
|
||||
279 00e2 F981 ldd r31,Y+1
|
||||
280 00e4 E80F add r30,r24
|
||||
281 00e6 F91F adc r31,r25
|
||||
282 00e8 4083 st Z,r20
|
||||
90:../avrlib/buffer.c **** // increment the length
|
||||
91:../avrlib/buffer.c **** buffer->datalength++;
|
||||
284 .LM28:
|
||||
285 00ea 8C81 ldd r24,Y+4
|
||||
286 00ec 9D81 ldd r25,Y+5
|
||||
287 00ee 0196 adiw r24,1
|
||||
288 00f0 8C83 std Y+4,r24
|
||||
289 00f2 9D83 std Y+5,r25
|
||||
92:../avrlib/buffer.c **** // return success
|
||||
93:../avrlib/buffer.c **** return -1;
|
||||
291 .LM29:
|
||||
292 00f4 8FEF ldi r24,lo8(255)
|
||||
293 00f6 90E0 ldi r25,hi8(255)
|
||||
294 00f8 02C0 rjmp .L10
|
||||
295 .L11:
|
||||
94:../avrlib/buffer.c **** }
|
||||
95:../avrlib/buffer.c **** else return 0;
|
||||
297 .LM30:
|
||||
298 00fa 80E0 ldi r24,lo8(0)
|
||||
299 00fc 90E0 ldi r25,hi8(0)
|
||||
300 .L10:
|
||||
301 /* epilogue: frame size=0 */
|
||||
302 00fe DF91 pop r29
|
||||
303 0100 CF91 pop r28
|
||||
304 0102 0895 ret
|
||||
305 /* epilogue end (size=3) */
|
||||
306 /* function bufferAddToEnd size 34 (29) */
|
||||
308 .Lscope4:
|
||||
312 .global bufferIsNotFull
|
||||
314 bufferIsNotFull:
|
||||
96:../avrlib/buffer.c **** }
|
||||
97:../avrlib/buffer.c ****
|
||||
98:../avrlib/buffer.c **** unsigned char bufferIsNotFull(cBuffer* buffer)
|
||||
99:../avrlib/buffer.c **** {
|
||||
316 .LM31:
|
||||
317 /* prologue: frame size=0 */
|
||||
318 /* prologue end (size=0) */
|
||||
319 0104 FC01 movw r30,r24
|
||||
100:../avrlib/buffer.c **** // check to see if the buffer has room
|
||||
101:../avrlib/buffer.c **** // return true if there is room
|
||||
102:../avrlib/buffer.c **** return (buffer->datalength < buffer->size);
|
||||
321 .LM32:
|
||||
322 0106 40E0 ldi r20,lo8(0)
|
||||
323 0108 50E0 ldi r21,hi8(0)
|
||||
324 010a 2481 ldd r18,Z+4
|
||||
325 010c 3581 ldd r19,Z+5
|
||||
326 010e 8281 ldd r24,Z+2
|
||||
327 0110 9381 ldd r25,Z+3
|
||||
328 0112 2817 cp r18,r24
|
||||
329 0114 3907 cpc r19,r25
|
||||
330 0116 10F4 brsh .L14
|
||||
332 .LM33:
|
||||
333 0118 41E0 ldi r20,lo8(1)
|
||||
334 011a 50E0 ldi r21,hi8(1)
|
||||
335 .L14:
|
||||
103:../avrlib/buffer.c **** }
|
||||
337 .LM34:
|
||||
338 011c CA01 movw r24,r20
|
||||
339 /* epilogue: frame size=0 */
|
||||
340 011e 0895 ret
|
||||
341 /* epilogue end (size=1) */
|
||||
342 /* function bufferIsNotFull size 14 (13) */
|
||||
344 .Lscope5:
|
||||
348 .global bufferFlush
|
||||
350 bufferFlush:
|
||||
104:../avrlib/buffer.c ****
|
||||
105:../avrlib/buffer.c **** void bufferFlush(cBuffer* buffer)
|
||||
106:../avrlib/buffer.c **** {
|
||||
352 .LM35:
|
||||
353 /* prologue: frame size=0 */
|
||||
354 /* prologue end (size=0) */
|
||||
107:../avrlib/buffer.c **** // flush contents of the buffer
|
||||
108:../avrlib/buffer.c **** buffer->datalength = 0;
|
||||
356 .LM36:
|
||||
357 0120 FC01 movw r30,r24
|
||||
358 0122 1482 std Z+4,__zero_reg__
|
||||
359 0124 1582 std Z+5,__zero_reg__
|
||||
360 /* epilogue: frame size=0 */
|
||||
361 0126 0895 ret
|
||||
362 /* epilogue end (size=1) */
|
||||
363 /* function bufferFlush size 4 (3) */
|
||||
365 .Lscope6:
|
||||
367 .text
|
||||
369 Letext:
|
||||
370 /* File "../avrlib/buffer.c": code 148 = 0x0094 ( 129), prologues 6, epilogues 13 */
|
||||
DEFINED SYMBOLS
|
||||
*ABS*:00000000 buffer.c
|
||||
*ABS*:0000003f __SREG__
|
||||
*ABS*:0000003e __SP_H__
|
||||
*ABS*:0000003d __SP_L__
|
||||
*ABS*:00000000 __tmp_reg__
|
||||
*ABS*:00000001 __zero_reg__
|
||||
/var/tmp//ccWNR2QI.s:46 .text:00000000 bufferInit
|
||||
/var/tmp//ccWNR2QI.s:79 .text:00000014 bufferGetFromFront
|
||||
/var/tmp//ccWNR2QI.s:152 .text:0000005c bufferDumpFromFront
|
||||
/var/tmp//ccWNR2QI.s:216 .text:0000009e bufferGetAtIndex
|
||||
/var/tmp//ccWNR2QI.s:253 .text:000000c0 bufferAddToEnd
|
||||
/var/tmp//ccWNR2QI.s:314 .text:00000104 bufferIsNotFull
|
||||
/var/tmp//ccWNR2QI.s:350 .text:00000120 bufferFlush
|
||||
/var/tmp//ccWNR2QI.s:369 .text:00000128 Letext
|
||||
|
||||
UNDEFINED SYMBOLS
|
||||
__do_copy_data
|
||||
__do_clear_bss
|
||||
__udivmodhi4
|
135
targets/arduino/rprintf.h
Executable file
135
targets/arduino/rprintf.h
Executable file
@ -0,0 +1,135 @@
|
||||
/*! \file rprintf.h \brief printf routine and associated routines. */
|
||||
//****************************************************************************
|
||||
//
|
||||
// File Name : 'rprintf.h'
|
||||
// Title : printf routine and associated routines
|
||||
// Author : Pascal Stang - Copyright (C) 2000-2002
|
||||
// Created : 2000.12.26
|
||||
// Revised : 2003.5.1
|
||||
// Version : 1.0
|
||||
// Target MCU : Atmel AVR series and other targets
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// NOTE: This code is currently below version 1.0, and therefore is considered
|
||||
// to be lacking in some functionality or documentation, or may not be fully
|
||||
// tested. Nonetheless, you can expect most functions to work.
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//****************************************************************************
|
||||
|
||||
#ifndef RPRINTF_H
|
||||
#define RPRINTF_H
|
||||
|
||||
// needed for use of PSTR below
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
// configuration
|
||||
// defining RPRINTF_SIMPLE will compile a smaller, simpler, and faster printf() function
|
||||
// defining RPRINTF_COMPLEX will compile a larger, more capable, and slower printf() function
|
||||
#ifndef RPRINTF_COMPLEX
|
||||
#define RPRINTF_SIMPLE
|
||||
#endif
|
||||
|
||||
// Define RPRINTF_FLOAT to enable the floating-point printf function: rprintfFloat()
|
||||
// (adds +4600bytes or 2.2Kwords of code)
|
||||
|
||||
// defines/constants
|
||||
#define STRING_IN_RAM 0
|
||||
#define STRING_IN_ROM 1
|
||||
|
||||
// make a putchar for those that are used to using it
|
||||
//#define putchar(c) rprintfChar(c);
|
||||
|
||||
// functions
|
||||
|
||||
//! initializes the rprintf library for an output stream
|
||||
// you must call this initializer once before using any other rprintf function
|
||||
// the argument must be a single-character stream output function
|
||||
void rprintfInit(void (*putchar_func)(unsigned char c));
|
||||
|
||||
//! prints a single character to the current output device
|
||||
void rprintfChar(unsigned char c);
|
||||
|
||||
//! prints a null-terminated string stored in RAM
|
||||
void rprintfStr(char str[]);
|
||||
|
||||
//! prints a section of a string stored in RAM
|
||||
// begins printing at position indicated by <start>
|
||||
// prints number of characters indicated by <len>
|
||||
void rprintfStrLen(char str[], unsigned int start, unsigned int len);
|
||||
|
||||
//! prints a string stored in program rom
|
||||
// NOTE: this function does not actually store your string in
|
||||
// program rom, but merely reads it assuming you stored it properly.
|
||||
void rprintfProgStr(const prog_char str[]);
|
||||
// Using the function rprintfProgStrM(...) automatically causes
|
||||
// your string to be stored in ROM, thereby not wasting precious RAM
|
||||
// Example usage:
|
||||
// rprintfProgStrM("Hello, this string is stored in program rom");
|
||||
#define rprintfProgStrM(string) (rprintfProgStr(PSTR(string)))
|
||||
|
||||
//! prints a carriage return and line feed
|
||||
// useful when printing to serial ports/terminals
|
||||
void rprintfCRLF(void);
|
||||
|
||||
// prints the number contained in "data" in hex format
|
||||
// u04,u08,u16,and u32 functions handle 4,8,16,or 32 bits respectively
|
||||
void rprintfu04(unsigned char data); ///< print 4-bit hex number
|
||||
void rprintfu08(unsigned char data); ///< print 8-bit hex number
|
||||
void rprintfu16(unsigned short data); ///< print 16-bit hex number
|
||||
void rprintfu32(unsigned long data); ///< print 32-bit hex number
|
||||
|
||||
//! a flexible integer number printing routine
|
||||
void rprintfNum(char base, char numDigits, char isSigned, char padchar, long n);
|
||||
|
||||
#ifdef RPRINTF_FLOAT
|
||||
//! floating-point print routine
|
||||
void rprintfFloat(char numDigits, double x);
|
||||
#endif
|
||||
|
||||
// NOTE: Below you'll see the function prototypes of rprintf1RamRom and
|
||||
// rprintf2RamRom. rprintf1RamRom and rprintf2RamRom are both reduced versions
|
||||
// of the regular C printf() command. However, they are modified to be able
|
||||
// to read their text/format strings from RAM or ROM in the Atmel microprocessors.
|
||||
// Unless you really intend to, do not use the "RamRom" versions of the functions
|
||||
// directly. Instead use the #defined function versions:
|
||||
//
|
||||
// printfx("text/format",args) ...to keep your text/format string stored in RAM
|
||||
// - or -
|
||||
// printfxROM("text/format",args) ...to keep your text/format string stored in ROM
|
||||
//
|
||||
// where x is either 1 or 2 for the simple or more powerful version of printf()
|
||||
//
|
||||
// Since there is much more ROM than RAM available in the Atmel microprocessors,
|
||||
// and nearly all text/format strings are constant (never change in the course
|
||||
// of the program), you should try to use the ROM printf version exclusively.
|
||||
// This will ensure you leave as much RAM as possible for program variables and
|
||||
// data.
|
||||
|
||||
#ifdef RPRINTF_SIMPLE
|
||||
// a simple printf routine
|
||||
int rprintf1RamRom(unsigned char stringInRom, const char *format, ...);
|
||||
// #defines for RAM or ROM operation
|
||||
#define rprintf1(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)
|
||||
#define rprintf1RAM(format, args...) rprintf1RamRom(STRING_IN_RAM, format, ## args)
|
||||
|
||||
// *** Default rprintf(...) ***
|
||||
// this next line determines what the the basic rprintf() defaults to:
|
||||
#define rprintf(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)
|
||||
#endif
|
||||
|
||||
#ifdef RPRINTF_COMPLEX
|
||||
// a more powerful printf routine
|
||||
int rprintf2RamRom(unsigned char stringInRom, const char *sfmt, ...);
|
||||
// #defines for RAM or ROM operation
|
||||
#define rprintf2(format, args...) rprintf2RamRom(STRING_IN_ROM, format, ## args)
|
||||
#define rprintf2RAM(format, args...) rprintf2RamRom(STRING_IN_RAM, format, ## args)
|
||||
|
||||
// *** Default rprintf(...) ***
|
||||
// this next line determines what the the basic rprintf() defaults to:
|
||||
#define rprintf(format, args...) rprintf2RamRom(STRING_IN_ROM, PSTR(format), ## args)
|
||||
#endif
|
||||
|
||||
#endif
|
472
targets/arduino/timer.c
Executable file
472
targets/arduino/timer.c
Executable file
@ -0,0 +1,472 @@
|
||||
/*! \file timer.c \brief System Timer function library. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'timer.c'
|
||||
// Title : System Timer function library
|
||||
// Author : Pascal Stang - Copyright (C) 2000-2002
|
||||
// Created : 11/22/2000
|
||||
// Revised : 07/09/2003
|
||||
// Version : 1.1
|
||||
// Target MCU : Atmel AVR Series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef WIN32
|
||||
#include <avr/io.h>
|
||||
#include <avr/signal.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/sleep.h>
|
||||
#endif
|
||||
|
||||
#include "global.h"
|
||||
#include "timer.h"
|
||||
|
||||
#include "rprintf.h"
|
||||
|
||||
// Program ROM constants
|
||||
// the prescale division values stored in order of timer control register index
|
||||
// STOP, CLK, CLK/8, CLK/64, CLK/256, CLK/1024
|
||||
unsigned short __attribute__ ((progmem)) TimerPrescaleFactor[] = {0,1,8,64,256,1024};
|
||||
// the prescale division values stored in order of timer control register index
|
||||
// STOP, CLK, CLK/8, CLK/32, CLK/64, CLK/128, CLK/256, CLK/1024
|
||||
unsigned short __attribute__ ((progmem)) TimerRTCPrescaleFactor[] = {0,1,8,32,64,128,256,1024};
|
||||
|
||||
// Global variables
|
||||
// time registers
|
||||
volatile unsigned long TimerPauseReg;
|
||||
volatile unsigned long Timer0Reg0;
|
||||
volatile unsigned long Timer2Reg0;
|
||||
|
||||
typedef void (*voidFuncPtr)(void);
|
||||
volatile static voidFuncPtr TimerIntFunc[TIMER_NUM_INTERRUPTS];
|
||||
|
||||
// delay for a minimum of <us> microseconds
|
||||
// the time resolution is dependent on the time the loop takes
|
||||
// e.g. with 4Mhz and 5 cycles per loop, the resolution is 1.25 us
|
||||
void delay_us(unsigned short time_us)
|
||||
{
|
||||
unsigned short delay_loops;
|
||||
register unsigned short i;
|
||||
|
||||
delay_loops = (time_us+3)/5*CYCLES_PER_US; // +3 for rounding up (dirty)
|
||||
|
||||
// one loop takes 5 cpu cycles
|
||||
for (i=0; i < delay_loops; i++) {};
|
||||
}
|
||||
/*
|
||||
void delay_ms(unsigned char time_ms)
|
||||
{
|
||||
unsigned short delay_count = F_CPU / 4000;
|
||||
|
||||
unsigned short cnt;
|
||||
asm volatile ("\n"
|
||||
"L_dl1%=:\n\t"
|
||||
"mov %A0, %A2\n\t"
|
||||
"mov %B0, %B2\n"
|
||||
"L_dl2%=:\n\t"
|
||||
"sbiw %A0, 1\n\t"
|
||||
"brne L_dl2%=\n\t"
|
||||
"dec %1\n\t" "brne L_dl1%=\n\t":"=&w" (cnt)
|
||||
:"r"(time_ms), "r"((unsigned short) (delay_count))
|
||||
);
|
||||
}
|
||||
*/
|
||||
void timerInit(void)
|
||||
{
|
||||
u08 intNum;
|
||||
// detach all user functions from interrupts
|
||||
for(intNum=0; intNum<TIMER_NUM_INTERRUPTS; intNum++)
|
||||
timerDetach(intNum);
|
||||
|
||||
// initialize all timers
|
||||
timer0Init();
|
||||
timer1Init();
|
||||
#ifdef TCNT2 // support timer2 only if it exists
|
||||
timer2Init();
|
||||
#endif
|
||||
// enable interrupts
|
||||
sei();
|
||||
}
|
||||
|
||||
void timer0Init()
|
||||
{
|
||||
// initialize timer 0
|
||||
timer0SetPrescaler( TIMER0PRESCALE ); // set prescaler
|
||||
outb(TCNT0, 0); // reset TCNT0
|
||||
sbi(TIMSK, TOIE0); // enable TCNT0 overflow interrupt
|
||||
|
||||
timer0ClearOverflowCount(); // initialize time registers
|
||||
}
|
||||
|
||||
void timer1Init(void)
|
||||
{
|
||||
// initialize timer 1
|
||||
timer1SetPrescaler( TIMER1PRESCALE ); // set prescaler
|
||||
outb(TCNT1H, 0); // reset TCNT1
|
||||
outb(TCNT1L, 0);
|
||||
sbi(TIMSK, TOIE1); // enable TCNT1 overflow
|
||||
}
|
||||
|
||||
#ifdef TCNT2 // support timer2 only if it exists
|
||||
void timer2Init(void)
|
||||
{
|
||||
// initialize timer 2
|
||||
timer2SetPrescaler( TIMER2PRESCALE ); // set prescaler
|
||||
outb(TCNT2, 0); // reset TCNT2
|
||||
sbi(TIMSK, TOIE2); // enable TCNT2 overflow
|
||||
|
||||
timer2ClearOverflowCount(); // initialize time registers
|
||||
}
|
||||
#endif
|
||||
|
||||
void timer0SetPrescaler(u08 prescale)
|
||||
{
|
||||
// set prescaler on timer 0
|
||||
outb(TCCR0, (inb(TCCR0) & ~TIMER_PRESCALE_MASK) | prescale);
|
||||
}
|
||||
|
||||
void timer1SetPrescaler(u08 prescale)
|
||||
{
|
||||
// set prescaler on timer 1
|
||||
outb(TCCR1B, (inb(TCCR1B) & ~TIMER_PRESCALE_MASK) | prescale);
|
||||
}
|
||||
|
||||
#ifdef TCNT2 // support timer2 only if it exists
|
||||
void timer2SetPrescaler(u08 prescale)
|
||||
{
|
||||
// set prescaler on timer 2
|
||||
outb(TCCR2, (inb(TCCR2) & ~TIMER_PRESCALE_MASK) | prescale);
|
||||
}
|
||||
#endif
|
||||
|
||||
u16 timer0GetPrescaler(void)
|
||||
{
|
||||
// get the current prescaler setting
|
||||
return (pgm_read_word(TimerPrescaleFactor+(inb(TCCR0) & TIMER_PRESCALE_MASK)));
|
||||
}
|
||||
|
||||
u16 timer1GetPrescaler(void)
|
||||
{
|
||||
// get the current prescaler setting
|
||||
return (pgm_read_word(TimerPrescaleFactor+(inb(TCCR1B) & TIMER_PRESCALE_MASK)));
|
||||
}
|
||||
|
||||
#ifdef TCNT2 // support timer2 only if it exists
|
||||
u16 timer2GetPrescaler(void)
|
||||
{
|
||||
//TODO: can we assume for all 3-timer AVR processors,
|
||||
// that timer2 is the RTC timer?
|
||||
|
||||
// get the current prescaler setting
|
||||
return (pgm_read_word(TimerRTCPrescaleFactor+(inb(TCCR2) & TIMER_PRESCALE_MASK)));
|
||||
}
|
||||
#endif
|
||||
|
||||
void timerAttach(u08 interruptNum, void (*userFunc)(void) )
|
||||
{
|
||||
// make sure the interrupt number is within bounds
|
||||
if(interruptNum < TIMER_NUM_INTERRUPTS)
|
||||
{
|
||||
// set the interrupt function to run
|
||||
// the supplied user's function
|
||||
TimerIntFunc[interruptNum] = userFunc;
|
||||
}
|
||||
}
|
||||
|
||||
void timerDetach(u08 interruptNum)
|
||||
{
|
||||
// make sure the interrupt number is within bounds
|
||||
if(interruptNum < TIMER_NUM_INTERRUPTS)
|
||||
{
|
||||
// set the interrupt function to run nothing
|
||||
TimerIntFunc[interruptNum] = 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
u32 timerMsToTics(u16 ms)
|
||||
{
|
||||
// calculate the prescaler division rate
|
||||
u16 prescaleDiv = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0)));
|
||||
// calculate the number of timer tics in x milliseconds
|
||||
return (ms*(F_CPU/(prescaleDiv*256)))/1000;
|
||||
}
|
||||
|
||||
u16 timerTicsToMs(u32 tics)
|
||||
{
|
||||
// calculate the prescaler division rate
|
||||
u16 prescaleDiv = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0)));
|
||||
// calculate the number of milliseconds in x timer tics
|
||||
return (tics*1000*(prescaleDiv*256))/F_CPU;
|
||||
}
|
||||
*/
|
||||
void timerPause(unsigned short pause_ms)
|
||||
{
|
||||
// pauses for exactly <pause_ms> number of milliseconds
|
||||
u08 timerThres;
|
||||
u32 ticRateHz;
|
||||
u32 pause;
|
||||
|
||||
// capture current pause timer value
|
||||
timerThres = inb(TCNT0);
|
||||
// reset pause timer overflow count
|
||||
TimerPauseReg = 0;
|
||||
// calculate delay for [pause_ms] milliseconds
|
||||
// prescaler division = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0)))
|
||||
ticRateHz = F_CPU/timer0GetPrescaler();
|
||||
// precision management
|
||||
// prevent overflow and precision underflow
|
||||
// -could add more conditions to improve accuracy
|
||||
if( ((ticRateHz < 429497) && (pause_ms <= 10000)) )
|
||||
pause = (pause_ms*ticRateHz)/1000;
|
||||
else
|
||||
pause = pause_ms*(ticRateHz/1000);
|
||||
|
||||
// loop until time expires
|
||||
while( ((TimerPauseReg<<8) | inb(TCNT0)) < (pause+timerThres) )
|
||||
{
|
||||
if( TimerPauseReg < (pause>>8));
|
||||
{
|
||||
// save power by idling the processor
|
||||
set_sleep_mode(SLEEP_MODE_IDLE);
|
||||
sleep_mode();
|
||||
}
|
||||
}
|
||||
|
||||
/* old inaccurate code, for reference
|
||||
|
||||
// calculate delay for [pause_ms] milliseconds
|
||||
u16 prescaleDiv = 1<<(pgm_read_byte(TimerPrescaleFactor+inb(TCCR0)));
|
||||
u32 pause = (pause_ms*(F_CPU/(prescaleDiv*256)))/1000;
|
||||
|
||||
TimerPauseReg = 0;
|
||||
while(TimerPauseReg < pause);
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
void timer0ClearOverflowCount(void)
|
||||
{
|
||||
// clear the timer overflow counter registers
|
||||
Timer0Reg0 = 0; // initialize time registers
|
||||
}
|
||||
|
||||
long timer0GetOverflowCount(void)
|
||||
{
|
||||
// return the current timer overflow count
|
||||
// (this is since the last timer0ClearOverflowCount() command was called)
|
||||
return Timer0Reg0;
|
||||
}
|
||||
|
||||
#ifdef TCNT2 // support timer2 only if it exists
|
||||
void timer2ClearOverflowCount(void)
|
||||
{
|
||||
// clear the timer overflow counter registers
|
||||
Timer2Reg0 = 0; // initialize time registers
|
||||
}
|
||||
|
||||
long timer2GetOverflowCount(void)
|
||||
{
|
||||
// return the current timer overflow count
|
||||
// (this is since the last timer2ClearOverflowCount() command was called)
|
||||
return Timer2Reg0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void timer1PWMInit(u08 bitRes)
|
||||
{
|
||||
// configures timer1 for use with PWM output
|
||||
// on OC1A and OC1B pins
|
||||
|
||||
// enable timer1 as 8,9,10bit PWM
|
||||
if(bitRes == 9)
|
||||
{ // 9bit mode
|
||||
sbi(TCCR1A,PWM11);
|
||||
cbi(TCCR1A,PWM10);
|
||||
}
|
||||
else if( bitRes == 10 )
|
||||
{ // 10bit mode
|
||||
sbi(TCCR1A,PWM11);
|
||||
sbi(TCCR1A,PWM10);
|
||||
}
|
||||
else
|
||||
{ // default 8bit mode
|
||||
cbi(TCCR1A,PWM11);
|
||||
sbi(TCCR1A,PWM10);
|
||||
}
|
||||
|
||||
// clear output compare value A
|
||||
outb(OCR1AH, 0);
|
||||
outb(OCR1AL, 0);
|
||||
// clear output compare value B
|
||||
outb(OCR1BH, 0);
|
||||
outb(OCR1BL, 0);
|
||||
}
|
||||
|
||||
#ifdef WGM10
|
||||
// include support for arbitrary top-count PWM
|
||||
// on new AVR processors that support it
|
||||
void timer1PWMInitICR(u16 topcount)
|
||||
{
|
||||
// set PWM mode with ICR top-count
|
||||
cbi(TCCR1A,WGM10);
|
||||
sbi(TCCR1A,WGM11);
|
||||
sbi(TCCR1B,WGM12);
|
||||
sbi(TCCR1B,WGM13);
|
||||
|
||||
// set top count value
|
||||
ICR1 = topcount;
|
||||
|
||||
// clear output compare value A
|
||||
OCR1A = 0;
|
||||
// clear output compare value B
|
||||
OCR1B = 0;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
void timer1PWMOff(void)
|
||||
{
|
||||
// turn off timer1 PWM mode
|
||||
cbi(TCCR1A,PWM11);
|
||||
cbi(TCCR1A,PWM10);
|
||||
// set PWM1A/B (OutputCompare action) to none
|
||||
timer1PWMAOff();
|
||||
timer1PWMBOff();
|
||||
}
|
||||
|
||||
void timer1PWMAOn(void)
|
||||
{
|
||||
// turn on channel A (OC1A) PWM output
|
||||
// set OC1A as non-inverted PWM
|
||||
sbi(TCCR1A,COM1A1);
|
||||
cbi(TCCR1A,COM1A0);
|
||||
}
|
||||
|
||||
void timer1PWMBOn(void)
|
||||
{
|
||||
// turn on channel B (OC1B) PWM output
|
||||
// set OC1B as non-inverted PWM
|
||||
sbi(TCCR1A,COM1B1);
|
||||
cbi(TCCR1A,COM1B0);
|
||||
}
|
||||
|
||||
void timer1PWMAOff(void)
|
||||
{
|
||||
// turn off channel A (OC1A) PWM output
|
||||
// set OC1A (OutputCompare action) to none
|
||||
cbi(TCCR1A,COM1A1);
|
||||
cbi(TCCR1A,COM1A0);
|
||||
}
|
||||
|
||||
void timer1PWMBOff(void)
|
||||
{
|
||||
// turn off channel B (OC1B) PWM output
|
||||
// set OC1B (OutputCompare action) to none
|
||||
cbi(TCCR1A,COM1B1);
|
||||
cbi(TCCR1A,COM1B0);
|
||||
}
|
||||
|
||||
void timer1PWMASet(u16 pwmDuty)
|
||||
{
|
||||
// set PWM (output compare) duty for channel A
|
||||
// this PWM output is generated on OC1A pin
|
||||
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM
|
||||
// pwmDuty should be in the range 0-511 for 9bit PWM
|
||||
// pwmDuty should be in the range 0-1023 for 10bit PWM
|
||||
//outp( (pwmDuty>>8), OCR1AH); // set the high 8bits of OCR1A
|
||||
//outp( (pwmDuty&0x00FF), OCR1AL); // set the low 8bits of OCR1A
|
||||
OCR1A = pwmDuty;
|
||||
}
|
||||
|
||||
void timer1PWMBSet(u16 pwmDuty)
|
||||
{
|
||||
// set PWM (output compare) duty for channel B
|
||||
// this PWM output is generated on OC1B pin
|
||||
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM
|
||||
// pwmDuty should be in the range 0-511 for 9bit PWM
|
||||
// pwmDuty should be in the range 0-1023 for 10bit PWM
|
||||
//outp( (pwmDuty>>8), OCR1BH); // set the high 8bits of OCR1B
|
||||
//outp( (pwmDuty&0x00FF), OCR1BL); // set the low 8bits of OCR1B
|
||||
OCR1B = pwmDuty;
|
||||
}
|
||||
|
||||
//! Interrupt handler for tcnt0 overflow interrupt
|
||||
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW0)
|
||||
{
|
||||
Timer0Reg0++; // increment low-order counter
|
||||
|
||||
// increment pause counter
|
||||
TimerPauseReg++;
|
||||
|
||||
// if a user function is defined, execute it too
|
||||
if(TimerIntFunc[TIMER0OVERFLOW_INT])
|
||||
TimerIntFunc[TIMER0OVERFLOW_INT]();
|
||||
}
|
||||
|
||||
//! Interrupt handler for tcnt1 overflow interrupt
|
||||
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW1)
|
||||
{
|
||||
// if a user function is defined, execute it
|
||||
if(TimerIntFunc[TIMER1OVERFLOW_INT])
|
||||
TimerIntFunc[TIMER1OVERFLOW_INT]();
|
||||
}
|
||||
|
||||
#ifdef TCNT2 // support timer2 only if it exists
|
||||
//! Interrupt handler for tcnt2 overflow interrupt
|
||||
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW2)
|
||||
{
|
||||
Timer2Reg0++; // increment low-order counter
|
||||
|
||||
// if a user function is defined, execute it
|
||||
if(TimerIntFunc[TIMER2OVERFLOW_INT])
|
||||
TimerIntFunc[TIMER2OVERFLOW_INT]();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef OCR0
|
||||
// include support for Output Compare 0 for new AVR processors that support it
|
||||
//! Interrupt handler for OutputCompare0 match (OC0) interrupt
|
||||
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE0)
|
||||
{
|
||||
// if a user function is defined, execute it
|
||||
if(TimerIntFunc[TIMER0OUTCOMPARE_INT])
|
||||
TimerIntFunc[TIMER0OUTCOMPARE_INT]();
|
||||
}
|
||||
#endif
|
||||
|
||||
//! Interrupt handler for CutputCompare1A match (OC1A) interrupt
|
||||
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE1A)
|
||||
{
|
||||
// if a user function is defined, execute it
|
||||
if(TimerIntFunc[TIMER1OUTCOMPAREA_INT])
|
||||
TimerIntFunc[TIMER1OUTCOMPAREA_INT]();
|
||||
}
|
||||
|
||||
//! Interrupt handler for OutputCompare1B match (OC1B) interrupt
|
||||
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE1B)
|
||||
{
|
||||
// if a user function is defined, execute it
|
||||
if(TimerIntFunc[TIMER1OUTCOMPAREB_INT])
|
||||
TimerIntFunc[TIMER1OUTCOMPAREB_INT]();
|
||||
}
|
||||
|
||||
//! Interrupt handler for InputCapture1 (IC1) interrupt
|
||||
TIMER_INTERRUPT_HANDLER(SIG_INPUT_CAPTURE1)
|
||||
{
|
||||
// if a user function is defined, execute it
|
||||
if(TimerIntFunc[TIMER1INPUTCAPTURE_INT])
|
||||
TimerIntFunc[TIMER1INPUTCAPTURE_INT]();
|
||||
}
|
||||
|
||||
//! Interrupt handler for OutputCompare2 match (OC2) interrupt
|
||||
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE2)
|
||||
{
|
||||
// if a user function is defined, execute it
|
||||
if(TimerIntFunc[TIMER2OUTCOMPARE_INT])
|
||||
TimerIntFunc[TIMER2OUTCOMPARE_INT]();
|
||||
}
|
278
targets/arduino/timer.h
Executable file
278
targets/arduino/timer.h
Executable file
@ -0,0 +1,278 @@
|
||||
/*! \file timer.h \brief System Timer function library. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'timer.h'
|
||||
// Title : System Timer function library
|
||||
// Author : Pascal Stang - Copyright (C) 2000-2002
|
||||
// Created : 11/22/2000
|
||||
// Revised : 02/10/2003
|
||||
// Version : 1.1
|
||||
// Target MCU : Atmel AVR Series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//
|
||||
// Notes: The Atmel AVR Series Processors each contain at least one
|
||||
// hardware timer/counter. Many of the processors contain 2 or 3
|
||||
// timers. Generally speaking, a timer is a hardware counter inside
|
||||
// the processor which counts at a rate related to the main CPU clock
|
||||
// frequency. Because the counter value increasing (counting up) at
|
||||
// a precise rate, we can use it as a timer to create or measure
|
||||
// precise delays, schedule events, or generate signals of a certain
|
||||
// frequency or pulse-width.
|
||||
// As an example, the ATmega163 processor has 3 timer/counters.
|
||||
// Timer0, Timer1, and Timer2 are 8, 16, and 8 bits wide respectively.
|
||||
// This means that they overflow, or roll over back to zero, at a
|
||||
// count value of 256 for 8bits or 65536 for 16bits. A prescaler is
|
||||
// avaiable for each timer, and the prescaler allows you to pre-divide
|
||||
// the main CPU clock rate down to a slower speed before feeding it to
|
||||
// the counting input of a timer. For example, if the CPU clock
|
||||
// frequency is 3.69MHz, and Timer0's prescaler is set to divide-by-8,
|
||||
// then Timer0 will "tic" at 3690000/8 = 461250Hz. Because Timer0 is
|
||||
// an 8bit timer, it will count to 256 in just 256/461250Hz = 0.555ms.
|
||||
// In fact, when it hits 255, it will overflow and start again at
|
||||
// zero. In this case, Timer0 will overflow 461250/256 = 1801.76
|
||||
// times per second.
|
||||
// Timer0 can be used a number of ways simultaneously. First, the
|
||||
// value of the timer can be read by accessing the CPU register TCNT0.
|
||||
// We could, for example, figure out how long it takes to execute a
|
||||
// C command by recording the value of TCNT0 before and after
|
||||
// execution, then subtract (after-before) = time elapsed. Or we can
|
||||
// enable the overflow interrupt which goes off every time T0
|
||||
// overflows and count out longer delays (multiple overflows), or
|
||||
// execute a special periodic function at every overflow.
|
||||
// The other timers (Timer1 and Timer2) offer all the abilities of
|
||||
// Timer0 and many more features. Both T1 and T2 can operate as
|
||||
// general-purpose timers, but T1 has special hardware allowing it to
|
||||
// generate PWM signals, while T2 is specially designed to help count
|
||||
// out real time (like hours, minutes, seconds). See the
|
||||
// Timer/Counter section of the processor datasheet for more info.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include "global.h"
|
||||
|
||||
// constants/macros/typdefs
|
||||
|
||||
// processor compatibility fixes
|
||||
#ifdef __AVR_ATmega323__
|
||||
// redefinition for the Mega323
|
||||
#define CTC1 CTC10
|
||||
#endif
|
||||
#ifndef PWM10
|
||||
// mega128 PWM bits
|
||||
#define PWM10 WGM10
|
||||
#define PWM11 WGM11
|
||||
#endif
|
||||
|
||||
// Timer/clock prescaler values and timer overflow rates
|
||||
// tics = rate at which the timer counts up
|
||||
// 8bitoverflow = rate at which the timer overflows 8bits (or reaches 256)
|
||||
// 16bit [overflow] = rate at which the timer overflows 16bits (65536)
|
||||
//
|
||||
// overflows can be used to generate periodic interrupts
|
||||
//
|
||||
// for 8MHz crystal
|
||||
// 0 = STOP (Timer not counting)
|
||||
// 1 = CLOCK tics= 8MHz 8bitoverflow= 31250Hz 16bit= 122.070Hz
|
||||
// 2 = CLOCK/8 tics= 1MHz 8bitoverflow= 3906.25Hz 16bit= 15.259Hz
|
||||
// 3 = CLOCK/64 tics= 125kHz 8bitoverflow= 488.28Hz 16bit= 1.907Hz
|
||||
// 4 = CLOCK/256 tics= 31250Hz 8bitoverflow= 122.07Hz 16bit= 0.477Hz
|
||||
// 5 = CLOCK/1024 tics= 7812.5Hz 8bitoverflow= 30.52Hz 16bit= 0.119Hz
|
||||
// 6 = External Clock on T(x) pin (falling edge)
|
||||
// 7 = External Clock on T(x) pin (rising edge)
|
||||
|
||||
// for 4MHz crystal
|
||||
// 0 = STOP (Timer not counting)
|
||||
// 1 = CLOCK tics= 4MHz 8bitoverflow= 15625Hz 16bit= 61.035Hz
|
||||
// 2 = CLOCK/8 tics= 500kHz 8bitoverflow= 1953.125Hz 16bit= 7.629Hz
|
||||
// 3 = CLOCK/64 tics= 62500Hz 8bitoverflow= 244.141Hz 16bit= 0.954Hz
|
||||
// 4 = CLOCK/256 tics= 15625Hz 8bitoverflow= 61.035Hz 16bit= 0.238Hz
|
||||
// 5 = CLOCK/1024 tics= 3906.25Hz 8bitoverflow= 15.259Hz 16bit= 0.060Hz
|
||||
// 6 = External Clock on T(x) pin (falling edge)
|
||||
// 7 = External Clock on T(x) pin (rising edge)
|
||||
|
||||
// for 3.69MHz crystal
|
||||
// 0 = STOP (Timer not counting)
|
||||
// 1 = CLOCK tics= 3.69MHz 8bitoverflow= 14414Hz 16bit= 56.304Hz
|
||||
// 2 = CLOCK/8 tics= 461250Hz 8bitoverflow= 1801.758Hz 16bit= 7.038Hz
|
||||
// 3 = CLOCK/64 tics= 57625.25Hz 8bitoverflow= 225.220Hz 16bit= 0.880Hz
|
||||
// 4 = CLOCK/256 tics= 14414.063Hz 8bitoverflow= 56.305Hz 16bit= 0.220Hz
|
||||
// 5 = CLOCK/1024 tics= 3603.516Hz 8bitoverflow= 14.076Hz 16bit= 0.055Hz
|
||||
// 6 = External Clock on T(x) pin (falling edge)
|
||||
// 7 = External Clock on T(x) pin (rising edge)
|
||||
|
||||
// for 32.768KHz crystal on timer 2 (use for real-time clock)
|
||||
// 0 = STOP
|
||||
// 1 = CLOCK tics= 32.768kHz 8bitoverflow= 128Hz
|
||||
// 2 = CLOCK/8 tics= 4096kHz 8bitoverflow= 16Hz
|
||||
// 3 = CLOCK/32 tics= 1024kHz 8bitoverflow= 4Hz
|
||||
// 4 = CLOCK/64 tics= 512Hz 8bitoverflow= 2Hz
|
||||
// 5 = CLOCK/128 tics= 256Hz 8bitoverflow= 1Hz
|
||||
// 6 = CLOCK/256 tics= 128Hz 8bitoverflow= 0.5Hz
|
||||
// 7 = CLOCK/1024 tics= 32Hz 8bitoverflow= 0.125Hz
|
||||
|
||||
#define TIMER_CLK_STOP 0x00 ///< Timer Stopped
|
||||
#define TIMER_CLK_DIV1 0x01 ///< Timer clocked at F_CPU
|
||||
#define TIMER_CLK_DIV8 0x02 ///< Timer clocked at F_CPU/8
|
||||
#define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64
|
||||
#define TIMER_CLK_DIV256 0x04 ///< Timer clocked at F_CPU/256
|
||||
#define TIMER_CLK_DIV1024 0x05 ///< Timer clocked at F_CPU/1024
|
||||
#define TIMER_CLK_T_FALL 0x06 ///< Timer clocked at T falling edge
|
||||
#define TIMER_CLK_T_RISE 0x07 ///< Timer clocked at T rising edge
|
||||
#define TIMER_PRESCALE_MASK 0x07 ///< Timer Prescaler Bit-Mask
|
||||
|
||||
#define TIMERRTC_CLK_STOP 0x00 ///< RTC Timer Stopped
|
||||
#define TIMERRTC_CLK_DIV1 0x01 ///< RTC Timer clocked at F_CPU
|
||||
#define TIMERRTC_CLK_DIV8 0x02 ///< RTC Timer clocked at F_CPU/8
|
||||
#define TIMERRTC_CLK_DIV32 0x03 ///< RTC Timer clocked at F_CPU/32
|
||||
#define TIMERRTC_CLK_DIV64 0x04 ///< RTC Timer clocked at F_CPU/64
|
||||
#define TIMERRTC_CLK_DIV128 0x05 ///< RTC Timer clocked at F_CPU/128
|
||||
#define TIMERRTC_CLK_DIV256 0x06 ///< RTC Timer clocked at F_CPU/256
|
||||
#define TIMERRTC_CLK_DIV1024 0x07 ///< RTC Timer clocked at F_CPU/1024
|
||||
#define TIMERRTC_PRESCALE_MASK 0x07 ///< RTC Timer Prescaler Bit-Mask
|
||||
|
||||
// default prescale settings for the timers
|
||||
// these settings are applied when you call
|
||||
// timerInit or any of the timer<x>Init
|
||||
#define TIMER0PRESCALE TIMER_CLK_DIV8 ///< timer 0 prescaler default
|
||||
#define TIMER1PRESCALE TIMER_CLK_DIV64 ///< timer 1 prescaler default
|
||||
#define TIMER2PRESCALE TIMERRTC_CLK_DIV64 ///< timer 2 prescaler default
|
||||
|
||||
// interrupt macros for attaching user functions to timer interrupts
|
||||
// use these with timerAttach( intNum, function )
|
||||
#define TIMER0OVERFLOW_INT 0
|
||||
#define TIMER1OVERFLOW_INT 1
|
||||
#define TIMER1OUTCOMPAREA_INT 2
|
||||
#define TIMER1OUTCOMPAREB_INT 3
|
||||
#define TIMER1INPUTCAPTURE_INT 4
|
||||
#define TIMER2OVERFLOW_INT 5
|
||||
#define TIMER2OUTCOMPARE_INT 6
|
||||
#ifdef OCR0 // for processors that support output compare on Timer0
|
||||
#define TIMER0OUTCOMPARE_INT 7
|
||||
#define TIMER_NUM_INTERRUPTS 8
|
||||
#else
|
||||
#define TIMER_NUM_INTERRUPTS 7
|
||||
#endif
|
||||
|
||||
// default type of interrupt handler to use for timers
|
||||
// *do not change unless you know what you're doing
|
||||
// Value may be SIGNAL or INTERRUPT
|
||||
#ifndef TIMER_INTERRUPT_HANDLER
|
||||
#define TIMER_INTERRUPT_HANDLER SIGNAL
|
||||
#endif
|
||||
|
||||
// functions
|
||||
#define delay delay_us
|
||||
#define delay_ms timerPause
|
||||
void delay_us(unsigned short time_us);
|
||||
|
||||
//! initializes timing system (all timers)
|
||||
// runs all timer init functions
|
||||
// sets all timers to default prescale values #defined in systimer.c
|
||||
void timerInit(void);
|
||||
|
||||
// default initialization routines for each timer
|
||||
void timer0Init(void); ///< initialize timer0
|
||||
void timer1Init(void); ///< initialize timer1
|
||||
#ifdef TCNT2 // support timer2 only if it exists
|
||||
void timer2Init(void); ///< initialize timer2
|
||||
#endif
|
||||
|
||||
// Clock prescaler set/get commands for each timer/counter
|
||||
// For setting the prescaler, you should use one of the #defines
|
||||
// above like TIMER_CLK_DIVx, where [x] is the division rate
|
||||
// you want.
|
||||
// When getting the current prescaler setting, the return value
|
||||
// will be the [x] division value currently set.
|
||||
void timer0SetPrescaler(u08 prescale); ///< set timer0 prescaler
|
||||
u16 timer0GetPrescaler(void); ///< get timer0 prescaler
|
||||
void timer1SetPrescaler(u08 prescale); ///< set timer1 prescaler
|
||||
u16 timer1GetPrescaler(void); ///< get timer0 prescaler
|
||||
#ifdef TCNT2 // support timer2 only if it exists
|
||||
void timer2SetPrescaler(u08 prescale); ///< set timer2 prescaler
|
||||
u16 timer2GetPrescaler(void); ///< get timer2 prescaler
|
||||
#endif
|
||||
|
||||
|
||||
// TimerAttach and Detach commands
|
||||
// These functions allow the attachment (or detachment) of any user function
|
||||
// to a timer interrupt. "Attaching" one of your own functions to a timer
|
||||
// interrupt means that it will be called whenever that interrupt happens.
|
||||
// Using attach is better than rewriting the actual INTERRUPT() function
|
||||
// because your code will still work and be compatible if the timer library
|
||||
// is updated. Also, using Attach allows your code and any predefined timer
|
||||
// code to work together and at the same time. (ie. "attaching" your own
|
||||
// function to the timer0 overflow doesn't prevent timerPause from working,
|
||||
// but rather allows you to share the interrupt.)
|
||||
//
|
||||
// timerAttach(TIMER1OVERFLOW_INT, myOverflowFunction);
|
||||
// timerDetach(TIMER1OVERFLOW_INT)
|
||||
//
|
||||
// timerAttach causes the myOverflowFunction() to be attached, and therefore
|
||||
// execute, whenever an overflow on timer1 occurs. timerDetach removes the
|
||||
// association and executes no user function when the interrupt occurs.
|
||||
// myOverflowFunction must be defined with no return value and no arguments:
|
||||
//
|
||||
// void myOverflowFunction(void) { ... }
|
||||
|
||||
//! Attach a user function to a timer interrupt
|
||||
void timerAttach(u08 interruptNum, void (*userFunc)(void) );
|
||||
//! Detach a user function from a timer interrupt
|
||||
void timerDetach(u08 interruptNum);
|
||||
|
||||
|
||||
// timing commands
|
||||
//! timerPause pauses for the number of milliseconds specified in <pause_ms>
|
||||
void timerPause(unsigned short pause_ms);
|
||||
|
||||
// overflow counters
|
||||
void timer0ClearOverflowCount(void); ///< clear timer0's overflow counter
|
||||
long timer0GetOverflowCount(void); ///< read timer0's overflow counter
|
||||
#ifdef TCNT2 // support timer2 only if it exists
|
||||
void timer2ClearOverflowCount(void); ///< clear timer2's overflow counter
|
||||
long timer2GetOverflowCount(void); ///< read timer0's overflow counter
|
||||
#endif
|
||||
|
||||
// PWM initialization and set commands for timer1
|
||||
// timer1PWMInit()
|
||||
// configures the timer1 hardware for PWM mode on pins OC1A and OC1B.
|
||||
// bitRes should be 8,9,or 10 for 8,9,or 10bit PWM resolution
|
||||
//
|
||||
// timer1PWMOff()
|
||||
// turns off all timer1 PWM output and set timer mode to normal state
|
||||
//
|
||||
// timer1PWMAOn() and timer1PWMBOn()
|
||||
// turn on output of PWM signals to OC1A or OC1B pins
|
||||
// NOTE: Until you define the OC1A and OC1B pins as outputs, and run
|
||||
// this "on" command, no PWM output will be output
|
||||
//
|
||||
// timer1PWMAOff() and timer1PWMBOff()
|
||||
// turn off output of PWM signals to OC1A or OC1B pins
|
||||
//
|
||||
// timer1PWMASet() and timer1PWMBSet()
|
||||
// sets the PWM duty cycle for each channel
|
||||
// NOTE: <pwmDuty> should be in the range 0-255 for 8bit PWM
|
||||
// <pwmDuty> should be in the range 0-511 for 9bit PWM
|
||||
// <pwmDuty> should be in the range 0-1023 for 10bit PWM
|
||||
// NOTE: the PWM frequency can be controlled in increments by setting the
|
||||
// prescaler for timer1
|
||||
|
||||
void timer1PWMInit(u08 bitRes); ///< initialize and set timer1 mode to PWM
|
||||
void timer1PWMInitICR(u16 topcount);///< initialize and set timer1 mode to PWM with specific top count
|
||||
void timer1PWMOff(void); ///< turn off all timer1 PWM output and set timer mode to normal
|
||||
void timer1PWMAOn(void); ///< turn on timer1 Channel A (OC1A) PWM output
|
||||
void timer1PWMBOn(void); ///< turn on timer1 Channel B (OC1B) PWM output
|
||||
void timer1PWMAOff(void); ///< turn off timer1 Channel A (OC1A) PWM output
|
||||
void timer1PWMBOff(void); ///< turn off timer1 Channel B (OC1B) PWM output
|
||||
void timer1PWMASet(u16 pwmDuty); ///< set duty of timer1 Channel A (OC1A) PWM output
|
||||
void timer1PWMBSet(u16 pwmDuty); ///< set duty of timer1 Channel B (OC1B) PWM output
|
||||
|
||||
// Pulse generation commands have been moved to the pulse.c library
|
||||
|
||||
#endif
|
1709
targets/arduino/timer.lst
Executable file
1709
targets/arduino/timer.lst
Executable file
File diff suppressed because it is too large
Load Diff
284
targets/arduino/uart.c
Executable file
284
targets/arduino/uart.c
Executable file
@ -0,0 +1,284 @@
|
||||
/*! \file uart.c \brief UART driver with buffer support. */
|
||||
// *****************************************************************************
|
||||
//
|
||||
// File Name : 'uart.c'
|
||||
// Title : UART driver with buffer support
|
||||
// Author : Pascal Stang - Copyright (C) 2000-2002
|
||||
// Created : 11/22/2000
|
||||
// Revised : 06/09/2003
|
||||
// Version : 1.3
|
||||
// Target MCU : ATMEL AVR Series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
// *****************************************************************************
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/signal.h>
|
||||
|
||||
#include "buffer.h"
|
||||
#include "uart.h"
|
||||
|
||||
// UART global variables
|
||||
// flag variables
|
||||
volatile u08 uartReadyTx; ///< uartReadyTx flag
|
||||
volatile u08 uartBufferedTx; ///< uartBufferedTx flag
|
||||
// receive and transmit buffers
|
||||
cBuffer uartRxBuffer; ///< uart receive buffer
|
||||
cBuffer uartTxBuffer; ///< uart transmit buffer
|
||||
unsigned short uartRxOverflow; ///< receive overflow counter
|
||||
|
||||
#ifndef UART_BUFFERS_EXTERNAL_RAM
|
||||
// using internal ram,
|
||||
// automatically allocate space in ram for each buffer
|
||||
static char uartRxData[UART_RX_BUFFER_SIZE];
|
||||
static char uartTxData[UART_TX_BUFFER_SIZE];
|
||||
#endif
|
||||
|
||||
typedef void (*voidFuncPtru08)(unsigned char);
|
||||
volatile static voidFuncPtru08 UartRxFunc;
|
||||
|
||||
//! enable and initialize the uart
|
||||
void uartInit(void)
|
||||
{
|
||||
// initialize the buffers
|
||||
uartInitBuffers();
|
||||
// initialize user receive handler
|
||||
UartRxFunc = 0;
|
||||
|
||||
// enable RxD/TxD and interrupts
|
||||
outb(UCR, BV(RXCIE)|BV(TXCIE)|BV(RXEN)|BV(TXEN));
|
||||
|
||||
// set default baud rate
|
||||
uartSetBaudRate(UART_DEFAULT_BAUD_RATE);
|
||||
// initialize states
|
||||
uartReadyTx = TRUE;
|
||||
uartBufferedTx = FALSE;
|
||||
// clear overflow count
|
||||
uartRxOverflow = 0;
|
||||
// enable interrupts
|
||||
sei();
|
||||
}
|
||||
|
||||
//! create and initialize the uart transmit and receive buffers
|
||||
void uartInitBuffers(void)
|
||||
{
|
||||
#ifndef UART_BUFFERS_EXTERNAL_RAM
|
||||
// initialize the UART receive buffer
|
||||
bufferInit(&uartRxBuffer, uartRxData, UART_RX_BUFFER_SIZE);
|
||||
// initialize the UART transmit buffer
|
||||
bufferInit(&uartTxBuffer, uartTxData, UART_TX_BUFFER_SIZE);
|
||||
#else
|
||||
// initialize the UART receive buffer
|
||||
bufferInit(&uartRxBuffer, (u08*) UART_RX_BUFFER_ADDR, UART_RX_BUFFER_SIZE);
|
||||
// initialize the UART transmit buffer
|
||||
bufferInit(&uartTxBuffer, (u08*) UART_TX_BUFFER_ADDR, UART_TX_BUFFER_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
//! redirects received data to a user function
|
||||
void uartSetRxHandler(void (*rx_func)(unsigned char c))
|
||||
{
|
||||
// set the receive interrupt to run the supplied user function
|
||||
UartRxFunc = rx_func;
|
||||
}
|
||||
|
||||
//! set the uart baud rate
|
||||
void uartSetBaudRate(u32 baudrate)
|
||||
{
|
||||
// calculate division factor for requested baud rate, and set it
|
||||
u16 bauddiv = ((F_CPU+(baudrate*8L))/(baudrate*16L)-1);
|
||||
outb(UBRRL, bauddiv);
|
||||
#ifdef UBRRH
|
||||
outb(UBRRH, bauddiv>>8);
|
||||
#endif
|
||||
}
|
||||
|
||||
//! returns the receive buffer structure
|
||||
cBuffer* uartGetRxBuffer(void)
|
||||
{
|
||||
// return rx buffer pointer
|
||||
return &uartRxBuffer;
|
||||
}
|
||||
|
||||
//! returns the transmit buffer structure
|
||||
cBuffer* uartGetTxBuffer(void)
|
||||
{
|
||||
// return tx buffer pointer
|
||||
return &uartTxBuffer;
|
||||
}
|
||||
|
||||
//! transmits a byte over the uart
|
||||
void uartSendByte(u08 txData)
|
||||
{
|
||||
// wait for the transmitter to be ready
|
||||
while(!uartReadyTx);
|
||||
// send byte
|
||||
outb(UDR, txData);
|
||||
// set ready state to FALSE
|
||||
uartReadyTx = FALSE;
|
||||
}
|
||||
|
||||
//! gets a single byte from the uart receive buffer (getchar-style)
|
||||
int uartGetByte(void)
|
||||
{
|
||||
u08 c;
|
||||
if(uartReceiveByte(&c))
|
||||
return c;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
//! gets a byte (if available) from the uart receive buffer
|
||||
u08 uartReceiveByte(u08* rxData)
|
||||
{
|
||||
// make sure we have a receive buffer
|
||||
if(uartRxBuffer.size)
|
||||
{
|
||||
// make sure we have data
|
||||
if(uartRxBuffer.datalength)
|
||||
{
|
||||
// get byte from beginning of buffer
|
||||
*rxData = bufferGetFromFront(&uartRxBuffer);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// no data
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// no buffer
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
//! flush all data out of the receive buffer
|
||||
void uartFlushReceiveBuffer(void)
|
||||
{
|
||||
// flush all data from receive buffer
|
||||
//bufferFlush(&uartRxBuffer);
|
||||
// same effect as above
|
||||
uartRxBuffer.datalength = 0;
|
||||
}
|
||||
|
||||
//! return true if uart receive buffer is empty
|
||||
u08 uartReceiveBufferIsEmpty(void)
|
||||
{
|
||||
if(uartRxBuffer.datalength == 0)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
//! add byte to end of uart Tx buffer
|
||||
void uartAddToTxBuffer(u08 data)
|
||||
{
|
||||
// add data byte to the end of the tx buffer
|
||||
bufferAddToEnd(&uartTxBuffer, data);
|
||||
}
|
||||
|
||||
//! start transmission of the current uart Tx buffer contents
|
||||
void uartSendTxBuffer(void)
|
||||
{
|
||||
// turn on buffered transmit
|
||||
uartBufferedTx = TRUE;
|
||||
// send the first byte to get things going by interrupts
|
||||
uartSendByte(bufferGetFromFront(&uartTxBuffer));
|
||||
}
|
||||
/*
|
||||
//! transmit nBytes from buffer out the uart
|
||||
u08 uartSendBuffer(char *buffer, u16 nBytes)
|
||||
{
|
||||
register u08 first;
|
||||
register u16 i;
|
||||
|
||||
// check if there's space (and that we have any bytes to send at all)
|
||||
if((uartTxBuffer.datalength + nBytes < uartTxBuffer.size) && nBytes)
|
||||
{
|
||||
// grab first character
|
||||
first = *buffer++;
|
||||
// copy user buffer to uart transmit buffer
|
||||
for(i = 0; i < nBytes-1; i++)
|
||||
{
|
||||
// put data bytes at end of buffer
|
||||
bufferAddToEnd(&uartTxBuffer, *buffer++);
|
||||
}
|
||||
|
||||
// send the first byte to get things going by interrupts
|
||||
uartBufferedTx = TRUE;
|
||||
uartSendByte(first);
|
||||
// return success
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return failure
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
*/
|
||||
//! UART Transmit Complete Interrupt Handler
|
||||
UART_INTERRUPT_HANDLER(SIG_UART_TRANS)
|
||||
{
|
||||
// check if buffered tx is enabled
|
||||
if(uartBufferedTx)
|
||||
{
|
||||
// check if there's data left in the buffer
|
||||
if(uartTxBuffer.datalength)
|
||||
{
|
||||
// send byte from top of buffer
|
||||
outb(UDR, bufferGetFromFront(&uartTxBuffer));
|
||||
}
|
||||
else
|
||||
{
|
||||
// no data left
|
||||
uartBufferedTx = FALSE;
|
||||
// return to ready state
|
||||
uartReadyTx = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we're using single-byte tx mode
|
||||
// indicate transmit complete, back to ready
|
||||
uartReadyTx = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
//! UART Receive Complete Interrupt Handler
|
||||
UART_INTERRUPT_HANDLER(SIG_UART_RECV)
|
||||
{
|
||||
u08 c;
|
||||
|
||||
// get received char
|
||||
c = inb(UDR);
|
||||
|
||||
// if there's a user function to handle this receive event
|
||||
if(UartRxFunc)
|
||||
{
|
||||
// call it and pass the received data
|
||||
UartRxFunc(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise do default processing
|
||||
// put received char in buffer
|
||||
// check if there's space
|
||||
if( !bufferAddToEnd(&uartRxBuffer, c) )
|
||||
{
|
||||
// no space in buffer
|
||||
// count overflow
|
||||
uartRxOverflow++;
|
||||
}
|
||||
}
|
||||
}
|
134
targets/arduino/uart.h
Executable file
134
targets/arduino/uart.h
Executable file
@ -0,0 +1,134 @@
|
||||
/*! \file uart.h \brief UART driver with buffer support. */
|
||||
//*****************************************************************************
|
||||
//
|
||||
// File Name : 'uart.h'
|
||||
// Title : UART driver with buffer support
|
||||
// Author : Pascal Stang - Copyright (C) 2000-2002
|
||||
// Created : 11/22/2000
|
||||
// Revised : 02/01/2004
|
||||
// Version : 1.3
|
||||
// Target MCU : ATMEL AVR Series
|
||||
// Editor Tabs : 4
|
||||
//
|
||||
// This code is distributed under the GNU Public License
|
||||
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef UART_H
|
||||
#define UART_H
|
||||
|
||||
#include "global.h"
|
||||
#include "buffer.h"
|
||||
|
||||
//! default baud rate
|
||||
//! can be changed by using uartSetBaudRate()
|
||||
#define UART_DEFAULT_BAUD_RATE 9600
|
||||
|
||||
// buffer memory allocation defines
|
||||
// buffer sizes
|
||||
#ifndef UART_TX_BUFFER_SIZE
|
||||
#define UART_TX_BUFFER_SIZE 0x0040 ///< number of bytes for uart transmit buffer
|
||||
#endif
|
||||
#ifndef UART_RX_BUFFER_SIZE
|
||||
#define UART_RX_BUFFER_SIZE 0x0040 ///< number of bytes for uart receive buffer
|
||||
#endif
|
||||
|
||||
// define this key if you wish to use
|
||||
// external RAM for the UART buffers
|
||||
//#define UART_BUFFER_EXTERNAL_RAM
|
||||
#ifdef UART_BUFFER_EXTERNAL_RAM
|
||||
// absolute address of uart buffers
|
||||
#define UART_TX_BUFFER_ADDR 0x1000
|
||||
#define UART_RX_BUFFER_ADDR 0x1100
|
||||
#endif
|
||||
|
||||
// type of interrupt handler to use
|
||||
// *do not change unless you know what you're doing
|
||||
// Value may be SIGNAL or INTERRUPT
|
||||
#ifndef UART_INTERRUPT_HANDLER
|
||||
#define UART_INTERRUPT_HANDLER SIGNAL
|
||||
#endif
|
||||
|
||||
// compatibility with most newer processors
|
||||
#ifdef UCSRB
|
||||
#define UCR UCSRB
|
||||
#endif
|
||||
// compatibility with old Mega processors
|
||||
#if defined(UBRR) && !defined(UBRRL)
|
||||
#define UBRRL UBRR
|
||||
#endif
|
||||
// compatibility with dual-uart processors
|
||||
// (if you need to use both uarts, please use the uart2 library)
|
||||
#if defined(__AVR_ATmega128__)
|
||||
#define UDR UDR0
|
||||
#define UCR UCSR0B
|
||||
#define UBRRL UBRR0L
|
||||
#define UBRRH UBRR0H
|
||||
#define SIG_UART_TRANS SIG_UART0_TRANS
|
||||
#define SIG_UART_RECV SIG_UART0_RECV
|
||||
#define SIG_UART_DATA SIG_UART0_DATA
|
||||
#endif
|
||||
#if defined(__AVR_ATmega161__)
|
||||
#define UDR UDR0
|
||||
#define UCR UCSR0B
|
||||
#define UBRRL UBRR0
|
||||
#define SIG_UART_TRANS SIG_UART0_TRANS
|
||||
#define SIG_UART_RECV SIG_UART0_RECV
|
||||
#define SIG_UART_DATA SIG_UART0_DATA
|
||||
#endif
|
||||
|
||||
// functions
|
||||
|
||||
//! initializes transmit and receive buffers
|
||||
// called from uartInit()
|
||||
void uartInitBuffers(void);
|
||||
|
||||
//! initializes uart
|
||||
void uartInit(void);
|
||||
|
||||
//! redirects received data to a user function
|
||||
void uartSetRxHandler(void (*rx_func)(unsigned char c));
|
||||
|
||||
//! sets the uart baud rate
|
||||
void uartSetBaudRate(u32 baudrate);
|
||||
|
||||
//! returns pointer to the receive buffer structure
|
||||
cBuffer* uartGetRxBuffer(void);
|
||||
|
||||
//! returns pointer to the transmit buffer structure
|
||||
cBuffer* uartGetTxBuffer(void);
|
||||
|
||||
//! sends a single byte over the uart
|
||||
void uartSendByte(u08 data);
|
||||
|
||||
//! gets a single byte from the uart receive buffer (getchar-style)
|
||||
// returns the byte, or -1 if no byte is available
|
||||
int uartGetByte(void);
|
||||
|
||||
//! gets a single byte from the uart receive buffer
|
||||
// Function returns TRUE if data was available, FALSE if not.
|
||||
// Actual data is returned in variable pointed to by "data".
|
||||
// example usage:
|
||||
// char myReceivedByte;
|
||||
// uartReceiveByte( &myReceivedByte );
|
||||
u08 uartReceiveByte(u08* data);
|
||||
|
||||
//! returns TRUE/FALSE if receive buffer is empty/not-empty
|
||||
u08 uartReceiveBufferIsEmpty(void);
|
||||
|
||||
//! flushes (deletes) all data from receive buffer
|
||||
void uartFlushReceiveBuffer(void);
|
||||
|
||||
//! add byte to end of uart Tx buffer
|
||||
void uartAddToTxBuffer(u08 data);
|
||||
|
||||
//! begins transmission of the transmit buffer under interrupt control
|
||||
void uartSendTxBuffer(void);
|
||||
|
||||
//! sends a buffer of length nBytes via the uart using interrupt control
|
||||
u08 uartSendBuffer(char *buffer, u16 nBytes);
|
||||
|
||||
#endif
|
||||
|
||||
|
789
targets/arduino/uart.lst
Executable file
789
targets/arduino/uart.lst
Executable file
@ -0,0 +1,789 @@
|
||||
1 .file "uart.c"
|
||||
2 .arch atmega8
|
||||
3 __SREG__ = 0x3f
|
||||
4 __SP_H__ = 0x3e
|
||||
5 __SP_L__ = 0x3d
|
||||
6 __tmp_reg__ = 0
|
||||
7 __zero_reg__ = 1
|
||||
8 .global __do_copy_data
|
||||
9 .global __do_clear_bss
|
||||
12 .text
|
||||
13 .Ltext0:
|
||||
86 .global uartSetBaudRate
|
||||
88 uartSetBaudRate:
|
||||
1:../avrlib/uart.c **** /*! \file uart.c \brief UART driver with buffer support. */
|
||||
2:../avrlib/uart.c **** // *****************************************************************************
|
||||
3:../avrlib/uart.c **** //
|
||||
4:../avrlib/uart.c **** // File Name : 'uart.c'
|
||||
5:../avrlib/uart.c **** // Title : UART driver with buffer support
|
||||
6:../avrlib/uart.c **** // Author : Pascal Stang - Copyright (C) 2000-2002
|
||||
7:../avrlib/uart.c **** // Created : 11/22/2000
|
||||
8:../avrlib/uart.c **** // Revised : 06/09/2003
|
||||
9:../avrlib/uart.c **** // Version : 1.3
|
||||
10:../avrlib/uart.c **** // Target MCU : ATMEL AVR Series
|
||||
11:../avrlib/uart.c **** // Editor Tabs : 4
|
||||
12:../avrlib/uart.c **** //
|
||||
13:../avrlib/uart.c **** // This code is distributed under the GNU Public License
|
||||
14:../avrlib/uart.c **** // which can be found at http://www.gnu.org/licenses/gpl.txt
|
||||
15:../avrlib/uart.c **** //
|
||||
16:../avrlib/uart.c **** // *****************************************************************************
|
||||
17:../avrlib/uart.c ****
|
||||
18:../avrlib/uart.c **** #include <avr/io.h>
|
||||
19:../avrlib/uart.c **** #include <avr/interrupt.h>
|
||||
20:../avrlib/uart.c **** #include <avr/signal.h>
|
||||
21:../avrlib/uart.c ****
|
||||
22:../avrlib/uart.c **** #include "buffer.h"
|
||||
23:../avrlib/uart.c **** #include "uart.h"
|
||||
24:../avrlib/uart.c ****
|
||||
25:../avrlib/uart.c **** // UART global variables
|
||||
26:../avrlib/uart.c **** // flag variables
|
||||
27:../avrlib/uart.c **** volatile u08 uartReadyTx; ///< uartReadyTx flag
|
||||
28:../avrlib/uart.c **** volatile u08 uartBufferedTx; ///< uartBufferedTx flag
|
||||
29:../avrlib/uart.c **** // receive and transmit buffers
|
||||
30:../avrlib/uart.c **** cBuffer uartRxBuffer; ///< uart receive buffer
|
||||
31:../avrlib/uart.c **** cBuffer uartTxBuffer; ///< uart transmit buffer
|
||||
32:../avrlib/uart.c **** unsigned short uartRxOverflow; ///< receive overflow counter
|
||||
33:../avrlib/uart.c ****
|
||||
34:../avrlib/uart.c **** #ifndef UART_BUFFERS_EXTERNAL_RAM
|
||||
35:../avrlib/uart.c **** // using internal ram,
|
||||
36:../avrlib/uart.c **** // automatically allocate space in ram for each buffer
|
||||
37:../avrlib/uart.c **** static char uartRxData[UART_RX_BUFFER_SIZE];
|
||||
38:../avrlib/uart.c **** static char uartTxData[UART_TX_BUFFER_SIZE];
|
||||
39:../avrlib/uart.c **** #endif
|
||||
40:../avrlib/uart.c ****
|
||||
41:../avrlib/uart.c **** typedef void (*voidFuncPtru08)(unsigned char);
|
||||
42:../avrlib/uart.c **** volatile static voidFuncPtru08 UartRxFunc;
|
||||
43:../avrlib/uart.c ****
|
||||
44:../avrlib/uart.c **** //! enable and initialize the uart
|
||||
45:../avrlib/uart.c **** void uartInit(void)
|
||||
46:../avrlib/uart.c **** {
|
||||
47:../avrlib/uart.c **** // initialize the buffers
|
||||
48:../avrlib/uart.c **** uartInitBuffers();
|
||||
49:../avrlib/uart.c **** // initialize user receive handler
|
||||
50:../avrlib/uart.c **** UartRxFunc = 0;
|
||||
51:../avrlib/uart.c ****
|
||||
52:../avrlib/uart.c **** // enable RxD/TxD and interrupts
|
||||
53:../avrlib/uart.c **** outb(UCR, BV(RXCIE)|BV(TXCIE)|BV(RXEN)|BV(TXEN));
|
||||
54:../avrlib/uart.c ****
|
||||
55:../avrlib/uart.c **** // set default baud rate
|
||||
56:../avrlib/uart.c **** uartSetBaudRate(UART_DEFAULT_BAUD_RATE);
|
||||
57:../avrlib/uart.c **** // initialize states
|
||||
58:../avrlib/uart.c **** uartReadyTx = TRUE;
|
||||
59:../avrlib/uart.c **** uartBufferedTx = FALSE;
|
||||
60:../avrlib/uart.c **** // clear overflow count
|
||||
61:../avrlib/uart.c **** uartRxOverflow = 0;
|
||||
62:../avrlib/uart.c **** // enable interrupts
|
||||
63:../avrlib/uart.c **** sei();
|
||||
64:../avrlib/uart.c **** }
|
||||
65:../avrlib/uart.c ****
|
||||
66:../avrlib/uart.c **** //! create and initialize the uart transmit and receive buffers
|
||||
67:../avrlib/uart.c **** void uartInitBuffers(void)
|
||||
68:../avrlib/uart.c **** {
|
||||
69:../avrlib/uart.c **** #ifndef UART_BUFFERS_EXTERNAL_RAM
|
||||
70:../avrlib/uart.c **** // initialize the UART receive buffer
|
||||
71:../avrlib/uart.c **** bufferInit(&uartRxBuffer, uartRxData, UART_RX_BUFFER_SIZE);
|
||||
72:../avrlib/uart.c **** // initialize the UART transmit buffer
|
||||
73:../avrlib/uart.c **** bufferInit(&uartTxBuffer, uartTxData, UART_TX_BUFFER_SIZE);
|
||||
74:../avrlib/uart.c **** #else
|
||||
75:../avrlib/uart.c **** // initialize the UART receive buffer
|
||||
76:../avrlib/uart.c **** bufferInit(&uartRxBuffer, (u08*) UART_RX_BUFFER_ADDR, UART_RX_BUFFER_SIZE);
|
||||
77:../avrlib/uart.c **** // initialize the UART transmit buffer
|
||||
78:../avrlib/uart.c **** bufferInit(&uartTxBuffer, (u08*) UART_TX_BUFFER_ADDR, UART_TX_BUFFER_SIZE);
|
||||
79:../avrlib/uart.c **** #endif
|
||||
80:../avrlib/uart.c **** }
|
||||
81:../avrlib/uart.c ****
|
||||
82:../avrlib/uart.c **** //! redirects received data to a user function
|
||||
83:../avrlib/uart.c **** void uartSetRxHandler(void (*rx_func)(unsigned char c))
|
||||
84:../avrlib/uart.c **** {
|
||||
85:../avrlib/uart.c **** // set the receive interrupt to run the supplied user function
|
||||
86:../avrlib/uart.c **** UartRxFunc = rx_func;
|
||||
87:../avrlib/uart.c **** }
|
||||
88:../avrlib/uart.c ****
|
||||
89:../avrlib/uart.c **** //! set the uart baud rate
|
||||
90:../avrlib/uart.c **** void uartSetBaudRate(u32 baudrate)
|
||||
91:../avrlib/uart.c **** {
|
||||
90 .LM1:
|
||||
91 /* prologue: frame size=0 */
|
||||
92 /* prologue end (size=0) */
|
||||
93 0000 DC01 movw r26,r24
|
||||
94 0002 CB01 movw r24,r22
|
||||
92:../avrlib/uart.c **** // calculate division factor for requested baud rate, and set it
|
||||
93:../avrlib/uart.c **** u16 bauddiv = ((F_CPU+(baudrate*8L))/(baudrate*16L)-1);
|
||||
96 .LM2:
|
||||
97 0004 73E0 ldi r23,3
|
||||
98 0006 880F 1: lsl r24
|
||||
99 0008 991F rol r25
|
||||
100 000a AA1F rol r26
|
||||
101 000c BB1F rol r27
|
||||
102 000e 7A95 dec r23
|
||||
103 0010 D1F7 brne 1b
|
||||
104 0012 9C01 movw r18,r24
|
||||
105 0014 AD01 movw r20,r26
|
||||
106 0016 220F lsl r18
|
||||
107 0018 331F rol r19
|
||||
108 001a 441F rol r20
|
||||
109 001c 551F rol r21
|
||||
110 001e 8050 subi r24,lo8(-(16000000))
|
||||
111 0020 9C4D sbci r25,hi8(-(16000000))
|
||||
112 0022 AB40 sbci r26,hlo8(-(16000000))
|
||||
113 0024 BF4F sbci r27,hhi8(-(16000000))
|
||||
114 0026 BC01 movw r22,r24
|
||||
115 0028 CD01 movw r24,r26
|
||||
116 002a 00D0 rcall __udivmodsi4
|
||||
117 002c DA01 movw r26,r20
|
||||
118 002e C901 movw r24,r18
|
||||
119 0030 0197 sbiw r24,1
|
||||
94:../avrlib/uart.c **** outb(UBRRL, bauddiv);
|
||||
121 .LM3:
|
||||
122 0032 89B9 out 41-0x20,r24
|
||||
95:../avrlib/uart.c **** #ifdef UBRRH
|
||||
96:../avrlib/uart.c **** outb(UBRRH, bauddiv>>8);
|
||||
124 .LM4:
|
||||
125 0034 892F mov r24,r25
|
||||
126 0036 9927 clr r25
|
||||
127 0038 80BD out 64-0x20,r24
|
||||
128 /* epilogue: frame size=0 */
|
||||
129 003a 0895 ret
|
||||
130 /* epilogue end (size=1) */
|
||||
131 /* function uartSetBaudRate size 30 (29) */
|
||||
136 .Lscope0:
|
||||
139 .global uartInitBuffers
|
||||
141 uartInitBuffers:
|
||||
143 .LM5:
|
||||
144 /* prologue: frame size=0 */
|
||||
145 /* prologue end (size=0) */
|
||||
147 .LM6:
|
||||
148 003c 40E4 ldi r20,lo8(64)
|
||||
149 003e 50E0 ldi r21,hi8(64)
|
||||
150 0040 60E0 ldi r22,lo8(uartRxData)
|
||||
151 0042 70E0 ldi r23,hi8(uartRxData)
|
||||
152 0044 80E0 ldi r24,lo8(uartRxBuffer)
|
||||
153 0046 90E0 ldi r25,hi8(uartRxBuffer)
|
||||
154 0048 00D0 rcall bufferInit
|
||||
156 .LM7:
|
||||
157 004a 40E4 ldi r20,lo8(64)
|
||||
158 004c 50E0 ldi r21,hi8(64)
|
||||
159 004e 60E0 ldi r22,lo8(uartTxData)
|
||||
160 0050 70E0 ldi r23,hi8(uartTxData)
|
||||
161 0052 80E0 ldi r24,lo8(uartTxBuffer)
|
||||
162 0054 90E0 ldi r25,hi8(uartTxBuffer)
|
||||
163 0056 00D0 rcall bufferInit
|
||||
164 /* epilogue: frame size=0 */
|
||||
165 0058 0895 ret
|
||||
166 /* epilogue end (size=1) */
|
||||
167 /* function uartInitBuffers size 15 (14) */
|
||||
169 .Lscope1:
|
||||
172 .global uartInit
|
||||
174 uartInit:
|
||||
176 .LM8:
|
||||
177 /* prologue: frame size=0 */
|
||||
178 /* prologue end (size=0) */
|
||||
180 .LM9:
|
||||
181 005a F0DF rcall uartInitBuffers
|
||||
183 .LM10:
|
||||
184 005c 1092 0000 sts (UartRxFunc)+1,__zero_reg__
|
||||
185 0060 1092 0000 sts UartRxFunc,__zero_reg__
|
||||
187 .LM11:
|
||||
188 0064 88ED ldi r24,lo8(-40)
|
||||
189 0066 8AB9 out 42-0x20,r24
|
||||
191 .LM12:
|
||||
192 0068 60E8 ldi r22,lo8(9600)
|
||||
193 006a 75E2 ldi r23,hi8(9600)
|
||||
194 006c 80E0 ldi r24,hlo8(9600)
|
||||
195 006e 90E0 ldi r25,hhi8(9600)
|
||||
196 0070 C7DF rcall uartSetBaudRate
|
||||
198 .LM13:
|
||||
199 0072 8FEF ldi r24,lo8(-1)
|
||||
200 0074 8093 0000 sts uartReadyTx,r24
|
||||
202 .LM14:
|
||||
203 0078 1092 0000 sts uartBufferedTx,__zero_reg__
|
||||
205 .LM15:
|
||||
206 007c 1092 0000 sts (uartRxOverflow)+1,__zero_reg__
|
||||
207 0080 1092 0000 sts uartRxOverflow,__zero_reg__
|
||||
209 .LM16:
|
||||
210 /* #APP */
|
||||
211 0084 7894 sei
|
||||
212 /* #NOAPP */
|
||||
213 /* epilogue: frame size=0 */
|
||||
214 0086 0895 ret
|
||||
215 /* epilogue end (size=1) */
|
||||
216 /* function uartInit size 24 (23) */
|
||||
218 .Lscope2:
|
||||
222 .global uartSetRxHandler
|
||||
224 uartSetRxHandler:
|
||||
226 .LM17:
|
||||
227 /* prologue: frame size=0 */
|
||||
228 /* prologue end (size=0) */
|
||||
230 .LM18:
|
||||
231 0088 9093 0000 sts (UartRxFunc)+1,r25
|
||||
232 008c 8093 0000 sts UartRxFunc,r24
|
||||
233 /* epilogue: frame size=0 */
|
||||
234 0090 0895 ret
|
||||
235 /* epilogue end (size=1) */
|
||||
236 /* function uartSetRxHandler size 5 (4) */
|
||||
238 .Lscope3:
|
||||
241 .global uartGetRxBuffer
|
||||
243 uartGetRxBuffer:
|
||||
97:../avrlib/uart.c **** #endif
|
||||
98:../avrlib/uart.c **** }
|
||||
99:../avrlib/uart.c ****
|
||||
100:../avrlib/uart.c **** //! returns the receive buffer structure
|
||||
101:../avrlib/uart.c **** cBuffer* uartGetRxBuffer(void)
|
||||
102:../avrlib/uart.c **** {
|
||||
245 .LM19:
|
||||
246 /* prologue: frame size=0 */
|
||||
247 /* prologue end (size=0) */
|
||||
103:../avrlib/uart.c **** // return rx buffer pointer
|
||||
104:../avrlib/uart.c **** return &uartRxBuffer;
|
||||
105:../avrlib/uart.c **** }
|
||||
249 .LM20:
|
||||
250 0092 80E0 ldi r24,lo8(uartRxBuffer)
|
||||
251 0094 90E0 ldi r25,hi8(uartRxBuffer)
|
||||
252 /* epilogue: frame size=0 */
|
||||
253 0096 0895 ret
|
||||
254 /* epilogue end (size=1) */
|
||||
255 /* function uartGetRxBuffer size 3 (2) */
|
||||
257 .Lscope4:
|
||||
260 .global uartGetTxBuffer
|
||||
262 uartGetTxBuffer:
|
||||
106:../avrlib/uart.c ****
|
||||
107:../avrlib/uart.c **** //! returns the transmit buffer structure
|
||||
108:../avrlib/uart.c **** cBuffer* uartGetTxBuffer(void)
|
||||
109:../avrlib/uart.c **** {
|
||||
264 .LM21:
|
||||
265 /* prologue: frame size=0 */
|
||||
266 /* prologue end (size=0) */
|
||||
110:../avrlib/uart.c **** // return tx buffer pointer
|
||||
111:../avrlib/uart.c **** return &uartTxBuffer;
|
||||
112:../avrlib/uart.c **** }
|
||||
268 .LM22:
|
||||
269 0098 80E0 ldi r24,lo8(uartTxBuffer)
|
||||
270 009a 90E0 ldi r25,hi8(uartTxBuffer)
|
||||
271 /* epilogue: frame size=0 */
|
||||
272 009c 0895 ret
|
||||
273 /* epilogue end (size=1) */
|
||||
274 /* function uartGetTxBuffer size 3 (2) */
|
||||
276 .Lscope5:
|
||||
280 .global uartSendByte
|
||||
282 uartSendByte:
|
||||
113:../avrlib/uart.c ****
|
||||
114:../avrlib/uart.c **** //! transmits a byte over the uart
|
||||
115:../avrlib/uart.c **** void uartSendByte(u08 txData)
|
||||
116:../avrlib/uart.c **** {
|
||||
284 .LM23:
|
||||
285 /* prologue: frame size=0 */
|
||||
286 /* prologue end (size=0) */
|
||||
287 009e 982F mov r25,r24
|
||||
288 .L8:
|
||||
117:../avrlib/uart.c **** // wait for the transmitter to be ready
|
||||
118:../avrlib/uart.c **** while(!uartReadyTx);
|
||||
290 .LM24:
|
||||
291 00a0 8091 0000 lds r24,uartReadyTx
|
||||
292 00a4 8823 tst r24
|
||||
293 00a6 E1F3 breq .L8
|
||||
119:../avrlib/uart.c **** // send byte
|
||||
120:../avrlib/uart.c **** outb(UDR, txData);
|
||||
295 .LM25:
|
||||
296 00a8 9CB9 out 44-0x20,r25
|
||||
121:../avrlib/uart.c **** // set ready state to FALSE
|
||||
122:../avrlib/uart.c **** uartReadyTx = FALSE;
|
||||
298 .LM26:
|
||||
299 00aa 1092 0000 sts uartReadyTx,__zero_reg__
|
||||
300 /* epilogue: frame size=0 */
|
||||
301 00ae 0895 ret
|
||||
302 /* epilogue end (size=1) */
|
||||
303 /* function uartSendByte size 9 (8) */
|
||||
305 .Lscope6:
|
||||
309 .global uartReceiveByte
|
||||
311 uartReceiveByte:
|
||||
123:../avrlib/uart.c **** }
|
||||
124:../avrlib/uart.c ****
|
||||
125:../avrlib/uart.c **** //! gets a single byte from the uart receive buffer (getchar-style)
|
||||
126:../avrlib/uart.c **** int uartGetByte(void)
|
||||
127:../avrlib/uart.c **** {
|
||||
128:../avrlib/uart.c **** u08 c;
|
||||
129:../avrlib/uart.c **** if(uartReceiveByte(&c))
|
||||
130:../avrlib/uart.c **** return c;
|
||||
131:../avrlib/uart.c **** else
|
||||
132:../avrlib/uart.c **** return -1;
|
||||
133:../avrlib/uart.c **** }
|
||||
134:../avrlib/uart.c ****
|
||||
135:../avrlib/uart.c **** //! gets a byte (if available) from the uart receive buffer
|
||||
136:../avrlib/uart.c **** u08 uartReceiveByte(u08* rxData)
|
||||
137:../avrlib/uart.c **** {
|
||||
313 .LM27:
|
||||
314 /* prologue: frame size=0 */
|
||||
315 00b0 CF93 push r28
|
||||
316 00b2 DF93 push r29
|
||||
317 /* prologue end (size=2) */
|
||||
318 00b4 EC01 movw r28,r24
|
||||
138:../avrlib/uart.c **** // make sure we have a receive buffer
|
||||
139:../avrlib/uart.c **** if(uartRxBuffer.size)
|
||||
320 .LM28:
|
||||
321 00b6 8091 0000 lds r24,uartRxBuffer+2
|
||||
322 00ba 9091 0000 lds r25,(uartRxBuffer+2)+1
|
||||
323 00be 0097 sbiw r24,0
|
||||
324 00c0 61F0 breq .L11
|
||||
140:../avrlib/uart.c **** {
|
||||
141:../avrlib/uart.c **** // make sure we have data
|
||||
142:../avrlib/uart.c **** if(uartRxBuffer.datalength)
|
||||
326 .LM29:
|
||||
327 00c2 8091 0000 lds r24,uartRxBuffer+4
|
||||
328 00c6 9091 0000 lds r25,(uartRxBuffer+4)+1
|
||||
329 00ca 0097 sbiw r24,0
|
||||
330 00cc 31F0 breq .L11
|
||||
143:../avrlib/uart.c **** {
|
||||
144:../avrlib/uart.c **** // get byte from beginning of buffer
|
||||
145:../avrlib/uart.c **** *rxData = bufferGetFromFront(&uartRxBuffer);
|
||||
332 .LM30:
|
||||
333 00ce 80E0 ldi r24,lo8(uartRxBuffer)
|
||||
334 00d0 90E0 ldi r25,hi8(uartRxBuffer)
|
||||
335 00d2 00D0 rcall bufferGetFromFront
|
||||
336 00d4 8883 st Y,r24
|
||||
146:../avrlib/uart.c **** return TRUE;
|
||||
338 .LM31:
|
||||
339 00d6 8FEF ldi r24,lo8(255)
|
||||
340 00d8 90E0 ldi r25,hi8(255)
|
||||
341 .L11:
|
||||
342 /* epilogue: frame size=0 */
|
||||
343 00da DF91 pop r29
|
||||
344 00dc CF91 pop r28
|
||||
345 00de 0895 ret
|
||||
346 /* epilogue end (size=3) */
|
||||
347 /* function uartReceiveByte size 24 (19) */
|
||||
349 .Lscope7:
|
||||
352 .global uartGetByte
|
||||
354 uartGetByte:
|
||||
356 .LM32:
|
||||
357 /* prologue: frame size=1 */
|
||||
358 00e0 CF93 push r28
|
||||
359 00e2 DF93 push r29
|
||||
360 00e4 CDB7 in r28,__SP_L__
|
||||
361 00e6 DEB7 in r29,__SP_H__
|
||||
362 00e8 2197 sbiw r28,1
|
||||
363 00ea 0FB6 in __tmp_reg__,__SREG__
|
||||
364 00ec F894 cli
|
||||
365 00ee DEBF out __SP_H__,r29
|
||||
366 00f0 0FBE out __SREG__,__tmp_reg__
|
||||
367 00f2 CDBF out __SP_L__,r28
|
||||
368 /* prologue end (size=10) */
|
||||
370 .LM33:
|
||||
371 00f4 CE01 movw r24,r28
|
||||
372 00f6 0196 adiw r24,1
|
||||
373 00f8 DBDF rcall uartReceiveByte
|
||||
374 00fa 8823 tst r24
|
||||
375 00fc 19F0 breq .L17
|
||||
377 .LM34:
|
||||
378 00fe 8981 ldd r24,Y+1
|
||||
379 0100 9927 clr r25
|
||||
380 0102 02C0 rjmp .L16
|
||||
381 .L17:
|
||||
383 .LM35:
|
||||
384 0104 8FEF ldi r24,lo8(-1)
|
||||
385 0106 9FEF ldi r25,hi8(-1)
|
||||
386 .L16:
|
||||
387 /* epilogue: frame size=1 */
|
||||
388 0108 2196 adiw r28,1
|
||||
389 010a 0FB6 in __tmp_reg__,__SREG__
|
||||
390 010c F894 cli
|
||||
391 010e DEBF out __SP_H__,r29
|
||||
392 0110 0FBE out __SREG__,__tmp_reg__
|
||||
393 0112 CDBF out __SP_L__,r28
|
||||
394 0114 DF91 pop r29
|
||||
395 0116 CF91 pop r28
|
||||
396 0118 0895 ret
|
||||
397 /* epilogue end (size=9) */
|
||||
398 /* function uartGetByte size 29 (10) */
|
||||
403 .Lscope8:
|
||||
406 .global uartFlushReceiveBuffer
|
||||
408 uartFlushReceiveBuffer:
|
||||
147:../avrlib/uart.c **** }
|
||||
148:../avrlib/uart.c **** else
|
||||
149:../avrlib/uart.c **** {
|
||||
150:../avrlib/uart.c **** // no data
|
||||
151:../avrlib/uart.c **** return FALSE;
|
||||
152:../avrlib/uart.c **** }
|
||||
153:../avrlib/uart.c **** }
|
||||
154:../avrlib/uart.c **** else
|
||||
155:../avrlib/uart.c **** {
|
||||
156:../avrlib/uart.c **** // no buffer
|
||||
157:../avrlib/uart.c **** return FALSE;
|
||||
158:../avrlib/uart.c **** }
|
||||
159:../avrlib/uart.c **** }
|
||||
160:../avrlib/uart.c ****
|
||||
161:../avrlib/uart.c **** //! flush all data out of the receive buffer
|
||||
162:../avrlib/uart.c **** void uartFlushReceiveBuffer(void)
|
||||
163:../avrlib/uart.c **** {
|
||||
410 .LM36:
|
||||
411 /* prologue: frame size=0 */
|
||||
412 /* prologue end (size=0) */
|
||||
164:../avrlib/uart.c **** // flush all data from receive buffer
|
||||
165:../avrlib/uart.c **** //bufferFlush(&uartRxBuffer);
|
||||
166:../avrlib/uart.c **** // same effect as above
|
||||
167:../avrlib/uart.c **** uartRxBuffer.datalength = 0;
|
||||
414 .LM37:
|
||||
415 011a 1092 0000 sts (uartRxBuffer+4)+1,__zero_reg__
|
||||
416 011e 1092 0000 sts uartRxBuffer+4,__zero_reg__
|
||||
417 /* epilogue: frame size=0 */
|
||||
418 0122 0895 ret
|
||||
419 /* epilogue end (size=1) */
|
||||
420 /* function uartFlushReceiveBuffer size 5 (4) */
|
||||
422 .Lscope9:
|
||||
425 .global uartReceiveBufferIsEmpty
|
||||
427 uartReceiveBufferIsEmpty:
|
||||
168:../avrlib/uart.c **** }
|
||||
169:../avrlib/uart.c ****
|
||||
170:../avrlib/uart.c **** //! return true if uart receive buffer is empty
|
||||
171:../avrlib/uart.c **** u08 uartReceiveBufferIsEmpty(void)
|
||||
172:../avrlib/uart.c **** {
|
||||
429 .LM38:
|
||||
430 /* prologue: frame size=0 */
|
||||
431 /* prologue end (size=0) */
|
||||
173:../avrlib/uart.c **** if(uartRxBuffer.datalength == 0)
|
||||
433 .LM39:
|
||||
434 0124 8091 0000 lds r24,uartRxBuffer+4
|
||||
435 0128 9091 0000 lds r25,(uartRxBuffer+4)+1
|
||||
436 012c 892B or r24,r25
|
||||
437 012e 19F4 brne .L21
|
||||
174:../avrlib/uart.c **** {
|
||||
175:../avrlib/uart.c **** return TRUE;
|
||||
439 .LM40:
|
||||
440 0130 8FEF ldi r24,lo8(255)
|
||||
441 0132 90E0 ldi r25,hi8(255)
|
||||
442 0134 0895 ret
|
||||
443 .L21:
|
||||
176:../avrlib/uart.c **** }
|
||||
177:../avrlib/uart.c **** else
|
||||
178:../avrlib/uart.c **** {
|
||||
179:../avrlib/uart.c **** return FALSE;
|
||||
445 .LM41:
|
||||
446 0136 80E0 ldi r24,lo8(0)
|
||||
447 0138 90E0 ldi r25,hi8(0)
|
||||
180:../avrlib/uart.c **** }
|
||||
181:../avrlib/uart.c **** }
|
||||
449 .LM42:
|
||||
450 013a 0895 ret
|
||||
451 /* epilogue: frame size=0 */
|
||||
452 013c 0895 ret
|
||||
453 /* epilogue end (size=1) */
|
||||
454 /* function uartReceiveBufferIsEmpty size 13 (12) */
|
||||
456 .Lscope10:
|
||||
460 .global uartAddToTxBuffer
|
||||
462 uartAddToTxBuffer:
|
||||
182:../avrlib/uart.c ****
|
||||
183:../avrlib/uart.c **** //! add byte to end of uart Tx buffer
|
||||
184:../avrlib/uart.c **** void uartAddToTxBuffer(u08 data)
|
||||
185:../avrlib/uart.c **** {
|
||||
464 .LM43:
|
||||
465 /* prologue: frame size=0 */
|
||||
466 /* prologue end (size=0) */
|
||||
186:../avrlib/uart.c **** // add data byte to the end of the tx buffer
|
||||
187:../avrlib/uart.c **** bufferAddToEnd(&uartTxBuffer, data);
|
||||
468 .LM44:
|
||||
469 013e 682F mov r22,r24
|
||||
470 0140 80E0 ldi r24,lo8(uartTxBuffer)
|
||||
471 0142 90E0 ldi r25,hi8(uartTxBuffer)
|
||||
472 0144 00D0 rcall bufferAddToEnd
|
||||
473 /* epilogue: frame size=0 */
|
||||
474 0146 0895 ret
|
||||
475 /* epilogue end (size=1) */
|
||||
476 /* function uartAddToTxBuffer size 5 (4) */
|
||||
478 .Lscope11:
|
||||
481 .global uartSendTxBuffer
|
||||
483 uartSendTxBuffer:
|
||||
188:../avrlib/uart.c **** }
|
||||
189:../avrlib/uart.c ****
|
||||
190:../avrlib/uart.c **** //! start transmission of the current uart Tx buffer contents
|
||||
191:../avrlib/uart.c **** void uartSendTxBuffer(void)
|
||||
192:../avrlib/uart.c **** {
|
||||
485 .LM45:
|
||||
486 /* prologue: frame size=0 */
|
||||
487 /* prologue end (size=0) */
|
||||
193:../avrlib/uart.c **** // turn on buffered transmit
|
||||
194:../avrlib/uart.c **** uartBufferedTx = TRUE;
|
||||
489 .LM46:
|
||||
490 0148 8FEF ldi r24,lo8(-1)
|
||||
491 014a 8093 0000 sts uartBufferedTx,r24
|
||||
195:../avrlib/uart.c **** // send the first byte to get things going by interrupts
|
||||
196:../avrlib/uart.c **** uartSendByte(bufferGetFromFront(&uartTxBuffer));
|
||||
493 .LM47:
|
||||
494 014e 80E0 ldi r24,lo8(uartTxBuffer)
|
||||
495 0150 90E0 ldi r25,hi8(uartTxBuffer)
|
||||
496 0152 00D0 rcall bufferGetFromFront
|
||||
497 0154 A4DF rcall uartSendByte
|
||||
498 /* epilogue: frame size=0 */
|
||||
499 0156 0895 ret
|
||||
500 /* epilogue end (size=1) */
|
||||
501 /* function uartSendTxBuffer size 8 (7) */
|
||||
503 .Lscope12:
|
||||
506 .global __vector_13
|
||||
508 __vector_13:
|
||||
197:../avrlib/uart.c **** }
|
||||
198:../avrlib/uart.c **** /*
|
||||
199:../avrlib/uart.c **** //! transmit nBytes from buffer out the uart
|
||||
200:../avrlib/uart.c **** u08 uartSendBuffer(char *buffer, u16 nBytes)
|
||||
201:../avrlib/uart.c **** {
|
||||
202:../avrlib/uart.c **** register u08 first;
|
||||
203:../avrlib/uart.c **** register u16 i;
|
||||
204:../avrlib/uart.c ****
|
||||
205:../avrlib/uart.c **** // check if there's space (and that we have any bytes to send at all)
|
||||
206:../avrlib/uart.c **** if((uartTxBuffer.datalength + nBytes < uartTxBuffer.size) && nBytes)
|
||||
207:../avrlib/uart.c **** {
|
||||
208:../avrlib/uart.c **** // grab first character
|
||||
209:../avrlib/uart.c **** first = *buffer++;
|
||||
210:../avrlib/uart.c **** // copy user buffer to uart transmit buffer
|
||||
211:../avrlib/uart.c **** for(i = 0; i < nBytes-1; i++)
|
||||
212:../avrlib/uart.c **** {
|
||||
213:../avrlib/uart.c **** // put data bytes at end of buffer
|
||||
214:../avrlib/uart.c **** bufferAddToEnd(&uartTxBuffer, *buffer++);
|
||||
215:../avrlib/uart.c **** }
|
||||
216:../avrlib/uart.c ****
|
||||
217:../avrlib/uart.c **** // send the first byte to get things going by interrupts
|
||||
218:../avrlib/uart.c **** uartBufferedTx = TRUE;
|
||||
219:../avrlib/uart.c **** uartSendByte(first);
|
||||
220:../avrlib/uart.c **** // return success
|
||||
221:../avrlib/uart.c **** return TRUE;
|
||||
222:../avrlib/uart.c **** }
|
||||
223:../avrlib/uart.c **** else
|
||||
224:../avrlib/uart.c **** {
|
||||
225:../avrlib/uart.c **** // return failure
|
||||
226:../avrlib/uart.c **** return FALSE;
|
||||
227:../avrlib/uart.c **** }
|
||||
228:../avrlib/uart.c **** }
|
||||
229:../avrlib/uart.c **** */
|
||||
230:../avrlib/uart.c **** //! UART Transmit Complete Interrupt Handler
|
||||
231:../avrlib/uart.c **** UART_INTERRUPT_HANDLER(SIG_UART_TRANS)
|
||||
232:../avrlib/uart.c **** {
|
||||
510 .LM48:
|
||||
511 /* prologue: frame size=0 */
|
||||
512 0158 1F92 push __zero_reg__
|
||||
513 015a 0F92 push __tmp_reg__
|
||||
514 015c 0FB6 in __tmp_reg__,__SREG__
|
||||
515 015e 0F92 push __tmp_reg__
|
||||
516 0160 1124 clr __zero_reg__
|
||||
517 0162 2F93 push r18
|
||||
518 0164 3F93 push r19
|
||||
519 0166 4F93 push r20
|
||||
520 0168 5F93 push r21
|
||||
521 016a 6F93 push r22
|
||||
522 016c 7F93 push r23
|
||||
523 016e 8F93 push r24
|
||||
524 0170 9F93 push r25
|
||||
525 0172 AF93 push r26
|
||||
526 0174 BF93 push r27
|
||||
527 0176 EF93 push r30
|
||||
528 0178 FF93 push r31
|
||||
529 /* prologue end (size=17) */
|
||||
233:../avrlib/uart.c **** // check if buffered tx is enabled
|
||||
234:../avrlib/uart.c **** if(uartBufferedTx)
|
||||
531 .LM49:
|
||||
532 017a 8091 0000 lds r24,uartBufferedTx
|
||||
533 017e 8823 tst r24
|
||||
534 0180 69F0 breq .L26
|
||||
235:../avrlib/uart.c **** {
|
||||
236:../avrlib/uart.c **** // check if there's data left in the buffer
|
||||
237:../avrlib/uart.c **** if(uartTxBuffer.datalength)
|
||||
536 .LM50:
|
||||
537 0182 8091 0000 lds r24,uartTxBuffer+4
|
||||
538 0186 9091 0000 lds r25,(uartTxBuffer+4)+1
|
||||
539 018a 892B or r24,r25
|
||||
540 018c 29F0 breq .L27
|
||||
238:../avrlib/uart.c **** {
|
||||
239:../avrlib/uart.c **** // send byte from top of buffer
|
||||
240:../avrlib/uart.c **** outb(UDR, bufferGetFromFront(&uartTxBuffer));
|
||||
542 .LM51:
|
||||
543 018e 80E0 ldi r24,lo8(uartTxBuffer)
|
||||
544 0190 90E0 ldi r25,hi8(uartTxBuffer)
|
||||
545 0192 00D0 rcall bufferGetFromFront
|
||||
546 0194 8CB9 out 44-0x20,r24
|
||||
547 0196 05C0 rjmp .L25
|
||||
548 .L27:
|
||||
241:../avrlib/uart.c **** }
|
||||
242:../avrlib/uart.c **** else
|
||||
243:../avrlib/uart.c **** {
|
||||
244:../avrlib/uart.c **** // no data left
|
||||
245:../avrlib/uart.c **** uartBufferedTx = FALSE;
|
||||
550 .LM52:
|
||||
551 0198 1092 0000 sts uartBufferedTx,__zero_reg__
|
||||
552 .L26:
|
||||
246:../avrlib/uart.c **** // return to ready state
|
||||
247:../avrlib/uart.c **** uartReadyTx = TRUE;
|
||||
248:../avrlib/uart.c **** }
|
||||
249:../avrlib/uart.c **** }
|
||||
250:../avrlib/uart.c **** else
|
||||
251:../avrlib/uart.c **** {
|
||||
252:../avrlib/uart.c **** // we're using single-byte tx mode
|
||||
253:../avrlib/uart.c **** // indicate transmit complete, back to ready
|
||||
254:../avrlib/uart.c **** uartReadyTx = TRUE;
|
||||
554 .LM53:
|
||||
555 019c 8FEF ldi r24,lo8(-1)
|
||||
556 019e 8093 0000 sts uartReadyTx,r24
|
||||
557 .L25:
|
||||
558 /* epilogue: frame size=0 */
|
||||
559 01a2 FF91 pop r31
|
||||
560 01a4 EF91 pop r30
|
||||
561 01a6 BF91 pop r27
|
||||
562 01a8 AF91 pop r26
|
||||
563 01aa 9F91 pop r25
|
||||
564 01ac 8F91 pop r24
|
||||
565 01ae 7F91 pop r23
|
||||
566 01b0 6F91 pop r22
|
||||
567 01b2 5F91 pop r21
|
||||
568 01b4 4F91 pop r20
|
||||
569 01b6 3F91 pop r19
|
||||
570 01b8 2F91 pop r18
|
||||
571 01ba 0F90 pop __tmp_reg__
|
||||
572 01bc 0FBE out __SREG__,__tmp_reg__
|
||||
573 01be 0F90 pop __tmp_reg__
|
||||
574 01c0 1F90 pop __zero_reg__
|
||||
575 01c2 1895 reti
|
||||
576 /* epilogue end (size=17) */
|
||||
577 /* function __vector_13 size 54 (20) */
|
||||
579 .Lscope13:
|
||||
582 .global __vector_11
|
||||
584 __vector_11:
|
||||
255:../avrlib/uart.c **** }
|
||||
256:../avrlib/uart.c **** }
|
||||
257:../avrlib/uart.c ****
|
||||
258:../avrlib/uart.c **** //! UART Receive Complete Interrupt Handler
|
||||
259:../avrlib/uart.c **** UART_INTERRUPT_HANDLER(SIG_UART_RECV)
|
||||
260:../avrlib/uart.c **** {
|
||||
586 .LM54:
|
||||
587 /* prologue: frame size=0 */
|
||||
588 01c4 1F92 push __zero_reg__
|
||||
589 01c6 0F92 push __tmp_reg__
|
||||
590 01c8 0FB6 in __tmp_reg__,__SREG__
|
||||
591 01ca 0F92 push __tmp_reg__
|
||||
592 01cc 1124 clr __zero_reg__
|
||||
593 01ce 2F93 push r18
|
||||
594 01d0 3F93 push r19
|
||||
595 01d2 4F93 push r20
|
||||
596 01d4 5F93 push r21
|
||||
597 01d6 6F93 push r22
|
||||
598 01d8 7F93 push r23
|
||||
599 01da 8F93 push r24
|
||||
600 01dc 9F93 push r25
|
||||
601 01de AF93 push r26
|
||||
602 01e0 BF93 push r27
|
||||
603 01e2 EF93 push r30
|
||||
604 01e4 FF93 push r31
|
||||
605 /* prologue end (size=17) */
|
||||
261:../avrlib/uart.c **** u08 c;
|
||||
262:../avrlib/uart.c ****
|
||||
263:../avrlib/uart.c **** // get received char
|
||||
264:../avrlib/uart.c **** c = inb(UDR);
|
||||
607 .LM55:
|
||||
608 01e6 6CB1 in r22,44-0x20
|
||||
265:../avrlib/uart.c ****
|
||||
266:../avrlib/uart.c **** // if there's a user function to handle this receive event
|
||||
267:../avrlib/uart.c **** if(UartRxFunc)
|
||||
610 .LM56:
|
||||
611 01e8 8091 0000 lds r24,UartRxFunc
|
||||
612 01ec 9091 0000 lds r25,(UartRxFunc)+1
|
||||
613 01f0 892B or r24,r25
|
||||
614 01f2 39F0 breq .L31
|
||||
268:../avrlib/uart.c **** {
|
||||
269:../avrlib/uart.c **** // call it and pass the received data
|
||||
270:../avrlib/uart.c **** UartRxFunc(c);
|
||||
616 .LM57:
|
||||
617 01f4 E091 0000 lds r30,UartRxFunc
|
||||
618 01f8 F091 0000 lds r31,(UartRxFunc)+1
|
||||
619 01fc 862F mov r24,r22
|
||||
620 01fe 0995 icall
|
||||
621 0200 0EC0 rjmp .L30
|
||||
622 .L31:
|
||||
271:../avrlib/uart.c **** }
|
||||
272:../avrlib/uart.c **** else
|
||||
273:../avrlib/uart.c **** {
|
||||
274:../avrlib/uart.c **** // otherwise do default processing
|
||||
275:../avrlib/uart.c **** // put received char in buffer
|
||||
276:../avrlib/uart.c **** // check if there's space
|
||||
277:../avrlib/uart.c **** if( !bufferAddToEnd(&uartRxBuffer, c) )
|
||||
624 .LM58:
|
||||
625 0202 80E0 ldi r24,lo8(uartRxBuffer)
|
||||
626 0204 90E0 ldi r25,hi8(uartRxBuffer)
|
||||
627 0206 00D0 rcall bufferAddToEnd
|
||||
628 0208 8823 tst r24
|
||||
629 020a 49F4 brne .L30
|
||||
278:../avrlib/uart.c **** {
|
||||
279:../avrlib/uart.c **** // no space in buffer
|
||||
280:../avrlib/uart.c **** // count overflow
|
||||
281:../avrlib/uart.c **** uartRxOverflow++;
|
||||
631 .LM59:
|
||||
632 020c 8091 0000 lds r24,uartRxOverflow
|
||||
633 0210 9091 0000 lds r25,(uartRxOverflow)+1
|
||||
634 0214 0196 adiw r24,1
|
||||
635 0216 9093 0000 sts (uartRxOverflow)+1,r25
|
||||
636 021a 8093 0000 sts uartRxOverflow,r24
|
||||
637 .L30:
|
||||
638 /* epilogue: frame size=0 */
|
||||
639 021e FF91 pop r31
|
||||
640 0220 EF91 pop r30
|
||||
641 0222 BF91 pop r27
|
||||
642 0224 AF91 pop r26
|
||||
643 0226 9F91 pop r25
|
||||
644 0228 8F91 pop r24
|
||||
645 022a 7F91 pop r23
|
||||
646 022c 6F91 pop r22
|
||||
647 022e 5F91 pop r21
|
||||
648 0230 4F91 pop r20
|
||||
649 0232 3F91 pop r19
|
||||
650 0234 2F91 pop r18
|
||||
651 0236 0F90 pop __tmp_reg__
|
||||
652 0238 0FBE out __SREG__,__tmp_reg__
|
||||
653 023a 0F90 pop __tmp_reg__
|
||||
654 023c 1F90 pop __zero_reg__
|
||||
655 023e 1895 reti
|
||||
656 /* epilogue end (size=17) */
|
||||
657 /* function __vector_11 size 62 (28) */
|
||||
662 .Lscope14:
|
||||
664 .comm uartReadyTx,1,1
|
||||
665 .comm uartBufferedTx,1,1
|
||||
666 .comm uartRxBuffer,8,1
|
||||
667 .comm uartTxBuffer,8,1
|
||||
668 .comm uartRxOverflow,2,1
|
||||
669 .lcomm uartRxData,64
|
||||
670 .lcomm uartTxData,64
|
||||
671 .lcomm UartRxFunc,2
|
||||
680 .text
|
||||
682 Letext:
|
||||
683 /* File "../avrlib/uart.c": code 289 = 0x0121 ( 186), prologues 46, epilogues 57 */
|
||||
DEFINED SYMBOLS
|
||||
*ABS*:00000000 uart.c
|
||||
*ABS*:0000003f __SREG__
|
||||
*ABS*:0000003e __SP_H__
|
||||
*ABS*:0000003d __SP_L__
|
||||
*ABS*:00000000 __tmp_reg__
|
||||
*ABS*:00000001 __zero_reg__
|
||||
/var/tmp//cclgUhYv.s:88 .text:00000000 uartSetBaudRate
|
||||
/var/tmp//cclgUhYv.s:141 .text:0000003c uartInitBuffers
|
||||
.bss:00000000 uartRxData
|
||||
*COM*:00000008 uartRxBuffer
|
||||
/var/tmp//cclgUhYv.s:669 .bss:00000040 uartTxData
|
||||
*COM*:00000008 uartTxBuffer
|
||||
/var/tmp//cclgUhYv.s:174 .text:0000005a uartInit
|
||||
/var/tmp//cclgUhYv.s:670 .bss:00000080 UartRxFunc
|
||||
*COM*:00000001 uartReadyTx
|
||||
*COM*:00000001 uartBufferedTx
|
||||
*COM*:00000002 uartRxOverflow
|
||||
/var/tmp//cclgUhYv.s:224 .text:00000088 uartSetRxHandler
|
||||
/var/tmp//cclgUhYv.s:243 .text:00000092 uartGetRxBuffer
|
||||
/var/tmp//cclgUhYv.s:262 .text:00000098 uartGetTxBuffer
|
||||
/var/tmp//cclgUhYv.s:282 .text:0000009e uartSendByte
|
||||
/var/tmp//cclgUhYv.s:311 .text:000000b0 uartReceiveByte
|
||||
/var/tmp//cclgUhYv.s:354 .text:000000e0 uartGetByte
|
||||
/var/tmp//cclgUhYv.s:408 .text:0000011a uartFlushReceiveBuffer
|
||||
/var/tmp//cclgUhYv.s:427 .text:00000124 uartReceiveBufferIsEmpty
|
||||
/var/tmp//cclgUhYv.s:462 .text:0000013e uartAddToTxBuffer
|
||||
/var/tmp//cclgUhYv.s:483 .text:00000148 uartSendTxBuffer
|
||||
/var/tmp//cclgUhYv.s:508 .text:00000158 __vector_13
|
||||
/var/tmp//cclgUhYv.s:584 .text:000001c4 __vector_11
|
||||
/var/tmp//cclgUhYv.s:682 .text:00000240 Letext
|
||||
|
||||
UNDEFINED SYMBOLS
|
||||
__do_copy_data
|
||||
__do_clear_bss
|
||||
__udivmodsi4
|
||||
bufferInit
|
||||
bufferGetFromFront
|
||||
bufferAddToEnd
|
52
targets/wiring/Matrix.h
Executable file
52
targets/wiring/Matrix.h
Executable file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Matrix.h - Max7219 LED Matrix library file for Wiring
|
||||
Part of the Wiring project - http://wiring.org.co
|
||||
|
||||
Copyright (c) 2004-2005 Hernando Barragan
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Max7219 LED Matrix library by Nicholas Zambetti
|
||||
*/
|
||||
|
||||
|
||||
#ifndef Matrix_h
|
||||
#define Matrix_h
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
class Matrix
|
||||
{
|
||||
private:
|
||||
uint8_t _pinClock;
|
||||
uint8_t _pinLoad;
|
||||
uint8_t _pinData;
|
||||
|
||||
uint8_t _screenBuffer[8];
|
||||
|
||||
void putByte(uint8_t);
|
||||
|
||||
public:
|
||||
Matrix(uint8_t, uint8_t, uint8_t);
|
||||
void set(uint8_t, uint8_t);
|
||||
void setAll(uint8_t);
|
||||
void setScanLimit(uint8_t);
|
||||
void setIntensity(uint8_t);
|
||||
void storePixel(uint8_t, uint8_t, uint8_t);
|
||||
void updatePixels(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
53
targets/wiring/Servo.h
Executable file
53
targets/wiring/Servo.h
Executable file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
Servo.h - Servo library file for Wiring
|
||||
Part of the Wiring project - http://wiring.org.co
|
||||
|
||||
Copyright (c) 2004-2005 Hernando Barragan
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Servo library by Nicholas Zambetti
|
||||
*/
|
||||
|
||||
|
||||
#ifndef Servo_h
|
||||
#define Servo_h
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
class Servo
|
||||
{
|
||||
private:
|
||||
uint8_t _index;
|
||||
uint8_t _pin;
|
||||
uint16_t _duty;
|
||||
static uint8_t _count;
|
||||
static Servo* _servos[];
|
||||
static int8_t _current;
|
||||
static uint16_t _positionTicks;
|
||||
static void start();
|
||||
static void end();
|
||||
static void service();
|
||||
public:
|
||||
Servo();
|
||||
uint8_t attach(int);
|
||||
void detach();
|
||||
void write(int);
|
||||
uint8_t read();
|
||||
uint8_t attached();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
BIN
targets/wiring/Servo.o
Normal file
BIN
targets/wiring/Servo.o
Normal file
Binary file not shown.
BIN
targets/wiring/WApplet.o
Normal file
BIN
targets/wiring/WApplet.o
Normal file
Binary file not shown.
246
targets/wiring/WConstants.h
Executable file
246
targets/wiring/WConstants.h
Executable file
@ -0,0 +1,246 @@
|
||||
/*
|
||||
WConstats.h - main definitions file for Wiring
|
||||
Part of the Wiring project - http://wiring.org.co
|
||||
|
||||
Copyright (c) 2004-2005 Hernando Barragan
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef WConstants_h
|
||||
#define WConstants_h
|
||||
|
||||
#define PI (3.1415927)
|
||||
#define HALF_PI (1.57079)
|
||||
#define TWO_PI (6.2831854)
|
||||
#define DEG_TO_RAD (0.01745329)
|
||||
#define RAD_TO_DEG (57.2957786)
|
||||
#define EPSILON (0.0001)
|
||||
|
||||
#define WPIN0 (1<<0)
|
||||
#define WPIN1 (1<<1)
|
||||
#define WPIN2 (1<<2)
|
||||
#define WPIN3 (1<<3)
|
||||
#define WPIN4 (1<<4)
|
||||
#define WPIN5 (1<<5)
|
||||
#define WPIN6 (1<<6)
|
||||
#define WPIN7 (1<<7)
|
||||
|
||||
#define WPWMPIN5 (1<<5) // PINB5
|
||||
#define WPWMPIN4 (1<<6) // PINB6
|
||||
#define WPWMPIN3 (1<<7) // PINB7
|
||||
#define WPWMPIN2 (1<<3) // PINE3
|
||||
#define WPWMPIN1 (1<<4) // PINE4
|
||||
#define WPWMPIN0 (1<<5) // PINE5
|
||||
|
||||
#define WPORTA PORTA
|
||||
#define WPORTB PORTB
|
||||
#define WPORTC PORTC
|
||||
#define WPORTD PORTD
|
||||
#define WPORTE PORTE
|
||||
#define WPORTF PORTF
|
||||
#define WPORTG PORTG
|
||||
|
||||
#define WPINA PINA
|
||||
#define WPINB PINB
|
||||
#define WPINC PINC
|
||||
#define WPIND PIND
|
||||
#define WPINE PINE
|
||||
#define WPINF PINF
|
||||
#define WPING PING
|
||||
|
||||
#define WDDRA DDRA
|
||||
#define WDDRB DDRB
|
||||
#define WDDRC DDRC
|
||||
#define WDDRD DDRD
|
||||
#define WDDRE DDRE
|
||||
#define WDDRF DDRF
|
||||
#define WDDRG DDRG
|
||||
|
||||
|
||||
#define HIGH 0x1
|
||||
#define LOW 0x0
|
||||
|
||||
#define INPUT 0x0
|
||||
#define OUTPUT 0x1
|
||||
|
||||
#define true 0x1
|
||||
#define false 0x0
|
||||
|
||||
#define CPU_FREQ 16000000L
|
||||
|
||||
#define TIMER0OVERFLOW_INT 0
|
||||
#define TIMER0OUTCOMPARE_INT 1
|
||||
#define TIMER1OVERFLOW_INT 2
|
||||
#define TIMER1OUTCOMPAREA_INT 3
|
||||
#define TIMER1OUTCOMPAREB_INT 4
|
||||
#define TIMER1OUTCOMPAREC_INT 5
|
||||
#define TIMER1INPUTCAPTURE_INT 6
|
||||
#define TIMER2OVERFLOW_INT 7
|
||||
#define TIMER2OUTCOMPARE_INT 8
|
||||
#define TIMER3OVERFLOW_INT 9
|
||||
#define TIMER3OUTCOMPAREA_INT 10
|
||||
#define TIMER3OUTCOMPAREB_INT 11
|
||||
#define TIMER3OUTCOMPAREC_INT 12
|
||||
#define TIMER3INPUTCAPTURE_INT 13
|
||||
|
||||
#define TIMER_NUM_INTERRUPTS 14
|
||||
|
||||
#define TIMER_CLK_STOP 0x00
|
||||
#define TIMER_CLK_DIV1 0x01
|
||||
#define TIMER_CLK_DIV8 0x02
|
||||
#define TIMER_CLK_DIV64 0x03
|
||||
#define TIMER_CLK_DIV256 0x04
|
||||
#define TIMER_CLK_DIV1024 0x05
|
||||
#define TIMER_CLK_T_FALL 0x06
|
||||
#define TIMER_CLK_T_RISE 0x07
|
||||
#define TIMER_PRESCALE_MASK 0x07
|
||||
|
||||
#define TIMERRTC_CLK_STOP 0x00
|
||||
#define TIMERRTC_CLK_DIV1 0x01
|
||||
#define TIMERRTC_CLK_DIV8 0x02
|
||||
#define TIMERRTC_CLK_DIV32 0x03
|
||||
#define TIMERRTC_CLK_DIV64 0x04
|
||||
#define TIMERRTC_CLK_DIV128 0x05
|
||||
#define TIMERRTC_CLK_DIV256 0x06
|
||||
#define TIMERRTC_CLK_DIV1024 0x07
|
||||
#define TIMERRTC_PRESCALE_MASK 0x07
|
||||
|
||||
#define TIMER0PRESCALE TIMERRTC_CLK_DIV64
|
||||
#define TIMER1PRESCALE TIMER_CLK_DIV64
|
||||
#define TIMER2PRESCALE TIMER_CLK_DIV8
|
||||
#define TIMER3PRESCALE TIMER_CLK_DIV64
|
||||
|
||||
#ifndef __cplusplus
|
||||
volatile struct {
|
||||
uint8_t rxInt : 1;
|
||||
uint8_t rx1Int : 1;
|
||||
uint8_t uart0TxComplete : 1;
|
||||
uint8_t uart1TxComplete : 1;
|
||||
} event;
|
||||
#endif
|
||||
|
||||
typedef struct wbuffer_t {
|
||||
uint16_t buflen;
|
||||
uint16_t bufcnt;
|
||||
uint8_t * in;
|
||||
uint8_t * out;
|
||||
uint8_t * buf;
|
||||
} WBuffer;
|
||||
|
||||
typedef struct {
|
||||
void (*begin) (int);
|
||||
uint8_t (*available) ();
|
||||
int (*read) ();
|
||||
void (*write) (int);
|
||||
void (*writeBytes) (char[]);
|
||||
} WSerial;
|
||||
|
||||
extern WSerial Serial1;
|
||||
extern WSerial Serial;
|
||||
|
||||
typedef uint8_t boolean;
|
||||
typedef uint8_t byte;
|
||||
|
||||
//int serial;
|
||||
#define DEF_UART 0
|
||||
#define AUX_UART 1
|
||||
#define SERIAL0 0
|
||||
#define SERIAL1 1
|
||||
|
||||
#define UART_BUF_LEN 32
|
||||
|
||||
|
||||
|
||||
#define min(a,b) ((a<b)?(a):(b))
|
||||
#define max(a,b) ((a>b)?(a):(b))
|
||||
#define abs(x) ((x>0)?(x):(-x))
|
||||
#define constrain(amt,low,high) ((amt<low)?(low):((amt>high)?(high):(amt)))
|
||||
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||
#define sq(x) ((x)*(x))
|
||||
|
||||
#define SERVO_NUM_CHANNELS 8
|
||||
#define SERVO_MAX 142
|
||||
#define SERVO_MIN 34
|
||||
#define POSITION_MAX 255
|
||||
#define SERVO_DEFAULT_PORT PORTA
|
||||
|
||||
|
||||
//static char uartBuffer[UART_BUF_LEN];
|
||||
//WBuffer uartbuf;
|
||||
typedef void (*voidFuncPtru08)(void);
|
||||
volatile static voidFuncPtru08 uartRxFunc;
|
||||
typedef void (*voidFuncPtr)(void);
|
||||
|
||||
|
||||
#define WD_CTRL_PORT PORTC
|
||||
#define WD_CTRL_DDR DDRC
|
||||
#define WD_CTRL_RS 0
|
||||
#define WD_CTRL_RW 1
|
||||
#define WD_CTRL_E 2
|
||||
#define WD_DATA_POUT PORTA
|
||||
#define WD_DATA_PIN PINA
|
||||
#define WD_DATA_DDR DDRA
|
||||
#define WD_LINE0_DDRAMADDR 0x00
|
||||
#define WD_LINE1_DDRAMADDR 0x40
|
||||
#define WD_LINE2_DDRAMADDR 0x14
|
||||
#define WD_LINE3_DDRAMADDR 0x54
|
||||
|
||||
#define WD_CLR 0
|
||||
#define WD_HOME 1
|
||||
#define WD_ENTRY_MODE 2
|
||||
#define WD_ENTRY_INC 1
|
||||
#define WD_ENTRY_SHIFT 0
|
||||
#define WD_ON_CTRL 3
|
||||
#define WD_ON_DISPLAY 2
|
||||
#define WD_ON_CURSOR 1
|
||||
#define WD_ON_BLINK 0
|
||||
#define WD_MOVE 4
|
||||
#define WD_MOVE_DISP 3
|
||||
#define WD_MOVE_RIGHT 2
|
||||
#define WD_FUNCTION 5
|
||||
#define WD_FUNCTION_8BIT 4
|
||||
#define WD_FUNCTION_2LINES 3
|
||||
#define WD_FUNCTION_10DOTS 2
|
||||
#define WD_CGRAM 6
|
||||
#define WD_DDRAM 7
|
||||
#define WD_BUSY 7
|
||||
|
||||
#define DATA_8_BITS 0x0
|
||||
#define DATA_4_BITS 0x1
|
||||
|
||||
#define SERIAL 0x0
|
||||
#define DISPLAY 0x1
|
||||
|
||||
#define EXTERNAL_NUM_INTERRUPTS 8
|
||||
#define NUM_ENCODERS 4
|
||||
#define EXTERNAL_INT_0 0
|
||||
#define EXTERNAL_INT_1 1
|
||||
#define EXTERNAL_INT_2 2
|
||||
#define EXTERNAL_INT_3 3
|
||||
#define EXTERNAL_INT_4 4
|
||||
#define EXTERNAL_INT_5 5
|
||||
#define EXTERNAL_INT_6 6
|
||||
#define EXTERNAL_INT_7 7
|
||||
|
||||
#ifndef __cplusplus
|
||||
void print(const char *template, ...);
|
||||
void pinMode(uint8_t, uint8_t);
|
||||
void digitalWrite(uint8_t, uint8_t);
|
||||
void delay(int);
|
||||
#endif
|
||||
|
||||
#endif
|
BIN
targets/wiring/WCounter.o
Normal file
BIN
targets/wiring/WCounter.o
Normal file
Binary file not shown.
BIN
targets/wiring/WDisplay.o
Normal file
BIN
targets/wiring/WDisplay.o
Normal file
Binary file not shown.
BIN
targets/wiring/WEncoder.o
Normal file
BIN
targets/wiring/WEncoder.o
Normal file
Binary file not shown.
BIN
targets/wiring/WInterrupts.o
Normal file
BIN
targets/wiring/WInterrupts.o
Normal file
Binary file not shown.
86
targets/wiring/WProgram.h
Executable file
86
targets/wiring/WProgram.h
Executable file
@ -0,0 +1,86 @@
|
||||
extern "C" {
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/delay.h>
|
||||
|
||||
#include "WConstants.h"
|
||||
|
||||
// main program prototypes
|
||||
void setup(void);
|
||||
void loop(void);
|
||||
|
||||
// timing prototypes
|
||||
void delay(int);
|
||||
int millis(void);
|
||||
|
||||
// pin prototypes
|
||||
void pinMode(uint8_t, uint8_t);
|
||||
uint8_t digitalRead(uint8_t);
|
||||
void digitalWrite(int, uint8_t);
|
||||
void portMode(int, int);
|
||||
int portRead(int);
|
||||
void portWrite(int, int);
|
||||
int analogRead(int);
|
||||
void analogWrite(int, int);
|
||||
|
||||
// pulse prototypes
|
||||
void beginPulse(void);
|
||||
void endPulse(void);
|
||||
void pulseFrequency(int, int);
|
||||
void pulseRun(int, int);
|
||||
void pulseStop(int);
|
||||
int pulseRunning(int);
|
||||
uint16_t pulseIn(uint8_t, uint8_t);
|
||||
|
||||
// interrupt management prototypes
|
||||
void attachInterrupt(uint8_t, void *(void) );
|
||||
void detachInterrupt(uint8_t);
|
||||
|
||||
// serial prototypes
|
||||
void beginSerial(int);
|
||||
void endSerial(void);
|
||||
int serialRead(void);
|
||||
void serialWrite(int);
|
||||
void serialWriteBytes(char[]);
|
||||
uint8_t serialAvailable(void);
|
||||
void beginSerial1(int);
|
||||
void endSerial1(void);
|
||||
int serial1Read(void);
|
||||
void serial1Write(int);
|
||||
void serial1WriteBytes(char[]);
|
||||
uint8_t serial1Available(void);
|
||||
void printMode(int);
|
||||
void print(const char *, ...);
|
||||
|
||||
/*
|
||||
// servo prototypes
|
||||
void beginServo(void);
|
||||
void endServo(void);
|
||||
void attachServo(int, int);
|
||||
uint8_t servoRead(int);
|
||||
void servoWrite(int, int);
|
||||
*/
|
||||
|
||||
// lcd prototypes
|
||||
void beginDisplay(void);
|
||||
void endDisplay(void);
|
||||
void displayWrite(int);
|
||||
void displayClear(void);
|
||||
void cursorHome(void);
|
||||
void cursorMoveTo(uint8_t, uint8_t);
|
||||
|
||||
// encoder prototypes
|
||||
void beginEncoder(void);
|
||||
void endEncoder(void);
|
||||
void attachEncoder(int, int, int);
|
||||
int32_t encoderRead(uint8_t);
|
||||
void encoderWrite(uint8_t, uint32_t);
|
||||
}
|
||||
|
||||
// library includes
|
||||
#include "Servo.h"
|
||||
//#include "Wire.h"
|
||||
//#include "Matrix.h"
|
||||
|
BIN
targets/wiring/WSerial.o
Normal file
BIN
targets/wiring/WSerial.o
Normal file
Binary file not shown.
BIN
targets/wiring/WTimer.o
Normal file
BIN
targets/wiring/WTimer.o
Normal file
Binary file not shown.
83
targets/wiring/Wire.h
Executable file
83
targets/wiring/Wire.h
Executable file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
Wire.h - TWI/I2C library file for Wiring
|
||||
Part of the Wiring project - http://wiring.org.co
|
||||
|
||||
Copyright (c) 2004-2005 Hernando Barragan
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Wire TWI/I2C library by Nicholas Zambetti
|
||||
*/
|
||||
|
||||
|
||||
#ifndef Wire_h
|
||||
#define Wire_h
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifndef TWI_FREQ
|
||||
#define TWI_FREQ 100000L
|
||||
#endif
|
||||
|
||||
#ifndef TWI_BUFFERSIZE
|
||||
#define TWI_BUFFERSIZE 32
|
||||
#endif
|
||||
|
||||
class Wire
|
||||
{
|
||||
private:
|
||||
static volatile uint8_t _state;
|
||||
static uint8_t _slarw;
|
||||
|
||||
static uint8_t _masterBuffer[TWI_BUFFERSIZE];
|
||||
static uint8_t _masterBufferLength;
|
||||
static volatile uint8_t _masterBufferIndex;
|
||||
|
||||
static void (*Wire::_onSlaveTransmit)(void);
|
||||
static void (*Wire::_onSlaveReceive)(int);
|
||||
|
||||
static uint8_t _txBuffer[TWI_BUFFERSIZE];
|
||||
static volatile uint8_t _txBufferIndex;
|
||||
static volatile uint8_t _txBufferLength;
|
||||
|
||||
static uint8_t _rxBuffer[TWI_BUFFERSIZE];
|
||||
static volatile uint8_t _rxBufferIndex;
|
||||
|
||||
uint8_t readFrom(uint8_t, uint8_t*, uint8_t);
|
||||
uint8_t writeTo(uint8_t, uint8_t*, uint8_t, uint8_t);
|
||||
static void reply(uint8_t);
|
||||
static void stop(void);
|
||||
static void releaseBus(void);
|
||||
static void interruptLogic(void);
|
||||
public:
|
||||
Wire(uint8_t);
|
||||
uint8_t read(int);
|
||||
void readBytes(int, uint8_t*, int);
|
||||
void readBytes(int, char*, int);
|
||||
void write(int, int);
|
||||
void writeBytes(int, uint8_t*, int);
|
||||
void writeBytes(int, char*);
|
||||
void transmit(uint8_t);
|
||||
void transmitBytes(uint8_t*, uint8_t);
|
||||
void transmitBytes(char*);
|
||||
uint8_t receive(void);
|
||||
void receiveBytes(uint8_t*);
|
||||
void receiveBytes(char*);
|
||||
void onDataIn( void (*)(int) );
|
||||
void onDataOut( void (*)(void) );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
BIN
targets/wiring/Wire.o
Normal file
BIN
targets/wiring/Wire.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user