From ae1c5d0f1437a7d822094c172780b116329f0d97 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 8 Jul 2004 03:50:19 +0000 Subject: [PATCH] Updates to grammar... --- Repair/RepairCompiler/MCC/CDL.cup | 1 + Repair/RepairCompiler/MCC/IR/SemanticChecker.java | 13 +++++++++++++ .../MCC/IR/StructureTypeDescriptor.java | 4 ++++ Repair/RepairCompiler/MCC/IR/TypeDescriptor.java | 3 +++ Repair/RepairCompiler/MCC/Lexer.lex | 1 + Repair/RepairCompiler/MCC/MDL.cup | 1 + Repair/RepairCompiler/MCC/SDL.cup | 1 + Repair/RepairCompiler/MCC/TDL.cup | 13 ++++++++++++- 8 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Repair/RepairCompiler/MCC/CDL.cup b/Repair/RepairCompiler/MCC/CDL.cup index 4206e84..2f7f2da 100755 --- a/Repair/RepairCompiler/MCC/CDL.cup +++ b/Repair/RepairCompiler/MCC/CDL.cup @@ -175,6 +175,7 @@ parser code {: terminal LABEL; terminal INT; terminal SUBTYPE; + terminal SUBCLASS; terminal OF; terminal SEMICOLON; diff --git a/Repair/RepairCompiler/MCC/IR/SemanticChecker.java b/Repair/RepairCompiler/MCC/IR/SemanticChecker.java index c35feaf..4dacc0b 100755 --- a/Repair/RepairCompiler/MCC/IR/SemanticChecker.java +++ b/Repair/RepairCompiler/MCC/IR/SemanticChecker.java @@ -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 diff --git a/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java b/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java index 347d1f9..4a2b55a 100755 --- a/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java +++ b/Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java @@ -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); } diff --git a/Repair/RepairCompiler/MCC/IR/TypeDescriptor.java b/Repair/RepairCompiler/MCC/IR/TypeDescriptor.java index f71fe4f..6609229 100755 --- a/Repair/RepairCompiler/MCC/IR/TypeDescriptor.java +++ b/Repair/RepairCompiler/MCC/IR/TypeDescriptor.java @@ -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) { diff --git a/Repair/RepairCompiler/MCC/Lexer.lex b/Repair/RepairCompiler/MCC/Lexer.lex index 6e630c0..ed6f239 100755 --- a/Repair/RepairCompiler/MCC/Lexer.lex +++ b/Repair/RepairCompiler/MCC/Lexer.lex @@ -82,6 +82,7 @@ CHAR=(\\\"|\\\'|\\\\|\\t|\\n|[\x20-\x21\x23-\x26\x28-\x5B\x5D-\x7E]) byte { return tok(Sym.BYTE, yytext()); } subtype { return tok(Sym.SUBTYPE, yytext()); } + subclass { return tok(Sym.SUBCLASS, yytext()); } of { return tok(Sym.OF, yytext()); } ";" { return tok(Sym.SEMICOLON, yytext()); } diff --git a/Repair/RepairCompiler/MCC/MDL.cup b/Repair/RepairCompiler/MCC/MDL.cup index c7b00d0..54d3aeb 100755 --- a/Repair/RepairCompiler/MCC/MDL.cup +++ b/Repair/RepairCompiler/MCC/MDL.cup @@ -181,6 +181,7 @@ parser code {: terminal LABEL; terminal INT; terminal SUBTYPE; + terminal SUBCLASS; terminal OF; terminal SEMICOLON; diff --git a/Repair/RepairCompiler/MCC/SDL.cup b/Repair/RepairCompiler/MCC/SDL.cup index 9792ebd..be328fe 100755 --- a/Repair/RepairCompiler/MCC/SDL.cup +++ b/Repair/RepairCompiler/MCC/SDL.cup @@ -164,6 +164,7 @@ parser code {: terminal LABEL; terminal INT; terminal SUBTYPE; + terminal SUBCLASS; terminal OF; terminal SEMICOLON; diff --git a/Repair/RepairCompiler/MCC/TDL.cup b/Repair/RepairCompiler/MCC/TDL.cup index 5fbed22..0ae3eb5 100755 --- a/Repair/RepairCompiler/MCC/TDL.cup +++ b/Repair/RepairCompiler/MCC/TDL.cup @@ -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 */ {: -- 2.34.1