Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2793df0597e482b44c4557ff7f434b7f1b35dcd3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*******************************************************************************
 * Copyright (c) 2004, 2014 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:
 *     John Camelon (IBM) - Initial API and implementation
 *     Markus Schorn (Wind River Systems)
 *     Thomas Corbat (IFS)
 *     Sergey Prigogin (Google)
 *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;

import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalEnumerationSpecifier;

/**
 * AST node for C++ enumeration specifiers.
 */
public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier
		implements IASTInternalEnumerationSpecifier, ICPPASTEnumerationSpecifier {
	private boolean fIsScoped;
	private boolean fIsOpaque;
	private IASTName fName;
	private ICPPASTDeclSpecifier fBaseType;

	private IASTEnumerator[] fEnumerators = IASTEnumerator.EMPTY_ENUMERATOR_ARRAY;
	private int fNumEnumerators;

	private Boolean fValuesComputed;
	private CPPEnumScope fScope;

	public CPPASTEnumerationSpecifier() {
	}

	public CPPASTEnumerationSpecifier(boolean isScoped, IASTName name, ICPPASTDeclSpecifier baseType) {
		fIsScoped= isScoped;
		setName(name);
		setBaseType(baseType);
	}
	
	@Override
	public CPPASTEnumerationSpecifier copy() {
		return copy(CopyStyle.withoutLocations);
	}
	
	@Override
	public CPPASTEnumerationSpecifier copy(CopyStyle style) {
		CPPASTEnumerationSpecifier copy = new CPPASTEnumerationSpecifier(fIsScoped,
				fName == null ? null : fName.copy(style),
				fBaseType == null ? null : fBaseType.copy(style));
		copy.fIsOpaque = fIsOpaque;
		for (IASTEnumerator enumerator : getEnumerators()) {
			copy.addEnumerator(enumerator == null ? null : enumerator.copy(style));
		}
		return super.copy(copy, style);
	}
	
	@Override
	public boolean startValueComputation() {
		if (fValuesComputed != null)
			return false;
		
		fValuesComputed= Boolean.FALSE;
		return true;
	}

	@Override
	public void finishValueComputation() {
		fValuesComputed= Boolean.TRUE;
	}

	@Override
	public boolean isValueComputationInProgress() {
		return fValuesComputed != null && !fValuesComputed;
	}

	@Override
	public void addEnumerator(IASTEnumerator enumerator) {
        assertNotFrozen();
		if (enumerator != null) {
			enumerator.setParent(this);
			enumerator.setPropertyInParent(ENUMERATOR);
			fEnumerators = ArrayUtil.appendAt(fEnumerators, fNumEnumerators++, enumerator);
		}
	}

	@Override
	public IASTEnumerator[] getEnumerators() {
		fEnumerators = ArrayUtil.trim(fEnumerators, fNumEnumerators);
		return fEnumerators;
	}

	@Override
	public void setName(IASTName name) {
        assertNotFrozen();
		fName = name;
		if (name != null) {
			name.setParent(this);
			name.setPropertyInParent(ENUMERATION_NAME);
		}
	}

	@Override
	public IASTName getName() {
		return fName;
	}

	@Override
	public boolean accept(ASTVisitor action) {
		if (action.shouldVisitDeclSpecifiers) {
			switch (action.visit(this)) {
			case ASTVisitor.PROCESS_ABORT:
				return false;
			case ASTVisitor.PROCESS_SKIP:
				return true;
			default:
				break;
			}
		}
		if (fName != null && !fName.accept(action))
			return false;
		
		if (fBaseType != null && !fBaseType.accept(action)) {
			return false;
		}

		if (!acceptByAttributeSpecifiers(action))
			return false;

		for (IASTEnumerator e : getEnumerators()) {
			if (!e.accept(action))
				return false;
		}
				
		if (action.shouldVisitDeclSpecifiers && action.leave(this) == ASTVisitor.PROCESS_ABORT)
			return false;

		return true;
	}

	@Override
	public int getRoleForName(IASTName n) {
		if (fName == n)
			return isOpaque() ? r_declaration : r_definition;
		return r_unclear;
	}

	@Override
	public void setIsScoped(boolean isScoped) {
		assertNotFrozen();
		fIsScoped= isScoped;
	}

	@Override
	public boolean isScoped() {
		return fIsScoped;
	}

	@Override
	public void setBaseType(ICPPASTDeclSpecifier baseType) {
		assertNotFrozen();
		fBaseType= baseType;
		if (baseType != null) {
			baseType.setParent(this);
			baseType.setPropertyInParent(BASE_TYPE);
		}
	}

	@Override
	public ICPPASTDeclSpecifier getBaseType() {
		return fBaseType;
	}

	@Override
	public void setIsOpaque(boolean isOpaque) {
		assertNotFrozen();
		fIsOpaque= isOpaque;
	}

	@Override
	public boolean isOpaque() {
		return fIsOpaque;
	}

	@Override
	public ICPPScope getScope() {
		if (isOpaque())
			return null;
		if (fScope == null) {
			fScope= new CPPEnumScope(this);
		}
		return fScope;
	}
}

Back to the top