[Swift-commit] r6069 - trunk/src/org/griphyn/vdl/engine

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Tue Nov 20 16:11:26 CST 2012


Author: hategan
Date: 2012-11-20 16:11:26 -0600 (Tue, 20 Nov 2012)
New Revision: 6069

Modified:
   trunk/src/org/griphyn/vdl/engine/CompilerUtils.java
   trunk/src/org/griphyn/vdl/engine/Karajan.java
   trunk/src/org/griphyn/vdl/engine/VariableScope.java
Log:
fixed NPE with shadowing warnings and improved warning messages to distinguish between "variable", "parameter" etc.

Modified: trunk/src/org/griphyn/vdl/engine/CompilerUtils.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/CompilerUtils.java	2012-11-20 21:29:29 UTC (rev 6068)
+++ trunk/src/org/griphyn/vdl/engine/CompilerUtils.java	2012-11-20 22:11:26 UTC (rev 6069)
@@ -22,7 +22,13 @@
             return getLine(n.getParentNode());
         }
         else {
-            return src.getNodeValue();
+            String loc = src.getNodeValue();
+            if (loc == null || loc.length() == 0) {
+                return "unknown";
+            }
+            else {
+                return loc.substring(loc.indexOf(' ') + 1);
+            }
         }
     }
 
@@ -30,12 +36,6 @@
         if (src == null) {
             return null;
         }
-        String loc = src.getDomNode().getAttributes().getNamedItem("src").getNodeValue();
-        if (loc == null) {
-            return null;
-        }
-        else {
-            return loc.substring(loc.indexOf(' ') + 1);
-        }
+        return getLine(src.getDomNode());
     }
 }

Modified: trunk/src/org/griphyn/vdl/engine/Karajan.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/Karajan.java	2012-11-20 21:29:29 UTC (rev 6068)
+++ trunk/src/org/griphyn/vdl/engine/Karajan.java	2012-11-20 22:11:26 UTC (rev 6069)
@@ -355,7 +355,7 @@
 				procST.setAttribute("arguments", paramST);
 			String type = normalize(param.getType().getLocalPart());
             checkIsTypeDefined(type);
-            innerScope.addVariable(param.getName(), type, param);
+            innerScope.addVariable(param.getName(), type, "Return parameter", param);
 		}
 		for (int i = 0; i < proc.sizeOfInputArray(); i++) {
 			FormalParameter param = proc.getInputArray(i);
@@ -367,7 +367,7 @@
 				procST.setAttribute("arguments", paramST);
 			String type = normalize(param.getType().getLocalPart());
 			checkIsTypeDefined(type);
-			outerScope.addVariable(param.getName(), type, param);
+			outerScope.addVariable(param.getName(), type, "Parameter", param);
 		}
 		
 		Binding bind;
@@ -441,9 +441,8 @@
 	}
 
 	public void variableForSymbol(Variable var, VariableScope scope) throws CompilationException {
-
 		checkIsTypeDefined(var.getType().getLocalPart());
-		scope.addVariable(var.getName(), var.getType().getLocalPart(), var.getIsGlobal(), var);
+		scope.addVariable(var.getName(), var.getType().getLocalPart(), "Variable", var.getIsGlobal(), var);
 	}
 
 	public void variable(Variable var, VariableScope scope) throws CompilationException {
@@ -498,7 +497,7 @@
 						scope.bodyTemplate.setAttribute("declarations",variableDeclarationST);
 						StringTemplate paramValueST=expressionToKarajan(param.getAbstractExpression(),scope);
 						String paramValueType = datatype(paramValueST);
-						scope.addVariable(parameterVariableName, paramValueType, param);
+						scope.addVariable(parameterVariableName, paramValueType, "Variable", param);
 						variableDeclarationST.setAttribute("type", paramValueType);
 						StringTemplate variableReferenceST = template("id");
 						variableReferenceST.setAttribute("var",parameterVariableName);
@@ -898,7 +897,7 @@
 		VariableScope loopScope = new VariableScope(this, scope, VariableScope.ENCLOSURE_LOOP);
 		VariableScope innerScope = new VariableScope(this, loopScope, VariableScope.ENCLOSURE_LOOP);
 
-		loopScope.addVariable(iterate.getVar(), "int", iterate);
+		loopScope.addVariable(iterate.getVar(), "int", "Iteration variable", iterate);
 
 		StringTemplate iterateST = template("iterate");
 		iterateST.setAttribute("line", getLine(iterate));
@@ -938,11 +937,11 @@
 			if (itemType == null) {
 			    throw new CompilationException("You can iterate through an array structure only");
 			}
-			innerScope.addVariable(foreach.getVar(), itemType, foreach);
+			innerScope.addVariable(foreach.getVar(), itemType, "Iteration variable", foreach);
 			foreachST.setAttribute("indexVar", foreach.getIndexVar());
 			foreachST.setAttribute("indexVarType", keyType);
 			if(foreach.getIndexVar() != null) {
-				innerScope.addVariable(foreach.getIndexVar(), keyType, foreach);
+				innerScope.addVariable(foreach.getIndexVar(), keyType, "Iteration variable", foreach);
 			}
 
 			innerScope.bodyTemplate = foreachST;

Modified: trunk/src/org/griphyn/vdl/engine/VariableScope.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/VariableScope.java	2012-11-20 21:29:29 UTC (rev 6068)
+++ trunk/src/org/griphyn/vdl/engine/VariableScope.java	2012-11-20 22:11:26 UTC (rev 6069)
@@ -120,15 +120,15 @@
 	    declaration already exists. Perhaps error in same scope and
 	    warning if it shadows an outer scope? */
 
-	public void addVariable(String name, String type, XmlObject src) throws CompilationException {
-		addVariable(name, type, false, src);
+	public void addVariable(String name, String type, String context, XmlObject src) throws CompilationException {
+		addVariable(name, type, context, false, src);
 	}
 	
 	public void inhibitClosing(String name) {
 		inhibitClosing.add(name);
 	}
 
-	public void addVariable(String name, String type, boolean global, XmlObject src) throws CompilationException {
+	public void addVariable(String name, String type, String context, boolean global, XmlObject src) throws CompilationException {
 	    if (logger.isDebugEnabled()) {
 	        logger.debug("Adding variable " + name + " of type " + type + " to scope " + hashCode());
 	    }
@@ -142,7 +142,7 @@
 		// by the above if? in which case isVariableDefined should
 		// be replaced by is locally defined test.
 		if(parentScope != null && parentScope.isVariableDefined(name)) {
-		    Warnings.warn("Variable " + name + ", defined on line " + CompilerUtils.getLine(src)
+		    Warnings.warn(context + " " + name + ", on line " + CompilerUtils.getLine(src)
 			+ ", shadows variable of same name on line " + parentScope.getDefinitionLine(name));
 		}
 




More information about the Swift-commit mailing list