@@ -248,7 +248,7 @@ class Parser // NOLINT(readability/identifiers)
248248 bool rTemplateDecl2 (typet &, TemplateDeclKind &kind);
249249 bool rTempArgList (irept &);
250250 bool rTempArgDeclaration (cpp_declarationt &);
251- bool rExternTemplateDecl (irept &);
251+ bool rExternTemplateDecl (cpp_declarationt &);
252252
253253 bool rDeclaration (cpp_declarationt &);
254254 bool rIntegralDeclaration (
@@ -257,11 +257,7 @@ class Parser // NOLINT(readability/identifiers)
257257 cpp_member_spect &,
258258 typet &,
259259 typet &);
260- bool rConstDeclaration (
261- cpp_declarationt &,
262- cpp_storage_spect &,
263- cpp_member_spect &,
264- typet &);
260+ bool rConstDeclaration (cpp_declarationt &);
265261 bool rOtherDeclaration (
266262 cpp_declarationt &,
267263 cpp_storage_spect &,
@@ -277,7 +273,7 @@ class Parser // NOLINT(readability/identifiers)
277273 bool optCvQualify (typet &);
278274 bool optAlignas (typet &);
279275 bool rAttribute (typet &);
280- bool optAttribute (cpp_declarationt &);
276+ bool optAttribute (typet &);
281277 bool optIntegralTypeOrClassSpec (typet &);
282278 bool rConstructorDecl (
283279 cpp_declaratort &,
@@ -312,7 +308,7 @@ class Parser // NOLINT(readability/identifiers)
312308 bool rBaseSpecifiers (irept &);
313309 bool rClassBody (exprt &);
314310 bool rClassMember (cpp_itemt &);
315- bool rAccessDecl (irept &);
311+ bool rAccessDecl (cpp_declarationt &);
316312
317313 bool rCommaExpression (exprt &);
318314
@@ -1336,7 +1332,7 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
13361332 extern.template.decl
13371333 : EXTERN TEMPLATE declaration
13381334*/
1339- bool Parser::rExternTemplateDecl (irept &decl)
1335+ bool Parser::rExternTemplateDecl (cpp_declarationt &decl)
13401336{
13411337 cpp_tokent tk1, tk2;
13421338
@@ -1346,8 +1342,7 @@ bool Parser::rExternTemplateDecl(irept &decl)
13461342 if (lex.get_token (tk2)!=TOK_TEMPLATE)
13471343 return false ;
13481344
1349- cpp_declarationt body;
1350- if (!rDeclaration (body))
1345+ if (!rDeclaration (decl))
13511346 return false ;
13521347
13531348 // decl=new PtreeExternTemplate(new Leaf(tk1),
@@ -1393,7 +1388,7 @@ bool Parser::rDeclaration(cpp_declarationt &declaration)
13931388 << lex.LookAhead (0 ) << ' \n ' ;
13941389 #endif
13951390
1396- if (!optAttribute (declaration))
1391+ if (!optAttribute (declaration. type () ))
13971392 return false ;
13981393
13991394 cpp_member_spect member_spec;
@@ -1465,7 +1460,7 @@ bool Parser::rDeclaration(cpp_declarationt &declaration)
14651460
14661461 if (cv_q.is_not_nil () &&
14671462 ((t==TOK_IDENTIFIER && lex.LookAhead (1 )==' =' ) || t==' *' ))
1468- return rConstDeclaration (declaration, storage_spec, member_spec, cv_q );
1463+ return rConstDeclaration (declaration);
14691464 else
14701465 return rOtherDeclaration (declaration, storage_spec, member_spec, cv_q);
14711466 }
@@ -1655,20 +1650,14 @@ bool Parser::rIntegralDeclaration(
16551650 }
16561651}
16571652
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)
16631654{
16641655 #ifdef DEBUG
16651656 indenter _i;
16661657 std::cout << std::string (__indent, ' ' ) << " Parser::rConstDeclaration\n " ;
16671658 #endif
16681659
1669- cpp_declarationt::declaratorst declarators;
1670-
1671- if (!rDeclarators (declarators, false ))
1660+ if (!rDeclarators (declaration.declarators (), false ))
16721661 return false ;
16731662
16741663 if (lex.LookAhead (0 )!=' ;' )
@@ -2130,21 +2119,39 @@ bool Parser::optAlignas(typet &cv)
21302119 {
21312120 if (lex.get_token (cp)==' )' )
21322121 {
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+
21342132 return true ;
21352133 }
21362134 }
21372135
21382136 lex.Restore (pos);
21392137
2140- exprt unary ;
2138+ exprt exp ;
21412139
2142- if (!rUnaryExpr (unary ))
2140+ if (!rCommaExpression (exp ))
21432141 return false ;
21442142
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);
21462148
2147- return true ;
2149+ merge_types (attr, cv);
2150+
2151+ return true ;
2152+ }
2153+
2154+ return false ;
21482155}
21492156
21502157bool Parser::rAttribute (typet &t)
@@ -2347,7 +2354,7 @@ bool Parser::rAttribute(typet &t)
23472354 return rAttribute (t);
23482355}
23492356
2350- bool Parser::optAttribute (cpp_declarationt &declaration )
2357+ bool Parser::optAttribute (typet &t )
23512358{
23522359 if (lex.LookAhead (0 )!=' [' ||
23532360 lex.LookAhead (1 )!=' [' )
@@ -2368,8 +2375,12 @@ bool Parser::optAttribute(cpp_declarationt &declaration)
23682375 return true ;
23692376
23702377 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+ }
23732384
23742385 default :
23752386 return false ;
@@ -4709,17 +4720,17 @@ bool Parser::rClassMember(cpp_itemt &member)
47094720 return true ;
47104721
47114722 lex.Restore (pos);
4712- return rAccessDecl (member);
4723+ return rAccessDecl (member. make_declaration () );
47134724 }
47144725}
47154726
47164727/*
47174728 access.decl
47184729 : name ';' e.g. <qualified class>::<member name>;
47194730*/
4720- bool Parser::rAccessDecl (irept &mem)
4731+ bool Parser::rAccessDecl (cpp_declarationt &mem)
47214732{
4722- irept name;
4733+ cpp_namet name;
47234734 cpp_tokent tk;
47244735
47254736 if (!rName (name))
@@ -4728,6 +4739,10 @@ bool Parser::rAccessDecl(irept &mem)
47284739 if (lex.get_token (tk)!=' ;' )
47294740 return false ;
47304741
4742+ cpp_declaratort name_decl;
4743+ name_decl.name () = name;
4744+ mem.declarators ().push_back (name_decl);
4745+
47314746 // mem=new PtreeAccessDecl(new PtreeName(name, encode),
47324747 // Ptree::List(new Leaf(tk)));
47334748 return true ;
@@ -8250,7 +8265,7 @@ bool Parser::rDeclarationStatement(codet &statement)
82508265 statement=codet (ID_decl);
82518266 statement.operands ().resize (1 );
82528267 cpp_declarationt &declaration=(cpp_declarationt &)(statement.op0 ());
8253- return rConstDeclaration (declaration, storage_spec, member_spec, cv_q );
8268+ return rConstDeclaration (declaration);
82548269 }
82558270 else
82568271 return rOtherDeclStatement (statement, storage_spec, cv_q);
0 commit comments