1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Merge remote-tracking branch 'cdt/master' into sd90

This commit is contained in:
Andrew Gvozdev 2012-04-11 15:12:40 -04:00
commit 7415f69a91
27 changed files with 396 additions and 449 deletions

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.index.tests; package org.eclipse.cdt.internal.index.tests;

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests; package org.eclipse.cdt.internal.pdom.tests;
@ -27,7 +27,6 @@ import org.eclipse.core.runtime.NullProgressMonitor;
* C functions. * C functions.
*/ */
public class CFunctionTests extends PDOMTestBase { public class CFunctionTests extends PDOMTestBase {
protected ICProject project; protected ICProject project;
protected PDOM pdom; protected PDOM pdom;
@ -81,7 +80,7 @@ public class CFunctionTests extends PDOMTestBase {
IFunction f= (IFunction) bindings[0]; IFunction f= (IFunction) bindings[0];
IParameter[] params= f.getParameters(); IParameter[] params= f.getParameters();
assertEquals(3, params.length); 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[1].getType() instanceof ICBasicType);
assertTrue(params[2].getType() instanceof ICBasicType); assertTrue(params[2].getType() instanceof ICBasicType);
} }

View file

@ -31,14 +31,12 @@ import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
/** /**
* Tests for verifying whether the PDOM correctly stores information about * Tests for verifying whether the PDOM correctly stores information about
* C++ non-member functions. * C++ non-member functions.
*/ */
public class CPPFunctionTests extends PDOMTestBase { public class CPPFunctionTests extends PDOMTestBase {
protected ICProject project; protected ICProject project;
protected PDOM pdom; protected PDOM pdom;
@ -58,13 +56,14 @@ public class CPPFunctionTests extends PDOMTestBase {
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
pdom.releaseReadLock(); pdom.releaseReadLock();
if (project != null) { 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 { public void testPointerToFunctionType() throws Exception {
assertDeclarationCount(pdom, "int2intPtr", 1); 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); assertEquals(1, b.length);
assertInstance(b[0], ICPPVariable.class); assertInstance(b[0], ICPPVariable.class);
ICPPVariable v= (ICPPVariable) b[0]; ICPPVariable v= (ICPPVariable) b[0];
@ -103,11 +102,11 @@ public class CPPFunctionTests extends PDOMTestBase {
assertEquals(1, bindings.length); assertEquals(1, bindings.length);
ICPPFunction function = (ICPPFunction) bindings[0]; ICPPFunction function = (ICPPFunction) bindings[0];
IParameter[] parameters = function.getParameters(); 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("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("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()); assertEquals("p3", parameters[2].getName());
} }
@ -127,7 +126,7 @@ public class CPPFunctionTests extends PDOMTestBase {
} }
public void testStaticCPPFunction() throws Exception { 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"); IBinding[] bindings = findUnqualifiedName(pdom, "staticCPPFunction");
assertEquals(1, bindings.length); assertEquals(1, bindings.length);
assertTrue(((ICPPFunction) bindings[0]).isStatic()); assertTrue(((ICPPFunction) bindings[0]).isStatic());

View file

@ -6,10 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* IBM Corporation * IBM Corporation
* Symbian - Fix a race condition (157992) * Symbian - Fix a race condition (157992)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests; package org.eclipse.cdt.internal.pdom.tests;
@ -55,7 +55,6 @@ import org.eclipse.ui.wizards.datatransfer.ImportOperation;
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public class PDOMTestBase extends BaseTestCase { public class PDOMTestBase extends BaseTestCase {
protected static final IProgressMonitor PROGRESS = new NullProgressMonitor(); protected static final IProgressMonitor PROGRESS = new NullProgressMonitor();
static IPath rootPath = new Path("resources/pdomtests"); static IPath rootPath = new Path("resources/pdomtests");
private String projectName= null; private String projectName= null;
@ -100,7 +99,7 @@ public class PDOMTestBase extends BaseTestCase {
mj.join(); mj.join();
// Index the project // Index the project
CCorePlugin.getIndexManager().setIndexerId(cprojects[0], IPDOMManager.ID_FAST_INDEXER); CCorePlugin.getIndexManager().setIndexerId(cprojects[0], IPDOMManager.ID_FAST_INDEXER);
// wait until the indexer is done // Wait until the indexer is done
try { try {
waitForIndexer(cprojects[0]); waitForIndexer(cprojects[0]);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -210,8 +209,6 @@ public class PDOMTestBase extends BaseTestCase {
assertEquals(visibility, member.getVisibility()); assertEquals(visibility, member.getVisibility());
} }
public static final void assertFunctionRefCount(PDOM pdom, Class[] args, IBinding[] bindingPool, int refCount) throws CoreException { public static final void assertFunctionRefCount(PDOM pdom, Class[] args, IBinding[] bindingPool, int refCount) throws CoreException {
IBinding[] bindings = findIFunctions(args, bindingPool); IBinding[] bindings = findIFunctions(args, bindingPool);
assertEquals(1, bindings.length); assertEquals(1, bindings.length);
@ -223,16 +220,16 @@ public class PDOMTestBase extends BaseTestCase {
public static IBinding[] findIFunctions(Class[] paramTypes, IBinding[] bindings) throws CoreException { public static IBinding[] findIFunctions(Class[] paramTypes, IBinding[] bindings) throws CoreException {
List preresult = new ArrayList(); List preresult = new ArrayList();
for (IBinding binding : bindings) { for (IBinding binding : bindings) {
if(binding instanceof IFunction) { if (binding instanceof IFunction) {
IFunction function = (IFunction) binding; IFunction function = (IFunction) binding;
IType[] candidate = function.getType().getParameterTypes(); IType[] candidate = function.getType().getParameterTypes();
boolean areEqual = candidate.length == paramTypes.length; boolean areEqual = candidate.length == paramTypes.length;
for(int j=0; areEqual && j<paramTypes.length; j++) { for (int j= 0; areEqual && j < paramTypes.length; j++) {
if(!paramTypes[j].isAssignableFrom(candidate[j].getClass())) { if (!paramTypes[j].isAssignableFrom(candidate[j].getClass())) {
areEqual = false; areEqual = false;
} }
} }
if(areEqual) { if (areEqual) {
preresult.add(binding); preresult.add(binding);
} }
} }
@ -242,7 +239,7 @@ public class PDOMTestBase extends BaseTestCase {
protected void assertInstance(Object o, Class c) { protected void assertInstance(Object o, Class c) {
assertNotNull(o); assertNotNull(o);
assertTrue("Expected "+c.getName()+" but got "+o.getClass().getName(), c.isInstance(o)); assertTrue("Expected " + c.getName() + " but got " + o.getClass().getName(), c.isInstance(o));
} }
public static Pattern[] makePatternArray(String[] args) { public static Pattern[] makePatternArray(String[] args) {

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.testplugin.util; package org.eclipse.cdt.core.testplugin.util;
@ -45,9 +45,9 @@ import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
public class BaseTestCase extends TestCase { public class BaseTestCase extends TestCase {
private boolean fExpectFailure= false; private boolean fExpectFailure;
private int fBugnumber= 0; private int fBugNumber;
private int fExpectedLoggedNonOK= 0; private int fExpectedLoggedNonOK;
public BaseTestCase() { public BaseTestCase() {
super(); super();
@ -213,8 +213,8 @@ public class BaseTestCase extends TestCase {
} }
} else if (r.errorCount() == 0 && r.failureCount() == 0) { } else if (r.errorCount() == 0 && r.failureCount() == 0) {
String err = "Unexpected success of " + getName(); String err = "Unexpected success of " + getName();
if (fBugnumber > 0) { if (fBugNumber > 0) {
err += ", bug #" + fBugnumber; err += ", bug #" + fBugNumber;
} }
result.addFailure(this, new AssertionFailedError(err)); result.addFailure(this, new AssertionFailedError(err));
} }
@ -222,9 +222,9 @@ public class BaseTestCase extends TestCase {
result.endTest(this); result.endTest(this);
} }
public void setExpectFailure(int bugnumber) { public void setExpectFailure(int bugNumber) {
fExpectFailure= true; fExpectFailure= true;
fBugnumber= bugnumber; fBugNumber= bugNumber;
} }
/** /**

View file

@ -6,18 +6,17 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Mike Kucera (IBM) - Initial API and implementation * Mike Kucera (IBM) - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
/** /**
* An implicit name generated on demand. * An AST node that may have implicit names.
* @since 5.1 * @since 5.1
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTImplicitNameOwner extends IASTNode { public interface IASTImplicitNameOwner extends IASTNode {
public static final ASTNodeProperty IMPLICIT_NAME = public static final ASTNodeProperty IMPLICIT_NAME =
new ASTNodeProperty("ICPPASTImplicitNameOwner.IMPLICIT_NAME"); //$NON-NLS-1$ new ASTNodeProperty("ICPPASTImplicitNameOwner.IMPLICIT_NAME"); //$NON-NLS-1$

View file

@ -10,7 +10,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
/** /**
* This represents a function in the program. A function is also a scope * This represents a function in the program. A function is also a scope
* for other bindings. * 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. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IFunction extends IBinding { public interface IFunction extends IBinding {
/** /**
* Returns the formal parameters of the function. * Returns the formal parameters of the function.
*/ */
public IParameter[] getParameters(); public IParameter[] getParameters();
/** /**
* Get the function scope * Returns the function scope
*/ */
public IScope getFunctionScope(); public IScope getFunctionScope();
/** /**
* Get the IFunctionType for this function * Returns the IFunctionType for this function
*/ */
public IFunctionType getType(); public IFunctionType getType();

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Niefer (IBM Corporation) - initial API and implementation * Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; 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. * @noextend This interface is not intended to be extended by clients.
*/ */
public interface ICPPFunction extends IFunction, ICPPBinding { 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(); public boolean isMutable();
/** /**
* is this an inline function * Is this an inline function
*/ */
@Override @Override
public boolean isInline(); public boolean isInline();

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* John Camelon (IBM Rational Software) - Initial API and implementation * John Camelon (IBM Rational Software) - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
@ -16,7 +16,6 @@ package org.eclipse.cdt.core.parser;
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IToken { public interface IToken {
// getters // getters
public int getType(); public int getType();
public String getImage(); public String getImage();
@ -27,19 +26,17 @@ public interface IToken {
public IToken getNext(); public IToken getNext();
public void setNext(IToken t); public void setNext(IToken t);
public void setType(int i); public void setType(int i);
// Token types // Token types
int FIRST_RESERVED_PREPROCESSOR= -200; int FIRST_RESERVED_PREPROCESSOR= -200;
int LAST_RESERVED_PREPROCESSOR= -101; int LAST_RESERVED_PREPROCESSOR= -101;
int FIRST_RESERVED_SCANNER= -100; int FIRST_RESERVED_SCANNER= -100;
int LAST_RESERVED_SCANNER= -1; int LAST_RESERVED_SCANNER= -1;
/** @since 5.2 */ /** @since 5.2 */
int t_PRAGMA = 5200; int t_PRAGMA = 5200;
int tIDENTIFIER = 1; int tIDENTIFIER = 1;
int tINTEGER = 2; int tINTEGER = 2;
int tCOLONCOLON = 3; int tCOLONCOLON = 3;

View file

@ -12,22 +12,24 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.util; package org.eclipse.cdt.core.parser.util;
import java.util.Arrays;
/** /**
* A static utility class for char arrays * A static utility class for char arrays
* @author dschaefe * @author dschaefe
*
*/ */
public class CharArrayUtils { public class CharArrayUtils {
public static final char[] EMPTY = new char[0]; public static final char[] EMPTY = {};
private CharArrayUtils() {} private CharArrayUtils() {}
public static final int hash(char[] str, int start, int length) { public static final int hash(char[] str, int start, int length) {
int h = 0; int h = 0;
int end = start + length; int end = start + length;
for (int curr = start; curr < end; ++curr) for (int curr = start; curr < end; ++curr) {
h += (h << 3) + str[curr]; h += (h << 3) + str[curr];
}
return h; return h;
} }
@ -35,19 +37,9 @@ public class CharArrayUtils {
public static final int hash(char[] str) { public static final int hash(char[] str) {
return hash(str, 0, str.length); return hash(str, 0, str.length);
} }
public static final boolean equals(char[] str1, char[] str2) { public static final boolean equals(char[] str1, char[] str2) {
if (str1 == str2) return Arrays.equals(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;
} }
public static final boolean equals(char[][] strarr1, char[][] strarr2) { public static final boolean equals(char[][] strarr1, char[][] strarr2) {
@ -55,7 +47,7 @@ public class CharArrayUtils {
return false; return false;
} }
for (int i = 0; i < strarr2.length; i++) { for (int i = 0; i < strarr2.length; i++) {
if (!equals(strarr1[i], strarr2[i])) { if (!Arrays.equals(strarr1[i], strarr2[i])) {
return false; return false;
} }
} }
@ -65,64 +57,65 @@ public class CharArrayUtils {
/** /**
* Implements a lexicographical comparator for char arrays. Comparison is done * Implements a lexicographical comparator for char arrays. Comparison is done
* on a per char basis, not a code-point basis. * on a per char basis, not a code-point basis.
* *
* @param str1 the first of the two char arrays to compare * @param str1 the first of the two char arrays to compare
* @param str2 the second 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 &lt; str2 and 1 if str1 &gt; str2 * @return 0 if str1==str2, -1 if str1 &lt; str2 and 1 if str1 &gt; str2
*/ */
/* /*
* aftodo - we should think about using the Character codepoint static methods * aftodo - we should think about using the Character codepoint static methods
* if we move to Java 5 * if we move to Java 5
*/ */
public static final int compare(char[] str1, char[] str2) { public static final int compare(char[] str1, char[] str2) {
if (str1 == str2) if (str1 == str2)
return 0; return 0;
int end= Math.min(str1.length, str2.length); int end= Math.min(str1.length, str2.length);
for (int i = 0; i < end; ++i) { for (int i = 0; i < end; ++i) {
int diff= str1[i] - str2[i]; int diff= str1[i] - str2[i];
if (diff != 0) if (diff != 0)
return diff; return diff;
} }
return str1.length - str2.length; return str1.length - str2.length;
} }
public static final boolean equals(char[] str1, int start1, int length1, char[] str2) { 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; return false;
if( str1 == str2 && start1 == 0 ) if (str1 == str2 && start1 == 0)
return true; return true;
for (int i = 0; i < length1; ++i) for (int i = 0; i < length1; ++i) {
if (str1[start1++] != str2[i]) if (str1[start1++] != str2[i])
return false; return false;
}
return true; return true;
} }
public static final boolean equals(char[] str1, int start1, int length1, char[] str2, boolean ignoreCase ) { public static final boolean equals(char[] str1, int start1, int length1, char[] str2, boolean ignoreCase) {
if( !ignoreCase ) if (!ignoreCase)
return equals( str1, start1, length1, str2 ); return equals(str1, start1, length1, str2);
if (length1 != str2.length || str1.length < start1 + length1 ) if (length1 != str2.length || str1.length < start1 + length1)
return false; return false;
for (int i = 0; i < length1; ++i) for (int i = 0; i < length1; ++i) {
if( Character.toLowerCase(str1[start1++]) != Character.toLowerCase( str2[i] ) ) if (Character.toLowerCase(str1[start1++]) != Character.toLowerCase(str2[i]))
return false; return false;
}
return true; return true;
} }
public static final char[] extract(char[] str, int start, int length) { public static final char[] extract(char[] str, int start, int length) {
if (start == 0 && length == str.length) if (start == 0 && length == str.length)
return str; return str;
char[] copy = new char[length]; char[] copy = new char[length];
System.arraycopy(str, start, copy, 0, length); System.arraycopy(str, start, copy, 0, length);
return copy; return copy;
} }
public static final char[] concat(char[] first, char[] second) { public static final char[] concat(char[] first, char[] second) {
if (first == null) if (first == null)
return second; return second;
@ -136,12 +129,8 @@ public class CharArrayUtils {
System.arraycopy(second, 0, result, length1, length2); System.arraycopy(second, 0, result, length1, length2);
return result; 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 max = array.length;
int replacedLength = toBeReplaced.length; int replacedLength = toBeReplaced.length;
int replacementLength = replacementChars.length; int replacementLength = replacementChars.length;
@ -150,8 +139,7 @@ public class CharArrayUtils {
int occurrenceCount = 0; int occurrenceCount = 0;
if (!equals(toBeReplaced, replacementChars)) { if (!equals(toBeReplaced, replacementChars)) {
next: for (int i = 0; i < max; i++) {
next : for (int i = 0; i < max; i++) {
int j = 0; int j = 0;
while (j < replacedLength) { while (j < replacedLength) {
if (i + j == max) if (i + j == max)
@ -160,21 +148,15 @@ public class CharArrayUtils {
continue next; continue next;
} }
if (occurrenceCount == starts.length) { if (occurrenceCount == starts.length) {
System.arraycopy( System.arraycopy(starts, 0, starts = new int[occurrenceCount * 2], 0,
starts, occurrenceCount);
0,
starts = new int[occurrenceCount * 2],
0,
occurrenceCount);
} }
starts[occurrenceCount++] = i; starts[occurrenceCount++] = i;
} }
} }
if (occurrenceCount == 0) if (occurrenceCount == 0)
return array; return array;
char[] result = char[] result = new char[max + occurrenceCount * (replacementLength - replacedLength)];
new char[max
+ occurrenceCount * (replacementLength - replacedLength)];
int inStart = 0, outStart = 0; int inStart = 0, outStart = 0;
for (int i = 0; i < occurrenceCount; i++) { for (int i = 0; i < occurrenceCount; i++) {
int offset = starts[i] - inStart; int offset = starts[i] - inStart;
@ -223,50 +205,55 @@ public class CharArrayUtils {
System.arraycopy(array, start, result, 0, end - start); System.arraycopy(array, start, result, 0, end - start);
return result; return result;
} }
public static final int indexOf(char toBeFound, char[] array) { 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]) if (toBeFound == array[i])
return 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 )
return -1;
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 )
return -1;
int j = 0;
for( int i = 0; i < array.length; i++ ){
if( toBeFound[j] == array[i] ){
if( ++j == toBeFound.length )
return i - j + 1;
}
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 )
return i;
} else j = toBeFound.length - 1;
} }
return -1; return -1;
} }
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++) {
if (toBeFound == buffer[i])
return i;
}
return -1;
}
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)
return i - j + 1;
} 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)
return i;
} else {
j = toBeFound.length - 1;
}
}
return -1;
}
final static public char[] trim(char[] chars) { final static public char[] trim(char[] chars) {
if (chars == null) if (chars == null)
return null; return null;
@ -296,20 +283,20 @@ public class CharArrayUtils {
* @param i * @param i
* @param charImage * @param charImage
*/ */
public static void overWrite( char[] buff, int i, char[] charImage ) { public static void overWrite(char[] buff, int i, char[] charImage) {
if( buff.length < i + charImage.length ) if (buff.length < i + charImage.length)
return; return;
for( int j = 0; j < charImage.length; j++ ){ for (int j = 0; j < charImage.length; j++) {
buff[ i + j ] = charImage[j]; buff[i + j] = charImage[j];
} }
} }
/** /**
* Find an array of chars in an array of arrays of chars. * Find an array of chars in an array of arrays of chars.
* @return offset where the array was found or <code>-1</code> * @return offset where the array was found or <code>-1</code>
*/ */
public static int indexOf(final char[] searchFor, final char[][] searchIn) { 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)) { if (equals(searchIn[i], searchFor)) {
return i; return i;
} }

View file

@ -27,16 +27,15 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType;
public class CExternalFunction extends CFunction implements ICExternalBinding { public class CExternalFunction extends CFunction implements ICExternalBinding {
private static final IType VOID_TYPE = new CBasicType(Kind.eVoid, 0); private static final IType VOID_TYPE = new CBasicType(Kind.eVoid, 0);
private IASTName name = null; private IASTName name;
private IASTTranslationUnit tu = null; private IASTTranslationUnit tu;
public CExternalFunction( IASTTranslationUnit tu, IASTName name ) { public CExternalFunction(IASTTranslationUnit tu, IASTName name) {
super( null ); super(null);
this.name = name; this.name = name;
this.tu = tu; this.tu = tu;
} }
@Override @Override
public IFunctionType getType() { public IFunctionType getType() {
if (type == null) { if (type == null) {

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -41,15 +41,15 @@ import org.eclipse.core.runtime.PlatformObject;
* Represents a function. * Represents a function.
*/ */
public class CFunction extends PlatformObject implements IFunction, ICInternalFunction { public class CFunction extends PlatformObject implements IFunction, ICInternalFunction {
private IASTDeclarator[] declarators = null; private IASTDeclarator[] declarators;
private IASTFunctionDeclarator definition; private IASTFunctionDeclarator definition;
private static final int FULLY_RESOLVED = 1; private static final int FULLY_RESOLVED = 1;
private static final int RESOLUTION_IN_PROGRESS = 1 << 1; private static final int RESOLUTION_IN_PROGRESS = 1 << 1;
private int bits = 0; private int bits = 0;
protected IFunctionType type = null; protected IFunctionType type = null;
public CFunction(IASTDeclarator declarator) { public CFunction(IASTDeclarator declarator) {
storeDeclarator(declarator); storeDeclarator(declarator);
} }
@ -66,13 +66,14 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
} }
} }
} }
@Override @Override
public IASTDeclarator getPhysicalNode() { public IASTDeclarator getPhysicalNode() {
if (definition != null) if (definition != null) {
return definition; return definition;
else if (declarators != null && declarators.length > 0) } else if (declarators != null && declarators.length > 0) {
return declarators[0]; return declarators[0];
}
return null; return null;
} }
@ -86,34 +87,35 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
} }
storeDeclarator(fnDeclarator); storeDeclarator(fnDeclarator);
} }
protected IASTTranslationUnit getTranslationUnit() { protected IASTTranslationUnit getTranslationUnit() {
if( definition != null ) if (definition != null) {
return definition.getTranslationUnit(); return definition.getTranslationUnit();
else if( declarators != null ) } else if (declarators != null) {
return declarators[0].getTranslationUnit(); return declarators[0].getTranslationUnit();
}
return null; return null;
} }
private void resolveAllDeclarations(){ private void resolveAllDeclarations() {
if( (bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0 ){ if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) {
bits |= RESOLUTION_IN_PROGRESS; bits |= RESOLUTION_IN_PROGRESS;
IASTTranslationUnit tu = getTranslationUnit(); IASTTranslationUnit tu = getTranslationUnit();
if( tu != null ){ if (tu != null) {
CVisitor.getDeclarations( tu, this ); CVisitor.getDeclarations(tu, this);
} }
declarators = ArrayUtil.trim(IASTDeclarator.class, declarators); declarators = ArrayUtil.trim(IASTDeclarator.class, declarators);
bits |= FULLY_RESOLVED; bits |= FULLY_RESOLVED;
bits &= ~RESOLUTION_IN_PROGRESS; bits &= ~RESOLUTION_IN_PROGRESS;
} }
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters() * @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
*/ */
@Override @Override
public IParameter[] getParameters() { public IParameter[] getParameters() {
int j=-1; int j= -1;
int len = declarators != null ? declarators.length : 0; int len = declarators != null ? declarators.length : 0;
for (IASTDeclarator dtor = definition; j < len; j++) { for (IASTDeclarator dtor = definition; j < len; j++) {
if (j >= 0) { if (j >= 0) {
@ -131,7 +133,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
} }
} }
return result; return result;
} }
if (dtor instanceof ICASTKnRFunctionDeclarator) { if (dtor instanceof ICASTKnRFunctionDeclarator) {
IASTName[] names = ((ICASTKnRFunctionDeclarator) dtor).getParameterNames(); IASTName[] names = ((ICASTKnRFunctionDeclarator) dtor).getParameterNames();
IParameter[] result = new IParameter[names.length]; IParameter[] result = new IParameter[names.length];
@ -145,43 +147,37 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
result[i] = (IParameter) decl.getName().resolveBinding(); result[i] = (IParameter) decl.getName().resolveBinding();
} else { } else {
result[i] = new CParameter.CParameterProblem(names[i], result[i] = new CParameter.CParameterProblem(names[i],
IProblemBinding.SEMANTIC_KNR_PARAMETER_DECLARATION_NOT_FOUND, names[i] IProblemBinding.SEMANTIC_KNR_PARAMETER_DECLARATION_NOT_FOUND,
.toCharArray()); names[i].toCharArray());
} }
} }
} }
return result; return result;
} }
} }
if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) { if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) {
resolveAllDeclarations(); resolveAllDeclarations();
return getParameters(); return getParameters();
} }
return CBuiltinParameter.createParameterList(getType()); return CBuiltinParameter.createParameterList(getType());
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
@Override @Override
public String getName() { public String getName() {
return getASTName().toString(); return getASTName().toString();
} }
@Override @Override
public char[] getNameCharArray(){ public char[] getNameCharArray() {
return getASTName().toCharArray(); return getASTName().toCharArray();
} }
private IASTName getASTName() { private IASTName getASTName() {
return ASTQueries.findInnermostDeclarator(getPhysicalNode()).getName(); return ASTQueries.findInnermostDeclarator(getPhysicalNode()).getName();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
@Override @Override
public IScope getScope() { public IScope getScope() {
IASTDeclarator dtor = getPhysicalNode(); IASTDeclarator dtor = getPhysicalNode();
@ -190,9 +186,6 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#getFunctionScope()
*/
@Override @Override
public IScope getFunctionScope() { public IScope getFunctionScope() {
if (definition != null) { if (definition != null) {
@ -223,67 +216,67 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
} }
return null; return null;
} }
public IBinding resolveParameter( IASTName paramName ){ public IBinding resolveParameter(IASTName paramName) {
if( paramName.getBinding() != null ) if (paramName.getBinding() != null)
return paramName.getBinding(); return paramName.getBinding();
IBinding binding = null; IBinding binding = null;
int idx = 0; int idx = 0;
IASTNode parent = paramName.getParent(); IASTNode parent = paramName.getParent();
while( parent instanceof IASTDeclarator && !(parent instanceof ICASTKnRFunctionDeclarator ) ) while (parent instanceof IASTDeclarator && !(parent instanceof ICASTKnRFunctionDeclarator))
parent = parent.getParent(); parent = parent.getParent();
ICASTKnRFunctionDeclarator fKnRDtor = null; ICASTKnRFunctionDeclarator fKnRDtor = null;
IASTDeclarator knrParamDtor = null; IASTDeclarator knrParamDtor = null;
if( parent instanceof IASTParameterDeclaration ){ if (parent instanceof IASTParameterDeclaration) {
IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) parent.getParent(); IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) parent.getParent();
IASTParameterDeclaration [] ps = fdtor.getParameters(); IASTParameterDeclaration [] ps = fdtor.getParameters();
for( ; idx < ps.length; idx++ ){ for (; idx < ps.length; idx++) {
if( parent == ps[idx] ) if (parent == ps[idx])
break; break;
} }
} else if( parent instanceof IASTSimpleDeclaration ){ } else if (parent instanceof IASTSimpleDeclaration) {
//KnR: name in declaration list //KnR: name in declaration list
fKnRDtor = (ICASTKnRFunctionDeclarator) parent.getParent(); fKnRDtor = (ICASTKnRFunctionDeclarator) parent.getParent();
IASTName [] ps = fKnRDtor.getParameterNames(); IASTName [] ps = fKnRDtor.getParameterNames();
char [] n = paramName.toCharArray(); char [] n = paramName.toCharArray();
for( ; idx < ps.length; idx++ ){ for (; idx < ps.length; idx++) {
if( CharArrayUtils.equals( ps[idx].toCharArray(), n ) ) if (CharArrayUtils.equals(ps[idx].toCharArray(), n))
break; break;
} }
} else { } else {
//KnR: name in name list //KnR: name in name list
fKnRDtor = (ICASTKnRFunctionDeclarator) parent; fKnRDtor = (ICASTKnRFunctionDeclarator) parent;
IASTName [] ps = fKnRDtor.getParameterNames(); IASTName [] ps = fKnRDtor.getParameterNames();
for( ; idx < ps.length; idx++ ){ for (; idx < ps.length; idx++) {
if( ps[idx] == paramName) if (ps[idx] == paramName)
break; break;
} }
knrParamDtor = CVisitor.getKnRParameterDeclarator( fKnRDtor, paramName ); knrParamDtor = CVisitor.getKnRParameterDeclarator(fKnRDtor, paramName);
if( knrParamDtor != null ) if (knrParamDtor != null)
paramName = knrParamDtor.getName(); paramName = knrParamDtor.getName();
} }
//create a new binding and set it for the corresponding parameter in all known defns and decls //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; IASTParameterDeclaration temp = null;
if( definition != null ){ if (definition != null) {
if( definition instanceof IASTStandardFunctionDeclarator ){ if (definition instanceof IASTStandardFunctionDeclarator) {
IASTParameterDeclaration [] parameters = ((IASTStandardFunctionDeclarator)definition).getParameters(); IASTParameterDeclaration [] parameters = ((IASTStandardFunctionDeclarator)definition).getParameters();
if( parameters.length > idx ) { if (parameters.length > idx) {
temp = parameters[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; fKnRDtor = (ICASTKnRFunctionDeclarator) definition;
IASTName [] parameterNames = fKnRDtor.getParameterNames(); IASTName [] parameterNames = fKnRDtor.getParameterNames();
if( parameterNames.length > idx ) { if (parameterNames.length > idx) {
IASTName n = parameterNames[idx]; IASTName n = parameterNames[idx];
n.setBinding( binding ); n.setBinding(binding);
IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator( fKnRDtor, n ); IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator(fKnRDtor, n);
if( dtor != null ){ if (dtor != null) {
dtor.getName().setBinding( binding ); dtor.getName().setBinding(binding);
} }
} }
} }
@ -292,159 +285,153 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
for (IASTDeclarator dtor : declarators) { for (IASTDeclarator dtor : declarators) {
if (dtor instanceof IASTStandardFunctionDeclarator) { if (dtor instanceof IASTStandardFunctionDeclarator) {
IASTStandardFunctionDeclarator fdtor= (IASTStandardFunctionDeclarator) dtor; IASTStandardFunctionDeclarator fdtor= (IASTStandardFunctionDeclarator) dtor;
if( fdtor.getParameters().length > idx ){ if (fdtor.getParameters().length > idx) {
temp = fdtor.getParameters()[idx]; temp = fdtor.getParameters()[idx];
ASTQueries.findInnermostDeclarator(temp.getDeclarator()).getName().setBinding( binding ); ASTQueries.findInnermostDeclarator(temp.getDeclarator()).getName().setBinding(binding);
} }
} }
} }
} }
return binding; return binding;
} }
protected void updateParameterBindings(IASTFunctionDeclarator fdtor) {
protected void updateParameterBindings( IASTFunctionDeclarator fdtor ){
IParameter [] params = getParameters(); IParameter [] params = getParameters();
if( fdtor instanceof IASTStandardFunctionDeclarator ){ if (fdtor instanceof IASTStandardFunctionDeclarator) {
IASTParameterDeclaration [] nps = ((IASTStandardFunctionDeclarator)fdtor).getParameters(); IASTParameterDeclaration [] nps = ((IASTStandardFunctionDeclarator)fdtor).getParameters();
if(params.length < nps.length ) if (params.length < nps.length)
return; return;
for( int i = 0; i < nps.length; i++ ){ for (int i = 0; i < nps.length; i++) {
IASTName name = ASTQueries.findInnermostDeclarator(nps[i].getDeclarator()).getName(); IASTName name = ASTQueries.findInnermostDeclarator(nps[i].getDeclarator()).getName();
name.setBinding( params[i] ); name.setBinding(params[i]);
if( params[i] instanceof CParameter ) if (params[i] instanceof CParameter)
((CParameter)params[i]).addDeclaration( name ); ((CParameter)params[i]).addDeclaration(name);
} }
} else { } else {
IASTName [] ns = ((ICASTKnRFunctionDeclarator)fdtor).getParameterNames(); IASTName [] ns = ((ICASTKnRFunctionDeclarator)fdtor).getParameterNames();
if( params.length > 0 && params.length != ns.length ) if (params.length > 0 && params.length != ns.length)
return; //problem return; //problem
for( int i = 0; i < params.length; i++ ){ for (int i = 0; i < params.length; i++) {
IASTName name = ns[i]; IASTName name = ns[i];
name.setBinding( params[i] ); name.setBinding(params[i]);
IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator( (ICASTKnRFunctionDeclarator) fdtor, name ); IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator((ICASTKnRFunctionDeclarator) fdtor, name);
if( dtor != null ){ if (dtor != null) {
dtor.getName().setBinding( params[i] ); dtor.getName().setBinding(params[i]);
if( params[i] instanceof CParameter ) if (params[i] instanceof CParameter)
((CParameter)params[i]).addDeclaration( dtor.getName() ); ((CParameter)params[i]).addDeclaration(dtor.getName());
} }
} }
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/
@Override @Override
public boolean isStatic() { public boolean isStatic() {
return isStatic(true); return isStatic(true);
} }
@Override @Override
public boolean isStatic(boolean resolveAll) { public boolean isStatic(boolean resolveAll) {
if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){ if (resolveAll && (bits & FULLY_RESOLVED) == 0) {
resolveAllDeclarations(); 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 dtor = definition;
IASTDeclarator[] ds = declarators; IASTDeclarator[] ds = declarators;
int i = -1; int i = -1;
do{ do {
if( dtor != null ){ if (dtor != null) {
IASTNode parent = dtor.getParent(); IASTNode parent = dtor.getParent();
while( !(parent instanceof IASTDeclaration) ) while (!(parent instanceof IASTDeclaration))
parent = parent.getParent(); parent = parent.getParent();
IASTDeclSpecifier declSpec = null; IASTDeclSpecifier declSpec = null;
if( parent instanceof IASTSimpleDeclaration ){ if (parent instanceof IASTSimpleDeclaration) {
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
} else if( parent instanceof IASTFunctionDefinition ) } else if (parent instanceof IASTFunctionDefinition)
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier(); declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec != null && declSpec.getStorageClass() == storage ) { if (declSpec != null && declSpec.getStorageClass() == storage) {
return true; return true;
} }
} }
if( ds != null && ++i < ds.length ) if (ds != null && ++i < ds.length) {
dtor = ds[i]; dtor = ds[i];
else } else {
break; break;
} while( dtor != null ); }
} while (dtor != null);
return false; return false;
} }
@Override @Override
public boolean isExtern() { public boolean isExtern() {
return isExtern(true); return isExtern(true);
} }
public boolean isExtern(boolean resolveAll) { public boolean isExtern(boolean resolveAll) {
if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){ if (resolveAll && (bits & FULLY_RESOLVED) == 0) {
resolveAllDeclarations(); resolveAllDeclarations();
} }
return hasStorageClass( IASTDeclSpecifier.sc_extern); return hasStorageClass(IASTDeclSpecifier.sc_extern);
} }
@Override @Override
public boolean isAuto() { public boolean isAuto() {
if( (bits & FULLY_RESOLVED) == 0 ){ if ((bits & FULLY_RESOLVED) == 0) {
resolveAllDeclarations(); resolveAllDeclarations();
} }
return hasStorageClass( IASTDeclSpecifier.sc_auto); return hasStorageClass(IASTDeclSpecifier.sc_auto);
} }
@Override @Override
public boolean isRegister() { public boolean isRegister() {
if( (bits & FULLY_RESOLVED) == 0 ){ if ((bits & FULLY_RESOLVED) == 0) {
resolveAllDeclarations(); resolveAllDeclarations();
} }
return hasStorageClass( IASTDeclSpecifier.sc_register); return hasStorageClass(IASTDeclSpecifier.sc_register);
} }
@Override @Override
public boolean isInline() { public boolean isInline() {
if( (bits & FULLY_RESOLVED) == 0 ){ if ((bits & FULLY_RESOLVED) == 0) {
resolveAllDeclarations(); resolveAllDeclarations();
} }
IASTDeclarator dtor = definition; IASTDeclarator dtor = definition;
IASTDeclarator[] ds = declarators; IASTDeclarator[] ds = declarators;
int i = -1; int i = -1;
do{ do {
if( dtor != null ){ if (dtor != null) {
IASTNode parent = dtor.getParent(); IASTNode parent = dtor.getParent();
while( !(parent instanceof IASTDeclaration) ) while (!(parent instanceof IASTDeclaration)) {
parent = parent.getParent(); parent = parent.getParent();
}
IASTDeclSpecifier declSpec = null; IASTDeclSpecifier declSpec = null;
if( parent instanceof IASTSimpleDeclaration ){ if (parent instanceof IASTSimpleDeclaration) {
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
} else if( parent instanceof IASTFunctionDefinition ) } else if (parent instanceof IASTFunctionDefinition) {
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier(); declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
}
if( declSpec != null && declSpec.isInline() )
if (declSpec != null && declSpec.isInline())
return true; return true;
} }
if( ds != null && ++i < ds.length ) if (ds != null && ++i < ds.length) {
dtor = ds[i]; dtor = ds[i];
else } else {
break; break;
} while( dtor != null ); }
} while (dtor != null);
return false; return false;
} }
@Override @Override
public boolean takesVarArgs() { public boolean takesVarArgs() {
if ((bits & FULLY_RESOLVED) == 0) { if ((bits & FULLY_RESOLVED) == 0) {
@ -469,10 +456,11 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
@Override @Override
public void setFullyResolved(boolean resolved) { public void setFullyResolved(boolean resolved) {
if( resolved ) if (resolved) {
bits |= FULLY_RESOLVED; bits |= FULLY_RESOLVED;
else } else {
bits &= ~FULLY_RESOLVED; bits &= ~FULLY_RESOLVED;
}
} }
@Override @Override
@ -489,7 +477,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
public IASTNode getDefinition() { public IASTNode getDefinition() {
return definition; return definition;
} }
@Override @Override
public IBinding getOwner() { public IBinding getOwner() {
return null; return null;

View file

@ -57,15 +57,14 @@ import org.eclipse.core.runtime.PlatformObject;
* Binding for c++ function * Binding for c++ function
*/ */
public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInternalFunction { public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInternalFunction {
protected IASTDeclarator[] declarations; protected IASTDeclarator[] declarations;
protected ICPPASTFunctionDeclarator definition; protected ICPPASTFunctionDeclarator definition;
protected ICPPFunctionType type = null; protected ICPPFunctionType type;
private static final int FULLY_RESOLVED = 1; private static final int FULLY_RESOLVED = 1;
private static final int RESOLUTION_IN_PROGRESS = 1 << 1; private static final int RESOLUTION_IN_PROGRESS = 1 << 1;
private int bits = 0; private int bits = 0;
public CPPFunction(IASTDeclarator declarator) { public CPPFunction(IASTDeclarator declarator) {
if (declarator != null) { if (declarator != null) {
IASTNode parent = ASTQueries.findOutermostDeclarator(declarator).getParent(); IASTNode parent = ASTQueries.findOutermostDeclarator(declarator).getParent();
@ -76,12 +75,12 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
} else { } else {
declarations = new IASTDeclarator[] { declarator }; declarations = new IASTDeclarator[] { declarator };
} }
IASTName name= getASTName(); IASTName name= getASTName();
name.setBinding(this); name.setBinding(this);
} }
} }
private void resolveAllDeclarations() { private void resolveAllDeclarations() {
if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) { if ((bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0) {
bits |= RESOLUTION_IN_PROGRESS; bits |= RESOLUTION_IN_PROGRESS;
@ -106,7 +105,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
bits &= ~RESOLUTION_IN_PROGRESS; bits &= ~RESOLUTION_IN_PROGRESS;
} }
} }
@Override @Override
public IASTDeclarator[] getDeclarations() { public IASTDeclarator[] getDeclarations() {
return declarations; return declarations;
@ -116,7 +115,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
public ICPPASTFunctionDeclarator getDefinition() { public ICPPASTFunctionDeclarator getDefinition() {
return definition; return definition;
} }
@Override @Override
public final void addDefinition(IASTNode node) { public final void addDefinition(IASTNode node) {
IASTDeclarator dtor = extractRelevantDtor(node); IASTDeclarator dtor = extractRelevantDtor(node);
@ -126,14 +125,14 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
definition = fdtor; definition = fdtor;
} }
} }
@Override @Override
public final void addDeclaration(IASTNode node) { public final void addDeclaration(IASTNode node) {
IASTDeclarator dtor = extractRelevantDtor(node); IASTDeclarator dtor = extractRelevantDtor(node);
if (dtor == null) { if (dtor == null) {
return; return;
} }
// function could be declared via a typedef // function could be declared via a typedef
if (dtor instanceof ICPPASTFunctionDeclarator) { if (dtor instanceof ICPPASTFunctionDeclarator) {
updateFunctionParameterBindings((ICPPASTFunctionDeclarator) dtor); updateFunctionParameterBindings((ICPPASTFunctionDeclarator) dtor);
@ -189,14 +188,14 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
resolveAllDeclarations(); resolveAllDeclarations();
if (definition != null) { if (definition != null) {
return definition.getFunctionScope(); return definition.getFunctionScope();
} }
for (IASTDeclarator dtor : declarations) { for (IASTDeclarator dtor : declarations) {
if (dtor instanceof ICPPASTFunctionDeclarator) { if (dtor instanceof ICPPASTFunctionDeclarator) {
return ((ICPPASTFunctionDeclarator) dtor).getFunctionScope(); return ((ICPPASTFunctionDeclarator) dtor).getFunctionScope();
} }
} }
// function declaration via typedef // function declaration via typedef
return null; return null;
} }
@ -210,7 +209,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
public char[] getNameCharArray() { public char[] getNameCharArray() {
return getASTName().getSimpleID(); return getASTName().getSimpleID();
} }
protected IASTName getASTName() { protected IASTName getASTName() {
IASTDeclarator dtor = (definition != null) ? definition : declarations[0]; IASTDeclarator dtor = (definition != null) ? definition : declarations[0];
dtor= ASTQueries.findInnermostDeclarator(dtor); dtor= ASTQueries.findInnermostDeclarator(dtor);
@ -231,10 +230,10 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
if (definition != null) { if (definition != null) {
IASTNode node = ASTQueries.findOutermostDeclarator(definition).getParent(); IASTNode node = ASTQueries.findOutermostDeclarator(definition).getParent();
IASTFunctionDefinition def = (IASTFunctionDefinition) node; IASTFunctionDefinition def = (IASTFunctionDefinition) node;
declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier(); declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier();
} else { } else {
IASTNode node = ASTQueries.findOutermostDeclarator(declarations[0]).getParent(); IASTNode node = ASTQueries.findOutermostDeclarator(declarations[0]).getParent();
IASTSimpleDeclaration decl = (IASTSimpleDeclaration)node; IASTSimpleDeclaration decl = (IASTSimpleDeclaration)node;
declSpec = (ICPPASTDeclSpecifier) decl.getDeclSpecifier(); declSpec = (ICPPASTDeclSpecifier) decl.getDeclSpecifier();
} }
if (declSpec.isFriend()) { if (declSpec.isFriend()) {
@ -268,7 +267,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
@Override @Override
public IBinding resolveParameter(CPPParameter param) { public IBinding resolveParameter(CPPParameter param) {
int pos= param.getParameterPosition(); int pos= param.getParameterPosition();
int tdeclLen= declarations == null ? 0 : declarations.length; int tdeclLen= declarations == null ? 0 : declarations.length;
for (int i= -1; i < tdeclLen; i++) { for (int i= -1; i < tdeclLen; i++) {
ICPPASTFunctionDeclarator tdecl; ICPPASTFunctionDeclarator tdecl;
@ -286,7 +285,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
} }
tdecl= (ICPPASTFunctionDeclarator) dtor; tdecl= (ICPPASTFunctionDeclarator) dtor;
} }
IASTParameterDeclaration[] params = tdecl.getParameters(); IASTParameterDeclaration[] params = tdecl.getParameters();
if (pos < params.length) { if (pos < params.length) {
final IASTName oName = getParamName(params[pos]); final IASTName oName = getParamName(params[pos]);
@ -299,7 +298,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
private IASTName getParamName(final IASTParameterDeclaration paramDecl) { private IASTName getParamName(final IASTParameterDeclaration paramDecl) {
return ASTQueries.findInnermostDeclarator(paramDecl.getDeclarator()).getName(); return ASTQueries.findInnermostDeclarator(paramDecl.getDeclarator()).getName();
} }
protected final void updateFunctionParameterBindings(ICPPASTFunctionDeclarator fdtor) { protected final void updateFunctionParameterBindings(ICPPASTFunctionDeclarator fdtor) {
IASTParameterDeclaration[] updateParams = fdtor.getParameters(); IASTParameterDeclaration[] updateParams = fdtor.getParameters();
@ -321,7 +320,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
} }
tdecl= (ICPPASTFunctionDeclarator) dtor; tdecl= (ICPPASTFunctionDeclarator) dtor;
} }
IASTParameterDeclaration[] params = tdecl.getParameters(); IASTParameterDeclaration[] params = tdecl.getParameters();
int end= Math.min(params.length, updateParams.length); int end= Math.min(params.length, updateParams.length);
for (; k < end; k++) { for (; k < end; k++) {
@ -352,7 +351,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
// //least significant = whether or not we are static // //least significant = whether or not we are static
// int state = (bits & IS_STATIC) >> 2; // int state = (bits & IS_STATIC) >> 2;
// if (state > 1) return (state % 2 != 0); // if (state > 1) return (state % 2 != 0);
// //
// IASTDeclSpecifier declSpec = null; // IASTDeclSpecifier declSpec = null;
// IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) getDefinition(); // IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) getDefinition();
// if (dtor != null) { // if (dtor != null) {
@ -362,7 +361,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
// return true; // return true;
// } // }
// } // }
// //
// IASTFunctionDeclarator[] dtors = (IASTFunctionDeclarator[]) getDeclarations(); // IASTFunctionDeclarator[] dtors = (IASTFunctionDeclarator[]) getDeclarations();
// if (dtors != null) { // if (dtors != null) {
// for (int i = 0; i < dtors.length; i++) { // for (int i = 0; i < dtors.length; i++) {
@ -377,7 +376,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
// bits |= 2 << 2; // bits |= 2 << 2;
// return false; // return false;
// } // }
@Override @Override
public String[] getQualifiedName() { public String[] getQualifiedName() {
return CPPVisitor.getQualifiedName(this); return CPPVisitor.getQualifiedName(this);
@ -409,7 +408,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
IASTNode parent = dtor.getParent(); IASTNode parent = dtor.getParent();
while (!(parent instanceof IASTDeclaration)) while (!(parent instanceof IASTDeclaration))
parent = parent.getParent(); parent = parent.getParent();
IASTDeclSpecifier declSpec = null; IASTDeclSpecifier declSpec = null;
if (parent instanceof IASTSimpleDeclaration) { if (parent instanceof IASTSimpleDeclaration) {
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
@ -428,7 +427,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
} while (dtor != null); } while (dtor != null);
return false; return false;
} }
@Override @Override
public boolean isDeleted() { public boolean isDeleted() {
return isDeletedDefinition(getDefinition()); return isDeletedDefinition(getDefinition());
@ -459,13 +458,13 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
IASTNode parent = dtor.getParent(); IASTNode parent = dtor.getParent();
while (!(parent instanceof IASTDeclaration)) while (!(parent instanceof IASTDeclaration))
parent = parent.getParent(); parent = parent.getParent();
IASTDeclSpecifier declSpec = null; IASTDeclSpecifier declSpec = null;
if (parent instanceof IASTSimpleDeclaration) if (parent instanceof IASTSimpleDeclaration)
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
else if (parent instanceof IASTFunctionDefinition) else if (parent instanceof IASTFunctionDefinition)
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier(); declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if (declSpec != null && declSpec.isInline()) if (declSpec != null && declSpec.isInline())
return true; return true;
} }
@ -513,12 +512,12 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
ICPPASTFunctionDeclarator dtor= getPreferredDtor(); ICPPASTFunctionDeclarator dtor= getPreferredDtor();
return dtor != null ? dtor.takesVarArgs() : false; return dtor != null ? dtor.takesVarArgs() : false;
} }
@Override @Override
public ILinkage getLinkage() { public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE; return Linkage.CPP_LINKAGE;
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder result = new StringBuilder(); 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$ result.append(t != null ? ASTTypeUtil.getParameterTypeString(t) : "()"); //$NON-NLS-1$
return result.toString(); return result.toString();
} }
@Override @Override
public IBinding getOwner() { public IBinding getOwner() {
return CPPVisitor.findNameOwner(getASTName(), false); return CPPVisitor.findNameOwner(getASTName(), false);
@ -538,12 +537,12 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
ICPPASTFunctionDeclarator declarator = getPreferredDtor(); ICPPASTFunctionDeclarator declarator = getPreferredDtor();
if (declarator != null) { if (declarator != null) {
IASTTypeId[] astTypeIds= declarator.getExceptionSpecification(); IASTTypeId[] astTypeIds= declarator.getExceptionSpecification();
if (astTypeIds.equals(ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION)) if (astTypeIds.equals(ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION))
return null; return null;
if (astTypeIds.equals(IASTTypeId.EMPTY_TYPEID_ARRAY)) if (astTypeIds.equals(IASTTypeId.EMPTY_TYPEID_ARRAY))
return IType.EMPTY_TYPE_ARRAY; return IType.EMPTY_TYPE_ARRAY;
IType[] typeIds = new IType[astTypeIds.length]; IType[] typeIds = new IType[astTypeIds.length];
for (int i= 0; i < astTypeIds.length; ++i) { for (int i= 0; i < astTypeIds.length; ++i) {
typeIds[i] = CPPVisitor.createType(astTypeIds[i]); typeIds[i] = CPPVisitor.createType(astTypeIds[i]);
@ -552,16 +551,16 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
} }
return null; return null;
} }
protected ICPPASTFunctionDeclarator getPreferredDtor() { protected ICPPASTFunctionDeclarator getPreferredDtor() {
ICPPASTFunctionDeclarator dtor = getDefinition(); ICPPASTFunctionDeclarator dtor = getDefinition();
if (dtor != null) if (dtor != null)
return dtor; return dtor;
IASTDeclarator[] dtors = getDeclarations(); IASTDeclarator[] dtors = getDeclarations();
if (dtors != null) { if (dtors != null) {
for (IASTDeclarator declarator : dtors) { for (IASTDeclarator declarator : dtors) {
if (declarator instanceof ICPPASTFunctionDeclarator) if (declarator instanceof ICPPASTFunctionDeclarator)
return (ICPPASTFunctionDeclarator) declarator; return (ICPPASTFunctionDeclarator) declarator;
} }
} }
@ -575,8 +574,8 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
public static int getRequiredArgumentCount(ICPPParameter[] pars) { public static int getRequiredArgumentCount(ICPPParameter[] pars) {
int result= pars.length; int result= pars.length;
while(result > 0) { while (result > 0) {
final ICPPParameter p = pars[result-1]; final ICPPParameter p = pars[result - 1];
if (p.hasDefaultValue() || p.isParameterPack()) { if (p.hasDefaultValue() || p.isParameterPack()) {
result--; result--;
} else { } else {
@ -592,6 +591,6 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
@Override @Override
public boolean hasParameterPack() { public boolean hasParameterPack() {
ICPPParameter[] pars= getParameters(); ICPPParameter[] pars= getParameters();
return pars.length > 0 && pars[pars.length-1].isParameterPack(); return pars.length > 0 && pars[pars.length - 1].isParameterPack();
} }
} }

View file

@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Niefer (IBM) - Initial API and implementation * Andrew Niefer (IBM) - Initial API and implementation
* Bryan Wilkinson (QNX) * Bryan Wilkinson (QNX)
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; 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. * also used as base class for function instances.
*/ */
public class CPPFunctionSpecialization extends CPPSpecialization implements ICPPFunction, ICPPInternalFunction { public class CPPFunctionSpecialization extends CPPSpecialization implements ICPPFunction, ICPPInternalFunction {
private ICPPFunctionType type = null; private ICPPFunctionType type;
private ICPPParameter[] fParams = null; private ICPPParameter[] fParams;
private IType[] specializedExceptionSpec = null; private IType[] specializedExceptionSpec;
private final ICPPClassSpecialization fContext; private final ICPPClassSpecialization fContext;
public CPPFunctionSpecialization(ICPPFunction orig, IBinding owner, ICPPTemplateParameterMap argMap) { public CPPFunctionSpecialization(ICPPFunction orig, IBinding owner, ICPPTemplateParameterMap argMap) {
@ -139,7 +139,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
IASTNode def = getDefinition(); IASTNode def = getDefinition();
while (!(def instanceof IASTFunctionDefinition)) while (!(def instanceof IASTFunctionDefinition))
def = def.getParent(); def = def.getParent();
return ((IASTFunctionDefinition)def).getDeclSpecifier().isInline(); return ((IASTFunctionDefinition) def).getDeclSpecifier().isInline();
} }
return getFunction().isInline(); return getFunction().isInline();
} }
@ -156,12 +156,13 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
public boolean isStatic() { public boolean isStatic() {
return isStatic(true); return isStatic(true);
} }
@Override @Override
public boolean isStatic(boolean resolveAll) { public boolean isStatic(boolean resolveAll) {
//TODO resolveAll //TODO resolveAll
IBinding f = getSpecializedBinding(); IBinding f = getSpecializedBinding();
if (f instanceof ICPPInternalFunction) if (f instanceof ICPPInternalFunction)
return ((ICPPInternalFunction)f).isStatic(resolveAll); return ((ICPPInternalFunction) f).isStatic(resolveAll);
if (f instanceof IIndexBinding && f instanceof ICPPFunction) { if (f instanceof IIndexBinding && f instanceof ICPPFunction) {
return ((ICPPFunction) f).isStatic(); return ((ICPPFunction) f).isStatic();
} }
@ -325,8 +326,8 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
IType[] types = function.getExceptionSpecification(); IType[] types = function.getExceptionSpecification();
if (types != null) { if (types != null) {
IType[] specializedTypeList = new IType[types.length]; IType[] specializedTypeList = new IType[types.length];
int j=0; int j= 0;
for (int i=0; i<types.length; ++i) { for (int i= 0; i < types.length; ++i) {
final IType origType = types[i]; final IType origType = types[i];
if (origType instanceof ICPPParameterPackType) { if (origType instanceof ICPPParameterPackType) {
IType[] specialized= specializeTypePack((ICPPParameterPackType) origType); IType[] specialized= specializeTypePack((ICPPParameterPackType) origType);

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Niefer (IBM) - Initial API and implementation * Andrew Niefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -45,8 +45,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
*/ */
public class CPPFunctionTemplate extends CPPTemplateDefinition public class CPPFunctionTemplate extends CPPTemplateDefinition
implements ICPPFunctionTemplate, ICPPInternalFunction { implements ICPPFunctionTemplate, ICPPInternalFunction {
protected ICPPFunctionType type;
protected ICPPFunctionType type = null;
public CPPFunctionTemplate(IASTName name) { public CPPFunctionTemplate(IASTName name) {
super(name); super(name);
@ -143,7 +142,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition
while (parent.getParent() instanceof IASTDeclarator) while (parent.getParent() instanceof IASTDeclarator)
parent = parent.getParent(); parent = parent.getParent();
IType t = getNestedType(CPPVisitor.createType((IASTDeclarator)parent), TDEF); IType t = getNestedType(CPPVisitor.createType((IASTDeclarator) parent), TDEF);
if (t instanceof ICPPFunctionType) { if (t instanceof ICPPFunctionType) {
type = (ICPPFunctionType) t; type = (ICPPFunctionType) t;
} else if (t instanceof ISemanticProblem){ } else if (t instanceof ISemanticProblem){
@ -171,10 +170,11 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition
return true; return true;
} }
} }
if (ns != null && ++i < ns.length) if (ns != null && ++i < ns.length) {
name = (IASTName) ns[i]; name = (IASTName) ns[i];
else } else {
break; break;
}
} while (name != null); } while (name != null);
return false; return false;
} }
@ -284,11 +284,12 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition
if (declSpec != null && declSpec.isInline()) if (declSpec != null && declSpec.isInline())
return true; return true;
} }
if (ns != null && ++i < ns.length) if (ns != null && ++i < ns.length) {
name = (IASTName) ns[i]; name = (IASTName) ns[i];
else } else {
break; break;
} while(name != null); }
} while (name != null);
return false; return false;
} }
@ -338,7 +339,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition
} }
private IASTDeclarator getDeclaratorByName(IASTNode node) { private IASTDeclarator getDeclaratorByName(IASTNode node) {
// skip qualified names and nested declarators. // Skip qualified names and nested declarators.
while (node != null) { while (node != null) {
node= node.getParent(); node= node.getParent();
if (node instanceof IASTDeclarator) { if (node instanceof IASTDeclarator) {
@ -375,7 +376,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition
} }
IType[] typeIds = new IType[astTypeIds.length]; IType[] typeIds = new IType[astTypeIds.length];
for (int i=0; i<astTypeIds.length; ++i) { for (int i = 0; i < astTypeIds.length; ++i) {
typeIds[i] = CPPVisitor.createType(astTypeIds[i]); typeIds[i] = CPPVisitor.createType(astTypeIds[i]);
} }
return typeIds; return typeIds;

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.c; package org.eclipse.cdt.internal.core.index.composite.c;
@ -31,9 +31,9 @@ class CompositeCFunction extends CompositeCBinding implements IFunction {
@Override @Override
public IParameter[] getParameters() { public IParameter[] getParameters() {
IParameter[] preResult = ((IFunction)rbinding).getParameters(); IParameter[] preResult = ((IFunction) rbinding).getParameters();
IParameter[] result = new IParameter[preResult.length]; IParameter[] result = new IParameter[preResult.length];
for(int i=0; i<preResult.length; i++) { for (int i= 0; i < preResult.length; i++) {
result[i] = (IParameter) cf.getCompositeBinding((IIndexFragmentBinding) preResult[i]); result[i] = (IParameter) cf.getCompositeBinding((IIndexFragmentBinding) preResult[i]);
} }
return result; return result;
@ -41,37 +41,37 @@ class CompositeCFunction extends CompositeCBinding implements IFunction {
@Override @Override
public IFunctionType getType() { public IFunctionType getType() {
IType rtype = ((IFunction)rbinding).getType(); IType rtype = ((IFunction) rbinding).getType();
return (IFunctionType) cf.getCompositeType(rtype); return (IFunctionType) cf.getCompositeType(rtype);
} }
@Override @Override
public boolean isAuto() { public boolean isAuto() {
return ((IFunction)rbinding).isAuto(); return ((IFunction) rbinding).isAuto();
} }
@Override @Override
public boolean isExtern() { public boolean isExtern() {
return ((IFunction)rbinding).isExtern(); return ((IFunction) rbinding).isExtern();
} }
@Override @Override
public boolean isInline() { public boolean isInline() {
return ((IFunction)rbinding).isInline(); return ((IFunction) rbinding).isInline();
} }
@Override @Override
public boolean isRegister() { public boolean isRegister() {
return ((IFunction)rbinding).isRegister(); return ((IFunction) rbinding).isRegister();
} }
@Override @Override
public boolean isStatic() { public boolean isStatic() {
return ((IFunction)rbinding).isStatic(); return ((IFunction) rbinding).isStatic();
} }
@Override @Override
public boolean takesVarArgs() { public boolean takesVarArgs() {
return ((IFunction)rbinding).takesVarArgs(); return ((IFunction) rbinding).takesVarArgs();
} }
} }

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp; package org.eclipse.cdt.internal.core.index.composite.cpp;
@ -28,17 +28,17 @@ class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction {
@Override @Override
public boolean isExternC() { public boolean isExternC() {
return ((ICPPFunction)rbinding).isExternC(); return ((ICPPFunction) rbinding).isExternC();
} }
@Override @Override
public boolean isInline() { public boolean isInline() {
return ((ICPPFunction)rbinding).isInline(); return ((ICPPFunction) rbinding).isInline();
} }
@Override @Override
public boolean isMutable() { public boolean isMutable() {
return ((ICPPFunction)rbinding).isMutable(); return ((ICPPFunction) rbinding).isMutable();
} }
@Override @Override
@ -48,8 +48,8 @@ class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction {
@Override @Override
public ICPPParameter[] getParameters() { public ICPPParameter[] getParameters() {
ICPPParameter[] result = ((ICPPFunction)rbinding).getParameters(); ICPPParameter[] result = ((ICPPFunction) rbinding).getParameters();
for(int i=0; i<result.length; i++) { for (int i= 0; i < result.length; i++) {
result[i] = (ICPPParameter) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); result[i] = (ICPPParameter) cf.getCompositeBinding((IIndexFragmentBinding) result[i]);
} }
return result; return result;
@ -57,48 +57,48 @@ class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction {
@Override @Override
public ICPPFunctionType getType() { public ICPPFunctionType getType() {
IType rtype = ((ICPPFunction)rbinding).getType(); IType rtype = ((ICPPFunction) rbinding).getType();
return (ICPPFunctionType) cf.getCompositeType(rtype); return (ICPPFunctionType) cf.getCompositeType(rtype);
} }
@Override @Override
public boolean isDeleted() { public boolean isDeleted() {
return ((ICPPFunction)rbinding).isDeleted(); return ((ICPPFunction) rbinding).isDeleted();
} }
@Override @Override
public boolean isAuto() { public boolean isAuto() {
return ((ICPPFunction)rbinding).isAuto(); return ((ICPPFunction) rbinding).isAuto();
} }
@Override @Override
public boolean isExtern() { public boolean isExtern() {
return ((ICPPFunction)rbinding).isExtern(); return ((ICPPFunction) rbinding).isExtern();
} }
@Override @Override
public boolean isRegister() { public boolean isRegister() {
return ((ICPPFunction)rbinding).isRegister(); return ((ICPPFunction) rbinding).isRegister();
} }
@Override @Override
public boolean isStatic() { public boolean isStatic() {
return ((ICPPFunction)rbinding).isStatic(); return ((ICPPFunction) rbinding).isStatic();
} }
@Override @Override
public boolean takesVarArgs() { public boolean takesVarArgs() {
return ((ICPPFunction)rbinding).takesVarArgs(); return ((ICPPFunction) rbinding).takesVarArgs();
} }
@Override @Override
public int getRequiredArgumentCount() { public int getRequiredArgumentCount() {
return ((ICPPFunction)rbinding).getRequiredArgumentCount(); return ((ICPPFunction) rbinding).getRequiredArgumentCount();
} }
@Override @Override
public boolean hasParameterPack() { public boolean hasParameterPack() {
return ((ICPPFunction)rbinding).hasParameterPack(); return ((ICPPFunction) rbinding).hasParameterPack();
} }
@Override @Override
@ -108,14 +108,12 @@ class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction {
@Override @Override
public String toString() { public String toString() {
StringBuffer result = new StringBuffer(); return getName() + " " + ASTTypeUtil.getParameterTypeString(getType()); //$NON-NLS-1$
result.append(getName()+" "+ASTTypeUtil.getParameterTypeString(getType())); //$NON-NLS-1$
return result.toString();
} }
@Override @Override
public IType[] getExceptionSpecification() { public IType[] getExceptionSpecification() {
IType[] es= ((ICPPFunction)rbinding).getExceptionSpecification(); IType[] es= ((ICPPFunction) rbinding).getExceptionSpecification();
if (es == null || es.length == 0) if (es == null || es.length == 0)
return es; return es;

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
@ -48,14 +48,13 @@ public class Token implements IToken, Cloneable {
@Override @Override
final public int getLength() { final public int getLength() {
return fEndOffset-fOffset; return fEndOffset - fOffset;
} }
@Override @Override
final public IToken getNext() { final public IToken getNext() {
return fNextToken; return fNextToken;
} }
@Override @Override
final public void setType(int kind) { final public void setType(int kind) {
@ -73,8 +72,8 @@ public class Token implements IToken, Cloneable {
} }
public void shiftOffset(int shift) { public void shiftOffset(int shift) {
fOffset+= shift; fOffset += shift;
fEndOffset+= shift; fEndOffset += shift;
} }
@Override @Override

View file

@ -9,7 +9,6 @@
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c; package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
@ -24,7 +23,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
* (const, volatile). * (const, volatile).
*/ */
public class PDOMCAnnotation { public class PDOMCAnnotation {
// Storage class specifiers and function annotations // Storage class specifiers and function annotations
public static final int AUTO_OFFSET = 0; public static final int AUTO_OFFSET = 0;
public static final int EXTERN_OFFSET = 1; public static final int EXTERN_OFFSET = 1;

View file

@ -6,12 +6,11 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* IBM Corporation * IBM Corporation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c; package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
@ -32,30 +31,25 @@ import org.eclipse.core.runtime.CoreException;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
*
*/ */
class PDOMCFunction extends PDOMBinding implements IFunction { class PDOMCFunction extends PDOMBinding implements IFunction {
/** /**
* Offset of total number of function parameters (relative to the * Offset of total number of function parameters (relative to the beginning of the record).
* beginning of the record).
*/ */
public static final int NUM_PARAMS = PDOMBinding.RECORD_SIZE; public static final int NUM_PARAMS = PDOMBinding.RECORD_SIZE;
/** /**
* Offset of total number of function parameters (relative to the * Offset of total number of function parameters (relative to the beginning of the record).
* beginning of the record).
*/ */
public static final int FIRST_PARAM = NUM_PARAMS + 4; public static final int FIRST_PARAM = NUM_PARAMS + 4;
/** /**
* Offset for the type of this function (relative to * Offset for the type of this function (relative to the beginning of the record).
* the beginning of the record).
*/ */
private static final int FUNCTION_TYPE = FIRST_PARAM + Database.PTR_SIZE; private static final int FUNCTION_TYPE = FIRST_PARAM + Database.PTR_SIZE;
/** /**
* Offset of annotation information (relative to the beginning of the * Offset of annotation information (relative to the beginning of the record).
* record).
*/ */
private static final int ANNOTATIONS = FUNCTION_TYPE + Database.TYPE_SIZE; // byte private static final int ANNOTATIONS = FUNCTION_TYPE + Database.TYPE_SIZE; // byte

View file

@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Doug Schaefer (QNX) - Initial API and implementation * Doug Schaefer (QNX) - Initial API and implementation
* IBM Corporation * IBM Corporation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -37,7 +37,6 @@ import org.eclipse.core.runtime.CoreException;
* Binding for c++ functions in the index. * Binding for c++ functions in the index.
*/ */
class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverloader { class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverloader {
private static final short ANNOT_PARAMETER_PACK = 8; private static final short ANNOT_PARAMETER_PACK = 8;
private static final short ANNOT_IS_DELETED = 9; private static final short ANNOT_IS_DELETED = 9;
@ -70,8 +69,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
protected static final int EXCEPTION_SPEC = SIGNATURE_HASH + 4; // int protected static final int EXCEPTION_SPEC = SIGNATURE_HASH + 4; // int
/** /**
* Offset of annotation information (relative to the beginning of the * Offset of annotation information (relative to the beginning of the record).
* record).
*/ */
private static final int ANNOTATION = EXCEPTION_SPEC + Database.PTR_SIZE; // short private static final int ANNOTATION = EXCEPTION_SPEC + Database.PTR_SIZE; // short
@ -102,10 +100,10 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
private short getAnnotation(ICPPFunction function) { private short getAnnotation(ICPPFunction function) {
int annot= PDOMCPPAnnotation.encodeAnnotation(function) & 0xff; int annot= PDOMCPPAnnotation.encodeAnnotation(function) & 0xff;
if (function.hasParameterPack()) { if (function.hasParameterPack()) {
annot |= (1<<ANNOT_PARAMETER_PACK); annot |= (1 << ANNOT_PARAMETER_PACK);
} }
if (function.isDeleted()) { if (function.isDeleted()) {
annot |= (1<<ANNOT_IS_DELETED); annot |= (1 << ANNOT_IS_DELETED);
} }
return (short) annot; return (short) annot;
} }
@ -134,7 +132,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
newBindingRequiredArgCount= func.getRequiredArgumentCount(); newBindingRequiredArgCount= func.getRequiredArgumentCount();
fType= null; fType= null;
linkage.storeType(record+FUNCTION_TYPE, newType); linkage.storeType(record + FUNCTION_TYPE, newType);
PDOMCPPParameter oldParams= getFirstParameter(null); PDOMCPPParameter oldParams= getFirstParameter(null);
int requiredCount; int requiredCount;
@ -167,7 +165,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
db.putInt(record + REQUIRED_ARG_COUNT, requiredCount); db.putInt(record + REQUIRED_ARG_COUNT, requiredCount);
fRequiredArgCount= requiredCount; fRequiredArgCount= requiredCount;
long oldRec = db.getRecPtr(record+EXCEPTION_SPEC); long oldRec = db.getRecPtr(record + EXCEPTION_SPEC);
storeExceptionSpec(extractExceptionSpec(func)); storeExceptionSpec(extractExceptionSpec(func));
if (oldRec != 0) { if (oldRec != 0) {
PDOMCPPTypeList.clearTypes(this, oldRec); PDOMCPPTypeList.clearTypes(this, oldRec);
@ -183,7 +181,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
IType[] extractExceptionSpec(ICPPFunction binding) { IType[] extractExceptionSpec(ICPPFunction binding) {
IType[] exceptionSpec; IType[] exceptionSpec;
if (binding instanceof ICPPMethod && ((ICPPMethod) binding).isImplicit()) { if (binding instanceof ICPPMethod && ((ICPPMethod) binding).isImplicit()) {
// don't store the exception specification, compute it on demand. // Don't store the exception specification, compute it on demand.
exceptionSpec= null; exceptionSpec= null;
} else { } else {
exceptionSpec= binding.getExceptionSpecification(); exceptionSpec= binding.getExceptionSpecification();
@ -197,7 +195,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
db.putInt(record + NUM_PARAMS, params.length); db.putInt(record + NUM_PARAMS, params.length);
db.putRecPtr(record + FIRST_PARAM, 0); db.putRecPtr(record + FIRST_PARAM, 0);
PDOMCPPParameter next= null; PDOMCPPParameter next= null;
for (int i= params.length-1; i >= 0; --i) { for (int i= params.length; --i >= 0;) {
next= new PDOMCPPParameter(linkage, this, params[i], next); next= new PDOMCPPParameter(linkage, this, params[i], next);
} }
db.putRecPtr(record + FIRST_PARAM, next == null ? 0 : next.getRecord()); 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 { private void setType(ICPPFunctionType ft) throws CoreException {
fType= null; fType= null;
getLinkage().storeType(record+FUNCTION_TYPE, ft); getLinkage().storeType(record + FUNCTION_TYPE, ft);
} }
@Override @Override
@ -241,7 +239,6 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
return getBit(getAnnotation(), PDOMCAnnotation.INLINE_OFFSET); return getBit(getAnnotation(), PDOMCAnnotation.INLINE_OFFSET);
} }
@Override @Override
public int getRequiredArgumentCount() { public int getRequiredArgumentCount() {
if (fRequiredArgCount == -1) { if (fRequiredArgCount == -1) {
@ -309,7 +306,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
public final ICPPFunctionType getType() { public final ICPPFunctionType getType() {
if (fType == null) { if (fType == null) {
try { try {
fType= (ICPPFunctionType) getLinkage().loadType(record+FUNCTION_TYPE); fType= (ICPPFunctionType) getLinkage().loadType(record + FUNCTION_TYPE);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
fType= new ProblemFunctionType(ISemanticProblem.TYPE_NOT_PERSISTED); fType= new ProblemFunctionType(ISemanticProblem.TYPE_NOT_PERSISTED);
@ -385,7 +382,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
@Override @Override
public IType[] getExceptionSpecification() { public IType[] getExceptionSpecification() {
try { try {
final long rec = getPDOM().getDB().getRecPtr(record+EXCEPTION_SPEC); final long rec = getPDOM().getDB().getRecPtr(record + EXCEPTION_SPEC);
return PDOMCPPTypeList.getTypes(this, rec); return PDOMCPPTypeList.getTypes(this, rec);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Bryan Wilkinson (QNX) - Initial API and implementation * Bryan Wilkinson (QNX) - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; 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 { class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICPPFunction {
/** /**
* Offset of total number of function parameters (relative to the * Offset of total number of function parameters (relative to the beginning of the record).
* beginning of the record).
*/ */
private static final int NUM_PARAMS = PDOMCPPSpecialization.RECORD_SIZE; private static final int NUM_PARAMS = PDOMCPPSpecialization.RECORD_SIZE;
/** /**
* Offset of pointer to the first parameter of this function (relative to * Offset of pointer to the first parameter of this function (relative to the beginning
* the beginning of the record). * of the record).
*/ */
private static final int FIRST_PARAM = NUM_PARAMS + 4; private static final int FIRST_PARAM = NUM_PARAMS + 4;
/** /**
* Offset for type of this function (relative to * Offset for type of this function (relative to the beginning of the record).
* the beginning of the record).
*/ */
private static final int FUNCTION_TYPE = FIRST_PARAM + Database.PTR_SIZE; 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 protected static final int EXCEPTION_SPEC = FUNCTION_TYPE + Database.TYPE_SIZE; // int
/** /**
* Offset of annotation information (relative to the beginning of the * Offset of annotation information (relative to the beginning of the record).
* record).
*/ */
protected static final int ANNOTATION_OFFSET = EXCEPTION_SPEC + Database.PTR_SIZE; // short protected static final int ANNOTATION_OFFSET = EXCEPTION_SPEC + Database.PTR_SIZE; // short
private static final int REQUIRED_ARG_COUNT_OFFSET= ANNOTATION_OFFSET + 2; private static final int REQUIRED_ARG_COUNT_OFFSET= ANNOTATION_OFFSET + 2;
/** /**
* The size in bytes of a PDOMCPPFunction record in the database. * The size in bytes of a PDOMCPPFunction record in the database.
*/ */
@SuppressWarnings("hiding") @SuppressWarnings("hiding")
protected static final int RECORD_SIZE = REQUIRED_ARG_COUNT_OFFSET + 4; protected static final int RECORD_SIZE = REQUIRED_ARG_COUNT_OFFSET + 4;
private static final short ANNOT_PARAMETER_PACK = 8; private static final short ANNOT_PARAMETER_PACK = 8;
private static final short ANNOT_IS_DELETED = 9; private static final short ANNOT_IS_DELETED = 9;
@ -102,7 +99,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
PDOMCPPParameterSpecialization next= null; PDOMCPPParameterSpecialization next= null;
for (int i= length-1; i >= 0; --i) { for (int i= length-1; i >= 0; --i) {
// There may be fewer or less original parameters, because of parameter packs. // There may be fewer or less original parameters, because of parameter packs.
if (i < origAstParams.length-1) { if (i < origAstParams.length - 1) {
// Normal case // Normal case
origPar= new PDOMCPPParameter(linkage, specialized, origAstParams[i], null); origPar= new PDOMCPPParameter(linkage, specialized, origAstParams[i], null);
} else if (origPar == null) { } else if (origPar == null) {
@ -118,12 +115,11 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
db.putInt(record + REQUIRED_ARG_COUNT_OFFSET, astFunction.getRequiredArgumentCount()); db.putInt(record + REQUIRED_ARG_COUNT_OFFSET, astFunction.getRequiredArgumentCount());
long typelist= 0; long typelist= 0;
if (astFunction instanceof ICPPMethod && ((ICPPMethod) astFunction).isImplicit()) { 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 { } else {
typelist = PDOMCPPTypeList.putTypes(this, astFunction.getExceptionSpecification()); typelist = PDOMCPPTypeList.putTypes(this, astFunction.getExceptionSpecification());
} }
db.putRecPtr(record + EXCEPTION_SPEC, typelist); db.putRecPtr(record + EXCEPTION_SPEC, typelist);
} }
private short getAnnotation(ICPPFunction astFunction) { private short getAnnotation(ICPPFunction astFunction) {
@ -132,7 +128,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
annot |= (1 << ANNOT_PARAMETER_PACK); annot |= (1 << ANNOT_PARAMETER_PACK);
} }
if (astFunction.isDeleted()) { if (astFunction.isDeleted()) {
annot |= (1<<ANNOT_IS_DELETED); annot |= (1 << ANNOT_IS_DELETED);
} }
return (short) annot; return (short) annot;
} }
@ -190,8 +186,9 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
long next = db.getRecPtr(record + FIRST_PARAM); long next = db.getRecPtr(record + FIRST_PARAM);
for (int i = 0; i < n && next != 0; i++) { for (int i = 0; i < n && next != 0; i++) {
IType type= i<ptypes.length ? ptypes[i] : null; IType type= i < ptypes.length ? ptypes[i] : null;
final PDOMCPPParameterSpecialization par = new PDOMCPPParameterSpecialization(linkage, next, type); final PDOMCPPParameterSpecialization par =
new PDOMCPPParameterSpecialization(linkage, next, type);
next= par.getNextPtr(); next= par.getNextPtr();
result[i]= par; result[i]= par;
} }
@ -247,7 +244,6 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
return getBit(readAnnotation(), PDOMCAnnotation.VARARGS_OFFSET); return getBit(readAnnotation(), PDOMCAnnotation.VARARGS_OFFSET);
} }
@Override @Override
public int getRequiredArgumentCount() { public int getRequiredArgumentCount() {
if (fRequiredArgCount == -1) { if (fRequiredArgCount == -1) {
@ -291,7 +287,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
@Override @Override
public IType[] getExceptionSpecification() { public IType[] getExceptionSpecification() {
try { try {
final long rec = getPDOM().getDB().getRecPtr(record+EXCEPTION_SPEC); final long rec = getPDOM().getDB().getRecPtr(record + EXCEPTION_SPEC);
return PDOMCPPTypeList.getTypes(this, rec); return PDOMCPPTypeList.getTypes(this, rec);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);

View file

@ -58,10 +58,10 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory {
public static final String GDB_7_2_VERSION = "7.2"; //$NON-NLS-1$ public static final String GDB_7_2_VERSION = "7.2"; //$NON-NLS-1$
/** @since 4.1 */ /** @since 4.1 */
public static final String GDB_7_2_1_VERSION = "7.2.1"; //$NON-NLS-1$ public static final String GDB_7_2_1_VERSION = "7.2.1"; //$NON-NLS-1$
/** @since 4.1 */
// Keep private until GDB 7.4 is released and we can change the constant public static final String GDB_7_3_VERSION = "7.3"; //$NON-NLS-1$
// to its proper value of 7.4 /** @since 4.1 */
private static final String GDB_7_4_VERSION = "7.3.50"; //$NON-NLS-1$ public static final String GDB_7_4_VERSION = "7.4"; //$NON-NLS-1$
private final String fVersion; private final String fVersion;

View file

@ -360,7 +360,7 @@ public class ExpressionVMProvider extends AbstractDMVMProvider
@Override @Override
public void expressionsAdded(IExpression[] expressions) { public void expressionsAdded(IExpression[] expressions) {
expressionsListChanged(ExpressionsChangedEvent.Type.ADDED, expressions, -1); expressionsListChanged(ExpressionsChangedEvent.Type.ADDED, expressions, DebugPlugin.getDefault().getExpressionManager().getExpressions().length - expressions.length);
} }
@Override @Override

View file

@ -157,8 +157,13 @@ public class ExpressionVMProviderModelProxyStrategy extends DefaultVMModelProxyS
case ADDED: case ADDED:
// New expressions are always added one element before last. // New expressions are always added one element before last.
// Last element is the "Add new expression" element. // Last element is the "Add new expression" element.
// Note: Index should be calculated when the IExpressionListener.expressionsAdded
// is called. If it's not, try to calculate it here based on parent count.
int parentCount = parentDelta.getChildCount(); int parentCount = parentDelta.getChildCount();
parentDelta.addNode(element, parentCount > 1 ? parentCount - 2 : -1, IModelDelta.ADDED); if (elementIdx == -1 && parentCount > 1) {
elementIdx = parentCount - 2;
}
parentDelta.addNode(element, elementIdx, IModelDelta.ADDED);
break; break;
case CHANGED: case CHANGED:
parentDelta.setFlags(parentDelta.getFlags() | IModelDelta.CONTENT); parentDelta.setFlags(parentDelta.getFlags() | IModelDelta.CONTENT);

View file

@ -24,7 +24,6 @@ import org.eclipse.core.runtime.PlatformObject;
@SuppressWarnings("restriction") @SuppressWarnings("restriction")
public class C99Function extends PlatformObject implements IC99Binding, IFunction, ITypeable { public class C99Function extends PlatformObject implements IC99Binding, IFunction, ITypeable {
private String name; private String name;
private IFunctionType type; private IFunctionType type;
private List<IParameter> parameters = new ArrayList<IParameter>(); private List<IParameter> parameters = new ArrayList<IParameter>();
@ -41,7 +40,6 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio
// the scope that represents the body of the function // the scope that represents the body of the function
private IScope bodyScope; private IScope bodyScope;
public C99Function() { public C99Function() {
} }
@ -54,8 +52,7 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio
this(name); this(name);
this.type = type; this.type = type;
} }
public IParameter[] getParameters() { public IParameter[] getParameters() {
return parameters.toArray(new IParameter[parameters.size()]); return parameters.toArray(new IParameter[parameters.size()]);
} }