diff --git a/app/preproc/test/data/foo1.cpp b/app/preproc/test/data/foo1.cpp new file mode 100644 index 000000000..7113b33fc --- /dev/null +++ b/app/preproc/test/data/foo1.cpp @@ -0,0 +1,21 @@ +int encoder = 4; +unsigned long speed = 0; + +void setup() +{ + pinMode(encoder, INPUT); +} + +void loop() +{ + speed = getspeed(); + delay(1000); +} + +unsigned long getspeed() +{ + unsigned long duration = 0; + duration = pulseIn(encoder, HIGH); + return(duration); +} + diff --git a/app/preproc/test/data/foo1.cpp.out b/app/preproc/test/data/foo1.cpp.out new file mode 100644 index 000000000..4542ae3ac --- /dev/null +++ b/app/preproc/test/data/foo1.cpp.out @@ -0,0 +1,3 @@ +void setup(); +void loop(); +unsigned long getspeed(); diff --git a/app/preproc/test/data/foo2.cpp b/app/preproc/test/data/foo2.cpp new file mode 100644 index 000000000..36db12ce9 --- /dev/null +++ b/app/preproc/test/data/foo2.cpp @@ -0,0 +1,8 @@ +void playMessage(prog_uchar* message){ + +maxStringSize = sizeof(message); // find message size +} + +void loop() { + playMessage(signMessage); +} diff --git a/app/preproc/test/data/foo2.cpp.out b/app/preproc/test/data/foo2.cpp.out new file mode 100644 index 000000000..688d1807e --- /dev/null +++ b/app/preproc/test/data/foo2.cpp.out @@ -0,0 +1,2 @@ +void playMessage(prog_uchar* message); +void loop(); diff --git a/app/preproc/test/data/foo3.cpp b/app/preproc/test/data/foo3.cpp new file mode 100644 index 000000000..9b92470d7 --- /dev/null +++ b/app/preproc/test/data/foo3.cpp @@ -0,0 +1,19 @@ +void setup() // run once, when the sketch starts +{ + ; +} + +void loop() // run over and over again +{ + ; +} + +/* +void loop(){ + if (1){ + ; + } +else if(0){ + ; +} +} */ diff --git a/app/preproc/test/data/foo3.cpp.out b/app/preproc/test/data/foo3.cpp.out new file mode 100644 index 000000000..82cdaeca9 --- /dev/null +++ b/app/preproc/test/data/foo3.cpp.out @@ -0,0 +1,2 @@ +void setup(); +void loop(); diff --git a/app/preproc/test/data/foo4.cpp b/app/preproc/test/data/foo4.cpp new file mode 100644 index 000000000..9bc971566 --- /dev/null +++ b/app/preproc/test/data/foo4.cpp @@ -0,0 +1,132 @@ +// +// Continually measures temperatures at three points using the Dallas DS18B20 on three +// separate Arduino pins. +// +// Uses the parasitic power mode +// +// Displays to a serial LCD operating at 9600 baud. +// +// Arduino Board DS18B20 +// +// +5 VDC +// | +// 4.7K +// 8 ---------------- |----- 2 (DQ) Note that terms 1 and 3 are grounded. +// +// 7 ---- same as above +// 6 ---- same as above +// +// Tx ---------------------------- To Serial LCD (LCD #117) +// +// Peter H Anderson, Baltimore, MD, May 5, '07 + + +void setup() +{ + int n, dev_channel[3] = {8, 7, 6}, _1W_Pin; + + for (n=0; n<1; n++) + { + _1W_Pin = dev_channel[n]; + digitalWrite(_1W_Pin, LOW); + pinMode(_1W_Pin, INPUT); // sets the digital pin as input (logic 1) + } + Serial.begin(9600); + delay(100); + Serial.print("?B40"); // set backlight intensity + delay(100); +} + +void loop() +{ + int n, dev_channel[3] = {8, 7, 6}, _1W_Pin; + int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract; + + for (n=0; n<3; n++) + { + _1W_Pin = dev_channel[n]; + OneWireReset(_1W_Pin); + OneWireOutByte(_1W_Pin, 0xcc, 0); + OneWireOutByte(_1W_Pin, 0x44, 1); // perform temperature conversion, strong pullup for one sec + + OneWireReset(_1W_Pin); + OneWireOutByte(_1W_Pin, 0xcc, 0); + OneWireOutByte(_1W_Pin, 0xbe, 0); + + LowByte = OneWireInByte(_1W_Pin); + HighByte = OneWireInByte(_1W_Pin); + TReading = (HighByte << 8) + LowByte; + SignBit = TReading & 0x8000; // test most sig bit + if (SignBit) // negative + { + TReading = (TReading ^ 0xffff) + 1; // 2's comp + } + Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25 + + Whole = Tc_100 / 100; // separate off the whole and fractional portions + Fract = Tc_100 % 100; + + if (n==0) // if its the first time, clear the LCD + { + Serial.print("?f"); + delay(100); + } + + if (SignBit) // If its negative + { + Serial.print("-"); + } + Serial.print(Whole); + Serial.print("."); + if (Fract < 10) + { + Serial.print("0"); + } + Serial.print(Fract); + Serial.print("?n"); + } + delay(5000); // 5 second delay. Adjust as necessary +} + +void OneWireReset(int _1W_Pin) // reset. Should improve to act as a presence pulse +{ + digitalWrite(_1W_Pin, LOW); + pinMode(_1W_Pin, OUTPUT); // bring low for 500 us + delayMicroseconds(500); + pinMode(_1W_Pin, INPUT); + delayMicroseconds(500); +} + +void OneWireOutByte(int _1W_Pin, byte d, byte strong) // output byte d (least sig bit first). +{ + byte n; + + for(n=8; n!=0; n--) + { + if ((d & 0x01) == 1) // test least sig bit + { + digitalWrite(_1W_Pin, LOW); + pinMode(_1W_Pin, OUTPUT); + delayMicroseconds(5); + pinMode(_1W_Pin, INPUT); + delayMicroseconds(60); + } + else + { + digitalWrite(_1W_Pin, LOW); + pinMode(_1W_Pin, OUTPUT); + delayMicroseconds(60); + pinMode(_1W_Pin, INPUT); + } + + d=d>>1; // now the next bit is in the least sig bit position. + } + if(strong) + { + digitalWrite(_1W_Pin, HIGH); // One sec of strong +5 VDC + pinMode(_1W_Pin, OUTPUT); + delay(1000); + pinMode(_1W_Pin, INPUT); + digitalWrite(_1W_Pin, LOW); + } +} diff --git a/app/preproc/test/data/foo4.cpp.out b/app/preproc/test/data/foo4.cpp.out new file mode 100644 index 000000000..58c736416 --- /dev/null +++ b/app/preproc/test/data/foo4.cpp.out @@ -0,0 +1,4 @@ +void setup(); +void loop(); +void OneWireReset(int _1W_Pin); +void OneWireOutByte(int _1W_Pin, byte d, byte strong); diff --git a/app/preproc/test/data/foo5.cpp b/app/preproc/test/data/foo5.cpp new file mode 100644 index 000000000..5b8ee2db4 --- /dev/null +++ b/app/preproc/test/data/foo5.cpp @@ -0,0 +1,16 @@ +void setup() +{ +} + +void loop() +{ + char cmd[16]; + int pin; + pin = atoi(&cmd[1]); +} + +/* +// convert string to numeric value +int atoi(char *array) { +} +*/ diff --git a/app/preproc/test/data/foo5.cpp.out b/app/preproc/test/data/foo5.cpp.out new file mode 100644 index 000000000..82cdaeca9 --- /dev/null +++ b/app/preproc/test/data/foo5.cpp.out @@ -0,0 +1,2 @@ +void setup(); +void loop(); diff --git a/app/preproc/test/data/foo6.cpp b/app/preproc/test/data/foo6.cpp new file mode 100644 index 000000000..f294435af --- /dev/null +++ b/app/preproc/test/data/foo6.cpp @@ -0,0 +1,11 @@ +void setup() +{ +} + +void loop() +{ +} + +void foo(int x, int y, char *z) +{ +} diff --git a/app/preproc/test/data/foo6.cpp.out b/app/preproc/test/data/foo6.cpp.out new file mode 100644 index 000000000..d35513110 --- /dev/null +++ b/app/preproc/test/data/foo6.cpp.out @@ -0,0 +1,3 @@ +void setup(); +void loop(); +void foo(int x, int y, char *z); diff --git a/app/preproc/test/data/foo7.cpp b/app/preproc/test/data/foo7.cpp new file mode 100644 index 000000000..93724a54a --- /dev/null +++ b/app/preproc/test/data/foo7.cpp @@ -0,0 +1,35 @@ +#include "hello" /* for blah */ + +int x[] = { 1, 2, 3 }; +int y[2] = { 1, 2 }; + +class Foo { +public: + Foo(); + Foo(int x); + int bar() { return x; } +private: + int x; +}; + +Foo::Foo(int x) : x(x) {} + +Foo::Foo() { + x = 0; +} + +Foo foo(3); +Foo bar = Foo(2); + +void setup() { +} + +void +loop ( + +) + + + +{ +} diff --git a/app/preproc/test/data/foo7.cpp.out b/app/preproc/test/data/foo7.cpp.out new file mode 100644 index 000000000..edb355ae0 --- /dev/null +++ b/app/preproc/test/data/foo7.cpp.out @@ -0,0 +1,5 @@ +void setup(); +void +loop ( + +); diff --git a/app/preproc/test/data/t1.cpp b/app/preproc/test/data/t1.cpp new file mode 100644 index 000000000..b11d4bfe5 --- /dev/null +++ b/app/preproc/test/data/t1.cpp @@ -0,0 +1,5 @@ +abc/* def */ghi +jkl// mno +pqr"stu"vwx +#yz +123 \ No newline at end of file diff --git a/app/preproc/test/data/t1.cpp.out b/app/preproc/test/data/t1.cpp.out new file mode 100644 index 000000000..723a710da --- /dev/null +++ b/app/preproc/test/data/t1.cpp.out @@ -0,0 +1,5 @@ +abc ghi +jkl +pqr vwx + +123 \ No newline at end of file diff --git a/app/preproc/test/data/t10.cpp b/app/preproc/test/data/t10.cpp new file mode 100644 index 000000000..735cb56fd --- /dev/null +++ b/app/preproc/test/data/t10.cpp @@ -0,0 +1 @@ +abc"d\nef\\\"ghi"jkl//" \ No newline at end of file diff --git a/app/preproc/test/data/t10.cpp.out b/app/preproc/test/data/t10.cpp.out new file mode 100644 index 000000000..abc43e324 --- /dev/null +++ b/app/preproc/test/data/t10.cpp.out @@ -0,0 +1 @@ +abc jkl \ No newline at end of file diff --git a/app/preproc/test/data/t11.cpp b/app/preproc/test/data/t11.cpp new file mode 100644 index 000000000..5e25564df --- /dev/null +++ b/app/preproc/test/data/t11.cpp @@ -0,0 +1 @@ +abc"d\\nef\\\"ghi"jkl//" \ No newline at end of file diff --git a/app/preproc/test/data/t11.cpp.out b/app/preproc/test/data/t11.cpp.out new file mode 100644 index 000000000..abc43e324 --- /dev/null +++ b/app/preproc/test/data/t11.cpp.out @@ -0,0 +1 @@ +abc jkl \ No newline at end of file diff --git a/app/preproc/test/data/t12.cpp b/app/preproc/test/data/t12.cpp new file mode 100644 index 000000000..1abde0a61 --- /dev/null +++ b/app/preproc/test/data/t12.cpp @@ -0,0 +1 @@ +abc"dnef\\\\\"ghi"jkl//" \ No newline at end of file diff --git a/app/preproc/test/data/t12.cpp.out b/app/preproc/test/data/t12.cpp.out new file mode 100644 index 000000000..abc43e324 --- /dev/null +++ b/app/preproc/test/data/t12.cpp.out @@ -0,0 +1 @@ +abc jkl \ No newline at end of file diff --git a/app/preproc/test/data/t13.cpp b/app/preproc/test/data/t13.cpp new file mode 100644 index 000000000..d0e184f75 --- /dev/null +++ b/app/preproc/test/data/t13.cpp @@ -0,0 +1 @@ +abc'"'def'"'ghi \ No newline at end of file diff --git a/app/preproc/test/data/t13.cpp.out b/app/preproc/test/data/t13.cpp.out new file mode 100644 index 000000000..a371d86fa --- /dev/null +++ b/app/preproc/test/data/t13.cpp.out @@ -0,0 +1 @@ +abc def ghi \ No newline at end of file diff --git a/app/preproc/test/data/t14.cpp b/app/preproc/test/data/t14.cpp new file mode 100644 index 000000000..5b5a740ab --- /dev/null +++ b/app/preproc/test/data/t14.cpp @@ -0,0 +1,2 @@ +# abc /* def +ghi */ jkl \ No newline at end of file diff --git a/app/preproc/test/data/t14.cpp.out b/app/preproc/test/data/t14.cpp.out new file mode 100644 index 000000000..872e9cc0b --- /dev/null +++ b/app/preproc/test/data/t14.cpp.out @@ -0,0 +1 @@ + jkl \ No newline at end of file diff --git a/app/preproc/test/data/t15.cpp b/app/preproc/test/data/t15.cpp new file mode 100644 index 000000000..a8b57e51d --- /dev/null +++ b/app/preproc/test/data/t15.cpp @@ -0,0 +1 @@ +abc /* def * ghi */ jkl diff --git a/app/preproc/test/data/t15.cpp.out b/app/preproc/test/data/t15.cpp.out new file mode 100644 index 000000000..87bb2bed0 --- /dev/null +++ b/app/preproc/test/data/t15.cpp.out @@ -0,0 +1 @@ +abc jkl diff --git a/app/preproc/test/data/t16.cpp b/app/preproc/test/data/t16.cpp new file mode 100644 index 000000000..e565fc803 --- /dev/null +++ b/app/preproc/test/data/t16.cpp @@ -0,0 +1 @@ +abc /* def * ghi **/ jkl diff --git a/app/preproc/test/data/t16.cpp.out b/app/preproc/test/data/t16.cpp.out new file mode 100644 index 000000000..87bb2bed0 --- /dev/null +++ b/app/preproc/test/data/t16.cpp.out @@ -0,0 +1 @@ +abc jkl diff --git a/app/preproc/test/data/t17.cpp b/app/preproc/test/data/t17.cpp new file mode 100644 index 000000000..bf639dc31 --- /dev/null +++ b/app/preproc/test/data/t17.cpp @@ -0,0 +1 @@ +abc /* def ** ghi **/ jkl diff --git a/app/preproc/test/data/t17.cpp.out b/app/preproc/test/data/t17.cpp.out new file mode 100644 index 000000000..87bb2bed0 --- /dev/null +++ b/app/preproc/test/data/t17.cpp.out @@ -0,0 +1 @@ +abc jkl diff --git a/app/preproc/test/data/t18.cpp b/app/preproc/test/data/t18.cpp new file mode 100644 index 000000000..ba05f1618 --- /dev/null +++ b/app/preproc/test/data/t18.cpp @@ -0,0 +1,3 @@ +abc /* def ** ghi *** +jkl * +* // mno **/ pqr diff --git a/app/preproc/test/data/t18.cpp.out b/app/preproc/test/data/t18.cpp.out new file mode 100644 index 000000000..5c75bd891 --- /dev/null +++ b/app/preproc/test/data/t18.cpp.out @@ -0,0 +1 @@ +abc pqr diff --git a/app/preproc/test/data/t2.cpp b/app/preproc/test/data/t2.cpp new file mode 100644 index 000000000..6083c0fc1 --- /dev/null +++ b/app/preproc/test/data/t2.cpp @@ -0,0 +1,3 @@ +abc // def /* +ghi +jlk // mno */ \ No newline at end of file diff --git a/app/preproc/test/data/t2.cpp.out b/app/preproc/test/data/t2.cpp.out new file mode 100644 index 000000000..1c6c05995 --- /dev/null +++ b/app/preproc/test/data/t2.cpp.out @@ -0,0 +1,3 @@ +abc +ghi +jlk \ No newline at end of file diff --git a/app/preproc/test/data/t3.cpp b/app/preproc/test/data/t3.cpp new file mode 100644 index 000000000..0fca745bb --- /dev/null +++ b/app/preproc/test/data/t3.cpp @@ -0,0 +1,3 @@ +// /* // */ " +asdf +// /* // */ " \ No newline at end of file diff --git a/app/preproc/test/data/t3.cpp.out b/app/preproc/test/data/t3.cpp.out new file mode 100644 index 000000000..4caa2172b --- /dev/null +++ b/app/preproc/test/data/t3.cpp.out @@ -0,0 +1,3 @@ + +asdf + \ No newline at end of file diff --git a/app/preproc/test/data/t4.cpp b/app/preproc/test/data/t4.cpp new file mode 100644 index 000000000..59db82ded --- /dev/null +++ b/app/preproc/test/data/t4.cpp @@ -0,0 +1,7 @@ +/* +abc +/* +def +*/ +ghi +*/ \ No newline at end of file diff --git a/app/preproc/test/data/t4.cpp.out b/app/preproc/test/data/t4.cpp.out new file mode 100644 index 000000000..16ef36566 --- /dev/null +++ b/app/preproc/test/data/t4.cpp.out @@ -0,0 +1,3 @@ + +ghi +*/ \ No newline at end of file diff --git a/app/preproc/test/data/t5.cpp b/app/preproc/test/data/t5.cpp new file mode 100644 index 000000000..85fd0ec2c --- /dev/null +++ b/app/preproc/test/data/t5.cpp @@ -0,0 +1 @@ +abc"def//ghi"jkl \ No newline at end of file diff --git a/app/preproc/test/data/t5.cpp.out b/app/preproc/test/data/t5.cpp.out new file mode 100644 index 000000000..1c1e993b0 --- /dev/null +++ b/app/preproc/test/data/t5.cpp.out @@ -0,0 +1 @@ +abc jkl \ No newline at end of file diff --git a/app/preproc/test/data/t6.cpp b/app/preproc/test/data/t6.cpp new file mode 100644 index 000000000..e65dafb96 --- /dev/null +++ b/app/preproc/test/data/t6.cpp @@ -0,0 +1,3 @@ +abc // def " ghi +jkl +mno // pqr " stu \ No newline at end of file diff --git a/app/preproc/test/data/t6.cpp.out b/app/preproc/test/data/t6.cpp.out new file mode 100644 index 000000000..29f1b4c26 --- /dev/null +++ b/app/preproc/test/data/t6.cpp.out @@ -0,0 +1,3 @@ +abc +jkl +mno \ No newline at end of file diff --git a/app/preproc/test/data/t7.cpp b/app/preproc/test/data/t7.cpp new file mode 100644 index 000000000..bf0a386a6 --- /dev/null +++ b/app/preproc/test/data/t7.cpp @@ -0,0 +1 @@ +abc"def\\"ghi"jkl//" \ No newline at end of file diff --git a/app/preproc/test/data/t7.cpp.out b/app/preproc/test/data/t7.cpp.out new file mode 100644 index 000000000..1bcf7d0d5 --- /dev/null +++ b/app/preproc/test/data/t7.cpp.out @@ -0,0 +1 @@ +abc ghi \ No newline at end of file diff --git a/app/preproc/test/data/t8.cpp b/app/preproc/test/data/t8.cpp new file mode 100644 index 000000000..34c7a17c2 --- /dev/null +++ b/app/preproc/test/data/t8.cpp @@ -0,0 +1 @@ +abc"def\"ghi"jkl \ No newline at end of file diff --git a/app/preproc/test/data/t8.cpp.out b/app/preproc/test/data/t8.cpp.out new file mode 100644 index 000000000..1c1e993b0 --- /dev/null +++ b/app/preproc/test/data/t8.cpp.out @@ -0,0 +1 @@ +abc jkl \ No newline at end of file diff --git a/app/preproc/test/data/t9.cpp b/app/preproc/test/data/t9.cpp new file mode 100644 index 000000000..3b63f08ce --- /dev/null +++ b/app/preproc/test/data/t9.cpp @@ -0,0 +1 @@ +abc"def\\\"ghi"jkl//" \ No newline at end of file diff --git a/app/preproc/test/data/t9.cpp.out b/app/preproc/test/data/t9.cpp.out new file mode 100644 index 000000000..abc43e324 --- /dev/null +++ b/app/preproc/test/data/t9.cpp.out @@ -0,0 +1 @@ +abc jkl \ No newline at end of file diff --git a/app/preproc/test/test.sh b/app/preproc/test/test.sh new file mode 100755 index 000000000..d50ecad0b --- /dev/null +++ b/app/preproc/test/test.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +javac -classpath ../../../build/shared/lib/oro.jar test_PdePreprocessor.java +for i in data/t*.cpp; do echo $i; java -classpath ../../../build/shared/lib/oro.jar:. test_PdePreprocessor strip $i | diff - $i.out; done +for i in data/foo*.cpp; do echo $i; java -classpath ../../../build/shared/lib/oro.jar:. test_PdePreprocessor prototypes $i | diff - $i.out; done diff --git a/app/preproc/test/test_PdePreprocessor.java b/app/preproc/test/test_PdePreprocessor.java new file mode 100644 index 000000000..38bd9145d --- /dev/null +++ b/app/preproc/test/test_PdePreprocessor.java @@ -0,0 +1,44 @@ +import java.io.Reader; +import java.io.File; +import java.io.FileReader; + +import java.util.List; +import java.util.ArrayList; + +import com.oroinc.text.regex.*; + +public class test_PdePreprocessor { + /************************************************************************ + Paste from PdePreprocessor.java: strip(), collapseBraces(), prototypes() + ************************************************************************/ + + public static void main(String[] args) { + if (args.length < 2) { + System.err.println("Usage: PreProc [strip|prototypes] "); + return; + } + + try { + test_PdePreprocessor preproc = new test_PdePreprocessor(); + Reader reader = new FileReader(new File(args[1])); + StringBuffer buffer = new StringBuffer(); + char[] buf = new char[1024]; + int n; + + while ((n = reader.read(buf, 0, 1024)) != -1) { + buffer.append(buf, 0, n); + } + + if (args[0].equals("strip")) { + System.out.print(preproc.strip(buffer.toString())); + } else { + List prototypes = preproc.prototypes(buffer.toString()); + for (int i = 0; i < prototypes.size(); i++) { + System.out.println((String) prototypes.get(i)); + } + } + } catch (Exception e) { + System.err.println(e); + } + } +} \ No newline at end of file