comparison lwcc/preproc.c @ 297:310df72c641d ccdev

Handle () surrounding macro args on invocation
author William Astle <lost@l-w.ca>
date Sat, 14 Sep 2013 21:27:03 -0600
parents 83fcc1ed6ad6
children 6112c67728ba
comparison
equal deleted inserted replaced
296:83fcc1ed6ad6 297:310df72c641d
772 struct token **arglist = NULL; 772 struct token **arglist = NULL;
773 int nargs = 0; 773 int nargs = 0;
774 struct expand_e *e; 774 struct expand_e *e;
775 struct token **exparglist = NULL; 775 struct token **exparglist = NULL;
776 int i; 776 int i;
777 777 int pcount;
778
778 s = symtab_find(pp, mname); 779 s = symtab_find(pp, mname);
779 if (!s) 780 if (!s)
780 return 0; 781 return 0;
781 782
782 for (e = pp -> expand_list; e; e = e -> next) 783 for (e = pp -> expand_list; e; e = e -> next)
825 arglist[0] = NULL; 826 arglist[0] = NULL;
826 t2 = NULL; 827 t2 = NULL;
827 828
828 while (t -> ttype != TOK_CPAREN) 829 while (t -> ttype != TOK_CPAREN)
829 { 830 {
831 pcount = 0;
830 if (t -> ttype == TOK_EOF) 832 if (t -> ttype == TOK_EOF)
831 { 833 {
832 preproc_throw_error(pp, "Unexpected EOF in macro call"); 834 preproc_throw_error(pp, "Unexpected EOF in macro call");
833 break; 835 break;
834 } 836 }
835 if (t -> ttype == TOK_EOL) 837 if (t -> ttype == TOK_EOL)
836 continue; 838 continue;
837 if (t -> ttype == TOK_COMMA) 839 if (t -> ttype == TOK_OPAREN)
840 pcount++;
841 else if (t -> ttype == TOK_CPAREN && pcount)
842 pcount--;
843 if (t -> ttype == TOK_COMMA && pcount == 0)
838 { 844 {
839 if (!(s -> vargs) || (nargs > s -> nargs)) 845 if (!(s -> vargs) || (nargs > s -> nargs))
840 { 846 {
841 nargs++; 847 nargs++;
842 arglist = lw_realloc(arglist, sizeof(struct token *) * nargs); 848 arglist = lw_realloc(arglist, sizeof(struct token *) * nargs);