import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
+
import net.sourceforge.phpdt.core.compiler.IProblem;
import net.sourceforge.phpdt.internal.compiler.env.IBinaryType;
import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
import net.sourceforge.phpdt.internal.compiler.env.INameEnvironment;
import net.sourceforge.phpdt.internal.compiler.env.ISourceType;
+import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
import net.sourceforge.phpdt.internal.compiler.impl.ITypeRequestor;
import net.sourceforge.phpdt.internal.compiler.lookup.LookupEnvironment;
import net.sourceforge.phpdt.internal.compiler.lookup.PackageBinding;
public class Compiler implements ITypeRequestor, ProblemSeverities {
public UnitParser parser;
public ICompilerRequestor requestor;
- // public CompilerOptions options;
+ public CompilerOptions options;
public ProblemReporter problemReporter;
// management of unit to be processed
//public CompilationUnitResult currentCompilationUnitResult;
// name lookup
public LookupEnvironment lookupEnvironment;
// ONCE STABILIZED, THESE SHOULD RETURN TO A FINAL FIELD
- public static boolean DEBUG = false;
+ public static boolean DEBUG = true;
public int parseThreshold = -1;
// number of initial units parsed at once (-1: none)
/*
* problems, the compiler will gather them all and hand them back
* as part of the compilation unit result.
*/
- public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy,
- // Map settings,
- final ICompilerRequestor requestor, IProblemFactory problemFactory) {
+ public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy,
+ Map settings, final ICompilerRequestor requestor,
+ IProblemFactory problemFactory) {
// create a problem handler given a handling policy
- // this.options = new CompilerOptions(settings);
+ this.options = new CompilerOptions(settings);
// wrap requestor in DebugRequestor if one is specified
// if(DebugRequestor == null) {
this.requestor = requestor;
// }
// };
// }
- this.problemReporter = new ProblemReporter(policy, problemFactory);//this.options,
- // problemFactory);
+ this.problemReporter = new ProblemReporter(policy, this.options,
+ problemFactory);
this.lookupEnvironment = new LookupEnvironment(this, problemReporter,
environment); //options, problemReporter, environment);
this.parser = new UnitParser(problemReporter);
* literals or leave them as they are in the source. If you put
* true, "Hello" + " world" will be converted to "Hello world".
*/
- public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy,
- // Map settings,
- final ICompilerRequestor requestor, IProblemFactory problemFactory,
- boolean parseLiteralExpressionsAsConstants) {
+ public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy,
+ Map settings, final ICompilerRequestor requestor,
+ IProblemFactory problemFactory, boolean parseLiteralExpressionsAsConstants) {
// create a problem handler given a handling policy
- // this.options = new CompilerOptions(settings);
+ this.options = new CompilerOptions(settings);
// wrap requestor in DebugRequestor if one is specified
// if(DebugRequestor == null) {
this.requestor = requestor;
// }
// };
// }
- this.problemReporter = new ProblemReporter(policy, problemFactory);//,
- // this.options,
- // problemFactory);
+ this.problemReporter = new ProblemReporter(policy, this.options,
+ problemFactory);
this.lookupEnvironment = new LookupEnvironment(this, problemReporter,
environment);//options, problemReporter, environment);
this.parser = new UnitParser(problemReporter);
// Switch the current policy and compilation result for this unit to the
// requested one.
CompilationResult unitResult = new CompilationResult(sourceUnit,
- totalUnits, totalUnits, 10); //this.options.maxProblemsPerUnit);
+ totalUnits, totalUnits, this.options.maxProblemsPerUnit);
try {
// diet parsing for large collection of unit
CompilationUnitDeclaration parsedUnit;
} else {
parsedUnit = parser.dietParse(sourceUnit, unitResult);
}
- // if (options.verbose) {
- // String count = String.valueOf(totalUnits + 1);
- // System.out.println(
- // Util.bind(
- // "compilation.request" , //$NON-NLS-1$
- // new String[] {
- // count,
- // count,
- // new String(sourceUnit.getFileName())}));
- // }
+ if (options.verbose) {
+ String count = String.valueOf(totalUnits + 1);
+ System.out.println(Util.bind("compilation.request", //$NON-NLS-1$
+ new String[]{count, count, new String(sourceUnit.getFileName())}));
+ }
// initial type binding creation
lookupEnvironment.buildTypeBindings(parsedUnit);
this.addCompilationUnit(sourceUnit, parsedUnit);
for (int i = 0; i < maxUnits; i++) {
CompilationUnitDeclaration parsedUnit;
CompilationResult unitResult = new CompilationResult(sourceUnits[i], i,
- maxUnits, 10);//, this.options.maxProblemsPerUnit);
+ maxUnits, this.options.maxProblemsPerUnit);
try {
// diet parsing for large collection of units
if (totalUnits < parseThreshold) {
} else {
parsedUnit = parser.dietParse(sourceUnits[i], unitResult);
}
- // if (options.verbose) {
- // System.out.println(
- // Util.bind(
- // "compilation.request" , //$NON-NLS-1$
- // new String[] {
- // String.valueOf(i + 1),
- // String.valueOf(maxUnits),
- // new String(sourceUnits[i].getFileName())}));
- // }
+ if (options.verbose) {
+ System.out.println(Util.bind("compilation.request", //$NON-NLS-1$
+ new String[]{String.valueOf(i + 1), String.valueOf(maxUnits),
+ new String(sourceUnits[i].getFileName())}));
+ }
// initial type binding creation
- lookupEnvironment.buildTypeBindings(parsedUnit);
+ // lookupEnvironment.buildTypeBindings(parsedUnit);
this.addCompilationUnit(sourceUnits[i], parsedUnit);
//} catch (AbortCompilationUnit e) {
//requestor.acceptResult(unitResult.tagAsAccepted());
for (; i < totalUnits; i++) {
unit = unitsToProcess[i];
try {
- // if (options.verbose)
- // System.out.println(
- // Util.bind(
- // "compilation.process" , //$NON-NLS-1$
- // new String[] {
- // String.valueOf(i + 1),
- // String.valueOf(totalUnits),
- // new String(unitsToProcess[i].getFileName())}));
+ if (options.verbose)
+ System.out.println(Util.bind("compilation.process", //$NON-NLS-1$
+ new String[]{String.valueOf(i + 1), String.valueOf(totalUnits),
+ new String(unitsToProcess[i].getFileName())}));
process(unit, i);
} finally {
// cleanup compilation unit result
unit.cleanUp();
- // if (options.verbose)
- // System.out.println(Util.bind("compilation.done", //$NON-NLS-1$
- // new String[] {
- // String.valueOf(i + 1),
- // String.valueOf(totalUnits),
- // new String(unitsToProcess[i].getFileName())}));
+ if (options.verbose)
+ System.out.println(Util.bind("compilation.done", //$NON-NLS-1$
+ new String[]{String.valueOf(i + 1), String.valueOf(totalUnits),
+ new String(unitsToProcess[i].getFileName())}));
}
unitsToProcess[i] = null; // release reference to processed unit
- // declaration
+ // declaration
requestor.acceptResult(unit.compilationResult.tagAsAccepted());
}
- } catch (AbortCompilation e) {
+ } catch (AbortCompilation e) {
this.handleInternalException(e, unit);
} catch (Error e) {
this.handleInternalException(e, unit, null);
if (unit.scope != null)
unit.scope.faultInTypes();
// verify inherited methods
- if (unit.scope != null)
- unit.scope.verifyMethods(lookupEnvironment.methodVerifier());
+ // if (unit.scope != null)
+ // unit.scope.verifyMethods(lookupEnvironment.methodVerifier());
// type checking
unit.resolve();
// flow analysis
// if (DebugRequestor != null) DebugRequestor.reset();
}
/**
+ * Internal API used to resolve a given compilation unit. Can run a subset of the compilation process
+ */
+ public CompilationUnitDeclaration resolve(
+ CompilationUnitDeclaration unit,
+ ICompilationUnit sourceUnit,
+ boolean verifyMethods,
+ boolean analyzeCode) {
+
+ try {
+ if (unit == null) {
+ // build and record parsed units
+ parseThreshold = 0; // will request a full parse
+ beginToCompile(new ICompilationUnit[] { sourceUnit });
+ // process all units (some more could be injected in the loop by the lookup environment)
+ unit = unitsToProcess[0];
+ } else {
+ // initial type binding creation
+ lookupEnvironment.buildTypeBindings(unit);
+
+ // binding resolution
+ lookupEnvironment.completeTypeBindings();
+ }
+ // TODO : jsurfer check this
+// this.parser.getMethodBodies(unit);
+ getMethodBodies(unit, 0);
+
+ if (unit.scope != null) {
+ // fault in fields & methods
+ unit.scope.faultInTypes();
+ if (unit.scope != null && verifyMethods) {
+ // http://dev.eclipse.org/bugs/show_bug.cgi?id=23117
+ // verify inherited methods
+ unit.scope.verifyMethods(lookupEnvironment.methodVerifier());
+ }
+ // type checking
+ unit.resolve();
+
+ // flow analysis
+// if (analyzeCode) unit.analyseCode();
+
+ // code generation
+// if (generateCode) unit.generateCode();
+ }
+ if (unitsToProcess != null) unitsToProcess[0] = null; // release reference to processed unit declaration
+ requestor.acceptResult(unit.compilationResult.tagAsAccepted());
+ return unit;
+ } catch (AbortCompilation e) {
+ this.handleInternalException(e, unit);
+ return unit == null ? unitsToProcess[0] : unit;
+ } catch (Error e) {
+ this.handleInternalException(e, unit, null);
+ throw e; // rethrow
+ } catch (RuntimeException e) {
+ this.handleInternalException(e, unit, null);
+ throw e; // rethrow
+ } finally {
+ // No reset is performed there anymore since,
+ // within the CodeAssist (or related tools),
+ // the compiler may be called *after* a call
+ // to this resolve(...) method. And such a call
+ // needs to have a compiler with a non-empty
+ // environment.
+ // this.reset();
+ }
+ }
+ /**
* Internal API used to resolve a given compilation unit. Can run a subset of
* the compilation process
*/
// if (generateCode) unit.generateCode();
}
unitsToProcess[0] = null; // release reference to processed unit
- // declaration
+ // declaration
requestor.acceptResult(unit.compilationResult.tagAsAccepted());
return unit;
} catch (AbortCompilation e) {
// this.reset();
}
}
+
}