mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Parameter type adjustment, bug 293538.
This commit is contained in:
parent
a98fd8092a
commit
f28c55fa02
2 changed files with 81 additions and 66 deletions
|
@ -7577,5 +7577,17 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
IASTImplicitNameOwner no= (IASTImplicitNameOwner) stmt.getReturnValue();
|
IASTImplicitNameOwner no= (IASTImplicitNameOwner) stmt.getReturnValue();
|
||||||
assertEquals(0, no.getImplicitNames().length);
|
assertEquals(0, no.getImplicitNames().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typedef int Fixed_Array[20];
|
||||||
|
// void f(const ::Fixed_Array message) {}
|
||||||
|
//
|
||||||
|
// void test() {
|
||||||
|
// int* ptr;
|
||||||
|
// f(ptr);
|
||||||
|
// }
|
||||||
|
public void testParameterAdjustment_293538() throws Exception {
|
||||||
|
final String code = getAboveComment();
|
||||||
|
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -220,15 +220,14 @@ public class SemanticUtil {
|
||||||
t= ((ITypedef) type).getType();
|
t= ((ITypedef) type).getType();
|
||||||
} else if (type instanceof IQualifierType) {
|
} else if (type instanceof IQualifierType) {
|
||||||
final IQualifierType qt = (IQualifierType) type;
|
final IQualifierType qt = (IQualifierType) type;
|
||||||
if (((options & CVQ) != 0)) {
|
final boolean cvq = (options & CVQ) != 0;
|
||||||
t= qt.getType();
|
if (cvq || tdef) {
|
||||||
} else if (tdef) {
|
t= getNestedType(qt.getType(), options);
|
||||||
IType temp= qt.getType();
|
if (!cvq || t instanceof IArrayType || t instanceof ICPPReferenceType) {
|
||||||
if (temp instanceof ITypedef) {
|
t= addQualifiers(t, qt.isConst(), qt.isVolatile());
|
||||||
temp= getNestedType(temp, TDEF);
|
|
||||||
return addQualifiers(temp, qt.isConst(), qt.isVolatile());
|
|
||||||
}
|
}
|
||||||
}
|
return t;
|
||||||
|
}
|
||||||
} else if ((options & ARRAY) != 0 && type instanceof IArrayType) {
|
} else if ((options & ARRAY) != 0 && type instanceof IArrayType) {
|
||||||
t= ((IArrayType) type).getType();
|
t= ((IArrayType) type).getType();
|
||||||
} else if ((options & REF) != 0 && type instanceof ICPPReferenceType) {
|
} else if ((options & REF) != 0 && type instanceof ICPPReferenceType) {
|
||||||
|
@ -245,45 +244,42 @@ public class SemanticUtil {
|
||||||
* Simplifies type by resolving typedefs within the given type.
|
* Simplifies type by resolving typedefs within the given type.
|
||||||
*/
|
*/
|
||||||
static IType getSimplifiedType(IType type) {
|
static IType getSimplifiedType(IType type) {
|
||||||
try {
|
if (type instanceof ICPPFunctionType) {
|
||||||
if (type instanceof ICPPFunctionType) {
|
final ICPPFunctionType ft = (ICPPFunctionType) type;
|
||||||
final ICPPFunctionType ft = (ICPPFunctionType) type;
|
IType ret = null;
|
||||||
IType ret = null;
|
IType[] params = null;
|
||||||
IType[] params = null;
|
final IType r = ft.getReturnType();
|
||||||
final IType r = ft.getReturnType();
|
ret = getSimplifiedType(r);
|
||||||
ret = getSimplifiedType(r);
|
IType[] ps = ft.getParameterTypes();
|
||||||
IType[] ps = ft.getParameterTypes();
|
params = getSimplifiedTypes(ps);
|
||||||
params = getSimplifiedTypes(ps);
|
if (ret == r && params == ps) {
|
||||||
if (ret == r && params == ps) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
return new CPPFunctionType(ret, params, ft.isConst(), ft.isVolatile());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type instanceof ITypedef) {
|
|
||||||
IType t= ((ITypedef) type).getType();
|
|
||||||
if (t != null)
|
|
||||||
return getSimplifiedType(t);
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
if (type instanceof ITypeContainer) {
|
return new CPPFunctionType(ret, params, ft.isConst(), ft.isVolatile());
|
||||||
final ITypeContainer tc = (ITypeContainer) type;
|
}
|
||||||
final IType nestedType= tc.getType();
|
|
||||||
if (nestedType == null)
|
if (type instanceof ITypedef) {
|
||||||
return type;
|
IType t= ((ITypedef) type).getType();
|
||||||
|
if (t != null)
|
||||||
IType newType= getSimplifiedType(nestedType);
|
return getSimplifiedType(t);
|
||||||
if (newType != nestedType) {
|
return type;
|
||||||
return replaceNestedType(tc, newType);
|
}
|
||||||
}
|
if (type instanceof ITypeContainer) {
|
||||||
|
final ITypeContainer tc = (ITypeContainer) type;
|
||||||
|
final IType nestedType= tc.getType();
|
||||||
|
if (nestedType == null)
|
||||||
return type;
|
return type;
|
||||||
|
|
||||||
|
IType newType= getSimplifiedType(nestedType);
|
||||||
|
if (newType != nestedType) {
|
||||||
|
return replaceNestedType(tc, newType);
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
return type;
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IType replaceNestedType(ITypeContainer type, IType newNestedType) throws DOMException {
|
public static IType replaceNestedType(ITypeContainer type, IType newNestedType) {
|
||||||
// bug 249085 make sure not to add unnecessary qualifications
|
// bug 249085 make sure not to add unnecessary qualifications
|
||||||
if (type instanceof IQualifierType) {
|
if (type instanceof IQualifierType) {
|
||||||
IQualifierType qt= (IQualifierType) type;
|
IQualifierType qt= (IQualifierType) type;
|
||||||
|
@ -299,34 +295,31 @@ public class SemanticUtil {
|
||||||
if (!(type instanceof IIndexType))
|
if (!(type instanceof IIndexType))
|
||||||
return type;
|
return type;
|
||||||
|
|
||||||
try {
|
if (type instanceof IFunctionType) {
|
||||||
if (type instanceof IFunctionType) {
|
final ICPPFunctionType ft = (ICPPFunctionType) type;
|
||||||
final ICPPFunctionType ft = (ICPPFunctionType) type;
|
final IType r = ft.getReturnType();
|
||||||
final IType r = ft.getReturnType();
|
final IType ret = mapToAST(r, node);
|
||||||
final IType ret = mapToAST(r, node);
|
if (ret == r) {
|
||||||
if (ret == r) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
return new CPPFunctionType(ret, ft.getParameterTypes(), ft.isConst(), ft.isVolatile());
|
|
||||||
}
|
|
||||||
if (type instanceof ITypeContainer) {
|
|
||||||
final ITypeContainer tc = (ITypeContainer) type;
|
|
||||||
final IType nestedType= tc.getType();
|
|
||||||
if (nestedType == null)
|
|
||||||
return type;
|
|
||||||
|
|
||||||
IType newType= mapToAST(nestedType, node);
|
|
||||||
if (newType != nestedType) {
|
|
||||||
return replaceNestedType(tc, newType);
|
|
||||||
}
|
|
||||||
return type;
|
return type;
|
||||||
} else if (type instanceof ICPPClassType && type instanceof IIndexType) {
|
|
||||||
IASTTranslationUnit tu = node.getTranslationUnit();
|
|
||||||
if (tu instanceof CPPASTTranslationUnit) {
|
|
||||||
return ((CPPASTTranslationUnit) tu).mapToAST((ICPPClassType) type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
return new CPPFunctionType(ret, ft.getParameterTypes(), ft.isConst(), ft.isVolatile());
|
||||||
|
}
|
||||||
|
if (type instanceof ITypeContainer) {
|
||||||
|
final ITypeContainer tc = (ITypeContainer) type;
|
||||||
|
final IType nestedType= tc.getType();
|
||||||
|
if (nestedType == null)
|
||||||
|
return type;
|
||||||
|
|
||||||
|
IType newType= mapToAST(nestedType, node);
|
||||||
|
if (newType != nestedType) {
|
||||||
|
return replaceNestedType(tc, newType);
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
} else if (type instanceof ICPPClassType && type instanceof IIndexType) {
|
||||||
|
IASTTranslationUnit tu = node.getTranslationUnit();
|
||||||
|
if (tu instanceof CPPASTTranslationUnit) {
|
||||||
|
return ((CPPASTTranslationUnit) tu).mapToAST((ICPPClassType) type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
@ -427,7 +420,17 @@ public class SemanticUtil {
|
||||||
return new CPPPointerType(pt.getType(), cnst || pt.isConst(), vol || pt.isVolatile());
|
return new CPPPointerType(pt.getType(), cnst || pt.isConst(), vol || pt.isVolatile());
|
||||||
}
|
}
|
||||||
return baseType;
|
return baseType;
|
||||||
}
|
} else if (baseType instanceof IArrayType) {
|
||||||
|
IArrayType at= (IArrayType) baseType;
|
||||||
|
IType nested= at.getType();
|
||||||
|
IType newNested= addQualifiers(nested, cnst, vol);
|
||||||
|
if (newNested != nested && at instanceof ITypeContainer) {
|
||||||
|
return replaceNestedType((ITypeContainer) at, newNested);
|
||||||
|
}
|
||||||
|
return at;
|
||||||
|
} else if (baseType instanceof ICPPReferenceType) {
|
||||||
|
return baseType;
|
||||||
|
}
|
||||||
|
|
||||||
return new CPPQualifierType(baseType, cnst, vol);
|
return new CPPQualifierType(baseType, cnst, vol);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue