mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-01 05:15:43 +02:00
Bug 432643 - Implement compositing for enum scopes
Change-Id: I0e96f4d831bd1be0325262d1f77fab5dd05ddbe7 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/24898 Tested-by: Hudson CI Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
f5942dac81
commit
aeb5ad721f
6 changed files with 94 additions and 6 deletions
|
@ -0,0 +1,24 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2014 Nathan Ridge.
|
||||||
|
* 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:
|
||||||
|
* Nathan Ridge - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for enumeration scopes.
|
||||||
|
*
|
||||||
|
* @noimplement This interface is not intended to be implemented by clients.
|
||||||
|
* @noextend This interface is not intended to be extended by clients.
|
||||||
|
*/
|
||||||
|
public interface ICPPEnumScope extends ICPPScope {
|
||||||
|
/**
|
||||||
|
* Returns the binding for the enumeration this scope is associated with.
|
||||||
|
*/
|
||||||
|
ICPPEnumeration getEnumerationType();
|
||||||
|
}
|
|
@ -12,12 +12,17 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.IName;
|
import org.eclipse.cdt.core.dom.IName;
|
||||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
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.dom.ast.ISemanticProblem;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTEnumerationSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTEnumerationSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumScope;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of namespace scopes, including global scope.
|
* Implementation of namespace scopes, including global scope.
|
||||||
*/
|
*/
|
||||||
public class CPPEnumScope extends CPPScope {
|
public class CPPEnumScope extends CPPScope implements ICPPEnumScope {
|
||||||
public CPPEnumScope(ICPPASTEnumerationSpecifier specifier) {
|
public CPPEnumScope(ICPPASTEnumerationSpecifier specifier) {
|
||||||
super(specifier);
|
super(specifier);
|
||||||
}
|
}
|
||||||
|
@ -32,4 +37,15 @@ public class CPPEnumScope extends CPPScope {
|
||||||
ICPPASTEnumerationSpecifier node = (ICPPASTEnumerationSpecifier) getPhysicalNode();
|
ICPPASTEnumerationSpecifier node = (ICPPASTEnumerationSpecifier) getPhysicalNode();
|
||||||
return node.getName();
|
return node.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ICPPEnumeration getEnumerationType() {
|
||||||
|
ICPPASTEnumerationSpecifier node = (ICPPASTEnumerationSpecifier) getPhysicalNode();
|
||||||
|
final IASTName name = node.getName();
|
||||||
|
IBinding binding = name.resolveBinding();
|
||||||
|
if (binding instanceof ICPPEnumeration)
|
||||||
|
return (ICPPEnumeration) binding;
|
||||||
|
|
||||||
|
return new CPPEnumeration.CPPEnumerationProblem(name, ISemanticProblem.BINDING_NO_CLASS, name.toCharArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
|
@ -51,6 +52,37 @@ import org.eclipse.core.runtime.PlatformObject;
|
||||||
public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, ICPPInternalBinding {
|
public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, ICPPInternalBinding {
|
||||||
private static final IASTName NOT_INITIALIZED = CPPASTName.NOT_INITIALIZED;
|
private static final IASTName NOT_INITIALIZED = CPPASTName.NOT_INITIALIZED;
|
||||||
private static final IEnumerator[] EMPTY_ENUMERATORS = {};
|
private static final IEnumerator[] EMPTY_ENUMERATORS = {};
|
||||||
|
|
||||||
|
public static class CPPEnumerationProblem extends ProblemBinding implements ICPPEnumeration, ICPPScope {
|
||||||
|
public CPPEnumerationProblem(IASTNode node, int id, char[] arg) {
|
||||||
|
super(node, id, arg);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public IEnumerator[] getEnumerators() {
|
||||||
|
return EMPTY_ENUMERATORS;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public long getMinValue() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public long getMaxValue() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isScoped() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public IType getFixedType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ICPPScope asScope() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private final boolean fIsScoped;
|
private final boolean fIsScoped;
|
||||||
private final IType fFixedType;
|
private final IType fFixedType;
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecializationSpecialization;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecializationSpecialization;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||||
|
@ -122,6 +123,10 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
|
||||||
ICPPClassScope classScope = (ICPPClassScope) rscope;
|
ICPPClassScope classScope = (ICPPClassScope) rscope;
|
||||||
return new CompositeCPPClassScope(this, findOneBinding(classScope.getClassType()));
|
return new CompositeCPPClassScope(this, findOneBinding(classScope.getClassType()));
|
||||||
}
|
}
|
||||||
|
if (rscope instanceof ICPPEnumScope) {
|
||||||
|
ICPPEnumScope enumScope = (ICPPEnumScope) rscope;
|
||||||
|
return new CompositeCPPEnumScope(this, findOneBinding(enumScope.getEnumerationType()));
|
||||||
|
}
|
||||||
if (rscope instanceof ICPPNamespaceScope) {
|
if (rscope instanceof ICPPNamespaceScope) {
|
||||||
ICPPNamespace[] namespaces;
|
ICPPNamespace[] namespaces;
|
||||||
if (rscope instanceof CompositeCPPNamespace) {
|
if (rscope instanceof CompositeCPPNamespace) {
|
||||||
|
@ -131,7 +136,7 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
|
||||||
namespaces = getNamespaces(rscope.getScopeBinding());
|
namespaces = getNamespaces(rscope.getScopeBinding());
|
||||||
}
|
}
|
||||||
return new CompositeCPPNamespaceScope(this, namespaces);
|
return new CompositeCPPNamespaceScope(this, namespaces);
|
||||||
}
|
}
|
||||||
throw new CompositingNotImplementedError(rscope.getClass().getName());
|
throw new CompositingNotImplementedError(rscope.getClass().getName());
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
|
|
|
@ -13,15 +13,15 @@ package org.eclipse.cdt.internal.core.index.composite.cpp;
|
||||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
|
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||||
|
|
||||||
class CompositeCPPEnumScope extends CompositeScope implements ICPPScope {
|
class CompositeCPPEnumScope extends CompositeScope implements ICPPEnumScope {
|
||||||
public CompositeCPPEnumScope(ICompositesFactory cf, IIndexFragmentBinding rbinding) {
|
public CompositeCPPEnumScope(ICompositesFactory cf, IIndexFragmentBinding rbinding) {
|
||||||
super(cf, rbinding);
|
super(cf, rbinding);
|
||||||
}
|
}
|
||||||
|
@ -58,4 +58,9 @@ class CompositeCPPEnumScope extends CompositeScope implements ICPPScope {
|
||||||
public IIndexBinding getScopeBinding() {
|
public IIndexBinding getScopeBinding() {
|
||||||
return cf.getCompositeBinding(rbinding);
|
return cf.getCompositeBinding(rbinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ICPPEnumeration getEnumerationType() {
|
||||||
|
return (ICPPEnumeration) getScopeBinding();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,8 @@ import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumScope;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
|
@ -40,7 +41,7 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
* Represents the enum scope for an enum stored in the index.
|
* Represents the enum scope for an enum stored in the index.
|
||||||
* For safe use all fields need to be final.
|
* For safe use all fields need to be final.
|
||||||
*/
|
*/
|
||||||
class PDOMCPPEnumScope implements ICPPScope, IIndexScope {
|
class PDOMCPPEnumScope implements ICPPEnumScope, IIndexScope {
|
||||||
private final IPDOMCPPEnumType fBinding;
|
private final IPDOMCPPEnumType fBinding;
|
||||||
|
|
||||||
public PDOMCPPEnumScope(IPDOMCPPEnumType binding) {
|
public PDOMCPPEnumScope(IPDOMCPPEnumType binding) {
|
||||||
|
@ -190,4 +191,9 @@ class PDOMCPPEnumScope implements ICPPScope, IIndexScope {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ICPPEnumeration getEnumerationType() {
|
||||||
|
return (ICPPEnumeration) getScopeBinding();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue