mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
fix bug 100403 qualified names in class member declarations
This commit is contained in:
parent
189ad381e0
commit
d30c9cee80
3 changed files with 47 additions and 29 deletions
|
@ -4779,15 +4779,15 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
|
||||
public void testBug84478_2() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("void f(){ \n");
|
||||
buffer.append(" if( int x = 1 ) x++; \n");
|
||||
buffer.append(" else x--; \n");
|
||||
buffer.append(" while( int y = 2 ) \n");
|
||||
buffer.append(" y++; \n");
|
||||
buffer.append(" for( int a = 1; int b = 2; b++){ \n");
|
||||
buffer.append(" a++; b++; \n");
|
||||
buffer.append(" } \n");
|
||||
buffer.append("} \n");
|
||||
buffer.append("void f(){ \n"); //$NON-NLS-1$
|
||||
buffer.append(" if( int x = 1 ) x++; \n"); //$NON-NLS-1$
|
||||
buffer.append(" else x--; \n"); //$NON-NLS-1$
|
||||
buffer.append(" while( int y = 2 ) \n"); //$NON-NLS-1$
|
||||
buffer.append(" y++; \n"); //$NON-NLS-1$
|
||||
buffer.append(" for( int a = 1; int b = 2; b++){ \n"); //$NON-NLS-1$
|
||||
buffer.append(" a++; b++; \n"); //$NON-NLS-1$
|
||||
buffer.append(" } \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP, true, true );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
|
@ -4810,10 +4810,10 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
|
||||
public void testBug100415() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("void free( void * ); \n");
|
||||
buffer.append("void f( char **p ){ \n");
|
||||
buffer.append(" free( p ); \n");
|
||||
buffer.append("} \n");
|
||||
buffer.append("void free( void * ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void f( char **p ){ \n"); //$NON-NLS-1$
|
||||
buffer.append(" free( p ); \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP, true, true );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
|
@ -4825,17 +4825,17 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
|
||||
public void testBug86688() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("class X; \n");
|
||||
buffer.append("void f() { \n");
|
||||
buffer.append(" class A { \n");
|
||||
buffer.append(" friend class X; \n");
|
||||
buffer.append(" }; \n");
|
||||
buffer.append("} \n");
|
||||
buffer.append("namespace B { \n");
|
||||
buffer.append(" class A { \n");
|
||||
buffer.append(" friend class X; \n");
|
||||
buffer.append(" }; \n");
|
||||
buffer.append("} \n");
|
||||
buffer.append("class X; \n"); //$NON-NLS-1$
|
||||
buffer.append("void f() { \n"); //$NON-NLS-1$
|
||||
buffer.append(" class A { \n"); //$NON-NLS-1$
|
||||
buffer.append(" friend class X; \n"); //$NON-NLS-1$
|
||||
buffer.append(" }; \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
buffer.append("namespace B { \n"); //$NON-NLS-1$
|
||||
buffer.append(" class A { \n"); //$NON-NLS-1$
|
||||
buffer.append(" friend class X; \n"); //$NON-NLS-1$
|
||||
buffer.append(" }; \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP, true, true );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
|
@ -4846,4 +4846,19 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertTrue( col.getName(3).resolveBinding() instanceof ICPPClassType );
|
||||
assertSame( X, col.getName(6).resolveBinding() );
|
||||
}
|
||||
|
||||
public void testBug100403() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("class m { \n"); //$NON-NLS-1$
|
||||
buffer.append(" int m::f(); \n"); //$NON-NLS-1$
|
||||
buffer.append("}; \n"); //$NON-NLS-1$
|
||||
buffer.append("int m::f(){} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP, true, true );
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
ICPPMethod f = (ICPPMethod) col.getName(3).resolveBinding();
|
||||
assertSame( f, col.getName(6).resolveBinding() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
@ -175,7 +174,7 @@ public class CPPSemantics {
|
|||
public boolean includeBlockItem( IASTNode item ){
|
||||
if( astName.getPropertyInParent() == STRING_LOOKUP_PROPERTY ) return true;
|
||||
if( ( astName != null && astName.getParent() instanceof IASTIdExpression ) ||
|
||||
item instanceof IASTNamespaceDefinition ||
|
||||
item instanceof ICPPASTNamespaceDefinition ||
|
||||
(item instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration)item).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier ) ||
|
||||
item instanceof ICPPASTTemplateDeclaration )
|
||||
{
|
||||
|
|
|
@ -162,9 +162,13 @@ public class CPPVisitor {
|
|||
parent instanceof ICPPASTTemplateId )
|
||||
{
|
||||
binding = CPPSemantics.resolveBinding( name );
|
||||
if( binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName &&
|
||||
((IProblemBinding)binding).getID() != IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND )
|
||||
if( binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName )
|
||||
{
|
||||
if( ((IProblemBinding)binding).getID() == IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND ){
|
||||
IASTNode node = getContainingBlockItem( name.getParent() );
|
||||
if( node.getPropertyInParent() != IASTCompositeTypeSpecifier.MEMBER_DECLARATION )
|
||||
return binding;
|
||||
}
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)parent).getNames();
|
||||
if( ns[ ns.length - 1 ] == name )
|
||||
parent = parent.getParent();
|
||||
|
@ -881,7 +885,7 @@ public class CPPVisitor {
|
|||
return p;
|
||||
} else if ( parent instanceof IASTStatement || parent instanceof IASTTranslationUnit ) {
|
||||
return parent;
|
||||
} else if( parent instanceof IASTFunctionDeclarator ){
|
||||
} else if( parent instanceof IASTFunctionDeclarator && node.getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER ){
|
||||
return node;
|
||||
} else if( parent instanceof IASTEnumerationSpecifier.IASTEnumerator ){
|
||||
return parent;
|
||||
|
|
Loading…
Add table
Reference in a new issue