From 448fec099f4ae97554844f20d6ac9e3a7c8f8349 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 22 Jul 2009 15:08:28 +0000 Subject: [PATCH] Adjusting c-parameter type for typedefs, bug 284248. --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 15 ++++++++ .../internal/core/dom/parser/c/CVisitor.java | 34 ++++++++++++------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 04a3b44903a..042883d917a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -6392,4 +6392,19 @@ public class AST2Tests extends AST2BaseTest { } } + + // /* Check that a parameter declared as a typedef'd array + // * is treated as a pointer + // */ + //typedef int my_buf[16]; + //void goo(my_buf in); + // + public void testBug284248() throws Exception { + for(ParserLanguage lang : ParserLanguage.values()) { + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), lang); + assertTrue(tu.isFrozen()); + IASTName n = ((IASTSimpleDeclaration)tu.getDeclarations()[1]).getDeclarators()[0].getName(); + assertTrue(((IFunction)n.resolveBinding()).getType().getParameterTypes()[0] instanceof IPointerType); + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 0e98e452116..99a4118ebd4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -51,6 +51,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; @@ -1273,22 +1274,31 @@ public class CVisitor extends ASTQueries { if (isParameter) { + IType paramType = type; + // Remove typedefs ready for subsequent processing. + while (paramType instanceof ITypedef) { + paramType = ((ITypedef)paramType).getType(); + } + //C99: 6.7.5.3-7 a declaration of a parameter as "array of type" shall be adjusted to "qualified pointer to type", where the //type qualifiers (if any) are those specified within the[and] of the array type derivation - if (type instanceof ICArrayType) { - ICArrayType at = (ICArrayType) type; - try { - int q= 0; - if (at.isConst()) q |= CPointerType.IS_CONST; - if (at.isVolatile()) q |= CPointerType.IS_VOLATILE; - if (at.isRestrict()) q |= CPointerType.IS_RESTRICT; - type = new CPointerType(at.getType(), q); - } catch (DOMException e) { - // stick to the array + if (paramType instanceof IArrayType) { // the index does not yet return ICArrayTypes + IArrayType at = (IArrayType) paramType; + int q= 0; + if (at instanceof ICArrayType) { + ICArrayType cat= (ICArrayType) at; + try { + if (cat.isConst()) q |= CPointerType.IS_CONST; + if (cat.isVolatile()) q |= CPointerType.IS_VOLATILE; + if (cat.isRestrict()) q |= CPointerType.IS_RESTRICT; + } catch (DOMException e) { + // ignore the qualifiers + } } - } else if (type instanceof IFunctionType) { + type = new CPointerType(at.getType(), q); + } else if (paramType instanceof IFunctionType) { //-8 A declaration of a parameter as "function returning type" shall be adjusted to "pointer to function returning type" - type = new CPointerType(type, 0); + type = new CPointerType(paramType, 0); } }