[Swift-commit] r7768 - in trunk: resources src/org/griphyn/vdl/engine
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Tue Apr 15 04:17:21 CDT 2014
Author: hategan
Date: 2014-04-15 04:17:17 -0500 (Tue, 15 Apr 2014)
New Revision: 7768
Modified:
trunk/resources/swiftscript.g
trunk/src/org/griphyn/vdl/engine/Karajan.java
Log:
fixed wrong procedure call prediction in parser and deal with the issue in the compiler (bug 1239)
Modified: trunk/resources/swiftscript.g
===================================================================
--- trunk/resources/swiftscript.g 2014-04-12 21:33:33 UTC (rev 7767)
+++ trunk/resources/swiftscript.g 2014-04-15 09:17:17 UTC (rev 7768)
@@ -653,36 +653,19 @@
:
id=identifier
ASSIGN
- (
- (predictProcedurecallAssign) => code=procedurecallCode
- { StringTemplate o = template("returnParam");
- o.setAttribute("name",id);
- code.setAttribute("outputs",o);
- }
- |
- code=variableAssign
- {
- code.setAttribute("lhs",id);
- }
- )
- ;
+ code=variableAssign {
+ code.setAttribute("lhs",id);
+ }
+;
appendStat returns [ StringTemplate code = null ]
{ StringTemplate id=null; }
:
id=identifier
APPEND
- (
- (predictProcedurecallAssign) => code=procedurecallCode {
- StringTemplate o = template("returnParam");
- o.setAttribute("name",id);
- code.setAttribute("outputs",o);
- }
- |
- code=arrayAppend {
- code.setAttribute("array", id);
- }
- )
+ code=arrayAppend {
+ code.setAttribute("array", id);
+ }
;
arrayAppend returns [ StringTemplate code = null ]
@@ -705,9 +688,6 @@
}
;
-predictProcedurecallAssign
- : ID LPAREN ;
-
procedurecallCode returns [StringTemplate code=template("call")]
{StringTemplate f=null;}
:
Modified: trunk/src/org/griphyn/vdl/engine/Karajan.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/Karajan.java 2014-04-12 21:33:33 UTC (rev 7767)
+++ trunk/src/org/griphyn/vdl/engine/Karajan.java 2014-04-15 09:17:17 UTC (rev 7768)
@@ -597,47 +597,67 @@
public void assign(Assign assign, VariableScope scope) throws CompilationException {
try {
- StringTemplate assignST = template("assign");
- StringTemplate varST = expressionToKarajan(assign.getAbstractExpressionArray(0), scope, true);
- String lValueType = datatype(varST);
-
- StringTemplate valueST = expressionToKarajan(assign.getAbstractExpressionArray(1), scope, false, lValueType);
-
- String rValueType = datatype(valueST);
-
- if (isAnyType(lValueType)) {
- if (isAnyType(rValueType)) {
- // any <- any
- }
- else {
- // any <- someType, so infer lValueType as rValueType
- setDatatype(varST, rValueType);
- }
- }
- else {
- if (isAnyType(rValueType)) {
- // someType <- any
- // only expressions that are allowed to return 'any' are procedures
- // for example readData(ret, file). These are special procedures that
- // need to look at the return type at run-time.
- }
- else if (!lValueType.equals(rValueType)){
- throw new CompilationException("You cannot assign value of type " + rValueType +
- " to a variable of type " + lValueType);
- }
- }
-
- assignST.setAttribute("var", varST);
- assignST.setAttribute("value", valueST);
- assignST.setAttribute("line", getLine(assign));
- String rootvar = abstractExpressionToRootVariable(assign.getAbstractExpressionArray(0));
- scope.addWriter(rootvar, getRootVariableWriteType(assign.getAbstractExpressionArray(0)), assign, assignST);
- scope.appendStatement(assignST);
+ XmlObject value = assign.getAbstractExpressionArray(1);
+ if (isCall(value)) {
+ Call call = (Call) value;
+ ActualParameter out = call.addNewOutput();
+ XmlObject src = assign.getAbstractExpressionArray(0);
+ out.getDomNode().appendChild(src.getDomNode());
+ call(call, scope, false);
+ }
+ else {
+ StringTemplate assignST = template("assign");
+ StringTemplate varST = expressionToKarajan(assign.getAbstractExpressionArray(0), scope, true);
+ String lValueType = datatype(varST);
+
+
+ StringTemplate valueST = expressionToKarajan(assign.getAbstractExpressionArray(1), scope, false, lValueType);
+
+ String rValueType = datatype(valueST);
+
+ if (isAnyType(lValueType)) {
+ if (isAnyType(rValueType)) {
+ // any <- any
+ }
+ else {
+ // any <- someType, so infer lValueType as rValueType
+ setDatatype(varST, rValueType);
+ }
+ }
+ else {
+ if (isAnyType(rValueType)) {
+ // someType <- any
+ // only expressions that are allowed to return 'any' are procedures
+ // for example readData(ret, file). These are special procedures that
+ // need to look at the return type at run-time.
+ }
+ else if (!lValueType.equals(rValueType)){
+ throw new CompilationException("You cannot assign value of type " + rValueType +
+ " to a variable of type " + lValueType);
+ }
+ }
+
+ assignST.setAttribute("var", varST);
+ assignST.setAttribute("value", valueST);
+ assignST.setAttribute("line", getLine(assign));
+ String rootvar = abstractExpressionToRootVariable(assign.getAbstractExpressionArray(0));
+ scope.addWriter(rootvar, getRootVariableWriteType(assign.getAbstractExpressionArray(0)), assign, assignST);
+ scope.appendStatement(assignST);
+ }
} catch(CompilationException re) {
throw new CompilationException("Compile error in assignment at "+assign.getSrc()+": "+re.getMessage(),re);
}
}
+ private boolean isCall(XmlObject value) {
+ Node expressionDOM = value.getDomNode();
+ String namespaceURI = expressionDOM.getNamespaceURI();
+ String localName = expressionDOM.getLocalName();
+ QName expressionQName = new QName(namespaceURI, localName);
+ return expressionQName.equals(CALL_EXPR);
+ }
+
+
private boolean isAnyType(String type) {
return ProcedureSignature.ANY.equals(type);
}
More information about the Swift-commit
mailing list