2323// cxx
2424#include < cxx/ast.h>
2525#include < cxx/control.h>
26+ #include < cxx/symbols.h>
2627#include < cxx/translation_unit.h>
2728#include < cxx/types.h>
2829
@@ -31,6 +32,8 @@ namespace cxx {
3132struct DeclSpecs ::Visitor {
3233 DeclSpecs& specs;
3334
35+ [[nodiscard]] auto control () const -> Control* { return specs.control (); }
36+
3437 void operator ()(GeneratedTypeSpecifierAST* ast);
3538 void operator ()(TypedefSpecifierAST* ast);
3639 void operator ()(FriendSpecifierAST* ast);
@@ -71,75 +74,257 @@ struct DeclSpecs::Visitor {
7174
7275void DeclSpecs::Visitor::operator ()(GeneratedTypeSpecifierAST* ast) {}
7376
74- void DeclSpecs::Visitor::operator ()(TypedefSpecifierAST* ast) {}
77+ void DeclSpecs::Visitor::operator ()(TypedefSpecifierAST* ast) {
78+ specs.isTypedef = true ;
79+ }
80+
81+ void DeclSpecs::Visitor::operator ()(FriendSpecifierAST* ast) {
82+ specs.isFriend = true ;
83+ }
84+
85+ void DeclSpecs::Visitor::operator ()(ConstevalSpecifierAST* ast) {
86+ specs.isConsteval = true ;
87+ }
88+
89+ void DeclSpecs::Visitor::operator ()(ConstinitSpecifierAST* ast) {
90+ specs.isConstinit = true ;
91+ }
92+
93+ void DeclSpecs::Visitor::operator ()(ConstexprSpecifierAST* ast) {
94+ specs.isConstexpr = true ;
95+ }
96+
97+ void DeclSpecs::Visitor::operator ()(InlineSpecifierAST* ast) {
98+ specs.isInline = true ;
99+ }
100+
101+ void DeclSpecs::Visitor::operator ()(StaticSpecifierAST* ast) {
102+ specs.isStatic = true ;
103+ }
104+
105+ void DeclSpecs::Visitor::operator ()(ExternSpecifierAST* ast) {
106+ specs.isExtern = true ;
107+ }
108+
109+ void DeclSpecs::Visitor::operator ()(ThreadLocalSpecifierAST* ast) {
110+ specs.isThreadLocal = true ;
111+ }
112+
113+ void DeclSpecs::Visitor::operator ()(ThreadSpecifierAST* ast) {
114+ specs.isThread = true ;
115+ }
116+
117+ void DeclSpecs::Visitor::operator ()(MutableSpecifierAST* ast) {
118+ specs.isMutable = true ;
119+ }
120+
121+ void DeclSpecs::Visitor::operator ()(VirtualSpecifierAST* ast) {
122+ specs.isVirtual = true ;
123+ }
124+
125+ void DeclSpecs::Visitor::operator ()(ExplicitSpecifierAST* ast) {
126+ specs.isExplicit = true ;
127+ }
128+
129+ void DeclSpecs::Visitor::operator ()(AutoTypeSpecifierAST* ast) {
130+ specs.typeSpecifier = ast;
131+ specs.type = control ()->getAutoType ();
132+ }
133+
134+ void DeclSpecs::Visitor::operator ()(VoidTypeSpecifierAST* ast) {
135+ specs.typeSpecifier = ast;
136+ specs.type = control ()->getVoidType ();
137+ }
138+
139+ void DeclSpecs::Visitor::operator ()(SizeTypeSpecifierAST* ast) {
140+ switch (ast->specifier ) {
141+ case TokenKind::T_SHORT:
142+ specs.isShort = true ;
143+ break ;
75144
76- void DeclSpecs::Visitor::operator ()(FriendSpecifierAST* ast) {}
145+ case TokenKind::T_LONG:
146+ if (specs.isLong )
147+ specs.isLongLong = true ;
148+ else
149+ specs.isLong = true ;
150+ break ;
77151
78- void DeclSpecs::Visitor::operator ()(ConstevalSpecifierAST* ast) {}
152+ default :
153+ break ;
154+ } // switch
155+ }
79156
80- void DeclSpecs::Visitor::operator ()(ConstinitSpecifierAST* ast) {}
157+ void DeclSpecs::Visitor::operator ()(SignTypeSpecifierAST* ast) {
158+ switch (ast->specifier ) {
159+ case TokenKind::T_SIGNED:
160+ specs.isSigned = true ;
161+ break ;
81162
82- void DeclSpecs::Visitor::operator ()(ConstexprSpecifierAST* ast) {}
163+ case TokenKind::T_UNSIGNED:
164+ specs.isUnsigned = true ;
165+ break ;
83166
84- void DeclSpecs::Visitor::operator ()(InlineSpecifierAST* ast) {}
167+ default :
168+ break ;
169+ } // switch
170+ }
85171
86- void DeclSpecs::Visitor::operator ()(StaticSpecifierAST* ast) {}
172+ void DeclSpecs::Visitor::operator ()(VaListTypeSpecifierAST* ast) {
173+ specs.typeSpecifier = ast;
174+ specs.type = control ()->getBuiltinVaListType ();
175+ }
87176
88- void DeclSpecs::Visitor::operator ()(ExternSpecifierAST* ast) {}
177+ void DeclSpecs::Visitor::operator ()(IntegralTypeSpecifierAST* ast) {
178+ specs.typeSpecifier = ast;
179+ switch (ast->specifier ) {
180+ case TokenKind::T_CHAR:
181+ specs.type = control ()->getCharType ();
182+ break ;
89183
90- void DeclSpecs::Visitor::operator ()(ThreadLocalSpecifierAST* ast) {}
184+ case TokenKind::T_CHAR8_T:
185+ specs.type = control ()->getChar8Type ();
186+ break ;
91187
92- void DeclSpecs::Visitor::operator ()(ThreadSpecifierAST* ast) {}
188+ case TokenKind::T_CHAR16_T:
189+ specs.type = control ()->getChar16Type ();
190+ break ;
93191
94- void DeclSpecs::Visitor::operator ()(MutableSpecifierAST* ast) {}
192+ case TokenKind::T_CHAR32_T:
193+ specs.type = control ()->getChar32Type ();
194+ break ;
95195
96- void DeclSpecs::Visitor::operator ()(VirtualSpecifierAST* ast) {}
196+ case TokenKind::T_WCHAR_T:
197+ specs.type = control ()->getWideCharType ();
198+ break ;
97199
98- void DeclSpecs::Visitor::operator ()(ExplicitSpecifierAST* ast) {}
200+ case TokenKind::T_BOOL:
201+ specs.type = control ()->getBoolType ();
202+ break ;
99203
100- void DeclSpecs::Visitor::operator ()(AutoTypeSpecifierAST* ast) {}
204+ case TokenKind::T_INT:
205+ specs.type = control ()->getIntType ();
206+ break ;
101207
102- void DeclSpecs::Visitor::operator ()(VoidTypeSpecifierAST* ast) {}
208+ case TokenKind::T___INT64:
209+ // ### todo
210+ break ;
103211
104- void DeclSpecs::Visitor::operator ()(SizeTypeSpecifierAST* ast) {}
212+ case TokenKind::T___INT128:
213+ // ### todo
214+ break ;
105215
106- void DeclSpecs::Visitor::operator ()(SignTypeSpecifierAST* ast) {}
216+ default :
217+ break ;
218+ } // switch
219+ }
107220
108- void DeclSpecs::Visitor::operator ()(VaListTypeSpecifierAST* ast) {}
221+ void DeclSpecs::Visitor::operator ()(FloatingPointTypeSpecifierAST* ast) {
222+ specs.typeSpecifier = ast;
223+ switch (ast->specifier ) {
224+ case TokenKind::T_FLOAT:
225+ specs.type = control ()->getFloatType ();
226+ break ;
109227
110- void DeclSpecs::Visitor::operator ()(IntegralTypeSpecifierAST* ast) {}
228+ case TokenKind::T_DOUBLE:
229+ specs.type = control ()->getDoubleType ();
230+ break ;
111231
112- void DeclSpecs::Visitor::operator ()(FloatingPointTypeSpecifierAST* ast) {}
232+ case TokenKind::T_LONG:
233+ specs.type = control ()->getLongDoubleType ();
234+ break ;
113235
114- void DeclSpecs::Visitor::operator ()(ComplexTypeSpecifierAST* ast) {}
236+ case TokenKind::T___FLOAT80:
237+ // ### todo
238+ break ;
115239
116- void DeclSpecs::Visitor::operator ()(NamedTypeSpecifierAST* ast) {}
240+ case TokenKind::T___FLOAT128:
241+ // ### todo
242+ break ;
117243
118- void DeclSpecs::Visitor::operator ()(AtomicTypeSpecifierAST* ast) {}
244+ default :
245+ break ;
246+ } // switch
247+ }
119248
120- void DeclSpecs::Visitor::operator ()(UnderlyingTypeSpecifierAST* ast) {}
249+ void DeclSpecs::Visitor::operator ()(ComplexTypeSpecifierAST* ast) {
250+ specs.typeSpecifier = ast;
251+ specs.isComplex = true ;
252+ }
121253
122- void DeclSpecs::Visitor::operator ()(ElaboratedTypeSpecifierAST* ast) {}
254+ void DeclSpecs::Visitor::operator ()(NamedTypeSpecifierAST* ast) {
255+ specs.typeSpecifier = ast;
256+ if (ast->symbol ) specs.type = ast->symbol ->type ();
257+ }
123258
124- void DeclSpecs::Visitor::operator ()(DecltypeAutoSpecifierAST* ast) {}
259+ void DeclSpecs::Visitor::operator ()(AtomicTypeSpecifierAST* ast) {
260+ specs.typeSpecifier = ast;
261+ // ### todo
262+ }
125263
126- void DeclSpecs::Visitor::operator ()(DecltypeSpecifierAST* ast) {}
264+ void DeclSpecs::Visitor::operator ()(UnderlyingTypeSpecifierAST* ast) {
265+ specs.typeSpecifier = ast;
266+
267+ if (ast->typeId ) {
268+ if (auto enumType = type_cast<EnumType>(ast->typeId ->type )) {
269+ specs.type = enumType->underlyingType ();
270+ } else if (auto scopedEnumType =
271+ type_cast<ScopedEnumType>(ast->typeId ->type )) {
272+ specs.type = scopedEnumType->underlyingType ();
273+ } else {
274+ specs.type =
275+ control ()->getUnresolvedUnderlyingType (specs.unit , ast->typeId );
276+ }
277+ }
278+ }
279+
280+ void DeclSpecs::Visitor::operator ()(ElaboratedTypeSpecifierAST* ast) {
281+ specs.typeSpecifier = ast;
282+ if (ast->symbol ) specs.type = ast->symbol ->type ();
283+ }
284+
285+ void DeclSpecs::Visitor::operator ()(DecltypeAutoSpecifierAST* ast) {
286+ specs.typeSpecifier = ast;
287+ specs.type = control ()->getDecltypeAutoType ();
288+ }
289+
290+ void DeclSpecs::Visitor::operator ()(DecltypeSpecifierAST* ast) {
291+ specs.typeSpecifier = ast;
292+ specs.type = ast->type ;
293+ }
127294
128295void DeclSpecs::Visitor::operator ()(PlaceholderTypeSpecifierAST* ast) {}
129296
130- void DeclSpecs::Visitor::operator ()(ConstQualifierAST* ast) {}
297+ void DeclSpecs::Visitor::operator ()(ConstQualifierAST* ast) {
298+ specs.isConst = true ;
299+ }
131300
132- void DeclSpecs::Visitor::operator ()(VolatileQualifierAST* ast) {}
301+ void DeclSpecs::Visitor::operator ()(VolatileQualifierAST* ast) {
302+ specs.isVolatile = true ;
303+ }
133304
134- void DeclSpecs::Visitor::operator ()(RestrictQualifierAST* ast) {}
305+ void DeclSpecs::Visitor::operator ()(RestrictQualifierAST* ast) {
306+ specs.isRestrict = true ;
307+ }
135308
136- void DeclSpecs::Visitor::operator ()(EnumSpecifierAST* ast) {}
309+ void DeclSpecs::Visitor::operator ()(EnumSpecifierAST* ast) {
310+ specs.typeSpecifier = ast;
311+ if (ast->symbol ) specs.type = ast->symbol ->type ();
312+ }
137313
138- void DeclSpecs::Visitor::operator ()(ClassSpecifierAST* ast) {}
314+ void DeclSpecs::Visitor::operator ()(ClassSpecifierAST* ast) {
315+ specs.typeSpecifier = ast;
316+ if (ast->symbol ) specs.type = ast->symbol ->type ();
317+ }
139318
140- void DeclSpecs::Visitor::operator ()(TypenameSpecifierAST* ast) {}
319+ void DeclSpecs::Visitor::operator ()(TypenameSpecifierAST* ast) {
320+ specs.typeSpecifier = ast;
321+ // ### todo
322+ }
141323
142- void DeclSpecs::Visitor::operator ()(SplicerTypeSpecifierAST* ast) {}
324+ void DeclSpecs::Visitor::operator ()(SplicerTypeSpecifierAST* ast) {
325+ specs.typeSpecifier = ast;
326+ // ### todo
327+ }
143328
144329DeclSpecs::DeclSpecs (TranslationUnit* unit) : unit(unit) {}
145330
0 commit comments