From e726c3d2179ad8a92a78b0794c6224dca55acc11 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 10 Apr 2012 14:19:12 -0700 Subject: Cosmetics. --- .../cdt/internal/index/tests/IndexTests.java | 2 +- .../cdt/internal/pdom/tests/CFunctionTests.java | 5 +- .../cdt/internal/pdom/tests/CPPFunctionTests.java | 15 +- .../cdt/internal/pdom/tests/PDOMTestBase.java | 23 +- .../cdt/core/testplugin/util/BaseTestCase.java | 18 +- .../cdt/core/dom/ast/IASTImplicitNameOwner.java | 5 +- .../org/eclipse/cdt/core/dom/ast/IFunction.java | 6 +- .../eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java | 9 +- .../cdt/core/parser/util/CharArrayUtils.java | 153 ++++++------- .../core/dom/parser/c/CExternalFunction.java | 9 +- .../cdt/internal/core/dom/parser/c/CFunction.java | 252 ++++++++++----------- .../internal/core/dom/parser/cpp/CPPFunction.java | 79 ++++--- .../dom/parser/cpp/CPPFunctionSpecialization.java | 21 +- .../core/dom/parser/cpp/CPPFunctionTemplate.java | 25 +- .../core/dom/parser/cpp/CPPUnknownFunction.java | 2 +- .../core/index/composite/c/CompositeCFunction.java | 20 +- .../index/composite/cpp/CompositeCPPFunction.java | 38 ++-- .../internal/core/pdom/dom/c/PDOMCAnnotation.java | 2 - .../internal/core/pdom/dom/c/PDOMCFunction.java | 22 +- .../core/pdom/dom/cpp/PDOMCPPFunction.java | 29 ++- .../dom/cpp/PDOMCPPFunctionSpecialization.java | 34 ++- .../dom/lrparser/c99/bindings/C99Function.java | 5 +- 22 files changed, 360 insertions(+), 414 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java index 97982030531..9ad58945e1c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; 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 0e194ad729f..fdc381a323a 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 @@ -6,7 +6,7 @@ * 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; @@ -27,7 +27,6 @@ import org.eclipse.core.runtime.NullProgressMonitor; * C functions. */ public class CFunctionTests extends PDOMTestBase { - protected ICProject project; protected PDOM pdom; @@ -81,7 +80,7 @@ public class CFunctionTests extends PDOMTestBase { IFunction f= (IFunction) bindings[0]; IParameter[] params= f.getParameters(); assertEquals(3, params.length); - assertNull(params[0].getType()); // its a problem binding in the DOM + assertNull(params[0].getType()); // It's a problem binding in the DOM assertTrue(params[1].getType() instanceof ICBasicType); assertTrue(params[2].getType() instanceof ICBasicType); } 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 bef9d26d97b..b834b1b654f 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 @@ -31,14 +31,12 @@ import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; /** * Tests for verifying whether the PDOM correctly stores information about * C++ non-member functions. */ public class CPPFunctionTests extends PDOMTestBase { - protected ICProject project; protected PDOM pdom; @@ -58,13 +56,14 @@ public class CPPFunctionTests extends PDOMTestBase { protected void tearDown() throws Exception { pdom.releaseReadLock(); if (project != null) { - project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); + project.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, npm()); } } public void testPointerToFunctionType() throws Exception { assertDeclarationCount(pdom, "int2intPtr", 1); - IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {"int2intPtr".toCharArray()}, IndexFilter.ALL, npm()); + IIndexFragmentBinding[] b= + pdom.findBindings(new char[][] { "int2intPtr".toCharArray() }, IndexFilter.ALL, npm()); assertEquals(1, b.length); assertInstance(b[0], ICPPVariable.class); ICPPVariable v= (ICPPVariable) b[0]; @@ -103,11 +102,11 @@ public class CPPFunctionTests extends PDOMTestBase { assertEquals(1, bindings.length); ICPPFunction function = (ICPPFunction) bindings[0]; IParameter[] parameters = function.getParameters(); - assertEquals(IBasicType.t_int, ((ICPPBasicType) parameters[0].getType()).getType()); + assertEquals(IBasicType.Kind.eInt, ((ICPPBasicType) parameters[0].getType()).getKind()); assertEquals("p1", parameters[0].getName()); - assertEquals(IBasicType.t_char, ((ICPPBasicType) parameters[1].getType()).getType()); + assertEquals(IBasicType.Kind.eChar, ((ICPPBasicType) parameters[1].getType()).getKind()); assertEquals("p2", parameters[1].getName()); - assertEquals(IBasicType.t_float, ((ICPPBasicType) parameters[2].getType()).getType()); + assertEquals(IBasicType.Kind.eFloat, ((ICPPBasicType) parameters[2].getType()).getKind()); assertEquals("p3", parameters[2].getName()); } @@ -127,7 +126,7 @@ public class CPPFunctionTests extends PDOMTestBase { } public void testStaticCPPFunction() throws Exception { - // static elements cannot be found on global scope, see bug 161216 + // Static elements cannot be found in global scope, see bug 161216 IBinding[] bindings = findUnqualifiedName(pdom, "staticCPPFunction"); assertEquals(1, bindings.length); assertTrue(((ICPPFunction) bindings[0]).isStatic()); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java index 404be910b5b..101d538cf53 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java @@ -6,10 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) - * IBM Corporation - * Symbian - Fix a race condition (157992) + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) + * IBM Corporation + * Symbian - Fix a race condition (157992) *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; @@ -55,7 +55,6 @@ import org.eclipse.ui.wizards.datatransfer.ImportOperation; * @author Doug Schaefer */ public class PDOMTestBase extends BaseTestCase { - protected static final IProgressMonitor PROGRESS = new NullProgressMonitor(); static IPath rootPath = new Path("resources/pdomtests"); private String projectName= null; @@ -100,7 +99,7 @@ public class PDOMTestBase extends BaseTestCase { mj.join(); // Index the project CCorePlugin.getIndexManager().setIndexerId(cprojects[0], IPDOMManager.ID_FAST_INDEXER); - // wait until the indexer is done + // Wait until the indexer is done try { waitForIndexer(cprojects[0]); } catch (InterruptedException e) { @@ -210,8 +209,6 @@ public class PDOMTestBase extends BaseTestCase { assertEquals(visibility, member.getVisibility()); } - - public static final void assertFunctionRefCount(PDOM pdom, Class[] args, IBinding[] bindingPool, int refCount) throws CoreException { IBinding[] bindings = findIFunctions(args, bindingPool); assertEquals(1, bindings.length); @@ -223,16 +220,16 @@ public class PDOMTestBase extends BaseTestCase { public static IBinding[] findIFunctions(Class[] paramTypes, IBinding[] bindings) throws CoreException { List preresult = new ArrayList(); for (IBinding binding : bindings) { - if(binding instanceof IFunction) { + if (binding instanceof IFunction) { IFunction function = (IFunction) binding; IType[] candidate = function.getType().getParameterTypes(); boolean areEqual = candidate.length == paramTypes.length; - for(int j=0; areEqual && j 0) { - err += ", bug #" + fBugnumber; + if (fBugNumber > 0) { + err += ", bug #" + fBugNumber; } result.addFailure(this, new AssertionFailedError(err)); } @@ -222,9 +222,9 @@ public class BaseTestCase extends TestCase { result.endTest(this); } - public void setExpectFailure(int bugnumber) { + public void setExpectFailure(int bugNumber) { fExpectFailure= true; - fBugnumber= bugnumber; + fBugNumber= bugNumber; } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTImplicitNameOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTImplicitNameOwner.java index e1c483fb947..bf2b610bbe5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTImplicitNameOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTImplicitNameOwner.java @@ -6,18 +6,17 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Mike Kucera (IBM) - Initial API and implementation + * Mike Kucera (IBM) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; /** - * An implicit name generated on demand. + * An AST node that may have implicit names. * @since 5.1 * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ public interface IASTImplicitNameOwner extends IASTNode { - public static final ASTNodeProperty IMPLICIT_NAME = new ASTNodeProperty("ICPPASTImplicitNameOwner.IMPLICIT_NAME"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java index c25ba02b936..ebafdabd6f9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; - /** * This represents a function in the program. A function is also a scope * for other bindings. @@ -19,19 +18,18 @@ package org.eclipse.cdt.core.dom.ast; * @noimplement This interface is not intended to be implemented by clients. */ public interface IFunction extends IBinding { - /** * Returns the formal parameters of the function. */ public IParameter[] getParameters(); /** - * Get the function scope + * Returns the function scope */ public IScope getFunctionScope(); /** - * Get the IFunctionType for this function + * Returns the IFunctionType for this function */ public IFunctionType getType(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java index 8c5f0ceef41..b1af1daf8a0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Niefer (IBM Corporation) - initial API and implementation - * Markus Schorn (Wind River Systems) + * Andrew Niefer (IBM Corporation) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; @@ -21,14 +21,13 @@ import org.eclipse.cdt.core.dom.ast.IType; * @noextend This interface is not intended to be extended by clients. */ public interface ICPPFunction extends IFunction, ICPPBinding { - /** - * does this function have the mutable storage class specifier + * Does this function have the mutable storage class specifier */ public boolean isMutable(); /** - * is this an inline function + * Is this an inline function */ @Override public boolean isInline(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java index 59462fa6fde..80608777453 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java @@ -12,22 +12,24 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser.util; +import java.util.Arrays; + /** * A static utility class for char arrays * @author dschaefe - * */ public class CharArrayUtils { - public static final char[] EMPTY = new char[0]; + public static final char[] EMPTY = {}; private CharArrayUtils() {} - + public static final int hash(char[] str, int start, int length) { int h = 0; int end = start + length; - - for (int curr = start; curr < end; ++curr) + + for (int curr = start; curr < end; ++curr) { h += (h << 3) + str[curr]; + } return h; } @@ -35,19 +37,9 @@ public class CharArrayUtils { public static final int hash(char[] str) { return hash(str, 0, str.length); } - + public static final boolean equals(char[] str1, char[] str2) { - if (str1 == str2) - return true; - - if (str1.length != str2.length) - return false; - - for (int i = 0; i < str1.length; ++i) - if (str1[i] != str2[i]) - return false; - - return true; + return Arrays.equals(str1, str2); } public static final boolean equals(char[][] strarr1, char[][] strarr2) { @@ -55,7 +47,7 @@ public class CharArrayUtils { return false; } for (int i = 0; i < strarr2.length; i++) { - if (!equals(strarr1[i], strarr2[i])) { + if (!Arrays.equals(strarr1[i], strarr2[i])) { return false; } } @@ -65,64 +57,65 @@ public class CharArrayUtils { /** * Implements a lexicographical comparator for char arrays. Comparison is done * on a per char basis, not a code-point basis. - * + * * @param str1 the first of the two char arrays to compare * @param str2 the second of the two char arrays to compare * @return 0 if str1==str2, -1 if str1 < str2 and 1 if str1 > str2 */ - /* + /* * aftodo - we should think about using the Character codepoint static methods * if we move to Java 5 */ public static final int compare(char[] str1, char[] str2) { if (str1 == str2) return 0; - + int end= Math.min(str1.length, str2.length); for (int i = 0; i < end; ++i) { int diff= str1[i] - str2[i]; if (diff != 0) return diff; } - + return str1.length - str2.length; } - + public static final boolean equals(char[] str1, int start1, int length1, char[] str2) { - if (length1 != str2.length || str1.length < length1+start1 ) + if (length1 != str2.length || str1.length < length1 + start1) return false; - if( str1 == str2 && start1 == 0 ) + if (str1 == str2 && start1 == 0) return true; - for (int i = 0; i < length1; ++i) + for (int i = 0; i < length1; ++i) { if (str1[start1++] != str2[i]) return false; - + } + return true; } - - public static final boolean equals(char[] str1, int start1, int length1, char[] str2, boolean ignoreCase ) { - if( !ignoreCase ) - return equals( str1, start1, length1, str2 ); - - if (length1 != str2.length || str1.length < start1 + length1 ) + + public static final boolean equals(char[] str1, int start1, int length1, char[] str2, boolean ignoreCase) { + if (!ignoreCase) + return equals(str1, start1, length1, str2); + + if (length1 != str2.length || str1.length < start1 + length1) return false; - - for (int i = 0; i < length1; ++i) - if( Character.toLowerCase(str1[start1++]) != Character.toLowerCase( str2[i] ) ) + + for (int i = 0; i < length1; ++i) { + if (Character.toLowerCase(str1[start1++]) != Character.toLowerCase(str2[i])) return false; - + } return true; } - + public static final char[] extract(char[] str, int start, int length) { if (start == 0 && length == str.length) return str; - + char[] copy = new char[length]; System.arraycopy(str, start, copy, 0, length); return copy; } - + public static final char[] concat(char[] first, char[] second) { if (first == null) return second; @@ -136,12 +129,8 @@ public class CharArrayUtils { System.arraycopy(second, 0, result, length1, length2); return result; } - - public static final char[] replace( - char[] array, - char[] toBeReplaced, - char[] replacementChars) { + public static final char[] replace(char[] array, char[] toBeReplaced, char[] replacementChars) { int max = array.length; int replacedLength = toBeReplaced.length; int replacementLength = replacementChars.length; @@ -150,8 +139,7 @@ public class CharArrayUtils { int occurrenceCount = 0; if (!equals(toBeReplaced, replacementChars)) { - - next : for (int i = 0; i < max; i++) { + next: for (int i = 0; i < max; i++) { int j = 0; while (j < replacedLength) { if (i + j == max) @@ -160,21 +148,15 @@ public class CharArrayUtils { continue next; } if (occurrenceCount == starts.length) { - System.arraycopy( - starts, - 0, - starts = new int[occurrenceCount * 2], - 0, - occurrenceCount); + System.arraycopy(starts, 0, starts = new int[occurrenceCount * 2], 0, + occurrenceCount); } starts[occurrenceCount++] = i; } } if (occurrenceCount == 0) return array; - char[] result = - new char[max - + occurrenceCount * (replacementLength - replacedLength)]; + char[] result = new char[max + occurrenceCount * (replacementLength - replacedLength)]; int inStart = 0, outStart = 0; for (int i = 0; i < occurrenceCount; i++) { int offset = starts[i] - inStart; @@ -223,50 +205,55 @@ public class CharArrayUtils { System.arraycopy(array, start, result, 0, end - start); return result; } - + public static final int indexOf(char toBeFound, char[] array) { - for (int i = 0; i < array.length; i++) + for (int i = 0; i < array.length; i++) { if (toBeFound == array[i]) return i; + } return -1; } - - public static int indexOf( char toBeFound, char[] buffer, int start, int end ) { - if( start < 0 || start > buffer.length || end > buffer.length ) + + public static int indexOf(char toBeFound, char[] buffer, int start, int end) { + if (start < 0 || start > buffer.length || end > buffer.length) return -1; - - for (int i = start; i < end; i++) + + for (int i = start; i < end; i++) { if (toBeFound == buffer[i]) return i; + } return -1; } - - public static final int indexOf( char[] toBeFound, char[] array ){ - if( toBeFound.length > array.length ) + + public static final int indexOf(char[] toBeFound, char[] array) { + if (toBeFound.length > array.length) return -1; - + int j = 0; - for( int i = 0; i < array.length; i++ ){ - if( toBeFound[j] == array[i] ){ - if( ++j == toBeFound.length ) + for (int i = 0; i < array.length; i++) { + if (toBeFound[j] == array[i]) { + if (++j == toBeFound.length) return i - j + 1; + } else { + j = 0; } - else j = 0; } return -1; } - + public static final int lastIndexOf(char[] toBeFound, char[] array) { int j = toBeFound.length - 1; - for (int i = array.length; --i >= 0;){ - if (toBeFound[j] == array[i]){ - if( --j == -1 ) + for (int i = array.length; --i >= 0;) { + if (toBeFound[j] == array[i]) { + if (--j == -1) return i; - } else j = toBeFound.length - 1; + } else { + j = toBeFound.length - 1; + } } return -1; } - + final static public char[] trim(char[] chars) { if (chars == null) return null; @@ -296,20 +283,20 @@ public class CharArrayUtils { * @param i * @param charImage */ - public static void overWrite( char[] buff, int i, char[] charImage ) { - if( buff.length < i + charImage.length ) + public static void overWrite(char[] buff, int i, char[] charImage) { + if (buff.length < i + charImage.length) return; - for( int j = 0; j < charImage.length; j++ ){ - buff[ i + j ] = charImage[j]; + for (int j = 0; j < charImage.length; j++) { + buff[i + j] = charImage[j]; } } - + /** * Find an array of chars in an array of arrays of chars. * @return offset where the array was found or -1 */ public static int indexOf(final char[] searchFor, final char[][] searchIn) { - for (int i=0; i < searchIn.length; i++) { + for (int i = 0; i < searchIn.length; i++) { if (equals(searchIn[i], searchFor)) { return i; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java index 4d67e2625f5..af3e5163fb3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java @@ -27,16 +27,15 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType; public class CExternalFunction extends CFunction implements ICExternalBinding { private static final IType VOID_TYPE = new CBasicType(Kind.eVoid, 0); - private IASTName name = null; - private IASTTranslationUnit tu = null; + private IASTName name; + private IASTTranslationUnit tu; - public CExternalFunction( IASTTranslationUnit tu, IASTName name ) { - super( null ); + public CExternalFunction(IASTTranslationUnit tu, IASTName name) { + super(null); this.name = name; this.tu = tu; } - @Override public IFunctionType getType() { if (type == null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 62ef92945e8..564ab70660f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -41,15 +41,15 @@ import org.eclipse.core.runtime.PlatformObject; * Represents a function. */ public class CFunction extends PlatformObject implements IFunction, ICInternalFunction { - private IASTDeclarator[] declarators = null; + private IASTDeclarator[] declarators; private IASTFunctionDeclarator definition; - + private static final int FULLY_RESOLVED = 1; private static final int RESOLUTION_IN_PROGRESS = 1 << 1; private int bits = 0; - + protected IFunctionType type = null; - + public CFunction(IASTDeclarator declarator) { storeDeclarator(declarator); } @@ -66,13 +66,14 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu } } } - + @Override public IASTDeclarator getPhysicalNode() { - if (definition != null) + if (definition != null) { return definition; - else if (declarators != null && declarators.length > 0) + } else if (declarators != null && declarators.length > 0) { return declarators[0]; + } return null; } @@ -86,34 +87,35 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu } storeDeclarator(fnDeclarator); } - + protected IASTTranslationUnit getTranslationUnit() { - if( definition != null ) + if (definition != null) { return definition.getTranslationUnit(); - else if( declarators != null ) + } else if (declarators != null) { return declarators[0].getTranslationUnit(); + } return null; } - - private void resolveAllDeclarations(){ - if( (bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0 ){ + + private void resolveAllDeclarations() { + if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) { bits |= RESOLUTION_IN_PROGRESS; IASTTranslationUnit tu = getTranslationUnit(); - if( tu != null ){ - CVisitor.getDeclarations( tu, this ); + if (tu != null) { + CVisitor.getDeclarations(tu, this); } declarators = ArrayUtil.trim(IASTDeclarator.class, declarators); bits |= FULLY_RESOLVED; bits &= ~RESOLUTION_IN_PROGRESS; } } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters() */ @Override public IParameter[] getParameters() { - int j=-1; + int j= -1; int len = declarators != null ? declarators.length : 0; for (IASTDeclarator dtor = definition; j < len; j++) { if (j >= 0) { @@ -131,7 +133,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu } } return result; - } + } if (dtor instanceof ICASTKnRFunctionDeclarator) { IASTName[] names = ((ICASTKnRFunctionDeclarator) dtor).getParameterNames(); IParameter[] result = new IParameter[names.length]; @@ -145,43 +147,37 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu result[i] = (IParameter) decl.getName().resolveBinding(); } else { result[i] = new CParameter.CParameterProblem(names[i], - IProblemBinding.SEMANTIC_KNR_PARAMETER_DECLARATION_NOT_FOUND, names[i] - .toCharArray()); + IProblemBinding.SEMANTIC_KNR_PARAMETER_DECLARATION_NOT_FOUND, + names[i].toCharArray()); } } } return result; } } - + if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) { resolveAllDeclarations(); return getParameters(); } - + return CBuiltinParameter.createParameterList(getType()); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() - */ @Override public String getName() { return getASTName().toString(); } - + @Override - public char[] getNameCharArray(){ + public char[] getNameCharArray() { return getASTName().toCharArray(); } private IASTName getASTName() { return ASTQueries.findInnermostDeclarator(getPhysicalNode()).getName(); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() - */ + @Override public IScope getScope() { IASTDeclarator dtor = getPhysicalNode(); @@ -190,9 +186,6 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu return null; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IFunction#getFunctionScope() - */ @Override public IScope getFunctionScope() { if (definition != null) { @@ -223,67 +216,67 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu } return null; } - - public IBinding resolveParameter( IASTName paramName ){ - if( paramName.getBinding() != null ) + + public IBinding resolveParameter(IASTName paramName) { + if (paramName.getBinding() != null) return paramName.getBinding(); IBinding binding = null; int idx = 0; IASTNode parent = paramName.getParent(); - while( parent instanceof IASTDeclarator && !(parent instanceof ICASTKnRFunctionDeclarator ) ) + while (parent instanceof IASTDeclarator && !(parent instanceof ICASTKnRFunctionDeclarator)) parent = parent.getParent(); - + ICASTKnRFunctionDeclarator fKnRDtor = null; IASTDeclarator knrParamDtor = null; - if( parent instanceof IASTParameterDeclaration ){ + if (parent instanceof IASTParameterDeclaration) { IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) parent.getParent(); IASTParameterDeclaration [] ps = fdtor.getParameters(); - for( ; idx < ps.length; idx++ ){ - if( parent == ps[idx] ) + for (; idx < ps.length; idx++) { + if (parent == ps[idx]) break; } - } else if( parent instanceof IASTSimpleDeclaration ){ + } else if (parent instanceof IASTSimpleDeclaration) { //KnR: name in declaration list fKnRDtor = (ICASTKnRFunctionDeclarator) parent.getParent(); IASTName [] ps = fKnRDtor.getParameterNames(); char [] n = paramName.toCharArray(); - for( ; idx < ps.length; idx++ ){ - if( CharArrayUtils.equals( ps[idx].toCharArray(), n ) ) + for (; idx < ps.length; idx++) { + if (CharArrayUtils.equals(ps[idx].toCharArray(), n)) break; - } + } } else { //KnR: name in name list fKnRDtor = (ICASTKnRFunctionDeclarator) parent; IASTName [] ps = fKnRDtor.getParameterNames(); - for( ; idx < ps.length; idx++ ){ - if( ps[idx] == paramName) + for (; idx < ps.length; idx++) { + if (ps[idx] == paramName) break; } - knrParamDtor = CVisitor.getKnRParameterDeclarator( fKnRDtor, paramName ); - if( knrParamDtor != null ) + knrParamDtor = CVisitor.getKnRParameterDeclarator(fKnRDtor, paramName); + if (knrParamDtor != null) paramName = knrParamDtor.getName(); } - + //create a new binding and set it for the corresponding parameter in all known defns and decls - binding = new CParameter( paramName ); + binding = new CParameter(paramName); IASTParameterDeclaration temp = null; - if( definition != null ){ - if( definition instanceof IASTStandardFunctionDeclarator ){ + if (definition != null) { + if (definition instanceof IASTStandardFunctionDeclarator) { IASTParameterDeclaration [] parameters = ((IASTStandardFunctionDeclarator)definition).getParameters(); - if( parameters.length > idx ) { + if (parameters.length > idx) { temp = parameters[idx]; - ASTQueries.findInnermostDeclarator(temp.getDeclarator()).getName().setBinding( binding ); + ASTQueries.findInnermostDeclarator(temp.getDeclarator()).getName().setBinding(binding); } - } else if( definition instanceof ICASTKnRFunctionDeclarator ){ + } else if (definition instanceof ICASTKnRFunctionDeclarator) { fKnRDtor = (ICASTKnRFunctionDeclarator) definition; IASTName [] parameterNames = fKnRDtor.getParameterNames(); - if( parameterNames.length > idx ) { + if (parameterNames.length > idx) { IASTName n = parameterNames[idx]; - n.setBinding( binding ); - IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator( fKnRDtor, n ); - if( dtor != null ){ - dtor.getName().setBinding( binding ); + n.setBinding(binding); + IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator(fKnRDtor, n); + if (dtor != null) { + dtor.getName().setBinding(binding); } } } @@ -292,159 +285,153 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu for (IASTDeclarator dtor : declarators) { if (dtor instanceof IASTStandardFunctionDeclarator) { IASTStandardFunctionDeclarator fdtor= (IASTStandardFunctionDeclarator) dtor; - if( fdtor.getParameters().length > idx ){ + if (fdtor.getParameters().length > idx) { temp = fdtor.getParameters()[idx]; - ASTQueries.findInnermostDeclarator(temp.getDeclarator()).getName().setBinding( binding ); + ASTQueries.findInnermostDeclarator(temp.getDeclarator()).getName().setBinding(binding); } } } } return binding; } - - - protected void updateParameterBindings( IASTFunctionDeclarator fdtor ){ + protected void updateParameterBindings(IASTFunctionDeclarator fdtor) { IParameter [] params = getParameters(); - if( fdtor instanceof IASTStandardFunctionDeclarator ){ + if (fdtor instanceof IASTStandardFunctionDeclarator) { IASTParameterDeclaration [] nps = ((IASTStandardFunctionDeclarator)fdtor).getParameters(); - if(params.length < nps.length ) - return; - for( int i = 0; i < nps.length; i++ ){ + if (params.length < nps.length) + return; + for (int i = 0; i < nps.length; i++) { IASTName name = ASTQueries.findInnermostDeclarator(nps[i].getDeclarator()).getName(); - name.setBinding( params[i] ); - if( params[i] instanceof CParameter ) - ((CParameter)params[i]).addDeclaration( name ); + name.setBinding(params[i]); + if (params[i] instanceof CParameter) + ((CParameter)params[i]).addDeclaration(name); } } else { IASTName [] ns = ((ICASTKnRFunctionDeclarator)fdtor).getParameterNames(); - if( params.length > 0 && params.length != ns.length ) + if (params.length > 0 && params.length != ns.length) return; //problem - - for( int i = 0; i < params.length; i++ ){ + + for (int i = 0; i < params.length; i++) { IASTName name = ns[i]; - name.setBinding( params[i] ); - IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator( (ICASTKnRFunctionDeclarator) fdtor, name ); - if( dtor != null ){ - dtor.getName().setBinding( params[i] ); - if( params[i] instanceof CParameter ) - ((CParameter)params[i]).addDeclaration( dtor.getName() ); + name.setBinding(params[i]); + IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator((ICASTKnRFunctionDeclarator) fdtor, name); + if (dtor != null) { + dtor.getName().setBinding(params[i]); + if (params[i] instanceof CParameter) + ((CParameter)params[i]).addDeclaration(dtor.getName()); } } } } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic() - */ @Override public boolean isStatic() { return isStatic(true); } - + @Override public boolean isStatic(boolean resolveAll) { - if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){ + if (resolveAll && (bits & FULLY_RESOLVED) == 0) { resolveAllDeclarations(); } - return hasStorageClass( IASTDeclSpecifier.sc_static ); + return hasStorageClass(IASTDeclSpecifier.sc_static); } - public boolean hasStorageClass( int storage){ + public boolean hasStorageClass(int storage) { IASTDeclarator dtor = definition; IASTDeclarator[] ds = declarators; int i = -1; - do{ - if( dtor != null ){ + do { + if (dtor != null) { IASTNode parent = dtor.getParent(); - while( !(parent instanceof IASTDeclaration) ) + while (!(parent instanceof IASTDeclaration)) parent = parent.getParent(); - + IASTDeclSpecifier declSpec = null; - if( parent instanceof IASTSimpleDeclaration ){ + if (parent instanceof IASTSimpleDeclaration) { declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); - } else if( parent instanceof IASTFunctionDefinition ) + } else if (parent instanceof IASTFunctionDefinition) declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier(); - - if( declSpec != null && declSpec.getStorageClass() == storage ) { + + if (declSpec != null && declSpec.getStorageClass() == storage) { return true; } } - - if( ds != null && ++i < ds.length ) + + if (ds != null && ++i < ds.length) { dtor = ds[i]; - else + } else { break; - } while( dtor != null ); + } + } while (dtor != null); return false; } - @Override public boolean isExtern() { return isExtern(true); } - + public boolean isExtern(boolean resolveAll) { - if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){ + if (resolveAll && (bits & FULLY_RESOLVED) == 0) { resolveAllDeclarations(); } - return hasStorageClass( IASTDeclSpecifier.sc_extern); + return hasStorageClass(IASTDeclSpecifier.sc_extern); } - @Override public boolean isAuto() { - if( (bits & FULLY_RESOLVED) == 0 ){ + if ((bits & FULLY_RESOLVED) == 0) { resolveAllDeclarations(); } - return hasStorageClass( IASTDeclSpecifier.sc_auto); + return hasStorageClass(IASTDeclSpecifier.sc_auto); } - @Override public boolean isRegister() { - if( (bits & FULLY_RESOLVED) == 0 ){ + if ((bits & FULLY_RESOLVED) == 0) { resolveAllDeclarations(); } - return hasStorageClass( IASTDeclSpecifier.sc_register); + return hasStorageClass(IASTDeclSpecifier.sc_register); } - @Override public boolean isInline() { - if( (bits & FULLY_RESOLVED) == 0 ){ + if ((bits & FULLY_RESOLVED) == 0) { resolveAllDeclarations(); } IASTDeclarator dtor = definition; IASTDeclarator[] ds = declarators; int i = -1; - do{ - if( dtor != null ){ + do { + if (dtor != null) { IASTNode parent = dtor.getParent(); - while( !(parent instanceof IASTDeclaration) ) + while (!(parent instanceof IASTDeclaration)) { parent = parent.getParent(); - + } + IASTDeclSpecifier declSpec = null; - if( parent instanceof IASTSimpleDeclaration ){ + if (parent instanceof IASTSimpleDeclaration) { declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); - } else if( parent instanceof IASTFunctionDefinition ) + } else if (parent instanceof IASTFunctionDefinition) { declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier(); - - if( declSpec != null && declSpec.isInline() ) + } + + if (declSpec != null && declSpec.isInline()) return true; } - if( ds != null && ++i < ds.length ) + if (ds != null && ++i < ds.length) { dtor = ds[i]; - else + } else { break; - } while( dtor != null ); - + } + } while (dtor != null); + return false; } - @Override public boolean takesVarArgs() { if ((bits & FULLY_RESOLVED) == 0) { @@ -469,10 +456,11 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu @Override public void setFullyResolved(boolean resolved) { - if( resolved ) + if (resolved) { bits |= FULLY_RESOLVED; - else + } else { bits &= ~FULLY_RESOLVED; + } } @Override @@ -489,7 +477,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu public IASTNode getDefinition() { return definition; } - + @Override public IBinding getOwner() { return null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 88ff224c1b9..071bb01590b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -57,15 +57,14 @@ import org.eclipse.core.runtime.PlatformObject; * Binding for c++ function */ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInternalFunction { - protected IASTDeclarator[] declarations; protected ICPPASTFunctionDeclarator definition; - protected ICPPFunctionType type = null; - + protected ICPPFunctionType type; + private static final int FULLY_RESOLVED = 1; private static final int RESOLUTION_IN_PROGRESS = 1 << 1; private int bits = 0; - + public CPPFunction(IASTDeclarator declarator) { if (declarator != null) { IASTNode parent = ASTQueries.findOutermostDeclarator(declarator).getParent(); @@ -76,12 +75,12 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } else { declarations = new IASTDeclarator[] { declarator }; } - + IASTName name= getASTName(); name.setBinding(this); } } - + private void resolveAllDeclarations() { if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) { bits |= RESOLUTION_IN_PROGRESS; @@ -106,7 +105,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt bits &= ~RESOLUTION_IN_PROGRESS; } } - + @Override public IASTDeclarator[] getDeclarations() { return declarations; @@ -116,7 +115,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt public ICPPASTFunctionDeclarator getDefinition() { return definition; } - + @Override public final void addDefinition(IASTNode node) { IASTDeclarator dtor = extractRelevantDtor(node); @@ -126,14 +125,14 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt definition = fdtor; } } - + @Override public final void addDeclaration(IASTNode node) { IASTDeclarator dtor = extractRelevantDtor(node); if (dtor == null) { return; } - + // function could be declared via a typedef if (dtor instanceof ICPPASTFunctionDeclarator) { updateFunctionParameterBindings((ICPPASTFunctionDeclarator) dtor); @@ -189,14 +188,14 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt resolveAllDeclarations(); if (definition != null) { return definition.getFunctionScope(); - } - + } + for (IASTDeclarator dtor : declarations) { if (dtor instanceof ICPPASTFunctionDeclarator) { return ((ICPPASTFunctionDeclarator) dtor).getFunctionScope(); } } - + // function declaration via typedef return null; } @@ -210,7 +209,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt public char[] getNameCharArray() { return getASTName().getSimpleID(); } - + protected IASTName getASTName() { IASTDeclarator dtor = (definition != null) ? definition : declarations[0]; dtor= ASTQueries.findInnermostDeclarator(dtor); @@ -231,10 +230,10 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt if (definition != null) { IASTNode node = ASTQueries.findOutermostDeclarator(definition).getParent(); IASTFunctionDefinition def = (IASTFunctionDefinition) node; - declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier(); + declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier(); } else { IASTNode node = ASTQueries.findOutermostDeclarator(declarations[0]).getParent(); - IASTSimpleDeclaration decl = (IASTSimpleDeclaration)node; + IASTSimpleDeclaration decl = (IASTSimpleDeclaration)node; declSpec = (ICPPASTDeclSpecifier) decl.getDeclSpecifier(); } if (declSpec.isFriend()) { @@ -268,7 +267,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt @Override public IBinding resolveParameter(CPPParameter param) { int pos= param.getParameterPosition(); - + int tdeclLen= declarations == null ? 0 : declarations.length; for (int i= -1; i < tdeclLen; i++) { ICPPASTFunctionDeclarator tdecl; @@ -286,7 +285,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } tdecl= (ICPPASTFunctionDeclarator) dtor; } - + IASTParameterDeclaration[] params = tdecl.getParameters(); if (pos < params.length) { final IASTName oName = getParamName(params[pos]); @@ -299,7 +298,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt private IASTName getParamName(final IASTParameterDeclaration paramDecl) { return ASTQueries.findInnermostDeclarator(paramDecl.getDeclarator()).getName(); } - + protected final void updateFunctionParameterBindings(ICPPASTFunctionDeclarator fdtor) { IASTParameterDeclaration[] updateParams = fdtor.getParameters(); @@ -321,7 +320,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } tdecl= (ICPPASTFunctionDeclarator) dtor; } - + IASTParameterDeclaration[] params = tdecl.getParameters(); int end= Math.min(params.length, updateParams.length); for (; k < end; k++) { @@ -352,7 +351,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt // //least significant = whether or not we are static // int state = (bits & IS_STATIC) >> 2; // if (state > 1) return (state % 2 != 0); -// +// // IASTDeclSpecifier declSpec = null; // IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) getDefinition(); // if (dtor != null) { @@ -362,7 +361,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt // return true; // } // } -// +// // IASTFunctionDeclarator[] dtors = (IASTFunctionDeclarator[]) getDeclarations(); // if (dtors != null) { // for (int i = 0; i < dtors.length; i++) { @@ -377,7 +376,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt // bits |= 2 << 2; // return false; // } - + @Override public String[] getQualifiedName() { return CPPVisitor.getQualifiedName(this); @@ -409,7 +408,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt IASTNode parent = dtor.getParent(); while (!(parent instanceof IASTDeclaration)) parent = parent.getParent(); - + IASTDeclSpecifier declSpec = null; if (parent instanceof IASTSimpleDeclaration) { declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); @@ -428,7 +427,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } while (dtor != null); return false; } - + @Override public boolean isDeleted() { return isDeletedDefinition(getDefinition()); @@ -459,13 +458,13 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt IASTNode parent = dtor.getParent(); while (!(parent instanceof IASTDeclaration)) parent = parent.getParent(); - + IASTDeclSpecifier declSpec = null; if (parent instanceof IASTSimpleDeclaration) declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); else if (parent instanceof IASTFunctionDefinition) declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier(); - + if (declSpec != null && declSpec.isInline()) return true; } @@ -513,12 +512,12 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt ICPPASTFunctionDeclarator dtor= getPreferredDtor(); return dtor != null ? dtor.takesVarArgs() : false; } - + @Override public ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } - + @Override public String toString() { StringBuilder result = new StringBuilder(); @@ -527,7 +526,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt result.append(t != null ? ASTTypeUtil.getParameterTypeString(t) : "()"); //$NON-NLS-1$ return result.toString(); } - + @Override public IBinding getOwner() { return CPPVisitor.findNameOwner(getASTName(), false); @@ -538,12 +537,12 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt ICPPASTFunctionDeclarator declarator = getPreferredDtor(); if (declarator != null) { IASTTypeId[] astTypeIds= declarator.getExceptionSpecification(); - if (astTypeIds.equals(ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION)) + if (astTypeIds.equals(ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION)) return null; - - if (astTypeIds.equals(IASTTypeId.EMPTY_TYPEID_ARRAY)) + + if (astTypeIds.equals(IASTTypeId.EMPTY_TYPEID_ARRAY)) return IType.EMPTY_TYPE_ARRAY; - + IType[] typeIds = new IType[astTypeIds.length]; for (int i= 0; i < astTypeIds.length; ++i) { typeIds[i] = CPPVisitor.createType(astTypeIds[i]); @@ -552,16 +551,16 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } return null; } - + protected ICPPASTFunctionDeclarator getPreferredDtor() { ICPPASTFunctionDeclarator dtor = getDefinition(); - if (dtor != null) + if (dtor != null) return dtor; IASTDeclarator[] dtors = getDeclarations(); if (dtors != null) { for (IASTDeclarator declarator : dtors) { - if (declarator instanceof ICPPASTFunctionDeclarator) + if (declarator instanceof ICPPASTFunctionDeclarator) return (ICPPASTFunctionDeclarator) declarator; } } @@ -575,8 +574,8 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt public static int getRequiredArgumentCount(ICPPParameter[] pars) { int result= pars.length; - while(result > 0) { - final ICPPParameter p = pars[result-1]; + while (result > 0) { + final ICPPParameter p = pars[result - 1]; if (p.hasDefaultValue() || p.isParameterPack()) { result--; } else { @@ -592,6 +591,6 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt @Override public boolean hasParameterPack() { ICPPParameter[] pars= getParameters(); - return pars.length > 0 && pars[pars.length-1].isParameterPack(); + return pars.length > 0 && pars[pars.length - 1].isParameterPack(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java index 15840d49762..cf13fb67c95 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Niefer (IBM) - Initial API and implementation - * Bryan Wilkinson (QNX) - * Markus Schorn (Wind River Systems) + * Andrew Niefer (IBM) - Initial API and implementation + * Bryan Wilkinson (QNX) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -40,9 +40,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; * also used as base class for function instances. */ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPPFunction, ICPPInternalFunction { - private ICPPFunctionType type = null; - private ICPPParameter[] fParams = null; - private IType[] specializedExceptionSpec = null; + private ICPPFunctionType type; + private ICPPParameter[] fParams; + private IType[] specializedExceptionSpec; private final ICPPClassSpecialization fContext; public CPPFunctionSpecialization(ICPPFunction orig, IBinding owner, ICPPTemplateParameterMap argMap) { @@ -139,7 +139,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP IASTNode def = getDefinition(); while (!(def instanceof IASTFunctionDefinition)) def = def.getParent(); - return ((IASTFunctionDefinition)def).getDeclSpecifier().isInline(); + return ((IASTFunctionDefinition) def).getDeclSpecifier().isInline(); } return getFunction().isInline(); } @@ -156,12 +156,13 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP public boolean isStatic() { return isStatic(true); } + @Override public boolean isStatic(boolean resolveAll) { //TODO resolveAll IBinding f = getSpecializedBinding(); if (f instanceof ICPPInternalFunction) - return ((ICPPInternalFunction)f).isStatic(resolveAll); + return ((ICPPInternalFunction) f).isStatic(resolveAll); if (f instanceof IIndexBinding && f instanceof ICPPFunction) { return ((ICPPFunction) f).isStatic(); } @@ -325,8 +326,8 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP IType[] types = function.getExceptionSpecification(); if (types != null) { IType[] specializedTypeList = new IType[types.length]; - int j=0; - for (int i=0; i= 0; --i) { + for (int i= params.length; --i >= 0;) { next= new PDOMCPPParameter(linkage, this, params[i], next); } db.putRecPtr(record + FIRST_PARAM, next == null ? 0 : next.getRecord()); @@ -205,7 +203,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl private void setType(ICPPFunctionType ft) throws CoreException { fType= null; - getLinkage().storeType(record+FUNCTION_TYPE, ft); + getLinkage().storeType(record + FUNCTION_TYPE, ft); } @Override @@ -241,7 +239,6 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl return getBit(getAnnotation(), PDOMCAnnotation.INLINE_OFFSET); } - @Override public int getRequiredArgumentCount() { if (fRequiredArgCount == -1) { @@ -309,7 +306,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl public final ICPPFunctionType getType() { if (fType == null) { try { - fType= (ICPPFunctionType) getLinkage().loadType(record+FUNCTION_TYPE); + fType= (ICPPFunctionType) getLinkage().loadType(record + FUNCTION_TYPE); } catch (CoreException e) { CCorePlugin.log(e); fType= new ProblemFunctionType(ISemanticProblem.TYPE_NOT_PERSISTED); @@ -385,7 +382,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl @Override public IType[] getExceptionSpecification() { try { - final long rec = getPDOM().getDB().getRecPtr(record+EXCEPTION_SPEC); + final long rec = getPDOM().getDB().getRecPtr(record + EXCEPTION_SPEC); return PDOMCPPTypeList.getTypes(this, rec); } catch (CoreException e) { CCorePlugin.log(e); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java index fcb5a413c11..9097d5c6197 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Bryan Wilkinson (QNX) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -35,20 +35,18 @@ import org.eclipse.core.runtime.CoreException; */ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICPPFunction { /** - * Offset of total number of function parameters (relative to the - * beginning of the record). + * Offset of total number of function parameters (relative to the beginning of the record). */ private static final int NUM_PARAMS = PDOMCPPSpecialization.RECORD_SIZE; /** - * Offset of pointer to the first parameter of this function (relative to - * the beginning of the record). + * Offset of pointer to the first parameter of this function (relative to the beginning + * of the record). */ private static final int FIRST_PARAM = NUM_PARAMS + 4; /** - * Offset for type of this function (relative to - * the beginning of the record). + * Offset for type of this function (relative to the beginning of the record). */ private static final int FUNCTION_TYPE = FIRST_PARAM + Database.PTR_SIZE; @@ -58,19 +56,18 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP protected static final int EXCEPTION_SPEC = FUNCTION_TYPE + Database.TYPE_SIZE; // int /** - * Offset of annotation information (relative to the beginning of the - * record). + * Offset of annotation information (relative to the beginning of the record). */ protected static final int ANNOTATION_OFFSET = EXCEPTION_SPEC + Database.PTR_SIZE; // short private static final int REQUIRED_ARG_COUNT_OFFSET= ANNOTATION_OFFSET + 2; + /** * The size in bytes of a PDOMCPPFunction record in the database. */ @SuppressWarnings("hiding") protected static final int RECORD_SIZE = REQUIRED_ARG_COUNT_OFFSET + 4; - private static final short ANNOT_PARAMETER_PACK = 8; private static final short ANNOT_IS_DELETED = 9; @@ -102,7 +99,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP PDOMCPPParameterSpecialization next= null; for (int i= length-1; i >= 0; --i) { // There may be fewer or less original parameters, because of parameter packs. - if (i < origAstParams.length-1) { + if (i < origAstParams.length - 1) { // Normal case origPar= new PDOMCPPParameter(linkage, specialized, origAstParams[i], null); } else if (origPar == null) { @@ -118,12 +115,11 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP db.putInt(record + REQUIRED_ARG_COUNT_OFFSET, astFunction.getRequiredArgumentCount()); long typelist= 0; if (astFunction instanceof ICPPMethod && ((ICPPMethod) astFunction).isImplicit()) { - // don't store the exception specification, computed it on demand. + // Don't store the exception specification, it is computed on demand. } else { typelist = PDOMCPPTypeList.putTypes(this, astFunction.getExceptionSpecification()); } db.putRecPtr(record + EXCEPTION_SPEC, typelist); - } private short getAnnotation(ICPPFunction astFunction) { @@ -132,7 +128,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP annot |= (1 << ANNOT_PARAMETER_PACK); } if (astFunction.isDeleted()) { - annot |= (1< parameters = new ArrayList(); @@ -41,7 +40,6 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio // the scope that represents the body of the function private IScope bodyScope; - public C99Function() { } @@ -54,8 +52,7 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio this(name); this.type = type; } - - + public IParameter[] getParameters() { return parameters.toArray(new IParameter[parameters.size()]); } -- cgit v1.2.3