misc changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / UnitParser.java
index 2da0761..d8a0199 100644 (file)
@@ -1,5 +1,7 @@
 package net.sourceforge.phpdt.internal.compiler.parser;
 
+import java.util.Stack;
+
 import net.sourceforge.phpdt.core.IJavaModelMarker;
 import net.sourceforge.phpdt.core.compiler.IProblem;
 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
@@ -7,7 +9,6 @@ import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
 import net.sourceforge.phpdt.internal.compiler.problem.AbortCompilation;
 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
 import net.sourceforge.phpdt.internal.compiler.util.Util;
-import net.sourceforge.phpdt.internal.core.BasicCompilationUnit;
 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
 import net.sourceforge.phpeclipse.internal.compiler.ast.ConstructorDeclaration;
 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
@@ -77,8 +78,8 @@ public class UnitParser extends Parser {
     firstToken = TokenNameMINUS_MINUS;
     scanner.recordLineSeparator = false;
   }
-  public void initialize() {
-    super.initialize();
+  public void initialize(boolean phpMode) {
+    super.initialize(phpMode);
     //positionning the parser for a new compilation unit
     //avoiding stack reallocation and all that....
     //         astPtr = -1;
@@ -132,13 +133,13 @@ public class UnitParser extends Parser {
 
   // A P I
 
-  public CompilationUnitDeclaration parse(ICompilationUnit sourceUnit, CompilationResult compilationResult) {
+  public CompilationUnitDeclaration parse(ICompilationUnit sourceUnit, CompilationResult compilationResult, boolean phpMode) {
     // parses a compilation unit and manages error handling (even bugs....)
 
     CompilationUnitDeclaration unit;
     try {
       /* automaton initialization */
-      initialize();
+      initialize(phpMode);
       goForCompilationUnit();
 
       /* scanner initialization */
@@ -161,8 +162,7 @@ public class UnitParser extends Parser {
 //        storeProblemsFor(((BasicCompilationUnit)sourceUnit).getResource(), compilationResult.getAllProblems());
 //      }
 //      // jsurfer end
-    } catch (CoreException e) {
-      e.printStackTrace();
+    
     } finally {
       unit = compilationUnit;
       compilationUnit = null; // reset parser
@@ -253,7 +253,7 @@ public class UnitParser extends Parser {
 
     //convert bugs into parse error
 
-    initialize();
+    initialize(false);
     goForConstructorBody();
     nestedMethod[nestedType]++;
 
@@ -265,15 +265,13 @@ public class UnitParser extends Parser {
       parse();
     } catch (AbortCompilation ex) {
       lastAct = ERROR_ACTION;
-    } catch (CoreException e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
+    
     } finally {
       nestedMethod[nestedType]--;
     }
 
     if (lastAct == ERROR_ACTION) {
-      initialize();
+      initialize(false);
       return;
     }
 
@@ -317,7 +315,7 @@ public class UnitParser extends Parser {
 
     //convert bugs into parse error
 
-    initialize();
+    initialize(false);
     goForExpression();
     nestedMethod[nestedType]++;
 
@@ -330,9 +328,6 @@ public class UnitParser extends Parser {
       parse();
     } catch (AbortCompilation ex) {
       lastAct = ERROR_ACTION;
-    } catch (CoreException e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
     } finally {
       nestedMethod[nestedType]--;
     }
@@ -356,7 +351,7 @@ public class UnitParser extends Parser {
 
     //convert bugs into parse error
 
-    initialize();
+    initialize(false);
     goForInitializer();
     nestedMethod[nestedType]++;
 
@@ -368,9 +363,6 @@ public class UnitParser extends Parser {
       parse();
     } catch (AbortCompilation ex) {
       lastAct = ERROR_ACTION;
-    } catch (CoreException e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
     } finally {
       nestedMethod[nestedType]--;
     }
@@ -389,52 +381,53 @@ public class UnitParser extends Parser {
   // A P I
 
   public void parse(MethodDeclaration md, CompilationUnitDeclaration unit) {
-    //only parse the method body of md
-    //fill out method statements
-
-    //convert bugs into parse error
-
-    if (md.isAbstract())
-      return;
-    // if (md.isNative())
-    //         return;
-    // if ((md.modifiers & AccSemicolonBody) != 0)
-    //         return;
-
-    initialize();
-    goForMethodBody();
-    nestedMethod[nestedType]++;
-
-    referenceContext = md;
-    compilationUnit = unit;
-
-    scanner.resetTo(md.sourceEnd + 1, md.declarationSourceEnd);
-    // reset the scanner to parser from { down to }
-    try {
-      parse();
-    } catch (AbortCompilation ex) {
-      lastAct = ERROR_ACTION;
-    } catch (CoreException e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
-    } finally {
-      nestedMethod[nestedType]--;
-    }
-
-    // if (lastAct == ERROR_ACTION) {
-    //         return;
-    // }
-    //
-    // //refill statements
-    // md.explicitDeclarations = realBlockStack[realBlockPtr--];
-    // int length;
-    // if ((length = astLengthStack[astLengthPtr--]) != 0)
-    //         System.arraycopy(
-    //                 astStack, 
-    //                 (astPtr -= length) + 1, 
-    //                 md.statements = new Statement[length], 
-    //                 0, 
-    //                 length); 
+//  TODO jsurfer - make the parse process work on methods ?
+    return; 
+    
+//    //only parse the method body of md
+//    //fill out method statements
+//
+//    //convert bugs into parse error
+//
+//    if (md.isAbstract())
+//      return;
+//    //       if (md.isNative())
+//    //               return;
+//    //       if ((md.modifiers & AccSemicolonBody) != 0)
+//    //               return;
+//
+//    initialize(false);
+//    goForMethodBody();
+//    nestedMethod[nestedType]++;
+//
+//    referenceContext = md;
+//    compilationUnit = unit;
+//
+//    scanner.resetTo(md.sourceEnd + 1, md.declarationSourceEnd);
+//   
+//    // reset the scanner to parser from { down to }
+//    try {
+//      parse();
+//    } catch (AbortCompilation ex) {
+//      lastAct = ERROR_ACTION;
+//    } finally {
+//      nestedMethod[nestedType]--;
+//    }
+//
+//    //       if (lastAct == ERROR_ACTION) {
+//    //               return;
+//    //       }
+//    //
+//    //       //refill statements
+//    //       md.explicitDeclarations = realBlockStack[realBlockPtr--];
+//    //       int length;
+//    //       if ((length = astLengthStack[astLengthPtr--]) != 0)
+//    //               System.arraycopy(
+//    //                       astStack, 
+//    //                       (astPtr -= length) + 1, 
+//    //                       md.statements = new Statement[length], 
+//    //                       0, 
+//    //                       length); 
   }
 
   // A P I
@@ -445,7 +438,7 @@ public class UnitParser extends Parser {
     CompilationUnitDeclaration unit;
     try {
       /* automaton initialization */
-      initialize();
+      initialize(false);
       goForCompilationUnit();
 
       /* scanner initialization */
@@ -456,9 +449,6 @@ public class UnitParser extends Parser {
         compilationUnit = new CompilationUnitDeclaration(problemReporter, compilationResult, scanner.source.length);
       /* run automaton */
       parse();
-    } catch (CoreException e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
     } catch (SyntaxError syntaxError) {
       // 
     } finally {
@@ -469,12 +459,15 @@ public class UnitParser extends Parser {
   }
 
   public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult) {
+       return dietParse(sourceUnit, compilationResult, false);
+  }
+  public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult, boolean phpMode) {
 
     CompilationUnitDeclaration parsedUnit;
     boolean old = diet;
     try {
       diet = true;
-      parsedUnit = parse(sourceUnit, compilationResult);
+      parsedUnit = parse(sourceUnit, compilationResult, phpMode);
     } finally {
       diet = old;
     }