improved error output
[org.ibex.tool.git] / src / java / org / ibex / tool / Compiler.java
index 5b14672..bba4466 100644 (file)
@@ -82,17 +82,29 @@ public class Compiler {
     private ClassLoader loader = ClassLoader.getSystemClassLoader();
     private Map loaded = new HashMap();
     private PrintWriter out = new PrintWriter(System.out);
-    private Preprocessor preprocessor = new Preprocessor(null, null, Collections.EMPTY_LIST);
+    private Preprocessor preprocessor;
 
     private Source[] sources;
 
     private File builddir = new File(".");
-    private File sourcedir = new File(".");
+    private String sourcedir = null;
+
+    public Compiler() {
+        List defs = Collections.EMPTY_LIST;
+
+        String define = System.getProperty("org.ibex.tool.preprocessor.define");
+        if (define != null) {
+            defs = new ArrayList();
+            StringTokenizer st = new StringTokenizer(define.toUpperCase(), ",");
+            while (st.hasMoreTokens()) defs.add(st.nextToken().trim());
+        }
+
+        preprocessor = new Preprocessor(null, null, defs);
+    }
 
-    public Compiler() { }
 
     public void setBuildDir(String dir) { builddir = new File(dir == null ? "." : dir); }
-    public void setSourceDir(String dir) { sourcedir = new File(dir == null ? "." : dir); }
+    public void setSourceDir(String dir) { sourcedir = dir; }
 
     /** Pass CompilerOptions.VERSION_1_*. A String of form "1.1", ".2", etc. */
     public void setSource(String v) { settings.put(CompilerOptions.OPTION_Source, v); }
@@ -104,7 +116,7 @@ public class Compiler {
 
     public void compile() {
         List s = new ArrayList();
-        filterSources(s, sourcedir, new char[0][]);
+        filterSources(s, new File(sourcedir), new char[0][]);
         if (DEBUG) System.out.println("working with "+s.size() +" sources");
         sources = new Source[s.size()]; s.toArray(sources);
         ICompilationUnit[] units = new ICompilationUnit[s.size()];
@@ -181,8 +193,10 @@ public class Compiler {
 
         private Source(File o, char[] n, char[][] p) {
             orig = o; this.n = n; this.p = p;
-            try { fileName = orig.getCanonicalPath().toCharArray(); } // FIXME: dont use full path
-            catch (IOException e) { fileName = orig.getName().toCharArray(); }
+            String file = sourcedir;
+            file += File.separatorChar +  str(p, File.separatorChar);
+            file += File.separatorChar + new String(n) + ".java";
+            fileName = file.toCharArray();
         }
     }
 
@@ -305,7 +319,7 @@ public class Compiler {
             for (int i=0; i < nested.length; i++)
                 nested[i] = new LoadedNestedType(classes[i]);
 
-            Constructor[] constructors = c.getConstructors();
+            Constructor[] constructors = c.getDeclaredConstructors();
             Method[] methods = c.getDeclaredMethods();
             if (methods.length + constructors.length > 0) {
                 meth = new IBinaryMethod[methods.length + constructors.length];
@@ -409,11 +423,12 @@ public class Compiler {
                 boolean hasErrors = false;
                 IProblem[] p = result.getProblems();
                 for (int i=0; i < p.length; i++) {
-                    if (p[i].isError()) hasErrors = true;
                     out.print(p[i].getOriginatingFileName());
                     out.print(':');
                     out.print(p[i].getSourceLineNumber());
                     out.print(':');
+                    if (p[i].isError()) { out.print(" error: "); hasErrors = true; }
+                    else out.print(" warning: ");
                     out.println(p[i].getMessage());
                 }
                 out.flush();