pike.git / src / cpp.cmod

version» Context lines:

pike.git/src/cpp.cmod:216:    int|void flags_sval)    flags ID_PROTECTED;    {    struct define_struct *d = THIS;    struct string_builder s;    struct array *arguments2 = arguments;    struct array *parts = THIS->parts;    INT32 i;    INT_TYPE flags = flags_sval?flags_sval->u.integer:0;    -  init_string_builder(&s, 0); -  if(d->magic) -  { -  struct pike_string *a = NULL; +  if (d->args >= 0) { +  if (!arguments) { +  ref_push_array(&empty_array); +  arguments = arguments2 = &empty_array;    -  if (arguments && (d->args > 0)) { -  a = ITEM(arguments)[0].u.string; +  if ((!d->args) || +  ((d->flags & CPP_MACRO_VARARGS) && (d->args == 1))) { +  /* NB: In the varargs case arguments2 will get +  * further adjustment below. +  */ +  } else { +  if (context_obj) { +  push_text("Expected %d arguments to macro %s, got none."); +  push_int(d->args); +  ref_push_string(d->name); +  apply(context_obj, "cpp_error", 3); +  } else { +  my_yyerror("Expected %d argumnets to macro %S, got none.", +  d->args, d->name);    } -  d->magic(context_obj, d, a, &s); -  -  goto done; +     } -  +  }    -  if (arguments2 && (d->flags & CPP_MACRO_VARARGS) && +  if (d->args != arguments2->size) { +  if (!(d->flags & CPP_MACRO_VARARGS) || +  (d->args > arguments2->size+1)) { +  /* Allow varargs to be left out. */ +  if (context_obj) { +  push_text("Bad number of arguments to macro %s, expected %d" +  ", got %d."); +  ref_push_string(d->name); +  push_int(d->args); +  push_int(arguments2->size); +  apply(context_obj, "cpp_error", 4); +  } else { +  my_yyerror("Bad number of arguments to macro %S, expected %d" +  ", got %d.", +  d->name, d->args, arguments2->size); +  } +  } +  if (d->args > arguments2->size) { +  /* Grow arguments2 to at least d->args elements. */ +  ref_push_array(arguments2); +  ref_push_string(empty_pike_string); +  f_aggregate(1); +  push_int(d->args - arguments2->size); +  o_multiply(); +  f_add(2); +  arguments2 = Pike_sp[-1].u.array; +  } else if ((d->flags & CPP_MACRO_VARARGS) &&    (arguments2->size > d->args)) {    /* Join all the varargs with commas. */    push_array(slice_array(arguments2, 0, d->args-1));    push_array(slice_array(arguments2, d->args-1, arguments2->size));    push_text(",");    o_multiply();    f_aggregate(1);    f_add(2);    arguments2 = Pike_sp[-1].u.array;    } -  +  } +  }    -  +  init_string_builder(&s, 0); +  if(d->magic) +  { +  struct pike_string *a = NULL; +  +  if (arguments2 && (d->args > 0)) { +  a = ITEM(arguments2)[0].u.string; +  } +  d->magic(context_obj, d, a, &s); +  +  goto done; +  } +     for (i = 0; i < parts->size; i++) {    struct svalue *sval = &parts->item[i];    switch (TYPEOF(*sval)) {    case PIKE_T_STRING:    string_builder_shared_strcat(&s, sval->u.string);    break;    case PIKE_T_INT:    {    int raw_arg = sval->u.integer;    int arg = raw_arg & DEF_ARG_MASK;