X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fibex%2Ftool%2FCompiler.java;h=8d10ce35fb33d3add67fb9bd321ba19ed3653c2c;hb=283369d4f4fbde8d91dc99f9b365db57671ab2d5;hp=08a399aff644cf0fe87b5e80904cc08e500f5ef0;hpb=f421ead1069fcf2dbb959db93202d458dc3ee70f;p=org.ibex.tool.git diff --git a/src/java/org/ibex/tool/Compiler.java b/src/java/org/ibex/tool/Compiler.java index 08a399a..8d10ce3 100644 --- a/src/java/org/ibex/tool/Compiler.java +++ b/src/java/org/ibex/tool/Compiler.java @@ -20,6 +20,7 @@ import org.eclipse.jdt.internal.compiler.impl.*; import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; public class Compiler { + private static final boolean DEBUG = false; // Static Entry Point ///////////////////////////////////////////////////// @@ -81,14 +82,26 @@ 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("."); - public Compiler() { } + 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 void setBuildDir(String dir) { builddir = new File(dir == null ? "." : dir); } public void setSourceDir(String dir) { sourcedir = new File(dir == null ? "." : dir); } @@ -104,12 +117,11 @@ public class Compiler { public void compile() { List s = new ArrayList(); filterSources(s, sourcedir, new char[0][]); - System.out.println("working with "+s.size() +" sources"); + if (DEBUG) System.out.println("working with "+s.size() +" sources"); sources = new Source[s.size()]; s.toArray(sources); ICompilationUnit[] units = new ICompilationUnit[s.size()]; for (int i=0; i < sources.length; i++) units[i] = sources[i].unit; - System.out.println("compiling"); org.eclipse.jdt.internal.compiler.Compiler jdt = new org.eclipse.jdt.internal.compiler.Compiler( env, policy, settings, results, problems); @@ -272,8 +284,6 @@ public class Compiler { for (int i=0; i < ex.length; i++) ex[i] = name(exs[i]); desc = descriptor(m.getParameterTypes(), m.getReturnType()); - /*if (new String(desc).indexOf("[") > -1) - System.out.println("method: "+m+", desc="+new String(desc));*/ // DEBUG } public int getModifiers() { return m.getModifiers(); } public char[] getSelector() { return m.getName().toCharArray(); } @@ -352,7 +362,6 @@ public class Compiler { final INameEnvironment env = new INameEnvironment() { public NameEnvironmentAnswer findType(char[][] c) { return findType(name(c), pack(c)); } public NameEnvironmentAnswer findType(char[] n, char[][] p) { - boolean DEBUG = false; if (DEBUG) System.out.println("requesting: "+ str(p, '.') + "."+new String(n)); try { @@ -407,7 +416,7 @@ public class Compiler { /** Used by compiler for processing compiled classes and their errors. */ private final ICompilerRequestor results = new ICompilerRequestor() { public void acceptResult(CompilationResult result) { - System.out.println("got result: "+result); + if (DEBUG) System.out.println("got result: "+result); if (result.hasProblems()) { boolean hasErrors = false; IProblem[] p = result.getProblems(); @@ -430,12 +439,12 @@ public class Compiler { File path = builddir; char[][] name = c[i].getCompoundName(); path = new File(builddir, str(pack(name), '/')); - System.out.println("DEBUG: creating path "+path+", out of builddir="+builddir); + if (DEBUG) System.out.println("DEBUG: creating path "+path+", out of builddir="+builddir); if (!path.exists()) path.mkdirs(); // write new class file path = new File(path, new String(name(name)) + ".class"); - System.out.println("DEBUG: writing file "+path); + if (DEBUG) System.out.println("DEBUG: writing file "+path); OutputStream o = new BufferedOutputStream( new FileOutputStream(path)); o.write(c[i].getBytes());