Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDelegate.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java248
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java24
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java22
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java6
6 files changed, 166 insertions, 154 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java
index 0358063b763..37d0f323284 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java
@@ -1,13 +1,14 @@
/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
+ * Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
- * Bryan Wilkinson (QNX)
+ * IBM - Initial API and implementation
+ * Bryan Wilkinson (QNX)
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -80,13 +81,13 @@ public class CPPASTUsingDeclaration extends CPPASTNode implements
public int getRoleForName(IASTName n) {
if( n == name )
- return r_reference;
+ return r_definition;
return r_unclear;
}
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
- List filtered = new ArrayList();
+ List<IBinding> filtered = new ArrayList<IBinding>();
for (int i = 0;i < bindings.length; i++) {
if (bindings[i] instanceof ICPPNamespace) {
@@ -94,6 +95,6 @@ public class CPPASTUsingDeclaration extends CPPASTNode implements
}
}
- return (IBinding[]) filtered.toArray(new IBinding[filtered.size()]);
+ return filtered.toArray(new IBinding[filtered.size()]);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDelegate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDelegate.java
index e1218f25e57..ca5c2ac9ff1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDelegate.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDelegate.java
@@ -113,6 +113,9 @@ public class CPPDelegate extends PlatformObject implements ICPPDelegate, ICPPInt
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDefinition()
*/
public IASTNode getDefinition() {
+ if (usingDeclaration instanceof ICPPInternalBinding) {
+ return ((ICPPInternalBinding) usingDeclaration).getDefinition();
+ }
return null;
}
@@ -153,4 +156,8 @@ public class CPPDelegate extends PlatformObject implements ICPPDelegate, ICPPInt
public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE;
}
+
+ public ICPPUsingDeclaration getUsingDeclaration() {
+ return usingDeclaration;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java
index be4f31704a4..a7b9358eb61 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java
@@ -10,7 +10,6 @@
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.IName;
@@ -1105,7 +1104,7 @@ public class CPPVisitor {
public static class CollectDeclarationsAction extends CPPASTVisitor {
private static final int DEFAULT_LIST_SIZE = 8;
private IASTName [] decls;
- private IBinding binding;
+ private IBinding[] bindings;
private int idx = 0;
private int kind;
@@ -1118,11 +1117,23 @@ public class CPPVisitor {
public CollectDeclarationsAction( IBinding binding ){
- this.binding = binding;
+ shouldVisitNames = true;
this.decls = new IASTName[ DEFAULT_LIST_SIZE ];
- shouldVisitNames = true;
- if( binding instanceof ILabel )
+ this.bindings = new IBinding[] {binding};
+ if (binding instanceof ICPPUsingDeclaration) {
+ try {
+ ICPPDelegate[] delegates= ((ICPPUsingDeclaration) binding).getDelegates();
+ this.bindings= new IBinding[delegates.length+1];
+ this.bindings[0]= binding;
+ for (int i=0; i < delegates.length; i++) {
+ this.bindings[i+1]= delegates[i].getBinding();
+ }
+ } catch (DOMException e) {
+ }
+ kind= KIND_COMPOSITE;
+ }
+ else if( binding instanceof ILabel )
kind = KIND_LABEL;
else if( binding instanceof ICPPTemplateParameter )
kind = KIND_TEMPLATE_PARAMETER;
@@ -1135,8 +1146,6 @@ public class CPPVisitor {
else if( binding instanceof ICPPNamespace) {
kind = KIND_NAMESPACE;
}
- else if( binding instanceof ICPPUsingDeclaration )
- kind = KIND_COMPOSITE;
else
kind = KIND_OBJ_FN;
}
@@ -1212,64 +1221,40 @@ public class CPPVisitor {
return PROCESS_CONTINUE;
}
- if( binding != null )
- {
- IBinding potential = name.resolveBinding();
- IBinding [] bs = null;
- IBinding candidate = null;
- int n = -1;
- if( potential instanceof ICPPUsingDeclaration ){
- try {
- bs = ((ICPPUsingDeclaration)potential).getDelegates();
- } catch ( DOMException e ) {
- return PROCESS_CONTINUE;
- }
- if( bs == null || bs.length == 0 )
- candidate = null;
- else
- candidate = bs[ ++n ];
- } else {
- candidate = potential;
- }
-
- while( candidate != null ) {
- boolean found = false;
- if( binding instanceof ICPPUsingDeclaration ){
- ICPPDelegate [] delegates = null;
- try {
- delegates = ((ICPPUsingDeclaration)binding).getDelegates();
- } catch (DOMException e1) {
- }
- if( delegates != null ){
- for (int i = 0; i < delegates.length; i++) {
- if( delegates[i].getBinding() == candidate ){
- found = true;
- break;
- }
- }
- }
- } else {
-// if( candidate instanceof ICPPDelegate )
-// found = ( ((ICPPDelegate)candidate).getBinding() == binding );
-// else
- found = ( binding == candidate );
- }
-
- if( found ){
- if( decls.length == idx ){
- IASTName [] temp = new IASTName[ decls.length * 2 ];
- System.arraycopy( decls, 0, temp, 0, decls.length );
- decls = temp;
- }
- decls[idx++] = name;
- }
- if( n > -1 && ++n < bs.length ){
- candidate = bs[n];
- } else break;
+ if( bindings != null ) {
+ if (isDeclarationsBinding(name.resolveBinding())) {
+ if( decls.length == idx ){
+ IASTName [] temp = new IASTName[ decls.length * 2 ];
+ System.arraycopy( decls, 0, temp, 0, decls.length );
+ decls = temp;
+ }
+ decls[idx++] = name;
}
}
return PROCESS_CONTINUE;
}
+
+ private boolean isDeclarationsBinding(IBinding nameBinding) {
+ nameBinding= unwindBinding(nameBinding);
+ if (nameBinding != null) {
+ for (int i = 0; i < bindings.length; i++) {
+ if (nameBinding.equals(unwindBinding(bindings[i]))) {
+ return true;
+ }
+ // a using declaration is a declaration for the references of its delegates
+ if (nameBinding instanceof ICPPUsingDeclaration) {
+ try {
+ if (ArrayUtil.contains(((ICPPUsingDeclaration) nameBinding).getDelegates(), bindings[i])) {
+ return true;
+ }
+ } catch (DOMException e) {
+ }
+ }
+ }
+ }
+ return false;
+ }
+
public IASTName[] getDeclarations(){
if( idx < decls.length ){
IASTName [] temp = new IASTName[ idx ];
@@ -1280,10 +1265,29 @@ public class CPPVisitor {
}
}
+
+ protected static IBinding unwindBinding(IBinding binding) {
+ while(true) {
+ if (binding instanceof ICPPSpecialization) {
+ binding= ((ICPPSpecialization) binding).getSpecializedBinding();
+ } else if (binding instanceof ICPPDelegate) {
+ ICPPDelegate delegate= (ICPPDelegate) binding;
+ if (delegate.getDelegateType() == ICPPDelegate.USING_DECLARATION) {
+ binding= delegate.getBinding();
+ } else {
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+ return binding;
+ }
+
public static class CollectReferencesAction extends CPPASTVisitor {
private static final int DEFAULT_LIST_SIZE = 8;
private IASTName [] refs;
- private IBinding binding;
+ private IBinding[] bindings;
private int idx = 0;
private int kind;
@@ -1295,28 +1299,35 @@ public class CPPVisitor {
public CollectReferencesAction( IBinding binding ){
- if (binding instanceof ICPPSpecialization) {
- binding= ((ICPPSpecialization) binding).getSpecializedBinding();
- }
- this.binding = binding;
+ shouldVisitNames = true;
this.refs = new IASTName[ DEFAULT_LIST_SIZE ];
+
+ binding = unwindBinding(binding);
+ this.bindings = new IBinding[] {binding};
- shouldVisitNames = true;
- if( binding instanceof ILabel )
+ if (binding instanceof ICPPUsingDeclaration) {
+ try {
+ ICPPDelegate[] delegates= ((ICPPUsingDeclaration) binding).getDelegates();
+ this.bindings= new IBinding[delegates.length];
+ for (int i = 0; i < delegates.length; i++) {
+ binding= this.bindings[i]= delegates[i].getBinding();
+ }
+ } catch (DOMException e) {
+ }
+ kind= KIND_COMPOSITE;
+ } else if( binding instanceof ILabel ) {
kind = KIND_LABEL;
- else if( binding instanceof ICompositeType ||
+ } else if( binding instanceof ICompositeType ||
binding instanceof ITypedef ||
- binding instanceof IEnumeration)
- {
+ binding instanceof IEnumeration) {
kind = KIND_TYPE;
- }
- else if( binding instanceof ICPPNamespace) {
+ } else if( binding instanceof ICPPNamespace) {
kind = KIND_NAMESPACE;
- } else if( binding instanceof ICPPUsingDeclaration ||
- binding instanceof ICPPTemplateParameter )
+ } else if( binding instanceof ICPPTemplateParameter ) {
kind = KIND_COMPOSITE;
- else
+ } else {
kind = KIND_OBJ_FN;
+ }
}
public int visit( IASTName name ){
@@ -1382,63 +1393,46 @@ public class CPPVisitor {
return PROCESS_CONTINUE;
}
- if( binding != null ){
- IBinding potential = name.resolveBinding();
- IBinding [] bs = null;
- IBinding candidate = null;
- int n = -1;
- if( potential instanceof ICPPUsingDeclaration ){
- try {
- bs = ((ICPPUsingDeclaration)potential).getDelegates();
- } catch ( DOMException e ) {
- return PROCESS_CONTINUE;
- }
- if( bs == null || bs.length == 0 )
- candidate = null;
- else
- candidate = bs[ ++n ];
- } else if (potential instanceof ICPPSpecialization) {
- candidate= ((ICPPSpecialization) potential).getSpecializedBinding();
- } else {
- candidate = potential;
- }
-
- while( candidate != null ) {
- boolean found = false;
- if( binding instanceof ICPPUsingDeclaration ){
- try {
- found = ArrayUtil.containsEqual( ((ICPPUsingDeclaration)binding).getDelegates(), candidate );
- } catch ( DOMException e ) {
- }
- } else if( potential instanceof ICPPUsingDeclaration ){
- found = sameBinding(binding, ((ICPPDelegate)candidate).getBinding());
- } else {
- found = sameBinding(binding, candidate);
- }
-
- if( found ){
- if( refs.length == idx ){
- IASTName [] temp = new IASTName[ refs.length * 2 ];
- System.arraycopy( refs, 0, temp, 0, refs.length );
- refs = temp;
- }
- refs[idx++] = name;
- break;
- }
- if( n > -1 && ++n < bs.length ){
- candidate = bs[n];
- } else break;
+ if( bindings != null ){
+ if (isReferenceBinding(name.resolveBinding())) {
+ if (refs.length == idx){
+ IASTName [] temp = new IASTName[ refs.length * 2 ];
+ System.arraycopy( refs, 0, temp, 0, refs.length );
+ refs = temp;
+ }
+ refs[idx++] = name;
}
}
return PROCESS_CONTINUE;
}
- private boolean sameBinding(IBinding binding1, IBinding binding2) {
- if (binding1 == binding2)
- return true;
- if (binding1.equals(binding2))
- return true;
+
+ private boolean isReferenceBinding(IBinding nameBinding) {
+ nameBinding= unwindBinding(nameBinding);
+ if (nameBinding != null) {
+ for (int i = 0; i < bindings.length; i++) {
+ if (nameBinding.equals(bindings[i])) {
+ return true;
+ }
+ }
+ if (nameBinding instanceof ICPPUsingDeclaration) {
+ try {
+ ICPPDelegate[] delegates= ((ICPPUsingDeclaration) nameBinding).getDelegates();
+ for (int i = 0; i < delegates.length; i++) {
+ ICPPDelegate delegate = delegates[i];
+ if (isReferenceBinding(delegate.getBinding())) {
+ return true;
+ }
+ }
+ } catch (DOMException e) {
+ }
+ return false;
+ } else {
+ return false;
+ }
+ }
return false;
}
+
public IASTName[] getReferences(){
if( idx < refs.length ){
IASTName [] temp = new IASTName[ idx ];
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java
index 4de0e3cc80e..62d0dc7c4ed 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java
@@ -11,7 +11,6 @@
* Andrew Ferguson (Symbian)
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.index;
import java.util.ArrayList;
@@ -31,6 +30,7 @@ import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
@@ -42,6 +42,7 @@ import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.internal.core.dom.Linkage;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDelegate;
import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
import org.eclipse.cdt.internal.core.index.composite.c.CCompositesFactory;
@@ -122,8 +123,9 @@ public class CIndex implements IIndex {
}
public IIndexName[] findNames(IBinding binding, int flags) throws CoreException {
+ LinkedList<IIndexFragmentName> result= new LinkedList<IIndexFragmentName>();
if (binding instanceof ICPPUsingDeclaration) {
- IBinding[] bindings= null;
+ ICPPDelegate[] bindings= null;
try {
bindings = ((ICPPUsingDeclaration)binding).getDelegates();
} catch (DOMException e) {
@@ -133,16 +135,26 @@ public class CIndex implements IIndex {
return new IIndexName[0];
}
if (bindings.length > 1) {
- ArrayList<IIndexName> result= new ArrayList<IIndexName>();
+ ArrayList<IIndexName> multi= new ArrayList<IIndexName>();
for (int i = 0; i < bindings.length; i++) {
IBinding b = bindings[i];
- result.addAll(Arrays.asList(findNames(b, flags)));
+ multi.addAll(Arrays.asList(findNames(b, flags)));
}
- return result.toArray(new IIndexName[result.size()]);
+ return multi.toArray(new IIndexName[multi.size()]);
}
binding= bindings[0];
+ } else if (binding instanceof CPPDelegate) {
+ CPPDelegate delegate= (CPPDelegate) binding;
+ if (delegate.getDelegateType() == ICPPDelegate.USING_DECLARATION) {
+ binding= delegate.getBinding();
+ IIndexFragmentBinding ib= (IIndexFragmentBinding) delegate.getUsingDeclaration().getAdapter(IIndexFragmentBinding.class);
+ if (ib != null) {
+ final IIndexFragmentName[] names= ib.getFragment().findNames(ib, flags);
+ result.addAll(Arrays.asList(names));
+ }
+ }
}
- LinkedList<IIndexFragmentName> result= new LinkedList<IIndexFragmentName>();
+
int fragCount= 0;
for (int i = 0; i < fPrimaryFragmentCount; i++) {
final IIndexFragmentName[] names = fFragments[i].findNames(binding, flags);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
index 0a7dbff881b..4925c795ef8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
@@ -11,7 +11,6 @@
* IBM Corporation
* Andrew Ferguson (Symbian)
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.dom.ILinkage;
@@ -36,7 +35,6 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
@@ -261,8 +259,12 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
} else {
// in case this is a delegate the scope of the delegate can be different to the
// scope of the delegating party (e.g. using-declarations)
- while (binding instanceof ICPPDelegate && !(binding instanceof ICPPNamespaceAlias)) {
- binding= ((ICPPDelegate) binding).getBinding();
+ while (binding instanceof ICPPDelegate) {
+ final ICPPDelegate delegate = (ICPPDelegate)binding;
+ if (delegate.getDelegateType() != ICPPDelegate.USING_DECLARATION) {
+ break;
+ }
+ binding= delegate.getBinding();
}
IScope scope = binding.getScope();
if (scope == null) {
@@ -356,17 +358,19 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
if (binding instanceof IField) {
return null;
}
- boolean isFileLocal= false;
+ boolean checkInSourceOnly= false;
if (binding instanceof IVariable) {
if (!(binding instanceof IField)) {
- isFileLocal= ASTInternal.isStatic((IVariable) binding);
+ checkInSourceOnly= ASTInternal.isStatic((IVariable) binding);
}
} else if (binding instanceof IFunction) {
IFunction f= (IFunction) binding;
- isFileLocal= ASTInternal.isStatic(f, false);
- }
+ checkInSourceOnly= ASTInternal.isStatic(f, false);
+// } else if (binding instanceof ITypedef || binding instanceof ICompositeType || binding instanceof IEnumeration) {
+// checkInSourceOnly= true;
+ }
- if (isFileLocal) {
+ if (checkInSourceOnly) {
String path= ASTInternal.getDeclaredInSourceFileOnly(binding);
if (path != null) {
return wpdom.getFileForASTPath(getLinkageID(), path);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java
index 1cb54f1330f..a8610be992e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java
@@ -17,7 +17,6 @@ import java.util.ArrayList;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
@@ -105,11 +104,6 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
if (name.isDeclaration()) {
return IS_DECLARATION;
}
-
- // special case a using-declaration is a declaration and a reference at the same time.
- if (name.getBinding() instanceof ICPPUsingDeclaration) {
- return IS_DEFINITION;
- }
return IS_REFERENCE;
}

Back to the top