Updates to grammar...
authorbdemsky <bdemsky>
Thu, 8 Jul 2004 03:50:19 +0000 (03:50 +0000)
committerbdemsky <bdemsky>
Thu, 8 Jul 2004 03:50:19 +0000 (03:50 +0000)
Repair/RepairCompiler/MCC/CDL.cup
Repair/RepairCompiler/MCC/IR/SemanticChecker.java
Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java
Repair/RepairCompiler/MCC/IR/TypeDescriptor.java
Repair/RepairCompiler/MCC/Lexer.lex
Repair/RepairCompiler/MCC/MDL.cup
Repair/RepairCompiler/MCC/SDL.cup
Repair/RepairCompiler/MCC/TDL.cup

index 4206e84c543a9f0109e2661091651b3eccd0ece4..2f7f2daa4f08e5da2e73de250d8fe7bd101e2ed5 100755 (executable)
@@ -175,6 +175,7 @@ parser code {:
     terminal LABEL;
     terminal INT;
     terminal SUBTYPE;
+    terminal SUBCLASS;
     terminal OF;
 
     terminal SEMICOLON;
index c35feaf168cd07e13dc7ea3de39ef14469a4f307..4dacc0b5ce2a48622e82004a93de45d912ef8d18 100755 (executable)
@@ -1070,6 +1070,19 @@ public class SemanticChecker {
 
             /* lookup the type to get the type descriptor */
             type.setSuperType(lookupType(subtype, CREATE_MISSING));
+        } else if (pn.getChild("subclass") != null) {
+            // has a subtype, lets try to resolve it
+            String subclass = pn.getChild("subclass").getTerminal();
+           
+            if (subclass.equals(typename)) {
+                // Semantic Error: cyclic inheritance
+                er.report(pn, "Cyclic inheritance prohibited");
+                ok = false;
+            }
+
+            /* lookup the type to get the type descriptor */
+            type.setSuperType(lookupType(subclass, CREATE_MISSING));
+            type.setSubClass(true);
         }
 
         // set the current type so that the recursive parses on the labels
index 347d1f9c7bba8a1483e8cb56659d0fcc38f671ef..4a2b55a0520c4000d1d4e74747a7896efd4d94f8 100755 (executable)
@@ -29,6 +29,10 @@ public class StructureTypeDescriptor extends TypeDescriptor {
         return fields.keys();
     }
     
+    public void setSubClass(boolean b) {
+       this.subclass=b;
+    }
+
     public Expr getSizeExpr() {
         return getOffsetExpr(null);
     }
index f71fe4f1d572c5d2f67610401081f4f3e1222c7b..6609229d5bcc49cec6a7918cc07044509ab1a486 100755 (executable)
@@ -9,6 +9,8 @@ package MCC.IR;
 public abstract class TypeDescriptor extends Descriptor {
     static int counter=0;
     int idnum;
+    boolean subclass;
+
 
     public int getId() {
        return idnum;
@@ -18,6 +20,7 @@ public abstract class TypeDescriptor extends Descriptor {
         super(name);
        if (!(this instanceof MissingTypeDescriptor))
            idnum=counter++;
+       subclass=false;
     }
 
     public boolean isSubtypeOf(TypeDescriptor td) {
index 6e630c00fc2e3597f08829bd92d2975897b156fb..ed6f239116dea1aafa0a1b99baa6df03a8a628d8 100755 (executable)
@@ -82,6 +82,7 @@ CHAR=(\\\"|\\\'|\\\\|\\t|\\n|[\x20-\x21\x23-\x26\x28-\x5B\x5D-\x7E])
 <YYINITIAL> byte                        { return tok(Sym.BYTE, yytext()); }
 
 <YYINITIAL> subtype                    { return tok(Sym.SUBTYPE, yytext()); }
+<YYINITIAL> subclass                   { return tok(Sym.SUBCLASS, yytext()); }
 <YYINITIAL> of                                 { return tok(Sym.OF, yytext()); }
 
 <YYINITIAL> ";"                                { return tok(Sym.SEMICOLON, yytext()); }
index c7b00d00a93d4b00ed9974f6b85fffef505c6713..54d3aebe05e34a7a963f5f9c4b9f4c31c298ddd8 100755 (executable)
@@ -181,6 +181,7 @@ parser code {:
     terminal LABEL;
     terminal INT;
     terminal SUBTYPE;
+    terminal SUBCLASS;
     terminal OF;
 
     terminal SEMICOLON;
index 9792ebd120d10047c3c2d14a0ed13ea85c042530..be328fec4ae7f284858b6429a3ca016c2c0dbb39 100755 (executable)
@@ -164,6 +164,7 @@ parser code {:
     terminal LABEL;
     terminal INT;
     terminal SUBTYPE;
+    terminal SUBCLASS;
     terminal OF;
 
     terminal SEMICOLON;
index 5fbed22b42544fdce28ea296166925329303559b..0ae3eb5765e778e633011f0dae3d82effa106869 100755 (executable)
@@ -162,6 +162,7 @@ parser code {:
     terminal LABEL;
     terminal INT;
     terminal SUBTYPE;
+    terminal SUBCLASS;
     terminal OF;
 
     terminal SEMICOLON;
@@ -256,7 +257,7 @@ structure ::=
        ;
 
 optsubtype ::= 
-          
+               /* subtype */
        SUBTYPE OF ID:type
        {:
        debugMessage(PRODSTRING);
@@ -264,6 +265,16 @@ optsubtype ::=
        subtype.addChild(type);
        RESULT = subtype;
        :}
+
+       | /* subclass */
+
+       SUBCLASS OF ID:type
+       {:
+       debugMessage(PRODSTRING);
+       ParseNode subtype = new ParseNode("subclass", parser.curLine(3));
+       subtype.addChild(type);
+       RESULT = subtype;
+       :}
        
        | /* nothing */
        {: