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

org.eclipse.cdt.core

Refactored parser for further content assist work.

org.eclipse.cdt.ui.tests
	Updated failed test to fail in new way as Content Assist feature work continues on ...
This commit is contained in:
John Camelon 2004-03-03 20:07:59 +00:00
parent 8404420b80
commit 3f823a9e08
6 changed files with 92 additions and 70 deletions

View file

@ -1,3 +1,6 @@
2004-03-03 John Camelon
Refactored parser for further content assist work.
2004-03-03 John Camelon 2004-03-03 John Camelon
Added some trace statements to CompleteParseASTFactory. Added some trace statements to CompleteParseASTFactory.
Cleaned up usage of Enum.getValue() wrt encapsulation of enumerator value. Cleaned up usage of Enum.getValue() wrt encapsulation of enumerator value.

View file

@ -17,7 +17,9 @@ import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTNode;
@ -25,6 +27,7 @@ import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets; import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.parser.token.Token; import org.eclipse.cdt.internal.core.parser.token.Token;
import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key; import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key;
/** /**
@ -137,6 +140,25 @@ public class ContextualParser extends CompleteParser {
checkEndOfFile(); checkEndOfFile();
} }
protected void setCompletionValues( IASTScope scope, CompletionKind kind, IToken first, IToken last ) throws EndOfFileException{
if( !queryLookaheadCapability() )
{
setCompletionScope( scope );
setCompletionKind( kind );
setCompletionKeywords( Key.EMPTY );
ITokenDuple duple = new TokenDuple( first, last );
ITokenDuple realDuple = duple.getSubrange( 0, duple.length() - 3 );
IASTNode node = null;
try {
node = astFactory.lookupSymbolInContext( scope, realDuple );
setCompletionContext( node );
} catch (ASTNotImplementedException e) {
// assert false;
}
}
}
protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTExpression firstExpression, boolean isTemplate) throws EndOfFileException { protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTExpression firstExpression, boolean isTemplate) throws EndOfFileException {
setCompletionValues(scope,kind,key, getCompletionContextForExpression(firstExpression,isTemplate) ); setCompletionValues(scope,kind,key, getCompletionContextForExpression(firstExpression,isTemplate) );
} }

View file

@ -173,67 +173,67 @@ public class ExpressionParser implements IExpressionParser {
* *
* name2 * name2
* : IDENTIFER * : IDENTIFER
* : template-id
* *
* @throws BacktrackException request a backtrack * @throws BacktrackException request a backtrack
*/ */
protected TokenDuple name(IASTScope scope, IASTCompletionNode.CompletionKind kind) throws BacktrackException, EndOfFileException { protected TokenDuple name(IASTScope scope, IASTCompletionNode.CompletionKind kind) throws BacktrackException, EndOfFileException {
IToken first = LA(1); IToken first = LA(1);
IToken last = null; IToken last = null;
IToken mark = mark(); IToken mark = mark();
try if (LT(1) == IToken.tCOLONCOLON)
{ last = consume( IToken.tCOLONCOLON );
if (LT(1) == IToken.tCOLONCOLON)
last = consume( IToken.tCOLONCOLON );
// TODO - whacky way to deal with destructors, please revisit
if (LT(1) == IToken.tCOMPL)
consume();
switch (LT(1))
{
case IToken.tIDENTIFIER :
last = consume(IToken.tIDENTIFIER);
IToken secondMark = null;
if( queryLookaheadCapability() )
secondMark = mark();
else
return new TokenDuple(last, last);
try if (LT(1) == IToken.tCOMPL)
{ consume();
last = consumeTemplateParameters(last);
} catch( BacktrackException bt ) switch (LT(1))
{ {
backup( secondMark ); case IToken.tIDENTIFIER :
} last = consume(IToken.tIDENTIFIER);
break; IToken secondMark = null;
default :
backup(mark); secondMark = mark();
throw backtrack;
} try
while (LT(1) == IToken.tCOLONCOLON) {
{ last = consumeTemplateParameters(last);
last = consume(); } catch( BacktrackException bt )
if (LT(1) == IToken.t_template) {
consume(); backup( secondMark );
if (LT(1) == IToken.tCOMPL) }
consume(); break;
switch (LT(1))
{ default :
case IToken.t_operator : backup(mark);
backup(mark); throw backtrack;
throw backtrack; }
case IToken.tIDENTIFIER :
last = consume(); while (LT(1) == IToken.tCOLONCOLON)
last = consumeTemplateParameters(last); {
} last = consume();
}
if (LT(1) == IToken.t_template)
consume();
if (LT(1) == IToken.tCOMPL)
consume();
switch (LT(1))
{
case IToken.t_operator :
backup(mark);
throw backtrack;
case IToken.tIDENTIFIER :
last = consume();
last = consumeTemplateParameters(last);
}
}
return new TokenDuple(first, last);
return new TokenDuple(first, last);
} catch( OffsetLimitReachedException olre )
{
backup(mark);
throw backtrack;
}
} }
/** /**
@ -1814,7 +1814,7 @@ public class ExpressionParser implements IExpressionParser {
} }
break; break;
default : default :
firstExpression = primaryExpression(scope); firstExpression = primaryExpression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
} }
IASTExpression secondExpression = null; IASTExpression secondExpression = null;
for (;;) for (;;)
@ -1932,7 +1932,7 @@ public class ExpressionParser implements IExpressionParser {
setCompletionValues(scope, CompletionKind.MEMBER_REFERENCE, KeywordSets.Key.EMPTY, firstExpression, isTemplate ); setCompletionValues(scope, CompletionKind.MEMBER_REFERENCE, KeywordSets.Key.EMPTY, firstExpression, isTemplate );
secondExpression = primaryExpression(scope); secondExpression = primaryExpression(scope, CompletionKind.MEMBER_REFERENCE);
checkEndOfFile(); checkEndOfFile();
setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, KeywordSets.Key.EMPTY ); setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, KeywordSets.Key.EMPTY );
@ -1973,7 +1973,7 @@ public class ExpressionParser implements IExpressionParser {
setCompletionValues(scope, CompletionKind.MEMBER_REFERENCE, KeywordSets.Key.EMPTY, firstExpression, isTemplate ); setCompletionValues(scope, CompletionKind.MEMBER_REFERENCE, KeywordSets.Key.EMPTY, firstExpression, isTemplate );
secondExpression = primaryExpression(scope); secondExpression = primaryExpression(scope, CompletionKind.MEMBER_REFERENCE);
checkEndOfFile(); checkEndOfFile();
setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, KeywordSets.Key.EMPTY ); setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, KeywordSets.Key.EMPTY );
@ -2062,7 +2062,7 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression primaryExpression(IASTScope scope) throws EndOfFileException, BacktrackException { protected IASTExpression primaryExpression(IASTScope scope, CompletionKind kind) throws EndOfFileException, BacktrackException {
IToken t = null; IToken t = null;
switch (LT(1)) switch (LT(1))
{ {
@ -2217,7 +2217,7 @@ public class ExpressionParser implements IExpressionParser {
IToken mark = mark(); IToken mark = mark();
try try
{ {
duple = name(scope, CompletionKind.SINGLE_NAME_REFERENCE); duple = name(scope, kind);
} }
catch( BacktrackException bt ) catch( BacktrackException bt )
{ {
@ -2248,11 +2248,6 @@ public class ExpressionParser implements IExpressionParser {
duple = d.getNameDuple(); duple = d.getNameDuple();
} }
catch(OffsetLimitReachedException olre )
{
backup(mark);
throw backtrack;
}
checkEndOfFile(); checkEndOfFile();
try try
@ -2459,6 +2454,9 @@ public class ExpressionParser implements IExpressionParser {
protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTExpression firstExpression, boolean isTemplate) throws EndOfFileException { protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTExpression firstExpression, boolean isTemplate) throws EndOfFileException {
} }
protected void setCompletionValues( IASTScope scope, CompletionKind kind, IToken first, IToken last ) throws EndOfFileException {
}
protected IASTExpression unaryOperatorCastExpression(IASTScope scope, IASTExpression.Kind kind) throws EndOfFileException, BacktrackException { protected IASTExpression unaryOperatorCastExpression(IASTScope scope, IASTExpression.Kind kind) throws EndOfFileException, BacktrackException {
IASTExpression castExpression = castExpression(scope); IASTExpression castExpression = castExpression(scope);
try try

View file

@ -2754,10 +2754,6 @@ public abstract class Parser extends ExpressionParser implements IParser
{ {
backup( mark ); backup( mark );
} }
catch( OffsetLimitReachedException olre )
{
backup(mark);
}
// declarationStatement // declarationStatement
declaration(scope, null, null); declaration(scope, null, null);

View file

@ -1,3 +1,6 @@
2004-03-03 John Camelon
Updated failed test to fail in new way as Content Assist feature work continues on ...
2004-01-30 John Camelon 2004-01-30 John Camelon
Updated CompletionFailedTest_MacroRef_NoPrefix_Bug50487, renamed it to CompletionTest_MacroRef_NoPrefix and moved to passed test package. Updated CompletionFailedTest_MacroRef_NoPrefix_Bug50487, renamed it to CompletionTest_MacroRef_NoPrefix and moved to passed test package.
Updated CompletionFailedTest_MacroRef_Prefix_Bug50487, renamed it to Y and moved to passed test package. Updated CompletionFailedTest_MacroRef_Prefix_Bug50487, renamed it to Y and moved to passed test package.

View file

@ -32,7 +32,7 @@ public class CompletionFailedTest_FunctionReference_Bug50807 extends Completion
private final String headerFileFullPath ="resources/contentassist/" + headerFileName; private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTMethod"; private final String expectedScopeName = "ASTMethod";
private final String expectedContextName = "null"; // either the context or the prefix should be meaningful "ASTMethod" private final String expectedContextName = "null"; // either the context or the prefix should be meaningful "ASTMethod"
private final CompletionKind expectedKind = CompletionKind.SINGLE_NAME_REFERENCE; // should be CompletionKind.FUNCTION_REFERENCE; private final CompletionKind expectedKind = CompletionKind.NO_SUCH_KIND; // should be CompletionKind.FUNCTION_REFERENCE;
private final String expectedPrefix = ""; // should be "xAClassMethod" private final String expectedPrefix = ""; // should be "xAClassMethod"
private final String[] expectedResults = { private final String[] expectedResults = {
// should be // should be