mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
fixed bug in testFunction(), removed needless extra empty declarations caused by extra completion tokens
This commit is contained in:
parent
9cd75c484e
commit
c693b2518a
6 changed files with 48 additions and 26 deletions
|
@ -62,13 +62,13 @@ public class C99CompleteParser2Tests extends CompleteParser2Tests {
|
||||||
// fail();
|
// fail();
|
||||||
// } catch(AssertionError _) { }
|
// } catch(AssertionError _) { }
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
//
|
|
||||||
// public void testBug102376() throws Exception { // gcc extension
|
public void testBug102376() throws Exception { // gcc extension
|
||||||
// try {
|
try {
|
||||||
// super.testBug102376();
|
super.testBug102376();
|
||||||
// fail();
|
fail();
|
||||||
// } catch(AssertionError _) { }
|
} catch(AssertionFailedError _) { }
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,10 +44,6 @@ public class C99CompletionBasicTest extends BasicCompletionTest {
|
||||||
return C99Language.getDefault();
|
return C99Language.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The C99 parser currently doesn't support ambiguity nodes.
|
|
||||||
// Therefore calling IASTCompletionNode.getNames() will
|
|
||||||
// never return more than one name.
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void testFunction() throws Exception {
|
public void testFunction() throws Exception {
|
||||||
|
@ -60,9 +56,9 @@ public class C99CompletionBasicTest extends BasicCompletionTest {
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
|
|
||||||
// There is only one name, for now
|
// There is only one name, for now
|
||||||
assertEquals(1, names.length);
|
assertEquals(2, names.length);
|
||||||
// The expression points to our functions
|
// The expression points to our functions
|
||||||
IBinding[] bindings = sortBindings(names[0].getCompletionContext().findBindings(names[0], true));
|
IBinding[] bindings = sortBindings(names[1].getCompletionContext().findBindings(names[1], true));
|
||||||
// There should be two since they both start with fu
|
// There should be two since they both start with fu
|
||||||
assertEquals(2, bindings.length);
|
assertEquals(2, bindings.length);
|
||||||
assertEquals("func", ((IFunction)bindings[0]).getName());//$NON-NLS-1$
|
assertEquals("func", ((IFunction)bindings[0]).getName());//$NON-NLS-1$
|
||||||
|
|
|
@ -72,10 +72,8 @@ class CPreprocessorAdapter {
|
||||||
org.eclipse.cdt.core.parser.IToken domEocToken = preprocessor.nextToken();
|
org.eclipse.cdt.core.parser.IToken domEocToken = preprocessor.nextToken();
|
||||||
assert domEocToken.getType() == tEOC;
|
assert domEocToken.getType() == tEOC;
|
||||||
|
|
||||||
IToken eocToken = createEOCToken(domEocToken, tokenMap);
|
|
||||||
|
|
||||||
for(int i = 0; i < NUM_EOC_TOKENS; i++)
|
for(int i = 0; i < NUM_EOC_TOKENS; i++)
|
||||||
tokenCollector.addToken(eocToken); // reuse the same reference, no need to create several objects
|
tokenCollector.addToken(createEOCToken(domEocToken, tokenMap));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
package org.eclipse.cdt.core.dom.lrparser.action;
|
package org.eclipse.cdt.core.dom.lrparser.action;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
|
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
@ -37,7 +38,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
*/
|
*/
|
||||||
public class ASTCompletionNode implements IASTCompletionNode {
|
public class ASTCompletionNode implements IASTCompletionNode {
|
||||||
|
|
||||||
private final LinkedList<IASTName> names = new LinkedList<IASTName>();
|
private final List<IASTName> names = new LinkedList<IASTName>();
|
||||||
|
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
private final IASTTranslationUnit tu;
|
private final IASTTranslationUnit tu;
|
||||||
|
@ -73,7 +74,7 @@ public class ASTCompletionNode implements IASTCompletionNode {
|
||||||
|
|
||||||
|
|
||||||
public IASTName[] getNames() {
|
public IASTName[] getNames() {
|
||||||
return names.toArray(new IASTName[0]);
|
return names.toArray(new IASTName[names.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -98,8 +98,8 @@ public abstract class BuildASTParserAction {
|
||||||
|
|
||||||
// turn debug tracing on and off
|
// turn debug tracing on and off
|
||||||
// TODO move this into an AspectJ project
|
// TODO move this into an AspectJ project
|
||||||
protected static final boolean TRACE_ACTIONS = true;
|
protected static final boolean TRACE_ACTIONS = false;
|
||||||
protected static final boolean TRACE_AST_STACK = true;
|
protected static final boolean TRACE_AST_STACK = false;
|
||||||
|
|
||||||
|
|
||||||
/** Stack that holds the intermediate nodes as the AST is being built */
|
/** Stack that holds the intermediate nodes as the AST is being built */
|
||||||
|
@ -163,6 +163,19 @@ public abstract class BuildASTParserAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to combine completion nodes from secondary parsers into
|
||||||
|
* the main completion node.
|
||||||
|
*/
|
||||||
|
protected void addNameToCompletionNode(IASTCompletionNode node) {
|
||||||
|
if(node == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(IASTName name : node.getNames())
|
||||||
|
addNameToCompletionNode(name, node.getPrefix());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the completion node if this is a completion parse, null otherwise.
|
* Returns the completion node if this is a completion parse, null otherwise.
|
||||||
*/
|
*/
|
||||||
|
@ -469,7 +482,8 @@ public abstract class BuildASTParserAction {
|
||||||
// try parsing as non-cast to resolve ambiguities
|
// try parsing as non-cast to resolve ambiguities
|
||||||
C99NoCastExpressionParser alternateParser = new C99NoCastExpressionParser(C99Parsersym.orderedTerminalSymbols);
|
C99NoCastExpressionParser alternateParser = new C99NoCastExpressionParser(C99Parsersym.orderedTerminalSymbols);
|
||||||
alternateParser.setTokens(parser.getRuleTokens());
|
alternateParser.setTokens(parser.getRuleTokens());
|
||||||
alternateParser.parse(tu);
|
IASTCompletionNode compNode = alternateParser.parse(tu);
|
||||||
|
addNameToCompletionNode(compNode);
|
||||||
IASTExpression alternateExpr = alternateParser.getParseResult();
|
IASTExpression alternateExpr = alternateParser.getParseResult();
|
||||||
|
|
||||||
if(alternateExpr == null || alternateExpr instanceof IASTProblemExpression)
|
if(alternateExpr == null || alternateExpr instanceof IASTProblemExpression)
|
||||||
|
|
|
@ -38,6 +38,7 @@ import java.util.List;
|
||||||
|
|
||||||
import lpg.lpgjavaruntime.IToken;
|
import lpg.lpgjavaruntime.IToken;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
@ -192,7 +193,8 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
|
||||||
// try parsing as an expression to resolve ambiguities
|
// try parsing as an expression to resolve ambiguities
|
||||||
C99SizeofExpressionParser alternateParser = new C99SizeofExpressionParser(C99Parsersym.orderedTerminalSymbols);
|
C99SizeofExpressionParser alternateParser = new C99SizeofExpressionParser(C99Parsersym.orderedTerminalSymbols);
|
||||||
alternateParser.setTokens(parser.getRuleTokens());
|
alternateParser.setTokens(parser.getRuleTokens());
|
||||||
alternateParser.parse(tu);
|
IASTCompletionNode completionNode = alternateParser.parse(tu);
|
||||||
|
addNameToCompletionNode(completionNode);
|
||||||
IASTExpression alternateExpr = alternateParser.getParseResult();
|
IASTExpression alternateExpr = alternateParser.getParseResult();
|
||||||
|
|
||||||
if(alternateExpr == null || alternateExpr instanceof IASTProblemExpression)
|
if(alternateExpr == null || alternateExpr instanceof IASTProblemExpression)
|
||||||
|
@ -580,6 +582,14 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
|
||||||
public void consumeDeclarationEmpty() {
|
public void consumeDeclarationEmpty() {
|
||||||
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
|
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
|
||||||
|
|
||||||
|
// Don't generate declaration nodes for extra EOC tokens
|
||||||
|
// TODO: the token type must be converted
|
||||||
|
if(asC99Kind(parser.getLeftIToken()) == C99Parsersym.TK_EndOfCompletion)
|
||||||
|
return;
|
||||||
|
|
||||||
|
List<IToken> tokens = parser.getRuleTokens();
|
||||||
|
|
||||||
|
System.out.println("what: " + parser.getLeftIToken().getKind());
|
||||||
IASTDeclSpecifier declSpecifier = nodeFactory.newCSimpleDeclSpecifier();
|
IASTDeclSpecifier declSpecifier = nodeFactory.newCSimpleDeclSpecifier();
|
||||||
IASTSimpleDeclaration declaration = nodeFactory.newSimpleDeclaration(declSpecifier);
|
IASTSimpleDeclaration declaration = nodeFactory.newSimpleDeclaration(declSpecifier);
|
||||||
setOffsetAndLength(declSpecifier);
|
setOffsetAndLength(declSpecifier);
|
||||||
|
@ -690,7 +700,8 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
|
||||||
C99ExpressionStatementParser expressionParser = new C99ExpressionStatementParser(C99Parsersym.orderedTerminalSymbols);
|
C99ExpressionStatementParser expressionParser = new C99ExpressionStatementParser(C99Parsersym.orderedTerminalSymbols);
|
||||||
expressionParser.setTokens(parser.getRuleTokens());
|
expressionParser.setTokens(parser.getRuleTokens());
|
||||||
// need to pass tu because any completion nodes need to be linked directly to the root
|
// need to pass tu because any completion nodes need to be linked directly to the root
|
||||||
expressionParser.parse(tu);
|
IASTCompletionNode compNode = expressionParser.parse(tu);
|
||||||
|
addNameToCompletionNode(compNode);
|
||||||
IASTExpression expr = expressionParser.getParseResult();
|
IASTExpression expr = expressionParser.getParseResult();
|
||||||
|
|
||||||
if(expr != null && !(expr instanceof IASTProblemExpression)) { // the parse may fail
|
if(expr != null && !(expr instanceof IASTProblemExpression)) { // the parse may fail
|
||||||
|
@ -699,10 +710,12 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expressionStatement == null)
|
if(expressionStatement == null) {
|
||||||
astStack.push(declarationStatement);
|
astStack.push(declarationStatement);
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
astStack.push(nodeFactory.newAmbiguousStatement(declarationStatement, expressionStatement));
|
astStack.push(nodeFactory.newAmbiguousStatement(declarationStatement, expressionStatement));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(TRACE_AST_STACK) System.out.println(astStack);
|
if(TRACE_AST_STACK) System.out.println(astStack);
|
||||||
|
|
Loading…
Add table
Reference in a new issue