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

Patch for Bryan - 181264 - support content assist in switch and while statements.

This commit is contained in:
Doug Schaefer 2007-05-16 19:34:59 +00:00
parent 809ce2a43e
commit 9d0bde031c
3 changed files with 85 additions and 18 deletions

View file

@ -100,4 +100,29 @@ public class BasicCompletionTest extends CompletionTestBase {
assertEquals("blah", ((ITypedef)bindings[0]).getName());
}
public void testBug181624() throws Exception {
StringBuffer code = new StringBuffer();
code.append("void foo() {");
code.append(" switch (");
// C++
IASTCompletionNode node = getGPPCompletionNode(code.toString());
assertNotNull(node);
// C
node = getGCCCompletionNode(code.toString());
assertNotNull(node);
code = new StringBuffer();
code.append("void foo() {");
code.append(" while (");
// C++
node = getGPPCompletionNode(code.toString());
assertNotNull(node);
// C
node = getGCCCompletionNode(code.toString());
assertNotNull(node);
}
}

View file

@ -2936,18 +2936,32 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
startOffset = consume().getOffset();
consume(IToken.tLPAREN);
IASTExpression switch_condition = condition();
consume(IToken.tRPAREN);
IASTStatement switch_body = statement();
switch (LT(1)) {
case IToken.tRPAREN:
consume();
break;
case IToken.tEOC:
break;
default:
throwBacktrack(LA(1));
}
IASTStatement switch_body = null;
if (LT(1) != IToken.tEOC)
switch_body = statement();
IASTSwitchStatement switch_statement = createSwitchStatement();
((ASTNode) switch_statement).setOffsetAndLength(startOffset,
calculateEndOffset(switch_body) - startOffset);
(switch_body != null ? calculateEndOffset(switch_body) : LA(1).getEndOffset()) - startOffset);
switch_statement.setControllerExpression(switch_condition);
switch_condition.setParent(switch_statement);
switch_condition.setPropertyInParent(IASTSwitchStatement.CONTROLLER_EXP);
switch_statement.setBody(switch_body);
switch_body.setParent(switch_statement);
switch_body.setPropertyInParent(IASTSwitchStatement.BODY);
if (switch_body != null) {
switch_statement.setBody(switch_body);
switch_body.setParent(switch_statement);
switch_body.setPropertyInParent(IASTSwitchStatement.BODY);
}
return switch_statement;
}

View file

@ -5212,12 +5212,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
int startOffset = consume().getOffset();
consume(IToken.tLPAREN);
IASTNode while_condition = cppStyleCondition(true);
consume(IToken.tRPAREN);
IASTStatement while_body = statement();
switch (LT(1)) {
case IToken.tRPAREN:
consume();
break;
case IToken.tEOC:
break;
default:
throwBacktrack(LA(1));
}
IASTStatement while_body = null;
if (LT(1) != IToken.tEOC)
while_body = statement();
ICPPASTWhileStatement while_statement = (ICPPASTWhileStatement) createWhileStatement();
((ASTNode) while_statement).setOffsetAndLength(startOffset,
calculateEndOffset(while_body) - startOffset);
(while_body != null ? calculateEndOffset(while_body) : LA(1).getEndOffset()) - startOffset);
if (while_condition instanceof IASTExpression) {
while_statement.setCondition((IASTExpression) while_condition);
while_condition.setParent(while_statement);
@ -5230,9 +5240,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
while_condition
.setPropertyInParent(ICPPASTWhileStatement.CONDITIONDECLARATION);
}
while_statement.setBody(while_body);
while_body.setParent(while_statement);
while_body.setPropertyInParent(IASTWhileStatement.BODY);
if (while_body != null) {
while_statement.setBody(while_body);
while_body.setParent(while_statement);
while_body.setPropertyInParent(IASTWhileStatement.BODY);
}
return while_statement;
}
@ -5488,12 +5502,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
startOffset = consume().getOffset();
consume(IToken.tLPAREN);
IASTNode switch_condition = cppStyleCondition(true);
consume(IToken.tRPAREN);
IASTStatement switch_body = statement();
switch (LT(1)) {
case IToken.tRPAREN:
consume();
break;
case IToken.tEOC:
break;
default:
throwBacktrack(LA(1));
}
IASTStatement switch_body = null;
if (LT(1) != IToken.tEOC)
switch_body = statement();
ICPPASTSwitchStatement switch_statement = createSwitchStatement();
((ASTNode) switch_statement).setOffsetAndLength(startOffset,
calculateEndOffset(switch_body) - startOffset);
(switch_body != null ? calculateEndOffset(switch_body) : LA(1).getEndOffset()) - startOffset);
if( switch_condition instanceof IASTExpression )
{
switch_statement.setControllerExpression((IASTExpression) switch_condition);
@ -5506,9 +5530,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
switch_condition.setParent(switch_statement);
switch_condition.setPropertyInParent(ICPPASTSwitchStatement.CONTROLLER_DECLARATION);
}
switch_statement.setBody(switch_body);
switch_body.setParent(switch_statement);
switch_body.setPropertyInParent(IASTSwitchStatement.BODY);
if (switch_body != null) {
switch_statement.setBody(switch_body);
switch_body.setParent(switch_statement);
switch_body.setPropertyInParent(IASTSwitchStatement.BODY);
}
return switch_statement;
}