more
[cdsspec-compiler.git] / grammer / spec_compiler.jj
index 93a5d8b07f7985553c9439a2601a73d3a1770ab2..cbe2e28d6240ab8a6853df36d0c68c7d647ce15a 100644 (file)
@@ -30,7 +30,7 @@
        
        b) Interface construct
        @Begin
-       @Interface: ...
+       @Interface_decl: ...
        @Commit_point_set:
                IDENTIFIER | IDENTIFIER ...
        @Condition: ... (Optional)
        @Begin
        @Interface_define: <Interface_Name>
        @End
+
+       g) Interface declare & define construct
+       @Begin
+       @Interface_decl_define: <Interface_Name>
+       @Commit_point_set:
+               IDENTIFIER | IDENTIFIER ...
+       @Condition: ... (Optional)
+       @HB_Condition:
+               IDENTIFIER :: <C_CPP_Condition>
+       @HB_Condition: ...
+       @ID: ... (Optional, use default ID)
+       @Check: (Optional)
+               ...
+       @Action: (Optional)
+               ...
+       @Post_action: (Optional)
+       @Post_check: (Optional)
+       @End
+
 */
 
 
@@ -179,6 +198,8 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
 
                public static String stringArray2String(ArrayList<String> content) {
                        StringBuilder sb = new StringBuilder();
+                       if (content.size() == 1)
+                               return content.get(0);
                        for (int i = 0; i < content.size(); i++) {
                                sb.append(content.get(i) + "\n");
                        }
@@ -309,6 +330,10 @@ SKIP : {
        <UNSIGNED: "unsigned">
 |
        <TEMPLATE: "template">
+|
+       <INLINE: "inline">
+|
+       <STATIC: "static">
 |
        <#DIGIT: ["0"-"9"]>
 |
@@ -386,6 +411,29 @@ SKIP : {
        <COLON: ":">
 |
        <DOUBLECOLON: "::">
+|
+       <DOUBLELESSTHAN: "<<">
+|
+       <DOUBLEGREATERTHAN: ">>">
+|
+       <TRIPLEGREATERTHAN: ">>>">
+|
+       <PLUS_EQUALS: "+=">
+|
+       <MINUS_EQUALS: "-=">
+|
+       <TIMES_EQUALS: "*=">
+|
+       <DIVIDE_EQUALS: "/=">
+|
+       <MOD_EQUALS: "%=">
+|
+       <XOR_EQUALS: "^=">
+|
+       <OR_EQUALS: "|=">
+|
+       <AND_EQUALS: "&=">
+
 |
        <SEMI_COLON: ";">
 |
@@ -514,7 +562,6 @@ void Test() :
        {
                System.out.println(func);
        }
-
        
 }
 
@@ -525,8 +572,8 @@ String ParameterizedName() :
 }
 {
        (str = <IDENTIFIER>.image {res = str;})
-       ("<" str = <IDENTIFIER>.image { res = res + "<" + str; }
-       ("," str = <IDENTIFIER>.image { res = res + ", " + str; })* ">"
+       ("<" str = Type() { res = res + "<" + str; }
+       ("," str = Type() { res = res + ", " + str; })* ">"
        { res = res + ">"; }
        )?
        {
@@ -536,11 +583,14 @@ String ParameterizedName() :
 
 FunctionHeader FuncDecl() :
 {
+       ArrayList<VariableDeclaration> templateList;
        String ret;
        QualifiedName funcName;
        ArrayList<VariableDeclaration> args;
 }
 {
+aa
+       (<STATIC> | <INLINE>)*
        ret = Type() 
        funcName = ParseQualifiedName() 
        args = FormalParamList() 
@@ -567,22 +617,31 @@ QualifiedName ParseQualifiedName() :
        }
 }
 
-ArrayList<String> TemplateParamList() :
+ArrayList<VariableDeclaration> TemplateParamList() :
 {
-       ArrayList<String> params;
-       String str;
+       ArrayList<VariableDeclaration> params;
+       String type;
+       String name;
 }
 {
        {
-               params = new ArrayList<String>();
+               params = new ArrayList<VariableDeclaration>();
        }
        <TEMPLATE>
        "<"
-       (str = <IDENTIFIER>.image 
-       str = <IDENTIFIER>.image {params.add(str);})
+       (type = <IDENTIFIER>.image 
+       name = <IDENTIFIER>.image
+       {
+               params.add(new VariableDeclaration(type, name));
+       }
+       )
 
-       ("," str = <IDENTIFIER>.image 
-       str = <IDENTIFIER>.image {params.add(str);})*
+       ("," type = <IDENTIFIER>.image 
+       name = <IDENTIFIER>.image
+       {
+               params.add(new VariableDeclaration(type, name));
+       }
+       )*
        ">"
        {
                //System.out.println(params);
@@ -639,6 +698,7 @@ ArrayList<String> C_CPP_CODE(ArrayList<String> headers) :
        (
        t = <CONST> | t = <STRUCT> | t = <CLASS> | t = <UNSIGNED> |
        (t = <TEMPLATE> { inTemplate = true;  })|
+       t = <STATIC> | t = <INLINE> |
        (t = <INCLUDE>
        {
                header = t.image;
@@ -660,17 +720,35 @@ ArrayList<String> C_CPP_CODE(ArrayList<String> headers) :
        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 = <DOUBLELESSTHAN> | 
+       t = <DOUBLEGREATERTHAN> |
+       t = <TRIPLEGREATERTHAN> | 
+
+       t = <PLUS_EQUALS> |
+       t = <MINUS_EQUALS> |
+       t = <TIMES_EQUALS> |
+       t = <DIVIDE_EQUALS> |
+       t = <MOD_EQUALS> |
+       t = <XOR_EQUALS> |
+       t = <OR_EQUALS> |
+       t = <AND_EQUALS> |
+
        (t = <SEMI_COLON> { newLine = true; } )
        | t = <STRING_LITERAL> | t = <CHARACTER_LITERAL> |
        t = <INTEGER_LITERAL> | t = <FLOATING_POINT_LITERAL> |
        (t = <DEFINE> { newLine = true; } )
        )
        {
-               text = text + " " + t.image;
+               if (text.equals("")) {
+                       text = t.image;
+               } else {
+                       text = text + " " + t.image;
+               }
                if (newLine) {
                        content.add(text);
                        text = "";
                        newLine = false;
+                       inTemplate = false;
                }
        }
        )+
@@ -798,8 +876,8 @@ ConditionalInterface Conditional_interface() :
        {
                hbConditionLabel = "";
        }
-       interfaceName = <IDENTIFIER>.image (<OPEN_BRACKET> hbConditionLabel =
-       <IDENTIFIER>.image <CLOSE_BRACKET>)?
+       interfaceName = <IDENTIFIER>.image (<OPEN_PAREN> hbConditionLabel =
+       <IDENTIFIER>.image <CLOSE_PAREN>)?
        {
                return new ConditionalInterface(interfaceName, hbConditionLabel);
        }
@@ -812,14 +890,14 @@ void Interface_cluster(GlobalConstruct inst) :
 }
 {
        (clusterName= <IDENTIFIER>.image)
-       <EQUALS> <OPEN_PAREN>
+       <EQUALS> <OPEN_BRACE>
                (condInterface = Conditional_interface()
                { inst.addInterface2Cluster(clusterName, condInterface); } 
                )
                (<COMMA> condInterface = Conditional_interface()
                { inst.addInterface2Cluster(clusterName, condInterface); } 
                )*
-       <CLOSE_PAREN>
+       <CLOSE_BRACE>
 }
 
 void Interface_clusters(GlobalConstruct inst) :
@@ -882,7 +960,7 @@ InterfaceConstruct Interface() :
                        (<CONDITION> (content = C_CPP_CODE(null) { condition = stringArray2String(content); }))?
                        (
                                <HB_CONDITION>
-                               (hbLabel = <IDENTIFIER>.image)
+                               (hbLabel = <IDENTIFIER>.image) <DOUBLECOLON>
                                (content = C_CPP_CODE(null) { hbCondition = stringArray2String(content); })
                                {
                                        if (hbConditions.containsKey(hbLabel)) {