1
/*******************************************************************************
2
* Copyright (c) 2006, 2009 QNX Software Systems 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
* Doug Schaefer (QNX) - Initial API and implementation
10
* Markus Schorn (Wind River Systems)
11
*******************************************************************************/
13
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
15
import org.eclipse.cdt.core.CCorePlugin;
16
import org.eclipse.cdt.core.dom.ast.DOMException;
17
import org.eclipse.cdt.core.dom.ast.IBinding;
18
import org.eclipse.cdt.core.dom.ast.IEnumerator;
19
import org.eclipse.cdt.core.dom.ast.IType;
20
import org.eclipse.cdt.core.dom.ast.IValue;
21
import org.eclipse.cdt.internal.core.dom.parser.Value;
22
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
23
import org.eclipse.cdt.internal.core.pdom.db.Database;
24
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
25
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
26
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
27
import org.eclipse.core.runtime.CoreException;
30
* Binding for a c++ enumerator in the index.
32
class PDOMCPPEnumerator extends PDOMCPPBinding implements IEnumerator {
34
private static final int ENUMERATION = PDOMBinding.RECORD_SIZE + 0;
35
private static final int NEXT_ENUMERATOR = PDOMBinding.RECORD_SIZE + 4;
36
private static final int VALUE= PDOMBinding.RECORD_SIZE + 8;
38
@SuppressWarnings("hiding")
39
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 12;
41
public PDOMCPPEnumerator(PDOMLinkage linkage, PDOMNode parent, IEnumerator enumerator, PDOMCPPEnumeration enumeration)
42
throws CoreException {
43
super(linkage, parent, enumerator.getNameCharArray());
45
final Database db = getDB();
46
db.putRecPtr(record + ENUMERATION, enumeration.getRecord());
47
storeValue(db, enumerator);
48
enumeration.addEnumerator(this);
51
public PDOMCPPEnumerator(PDOMLinkage linkage, long record) {
52
super(linkage, record);
56
protected int getRecordSize() {
61
public int getNodeType() {
62
return IIndexCPPBindingConstants.CPPENUMERATOR;
65
private void storeValue(final Database db, IEnumerator enumerator) throws CoreException {
66
IValue value= enumerator.getValue();
68
Long val= value.numericalValue();
69
db.putInt(record + VALUE, val == null ? -1 : val.intValue());
74
public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
75
if (newBinding instanceof IEnumerator)
76
storeValue(getDB(), (IEnumerator) newBinding);
79
public PDOMCPPEnumerator getNextEnumerator() throws CoreException {
80
long value = getDB().getRecPtr(record + NEXT_ENUMERATOR);
81
return value != 0 ? new PDOMCPPEnumerator(getLinkage(), value) : null;
84
public void setNextEnumerator(PDOMCPPEnumerator enumerator) throws CoreException {
85
long value = enumerator != null ? enumerator.getRecord() : 0;
86
getDB().putRecPtr(record + NEXT_ENUMERATOR, value);
89
public IType getType() throws DOMException {
91
return new PDOMCPPEnumeration(getLinkage(), getDB().getRecPtr(record + ENUMERATION));
92
} catch (CoreException e) {
98
public IValue getValue() {
100
int val= getDB().getInt(record + VALUE);
101
return Value.create(val);
102
} catch (CoreException e) {
105
return Value.UNKNOWN;