1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 234463, fix for testForStatement1

This commit is contained in:
Mike Kucera 2008-05-28 19:50:25 +00:00
parent 3e8493f505
commit 8037d270d8
2 changed files with 28 additions and 0 deletions

View file

@ -28,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
@ -667,6 +668,20 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
else // its null
initializer = nodeFactory.newNullStatement();
// bug 234463, fix for content assist to work in this case
int TK_EOC = TK_EndOfCompletion; // TODO: change this in the grammar file
List<IToken> tokens = parser.getRuleTokens();
if(matchTokens(tokens, tokenMap,
TK_for, TK_LeftParen, TK_Completion, TK_EOC, TK_EOC, TK_EOC, TK_EOC)) {
IASTName name = createName(tokens.get(2));
IASTIdExpression idExpression = nodeFactory.newIdExpression(name);
setOffsetAndLength(idExpression, offset(name), length(name));
initializer = nodeFactory.newExpressionStatement(idExpression);
setOffsetAndLength(initializer, offset(name), length(name));
}
if(node != null)
setOffsetAndLength(initializer, offset(node), length(node));

View file

@ -637,6 +637,19 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
Object condition = astStack.pop(); // can be an expression or a declaration
IASTStatement initializer = (IASTStatement) astStack.pop();
// bug 234463, fix for content assist to work in this case
int TK_EOC = TK_EndOfCompletion; // TODO: change this in the grammar file
List<IToken> tokens = parser.getRuleTokens();
if(matchTokens(tokens, tokenMap,
TK_for, TK_LeftParen, TK_Completion, TK_EOC, TK_EOC, TK_EOC, TK_EOC)) {
IASTName name = createName(tokens.get(2));
IASTIdExpression idExpression = nodeFactory.newIdExpression(name);
setOffsetAndLength(idExpression, offset(name), length(name));
initializer = nodeFactory.newExpressionStatement(idExpression);
setOffsetAndLength(initializer, offset(name), length(name));
}
IASTForStatement forStat;
if(condition instanceof IASTExpression)
forStat = nodeFactory.newForStatement(initializer, (IASTExpression)condition, expr, body);