From edeb6f1af14fa0a5eaba55bc0c0ca84be90c8f7d Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Tue, 11 Nov 2008 12:43:26 +0000 Subject: [PATCH] Support for parameter annotations by Sebastian Moss, bug 254520. --- .../internal/pdom/tests/CFunctionTests.java | 17 ++++++-- .../internal/pdom/tests/CPPFunctionTests.java | 10 +++++ .../pdomtests/functionTests/modifiers.c | 1 + .../pdomtests/functionTests/modifiers.cpp | 1 + .../core/dom/parser/c/CParameter.java | 35 +++++++++------- .../core/dom/parser/cpp/CPPParameter.java | 31 +++++++------- .../eclipse/cdt/internal/core/pdom/PDOM.java | 3 +- .../core/pdom/dom/c/PDOMCParameter.java | 36 ++++++++++++++-- .../core/pdom/dom/cpp/PDOMCPPParameter.java | 42 +++++++++++++++---- 9 files changed, 127 insertions(+), 49 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java index 623bac1b99a..0e194ad729f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java @@ -1,14 +1,13 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation. + * Copyright (c) 2006, 2008 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.pdom.tests; import junit.framework.Test; @@ -36,12 +35,14 @@ public class CFunctionTests extends PDOMTestBase { return suite(CFunctionTests.class); } + @Override protected void setUp() throws Exception { project = createProject("functionTests"); pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project); pdom.acquireReadLock(); } + @Override protected void tearDown() throws Exception { pdom.releaseReadLock(); if (project != null) { @@ -84,4 +85,14 @@ public class CFunctionTests extends PDOMTestBase { assertTrue(params[1].getType() instanceof ICBasicType); assertTrue(params[2].getType() instanceof ICBasicType); } + + public void testFunctionWithRegisterParam() throws Exception { + IBinding[] bindings = findQualifiedName(pdom, "storageClassCFunction"); + assertEquals(1, bindings.length); + IFunction f= (IFunction) bindings[0]; + IParameter[] params= f.getParameters(); + assertEquals(2, params.length); + assertEquals(true, params[0].isRegister()); + assertEquals(false, params[1].isRegister()); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java index a0cfce22d09..d93def16046 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java @@ -111,6 +111,16 @@ public class CPPFunctionTests extends PDOMTestBase { assertEquals("p3", parameters[2].getName()); } + public void testStorageClassSpecParameters() throws Exception { + IBinding[] bindings = findQualifiedName(pdom, "storageClassCPPFunction"); + assertEquals(1, bindings.length); + ICPPFunction function = (ICPPFunction) bindings[0]; + IParameter[] parameters = function.getParameters(); + assertEquals(2, parameters.length); + assertEquals(true, parameters[0].isRegister()); + assertEquals(true, parameters[1].isAuto()); + } + public void testExternCPPFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "externCPPFunction"); assertEquals(1, bindings.length); diff --git a/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.c b/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.c index e8364076689..8ee78772ddc 100644 --- a/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.c +++ b/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.c @@ -5,6 +5,7 @@ inline void inlineCFunction(long p1); void varArgsCFunction(int p1, ...); const void constCFunction(); volatile void volatileCFunction(); +void storageClassCFunction(register int p1, int p2); void voidCFunction(); int intCFunction(); diff --git a/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.cpp b/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.cpp index 41edbcd4e75..bd5ef3c900e 100644 --- a/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.cpp +++ b/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.cpp @@ -1,4 +1,5 @@ double normalCPPFunction(int p1, char p2, float p3); +void storageClassCPPFunction(register int p1, auto int p2); static int staticCPPFunction(double p1); extern float externCPPFunction(int p1); inline void inlineCPPFunction(long p1); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java index b6f08650087..0f568a5c399 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IParameter; @@ -174,21 +175,25 @@ public class CParameter extends PlatformObject implements IParameter { return hasStorageClass( IASTDeclSpecifier.sc_register ); } - public boolean hasStorageClass( int storage ){ - if( declarations == null ) - return false; - for( int i = 0; i < declarations.length && declarations[i] != null; i++ ){ - IASTNode parent = declarations[i].getParent(); - while( !(parent instanceof IASTDeclaration) ) - parent = parent.getParent(); - - if( parent instanceof IASTSimpleDeclaration ){ - IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); - if( declSpec.getStorageClass() == storage ) - return true; - } - } - return false; + public boolean hasStorageClass(int storage) { + if (declarations == null) + return false; + + for (int i = 0; i < declarations.length && declarations[i] != null; i++) { + IASTNode parent= declarations[i].getParent(); + while (!(parent instanceof IASTParameterDeclaration) && !(parent instanceof IASTDeclaration)) + parent= parent.getParent(); + + IASTDeclSpecifier declSpec = null; + if (parent instanceof IASTSimpleDeclaration) { + declSpec = ((IASTSimpleDeclaration) parent).getDeclSpecifier(); + } else if (parent instanceof IASTParameterDeclaration) { + declSpec = ((IASTParameterDeclaration) parent).getDeclSpecifier(); + } + if (declSpec != null) + return declSpec.getStorageClass() == storage; + } + return false; } public ILinkage getLinkage() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java index 20219023d86..f5e9be4acab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java @@ -20,7 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; @@ -252,22 +252,19 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI } public boolean hasStorageClass(int storage) { - IASTNode[] ns = getDeclarations(); - if (ns == null) - return false; - - for (int i = 0; i < ns.length && ns[i] != null; i++) { - IASTNode parent = ns[i].getParent(); - while (!(parent instanceof IASTDeclaration)) - parent = parent.getParent(); - - if (parent instanceof IASTSimpleDeclaration) { - IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); - if (declSpec.getStorageClass() == storage) - return true; - } - } - return false; + IASTNode[] ns = getDeclarations(); + if (ns == null) + return false; + + for (int i = 0; i < ns.length && ns[i] != null; i++) { + IASTNode parent = ns[i].getParent(); + while (!(parent instanceof IASTParameterDeclaration)) + parent = parent.getParent(); + IASTDeclSpecifier declSpec = ((IASTParameterDeclaration) parent).getDeclSpecifier(); + if (declSpec.getStorageClass() == storage) + return true; + } + return false; } public IASTInitializer getDefaultValue() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index d7760e0e7b2..0ce5992f398 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -166,11 +166,12 @@ public class PDOM extends PlatformObject implements IPDOM { * 74.0 - changes for proper template argument support, bug 242668 * 75.0 - support for friends, bug 250167 * 76.0 - support for exception specification, bug 252697 + * 77.0 - support for parameter annotations, bug 254520 */ private static int version(int major, int minor) { return major << 16 + minor; } - public static final int MAJOR_VERSION = 76; + public static final int MAJOR_VERSION = 77; public static final int MINOR_VERSION = 0; // minor versions must be compatible public static final int CURRENT_VERSION= version(MAJOR_VERSION, MINOR_VERSION); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java index bec67249341..2d2ab74f0d9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java @@ -41,9 +41,14 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding { private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE + 0; private static final int TYPE = PDOMNamedNode.RECORD_SIZE + 4; + protected static final int FLAGS = PDOMNamedNode.RECORD_SIZE + 8; + @SuppressWarnings("hiding") - public static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 8; - + public static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 9; + static { + assert RECORD_SIZE <= 22; // 23 would yield a 32-byte block + } + public PDOMCParameter(PDOM pdom, int record) { super(pdom, record); } @@ -62,6 +67,8 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding { PDOMNode typeNode = getLinkageImpl().addType(this, type); db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0); } + byte flags = encodeFlags(param); + db.putByte(record + FLAGS, flags); } } catch(DOMException e) { throw new CoreException(Util.createStatus(e)); @@ -105,7 +112,8 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding { } public boolean isAuto() throws DOMException { - throw new PDOMNotImplementedError(); + byte flag = 1<