diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java index 46c1c670932..95666bb1e7e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexCPPBindingResolutionTest.java @@ -458,6 +458,18 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas IBinding b0 = getBindingFromASTName("foo();", 3); } + // // the header + // typedef int TYPE; + // namespace ns { + // const TYPE* foo(int a); + // }; + + // #include "header.h" + // const TYPE* ns::foo(int a) { return 0; } + public void testTypeQualifier() { + IBinding b0 = getBindingFromASTName("foo(", 3); + } + // // header // class Base { public: void foo(int i) {} }; // class Derived : public Base { public: void foo(long l) {} }; @@ -839,6 +851,34 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // // the header + // void f(int*){} // b1 + // void f(const int*){} // b2 + // void f(int const*){} // b2, redef + // void f(int *const){} // b1, redef + // void f(const int*const){} // b2, redef + // void f(int const*const){} // b2, redef + public void testConstIntPtrParameterInDefinitionAST() throws CoreException { + IBinding binding1= getBindingFromASTName("f(int*){}", 1); + IBinding binding2= getBindingFromASTName("f(const int*){}", 1); + getProblemFromASTName("f(int const*){}", 1); + getProblemFromASTName("f(int *const){}", 1); + getProblemFromASTName("f(const int*const){}", 1); + getProblemFromASTName("f(int const*const){}", 1); + } + + // // the header + + // void f(int&){} // b1 + // void f(const int&){} // b2 + // void f(int const&){} // b2, redef + public void testConstIntRefParameterInDefinitionAST() throws CoreException { + IBinding binding1= getBindingFromASTName("f(int&){}", 1); + IBinding binding2= getBindingFromASTName("f(const int&){}", 1); + getProblemFromASTName("f(int const&){}", 1); + } + + // // the header + // void f(int*); // b1 // void f(const int*); // b2 // void f(int const*); // b2 @@ -848,10 +888,6 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // // void f(int*){} // b1 // void f(const int*){} // b2 - // void f(int const*){} // b2, redef - // void f(int *const){} // b1, redef - // void f(const int*const){} // b2, redef - // void f(int const*const){} // b2, redef // // void ref() { // int* int_ptr = 0; @@ -868,15 +904,9 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // f(const_int_ptr_const); // b2 // f(int_const_ptr_const); // b2 // } - public void _testConstIntPtrParameterInDefinitionAST() throws CoreException { + public void testConstIntPtrParameterInDefinitionAST2() throws CoreException { IBinding binding1= getBindingFromASTName("f(int*){}", 1); - assertEquals(2, index.findNames(binding1, IIndex.FIND_DECLARATIONS).length); IBinding binding2= getBindingFromASTName("f(const int*){}", 1); - assertEquals(4, index.findNames(binding2, IIndex.FIND_DECLARATIONS).length); - getProblemFromASTName("f(int const*){}", 1); - getProblemFromASTName("f(int *const){}", 1); - getProblemFromASTName("f(const int*const){}", 1); - getProblemFromASTName("f(int const*const){}", 1); assertEquals(binding1, getBindingFromASTName("f(int_ptr)", 1)); assertEquals(binding2, getBindingFromASTName("f(const_int_ptr)", 1)); @@ -885,7 +915,7 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas assertEquals(binding2, getBindingFromASTName("f(const_int_ptr_const)", 1)); assertEquals(binding2, getBindingFromASTName("f(int_const_ptr_const)", 1)); } - + // // the header // void f(int*); // b1 // void f(const int*); // b2 @@ -897,10 +927,6 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // #include "header.h" // void f(int*){} // b1 // void f(const int*){} // b2 - // void f(int const*){} // b2, redef - // void f(int *const){} // b1, redef - // void f(const int*const){} // b2, redef - // void f(int const*const){} // b2, redef // // void ref() { // int* int_ptr = 0; @@ -917,15 +943,9 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas // f(const_int_ptr_const); // b2 // f(int_const_ptr_const); // b2 // } - public void _testConstIntPtrParameterInDefinition() throws CoreException { + public void testConstIntPtrParameterInDefinition() throws CoreException { IBinding binding1= getBindingFromASTName("f(int*){}", 1); - assertEquals(2, index.findNames(binding1, IIndex.FIND_DECLARATIONS).length); IBinding binding2= getBindingFromASTName("f(const int*){}", 1); - assertEquals(4, index.findNames(binding2, IIndex.FIND_DECLARATIONS).length); - getProblemFromASTName("f(int const*){}", 1); - getProblemFromASTName("f(int *const){}", 1); - getProblemFromASTName("f(const int*const){}", 1); - getProblemFromASTName("f(int const*const){}", 1); assertEquals(binding1, getBindingFromASTName("f(int_ptr)", 1)); assertEquals(binding2, getBindingFromASTName("f(const_int_ptr)", 1)); @@ -933,6 +953,9 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas assertEquals(binding1, getBindingFromASTName("f(int_ptr_const)", 1)); assertEquals(binding2, getBindingFromASTName("f(const_int_ptr_const)", 1)); assertEquals(binding2, getBindingFromASTName("f(int_const_ptr_const)", 1)); + + assertEquals(2, index.findNames(binding1, IIndex.FIND_DECLARATIONS).length); + assertEquals(4, index.findNames(binding2, IIndex.FIND_DECLARATIONS).length); } } diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java index d625cfa7d2f..243bf91a3d4 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java @@ -83,7 +83,8 @@ public class TestSourceReader { contents.remove(0); content = new StringBuffer(); } - if(line.indexOf(testName) != -1) { + int idx= line.indexOf(testName); + if( idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx+testName.length()))) { return (StringBuffer[]) contents.toArray(new StringBuffer[contents.size()]); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index 5363efada8c..d5074a949e6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -1916,15 +1916,22 @@ public class CPPSemantics { for( int i = 0; i < items.length && items[i] != null; i++ ){ Object o = items[i]; boolean declaredBefore = declaredBefore( o, name ); - if( !data.checkWholeClassScope && !declaredBefore ) - continue; + boolean checkResolvedNamesOnly= false; + if( !data.checkWholeClassScope && !declaredBefore) { + if (!name.isReference()) { + checkResolvedNamesOnly= true; + declaredBefore= true; + } + else + continue; + } if( o instanceof IASTName ){ - temp = ((IASTName) o).resolveBinding(); + IASTName on= (IASTName) o; + temp = checkResolvedNamesOnly ? on.getBinding() : on.resolveBinding(); if( temp == null ) continue; } else if( o instanceof IBinding ){ temp = (IBinding) o; - } else continue; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index ef53b6b1f3a..41ae1d7facd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -1382,56 +1382,28 @@ public class CPPVisitor { for( int i = 0; i < parameters.length; i++ ){ try { pt = parameters[i].getType(); + + // remove qualifiers + if (pt instanceof IQualifierType) { + pt= ((IQualifierType) pt).getType(); + } + + if( pt instanceof IArrayType ){ + pt = new CPPPointerType( ((IArrayType) pt).getType() ); + } else if( pt instanceof IFunctionType ){ + pt = new CPPPointerType( pt ); + } } catch ( DOMException e ) { pt = e.getProblem(); } - IType [] temp = new IType[] { (IType) pt.clone() }; - int lastIdx = 0; - while( pt instanceof ITypeContainer){ - try { - pt = ((ITypeContainer)pt).getType(); - } catch ( DOMException e1 ) { - pt = e1.getProblem(); - } - if( pt instanceof ITypeContainer && !(pt instanceof ITypedef) ){ - IType t = (IType) pt.clone(); - ((ITypeContainer) temp[ lastIdx ]).setType( t ); - temp = (IType[]) ArrayUtil.append( IType.class, temp, t ); - lastIdx++; - } else { - temp = (IType[]) ArrayUtil.append( IType.class, temp, pt ); - lastIdx++; - break; - } - } - - if( lastIdx > 0 && temp[ lastIdx - 1 ] instanceof IQualifierType ){ - temp[lastIdx - 1] = temp[lastIdx--]; - if( lastIdx > 0 ){ - ITypeContainer cont = (ITypeContainer) temp[ lastIdx - 1 ]; - cont.setType( temp[ lastIdx ] ); - } - } - - IType lastType = temp[ 0 ]; - if( lastType instanceof IArrayType ){ - try { - lastType = new CPPPointerType( ((IArrayType) lastType).getType() ); - } catch ( DOMException e1 ) { - lastType = e1.getProblem(); - } - } else if( lastType instanceof IFunctionType ){ - lastType = new CPPPointerType( lastType ); - } - - pTypes[i] = lastType; + pTypes[i] = pt; } return new CPPFunctionType( returnType, pTypes ); } - private static IType createType( IType returnType, ICPPASTFunctionDeclarator fnDtor ){ + private static IType createType( IType returnType, ICPPASTFunctionDeclarator fnDtor ) { IASTParameterDeclaration [] params = fnDtor.getParameters(); IType [] pTypes = new IType [ params.length ]; IType pt = null; @@ -1439,23 +1411,28 @@ public class CPPVisitor { for( int i = 0; i < params.length; i++ ){ IASTDeclSpecifier pDeclSpec = params[i].getDeclSpecifier(); IASTDeclarator pDtor = params[i].getDeclarator(); + pt = createType( pDeclSpec ); + pt = createType( pt, pDtor ); + //8.3.5-3 //Any cv-qualifier modifying a parameter type is deleted. //so only create the base type from the declspec and not the qualifiers - pt = getBaseType( pDeclSpec ); - - pt = createType( pt, pDtor ); - - //any parameter of type array of T is adjusted to be pointer to T - if( pt instanceof IArrayType ){ - IArrayType at = (IArrayType) pt; - try { + try { + if (pt instanceof IQualifierType) { + pt= ((IQualifierType) pt).getType(); + } + if (pt instanceof CPPPointerType) { + pt= ((CPPPointerType) pt).stripQualifiers(); + } + //any parameter of type array of T is adjusted to be pointer to T + if( pt instanceof IArrayType ){ + IArrayType at = (IArrayType) pt; pt = new CPPPointerType( at.getType() ); - } catch ( DOMException e ) { - pt = e.getProblem(); - } - } - + } + } catch ( DOMException e ) { + pt = e.getProblem(); + } + //any parameter to type function returning T is adjusted to be pointer to function if( pt instanceof IFunctionType ){ pt = new CPPPointerType( pt ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java index 4d4236900c7..15656be9f93 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java @@ -81,7 +81,8 @@ class PDOMCPPFunction extends PDOMCPPBinding implements IIndexType, ICPPFunction Database db = pdom.getDB(); IBinding binding = function; try { - IType rt= function.getType().getReturnType(); + IFunctionType ft= function.getType(); + IType rt= ft.getReturnType(); if (rt != null) { PDOMNode typeNode = getLinkageImpl().addType(this, rt); if (typeNode != null) { @@ -89,11 +90,13 @@ class PDOMCPPFunction extends PDOMCPPBinding implements IIndexType, ICPPFunction } } - IParameter[] params = function.getParameters(); + IParameter[] params= function.getParameters(); + IType[] paramTypes= ft.getParameterTypes(); db.putInt(record + NUM_PARAMS, params.length); for (int i=0; i