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

Fixed defects 71094 & 68528.

This commit is contained in:
John Camelon 2004-08-04 19:26:31 +00:00
parent 39e2a667df
commit 903d1ac7a8
4 changed files with 252 additions and 153 deletions

View file

@ -2079,4 +2079,35 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
parse( writer.toString() ); parse( writer.toString() );
} }
public void testBug68528() throws Exception
{
Writer writer = new StringWriter();
writer.write( "namespace N526026\n" );
writer.write( "{\n" );
writer.write( "template <typename T>\n" );
writer.write( "class T526026\n" );
writer.write( "{\n" );
writer.write( "typedef int diff;\n" );
writer.write( "};\n" );
writer.write( "\n" );
writer.write( "template<typename T>\n" );
writer.write( "inline T526026< T >\n" );
writer.write( "operator+(typename T526026<T>::diff d, const T526026<T> & x )\n" );
writer.write( "{ return T526026< T >(); }\n" );
writer.write( "}\n" );
parse( writer.toString(), false );
}
public void testBug71094() throws Exception
{
Writer writer = new StringWriter();
writer.write( "using namespace DOESNOTEXIST;\n" );
writer.write( "class A { int x; };\n" );
Iterator i = parse( writer.toString(), false ).getDeclarations();
assertTrue( i.hasNext() );
assertTrue( i.next() instanceof IASTAbstractTypeSpecifierDeclaration );
assertFalse( i.hasNext() );
}
} }

View file

@ -504,6 +504,7 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void exitCompilationUnit(IASTCompilationUnit cu ) public void exitCompilationUnit(IASTCompilationUnit cu )
{ {
popScope();
} }
@ -525,12 +526,14 @@ public class CompleteParseBaseTest extends TestCase
{ {
Scope s = (Scope)scopes.pop(); Scope s = (Scope)scopes.pop();
h.put( s.getScope(), s ); h.put( s.getScope(), s );
--depth;
return s; return s;
} }
protected void pushScope( IASTScope scope ) protected void pushScope( IASTScope scope )
{ {
scopes.push( new Scope( scope )); scopes.push( new Scope( scope ));
++depth;
} }
Hashtable h = new Hashtable(); Hashtable h = new Hashtable();
@ -547,6 +550,7 @@ public class CompleteParseBaseTest extends TestCase
List problems = new ArrayList(); List problems = new ArrayList();
private int depth = 0;
public Iterator getProblems() { public Iterator getProblems() {
return problems.iterator(); return problems.iterator();
@ -709,6 +713,7 @@ public class CompleteParseBaseTest extends TestCase
protected void pushCodeScope(IASTCodeScope scope) protected void pushCodeScope(IASTCodeScope scope)
{ {
scopes.push( new CodeScope( scope ) ); scopes.push( new CodeScope( scope ) );
++depth;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -757,6 +762,13 @@ public class CompleteParseBaseTest extends TestCase
public void acceptFriendDeclaration(IASTDeclaration declaration) { public void acceptFriendDeclaration(IASTDeclaration declaration) {
getCurrentScope().addDeclaration( declaration ); getCurrentScope().addDeclaration( declaration );
} }
/**
* @return
*/
public boolean isBalanced() {
return depth == 0;
}
} }
protected Iterator getNestedScopes( IASTCodeScope scope ) protected Iterator getNestedScopes( IASTCodeScope scope )
@ -797,7 +809,10 @@ public class CompleteParseBaseTest extends TestCase
// throw exception if there are generated IProblems // throw exception if there are generated IProblems
if( (! parseResult || callback.getProblems().hasNext() ) && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ if( (! parseResult || callback.getProblems().hasNext() ) && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$
if( parseResult ) if( parseResult )
{
assertTrue( ((CompleteParser)parser).validateCaches()); assertTrue( ((CompleteParser)parser).validateCaches());
assertTrue( callback.isBalanced() );
}
return callback.getCompilationUnit(); return callback.getCompilationUnit();
} }

View file

@ -2896,7 +2896,8 @@ public class ExpressionParser implements IExpressionParser, IParserData {
*/ */
protected void errorHandling() throws EndOfFileException { protected void errorHandling() throws EndOfFileException {
int depth = ( LT(1) == IToken.tLBRACE ) ? 1 : 0; int depth = ( LT(1) == IToken.tLBRACE ) ? 1 : 0;
consume(); int type = consume().getType();
if( type == IToken.tSEMI ) return;
while (!((LT(1) == IToken.tSEMI && depth == 0) while (!((LT(1) == IToken.tSEMI && depth == 0)
|| (LT(1) == IToken.tRBRACE && depth == 1))) || (LT(1) == IToken.tRBRACE && depth == 1)))
{ {

View file

@ -319,6 +319,11 @@ public abstract class Parser extends ExpressionParser implements IParser
{ {
astUD = astFactory.createUsingDirective(scope, duple, firstToken.getOffset(), firstToken.getLineNumber(), last.getEndOffset(), last.getLineNumber()); astUD = astFactory.createUsingDirective(scope, duple, firstToken.getOffset(), firstToken.getLineNumber(), last.getEndOffset(), last.getLineNumber());
} }
catch( ASTSemanticException ase )
{
backup( last );
throwBacktrack( ase.getProblem() );
}
catch (Exception e1) catch (Exception e1)
{ {
logException( "usingClause:createUsingDirective", e1 ); //$NON-NLS-1$ logException( "usingClause:createUsingDirective", e1 ); //$NON-NLS-1$
@ -419,34 +424,40 @@ public abstract class Parser extends ExpressionParser implements IParser
throwBacktrack(firstToken.getOffset(), lbrace.getEndOffset(), lbrace.getLineNumber(), lbrace.getFilename()); throwBacktrack(firstToken.getOffset(), lbrace.getEndOffset(), lbrace.getLineNumber(), lbrace.getFilename());
} }
linkage.enterScope( requestor, astFactory.getReferenceManager() ); linkage.enterScope( requestor, astFactory.getReferenceManager() );
linkageDeclarationLoop : while (LT(1) != IToken.tRBRACE) try
{ {
int checkToken = LA(1).hashCode(); linkageDeclarationLoop : while (LT(1) != IToken.tRBRACE)
switch (LT(1)) {
{ int checkToken = LA(1).hashCode();
case IToken.tRBRACE : switch (LT(1))
consume(IToken.tRBRACE); {
break linkageDeclarationLoop; case IToken.tRBRACE :
default : consume(IToken.tRBRACE);
try break linkageDeclarationLoop;
{ default :
declaration(linkage, null, null, KeywordSetKey.DECLARATION); try
} {
catch (BacktrackException bt) declaration(linkage, null, null, KeywordSetKey.DECLARATION);
{ }
failParse(bt); catch (BacktrackException bt)
if (checkToken == LA(1).hashCode()) {
failParseWithErrorHandling(); failParse(bt);
} if (checkToken == LA(1).hashCode())
} failParseWithErrorHandling();
if (checkToken == LA(1).hashCode()) }
failParseWithErrorHandling(); }
} if (checkToken == LA(1).hashCode())
// consume the } failParseWithErrorHandling();
IToken lastTokenConsumed = consume(); }
linkage.setEndingOffsetAndLineNumber(lastTokenConsumed.getEndOffset(), lastTokenConsumed.getLineNumber()); // consume the }
linkage.exitScope( requestor, astFactory.getReferenceManager() ); IToken lastTokenConsumed = consume();
linkage.setEndingOffsetAndLineNumber(lastTokenConsumed.getEndOffset(), lastTokenConsumed.getLineNumber());
}
finally
{
linkage.exitScope( requestor, astFactory.getReferenceManager() );
}
return linkage; return linkage;
} }
// single declaration // single declaration
@ -468,8 +479,14 @@ public abstract class Parser extends ExpressionParser implements IParser
return null; return null;
} }
linkage.enterScope( requestor, astFactory.getReferenceManager() ); linkage.enterScope( requestor, astFactory.getReferenceManager() );
declaration(linkage, null, null, KeywordSetKey.DECLARATION); try
linkage.exitScope( requestor, astFactory.getReferenceManager() ); {
declaration(linkage, null, null, KeywordSetKey.DECLARATION);
}
finally
{
linkage.exitScope( requestor, astFactory.getReferenceManager() );
}
return linkage; return linkage;
} }
@ -522,9 +539,14 @@ public abstract class Parser extends ExpressionParser implements IParser
return null; return null;
} }
templateInstantiation.enterScope( requestor, astFactory.getReferenceManager() ); templateInstantiation.enterScope( requestor, astFactory.getReferenceManager() );
declaration(templateInstantiation, templateInstantiation, null, KeywordSetKey.DECLARATION); try
templateInstantiation.setEndingOffsetAndLineNumber(lastToken.getEndOffset(), lastToken.getLineNumber()); {
templateInstantiation.exitScope( requestor, astFactory.getReferenceManager() ); declaration(templateInstantiation, templateInstantiation, null, KeywordSetKey.DECLARATION);
templateInstantiation.setEndingOffsetAndLineNumber(lastToken.getEndOffset(), lastToken.getLineNumber());
} finally
{
templateInstantiation.exitScope( requestor, astFactory.getReferenceManager() );
}
return templateInstantiation; return templateInstantiation;
} }
@ -550,10 +572,16 @@ public abstract class Parser extends ExpressionParser implements IParser
return null; return null;
} }
templateSpecialization.enterScope(requestor, astFactory.getReferenceManager()); templateSpecialization.enterScope(requestor, astFactory.getReferenceManager());
declaration(templateSpecialization, templateSpecialization, null, KeywordSetKey.DECLARATION); try
templateSpecialization.setEndingOffsetAndLineNumber( {
lastToken.getEndOffset(), lastToken.getLineNumber()); declaration(templateSpecialization, templateSpecialization, null, KeywordSetKey.DECLARATION);
templateSpecialization.exitScope(requestor, astFactory.getReferenceManager()); templateSpecialization.setEndingOffsetAndLineNumber(
lastToken.getEndOffset(), lastToken.getLineNumber());
}
finally
{
templateSpecialization.exitScope(requestor, astFactory.getReferenceManager());
}
return templateSpecialization; return templateSpecialization;
} }
@ -581,13 +609,11 @@ public abstract class Parser extends ExpressionParser implements IParser
templateDecl.enterScope( requestor, astFactory.getReferenceManager() ); templateDecl.enterScope( requestor, astFactory.getReferenceManager() );
try{ try{
declaration(templateDecl, templateDecl, null, KeywordSetKey.DECLARATION ); declaration(templateDecl, templateDecl, null, KeywordSetKey.DECLARATION );
} catch( EndOfFileException e ){
templateDecl.setEndingOffsetAndLineNumber( lastToken.getEndOffset(), lastToken.getLineNumber() ); templateDecl.setEndingOffsetAndLineNumber( lastToken.getEndOffset(), lastToken.getLineNumber() );
} finally
{
templateDecl.exitScope( requestor, astFactory.getReferenceManager() ); templateDecl.exitScope( requestor, astFactory.getReferenceManager() );
throw e;
} }
templateDecl.setEndingOffsetAndLineNumber( lastToken.getEndOffset(), lastToken.getLineNumber() );
templateDecl.exitScope( requestor, astFactory.getReferenceManager() );
return templateDecl; return templateDecl;
} }
catch (BacktrackException bt) catch (BacktrackException bt)
@ -998,39 +1024,45 @@ public abstract class Parser extends ExpressionParser implements IParser
return null; return null;
} }
namespaceDefinition.enterScope( requestor, astFactory.getReferenceManager() ); namespaceDefinition.enterScope( requestor, astFactory.getReferenceManager() );
setCompletionValues(scope,CompletionKind.VARIABLE_TYPE, KeywordSetKey.DECLARATION ); try
endDeclaration( namespaceDefinition ); {
namespaceDeclarationLoop : while (LT(1) != IToken.tRBRACE) setCompletionValues(scope,CompletionKind.VARIABLE_TYPE, KeywordSetKey.DECLARATION );
{ endDeclaration( namespaceDefinition );
int checkToken = LA(1).hashCode(); namespaceDeclarationLoop : while (LT(1) != IToken.tRBRACE)
switch (LT(1)) {
{ int checkToken = LA(1).hashCode();
case IToken.tRBRACE : switch (LT(1))
//consume(Token.tRBRACE); {
break namespaceDeclarationLoop; case IToken.tRBRACE :
default : //consume(Token.tRBRACE);
try break namespaceDeclarationLoop;
{ default :
declaration(namespaceDefinition, null, null, KeywordSetKey.DECLARATION); try
} {
catch (BacktrackException bt) declaration(namespaceDefinition, null, null, KeywordSetKey.DECLARATION);
{ }
failParse(bt); catch (BacktrackException bt)
if (checkToken == LA(1).hashCode()) {
failParseWithErrorHandling(); failParse(bt);
} if (checkToken == LA(1).hashCode())
} failParseWithErrorHandling();
if (checkToken == LA(1).hashCode()) }
failParseWithErrorHandling(); }
} if (checkToken == LA(1).hashCode())
setCompletionValues(scope, CompletionKind.NO_SUCH_KIND,KeywordSetKey.EMPTY ); failParseWithErrorHandling();
// consume the } }
IToken last = consume(IToken.tRBRACE); setCompletionValues(scope, CompletionKind.NO_SUCH_KIND,KeywordSetKey.EMPTY );
// consume the }
namespaceDefinition.setEndingOffsetAndLineNumber( IToken last = consume(IToken.tRBRACE);
last.getOffset() + last.getLength(), last.getLineNumber());
setCompletionValues(scope, kind, KeywordSetKey.DECLARATION ); namespaceDefinition.setEndingOffsetAndLineNumber(
namespaceDefinition.exitScope( requestor, astFactory.getReferenceManager() ); last.getOffset() + last.getLength(), last.getLineNumber());
setCompletionValues(scope, kind, KeywordSetKey.DECLARATION );
}
finally
{
namespaceDefinition.exitScope( requestor, astFactory.getReferenceManager() );
}
return namespaceDefinition; return namespaceDefinition;
} }
else if( LT(1) == IToken.tASSIGN ) else if( LT(1) == IToken.tASSIGN )
@ -1244,17 +1276,22 @@ public abstract class Parser extends ExpressionParser implements IParser
IASTDeclaration declaration = (IASTDeclaration)l.get(0); IASTDeclaration declaration = (IASTDeclaration)l.get(0);
endDeclaration( declaration ); endDeclaration( declaration );
declaration.enterScope( requestor, astFactory.getReferenceManager() ); declaration.enterScope( requestor, astFactory.getReferenceManager() );
if( sdw.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ) try
((IASTSimpleTypeSpecifier)sdw.getTypeSpecifier()).releaseReferences( astFactory.getReferenceManager() ); {
if( sdw.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier )
if ( !( declaration instanceof IASTScope ) ) ((IASTSimpleTypeSpecifier)sdw.getTypeSpecifier()).releaseReferences( astFactory.getReferenceManager() );
throwBacktrack(firstOffset, endOffset, firstLine, fn);
if ( !( declaration instanceof IASTScope ) )
handleFunctionBody((IASTScope)declaration ); throwBacktrack(firstOffset, endOffset, firstLine, fn);
((IASTOffsetableElement)declaration).setEndingOffsetAndLineNumber(
lastToken.getEndOffset(), lastToken.getLineNumber()); handleFunctionBody((IASTScope)declaration );
((IASTOffsetableElement)declaration).setEndingOffsetAndLineNumber(
declaration.exitScope( requestor, astFactory.getReferenceManager() ); lastToken.getEndOffset(), lastToken.getLineNumber());
}
finally
{
declaration.exitScope( requestor, astFactory.getReferenceManager() );
}
if( hasFunctionTryBlock ) if( hasFunctionTryBlock )
catchHandlerSequence( scope ); catchHandlerSequence( scope );
@ -2791,64 +2828,74 @@ public abstract class Parser extends ExpressionParser implements IParser
if (LT(1) == IToken.tCOLON) { if (LT(1) == IToken.tCOLON) {
baseSpecifier(astClassSpecifier); baseSpecifier(astClassSpecifier);
} }
if (LT(1) == IToken.tLBRACE) { if (LT(1) == IToken.tLBRACE) {
consume(IToken.tLBRACE); consume(IToken.tLBRACE);
setCompletionValues(astClassSpecifier, CompletionKind.FIELD_TYPE, setCompletionValues(astClassSpecifier, CompletionKind.FIELD_TYPE,
KeywordSetKey.MEMBER); KeywordSetKey.MEMBER);
astClassSpecifier.enterScope(requestor, astFactory astClassSpecifier.enterScope(requestor, astFactory
.getReferenceManager()); .getReferenceManager());
handleClassSpecifier(astClassSpecifier);
memberDeclarationLoop : while (LT(1) != IToken.tRBRACE) { try
int checkToken = LA(1).hashCode(); {
switch (LT(1)) { handleClassSpecifier(astClassSpecifier);
case IToken.t_public : memberDeclarationLoop : while (LT(1) != IToken.tRBRACE)
consume(); {
consume(IToken.tCOLON); int checkToken = LA(1).hashCode();
astClassSpecifier switch (LT(1)) {
.setCurrentVisibility(ASTAccessVisibility.PUBLIC); case IToken.t_public :
break; consume();
case IToken.t_protected : consume(IToken.tCOLON);
consume(); astClassSpecifier
consume(IToken.tCOLON); .setCurrentVisibility(ASTAccessVisibility.PUBLIC);
astClassSpecifier break;
.setCurrentVisibility(ASTAccessVisibility.PROTECTED); case IToken.t_protected :
break; consume();
consume(IToken.tCOLON);
case IToken.t_private : astClassSpecifier
consume(); .setCurrentVisibility(ASTAccessVisibility.PROTECTED);
consume(IToken.tCOLON); break;
astClassSpecifier
.setCurrentVisibility(ASTAccessVisibility.PRIVATE); case IToken.t_private :
break; consume();
case IToken.tRBRACE : consume(IToken.tCOLON);
consume(IToken.tRBRACE); astClassSpecifier
break memberDeclarationLoop; .setCurrentVisibility(ASTAccessVisibility.PRIVATE);
default : break;
try { case IToken.tRBRACE :
declaration(astClassSpecifier, null, null, consume(IToken.tRBRACE);
KeywordSetKey.MEMBER); break memberDeclarationLoop;
} catch (BacktrackException bt) { default :
if (checkToken == LA(1).hashCode()) try {
failParseWithErrorHandling(); declaration(astClassSpecifier, null, null,
} KeywordSetKey.MEMBER);
} catch (BacktrackException bt) {
if (checkToken == LA(1).hashCode())
failParseWithErrorHandling();
}
}
if (checkToken == LA(1).hashCode())
failParseWithErrorHandling();
}
// consume the }
IToken lt = consume(IToken.tRBRACE);
astClassSpecifier.setEndingOffsetAndLineNumber(lt.getEndOffset(),
lt.getLineNumber());
try {
astFactory.signalEndOfClassSpecifier(astClassSpecifier);
} catch (Exception e1) {
logException("classSpecifier:signalEndOfClassSpecifier", e1); //$NON-NLS-1$
throwBacktrack(lt.getOffset(), lt.getEndOffset(), lt.getLineNumber(), lt.getFilename());
} }
if (checkToken == LA(1).hashCode())
failParseWithErrorHandling();
}
// consume the }
IToken lt = consume(IToken.tRBRACE);
astClassSpecifier.setEndingOffsetAndLineNumber(lt.getEndOffset(),
lt.getLineNumber());
try { }
astFactory.signalEndOfClassSpecifier(astClassSpecifier); finally
} catch (Exception e1) { {
logException("classSpecifier:signalEndOfClassSpecifier", e1); //$NON-NLS-1$ astClassSpecifier.exitScope(requestor, astFactory
throwBacktrack(lt.getOffset(), lt.getEndOffset(), lt.getLineNumber(), lt.getFilename()); .getReferenceManager());
} }
astClassSpecifier.exitScope(requestor, astFactory
.getReferenceManager());
} }
} }
@ -3270,27 +3317,32 @@ public abstract class Parser extends ExpressionParser implements IParser
newScope.enterScope(requestor, astFactory.getReferenceManager()); newScope.enterScope(requestor, astFactory.getReferenceManager());
} }
setCompletionValues((createNewScope ? newScope : scope), try
CompletionKind.SINGLE_NAME_REFERENCE, KeywordSetKey.STATEMENT); {
setCompletionValues((createNewScope ? newScope : scope),
while (LT(1) != IToken.tRBRACE) { CompletionKind.SINGLE_NAME_REFERENCE, KeywordSetKey.STATEMENT);
int checkToken = LA(1).hashCode();
try { while (LT(1) != IToken.tRBRACE) {
statement((IASTCodeScope) (createNewScope ? newScope : scope)); int checkToken = LA(1).hashCode();
} catch (BacktrackException b) { try {
failParse(b); statement((IASTCodeScope) (createNewScope ? newScope : scope));
if (LA(1).hashCode() == checkToken) } catch (BacktrackException b) {
failParseWithErrorHandling(); failParse(b);
if (LA(1).hashCode() == checkToken)
failParseWithErrorHandling();
}
setCompletionValues(((createNewScope ? newScope : scope)),
CompletionKind.SINGLE_NAME_REFERENCE,
KeywordSetKey.STATEMENT);
} }
setCompletionValues(((createNewScope ? newScope : scope)),
CompletionKind.SINGLE_NAME_REFERENCE, consume(IToken.tRBRACE);
KeywordSetKey.STATEMENT); }
finally
{
if (createNewScope)
newScope.exitScope(requestor, astFactory.getReferenceManager());
} }
consume(IToken.tRBRACE);
if (createNewScope)
newScope.exitScope(requestor, astFactory.getReferenceManager());
} }
protected IASTCompilationUnit compilationUnit; protected IASTCompilationUnit compilationUnit;