@@ -343,7 +343,7 @@ class Parser
343
343
unsigned number_of_errors;
344
344
irep_idt current_function;
345
345
346
- void merge_types (typet &src, typet &dest);
346
+ void merge_types (const typet &src, typet &dest);
347
347
348
348
void set_location (irept &dest, const cpp_tokent &token)
349
349
{
@@ -355,12 +355,22 @@ class Parser
355
355
source_location.set_function (current_function);
356
356
}
357
357
358
- void make_subtype (typet &src, typet &dest)
358
+ void make_subtype (const typet &src, typet &dest)
359
359
{
360
360
typet *p=&dest;
361
+
361
362
while (p->id ()!=irep_idt () && p->is_not_nil ())
362
- p=&p->subtype ();
363
- p->swap (src);
363
+ {
364
+ if (p->id ()==ID_merged_type)
365
+ {
366
+ assert (!p->subtypes ().empty ());
367
+ p=&p->subtypes ().back ();
368
+ }
369
+ else
370
+ p=&p->subtype ();
371
+ }
372
+
373
+ *p=src;
364
374
}
365
375
366
376
unsigned int max_errors;
@@ -452,7 +462,7 @@ void Parser::make_sub_scope(const irep_idt &id, new_scopet::kindt kind)
452
462
453
463
/* ******************************************************************\
454
464
455
- Function:
465
+ Function: Parser::rString
456
466
457
467
Inputs:
458
468
@@ -472,7 +482,7 @@ bool Parser::rString(cpp_tokent &tk)
472
482
473
483
/* ******************************************************************\
474
484
475
- Function:
485
+ Function: Parser::merge_types
476
486
477
487
Inputs:
478
488
@@ -482,22 +492,22 @@ bool Parser::rString(cpp_tokent &tk)
482
492
483
493
\*******************************************************************/
484
494
485
- void Parser::merge_types (typet &src, typet &dest)
495
+ void Parser::merge_types (const typet &src, typet &dest)
486
496
{
487
497
if (src.is_nil ()) return ;
488
498
489
499
if (dest.is_nil ())
490
- dest. swap ( src) ;
500
+ dest= src;
491
501
else
492
502
{
493
503
if (dest.id ()!=ID_merged_type)
494
504
{
495
505
typet tmp (ID_merged_type);
496
506
tmp.move_to_subtypes (dest);
497
- dest. swap ( tmp) ;
507
+ dest= tmp;
498
508
}
499
509
500
- dest.move_to_subtypes (src);
510
+ dest.copy_to_subtypes (src);
501
511
}
502
512
}
503
513
@@ -3428,7 +3438,7 @@ bool Parser::rDeclarator(
3428
3438
3429
3439
/* ******************************************************************\
3430
3440
3431
- Function:
3441
+ Function: Parser::optPtrOperator
3432
3442
3433
3443
Inputs:
3434
3444
@@ -3461,17 +3471,21 @@ bool Parser::optPtrOperator(typet &ptrs)
3461
3471
3462
3472
if (t==' *' )
3463
3473
{
3464
- typet op (ID_pointer) ;
3474
+ pointer_typet op;
3465
3475
cpp_tokent tk;
3466
3476
lex.get_token (tk);
3467
3477
set_location (op, tk);
3468
3478
3469
3479
typet cv;
3470
3480
cv.make_nil ();
3471
- optCvQualify (cv);
3472
- op.add (ID_C_qualifier).swap (cv);
3473
-
3474
- t_list.push_back (op);
3481
+ optCvQualify (cv); // the qualifier is for the pointer
3482
+ if (cv.is_not_nil ())
3483
+ {
3484
+ merge_types (op, cv);
3485
+ t_list.push_back (cv);
3486
+ }
3487
+ else
3488
+ t_list.push_back (op);
3475
3489
}
3476
3490
else if (t==' ^' )
3477
3491
{
@@ -3483,10 +3497,14 @@ bool Parser::optPtrOperator(typet &ptrs)
3483
3497
3484
3498
typet cv;
3485
3499
cv.make_nil ();
3486
- optCvQualify (cv);
3487
- op.add (ID_C_qualifier).swap (cv);
3488
-
3489
- t_list.push_back (op);
3500
+ optCvQualify (cv); // the qualifier is for the pointer
3501
+ if (cv.is_not_nil ())
3502
+ {
3503
+ merge_types (op, cv);
3504
+ t_list.push_back (cv);
3505
+ }
3506
+ else
3507
+ t_list.push_back (op);
3490
3508
}
3491
3509
else if (isPtrToMember (0 ))
3492
3510
{
@@ -3496,10 +3514,14 @@ bool Parser::optPtrOperator(typet &ptrs)
3496
3514
3497
3515
typet cv;
3498
3516
cv.make_nil ();
3499
- optCvQualify (cv);
3500
- op.add (ID_C_qualifier).swap (cv);
3501
-
3502
- t_list.push_back (op);
3517
+ optCvQualify (cv); // the qualifier is for the pointer
3518
+ if (cv.is_not_nil ())
3519
+ {
3520
+ merge_types (op, cv);
3521
+ t_list.push_back (cv);
3522
+ }
3523
+ else
3524
+ t_list.push_back (op);
3503
3525
}
3504
3526
else
3505
3527
break ;
@@ -3533,7 +3555,17 @@ bool Parser::optPtrOperator(typet &ptrs)
3533
3555
it!=t_list.rend ();
3534
3556
it++)
3535
3557
{
3536
- it->subtype ().swap (ptrs);
3558
+ if (it->id ()==ID_merged_type)
3559
+ {
3560
+ assert (!it->subtypes ().empty ());
3561
+ it->subtypes ().back ().subtype ().swap (ptrs);
3562
+ }
3563
+ else
3564
+ {
3565
+ assert (it->is_not_nil ());
3566
+ it->subtype ().swap (ptrs);
3567
+ }
3568
+
3537
3569
ptrs.swap (*it);
3538
3570
}
3539
3571
@@ -3947,7 +3979,7 @@ bool Parser::rOperatorName(irept &name)
3947
3979
3948
3980
/* ******************************************************************\
3949
3981
3950
- Function:
3982
+ Function: Parser::rCastOperatorName
3951
3983
3952
3984
Inputs:
3953
3985
@@ -3991,33 +4023,12 @@ bool Parser::rCastOperatorName(irept &name)
3991
4023
3992
4024
if (!optPtrOperator (ptr))
3993
4025
return false ;
4026
+
4027
+ make_subtype (type_name, ptr);
4028
+ merge_types (cv2, ptr);
4029
+ name = ptr;
3994
4030
3995
- if (ptr.is_nil ())
3996
- {
3997
- name=type_name;
3998
- return true ;
3999
- }
4000
- else
4001
- {
4002
- std::list<typet> t_list;
4003
- do
4004
- {
4005
- t_list.push_back (ptr);
4006
- typet tmp = ptr.subtype ();
4007
- ptr = tmp;
4008
- }while (ptr.is_not_nil ());
4009
-
4010
- ptr = type_name;
4011
- while (!t_list.empty ())
4012
- {
4013
- t_list.back ().subtype () = ptr;
4014
- ptr = t_list.back ();
4015
- t_list.pop_back ();
4016
- }
4017
- merge_types (cv2,ptr);
4018
- name = ptr;
4019
- return true ;
4020
- }
4031
+ return true ;
4021
4032
}
4022
4033
4023
4034
/* ******************************************************************\
@@ -6117,6 +6128,7 @@ bool Parser::rTypeNameOrFunctionType(typet &tname)
6117
6128
6118
6129
if (!optPtrOperator (tname))
6119
6130
return false ;
6131
+
6120
6132
return true ;
6121
6133
}
6122
6134
0 commit comments