protected boolean diet = false; //tells the scanner to jump over some
- // parts of the code/expressions like
- // method bodies
- //scanner token
+ /**
+ * the PHP token scanner
+ */
public Scanner scanner;
- // private ArrayList phpList;
-
- // private int currentPHPString;
-
- // private boolean phpEnd;
-
- // private static HashMap keywordMap = null;
- private String str;
-
- // current character
- // char ch;
- // current token
int token;
- // row counter for syntax errors:
- //int rowCount;
- // column counter for syntax errors:
- //int columnCount;
- //int chIndx;
- //
- // // current identifier
- // String identifier;
- // Long longNumber;
-
- // Double doubleNumber;
-
- // private String stringValue;
-
- /** Contains the current expression. */
- // private StringBuffer expression;
- //private boolean phpMode;
protected int modifiers;
protected int modifiersSourceStart;
protected Parser(ProblemReporter problemReporter) {
this.problemReporter = problemReporter;
this.options = problemReporter.options;
- // this.currentPHPString = 0;
- // PHPParserSuperclass.fileToParse = fileToParse;
- // this.phpList = null;
- // this.indexManager = null;
- this.str = "";
this.token = TokenNameEOF;
- // this.chIndx = 0;
- // this.rowCount = 1;
- // this.columnCount = 0;
- // this.phpEnd = false;
- // getNextToken();
this.initializeScanner();
}
public void setFileToParse(IFile fileToParse) {
- // this.currentPHPString = 0;
- // PHPParserSuperclass.fileToParse = fileToParse;
- // this.phpList = null;
- // this.indexManager = null;
- this.str = "";
this.token = TokenNameEOF;
- // this.phpEnd = false;
this.initializeScanner();
}
// PHPParserSuperclass.fileToParse = fileToParse;
// this.phpList = null;
this.includesList = null;
- this.str = "";
+// this.str = "";
this.token = TokenNameEOF;
// this.chIndx = 0;
// this.rowCount = 1;
}
}
- private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
- if (referenceContext != null) {
- problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
- compilationUnit.compilationResult);
- }
- }
+// private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
+// if (referenceContext != null) {
+// problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
+// compilationUnit.compilationResult);
+// }
+// }
/**
* gets the next token from input
}
public void init(String s) {
- this.str = s;
+// this.str = s;
this.token = TokenNameEOF;
this.includesList = new ArrayList();
// this.chIndx = 0;
referenceContext = null;
this.includesList = new ArrayList();
// this.indexManager = indexManager;
- this.str = "";
+// this.str = "";
this.token = TokenNameEOF;
// this.chIndx = 0;
// this.rowCount = 1;
if (token != TokenNameVariable) {
throwSyntaxError("Variable expected in 'catch' statement.");
}
+ addVariableSet();
getNextToken();
if (token != TokenNameRPAREN) {
throwSyntaxError("')' expected in 'catch' statement.");
if (token != TokenNameVariable) {
throwSyntaxError("Variable expected in 'catch' statement.");
}
+ addVariableSet();
getNextToken();
if (token != TokenNameRPAREN) {
throwSyntaxError("')' expected in 'catch' statement.");
}
}
- private void class_extends(TypeDeclaration typeDecl) {
- // /* empty */
- // | T_EXTENDS interface_list
- if (token == TokenNameextends) {
- getNextToken();
-
- if (token == TokenNameIdentifier) {
- getNextToken();
- } else {
- throwSyntaxError("Class name expected after keyword 'extends'.");
- }
- }
- }
+// private void class_extends(TypeDeclaration typeDecl) {
+// // /* empty */
+// // | T_EXTENDS interface_list
+// if (token == TokenNameextends) {
+// getNextToken();
+//
+// if (token == TokenNameIdentifier) {
+// getNextToken();
+// } else {
+// throwSyntaxError("Class name expected after keyword 'extends'.");
+// }
+// }
+// }
private void interface_extends_list(TypeDeclaration typeDecl) {
// /* empty */
if (lhs != null && lhs instanceof FieldReference) {
addVariableSet(((FieldReference) lhs).token);
}
- // if (lhsVar != null) {
- // addVariableSet(lhsVar);
- // }
getNextToken();
if (token == TokenNameAND) {
getNextToken();
// base_variable_with_function_calls:
// base_variable
//| function_call
- boolean functionCall = false;
if (Scanner.TRACE) {
System.out.println("TRACE: base_variable_with_function_calls()");
}
- // if (token == TokenNameIdentifier) {
- // functionCall = true;
- // } else if (token == TokenNameVariable) {
- // int tempToken = token;
- // int tempPosition = scanner.currentPosition;
- // getNextToken();
- // if (token == TokenNameLPAREN) {
- // functionCall = true;
- // }
- // token = tempToken;
- // scanner.currentPosition = tempPosition;
- // scanner.phpMode = true;
- // }
- // if (functionCall) {
return function_call(lefthandside, ignoreVar);
- // } else {
- // base_variable();
- // }
}
private Expression base_variable() {
// }
// }
- private void encaps_var_offset() {
- // T_STRING
- // | T_NUM_STRING
- // | T_VARIABLE
- switch (token) {
- case TokenNameSTRING:
- getNextToken();
- break;
- case TokenNameIntegerLiteral:
- getNextToken();
- break;
- case TokenNameVariable:
- getNextToken();
- break;
- case TokenNameIdentifier:
- getNextToken();
- break;
- default:
- throwSyntaxError("Variable or String token expected.");
- break;
- }
- }
+// private void encaps_var_offset() {
+// // T_STRING
+// // | T_NUM_STRING
+// // | T_VARIABLE
+// switch (token) {
+// case TokenNameSTRING:
+// getNextToken();
+// break;
+// case TokenNameIntegerLiteral:
+// getNextToken();
+// break;
+// case TokenNameVariable:
+// getNextToken();
+// break;
+// case TokenNameIdentifier:
+// getNextToken();
+// break;
+// default:
+// throwSyntaxError("Variable or String token expected.");
+// break;
+// }
+// }
private void internal_functions_in_yacc() {
// int start = 0;
String filePath = path.toString();
String ext = file.getRawLocation().getFileExtension();
int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
- int length;
impt.tokens = CharOperation.splitOn('/', filePath.toCharArray(), 0, filePath.length() - fileExtensionLength);
impt.setFile(PHPFileUtil.createFile(path, project));
}
}
- public void reportSyntaxError() { //int act, int currentKind, int
- // stateStackTop) {
- /* remember current scanner position */
- int startPos = scanner.startPosition;
- int currentPos = scanner.currentPosition;
- // String[] expectings;
- // String tokenName = name[symbol_index[currentKind]];
- //fetch all "accurate" possible terminals that could recover the error
- // int start, end = start = asi(stack[stateStackTop]);
- // while (asr[end] != 0)
- // end++;
- // int length = end - start;
- // expectings = new String[length];
- // if (length != 0) {
- // char[] indexes = new char[length];
- // System.arraycopy(asr, start, indexes, 0, length);
- // for (int i = 0; i < length; i++) {
- // expectings[i] = name[symbol_index[indexes[i]]];
- // }
- // }
- //if the pb is an EOF, try to tell the user that they are some
- // if (tokenName.equals(UNEXPECTED_EOF)) {
- // if (!this.checkAndReportBracketAnomalies(problemReporter())) {
- // char[] tokenSource;
- // try {
- // tokenSource = this.scanner.getCurrentTokenSource();
- // } catch (Exception e) {
- // tokenSource = new char[] {};
- // }
- // problemReporter().parseError(
- // this.scanner.startPosition,
- // this.scanner.currentPosition - 1,
- // tokenSource,
- // tokenName,
- // expectings);
- // }
- // } else { //the next test is HEAVILY grammar DEPENDENT.
- // if ((length == 14)
- // && (expectings[0] == "=") //$NON-NLS-1$
- // && (expectings[1] == "*=") //$NON-NLS-1$
- // && (expressionPtr > -1)) {
- // switch(currentKind) {
- // case TokenNameSEMICOLON:
- // case TokenNamePLUS:
- // case TokenNameMINUS:
- // case TokenNameDIVIDE:
- // case TokenNameREMAINDER:
- // case TokenNameMULTIPLY:
- // case TokenNameLEFT_SHIFT:
- // case TokenNameRIGHT_SHIFT:
- //// case TokenNameUNSIGNED_RIGHT_SHIFT:
- // case TokenNameLESS:
- // case TokenNameGREATER:
- // case TokenNameLESS_EQUAL:
- // case TokenNameGREATER_EQUAL:
- // case TokenNameEQUAL_EQUAL:
- // case TokenNameNOT_EQUAL:
- // case TokenNameXOR:
- // case TokenNameAND:
- // case TokenNameOR:
- // case TokenNameOR_OR:
- // case TokenNameAND_AND:
- // // the ; is not the expected token ==> it ends a statement when an
- // expression is not ended
- // problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
- // break;
- // case TokenNameRBRACE :
- // problemReporter().missingSemiColon(expressionStack[expressionPtr]);
- // break;
- // default:
- // char[] tokenSource;
- // try {
- // tokenSource = this.scanner.getCurrentTokenSource();
- // } catch (Exception e) {
- // tokenSource = new char[] {};
- // }
- // problemReporter().parseError(
- // this.scanner.startPosition,
- // this.scanner.currentPosition - 1,
- // tokenSource,
- // tokenName,
- // expectings);
- // this.checkAndReportBracketAnomalies(problemReporter());
- // }
- // } else {
- char[] tokenSource;
- try {
- tokenSource = this.scanner.getCurrentTokenSource();
- } catch (Exception e) {
- tokenSource = new char[] {};
- }
- // problemReporter().parseError(
- // this.scanner.startPosition,
- // this.scanner.currentPosition - 1,
- // tokenSource,
- // tokenName,
- // expectings);
- this.checkAndReportBracketAnomalies(problemReporter());
- // }
- // }
- /* reset scanner where it was */
- scanner.startPosition = startPos;
- scanner.currentPosition = currentPos;
- }
+// public void reportSyntaxError() { //int act, int currentKind, int
+// // stateStackTop) {
+// /* remember current scanner position */
+// int startPos = scanner.startPosition;
+// int currentPos = scanner.currentPosition;
+//
+// this.checkAndReportBracketAnomalies(problemReporter());
+// /* reset scanner where it was */
+// scanner.startPosition = startPos;
+// scanner.currentPosition = currentPos;
+// }
public static final int RoundBracket = 0;
/*
* Reconsider the entire source looking for inconsistencies in {} () []
*/
- public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
- scanner.wasAcr = false;
- boolean anomaliesDetected = false;
- try {
- char[] source = scanner.source;
- int[] leftCount = { 0, 0, 0 };
- int[] rightCount = { 0, 0, 0 };
- int[] depths = { 0, 0, 0 };
- int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
- int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
- int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
- int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
- scanner.currentPosition = scanner.initialPosition; //starting
- // point
- // (first-zero-based
- // char)
- while (scanner.currentPosition < scanner.eofPosition) { //loop for
- // jumping
- // over
- // comments
- try {
- // ---------Consume white space and handles
- // startPosition---------
- boolean isWhiteSpace;
- do {
- scanner.startPosition = scanner.currentPosition;
- // if (((scanner.currentCharacter =
- // source[scanner.currentPosition++]) == '\\') &&
- // (source[scanner.currentPosition] == 'u')) {
- // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
- // } else {
- if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
- if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
- // only record line positions we have not
- // recorded yet
- scanner.pushLineSeparator();
- }
- }
- isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
- // }
- } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
- // -------consume token until } is found---------
- switch (scanner.currentCharacter) {
- case '{': {
- int index = leftCount[CurlyBracket]++;
- if (index == leftPositions[CurlyBracket].length) {
- System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
- System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
- }
- leftPositions[CurlyBracket][index] = scanner.startPosition;
- leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
- }
- break;
- case '}': {
- int index = rightCount[CurlyBracket]++;
- if (index == rightPositions[CurlyBracket].length) {
- System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
- System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
- }
- rightPositions[CurlyBracket][index] = scanner.startPosition;
- rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
- }
- break;
- case '(': {
- int index = leftCount[RoundBracket]++;
- if (index == leftPositions[RoundBracket].length) {
- System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
- System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
- }
- leftPositions[RoundBracket][index] = scanner.startPosition;
- leftDepths[RoundBracket][index] = depths[RoundBracket]++;
- }
- break;
- case ')': {
- int index = rightCount[RoundBracket]++;
- if (index == rightPositions[RoundBracket].length) {
- System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
- System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
- }
- rightPositions[RoundBracket][index] = scanner.startPosition;
- rightDepths[RoundBracket][index] = --depths[RoundBracket];
- }
- break;
- case '[': {
- int index = leftCount[SquareBracket]++;
- if (index == leftPositions[SquareBracket].length) {
- System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
- System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
- }
- leftPositions[SquareBracket][index] = scanner.startPosition;
- leftDepths[SquareBracket][index] = depths[SquareBracket]++;
- }
- break;
- case ']': {
- int index = rightCount[SquareBracket]++;
- if (index == rightPositions[SquareBracket].length) {
- System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
- System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
- }
- rightPositions[SquareBracket][index] = scanner.startPosition;
- rightDepths[SquareBracket][index] = --depths[SquareBracket];
- }
- break;
- case '\'': {
- if (scanner.getNextChar('\\')) {
- scanner.scanEscapeCharacter();
- } else { // consume next character
- scanner.unicodeAsBackSlash = false;
- // if (((scanner.currentCharacter =
- // source[scanner.currentPosition++]) ==
- // '\\') &&
- // (source[scanner.currentPosition] ==
- // 'u')) {
- // scanner.getNextUnicodeChar();
- // } else {
- if (scanner.withoutUnicodePtr != 0) {
- scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
- }
- // }
- }
- scanner.getNextChar('\'');
- break;
- }
- case '"':
- // consume next character
- scanner.unicodeAsBackSlash = false;
- // if (((scanner.currentCharacter =
- // source[scanner.currentPosition++]) == '\\') &&
- // (source[scanner.currentPosition] == 'u')) {
- // scanner.getNextUnicodeChar();
- // } else {
- if (scanner.withoutUnicodePtr != 0) {
- scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
- }
- // }
- while (scanner.currentCharacter != '"') {
- if (scanner.currentCharacter == '\r') {
- if (source[scanner.currentPosition] == '\n')
- scanner.currentPosition++;
- break; // the string cannot go further that
- // the line
- }
- if (scanner.currentCharacter == '\n') {
- break; // the string cannot go further that
- // the line
- }
- if (scanner.currentCharacter == '\\') {
- scanner.scanEscapeCharacter();
- }
- // consume next character
- scanner.unicodeAsBackSlash = false;
- // if (((scanner.currentCharacter =
- // source[scanner.currentPosition++]) == '\\')
- // && (source[scanner.currentPosition] == 'u'))
- // {
- // scanner.getNextUnicodeChar();
- // } else {
- if (scanner.withoutUnicodePtr != 0) {
- scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
- }
- // }
- }
- break;
- case '/': {
- int test;
- if ((test = scanner.getNextChar('/', '*')) == 0) { //line
- // comment
- //get the next char
- if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
- && (source[scanner.currentPosition] == 'u')) {
- //-------------unicode traitement
- // ------------
- int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
- scanner.currentPosition++;
- while (source[scanner.currentPosition] == 'u') {
- scanner.currentPosition++;
- }
- if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
- || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
- || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
- || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
- // don't
- // care of the
- // value
- scanner.currentCharacter = 'A';
- } //something different from \n and \r
- else {
- scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
- }
- }
- while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
- //get the next char
- scanner.startPosition = scanner.currentPosition;
- if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
- && (source[scanner.currentPosition] == 'u')) {
- //-------------unicode traitement
- // ------------
- int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
- scanner.currentPosition++;
- while (source[scanner.currentPosition] == 'u') {
- scanner.currentPosition++;
- }
- if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
- || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
- || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
- || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
- // don't
- // care of the
- // value
- scanner.currentCharacter = 'A';
- } //something different from \n
- // and \r
- else {
- scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
- }
- }
- }
- if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
- if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
- // only record line positions we
- // have not recorded yet
- scanner.pushLineSeparator();
- if (this.scanner.taskTags != null) {
- this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
- .getCurrentTokenEndPosition());
- }
- }
- }
- break;
- }
- if (test > 0) { //traditional and annotation
- // comment
- boolean star = false;
- // consume next character
- scanner.unicodeAsBackSlash = false;
- // if (((scanner.currentCharacter =
- // source[scanner.currentPosition++]) ==
- // '\\') &&
- // (source[scanner.currentPosition] ==
- // 'u')) {
- // scanner.getNextUnicodeChar();
- // } else {
- if (scanner.withoutUnicodePtr != 0) {
- scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
- }
- // }
- if (scanner.currentCharacter == '*') {
- star = true;
- }
- //get the next char
- if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
- && (source[scanner.currentPosition] == 'u')) {
- //-------------unicode traitement
- // ------------
- int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
- scanner.currentPosition++;
- while (source[scanner.currentPosition] == 'u') {
- scanner.currentPosition++;
- }
- if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
- || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
- || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
- || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
- // don't
- // care of the
- // value
- scanner.currentCharacter = 'A';
- } //something different from * and /
- else {
- scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
- }
- }
- //loop until end of comment */
- while ((scanner.currentCharacter != '/') || (!star)) {
- star = scanner.currentCharacter == '*';
- //get next char
- if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
- && (source[scanner.currentPosition] == 'u')) {
- //-------------unicode traitement
- // ------------
- int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
- scanner.currentPosition++;
- while (source[scanner.currentPosition] == 'u') {
- scanner.currentPosition++;
- }
- if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
- || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
- || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
- || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
- // don't
- // care of the
- // value
- scanner.currentCharacter = 'A';
- } //something different from * and
- // /
- else {
- scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
- }
- }
- }
- if (this.scanner.taskTags != null) {
- this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
- }
- break;
- }
- break;
- }
- default:
- if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
- scanner.scanIdentifierOrKeyword(false);
- break;
- }
- if (Character.isDigit(scanner.currentCharacter)) {
- scanner.scanNumber(false);
- break;
- }
- }
- //-----------------end switch while
- // try--------------------
- } catch (IndexOutOfBoundsException e) {
- break; // read until EOF
- } catch (InvalidInputException e) {
- return false; // no clue
- }
- }
- if (scanner.recordLineSeparator) {
- compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
- }
- // check placement anomalies against other kinds of brackets
- for (int kind = 0; kind < BracketKinds; kind++) {
- for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
- int start = leftPositions[kind][leftIndex]; // deepest
- // first
- // find matching closing bracket
- int depth = leftDepths[kind][leftIndex];
- int end = -1;
- for (int i = 0; i < rightCount[kind]; i++) {
- int pos = rightPositions[kind][i];
- // want matching bracket further in source with same
- // depth
- if ((pos > start) && (depth == rightDepths[kind][i])) {
- end = pos;
- break;
- }
- }
- if (end < 0) { // did not find a good closing match
- problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
- return true;
- }
- // check if even number of opening/closing other brackets
- // in between this pair of brackets
- int balance = 0;
- for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
- for (int i = 0; i < leftCount[otherKind]; i++) {
- int pos = leftPositions[otherKind][i];
- if ((pos > start) && (pos < end))
- balance++;
- }
- for (int i = 0; i < rightCount[otherKind]; i++) {
- int pos = rightPositions[otherKind][i];
- if ((pos > start) && (pos < end))
- balance--;
- }
- if (balance != 0) {
- problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
- // anomaly
- return true;
- }
- }
- }
- // too many opening brackets ?
- for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
- anomaliesDetected = true;
- problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
- compilationUnit.compilationResult);
- }
- // too many closing brackets ?
- for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
- anomaliesDetected = true;
- problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
- }
- if (anomaliesDetected)
- return true;
- }
- return anomaliesDetected;
- } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
- return anomaliesDetected;
- } catch (NullPointerException e) { // jdk1.2.2 jit bug
- return anomaliesDetected;
- }
- }
+// public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
+// scanner.wasAcr = false;
+// boolean anomaliesDetected = false;
+// try {
+// char[] source = scanner.source;
+// int[] leftCount = { 0, 0, 0 };
+// int[] rightCount = { 0, 0, 0 };
+// int[] depths = { 0, 0, 0 };
+// int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
+// int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
+// int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
+// int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
+// scanner.currentPosition = scanner.initialPosition; //starting
+// // point
+// // (first-zero-based
+// // char)
+// while (scanner.currentPosition < scanner.eofPosition) { //loop for
+// // jumping
+// // over
+// // comments
+// try {
+// // ---------Consume white space and handles
+// // startPosition---------
+// boolean isWhiteSpace;
+// do {
+// scanner.startPosition = scanner.currentPosition;
+// // if (((scanner.currentCharacter =
+// // source[scanner.currentPosition++]) == '\\') &&
+// // (source[scanner.currentPosition] == 'u')) {
+// // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
+// // } else {
+// if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
+// if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
+// // only record line positions we have not
+// // recorded yet
+// scanner.pushLineSeparator();
+// }
+// }
+// isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
+// // }
+// } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
+// // -------consume token until } is found---------
+// switch (scanner.currentCharacter) {
+// case '{': {
+// int index = leftCount[CurlyBracket]++;
+// if (index == leftPositions[CurlyBracket].length) {
+// System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
+// System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
+// }
+// leftPositions[CurlyBracket][index] = scanner.startPosition;
+// leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
+// }
+// break;
+// case '}': {
+// int index = rightCount[CurlyBracket]++;
+// if (index == rightPositions[CurlyBracket].length) {
+// System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
+// System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
+// }
+// rightPositions[CurlyBracket][index] = scanner.startPosition;
+// rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
+// }
+// break;
+// case '(': {
+// int index = leftCount[RoundBracket]++;
+// if (index == leftPositions[RoundBracket].length) {
+// System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
+// System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
+// }
+// leftPositions[RoundBracket][index] = scanner.startPosition;
+// leftDepths[RoundBracket][index] = depths[RoundBracket]++;
+// }
+// break;
+// case ')': {
+// int index = rightCount[RoundBracket]++;
+// if (index == rightPositions[RoundBracket].length) {
+// System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
+// System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
+// }
+// rightPositions[RoundBracket][index] = scanner.startPosition;
+// rightDepths[RoundBracket][index] = --depths[RoundBracket];
+// }
+// break;
+// case '[': {
+// int index = leftCount[SquareBracket]++;
+// if (index == leftPositions[SquareBracket].length) {
+// System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
+// System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
+// }
+// leftPositions[SquareBracket][index] = scanner.startPosition;
+// leftDepths[SquareBracket][index] = depths[SquareBracket]++;
+// }
+// break;
+// case ']': {
+// int index = rightCount[SquareBracket]++;
+// if (index == rightPositions[SquareBracket].length) {
+// System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
+// System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
+// }
+// rightPositions[SquareBracket][index] = scanner.startPosition;
+// rightDepths[SquareBracket][index] = --depths[SquareBracket];
+// }
+// break;
+// case '\'': {
+// if (scanner.getNextChar('\\')) {
+// scanner.scanEscapeCharacter();
+// } else { // consume next character
+// scanner.unicodeAsBackSlash = false;
+// // if (((scanner.currentCharacter =
+// // source[scanner.currentPosition++]) ==
+// // '\\') &&
+// // (source[scanner.currentPosition] ==
+// // 'u')) {
+// // scanner.getNextUnicodeChar();
+// // } else {
+// if (scanner.withoutUnicodePtr != 0) {
+// scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
+// }
+// // }
+// }
+// scanner.getNextChar('\'');
+// break;
+// }
+// case '"':
+// // consume next character
+// scanner.unicodeAsBackSlash = false;
+// // if (((scanner.currentCharacter =
+// // source[scanner.currentPosition++]) == '\\') &&
+// // (source[scanner.currentPosition] == 'u')) {
+// // scanner.getNextUnicodeChar();
+// // } else {
+// if (scanner.withoutUnicodePtr != 0) {
+// scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
+// }
+// // }
+// while (scanner.currentCharacter != '"') {
+// if (scanner.currentCharacter == '\r') {
+// if (source[scanner.currentPosition] == '\n')
+// scanner.currentPosition++;
+// break; // the string cannot go further that
+// // the line
+// }
+// if (scanner.currentCharacter == '\n') {
+// break; // the string cannot go further that
+// // the line
+// }
+// if (scanner.currentCharacter == '\\') {
+// scanner.scanEscapeCharacter();
+// }
+// // consume next character
+// scanner.unicodeAsBackSlash = false;
+// // if (((scanner.currentCharacter =
+// // source[scanner.currentPosition++]) == '\\')
+// // && (source[scanner.currentPosition] == 'u'))
+// // {
+// // scanner.getNextUnicodeChar();
+// // } else {
+// if (scanner.withoutUnicodePtr != 0) {
+// scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
+// }
+// // }
+// }
+// break;
+// case '/': {
+// int test;
+// if ((test = scanner.getNextChar('/', '*')) == 0) { //line
+// // comment
+// //get the next char
+// if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
+// && (source[scanner.currentPosition] == 'u')) {
+// //-------------unicode traitement
+// // ------------
+// int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
+// scanner.currentPosition++;
+// while (source[scanner.currentPosition] == 'u') {
+// scanner.currentPosition++;
+// }
+// if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
+// || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
+// || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
+// || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
+// // don't
+// // care of the
+// // value
+// scanner.currentCharacter = 'A';
+// } //something different from \n and \r
+// else {
+// scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
+// }
+// }
+// while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
+// //get the next char
+// scanner.startPosition = scanner.currentPosition;
+// if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
+// && (source[scanner.currentPosition] == 'u')) {
+// //-------------unicode traitement
+// // ------------
+// int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
+// scanner.currentPosition++;
+// while (source[scanner.currentPosition] == 'u') {
+// scanner.currentPosition++;
+// }
+// if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
+// || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
+// || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
+// || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
+// // don't
+// // care of the
+// // value
+// scanner.currentCharacter = 'A';
+// } //something different from \n
+// // and \r
+// else {
+// scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
+// }
+// }
+// }
+// if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
+// if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
+// // only record line positions we
+// // have not recorded yet
+// scanner.pushLineSeparator();
+// if (this.scanner.taskTags != null) {
+// this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
+// .getCurrentTokenEndPosition());
+// }
+// }
+// }
+// break;
+// }
+// if (test > 0) { //traditional and annotation
+// // comment
+// boolean star = false;
+// // consume next character
+// scanner.unicodeAsBackSlash = false;
+// // if (((scanner.currentCharacter =
+// // source[scanner.currentPosition++]) ==
+// // '\\') &&
+// // (source[scanner.currentPosition] ==
+// // 'u')) {
+// // scanner.getNextUnicodeChar();
+// // } else {
+// if (scanner.withoutUnicodePtr != 0) {
+// scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
+// }
+// // }
+// if (scanner.currentCharacter == '*') {
+// star = true;
+// }
+// //get the next char
+// if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
+// && (source[scanner.currentPosition] == 'u')) {
+// //-------------unicode traitement
+// // ------------
+// int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
+// scanner.currentPosition++;
+// while (source[scanner.currentPosition] == 'u') {
+// scanner.currentPosition++;
+// }
+// if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
+// || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
+// || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
+// || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
+// // don't
+// // care of the
+// // value
+// scanner.currentCharacter = 'A';
+// } //something different from * and /
+// else {
+// scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
+// }
+// }
+// //loop until end of comment */
+// while ((scanner.currentCharacter != '/') || (!star)) {
+// star = scanner.currentCharacter == '*';
+// //get next char
+// if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
+// && (source[scanner.currentPosition] == 'u')) {
+// //-------------unicode traitement
+// // ------------
+// int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
+// scanner.currentPosition++;
+// while (source[scanner.currentPosition] == 'u') {
+// scanner.currentPosition++;
+// }
+// if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
+// || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
+// || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
+// || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
+// // don't
+// // care of the
+// // value
+// scanner.currentCharacter = 'A';
+// } //something different from * and
+// // /
+// else {
+// scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
+// }
+// }
+// }
+// if (this.scanner.taskTags != null) {
+// this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
+// }
+// break;
+// }
+// break;
+// }
+// default:
+// if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
+// scanner.scanIdentifierOrKeyword(false);
+// break;
+// }
+// if (Character.isDigit(scanner.currentCharacter)) {
+// scanner.scanNumber(false);
+// break;
+// }
+// }
+// //-----------------end switch while
+// // try--------------------
+// } catch (IndexOutOfBoundsException e) {
+// break; // read until EOF
+// } catch (InvalidInputException e) {
+// return false; // no clue
+// }
+// }
+// if (scanner.recordLineSeparator) {
+// compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
+// }
+// // check placement anomalies against other kinds of brackets
+// for (int kind = 0; kind < BracketKinds; kind++) {
+// for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
+// int start = leftPositions[kind][leftIndex]; // deepest
+// // first
+// // find matching closing bracket
+// int depth = leftDepths[kind][leftIndex];
+// int end = -1;
+// for (int i = 0; i < rightCount[kind]; i++) {
+// int pos = rightPositions[kind][i];
+// // want matching bracket further in source with same
+// // depth
+// if ((pos > start) && (depth == rightDepths[kind][i])) {
+// end = pos;
+// break;
+// }
+// }
+// if (end < 0) { // did not find a good closing match
+// problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
+// return true;
+// }
+// // check if even number of opening/closing other brackets
+// // in between this pair of brackets
+// int balance = 0;
+// for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
+// for (int i = 0; i < leftCount[otherKind]; i++) {
+// int pos = leftPositions[otherKind][i];
+// if ((pos > start) && (pos < end))
+// balance++;
+// }
+// for (int i = 0; i < rightCount[otherKind]; i++) {
+// int pos = rightPositions[otherKind][i];
+// if ((pos > start) && (pos < end))
+// balance--;
+// }
+// if (balance != 0) {
+// problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
+// // anomaly
+// return true;
+// }
+// }
+// }
+// // too many opening brackets ?
+// for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
+// anomaliesDetected = true;
+// problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
+// compilationUnit.compilationResult);
+// }
+// // too many closing brackets ?
+// for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
+// anomaliesDetected = true;
+// problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
+// }
+// if (anomaliesDetected)
+// return true;
+// }
+// return anomaliesDetected;
+// } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
+// return anomaliesDetected;
+// } catch (NullPointerException e) { // jdk1.2.2 jit bug
+// return anomaliesDetected;
+// }
+// }
protected void pushOnAstLengthStack(int pos) {
try {
String ext = file.getRawLocation().getFileExtension();
int fileExtensionLength = ext == null ? 0 : ext.length() + 1;
ImportReference impt;
- int length;
char[][] tokens;
if (filePath.startsWith(projectPath)) {
tokens = CharOperation
*/
private boolean containsVariableSet() {
return containsVariableSet(scanner.getCurrentTokenSource());
- // if (!fStackUnassigned.isEmpty()) {
- // HashSet set;
- // String str = new String(scanner.getCurrentTokenSource());
- // for (int i = 0; i < fStackUnassigned.size(); i++) {
- // set = (HashSet) fStackUnassigned.get(i);
- // if (set.contains(str)) {
- // return true;
- // }
- // }
- // return false;
- // }
- // return true;
}
private boolean containsVariableSet(char[] token) {