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

Fixes endless loop of content assist within c-initializer clause, bug 230389.

This commit is contained in:
Markus Schorn 2008-05-07 09:13:03 +00:00
parent b8817c486c
commit 215d87e7ae
3 changed files with 35 additions and 9 deletions

View file

@ -184,7 +184,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
for (;;) {
int checkHashcode = LA(1).hashCode();
final IToken startToken= LA(1);
// required at least one initializer list
// get designator list
List<IASTNode> newDesignators = designatorList();
@ -208,18 +208,18 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
desigInitializer.setOperandInitializer(initializer);
result.addInitializer(desigInitializer);
}
// can end with just a '}'
if (LT(1) == IToken.tRBRACE)
break;
// can end with ", }"
// can end with ", }" or "}"
if (LT(1) == IToken.tCOMMA)
consume();
if (LT(1) == IToken.tRBRACE)
break;
if (checkHashcode == LA(1).hashCode()) {
IToken l2 = LA(1);
throwBacktrack(startingOffset, l2.getEndOffset()
- startingOffset);
final IToken nextToken= LA(1);
if (nextToken.getType() == IToken.tEOC) {
return result;
}
if (nextToken == startToken) {
throwBacktrack(startingOffset, nextToken.getEndOffset() - startingOffset);
return null;
}

View file

@ -203,6 +203,10 @@ public class CompletionTests extends AbstractContentAssistTest {
assertContentAssistResults(offset, expected, true, compareType);
}
protected void assertCompletionResults(String[] expected) throws Exception {
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
}
//void gfunc() {C1 v; v.m/*cursor*/
public void _testLocalVariable() throws Exception {
// fails because of additional m1private(void)
@ -1132,4 +1136,15 @@ public class CompletionTests extends AbstractContentAssistTest {
final String[] expected= {"blocal"};
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
}
// enum {enum0, enum1, enum2};
// typedef struct {
// int byte1;
// int byte2;
// } MYSTRUCT_TYPE;
// static const MYSTRUCT_TYPE myArrayOfStructs[] = {{enum/*cursor*/
public void testCompletionInInitializerList_Bug230389() throws Exception {
final String[] expected= {"enum0", "enum1", "enum2"};
assertCompletionResults(expected);
}
}

View file

@ -928,4 +928,15 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest {
final String[] expected= {"pIShell"};
assertCompletionResults(expected);
}
// enum {enum0, enum1, enum2};
// typedef struct {
// int byte1;
// int byte2;
// } MYSTRUCT_TYPE;
// static const MYSTRUCT_TYPE myArrayOfStructs[] = {{enum/*cursor*/
public void testCompletionInInitializerList_Bug230389() throws Exception {
final String[] expected= {"enum0", "enum1", "enum2"};
assertCompletionResults(expected);
}
}