mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-08 16:55:38 +02:00
fixing bug 84186
This commit is contained in:
parent
ec6276d5dd
commit
10a5054abe
3 changed files with 57 additions and 4 deletions
|
@ -2718,4 +2718,27 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
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$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug84186() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "struct s1 { struct s2 *s2p; /* ... */ }; // D1 \n"); //$NON-NLS-1$
|
||||||
|
buffer.append( "struct s2 { struct s1 *s1p; /* ... */ }; // D2 \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||||
|
CNameCollector col = new CNameCollector();
|
||||||
|
CVisitor.visitTranslationUnit(tu, col);
|
||||||
|
|
||||||
|
assertEquals(col.size(), 6);
|
||||||
|
|
||||||
|
ICompositeType s_ref = (ICompositeType) col.getName(1).resolveBinding();
|
||||||
|
ICompositeType s_decl = (ICompositeType) col.getName(3).resolveBinding();
|
||||||
|
|
||||||
|
assertSame( s_ref, s_decl );
|
||||||
|
CVisitor.clearBindings( tu );
|
||||||
|
|
||||||
|
s_decl = (ICompositeType) col.getName(3).resolveBinding();
|
||||||
|
s_ref = (ICompositeType) col.getName(1).resolveBinding();
|
||||||
|
|
||||||
|
assertSame( s_ref, s_decl );
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
@ -26,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created on Nov 8, 2004
|
* Created on Nov 8, 2004
|
||||||
|
@ -75,9 +77,13 @@ public class CStructure implements ICompositeType, ICBinding {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||||
*/
|
*/
|
||||||
public IScope getScope() {
|
public IScope getScope() throws DOMException {
|
||||||
IASTDeclSpecifier declSpec = (IASTDeclSpecifier) ( ( definition != null ) ? (IASTNode)definition : declarations[0] );
|
IASTDeclSpecifier declSpec = (IASTDeclSpecifier) ( ( definition != null ) ? (IASTNode)definition : declarations[0] );
|
||||||
return CVisitor.getContainingScope( declSpec );
|
IScope scope = CVisitor.getContainingScope( declSpec );
|
||||||
|
while( scope instanceof ICCompositeTypeScope ){
|
||||||
|
scope = scope.getParent();
|
||||||
|
}
|
||||||
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -168,4 +174,12 @@ public class CStructure implements ICompositeType, ICBinding {
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param compositeTypeSpec
|
||||||
|
*/
|
||||||
|
public void addDefinition(ICASTCompositeTypeSpecifier compositeTypeSpec) {
|
||||||
|
definition = compositeTypeSpec;
|
||||||
|
((CASTName)compositeTypeSpec.getName()).setBinding( this );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
|
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICScope;
|
import org.eclipse.cdt.core.dom.ast.c.ICScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||||
|
@ -770,8 +771,23 @@ public class CVisitor {
|
||||||
|
|
||||||
|
|
||||||
private static IBinding createBinding( ICASTCompositeTypeSpecifier compositeTypeSpec ){
|
private static IBinding createBinding( ICASTCompositeTypeSpecifier compositeTypeSpec ){
|
||||||
ICompositeType binding = new CStructure( compositeTypeSpec );
|
ICScope scope = null;
|
||||||
ICScope scope;
|
IBinding binding = null;
|
||||||
|
try {
|
||||||
|
scope = (ICScope) getContainingScope( compositeTypeSpec );
|
||||||
|
while( scope instanceof ICCompositeTypeScope )
|
||||||
|
scope = (ICScope) scope.getParent();
|
||||||
|
|
||||||
|
binding = scope.getBinding( ICScope.NAMESPACE_TYPE_TAG, compositeTypeSpec.getName().toCharArray() );
|
||||||
|
if( binding != null ){
|
||||||
|
((CStructure)binding).addDefinition( compositeTypeSpec );
|
||||||
|
return binding;
|
||||||
|
}
|
||||||
|
} catch (DOMException e2) {
|
||||||
|
}
|
||||||
|
|
||||||
|
binding = new CStructure( compositeTypeSpec );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
scope = (ICScope) binding.getScope();
|
scope = (ICScope) binding.getScope();
|
||||||
scope.addBinding( binding );
|
scope.addBinding( binding );
|
||||||
|
|
Loading…
Add table
Reference in a new issue