1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-02 13:55:39 +02:00

Refactored declarator() a bit.

This commit is contained in:
John Camelon 2005-05-06 19:44:05 +00:00
parent 6ed4079125
commit 05adf9b805

View file

@ -935,8 +935,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
declSpecifier = declSpecifierSeq(true, true); declSpecifier = declSpecifierSeq(true, true);
if (LT(1) != IToken.tEOC) if (LT(1) != IToken.tEOC)
declarator = declarator( declarator = declarator(
SimpleDeclarationStrategy.TRY_CONSTRUCTOR, forNewExpression, SimpleDeclarationStrategy.TRY_CONSTRUCTOR, forNewExpression);
forNewExpression);
} catch (BacktrackException bt) { } catch (BacktrackException bt) {
backup(mark); backup(mark);
throwBacktrack(startingOffset, figureEndOffset(declSpecifier, throwBacktrack(startingOffset, figureEndOffset(declSpecifier,
@ -3549,7 +3548,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
*/ */
protected IASTDeclarator initDeclarator(SimpleDeclarationStrategy strategy) protected IASTDeclarator initDeclarator(SimpleDeclarationStrategy strategy)
throws EndOfFileException, BacktrackException { throws EndOfFileException, BacktrackException {
IASTDeclarator d = declarator(strategy, false, false); IASTDeclarator d = declarator(strategy, false);
IASTInitializer initializer = optionalCPPInitializer(d); IASTInitializer initializer = optionalCPPInitializer(d);
if (initializer != null) { if (initializer != null) {
@ -3681,19 +3680,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
* (constantExpression)? "]" | "(" declarator")" | directDeclarator "(" * (constantExpression)? "]" | "(" declarator")" | directDeclarator "("
* parameterDeclarationClause ")" (oldKRParameterDeclaration)* declaratorId : * parameterDeclarationClause ")" (oldKRParameterDeclaration)* declaratorId :
* name * name
*
* @param forNewTypeId * @param forNewTypeId
* TODO * TODO
* @param skipArrayDeclarator
* TODO
* @param container * @param container
* IParserCallback object that represents the owner declaration. * IParserCallback object that represents the owner declaration.
*
* @return declarator that this parsing produced. * @return declarator that this parsing produced.
* @throws BacktrackException * @throws BacktrackException
* request a backtrack * request a backtrack
*/ */
protected IASTDeclarator declarator(SimpleDeclarationStrategy strategy, protected IASTDeclarator declarator(SimpleDeclarationStrategy strategy,
boolean forNewTypeId, boolean skipArrayDeclarator) boolean forNewTypeId)
throws EndOfFileException, BacktrackException { throws EndOfFileException, BacktrackException {
IToken la = LA(1); IToken la = LA(1);
@ -3722,8 +3719,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IToken mark = mark(); IToken mark = mark();
try { try {
consume(); consume();
innerDecl = declarator(strategy, forNewTypeId, innerDecl = declarator(strategy, forNewTypeId);
skipArrayDeclarator);
finalOffset = consume(IToken.tRPAREN).getEndOffset(); finalOffset = consume(IToken.tRPAREN).getEndOffset();
} catch (BacktrackException bte) { } catch (BacktrackException bte) {
backup(mark); backup(mark);
@ -3746,32 +3742,33 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
switch (LT(1)) { switch (LT(1)) {
case IToken.tLPAREN: case IToken.tLPAREN:
boolean failed = false; // boolean failed = false;
//
// temporary fix for initializer/function declaration // // temporary fix for initializer/function declaration
// ambiguity // // ambiguity
if (!LA(2).looksLikeExpression() // if (!LA(2).looksLikeExpression()
&& strategy != SimpleDeclarationStrategy.TRY_VARIABLE) { // && strategy != SimpleDeclarationStrategy.TRY_VARIABLE) {
if (LT(2) == IToken.tIDENTIFIER) { // if (LT(2) == IToken.tIDENTIFIER) {
IToken newMark = mark(); // IToken newMark = mark();
consume(IToken.tLPAREN); // consume(IToken.tLPAREN);
try { // try {
name(); // name();
// TODO - we need to lookup/resolve this name // // TODO - we need to lookup/resolve this name
// see if its a type ... // // see if its a type ...
// if it is a type, failed = false // // if it is a type, failed = false
// else failed = true // // else failed = true
failed = false; // failed = false;
} catch (BacktrackException b) { // } catch (BacktrackException b) {
failed = true; // failed = true;
} // }
//
backup(newMark); // backup(newMark);
} // }
} // }
if ((!LA(2).looksLikeExpression() if ((!LA(2).looksLikeExpression()
&& strategy != SimpleDeclarationStrategy.TRY_VARIABLE && strategy != SimpleDeclarationStrategy.TRY_VARIABLE
&& !failed && !forNewTypeId)) { // && !failed
&& !forNewTypeId)) {
// parameterDeclarationClause // parameterDeclarationClause
isFunction = true; isFunction = true;
// TODO need to create a temporary scope object here // TODO need to create a temporary scope object here
@ -3906,7 +3903,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
} }
break; break;
case IToken.tLBRACKET: case IToken.tLBRACKET:
if (skipArrayDeclarator) if (forNewTypeId)
break; break;
arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE); arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
consumeArrayModifiers(arrayMods); consumeArrayModifiers(arrayMods);