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

fixing bug 65114, NPE in getParentClassSpecifier(), caused by template

lookup issues in the class base clause
This commit is contained in:
Andrew Niefer 2004-06-09 21:33:50 +00:00
parent b9af09113a
commit 8d55216fb7
4 changed files with 77 additions and 40 deletions

View file

@ -1,9 +1,9 @@
/*******************************************************************************
* Copyright (c) 2004 IBM 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
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
@ -1012,4 +1012,36 @@ public class CompleteParseASTTemplateTest extends CompleteParseBaseTest {
assertAllReferences( 4, createTaskList( new Task( simple ), new Task( _Tp ),
new Task( malloc ), new Task( inst ) ) );
}
public void testBug655114_2() throws Exception
{
Writer writer = new StringWriter();
writer.write( "template < typename _Alloc > class base_allocator { int _Tp; }; \n"); //$NON-NLS-1$
writer.write( "template < class T > class B {}; \n"); //$NON-NLS-1$
writer.write( "template <> class B < int > {}; \n"); //$NON-NLS-1$
writer.write( "template < typename _Alloc > class allocator; \n"); //$NON-NLS-1$
writer.write( "template < typename _Tp > class allocator : base_allocator<_Tp>, B<_Tp> {}; \n"); //$NON-NLS-1$
Iterator i = parse( writer.toString() ).getDeclarations();
IASTTemplateDeclaration base = (IASTTemplateDeclaration) i.next();
IASTClassSpecifier baseCls = (IASTClassSpecifier) base.getOwnedDeclaration();
IASTTemplateDeclaration B1 = (IASTTemplateDeclaration) i.next();
IASTTemplateDeclaration B2 = (IASTTemplateDeclaration) i.next();
IASTClassSpecifier B1cls = (IASTClassSpecifier) B1.getOwnedDeclaration();
IASTClassSpecifier B2cls = (IASTClassSpecifier) B2.getOwnedDeclaration();
IASTTemplateDeclaration forward = (IASTTemplateDeclaration) i.next();
IASTTemplateDeclaration allocator = (IASTTemplateDeclaration) i.next();
IASTClassSpecifier cls = (IASTClassSpecifier) allocator.getOwnedDeclaration();
i = cls.getBaseClauses();
IASTBaseSpecifier clause = (IASTBaseSpecifier) i.next();
assertEquals( clause.getParentClassSpecifier(), baseCls );
clause = (IASTBaseSpecifier) i.next();
assertEquals( clause.getParentClassSpecifier(), B1cls );
}
}

View file

@ -1,9 +1,9 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* Copyright (c) 2002,2003, 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
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Rational Software - Initial API and implementation
@ -2836,6 +2836,8 @@ public abstract class Parser extends ExpressionParser implements IParser
ASTAccessVisibility visibility = ASTAccessVisibility.PUBLIC;
ITokenDuple nameDuple = null;
ArrayList bases = null;
baseSpecifierLoop : for (;;)
{
switch (LT(1))
@ -2861,26 +2863,17 @@ public abstract class Parser extends ExpressionParser implements IParser
break;
case IToken.tCOLONCOLON :
case IToken.tIDENTIFIER :
nameDuple = name(astClassSpec.getOwnerScope(), CompletionKind.CLASS_REFERENCE, KeywordSetKey.BASE_SPECIFIER );
//to get templates right we need to use the class as the scope
nameDuple = name(astClassSpec, CompletionKind.CLASS_REFERENCE, KeywordSetKey.BASE_SPECIFIER );
break;
case IToken.tCOMMA :
try
{
astFactory.addBaseSpecifier(
astClassSpec,
isVirtual,
visibility,
nameDuple );
}
catch (ASTSemanticException e)
{
failParse();
throw backtrack;
} catch (Exception e)
{
logException( "baseSpecifier_1::addBaseSpecifier", e ); //$NON-NLS-1$
throw backtrack;
}
//because we are using the class as the scope to get the name, we need to postpone adding the base
//specifiers until after we have all the nameDuples
if( bases == null ){
bases = new ArrayList(5);
}
bases.add( new Object[] { isVirtual ? Boolean.TRUE : Boolean.FALSE, visibility, nameDuple } );
isVirtual = false;
visibility = ASTAccessVisibility.PUBLIC;
nameDuple = null;
@ -2894,7 +2887,18 @@ public abstract class Parser extends ExpressionParser implements IParser
try
{
astFactory.addBaseSpecifier(
if( bases != null ){
int size = bases.size();
for( int i = 0; i < size; i++ ){
Object [] data = (Object[]) bases.get( i );
astFactory.addBaseSpecifier( astClassSpec,
((Boolean)data[0]).booleanValue(),
(ASTAccessVisibility) data[1],
(ITokenDuple)data[2] );
}
}
astFactory.addBaseSpecifier(
astClassSpec,
isVirtual,
visibility,

View file

@ -1,9 +1,9 @@
/**********************************************************************
* Copyright (c) 2002,2003,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
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05. html
* http://www.eclipse.org/legal/cpl-v10. html
*
* Contributors:
* Rational Software - Initial API and implementation
@ -370,7 +370,8 @@ public class ParserSymbolTable {
IContainerSymbol containing = lookIn.getContainingSymbol();
IContainerSymbol outer = (containing != null ) ? containing.getContainingSymbol() : null;
if( ( containing instanceof IDerivableContainerSymbol && outer instanceof ITemplateSymbol) ||
( lookIn instanceof IParameterizedSymbol && containing instanceof ITemplateSymbol ) )
( lookIn instanceof IParameterizedSymbol && containing instanceof ITemplateSymbol ) ||
( lookIn instanceof IDerivableContainerSymbol && containing instanceof ITemplateSymbol ) )
{
data.templateMember = lookIn;
}

View file

@ -1,9 +1,9 @@
/**********************************************************************
* 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
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
@ -24,17 +24,17 @@ import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
*/
public class CompletionTest_ClassReference_Prefix extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart20.h";
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 String fileName = "CompletionTestStart20.h"; //$NON-NLS-1$
private final String fileFullPath ="resources/contentassist/" + fileName; //$NON-NLS-1$
private final String headerFileName = "CompletionTestStart.h"; //$NON-NLS-1$
private final String headerFileFullPath ="resources/contentassist/" + headerFileName; //$NON-NLS-1$
private final String expectedScopeName = "ASTClassSpecifier"; //$NON-NLS-1$
private final String expectedContextName = "null"; //$NON-NLS-1$
private final CompletionKind expectedKind = CompletionKind.CLASS_REFERENCE;
private final String expectedPrefix = "a";
private final String expectedPrefix = "a"; //$NON-NLS-1$
private final String[] expectedResults = {
"aClass",
"anotherClass"
"aClass", //$NON-NLS-1$
"anotherClass" //$NON-NLS-1$
};
public CompletionTest_ClassReference_Prefix(String name) {
@ -43,7 +43,7 @@ public class CompletionTest_ClassReference_Prefix extends CompletionProposalsBa
public static Test suite() {
TestSuite suite= new TestSuite(CompletionTest_ClassReference_Prefix.class.getName());
suite.addTest(new CompletionTest_ClassReference_Prefix("testCompletionProposals"));
suite.addTest(new CompletionTest_ClassReference_Prefix("testCompletionProposals")); //$NON-NLS-1$
return suite;
}
@ -51,7 +51,7 @@ public class CompletionTest_ClassReference_Prefix extends CompletionProposalsBa
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
protected int getCompletionPosition() {
return getBuffer().indexOf(" a ") + 2;
return getBuffer().indexOf(" a ") + 2; //$NON-NLS-1$
}
/* (non-Javadoc)