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.ast.CompilationUnitDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
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.problem.ProblemReporter;
import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
import net.sourceforge.phpdt.internal.compiler.util.Util;
-import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
+
public class Compiler implements ITypeRequestor, ProblemSeverities {
public UnitParser parser;
public ICompilerRequestor requestor;
// name lookup
public LookupEnvironment lookupEnvironment;
// ONCE STABILIZED, THESE SHOULD RETURN TO A FINAL FIELD
- public static boolean DEBUG = true;
+ public static boolean DEBUG = false;
public int parseThreshold = -1;
// number of initial units parsed at once (-1: none)
/*
* @param parseLiteralExpressionsAsConstants
* <code>boolean</code> This parameter is used to optimize the
* literals or leave them as they are in the source. If you put
- * true, "Hello" + " world" will be converted to "Hello world".
+ * true, "Hello" . " world" will be converted to "Hello world".
*/
public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy,
Map settings, final ICompilerRequestor requestor,
// if (options.verbose) {
// if (totalUnits > 1) {
// System.out.println(
- // Util.bind("compilation.units" , String.valueOf(totalUnits)));
+ // ProjectPrefUtil.bind("compilation.units" , String.valueOf(totalUnits)));
// //$NON-NLS-1$
// } else {
// System.out.println(
- // Util.bind("compilation.unit" , String.valueOf(totalUnits)));
+ // ProjectPrefUtil.bind("compilation.unit" , String.valueOf(totalUnits)));
// //$NON-NLS-1$
// }
// }
// 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
*/
// this.reset();
}
}
-}
+
+}
\ No newline at end of file