1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-06 15:55:47 +02:00

fix bug 84185

This commit is contained in:
Andrew Niefer 2005-02-02 19:18:41 +00:00
parent 9801ce2900
commit 71309151e2
5 changed files with 101 additions and 10 deletions

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
@ -971,5 +972,45 @@ public class AST2CPPTests extends AST2BaseTest {
assertInstances( col, A, 4 ); assertInstances( col, A, 4 );
assertInstances( col, x, 3 ); assertInstances( col, x, 3 );
} }
public void _testBug84250() throws Exception{
StringBuffer buffer = new StringBuffer();
buffer.append("void f() { \n"); //$NON-NLS-1$
buffer.append(" int ( *p ) [2]; \n"); //$NON-NLS-1$
buffer.append(" (&p)[0] = 1; \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
CPPNameCollector col = new CPPNameCollector();
CPPVisitor.visitTranslationUnit(tu, col);
assertEquals(col.size(), 3);
IVariable p = (IVariable) col.getName(1).resolveBinding();
assertTrue( p.getType() instanceof IPointerType );
assertTrue( ((IPointerType)p.getType()).getType() instanceof IArrayType );
IArrayType at = (IArrayType) ((IPointerType)p.getType()).getType();
assertTrue( at.getType() instanceof IBasicType );
assertInstances( col, p, 2 );
}
public void _testBug84250_2() throws Exception{
StringBuffer buffer = new StringBuffer();
buffer.append("void f() { \n"); //$NON-NLS-1$
buffer.append(" int ( *p ) [2]; \n"); //$NON-NLS-1$
buffer.append(" (&p)[0] = 1; \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
CPPNameCollector col = new CPPNameCollector();
CPPVisitor.visitTranslationUnit(tu, col);
assertEquals(col.size(), 3);
IVariable p_ref = (IVariable) col.getName(2).resolveBinding();
IVariable p_decl = (IVariable) col.getName(1).resolveBinding();
assertSame( p_ref, p_decl );
}
} }

View file

@ -2620,6 +2620,45 @@ public class AST2Tests extends AST2BaseTest {
assertInstances( col, e, 2 ); assertInstances( col, e, 2 );
} }
public void testBug84185() throws Exception{
StringBuffer buffer = new StringBuffer();
buffer.append("void f() { \n"); //$NON-NLS-1$
buffer.append(" int ( *p ) [2]; \n"); //$NON-NLS-1$
buffer.append(" (&p)[0] = 1; \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector col = new CNameCollector();
CVisitor.visitTranslationUnit(tu, col);
assertEquals(col.size(), 3);
IVariable p = (IVariable) col.getName(1).resolveBinding();
assertTrue( p.getType() instanceof IPointerType );
assertTrue( ((IPointerType)p.getType()).getType() instanceof IArrayType );
IArrayType at = (IArrayType) ((IPointerType)p.getType()).getType();
assertTrue( at.getType() instanceof IBasicType );
assertInstances( col, p, 2 );
}
public void testBug84185_2() throws Exception{
StringBuffer buffer = new StringBuffer();
buffer.append("void f() { \n"); //$NON-NLS-1$
buffer.append(" int ( *p ) [2]; \n"); //$NON-NLS-1$
buffer.append(" (&p)[0] = 1; \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector col = new CNameCollector();
CVisitor.visitTranslationUnit(tu, col);
assertEquals(col.size(), 3);
IVariable p_ref = (IVariable) col.getName(2).resolveBinding();
IVariable p_decl = (IVariable) col.getName(1).resolveBinding();
assertSame( p_ref, p_decl );
}
public void testBug84176() throws Exception { public void testBug84176() throws Exception {
StringBuffer buffer = new StringBuffer( "// example from: C99 6.5.2.5-16\n" ); //$NON-NLS-1$ StringBuffer buffer = new StringBuffer( "// example from: C99 6.5.2.5-16\n" ); //$NON-NLS-1$
buffer.append( "struct s { int i; };\n"); //$NON-NLS-1$ buffer.append( "struct s { int i; };\n"); //$NON-NLS-1$

View file

@ -1631,8 +1631,8 @@ public class CompleteParser2Tests extends TestCase {
CPPNameCollector col = new CPPNameCollector(); CPPNameCollector col = new CPPNameCollector();
CPPVisitor.visitTranslationUnit( tu, col ); CPPVisitor.visitTranslationUnit( tu, col );
assertEquals( col.size(), 5 ); assertEquals( col.size(), 4 );
ICPPField pfi = (ICPPField)col.getName(3).resolveBinding(); ICPPField pfi = (ICPPField)col.getName(2).resolveBinding();
assertNotNull( pfi ); assertNotNull( pfi );
assertTrue( pfi.getType() instanceof IPointerType ); assertTrue( pfi.getType() instanceof IPointerType );

View file

@ -703,7 +703,7 @@ public class CVisitor {
} }
} }
} }
} else if ( parent instanceof IASTFunctionDeclarator ) { } else if ( parent instanceof IASTDeclarator ) {
binding = createBinding(declarator); binding = createBinding(declarator);
} }
@ -1159,6 +1159,9 @@ public class CVisitor {
IASTDeclarator [] declarators = simpleDeclaration.getDeclarators(); IASTDeclarator [] declarators = simpleDeclaration.getDeclarators();
for( int i = 0; i < declarators.length; i++ ){ for( int i = 0; i < declarators.length; i++ ){
IASTDeclarator declarator = declarators[i]; IASTDeclarator declarator = declarators[i];
while( declarator.getNestedDeclarator() != null ){
declarator = declarator.getNestedDeclarator();
}
tempName = declarator.getName(); tempName = declarator.getName();
if( CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){ if( CharArrayUtils.equals( tempName.toCharArray(), name.toCharArray() ) ){
return tempName.resolveBinding(); return tempName.resolveBinding();
@ -1351,7 +1354,10 @@ public class CVisitor {
} }
} }
if( declarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR ){ //having a nested declarator implies that the name on this declarator is empty
if( declarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR &&
declarator.getNestedDeclarator() == null )
{
if( !visitName( declarator.getName(), action ) ) return false; if( !visitName( declarator.getName(), action ) ) return false;
} }
@ -1652,8 +1658,8 @@ public class CVisitor {
return lastType; return lastType;
// if it's a function declarator then use recursion to get the parent's type // if it's a declarator then use recursion to get the parent's type
} else if (declarator.getParent() instanceof IASTFunctionDeclarator) { } else if (declarator.getParent() instanceof IASTDeclarator) {
IASTDeclarator origDecltor = (IASTDeclarator)declarator.getParent(); IASTDeclarator origDecltor = (IASTDeclarator)declarator.getParent();
IType lastType = createType(origDecltor.getName(), isParm); // use recursion to get the type of the IASTDeclarator's parent IType lastType = createType(origDecltor.getName(), isParm); // use recursion to get the type of the IASTDeclarator's parent
@ -1667,7 +1673,7 @@ public class CVisitor {
lastType = new CFunctionType(lastType, getParmTypes((IASTFunctionDeclarator)declarator)); lastType = new CFunctionType(lastType, getParmTypes((IASTFunctionDeclarator)declarator));
// if it was a function declarator and its parent is not a function definition then do cleanup from the recursion here (setup pointers/arrays/ and check if need function type) // if it was a declarator and its parent is not a function definition then do cleanup from the recursion here (setup pointers/arrays/ and check if need function type)
} else { } else {
if (declarator.getPointerOperators() != IASTDeclarator.EMPTY_DECLARATOR_ARRAY) if (declarator.getPointerOperators() != IASTDeclarator.EMPTY_DECLARATOR_ARRAY)
lastType = setupPointerChain(declarator.getPointerOperators(), lastType); lastType = setupPointerChain(declarator.getPointerOperators(), lastType);

View file

@ -367,8 +367,11 @@ public class CPPVisitor {
} else if( parent instanceof IASTParameterDeclaration ){ } else if( parent instanceof IASTParameterDeclaration ){
IASTParameterDeclaration param = (IASTParameterDeclaration) parent; IASTParameterDeclaration param = (IASTParameterDeclaration) parent;
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent(); IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
IFunction function = (IFunction) fDtor.getName().resolveBinding(); IBinding temp = fDtor.getName().resolveBinding();
binding = ((CPPFunction) function).resolveParameter( param ); if( temp instanceof IFunction ){
CPPFunction function = (CPPFunction) temp;
binding = function.resolveParameter( param );
}
} else if( parent instanceof IASTSimpleDeclaration ){ } else if( parent instanceof IASTSimpleDeclaration ){
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent; IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent;
if( simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){ if( simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){
@ -898,7 +901,9 @@ public class CPPVisitor {
} }
} }
if( declarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR ){ if( declarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR &&
declarator.getNestedDeclarator() == null )
{
if( !visitName( declarator.getName(), action ) ) return false; if( !visitName( declarator.getName(), action ) ) return false;
} }