@@ -343,7 +343,7 @@ class Parser
343343 unsigned number_of_errors;
344344 irep_idt current_function;
345345
346- void merge_types (typet &src, typet &dest);
346+ void merge_types (const typet &src, typet &dest);
347347
348348 void set_location (irept &dest, const cpp_tokent &token)
349349 {
@@ -355,12 +355,22 @@ class Parser
355355 source_location.set_function (current_function);
356356 }
357357
358- void make_subtype (typet &src, typet &dest)
358+ void make_subtype (const typet &src, typet &dest)
359359 {
360360 typet *p=&dest;
361+
361362 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;
364374 }
365375
366376 unsigned int max_errors;
@@ -452,7 +462,7 @@ void Parser::make_sub_scope(const irep_idt &id, new_scopet::kindt kind)
452462
453463/* ******************************************************************\
454464
455- Function:
465+ Function: Parser::rString
456466
457467 Inputs:
458468
@@ -472,7 +482,7 @@ bool Parser::rString(cpp_tokent &tk)
472482
473483/* ******************************************************************\
474484
475- Function:
485+ Function: Parser::merge_types
476486
477487 Inputs:
478488
@@ -482,22 +492,22 @@ bool Parser::rString(cpp_tokent &tk)
482492
483493\*******************************************************************/
484494
485- void Parser::merge_types (typet &src, typet &dest)
495+ void Parser::merge_types (const typet &src, typet &dest)
486496{
487497 if (src.is_nil ()) return ;
488498
489499 if (dest.is_nil ())
490- dest. swap ( src) ;
500+ dest= src;
491501 else
492502 {
493503 if (dest.id ()!=ID_merged_type)
494504 {
495505 typet tmp (ID_merged_type);
496506 tmp.move_to_subtypes (dest);
497- dest. swap ( tmp) ;
507+ dest= tmp;
498508 }
499509
500- dest.move_to_subtypes (src);
510+ dest.copy_to_subtypes (src);
501511 }
502512}
503513
@@ -3428,7 +3438,7 @@ bool Parser::rDeclarator(
34283438
34293439/* ******************************************************************\
34303440
3431- Function:
3441+ Function: Parser::optPtrOperator
34323442
34333443 Inputs:
34343444
@@ -3461,17 +3471,21 @@ bool Parser::optPtrOperator(typet &ptrs)
34613471
34623472 if (t==' *' )
34633473 {
3464- typet op (ID_pointer) ;
3474+ pointer_typet op;
34653475 cpp_tokent tk;
34663476 lex.get_token (tk);
34673477 set_location (op, tk);
34683478
34693479 typet cv;
34703480 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);
34753489 }
34763490 else if (t==' ^' )
34773491 {
@@ -3483,10 +3497,14 @@ bool Parser::optPtrOperator(typet &ptrs)
34833497
34843498 typet cv;
34853499 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);
34903508 }
34913509 else if (isPtrToMember (0 ))
34923510 {
@@ -3496,10 +3514,14 @@ bool Parser::optPtrOperator(typet &ptrs)
34963514
34973515 typet cv;
34983516 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);
35033525 }
35043526 else
35053527 break ;
@@ -3533,7 +3555,17 @@ bool Parser::optPtrOperator(typet &ptrs)
35333555 it!=t_list.rend ();
35343556 it++)
35353557 {
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+
35373569 ptrs.swap (*it);
35383570 }
35393571
@@ -3947,7 +3979,7 @@ bool Parser::rOperatorName(irept &name)
39473979
39483980/* ******************************************************************\
39493981
3950- Function:
3982+ Function: Parser::rCastOperatorName
39513983
39523984 Inputs:
39533985
@@ -3991,33 +4023,12 @@ bool Parser::rCastOperatorName(irept &name)
39914023
39924024 if (!optPtrOperator (ptr))
39934025 return false ;
4026+
4027+ make_subtype (type_name, ptr);
4028+ merge_types (cv2, ptr);
4029+ name = ptr;
39944030
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 ;
40214032}
40224033
40234034/* ******************************************************************\
@@ -6117,6 +6128,7 @@ bool Parser::rTypeNameOrFunctionType(typet &tname)
61176128
61186129 if (!optPtrOperator (tname))
61196130 return false ;
6131+
61206132 return true ;
61216133 }
61226134
0 commit comments