mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 02:36:01 +02:00
fix bug 84266
This commit is contained in:
parent
88f6cff423
commit
ec6276d5dd
5 changed files with 138 additions and 32 deletions
|
@ -1018,5 +1018,41 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertSame( p_ref, p_decl );
|
assertSame( p_ref, p_decl );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug84266() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "struct s { double i; } f(void); \n"); //$NON-NLS-1$
|
||||||
|
buffer.append( "struct s f(void){} \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
CPPVisitor.visitTranslationUnit(tu, col);
|
||||||
|
|
||||||
|
assertEquals(col.size(), 7);
|
||||||
|
|
||||||
|
ICompositeType s_ref = (ICompositeType) col.getName(4).resolveBinding();
|
||||||
|
ICompositeType s_decl = (ICompositeType) col.getName(0).resolveBinding();
|
||||||
|
|
||||||
|
assertSame( s_ref, s_decl );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBug84266_2() throws Exception {
|
||||||
|
IASTTranslationUnit tu = parse("struct s f(void);", ParserLanguage.CPP); //$NON-NLS-1$
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
CPPVisitor.visitTranslationUnit(tu, col);
|
||||||
|
|
||||||
|
assertEquals(col.size(), 3);
|
||||||
|
|
||||||
|
ICompositeType s = (ICompositeType) col.getName(0).resolveBinding();
|
||||||
|
assertNotNull( s );
|
||||||
|
|
||||||
|
tu = parse("struct s f(void){}", ParserLanguage.CPP); //$NON-NLS-1$
|
||||||
|
col = new CPPNameCollector();
|
||||||
|
CPPVisitor.visitTranslationUnit(tu, col);
|
||||||
|
|
||||||
|
assertEquals(col.size(), 3);
|
||||||
|
|
||||||
|
s = (ICompositeType) col.getName(0).resolveBinding();
|
||||||
|
assertNotNull( s );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2672,6 +2672,49 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
parse( buffer.toString(), ParserLanguage.C );
|
parse( buffer.toString(), ParserLanguage.C );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug84266() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "struct s { double i; } f(void); \n"); //$NON-NLS-1$
|
||||||
|
buffer.append( "struct s f(void){} \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||||
|
CNameCollector col = new CNameCollector();
|
||||||
|
CVisitor.visitTranslationUnit(tu, col);
|
||||||
|
|
||||||
|
assertEquals(col.size(), 7);
|
||||||
|
|
||||||
|
ICompositeType s_ref = (ICompositeType) col.getName(4).resolveBinding();
|
||||||
|
ICompositeType s_decl = (ICompositeType) col.getName(0).resolveBinding();
|
||||||
|
|
||||||
|
assertSame( s_ref, s_decl );
|
||||||
|
CVisitor.clearBindings( tu );
|
||||||
|
|
||||||
|
s_decl = (ICompositeType) col.getName(0).resolveBinding();
|
||||||
|
s_ref = (ICompositeType) col.getName(4).resolveBinding();
|
||||||
|
|
||||||
|
assertSame( s_ref, s_decl );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBug84266_2() throws Exception {
|
||||||
|
IASTTranslationUnit tu = parse("struct s f(void);", ParserLanguage.C); //$NON-NLS-1$
|
||||||
|
CNameCollector col = new CNameCollector();
|
||||||
|
CVisitor.visitTranslationUnit(tu, col);
|
||||||
|
|
||||||
|
assertEquals(col.size(), 3);
|
||||||
|
|
||||||
|
ICompositeType s = (ICompositeType) col.getName(0).resolveBinding();
|
||||||
|
assertNotNull( s );
|
||||||
|
|
||||||
|
tu = parse("struct s f(void){}", ParserLanguage.C); //$NON-NLS-1$
|
||||||
|
col = new CNameCollector();
|
||||||
|
CVisitor.visitTranslationUnit(tu, col);
|
||||||
|
|
||||||
|
assertEquals(col.size(), 3);
|
||||||
|
|
||||||
|
s = (ICompositeType) col.getName(0).resolveBinding();
|
||||||
|
assertNotNull( s );
|
||||||
|
}
|
||||||
|
|
||||||
public void testBug84250() throws Exception {
|
public void testBug84250() throws Exception {
|
||||||
assertTrue( ((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) parse( "void f() { int (*p) [2]; }", ParserLanguage.C ).getDeclarations()[0]).getBody()).getStatements()[0]).getDeclaration() instanceof IASTSimpleDeclaration ); //$NON-NLS-1$
|
assertTrue( ((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) parse( "void f() { int (*p) [2]; }", ParserLanguage.C ).getDeclarations()[0]).getBody()).getStatements()[0]).getDeclaration() instanceof IASTSimpleDeclaration ); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
|
@ -1652,7 +1652,7 @@ public class CompleteParser2Tests extends TestCase {
|
||||||
|
|
||||||
assertEquals( col.size(), 2 );
|
assertEquals( col.size(), 2 );
|
||||||
|
|
||||||
IProblemBinding blah = (IProblemBinding) col.getName(0).resolveBinding();
|
ICPPClassType blah = (ICPPClassType) col.getName(0).resolveBinding();
|
||||||
ITypedef sb = (ITypedef) col.getName(1).resolveBinding();
|
ITypedef sb = (ITypedef) col.getName(1).resolveBinding();
|
||||||
assertSame( sb.getType(), blah );
|
assertSame( sb.getType(), blah );
|
||||||
}
|
}
|
||||||
|
|
|
@ -562,30 +562,31 @@ public class CVisitor {
|
||||||
}
|
}
|
||||||
private static IBinding createBinding( ICASTElaboratedTypeSpecifier elabTypeSpec ){
|
private static IBinding createBinding( ICASTElaboratedTypeSpecifier elabTypeSpec ){
|
||||||
IASTNode parent = elabTypeSpec.getParent();
|
IASTNode parent = elabTypeSpec.getParent();
|
||||||
if( parent instanceof IASTSimpleDeclaration ){
|
if( parent instanceof IASTDeclaration ){
|
||||||
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) parent;
|
int bits = TAGS;
|
||||||
if( declaration.getDeclarators().length == 0 ){
|
if( parent instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration)parent).getDeclarators().length == 0 ){
|
||||||
//forward declaration
|
bits |= CURRENT_SCOPE;
|
||||||
IBinding binding = resolveBinding( elabTypeSpec, CURRENT_SCOPE | TAGS );
|
}
|
||||||
if( binding == null ){
|
|
||||||
if( elabTypeSpec.getKind() == IASTElaboratedTypeSpecifier.k_enum ){
|
IBinding binding = resolveBinding( elabTypeSpec, bits );
|
||||||
binding = new CEnumeration( elabTypeSpec.getName() );
|
if( binding != null ){
|
||||||
} else {
|
if( binding instanceof CEnumeration ){
|
||||||
binding = new CStructure( elabTypeSpec );
|
((CEnumeration)binding).addDeclaration( elabTypeSpec.getName() );
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
try {
|
if( elabTypeSpec.getKind() == IASTElaboratedTypeSpecifier.k_enum ){
|
||||||
((ICScope) binding.getScope()).addBinding( binding );
|
binding = new CEnumeration( elabTypeSpec.getName() );
|
||||||
} catch ( DOMException e ) {
|
} else {
|
||||||
}
|
binding = new CStructure( elabTypeSpec );
|
||||||
} else {
|
}
|
||||||
if( binding instanceof CEnumeration ){
|
|
||||||
((CEnumeration)binding).addDeclaration( elabTypeSpec.getName() );
|
try {
|
||||||
}
|
((ICScope) binding.getScope()).addBinding( binding );
|
||||||
}
|
} catch ( DOMException e ) {
|
||||||
return binding;
|
}
|
||||||
}
|
}
|
||||||
return resolveBinding( elabTypeSpec, COMPLETE | TAGS );
|
|
||||||
|
return binding;
|
||||||
} else if( parent instanceof IASTTypeId || parent instanceof IASTParameterDeclaration ){
|
} else if( parent instanceof IASTTypeId || parent instanceof IASTParameterDeclaration ){
|
||||||
IASTNode blockItem = getContainingBlockItem( parent );
|
IASTNode blockItem = getContainingBlockItem( parent );
|
||||||
return findBinding( blockItem, elabTypeSpec.getName(), COMPLETE | TAGS );
|
return findBinding( blockItem, elabTypeSpec.getName(), COMPLETE | TAGS );
|
||||||
|
@ -977,7 +978,7 @@ public class CVisitor {
|
||||||
|
|
||||||
public static IScope getContainingScope( IASTDeclSpecifier compTypeSpec ){
|
public static IScope getContainingScope( IASTDeclSpecifier compTypeSpec ){
|
||||||
IASTNode parent = compTypeSpec.getParent();
|
IASTNode parent = compTypeSpec.getParent();
|
||||||
return getContainingScope( (IASTSimpleDeclaration) parent );
|
return getContainingScope( parent );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -241,19 +241,45 @@ public class CPPVisitor {
|
||||||
|
|
||||||
private static IBinding createBinding( ICPPASTElaboratedTypeSpecifier elabType ){
|
private static IBinding createBinding( ICPPASTElaboratedTypeSpecifier elabType ){
|
||||||
IASTNode parent = elabType.getParent();
|
IASTNode parent = elabType.getParent();
|
||||||
|
IBinding binding = null;
|
||||||
|
boolean mustBeSimple = true;
|
||||||
if( parent instanceof IASTSimpleDeclaration ){
|
if( parent instanceof IASTSimpleDeclaration ){
|
||||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)parent).getDeclarators();
|
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)parent).getDeclarators();
|
||||||
if( dtors.length > 0 ){
|
if( dtors.length > 0 ){
|
||||||
return CPPSemantics.resolveBinding( elabType.getName() );
|
binding = CPPSemantics.resolveBinding( elabType.getName() );
|
||||||
|
} else {
|
||||||
|
mustBeSimple = false;
|
||||||
}
|
}
|
||||||
} else if( parent instanceof IASTParameterDeclaration ){
|
} else if( parent instanceof IASTParameterDeclaration ||
|
||||||
return CPPSemantics.resolveBinding( elabType.getName() );
|
parent instanceof IASTDeclaration ||
|
||||||
} else if( parent instanceof IASTTypeId ){
|
parent instanceof IASTTypeId )
|
||||||
return CPPSemantics.resolveBinding( elabType.getName() );
|
{
|
||||||
|
binding = CPPSemantics.resolveBinding( elabType.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( binding != null &&
|
||||||
|
(!(binding instanceof IProblemBinding) ||((IProblemBinding)binding).getID() != IProblemBinding.SEMANTIC_NAME_NOT_FOUND) )
|
||||||
|
{
|
||||||
|
return binding;
|
||||||
|
}
|
||||||
|
|
||||||
|
//7.1.5.3-2 ... If name lookup does not find a declaration for the name, the elaborated-type-specifier is ill-formed
|
||||||
|
//unless it is of the simple form class-key identifier
|
||||||
|
if( mustBeSimple && elabType.getName() instanceof ICPPASTQualifiedName )
|
||||||
|
return binding;
|
||||||
|
|
||||||
ICPPScope scope = (ICPPScope) getContainingScope( elabType );
|
ICPPScope scope = (ICPPScope) getContainingScope( elabType );
|
||||||
IBinding binding;
|
|
||||||
|
if( mustBeSimple ){
|
||||||
|
//3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype scope that contains
|
||||||
|
//the declaration
|
||||||
|
while( scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope ){
|
||||||
|
try {
|
||||||
|
scope = (ICPPScope) scope.getParent();
|
||||||
|
} catch (DOMException e1) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
binding = scope.getBinding( elabType.getName() );
|
binding = scope.getBinding( elabType.getName() );
|
||||||
if( binding == null ){
|
if( binding == null ){
|
||||||
|
|
Loading…
Add table
Reference in a new issue