1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 04:45:38 +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:
Nathan Ridge 2014-04-12 02:34:28 -04:00 committed by Sergey Prigogin
parent f5942dac81
commit aeb5ad721f
6 changed files with 94 additions and 6 deletions

View file

@ -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();
}

View file

@ -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.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.ICPPEnumScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
/**
* Implementation of namespace scopes, including global scope.
*/
public class CPPEnumScope extends CPPScope {
public class CPPEnumScope extends CPPScope implements ICPPEnumScope {
public CPPEnumScope(ICPPASTEnumerationSpecifier specifier) {
super(specifier);
}
@ -32,4 +37,15 @@ public class CPPEnumScope extends CPPScope {
ICPPASTEnumerationSpecifier node = (ICPPASTEnumerationSpecifier) getPhysicalNode();
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());
}
}

View file

@ -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.CharArrayUtils;
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.SemanticUtil;
import org.eclipse.core.runtime.PlatformObject;
@ -51,6 +52,37 @@ import org.eclipse.core.runtime.PlatformObject;
public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, ICPPInternalBinding {
private static final IASTName NOT_INITIALIZED = CPPASTName.NOT_INITIALIZED;
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 IType fFixedType;

View file

@ -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.ICPPClassType;
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.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
@ -122,6 +123,10 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
ICPPClassScope classScope = (ICPPClassScope) rscope;
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) {
ICPPNamespace[] namespaces;
if (rscope instanceof CompositeCPPNamespace) {
@ -131,7 +136,7 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
namespaces = getNamespaces(rscope.getScopeBinding());
}
return new CompositeCPPNamespaceScope(this, namespaces);
}
}
throw new CompositingNotImplementedError(rscope.getClass().getName());
} catch (CoreException e) {
CCorePlugin.log(e);

View file

@ -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.IASTName;
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.ICPPScope;
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.composite.CompositeScope;
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) {
super(cf, rbinding);
}
@ -58,4 +58,9 @@ class CompositeCPPEnumScope extends CompositeScope implements ICPPScope {
public IIndexBinding getScopeBinding() {
return cf.getCompositeBinding(rbinding);
}
@Override
public ICPPEnumeration getEnumerationType() {
return (ICPPEnumeration) getScopeBinding();
}
}

View file

@ -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.IBinding;
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.IIndexFileSet;
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.
* For safe use all fields need to be final.
*/
class PDOMCPPEnumScope implements ICPPScope, IIndexScope {
class PDOMCPPEnumScope implements ICPPEnumScope, IIndexScope {
private final IPDOMCPPEnumType fBinding;
public PDOMCPPEnumScope(IPDOMCPPEnumType binding) {
@ -190,4 +191,9 @@ class PDOMCPPEnumScope implements ICPPScope, IIndexScope {
CCorePlugin.log(e);
}
}
@Override
public ICPPEnumeration getEnumerationType() {
return (ICPPEnumeration) getScopeBinding();
}
}