1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

cleaned up the code in parseTypeIdOrUnaryExpression()

This commit is contained in:
Mike Kucera 2008-02-05 15:40:42 +00:00
parent 22f2deea94
commit a8f928a682

View file

@ -1938,16 +1938,14 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
throwBacktrack(token.getOffset(), token.getLength()); throwBacktrack(token.getOffset(), token.getLength());
} }
protected IASTNode[] parseTypeIdOrUnaryExpression( protected IASTNode[] parseTypeIdOrUnaryExpression(boolean typeIdWithParentheses) throws EndOfFileException {
boolean typeIdWithParentheses) throws EndOfFileException {
return parseTypeIdOrUnaryExpression(typeIdWithParentheses, new int[1]); return parseTypeIdOrUnaryExpression(typeIdWithParentheses, new int[1]);
} }
protected IASTNode[] parseTypeIdOrUnaryExpression( protected IASTNode[] parseTypeIdOrUnaryExpression(boolean typeIdWithParentheses, int[] endoffset) throws EndOfFileException {
boolean typeIdWithParentheses, int[] endoffset) throws EndOfFileException {
IASTTypeId typeId = null; IASTTypeId typeId = null;
IASTExpression unaryExpression = null;
IToken typeIdLA = null, unaryExpressionLA = null; IToken typeIdLA = null;
IToken mark = mark(); IToken mark = mark();
try { try {
if (typeIdWithParentheses) if (typeIdWithParentheses)
@ -1971,36 +1969,27 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
} }
} }
} catch (BacktrackException e) { } catch (BacktrackException e) { }
typeId = null;
}
backup(mark); backup(mark);
IToken unaryExpressionLA = null;
IASTExpression unaryExpression = null;
try { try {
unaryExpression = unaryExpression(); unaryExpression = unaryExpression(); // throws BacktrackException
unaryExpressionLA = LA(1); unaryExpressionLA = LA(1);
} catch (BacktrackException bte) { } catch (BacktrackException bte) { }
unaryExpression = null;
}
IASTNode[] result;
if (unaryExpression == null && typeId != null) { if (unaryExpression == null && typeId != null) {
backup(typeIdLA); backup(typeIdLA);
result = new IASTNode[1]; return new IASTNode[] {typeId};
result[0] = typeId;
return result;
} }
if (unaryExpression != null && typeId == null) { if (unaryExpression != null && typeId == null) {
backup(unaryExpressionLA); backup(unaryExpressionLA);
result = new IASTNode[1];
result[0] = unaryExpression;
endoffset[0]= calculateEndOffset(unaryExpression); endoffset[0]= calculateEndOffset(unaryExpression);
return result; return new IASTNode[] {unaryExpression};
} }
if (unaryExpression != null && typeId != null if (unaryExpression != null && typeId != null && typeIdLA == unaryExpressionLA) {
&& typeIdLA == unaryExpressionLA) { return new IASTNode[] {typeId, unaryExpression};
result = new IASTNode[2];
result[0] = typeId;
result[1] = unaryExpression;
return result;
} }
return EMPTY_NODE_ARRAY; return EMPTY_NODE_ARRAY;