~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumerator.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
7
 
 *
8
 
 * Contributors:
9
 
 *    Doug Schaefer (QNX) - Initial API and implementation
10
 
 *    Markus Schorn (Wind River Systems)
11
 
 *******************************************************************************/
12
 
 
13
 
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
14
 
 
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;
28
 
 
29
 
/**
30
 
 * Binding for a c++ enumerator in the index.
31
 
 */
32
 
class PDOMCPPEnumerator extends PDOMCPPBinding implements IEnumerator {
33
 
 
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;
37
 
        
38
 
        @SuppressWarnings("hiding")
39
 
        protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 12;
40
 
                
41
 
        public PDOMCPPEnumerator(PDOMLinkage linkage, PDOMNode parent, IEnumerator enumerator, PDOMCPPEnumeration enumeration)
42
 
                        throws CoreException {
43
 
                super(linkage, parent, enumerator.getNameCharArray());
44
 
                
45
 
                final Database db = getDB();
46
 
                db.putRecPtr(record + ENUMERATION, enumeration.getRecord());
47
 
                storeValue(db, enumerator);
48
 
                enumeration.addEnumerator(this);
49
 
        }
50
 
 
51
 
        public PDOMCPPEnumerator(PDOMLinkage linkage, long record) {
52
 
                super(linkage, record);
53
 
        }
54
 
 
55
 
        @Override
56
 
        protected int getRecordSize() {
57
 
                return RECORD_SIZE;
58
 
        }
59
 
        
60
 
        @Override
61
 
        public int getNodeType() {
62
 
                return IIndexCPPBindingConstants.CPPENUMERATOR;
63
 
        }
64
 
 
65
 
        private void storeValue(final Database db, IEnumerator enumerator) throws CoreException {
66
 
                IValue value= enumerator.getValue();
67
 
                if (value != null) {
68
 
                        Long val= value.numericalValue();
69
 
                        db.putInt(record + VALUE, val == null ? -1 : val.intValue());
70
 
                }
71
 
        }
72
 
        
73
 
        @Override
74
 
        public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
75
 
                if (newBinding instanceof IEnumerator)
76
 
                        storeValue(getDB(), (IEnumerator) newBinding);
77
 
        }
78
 
 
79
 
        public PDOMCPPEnumerator getNextEnumerator() throws CoreException {
80
 
                long value = getDB().getRecPtr(record + NEXT_ENUMERATOR);
81
 
                return value != 0 ? new PDOMCPPEnumerator(getLinkage(), value) : null;
82
 
        }
83
 
        
84
 
        public void setNextEnumerator(PDOMCPPEnumerator enumerator) throws CoreException {
85
 
                long value = enumerator != null ? enumerator.getRecord() : 0;
86
 
                getDB().putRecPtr(record + NEXT_ENUMERATOR, value);
87
 
        }
88
 
        
89
 
        public IType getType() throws DOMException {
90
 
                try {
91
 
                        return new PDOMCPPEnumeration(getLinkage(), getDB().getRecPtr(record + ENUMERATION));
92
 
                } catch (CoreException e) {
93
 
                        CCorePlugin.log(e);
94
 
                        return null;
95
 
                }
96
 
        }
97
 
        
98
 
        public IValue getValue() {
99
 
                try {
100
 
                        int val= getDB().getInt(record + VALUE);
101
 
                        return Value.create(val);
102
 
                } catch (CoreException e) {
103
 
                        CCorePlugin.log(e);
104
 
                }
105
 
                return Value.UNKNOWN;
106
 
        }
107
 
}