[Swift-commit] r2977 - in trunk: src/org/griphyn/vdl/engine tests/language-behaviour

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Wed Jun 24 15:18:32 CDT 2009


Author: benc
Date: 2009-06-24 15:18:32 -0500 (Wed, 24 Jun 2009)
New Revision: 2977

Added:
   trunk/tests/language-behaviour/0013-out-of-order.out.expected
   trunk/tests/language-behaviour/0013-out-of-order.swift
Modified:
   trunk/src/org/griphyn/vdl/engine/Karajan.java
Log:
split the declaration of variables into two stages: a stage where the
name and type are put in the scope symbol tables, and a stage where the
mapping expression (if it exists) is processed and variable template is
generated.

this is needed to allow global variables to be known before procedures
are processed.

Modified: trunk/src/org/griphyn/vdl/engine/Karajan.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/Karajan.java	2009-06-24 20:17:48 UTC (rev 2976)
+++ trunk/src/org/griphyn/vdl/engine/Karajan.java	2009-06-24 20:18:32 UTC (rev 2977)
@@ -173,6 +173,8 @@
 			}
 		}
 		
+		statementsForSymbols(prog, scope);
+
 		// Keep track of declared procedures
 		for (int i = 0; i < prog.sizeOfProcedureArray(); i++) {
 			Procedure proc = prog.getProcedureArray(i);
@@ -231,6 +233,7 @@
 		else {			
 			VariableScope compoundScope = new VariableScope(this, innerScope);
 			compoundScope.bodyTemplate = procST;
+			statementsForSymbols(proc, compoundScope);		
 			statements(proc, compoundScope);		
 		}			
 	}
@@ -247,12 +250,17 @@
 		return paramST;
 	}
 
+	public void variableForSymbol(Variable var, VariableScope scope) throws CompilationException {
+
+		checkIsTypeDefined(var.getType().getLocalPart());
+		scope.addVariable(var.getName(), var.getType().getLocalPart());
+	}
+
 	public void variable(Variable var, VariableScope scope) throws CompilationException {
 		StringTemplate variableST = template("variable");
 		variableST.setAttribute("name", var.getName());
 		variableST.setAttribute("type", var.getType().getLocalPart());
-
-		checkIsTypeDefined(var.getType().getLocalPart());
+		
 		if(!var.isNil()) {
 
 			if (var.getFile() != null) {
@@ -323,8 +331,8 @@
 			variableST.setAttribute("mapping", mappingST);
 			variableST.setAttribute("nil", Boolean.TRUE);
 		}
+
 		scope.bodyTemplate.setAttribute("declarations", variableST);
-		scope.addVariable(var.getName(), var.getType().getLocalPart());
 	}
 
 	void checkIsTypeDefined(String type) throws CompilationException {		
@@ -363,6 +371,15 @@
 		}
 	}
 
+	public void statementsForSymbols(XmlObject prog, VariableScope scope) throws CompilationException {
+		XmlCursor cursor = prog.newCursor();
+		cursor.selectPath("*");
+		while (cursor.toNextSelection()) {
+			XmlObject child = cursor.getObject();
+			statementForSymbol(child, scope);
+		}
+	}
+
 	public void statements(XmlObject prog, VariableScope scope) throws CompilationException {
 		XmlCursor cursor = prog.newCursor();
 		cursor.selectPath("*");
@@ -372,6 +389,26 @@
 		}
 	}
 
+	public void statementForSymbol(XmlObject child, VariableScope scope) throws CompilationException {
+		if (child instanceof Variable) {
+			variableForSymbol((Variable) child, scope);
+		}
+		else if (child instanceof Assign
+			|| child instanceof Call
+			|| child instanceof Foreach
+			|| child instanceof Iterate
+			|| child instanceof If
+			|| child instanceof Switch
+			|| child instanceof Procedure
+			|| child instanceof Types
+			|| child instanceof FormalParameter) {
+			// ignore these - they're expected but we don't need to
+			// do anything for them here
+		} else {
+			throw new CompilationException("Unexpected element in XML. Implementing class "+child.getClass()+", content "+child);
+		}
+	}
+
 	public void statement(XmlObject child, VariableScope scope) throws CompilationException {
 		if (child instanceof Variable) {
 			variable((Variable) child, scope);
@@ -402,6 +439,7 @@
 		}
 	}
 
+
 	public StringTemplate call(Call call, VariableScope scope, boolean inhibitOutput) throws CompilationException {
 		try {
 			// Check is called procedure declared previously 
@@ -588,6 +626,7 @@
 		iterateST.setAttribute("var", iterate.getVar());
 		innerScope.bodyTemplate = iterateST;
 
+		statementsForSymbols(iterate.getBody(), innerScope);
 		statements(iterate.getBody(), innerScope);
 
 		XmlObject cond = iterate.getAbstractExpression();
@@ -627,6 +666,7 @@
 
 			innerScope.bodyTemplate = foreachST;
 
+			statementsForSymbols(foreach.getBody(), innerScope);
 			statements(foreach.getBody(), innerScope);
 
 			Object statementID = new Integer(callID++);
@@ -656,6 +696,7 @@
 		innerThenScope.bodyTemplate = template("sub_comp");
 		ifST.setAttribute("vthen", innerThenScope.bodyTemplate);
 
+		statementsForSymbols(thenstat, innerThenScope);
 		statements(thenstat, innerThenScope);
 
 		Object statementID = new Integer(callID++);
@@ -672,6 +713,7 @@
 			innerElseScope.bodyTemplate = template("sub_comp");
 			ifST.setAttribute("velse", innerElseScope.bodyTemplate);
 
+			statementsForSymbols(elsestat, innerElseScope);
 			statements(elsestat, innerElseScope);
 
 			Iterator elseScopeIterator = innerElseScope.getVariableIterator();
@@ -714,6 +756,7 @@
 			VariableScope defaultScope = new VariableScope(this, scope);
 			defaultScope.bodyTemplate = template("sub_comp");
 			switchST.setAttribute("sdefault", defaultScope.bodyTemplate);
+			statementsForSymbols(defaultstat, defaultScope);
 			statements(defaultstat, defaultScope);
 			Iterator defaultScopeIterator = defaultScope.getVariableIterator();
 			while(defaultScopeIterator.hasNext()) {
@@ -726,6 +769,7 @@
 	public void caseStat(Case casestat, VariableScope scope) throws CompilationException {
 		StringTemplate valueST = expressionToKarajan(casestat.getAbstractExpression(), scope);
 		scope.bodyTemplate.setAttribute("value", valueST.toString());
+		statementsForSymbols(casestat.getStatements(), scope);
 		statements(casestat.getStatements(), scope);
 	}
 

Added: trunk/tests/language-behaviour/0013-out-of-order.out.expected
===================================================================
--- trunk/tests/language-behaviour/0013-out-of-order.out.expected	                        (rev 0)
+++ trunk/tests/language-behaviour/0013-out-of-order.out.expected	2009-06-24 20:18:32 UTC (rev 2977)
@@ -0,0 +1 @@
+hello

Added: trunk/tests/language-behaviour/0013-out-of-order.swift
===================================================================
--- trunk/tests/language-behaviour/0013-out-of-order.swift	                        (rev 0)
+++ trunk/tests/language-behaviour/0013-out-of-order.swift	2009-06-24 20:18:32 UTC (rev 2977)
@@ -0,0 +1,12 @@
+type messagefile;
+
+(messagefile t) greeting() { 
+    app {
+        echo "hello" stdout=@filename(t);
+    }
+}
+
+messagefile outfile <"0013-out-of-order.out">;
+
+outfile = greeting();
+




More information about the Swift-commit mailing list