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

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.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) 2005, 2010 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
 *    IBM Corporation
 
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.IASTName;
 
17
import org.eclipse.cdt.core.dom.ast.IBinding;
 
18
import org.eclipse.cdt.core.dom.ast.IType;
 
19
import org.eclipse.cdt.core.dom.ast.IValue;
 
20
import org.eclipse.cdt.core.dom.ast.IVariable;
 
21
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
 
22
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
 
23
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
 
24
import org.eclipse.cdt.internal.core.pdom.db.Database;
 
25
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
 
26
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
 
27
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
 
28
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
 
29
import org.eclipse.core.runtime.CoreException;
 
30
 
 
31
/**
 
32
 * Binding for a c++ variable in the index, serves as a base class for fields.
 
33
 */
 
34
class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable {
 
35
 
 
36
        private static final int TYPE_OFFSET = PDOMCPPBinding.RECORD_SIZE;
 
37
        private static final int VALUE_OFFSET = TYPE_OFFSET + Database.TYPE_SIZE;
 
38
        protected static final int ANNOTATIONS = VALUE_OFFSET + Database.VALUE_SIZE; // byte
 
39
        @SuppressWarnings("hiding")
 
40
        protected static final int RECORD_SIZE = ANNOTATIONS + 1;
 
41
        
 
42
        public PDOMCPPVariable(PDOMLinkage linkage, PDOMNode parent, IVariable variable) throws CoreException {
 
43
                super(linkage, parent, variable.getNameCharArray());
 
44
                
 
45
                // Find the type record
 
46
                Database db = getDB();
 
47
                setType(parent.getLinkage(), variable.getType());
 
48
                db.putByte(record + ANNOTATIONS, encodeFlags(variable));
 
49
                setValue(db, variable);
 
50
        }
 
51
 
 
52
        private void setValue(Database db, IVariable variable) throws CoreException {
 
53
                IValue val= variable.getInitialValue();
 
54
                getLinkage().storeValue(record + VALUE_OFFSET, val);
 
55
        }
 
56
 
 
57
        @Override
 
58
        public void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException {
 
59
                if (newBinding instanceof IVariable) {
 
60
                        final Database db = getDB();
 
61
                        IVariable var= (IVariable) newBinding;
 
62
                        IType newType= var.getType();
 
63
                        setType(linkage, newType);
 
64
                        setValue(db, var);
 
65
                        db.putByte(record + ANNOTATIONS, encodeFlags(var));
 
66
                }
 
67
        }
 
68
 
 
69
 
 
70
        private void setType(final PDOMLinkage linkage, IType newType) throws CoreException {
 
71
                linkage.storeType(record+TYPE_OFFSET, newType);
 
72
        }
 
73
 
 
74
        protected byte encodeFlags(IVariable variable) {
 
75
                return PDOMCPPAnnotation.encodeAnnotation(variable);
 
76
        }
 
77
        
 
78
        public PDOMCPPVariable(PDOMLinkage linkage, long record) {
 
79
                super(linkage, record);
 
80
        }
 
81
        
 
82
        @Override
 
83
        protected int getRecordSize() {
 
84
                return RECORD_SIZE;
 
85
        }
 
86
 
 
87
        @Override
 
88
        public int getNodeType() {
 
89
                return IIndexCPPBindingConstants.CPPVARIABLE;
 
90
        }
 
91
        
 
92
        public boolean isMutable() {
 
93
                // ISO/IEC 14882:2003 7.1.1.8
 
94
                return false; 
 
95
        }
 
96
 
 
97
        public IType getType() {
 
98
                try {
 
99
                        return getLinkage().loadType(record + TYPE_OFFSET);
 
100
                } catch (CoreException e) {
 
101
                        CCorePlugin.log(e);
 
102
                        return null;
 
103
                }
 
104
        }
 
105
        
 
106
        public IValue getInitialValue() {
 
107
                try {
 
108
                        return getLinkage().loadValue(record + VALUE_OFFSET);
 
109
                } catch (CoreException e) {
 
110
                        CCorePlugin.log(e);
 
111
                        return null;
 
112
                }
 
113
        }
 
114
 
 
115
        public boolean isAuto() {
 
116
                return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.AUTO_OFFSET);
 
117
        }
 
118
 
 
119
        public boolean isExtern() {
 
120
                return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.EXTERN_OFFSET);
 
121
        }
 
122
 
 
123
        public boolean isExternC() {
 
124
                return getBit(getByte(record + ANNOTATIONS), PDOMCPPAnnotation.EXTERN_C_OFFSET);
 
125
        }
 
126
 
 
127
        public boolean isRegister() {
 
128
                return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.REGISTER_OFFSET);
 
129
        }
 
130
 
 
131
        public boolean isStatic() {
 
132
                return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.STATIC_OFFSET);
 
133
        }
 
134
 
 
135
        @Override
 
136
        public int getAdditionalNameFlags(int standardFlags, IASTName name) {
 
137
                if ((standardFlags & PDOMName.IS_REFERENCE) == PDOMName.IS_REFERENCE) {
 
138
                        return CPPVariableReadWriteFlags.getReadWriteFlags(name);
 
139
                }
 
140
                return 0;
 
141
        }
 
142
}