blob: 9945c965a808db7f1aa6e2cc927d2aec62c7ff90 (
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
|
/*******************************************************************************
* Copyright (c) 2005, 2015 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:
* Devin Steffler (IBM Rational Software) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICPointerType;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.core.runtime.CoreException;
public class CPointerType implements ICPointerType, ITypeContainer, ISerializableType {
static public final CPointerType VOID_POINTER = new CPointerType(CBasicType.VOID, 0);
static public final int IS_CONST = 1;
static public final int IS_RESTRICT = 1 << 1;
static public final int IS_VOLATILE = 1 << 2;
IType nextType = null;
private int qualifiers = 0;
public CPointerType() {}
public CPointerType(IType next, int qualifiers) {
this.nextType = next;
this.qualifiers = qualifiers;
}
@Override
public boolean isSameType(IType obj) {
if (obj == this)
return true;
if (obj instanceof ITypedef)
return obj.isSameType(this);
if (obj instanceof ICPointerType) {
ICPointerType pt = (ICPointerType) obj;
if (isConst() != pt.isConst()) return false;
if (isRestrict() != pt.isRestrict()) return false;
if (isVolatile() != pt.isVolatile()) return false;
return pt.getType().isSameType(nextType);
}
return false;
}
@Override
public boolean isRestrict() {
return (qualifiers & IS_RESTRICT) != 0;
}
@Override
public IType getType() {
return nextType;
}
@Override
public void setType(IType type) {
nextType = type;
}
@Override
public boolean isConst() {
return (qualifiers & IS_CONST) != 0;
}
@Override
public boolean isVolatile() {
return (qualifiers & IS_VOLATILE) != 0;
}
@Override
public Object clone() {
IType t = null;
try {
t = (IType) super.clone();
} catch (CloneNotSupportedException e) {
// Not going to happen.
}
return t;
}
public void setQualifiers(int qualifiers) {
this.qualifiers = qualifiers;
}
@Override
public void marshal(ITypeMarshalBuffer buffer) throws CoreException {
short firstBytes = ITypeMarshalBuffer.POINTER_TYPE;
if (isConst()) firstBytes |= ITypeMarshalBuffer.FLAG1;
if (isVolatile()) firstBytes |= ITypeMarshalBuffer.FLAG2;
if (isRestrict()) firstBytes |= ITypeMarshalBuffer.FLAG3;
buffer.putShort(firstBytes);
buffer.marshalType(getType());
}
public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException {
IType nested= buffer.unmarshalType();
return new CPointerType(nested, firstBytes/ITypeMarshalBuffer.FLAG1);
}
@Override
public String toString() {
return ASTTypeUtil.getType(this);
}
}
|