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,40 +1580,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
for (;;) { for (;;) {
switch (LT(1)) { switch (LT(1)) {
case IToken.tLPAREN: case IToken.tLPAREN:
boolean failed = false;
// temporary fix for initializer/function declaration
// ambiguity
if (!LA(2).looksLikeExpression()) {
if (LT(2) == IToken.tIDENTIFIER) {
IToken newMark = mark();
consume(IToken.tLPAREN);
ITokenDuple queryName = null;
try {
try {
IToken i = identifier();
queryName = TokenFactory.createTokenDuple(
i, i);
// look it up
failed = true;
} catch (Exception e) {
int endOffset = (lastToken != null) ? lastToken
.getEndOffset()
: 0;
logException(
"declarator:queryIsTypeName", e); //$NON-NLS-1$
throwBacktrack(startingOffset, endOffset,
line, newMark.getFilename());
}
} catch (BacktrackException b) {
failed = true;
}
if (queryName != null)
queryName.freeReferences();
backup(newMark);
}
}
if ((!LA(2).looksLikeExpression() && !failed)) {
// parameterDeclarationClause // parameterDeclarationClause
// d.setIsFunction(true); // d.setIsFunction(true);
// TODO need to create a temporary scope object here // TODO need to create a temporary scope object here
@ -1647,7 +1613,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
seenParameter = true; seenParameter = true;
} }
} }
}
break; break;
case IToken.tLBRACKET: case IToken.tLBRACKET:
if( arrayMods == Collections.EMPTY_LIST ) if( arrayMods == Collections.EMPTY_LIST )