From ae1108f9a9461eceabe5bb8dd9e6c8be65646986 Mon Sep 17 00:00:00 2001 From: Edward Mann Date: Tue, 2 Nov 2010 11:39:59 +0000 Subject: [PATCH] The namespace fix would go into endless loop if you left the ; off the end of the statement. I have fixed it so that it will stop and throw an error. --- .../phpdt/internal/compiler/parser/Parser.java | 186 +++++++++++--------- 1 files changed, 101 insertions(+), 85 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java index 3d33858..badc067 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java @@ -459,11 +459,13 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, * but in switch-case it's recommended to avoid * accidental fall-through later when editing the code */ - problemReporter.unreachableCode(new String(scanner - .getCurrentIdentifierSource()), - statement.sourceStart, statement.sourceEnd, - referenceContext, - compilationUnit.compilationResult); + problemReporter + .unreachableCode( + new String(scanner + .getCurrentIdentifierSource()), + statement.sourceStart, + statement.sourceEnd, referenceContext, + compilationUnit.compilationResult); } } if ((token == TokenNameRBRACE) || (token == TokenNamecase) @@ -856,14 +858,14 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, getNextToken(); } return statement; - } else if(token == TokenNameconst){ + } else if (token == TokenNameconst) { + // TODO make sure you clean this hack up ed_mann. getNextToken(); - if(token == TokenNameIdentifier){ + if (token == TokenNameIdentifier) { getNextToken(); - if(token == TokenNameEQUAL){ + if (token == TokenNameEQUAL) { getNextToken(); } - //throwSyntaxError("'Ed i know your here"); } } else if (token == TokenNamestatic) { getNextToken(); @@ -1153,11 +1155,11 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, // | '$' '{' expr '}' if (token == TokenNameVariable) { if (fMethodVariables != null) { - VariableInfo info = new VariableInfo(scanner - .getCurrentTokenStartPosition(), + VariableInfo info = new VariableInfo( + scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR); - fMethodVariables.put(new String(scanner - .getCurrentIdentifierSource()), info); + fMethodVariables.put( + new String(scanner.getCurrentIdentifierSource()), info); } addVariableSet(set); getNextToken(); @@ -1186,11 +1188,12 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, while (true) { if (token == TokenNameVariable) { if (fMethodVariables != null) { - VariableInfo info = new VariableInfo(scanner - .getCurrentTokenStartPosition(), + VariableInfo info = new VariableInfo( + scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR); - fMethodVariables.put(new String(scanner - .getCurrentIdentifierSource()), info); + fMethodVariables.put( + new String(scanner.getCurrentIdentifierSource()), + info); } addVariableSet(set); getNextToken(); @@ -1248,11 +1251,13 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (token == TokenNameIdentifier || token > TokenNameKEYWORD) { typeDecl.name = scanner.getCurrentIdentifierSource(); if (token > TokenNameKEYWORD) { - problemReporter.phpKeywordWarning(new String[] { scanner - .toStringAction(token) }, scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition(), referenceContext, - compilationUnit.compilationResult); + problemReporter + .phpKeywordWarning(new String[] { scanner + .toStringAction(token) }, scanner + .getCurrentTokenStartPosition(), scanner + .getCurrentTokenEndPosition(), + referenceContext, + compilationUnit.compilationResult); // throwSyntaxError("Don't use a keyword for interface // declaration [" // + scanner.toStringAction(token) + "].", @@ -1280,11 +1285,13 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (token == TokenNameIdentifier || token > TokenNameKEYWORD) { typeDecl.name = scanner.getCurrentIdentifierSource(); if (token > TokenNameKEYWORD) { - problemReporter.phpKeywordWarning(new String[] { scanner - .toStringAction(token) }, scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition(), referenceContext, - compilationUnit.compilationResult); + problemReporter + .phpKeywordWarning(new String[] { scanner + .toStringAction(token) }, scanner + .getCurrentTokenStartPosition(), scanner + .getCurrentTokenEndPosition(), + referenceContext, + compilationUnit.compilationResult); // throwSyntaxError("Don't use a keyword for class // declaration [" + // scanner.toStringAction(token) + "].", @@ -1524,9 +1531,9 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (token == TokenNamevar) { checkAndSetModifiers(AccPublic); - problemReporter.phpVarDeprecatedWarning(scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition(), referenceContext, + problemReporter.phpVarDeprecatedWarning( + scanner.getCurrentTokenStartPosition(), + scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult); getNextToken(); class_variable_declaration(declarationSourceStart, list); @@ -1583,10 +1590,10 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (token != TokenNameIdentifier) { throwSyntaxError("Identifier expected in class const declaration."); } - FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner - .getCurrentIdentifierSource(), scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition()); + FieldDeclaration fieldDeclaration = new FieldDeclaration( + scanner.getCurrentIdentifierSource(), + scanner.getCurrentTokenStartPosition(), + scanner.getCurrentTokenEndPosition()); fieldDeclaration.modifiers = this.modifiers; fieldDeclaration.declarationSourceStart = declarationSourceStart; fieldDeclaration.declarationSourceEnd = scanner @@ -1701,11 +1708,12 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, fieldDeclaration.modifiersSourceStart = declarationSourceStart; list.add(fieldDeclaration); if (fTypeVariables != null) { - VariableInfo info = new VariableInfo(scanner - .getCurrentTokenStartPosition(), + VariableInfo info = new VariableInfo( + scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT); - fTypeVariables.put(new String(scanner - .getCurrentIdentifierSource()), info); + fTypeVariables.put( + new String(scanner.getCurrentIdentifierSource()), + info); } getNextToken(); if (token == TokenNameEQUAL) { @@ -1744,12 +1752,11 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl }; } else { AbstractMethodDeclaration[] newMethods; - System - .arraycopy( - typeDecl.methods, - 0, - newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], - 0, typeDecl.methods.length); + System.arraycopy( + typeDecl.methods, + 0, + newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], + 0, typeDecl.methods.length); newMethods[typeDecl.methods.length] = methodDecl; typeDecl.methods = newMethods; } @@ -1791,10 +1798,10 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (Scanner.isIdentifierOrKeyword(token)) { methodDecl.selector = scanner.getCurrentIdentifierSource(); if (token > TokenNameKEYWORD) { - problemReporter.phpKeywordWarning(new String[] { scanner - .toStringAction(token) }, scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition(), referenceContext, + problemReporter.phpKeywordWarning( + new String[] { scanner.toStringAction(token) }, + scanner.getCurrentTokenStartPosition(), + scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult); } getNextToken(); @@ -1858,17 +1865,18 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (fMethodVariables != null) { VariableInfo info; if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) { - info = new VariableInfo(scanner - .getCurrentTokenStartPosition(), + info = new VariableInfo( + scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION); } else { - info = new VariableInfo(scanner - .getCurrentTokenStartPosition(), + info = new VariableInfo( + scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION); } info.typeIdentifier = typeIdentifier; - fMethodVariables.put(new String(scanner - .getCurrentIdentifierSource()), info); + fMethodVariables + .put(new String(scanner + .getCurrentIdentifierSource()), info); } addVariableSet(set); getNextToken(); @@ -2486,7 +2494,6 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, case TokenNameconst: internal_functions_in_yacc(); break; - // | '(' expr ')' case TokenNameLPAREN: getNextToken(); expr(); @@ -2616,17 +2623,17 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, // } // break; case TokenNameStringDoubleQuote: - expression = new StringLiteralDQ(scanner - .getCurrentStringLiteralSource(), scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition()); + expression = new StringLiteralDQ( + scanner.getCurrentStringLiteralSource(), + scanner.getCurrentTokenStartPosition(), + scanner.getCurrentTokenEndPosition()); common_scalar(); break; case TokenNameStringSingleQuote: - expression = new StringLiteralSQ(scanner - .getCurrentStringLiteralSource(), scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition()); + expression = new StringLiteralSQ( + scanner.getCurrentStringLiteralSource(), + scanner.getCurrentTokenStartPosition(), + scanner.getCurrentTokenEndPosition()); common_scalar(); break; case TokenNameIntegerLiteral: @@ -3029,7 +3036,8 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, int pos = scanner.currentPosition; getNextToken(); if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) { - // Not terminated by T_STRING, reduce to dynamic_class_name_reference + // Not terminated by T_STRING, reduce to + // dynamic_class_name_reference scanner.currentPosition = pos; token = TokenNameIdentifier; ref = null; @@ -3476,9 +3484,9 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, addVariableSet(); } } - FieldReference ref = new FieldReference(scanner - .getCurrentIdentifierSource(), scanner - .getCurrentTokenStartPosition()); + FieldReference ref = new FieldReference( + scanner.getCurrentIdentifierSource(), + scanner.getCurrentTokenStartPosition()); getNextToken(); return ref; } else { @@ -4112,22 +4120,29 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, break; } } - + /** * parse and check the namespace name + * * @since 1.2.3 * @param namespaceToken */ - private void checkNameSpaceName(){ + private void checkNameSpaceName() { getNextToken(); - while (true) { - if (token == TokenNameSEMICOLON) { - break; - } + while (true) { + if (token == TokenNameForwardSlash || token == TokenNameIdentifier) { getNextToken(); + } else { + break; } - + } + if (token != TokenNameSEMICOLON) { + throwSyntaxError("';' expected after keyword '" + + scanner.toStringAction(TokenNameNamespace) + "'"); + } + } + /** * Parse and check the include file name * @@ -4175,8 +4190,9 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, StringLiteral literal = (StringLiteral) expression; char[] includeName = literal.source(); if (includeName.length == 0) { - reportSyntaxError("Empty filename after keyword '" - + scanner.toStringAction(includeToken) + "'", + reportSyntaxError( + "Empty filename after keyword '" + + scanner.toStringAction(includeToken) + "'", literal.sourceStart, literal.sourceStart + 1); } String includeNameString = new String(includeName); @@ -4219,9 +4235,9 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, IFile f = PHPFileUtil.createFile(path, project); - impt.tokens = CharOperation.splitOn('/', filePath - .toCharArray(), 0, filePath.length() - - fileExtensionLength); + impt.tokens = CharOperation.splitOn('/', + filePath.toCharArray(), 0, + filePath.length() - fileExtensionLength); impt.setFile(f); } catch (Exception e) { // the file is outside of the workspace @@ -5027,12 +5043,12 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, // create a package name similar to java package names String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()) .toString(); - String filePath = file.getFullPath().toString(); - - String ext = file.getFileExtension(); - int fileExtensionLength = ext == null ? 0 : ext.length() + 1; - ImportReference impt; - char[][] tokens; + String filePath = file.getFullPath().toString(); + + String ext = file.getFileExtension(); + int fileExtensionLength = ext == null ? 0 : ext.length() + 1; + ImportReference impt; + char[][] tokens; if (filePath.startsWith(projectPath)) { tokens = CharOperation.splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length() -- 1.7.1