Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6ed3b42b04d38413433c98af1cf46ece545c0968 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package org.eclipse.cdt.internal.core.parser.util;

import org.eclipse.cdt.internal.core.parser.Token;

/**
 * @author jcamelon
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class DeclSpecifier {
	
	// DeclSpecifier layed out as bit array
	// leftmost 5 bits are type
	public static final int typeMask = 0x001f;
	public static final int isAuto = 0x0020;
	public static final int isRegister = 0x0040;
	public static final int isStatic = 0x0080;
	public static final int isExtern = 0x0100;
	public static final int isMutable = 0x0200;
	public static final int isInline = 0x0400;
	public static final int isVirtual = 0x0800;
	public static final int isExplicit = 0x1000;
	public static final int isTypedef = 0x2000;
	public static final int isFriend = 0x4000;
	public static final int isConst = 0x8000;
	public static final int isVolatile = 0x10000;
	public static final int isUnsigned = 0x20000;
	public static final int isShort = 0x40000;
	public static final int isLong = 0x80000;

	private int declSpecifierSeq = 0;
	public int getDeclSpecifierSeq() { return declSpecifierSeq; }

	// Convenience methods
	private void setBit(boolean b, int mask) {
		if (b)
			declSpecifierSeq = declSpecifierSeq | mask;
		else
			declSpecifierSeq = declSpecifierSeq & ~mask;
	}
	
	private boolean checkBit(int mask) {
		return (declSpecifierSeq & mask) == 1;
	}
	
	public void setAuto(boolean b) { setBit(b, isAuto); }
	public boolean isAuto() { return checkBit(isAuto); }
	
	public void setRegister(boolean b) { setBit(b, isRegister); }
	public boolean isRegister() { return checkBit(isRegister); } 
	
	public void setStatic(boolean b) { setBit(b, isStatic); }
	public boolean isStatic() { return checkBit(isStatic); }
	
	public void setExtern(boolean b) { setBit(b, isExtern); }
	public boolean isExtern() { return checkBit(isExtern); }
	
	public void setMutable(boolean b) { setBit(b, isMutable); }
	public boolean isMutable() { return checkBit(isMutable); }
	
	public void setInline(boolean b) { setBit(b, isInline); }
	public boolean isInline() { return checkBit(isInline); }
	
	public void setVirtual(boolean b) { setBit(b, isVirtual); }
	public boolean isVirtual() { return checkBit(isVirtual); }
	
	public void setExplicit(boolean b) { setBit(b, isExplicit); }
	public boolean isExplicit() { return checkBit(isExplicit); }
	
	public void setTypedef(boolean b) { setBit(b, isTypedef); }
	public boolean isTypedef() { return checkBit(isTypedef); }
	
	public void setFriend(boolean b) { setBit(b, isFriend); }
	public boolean isFriend() { return checkBit(isFriend); }
	
	public void setConst(boolean b) { setBit(b, isConst); }
	public boolean isConst() { return checkBit(isConst); }
	
	public void setVolatile(boolean b) { setBit(b, isVolatile); }
	public boolean isVolatile() { return checkBit(isVolatile); }

	public void setUnsigned(boolean b) { setBit(b, isUnsigned); }
	public boolean isUnsigned() {	return checkBit(isUnsigned); }
	
	public void setShort(boolean b) { setBit(b, isShort); }
	public boolean isShort() { return checkBit(isShort); }

	public void setLong(boolean b) { setBit(b, isLong); }
	public boolean isLong() {	return checkBit(isLong); }

	// Simple Types
	public static final int t_type = 0; // Type Specifier
	public static final int t_char = 1;
	public static final int t_wchar_t = 2;
	public static final int t_bool = 3;
	public static final int t_int = 4;
	public static final int t_float = 5;
	public static final int t_double = 6;
	public static final int t_void = 7;
	
	public void setType( Token token )
	{
		switch (token.getType()) {
			case Token.t_auto:
				setAuto(true);
				break;
			case Token.t_register:
				setRegister(true);
				break;
			case Token.t_static:
				setStatic(true);
				break;
			case Token.t_extern:
				setExtern(true);
				break;
			case Token.t_mutable:
				setMutable(true);
				break;
			case Token.t_inline:
				setInline(true);
				break;
			case Token.t_virtual:
				setVirtual(true);
				break;
			case Token.t_explicit:
				setExplicit(true);
				break;
			case Token.t_typedef:
				setTypedef(true);
				break;
			case Token.t_friend:
				setFriend(true);
				break;
			case Token.t_const:
				setConst(true);
				break;
			case Token.t_volatile:
				setVolatile(true);
				break;
			case Token.t_char:
				setType(DeclarationSpecifier.t_char);
				break;
			case Token.t_wchar_t:
				setType(DeclarationSpecifier.t_wchar_t);
				break;
			case Token.t_bool:
				setType(DeclarationSpecifier.t_bool);
				break;
			case Token.t_short:
				setShort(true);
				break;
			case Token.t_int:
				setType(DeclarationSpecifier.t_int);
				break;
			case Token.t_long:
				setLong(true);
				break;
			case Token.t_signed:
				setUnsigned(false);
				break;
			case Token.t_unsigned:
				setUnsigned(true);
				break;
			case Token.t_float:
				setType(DeclarationSpecifier.t_float);
				break;
			case Token.t_double:
				setType(DeclarationSpecifier.t_double);
				break;
			case Token.t_void:
				setType(DeclarationSpecifier.t_void);
				break;
			case Token.tIDENTIFIER:
				setType(DeclarationSpecifier.t_type);
				break;
		}

	}
	
	public void setType(int t) {
		declSpecifierSeq = declSpecifierSeq & ~typeMask | t;
	}
	
	public int getType() {
		return declSpecifierSeq & typeMask;
	}

}

Back to the top