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

Provided a partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=50152
	Updated IExpressionParser::expression() interface necessitated by this fix, and updated its clients appropriately.  

org.eclipse.cdt.core.tests
	Updated test cases that used IExpressionParser::expression().  
	Added CompletionParseTest::testCompletionInFunctionBodyFullyQualified(). 
	Added CompletionParseTest::testCompletionInFunctionBodyQualifiedName().

org.eclipse.cdt.ui.tests
	Updated CompletionFailedTest_ScopedReference_Prefix_Bug50152, moved it out of failed tests package and renamed it to CompletionTest_ScopedReference_Prefix_Bug50152.
	Updated CompletionFailedTest_TypeDef_Bug52948, moved it out of failed tests package and renamed it to CompletionTest_TypeDef_Bug52948. 
	Updated CompletionFailedTest_ScopedReference_NoPrefix_Bug50152 to show Hoda/Andrew what is still broken.
This commit is contained in:
John Camelon 2004-04-07 04:32:18 +00:00
parent 98b86d1d78
commit 26facfb422
16 changed files with 539 additions and 214 deletions

View file

@ -1,4 +1,9 @@
2004-04-05 Andrew Niefer 2004-04-07 John Camelon
Updated test cases that used IExpressionParser::expression().
Added CompletionParseTest::testCompletionInFunctionBodyFullyQualified().
Added CompletionParseTest::testCompletionInFunctionBodyQualifiedName().
2004-04-06 Andrew Niefer
added parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.testBug47625() added parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.testBug47625()
2004-04-06 John Camelon 2004-04-06 John Camelon

View file

@ -300,7 +300,8 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void enterCompilationUnit(IASTCompilationUnit compilationUnit) public void enterCompilationUnit(IASTCompilationUnit compilationUnit)
{ {
pushScope( compilationUnit ); pushScope( compilationUnit );
this.compilationUnit = getCurrentScope();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -478,7 +479,6 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void exitCompilationUnit(IASTCompilationUnit compilationUnit) public void exitCompilationUnit(IASTCompilationUnit compilationUnit)
{ {
this.compilationUnit = popScope();
} }

View file

@ -9,7 +9,9 @@ package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.NullLogService;
@ -20,17 +22,21 @@ import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope; import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTField; import org.eclipse.cdt.core.parser.ast.IASTField;
import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult; import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind; import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
import org.eclipse.core.runtime.NullProgressMonitor;
/** /**
* @author jcamelon * @author jcamelon
@ -689,4 +695,116 @@ public class CompletionParseTest extends CompleteParseBaseTest {
assertFalse( iter.hasNext() ); assertFalse( iter.hasNext() );
} }
public void testCompletionInFunctionBodyFullyQualified() throws Exception
{
StringWriter writer = new StringWriter();
writer.write( "int aInteger = 5;\n");
writer.write( "namespace NMS { \n");
writer.write( " int foo() { \n");
writer.write( "::A ");
writer.write( "}\n}\n");
String code = writer.toString();
for( int i = 0; i < 2; ++i )
{
String stringToCompleteAfter = ( i == 0 ) ? "::" : "::A";
IASTCompletionNode node = parse( code, code.indexOf( stringToCompleteAfter) + stringToCompleteAfter.length() );
validateCompletionNode(node, ( i == 0 ? "" : "A"), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE, getCompilationUnit() );
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
node.getCompletionContext() );
Set results = new HashSet();
results.add( "aInteger");
if( i == 0 )
results.add( "NMS");
validateLookupResult(result, results );
}
}
/**
* @param result
*/
private void validateLookupResult(ILookupResult result, Set matches) {
assertNotNull( matches );
assertEquals( result.getResultsSize(), matches.size() );
Iterator iter = result.getNodes();
int assertionCount = 0;
while( iter.hasNext() )
{
IASTOffsetableNamedElement element = (IASTOffsetableNamedElement) iter.next();
assertTrue( matches.contains( element.getName() ));
}
}
/**
* @return
*/
protected IASTCompilationUnit getCompilationUnit() {
CompleteParseBaseTest.Scope s = (Scope) callback.getCompilationUnit();
IASTCompilationUnit compilationUnit = (IASTCompilationUnit) ((Scope) callback.getCompilationUnit()).getScope();
return compilationUnit;
}
/**
* @param node
*/
protected void validateCompletionNode(IASTCompletionNode node, String prefix, CompletionKind kind, IASTNode context ) {
assertNotNull( node );
assertEquals( node.getCompletionPrefix(), prefix);
assertEquals( node.getCompletionKind(), kind );
assertEquals( node.getCompletionContext(), context );
assertFalse( node.getKeywords().hasNext() );
}
public void testCompletionInFunctionBodyQualifiedName() throws Exception
{
StringWriter writer = new StringWriter();
writer.write( "namespace ABC {\n");
writer.write( " struct DEF { int x; }; \n" );
writer.write( " struct GHI { float y;};\n");
writer.write( "}\n");
writer.write( "int main() { ABC::D }\n");
String code = writer.toString();
for( int j = 0; j< 2; ++j )
{
String stringToCompleteAfter = (j == 0 ) ? "::" : "::D";
IASTCompletionNode node = parse( code, code.indexOf( stringToCompleteAfter) + stringToCompleteAfter.length() );
IASTNamespaceDefinition namespaceDefinition = null;
Iterator i = callback.getCompilationUnit().getDeclarations();
while( i.hasNext() )
{
IASTDeclaration d = (IASTDeclaration) i.next();
if( d instanceof IASTNamespaceDefinition )
if( ((IASTNamespaceDefinition)d).getName().equals( "ABC") )
{
namespaceDefinition = (IASTNamespaceDefinition) d;
break;
}
}
assertNotNull( namespaceDefinition );
validateCompletionNode( node,
( j == 0 ) ? "" : "D",
IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE, namespaceDefinition );
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
node.getCompletionContext() );
Set results = new HashSet();
results.add( "DEF");
if( j == 0 )
results.add( "GHI");
validateLookupResult(result, results );
}
}
} }

View file

@ -29,7 +29,7 @@ public class ExprEvalTest extends TestCase {
final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor(); final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor();
IExpressionParser parser = InternalParserUtil.createExpressionParser(ParserFactory.createScanner( new StringReader( code ), getClass().getName(), new ScannerInfo(), null, ParserLanguage.CPP, nullCallback, new NullLogService() ), ParserLanguage.CPP, null ); IExpressionParser parser = InternalParserUtil.createExpressionParser(ParserFactory.createScanner( new StringReader( code ), getClass().getName(), new ScannerInfo(), null, ParserLanguage.CPP, nullCallback, new NullLogService() ), ParserLanguage.CPP, null );
IASTExpression expression = parser.expression(null); IASTExpression expression = parser.expression(null,null);
assertEquals(expectedValue, expression.evaluateExpression()); assertEquals(expectedValue, expression.evaluateExpression());
} }

View file

@ -1,3 +1,7 @@
2004-04-07 John Camelon
Provided a partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=50152
Updated IExpressionParser::expression() interface necessitated by this fix, and updated its clients appropriately.
2004-04-06 David Daoust 2004-04-06 David Daoust
Removed some temporary objects that the scanner was producing. Removed some temporary objects that the scanner was producing.
Fixed small bug in GCCScannerExtension. Fixed small bug in GCCScannerExtension.

View file

@ -132,6 +132,8 @@ public class ContextualParser extends CompleteParser {
setCompletionValues(scope, kind, key, null ); setCompletionValues(scope, kind, key, null );
} }
protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTNode node) throws EndOfFileException { protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTNode node) throws EndOfFileException {
setCompletionScope(scope); setCompletionScope(scope);
setCompletionKeywords(key); setCompletionKeywords(key);
@ -140,22 +142,18 @@ public class ContextualParser extends CompleteParser {
checkEndOfFile(); checkEndOfFile();
} }
protected void setCompletionValues( IASTScope scope, CompletionKind kind, IToken first, IToken last ) throws EndOfFileException{ protected void setCompletionValues( IASTScope scope, CompletionKind kind, IToken first, IToken last ) throws EndOfFileException{
if( !queryLookaheadCapability() ) setCompletionScope( scope );
{ setCompletionKind( kind );
setCompletionScope( scope ); setCompletionKeywords( Key.EMPTY );
setCompletionKind( kind ); ITokenDuple duple = new TokenDuple( first, last );
setCompletionKeywords( Key.EMPTY ); try {
ITokenDuple duple = new TokenDuple( first, last ); setCompletionContext( astFactory.lookupSymbolInContext( scope, duple ) );
ITokenDuple realDuple = duple.getSubrange( 0, duple.length() - 3 ); } catch (ASTNotImplementedException e) {
IASTNode node = null;
try {
node = astFactory.lookupSymbolInContext( scope, realDuple );
setCompletionContext( node );
} catch (ASTNotImplementedException e) {
// assert false;
}
} }
} }
@ -167,4 +165,21 @@ public class ContextualParser extends CompleteParser {
this.scope = scope; this.scope = scope;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setCompletionValues(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind)
*/
protected void setCompletionValues(IASTScope scope, CompletionKind kind) throws EndOfFileException {
setCompletionScope(scope);
setCompletionKind(kind);
checkEndOfFile();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setCompletionValues(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind, org.eclipse.cdt.core.parser.ast.IASTNode)
*/
protected void setCompletionValues(IASTScope scope, CompletionKind kind,
IASTNode context) throws EndOfFileException {
setCompletionScope(scope);
setCompletionKind(kind);
setCompletionContext(context);
checkEndOfFile(); }
} }

View file

@ -174,7 +174,7 @@ public class ExpressionParser implements IExpressionParser {
IToken mark = mark(); IToken mark = mark();
try{ try{
IASTTypeId typeId = typeId( scope, false ); IASTTypeId typeId = typeId( scope, false, CompletionKind.TYPE_REFERENCE );
expression = astFactory.createExpression( scope, IASTExpression.Kind.POSTFIX_TYPEID_TYPEID, expression = astFactory.createExpression( scope, IASTExpression.Kind.POSTFIX_TYPEID_TYPEID,
null, null, null, typeId, null, "", null); //$NON-NLS-1$ null, null, null, typeId, null, "", null); //$NON-NLS-1$
@ -188,7 +188,7 @@ public class ExpressionParser implements IExpressionParser {
if( ! completedArg ){ if( ! completedArg ){
try{ try{
expression = assignmentExpression( scope ); expression = assignmentExpression( scope, CompletionKind.VARIABLE_TYPE );
if( expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_EMPTY ){ if( expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_EMPTY ){
throw backtrack; throw backtrack;
} }
@ -262,7 +262,7 @@ public class ExpressionParser implements IExpressionParser {
* *
* @throws BacktrackException request a backtrack * @throws BacktrackException request a backtrack
*/ */
protected TokenDuple name(IASTScope scope, IASTCompletionNode.CompletionKind kind) throws BacktrackException, EndOfFileException { protected ITokenDuple name(IASTScope scope, IASTCompletionNode.CompletionKind kind) throws BacktrackException, EndOfFileException {
IToken first = LA(1); IToken first = LA(1);
IToken last = null; IToken last = null;
@ -270,10 +270,13 @@ public class ExpressionParser implements IExpressionParser {
List argumentList = new LinkedList(); List argumentList = new LinkedList();
boolean hasTemplateId = false; boolean hasTemplateId = false;
boolean startsWithColonColon = false;
if (LT(1) == IToken.tCOLONCOLON){ if (LT(1) == IToken.tCOLONCOLON){
argumentList.add( null ); argumentList.add( null );
last = consume( IToken.tCOLONCOLON ); last = consume( IToken.tCOLONCOLON );
setCompletionValues( scope, kind, Key.EMPTY, getCompliationUnit() );
startsWithColonColon = true;
} }
if (LT(1) == IToken.tCOMPL) if (LT(1) == IToken.tCOMPL)
@ -282,7 +285,15 @@ public class ExpressionParser implements IExpressionParser {
switch (LT(1)) switch (LT(1))
{ {
case IToken.tIDENTIFIER : case IToken.tIDENTIFIER :
last = consume(IToken.tIDENTIFIER); IToken prev = last;
last = consume(IToken.tIDENTIFIER);
if( startsWithColonColon )
setCompletionValues( scope, kind, getCompliationUnit() );
else if( prev != null )
setCompletionValues(scope, kind, first, prev );
else
setCompletionValues(scope, kind );
last = consumeTemplateArguments(scope, last, argumentList); last = consumeTemplateArguments(scope, last, argumentList);
if( last.getType() == IToken.tGT ) if( last.getType() == IToken.tGT )
hasTemplateId = true; hasTemplateId = true;
@ -295,12 +306,14 @@ public class ExpressionParser implements IExpressionParser {
while (LT(1) == IToken.tCOLONCOLON) while (LT(1) == IToken.tCOLONCOLON)
{ {
last = consume(); IToken prev = last;
last = consume(IToken.tCOLONCOLON);
setCompletionValues( scope, kind, first, prev );
if (LT(1) == IToken.t_template) if (queryLookaheadCapability() && LT(1) == IToken.t_template)
consume(); consume();
if (LT(1) == IToken.tCOMPL) if (queryLookaheadCapability() && LT(1) == IToken.tCOMPL)
consume(); consume();
switch (LT(1)) switch (LT(1))
@ -320,6 +333,37 @@ public class ExpressionParser implements IExpressionParser {
} }
/**
* @param scope
* @param kind
*/
protected void setCompletionValues(IASTScope scope, CompletionKind kind, IASTNode context ) throws EndOfFileException{
}
/**
* @param scope
* @param kind
*/
protected void setCompletionValues(IASTScope scope, CompletionKind kind) throws EndOfFileException{
}
/**
* @return
*/
protected IASTNode getCompliationUnit() {
return null;
}
/**
* @param scope
* @param kind
* @param key
* @param node
*/
protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTNode node) throws EndOfFileException
{
}
/** /**
* @param scope * @param scope
* @param last * @param last
@ -394,7 +438,7 @@ public class ExpressionParser implements IExpressionParser {
IASTExpression exp = null; IASTExpression exp = null;
if (LT(1) != IToken.tRBRACKET) if (LT(1) != IToken.tRBRACKET)
{ {
exp = constantExpression(scope); exp = constantExpression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
} }
consume(IToken.tRBRACKET); consume(IToken.tRBRACKET);
IASTArrayModifier arrayMod; IASTArrayModifier arrayMod;
@ -446,7 +490,7 @@ public class ExpressionParser implements IExpressionParser {
else else
{ {
// must be a conversion function // must be a conversion function
typeId(d.getDeclarationWrapper().getScope(), true ); typeId(d.getDeclarationWrapper().getScope(), true, CompletionKind.TYPE_REFERENCE );
toSend = lastToken; toSend = lastToken;
} }
@ -531,16 +575,16 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression constantExpression(IASTScope scope) throws BacktrackException, EndOfFileException { protected IASTExpression constantExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
return conditionalExpression(scope); return conditionalExpression(scope,kind);
} }
public IASTExpression expression(IASTScope scope) throws BacktrackException, EndOfFileException { public IASTExpression expression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
IASTExpression assignmentExpression = assignmentExpression(scope); IASTExpression assignmentExpression = assignmentExpression(scope,kind);
while (LT(1) == IToken.tCOMMA) while (LT(1) == IToken.tCOMMA)
{ {
consume(); consume();
IASTExpression secondExpression = assignmentExpression(scope); IASTExpression secondExpression = assignmentExpression(scope,kind);
try try
{ {
assignmentExpression = assignmentExpression =
@ -568,11 +612,11 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression assignmentExpression(IASTScope scope) throws EndOfFileException, BacktrackException { protected IASTExpression assignmentExpression(IASTScope scope, CompletionKind kind) throws EndOfFileException, BacktrackException {
if (LT(1) == IToken.t_throw) { if (LT(1) == IToken.t_throw) {
return throwExpression(scope); return throwExpression(scope);
} }
IASTExpression conditionalExpression = conditionalExpression(scope); IASTExpression conditionalExpression = conditionalExpression(scope,kind);
// if the condition not taken, try assignment operators // if the condition not taken, try assignment operators
if (conditionalExpression != null if (conditionalExpression != null
&& conditionalExpression.getExpressionKind() && conditionalExpression.getExpressionKind()
@ -583,57 +627,57 @@ public class ExpressionParser implements IExpressionParser {
return assignmentOperatorExpression( return assignmentOperatorExpression(
scope, scope,
IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL, IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL,
conditionalExpression); conditionalExpression, kind);
case IToken.tSTARASSIGN : case IToken.tSTARASSIGN :
return assignmentOperatorExpression( return assignmentOperatorExpression(
scope, scope,
IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT, IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT,
conditionalExpression); conditionalExpression, kind);
case IToken.tDIVASSIGN : case IToken.tDIVASSIGN :
return assignmentOperatorExpression( return assignmentOperatorExpression(
scope, scope,
IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV, IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV,
conditionalExpression); conditionalExpression, kind);
case IToken.tMODASSIGN : case IToken.tMODASSIGN :
return assignmentOperatorExpression( return assignmentOperatorExpression(
scope, scope,
IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD, IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD,
conditionalExpression); conditionalExpression, kind);
case IToken.tPLUSASSIGN : case IToken.tPLUSASSIGN :
return assignmentOperatorExpression( return assignmentOperatorExpression(
scope, scope,
IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS, IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS,
conditionalExpression); conditionalExpression, kind);
case IToken.tMINUSASSIGN : case IToken.tMINUSASSIGN :
return assignmentOperatorExpression( return assignmentOperatorExpression(
scope, scope,
IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS, IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS,
conditionalExpression); conditionalExpression, kind);
case IToken.tSHIFTRASSIGN : case IToken.tSHIFTRASSIGN :
return assignmentOperatorExpression( return assignmentOperatorExpression(
scope, scope,
IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT, IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT,
conditionalExpression); conditionalExpression, kind);
case IToken.tSHIFTLASSIGN : case IToken.tSHIFTLASSIGN :
return assignmentOperatorExpression( return assignmentOperatorExpression(
scope, scope,
IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT, IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT,
conditionalExpression); conditionalExpression, kind);
case IToken.tAMPERASSIGN : case IToken.tAMPERASSIGN :
return assignmentOperatorExpression( return assignmentOperatorExpression(
scope, scope,
IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND, IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND,
conditionalExpression); conditionalExpression, kind);
case IToken.tXORASSIGN : case IToken.tXORASSIGN :
return assignmentOperatorExpression( return assignmentOperatorExpression(
scope, scope,
IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR, IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR,
conditionalExpression); conditionalExpression, kind);
case IToken.tBITORASSIGN : case IToken.tBITORASSIGN :
return assignmentOperatorExpression( return assignmentOperatorExpression(
scope, scope,
IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR, IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR,
conditionalExpression); conditionalExpression, kind);
} }
return conditionalExpression; return conditionalExpression;
} }
@ -647,7 +691,7 @@ public class ExpressionParser implements IExpressionParser {
IASTExpression throwExpression = null; IASTExpression throwExpression = null;
try try
{ {
throwExpression = expression(scope); throwExpression = expression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
} }
catch (BacktrackException b) catch (BacktrackException b)
{ {
@ -677,14 +721,14 @@ public class ExpressionParser implements IExpressionParser {
* @return * @return
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression conditionalExpression(IASTScope scope) throws BacktrackException, EndOfFileException { protected IASTExpression conditionalExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
IASTExpression firstExpression = logicalOrExpression(scope); IASTExpression firstExpression = logicalOrExpression(scope,kind);
if (LT(1) == IToken.tQUESTION) if (LT(1) == IToken.tQUESTION)
{ {
consume(); consume();
IASTExpression secondExpression = expression(scope); IASTExpression secondExpression = expression(scope,kind);
consume(IToken.tCOLON); consume(IToken.tCOLON);
IASTExpression thirdExpression = assignmentExpression(scope); IASTExpression thirdExpression = assignmentExpression(scope,kind);
try try
{ {
return astFactory.createExpression( return astFactory.createExpression(
@ -712,12 +756,12 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression logicalOrExpression(IASTScope scope) throws BacktrackException, EndOfFileException { protected IASTExpression logicalOrExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
IASTExpression firstExpression = logicalAndExpression(scope); IASTExpression firstExpression = logicalAndExpression(scope,kind);
while (LT(1) == IToken.tOR) while (LT(1) == IToken.tOR)
{ {
consume(); consume();
IASTExpression secondExpression = logicalAndExpression(scope); IASTExpression secondExpression = logicalAndExpression(scope,kind);
try try
{ {
@ -746,12 +790,12 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression logicalAndExpression(IASTScope scope) throws BacktrackException, EndOfFileException { protected IASTExpression logicalAndExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
IASTExpression firstExpression = inclusiveOrExpression( scope ); IASTExpression firstExpression = inclusiveOrExpression( scope,kind );
while (LT(1) == IToken.tAND) while (LT(1) == IToken.tAND)
{ {
consume(); consume();
IASTExpression secondExpression = inclusiveOrExpression( scope ); IASTExpression secondExpression = inclusiveOrExpression( scope,kind );
try try
{ {
firstExpression = firstExpression =
@ -779,12 +823,12 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression inclusiveOrExpression(IASTScope scope) throws BacktrackException, EndOfFileException { protected IASTExpression inclusiveOrExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
IASTExpression firstExpression = exclusiveOrExpression(scope); IASTExpression firstExpression = exclusiveOrExpression(scope,kind);
while (LT(1) == IToken.tBITOR) while (LT(1) == IToken.tBITOR)
{ {
consume(); consume();
IASTExpression secondExpression = exclusiveOrExpression(scope); IASTExpression secondExpression = exclusiveOrExpression(scope,kind);
try try
{ {
@ -813,13 +857,13 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression exclusiveOrExpression(IASTScope scope) throws BacktrackException, EndOfFileException { protected IASTExpression exclusiveOrExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
IASTExpression firstExpression = andExpression( scope ); IASTExpression firstExpression = andExpression( scope,kind );
while (LT(1) == IToken.tXOR) while (LT(1) == IToken.tXOR)
{ {
consume(); consume();
IASTExpression secondExpression = andExpression( scope ); IASTExpression secondExpression = andExpression( scope,kind );
try try
{ {
@ -848,12 +892,12 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression andExpression(IASTScope scope) throws EndOfFileException, BacktrackException { protected IASTExpression andExpression(IASTScope scope, CompletionKind kind) throws EndOfFileException, BacktrackException {
IASTExpression firstExpression = equalityExpression(scope); IASTExpression firstExpression = equalityExpression(scope,kind);
while (LT(1) == IToken.tAMPER) while (LT(1) == IToken.tAMPER)
{ {
consume(); consume();
IASTExpression secondExpression = equalityExpression(scope); IASTExpression secondExpression = equalityExpression(scope,kind);
try try
{ {
@ -882,8 +926,8 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression equalityExpression(IASTScope scope) throws EndOfFileException, BacktrackException { protected IASTExpression equalityExpression(IASTScope scope, CompletionKind kind) throws EndOfFileException, BacktrackException {
IASTExpression firstExpression = relationalExpression(scope); IASTExpression firstExpression = relationalExpression(scope,kind);
for (;;) for (;;)
{ {
switch (LT(1)) switch (LT(1))
@ -892,7 +936,7 @@ public class ExpressionParser implements IExpressionParser {
case IToken.tNOTEQUAL : case IToken.tNOTEQUAL :
IToken t = consume(); IToken t = consume();
IASTExpression secondExpression = IASTExpression secondExpression =
relationalExpression(scope); relationalExpression(scope,kind);
try try
{ {
@ -926,8 +970,8 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression relationalExpression(IASTScope scope) throws BacktrackException, EndOfFileException { protected IASTExpression relationalExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
IASTExpression firstExpression = shiftExpression(scope); IASTExpression firstExpression = shiftExpression(scope,kind);
for (;;) for (;;)
{ {
switch (LT(1)) switch (LT(1))
@ -943,7 +987,7 @@ public class ExpressionParser implements IExpressionParser {
IToken t = consume(); IToken t = consume();
IToken next = LA(1); IToken next = LA(1);
IASTExpression secondExpression = IASTExpression secondExpression =
shiftExpression(scope); shiftExpression(scope,kind);
if (next == LA(1)) if (next == LA(1))
{ {
// we did not consume anything // we did not consume anything
@ -953,24 +997,24 @@ public class ExpressionParser implements IExpressionParser {
} }
else else
{ {
IASTExpression.Kind kind = null; IASTExpression.Kind expressionKind = null;
switch (t.getType()) switch (t.getType())
{ {
case IToken.tGT : case IToken.tGT :
kind = expressionKind =
IASTExpression.Kind.RELATIONAL_GREATERTHAN; IASTExpression.Kind.RELATIONAL_GREATERTHAN;
break; break;
case IToken.tLT : case IToken.tLT :
kind = IASTExpression.Kind.RELATIONAL_LESSTHAN; expressionKind = IASTExpression.Kind.RELATIONAL_LESSTHAN;
break; break;
case IToken.tLTEQUAL : case IToken.tLTEQUAL :
kind = expressionKind =
IASTExpression IASTExpression
.Kind .Kind
.RELATIONAL_LESSTHANEQUALTO; .RELATIONAL_LESSTHANEQUALTO;
break; break;
case IToken.tGTEQUAL : case IToken.tGTEQUAL :
kind = expressionKind =
IASTExpression IASTExpression
.Kind .Kind
.RELATIONAL_GREATERTHANEQUALTO; .RELATIONAL_GREATERTHANEQUALTO;
@ -981,7 +1025,7 @@ public class ExpressionParser implements IExpressionParser {
firstExpression = firstExpression =
astFactory.createExpression( astFactory.createExpression(
scope, scope,
kind, expressionKind,
firstExpression, firstExpression,
secondExpression, secondExpression,
null, null,
@ -1007,8 +1051,8 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression shiftExpression(IASTScope scope) throws BacktrackException, EndOfFileException { protected IASTExpression shiftExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
IASTExpression firstExpression = additiveExpression(scope); IASTExpression firstExpression = additiveExpression(scope,kind);
for (;;) for (;;)
{ {
switch (LT(1)) switch (LT(1))
@ -1017,7 +1061,7 @@ public class ExpressionParser implements IExpressionParser {
case IToken.tSHIFTR : case IToken.tSHIFTR :
IToken t = consume(); IToken t = consume();
IASTExpression secondExpression = IASTExpression secondExpression =
additiveExpression(scope); additiveExpression(scope,kind);
try try
{ {
firstExpression = firstExpression =
@ -1050,8 +1094,8 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression additiveExpression(IASTScope scope) throws BacktrackException, EndOfFileException { protected IASTExpression additiveExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
IASTExpression firstExpression = multiplicativeExpression( scope ); IASTExpression firstExpression = multiplicativeExpression( scope, kind );
for (;;) for (;;)
{ {
switch (LT(1)) switch (LT(1))
@ -1060,7 +1104,7 @@ public class ExpressionParser implements IExpressionParser {
case IToken.tMINUS : case IToken.tMINUS :
IToken t = consume(); IToken t = consume();
IASTExpression secondExpression = IASTExpression secondExpression =
multiplicativeExpression(scope); multiplicativeExpression(scope,kind);
try try
{ {
firstExpression = firstExpression =
@ -1093,8 +1137,8 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression multiplicativeExpression(IASTScope scope) throws BacktrackException, EndOfFileException { protected IASTExpression multiplicativeExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
IASTExpression firstExpression = pmExpression(scope); IASTExpression firstExpression = pmExpression(scope,kind);
for (;;) for (;;)
{ {
switch (LT(1)) switch (LT(1))
@ -1103,18 +1147,18 @@ public class ExpressionParser implements IExpressionParser {
case IToken.tDIV : case IToken.tDIV :
case IToken.tMOD : case IToken.tMOD :
IToken t = consume(); IToken t = consume();
IASTExpression secondExpression = pmExpression(scope); IASTExpression secondExpression = pmExpression(scope,kind);
IASTExpression.Kind kind = null; IASTExpression.Kind expressionKind = null;
switch (t.getType()) switch (t.getType())
{ {
case IToken.tSTAR : case IToken.tSTAR :
kind = IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY; expressionKind = IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY;
break; break;
case IToken.tDIV : case IToken.tDIV :
kind = IASTExpression.Kind.MULTIPLICATIVE_DIVIDE; expressionKind = IASTExpression.Kind.MULTIPLICATIVE_DIVIDE;
break; break;
case IToken.tMOD : case IToken.tMOD :
kind = IASTExpression.Kind.MULTIPLICATIVE_MODULUS; expressionKind = IASTExpression.Kind.MULTIPLICATIVE_MODULUS;
break; break;
} }
try try
@ -1122,7 +1166,7 @@ public class ExpressionParser implements IExpressionParser {
firstExpression = firstExpression =
astFactory.createExpression( astFactory.createExpression(
scope, scope,
kind, expressionKind,
firstExpression, firstExpression,
secondExpression, secondExpression,
null, null,
@ -1147,8 +1191,8 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression pmExpression(IASTScope scope) throws EndOfFileException, BacktrackException { protected IASTExpression pmExpression(IASTScope scope, CompletionKind kind) throws EndOfFileException, BacktrackException {
IASTExpression firstExpression = castExpression(scope); IASTExpression firstExpression = castExpression(scope,kind);
for (;;) for (;;)
{ {
switch (LT(1)) switch (LT(1))
@ -1157,7 +1201,7 @@ public class ExpressionParser implements IExpressionParser {
case IToken.tARROWSTAR : case IToken.tARROWSTAR :
IToken t = consume(); IToken t = consume();
IASTExpression secondExpression = IASTExpression secondExpression =
castExpression(scope); castExpression(scope,kind);
try try
{ {
firstExpression = firstExpression =
@ -1191,7 +1235,7 @@ public class ExpressionParser implements IExpressionParser {
* : unaryExpression * : unaryExpression
* | "(" typeId ")" castExpression * | "(" typeId ")" castExpression
*/ */
protected IASTExpression castExpression(IASTScope scope) throws EndOfFileException, BacktrackException { protected IASTExpression castExpression(IASTScope scope, CompletionKind kind) throws EndOfFileException, BacktrackException {
// TO DO: we need proper symbol checkint to ensure type name // TO DO: we need proper symbol checkint to ensure type name
if (LT(1) == IToken.tLPAREN) if (LT(1) == IToken.tLPAREN)
{ {
@ -1203,10 +1247,10 @@ public class ExpressionParser implements IExpressionParser {
// If this isn't a type name, then we shouldn't be here // If this isn't a type name, then we shouldn't be here
try try
{ {
typeId = typeId(scope, false); typeId = typeId(scope, false, CompletionKind.TYPE_REFERENCE);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if( templateIdScopes != null ){ templateIdScopes.pop(); popped = true;} if( templateIdScopes != null ){ templateIdScopes.pop(); popped = true;}
IASTExpression castExpression = castExpression(scope); IASTExpression castExpression = castExpression(scope,kind);
try try
{ {
return astFactory.createExpression( return astFactory.createExpression(
@ -1232,14 +1276,15 @@ public class ExpressionParser implements IExpressionParser {
if( templateIdScopes != null && !popped ){ templateIdScopes.pop(); } if( templateIdScopes != null && !popped ){ templateIdScopes.pop(); }
} }
} }
return unaryExpression(scope); return unaryExpression(scope,kind);
} }
/** /**
* @param completionKind TODO
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTTypeId typeId(IASTScope scope, boolean skipArrayModifiers) throws EndOfFileException, BacktrackException { protected IASTTypeId typeId(IASTScope scope, boolean skipArrayModifiers, CompletionKind completionKind) throws EndOfFileException, BacktrackException {
IToken mark = mark(); IToken mark = mark();
ITokenDuple name = null; ITokenDuple name = null;
boolean isConst = false, isVolatile = false; boolean isConst = false, isVolatile = false;
@ -1252,7 +1297,7 @@ public class ExpressionParser implements IExpressionParser {
{ {
try try
{ {
name = name(scope, CompletionKind.TYPE_REFERENCE ); name = name(scope, completionKind );
kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
break; break;
} }
@ -1299,7 +1344,7 @@ public class ExpressionParser implements IExpressionParser {
case IToken.tIDENTIFIER : case IToken.tIDENTIFIER :
if( encounteredType ) break simpleMods; if( encounteredType ) break simpleMods;
encounteredType = true; encounteredType = true;
name = name(scope, CompletionKind.TYPE_REFERENCE); name = name(scope, completionKind );
kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
break; break;
@ -1383,7 +1428,7 @@ public class ExpressionParser implements IExpressionParser {
consume(); consume();
try try
{ {
name = name(scope, CompletionKind.TYPE_REFERENCE ); name = name(scope, completionKind );
kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
} catch( BacktrackException b ) } catch( BacktrackException b )
{ {
@ -1432,7 +1477,7 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression deleteExpression(IASTScope scope) throws EndOfFileException, BacktrackException { protected IASTExpression deleteExpression(IASTScope scope, CompletionKind kind) throws EndOfFileException, BacktrackException {
if (LT(1) == IToken.tCOLONCOLON) if (LT(1) == IToken.tCOLONCOLON)
{ {
// global scope // global scope
@ -1447,7 +1492,7 @@ public class ExpressionParser implements IExpressionParser {
consume(IToken.tRBRACKET); consume(IToken.tRBRACKET);
vectored = true; vectored = true;
} }
IASTExpression castExpression = castExpression(scope); IASTExpression castExpression = castExpression(scope,kind);
try try
{ {
return astFactory.createExpression( return astFactory.createExpression(
@ -1512,7 +1557,7 @@ public class ExpressionParser implements IExpressionParser {
// Try to consume placement list // Try to consume placement list
// Note: since expressionList and expression are the same... // Note: since expressionList and expression are the same...
backtrackMarker = mark(); backtrackMarker = mark();
newPlacementExpressions.add(expression(scope)); newPlacementExpressions.add(expression(scope, CompletionKind.SINGLE_NAME_REFERENCE));
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if( templateIdScopes != null ){ templateIdScopes.pop(); } //pop 1st Parent if( templateIdScopes != null ){ templateIdScopes.pop(); } //pop 1st Parent
placementParseFailure = false; placementParseFailure = false;
@ -1533,7 +1578,7 @@ public class ExpressionParser implements IExpressionParser {
// CASE: new (typeid-not-looking-as-placement) ... // CASE: new (typeid-not-looking-as-placement) ...
// the first expression in () is not a placement // the first expression in () is not a placement
// - then it has to be typeId // - then it has to be typeId
typeId = typeId(scope, true ); typeId = typeId(scope, true, CompletionKind.NEW_TYPE_REFERENCE );
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if( templateIdScopes != null ){ templateIdScopes.pop(); } //pop 1st Paren if( templateIdScopes != null ){ templateIdScopes.pop(); } //pop 1st Paren
} }
@ -1558,7 +1603,7 @@ public class ExpressionParser implements IExpressionParser {
try try
{ {
backtrackMarker = mark(); backtrackMarker = mark();
typeId = typeId(scope, true); typeId = typeId(scope, true, CompletionKind.NEW_TYPE_REFERENCE);
} }
catch (BacktrackException e) catch (BacktrackException e)
{ {
@ -1577,7 +1622,7 @@ public class ExpressionParser implements IExpressionParser {
// The problem is, the first expression might as well be a typeid // The problem is, the first expression might as well be a typeid
try try
{ {
typeId = typeId(scope, true); typeId = typeId(scope, true, CompletionKind.NEW_TYPE_REFERENCE);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if( templateIdScopes != null ){ templateIdScopes.pop(); } //popping the 2nd Paren if( templateIdScopes != null ){ templateIdScopes.pop(); } //popping the 2nd Paren
@ -1628,7 +1673,7 @@ public class ExpressionParser implements IExpressionParser {
// CASE: new typeid ... // CASE: new typeid ...
// new parameters do not start with '(' // new parameters do not start with '('
// i.e it has to be a plain typeId // i.e it has to be a plain typeId
typeId = typeId(scope, true); typeId = typeId(scope, true, CompletionKind.NEW_TYPE_REFERENCE);
} }
while (LT(1) == IToken.tLBRACKET) while (LT(1) == IToken.tLBRACKET)
{ {
@ -1637,7 +1682,7 @@ public class ExpressionParser implements IExpressionParser {
if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLBRACKET ) ); } if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLBRACKET ) ); }
newTypeIdExpressions.add(assignmentExpression(scope)); newTypeIdExpressions.add(assignmentExpression(scope, CompletionKind.SINGLE_NAME_REFERENCE));
consume(IToken.tRBRACKET); consume(IToken.tRBRACKET);
if( templateIdScopes != null ){ templateIdScopes.pop(); } if( templateIdScopes != null ){ templateIdScopes.pop(); }
@ -1649,7 +1694,7 @@ public class ExpressionParser implements IExpressionParser {
if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLPAREN ) ); } if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLPAREN ) ); }
if (LT(1) != IToken.tRPAREN) if (LT(1) != IToken.tRPAREN)
newInitializerExpressions.add(expression(scope)); newInitializerExpressions.add(expression(scope, CompletionKind.SINGLE_NAME_REFERENCE));
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if( templateIdScopes != null ){ templateIdScopes.pop(); } if( templateIdScopes != null ){ templateIdScopes.pop(); }
@ -1676,41 +1721,41 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression unaryExpression(IASTScope scope) throws EndOfFileException, BacktrackException { protected IASTExpression unaryExpression(IASTScope scope, CompletionKind kind) throws EndOfFileException, BacktrackException {
switch (LT(1)) switch (LT(1))
{ {
case IToken.tSTAR : case IToken.tSTAR :
consume(); consume();
return unaryOperatorCastExpression(scope, return unaryOperatorCastExpression(scope,
IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION); IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION,kind);
case IToken.tAMPER : case IToken.tAMPER :
consume(); consume();
return unaryOperatorCastExpression(scope, return unaryOperatorCastExpression(scope,
IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION); IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION,kind);
case IToken.tPLUS : case IToken.tPLUS :
consume(); consume();
return unaryOperatorCastExpression(scope, return unaryOperatorCastExpression(scope,
IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION); IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION,kind);
case IToken.tMINUS : case IToken.tMINUS :
consume(); consume();
return unaryOperatorCastExpression(scope, return unaryOperatorCastExpression(scope,
IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION); IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION,kind);
case IToken.tNOT : case IToken.tNOT :
consume(); consume();
return unaryOperatorCastExpression(scope, return unaryOperatorCastExpression(scope,
IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION); IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION,kind);
case IToken.tCOMPL : case IToken.tCOMPL :
consume(); consume();
return unaryOperatorCastExpression(scope, return unaryOperatorCastExpression(scope,
IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION); IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION,kind);
case IToken.tINCR : case IToken.tINCR :
consume(); consume();
return unaryOperatorCastExpression(scope, return unaryOperatorCastExpression(scope,
IASTExpression.Kind.UNARY_INCREMENT); IASTExpression.Kind.UNARY_INCREMENT,kind);
case IToken.tDECR : case IToken.tDECR :
consume(); consume();
return unaryOperatorCastExpression(scope, return unaryOperatorCastExpression(scope,
IASTExpression.Kind.UNARY_DECREMENT); IASTExpression.Kind.UNARY_DECREMENT,kind);
case IToken.t_sizeof : case IToken.t_sizeof :
consume(IToken.t_sizeof); consume(IToken.t_sizeof);
IToken mark = LA(1); IToken mark = LA(1);
@ -1721,18 +1766,18 @@ public class ExpressionParser implements IExpressionParser {
try try
{ {
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
d = typeId(scope, false); d = typeId(scope, false, CompletionKind.TYPE_REFERENCE);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
} }
catch (BacktrackException bt) catch (BacktrackException bt)
{ {
backup(mark); backup(mark);
unaryExpression = unaryExpression(scope); unaryExpression = unaryExpression(scope,kind);
} }
} }
else else
{ {
unaryExpression = unaryExpression(scope); unaryExpression = unaryExpression(scope,kind);
} }
if (d != null & unaryExpression == null) if (d != null & unaryExpression == null)
try try
@ -1777,19 +1822,22 @@ public class ExpressionParser implements IExpressionParser {
case IToken.t_new : case IToken.t_new :
return newExpression(scope); return newExpression(scope);
case IToken.t_delete : case IToken.t_delete :
return deleteExpression(scope); return deleteExpression(scope,kind);
case IToken.tCOLONCOLON : case IToken.tCOLONCOLON :
switch (LT(2)) if( queryLookaheadCapability(2))
{ {
case IToken.t_new : switch (LT(2))
return newExpression(scope); {
case IToken.t_delete : case IToken.t_new :
return deleteExpression(scope); return newExpression(scope);
default : case IToken.t_delete :
return postfixExpression(scope); return deleteExpression(scope,kind);
} default :
return postfixExpression(scope,kind);
}
}
default : default :
return postfixExpression(scope); return postfixExpression(scope,kind);
} }
} }
@ -1797,7 +1845,7 @@ public class ExpressionParser implements IExpressionParser {
* @param expression * @param expression
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTExpression postfixExpression(IASTScope scope) throws EndOfFileException, BacktrackException { protected IASTExpression postfixExpression(IASTScope scope, CompletionKind kind) throws EndOfFileException, BacktrackException {
IASTExpression firstExpression = null; IASTExpression firstExpression = null;
boolean isTemplate = false; boolean isTemplate = false;
checkEndOfFile(); checkEndOfFile();
@ -1826,7 +1874,7 @@ public class ExpressionParser implements IExpressionParser {
} }
consume( IToken.tLPAREN ); consume( IToken.tLPAREN );
if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLPAREN ) ); } if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLPAREN ) ); }
IASTExpression expressionList = expression( scope ); IASTExpression expressionList = expression( scope, CompletionKind.TYPE_REFERENCE );
consume( IToken.tRPAREN ); consume( IToken.tRPAREN );
if( templateIdScopes != null ){ templateIdScopes.pop(); } if( templateIdScopes != null ){ templateIdScopes.pop(); }
try { try {
@ -1927,12 +1975,12 @@ public class ExpressionParser implements IExpressionParser {
IASTTypeId typeId = null; IASTTypeId typeId = null;
try try
{ {
typeId = typeId(scope, false); typeId = typeId(scope, false, CompletionKind.TYPE_REFERENCE);
} }
catch (BacktrackException b) catch (BacktrackException b)
{ {
isTypeId = false; isTypeId = false;
lhs = expression(scope); lhs = expression(scope, CompletionKind.TYPE_REFERENCE);
} }
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if( templateIdScopes != null ){ templateIdScopes.pop(); } if( templateIdScopes != null ){ templateIdScopes.pop(); }
@ -1960,7 +2008,7 @@ public class ExpressionParser implements IExpressionParser {
} }
break; break;
default : default :
firstExpression = primaryExpression(scope, CompletionKind.SINGLE_NAME_REFERENCE); firstExpression = primaryExpression(scope, kind);
} }
IASTExpression secondExpression = null; IASTExpression secondExpression = null;
for (;;) for (;;)
@ -1971,7 +2019,7 @@ public class ExpressionParser implements IExpressionParser {
// array access // array access
consume(); consume();
if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLBRACKET ) ); } if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLBRACKET ) ); }
secondExpression = expression(scope); secondExpression = expression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
consume(IToken.tRBRACKET); consume(IToken.tRBRACKET);
if( templateIdScopes != null ){ templateIdScopes.pop(); } if( templateIdScopes != null ){ templateIdScopes.pop(); }
try try
@ -1999,7 +2047,7 @@ public class ExpressionParser implements IExpressionParser {
// function call // function call
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLPAREN ) ); } if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLPAREN ) ); }
secondExpression = expression(scope); secondExpression = expression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if( templateIdScopes != null ){ templateIdScopes.pop(); } if( templateIdScopes != null ){ templateIdScopes.pop(); }
try try
@ -2182,10 +2230,10 @@ public class ExpressionParser implements IExpressionParser {
LA(1); LA(1);
} }
protected IASTExpression simpleTypeConstructorExpression(IASTScope scope, Kind type) throws EndOfFileException, BacktrackException { protected IASTExpression simpleTypeConstructorExpression(IASTScope scope, Kind type ) throws EndOfFileException, BacktrackException {
consume(); consume();
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
IASTExpression inside = expression(scope); IASTExpression inside = expression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
try try
{ {
@ -2340,7 +2388,7 @@ public class ExpressionParser implements IExpressionParser {
case IToken.tLPAREN : case IToken.tLPAREN :
consume(); consume();
if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLPAREN ) ); } if( templateIdScopes != null ){ templateIdScopes.push( new Integer( IToken.tLPAREN ) ); }
IASTExpression lhs = expression(scope); IASTExpression lhs = expression(scope, kind);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if( templateIdScopes != null ){ templateIdScopes.pop(); } if( templateIdScopes != null ){ templateIdScopes.pop(); }
try try
@ -2579,9 +2627,9 @@ public class ExpressionParser implements IExpressionParser {
lastToken = null; // this is not entirely right ... lastToken = null; // this is not entirely right ...
} }
protected IASTExpression assignmentOperatorExpression(IASTScope scope, IASTExpression.Kind kind, IASTExpression lhs) throws EndOfFileException, BacktrackException { protected IASTExpression assignmentOperatorExpression(IASTScope scope, IASTExpression.Kind kind, IASTExpression lhs, CompletionKind completionKind) throws EndOfFileException, BacktrackException {
consume(); consume();
IASTExpression assignmentExpression = assignmentExpression(scope); IASTExpression assignmentExpression = assignmentExpression(scope,completionKind);
try try
{ {
@ -2615,8 +2663,9 @@ public class ExpressionParser implements IExpressionParser {
protected void setCompletionValues( IASTScope scope, CompletionKind kind, IToken first, IToken last ) 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 {
IASTExpression castExpression = castExpression(scope); protected IASTExpression unaryOperatorCastExpression(IASTScope scope, IASTExpression.Kind kind, CompletionKind completionKind) throws EndOfFileException, BacktrackException {
IASTExpression castExpression = castExpression(scope,completionKind);
try try
{ {
return astFactory.createExpression( return astFactory.createExpression(
@ -2640,10 +2689,10 @@ public class ExpressionParser implements IExpressionParser {
protected IASTExpression specialCastExpression(IASTScope scope, IASTExpression.Kind kind) throws EndOfFileException, BacktrackException { protected IASTExpression specialCastExpression(IASTScope scope, IASTExpression.Kind kind) throws EndOfFileException, BacktrackException {
consume(); consume();
consume(IToken.tLT); consume(IToken.tLT);
IASTTypeId duple = typeId(scope, false); IASTTypeId duple = typeId(scope, false, CompletionKind.TYPE_REFERENCE);
consume(IToken.tGT); consume(IToken.tGT);
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
IASTExpression lhs = expression(scope); IASTExpression lhs = expression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
try try
{ {

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.parser;
import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.BacktrackException;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IFilenameProvider; import org.eclipse.cdt.core.parser.IFilenameProvider;
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.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTScope;
@ -30,6 +31,6 @@ public interface IExpressionParser extends IFilenameProvider {
* @throws BacktrackException thrown if the Scanner/Stream provided does not yield a valid * @throws BacktrackException thrown if the Scanner/Stream provided does not yield a valid
* expression * expression
*/ */
public IASTExpression expression(IASTScope scope) throws BacktrackException, EndOfFileException; public IASTExpression expression(IASTScope scope, IASTCompletionNode.CompletionKind kind) throws BacktrackException, EndOfFileException;
} }

View file

@ -245,7 +245,7 @@ public abstract class Parser extends ExpressionParser implements IParser
setCompletionValues(scope, CompletionKind.NAMESPACE_REFERENCE, Key.EMPTY ); setCompletionValues(scope, CompletionKind.NAMESPACE_REFERENCE, Key.EMPTY );
// optional :: and nested classes handled in name // optional :: and nested classes handled in name
TokenDuple duple = null; ITokenDuple duple = null;
if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON) if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON)
duple = name(scope, CompletionKind.NAMESPACE_REFERENCE); duple = name(scope, CompletionKind.NAMESPACE_REFERENCE);
else else
@ -284,7 +284,7 @@ public abstract class Parser extends ExpressionParser implements IParser
} }
setCompletionValues(scope, CompletionKind.TYPE_REFERENCE, Key.NAMESPACE_ONLY ); setCompletionValues(scope, CompletionKind.TYPE_REFERENCE, Key.NAMESPACE_ONLY );
TokenDuple name = null; ITokenDuple name = null;
if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON) if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON)
{ {
// optional :: and nested classes handled in name // optional :: and nested classes handled in name
@ -573,7 +573,7 @@ public abstract class Parser extends ExpressionParser implements IParser
if (LT(1) == IToken.tASSIGN) // optional = type-id if (LT(1) == IToken.tASSIGN) // optional = type-id
{ {
consume(IToken.tASSIGN); consume(IToken.tASSIGN);
typeId = typeId(parameterScope, false); // type-id typeId = typeId(parameterScope, false, CompletionKind.TYPE_REFERENCE); // type-id
} }
} }
@ -616,7 +616,7 @@ public abstract class Parser extends ExpressionParser implements IParser
if (LT(1) == IToken.tASSIGN) // optional = type-id if (LT(1) == IToken.tASSIGN) // optional = type-id
{ {
consume(IToken.tASSIGN); consume(IToken.tASSIGN);
optionalTypeId = typeId(parameterScope, false); optionalTypeId = typeId(parameterScope, false, CompletionKind.TYPE_REFERENCE);
} }
} }
@ -947,8 +947,9 @@ public abstract class Parser extends ExpressionParser implements IParser
new DeclarationWrapper(scope, firstToken.getOffset(), firstToken.getLineNumber(), ownerTemplate); new DeclarationWrapper(scope, firstToken.getOffset(), firstToken.getLineNumber(), ownerTemplate);
firstToken = null; // necessary for scalability firstToken = null; // necessary for scalability
setCompletionValues( scope, getCompletionKindForDeclaration(scope, overideKind), Key.DECL_SPECIFIER_SEQUENCE ); CompletionKind completionKindForDeclaration = getCompletionKindForDeclaration(scope, overideKind);
declSpecifierSeq(sdw, false, strategy == SimpleDeclarationStrategy.TRY_CONSTRUCTOR ); setCompletionValues( scope, completionKindForDeclaration, Key.DECL_SPECIFIER_SEQUENCE );
declSpecifierSeq(sdw, false, strategy == SimpleDeclarationStrategy.TRY_CONSTRUCTOR, completionKindForDeclaration );
if (sdw.getTypeSpecifier() == null && sdw.getSimpleType() != IASTSimpleTypeSpecifier.Type.UNSPECIFIED ) if (sdw.getTypeSpecifier() == null && sdw.getSimpleType() != IASTSimpleTypeSpecifier.Type.UNSPECIFIED )
try try
{ {
@ -974,12 +975,13 @@ public abstract class Parser extends ExpressionParser implements IParser
Declarator declarator = null; Declarator declarator = null;
if (LT(1) != IToken.tSEMI) if (LT(1) != IToken.tSEMI)
{ {
declarator = initDeclarator(sdw, strategy); declarator = initDeclarator(sdw, strategy, completionKindForDeclaration
);
while (LT(1) == IToken.tCOMMA) while (LT(1) == IToken.tCOMMA)
{ {
consume(); consume();
initDeclarator(sdw, strategy); initDeclarator(sdw, strategy, completionKindForDeclaration );
} }
} }
@ -1142,7 +1144,7 @@ public abstract class Parser extends ExpressionParser implements IParser
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
IASTExpression expressionList = null; IASTExpression expressionList = null;
expressionList = expression(d.getDeclarationWrapper().getScope()); expressionList = expression(d.getDeclarationWrapper().getScope(), CompletionKind.SINGLE_NAME_REFERENCE);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
@ -1183,7 +1185,7 @@ public abstract class Parser extends ExpressionParser implements IParser
DeclarationWrapper sdw = DeclarationWrapper sdw =
new DeclarationWrapper(scope, current.getOffset(), current.getLineNumber(), null); new DeclarationWrapper(scope, current.getOffset(), current.getLineNumber(), null);
declSpecifierSeq(sdw, true, false); declSpecifierSeq(sdw, true, false, CompletionKind.ARGUMENT_TYPE);
if (sdw.getTypeSpecifier() == null if (sdw.getTypeSpecifier() == null
&& sdw.getSimpleType() && sdw.getSimpleType()
!= IASTSimpleTypeSpecifier.Type.UNSPECIFIED) != IASTSimpleTypeSpecifier.Type.UNSPECIFIED)
@ -1214,7 +1216,7 @@ public abstract class Parser extends ExpressionParser implements IParser
setCompletionValues(scope,CompletionKind.USER_SPECIFIED_NAME,Key.EMPTY ); setCompletionValues(scope,CompletionKind.USER_SPECIFIED_NAME,Key.EMPTY );
if (LT(1) != IToken.tSEMI) if (LT(1) != IToken.tSEMI)
initDeclarator(sdw, SimpleDeclarationStrategy.TRY_FUNCTION ); initDeclarator(sdw, SimpleDeclarationStrategy.TRY_FUNCTION, CompletionKind.VARIABLE_TYPE );
if( lastToken != null ) if( lastToken != null )
sdw.setEndingOffsetAndLineNumber( lastToken.getEndOffset(), lastToken.getLineNumber() ); sdw.setEndingOffsetAndLineNumber( lastToken.getEndOffset(), lastToken.getLineNumber() );
@ -1289,19 +1291,19 @@ public abstract class Parser extends ExpressionParser implements IParser
* @return whether or not this looks like a constructor (true or false) * @return whether or not this looks like a constructor (true or false)
* @throws EndOfFileException we could encounter EOF while looking ahead * @throws EndOfFileException we could encounter EOF while looking ahead
*/ */
private boolean lookAheadForConstructorOrConversion(Flags flags, DeclarationWrapper sdw ) private boolean lookAheadForConstructorOrConversion(Flags flags, DeclarationWrapper sdw, CompletionKind kind )
throws EndOfFileException throws EndOfFileException
{ {
if (flags.isForParameterDeclaration()) if (flags.isForParameterDeclaration())
return false; return false;
if (LT(2) == IToken.tLPAREN && flags.isForConstructor()) if (queryLookaheadCapability(2) && LT(2) == IToken.tLPAREN && flags.isForConstructor())
return true; return true;
IToken mark = mark(); IToken mark = mark();
Declarator d = new Declarator( sdw ); Declarator d = new Declarator( sdw );
try try
{ {
consumeTemplatedOperatorName( d ); consumeTemplatedOperatorName( d, kind );
} }
catch (BacktrackException e) catch (BacktrackException e)
{ {
@ -1380,7 +1382,7 @@ public abstract class Parser extends ExpressionParser implements IParser
protected void declSpecifierSeq( protected void declSpecifierSeq(
DeclarationWrapper sdw, DeclarationWrapper sdw,
boolean parm, boolean parm,
boolean tryConstructor ) boolean tryConstructor, CompletionKind kind )
throws BacktrackException, EndOfFileException throws BacktrackException, EndOfFileException
{ {
Flags flags = new Flags(parm, tryConstructor); Flags flags = new Flags(parm, tryConstructor);
@ -1591,7 +1593,7 @@ public abstract class Parser extends ExpressionParser implements IParser
new TokenDuple(typeNameBegin, typeNameEnd)); new TokenDuple(typeNameBegin, typeNameEnd));
return; return;
} }
if (lookAheadForConstructorOrConversion(flags, sdw)) if (lookAheadForConstructorOrConversion(flags, sdw, kind))
{ {
if (typeNameBegin != null) if (typeNameBegin != null)
sdw.setTypeName( sdw.setTypeName(
@ -1607,7 +1609,7 @@ public abstract class Parser extends ExpressionParser implements IParser
return; return;
} }
ITokenDuple d = name(sdw.getScope(), CompletionKind.TYPE_REFERENCE ); ITokenDuple d = name(sdw.getScope(), kind );
sdw.setTypeName(d); sdw.setTypeName(d);
sdw.setSimpleType( IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); sdw.setSimpleType( IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME );
flags.setEncounteredTypename(true); flags.setEncounteredTypename(true);
@ -1747,10 +1749,10 @@ public abstract class Parser extends ExpressionParser implements IParser
* @throws BacktrackException request a backtrack * @throws BacktrackException request a backtrack
*/ */
protected Declarator initDeclarator( protected Declarator initDeclarator(
DeclarationWrapper sdw, SimpleDeclarationStrategy strategy ) DeclarationWrapper sdw, SimpleDeclarationStrategy strategy, CompletionKind kind )
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
{ {
Declarator d = declarator(sdw, sdw.getScope(), strategy ); Declarator d = declarator(sdw, sdw.getScope(), strategy, kind );
if( language == ParserLanguage.CPP ) if( language == ParserLanguage.CPP )
optionalCPPInitializer(d); optionalCPPInitializer(d);
else if( language == ParserLanguage.C ) else if( language == ParserLanguage.C )
@ -1782,7 +1784,7 @@ public abstract class Parser extends ExpressionParser implements IParser
consume(IToken.tLPAREN); // EAT IT! consume(IToken.tLPAREN); // EAT IT!
setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY); setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY);
IASTExpression astExpression = null; IASTExpression astExpression = null;
astExpression = expression(scope); astExpression = expression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY); setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
d.setConstructorExpression(astExpression); d.setConstructorExpression(astExpression);
@ -1854,7 +1856,7 @@ public abstract class Parser extends ExpressionParser implements IParser
// assignmentExpression // assignmentExpression
try try
{ {
IASTExpression assignmentExpression = assignmentExpression(scope); IASTExpression assignmentExpression = assignmentExpression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
try try
{ {
return astFactory.createInitializerClause( return astFactory.createInitializerClause(
@ -1931,7 +1933,7 @@ public abstract class Parser extends ExpressionParser implements IParser
try try
{ {
IASTExpression assignmentExpression = IASTExpression assignmentExpression =
assignmentExpression(scope); assignmentExpression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
try try
{ {
@ -1979,7 +1981,7 @@ public abstract class Parser extends ExpressionParser implements IParser
else if( LT(1) == IToken.tLBRACKET ) else if( LT(1) == IToken.tLBRACKET )
{ {
consume( IToken.tLBRACKET ); consume( IToken.tLBRACKET );
constantExpression = expression( scope ); constantExpression = expression( scope, CompletionKind.SINGLE_NAME_REFERENCE );
consume( IToken.tRBRACKET ); consume( IToken.tRBRACKET );
kind = IASTDesignator.DesignatorKind.SUBSCRIPT; kind = IASTDesignator.DesignatorKind.SUBSCRIPT;
} }
@ -2014,7 +2016,7 @@ public abstract class Parser extends ExpressionParser implements IParser
* @throws BacktrackException request a backtrack * @throws BacktrackException request a backtrack
*/ */
protected Declarator declarator( protected Declarator declarator(
IDeclaratorOwner owner, IASTScope scope, SimpleDeclarationStrategy strategy ) IDeclaratorOwner owner, IASTScope scope, SimpleDeclarationStrategy strategy, CompletionKind kind )
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
{ {
Declarator d = null; Declarator d = null;
@ -2028,11 +2030,11 @@ public abstract class Parser extends ExpressionParser implements IParser
if (LT(1) == IToken.tLPAREN) if (LT(1) == IToken.tLPAREN)
{ {
consume(); consume();
declarator(d, scope, strategy ); declarator(d, scope, strategy, kind );
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
} }
else else
consumeTemplatedOperatorName(d); consumeTemplatedOperatorName(d, kind);
for (;;) for (;;)
{ {
@ -2143,13 +2145,13 @@ public abstract class Parser extends ExpressionParser implements IParser
String image = LA(1).getImage(); String image = LA(1).getImage();
try try
{ {
duple = typeId(scope, false); duple = typeId(scope, false, CompletionKind.EXCEPTION_REFERENCE );
exceptionSpecIds.add(duple); exceptionSpecIds.add(duple);
} }
catch (BacktrackException e) catch (BacktrackException e)
{ {
failParse(); failParse();
TraceUtil.outputTrace( log, "Unexpected Token =", null, image, null, null ); //$NON-NLS-1$ TraceUtil.outputTrace( log, "Unexpected Token =", null, image, null, null );
consume(); consume();
// eat this token anyway // eat this token anyway
continue; continue;
@ -2207,8 +2209,7 @@ public abstract class Parser extends ExpressionParser implements IParser
continue; continue;
case IToken.tCOLON : case IToken.tCOLON :
consume(IToken.tCOLON); consume(IToken.tCOLON);
IASTExpression exp = null; IASTExpression exp = constantExpression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
exp = constantExpression(scope);
d.setBitFieldExpression(exp); d.setBitFieldExpression(exp);
default : default :
break; break;
@ -2224,7 +2225,8 @@ public abstract class Parser extends ExpressionParser implements IParser
((Declarator)d.getOwner()).setOwnedDeclarator(d); ((Declarator)d.getOwner()).setOwnedDeclarator(d);
return d; return d;
} }
protected void consumeTemplatedOperatorName(Declarator d)
protected void consumeTemplatedOperatorName(Declarator d, CompletionKind kind)
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
{ {
if (LT(1) == IToken.t_operator) if (LT(1) == IToken.t_operator)
@ -2233,7 +2235,7 @@ public abstract class Parser extends ExpressionParser implements IParser
{ {
try try
{ {
ITokenDuple duple = name(d.getDeclarationWrapper().getScope(), CompletionKind.SINGLE_NAME_REFERENCE ); ITokenDuple duple = name(d.getDeclarationWrapper().getScope(), kind );
d.setName(duple); d.setName(duple);
} }
@ -2347,7 +2349,7 @@ public abstract class Parser extends ExpressionParser implements IParser
if (LT(1) == IToken.tASSIGN) if (LT(1) == IToken.tASSIGN)
{ {
consume(IToken.tASSIGN); consume(IToken.tASSIGN);
initialValue = constantExpression(sdw.getScope()); initialValue = constantExpression(sdw.getScope(), CompletionKind.SINGLE_NAME_REFERENCE);
} }
if (LT(1) == IToken.tRBRACE) if (LT(1) == IToken.tRBRACE)
@ -2598,7 +2600,7 @@ public abstract class Parser extends ExpressionParser implements IParser
break; break;
case IToken.tCOLONCOLON : case IToken.tCOLONCOLON :
case IToken.tIDENTIFIER : case IToken.tIDENTIFIER :
nameDuple = name(astClassSpec, CompletionKind.CLASS_REFERENCE ); nameDuple = name(astClassSpec.getOwnerScope(), CompletionKind.CLASS_REFERENCE );
break; break;
case IToken.tCOMMA : case IToken.tCOMMA :
try try
@ -2667,7 +2669,7 @@ public abstract class Parser extends ExpressionParser implements IParser
{ {
case IToken.t_case : case IToken.t_case :
consume(IToken.t_case); consume(IToken.t_case);
IASTExpression constant_expression = constantExpression(scope); IASTExpression constant_expression = constantExpression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
constant_expression.acceptElement(requestor); constant_expression.acceptElement(requestor);
consume(IToken.tCOLON); consume(IToken.tCOLON);
statement(scope); statement(scope);
@ -2735,7 +2737,7 @@ public abstract class Parser extends ExpressionParser implements IParser
consume(IToken.tSEMI); consume(IToken.tSEMI);
if (LT(1) != IToken.tRPAREN) if (LT(1) != IToken.tRPAREN)
{ {
IASTExpression finalExpression = expression(scope); IASTExpression finalExpression = expression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
finalExpression.acceptElement(requestor); finalExpression.acceptElement(requestor);
} }
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
@ -2753,7 +2755,7 @@ public abstract class Parser extends ExpressionParser implements IParser
consume(); consume();
if (LT(1) != IToken.tSEMI) if (LT(1) != IToken.tSEMI)
{ {
IASTExpression retVal = expression(scope); IASTExpression retVal = expression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
retVal.acceptElement(requestor); retVal.acceptElement(requestor);
} }
consume(IToken.tSEMI); consume(IToken.tSEMI);
@ -2794,9 +2796,9 @@ public abstract class Parser extends ExpressionParser implements IParser
IToken mark = mark(); IToken mark = mark();
try try
{ {
IASTExpression thisExpression = expression(scope); IASTExpression expressionStatement = expression(scope, CompletionKind.SINGLE_NAME_REFERENCE);
consume(IToken.tSEMI); consume(IToken.tSEMI);
thisExpression.acceptElement( requestor ); expressionStatement.acceptElement( requestor );
return; return;
} }
catch (BacktrackException b) catch (BacktrackException b)
@ -2857,7 +2859,7 @@ public abstract class Parser extends ExpressionParser implements IParser
*/ */
protected void condition( IASTScope scope ) throws BacktrackException, EndOfFileException protected void condition( IASTScope scope ) throws BacktrackException, EndOfFileException
{ {
IASTExpression someExpression = expression( scope ); IASTExpression someExpression = expression( scope, CompletionKind.SINGLE_NAME_REFERENCE );
someExpression.acceptElement(requestor); someExpression.acceptElement(requestor);
//TODO type-specifier-seq declarator = assignment expression //TODO type-specifier-seq declarator = assignment expression
} }
@ -2870,7 +2872,7 @@ public abstract class Parser extends ExpressionParser implements IParser
IToken mark = mark(); IToken mark = mark();
try try
{ {
IASTExpression e = expression( scope ); IASTExpression e = expression( scope, CompletionKind.SINGLE_NAME_REFERENCE );
e.acceptElement(requestor); e.acceptElement(requestor);
consume( IToken.tSEMI ); consume( IToken.tSEMI );
@ -3011,6 +3013,7 @@ public abstract class Parser extends ExpressionParser implements IParser
protected void setCompletionToken( IToken token ) protected void setCompletionToken( IToken token )
{ {
// do nothing!
} }
protected IToken getCompletionToken() protected IToken getCompletionToken()
@ -3023,28 +3026,33 @@ public abstract class Parser extends ExpressionParser implements IParser
*/ */
public IASTNode parse(int startingOffset, int endingOffset) public IASTNode parse(int startingOffset, int endingOffset)
throws ParseError { throws ParseError {
// TODO Auto-generated method stub throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IParser#parse(int) * @see org.eclipse.cdt.core.parser.IParser#parse(int)
*/ */
public IASTCompletionNode parse(int offset) throws ParseError { public IASTCompletionNode parse(int offset) throws ParseError {
// TODO Auto-generated method stub throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setupASTFactory(org.eclipse.cdt.core.parser.IScanner, org.eclipse.cdt.core.parser.ParserLanguage) * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setupASTFactory(org.eclipse.cdt.core.parser.IScanner, org.eclipse.cdt.core.parser.ParserLanguage)
*/ */
protected void setupASTFactory(IScanner scanner, ParserLanguage language) { protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
// do nothing as of yet
// subclasses will need to implement this method
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ExpressionParser#parserTimeout() * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#parserTimeout()
*/ */
protected boolean parserTimeout() { protected boolean parserTimeout() {
// TODO Auto-generated method stub
return requestor.parserTimeout(); return requestor.parserTimeout();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.ExpressionParser#getCompliationUnit()
*/
protected IASTNode getCompliationUnit() {
return compilationUnit;
}
} }

View file

@ -2245,7 +2245,8 @@ public class ParserSymbolTable {
} }
if( ! (qualifyingSymbol instanceof IDerivableContainerSymbol) ){ if( ! (qualifyingSymbol instanceof IDerivableContainerSymbol) ){
throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError ); // throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError ); //TODO - Andrew, why is this an error?
return ASTAccessVisibility.PUBLIC;
} }
List parents = ((IDerivableContainerSymbol) qualifyingSymbol).getParents(); List parents = ((IDerivableContainerSymbol) qualifyingSymbol).getParents();

View file

@ -2447,7 +2447,7 @@ public class Scanner implements IScanner {
parser = InternalParserUtil.createExpressionParser(trial, scannerData.getLanguage(), NULL_LOG_SERVICE); parser = InternalParserUtil.createExpressionParser(trial, scannerData.getLanguage(), NULL_LOG_SERVICE);
try { try {
IASTExpression exp = parser.expression(null); IASTExpression exp = parser.expression(null, null);
if( exp.evaluateExpression() == 0 ) if( exp.evaluateExpression() == 0 )
return false; return false;
return true; return true;

View file

@ -1,3 +1,8 @@
2004-04-07 John Camelon
Updated CompletionFailedTest_ScopedReference_Prefix_Bug50152, moved it out of failed tests package and renamed it to CompletionTest_ScopedReference_Prefix_Bug50152.
Updated CompletionFailedTest_TypeDef_Bug52948, moved it out of failed tests package and renamed it to CompletionTest_TypeDef_Bug52948.
Updated CompletionFailedTest_ScopedReference_NoPrefix_Bug50152 to show Hoda/Andrew what is still broken.
2004-03-08 Hoda Amer 2004-03-08 Hoda Amer
Added one failed test: CompletionFailedTest_TypeDef_Bug52948 Added one failed test: CompletionFailedTest_TypeDef_Bug52948

View file

@ -70,12 +70,12 @@ public class AutomatedSuite extends TestSuite {
// Failed Tests // Failed Tests
addTest(CompletionFailedTest_ScopedReference_NoPrefix_Bug50152.suite()); addTest(CompletionFailedTest_ScopedReference_NoPrefix_Bug50152.suite());
addTest(CompletionFailedTest_ScopedReference_Prefix_Bug50152.suite()); addTest(CompletionTest_ScopedReference_Prefix_Bug50152.suite());
addTest(CompletionTest_MacroRef_NoPrefix.suite()); addTest(CompletionTest_MacroRef_NoPrefix.suite());
addTest(CompletionTest_MacroRef_Prefix.suite()); addTest(CompletionTest_MacroRef_Prefix.suite());
addTest(CompletionFailedTest_FunctionReference_Bug50807.suite()); addTest(CompletionFailedTest_FunctionReference_Bug50807.suite());
addTest(CompletionFailedTest_ConstructorReference_Bug50808.suite()); addTest(CompletionFailedTest_ConstructorReference_Bug50808.suite());
addTest(CompletionFailedTest_TypeDef_Bug52948.suite()); addTest(CompletionTest_TypeDef_Bug52948.suite());
} }
} }

View file

@ -8,12 +8,11 @@
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist.failedtests; package org.eclipse.cdt.ui.tests.text.contentassist;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
/** /**
* @author hamer * @author hamer
@ -22,27 +21,27 @@ import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
* Bug#50152: Wrong context sent after a "::" * Bug#50152: Wrong context sent after a "::"
* *
*/ */
public class CompletionFailedTest_ScopedReference_Prefix_Bug50152 extends CompletionProposalsBaseTest{ public class CompletionTest_ScopedReference_Prefix_Bug50152 extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart31.cpp"; private final String fileName = "CompletionTestStart31.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName; private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h"; private final String headerFileName = "CompletionTestStart.h";
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"; // should be "ASTNamespaceDefinition"; private final String expectedContextName = "ASTNamespaceDefinition";
private final CompletionKind expectedKind = CompletionKind.SINGLE_NAME_REFERENCE; // should be CompletionKind.SCOPED_REFERENCE; private final CompletionKind expectedKind = CompletionKind.SINGLE_NAME_REFERENCE;
private final String expectedPrefix = "a"; private final String expectedPrefix = "a";
private final String[] expectedResults = { private final String[] expectedResults = {
// shoud be "aNamespaceFunction() void" "aNamespaceFunction() void"
}; };
public CompletionFailedTest_ScopedReference_Prefix_Bug50152(String name) { public CompletionTest_ScopedReference_Prefix_Bug50152(String name) {
super(name); super(name);
} }
public static Test suite() { public static Test suite() {
TestSuite suite= new TestSuite(CompletionFailedTest_ScopedReference_Prefix_Bug50152.class.getName()); TestSuite suite= new TestSuite(CompletionTest_ScopedReference_Prefix_Bug50152.class.getName());
suite.addTest(new CompletionFailedTest_ScopedReference_Prefix_Bug50152("testCompletionProposals")); suite.addTest(new CompletionTest_ScopedReference_Prefix_Bug50152("testCompletionProposals"));
return suite; return suite;
} }

View file

@ -0,0 +1,120 @@
/**********************************************************************
* Copyright (c) 2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
/**
* @author hamer
*
* Testing Typedef as a possible returned type.
* Bug#52948
*
*/
public class CompletionTest_TypeDef_Bug52948 extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart37.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTCompilationUnit";
private final String expectedContextName = "null";
private final CompletionKind expectedKind = CompletionKind.VARIABLE_TYPE;
private final String expectedPrefix = "m";
private final String[] expectedResults = {
"myType"
};
public CompletionTest_TypeDef_Bug52948(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionTest_TypeDef_Bug52948.class.getName());
suite.addTest(new CompletionTest_TypeDef_Bug52948("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
protected int getCompletionPosition() {
return getBuffer().indexOf(" m ") + 2;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedScope()
*/
protected String getExpectedScopeClassName() {
return expectedScopeName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedContext()
*/
protected String getExpectedContextClassName() {
return expectedContextName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedKind()
*/
protected CompletionKind getExpectedKind() {
return expectedKind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix()
*/
protected String getExpectedPrefix() {
return expectedPrefix;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues()
*/
protected String[] getExpectedResultsValues() {
return expectedResults;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName()
*/
protected String getFileName() {
return fileName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath()
*/
protected String getFileFullPath() {
return fileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath()
*/
protected String getHeaderFileFullPath() {
return headerFileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName()
*/
protected String getHeaderFileName() {
return headerFileName;
}
}

View file

@ -29,11 +29,11 @@ public class CompletionFailedTest_ScopedReference_NoPrefix_Bug50152 extends Com
private final String headerFileName = "CompletionTestStart.h"; private final String headerFileName = "CompletionTestStart.h";
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"; // should be "ASTNamespaceDefinition"; private final String expectedContextName = "ASTNamespaceDefinition";
private final CompletionKind expectedKind = CompletionKind.SINGLE_NAME_REFERENCE; // should be CompletionKind.SCOPED_REFERENCE; private final CompletionKind expectedKind = CompletionKind.SINGLE_NAME_REFERENCE;
private final String expectedPrefix = ""; private final String expectedPrefix = "";
private final String[] expectedResults = { private final String[] expectedResults = {
// shoud be "aNamespaceFunction() void" // "aNamespaceFunction() void" /* Hoda uncomment this to see the failure */
}; };
public CompletionFailedTest_ScopedReference_NoPrefix_Bug50152(String name) { public CompletionFailedTest_ScopedReference_NoPrefix_Bug50152(String name) {