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

View file

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