mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 23:05:47 +02:00
Bug 457503 - Argument-dependent lookup fails for index types in global
namespace
This commit is contained in:
parent
773eb90b41
commit
568e8a995b
19 changed files with 319 additions and 79 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2014 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2015 Wind River Systems, Inc. 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
|
||||
|
@ -1308,6 +1308,23 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
|
|||
assertEquals("base", name.resolveBinding().getOwner().getName());
|
||||
}
|
||||
|
||||
// class A {};
|
||||
|
||||
// void waldo(A p) {}
|
||||
//
|
||||
// namespace ns {
|
||||
//
|
||||
// void waldo() {}
|
||||
//
|
||||
// void test(A a) {
|
||||
// waldo(a);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
public void test_457503() throws Exception {
|
||||
checkBindings();
|
||||
}
|
||||
|
||||
// class A {
|
||||
// class B;
|
||||
// };
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2014 Symbian Software Systems and others.
|
||||
* Copyright (c) 2007, 2015 Symbian Software Systems 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
|
||||
|
@ -22,6 +22,7 @@ import junit.framework.TestSuite;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
|
@ -236,7 +237,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
// namespace n { class C{}; }
|
||||
// m::C c;
|
||||
public void testUsingNamingDirective_177917_1b() {
|
||||
IBinding b0= getBindingFromASTName("C c", 1);
|
||||
IBinding b0= getBindingFromFirstIdentifier("C c");
|
||||
}
|
||||
|
||||
// int ff(int x) { return x; }
|
||||
|
@ -438,7 +439,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
assertVariable(b1, "c", ICPPClassType.class, "C");
|
||||
ICPPClassType b1type = (ICPPClassType) ((ICPPVariable) b1).getType();
|
||||
assertClassTypeBinding(b1type, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
|
||||
assertTrue(b1type.getScope() == null);
|
||||
assertEquals(EScopeKind.eGlobal, b1type.getScope().getKind());
|
||||
assertTrue(b1type.getCompositeScope() instanceof ICPPClassScope);
|
||||
assertClassTypeBinding(((ICPPClassScope) b1type.getCompositeScope()).getClassType(), "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
|
||||
}
|
||||
|
@ -468,7 +469,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
assertVariable(b7, "e", IEnumeration.class, "E");
|
||||
IEnumeration b5type = (IEnumeration) ((ICPPVariable) b7).getType();
|
||||
assertEnumeration(b5type, "E", new String[] {"ER1","ER2","ER3"});
|
||||
assertTrue(b5type.getScope() == null);
|
||||
assertEquals(EScopeKind.eGlobal, b5type.getScope().getKind());
|
||||
}
|
||||
{
|
||||
IBinding b8 = getBindingFromASTName("var1 = 1;", 4);
|
||||
|
@ -505,7 +506,6 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
IBinding b25 = getBindingFromASTName("S {}; /*base*/", 1);
|
||||
}
|
||||
|
||||
|
||||
//// header content
|
||||
//class TopC {}; struct TopS {}; union TopU {}; enum TopE {TopER1,TopER2};
|
||||
//short topBasic; void *topPtr; TopC *topCPtr; TopU topFunc(){return *new TopU();}
|
||||
|
@ -566,19 +566,19 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
IBinding b0 = getBindingFromASTName("S _s0;", 1);
|
||||
assertTrue(b0.getScope() instanceof ICPPNamespaceScope);
|
||||
assertTrue(b0.getScope().getParent() instanceof ICPPNamespaceScope);
|
||||
assertTrue(b0.getScope().getParent().getParent() == null);
|
||||
assertEquals(EScopeKind.eGlobal, b0.getScope().getParent().getParent().getKind());
|
||||
assertQNEquals("n1::n2::S", b0);
|
||||
|
||||
IBinding b1 = getBindingFromASTName("S _s1;", 1);
|
||||
assertTrue(b1.getScope() instanceof ICPPNamespaceScope);
|
||||
assertTrue(b1.getScope().getParent() instanceof ICPPNamespaceScope);
|
||||
assertTrue(b1.getScope().getParent().getParent() == null);
|
||||
assertEquals(EScopeKind.eGlobal, b1.getScope().getParent().getParent().getKind());
|
||||
assertQNEquals("n1::n2::S", b1);
|
||||
|
||||
IBinding b2 = getBindingFromASTName("S _s2;", 1);
|
||||
assertTrue(b2.getScope() instanceof ICPPClassScope);
|
||||
assertTrue(b2.getScope().getParent() instanceof ICPPClassScope);
|
||||
assertTrue(b2.getScope().getParent().getParent() == null);
|
||||
assertEquals(EScopeKind.eGlobal, b2.getScope().getParent().getParent().getKind());
|
||||
assertQNEquals("c1::c2::S", b2);
|
||||
|
||||
IBinding b3 = getBindingFromASTName("S _s3;", 1);
|
||||
|
@ -601,7 +601,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
assertTrue(b10.getScope().getParent() instanceof ICPPClassScope);
|
||||
assertTrue(b10.getScope().getParent().getParent() instanceof ICPPClassScope);
|
||||
assertTrue(b10.getScope().getParent().getParent().getParent() instanceof ICPPNamespaceScope);
|
||||
assertTrue(b10.getScope().getParent().getParent().getParent().getParent() == null);
|
||||
assertEquals(EScopeKind.eGlobal, b10.getScope().getParent().getParent().getParent().getParent().getKind());
|
||||
assertQNEquals("n3::c3::s3::u3::S", b10);
|
||||
|
||||
IBinding b11 = getBindingFromASTName("S _s11;", 1);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2014 Symbian Software Systems and others.
|
||||
* Copyright (c) 2007, 2015 Symbian Software Systems 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
|
||||
|
@ -19,6 +19,7 @@ import java.util.List;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
|
||||
|
@ -1185,7 +1186,8 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
IBinding foo3= getBindingFromASTName("foo(e)", 3);
|
||||
IBinding foo4= getBindingFromASTName("foo(cx)", 3);
|
||||
|
||||
assertEquals(foo1, foo2); assertEquals(foo2, foo3);
|
||||
assertEquals(foo1, foo2);
|
||||
assertEquals(foo2, foo3);
|
||||
assertEquals(foo3, foo4);
|
||||
}
|
||||
|
||||
|
@ -1209,8 +1211,8 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
ICPPClassType sc1= assertInstance(b1.getSpecializedBinding(), ICPPClassType.class);
|
||||
assertTrue(sc0.isSameType(sc1));
|
||||
|
||||
assertNull(sc0.getScope());
|
||||
assertNull(b0.getScope());
|
||||
assertEquals(EScopeKind.eGlobal, sc0.getScope().getKind());
|
||||
assertEquals(EScopeKind.eGlobal, b0.getScope().getKind());
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
|
@ -1256,7 +1258,8 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
|
||||
assertFalse(b0 instanceof ICPPSpecialization);
|
||||
|
||||
IIndexScope s0= (IIndexScope) b0.getScope(), s4= (IIndexScope) b4.getScope();
|
||||
IIndexScope s0= (IIndexScope) b0.getScope();
|
||||
IIndexScope s4= (IIndexScope) b4.getScope();
|
||||
IScope s1= b1.getScope();
|
||||
|
||||
assertTrue(((IType)s0.getScopeBinding()).isSameType((IType)((IIndexScope)b2.getCompositeScope()).getScopeBinding()));
|
||||
|
@ -1315,7 +1318,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
ICPPClassScope s1= assertInstance(b1.getScope(), ICPPClassScope.class);
|
||||
assertInstance(s1.getClassType(), ICPPTemplateDefinition.class);
|
||||
|
||||
assertNull(s1.getClassType().getScope());
|
||||
assertEquals(EScopeKind.eGlobal, s1.getClassType().getScope().getKind());
|
||||
}
|
||||
|
||||
// typedef signed int SI;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008, 2013 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 2015 Wind River Systems, Inc. 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
|
||||
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
|
@ -421,7 +422,16 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
|||
/**
|
||||
* Can be called to create a type for a type-id.
|
||||
*/
|
||||
abstract protected IType createType(IASTTypeId typeid);
|
||||
protected abstract IType createType(IASTTypeId typeid);
|
||||
|
||||
/**
|
||||
* Maps an index scope to the AST.
|
||||
*
|
||||
* @param scope a scope, possibly from index
|
||||
* @return the corresponding scope in the AST, or the original scope if it doesn't have
|
||||
* a counterpart in the AST.
|
||||
*/
|
||||
public abstract IScope mapToASTScope(IScope scope);
|
||||
|
||||
protected <T extends ASTTranslationUnit> T copy(T copy, CopyStyle style) {
|
||||
copy.setIndex(fIndex);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2011 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2015 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
|
||||
|
@ -9,6 +9,7 @@
|
|||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Yuan Zhang / Beth Tibbitts (IBM Research)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
|
@ -21,11 +22,13 @@ import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
|||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
|
||||
/**
|
||||
* C-specific implementation of a translation unit.
|
||||
|
@ -101,6 +104,20 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig
|
|||
accept(new CASTAmbiguityResolver());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScope mapToASTScope(IScope scope) {
|
||||
if (scope instanceof IIndexScope) {
|
||||
if (scope.getKind() == EScopeKind.eGlobal)
|
||||
return getScope();
|
||||
if (scope instanceof ICCompositeTypeScope) {
|
||||
ICompositeType type = ((ICCompositeTypeScope) scope).getCompositeType();
|
||||
type = mapToASTType(type);
|
||||
return type.getCompositeScope();
|
||||
}
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps structs from the index into this AST.
|
||||
*/
|
||||
|
|
|
@ -161,13 +161,7 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
|
|||
fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an index scope to the AST.
|
||||
*
|
||||
* @param scope a scope, possibly from index
|
||||
* @return the corresponding scope in the AST, or the original scope if it doesn't have
|
||||
* a counterpart in the AST.
|
||||
*/
|
||||
@Override
|
||||
public IScope mapToASTScope(IScope scope) {
|
||||
if (scope instanceof IIndexScope) {
|
||||
return fScopeMapper.mapToASTScope((IIndexScope) scope);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 2015 Wind River Systems, Inc. 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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -175,12 +176,19 @@ public class CPPScopeMapper {
|
|||
public ICPPInternalNamespaceScope[] getInlineNamespaces() {
|
||||
// Obtain the inline namespaces from the index and map them to the ast
|
||||
ICPPNamespaceScope[] pre = fScope.getInlineNamespaces();
|
||||
if (pre.length == 0)
|
||||
return ICPPInternalNamespaceScope.EMPTY_NAMESPACE_SCOPE_ARRAY;
|
||||
ICPPInternalNamespaceScope[] result= new ICPPInternalNamespaceScope[pre.length];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i]= (ICPPInternalNamespaceScope) mapToASTScope((IIndexScope) pre[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return fScope.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,6 +221,11 @@ public class CPPScopeMapper {
|
|||
public int getPointOfDeclaration() {
|
||||
return fOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return fDirective.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -302,7 +315,7 @@ public class CPPScopeMapper {
|
|||
|
||||
private String getReverseQualifiedName(IScope scope) throws DOMException {
|
||||
final CPPNamespaceScope tuscope = fTu.getScope();
|
||||
if (scope == tuscope || scope == null) {
|
||||
if (scope == tuscope || scope == null || scope.getKind() == EScopeKind.eGlobal) {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
StringBuilder buf= new StringBuilder();
|
||||
|
@ -311,7 +324,7 @@ public class CPPScopeMapper {
|
|||
buf.append(scopeName.getSimpleID());
|
||||
}
|
||||
scope= scope.getParent();
|
||||
while (scope != null && scope != tuscope) {
|
||||
while (scope.getKind() != EScopeKind.eGlobal && scope != tuscope) {
|
||||
buf.append(':');
|
||||
scopeName= scope.getScopeName();
|
||||
if (scopeName != null) {
|
||||
|
@ -326,7 +339,7 @@ public class CPPScopeMapper {
|
|||
* Maps namespace scopes from the index back into the AST.
|
||||
*/
|
||||
public IScope mapToASTScope(IIndexScope scope) {
|
||||
if (scope == null) {
|
||||
if (scope.getKind() == EScopeKind.eGlobal) {
|
||||
return fTu.getScope();
|
||||
}
|
||||
if (scope instanceof ICPPNamespaceScope) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008, 2009 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 2015 Wind River Systems, Inc. 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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -64,6 +65,6 @@ public class CPPUsingDirective implements ICPPUsingDirective {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return fNamespaceName.toString();
|
||||
return "using namespace " + fNamespaceName.toString(); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2010, 2015 Wind River Systems, Inc. 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:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -16,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
|||
* For namespace scopes from the AST or mapped index namespace scopes.
|
||||
*/
|
||||
public interface ICPPInternalNamespaceScope extends ICPPNamespaceScope {
|
||||
public ICPPInternalNamespaceScope[] EMPTY_NAMESPACE_SCOPE_ARRAY = {};
|
||||
|
||||
/**
|
||||
* Returns the enclosing namespace set (7.3.1-9)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2014 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2015 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
|
||||
|
@ -68,6 +68,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
|||
import org.eclipse.cdt.core.parser.util.CharArraySet;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
|
||||
|
@ -541,8 +542,8 @@ public class SemanticUtil {
|
|||
public static IScope mapToAST(IScope scope, IASTNode point) {
|
||||
if (point != null) {
|
||||
IASTTranslationUnit ast = point.getTranslationUnit();
|
||||
if (ast instanceof CPPASTTranslationUnit) {
|
||||
return ((CPPASTTranslationUnit) ast).mapToASTScope(scope);
|
||||
if (ast instanceof ASTTranslationUnit) {
|
||||
return ((ASTTranslationUnit) ast).mapToASTScope(scope);
|
||||
}
|
||||
}
|
||||
return scope;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2010 Symbian Software Systems and others.
|
||||
* Copyright (c) 2007, 2015 Symbian Software Systems 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
|
||||
|
@ -7,9 +7,11 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index.composite.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
|
@ -50,6 +52,9 @@ public class CCompositesFactory extends AbstractCompositeFactory {
|
|||
public IIndexScope getCompositeScope(IIndexScope rscope) {
|
||||
if (rscope == null)
|
||||
return null;
|
||||
if (rscope.getKind() == EScopeKind.eGlobal)
|
||||
return rscope;
|
||||
|
||||
if (rscope instanceof ICCompositeTypeScope) {
|
||||
ICCompositeTypeScope cscope = (ICCompositeTypeScope) rscope;
|
||||
IIndexFragmentBinding rbinding = (IIndexFragmentBinding) cscope.getCompositeType();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2014 Symbian Software Systems and others.
|
||||
* Copyright (c) 2007, 2015 Symbian Software Systems 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
|
||||
|
@ -13,6 +13,7 @@
|
|||
package org.eclipse.cdt.internal.core.index.composite.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
@ -118,7 +119,10 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
|
|||
try {
|
||||
if (rscope == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (rscope.getKind() == EScopeKind.eGlobal) {
|
||||
return rscope;
|
||||
}
|
||||
if (rscope instanceof ICPPClassScope) {
|
||||
if (rscope instanceof ICPPClassSpecializationScope) {
|
||||
return new CompositeCPPClassSpecializationScope(this, (IIndexFragmentBinding) rscope.getScopeBinding());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2010 QNX Software Systems and others.
|
||||
* Copyright (c) 2005, 2015 QNX Software Systems 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
|
||||
|
@ -9,6 +9,7 @@
|
|||
* Doug Schaefer (QNX) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
|
@ -17,19 +18,15 @@ import java.lang.reflect.Modifier;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
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.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope.ScopeLookupData;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.tag.ITagReader;
|
||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBindingComparator;
|
||||
|
@ -38,6 +35,7 @@ import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IString;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.PDOMExternalReferencesList;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCGlobalScope;
|
||||
import org.eclipse.cdt.internal.core.pdom.tag.PDOMTaggable;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
@ -55,6 +53,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding
|
|||
|
||||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 20;
|
||||
|
||||
private byte hasDeclaration= -1;
|
||||
|
||||
protected PDOMBinding(PDOMLinkage linkage, PDOMNode parent, char[] name) throws CoreException {
|
||||
|
@ -255,39 +254,24 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding
|
|||
if (parent instanceof IIndexScope) {
|
||||
return (IIndexScope) parent;
|
||||
}
|
||||
} catch (CoreException ce) {
|
||||
CCorePlugin.log(ce);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IIndexScope getScope() {
|
||||
// The parent node in the binding hierarchy is the scope.
|
||||
try {
|
||||
IBinding parent= getParentBinding();
|
||||
while (parent != null) {
|
||||
if (parent instanceof ICPPClassType) {
|
||||
return (IIndexScope) ((ICPPClassType) parent).getCompositeScope();
|
||||
} else if (parent instanceof ICPPUnknownBinding) {
|
||||
return (IIndexScope) ((ICPPUnknownBinding) parent).asScope();
|
||||
} else if (parent instanceof ICPPEnumeration) {
|
||||
final ICPPEnumeration enumeration = (ICPPEnumeration) parent;
|
||||
if (enumeration.isScoped()) {
|
||||
return (IIndexScope) enumeration.asScope();
|
||||
}
|
||||
parent= ((PDOMNamedNode) parent).getParentBinding();
|
||||
} else if (parent instanceof IIndexScope) {
|
||||
return (IIndexScope) parent;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return null;
|
||||
return PDOMCGlobalScope.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIndexScope getScope() {
|
||||
// The parent node in the binding hierarchy is the scope.
|
||||
try {
|
||||
IBinding parent= getParentBinding();
|
||||
if (parent instanceof IIndexScope) {
|
||||
return (IIndexScope) parent;
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return PDOMCGlobalScope.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Google, Inc 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:
|
||||
* Sergey Prigogin (Google) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
import org.eclipse.cdt.core.index.IIndexName;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
|
||||
/**
|
||||
* Base class for C and C++ global index scopes.
|
||||
*/
|
||||
public abstract class PDOMGlobalScope implements IIndexScope {
|
||||
@Override
|
||||
public EScopeKind getKind() {
|
||||
return EScopeKind.eGlobal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] find(String name) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding getBinding(IASTName name, boolean resolve) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
|
||||
IIndexFileSet acceptLocalBindings) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] getBindings(ScopeLookupData lookup) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIndexBinding getScopeBinding() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIndexScope getParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIndexName getScopeName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<global scope>"; //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Google, Inc 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:
|
||||
* Sergey Prigogin (Google) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICScope;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMGlobalScope;
|
||||
|
||||
/**
|
||||
* Represents the global C index scope.
|
||||
*/
|
||||
public class PDOMCGlobalScope extends PDOMGlobalScope implements ICScope {
|
||||
public static final PDOMCGlobalScope INSTANCE = new PDOMCGlobalScope();
|
||||
|
||||
private PDOMCGlobalScope() {}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2009 Symbian Corporation and others.
|
||||
* Copyright (c) 2006, 2015 Symbian 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
|
||||
|
@ -8,14 +8,22 @@
|
|||
* Contributors:
|
||||
* Symbian - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
@ -49,4 +57,33 @@ public abstract class PDOMCPPBinding extends PDOMBinding implements ICPPBinding
|
|||
// Local stuff is not stored in the index.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IIndexScope getScope() {
|
||||
// The parent node in the binding hierarchy is the scope.
|
||||
try {
|
||||
IBinding parent= getParentBinding();
|
||||
while (parent != null) {
|
||||
if (parent instanceof ICPPClassType) {
|
||||
return (IIndexScope) ((ICPPClassType) parent).getCompositeScope();
|
||||
} else if (parent instanceof ICPPUnknownBinding) {
|
||||
return (IIndexScope) ((ICPPUnknownBinding) parent).asScope();
|
||||
} else if (parent instanceof ICPPEnumeration) {
|
||||
final ICPPEnumeration enumeration = (ICPPEnumeration) parent;
|
||||
if (enumeration.isScoped()) {
|
||||
return (IIndexScope) enumeration.asScope();
|
||||
}
|
||||
parent= ((PDOMNamedNode) parent).getParentBinding();
|
||||
} else if (parent instanceof IIndexScope) {
|
||||
return (IIndexScope) parent;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return PDOMCPPGlobalScope.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Google, Inc 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:
|
||||
* Sergey Prigogin (Google) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMGlobalScope;
|
||||
|
||||
/**
|
||||
* Represents the global C++ index scope.
|
||||
*/
|
||||
public class PDOMCPPGlobalScope extends PDOMGlobalScope implements ICPPNamespaceScope {
|
||||
public static final PDOMCPPGlobalScope INSTANCE = new PDOMCPPGlobalScope();
|
||||
|
||||
private PDOMCPPGlobalScope() {}
|
||||
|
||||
@Override
|
||||
public void addUsingDirective(ICPPUsingDirective usingDirective) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPUsingDirective[] getUsingDirectives() {
|
||||
return ICPPUsingDirective.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPNamespaceScope[] getInlineNamespaces() {
|
||||
return ICPPNamespaceScope.EMPTY_NAMESPACE_SCOPE_ARRAY;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 2015 Wind River Systems, Inc. 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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
|
@ -86,7 +87,7 @@ public class PDOMCPPUsingDirective implements ICPPUsingDirective, IPDOMNode {
|
|||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return null;
|
||||
return PDOMCPPGlobalScope.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -116,4 +117,9 @@ public class PDOMCPPUsingDirective implements ICPPUsingDirective, IPDOMNode {
|
|||
public void delete(PDOMLinkage linkage) throws CoreException {
|
||||
fLinkage.getDB().free(fRecord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "using namespace " + getNominatedScope(); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2014 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2005, 2015 Wind River Systems, Inc. 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
|
||||
|
@ -36,6 +36,7 @@ import org.eclipse.ui.services.IDisposable;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
|
@ -360,6 +361,9 @@ public class ASTManager implements IDisposable {
|
|||
return hasSameLocation(node1, node2, fileStatic);
|
||||
}
|
||||
|
||||
if (s1.getKind() == EScopeKind.eGlobal && s2.getKind() == EScopeKind.eGlobal)
|
||||
return TRUE;
|
||||
|
||||
String name1= getName(s1);
|
||||
String name2= getName(s2);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue