From 24d5c10e5f7209bea568976aa9ba30059e51f007 Mon Sep 17 00:00:00 2001
From: Anders Nilsson <anders.nilsson@cs.lth.se>
Date: Sun, 12 Nov 2006 22:43:21 +0100
Subject: [PATCH] JavaCC generation almost(?) complete

---
 CompilerGeneration.jrag | 49 +++++++++++++++++++++++++----------------
 Misc.jrag               |  6 +++++
 Types.jrag              | 21 ++++++++++++++++++
 3 files changed, 57 insertions(+), 19 deletions(-)
 create mode 100644 Misc.jrag

diff --git a/CompilerGeneration.jrag b/CompilerGeneration.jrag
index 6733e0c..572f1b6 100644
--- a/CompilerGeneration.jrag
+++ b/CompilerGeneration.jrag
@@ -1,6 +1,7 @@
 /* -*-Java-*- */
 
 import java.io.*;
+import java.util.*;
 
 aspect AbsGrammarGeneration {
     void ASTNode.genAbsGrammar(PrintStream pStream) {
@@ -138,25 +139,35 @@ aspect JavaCCGen {
 		pStream.println("void "+getId()+"() : {}");
 		pStream.println("{");
 		if (getId().equals("Device")) {
-			pStream.print("\"<\" ( <DEVICE> \">\"");
-			Restrictions restr = getRestrictions();
-			for (int i=0; i< getNumRestriction(); i++) {
-				OwlRestriction res = restr.getOwlRestriction(i);
-				pStream.print("("+res.getRestrictionClassId()+")"+
-							  (res.allValuesFrom()?"*":"")+" ");
-			}
-			pStream.println(" #Device("+getNumRestriction()+")");
-			// List all subclasses
-			pStream.println(")");
-		} else {
-			pStream.print(" <"+getId().toUpperCase()+"> \">\"");
-			Restrictions restr = getRestrictions();
-			for (int i=0; i< getNumRestriction(); i++) {
-				OwlRestriction res = restr.getOwlRestriction(i);
-				pStream.print("("+res.getRestrictionClassId()+")"+
-							  (res.allValuesFrom()?"*":"")+" ");
-			}
-			pStream.println(" #"+getId()+"("+getNumRestriction()+")");
+			pStream.print("  \"<\"");
+// 			pStream.print("\"<\" ( <DEVICE> \">\"");
+// 			Restrictions restr = getRestrictions();
+// 			for (int i=0; i< getNumRestriction(); i++) {
+// 				OwlRestriction res = restr.getOwlRestriction(i);
+// 				pStream.print("("+res.getRestrictionClassId()+")"+
+// 							  (res.allValuesFrom()?"*":"")+" ");
+// 			}
+// 			pStream.println(" #Device("+getNumRestriction()+"))");
+// 			// List all subclasses
+// 			Iterator subIter = getSubClasses().iterator();
+// 			while (subIter.hasNext()) {
+// 				OwlClassDecl subClass = (OwlClassDecl) subIter.next();
+// 				pStream.println("| "+subClass.getId()+"()");
+// 			}
+		}
+		pStream.print("  ( <"+getId().toUpperCase()+"> \">\"");
+		Restrictions restr = getRestrictions();
+		for (int i=0; i< getNumRestriction(); i++) {
+			OwlRestriction res = restr.getOwlRestriction(i);
+			pStream.print("("+res.getRestrictionClassId()+")"+
+						  (res.allValuesFrom()?"*":"")+" ");
+		}
+		pStream.println(" #"+getId()+"("+getNumRestriction()+"))");
+		// List all subclasses
+		Iterator subIter = getSubClasses().iterator();
+		while (subIter.hasNext()) {
+			OwlClassDecl subClass = (OwlClassDecl) subIter.next();
+			pStream.println("      | "+subClass.getId()+"()");
 		}
 		pStream.println("}");
 	}
diff --git a/Misc.jrag b/Misc.jrag
new file mode 100644
index 0000000..a9d0f4a
--- /dev/null
+++ b/Misc.jrag
@@ -0,0 +1,6 @@
+/* -*-Java-*- */
+
+aspect Misc {
+	syn Start ASTNode.goStart() = getParent().goStart();
+	eq Start.goStart() = this;
+}
diff --git a/Types.jrag b/Types.jrag
index 74579da..02ede7c 100644
--- a/Types.jrag
+++ b/Types.jrag
@@ -1,5 +1,7 @@
 /* -*-Java-*- */
 
+import java.util.ArrayList;
+
 aspect Types {
     syn lazy OClass OClass.getSuperClass();
     eq OwlClassDecl.getSuperClass() {
@@ -51,6 +53,25 @@ aspect Types {
 		// 	}
 		// 	return p;
     }
+
+	syn lazy ArrayList OClass.getSubClasses();
+	eq OwlClassUse.getSubClasses() = decl().getSubClasses();
+	eq OwlClassDecl.getSubClasses() {
+		return goStart().getSubClasses(this,new ArrayList());
+	}
+
+	syn ArrayList ASTNode.getSubClasses(OwlClassDecl klass, ArrayList l) {
+		for (int i=0; i<getNumChild(); i++) {
+			getChild(i).getSubClasses(klass,l);
+		}
+		return l;
+	}
+	eq OwlClassDecl.getSubClasses(OwlClassDecl klass, ArrayList l) {
+		if (getSuperClass() == klass) {
+			l.add(this);
+		}
+		return l;
+	}
 }
 
 aspect Restrictions {
-- 
GitLab