From f28c55fa028c0cbda3e93404fb8827015e57b4dd Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 28 Oct 2009 09:26:05 +0000 Subject: [PATCH] Parameter type adjustment, bug 293538. --- .../core/parser/tests/ast2/AST2CPPTests.java | 12 ++ .../parser/cpp/semantics/SemanticUtil.java | 135 +++++++++--------- 2 files changed, 81 insertions(+), 66 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index b63d06ec1f1..e0cb9b1cd3e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -7577,5 +7577,17 @@ public class AST2CPPTests extends AST2BaseTest { IASTImplicitNameOwner no= (IASTImplicitNameOwner) stmt.getReturnValue(); 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); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index 4ea1d023018..8b7d85e51b2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -220,15 +220,14 @@ public class SemanticUtil { t= ((ITypedef) type).getType(); } else if (type instanceof IQualifierType) { final IQualifierType qt = (IQualifierType) type; - if (((options & CVQ) != 0)) { - t= qt.getType(); - } else if (tdef) { - IType temp= qt.getType(); - if (temp instanceof ITypedef) { - temp= getNestedType(temp, TDEF); - return addQualifiers(temp, qt.isConst(), qt.isVolatile()); + final boolean cvq = (options & CVQ) != 0; + if (cvq || tdef) { + t= getNestedType(qt.getType(), options); + if (!cvq || t instanceof IArrayType || t instanceof ICPPReferenceType) { + t= addQualifiers(t, qt.isConst(), qt.isVolatile()); } - } + return t; + } } else if ((options & ARRAY) != 0 && type instanceof IArrayType) { t= ((IArrayType) type).getType(); } else if ((options & REF) != 0 && type instanceof ICPPReferenceType) { @@ -245,45 +244,42 @@ public class SemanticUtil { * Simplifies type by resolving typedefs within the given type. */ static IType getSimplifiedType(IType type) { - try { - if (type instanceof ICPPFunctionType) { - final ICPPFunctionType ft = (ICPPFunctionType) type; - IType ret = null; - IType[] params = null; - final IType r = ft.getReturnType(); - ret = getSimplifiedType(r); - IType[] ps = ft.getParameterTypes(); - params = getSimplifiedTypes(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); + if (type instanceof ICPPFunctionType) { + final ICPPFunctionType ft = (ICPPFunctionType) type; + IType ret = null; + IType[] params = null; + final IType r = ft.getReturnType(); + ret = getSimplifiedType(r); + IType[] ps = ft.getParameterTypes(); + params = getSimplifiedTypes(ps); + if (ret == r && params == ps) { return type; } - if (type instanceof ITypeContainer) { - final ITypeContainer tc = (ITypeContainer) type; - final IType nestedType= tc.getType(); - if (nestedType == null) - return type; - - IType newType= getSimplifiedType(nestedType); - if (newType != nestedType) { - return replaceNestedType(tc, newType); - } + 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; + } + if (type instanceof ITypeContainer) { + final ITypeContainer tc = (ITypeContainer) type; + final IType nestedType= tc.getType(); + if (nestedType == null) return type; + + IType newType= getSimplifiedType(nestedType); + if (newType != nestedType) { + return replaceNestedType(tc, newType); } - } catch (DOMException e) { + 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 if (type instanceof IQualifierType) { IQualifierType qt= (IQualifierType) type; @@ -299,34 +295,31 @@ public class SemanticUtil { if (!(type instanceof IIndexType)) return type; - try { - if (type instanceof IFunctionType) { - final ICPPFunctionType ft = (ICPPFunctionType) type; - final IType r = ft.getReturnType(); - final IType ret = mapToAST(r, node); - 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); - } + if (type instanceof IFunctionType) { + final ICPPFunctionType ft = (ICPPFunctionType) type; + final IType r = ft.getReturnType(); + final IType ret = mapToAST(r, node); + if (ret == r) { 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; } @@ -427,7 +420,17 @@ public class SemanticUtil { return new CPPPointerType(pt.getType(), cnst || pt.isConst(), vol || pt.isVolatile()); } 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); }