@@ -248,7 +248,7 @@ class Parser // NOLINT(readability/identifiers)
248
248
bool rTemplateDecl2 (typet &, TemplateDeclKind &kind);
249
249
bool rTempArgList (irept &);
250
250
bool rTempArgDeclaration (cpp_declarationt &);
251
- bool rExternTemplateDecl (irept &);
251
+ bool rExternTemplateDecl (cpp_declarationt &);
252
252
253
253
bool rDeclaration (cpp_declarationt &);
254
254
bool rIntegralDeclaration (
@@ -257,11 +257,7 @@ class Parser // NOLINT(readability/identifiers)
257
257
cpp_member_spect &,
258
258
typet &,
259
259
typet &);
260
- bool rConstDeclaration (
261
- cpp_declarationt &,
262
- cpp_storage_spect &,
263
- cpp_member_spect &,
264
- typet &);
260
+ bool rConstDeclaration (cpp_declarationt &);
265
261
bool rOtherDeclaration (
266
262
cpp_declarationt &,
267
263
cpp_storage_spect &,
@@ -277,7 +273,7 @@ class Parser // NOLINT(readability/identifiers)
277
273
bool optCvQualify (typet &);
278
274
bool optAlignas (typet &);
279
275
bool rAttribute (typet &);
280
- bool optAttribute (cpp_declarationt &);
276
+ bool optAttribute (typet &);
281
277
bool optIntegralTypeOrClassSpec (typet &);
282
278
bool rConstructorDecl (
283
279
cpp_declaratort &,
@@ -312,7 +308,7 @@ class Parser // NOLINT(readability/identifiers)
312
308
bool rBaseSpecifiers (irept &);
313
309
bool rClassBody (exprt &);
314
310
bool rClassMember (cpp_itemt &);
315
- bool rAccessDecl (irept &);
311
+ bool rAccessDecl (cpp_declarationt &);
316
312
317
313
bool rCommaExpression (exprt &);
318
314
@@ -1336,7 +1332,7 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
1336
1332
extern.template.decl
1337
1333
: EXTERN TEMPLATE declaration
1338
1334
*/
1339
- bool Parser::rExternTemplateDecl (irept &decl)
1335
+ bool Parser::rExternTemplateDecl (cpp_declarationt &decl)
1340
1336
{
1341
1337
cpp_tokent tk1, tk2;
1342
1338
@@ -1346,8 +1342,7 @@ bool Parser::rExternTemplateDecl(irept &decl)
1346
1342
if (lex.get_token (tk2)!=TOK_TEMPLATE)
1347
1343
return false ;
1348
1344
1349
- cpp_declarationt body;
1350
- if (!rDeclaration (body))
1345
+ if (!rDeclaration (decl))
1351
1346
return false ;
1352
1347
1353
1348
// decl=new PtreeExternTemplate(new Leaf(tk1),
@@ -1393,7 +1388,7 @@ bool Parser::rDeclaration(cpp_declarationt &declaration)
1393
1388
<< lex.LookAhead (0 ) << ' \n ' ;
1394
1389
#endif
1395
1390
1396
- if (!optAttribute (declaration))
1391
+ if (!optAttribute (declaration. type () ))
1397
1392
return false ;
1398
1393
1399
1394
cpp_member_spect member_spec;
@@ -1465,7 +1460,7 @@ bool Parser::rDeclaration(cpp_declarationt &declaration)
1465
1460
1466
1461
if (cv_q.is_not_nil () &&
1467
1462
((t==TOK_IDENTIFIER && lex.LookAhead (1 )==' =' ) || t==' *' ))
1468
- return rConstDeclaration (declaration, storage_spec, member_spec, cv_q );
1463
+ return rConstDeclaration (declaration);
1469
1464
else
1470
1465
return rOtherDeclaration (declaration, storage_spec, member_spec, cv_q);
1471
1466
}
@@ -1655,20 +1650,14 @@ bool Parser::rIntegralDeclaration(
1655
1650
}
1656
1651
}
1657
1652
1658
- bool Parser::rConstDeclaration (
1659
- cpp_declarationt &declaration,
1660
- cpp_storage_spect &storage_spec,
1661
- cpp_member_spect &member_spec,
1662
- typet &cv_q)
1653
+ bool Parser::rConstDeclaration (cpp_declarationt &declaration)
1663
1654
{
1664
1655
#ifdef DEBUG
1665
1656
indenter _i;
1666
1657
std::cout << std::string (__indent, ' ' ) << " Parser::rConstDeclaration\n " ;
1667
1658
#endif
1668
1659
1669
- cpp_declarationt::declaratorst declarators;
1670
-
1671
- if (!rDeclarators (declarators, false ))
1660
+ if (!rDeclarators (declaration.declarators (), false ))
1672
1661
return false ;
1673
1662
1674
1663
if (lex.LookAhead (0 )!=' ;' )
@@ -2130,21 +2119,39 @@ bool Parser::optAlignas(typet &cv)
2130
2119
{
2131
2120
if (lex.get_token (cp)==' )' )
2132
2121
{
2133
- // TODO
2122
+ exprt exp (ID_alignof);
2123
+ exp .add (ID_type_arg).swap (tname);
2124
+ set_location (exp , tk);
2125
+
2126
+ typet attr (ID_aligned);
2127
+ set_location (attr, tk);
2128
+ attr.add (ID_size, exp );
2129
+
2130
+ merge_types (attr, cv);
2131
+
2134
2132
return true ;
2135
2133
}
2136
2134
}
2137
2135
2138
2136
lex.Restore (pos);
2139
2137
2140
- exprt unary ;
2138
+ exprt exp ;
2141
2139
2142
- if (!rUnaryExpr (unary ))
2140
+ if (!rCommaExpression ( exp ))
2143
2141
return false ;
2144
2142
2145
- // TODO
2143
+ if (lex.get_token (cp)==' )' )
2144
+ {
2145
+ typet attr (ID_aligned);
2146
+ set_location (attr, tk);
2147
+ attr.add (ID_size, exp );
2146
2148
2147
- return true ;
2149
+ merge_types (attr, cv);
2150
+
2151
+ return true ;
2152
+ }
2153
+
2154
+ return false ;
2148
2155
}
2149
2156
2150
2157
bool Parser::rAttribute (typet &t)
@@ -2347,7 +2354,7 @@ bool Parser::rAttribute(typet &t)
2347
2354
return rAttribute (t);
2348
2355
}
2349
2356
2350
- bool Parser::optAttribute (cpp_declarationt &declaration )
2357
+ bool Parser::optAttribute (typet &t )
2351
2358
{
2352
2359
if (lex.LookAhead (0 )!=' [' ||
2353
2360
lex.LookAhead (1 )!=' [' )
@@ -2368,8 +2375,12 @@ bool Parser::optAttribute(cpp_declarationt &declaration)
2368
2375
return true ;
2369
2376
2370
2377
case TOK_NORETURN:
2371
- // TODO
2372
- break ;
2378
+ {
2379
+ typet attr (ID_noreturn);
2380
+ set_location (attr, tk);
2381
+ merge_types (attr, t);
2382
+ break ;
2383
+ }
2373
2384
2374
2385
default :
2375
2386
return false ;
@@ -4709,17 +4720,17 @@ bool Parser::rClassMember(cpp_itemt &member)
4709
4720
return true ;
4710
4721
4711
4722
lex.Restore (pos);
4712
- return rAccessDecl (member);
4723
+ return rAccessDecl (member. make_declaration () );
4713
4724
}
4714
4725
}
4715
4726
4716
4727
/*
4717
4728
access.decl
4718
4729
: name ';' e.g. <qualified class>::<member name>;
4719
4730
*/
4720
- bool Parser::rAccessDecl (irept &mem)
4731
+ bool Parser::rAccessDecl (cpp_declarationt &mem)
4721
4732
{
4722
- irept name;
4733
+ cpp_namet name;
4723
4734
cpp_tokent tk;
4724
4735
4725
4736
if (!rName (name))
@@ -4728,6 +4739,10 @@ bool Parser::rAccessDecl(irept &mem)
4728
4739
if (lex.get_token (tk)!=' ;' )
4729
4740
return false ;
4730
4741
4742
+ cpp_declaratort name_decl;
4743
+ name_decl.name () = name;
4744
+ mem.declarators ().push_back (name_decl);
4745
+
4731
4746
// mem=new PtreeAccessDecl(new PtreeName(name, encode),
4732
4747
// Ptree::List(new Leaf(tk)));
4733
4748
return true ;
@@ -8250,7 +8265,7 @@ bool Parser::rDeclarationStatement(codet &statement)
8250
8265
statement=codet (ID_decl);
8251
8266
statement.operands ().resize (1 );
8252
8267
cpp_declarationt &declaration=(cpp_declarationt &)(statement.op0 ());
8253
- return rConstDeclaration (declaration, storage_spec, member_spec, cv_q );
8268
+ return rConstDeclaration (declaration);
8254
8269
}
8255
8270
else
8256
8271
return rOtherDeclStatement (statement, storage_spec, cv_q);
0 commit comments