mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Correct modeling of template-scopes, bug 237026.
This commit is contained in:
parent
c9b8e80699
commit
8152453880
28 changed files with 207 additions and 610 deletions
|
@ -5526,11 +5526,8 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
// namespace ns { typedef int ns::TINT; } // illegal, still no CCE is expected.
|
||||
public void testQualifiedTypedefs_Bug222093() throws Exception{
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
|
||||
IBinding td= bh.assertNonProblem("TINT", 4);
|
||||
IBinding td= bh.assertProblem("TINT", 4);
|
||||
bh.assertProblem("ns::", 2);
|
||||
|
||||
assertTrue(td instanceof ITypedef);
|
||||
assertTrue(((ITypedef) td).getType() instanceof ICPPBasicType);
|
||||
}
|
||||
|
||||
// void func() {
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 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 Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
* mstodo- the class should be removed
|
||||
*/
|
||||
public class AST2CSpecFailingTest extends AST2SpecBaseTest {
|
||||
|
||||
public AST2CSpecFailingTest() {
|
||||
}
|
||||
|
||||
public AST2CSpecFailingTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(C 6.7.7-6):
|
||||
typedef signed int t;
|
||||
typedef int plain;
|
||||
struct tag {
|
||||
unsigned t:4;
|
||||
const t:5;
|
||||
plain r:5;
|
||||
};
|
||||
t f(t (t));
|
||||
long t;
|
||||
--End Example]
|
||||
*/
|
||||
public void test6_7_7s6() throws Exception {
|
||||
// test is no longer failing, was moved to AST2CSpecTest
|
||||
// StringBuffer buffer = new StringBuffer();
|
||||
// buffer.append("typedef signed int t;\n"); //$NON-NLS-1$
|
||||
// buffer.append("typedef int plain;\n"); //$NON-NLS-1$
|
||||
// buffer.append("struct tag {\n"); //$NON-NLS-1$
|
||||
// buffer.append("unsigned t:4;\n"); //$NON-NLS-1$
|
||||
// buffer.append("const t:5;\n"); //$NON-NLS-1$
|
||||
// buffer.append("plain r:5;\n"); //$NON-NLS-1$
|
||||
// buffer.append("};\n"); //$NON-NLS-1$
|
||||
// buffer.append("t f(t (t));\n"); //$NON-NLS-1$
|
||||
// buffer.append("long t;\n"); //$NON-NLS-1$
|
||||
// try {
|
||||
// parse(buffer.toString(), ParserLanguage.C, true, 0);
|
||||
// assertTrue(false);
|
||||
// } catch (Exception e) {}
|
||||
}
|
||||
}
|
|
@ -3110,5 +3110,13 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
public void testBug239586_ClassCast() throws Exception {
|
||||
parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP);
|
||||
}
|
||||
|
||||
|
||||
// template<typename T1> class CT {
|
||||
// static int x;
|
||||
// };
|
||||
// template<typename T> int CT<T>::x = sizeof(T);
|
||||
public void testUsingTemplParamInInitializerOfStaticField() throws Exception {
|
||||
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
||||
ICPPTemplateTypeParameter t= ba.assertNonProblem("T)", 1, ICPPTemplateTypeParameter.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
|
@ -1064,13 +1063,8 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
ICPPClassType sc1= assertInstance(b1.getSpecializedBinding(), ICPPClassType.class);
|
||||
assertTrue(sc0.isSameType(sc1));
|
||||
|
||||
IIndexScope sc2= assertInstance(sc0.getScope(), IIndexScope.class, ICPPTemplateScope.class);
|
||||
assertNull(sc0.getScope());
|
||||
assertNull(b0.getScope());
|
||||
assertEquals(sc2.getScopeBinding(), sc1);
|
||||
|
||||
// template scopes will not be supported in the future, see bug 237026
|
||||
// assertInstance(b0.getScope(), ICPPTemplateScope.class);
|
||||
// assertNotSame(sc2, b0.getScope());
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
|
@ -1176,7 +1170,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
ICPPClassScope s1= assertInstance(b1.getScope(), ICPPClassScope.class);
|
||||
assertInstance(s1.getClassType(), ICPPTemplateDefinition.class);
|
||||
|
||||
assertInstance(s1.getClassType().getScope(), ICPPTemplateScope.class);
|
||||
assertNull(s1.getClassType().getScope());
|
||||
}
|
||||
|
||||
// typedef signed int SI;
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
|
@ -16,7 +16,10 @@ import org.eclipse.cdt.core.dom.IName;
|
|||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
* Scopes can be used to look-up names. With the exception of template-scopes the scopes
|
||||
* can be arranged in a hierarchy.
|
||||
*
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface IScope {
|
||||
|
||||
|
@ -28,10 +31,11 @@ public interface IScope {
|
|||
public IName getScopeName() throws DOMException;
|
||||
|
||||
/**
|
||||
* Scopes are arranged hierarchically. Lookups will generally
|
||||
* flow upward to find resolution.
|
||||
*
|
||||
* @return The parent scope.
|
||||
* The method returns the first enclosing non-template scope, or <code>null</code> if this
|
||||
* is the global scope.
|
||||
* <p>
|
||||
* For scopes obtained from an index, <code>null</code> is returned to indicate that the
|
||||
* scope is only enclosed by the global scope.
|
||||
*/
|
||||
public IScope getParent() throws DOMException;
|
||||
|
||||
|
|
|
@ -6,24 +6,30 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Mar 11, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
* A separate template scope is used for each template declaration. This leads to a
|
||||
* non-hierarchical structure of scopes. E.g. for a method of a class-template the
|
||||
* declaration and definition will nests in different template-scopes. Therefore
|
||||
* {@link IScope#getParent()} will never return a template scope unless the method is
|
||||
* called for a template-scope that directly nests in another one.
|
||||
*
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ICPPTemplateScope extends ICPPScope {
|
||||
|
||||
/**
|
||||
* get the template that this scope represents
|
||||
* Returns the corresponding template declaration
|
||||
* @since 5.1
|
||||
*/
|
||||
public ICPPTemplateDefinition getTemplateDefinition() throws DOMException;
|
||||
public ICPPASTTemplateDeclaration getTemplateDeclaration();
|
||||
|
||||
@Deprecated
|
||||
public ICPPTemplateDefinition getTemplateDefinition() throws DOMException;
|
||||
}
|
||||
|
|
|
@ -11,18 +11,18 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -127,8 +127,17 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
|
|||
if (scope != null)
|
||||
return scope;
|
||||
|
||||
ASTNodeProperty prop = getPropertyInParent();
|
||||
if (prop == IASTSimpleDeclaration.DECLARATOR || prop == IASTFunctionDefinition.DECLARATOR) {
|
||||
// introduce a scope for function declarations and definitions, only.
|
||||
IASTNode node= getParent();
|
||||
while(!(node instanceof IASTDeclaration)) {
|
||||
if (node==null)
|
||||
return null;
|
||||
node= node.getParent();
|
||||
}
|
||||
if (node instanceof IASTParameterDeclaration)
|
||||
return null;
|
||||
|
||||
if (CPPVisitor.findTypeRelevantDeclarator(this) == this) {
|
||||
scope = new CPPFunctionScope(this);
|
||||
}
|
||||
return scope;
|
||||
|
|
|
@ -146,11 +146,8 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
@Override
|
||||
public IScope getParent() {
|
||||
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
|
||||
IASTName compName = compType.getName();
|
||||
if (compName instanceof ICPPASTQualifiedName) {
|
||||
compName = ((ICPPASTQualifiedName) compName).getLastName();
|
||||
}
|
||||
return CPPVisitor.getContainingScope(compName);
|
||||
IASTName compName = compType.getName().getLastName();
|
||||
return CPPVisitor.getContainingNonTemplateScope(compName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -10,9 +10,6 @@
|
|||
* Markus Schorn (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Dec 1, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -30,10 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.ILabel;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
@ -102,25 +96,8 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope {
|
|||
//we can't just resolve the function and get its parent scope, since there are cases where that
|
||||
//could loop since resolving functions requires resolving their parameter types
|
||||
IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) getPhysicalNode();
|
||||
IASTName name = fdtor.getName();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
ICPPASTQualifiedName qual = (ICPPASTQualifiedName) name;
|
||||
IASTName[] ns = qual.getNames();
|
||||
if (ns.length > 1) {
|
||||
IBinding binding = ns[ ns.length - 2 ].resolveBinding();
|
||||
if (binding == null)
|
||||
return null;
|
||||
else if (binding instanceof ICPPClassType)
|
||||
return ((ICPPClassType)binding).getCompositeScope();
|
||||
else if (binding instanceof ICPPNamespace)
|
||||
return ((ICPPNamespace)binding).getNamespaceScope();
|
||||
return binding.getScope();
|
||||
} else if (qual.isFullyQualified()) {
|
||||
return qual.getTranslationUnit().getScope();
|
||||
}
|
||||
}
|
||||
|
||||
return CPPVisitor.getContainingScope(name);
|
||||
IASTName name = fdtor.getName().getLastName();
|
||||
return CPPVisitor.getContainingNonTemplateScope(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -64,11 +64,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
|||
this.physicalNode = physicalNode;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
|
||||
*/
|
||||
public IScope getParent() throws DOMException {
|
||||
return CPPVisitor.getContainingScope(physicalNode);
|
||||
return CPPVisitor.getContainingNonTemplateScope(physicalNode);
|
||||
}
|
||||
|
||||
public IASTNode getPhysicalNode() {
|
||||
|
|
|
@ -12,17 +12,9 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
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.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
|
@ -33,27 +25,17 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
|||
*/
|
||||
public class CPPTemplateScope extends CPPScope implements ICPPTemplateScope {
|
||||
|
||||
//private ICPPTemplateDefinition primaryDefinition;
|
||||
/**
|
||||
* @param physicalNode
|
||||
*/
|
||||
public CPPTemplateScope(IASTNode physicalNode) {
|
||||
super(physicalNode);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope#getTemplateDefinition()
|
||||
*/
|
||||
public ICPPTemplateDefinition getTemplateDefinition() {
|
||||
// if (primaryDefinition == null) {
|
||||
// //primaryDefinition = CPPTemplates.getTemplateDefinition(this);
|
||||
// ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) getPhysicalNode();
|
||||
// IASTDeclaration decl = template.getDeclaration();
|
||||
// return new CPPTemplateDefinition(decl);
|
||||
// }
|
||||
// return primaryDefinition;
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICPPASTTemplateDeclaration getTemplateDeclaration() {
|
||||
return (ICPPASTTemplateDeclaration) getPhysicalNode();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getScopeName()
|
||||
|
@ -66,46 +48,6 @@ public class CPPTemplateScope extends CPPScope implements ICPPTemplateScope {
|
|||
|
||||
@Override
|
||||
public IScope getParent() {
|
||||
ICPPASTTemplateDeclaration templateDecl = (ICPPASTTemplateDeclaration) getPhysicalNode();
|
||||
IASTName name = CPPTemplates.getTemplateName(templateDecl);
|
||||
IASTNode p = name != null ? name.getParent() : null;
|
||||
if (p instanceof ICPPASTQualifiedName) {
|
||||
ICPPASTQualifiedName qual = (ICPPASTQualifiedName) p;
|
||||
IASTName[] names = qual.getNames();
|
||||
int i = 0;
|
||||
for (; i < names.length; i++) {
|
||||
if (names[i] == name)
|
||||
break;
|
||||
}
|
||||
if (i > 0) {
|
||||
try {
|
||||
IBinding binding = names[i - 1].resolveBinding();
|
||||
if (binding instanceof ICPPClassType) {
|
||||
return ((ICPPClassType) binding).getCompositeScope();
|
||||
} else if (binding instanceof ICPPNamespace) {
|
||||
return ((ICPPNamespace) binding).getNamespaceScope();
|
||||
} else if (binding instanceof ICPPUnknownBinding) {
|
||||
return ((ICPPUnknownBinding) binding).getUnknownScope();
|
||||
} else if (binding instanceof IProblemBinding) {
|
||||
if (binding instanceof ICPPScope)
|
||||
return (IScope) binding;
|
||||
return new CPPScope.CPPScopeProblem(names[i - 1], IProblemBinding.SEMANTIC_BAD_SCOPE,
|
||||
names[i - 1].toCharArray());
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
IScope result = e.getProblem();
|
||||
if (result instanceof ICPPScope) {
|
||||
return result;
|
||||
}
|
||||
return new CPPScope.CPPScopeProblem(names[i - 1], IProblemBinding.SEMANTIC_BAD_SCOPE,
|
||||
names[i - 1].toCharArray());
|
||||
}
|
||||
} else if (qual.isFullyQualified()) {
|
||||
return qual.getTranslationUnit().getScope();
|
||||
}
|
||||
}
|
||||
while (templateDecl.getParent() instanceof ICPPASTTemplateDeclaration)
|
||||
templateDecl = (ICPPASTTemplateDeclaration) templateDecl.getParent();
|
||||
return CPPVisitor.getContainingScope(templateDecl);
|
||||
return CPPVisitor.getContainingNonTemplateScope(getPhysicalNode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,7 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
|
|||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFieldReference;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||
|
@ -633,33 +634,56 @@ public class CPPSemantics {
|
|||
static protected void lookup(LookupData data, Object start) throws DOMException{
|
||||
final IIndexFileSet fileSet= getIndexFileSet(data);
|
||||
final boolean isIndexBased= fileSet != IIndexFileSet.EMPTY;
|
||||
|
||||
IASTNode node = data.astName;
|
||||
ICPPScope scope = null;
|
||||
if (start instanceof ICPPScope)
|
||||
scope = (ICPPScope) start;
|
||||
else if (start instanceof IASTName)
|
||||
scope = getLookupScope((IASTName) start);
|
||||
else
|
||||
|
||||
IASTNode blockItem= data.astName;
|
||||
if (blockItem == null)
|
||||
return;
|
||||
|
||||
if (data.astName == null)
|
||||
|
||||
ICPPScope nextScope= null;
|
||||
if (start instanceof ICPPScope) {
|
||||
nextScope= (ICPPScope) start;
|
||||
} else if (start instanceof IASTName) {
|
||||
nextScope= getLookupScope((IASTName) start);
|
||||
}
|
||||
if (nextScope == null)
|
||||
return;
|
||||
|
||||
|
||||
boolean friendInLocalClass = false;
|
||||
if (scope instanceof ICPPClassScope && data.forFriendship()) {
|
||||
if (nextScope instanceof ICPPClassScope && data.forFriendship()) {
|
||||
try {
|
||||
ICPPClassType cls = ((ICPPClassScope)scope).getClassType();
|
||||
ICPPClassType cls = ((ICPPClassScope)nextScope).getClassType();
|
||||
friendInLocalClass = !cls.isGloballyQualified();
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
|
||||
ICPPTemplateScope nextTmplScope;
|
||||
if (nextScope instanceof ICPPTemplateScope) {
|
||||
nextTmplScope= (ICPPTemplateScope) nextScope;
|
||||
nextScope= getParentScope(nextScope, data.tu);
|
||||
} else {
|
||||
nextTmplScope= enclosingTemplateScope(data.astName);
|
||||
}
|
||||
|
||||
while (scope != null) {
|
||||
|
||||
while (nextScope != null || nextTmplScope != null) {
|
||||
// when the non-template scope is no longer contained within the first template scope,
|
||||
// we use the template scope for the next iteration.
|
||||
boolean useTemplScope= false;
|
||||
if (nextTmplScope != null) {
|
||||
useTemplScope= true;
|
||||
if (nextScope instanceof IASTInternalScope) {
|
||||
final IASTNode node= ((IASTInternalScope) nextScope).getPhysicalNode();
|
||||
if (node != null && nextTmplScope.getTemplateDeclaration().contains(node)) {
|
||||
useTemplScope= false;
|
||||
}
|
||||
}
|
||||
}
|
||||
ICPPScope scope= useTemplScope ? nextTmplScope : nextScope;
|
||||
if (scope instanceof IIndexScope && data.tu != null) {
|
||||
scope= (ICPPScope) data.tu.mapToASTScope(((IIndexScope) scope));
|
||||
}
|
||||
IASTNode blockItem = CPPVisitor.getContainingBlockItem(node);
|
||||
blockItem = CPPVisitor.getContainingBlockItem(blockItem);
|
||||
|
||||
if (!data.usingDirectivesOnly) {
|
||||
if (data.contentAssist) {
|
||||
|
@ -737,29 +761,37 @@ public class CPPSemantics {
|
|||
data.usingDirectivesOnly = true;
|
||||
}
|
||||
|
||||
if (blockItem != null)
|
||||
node = blockItem;
|
||||
|
||||
ICPPScope parentScope = (ICPPScope) getParentScope(scope, data.tu);
|
||||
if (parentScope instanceof ICPPTemplateScope) {
|
||||
IASTNode declNode = node;
|
||||
while (declNode != null && !(declNode instanceof ICPPASTTemplateDeclaration)) {
|
||||
node = declNode;
|
||||
declNode = declNode.getParent();
|
||||
}
|
||||
if (declNode != null) {
|
||||
ICPPASTTemplateDeclaration templateDecl = (ICPPASTTemplateDeclaration) declNode;
|
||||
ICPPTemplateScope templateScope = templateDecl.getScope();
|
||||
if (templateScope.getTemplateDefinition() == ((ICPPTemplateScope)parentScope).getTemplateDefinition()) {
|
||||
parentScope = templateScope;
|
||||
}
|
||||
}
|
||||
// compute next scopes
|
||||
if (useTemplScope && nextTmplScope != null) {
|
||||
nextTmplScope= enclosingTemplateScope(nextTmplScope.getTemplateDeclaration());
|
||||
} else {
|
||||
nextScope= getParentScope(scope, data.tu);
|
||||
}
|
||||
scope = parentScope;
|
||||
}
|
||||
}
|
||||
|
||||
private static IScope getParentScope(IScope scope, CPPASTTranslationUnit unit) throws DOMException {
|
||||
|
||||
private static ICPPTemplateScope enclosingTemplateScope(IASTNode node) {
|
||||
IASTNode parent= node.getParent();
|
||||
if (parent instanceof IASTName) {
|
||||
if (parent instanceof ICPPASTTemplateId) {
|
||||
node= parent;
|
||||
parent= node.getParent();
|
||||
}
|
||||
if (parent instanceof ICPPASTQualifiedName) {
|
||||
ICPPASTQualifiedName qname= (ICPPASTQualifiedName) parent;
|
||||
if (qname.isFullyQualified() || qname.getNames()[0] != node)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
while (!(parent instanceof ICPPASTTemplateDeclaration)) {
|
||||
if (parent == null)
|
||||
return null;
|
||||
parent= parent.getParent();
|
||||
}
|
||||
return ((ICPPASTTemplateDeclaration) parent).getScope();
|
||||
}
|
||||
|
||||
private static ICPPScope getParentScope(IScope scope, CPPASTTranslationUnit unit) throws DOMException {
|
||||
IScope parentScope= scope.getParent();
|
||||
// the index cannot return the translation unit as parent scope
|
||||
if (unit != null) {
|
||||
|
@ -770,7 +802,7 @@ public class CPPSemantics {
|
|||
parentScope= unit.mapToASTScope((IIndexScope) parentScope);
|
||||
}
|
||||
}
|
||||
return parentScope;
|
||||
return (ICPPScope) parentScope;
|
||||
}
|
||||
|
||||
private static Object lookupInParents(LookupData data, ICPPScope lookIn) throws DOMException{
|
||||
|
|
|
@ -369,36 +369,25 @@ public class CPPVisitor {
|
|||
if (mustBeSimple && elabType.getName() instanceof ICPPASTQualifiedName)
|
||||
return binding;
|
||||
|
||||
boolean template = false;
|
||||
ICPPScope scope = (ICPPScope) getContainingScope(name);
|
||||
if (scope instanceof ICPPTemplateScope) {
|
||||
ICPPScope parentScope = null;
|
||||
try {
|
||||
template = true;
|
||||
parentScope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
|
||||
} catch (DOMException e1) {
|
||||
}
|
||||
scope = parentScope;
|
||||
}
|
||||
|
||||
if (mustBeSimple) {
|
||||
//3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype scope that contains
|
||||
//the declaration
|
||||
while (scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) {
|
||||
try {
|
||||
scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
|
||||
} catch (DOMException e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (scope instanceof ICPPClassScope && isFriend && !qualified) {
|
||||
try {
|
||||
while (scope instanceof ICPPClassScope)
|
||||
scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
|
||||
} catch (DOMException e1) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
boolean template = false;
|
||||
ICPPScope scope = (ICPPScope) getContainingScope(name);
|
||||
while (scope instanceof ICPPTemplateScope) {
|
||||
template = true;
|
||||
scope= (ICPPScope) scope.getParent();
|
||||
}
|
||||
|
||||
if (mustBeSimple) {
|
||||
//3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype scope that contains
|
||||
//the declaration
|
||||
while (scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) {
|
||||
scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
|
||||
}
|
||||
}
|
||||
if (scope instanceof ICPPClassScope && isFriend && !qualified) {
|
||||
while (scope instanceof ICPPClassScope)
|
||||
scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
|
||||
}
|
||||
if (scope != null) {
|
||||
binding = scope.getBinding(elabType.getName(), false);
|
||||
}
|
||||
|
@ -426,19 +415,15 @@ public class CPPVisitor {
|
|||
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = ns[ns.length - 1];
|
||||
}
|
||||
ICPPScope scope = (ICPPScope) getContainingScope(name);
|
||||
boolean template = false;
|
||||
if (scope instanceof ICPPTemplateScope) {
|
||||
template = true;
|
||||
ICPPScope parentScope = null;
|
||||
try {
|
||||
parentScope = (ICPPScope) getParentScope(scope, compType.getTranslationUnit());
|
||||
} catch (DOMException e1) {
|
||||
}
|
||||
scope = parentScope;
|
||||
}
|
||||
IBinding binding = null;
|
||||
|
||||
IBinding binding = null;
|
||||
ICPPScope scope = (ICPPScope) getContainingScope(name);
|
||||
try {
|
||||
boolean template = false;
|
||||
while (scope instanceof ICPPTemplateScope) {
|
||||
template = true;
|
||||
scope= (ICPPScope) scope.getParent();
|
||||
}
|
||||
if (name instanceof ICPPASTTemplateId) {
|
||||
return CPPTemplates.createExplicitClassSpecialization(compType);
|
||||
}
|
||||
|
@ -550,32 +535,27 @@ public class CPPVisitor {
|
|||
return CPPTemplates.createBinding((ICPPASTTemplateParameter) parent);
|
||||
}
|
||||
|
||||
boolean template = false;
|
||||
ICPPScope scope = (ICPPScope) getContainingScope((IASTNode) name);
|
||||
if (scope instanceof ICPPTemplateScope) {
|
||||
ICPPScope parentScope = null;
|
||||
try {
|
||||
template = true;
|
||||
parentScope = (ICPPScope) getParentScope(scope, name.getTranslationUnit());
|
||||
} catch (DOMException e1) {
|
||||
}
|
||||
scope = parentScope;
|
||||
}
|
||||
if (parent instanceof IASTSimpleDeclaration && scope instanceof ICPPClassScope) {
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)parent).getDeclSpecifier();
|
||||
if (declSpec.isFriend()) {
|
||||
try {
|
||||
scope = (ICPPScope) getParentScope(scope, name.getTranslationUnit());
|
||||
} catch (DOMException e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IBinding binding;
|
||||
try {
|
||||
ICPPScope scope = (ICPPScope) getContainingScope((IASTNode) name);
|
||||
|
||||
boolean template = false;
|
||||
try {
|
||||
while (scope instanceof ICPPTemplateScope) {
|
||||
template = true;
|
||||
scope= (ICPPScope) scope.getParent();
|
||||
}
|
||||
if (parent instanceof IASTSimpleDeclaration && scope instanceof ICPPClassScope) {
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)parent).getDeclSpecifier();
|
||||
if (declSpec.isFriend()) {
|
||||
try {
|
||||
scope = (ICPPScope) getParentScope(scope, name.getTranslationUnit());
|
||||
} catch (DOMException e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
binding = (scope != null) ? scope.getBinding(name, false) : null;
|
||||
} catch (DOMException e) {
|
||||
binding = null;
|
||||
return e.getProblem();
|
||||
}
|
||||
|
||||
IASTSimpleDeclaration simpleDecl = (parent instanceof IASTSimpleDeclaration) ?
|
||||
|
@ -754,6 +734,14 @@ public class CPPVisitor {
|
|||
|
||||
}
|
||||
|
||||
public static IScope getContainingNonTemplateScope(final IASTNode inputNode) {
|
||||
IScope scope= getContainingScope(inputNode);
|
||||
while (scope instanceof ICPPTemplateScope) {
|
||||
scope= CPPVisitor.getContainingScope(((ICPPTemplateScope) scope).getTemplateDeclaration());
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
public static IScope getContainingScope(final IASTNode inputNode) {
|
||||
if (inputNode == null || inputNode instanceof IASTTranslationUnit)
|
||||
return null;
|
||||
|
@ -787,27 +775,19 @@ public class CPPVisitor {
|
|||
return getContainingScope((IASTStatement) node);
|
||||
} else if (node instanceof IASTTypeId) {
|
||||
if (node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
|
||||
ICPPASTTemplateDeclaration decl = CPPTemplates.getTemplateDeclaration((IASTName) node.getParent());
|
||||
if (decl == null) {
|
||||
node = node.getParent();
|
||||
while (node instanceof IASTName)
|
||||
node = node.getParent();
|
||||
continue;
|
||||
}
|
||||
node= node.getParent(); // template-id
|
||||
while(node instanceof IASTName) {
|
||||
node= node.getParent();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
} else if (node instanceof IASTParameterDeclaration) {
|
||||
IASTNode parent = node.getParent();
|
||||
if (parent instanceof ICPPASTFunctionDeclarator) {
|
||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent;
|
||||
if (dtor.getNestedDeclarator() == null || dtor.getNestedDeclarator().getPointerOperators().length == 0) {
|
||||
while (parent.getParent() instanceof IASTDeclarator)
|
||||
parent = parent.getParent();
|
||||
ASTNodeProperty prop = parent.getPropertyInParent();
|
||||
if (prop == IASTSimpleDeclaration.DECLARATOR)
|
||||
return dtor.getFunctionScope();
|
||||
else if (prop == IASTFunctionDefinition.DECLARATOR)
|
||||
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent.getParent()).getBody()).getScope();
|
||||
}
|
||||
IScope scope= dtor.getFunctionScope();
|
||||
if (scope != null)
|
||||
return scope;
|
||||
} else if (parent instanceof ICPPASTTemplateDeclaration) {
|
||||
return CPPTemplates.getContainingScope(node);
|
||||
}
|
||||
|
@ -890,9 +870,6 @@ public class CPPVisitor {
|
|||
name = (IASTName) parent;
|
||||
parent = name.getParent();
|
||||
}
|
||||
ICPPASTTemplateDeclaration tmplDecl = CPPTemplates.getTemplateDeclaration(name);
|
||||
if (tmplDecl != null)
|
||||
return tmplDecl.getScope();
|
||||
|
||||
if (parent instanceof ICPPASTQualifiedName) {
|
||||
final ICPPASTQualifiedName qname= (ICPPASTQualifiedName) parent;
|
||||
|
@ -905,12 +882,6 @@ public class CPPVisitor {
|
|||
if (qname.isFullyQualified()) {
|
||||
return parent.getTranslationUnit().getScope();
|
||||
}
|
||||
for (int j=1; j < names.length; j++) {
|
||||
tmplDecl = CPPTemplates.getTemplateDeclaration(names[j]);
|
||||
if (tmplDecl != null) {
|
||||
return getContainingScope(tmplDecl);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i > 0) {
|
||||
IBinding binding = names[i-1].resolveBinding();
|
||||
|
@ -1768,8 +1739,9 @@ public class CPPVisitor {
|
|||
funcName = ns[ns.length - 1];
|
||||
}
|
||||
IScope s = getContainingScope(funcName);
|
||||
if (s instanceof ICPPTemplateScope)
|
||||
s = getParentScope(s, funcName.getTranslationUnit());
|
||||
while (s instanceof ICPPTemplateScope) {
|
||||
s = s.getParent();
|
||||
}
|
||||
if (s instanceof ICPPClassScope) {
|
||||
ICPPClassScope cScope = (ICPPClassScope) s;
|
||||
IType type = cScope.getClassType();
|
||||
|
|
|
@ -46,7 +46,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
|
@ -102,9 +101,6 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
|
|||
}
|
||||
return new CompositeCPPNamespaceScope(this, namespaces);
|
||||
}
|
||||
if (rscope instanceof ICPPTemplateScope) {
|
||||
return new CompositeCPPTemplateScope(this, (ICPPTemplateScope) rscope);
|
||||
}
|
||||
if (rscope instanceof ICPPInternalUnknownScope) {
|
||||
ICPPInternalUnknownScope uscope= (ICPPInternalUnknownScope) rscope;
|
||||
final ICPPBinding binding = uscope.getScopeBinding();
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2008 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index.composite.cpp;
|
||||
|
||||
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.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
|
||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||
|
||||
public class CompositeCPPTemplateScope extends CompositeScope implements ICPPTemplateScope {
|
||||
public CompositeCPPTemplateScope(ICompositesFactory cf,
|
||||
ICPPTemplateScope rbinding) {
|
||||
super(cf, (IIndexFragmentBinding) ((IIndexScope)rbinding).getScopeBinding());
|
||||
}
|
||||
|
||||
public ICPPTemplateDefinition getTemplateDefinition() throws DOMException {
|
||||
ICPPTemplateDefinition preresult= (getTemplateScope()).getTemplateDefinition();
|
||||
return (ICPPTemplateDefinition) processUncertainBinding(preresult);
|
||||
}
|
||||
|
||||
private ICPPTemplateScope getTemplateScope() {
|
||||
if (rbinding instanceof ICPPTemplateScope)
|
||||
return (ICPPTemplateScope) rbinding;
|
||||
return (ICPPTemplateScope) rbinding.getScope();
|
||||
}
|
||||
|
||||
public IBinding[] find(String name) throws DOMException {
|
||||
IBinding[] preresult = (getTemplateScope()).find(name);
|
||||
return processUncertainBindings(preresult);
|
||||
}
|
||||
|
||||
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
|
||||
IBinding binding = (getTemplateScope()).getBinding(name, resolve, fileSet);
|
||||
return processUncertainBinding(binding);
|
||||
}
|
||||
|
||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
|
||||
IBinding[] bindings = (getTemplateScope()).getBindings(name, resolve, prefixLookup, fileSet);
|
||||
return processUncertainBindings(bindings);
|
||||
}
|
||||
|
||||
public IIndexBinding getScopeBinding() {
|
||||
return cf.getCompositeBinding(rbinding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIndexScope getParent() {
|
||||
// the binding is the binding for both the composite and the template scope, so
|
||||
// make sure to use the parent of the scope.
|
||||
final IIndexScope templateScope= rbinding.getScope();
|
||||
return cf.getCompositeScope(templateScope.getParent());
|
||||
}
|
||||
}
|
|
@ -198,7 +198,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding
|
|||
return null;
|
||||
}
|
||||
|
||||
public IIndexScope getScope() {
|
||||
public final IIndexScope getScope() {
|
||||
// The parent node in the binding hierarchy is the scope.
|
||||
try {
|
||||
IBinding parent= getParentBinding();
|
||||
|
|
|
@ -19,32 +19,21 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
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.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
||||
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.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
@ -141,77 +130,7 @@ public class PDOMCPPClassTemplate extends PDOMCPPClassType implements ICPPClassT
|
|||
return new ICPPClassTemplatePartialSpecialization[0];
|
||||
}
|
||||
}
|
||||
|
||||
private class PDOMCPPTemplateScope implements ICPPTemplateScope, IIndexScope {
|
||||
public IBinding[] find(String name) throws DOMException {
|
||||
return CPPSemantics.findBindings(this, name, false);
|
||||
}
|
||||
|
||||
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
|
||||
return getBinding(name, resolve, IIndexFileSet.EMPTY);
|
||||
}
|
||||
|
||||
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
|
||||
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
|
||||
}
|
||||
|
||||
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet)
|
||||
throws DOMException {
|
||||
try {
|
||||
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray());
|
||||
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + PARAMETERS, getLinkageImpl());
|
||||
list.accept(visitor);
|
||||
|
||||
return CPPSemantics.resolveAmbiguities(name, visitor.getBindings());
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet)
|
||||
throws DOMException {
|
||||
IBinding[] result = null;
|
||||
try {
|
||||
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null,
|
||||
prefixLookup, !prefixLookup);
|
||||
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + PARAMETERS, getLinkageImpl());
|
||||
list.accept(visitor);
|
||||
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
|
||||
}
|
||||
|
||||
public IIndexScope getParent() {
|
||||
return PDOMCPPClassTemplate.this.getParent();
|
||||
}
|
||||
|
||||
public ICPPTemplateDefinition getTemplateDefinition()
|
||||
throws DOMException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public IIndexName getScopeName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public IIndexBinding getScopeBinding() {
|
||||
return PDOMCPPClassTemplate.this;
|
||||
}
|
||||
}
|
||||
|
||||
private PDOMCPPTemplateScope scope;
|
||||
|
||||
@Override
|
||||
public IIndexScope getScope() {
|
||||
if (scope == null) {
|
||||
scope = new PDOMCPPTemplateScope();
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(IPDOMVisitor visitor) throws CoreException {
|
||||
super.accept(visitor);
|
||||
|
|
|
@ -10,10 +10,8 @@
|
|||
* IBM Corporation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
|
@ -50,12 +48,7 @@ class PDOMCPPField extends PDOMCPPVariable implements ICPPField {
|
|||
}
|
||||
|
||||
public ICPPClassType getClassOwner() {
|
||||
try {
|
||||
return (ICPPClassType)getParentNode();
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
}
|
||||
return (ICPPClassType) getOwner();
|
||||
}
|
||||
|
||||
public int getVisibility() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2007, 2008 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
|
||||
|
@ -111,7 +111,7 @@ class PDOMCPPFieldSpecialization extends PDOMCPPSpecialization implements
|
|||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
return getField().getClassOwner();
|
||||
return (ICPPClassType) getOwner();
|
||||
}
|
||||
|
||||
public int getVisibility() throws DOMException {
|
||||
|
|
|
@ -23,10 +23,8 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
@ -46,7 +44,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* @author Bryan Wilkinson
|
||||
*/
|
||||
class PDOMCPPFunctionTemplate extends PDOMCPPFunction
|
||||
implements ICPPFunctionTemplate, ICPPInstanceCache, IPDOMMemberOwner, ICPPTemplateScope, IIndexScope {
|
||||
implements ICPPFunctionTemplate, ICPPInstanceCache, IPDOMMemberOwner, IIndexScope {
|
||||
|
||||
private static final int TEMPLATE_PARAMS = PDOMCPPFunction.RECORD_SIZE + 0;
|
||||
|
||||
|
@ -122,10 +120,6 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction
|
|||
list.accept(visitor);
|
||||
}
|
||||
|
||||
public ICPPTemplateDefinition getTemplateDefinition() throws DOMException {
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBinding[] find(String name) throws DOMException {
|
||||
return CPPSemantics.findBindings( this, name, false );
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2007, 2008 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
* QNX - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
|
@ -40,11 +41,6 @@ class PDOMCPPFunctionTemplateSpecialization extends PDOMCPPFunctionSpecializatio
|
|||
super(pdom, bindingRecord);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeType() {
|
||||
return IIndexCPPBindingConstants.CPP_FUNCTION_TEMPLATE_SPECIALIZATION;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
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.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
|
@ -151,12 +150,7 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod {
|
|||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
try {
|
||||
return (ICPPClassType) getParentNode();
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
}
|
||||
return (ICPPClassType) getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -70,7 +70,7 @@ class PDOMCPPMethodInstance extends PDOMCPPFunctionInstance implements
|
|||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
return ((ICPPMethod)getTemplateDefinition()).getClassOwner();
|
||||
return (ICPPClassType) getOwner();
|
||||
}
|
||||
|
||||
public int getVisibility() throws DOMException {
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
|
@ -103,11 +101,7 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization
|
|||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
IScope scope= getScope();
|
||||
if (scope instanceof ICPPClassScope) {
|
||||
return ((ICPPClassScope) scope).getClassType();
|
||||
}
|
||||
return null;
|
||||
return (ICPPClassType) getOwner();
|
||||
}
|
||||
|
||||
public int getVisibility() throws DOMException {
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
*******************************************************************************/
|
||||
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.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||
|
@ -92,12 +91,7 @@ class PDOMCPPMethodTemplate extends PDOMCPPFunctionTemplate implements ICPPMetho
|
|||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
try {
|
||||
return (ICPPClassType) getParentNode();
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
}
|
||||
return (ICPPClassType) getOwner();
|
||||
}
|
||||
|
||||
public int getVisibility() throws DOMException {
|
||||
|
|
|
@ -13,12 +13,9 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
|
@ -31,12 +28,6 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
class PDOMCPPMethodTemplateSpecialization extends
|
||||
PDOMCPPFunctionTemplateSpecialization implements ICPPMethod {
|
||||
|
||||
/**
|
||||
* The size in bytes of a PDOMCPPMethodTemplateSpecialization record in the database.
|
||||
*/
|
||||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = PDOMCPPFunctionTemplateSpecialization.RECORD_SIZE + 0;
|
||||
|
||||
public PDOMCPPMethodTemplateSpecialization(PDOM pdom, PDOMNode parent, ICPPMethod method, PDOMBinding specialized)
|
||||
throws CoreException {
|
||||
|
@ -47,11 +38,6 @@ class PDOMCPPMethodTemplateSpecialization extends
|
|||
super(pdom, bindingRecord);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeType() {
|
||||
return IIndexCPPBindingConstants.CPP_METHOD_TEMPLATE_SPECIALIZATION;
|
||||
|
@ -82,14 +68,7 @@ class PDOMCPPMethodTemplateSpecialization extends
|
|||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
IScope scope= getScope();
|
||||
if (scope instanceof ICPPTemplateScope) {
|
||||
scope= scope.getParent();
|
||||
}
|
||||
if( scope instanceof ICPPClassScope ){
|
||||
return ((ICPPClassScope)scope).getClassType();
|
||||
}
|
||||
return null;
|
||||
return (ICPPClassType) getOwner();
|
||||
}
|
||||
|
||||
public int getVisibility() throws DOMException {
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 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 Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.tests;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
|
||||
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
|
||||
import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.AST2CSpecFailingTest;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class LRCSpecFailingTest extends AST2CSpecFailingTest {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(LRCSpecFailingTest.class);
|
||||
}
|
||||
|
||||
public LRCSpecFailingTest() { }
|
||||
public LRCSpecFailingTest(String name) { super(name); }
|
||||
|
||||
|
||||
@Override
|
||||
protected void parseCandCPP( String code, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
|
||||
parse(code, ParserLanguage.C, checkBindings, expectedProblemBindings);
|
||||
parse(code, ParserLanguage.CPP, checkBindings, expectedProblemBindings);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
|
||||
return ParseHelper.parse(code, language, true, checkBindings, expectedProblemBindings );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IASTTranslationUnit parse(String code, ParserLanguage lang, String[] problems) throws ParserException {
|
||||
ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
|
||||
return ParseHelper.parse(code, language, problems);
|
||||
}
|
||||
|
||||
protected BaseExtensibleLanguage getCLanguage() {
|
||||
return C99Language.getDefault();
|
||||
}
|
||||
|
||||
protected BaseExtensibleLanguage getCPPLanguage() {
|
||||
return ISOCPPLanguage.getDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test6_7_7s6() throws Exception { // this test actually passes, yay!
|
||||
try {
|
||||
super.test6_7_7s6();
|
||||
} catch (AssertionFailedError e) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,7 +36,6 @@ public class LRParserTestSuite extends TestSuite {
|
|||
addTestSuite(LRCPPSpecFailingTest.class);
|
||||
addTestSuite(LRCPPSpecTest.class);
|
||||
addTestSuite(LRCPPTests.class);
|
||||
addTestSuite(LRCSpecFailingTest.class);
|
||||
addTestSuite(LRCSpecTests.class); // a couple of failures
|
||||
addTestSuite(LRDigraphTrigraphTests.class);
|
||||
addTestSuite(LRDOMLocationInclusionTests.class);
|
||||
|
|
Loading…
Add table
Reference in a new issue