lots of changes
authorPeizhao Ou <peizhaoo@uci.edu>
Wed, 23 Oct 2013 11:09:23 +0000 (04:09 -0700)
committerPeizhao Ou <peizhaoo@uci.edu>
Wed, 23 Oct 2013 11:09:23 +0000 (04:09 -0700)
22 files changed:
grammer/pre_scanner.jj [new file with mode: 0644]
grammer/spec-compiler.jj [deleted file]
grammer/spec.txt
grammer/spec_compiler.jj [new file with mode: 0644]
run-javacc.sh
src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java
src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java
src/edu/uci/eecs/specCompiler/codeGenerator/SemanticsChecker.java
src/edu/uci/eecs/specCompiler/specExtraction/CPDefineCheckConstruct.java
src/edu/uci/eecs/specCompiler/specExtraction/CPDefineConstruct.java
src/edu/uci/eecs/specCompiler/specExtraction/Construct.java
src/edu/uci/eecs/specCompiler/specExtraction/EntryPointConstruct.java
src/edu/uci/eecs/specCompiler/specExtraction/GlobalConstruct.java
src/edu/uci/eecs/specCompiler/specExtraction/InterfaceConstruct.java
src/edu/uci/eecs/specCompiler/specExtraction/InterfaceDefineConstruct.java
src/edu/uci/eecs/specCompiler/specExtraction/PotentialCPDefineConstruct.java
src/edu/uci/eecs/specCompiler/specExtraction/SpecConstruct.java [deleted file]
src/edu/uci/eecs/specCompiler/specExtraction/SpecConstructInfo.java [deleted file]
src/edu/uci/eecs/specCompiler/specExtraction/SpecExtractor.java
src/edu/uci/eecs/specCompiler/specExtraction/SpecNotMatchException.java [deleted file]
test.c [deleted file]
test.cc [new file with mode: 0644]

diff --git a/grammer/pre_scanner.jj b/grammer/pre_scanner.jj
new file mode 100644 (file)
index 0000000..301ae88
--- /dev/null
@@ -0,0 +1,52 @@
+/* pre_scan.jj Process the backslash at the end of line */
+
+options {
+       STATIC = false;
+       JAVA_UNICODE_ESCAPE = true;
+}
+
+PARSER_BEGIN(PreScanner)
+package edu.uci.eecs.specCompiler.grammerParser.preScanner;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+
+       public class PreScanner {
+               public static void main(String[] argvs)
+               throws ParseException, TokenMgrError {
+                       try {
+                               FileInputStream fis = new FileInputStream("./grammer/spec.txt");
+                               PreScanner preScanner = new PreScanner(fis);
+                               String code = preScanner.ProcessEndBackslash();
+                               System.out.println(code);
+                               System.out.println("Finished!");
+                       } catch (FileNotFoundException e) {
+                               e.printStackTrace();
+                       }
+               }
+       }
+PARSER_END(PreScanner)
+
+SKIP : {
+       <"\\\n">
+}
+
+TOKEN : {
+       <ANY: ~[]>
+}
+
+String ProcessEndBackslash() :
+{
+       StringBuilder sb;
+       String str;
+}
+{
+       { sb = new StringBuilder(); }
+       (str = <ANY>.image { sb.append(str); } )* <EOF>
+       {
+               return sb.toString();
+       }
+}
diff --git a/grammer/spec-compiler.jj b/grammer/spec-compiler.jj
deleted file mode 100644 (file)
index c048141..0000000
+++ /dev/null
@@ -1,490 +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 :: <C_CPP_Condition>
-       @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: <Interface_Name>
-       @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.ParseSpec();
-                               System.out.println("Parsing finished!");
-                       } 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, IN_SPEC > SKIP : {
-       "*/": DEFAULT
-}
-
-SKIP : {
-       "/*": IN_COMMENT
-}
-
-SKIP : {
-       "/**": IN_SPEC
-}
-
-<IN_SPEC> TOKEN : {
-       <BEGIN: "@Begin">
-|
-       <END: "@End">
-|
-       <OPTIONS: "@Options:">
-|
-       <GLOBAL_DEFINE: "@Global_define:">
-|
-       <DECLARE_VAR: "@DeclareVar:">
-|
-       <INIT_VAR: "@InitVar:">
-|
-       <DEFINE_FUNC: "@DefineFunc:">
-|
-       <INTERFACE_CLUSTER: "@Interface_cluster:">
-|
-       <HAPPENS_BEFORE: "@Happens_before:">
-|
-       <INTERFACE: "@Interface:">
-|
-       <COMMIT_POINT_SET: "@Commit_point_set:">
-|
-       <ENTRY_POINT: "@Entry_point">
-|
-       <INTERFACE_DEFINE: "@Interface_define:">
-|
-       <CONDITION: "@Condition:">
-|
-       <HB_CONDITION: "@HB_condition:">
-|
-       <ID: "@ID:">
-|
-       <CHECK: "@Check:">
-|
-       <ACTION: "@Action:">
-|
-       <DEFINEVAR: "@DefineVar:">
-|
-       <CODE: "@Code:">
-|
-       <POST_ACTION: "@Post_action:">
-|
-       <POST_CHECK: "@Post_check:">
-|
-       <POTENTIAL_COMMIT_POINT_DEFINE: "@Potential_commit_point_define:">
-|
-       <LABEL: "@Label:">
-|
-       <COMMIT_POINT_DEFINE_CHECK: "@Commit_point_define_check:">
-|
-       <COMMIT_POINT_DEFINE: "@Commit_point_define:">
-|
-       <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
-}
-
-SKIP :
-{
-       " "
-|
-       "\n"
-|
-       "\r"
-|
-       "\r\n"
-|
-       "\t"
-|
-       // "#" comment for the specification
-       <"#" (~["\n", "\r"])* (["\n", "\r"])>
-|
-       // "//" comment for the specification
-       <"//" (~["\n", "\r"])* (["\n", "\r"])>
-}
-
-<IN_SPEC, DEFAULT> TOKEN :
-{
-/*   Specification & C/C++ shared tokens   */
-// Reserved keywords
-       <CONST: "const">
-|
-       <STRUCT: "struct">
-|
-       <TYPENAME: "typename">
-|
-       <#DIGIT: ["0"-"9"]>
-|
-       <#LETTER: ["a"-"z", "A"-"Z"]>
-|
-       <IDENTIFIER: (<LETTER> | "_") (<LETTER> | <DIGIT> | "_")*>
-|
-       <EQUALS: "=">
-|
-       <OPEN_PAREN: "{">
-|
-       <CLOSE_PAREN: "}">
-|
-       <OPEN_BRACKET: "(">
-|
-       <CLOSE_BRACKET: ")">
-|
-       <HB_SYMBOL: "->">
-|
-       <COMMA: ",">
-
-|
-/*   C/C++ only token*/
-       <DOT: ".">
-|
-       <STAR: "*">
-|
-       <NEGATE: "~">
-|
-       <EXCLAMATION: "!">
-|
-       <AND: "&">
-|
-       <OR: "|">
-|
-       <MOD: "%">
-|
-       <PLUS: "+">
-|
-       <PLUSPLUS: "++">
-|
-       <MINUS: "-">
-|
-       <MINUSMINUS: "--">
-|
-       <DIVIDE: "/">
-|
-       <BACKSLASH: "\\">
-|
-       <LESS_THAN: "<">
-|
-       <GREATER_THAN: ">">
-|
-       <GREATER_EQUALS: ">=">
-|
-       <LESS_EQUALS: "<=">
-|
-       <LOGICAL_EQUALS: "==">
-|
-       <NOT_EQUALS: "!=">
-|
-       <LOGICAL_AND: "&&">
-|
-       <LOGICAL_OR: "||">
-|
-       <XOR: "^">
-|
-       <QUESTION_MARK: "?">
-|
-       <COLON: ":">
-|
-       <DOUBLECOLON: "::">
-|
-       <SEMI_COLON: ";">
-|
-       <STRING_LITERAL:
-       "\""
-       ((~["\"","\\","\n","\r"])
-       | ("\\"
-               ( ["n","t","b","r","f","\\","'","\""]
-               | ["0"-"7"] ( ["0"-"7"] )?
-               | ["0"-"3"] ["0"-"7"]
-                       ["0"-"7"]
-               )
-               )
-       )*
-       "\"">
-|
-       <CHARACTER_LITERAL:
-       "'"
-       ((~["'","\\","\n","\r"])
-       | ("\\"
-               (["n","t","b","r","f","\\","'","\""]
-               | ["0"-"7"] ( ["0"-"7"] )?
-               | ["0"-"3"] ["0"-"7"]
-               ["0"-"7"]
-               )
-               )
-       )
-       "'">
-|
-       < INTEGER_LITERAL:
-        <DECIMAL_LITERAL> (["l","L"])?
-      | <HEX_LITERAL> (["l","L"])?
-      | <OCTAL_LITERAL> (["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>
-      | <HEXADECIMAL_FLOATING_POINT_LITERAL> >
-|
-       < #DECIMAL_FLOATING_POINT_LITERAL:
-        (["0"-"9"])+ "." (["0"-"9"])* (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
-      | "." (["0"-"9"])+ (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
-      | (["0"-"9"])+ <DECIMAL_EXPONENT> (["f","F","d","D"])?
-      | (["0"-"9"])+ (<DECIMAL_EXPONENT>)? ["f","F","d","D"]>
-|
-       < #DECIMAL_EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
-|
-       < #HEXADECIMAL_FLOATING_POINT_LITERAL:
-        "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])+ (".")? <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?
-      | "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])* "." (["0"-"9","a"-"f","A"-"F"])+ <HEXADECIMAL_EXPONENT> (["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 = <IDENTIFIER>.image {
-               if (!type.equals(""))
-                       type = type + " " + str;
-               else
-                       type = str;
-       }))
-       ((str = "const".image {
-               if (!type.equals(""))
-                       type = type + " " + str;
-               else
-                       type = str;
-       }) |
-       (str = <STAR>.image {
-               if (!type.equals(""))
-                       type = type + " " + str;
-               else
-                       type = str;
-       }) |
-       (str = <AND>.image {
-               if (!type.equals(""))
-                       type = type + " " + str;
-               else
-                       type = str;
-       })
-       )*
-       {
-               return type;
-       }
-}
-
-ArrayList<String> FormalParamList() :
-{
-       ArrayList<String> typeParams;
-}
-{
-       {
-               typeParams = new ArrayList<String>();
-       }
-       (TypeParam(typeParams) (<COMMA> TypeParam(typeParams))*)?
-       {
-               System.out.println(typeParams);
-               return typeParams;
-       }
-}
-
-void TypeParam(ArrayList<String> typeParams) :
-{
-       String type, param;
-}
-{
-       (type = Type()) (param = <IDENTIFIER>.image)
-       {
-               typeParams.add(type);
-               typeParams.add(param);
-       }
-}
-
-void ParseSpec() :
-{}
-{
-       <BEGIN> <POTENTIAL_COMMIT_POINT_DEFINE> C_CPP_CODE() <LABEL> <END>
-}
-
-String C_CPP_CODE() :
-{
-       StringBuilder text;
-       Token t;
-}
-{
-       {
-               text = new StringBuilder();
-               t = new Token();
-       }
-       (
-       //LOOKAHEAD(2)
-       (
-       t = <CONST> | t = <STRUCT> |
-       t = <IDENTIFIER> | t = <EQUALS> | t = <OPEN_PAREN> | t = <CLOSE_PAREN> |
-       t = <OPEN_BRACKET> | t = <CLOSE_BRACKET> | t = <HB_SYMBOL> | t = <COMMA> |
-       t = <DOT> | t = <STAR> | t = <NEGATE> | t = <EXCLAMATION> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
-       t = <PLUSPLUS> | t = <MINUS> | t = <MINUSMINUS> | t = <DIVIDE> | t = <BACKSLASH> |
-       t = <LESS_THAN> | t = <GREATER_THAN> | t = <GREATER_EQUALS>     | t = <LESS_EQUALS> |
-       t = <LOGICAL_EQUALS> | t = <NOT_EQUALS> | t = <LOGICAL_AND> | t = <LOGICAL_OR> | t = <XOR> |
-       t = <QUESTION_MARK> | t = <COLON> | t = <DOUBLECOLON> |
-       t = <SEMI_COLON> | t = <STRING_LITERAL> | t = <CHARACTER_LITERAL> |
-       t = <INTEGER_LITERAL> | t = <FLOATING_POINT_LITERAL>
-       )
-       {
-               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();
-       }
-}
-
-
-void Comment() :
-{}
-{
-       C_CPP_CODE() 
-}
-
-void Parse() :
-{}
-{
-       C_CPP_CODE() | 
-       <EOF>
-}
index ec46024..8b8beb3 100644 (file)
-#include <threads.h>
-#include <stdlib.h>
-#include "librace.h"
-#include "model-assert.h"
-
-#include "my_queue.h"
-
-#define relaxed memory_order_relaxed
-#define release memory_order_release
-#define acquire memory_order_acquire
-
-#define MAX_FREELIST 4 /* Each thread can own up to MAX_FREELIST free nodes */
-#define INITIAL_FREE 2 /* Each thread starts with INITIAL_FREE free nodes */
-
-#define POISON_IDX 0x666
-
-static unsigned int (*free_lists)[MAX_FREELIST];
-
-/* Search this thread's free list for a "new" node */
-static unsigned int new_node()
-{
-       int i;
-       int t = get_thread_num();
-       for (i = 0; i < MAX_FREELIST; i++) {
-               unsigned int node = load_32(&free_lists[t][i]);
-               if (node) {
-                       store_32(&free_lists[t][i], 0);
-                       return node;
-               }
-       }
-       /* free_list is empty? */
-       MODEL_ASSERT(0);
+int main() {
+       struct pair<int> *p;
+       p -> x = 2
+       + 3 - 3;
+       /**
+         @Begin
+         @Potential_commit_point_define:
+         __ATOMIC_RET__ == true
+         @Label:
+               Enqueue_Success_Point
+         @End
+        */
        return 0;
 }
-
-/* Place this node index back on this thread's free list */
-static void reclaim(unsigned int node)
-{
-       int i;
-       int t = get_thread_num();
-
-       /* Don't reclaim NULL node */
-       MODEL_ASSERT(node);
-
-       for (i = 0; i < MAX_FREELIST; i++) {
-               /* Should never race with our own thread here */
-               unsigned int idx = load_32(&free_lists[t][i]);
-
-               /* Found empty spot in free list */
-               if (idx == 0) {
-                       store_32(&free_lists[t][i], node);
-                       return;
-               }
-       }
-       /* free list is full? */
-       MODEL_ASSERT(0);
-}
-
-void init_queue(queue_t *q, int num_threads)
-{
-       /*
-               @Begin
-               @Entry_point
-               @End
-       */
-
-       int i, j;
-
-       /* Initialize each thread's free list with INITIAL_FREE pointers */
-       /* The actual nodes are initialized with poison indexes */
-       free_lists = malloc(num_threads * sizeof(*free_lists));
-       for (i = 0; i < num_threads; i++) {
-               for (j = 0; j < INITIAL_FREE; j++) {
-                       free_lists[i][j] = 2 + i * MAX_FREELIST + j;
-                       atomic_init(&q->nodes[free_lists[i][j]].next, MAKE_POINTER(POISON_IDX, 0));
-               }
-       }
-
-       /* initialize queue */
-       atomic_init(&q->head, MAKE_POINTER(1, 0));
-       atomic_init(&q->tail, MAKE_POINTER(1, 0));
-       atomic_init(&q->nodes[1].next, MAKE_POINTER(0, 0));
-}
-
-/*
-       @Begin
-       @Interface_define: Enqueue
-       @End
-*/
-void enqueue(queue_t *q, unsigned int val)
-{
-       int success = 0;
-       unsigned int node;
-       pointer tail;
-       pointer next;
-       pointer tmp;
-
-       node = new_node();
-       store_32(&q->nodes[node].value, val);
-       tmp = atomic_load_explicit(&q->nodes[node].next, relaxed);
-       set_ptr(&tmp, 0); // NULL
-       atomic_store_explicit(&q->nodes[node].next, tmp, relaxed);
-
-       while (!success) {
-               tail = atomic_load_explicit(&q->tail, acquire);
-               next = atomic_load_explicit(&q->nodes[get_ptr(tail)].next, acquire);
-               if (tail == atomic_load_explicit(&q->tail, relaxed)) {
-
-                       /* Check for uninitialized 'next' */
-                       MODEL_ASSERT(get_ptr(next) != POISON_IDX);
-
-                       if (get_ptr(next) == 0) { // == NULL
-                               pointer value = MAKE_POINTER(node, get_count(next) + 1);
-                               success = atomic_compare_exchange_strong_explicit(&q->nodes[get_ptr(tail)].next,
-                                               &next, value, release, release);
-                       }
-                       if (!success) {
-                               unsigned int ptr = get_ptr(atomic_load_explicit(&q->nodes[get_ptr(tail)].next, acquire));
-                               pointer value = MAKE_POINTER(ptr,
-                                               get_count(tail) + 1);
-                               int commit_success = 0;
-                               commit_success = atomic_compare_exchange_strong_explicit(&q->tail,
-                                               &tail, value, release, release);
-                               /**
-                                       @Begin
-                                       @Potential_commit_point_check: __ATOMIC_RET__ == true
-                                       @Label: Enqueue_Success_Point
-                                       @End
-                               */
-                               thrd_yield();
-                       }
-               }
-       }
-       atomic_compare_exchange_strong_explicit(&q->tail,
-                       &tail,
-                       MAKE_POINTER(node, get_count(tail) + 1),
-                       release, release);
-}
-
-
-/*
-       @Begin
-       @Interface_define: Dequeue
-       @End
-*/
-unsigned int dequeue(queue_t *q)
-{
-       unsigned int value;
-       int success = 0;
-       pointer head;
-       pointer tail;
-       pointer next;
-
-       while (!success) {
-               head = atomic_load_explicit(&q->head, acquire);
-               tail = atomic_load_explicit(&q->tail, relaxed);
-               next = atomic_load_explicit(&q->nodes[get_ptr(head)].next, acquire);
-               if (atomic_load_explicit(&q->head, relaxed) == head) {
-                       if (get_ptr(head) == get_ptr(tail)) {
-
-                               /* Check for uninitialized 'next' */
-                               MODEL_ASSERT(get_ptr(next) != POISON_IDX);
-
-                               if (get_ptr(next) == 0) { // NULL
-                                       return 0; // NULL
-                               }
-                               atomic_compare_exchange_strong_explicit(&q->tail,
-                                               &tail,
-                                               MAKE_POINTER(get_ptr(next), get_count(tail) + 1),
-                                               release, release);
-                               thrd_yield();
-                       } else {
-                               value = load_32(&q->nodes[get_ptr(next)].value);
-                               success = atomic_compare_exchange_strong_explicit(&q->head,
-                                               &head,
-                                               MAKE_POINTER(get_ptr(next), get_count(head) + 1),
-                                               release, release);
-                               /*
-                                       @Begin
-                                       @Commit_point_define_check: __ATOMIC_RET__ == true
-                                       @Label: Dequeue_Success_Point
-                                       @End
-                               */
-                               if (!success)
-                                       thrd_yield();
-                       }
-               }
-       }
-       reclaim(get_ptr(head));
-       return value;
-}
diff --git a/grammer/spec_compiler.jj b/grammer/spec_compiler.jj
new file mode 100644 (file)
index 0000000..57956dc
--- /dev/null
@@ -0,0 +1,857 @@
+/* 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 :: <C_CPP_Condition>
+       @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: <Interface_Name>
+       @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.io.File;
+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 {
+               private static ArrayList<String> _content;
+               private static File _file;
+               private static ArrayList<Construct> _constructs;
+
+               public static void main(String[] argvs)
+               throws ParseException, TokenMgrError {
+                       try {
+                               File f = new File("./grammer/spec.txt");
+                               FileInputStream fis = new FileInputStream(f);
+                               SpecParser parser = new SpecParser(fis);
+                               ArrayList<String> content = new ArrayList<String>();
+                               ArrayList<Construct> constructs = new ArrayList<Construct>();
+                               parser.Parse(f, content, constructs);
+                               System.out.println("Parsing finished!");
+                       } catch (FileNotFoundException e) {
+                               e.printStackTrace();
+                       }
+               }
+
+               public static void ParseFile(File f, ArrayList<String> content, ArrayList<Construct> constructs)
+               throws ParseException, TokenMgrError {
+                       try {
+                               InputStream input = new FileInputStream(f);
+                               SpecParser parser = new SpecParser(input);
+                               parser.Parse(f, content, constructs);
+                       } catch (FileNotFoundException e) {
+                               e.printStackTrace();
+                       }
+               }
+
+               public static String stringArray2String(ArrayList<String> content) {
+                       StringBuilder sb = new StringBuilder();
+                       for (int i = 0; i < content.size(); i++) {
+                               sb.append(content.get(i) + "\n");
+                       }
+                       return sb.toString();
+               }
+
+       }
+PARSER_END(SpecParser)
+
+
+
+<*> SKIP :
+{
+       " "
+|
+       "\n"
+|
+       "\r"
+|
+       "\r\n"
+|
+       "\t"
+}
+
+SKIP : {
+       "/**" : IN_POTENTIAL_SPEC
+}
+
+<IN_POTENTIAL_SPEC> TOKEN : {
+       <BEGIN: "@Begin"> : IN_SPEC
+}
+
+<IN_SPEC> SKIP : {
+       "*/" : DEFAULT
+}
+
+SKIP : {
+       "/*": IN_COMMENT
+}
+
+<*> SKIP : {
+       // "//" comment for the specification
+       <"//" (~["\n", "\r"])* (["\n", "\r"])>
+}
+
+<IN_COMMENT, IN_POTENTIAL_SPEC> SKIP : {
+       "*/": DEFAULT
+}
+
+<IN_COMMENT, IN_POTENTIAL_SPEC> SKIP : { <  ~[] > }
+
+<IN_SPEC> SKIP :
+{
+       // "#" comment for the specification
+       <"#" (~["\n", "\r"])* (["\n", "\r"])>
+}
+
+
+<IN_SPEC> TOKEN : {
+       <END: "@End">
+|
+       <OPTIONS: "@Options:">
+|
+       <GLOBAL_DEFINE: "@Global_define:">
+|
+       <DECLARE_VAR: "@DeclareVar:">
+|
+       <INIT_VAR: "@InitVar:">
+|
+       <DEFINE_FUNC: "@DefineFunc:">
+|
+       <INTERFACE_CLUSTER: "@Interface_cluster:">
+|
+       <HAPPENS_BEFORE: "@Happens_before:">
+|
+       <INTERFACE: "@Interface:">
+|
+       <COMMIT_POINT_SET: "@Commit_point_set:">
+|
+       <ENTRY_POINT: "@Entry_point">
+|
+       <INTERFACE_DEFINE: "@Interface_define:">
+|
+       <CONDITION: "@Condition:">
+|
+       <HB_CONDITION: "@HB_condition:">
+|
+       <ID: "@ID:">
+|
+       <CHECK: "@Check:">
+|
+       <ACTION: "@Action:">
+|
+       <DEFINEVAR: "@DefineVar:">
+|
+       <CODE: "@Code:">
+|
+       <POST_ACTION: "@Post_action:">
+|
+       <POST_CHECK: "@Post_check:">
+|
+       <POTENTIAL_COMMIT_POINT_DEFINE: "@Potential_commit_point_define:">
+|
+       <LABEL: "@Label:">
+|
+       <COMMIT_POINT_DEFINE_CHECK: "@Commit_point_define_check:">
+|
+       <COMMIT_POINT_DEFINE: "@Commit_point_define:">
+|
+       <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
+}
+
+
+<IN_SPEC, DEFAULT> TOKEN :
+{
+/*   Specification & C/C++ shared tokens   */
+// Reserved keywords
+       <CONST: "const">
+|
+       <STRUCT: "struct">
+|
+       <TYPENAME: "typename">
+|
+       <#DIGIT: ["0"-"9"]>
+|
+       <#LETTER: ["a"-"z", "A"-"Z"]>
+|
+       <IDENTIFIER: (<LETTER> | "_") (<LETTER> | <DIGIT> | "_")*>
+|
+       <POUND: "#">
+|
+       <OPEN_BRACKET: "[">
+|
+       <CLOSE_BRACKET: "]">
+|
+       <EQUALS: "=">
+|
+       <OPEN_PAREN: "(">
+|
+       <CLOSE_PAREN: ")">
+|
+       <OPEN_BRACE: "{">
+|
+       <CLOSE_BRACE: "}">
+|
+       <HB_SYMBOL: "->">
+|
+       <COMMA: ",">
+
+|
+/*   C/C++ only token*/
+       <DOT: ".">
+|
+       <STAR: "*">
+|
+       <NEGATE: "~">
+|
+       <EXCLAMATION: "!">
+|
+       <AND: "&">
+|
+       <OR: "|">
+|
+       <MOD: "%">
+|
+       <PLUS: "+">
+|
+       <PLUSPLUS: "++">
+|
+       <MINUS: "-">
+|
+       <MINUSMINUS: "--">
+|
+       <DIVIDE: "/">
+|
+       <BACKSLASH: "\\">
+|
+       <LESS_THAN: "<">
+|
+       <GREATER_THAN: ">">
+|
+       <GREATER_EQUALS: ">=">
+|
+       <LESS_EQUALS: "<=">
+|
+       <LOGICAL_EQUALS: "==">
+|
+       <NOT_EQUALS: "!=">
+|
+       <LOGICAL_AND: "&&">
+|
+       <LOGICAL_OR: "||">
+|
+       <XOR: "^">
+|
+       <QUESTION_MARK: "?">
+|
+       <COLON: ":">
+|
+       <DOUBLECOLON: "::">
+|
+       <SEMI_COLON: ";">
+|
+       <STRING_LITERAL:
+       "\""
+       ((~["\"","\\","\n","\r"])
+       | ("\\"
+               ( ["n","t","b","r","f","\\","'","\""]
+               | ["0"-"7"] ( ["0"-"7"] )?
+               | ["0"-"3"] ["0"-"7"]
+                       ["0"-"7"]
+               )
+               )
+       )*
+       "\"">
+|
+       <CHARACTER_LITERAL:
+       "'"
+       ((~["'","\\","\n","\r"])
+       | ("\\"
+               (["n","t","b","r","f","\\","'","\""]
+               | ["0"-"7"] ( ["0"-"7"] )?
+               | ["0"-"3"] ["0"-"7"]
+               ["0"-"7"]
+               )
+               )
+       )
+       "'">
+|
+       < INTEGER_LITERAL:
+        <DECIMAL_LITERAL> (["l","L"])?
+      | <HEX_LITERAL> (["l","L"])?
+      | <OCTAL_LITERAL> (["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>
+      | <HEXADECIMAL_FLOATING_POINT_LITERAL> >
+|
+       < #DECIMAL_FLOATING_POINT_LITERAL:
+        (["0"-"9"])+ "." (["0"-"9"])* (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
+      | "." (["0"-"9"])+ (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
+      | (["0"-"9"])+ <DECIMAL_EXPONENT> (["f","F","d","D"])?
+      | (["0"-"9"])+ (<DECIMAL_EXPONENT>)? ["f","F","d","D"]>
+|
+       < #DECIMAL_EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
+|
+       < #HEXADECIMAL_FLOATING_POINT_LITERAL:
+        "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])+ (".")? <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?
+      | "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])* "." (["0"-"9","a"-"f","A"-"F"])+ <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?>
+|
+       < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ >
+|
+       < #SPACE: (" " | "\t")+>
+|
+       < #TO_END_OF_LINE: (~["\n"])+>
+|
+       /* Macro token */
+       <INCLUDE: "#" (<SPACE>)? "include" <SPACE> (<STRING_LITERAL> | "<" (<LETTER> | <DOT>)+ ">")>
+|
+       <DEFINE: "#" (<SPACE>)? <TO_END_OF_LINE>>
+}
+
+String Type() :
+{
+       String type;
+       String str;
+}
+{
+       { type = ""; }
+       ("const"
+       { type = "const"; }
+       )?
+       (("struct" { type = type + " struct"; })? 
+       (str = <IDENTIFIER>.image {
+               if (!type.equals(""))
+                       type = type + " " + str;
+               else
+                       type = str;
+       }))
+       ((str = "const".image {
+               if (!type.equals(""))
+                       type = type + " " + str;
+               else
+                       type = str;
+       }) |
+       (str = <STAR>.image {
+               if (!type.equals(""))
+                       type = type + " " + str;
+               else
+                       type = str;
+       }) |
+       (str = <AND>.image {
+               if (!type.equals(""))
+                       type = type + " " + str;
+               else
+                       type = str;
+       })
+       )*
+       {
+               return type;
+       }
+}
+
+ArrayList<String> FormalParamList() :
+{
+       ArrayList<String> typeParams;
+}
+{
+       {
+               typeParams = new ArrayList<String>();
+       }
+       (TypeParam(typeParams) (<COMMA> TypeParam(typeParams))*)?
+       {
+               System.out.println(typeParams);
+               return typeParams;
+       }
+}
+
+void TypeParam(ArrayList<String> typeParams) :
+{
+       String type, param;
+}
+{
+       (type = Type()) (param = <IDENTIFIER>.image)
+       {
+               typeParams.add(type);
+               typeParams.add(param);
+       }
+}
+
+ArrayList<String> C_CPP_CODE() :
+{
+       String text;
+       Token t;
+       boolean newLine = false;
+       ArrayList<String> content;
+}
+{
+       {
+               text = "";
+               t = new Token();
+               content = new ArrayList<String>();
+       }
+       (
+       LOOKAHEAD(2)
+       (
+       t = <CONST> | t = <STRUCT> | t = <TYPENAME> |
+       t = <IDENTIFIER> | t = <POUND> |
+       (t = <OPEN_BRACE>  { newLine = true; } ) |
+       (t = <CLOSE_BRACE>  { newLine = true; } ) | 
+       t = <EQUALS> | t = <OPEN_PAREN> | t = <CLOSE_PAREN> | 
+       t = <OPEN_BRACKET> | t = <CLOSE_BRACKET>
+       | t = <HB_SYMBOL> | t = <COMMA> |
+       t = <DOT> | t = <STAR> | t = <NEGATE> | t = <EXCLAMATION> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
+       t = <PLUSPLUS> | t = <MINUS> | t = <MINUSMINUS> | t = <DIVIDE> | t = <BACKSLASH> |
+       t = <LESS_THAN> | t = <GREATER_THAN> | t = <GREATER_EQUALS>     | t = <LESS_EQUALS> |
+       t = <LOGICAL_EQUALS> | t = <NOT_EQUALS> | t = <LOGICAL_AND> | t = <LOGICAL_OR> | t = <XOR> |
+       t = <QUESTION_MARK> | t = <COLON> | t = <DOUBLECOLON> |
+       (t = <SEMI_COLON> { newLine = true; } )
+       | t = <STRING_LITERAL> | t = <CHARACTER_LITERAL> |
+       t = <INTEGER_LITERAL> | t = <FLOATING_POINT_LITERAL> |
+       (t = <INCLUDE> { newLine = true; } ) |
+       (t = <DEFINE> { newLine = true; } )
+       )
+       {
+               text = text + " " + t.image;
+               if (newLine) {
+                       content.add(text);
+                       text = "";
+                       newLine = false;
+               }
+       }
+       )+
+
+       {
+               return content;
+       }
+}
+
+
+void Parse(File f, ArrayList<String> content, ArrayList<Construct> constructs) :
+{
+       Construct inst;
+       ArrayList<String> code;
+}
+{
+       {
+               _file = f;
+               _content = content;
+               _constructs = constructs;
+       }
+       ((inst = ParseSpec() { _constructs.add(inst); }) |
+       ((code = C_CPP_CODE()) { _content.addAll(code); })
+       )* <EOF>
+}
+
+Construct ParseSpec() :
+{
+       Construct res;  
+}
+{
+       (
+       LOOKAHEAD(2) res = Global_construct() |
+       LOOKAHEAD(2) res = Interface() |
+       LOOKAHEAD(2) res = Potential_commit_point_define() |
+       LOOKAHEAD(2) res = Commit_point_define() |
+       LOOKAHEAD(2) res = Commit_point_define_check() |
+       LOOKAHEAD(2) res = Entry_point() |
+       LOOKAHEAD(2) res = Interface_define()
+       )
+       {
+               //System.out.println(res);
+               return res;
+       }
+}
+
+GlobalConstruct Global_construct() :
+{
+       GlobalConstruct res;
+       SequentialDefineSubConstruct code;
+       HashMap<String, String> options;
+       String key, value;
+}
+{
+       {
+               res = null;
+               options = new HashMap<String, String>();
+       }
+               <BEGIN> 
+                       (<OPTIONS>
+                               ((key = <IDENTIFIER>.image)
+                               <EQUALS>
+                               (value = <IDENTIFIER>.image)
+                               {
+                                       if (options.containsKey(key)) {
+                                               throw new ParseException("Duplicate options!");
+                                       }
+                                       options.put(key, value);
+                               }
+                               <SEMI_COLON>
+                               )*
+                       )?
+                       (code = Global_define())
+                       { res = new GlobalConstruct(_file, _content.size(), code, options); }
+                       (Interface_clusters(res))?
+                       (Happens_before(res))?
+               <END>
+       {
+               res.unfoldInterfaceCluster();
+               return res;
+       }
+}
+
+SequentialDefineSubConstruct Global_define() :
+{
+       String declareVar, initVar, defineFunc;
+       ArrayList<String> code;
+}
+{
+       {
+               declareVar = "";
+               initVar = "";
+               defineFunc = "";
+       }
+       <GLOBAL_DEFINE>
+               (<DECLARE_VAR> (code = C_CPP_CODE() { declareVar = stringArray2String(code); } ))?
+       (<INIT_VAR> (code = C_CPP_CODE() { initVar = stringArray2String(code); } ))?
+       (<DEFINE_FUNC> (code = C_CPP_CODE() { defineFunc = stringArray2String(code); }))?
+       {
+               SequentialDefineSubConstruct res = new SequentialDefineSubConstruct(declareVar, initVar, defineFunc);
+               //System.out.println(res);
+               return res;
+       }
+}
+
+ConditionalInterface Conditional_interface() :
+{
+       String interfaceName, hbConditionLabel;
+}
+{
+       {
+               hbConditionLabel = "";
+       }
+       interfaceName = <IDENTIFIER>.image (<OPEN_BRACKET> hbConditionLabel =
+       <IDENTIFIER>.image <CLOSE_BRACKET>)?
+       {
+               return new ConditionalInterface(interfaceName, hbConditionLabel);
+       }
+}
+
+void Interface_cluster(GlobalConstruct inst) :
+{
+       String clusterName;
+       ConditionalInterface condInterface;
+}
+{
+       (clusterName= <IDENTIFIER>.image)
+       <EQUALS> <OPEN_PAREN>
+               (condInterface = Conditional_interface()
+               { inst.addInterface2Cluster(clusterName, condInterface); } 
+               )
+               (<COMMA> condInterface = Conditional_interface()
+               { inst.addInterface2Cluster(clusterName, condInterface); } 
+               )*
+       <CLOSE_PAREN>
+}
+
+void Interface_clusters(GlobalConstruct inst) :
+{}
+{
+       <INTERFACE_CLUSTER> (Interface_cluster(inst))+
+}
+
+void Happens_before(GlobalConstruct inst) :
+{
+       ConditionalInterface left, right;       
+}
+{
+       <HAPPENS_BEFORE> 
+       (
+       left = Conditional_interface() <HB_SYMBOL> right = Conditional_interface()
+       { inst.addHBCondition(left, right); }
+       )+
+}
+
+InterfaceConstruct Interface() :
+{
+       InterfaceConstruct res;
+       String interfaceName, condition, idCode, check, postAction,
+               postCheck, commitPoint, hbLabel, hbCondition;
+       ActionSubConstruct action;
+       ArrayList<String> commitPointSet;
+       HashMap<String, String> hbConditions;
+       ArrayList<String> content;
+}
+{
+       {
+               res = null;
+               action = null;
+               condition = "";
+               idCode = "";
+               check = "";
+               postAction = "";
+               postCheck = "";
+               commitPointSet = new ArrayList<String>();
+               hbConditions = new HashMap<String, String>();
+       }
+               <BEGIN>
+                       <INTERFACE> (interfaceName = <IDENTIFIER>.image)
+                       <COMMIT_POINT_SET>
+                               (commitPoint = <IDENTIFIER>.image
+                               { commitPointSet.add(commitPoint); }
+                               )
+                               (<OR>
+                                       (commitPoint = <IDENTIFIER>.image)
+                                       {
+                                               if (commitPointSet.contains(commitPoint)) {
+                                                       throw new ParseException(interfaceName + " has" +
+                                                               "duplicate commit point labels");
+                                               }
+                                               commitPointSet.add(commitPoint);
+                                       }
+                               )*
+
+                       (<CONDITION> (content = C_CPP_CODE() { condition = stringArray2String(content); }))?
+                       (
+                               <HB_CONDITION>
+                               (hbLabel = <IDENTIFIER>.image)
+                               (content = C_CPP_CODE() { hbCondition = stringArray2String(content); })
+                               {
+                                       if (hbConditions.containsKey(hbLabel)) {
+                                               throw new ParseException(interfaceName + " has" +
+                                                       "duplicate happens-before condtion labels");
+                                       }
+                                       hbConditions.put(hbLabel, hbCondition);
+                               }
+                       )*
+                       (<ID> (content = C_CPP_CODE() { idCode = stringArray2String(content); }))?
+                       (<CHECK> (content = C_CPP_CODE() { check = stringArray2String(content); }))?
+                       (action = Action())?
+                       (<POST_ACTION> (content = C_CPP_CODE() { postAction = stringArray2String(content); }))?
+                       (<POST_CHECK> (content = C_CPP_CODE() { postCheck = stringArray2String(content); }))?
+               <END>
+       {
+               res = new InterfaceConstruct(_file, _content.size(), interfaceName, commitPointSet, condition,
+                       hbConditions, idCode, check, action, postAction, postCheck);
+               return res;
+       }
+}
+
+ActionSubConstruct Action() :
+{
+       String type, name, expr, defineVarStr, code;
+       ArrayList<DefineVar> defineVars;
+       ArrayList<String> content;
+}
+{
+       {
+               defineVars = new ArrayList<DefineVar>();
+               code = "";
+       }
+       <ACTION>
+       (
+               (
+               (<DEFINEVAR> (content = C_CPP_CODE() { defineVarStr = stringArray2String(content); }) 
+               {
+                       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> (content = C_CPP_CODE() { code = stringArray2String(content); }))? ) 
+       )
+       
+       {
+               ActionSubConstruct res = new ActionSubConstruct(defineVars, code);
+               return res;
+       }
+}
+
+PotentialCPDefineConstruct Potential_commit_point_define() :
+{
+       PotentialCPDefineConstruct res;
+       String label, condition;
+       ArrayList<String> content;
+}
+{
+
+       { res = null; }
+               <BEGIN>
+                       <POTENTIAL_COMMIT_POINT_DEFINE> (content = C_CPP_CODE() { condition = stringArray2String(content); })
+                       <LABEL> (label = <IDENTIFIER>.image)
+               <END>
+       {
+               res = new PotentialCPDefineConstruct(_file, _content.size(), label, condition); 
+               return res;
+       }
+}
+
+
+CPDefineConstruct Commit_point_define() :
+{
+       CPDefineConstruct res;
+       String label, potentialCPLabel, condition;
+       ArrayList<String> content;
+}
+{
+
+       { res = null; }
+               <BEGIN>
+                       <COMMIT_POINT_DEFINE> (content = C_CPP_CODE() { condition = stringArray2String(content); })
+                       <POTENTIAL_COMMIT_POINT_LABEL> (potentialCPLabel = <IDENTIFIER>.image)
+                       <LABEL> (label = <IDENTIFIER>.image)
+               <END>
+       {
+               res = new CPDefineConstruct(_file, _content.size(), label, potentialCPLabel, condition);
+               return res;
+       }
+}
+
+
+CPDefineCheckConstruct Commit_point_define_check() :
+{
+       CPDefineCheckConstruct res;     
+       String label, condition;
+       ArrayList<String> content;
+}
+{
+
+       { res = null; }
+               <BEGIN> 
+                       <COMMIT_POINT_DEFINE_CHECK> (content = C_CPP_CODE() { condition = stringArray2String(content); })
+                       <LABEL> (label = <IDENTIFIER>.image)
+               <END>
+       {
+               res = new CPDefineCheckConstruct(_file, _content.size(), label, condition);
+               return res;
+       }
+}
+
+EntryPointConstruct Entry_point() :
+{}
+{
+
+               <BEGIN> 
+                       <ENTRY_POINT>
+               <END>
+       {
+               return new EntryPointConstruct(_file, _content.size());
+       }
+}
+
+InterfaceDefineConstruct Interface_define() :
+{
+       String name;    
+}
+{
+               <BEGIN>
+                       <INTERFACE_DEFINE> (name = <IDENTIFIER>.image)
+               <END>
+       {
+               return new InterfaceDefineConstruct(_file, _content.size(), name);
+       }
+}
index a8484bd..ab350be 100755 (executable)
@@ -6,17 +6,17 @@ fi
 
 JAVACC_PATH=$SPEC_COMPILER_HOME/lib
 
-OUTPUT_PATH=$SPEC_COMPILER_HOME/src/edu/uci/eecs/specCompiler/grammerParser
-mkdir -p $OUTPUT_PATH
+PRE_SCANNER_FILE=$SPEC_COMPILER_HOME/grammer/pre_scanner.jj
+GRAMMER_FILE=$SPEC_COMPILER_HOME/grammer/spec_compiler.jj
 
-GRAMMER_FILE=$SPEC_COMPILER_HOME/grammer/spec-compiler.jj
-
-if [ -z $1 ]; then
-       echo "Using the default grammer file: $GRAMMER_FILE."
-else
-       GRAMMER_FILE=$1
-fi
+PRE_SCANNER_OUTPUT_PATH=$SPEC_COMPILER_HOME/src/edu/uci/eecs/specCompiler/grammerParser/preScanner
+GRAMMER_OUTPUT_PATH=$SPEC_COMPILER_HOME/src/edu/uci/eecs/specCompiler/grammerParser
 
 echo "Deleting the old generated java files."
-rm $OUTPUT_PATH/*.java
-java -cp $JAVACC_PATH/javacc.jar javacc -OUTPUT_DIRECTORY=$OUTPUT_PATH $GRAMMER_FILE
+rm -r $GRAMMER_OUTPUT_PATH/*
+
+mkdir -p $PRE_SCANNER_OUTPUT_PATH
+mkdir -p $GRAMMER_OUTPUT_PATH
+
+java -cp $JAVACC_PATH/javacc.jar javacc -OUTPUT_DIRECTORY=$PRE_SCANNER_OUTPUT_PATH $PRE_SCANNER_FILE
+java -cp $JAVACC_PATH/javacc.jar javacc -OUTPUT_DIRECTORY=$GRAMMER_OUTPUT_PATH $GRAMMER_FILE
index 3569e20..399c036 100644 (file)
@@ -18,9 +18,7 @@ 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.SequentialDefineSubConstruct;
-import edu.uci.eecs.specCompiler.specExtraction.SpecConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.SpecExtractor;
-import edu.uci.eecs.specCompiler.specExtraction.SpecNotMatchException;
 
 /**
  * <p>
@@ -52,11 +50,7 @@ public class CodeGenerator {
 
                _extractor = new SpecExtractor();
 
-               try {
-                       _extractor.extract(srcFiles);
-               } catch (SpecNotMatchException e1) {
-                       e1.printStackTrace();
-               }
+               _extractor.extract(srcFiles);
 
                _semantics = new SemanticsChecker(_extractor.getConstructs());
                try {
@@ -96,8 +90,7 @@ public class CodeGenerator {
         * "@Interface" define
         * </p>
         */
-       private void globalConstruct2Code(SpecConstruct inst) {
-               GlobalConstruct construct = (GlobalConstruct) inst.construct;
+       private void globalConstruct2Code(GlobalConstruct construct) {
                ArrayList<String> newCode = CodeVariables.generateGlobalVarDeclaration(
                                _semantics, construct);
                // Record the global content array to generate the new file
@@ -105,11 +98,10 @@ public class CodeGenerator {
        }
 
        // Mainly rename and wrap the interface
-       private void interface2Code(SpecConstruct inst)
+       private void interface2Code(InterfaceConstruct construct)
                        throws InterfaceWrongFormatException {
-               int lineNum = inst.endLineNum + 1;
-               InterfaceConstruct construct = (InterfaceConstruct) inst.construct;
-               
+               int lineNum = construct.begin + 1;
+
                // Rename the interface name
                File file = inst.file;
                String funcDecl = inst.interfaceDeclBody;
@@ -125,7 +117,8 @@ public class CodeGenerator {
                }
 
                // Generate new wrapper
-               ArrayList<String> newCode = CodeVariables.generateInterfaceWrapper(_semantics, inst);
+               ArrayList<String> newCode = CodeVariables.generateInterfaceWrapper(
+                               _semantics, inst);
                // Add it to the codeAdditions
                CodeAddition addition = new CodeAddition(lineNum, newCode);
                if (!codeAdditions.containsKey(inst.file)) {
@@ -135,7 +128,7 @@ public class CodeGenerator {
        }
 
        // Returns the function name that has been renamed and replace the old line
-       private String renameInterface(SpecConstruct inst)
+       private String renameInterface(Construct inst)
                        throws InterfaceWrongFormatException {
                String funcDecl = inst.interfaceDeclBody;
                ArrayList<String> content = contents.get(inst.file);
@@ -149,65 +142,60 @@ public class CodeGenerator {
                }
                IDExtractor idExtractor = new IDExtractor(funcDecl, beginIdx);
                String funcName = idExtractor.getPrevID();
-               int idBeginIdx = idExtractor.getIDBeginIdx(),
-                               idEndIdx = idExtractor.getIDEndIdx(),
-                               idLineBeginIdx = idExtractor.lineBeginIdxOfID(),
-                               idLineEndIdx = idExtractor.lineEndIdxOfID();
+               int idBeginIdx = idExtractor.getIDBeginIdx(), idEndIdx = idExtractor
+                               .getIDEndIdx(), idLineBeginIdx = idExtractor.lineBeginIdxOfID(), idLineEndIdx = idExtractor
+                               .lineEndIdxOfID();
                String newLine = funcDecl.substring(idLineBeginIdx, idBeginIdx)
                                + CodeVariables.SPEC_INTERFACE_WRAPPER + funcName
                                + funcDecl.substring(idEndIdx + 1, idLineEndIdx + 1);
-               
+
                int lineNumOfID = idExtractor.lineNumOfID();
                // Be careful: lineNum - 1 -> index of content array
                content.set(inst.endLineNum + lineNumOfID, newLine);
                return funcName;
        }
 
-       private void potentialCP2Code(SpecConstruct inst) {
-               int lineNum = inst.endLineNum + 1;
-               GlobalConstruct construct = (GlobalConstruct) inst.construct;
+       private void potentialCPDefine2Code(PotentialCPDefineConstruct construct) {
+               int lineNum = construct.beginLineNum;
                ArrayList<String> newCode = new ArrayList<String>();
 
                CodeAddition addition = new CodeAddition(lineNum, newCode);
-               if (!codeAdditions.containsKey(inst.file)) {
-                       codeAdditions.put(inst.file, new ArrayList<CodeAddition>());
+               if (!codeAdditions.containsKey(construct.file)) {
+                       codeAdditions.put(construct.file, new ArrayList<CodeAddition>());
                }
-               codeAdditions.get(inst.file).add(addition);
+               codeAdditions.get(construct.file).add(addition);
        }
 
-       private void CPDefine2Code(SpecConstruct inst) {
-               int lineNum = inst.endLineNum + 1;
-               GlobalConstruct construct = (GlobalConstruct) inst.construct;
+       private void CPDefine2Code(CPDefineConstruct construct) {
+               int lineNum = construct.beginLineNum;
                ArrayList<String> newCode = new ArrayList<String>();
 
                CodeAddition addition = new CodeAddition(lineNum, newCode);
-               if (!codeAdditions.containsKey(inst.file)) {
-                       codeAdditions.put(inst.file, new ArrayList<CodeAddition>());
+               if (!codeAdditions.containsKey(construct.file)) {
+                       codeAdditions.put(construct.file, new ArrayList<CodeAddition>());
                }
-               codeAdditions.get(inst.file).add(addition);
+               codeAdditions.get(construct.file).add(addition);
        }
 
-       private void CPDefineCheck2Code(SpecConstruct inst) {
-               int lineNum = inst.endLineNum + 1;
-               GlobalConstruct construct = (GlobalConstruct) inst.construct;
+       private void CPDefineCheck2Code(CPDefineCheckConstruct construct) {
+               int lineNum = construct.beginLineNum;
                ArrayList<String> newCode = new ArrayList<String>();
 
                CodeAddition addition = new CodeAddition(lineNum, newCode);
-               if (!codeAdditions.containsKey(inst.file)) {
-                       codeAdditions.put(inst.file, new ArrayList<CodeAddition>());
+               if (!codeAdditions.containsKey(construct.file)) {
+                       codeAdditions.put(construct.file, new ArrayList<CodeAddition>());
                }
-               codeAdditions.get(inst.file).add(addition);
+               codeAdditions.get(construct.file).add(addition);
        }
 
        public void generateCode() {
                for (int i = 0; i < _semantics.constructs.size(); i++) {
-                       SpecConstruct inst = _semantics.constructs.get(i);
-                       Construct construct = inst.construct;
+                       Construct construct = _semantics.constructs.get(i);
                        if (construct instanceof GlobalConstruct) {
-                               globalConstruct2Code(inst);
+                               globalConstruct2Code((GlobalConstruct) construct);
                        } else if (construct instanceof InterfaceConstruct) {
                                try {
-                                       interface2Code(inst);
+                                       interface2Code((InterfaceConstruct) construct);
                                } catch (InterfaceWrongFormatException e) {
                                        e.printStackTrace();
                                }
index d2fe6b8..3945136 100644 (file)
@@ -7,9 +7,8 @@ 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.SequentialDefineSubConstruct;
-import edu.uci.eecs.specCompiler.specExtraction.SpecExtractor;
 import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct.DefineVar;
-import edu.uci.eecs.specCompiler.specExtraction.SpecConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.SpecExtractor;
 
 public class CodeVariables {
        // C++ code or library
@@ -234,7 +233,7 @@ public class CodeVariables {
                // DefineVar declaration
                for (String interfaceName : semantics.interfaceName2Construct.keySet()) {
                        InterfaceConstruct iConstruct = (InterfaceConstruct) semantics.interfaceName2Construct
-                                       .get(interfaceName).construct;
+                                       .get(interfaceName);
                        ArrayList<DefineVar> defineVars = iConstruct.action.defineVars;
                        if (defineVars.size() > 0) {
                                newCode.add(COMMENT("DefineVar in " + interfaceName));
@@ -274,7 +273,7 @@ public class CodeVariables {
                newCode.add(COMMENT("Init DefineVars"));
                for (String interfaceName : semantics.interfaceName2Construct.keySet()) {
                        InterfaceConstruct iConstruct = (InterfaceConstruct) semantics.interfaceName2Construct
-                                       .get(interfaceName).construct;
+                                       .get(interfaceName);
                        ArrayList<DefineVar> defineVars = iConstruct.action.defineVars;
                        if (defineVars.size() > 0) {
                                newCode.add(COMMENT("DefineVar in " + interfaceName));
@@ -350,11 +349,10 @@ public class CodeVariables {
        }
 
        public static ArrayList<String> generateInterfaceWrapper(
-                       SemanticsChecker semantics, SpecConstruct inst) {
-               InterfaceConstruct construct = (InterfaceConstruct) inst.construct;
+                       SemanticsChecker semantics, InterfaceConstruct construct) {
                ArrayList<String> newCode = new ArrayList<String>();
-               String funcDecl = inst.interfaceDeclBody.substring(0,
-                               inst.interfaceDeclBody.indexOf(')') + 1);
+               String funcDecl = construct.interfaceDeclBody.substring(0,
+                               construct.interfaceDeclBody.indexOf(')') + 1);
                String returnType = getFuncReturnType(funcDecl), funcName = getFuncName(funcDecl), renamedFuncName = SPEC_INTERFACE_WRAPPER
                                + funcName;
                ArrayList<String> args = getFuncArgs(funcDecl);
@@ -487,8 +485,7 @@ public class CodeVariables {
        }
 
        public static ArrayList<String> generatePotentialCPDefine(
-                       SemanticsChecker semantics, SpecConstruct inst) {
-               PotentialCPDefineConstruct construct = (PotentialCPDefineConstruct) inst.construct;
+                       SemanticsChecker semantics, PotentialCPDefineConstruct construct) {
                ArrayList<String> newCode = new ArrayList<String>();
 
                // Generate redundant header files
index 9eca53b..d22ddee 100644 (file)
@@ -14,14 +14,13 @@ import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.InterfaceConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct;
-import edu.uci.eecs.specCompiler.specExtraction.SpecConstruct;
 
 public class SemanticsChecker {
-       public final ArrayList<SpecConstruct> constructs;
-       public final HashMap<String, SpecConstruct> CPLabel2Construct;
-       public final HashMap<String, SpecConstruct> potentialCPLabel2Construct;
-       public final HashMap<String, SpecConstruct> interfaceName2Construct;
-       public final HashMap<String, SpecConstruct> interfaceName2DefineConstruct;
+       public final ArrayList<Construct> constructs;
+       public final HashMap<String, Construct> CPLabel2Construct;
+       public final HashMap<String, Construct> potentialCPLabel2Construct;
+       public final HashMap<String, Construct> interfaceName2Construct;
+       public final HashMap<String, Construct> interfaceName2DefineConstruct;
        public final HashMap<String, ArrayList<InterfaceConstruct>> CPLabel2InterfaceConstruct;
        public final HashSet<DefineVar> defineVars;
        
@@ -31,18 +30,18 @@ public class SemanticsChecker {
 
        private HashMap<String, String> options;
        private HashMap<ConditionalInterface, HashSet<ConditionalInterface>> hbConditions;
-       private SpecConstruct entryPointConstruct;
+       private Construct entryPointConstruct;
        
        private int _interfaceNum;
        private int _hbLabelNum;
        private int _commitPointNum;    
 
-       public SemanticsChecker(ArrayList<SpecConstruct> constructs) {
+       public SemanticsChecker(ArrayList<Construct> constructs) {
                this.constructs = constructs;
-               this.CPLabel2Construct = new HashMap<String, SpecConstruct>();
-               this.potentialCPLabel2Construct = new HashMap<String, SpecConstruct>();
-               this.interfaceName2Construct = new HashMap<String, SpecConstruct>();
-               this.interfaceName2DefineConstruct = new HashMap<String, SpecConstruct>();
+               this.CPLabel2Construct = new HashMap<String, Construct>();
+               this.potentialCPLabel2Construct = new HashMap<String, Construct>();
+               this.interfaceName2Construct = new HashMap<String, Construct>();
+               this.interfaceName2DefineConstruct = new HashMap<String, Construct>();
                this.CPLabel2InterfaceConstruct = new HashMap<String, ArrayList<InterfaceConstruct>>();
                this.defineVars = new HashSet<DefineVar>();
                this.entryPointConstruct = null;
@@ -76,7 +75,7 @@ public class SemanticsChecker {
                                                        + "\"!");
                } else if (!label.equals("")) {
                        InterfaceConstruct iConstruct = (InterfaceConstruct) interfaceName2Construct
-                                       .get(interfaceName).construct;
+                                       .get(interfaceName);
                        if (!iConstruct.hbConditions.containsKey(label)) {
                                throw new SemanticsCheckerException("Interface "
                                                + interfaceName + " doesn't contain HB_codition: "
@@ -126,7 +125,7 @@ public class SemanticsChecker {
                boolean hasGlobalConstruct = false;
                // First grab the information from the interface
                for (int i = 0; i < constructs.size(); i++) {
-                       Construct inst = constructs.get(i).construct;
+                       Construct inst = constructs.get(i);
                        if (inst instanceof InterfaceConstruct) {
                                InterfaceConstruct iConstruct = (InterfaceConstruct) inst;
                                if (interfaceName2Construct.containsKey(iConstruct.name)) {
@@ -156,8 +155,7 @@ public class SemanticsChecker {
 
                String label;
                for (int i = 0; i < constructs.size(); i++) {
-                       SpecConstruct inst = constructs.get(i);
-                       Construct construct = inst.construct;
+                       Construct construct = constructs.get(i);
                        if (construct instanceof GlobalConstruct) {
                                GlobalConstruct theConstruct = (GlobalConstruct) construct;
                                if (!hasGlobalConstruct)
@@ -186,7 +184,7 @@ public class SemanticsChecker {
                                // Number the commit_point label
                                commitPointLabel2Num.put(label, _commitPointNum++);
                                
-                               potentialCPLabel2Construct.put(label, inst);
+                               potentialCPLabel2Construct.put(label, construct);
                        } else if (construct instanceof CPDefineCheckConstruct) {
                                CPDefineCheckConstruct theConstruct = (CPDefineCheckConstruct) construct;
                                label = theConstruct.label;
@@ -194,7 +192,7 @@ public class SemanticsChecker {
                                // Number the commit_point label
                                commitPointLabel2Num.put(label, _commitPointNum++);
                                
-                               CPLabel2Construct.put(label, inst);
+                               CPLabel2Construct.put(label, construct);
                        } else if (construct instanceof CPDefineConstruct) {
                                CPDefineConstruct theConstruct = (CPDefineConstruct) construct;
                                label = theConstruct.label;
@@ -202,13 +200,13 @@ public class SemanticsChecker {
                                // Number the commit_point label
                                commitPointLabel2Num.put(label, _commitPointNum++);
                                
-                               CPLabel2Construct.put(label, inst);
+                               CPLabel2Construct.put(label, construct);
                        } else if (construct instanceof EntryPointConstruct) {
                                if (entryPointConstruct != null) {
                                        throw new SemanticsCheckerException(
                                                        "More than one entry point!");
                                }
-                               entryPointConstruct = inst;
+                               entryPointConstruct = construct;
                        } else if (construct instanceof InterfaceDefineConstruct) {
                                InterfaceDefineConstruct theConstruct = (InterfaceDefineConstruct) construct;
                                String name = theConstruct.name;
@@ -216,7 +214,7 @@ public class SemanticsChecker {
                                        throw new SemanticsCheckerException(
                                                        "Interface define label duplicates!");
                                }
-                               interfaceName2DefineConstruct.put(name, inst);
+                               interfaceName2DefineConstruct.put(name, construct);
                        }
                }
        }
index ed504e1..99f8fc8 100644 (file)
@@ -1,14 +1,18 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
+import java.io.File;
+
 public class CPDefineCheckConstruct extends Construct {
        public final String label;
        public final String condition;
-       
-       public CPDefineCheckConstruct(String label, String condition) {
+
+       public CPDefineCheckConstruct(File file, int beginLineNum, String label,
+                       String condition) {
+               super(file, beginLineNum);
                this.label = label;
                this.condition = condition;
        }
-       
+
        public String toString() {
                StringBuffer res = new StringBuffer();
                res.append("@Commit_point_define_check:\n");
index 7d22728..8c31a9b 100644 (file)
@@ -1,16 +1,20 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
+import java.io.File;
+
 public class CPDefineConstruct extends Construct {
        public final String label;
        public final String potentialCPLabel;
        public final String condition;
-       
-       public CPDefineConstruct(String label, String potentialCPLabel, String condition) {
+
+       public CPDefineConstruct(File file, int beginLineNum, String label,
+                       String potentialCPLabel, String condition) {
+               super(file, beginLineNum);
                this.label = label;
                this.potentialCPLabel = potentialCPLabel;
                this.condition = condition;
        }
-       
+
        public String toString() {
                StringBuffer res = new StringBuffer();
                res.append("@Potential_commit_point_define:\n");
index 4aa4fcf..373948b 100644 (file)
@@ -1,11 +1,29 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
+import java.io.File;
+
 /**
  * <p>
  * This is just an abstract class for all the constructs.
  * </p>
+ * 
  * @author peizhaoo
- *
+ * 
  */
 abstract public class Construct {
+       public final File file;
+       public final int beginLineNum;
+       public final String interfaceDeclBody;
+
+       public Construct(File file, int beginLineNum) {
+               this.file = file;
+               this.beginLineNum = beginLineNum;
+               this.interfaceDeclBody = "";
+       }
+
+       public Construct(File file, int beginLineNum, String interfaceDeclBody) {
+               this.file = file;
+               this.beginLineNum = beginLineNum;
+               this.interfaceDeclBody = interfaceDeclBody;
+       }
 }
index df9d4d6..2d13561 100644 (file)
@@ -1,6 +1,12 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
+import java.io.File;
+
 public class EntryPointConstruct extends Construct {
+       public EntryPointConstruct(File file, int beginLineNum) {
+               super(file, beginLineNum);
+       }
+
        public String toString() {
                return "@Entry_point";
        }
index c2f0efb..366dab7 100644 (file)
@@ -1,5 +1,6 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
+import java.io.File;
 import java.util.HashMap;
 import java.util.HashSet;
 
@@ -9,53 +10,60 @@ public class GlobalConstruct extends Construct {
        private final HashMap<ConditionalInterface, HashSet<ConditionalInterface>> originalHBRelations;
        public final HashMap<ConditionalInterface, HashSet<ConditionalInterface>> hbRelations;
        public final HashMap<String, String> options;
-       
-       public GlobalConstruct(SequentialDefineSubConstruct code, HashMap<String, String> options) {
+
+       public GlobalConstruct(File file, int beginLineNum,
+                       SequentialDefineSubConstruct code, HashMap<String, String> options) {
+               super(file, beginLineNum);
                this.code = code;
                this.interfaceCluster = new HashMap<String, HashSet<ConditionalInterface>>();
                this.originalHBRelations = new HashMap<ConditionalInterface, HashSet<ConditionalInterface>>();
                this.hbRelations = new HashMap<ConditionalInterface, HashSet<ConditionalInterface>>();
                this.options = options;
        }
-               
-       public void addInterface2Cluster(String clusterName, ConditionalInterface condInterface) {
+
+       public void addInterface2Cluster(String clusterName,
+                       ConditionalInterface condInterface) {
                if (!interfaceCluster.containsKey(clusterName)) {
-                       interfaceCluster.put(clusterName, new HashSet<ConditionalInterface>());
+                       interfaceCluster.put(clusterName,
+                                       new HashSet<ConditionalInterface>());
                }
                HashSet<ConditionalInterface> set = interfaceCluster.get(clusterName);
                set.add(condInterface);
        }
-       
-       public void addHBCondition(ConditionalInterface left, ConditionalInterface right) {
+
+       public void addHBCondition(ConditionalInterface left,
+                       ConditionalInterface right) {
                if (!originalHBRelations.containsKey(left)) {
                        originalHBRelations.put(left, new HashSet<ConditionalInterface>());
                }
                HashSet<ConditionalInterface> set = originalHBRelations.get(left);
                set.add(right);
        }
-       
-       private void addUnfoldedHBCondition(ConditionalInterface left, ConditionalInterface right) {
+
+       private void addUnfoldedHBCondition(ConditionalInterface left,
+                       ConditionalInterface right) {
                if (!hbRelations.containsKey(left)) {
                        hbRelations.put(left, new HashSet<ConditionalInterface>());
                }
                HashSet<ConditionalInterface> set = hbRelations.get(left);
                set.add(right);
        }
-       
-       private HashSet<ConditionalInterface> getByName(ConditionalInterface condInterface) {
+
+       private HashSet<ConditionalInterface> getByName(
+                       ConditionalInterface condInterface) {
                if (interfaceCluster.containsKey(condInterface.interfaceName))
                        return interfaceCluster.get(condInterface.interfaceName);
                HashSet<ConditionalInterface> res = new HashSet<ConditionalInterface>();
                res.add(condInterface);
                return res;
        }
-       
+
        public void unfoldInterfaceCluster() {
                for (ConditionalInterface left : originalHBRelations.keySet()) {
-                       HashSet<ConditionalInterface> rights = originalHBRelations.get(left);
+                       HashSet<ConditionalInterface> rights = originalHBRelations
+                                       .get(left);
                        for (ConditionalInterface right : rights) {
-                               HashSet<ConditionalInterface> leftCondInterfaces = getByName(left),
-                                               rightCondInterfaces = getByName(right);
+                               HashSet<ConditionalInterface> leftCondInterfaces = getByName(left), rightCondInterfaces = getByName(right);
                                for (ConditionalInterface l : leftCondInterfaces) {
                                        for (ConditionalInterface r : rightCondInterfaces) {
                                                addUnfoldedHBCondition(l, r);
@@ -64,12 +72,12 @@ public class GlobalConstruct extends Construct {
                        }
                }
        }
-       
+
        public String toString() {
                StringBuilder sb = new StringBuilder("GlobalConstruct:\n");
                sb.append("@Code:\n");
                sb.append(code);
-               
+
                sb.append("@Happens_before:\n");
                for (ConditionalInterface left : hbRelations.keySet()) {
                        HashSet<ConditionalInterface> rights = hbRelations.get(left);
@@ -79,7 +87,7 @@ public class GlobalConstruct extends Construct {
                        }
                        sb.append(".\n");
                }
-               
+
                return sb.toString();
        }
 }
index 6af7197..72e75a8 100644 (file)
@@ -1,5 +1,6 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
 
@@ -14,9 +15,11 @@ public class InterfaceConstruct extends Construct {
        public final String postAction;
        public final String postCheck;
 
-       public InterfaceConstruct(String name, ArrayList<String> commitPointSet,
-                       String condition, HashMap<String, String> hbConditions, String idCode,
-                       String check, ActionSubConstruct action, String postAction, String postCheck) {
+       public InterfaceConstruct(File file, int beginLineNum, String name,
+                       ArrayList<String> commitPointSet, String condition,
+                       HashMap<String, String> hbConditions, String idCode, String check,
+                       ActionSubConstruct action, String postAction, String postCheck) {
+               super(file, beginLineNum);
                this.name = name;
                this.commitPointSet = commitPointSet;
                this.condition = condition;
@@ -27,7 +30,7 @@ public class InterfaceConstruct extends Construct {
                this.postAction = postAction;
                this.postCheck = postCheck;
        }
-       
+
        public String toString() {
                StringBuilder sb = new StringBuilder("InterfaceConstruct:\n");
                sb.append("@Interface: " + name + "\n");
@@ -50,7 +53,7 @@ public class InterfaceConstruct extends Construct {
                sb.append("@Post_action:\n");
                sb.append(postAction + "\n");
                sb.append("@Post_check: " + postCheck + "\n");
-               
+
                return sb.toString();
        }
 }
index 920e301..8231c18 100644 (file)
@@ -1,13 +1,16 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
+import java.io.File;
+
 public class InterfaceDefineConstruct extends Construct {
        public final String name;
        private String funcDecl;
-       
-       public InterfaceDefineConstruct(String name) {
+
+       public InterfaceDefineConstruct(File file, int beginLineNum, String name) {
+               super(file, beginLineNum);
                this.name = name;
        }
-       
+
        public String toString() {
                return "@Interface_define: " + name;
        }
index 3f68610..f0eb403 100644 (file)
@@ -1,14 +1,18 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
+import java.io.File;
+
 public class PotentialCPDefineConstruct extends Construct {
        public final String label;
        public final String condition;
-       
-       public PotentialCPDefineConstruct(String label, String condition) {
+
+       public PotentialCPDefineConstruct(File file, int beginLineNum,
+                       String label, String condition) {
+               super(file, beginLineNum);
                this.label = label;
                this.condition = condition;
        }
-       
+
        public String toString() {
                StringBuffer res = new StringBuffer();
                res.append("@Potential_commit_point_define:\n");
diff --git a/src/edu/uci/eecs/specCompiler/specExtraction/SpecConstruct.java b/src/edu/uci/eecs/specCompiler/specExtraction/SpecConstruct.java
deleted file mode 100644 (file)
index e80cbd7..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-package edu.uci.eecs.specCompiler.specExtraction;
-
-import java.io.File;
-
-/**
- * <p>
- * This class represents the plain context for each specification construct.
- * Besides, it also stores some useful information such as interfaceDeclBody,
- * which is used in @Interface construct to wrap and rename interface calls.
- * </p>
- * @author peizhaoo
- *
- */
-public class SpecConstruct {
-       public final String plainText;
-       public final File file;
-       public final int beginLineNum;
-       public final int endLineNum;
-       public final String interfaceDeclBody;
-       public final Construct construct;
-       
-       public SpecConstruct(String plainText, File file,
-                       int beginLineNum, int endLineNum, Construct construct) {
-               this.plainText = plainText;
-               this.file = file;
-               this.beginLineNum = beginLineNum;
-               this.endLineNum = endLineNum;
-               this.construct = construct;
-               this.interfaceDeclBody = ""; 
-       }
-       
-       public SpecConstruct(String plainText, File file,
-                       int beginLineNum, int endLineNum, Construct construct,
-                       String interfaceDeclBody) {
-               this.plainText = plainText;
-               this.file = file;
-               this.beginLineNum = beginLineNum;
-               this.endLineNum = endLineNum;
-               this.construct = construct;
-               this.interfaceDeclBody = interfaceDeclBody; 
-       }
-       
-       public String toString() {
-               StringBuilder sb = new StringBuilder();
-               sb.append("File: " + file.getAbsolutePath() + "\n");
-               sb.append("Begin: "
-                               + beginLineNum + "  End: " + endLineNum + "\n");
-               sb.append(construct);
-               if (construct instanceof InterfaceConstruct
-                               || construct instanceof InterfaceDefineConstruct) {
-                       sb.append("Function declaration: " + interfaceDeclBody);
-               }
-               return sb.toString();
-               
-       }
-}
diff --git a/src/edu/uci/eecs/specCompiler/specExtraction/SpecConstructInfo.java b/src/edu/uci/eecs/specCompiler/specExtraction/SpecConstructInfo.java
deleted file mode 100644 (file)
index 23a905d..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-package edu.uci.eecs.specCompiler.specExtraction;
-
-public class SpecConstructInfo {
-       
-}
index 58b463f..1286a14 100644 (file)
@@ -24,12 +24,16 @@ import edu.uci.eecs.specCompiler.grammerParser.TokenMgrError;
  * 
  */
 public class SpecExtractor {
-       private ArrayList<SpecConstruct> _constructs;
+       private ArrayList<Construct> _constructs;
        private int _beginLineNum, _endLineNum;
        private String _beginLine;
 
        public SpecExtractor() {
-               _constructs = new ArrayList<SpecConstruct>();
+               _constructs = new ArrayList<Construct>();
+       }
+       
+       ArrayList<Construct> getConstructs() {
+               return this._constructs;
        }
 
        /**
@@ -41,127 +45,14 @@ public class SpecExtractor {
         * @param files
         * @throws SpecNotMatchException
         */
-       public void extract(File[] files) throws SpecNotMatchException {
+       public void extract(File[] files) {
                for (int i = 0; i < files.length; i++)
                        extract(files[i]);
        }
 
-       public void extract(File file) throws SpecNotMatchException {
+       public void extract(File file) {
                StringBuilder specText = new StringBuilder();
-               try {
-                       LineNumberReader reader = new LineNumberReader(new FileReader(file));
-                       String prevLine = "", curLine, trimedLine, funcDecl;
-                       SpecConstruct specConstruct;
-                       boolean foundHead = false;
-                       while ((curLine = reader.readLine()) != null) {
-                               if (prevLine.endsWith("\\"))
-                                       continue;
-                               trimedLine = trimSpace(curLine);
-                               if (!foundHead) {
-                                       if (trimedLine.startsWith("/**")) {
-                                               _beginLineNum = reader.getLineNumber();
-                                               _beginLine = curLine;
-                                               foundHead = true;
-                                               specText.append("\n");
-                                               specText.append(curLine);
-                                               if (trimedLine.endsWith("*/")) {
-                                                       _endLineNum = reader.getLineNumber();
-                                                       foundHead = false;
-                                                       if (isComment(specText.toString()))
-                                                               continue;
-                                                       Construct inst = SpecParser.parseSpec(specText
-                                                                       .toString());
-                                                       if (inst instanceof InterfaceConstruct
-                                                                       || inst instanceof InterfaceDefineConstruct) {
-                                                               funcDecl = readFunctionDecl(reader);
-                                                               specConstruct = new SpecConstruct(
-                                                                               specText.toString(), file,
-                                                                               _beginLineNum, _endLineNum, inst,
-                                                                               funcDecl);
-                                                       } else {
-                                                               specConstruct = new SpecConstruct(
-                                                                               specText.toString(), file,
-                                                                               _beginLineNum, _endLineNum, inst);
-                                                       }
-                                                       _constructs.add(specConstruct);
-                                                       specText = new StringBuilder();
-                                                       // System.out.println(specConstruct);
-                                               }
-                                       }
-                               } else {
-                                       specText.append("\n");
-                                       specText.append(curLine);
-                                       if (trimedLine.endsWith("*/")) {
-                                               _endLineNum = reader.getLineNumber();
-                                               foundHead = false;
-                                               if (isComment(specText.toString())) {
-                                                       specText = new StringBuilder();
-                                                       continue;
-                                               }
-                                               Construct inst = SpecParser.parseSpec(specText
-                                                               .toString());
-                                               if (inst instanceof InterfaceConstruct
-                                                               || inst instanceof InterfaceDefineConstruct) {
-                                                       funcDecl = readFunctionDecl(reader);
-                                                       specConstruct = new SpecConstruct(
-                                                                       specText.toString(), file, _beginLineNum,
-                                                                       _endLineNum, inst, funcDecl);
-                                               } else {
-                                                       specConstruct = new SpecConstruct(
-                                                                       specText.toString(), file, _beginLineNum,
-                                                                       _endLineNum, inst);
-                                               }
-                                               _constructs.add(specConstruct);
-                                               specText = new StringBuilder();
-                                               // System.out.println(specConstruct);
-                                       }
-                               }
-                       }
-                       // At the end we can only find the head "/**" but no tail found
-                       if (foundHead) {
-                               String msg = "In file \"" + file.getAbsolutePath()
-                                               + "\", line: " + _beginLineNum + "\n" + _beginLine
-                                               + "\n" + "Can't find matching spec.";
-                               throw new SpecNotMatchException(msg);
-                       }
-               } catch (FileNotFoundException e) {
-                       e.printStackTrace();
-               } catch (IOException e) {
-                       e.printStackTrace();
-               } catch (ParseException e) {
-                       printSpecInfo(file, specText.toString());
-                       e.printStackTrace();
-               } catch (TokenMgrError e) {
-                       printSpecInfo(file, specText.toString());
-                       e.printStackTrace();
-               }
-       }
-
-       private void printSpecInfo(File file, String text) {
-               System.out.println("Error in spec!");
-               System.out.println("File: " + file.getAbsolutePath());
-               System.out.println("Begin: " + _beginLineNum + "  End: " + _endLineNum);
-               System.out.println(text);
-       }
-
-       private boolean isComment(String specText) {
-               if (specText.indexOf("@Begin") != -1)
-                       return false;
-               return true;
-       }
-
-       private String readFunctionDecl(LineNumberReader reader) throws IOException {
-               String res = "", curLine;
-               while ((curLine = reader.readLine()) != null) {
-                       int braceIdx = curLine.indexOf(')');
-                       if (braceIdx == -1) {
-                               res = res + " " + curLine;
-                       } else {
-                               res = res + curLine;
-                               break;
-                       }
-               }
-               return res;
+               
        }
 
        public static String trimSpace(String line) {
@@ -182,18 +73,4 @@ public class SpecExtractor {
                else
                        return line.substring(i, j + 1);
        }
-
-       public ArrayList<SpecConstruct> getConstructs() {
-               return this._constructs;
-       }
-
-       public static void main(String[] argvs) {
-               SpecExtractor extractor = new SpecExtractor();
-               File file = new File("./grammer/spec1.txt");
-               try {
-                       extractor.extract(file);
-               } catch (SpecNotMatchException e) {
-                       e.printStackTrace();
-               }
-       }
 }
diff --git a/src/edu/uci/eecs/specCompiler/specExtraction/SpecNotMatchException.java b/src/edu/uci/eecs/specCompiler/specExtraction/SpecNotMatchException.java
deleted file mode 100644 (file)
index cf3ce52..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package edu.uci.eecs.specCompiler.specExtraction;
-
-import java.io.File;
-
-public class SpecNotMatchException extends Exception {
-       public SpecNotMatchException(String msg) {
-               super(msg);
-       }
-}
diff --git a/test.c b/test.c
deleted file mode 100644 (file)
index ebb88e0..0000000
--- a/test.c
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <stdio.h>
-#include <stddef.h>
-
-struct pair {
-       int x, y;
-};
-
-int func() {
-       return 3;
-}
-
-int main() {
-       int b;
-       b = (int a = func());
-       return 0;
-}
diff --git a/test.cc b/test.cc
new file mode 100644 (file)
index 0000000..e69de29