From 1c06bc88ba6f7c5882d726207fa6e05e734cb1bd Mon Sep 17 00:00:00 2001 From: Peizhao Ou Date: Wed, 17 Feb 2016 16:43:11 -0800 Subject: [PATCH] clean code --- benchmark/chase-lev-deque-bugfix/deque.c | 4 + benchmark/chase-lev-deque-bugfix/deque.h | 3 +- grammer/README.txt | 7 - grammer/backup-spec-compiler.jj | 800 ----------- grammer/pre_scanner.jj | 52 - grammer/spec.txt | 55 - grammer/spec_compiler.jj | 1280 ----------------- grammer/util.jj | 76 +- notes/nondeterm-spec.txt | 7 + output/Makefile | 19 - output/benchmarks.mk | 33 - output/chase-lev-deque-bugfix/Makefile | 17 - output/chase-lev-deque-bugfix/deque.c | 271 ---- output/chase-lev-deque-bugfix/deque.h | 233 --- output/chase-lev-deque-bugfix/deque.o | Bin 26688 -> 0 bytes output/chase-lev-deque-bugfix/main | Bin 32996 -> 0 bytes output/chase-lev-deque-bugfix/main.c | 55 - output/chase-lev-deque-bugfix/testcase.c | 62 - output/chase-lev-deque-bugfix/testcase1 | Bin 33067 -> 0 bytes output/chase-lev-deque-bugfix/testcase1.c | 63 - output/chase-lev-deque-bugfix/testcase2 | Bin 33059 -> 0 bytes output/chase-lev-deque-bugfix/testcase2.c | 60 - output/cliffc-hashtable/cliffc_hashtable.h | 911 ------------ output/cliffc-hashtable/main.cc | 111 -- .../concurrent-hashmap/ConcurrentHashMap.java | 1224 ---------------- output/concurrent-hashmap/Makefile | 15 - output/concurrent-hashmap/hashmap.h | 471 ------ output/concurrent-hashmap/hashmap.o | Bin 16269712 -> 0 bytes output/concurrent-hashmap/main | Bin 55046 -> 0 bytes output/concurrent-hashmap/main.cc | 35 - output/concurrent-hashmap/note.txt | 17 - output/concurrent-hashmap/testcase1 | Bin 55075 -> 0 bytes output/concurrent-hashmap/testcase1.cc | 37 - output/include/unrelacy.h | 96 -- output/linuxrwlocks/Makefile | 11 - output/linuxrwlocks/linuxrwlocks | Bin 40367 -> 0 bytes output/linuxrwlocks/linuxrwlocks.c | 940 ------------ output/linuxrwlocks/testcase1 | Bin 40348 -> 0 bytes output/linuxrwlocks/testcase1.c | 926 ------------ output/linuxrwlocks/testcase2 | Bin 40356 -> 0 bytes output/linuxrwlocks/testcase2.c | 930 ------------ output/mcs-lock/Makefile | 11 - output/mcs-lock/mcs-lock | Bin 70106 -> 0 bytes output/mcs-lock/mcs-lock.cc | 40 - output/mcs-lock/mcs-lock.h | 332 ----- output/mpmc-queue/Makefile | 11 - output/mpmc-queue/mpmc-queue.cc | 141 -- output/mpmc-queue/mpmc-queue.h | 700 --------- output/mpmc-queue/testcase | Bin 78653 -> 0 bytes output/mpmc-queue/testcase.cc | 65 - output/mpmc-queue/testcase1 | Bin 78694 -> 0 bytes output/mpmc-queue/testcase1.cc | 65 - output/mpmc-queue/testcase2 | Bin 78894 -> 0 bytes output/mpmc-queue/testcase2.cc | 91 -- output/mpmc-queue/testcase3 | Bin 79260 -> 0 bytes output/mpmc-queue/testcase3.cc | 105 -- output/ms-queue/Makefile | 26 - output/ms-queue/main | Bin 37336 -> 0 bytes output/ms-queue/main.c | 88 -- output/ms-queue/main.o | Bin 20512 -> 0 bytes output/ms-queue/my_queue.c | 333 ----- output/ms-queue/my_queue.h | 204 --- output/ms-queue/my_queue.o | Bin 27080 -> 0 bytes output/ms-queue/testcase1 | Bin 33327 -> 0 bytes output/ms-queue/testcase1.c | 75 - output/ms-queue/testcase1.o | Bin 19592 -> 0 bytes output/ms-queue/testcase2 | Bin 33367 -> 0 bytes output/ms-queue/testcase2.c | 77 - output/ms-queue/testcase2.o | Bin 19808 -> 0 bytes output/ms-queue/testcase3 | Bin 37471 -> 0 bytes output/ms-queue/testcase3.c | 84 -- output/ms-queue/testcase3.o | Bin 20240 -> 0 bytes output/read-copy-update/Makefile | 9 - output/read-copy-update/rcu | Bin 60218 -> 0 bytes output/read-copy-update/rcu.cc | 352 ----- output/run.sh | 29 - output/seqlock/Makefile | 9 - output/spsc-bugfix/Makefile | 23 - output/spsc-bugfix/eventcount.h | 74 - output/spsc-bugfix/queue.h | 340 ----- output/spsc-bugfix/spsc-queue | Bin 78257 -> 0 bytes output/spsc-bugfix/spsc-queue.cc | 34 - run-javacc.sh | 20 +- setup-env.sh | 7 - .../uci/eecs/codeGenerator/CodeAdditions.java | 87 ++ .../uci/eecs/codeGenerator/CodeGenerator.java | 315 ++++ .../codeGenerator/CodeGeneratorUtils.java | 1174 +++++++++++++++ .../uci/eecs/codeGenerator/Environment.java | 27 + .../codeGenerator/CodeAddition.java | 28 - .../codeGenerator/CodeGenerator.java | 362 ----- .../codeGenerator/CodeVariables.java | 1074 -------------- .../codeGenerator/Environment.java | 14 - .../InterfaceWrongFormatException.java | 7 - .../codeGenerator/ProgramUnit.java | 30 - .../codeGenerator/SemanticsChecker.java | 362 ----- .../SemanticsCheckerException.java | 7 - .../specExtraction/CPClearConstruct.java | 23 - .../CPDefineCheckConstruct.java | 34 - .../specExtraction/CPDefineConstruct.java | 38 - .../specExtraction/ClassBeginConstruct.java | 13 - .../specExtraction/ClassEndConstruct.java | 13 - .../specExtraction/ConditionalInterface.java | 31 - .../specExtraction/Construct.java | 21 - .../specExtraction/EntryPointConstruct.java | 13 - .../specExtraction/GlobalConstruct.java | 103 -- .../specExtraction/IDExtractor.java | 120 -- .../specExtraction/InterfaceConstruct.java | 59 - .../InterfaceDefineConstruct.java | 16 - .../specExtraction/ParserUtils.java | 92 -- .../PotentialCPDefineConstruct.java | 34 - .../SequentialDefineSubConstruct.java | 41 - .../specExtraction/SourceFileInfo.java | 31 - .../specExtraction/SpecExtractor.java | 76 - .../specExtraction/SpecInfoScanner.java | 67 - .../specExtraction/VariableDeclaration.java | 15 - src/edu/uci/eecs/specExtraction/Code.java | 197 +++ .../specExtraction/CommutativityRule.java | 9 +- .../uci/eecs/specExtraction/Construct.java | 28 + .../eecs/specExtraction/EntryConstruct.java | 30 + .../specExtraction/FunctionHeader.java | 104 +- .../eecs/specExtraction/GlobalConstruct.java | 230 +++ .../specExtraction/InterfaceConstruct.java | 202 +++ .../uci/eecs/specExtraction/OPConstruct.java | 51 + src/edu/uci/eecs/specExtraction/OPType.java | 13 + .../specExtraction/QualifiedName.java | 24 +- .../eecs/specExtraction/SpecExtractor.java | 617 ++++++++ .../uci/eecs/specExtraction/SpecNaming.java | 190 +++ .../uci/eecs/specExtraction/SpecUtils.java | 231 +++ .../specExtraction/VariableDeclaration.java | 44 + .../WrongAnnotationException.java | 66 + 130 files changed, 3672 insertions(+), 14857 deletions(-) delete mode 100644 grammer/README.txt delete mode 100644 grammer/backup-spec-compiler.jj delete mode 100644 grammer/pre_scanner.jj delete mode 100644 grammer/spec.txt delete mode 100644 grammer/spec_compiler.jj delete mode 100644 output/Makefile delete mode 100644 output/benchmarks.mk delete mode 100644 output/chase-lev-deque-bugfix/Makefile delete mode 100644 output/chase-lev-deque-bugfix/deque.c delete mode 100644 output/chase-lev-deque-bugfix/deque.h delete mode 100644 output/chase-lev-deque-bugfix/deque.o delete mode 100755 output/chase-lev-deque-bugfix/main delete mode 100644 output/chase-lev-deque-bugfix/main.c delete mode 100644 output/chase-lev-deque-bugfix/testcase.c delete mode 100755 output/chase-lev-deque-bugfix/testcase1 delete mode 100644 output/chase-lev-deque-bugfix/testcase1.c delete mode 100755 output/chase-lev-deque-bugfix/testcase2 delete mode 100644 output/chase-lev-deque-bugfix/testcase2.c delete mode 100644 output/cliffc-hashtable/cliffc_hashtable.h delete mode 100644 output/cliffc-hashtable/main.cc delete mode 100644 output/concurrent-hashmap/ConcurrentHashMap.java delete mode 100644 output/concurrent-hashmap/Makefile delete mode 100644 output/concurrent-hashmap/hashmap.h delete mode 100644 output/concurrent-hashmap/hashmap.o delete mode 100755 output/concurrent-hashmap/main delete mode 100644 output/concurrent-hashmap/main.cc delete mode 100644 output/concurrent-hashmap/note.txt delete mode 100755 output/concurrent-hashmap/testcase1 delete mode 100644 output/concurrent-hashmap/testcase1.cc delete mode 100644 output/include/unrelacy.h delete mode 100644 output/linuxrwlocks/Makefile delete mode 100755 output/linuxrwlocks/linuxrwlocks delete mode 100644 output/linuxrwlocks/linuxrwlocks.c delete mode 100755 output/linuxrwlocks/testcase1 delete mode 100644 output/linuxrwlocks/testcase1.c delete mode 100755 output/linuxrwlocks/testcase2 delete mode 100644 output/linuxrwlocks/testcase2.c delete mode 100644 output/mcs-lock/Makefile delete mode 100755 output/mcs-lock/mcs-lock delete mode 100644 output/mcs-lock/mcs-lock.cc delete mode 100644 output/mcs-lock/mcs-lock.h delete mode 100644 output/mpmc-queue/Makefile delete mode 100644 output/mpmc-queue/mpmc-queue.cc delete mode 100644 output/mpmc-queue/mpmc-queue.h delete mode 100755 output/mpmc-queue/testcase delete mode 100644 output/mpmc-queue/testcase.cc delete mode 100755 output/mpmc-queue/testcase1 delete mode 100644 output/mpmc-queue/testcase1.cc delete mode 100755 output/mpmc-queue/testcase2 delete mode 100644 output/mpmc-queue/testcase2.cc delete mode 100755 output/mpmc-queue/testcase3 delete mode 100644 output/mpmc-queue/testcase3.cc delete mode 100644 output/ms-queue/Makefile delete mode 100755 output/ms-queue/main delete mode 100644 output/ms-queue/main.c delete mode 100644 output/ms-queue/main.o delete mode 100644 output/ms-queue/my_queue.c delete mode 100644 output/ms-queue/my_queue.h delete mode 100644 output/ms-queue/my_queue.o delete mode 100755 output/ms-queue/testcase1 delete mode 100644 output/ms-queue/testcase1.c delete mode 100644 output/ms-queue/testcase1.o delete mode 100755 output/ms-queue/testcase2 delete mode 100644 output/ms-queue/testcase2.c delete mode 100644 output/ms-queue/testcase2.o delete mode 100755 output/ms-queue/testcase3 delete mode 100644 output/ms-queue/testcase3.c delete mode 100644 output/ms-queue/testcase3.o delete mode 100644 output/read-copy-update/Makefile delete mode 100755 output/read-copy-update/rcu delete mode 100644 output/read-copy-update/rcu.cc delete mode 100755 output/run.sh delete mode 100644 output/seqlock/Makefile delete mode 100644 output/spsc-bugfix/Makefile delete mode 100644 output/spsc-bugfix/eventcount.h delete mode 100644 output/spsc-bugfix/queue.h delete mode 100755 output/spsc-bugfix/spsc-queue delete mode 100644 output/spsc-bugfix/spsc-queue.cc delete mode 100644 setup-env.sh create mode 100644 src/edu/uci/eecs/codeGenerator/CodeAdditions.java create mode 100644 src/edu/uci/eecs/codeGenerator/CodeGenerator.java create mode 100644 src/edu/uci/eecs/codeGenerator/CodeGeneratorUtils.java create mode 100644 src/edu/uci/eecs/codeGenerator/Environment.java delete mode 100644 src/edu/uci/eecs/specCompiler/codeGenerator/CodeAddition.java delete mode 100644 src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java delete mode 100644 src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java delete mode 100644 src/edu/uci/eecs/specCompiler/codeGenerator/Environment.java delete mode 100644 src/edu/uci/eecs/specCompiler/codeGenerator/InterfaceWrongFormatException.java delete mode 100644 src/edu/uci/eecs/specCompiler/codeGenerator/ProgramUnit.java delete mode 100644 src/edu/uci/eecs/specCompiler/codeGenerator/SemanticsChecker.java delete mode 100644 src/edu/uci/eecs/specCompiler/codeGenerator/SemanticsCheckerException.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/CPClearConstruct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/CPDefineCheckConstruct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/CPDefineConstruct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/ClassBeginConstruct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/ClassEndConstruct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/ConditionalInterface.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/Construct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/EntryPointConstruct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/GlobalConstruct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/IDExtractor.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/InterfaceConstruct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/InterfaceDefineConstruct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/ParserUtils.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/PotentialCPDefineConstruct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/SequentialDefineSubConstruct.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/SourceFileInfo.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/SpecExtractor.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/SpecInfoScanner.java delete mode 100644 src/edu/uci/eecs/specCompiler/specExtraction/VariableDeclaration.java create mode 100644 src/edu/uci/eecs/specExtraction/Code.java rename src/edu/uci/eecs/{specCompiler => }/specExtraction/CommutativityRule.java (58%) create mode 100644 src/edu/uci/eecs/specExtraction/Construct.java create mode 100644 src/edu/uci/eecs/specExtraction/EntryConstruct.java rename src/edu/uci/eecs/{specCompiler => }/specExtraction/FunctionHeader.java (52%) create mode 100644 src/edu/uci/eecs/specExtraction/GlobalConstruct.java create mode 100644 src/edu/uci/eecs/specExtraction/InterfaceConstruct.java create mode 100644 src/edu/uci/eecs/specExtraction/OPConstruct.java create mode 100644 src/edu/uci/eecs/specExtraction/OPType.java rename src/edu/uci/eecs/{specCompiler => }/specExtraction/QualifiedName.java (59%) create mode 100644 src/edu/uci/eecs/specExtraction/SpecExtractor.java create mode 100644 src/edu/uci/eecs/specExtraction/SpecNaming.java create mode 100644 src/edu/uci/eecs/specExtraction/SpecUtils.java create mode 100644 src/edu/uci/eecs/specExtraction/VariableDeclaration.java create mode 100644 src/edu/uci/eecs/specExtraction/WrongAnnotationException.java diff --git a/benchmark/chase-lev-deque-bugfix/deque.c b/benchmark/chase-lev-deque-bugfix/deque.c index bb12be0..9c6625e 100644 --- a/benchmark/chase-lev-deque-bugfix/deque.c +++ b/benchmark/chase-lev-deque-bugfix/deque.c @@ -4,6 +4,10 @@ #include #include +inline bool fail(int ret) { + return ret == ABORT || ret == EMPTY; +} + Deque * create() { Deque * q = (Deque *) calloc(1, sizeof(Deque)); Array * a = (Array *) calloc(1, sizeof(Array)+2*sizeof(atomic_int)); diff --git a/benchmark/chase-lev-deque-bugfix/deque.h b/benchmark/chase-lev-deque-bugfix/deque.h index 9292e16..4d1f34e 100644 --- a/benchmark/chase-lev-deque-bugfix/deque.h +++ b/benchmark/chase-lev-deque-bugfix/deque.h @@ -21,6 +21,7 @@ typedef struct { #define EMPTY 0xffffffff #define ABORT 0xfffffffe +inline bool fail(int ret); /** @Begin @Options: @@ -42,7 +43,7 @@ typedef struct { Push -> Steal @Commutativity: Push <-> Steal: true @Commutativity: Take <-> Steal: true - @Commutativity: Steal <-> Steal: _Method1.__RET__ == ABORT || _Method2.__RET__ == ABORT + @Commutativity: Steal <-> Steal: fail(_Method1.__RET__) || fail(_Method2.__RET__) @End */ diff --git a/grammer/README.txt b/grammer/README.txt deleted file mode 100644 index 0d25b20..0000000 --- a/grammer/README.txt +++ /dev/null @@ -1,7 +0,0 @@ -"preScanner.jj" is used to process the backslash sign at the end of a line -(basically splice broken lines before really processing the specifications). - -"util.jj" is used to process some specific strings, such as the declaration of a -function with templated types. It is designed to be used as a library funcions. - -"spec_compiler.jj" is the file to parse the extracted specifications. diff --git a/grammer/backup-spec-compiler.jj b/grammer/backup-spec-compiler.jj deleted file mode 100644 index e65f339..0000000 --- a/grammer/backup-spec-compiler.jj +++ /dev/null @@ -1,800 +0,0 @@ -/* spec-compiler.jj Grammer definition for the specification */ - - -/* - SPEC constructs: - Each construct should be embraced by /DOUBLE_STAR ... STAR/ annotation. - Within there, any line beginning with a "#" is a comment of the annotation. - Each constrcut should begin with @Begin and end with @End. Otherwise, the - annotation would be considered as normal comments of the source. - - a) Global construct - @Begin - @Options: - # If LANG is not define, it's C++ by default. C does not support class - # and template, so if it's defined as C, we should also have a explicit - # entry point. - LANG = C; - @Global_define: - @DeclareVar: - @InitVar: - @DefineFunc: - ... - @Interface_cluster: - ... - @Happens-before: - ... - @End - - b) Interface construct - @Begin - @Interface: ... - @Commit_point_set: - IDENTIFIER | IDENTIFIER ... - @Condition: ... (Optional) - @HB_Condition: - IDENTIFIER :: - @HB_Condition: ... - @ID: ... (Optional, use default ID) - @Check: (Optional) - ... - @Action: (Optional) - # Type here must be a pointer - @DefineVar: Type var1 = SomeExpression (Optional) - @Code (Optional) - ... - @Post_action: (Optional) - @Post_check: (Optional) - @End - - c) Potential commit construct - @Begin - @Potential_commit_point_define: ... - @Label: ... - @End - - d) Commit point define construct - @Begin - @Commit_point_define_check: ... - @Label: ... - @End - - OR - - @Begin - @Commit_point_define: ... - @Potential_commit_point_label: ... - @Label: ... - @End - - e) Entry point construct - @Begin - @Entry_point - @End - - f) Interface define construct - @Begin - @Interface_define: - @End -*/ - - - -options { - STATIC = false; - JAVA_UNICODE_ESCAPE = true; -} - -PARSER_BEGIN(SpecParser) -package edu.uci.eecs.specCompiler.grammerParser; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; - -import edu.uci.eecs.specCompiler.specExtraction.Construct; -import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct; -import edu.uci.eecs.specCompiler.specExtraction.InterfaceConstruct; -import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct; -import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct; -import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct; -import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface; -import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct; -import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct.DefineVar; -import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct; -import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct; -import edu.uci.eecs.specCompiler.specExtraction.EntryPointConstruct; - - public class SpecParser { - public static void main(String[] argvs) - throws ParseException, TokenMgrError { - try { - FileInputStream fis = new FileInputStream("./grammer/spec.txt"); - SpecParser parser = new SpecParser(fis); - //parser.Parse(); - System.out.println("Parsing finished!"); - ArrayList typeParams = parser.FormalParamList(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - - public static Construct parseSpec(String text) - throws ParseException, TokenMgrError { - InputStream input = new ByteArrayInputStream(text.getBytes()); - SpecParser parser = new SpecParser(input); - return parser.Parse(); - } - - - } -PARSER_END(SpecParser) - - "/*"} - -< IN_COMMENT > SKIP : { < ~[] > } - -< IN_COMMENT > SKIP : { - "*/": DEFAULT -} - - TOKEN : { - | - -} - -SKIP : -{ - " " -| - "\n" -| - "\r" -| - "\r\n" -| - "\t" -| - // "#" comment for the specification - <"#" (~["\n", "\r"])* (["\n", "\r"])> -| - // "//" comment for the specification - <"//" (~["\n", "\r"])* (["\n", "\r"])> -} - - TOKEN : -{ -/* Above are specification-only tokens */ - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - - - -/* Specification & C/C++ shared tokens */ - -// Reserved keywords -| - -| - -| - - - -| - <#DIGIT: ["0"-"9"]> -| - <#LETTER: ["a"-"z", "A"-"Z"]> -| - | "_") ( | | "_")*> -| - -| - -| - -| - -| - "> -| - - -| -/* C/C++ only token*/ - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - "> -| - ="> -| - -| - -| - -| - -| - -| - -| - -| - -| - -| - < INTEGER_LITERAL: - (["l","L"])? - | (["l","L"])? - | (["l","L"])?> -| - < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > -| - < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > -| - < #OCTAL_LITERAL: "0" (["0"-"7"])* > -| - < FLOATING_POINT_LITERAL: - - | > -| - < #DECIMAL_FLOATING_POINT_LITERAL: - (["0"-"9"])+ "." (["0"-"9"])* ()? (["f","F","d","D"])? - | "." (["0"-"9"])+ ()? (["f","F","d","D"])? - | (["0"-"9"])+ (["f","F","d","D"])? - | (["0"-"9"])+ ()? ["f","F","d","D"]> -| - < #DECIMAL_EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > -| - < #HEXADECIMAL_FLOATING_POINT_LITERAL: - "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])+ (".")? (["f","F","d","D"])? - | "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])* "." (["0"-"9","a"-"f","A"-"F"])+ (["f","F","d","D"])?> -| - < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ > -} - -String Type() : -{ - String type; - String str; -} -{ - { type = ""; } - ("const" - { type = "const"; } - )? - (("struct" { type = type + " struct"; })? - (str = .image { - if (!type.equals("")) - type = type + " " + str; - else - type = str; - })) - ((str = "const".image { - if (!type.equals("")) - type = type + " " + str; - else - type = str; - }) | - (str = .image { - if (!type.equals("")) - type = type + " " + str; - else - type = str; - }) | - (str = .image { - if (!type.equals("")) - type = type + " " + str; - else - type = str; - }) - )* - { - return type; - } -} - -ArrayList FormalParamList() : -{ - ArrayList typeParams; -} -{ - { - typeParams = new ArrayList(); - } - (TypeParam(typeParams) ( TypeParam(typeParams))*)? - { - System.out.println(typeParams); - return typeParams; - } -} - -void TypeParam(ArrayList typeParams) : -{ - String type, param; -} -{ - (type = Type()) (param = .image) - { - typeParams.add(type); - typeParams.add(param); - } -} - -Construct Parse() : -{ - Construct res; -} -{ - ( - LOOKAHEAD(3) res = Global_construct() | - LOOKAHEAD(3) res = Interface() | - LOOKAHEAD(3) res = Potential_commit_point_define() | - LOOKAHEAD(3) res = Commit_point_define() | - LOOKAHEAD(3) res = Commit_point_define_check() | - LOOKAHEAD(3) res = Entry_point() | - LOOKAHEAD(3) res = Interface_define() - ) - - { - //System.out.println(res); - return res; - } -} - -GlobalConstruct Global_construct() : -{ - GlobalConstruct res; - SequentialDefineSubConstruct code; - HashMap options; - String key, value; -} -{ - { - res = null; - options = new HashMap(); - } - - - ( - ((key = .image) - - (value = .image) - { - if (options.containsKey(key)) { - throw new ParseException("Duplicate options!"); - } - options.put(key, value); - } - - )* - )? - (code = Global_define()) - { res = new GlobalConstruct(code, options); } - (Interface_clusters(res))? - (Happens_before(res))? - - - { - res.unfoldInterfaceCluster(); - return res; - } -} - -String C_CPP_CODE() : -{ - StringBuilder text; - Token t; -} -{ - { - text = new StringBuilder(); - t = new Token(); - } - ( - //LOOKAHEAD(2) - ( - t = | t = | - t = | t = | t = | t = | - t = | t = | t = | t = | - t = | t = | t = | t = | t = | t = | t = | t = | - t = | t = | t = | t = | t = | - t = | t = | t = | t = | - t = | t = | t = | t = | t = | - t = | t = | t = | - t = | t = | t = | - t = | t = - ) - { - text.append(t.image); - if (t.image.equals(";") || t.image.equals("\\") - || t.image.equals("{") || t.image.equals("}")) - text.append("\n"); - else - text.append(" "); - } - )+ - { - //System.out.println(text); - return text.toString(); - } -} - -SequentialDefineSubConstruct Global_define() : -{ - String declareVar, initVar, defineFunc; -} -{ - { - declareVar = ""; - initVar = ""; - defineFunc = ""; - } - - ( (declareVar = C_CPP_CODE()))? - ( (initVar = C_CPP_CODE()))? - ( (defineFunc = C_CPP_CODE()))? - { - SequentialDefineSubConstruct res = new SequentialDefineSubConstruct(declareVar, initVar, defineFunc); - //System.out.println(res); - return res; - } -} - -ConditionalInterface Conditional_interface() : -{ - String interfaceName, hbConditionLabel; -} -{ - { - hbConditionLabel = ""; - } - interfaceName = .image ( hbConditionLabel = - .image )? - { - return new ConditionalInterface(interfaceName, hbConditionLabel); - } -} - -void Interface_cluster(GlobalConstruct inst) : -{ - String clusterName; - ConditionalInterface condInterface; -} -{ - (clusterName= .image) - - (condInterface = Conditional_interface() - { inst.addInterface2Cluster(clusterName, condInterface); } - ) - ( condInterface = Conditional_interface() - { inst.addInterface2Cluster(clusterName, condInterface); } - )* - -} - -void Interface_clusters(GlobalConstruct inst) : -{} -{ - (Interface_cluster(inst))+ -} - -void Happens_before(GlobalConstruct inst) : -{ - ConditionalInterface left, right; -} -{ - - ( - left = Conditional_interface() right = Conditional_interface() - { inst.addHBCondition(left, right); } - )+ -} - -InterfaceConstruct Interface() : -{ - InterfaceConstruct res; - String interfaceName, condition, idCode, check, postAction, - postCheck, commitPoint, hbLabel, hbCondition; - ActionSubConstruct action; - ArrayList commitPointSet; - HashMap hbConditions; -} -{ - { - res = null; - action = null; - condition = ""; - idCode = ""; - check = ""; - postAction = ""; - postCheck = ""; - commitPointSet = new ArrayList(); - hbConditions = new HashMap(); - } - - - (interfaceName = .image) - - (commitPoint = .image - { commitPointSet.add(commitPoint); } - ) - ( - (commitPoint = .image) - { - if (commitPointSet.contains(commitPoint)) { - throw new ParseException(interfaceName + " has" + - "duplicate commit point labels"); - } - commitPointSet.add(commitPoint); - } - )* - - ( (condition = C_CPP_CODE()))? - ( - - (hbLabel = .image) - (hbCondition = C_CPP_CODE()) - { - if (hbConditions.containsKey(hbLabel)) { - throw new ParseException(interfaceName + " has" + - "duplicate happens-before condtion labels"); - } - hbConditions.put(hbLabel, hbCondition); - } - )* - ( (idCode = C_CPP_CODE()))? - ( (check = C_CPP_CODE()))? - (action = Action())? - ( (postAction = C_CPP_CODE()))? - ( (postCheck = C_CPP_CODE()))? - - - { - res = new InterfaceConstruct(interfaceName, commitPointSet, condition, - hbConditions, idCode, check, action, postAction, postCheck); - return res; - } -} - -ActionSubConstruct Action() : -{ - String type, name, expr, defineVarStr, code; - ArrayList defineVars; -} -{ - { - defineVars = new ArrayList(); - code = ""; - } - - ( - ( - ( (defineVarStr = C_CPP_CODE()) - { - int eqIdx = defineVarStr.indexOf('='); - int typeEnd = defineVarStr.lastIndexOf(' ', eqIdx - 2); - type = defineVarStr.substring(0, typeEnd); - name = defineVarStr.substring(typeEnd + 1, eqIdx - 1); - expr = defineVarStr.substring(eqIdx + 2); - DefineVar defineVar = new DefineVar(type, name, expr); - defineVars.add(defineVar); - })* ( (code = C_CPP_CODE()))? ) - ) - - { - ActionSubConstruct res = new ActionSubConstruct(defineVars, code); - return res; - } -} - -PotentialCPDefineConstruct Potential_commit_point_define() : -{ - PotentialCPDefineConstruct res; - String label, condition; -} -{ - - { res = null; } - - - (condition = C_CPP_CODE()) -