~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/c/PDOMCParameter.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
 
 *    Andrew Ferguson (Symbian)
11
 
 *    Markus Schorn (Wind River Systems)
12
 
 *******************************************************************************/
13
 
package org.eclipse.cdt.internal.core.pdom.dom.c;
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.IASTInitializer;
18
 
import org.eclipse.cdt.core.dom.ast.IParameter;
19
 
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
20
 
import org.eclipse.cdt.core.dom.ast.IType;
21
 
import org.eclipse.cdt.core.dom.ast.IValue;
22
 
import org.eclipse.cdt.core.index.IIndexFile;
23
 
import org.eclipse.cdt.internal.core.Util;
24
 
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
25
 
import org.eclipse.cdt.internal.core.index.IIndexFragment;
26
 
import org.eclipse.cdt.internal.core.index.IIndexScope;
27
 
import org.eclipse.cdt.internal.core.pdom.db.Database;
28
 
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding;
29
 
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
30
 
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
31
 
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
32
 
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
33
 
import org.eclipse.core.runtime.CoreException;
34
 
 
35
 
/**
36
 
 * Binding for a function parameter in the index.
37
 
 */
38
 
class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding {
39
 
 
40
 
        private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE + 0;
41
 
        private static final int TYPE = PDOMNamedNode.RECORD_SIZE + 4;
42
 
        
43
 
        protected static final int FLAGS = PDOMNamedNode.RECORD_SIZE + 8;
44
 
        
45
 
        @SuppressWarnings("hiding")
46
 
        public static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 9;
47
 
        static {
48
 
                assert RECORD_SIZE <= 22; // 23 would yield a 32-byte block
49
 
        }
50
 
        
51
 
        public PDOMCParameter(PDOMLinkage linkage, long record) {
52
 
                super(linkage, record);
53
 
        }
54
 
 
55
 
        public PDOMCParameter(PDOMLinkage linkage, PDOMNode parent, IParameter param)
56
 
                        throws CoreException {
57
 
                super(linkage, parent, param.getNameCharArray());
58
 
                
59
 
                Database db = getDB();
60
 
 
61
 
                db.putRecPtr(record + NEXT_PARAM, 0);
62
 
                try {
63
 
                        if(!(param instanceof IProblemBinding)) {
64
 
                                IType type = param.getType();
65
 
                                if (type != null) {
66
 
                                        PDOMNode typeNode = getLinkage().addType(this, type);
67
 
                                        db.putRecPtr(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);
68
 
                                }
69
 
                                byte flags = encodeFlags(param);
70
 
                                db.putByte(record + FLAGS, flags);
71
 
                        }
72
 
                } catch(DOMException e) {
73
 
                        throw new CoreException(Util.createStatus(e));
74
 
                }
75
 
        }
76
 
 
77
 
        @Override
78
 
        protected int getRecordSize() {
79
 
                return RECORD_SIZE;
80
 
        }
81
 
 
82
 
        @Override
83
 
        public int getNodeType() {
84
 
                return IIndexCBindingConstants.CPARAMETER;
85
 
        }
86
 
        
87
 
        public void setNextParameter(PDOMCParameter nextParam) throws CoreException {
88
 
                long rec = nextParam != null ? nextParam.getRecord() : 0;
89
 
                getDB().putRecPtr(record + NEXT_PARAM, rec);
90
 
        }
91
 
 
92
 
        public PDOMCParameter getNextParameter() throws CoreException {
93
 
                long rec = getDB().getRecPtr(record + NEXT_PARAM);
94
 
                return rec != 0 ? new PDOMCParameter(getLinkage(), rec) : null;
95
 
        }
96
 
        
97
 
        public IASTInitializer getDefaultValue() {
98
 
                return null;
99
 
//              TODO throw new PDOMNotImplementedError();
100
 
        }
101
 
 
102
 
        public IType getType() {
103
 
                try {
104
 
                        PDOMLinkage linkage = getLinkage(); 
105
 
                        PDOMNode node = linkage.getNode(getDB().getRecPtr(record + TYPE));
106
 
                        return node instanceof IType ? (IType)node : null;
107
 
                } catch (CoreException e) {
108
 
                        CCorePlugin.log(e);
109
 
                        return null;
110
 
                }
111
 
        }
112
 
 
113
 
        public boolean isAuto() throws DOMException {
114
 
                byte flag = 1<<PDOMCAnnotation.AUTO_OFFSET;
115
 
                return hasFlag(flag, true);
116
 
        }
117
 
 
118
 
        public boolean isExtern() throws DOMException {
119
 
                throw new PDOMNotImplementedError();
120
 
        }
121
 
 
122
 
        public boolean isRegister() throws DOMException {
123
 
                byte flag = 1<<PDOMCAnnotation.REGISTER_OFFSET;
124
 
                return hasFlag(flag, false);
125
 
        }
126
 
 
127
 
        public boolean isStatic() throws DOMException {
128
 
                throw new PDOMNotImplementedError();
129
 
        }
130
 
 
131
 
        public String getName() {
132
 
                return new String(getNameCharArray());
133
 
        }
134
 
 
135
 
        public IIndexScope getScope() {
136
 
                throw new PDOMNotImplementedError();
137
 
        }
138
 
 
139
 
        @SuppressWarnings("unchecked")
140
 
        public Object getAdapter(Class adapter) {
141
 
                return null;
142
 
        }
143
 
 
144
 
        @Override
145
 
        public char[] getNameCharArray() {
146
 
                try {
147
 
                        return super.getNameCharArray();
148
 
                } catch (CoreException e) {
149
 
                        CCorePlugin.log(e);
150
 
                        return new char[0];
151
 
                }
152
 
        }
153
 
 
154
 
        public IIndexFragment getFragment() {
155
 
                return getPDOM();
156
 
        }
157
 
 
158
 
        public boolean hasDefinition() throws CoreException {
159
 
                // parameter bindings do not span index fragments
160
 
                return true;
161
 
        }
162
 
 
163
 
        public boolean hasDeclaration() throws CoreException {
164
 
                // parameter bindings do not span index fragments
165
 
                return true;
166
 
        }
167
 
 
168
 
        public int compareTo(Object arg0) {
169
 
                throw new PDOMNotImplementedError();
170
 
        }
171
 
        
172
 
        public String[] getQualifiedName() {
173
 
                throw new PDOMNotImplementedError();
174
 
        }
175
 
 
176
 
        public char[][] getQualifiedNameCharArray() throws DOMException {
177
 
                throw new PDOMNotImplementedError();
178
 
        }
179
 
 
180
 
        public boolean isGloballyQualified() throws DOMException {
181
 
                throw new PDOMNotImplementedError();
182
 
        }
183
 
        
184
 
        public int getBindingConstant() {
185
 
                return getNodeType();
186
 
        }
187
 
        
188
 
        @Override
189
 
        public void delete(PDOMLinkage linkage) throws CoreException {
190
 
                linkage.deleteType(getType(), record);
191
 
                PDOMCParameter next= getNextParameter();
192
 
                if (next != null) {
193
 
                        next.delete(linkage);
194
 
                }
195
 
                super.delete(linkage);
196
 
        }
197
 
        
198
 
        public boolean isFileLocal() throws CoreException {
199
 
                return false;
200
 
        }
201
 
        
202
 
        public IIndexFile getLocalToFile() throws CoreException {
203
 
                return null;
204
 
        }
205
 
 
206
 
        public IValue getInitialValue() {
207
 
                return null;
208
 
        }
209
 
 
210
 
        protected byte encodeFlags(IParameter param) {
211
 
                // C99 ISO/IEC 9899: 6.7.5.3.2
212
 
                byte flags= 0;
213
 
                try {
214
 
                        flags |= (param.isAuto() ? 1 : 0) << PDOMCAnnotation.AUTO_OFFSET;
215
 
                        flags |= (param.isRegister() ? 1 : 0) << PDOMCAnnotation.REGISTER_OFFSET;
216
 
                } catch (DOMException e) {
217
 
                        // ignore and miss out on some flags
218
 
                }
219
 
                return flags;
220
 
        }
221
 
 
222
 
        protected boolean hasFlag(byte flag, boolean defValue) {
223
 
                try {
224
 
                        byte myflags= getDB().getByte(record + FLAGS);
225
 
                        return (myflags & flag) == flag;
226
 
                } catch (CoreException e) {
227
 
                        CCorePlugin.log(e);
228
 
                }
229
 
                return defValue;
230
 
        }
231
 
        
232
 
}