@@ -6363,7 +6363,10 @@ bool Parser::rAllocateInitializer(exprt &init)
6363
6363
postfix.exp
6364
6364
: primary.exp
6365
6365
| postfix.expr '[' comma.expression ']'
6366
+ | postfix.expr '[' initializer ']'
6366
6367
| postfix.expr '(' function.arguments ')'
6368
+ | integral.or.class.spec '(' function.arguments ')'
6369
+ | integral.or.class.spec initializer
6367
6370
| postfix.expr '.' var.name
6368
6371
| postfix.expr ArrowOp var.name
6369
6372
| postfix.expr IncOp
@@ -6372,8 +6375,6 @@ bool Parser::rAllocateInitializer(exprt &init)
6372
6375
openc++.postfix.expr
6373
6376
: postfix.expr '.' userdef.statement
6374
6377
| postfix.expr ArrowOp userdef.statement
6375
-
6376
- Note: function-style casts are accepted as function calls.
6377
6378
*/
6378
6379
bool Parser::rPostfixExpr (exprt &exp)
6379
6380
{
@@ -6382,8 +6383,89 @@ bool Parser::rPostfixExpr(exprt &exp)
6382
6383
std::cout << std::string (__indent, ' ' ) << " Parser::rPostfixExpr 0\n " ;
6383
6384
#endif
6384
6385
6385
- if (!rPrimaryExpr (exp))
6386
- return false ;
6386
+ typet type;
6387
+
6388
+ cpp_token_buffert::post pos=lex.Save ();
6389
+ // try to see whether this is explicit type conversion, else it has to be
6390
+ // a primary-expression
6391
+ if (optIntegralTypeOrClassSpec (type) &&
6392
+ type.is_not_nil () &&
6393
+ (lex.LookAhead (0 ) == ' (' || lex.LookAhead (0 ) == ' {' ))
6394
+ {
6395
+ #ifdef DEBUG
6396
+ std::cout << std::string (__indent, ' ' ) << " Parser::rPostfixExpr 0.1\n " ;
6397
+ #endif
6398
+
6399
+ cpp_tokent tk;
6400
+ lex.LookAhead (0 , tk);
6401
+ exprt exp2;
6402
+ if (lex.LookAhead (0 )==' {' )
6403
+ {
6404
+ if (!rInitializeExpr (exp2))
6405
+ return false ;
6406
+ }
6407
+ else
6408
+ {
6409
+ // lex.LookAhead(0)=='('
6410
+ lex.get_token (tk);
6411
+
6412
+ if (!rFunctionArguments (exp2))
6413
+ return false ;
6414
+
6415
+ cpp_tokent tk2;
6416
+ if (lex.get_token (tk2)!=' )' )
6417
+ return false ;
6418
+ }
6419
+
6420
+ exp=exprt (" explicit-constructor-call" );
6421
+ exp.type ().swap (type);
6422
+ exp.operands ().swap (exp2.operands ());
6423
+ set_location (exp, tk);
6424
+ }
6425
+ else
6426
+ lex.Restore (pos);
6427
+
6428
+ exprt type_or_function_name;
6429
+ if (rName (type_or_function_name) &&
6430
+ (lex.LookAhead (0 ) == ' (' || lex.LookAhead (0 ) == ' {' ))
6431
+ {
6432
+ #ifdef DEBUG
6433
+ std::cout << std::string (__indent, ' ' ) << " Parser::rPostfixExpr 0.2\n " ;
6434
+ #endif
6435
+
6436
+ cpp_tokent tk;
6437
+ lex.LookAhead (0 , tk);
6438
+ exprt exp2;
6439
+ if (lex.LookAhead (0 )==' {' )
6440
+ {
6441
+ if (!rInitializeExpr (exp2))
6442
+ return false ;
6443
+ }
6444
+ else
6445
+ {
6446
+ // lex.LookAhead(0)=='('
6447
+ lex.get_token (tk);
6448
+
6449
+ if (!rFunctionArguments (exp2))
6450
+ return false ;
6451
+
6452
+ cpp_tokent tk2;
6453
+ if (lex.get_token (tk2)!=' )' )
6454
+ return false ;
6455
+ }
6456
+
6457
+ side_effect_expr_function_callt fc (
6458
+ std::move (type_or_function_name), exp2.operands (), typet{}, source_locationt{});
6459
+ set_location (fc, tk);
6460
+
6461
+ exp.swap (fc);
6462
+ }
6463
+ else
6464
+ {
6465
+ lex.Restore (pos);
6466
+ if (!rPrimaryExpr (exp))
6467
+ return false ;
6468
+ }
6387
6469
6388
6470
#ifdef DEBUG
6389
6471
std::cout << std::string (__indent, ' ' ) << " Parser::rPostfixExpr 1\n " ;
@@ -6399,7 +6481,14 @@ bool Parser::rPostfixExpr(exprt &exp)
6399
6481
{
6400
6482
case ' [' :
6401
6483
lex.get_token (op);
6402
- if (!rCommaExpression (e))
6484
+
6485
+ if (lex.LookAhead (0 ) == ' {' )
6486
+ {
6487
+ // C++11 initialisation expression
6488
+ if (!rInitializeExpr (e))
6489
+ return false ;
6490
+ }
6491
+ else if (!rCommaExpression (e))
6403
6492
return false ;
6404
6493
6405
6494
#ifdef DEBUG
@@ -6424,7 +6513,6 @@ bool Parser::rPostfixExpr(exprt &exp)
6424
6513
std::cout << std::string (__indent, ' ' ) << " Parser::rPostfixExpr 3\n " ;
6425
6514
#endif
6426
6515
6427
- lex.get_token (op);
6428
6516
if (!rFunctionArguments (e))
6429
6517
return false ;
6430
6518
@@ -6718,8 +6806,6 @@ bool Parser::rTypePredicate(exprt &expr)
6718
6806
| THIS
6719
6807
| var.name
6720
6808
| '(' comma.expression ')'
6721
- | integral.or.class.spec '(' function.arguments ')'
6722
- | integral.or.class.spec initializer
6723
6809
| typeid.expr
6724
6810
| true
6725
6811
| false
@@ -6837,12 +6923,6 @@ bool Parser::rPrimaryExpr(exprt &exp)
6837
6923
#endif
6838
6924
return true ;
6839
6925
6840
- case ' {' : // C++11 initialisation expression
6841
- #ifdef DEBUG
6842
- std::cout << std::string (__indent, ' ' ) << " Parser::rPrimaryExpr 10\n " ;
6843
- #endif
6844
- return rInitializeExpr (exp);
6845
-
6846
6926
case TOK_TYPEID:
6847
6927
return rTypeidExpr (exp);
6848
6928
@@ -6873,60 +6953,6 @@ bool Parser::rPrimaryExpr(exprt &exp)
6873
6953
std::cout << std::string (__indent, ' ' ) << " Parser::rPrimaryExpr 14\n " ;
6874
6954
#endif
6875
6955
{
6876
- typet type;
6877
-
6878
- if (!optIntegralTypeOrClassSpec (type))
6879
- return false ;
6880
-
6881
- #ifdef DEBUG
6882
- std::cout << std::string (__indent, ' ' ) << " Parser::rPrimaryExpr 15\n " ;
6883
- #endif
6884
-
6885
- if (type.is_not_nil () && lex.LookAhead (0 )==TOK_SCOPE)
6886
- {
6887
- lex.get_token (tk);
6888
- lex.get_token (tk);
6889
-
6890
- // TODO
6891
- }
6892
- else if (type.is_not_nil ())
6893
- {
6894
- #ifdef DEBUG
6895
- std::cout << std::string (__indent, ' ' ) << " Parser::rPrimaryExpr 16\n " ;
6896
- #endif
6897
- if (lex.LookAhead (0 )==' {' )
6898
- {
6899
- lex.LookAhead (0 , tk);
6900
-
6901
- exprt exp2;
6902
- if (!rInitializeExpr (exp2))
6903
- return false ;
6904
-
6905
- exp=exprt (" explicit-constructor-call" );
6906
- exp.type ().swap (type);
6907
- exp.add_to_operands (std::move (exp2));
6908
- set_location (exp, tk);
6909
- }
6910
- else if (lex.LookAhead (0 )==' (' )
6911
- {
6912
- lex.get_token (tk);
6913
-
6914
- exprt exp2;
6915
- if (!rFunctionArguments (exp2))
6916
- return false ;
6917
-
6918
- if (lex.get_token (tk2)!=' )' )
6919
- return false ;
6920
-
6921
- exp=exprt (" explicit-constructor-call" );
6922
- exp.type ().swap (type);
6923
- exp.operands ().swap (exp2.operands ());
6924
- set_location (exp, tk);
6925
- }
6926
- else
6927
- return false ;
6928
- }
6929
- else
6930
6956
{
6931
6957
if (!rVarName (exp))
6932
6958
return false ;
0 commit comments