1) Fixed issue #828: Non initialized variable warnings doesn't work with variables...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Parser.java
index 121754c..1626006 100644 (file)
@@ -3682,34 +3682,49 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                variable_without_objects(false, false);
        }
 
-       private Expression base_variable_with_function_calls(boolean lefthandside,
-                       boolean ignoreVar) {
-               // base_variable_with_function_calls:
-               // base_variable
-               // | function_call
+       /**
+        * base_variable_with_function_calls:
+        * base_variable | function_call
+        *  
+        * @param lefthandside
+        * @param ignoreVar
+        * @return
+        */
+       private Expression base_variable_with_function_calls (boolean lefthandside, boolean ignoreVar) {
                if (Scanner.TRACE) {
                        System.out.println("TRACE: base_variable_with_function_calls()");
                }
+               
                return function_call(lefthandside, ignoreVar);
        }
 
-       private Expression base_variable(boolean lefthandside) {
-               // base_variable:
-               // reference_variable
-               // | simple_indirect_reference reference_variable
-               // | static_member
+       /**
+        * base_variable:
+        * reference_variable
+        * | simple_indirect_reference reference_variable
+        * | static_member
+        * 
+        * @param lefthandside
+        * @return
+        */
+       private Expression base_variable (boolean lefthandside) {
                Expression ref = null;
+               
                if (Scanner.TRACE) {
-                       System.out.println("TRACE: base_variable()");
+                       System.out.println ("TRACE: base_variable()");
                }
+               
                if (token == TokenName.IDENTIFIER) {
-                       static_member();
-               } else {
+                       static_member ();
+               } 
+               else {
                        while (token == TokenName.DOLLAR) {
-                               getNextToken();
+                               getNextToken ();
                        }
-                       reference_variable(lefthandside, false);
+                       
+                       reference_variable (lefthandside, false);
                }
+               
                return ref;
        }
 
@@ -3718,8 +3733,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
        // // '$'
        // //| simple_indirect_reference '$'
        // }
-       private Expression reference_variable(boolean lefthandside,
-                       boolean ignoreVar) {
+       private Expression reference_variable (boolean lefthandside, boolean ignoreVar) {
                // reference_variable:
                // reference_variable '[' dim_offset ']'
                // | reference_variable '{' expr '}'
@@ -3758,51 +3772,59 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                return ref;
        }
 
-       private Expression compound_variable(boolean lefthandside, boolean ignoreVar) {
+       private Expression compound_variable (boolean lefthandside, boolean ignoreVar) {
                // compound_variable:
                // T_VARIABLE
                // | '$' '{' expr '}'
                if (Scanner.TRACE) {
                        System.out.println("TRACE: compound_variable()");
                }
+               
                if (token == TokenName.VARIABLE) {
                        if (!lefthandside) {
                                if (!containsVariableSet()) {
                                        // reportSyntaxError("The local variable " + new
                                        // String(scanner.getCurrentIdentifierSource())
                                        // + " may not have been initialized");
-                                       problemReporter.uninitializedLocalVariable(new String(
-                                                       scanner.getCurrentIdentifierSource()), scanner
-                                                       .getCurrentTokenStartPosition(), scanner
-                                                       .getCurrentTokenEndPosition(), referenceContext,
-                                                       compilationUnit.compilationResult);
+                                       problemReporter.uninitializedLocalVariable (
+                                                       new String (scanner.getCurrentIdentifierSource()), 
+                                                                   scanner.getCurrentTokenStartPosition(),
+                                                                   scanner.getCurrentTokenEndPosition(), 
+                                                                   referenceContext,
+                                                                   compilationUnit.compilationResult);
                                }
                        } else {
                                if (!ignoreVar) {
                                        addVariableSet();
                                }
                        }
-                       FieldReference ref = new FieldReference(scanner
-                                       .getCurrentIdentifierSource(), scanner
-                                       .getCurrentTokenStartPosition());
+                       
+                       FieldReference ref = new FieldReference (scanner.getCurrentIdentifierSource(), 
+                                                                                                        scanner.getCurrentTokenStartPosition());
                        getNextToken();
                        return ref;
-               } else {
+               } 
+               else {
                        // because of simple_indirect_reference
                        while (token == TokenName.DOLLAR) {
                                getNextToken();
                        }
+                       
                        if (token != TokenName.LBRACE) {
                                reportSyntaxError("'{' expected after compound variable token '$'.");
                                return null;
                        }
+                       
                        getNextToken();
                        expr();
+                       
                        if (token != TokenName.RBRACE) {
                                throwSyntaxError("'}' expected after compound variable token '$'.");
                        }
+                       
                        getNextToken();
                }
+               
                return null;
        } // private void dim_offset() { // // dim_offset: // // /* empty */
 
@@ -3816,9 +3838,12 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                if (Scanner.TRACE) {
                        System.out.println("TRACE: object_property()");
                }
-               if (token == TokenName.VARIABLE || token == TokenName.DOLLAR) {
-                       variable_without_objects(false, false);
-               } else {
+               
+               if ((token == TokenName.VARIABLE) || 
+                       (token == TokenName.DOLLAR)) {
+                       variable_without_objects (false, false);
+               } 
+               else {
                        object_dim_list();
                }
        }
@@ -3831,27 +3856,37 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                if (Scanner.TRACE) {
                        System.out.println("TRACE: object_dim_list()");
                }
+               
                variable_name();
+               
                while (true) {
                        if (token == TokenName.LBRACE) {
                                getNextToken();
                                expr();
+                               
                                if (token != TokenName.RBRACE) {
                                        throwSyntaxError("'}' expected in object_dim_list.");
                                }
+                               
                                getNextToken();
-                       } else if (token == TokenName.LBRACKET) {
+                       } 
+                       else if (token == TokenName.LBRACKET) {
                                getNextToken();
+                               
                                if (token == TokenName.RBRACKET) {
                                        getNextToken();
                                        continue;
                                }
+                               
                                expr();
+                               
                                if (token != TokenName.RBRACKET) {
                                        throwSyntaxError("']' expected in object_dim_list.");
                                }
+                               
                                getNextToken();
-                       } else {
+                       } 
+                       else {
                                break;
                        }
                }
@@ -3864,20 +3899,27 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                if (Scanner.TRACE) {
                        System.out.println("TRACE: variable_name()");
                }
-               if (token == TokenName.IDENTIFIER || token.compareTo (TokenName.KEYWORD) > 0) {
+               
+               if ((token == TokenName.IDENTIFIER) || 
+                        (token.compareTo (TokenName.KEYWORD) > 0)) {
                        if (token.compareTo (TokenName.KEYWORD) > 0) {
                                // TODO show a warning "Keyword used as variable" ?
                        }
+                       
                        getNextToken();
-               } else {
+               } 
+               else {
                        if (token != TokenName.LBRACE) {
                                throwSyntaxError("'{' expected in variable name.");
                        }
+                       
                        getNextToken();
                        expr();
+                       
                        if (token != TokenName.RBRACE) {
                                throwSyntaxError("'}' expected in variable name.");
                        }
+                       
                        getNextToken();
                }
        }
@@ -3894,22 +3936,26 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                variable(false, false);
        }
 
-       private Expression variable(boolean lefthandside, boolean ignoreVar) {
-               // variable:
-               // base_variable_with_function_calls T_OBJECT_OPERATOR
-               // object_property method_or_not variable_properties
-               // | base_variable_with_function_calls
-               Expression ref = base_variable_with_function_calls(lefthandside,
-                               ignoreVar);
-               if (token == TokenName.MINUS_GREATER) {
-                       ref = null;
-                       getNextToken();
-                       object_property();
-                       method_or_not();
-                       variable_properties();
-               }
-               else if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
-                       ref = null;
+       /**
+        * 
+        * variable:
+        * base_variable_with_function_calls T_OBJECT_OPERATOR
+        * object_property method_or_not variable_properties
+        * | base_variable_with_function_calls
+        * 
+        * @param lefthandside
+        * @param ignoreVar
+        * @return
+        */
+       private Expression variable (boolean lefthandside, boolean ignoreVar) {
+               Expression ref = base_variable_with_function_calls (lefthandside, ignoreVar);
+               
+               if ((token == TokenName.MINUS_GREATER) ||
+                   (token == TokenName.PAAMAYIM_NEKUDOTAYIM))  {
+/* I don't know why ref was set to null, but if it is null, the variable will neither be added to the set of variable,
+ * nor would it be checked for beeing unitialized. So I don't set it to null!
+ */
+//                     ref = null;
                        getNextToken();
                        object_property();
                        method_or_not();
@@ -3934,11 +3980,13 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                if (Scanner.TRACE) {
                        System.out.println("TRACE: variable_property()");
                }
+               
                if (token == TokenName.MINUS_GREATER) {
                        getNextToken();
                        object_property();
                        method_or_not();
-               } else {
+               } 
+               else {
                        throwSyntaxError("'->' expected in variable_property.");
                }
        }