1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 11:25:35 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-04-08 22:25:36 -07:00
parent 2ab852ece0
commit 07561ca883
3 changed files with 25 additions and 33 deletions

View file

@ -563,10 +563,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
/** /**
* Parse an identifier. * Parses an identifier.
* *
* @throws BacktrackException * @throws BacktrackException request a backtrack
* request a backtrack
*/ */
protected abstract IASTName identifier() throws EndOfFileException, BacktrackException; protected abstract IASTName identifier() throws EndOfFileException, BacktrackException;
@ -1242,7 +1241,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
IASTCastExpression result = buildCastExpression(IASTCastExpression.op_cast, IASTCastExpression result = buildCastExpression(IASTCastExpression.op_cast,
typeId, rhs, startingOffset, calculateEndOffset(rhs)); typeId, rhs, startingOffset, calculateEndOffset(rhs));
if (!unaryFailed && couldBeFunctionCall && rhs instanceof IASTCastExpression == false) { if (!unaryFailed && couldBeFunctionCall && !(rhs instanceof IASTCastExpression)) {
IToken markEnd= mark(); IToken markEnd= mark();
backup(mark); backup(mark);
try { try {
@ -2164,27 +2163,25 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return cs; return cs;
} }
protected int figureEndOffset(IASTDeclSpecifier declSpec, IASTDeclarator[] declarators) { protected int figureEndOffset(IASTDeclSpecifier declSpec, IASTDeclarator[] declarators) {
if (declarators.length == 0) if (declarators.length == 0)
return calculateEndOffset(declSpec); return calculateEndOffset(declSpec);
return calculateEndOffset(declarators[declarators.length - 1]); return calculateEndOffset(declarators[declarators.length - 1]);
} }
protected int figureEndOffset(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) { protected int figureEndOffset(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
if (declarator == null || ((ASTNode) declarator).getLength() == 0) if (declarator == null || ((ASTNode) declarator).getLength() == 0)
return calculateEndOffset(declSpecifier); return calculateEndOffset(declSpecifier);
return calculateEndOffset(declarator); return calculateEndOffset(declarator);
} }
protected void throwBacktrack(IToken token) throws BacktrackException { protected void throwBacktrack(IToken token) throws BacktrackException {
throwBacktrack(token.getOffset(), token.getLength()); throwBacktrack(token.getOffset(), token.getLength());
} }
protected IASTExpression parseTypeidInParenthesisOrUnaryExpression(boolean exprIsLimitedToParenthesis, protected IASTExpression parseTypeidInParenthesisOrUnaryExpression(boolean exprIsLimitedToParenthesis,
int offset, int typeExprKind, int unaryExprKind, CastExprCtx ctx, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException { int offset, int typeExprKind, int unaryExprKind, CastExprCtx ctx, ITemplateIdStrategy strat)
throws BacktrackException, EndOfFileException {
IASTTypeId typeid; IASTTypeId typeid;
IASTExpression expr= null; IASTExpression expr= null;
IToken typeidLA= null; IToken typeidLA= null;
@ -2315,7 +2312,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
/** /**
* Accept a sequence of __attribute__ or __declspec * Accepts a sequence of __attribute__ or __declspec.
* *
* @param allowAttrib if true accept any number of __attribute__ * @param allowAttrib if true accept any number of __attribute__
* @param allowDeclspec if true accept any number of __declspec * @param allowDeclspec if true accept any number of __declspec
@ -2416,7 +2413,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
* @throws EndOfFileException * @throws EndOfFileException
*/ */
protected void handleOtherDeclSpecModifier() throws BacktrackException, EndOfFileException { protected void handleOtherDeclSpecModifier() throws BacktrackException, EndOfFileException {
// default action: consume keyword plus optional parenthesised "something" // default action: consume keyword plus optional parenthesized "something"
consume(); consume();
IToken token = LA(1); IToken token = LA(1);

View file

@ -6,10 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* John Camelon (IBM Rational Software) - Initial API and implementation * John Camelon (IBM Rational Software) - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Ed Swartz (Nokia) * Ed Swartz (Nokia)
* Mike Kucera (IBM) - bug #206952 * Mike Kucera (IBM) - bug #206952
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -415,7 +415,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
final IASTDeclarator outerDtor= declarators[0]; final IASTDeclarator outerDtor= declarators[0];
final IASTDeclarator fdtor= ASTQueries.findTypeRelevantDeclarator(outerDtor); final IASTDeclarator fdtor= ASTQueries.findTypeRelevantDeclarator(outerDtor);
if (fdtor instanceof IASTFunctionDeclarator == false) if (!(fdtor instanceof IASTFunctionDeclarator))
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
IASTFunctionDefinition funcDefinition = nodeFactory.newFunctionDefinition(declSpec, (IASTFunctionDeclarator) fdtor, null); IASTFunctionDefinition funcDefinition = nodeFactory.newFunctionDefinition(declSpec, (IASTFunctionDeclarator) fdtor, null);
@ -465,8 +465,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
} }
private IASTExpression expression(final ExprKind kind) throws EndOfFileException, BacktrackException { private IASTExpression expression(final ExprKind kind) throws EndOfFileException, BacktrackException {
final boolean allowComma= kind==ExprKind.eExpression; final boolean allowComma= kind == ExprKind.eExpression;
boolean allowAssignment= kind !=ExprKind.eConstant; boolean allowAssignment= kind != ExprKind.eConstant;
int lt1; int lt1;
int conditionCount= 0; int conditionCount= 0;
BinaryOperator lastOperator= null; BinaryOperator lastOperator= null;
@ -479,7 +479,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
// <logical-or> ? <expression> : <assignment-expression> // <logical-or> ? <expression> : <assignment-expression>
// Precedence: 25 is lower than precedence of logical or; 0 is lower than precedence of expression // Precedence: 25 is lower than precedence of logical or; 0 is lower than precedence of expression
lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 25, 0); lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 25, 0);
if (LT(2) == IToken.tCOLON) { if (LT(2) == IToken.tCOLON) {
// Gnu extension: The expression after '?' can be omitted. // Gnu extension: The expression after '?' can be omitted.
consume(); // Consume operator consume(); // Consume operator
lastExpression= null; // Next cast expression is just null lastExpression= null; // Next cast expression is just null
@ -1491,7 +1491,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
int startOffset= last.getOffset(); int startOffset= last.getOffset();
// check for K&R C parameters (0 means it's not K&R C) // check for K&R C parameters (0 means it's not K&R C)
if (fPreventKnrCheck==0 && supportKnRC) { if (fPreventKnrCheck == 0 && supportKnRC) {
fPreventKnrCheck++; fPreventKnrCheck++;
try { try {
final int numKnRCParms = countKnRCParms(); final int numKnRCParms = countKnRCParms();
@ -1597,7 +1597,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
} }
private IASTSimpleDeclaration checkKnrParameterDeclaration(IASTDeclaration decl, final IASTName[] parmNames) { private IASTSimpleDeclaration checkKnrParameterDeclaration(IASTDeclaration decl, final IASTName[] parmNames) {
if (decl instanceof IASTSimpleDeclaration == false) if (!(decl instanceof IASTSimpleDeclaration))
return null; return null;
IASTSimpleDeclaration declaration= ((IASTSimpleDeclaration) decl); IASTSimpleDeclaration declaration= ((IASTSimpleDeclaration) decl);
@ -1839,7 +1839,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
return parseDeclarationOrExpressionStatement(); return parseDeclarationOrExpressionStatement();
} }
} }
@Override @Override
@ -1863,7 +1862,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
previousWasIdentifier = false; previousWasIdentifier = false;
} else if (LT(1) == IToken.tIDENTIFIER) { } else if (LT(1) == IToken.tIDENTIFIER) {
consume(); consume();
if (previousWasIdentifier == true) { if (previousWasIdentifier) {
backup(mark); backup(mark);
return 0; // i.e. KnR C won't have int f(typedef x) return 0; // i.e. KnR C won't have int f(typedef x)
// char // char
@ -2011,9 +2010,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (if_statement != null) { if (if_statement != null) {
if_statement.setElseClause(new_if_statement); if_statement.setElseClause(new_if_statement);
((ASTNode) if_statement) ((ASTNode) if_statement).setLength(calculateEndOffset(new_if_statement)
.setLength(calculateEndOffset(new_if_statement) - ((ASTNode) if_statement).getOffset());
- ((ASTNode) if_statement).getOffset());
} }
if (result == null && if_statement != null) if (result == null && if_statement != null)
result = if_statement; result = if_statement;
@ -2027,9 +2025,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
new_if_statement.setElseClause(elseStatement); new_if_statement.setElseClause(elseStatement);
if (if_statement != null) { if (if_statement != null) {
if_statement.setElseClause(new_if_statement); if_statement.setElseClause(new_if_statement);
((ASTNode) if_statement) ((ASTNode) if_statement).setLength(calculateEndOffset(new_if_statement)
.setLength(calculateEndOffset(new_if_statement) - ((ASTNode) if_statement).getOffset());
- ((ASTNode) if_statement).getOffset());
} else { } else {
if (result == null) if (result == null)
result = new_if_statement; result = new_if_statement;
@ -2037,12 +2034,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
} }
} else { } else {
if( thenClause != null ) if( thenClause != null )
((ASTNode) new_if_statement) ((ASTNode) new_if_statement).setLength(calculateEndOffset(thenClause) - start);
.setLength(calculateEndOffset(thenClause) - start);
if (if_statement != null) { if (if_statement != null) {
if_statement.setElseClause(new_if_statement); if_statement.setElseClause(new_if_statement);
((ASTNode) new_if_statement) ((ASTNode) new_if_statement).setLength(calculateEndOffset(new_if_statement) - start);
.setLength(calculateEndOffset(new_if_statement) - start);
} }
if (result == null && if_statement != null) if (result == null && if_statement != null)
result = if_statement; result = if_statement;

View file

@ -2454,7 +2454,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IASTDeclarator outerDtor) throws EndOfFileException, BacktrackException { IASTDeclarator outerDtor) throws EndOfFileException, BacktrackException {
final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(outerDtor); final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(outerDtor);
if (dtor instanceof ICPPASTFunctionDeclarator == false) if (!(dtor instanceof ICPPASTFunctionDeclarator))
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);