mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Fix for 168189, ptr-to-const-type in parameter list.
This commit is contained in:
parent
01627fb59e
commit
ab07486e81
6 changed files with 99 additions and 89 deletions
|
@ -458,6 +458,18 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
|
||||||
IBinding b0 = getBindingFromASTName("foo();", 3);
|
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
|
// // header
|
||||||
// class Base { public: void foo(int i) {} };
|
// class Base { public: void foo(int i) {} };
|
||||||
// class Derived : public Base { public: void foo(long l) {} };
|
// class Derived : public Base { public: void foo(long l) {} };
|
||||||
|
@ -839,6 +851,34 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
|
||||||
|
|
||||||
// // the header
|
// // 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(int*); // b1
|
||||||
// void f(const int*); // b2
|
// void f(const int*); // b2
|
||||||
// void f(int const*); // b2
|
// void f(int const*); // b2
|
||||||
|
@ -848,10 +888,6 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
|
||||||
//
|
//
|
||||||
// void f(int*){} // b1
|
// void f(int*){} // b1
|
||||||
// void f(const int*){} // b2
|
// 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() {
|
// void ref() {
|
||||||
// int* int_ptr = 0;
|
// int* int_ptr = 0;
|
||||||
|
@ -868,15 +904,9 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
|
||||||
// f(const_int_ptr_const); // b2
|
// f(const_int_ptr_const); // b2
|
||||||
// f(int_const_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);
|
IBinding binding1= getBindingFromASTName("f(int*){}", 1);
|
||||||
assertEquals(2, index.findNames(binding1, IIndex.FIND_DECLARATIONS).length);
|
|
||||||
IBinding binding2= getBindingFromASTName("f(const int*){}", 1);
|
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(binding1, getBindingFromASTName("f(int_ptr)", 1));
|
||||||
assertEquals(binding2, getBindingFromASTName("f(const_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(const_int_ptr_const)", 1));
|
||||||
assertEquals(binding2, getBindingFromASTName("f(int_const_ptr_const)", 1));
|
assertEquals(binding2, getBindingFromASTName("f(int_const_ptr_const)", 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// // the header
|
// // the header
|
||||||
// void f(int*); // b1
|
// void f(int*); // b1
|
||||||
// void f(const int*); // b2
|
// void f(const int*); // b2
|
||||||
|
@ -897,10 +927,6 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
|
||||||
// #include "header.h"
|
// #include "header.h"
|
||||||
// void f(int*){} // b1
|
// void f(int*){} // b1
|
||||||
// void f(const int*){} // b2
|
// 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() {
|
// void ref() {
|
||||||
// int* int_ptr = 0;
|
// int* int_ptr = 0;
|
||||||
|
@ -917,15 +943,9 @@ public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBas
|
||||||
// f(const_int_ptr_const); // b2
|
// f(const_int_ptr_const); // b2
|
||||||
// f(int_const_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);
|
IBinding binding1= getBindingFromASTName("f(int*){}", 1);
|
||||||
assertEquals(2, index.findNames(binding1, IIndex.FIND_DECLARATIONS).length);
|
|
||||||
IBinding binding2= getBindingFromASTName("f(const int*){}", 1);
|
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(binding1, getBindingFromASTName("f(int_ptr)", 1));
|
||||||
assertEquals(binding2, getBindingFromASTName("f(const_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(binding1, getBindingFromASTName("f(int_ptr_const)", 1));
|
||||||
assertEquals(binding2, getBindingFromASTName("f(const_int_ptr_const)", 1));
|
assertEquals(binding2, getBindingFromASTName("f(const_int_ptr_const)", 1));
|
||||||
assertEquals(binding2, getBindingFromASTName("f(int_const_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,8 @@ public class TestSourceReader {
|
||||||
contents.remove(0);
|
contents.remove(0);
|
||||||
content = new StringBuffer();
|
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()]);
|
return (StringBuffer[]) contents.toArray(new StringBuffer[contents.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1916,15 +1916,22 @@ public class CPPSemantics {
|
||||||
for( int i = 0; i < items.length && items[i] != null; i++ ){
|
for( int i = 0; i < items.length && items[i] != null; i++ ){
|
||||||
Object o = items[i];
|
Object o = items[i];
|
||||||
boolean declaredBefore = declaredBefore( o, name );
|
boolean declaredBefore = declaredBefore( o, name );
|
||||||
if( !data.checkWholeClassScope && !declaredBefore )
|
boolean checkResolvedNamesOnly= false;
|
||||||
continue;
|
if( !data.checkWholeClassScope && !declaredBefore) {
|
||||||
|
if (!name.isReference()) {
|
||||||
|
checkResolvedNamesOnly= true;
|
||||||
|
declaredBefore= true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if( o instanceof IASTName ){
|
if( o instanceof IASTName ){
|
||||||
temp = ((IASTName) o).resolveBinding();
|
IASTName on= (IASTName) o;
|
||||||
|
temp = checkResolvedNamesOnly ? on.getBinding() : on.resolveBinding();
|
||||||
if( temp == null )
|
if( temp == null )
|
||||||
continue;
|
continue;
|
||||||
} else if( o instanceof IBinding ){
|
} else if( o instanceof IBinding ){
|
||||||
temp = (IBinding) o;
|
temp = (IBinding) o;
|
||||||
|
|
||||||
} else
|
} else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -1382,56 +1382,28 @@ public class CPPVisitor {
|
||||||
for( int i = 0; i < parameters.length; i++ ){
|
for( int i = 0; i < parameters.length; i++ ){
|
||||||
try {
|
try {
|
||||||
pt = parameters[i].getType();
|
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 ) {
|
} catch ( DOMException e ) {
|
||||||
pt = e.getProblem();
|
pt = e.getProblem();
|
||||||
}
|
}
|
||||||
|
|
||||||
IType [] temp = new IType[] { (IType) pt.clone() };
|
pTypes[i] = pt;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CPPFunctionType( returnType, pTypes );
|
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();
|
IASTParameterDeclaration [] params = fnDtor.getParameters();
|
||||||
IType [] pTypes = new IType [ params.length ];
|
IType [] pTypes = new IType [ params.length ];
|
||||||
IType pt = null;
|
IType pt = null;
|
||||||
|
@ -1439,23 +1411,28 @@ public class CPPVisitor {
|
||||||
for( int i = 0; i < params.length; i++ ){
|
for( int i = 0; i < params.length; i++ ){
|
||||||
IASTDeclSpecifier pDeclSpec = params[i].getDeclSpecifier();
|
IASTDeclSpecifier pDeclSpec = params[i].getDeclSpecifier();
|
||||||
IASTDeclarator pDtor = params[i].getDeclarator();
|
IASTDeclarator pDtor = params[i].getDeclarator();
|
||||||
|
pt = createType( pDeclSpec );
|
||||||
|
pt = createType( pt, pDtor );
|
||||||
|
|
||||||
//8.3.5-3
|
//8.3.5-3
|
||||||
//Any cv-qualifier modifying a parameter type is deleted.
|
//Any cv-qualifier modifying a parameter type is deleted.
|
||||||
//so only create the base type from the declspec and not the qualifiers
|
//so only create the base type from the declspec and not the qualifiers
|
||||||
pt = getBaseType( pDeclSpec );
|
try {
|
||||||
|
if (pt instanceof IQualifierType) {
|
||||||
pt = createType( pt, pDtor );
|
pt= ((IQualifierType) pt).getType();
|
||||||
|
}
|
||||||
//any parameter of type array of T is adjusted to be pointer to T
|
if (pt instanceof CPPPointerType) {
|
||||||
if( pt instanceof IArrayType ){
|
pt= ((CPPPointerType) pt).stripQualifiers();
|
||||||
IArrayType at = (IArrayType) pt;
|
}
|
||||||
try {
|
//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() );
|
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
|
//any parameter to type function returning T is adjusted to be pointer to function
|
||||||
if( pt instanceof IFunctionType ){
|
if( pt instanceof IFunctionType ){
|
||||||
pt = new CPPPointerType( pt );
|
pt = new CPPPointerType( pt );
|
||||||
|
|
|
@ -81,7 +81,8 @@ class PDOMCPPFunction extends PDOMCPPBinding implements IIndexType, ICPPFunction
|
||||||
Database db = pdom.getDB();
|
Database db = pdom.getDB();
|
||||||
IBinding binding = function;
|
IBinding binding = function;
|
||||||
try {
|
try {
|
||||||
IType rt= function.getType().getReturnType();
|
IFunctionType ft= function.getType();
|
||||||
|
IType rt= ft.getReturnType();
|
||||||
if (rt != null) {
|
if (rt != null) {
|
||||||
PDOMNode typeNode = getLinkageImpl().addType(this, rt);
|
PDOMNode typeNode = getLinkageImpl().addType(this, rt);
|
||||||
if (typeNode != null) {
|
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);
|
db.putInt(record + NUM_PARAMS, params.length);
|
||||||
|
|
||||||
for (int i=0; i<params.length; ++i) {
|
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));
|
db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(binding));
|
||||||
IFunctionType ftype = function.getType();
|
IFunctionType ftype = function.getType();
|
||||||
|
|
|
@ -65,7 +65,7 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
|
||||||
super(pdom, record);
|
super(pdom, record);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMCPPParameter(PDOM pdom, PDOMNode parent, IParameter param)
|
public PDOMCPPParameter(PDOM pdom, PDOMNode parent, IParameter param, IType type)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
super(pdom, parent, param.getNameCharArray());
|
super(pdom, parent, param.getNameCharArray());
|
||||||
|
|
||||||
|
@ -76,9 +76,8 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
|
||||||
db.putByte(record + FLAGS, flags);
|
db.putByte(record + FLAGS, flags);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IType type = param.getType();
|
if (type == null)
|
||||||
while(type instanceof ITypedef)
|
type= param.getType();
|
||||||
type = ((ITypedef)type).getType();
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
PDOMNode typeNode = getLinkageImpl().addType(this, type);
|
PDOMNode typeNode = getLinkageImpl().addType(this, type);
|
||||||
db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);
|
db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);
|
||||||
|
|
Loading…
Add table
Reference in a new issue