1
/*******************************************************************************
2
* Copyright (c) 2004, 2009 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - initial API and implementation
10
* Markus Schorn (Wind River Systems)
11
* Sergey Prigogin (Google)
12
*******************************************************************************/
13
package org.eclipse.cdt.internal.core.dom.parser.cpp;
15
import org.eclipse.cdt.core.dom.ILinkage;
16
import org.eclipse.cdt.core.dom.ast.DOMException;
17
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
18
import org.eclipse.cdt.core.dom.ast.IASTName;
19
import org.eclipse.cdt.core.dom.ast.IASTNode;
20
import org.eclipse.cdt.core.dom.ast.IBinding;
21
import org.eclipse.cdt.core.dom.ast.IEnumeration;
22
import org.eclipse.cdt.core.dom.ast.IEnumerator;
23
import org.eclipse.cdt.core.dom.ast.IScope;
24
import org.eclipse.cdt.core.dom.ast.IType;
25
import org.eclipse.cdt.core.dom.ast.ITypedef;
26
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
27
import org.eclipse.cdt.internal.core.dom.Linkage;
28
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
29
import org.eclipse.cdt.internal.core.index.IIndexType;
30
import org.eclipse.core.runtime.PlatformObject;
35
public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPPInternalBinding {
36
private IASTName enumName;
38
public CPPEnumeration( IASTName name ) {
40
name.setBinding( this );
43
public IASTNode[] getDeclarations() {
47
public IASTNode getDefinition() {
51
public String getName() {
52
return new String(getNameCharArray());
55
public char[] getNameCharArray() {
56
return enumName.getSimpleID();
59
public IScope getScope() {
60
return CPPVisitor.getContainingScope( enumName );
63
public IASTNode getPhysicalNode() {
68
public Object clone(){
71
t = (IType) super.clone();
72
} catch ( CloneNotSupportedException e ) {
78
public IEnumerator[] getEnumerators() {
79
IASTEnumerationSpecifier.IASTEnumerator[] enums = ((IASTEnumerationSpecifier)enumName.getParent()).getEnumerators();
80
IEnumerator [] bindings = new IEnumerator [ enums.length ];
82
for( int i = 0; i < enums.length; i++ ){
83
bindings[i] = (IEnumerator) enums[i].getName().resolveBinding();
88
public String[] getQualifiedName() {
89
return CPPVisitor.getQualifiedName( this );
92
public char[][] getQualifiedNameCharArray() {
93
return CPPVisitor.getQualifiedNameCharArray( this );
96
public boolean isGloballyQualified() throws DOMException {
97
IScope scope = getScope();
98
while( scope != null ){
99
if( scope instanceof ICPPBlockScope )
101
scope = scope.getParent();
106
public void addDefinition(IASTNode node) {
109
public void addDeclaration(IASTNode node) {
112
public boolean isSameType( IType type ) {
115
if( type instanceof ITypedef || type instanceof IIndexType)
116
return type.isSameType( this );
120
public ILinkage getLinkage() {
121
return Linkage.CPP_LINKAGE;
124
public IBinding getOwner() throws DOMException {
125
return CPPVisitor.findDeclarationOwner(enumName, true);