1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Fixed bug in GNUCSourceParser regarding parsing typedefed anonymous structs as parameters in a function definition.

This commit is contained in:
John Camelon 2004-11-23 15:22:42 +00:00
parent 894e597b9e
commit b36410c4ee
2 changed files with 38 additions and 66 deletions

View file

@ -712,5 +712,11 @@ public class AST2Tests extends AST2BaseTest {
assertEquals( label_1, label_2 ); assertEquals( label_1, label_2 );
} }
public void testAnonStruct() throws Exception
{
StringBuffer buffer = new StringBuffer( "typedef struct { } X;\n"); //$NON-NLS-1$
buffer.append( "int f( X x );"); //$NON-NLS-1$
parse( buffer.toString(), ParserLanguage.C );
}
} }

View file

@ -1580,74 +1580,40 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
for (;;) { for (;;) {
switch (LT(1)) { switch (LT(1)) {
case IToken.tLPAREN: case IToken.tLPAREN:
boolean failed = false; // parameterDeclarationClause
// temporary fix for initializer/function declaration // d.setIsFunction(true);
// ambiguity // TODO need to create a temporary scope object here
if (!LA(2).looksLikeExpression()) { consume(IToken.tLPAREN);
if (LT(2) == IToken.tIDENTIFIER) { isFunction = true;
IToken newMark = mark(); boolean seenParameter = false;
consume(IToken.tLPAREN); parameterDeclarationLoop: for (;;) {
ITokenDuple queryName = null; switch (LT(1)) {
try { case IToken.tRPAREN:
try { consume();
IToken i = identifier(); break parameterDeclarationLoop;
queryName = TokenFactory.createTokenDuple( case IToken.tELLIPSIS:
i, i); consume();
// look it up encounteredVarArgs = true;
failed = true; break;
} catch (Exception e) { case IToken.tCOMMA:
int endOffset = (lastToken != null) ? lastToken consume();
.getEndOffset() seenParameter = false;
: 0; break;
logException( default:
"declarator:queryIsTypeName", e); //$NON-NLS-1$ int endOffset = (lastToken != null) ? lastToken
throwBacktrack(startingOffset, endOffset, .getEndOffset() : 0;
line, newMark.getFilename()); if (seenParameter)
} throwBacktrack(startingOffset, endOffset,
} catch (BacktrackException b) { line, fn);
failed = true; IASTParameterDeclaration pd = parameterDeclaration();
} if (parameters == Collections.EMPTY_LIST)
parameters = new ArrayList(
DEFAULT_PARAMETERS_LIST_SIZE);
parameters.add(pd);
seenParameter = true;
}
}
if (queryName != null)
queryName.freeReferences();
backup(newMark);
}
}
if ((!LA(2).looksLikeExpression() && !failed)) {
// parameterDeclarationClause
// d.setIsFunction(true);
// TODO need to create a temporary scope object here
consume(IToken.tLPAREN);
isFunction = true;
boolean seenParameter = false;
parameterDeclarationLoop: for (;;) {
switch (LT(1)) {
case IToken.tRPAREN:
consume();
break parameterDeclarationLoop;
case IToken.tELLIPSIS:
consume();
encounteredVarArgs = true;
break;
case IToken.tCOMMA:
consume();
seenParameter = false;
break;
default:
int endOffset = (lastToken != null) ? lastToken
.getEndOffset() : 0;
if (seenParameter)
throwBacktrack(startingOffset, endOffset,
line, fn);
IASTParameterDeclaration pd = parameterDeclaration();
if (parameters == Collections.EMPTY_LIST)
parameters = new ArrayList(
DEFAULT_PARAMETERS_LIST_SIZE);
parameters.add(pd);
seenParameter = true;
}
}
}
break; break;
case IToken.tLBRACKET: case IToken.tLBRACKET:
if( arrayMods == Collections.EMPTY_LIST ) if( arrayMods == Collections.EMPTY_LIST )