Refactored packagename to net.sourceforge.phpdt.internal.compiler.ast
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Parser.java
index 459987a..c34ca1d 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002 www.phpeclipse.de All rights reserved. This program and the accompanying material 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-v10.html
- * 
+ *
  * Contributors: www.phpeclipse.de
  **********************************************************************************************************************************/
 package net.sourceforge.phpdt.internal.compiler.parser;
@@ -14,6 +14,33 @@ import java.util.HashSet;
 import net.sourceforge.phpdt.core.compiler.CharOperation;
 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
+import net.sourceforge.phpdt.internal.compiler.ast.AND_AND_Expression;
+import net.sourceforge.phpdt.internal.compiler.ast.ASTNode;
+import net.sourceforge.phpdt.internal.compiler.ast.AbstractMethodDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.BinaryExpression;
+import net.sourceforge.phpdt.internal.compiler.ast.Block;
+import net.sourceforge.phpdt.internal.compiler.ast.BreakStatement;
+import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.ConditionalExpression;
+import net.sourceforge.phpdt.internal.compiler.ast.ContinueStatement;
+import net.sourceforge.phpdt.internal.compiler.ast.EqualExpression;
+import net.sourceforge.phpdt.internal.compiler.ast.Expression;
+import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.FieldReference;
+import net.sourceforge.phpdt.internal.compiler.ast.IfStatement;
+import net.sourceforge.phpdt.internal.compiler.ast.ImportReference;
+import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression;
+import net.sourceforge.phpdt.internal.compiler.ast.MethodDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.OR_OR_Expression;
+import net.sourceforge.phpdt.internal.compiler.ast.OperatorIds;
+import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement;
+import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
+import net.sourceforge.phpdt.internal.compiler.ast.Statement;
+import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral;
+import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralDQ;
+import net.sourceforge.phpdt.internal.compiler.ast.StringLiteralSQ;
+import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
@@ -23,33 +50,6 @@ import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
 import net.sourceforge.phpdt.internal.compiler.util.Util;
 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
-import net.sourceforge.phpeclipse.internal.compiler.ast.AND_AND_Expression;
-import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
-import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
-import net.sourceforge.phpeclipse.internal.compiler.ast.Block;
-import net.sourceforge.phpeclipse.internal.compiler.ast.BreakStatement;
-import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.ConditionalExpression;
-import net.sourceforge.phpeclipse.internal.compiler.ast.ContinueStatement;
-import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
-import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
-import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
-import net.sourceforge.phpeclipse.internal.compiler.ast.IfStatement;
-import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
-import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
-import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.OR_OR_Expression;
-import net.sourceforge.phpeclipse.internal.compiler.ast.OperatorIds;
-import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
-import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
-import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
-import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
-import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralDQ;
-import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralSQ;
-import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
 
 import org.eclipse.core.resources.IFile;
@@ -99,7 +99,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
 
        /**
         * ClassDeclaration Constructor.
-        * 
+        *
         * @param s
         * @param sess
         *          Description of Parameter
@@ -142,7 +142,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
        /**
         * This method will throw the SyntaxError. It will add the good lines and
         * columns to the Error
-        * 
+        *
         * @param error
         *          the error message
         * @throws SyntaxError
@@ -163,7 +163,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
        /**
         * This method will throw the SyntaxError. It will add the good lines and
         * columns to the Error
-        * 
+        *
         * @param error
         *          the error message
         * @throws SyntaxError
@@ -2502,6 +2502,20 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
                        // | rw_variable T_INC
                        // | rw_variable T_DEC
                        case TokenNameIdentifier:
+                               char[] ident = scanner.getCurrentTokenSource();
+                               Expression lhsIdentifier = identifier(true, true);
+                               if (lhsIdentifier != null) {
+                                       expression = lhsIdentifier;
+                               }
+                               if (token == TokenNameEQUAL || token == TokenNamePLUS_EQUAL
+                                               || token == TokenNameMINUS_EQUAL || token == TokenNameMULTIPLY_EQUAL || token == TokenNameDIVIDE_EQUAL
+                                               || token == TokenNameDOT_EQUAL || token == TokenNameREMAINDER_EQUAL || token == TokenNameAND_EQUAL
+                                               || token == TokenNameOR_EQUAL || token == TokenNameXOR_EQUAL || token == TokenNameRIGHT_SHIFT_EQUAL
+                                               || token == TokenNameLEFT_SHIFT_EQUAL) {
+                                       String error = "Assignment operator '"+scanner.toStringAction(token)+"' not allowed after identifier '"+new String(ident)+"' (use 'define(...)' to define constants).";
+                                       throwSyntaxError(error);
+                               }
+                               break;
                        case TokenNameVariable:
                        case TokenNameDOLLAR:
                                boolean rememberedVar = false;
@@ -3330,6 +3344,22 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
                }
        }
 
+       private Expression identifier(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 == TokenNameMINUS_GREATER) {
+                       ref = null;
+                       getNextToken();
+                       object_property();
+                       method_or_not();
+                       variable_properties();
+               }
+               return ref;
+       }
+
        private void method_or_not() {
                // method_or_not:
                // '(' function_call_parameter_list ')'
@@ -3676,7 +3706,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
 
        /**
         * Parse and check the include file name
-        * 
+        *
         * @param includeToken
         */
        private void checkFileName(int includeToken) {
@@ -3975,7 +4005,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
        // /* remember current scanner position */
        // int startPos = scanner.startPosition;
        // int currentPos = scanner.currentPosition;
-       //    
+       //
        // this.checkAndReportBracketAnomalies(problemReporter());
        // /* reset scanner where it was */
        // scanner.startPosition = startPos;
@@ -4561,7 +4591,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
                        "$_SESSION", "$_SERVER" };
 
        /**
-        * 
+        *
         */
        private void pushFunctionVariableSet() {
                HashSet set = new HashSet();
@@ -4600,7 +4630,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
 
        /**
         * add the current identifier source to the <i>set of assigned variables </i>
-        * 
+        *
         * @param set
         */
        private void addVariableSet(HashSet set) {
@@ -4611,7 +4641,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
 
        /**
         * add the current identifier source to the <i>set of assigned variables </i>
-        * 
+        *
         */
        private void addVariableSet() {
                HashSet set = peekVariableSet();
@@ -4622,7 +4652,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
 
        /**
         * add the current identifier source to the <i>set of assigned variables </i>
-        * 
+        *
         */
        private void addVariableSet(char[] token) {
                HashSet set = peekVariableSet();
@@ -4635,7 +4665,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
         * check if the current identifier source is in the <i>set of assigned
         * variables </i> Returns true, if no set is defined for the current scanner
         * position
-        * 
+        *
         */
        private boolean containsVariableSet() {
                return containsVariableSet(scanner.getCurrentTokenSource());