@@ -244,14 +244,15 @@ uint type_parameterSize(const type* t, tym_t tyf)
244244@trusted
245245uint type_paramsize (const type* t)
246246{
247- targ_size_t sz = 0 ;
247+ size_t sz = 0 ;
248248 if (tyfunc(t.Tty))
249249 {
250- for (const (param_t)* p = t.Tparamtypes; p; p = p.Pnext)
251- {
252- const size_t n = type_parameterSize(p.Ptype, tybasic(t.Tty));
253- sz += _align(REGSIZE ,n); // align to REGSIZE boundary
254- }
250+ if (t.Tparamtypes)
251+ foreach (ref p; (* t.Tparamtypes)[])
252+ {
253+ const size_t n = type_parameterSize(p.Ptype, tybasic(t.Tty));
254+ sz += _align(REGSIZE ,n); // align to REGSIZE boundary
255+ }
255256 }
256257 return cast (uint )sz;
257258}
@@ -404,7 +405,7 @@ type* type_delegate(type* tnext)
404405}
405406
406407/* **********************************
407- * Allocation a function type.
408+ * Allocate a function type.
408409 * Params:
409410 * tyf = function type
410411 * ptypes = types of the function parameters
@@ -416,16 +417,21 @@ type* type_delegate(type* tnext)
416417@trusted
417418type* type_function (tym_t tyf, type* [] ptypes, bool variadic, type* tret)
418419{
419- param_t* paramtypes = null ;
420- foreach (p; ptypes)
421- {
422- param_append_type(¶mtypes, p);
423- }
424420 type* t = type_allocn(tyf, tret);
425421 t.Tflags |= TF .prototype;
426422 if (! variadic)
427423 t.Tflags |= TF .fixed;
428- t.Tparamtypes = paramtypes;
424+
425+ if (ptypes.length)
426+ {
427+ param_t* paramtypes = cast (param_t* )mem_calloc(ptypes.length * param_t.sizeof);
428+ foreach (i, tx; ptypes)
429+ {
430+ paramtypes[i].Ptype = tx;
431+ }
432+ t.Tparamtypes = cast (param_t[]* )mem_malloc(param_t[].sizeof);
433+ * t.Tparamtypes = paramtypes[0 .. ptypes.length];
434+ }
429435 t.Tcount++ ;
430436 return t;
431437}
@@ -525,7 +531,7 @@ void type_free(type* t)
525531 break ;
526532 tym_t ty = tybasic(t.Tty);
527533 if (tyfunc(ty))
528- param_free(& t.Tparamtypes);
534+ param_free(t.Tparamtypes);
529535 else if (t.Tflags & TF .vla && t.Tel)
530536 el_free(t.Tel);
531537 else if (t.Tkey && typtr(ty))
@@ -706,14 +712,18 @@ void type_term()
706712
707713/* *************************
708714 * Make copy of a type.
715+ * Params:
716+ * tf = type to copy
717+ * Returns:
718+ * copy of tf
709719 */
710720
711721@trusted
712- type* type_copy (type* t )
722+ type* type_copy (type* tf )
713723{
714- type_debug(t );
715- type* tn = type_alloc(t .Tty);
716- * tn = * t ;
724+ type_debug(tf );
725+ type* tn = type_alloc(tf .Tty);
726+ * tn = * tf ;
717727 switch (tybasic(tn.Tty))
718728 {
719729 case TYarray:
@@ -724,13 +734,23 @@ type* type_copy(type* t)
724734 default :
725735 if (tyfunc(tn.Tty))
726736 {
727- tn.Tparamtypes = null ;
728- for (param_t * p = t .Tparamtypes; p; p = p.Pnext )
737+ // Copy the parameters for the function type
738+ if (tn .Tparamtypes)
729739 {
730- param_t* pn = param_append_type(&tn.Tparamtypes,p.Ptype);
731- if (p.Pident)
740+ tn.Tparamtypes = cast (param_t[]* )mem_calloc(param_t[].sizeof);
741+
742+ // allocate new array for tn
743+ const length = (* tf.Tparamtypes)[].length; // length of source array
744+ * tn.Tparamtypes = (cast (param_t* )mem_calloc(param_t.sizeof * length))[0 .. length];
745+
746+ param_t[] pn = * tn.Tparamtypes;
747+ foreach (i, pf; (* tf.Tparamtypes)[])
732748 {
733- pn.Pident = cast (char * )mem_strdup(p.Pident);
749+ pn[i].Pident = cast (char * )mem_strdup(pf.Pident);
750+ auto t = pf.Ptype;
751+ type_debug(t);
752+ t.Tcount++ ;
753+ pn[i].Ptype = t;
734754 }
735755 }
736756 }
@@ -860,25 +880,31 @@ type* type_setdependent(type* t)
860880/* ******************************
861881 * Recursively check if type u is embedded in type t.
862882 * Returns:
863- * != 0 if embedded
883+ * true if embedded
864884 */
865885
866886@trusted
867- int type_embed (const ( type) * t, const type* u)
887+ bool type_embed (type* t,type* u)
868888{
869889 for (; t; t = t.Tnext)
870890 {
871891 type_debug(t);
872892 if (t == u)
873- return 1 ;
893+ return true ;
874894 if (tyfunc(t.Tty))
875895 {
876- for (const (param_t)* p = t.Tparamtypes; p; p = p.Pnext)
877- if (type_embed(p.Ptype,u))
878- return 1 ;
896+ if (t.Tparamtypes)
897+ {
898+ const length = (* t.Tparamtypes).length;
899+ foreach (i; 0 .. length)
900+ {
901+ if (type_embed((* t.Tparamtypes)[i].Ptype,u))
902+ return true ;
903+ }
904+ }
879905 }
880906 }
881- return 0 ;
907+ return false ;
882908}
883909
884910
@@ -934,16 +960,20 @@ void type_print(const type* t)
934960 default :
935961 if (tyfunc(t.Tty))
936962 {
937- int i = 1 ;
938- for (const (param_t)* p = t.Tparamtypes; p; p = p.Pnext)
939- { printf(" \n P%d (%p): " ,i++ ,p);
940- fflush(stdout);
941-
942- printf(" Pident=%p,Ptype=%p,Pnext=%p " ,p.Pident,p.Ptype,p.Pnext);
943- param_debug(p);
944- if (p.Pident)
945- printf(" '%s' " , p.Pident);
946- type_print(p.Ptype);
963+ if (t.Tparamtypes)
964+ {
965+ auto a = * t.Tparamtypes;
966+ foreach (i, ref p; a)
967+ {
968+ printf(" \n P%zd: " ,i);
969+ fflush(stdout);
970+
971+ printf(" Pident=%p,Ptype=%p " ,p.Pident,p.Ptype);
972+ param_debug(&p);
973+ if (p.Pident)
974+ printf(" '%s' " , p.Pident);
975+ type_print(p.Ptype);
976+ }
947977 }
948978 }
949979 break ;
@@ -959,7 +989,7 @@ void type_print(const type* t)
959989@trusted
960990void param_t_print (const scope param_t* p)
961991{
962- printf(" Pident=%p,Ptype=%p,Pnext=%p \n " ,p.Pident,p.Ptype,p.Pnext );
992+ printf(" Pident=%p,Ptype=%p\n " ,p.Pident,p.Ptype);
963993 if (p.Pident)
964994 printf(" \t Pident = '%s'\n " , p.Pident);
965995 if (p.Ptype)
@@ -976,85 +1006,29 @@ void param_t_print_list(scope param_t* p)
9761006}
9771007
9781008
979- /* ***************************
980- * Allocate a param_t.
981- */
982-
983- @trusted
984- param_t* param_calloc ()
985- {
986- static param_t pzero;
987- param_t* p;
988-
989- if (param_list)
990- {
991- p = param_list;
992- param_list = p.Pnext;
993- }
994- else
995- {
996- p = cast (param_t* ) mem_fmalloc(param_t.sizeof);
997- }
998- * p = pzero;
999-
1000- debug p.id = param_t.IDparam;
1001-
1002- return p;
1003- }
1004-
1005- /* **************************
1006- * Allocate a param_t of type t, and append it to parameter list.
1007- */
1008-
1009- param_t* param_append_type (param_t** pp,type* t)
1010- {
1011- param_t* p = param_calloc();
1012- while (* pp)
1013- {
1014- param_debug(* pp);
1015- pp = &((* pp).Pnext); /* find end of list */
1016- }
1017- * pp = p; /* append p to list */
1018- type_debug(t);
1019- p.Ptype = t;
1020- t.Tcount++ ;
1021- return p;
1022- }
1023-
1024- /* ***********************
1025- * Version of param_free() suitable for list_free().
1026- */
1027-
1028- @trusted
1029- void param_free_l (param_t* p)
1030- {
1031- param_free(&p);
1032- }
1033-
10341009/* **********************
10351010 * Free parameter list.
10361011 * Output:
10371012 * paramlst = null
10381013 */
10391014
10401015@trusted
1041- void param_free (param_t* * pparamlst)
1016+ void param_free (ref param_t[] * pparamlst)
10421017{
10431018 // debug_assert(PARSER);
1044- param_t* pn;
1045- for (param_t* p = * pparamlst; p; p = pn)
1019+ if (pparamlst)
10461020 {
1047- param_debug(p) ;
1048- pn = p.Pnext;
1049- type_free(p.Ptype);
1050- mem_free (p.Pident );
1051-
1052- debug p.id = 0 ;
1053-
1054- p.Pnext = param_list ;
1055- param_list = p ;
1021+ param_t[] a = * pparamlst ;
1022+ foreach ( ref p; a)
1023+ {
1024+ type_free (p.Ptype );
1025+ mem_free(p.Pident);
1026+ debug p.id = 0 ;
1027+ }
1028+ mem_free(a.ptr) ;
1029+ mem_free(pparamlst) ;
10561030 }
1057- * pparamlst = null ;
1031+ pparamlst = null ;
10581032}
10591033
10601034/* **********************************
@@ -1085,12 +1059,26 @@ param_t* param_t_search(return scope param_t* p, const(char)* id)
10851059}
10861060
10871061// Return TRUE if type lists match.
1088- private int paramlstmatch (param_t* p1,param_t* p2)
1062+ private int paramlstmatch (param_t[] * p1,param_t[] * p2)
10891063{
1090- return p1 == p2 ||
1091- p1 && p2 && typematch(p1.Ptype,p2.Ptype,0 ) &&
1092- paramlstmatch(p1.Pnext,p2.Pnext)
1093- ;
1064+ if (p1 == p2)
1065+ return true ;
1066+
1067+ if (! (p1 && p2))
1068+ return false ;
1069+
1070+ param_t[] a1 = * p1,
1071+ a2 = * p2;
1072+
1073+ if (a1.length != a2.length)
1074+ return false ;
1075+
1076+ foreach (i; 0 .. a1.length)
1077+ {
1078+ if (! typematch(a1[i].Ptype, a2[i].Ptype, 0 ))
1079+ return false ;
1080+ }
1081+ return true ;
10941082}
10951083
10961084/* ************************************************
0 commit comments