X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java index e0377d7..081c885 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/Compiler.java @@ -1,37 +1,46 @@ /******************************************************************************* - * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others. + * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 + * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html + * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation - ******************************************************************************/ + *******************************************************************************/ package net.sourceforge.phpdt.internal.compiler; -import net.sourceforge.phpdt.core.compiler.*; -import net.sourceforge.phpdt.internal.compiler.env.*; -import net.sourceforge.phpdt.internal.compiler.impl.*; -import net.sourceforge.phpdt.internal.compiler.ast.*; -import net.sourceforge.phpdt.internal.compiler.lookup.*; -import net.sourceforge.phpdt.internal.compiler.parser.*; -import net.sourceforge.phpdt.internal.compiler.problem.*; -import net.sourceforge.phpdt.internal.compiler.util.*; - -import java.io.*; -import java.util.*; +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.ITypeRequestor; +import net.sourceforge.phpdt.internal.compiler.lookup.LookupEnvironment; +import net.sourceforge.phpdt.internal.compiler.lookup.PackageBinding; +import net.sourceforge.phpdt.internal.compiler.parser.UnitParser; +import net.sourceforge.phpdt.internal.compiler.problem.AbortCompilation; +import net.sourceforge.phpdt.internal.compiler.problem.AbortCompilationUnit; +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 Parser parser; - ICompilerRequestor requestor; - public CompilerOptions options; + public UnitParser parser; + public ICompilerRequestor requestor; +// public CompilerOptions options; public ProblemReporter problemReporter; // management of unit to be processed //public CompilationUnitResult currentCompilationUnitResult; - CompilationUnitDeclaration[] unitsToProcess; - int totalUnits; // (totalUnits-1) gives the last unit in unitToProcess + public CompilationUnitDeclaration[] unitsToProcess; + public int totalUnits; // (totalUnits-1) gives the last unit in unitToProcess // name lookup public LookupEnvironment lookupEnvironment; @@ -47,7 +56,7 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { * builder implementation. It is reset at the end of compilation, and should not * persist any information after having been reset. */ - public static IDebugRequestor DebugRequestor = null; +// public static IDebugRequestor DebugRequestor = null; /** * Answer a new compiler using the given name environment and compiler options. @@ -85,35 +94,35 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { public Compiler( INameEnvironment environment, IErrorHandlingPolicy policy, - Map settings, +// 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) { +// if(DebugRequestor == null) { this.requestor = requestor; - } else { - this.requestor = new ICompilerRequestor(){ - public void acceptResult(CompilationResult result){ - if (DebugRequestor.isActive()){ - DebugRequestor.acceptDebugResult(result); - } - requestor.acceptResult(result); - } - }; - } +// } else { +// this.requestor = new ICompilerRequestor(){ +// public void acceptResult(CompilationResult result){ +// if (DebugRequestor.isActive()){ +// DebugRequestor.acceptDebugResult(result); +// } +// requestor.acceptResult(result); +// } +// }; +// } this.problemReporter = - new ProblemReporter(policy, this.options, problemFactory); + new ProblemReporter(policy, problemFactory);//this.options, problemFactory); this.lookupEnvironment = - new LookupEnvironment(this, options, problemReporter, environment); + new LookupEnvironment(this, problemReporter, environment); //options, problemReporter, environment); this.parser = - new Parser( - problemReporter, - this.options.parseLiteralExpressionsAsConstants, - this.options.assertMode); + new UnitParser( + problemReporter); +// this.options.parseLiteralExpressionsAsConstants, +// options.sourceLevel >= CompilerOptions.JDK1_4); } /** @@ -155,36 +164,36 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { public Compiler( INameEnvironment environment, IErrorHandlingPolicy policy, - Map settings, +// 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) { +// if(DebugRequestor == null) { this.requestor = requestor; - } else { - this.requestor = new ICompilerRequestor(){ - public void acceptResult(CompilationResult result){ - if (DebugRequestor.isActive()){ - DebugRequestor.acceptDebugResult(result); - } - requestor.acceptResult(result); - } - }; - } +// } else { +// this.requestor = new ICompilerRequestor(){ +// public void acceptResult(CompilationResult result){ +// if (DebugRequestor.isActive()){ +// DebugRequestor.acceptDebugResult(result); +// } +// requestor.acceptResult(result); +// } +// }; +// } this.problemReporter = - new ProblemReporter(policy, this.options, problemFactory); + new ProblemReporter(policy, problemFactory);//, this.options, problemFactory); this.lookupEnvironment = - new LookupEnvironment(this, options, problemReporter, environment); + new LookupEnvironment(this, problemReporter, environment);//options, problemReporter, environment); this.parser = - new Parser( - problemReporter, - parseLiteralExpressionsAsConstants, - this.options.assertMode); + new UnitParser( + problemReporter); +// parseLiteralExpressionsAsConstants, + // this.options.sourceLevel >= CompilerOptions.JDK1_4); } /** @@ -201,25 +210,26 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { public void accept(ICompilationUnit sourceUnit) { // Switch the current policy and compilation result for this unit to the requested one. CompilationResult unitResult = - new CompilationResult(sourceUnit, totalUnits, totalUnits, this.options.maxProblemsPerUnit); + new CompilationResult(sourceUnit, totalUnits, totalUnits, 10); //this.options.maxProblemsPerUnit); try { // diet parsing for large collection of unit CompilationUnitDeclaration parsedUnit; if (totalUnits < parseThreshold) { - parsedUnit = parser.parse(sourceUnit, unitResult); + parsedUnit = parser.parse(sourceUnit, unitResult,false); } else { parsedUnit = parser.dietParse(sourceUnit, unitResult); } - if (options.verbose) { - System.out.println( - Util.bind( - "compilation.request" , //$NON-NLS-1$ - new String[] { - String.valueOf(totalUnits + 1), - String.valueOf(totalUnits + 1), - 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); @@ -279,23 +289,23 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { for (int i = 0; i < maxUnits; i++) { CompilationUnitDeclaration parsedUnit; CompilationResult unitResult = - new CompilationResult(sourceUnits[i], i, maxUnits, this.options.maxProblemsPerUnit); + new CompilationResult(sourceUnits[i], i, maxUnits, 10);//, this.options.maxProblemsPerUnit); try { // diet parsing for large collection of units if (totalUnits < parseThreshold) { - parsedUnit = parser.parse(sourceUnits[i], unitResult); + parsedUnit = parser.parse(sourceUnits[i], unitResult, false); } 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); this.addCompilationUnit(sourceUnits[i], parsedUnit); @@ -326,24 +336,24 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { 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 requestor.acceptResult(unit.compilationResult.tagAsAccepted()); @@ -359,15 +369,15 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { } finally { this.reset(); } - if (options.verbose) { - if (totalUnits > 1) { - System.out.println( - Util.bind("compilation.units" , String.valueOf(totalUnits))); //$NON-NLS-1$ - } else { - System.out.println( - Util.bind("compilation.unit" , String.valueOf(totalUnits))); //$NON-NLS-1$ - } - } +// if (options.verbose) { +// if (totalUnits > 1) { +// System.out.println( +// Util.bind("compilation.units" , String.valueOf(totalUnits))); //$NON-NLS-1$ +// } else { +// System.out.println( +// Util.bind("compilation.unit" , String.valueOf(totalUnits))); //$NON-NLS-1$ +// } +// } } protected void getMethodBodies(CompilationUnitDeclaration unit, int place) { @@ -386,8 +396,10 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { parser.scanner.setSource( unit.compilationResult.compilationUnit.getContents()); if (unit.types != null) { - for (int i = unit.types.length; --i >= 0;) - unit.types[i].parseMethod(parser, unit); + for (int i = unit.types.size(); --i >= 0;) + if (unit.types.get(i) instanceof TypeDeclaration) { + ((TypeDeclaration)unit.types.get(i)).parseMethod(parser, unit); + } } } @@ -416,16 +428,19 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { internalException.printStackTrace(writer); StringBuffer buffer = stringWriter.getBuffer(); + String[] pbArguments = new String[] { + Util.bind("compilation.internalError" ) //$NON-NLS-1$ + + "\n" //$NON-NLS-1$ + + buffer.toString()}; + result .record( problemReporter .createProblem( result.getFileName(), IProblem.Unclassified, - new String[] { - Util.bind("compilation.internalError" ) //$NON-NLS-1$ - + "\n" //$NON-NLS-1$ - + buffer.toString()}, + pbArguments, + pbArguments, Error, // severity 0, // source start 0, // source end @@ -477,6 +492,7 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { result.getFileName(), abortException.problemId, abortException.problemArguments, + abortException.messageArguments, Error, // severity 0, // source start 0, // source end @@ -517,7 +533,7 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { /** * Process a compilation unit already parsed and build. */ - private void process(CompilationUnitDeclaration unit, int i) { + public void process(CompilationUnitDeclaration unit, int i) { getMethodBodies(unit, i); @@ -536,11 +552,11 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { unit.analyseCode(); // code generation - unit.generateCode(); +// unit.generateCode(); // reference info - if (options.produceReferenceInfo && unit.scope != null) - unit.scope.storeDependencyInfo(); +// if (options.produceReferenceInfo && unit.scope != null) +// unit.scope.storeDependencyInfo(); // refresh the total number of units known at this stage unit.compilationResult.totalUnitsKnown = totalUnits; @@ -549,13 +565,18 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { lookupEnvironment.reset(); parser.scanner.source = null; unitsToProcess = null; - if (DebugRequestor != null) DebugRequestor.reset(); +// if (DebugRequestor != null) DebugRequestor.reset(); } /** - * Internal API used to resolve a compilation unit minimally for code assist engine + * Internal API used to resolve a given compilation unit. Can run a subset of the compilation process */ - public CompilationUnitDeclaration resolve(ICompilationUnit sourceUnit) { + public CompilationUnitDeclaration resolve( + ICompilationUnit sourceUnit, + boolean verifyMethods, + boolean analyzeCode) { +// boolean generateCode) { + CompilationUnitDeclaration unit = null; try { // build and record parsed units @@ -565,10 +586,22 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { unit = unitsToProcess[0]; getMethodBodies(unit, 0); if (unit.scope != null) { - // fault in fields & methods - unit.scope.faultInTypes(); - // type checking - unit.resolve(); +// // 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(); } unitsToProcess[0] = null; // release reference to processed unit declaration requestor.acceptResult(unit.compilationResult.tagAsAccepted()); @@ -592,4 +625,4 @@ public class Compiler implements ITypeRequestor, ProblemSeverities { // this.reset(); } } -} \ No newline at end of file +}