changeset 190:d26bcb7dc691

Updated eclipse plugin to distinguish between errors and info.
author Sigurd Meldgaard <stm@daimi.au.dk>
date Wed, 16 Dec 2009 15:25:01 +0100
parents 67503a9dd613
children 847575998490
files eclipse/src/eu/cace/pysmcl/builder/PySMCLCompiler.java eclipse/src/eu/cace/pysmcl/preferences/PreferenceConstants.java eclipse/src/eu/cace/pysmcl/preferences/PreferenceInitializer.java eclipse/src/eu/cace/pysmcl/preferences/PreferencePage.java
diffstat 4 files changed, 85 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/eclipse/src/eu/cace/pysmcl/builder/PySMCLCompiler.java	Wed Dec 16 15:21:17 2009 +0100
+++ b/eclipse/src/eu/cace/pysmcl/builder/PySMCLCompiler.java	Wed Dec 16 15:25:01 2009 +0100
@@ -31,7 +31,7 @@
 }
 
 class PySMCLCompiler {
-
+	
 	/**
 	 * Exit codes from the Python PySMCL compiler.
 	 */
@@ -71,10 +71,7 @@
 		try {
 			String result = compile(resource.getRawLocation().makeAbsolute());
 			for (SMCLProblem problem : parsePySMCLOutput(resource, result)) {
-
-				handler.warning(problem.getDescription(), problem
-						.getStartChar(), problem.getEndChar(), problem
-						.getLocation());
+				handler.markProblem(problem);
 			}
 		} catch (PySMCLException e) {
 			// TODO: How does PySMCL handle badly formatted programs?
@@ -84,7 +81,12 @@
 			// Badly formed programs should probably be ignored while true
 			// compilation errors should be marked with an error at the top
 			// line.
-			handler.error(e.getMessage(), 0, 0, "");
+			try {
+				handler.markProblem(createMarker(resource, "Error during analysis", 1, 0, 1, IMarker.SEVERITY_ERROR));
+				e.printStackTrace();
+			} catch (PySMCLException e1) {
+				e1.printStackTrace();
+			}
 		}
 
 	}
@@ -98,7 +100,7 @@
 			}
 			return a;
 		} else { 
-			return null;
+			throw new RuntimeException("The string: '" + input + "' did not match pattern: '" + regex + "'");
 		}
 		
 	}
@@ -116,21 +118,31 @@
 		try{
 			System.out.println(output);
 			for(String line : output.split("\n")){
-				if(line.startsWith("secret:")){
+				if(line.startsWith("Seeding")){
+					//ignore
+				}else if(line.startsWith("secret:")){
 					List<String> m = splitGroup("secret: (\\d+) (\\d+) (\\d+) \\((.*)\\)", line);
 					res.add(createMarker(resource,
 							"This expression may return a secret value: "
 							+ m.get(3),
 							Integer.parseInt(m.get(0)),
 							Integer.parseInt(m.get(1)),
-							Integer.parseInt(m.get(2))));				
+							Integer.parseInt(m.get(2)), IMarker.SEVERITY_INFO));				
 				} else if(line.startsWith("values:")){
-					List<String> m = splitGroup("values: (\\d+) (\\d+) (\\d+) ((\\(.*\\))|(_\\|_))", line);
+					List<String> m = splitGroup("values: (\\d+) (\\d+) (\\d+) \\((.*)\\)", line);
 					res.add(createMarker(resource,
 							""+m.get(3),
 							Integer.parseInt(m.get(0)),
 							Integer.parseInt(m.get(1)),
-							Integer.parseInt(m.get(2))));				
+							Integer.parseInt(m.get(2)), IMarker.SEVERITY_INFO));				
+				} else if(line.startsWith("error:")){
+					List<String> m = splitGroup("error: (\\d+) (\\d+) (\\d+) \\((.*)\\)", line);
+					System.out.println(m);
+					res.add(createMarker(resource,
+							""+m.get(3),
+							Integer.parseInt(m.get(0)),
+							Integer.parseInt(m.get(1)),
+							Integer.parseInt(m.get(2)), IMarker.SEVERITY_ERROR));				
 				} else {
 					throw new RuntimeException("Badly formatted output");
 				}
@@ -146,14 +158,14 @@
 	}
 
 	private SMCLProblem createMarker(IFile resource, String description, int line,
-			int startChar, int length) throws PySMCLException {
+			int startChar, int length, int severity) throws PySMCLException {
 		String program = readProgram(resource);
 		int lineOffset = getLineOffset(program, line - 1);
 		String location = "Line " + line + " (" + (startChar + 1) + ";"
 				+ (startChar + length) + ")";
 		return new SMCLProblem(lineOffset + startChar, lineOffset
 				+ startChar + length,
-				description, location);
+				description, location, severity);
 	}
 
 	/**
@@ -207,47 +219,6 @@
 				+ program);
 	}
 
-	/**
-	 * Represents a PySMCL compiler issue error/warning report.
-	 * 
-	 */
-	private class SMCLProblem {
-		private final int startChar;
-		private final int endChar;
-		private final String description;
-		private final String location;
-
-		public SMCLProblem(int start, int end, String description,
-				String location) {
-			this.startChar = start;
-			this.endChar = end;
-			this.description = description;
-			this.location = location;
-		}
-
-		public String getLocation() {
-			return this.location;
-		}
-
-		int getStartChar() {
-			return this.startChar;
-		}
-
-		int getEndChar() {
-			return this.endChar;
-		}
-
-		String getDescription() {
-			return this.description;
-		}
-
-		@Override
-		public String toString() {
-			return "SMCLProblem(" + this.description + ";" + this.startChar
-					+ "," + this.endChar + ")";
-		}
-
-	}
 
 	/**
 	 * Starts PySMCL as an external process.
@@ -262,15 +233,15 @@
 		IPreferenceStore store = Activator.getDefault().getPreferenceStore();
 		String python = store.getString(PreferenceConstants.P_PYTHON);
 		String pySmclBasePath = store.getString(PreferenceConstants.P_PYSMCL);
+		String viffBasePath = store.getString(PreferenceConstants.P_VIFF);
 
-		// TODO: Currently hardcoded to invoke the emacs/info.py program.
 		if (!pySmclBasePath.endsWith(File.pathSeparator))
 			pySmclBasePath += File.separator;
 		
 		String compiler = pySmclBasePath + "pysmcl" + File.separator + "editor_info.py";
 
 		Map<String, String> environ = new HashMap<String, String>();
-		environ.put("PYTHONPATH", pySmclBasePath);
+		environ.put("PYTHONPATH", pySmclBasePath+":"+viffBasePath);
 		String[] cmd = new String[] { python, compiler, resource.toOSString() };
 		ProcessExecutor exec = new ProcessExecutor(cmd, environ);
 
@@ -290,6 +261,55 @@
 
 }
 
+/**
+ * Represents a PySMCL compiler issue error/warning report.
+ * 
+ */
+class SMCLProblem {
+	private int severity;
+	private final int startChar;
+	private final int endChar;
+	private final String description;
+	private final String location;
+
+	public SMCLProblem(int start, int end, String description,
+			String location, int severity) {
+		this.startChar = start;
+		this.endChar = end;
+		this.description = description;
+		this.location = location;
+		this.severity = severity;
+	}
+	
+	public int getSeverity(){
+		return this.severity;
+	}
+
+	public String getLocation() {
+		return this.location;
+	}
+
+	int getStartChar() {
+		return this.startChar;
+	}
+
+	int getEndChar() {
+		return this.endChar;
+	}
+
+	String getDescription() {
+		return this.description;
+	}
+
+	@Override
+	public String toString() {
+		return "SMCLProblem(" + this.description + ";" + this.startChar
+				+ "," + this.endChar + ")";
+	}
+
+}
+
+
 class CompilerMessageHandler {
 
 	private IMarkable markable;
@@ -305,11 +325,9 @@
 		markable.addMarker(file, msg, start, end, severity, location);
 	}
 
-	public void error(String msg, int start, int end, String location) {
-		addMarker(msg, start, end, IMarker.SEVERITY_ERROR, location);
+	
+	public void markProblem(SMCLProblem problem){
+		addMarker(problem.getDescription(), problem.getStartChar(), problem.getEndChar(),
+				problem.getSeverity(), problem.getLocation());
 	}
-
-	public void warning(String msg, int start, int end, String location) {
-		addMarker(msg, start, end, IMarker.SEVERITY_WARNING, location);
 	}
-}
--- a/eclipse/src/eu/cace/pysmcl/preferences/PreferenceConstants.java	Wed Dec 16 15:21:17 2009 +0100
+++ b/eclipse/src/eu/cace/pysmcl/preferences/PreferenceConstants.java	Wed Dec 16 15:25:01 2009 +0100
@@ -9,5 +9,6 @@
 	public static final String P_PYTHON = "pathPython";
 	
 	public static final String P_PYSMCL = "pathPySMCL";
+	public static final String P_VIFF = "pathVIFF";
 
 }
--- a/eclipse/src/eu/cace/pysmcl/preferences/PreferenceInitializer.java	Wed Dec 16 15:21:17 2009 +0100
+++ b/eclipse/src/eu/cace/pysmcl/preferences/PreferenceInitializer.java	Wed Dec 16 15:25:01 2009 +0100
@@ -23,6 +23,8 @@
 		
 		// TODO: Search for PySMCL location?
 		store.setDefault(PreferenceConstants.P_PYSMCL, "");
+
+		store.setDefault(PreferenceConstants.P_VIFF, "");
 	}
 
 }
--- a/eclipse/src/eu/cace/pysmcl/preferences/PreferencePage.java	Wed Dec 16 15:21:17 2009 +0100
+++ b/eclipse/src/eu/cace/pysmcl/preferences/PreferencePage.java	Wed Dec 16 15:25:01 2009 +0100
@@ -36,6 +36,8 @@
 				"&Python VM Location:", getFieldEditorParent()));
 		addField(new DirectoryFieldEditor(PreferenceConstants.P_PYSMCL,
 				"&PySMCL Location:", getFieldEditorParent()));
+		addField(new DirectoryFieldEditor(PreferenceConstants.P_VIFF,
+				"&VIFF Location:", getFieldEditorParent()));
 	}
 
 	/*