1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-30 21:55:31 +02:00

Fix for 168189, ptr-to-const-type in parameter list.

This commit is contained in:
Markus Schorn 2006-12-15 16:44:57 +00:00
parent 01627fb59e
commit ab07486e81
6 changed files with 99 additions and 89 deletions

View file

@ -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);
}
}

View file

@ -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()]);
}
}

View file

@ -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;

View file

@ -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 );

View file

@ -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<params.length; ++i) {
setFirstParameter(new PDOMCPPParameter(pdom, this, params[i]));
IType pt= i<paramTypes.length ? paramTypes[i] : null;
setFirstParameter(new PDOMCPPParameter(pdom, this, params[i], pt));
}
db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(binding));
IFunctionType ftype = function.getType();

View file

@ -65,7 +65,7 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
super(pdom, record);
}
public PDOMCPPParameter(PDOM pdom, PDOMNode parent, IParameter param)
public PDOMCPPParameter(PDOM pdom, PDOMNode parent, IParameter param, IType type)
throws CoreException {
super(pdom, parent, param.getNameCharArray());
@ -76,9 +76,8 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
db.putByte(record + FLAGS, flags);
try {
IType type = param.getType();
while(type instanceof ITypedef)
type = ((ITypedef)type).getType();
if (type == null)
type= param.getType();
if (type != null) {
PDOMNode typeNode = getLinkageImpl().addType(this, type);
db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);