pike.git / src / cpp.cmod

version» Context lines:

pike.git/src/cpp.cmod:3352:    }    UNSETJMP(recovery);       CALC_DUMPPOS("Done");       return pos;   }      /* NB: This function is only called from low_cpp(), which    * means that Pike_fp->current_object is an object(CPP). +  * +  * NB: The arguments (if any) are in an array at the top of the stack, +  * and if none there is UNDEFINED.    */   static void apply_define(struct CPP_struct *this,    struct define_struct *d, -  struct define_argument *arguments, +     short flags,    struct pike_string *charset)   {    struct svalue *save_sp = Pike_sp;    int save_flags;       /* Keep d around... */    push_svalue(&d->self);    -  if (d->args < 0) { -  push_undefined(); -  } else { -  int i; -  BEGIN_AGGREGATE_ARRAY(d->args) { -  for (i = 0; i < d->args; i++) { -  push_string(make_shared_binary_pcharp(arguments[i].arg, -  arguments[i].len)); -  DO_AGGREGATE_ARRAY(120); +  stack_swap(); +  +  if ((d->args == 1) && !Pike_sp[-1].u.array->size && +  !(d->flags & CPP_MACRO_VARARGS)) { +  // Allow a single argument to be left out. +  pop_stack(); +  ref_push_string(empty_pike_string); +  f_aggregate(1);    } -  } END_AGGREGATE_ARRAY; -  } +     ref_push_object(Pike_fp->current_object);    push_int(flags);    apply_lfun(d->self.u.object, LFUN_CALL, 3);       save_flags = d->flags;    d->flags |= CPP_MACRO_DISABLED;       /* NB: We're executing in the CPP context object. */    low_cpp(this, MKPCHARP_STR(Pike_sp[-1].u.string), Pike_sp[-1].u.string->len,    flags & ~(CPP_EXPECT_ENDIF | CPP_EXPECT_ELSE),
pike.git/src/cpp.cmod:3529:    /* NOTE: defined() must be handled here, since its argument    * must not be macro expanded.    */    d = defined_macro;    }else{    d=FIND_DEFINE(s);    }       if(d && !(d->flags & CPP_MACRO_DISABLED))    { -  int arg=0; +     INT_TYPE start_line = this->current_line;    struct string_builder tmp;    struct define_argument arguments[ MAX_ARGS];       if (d == defined_macro) {    free_string (s);    s = NULL;    }       if(d->args>=0)
pike.git/src/cpp.cmod:3554:    {    if (s) {    string_builder_shared_strcat(&this->buf,s);    free_string(s);    }    /* Restore the post-whitespace. */    string_builder_putchar(&this->buf, ' ');    break;    }    -  for(arg=0;arg<d->args;arg++) -  { -  if(arg && DATA(pos)==',') -  { -  pos++; +     SKIPWHITE(); -  }else{ +  +  BEGIN_AGGREGATE_ARRAY(d->args) { +  int arg=0; +  +  while (DATA(pos) != ')') { +  PCHARP arg_start; +  size_t arg_len; +  if(arg) { +  GOBBLE(',');    SKIPWHITE(); -  if(DATA(pos)==')') -  { -  if(((d->flags & CPP_MACRO_VARARGS) && (arg + 1 == d->args)) || -  (!arg && (d->args == 1))) { -  /* Allow varargs to be left out. -  * -  * Allow a single argument to be left out. -  */ -  arguments[arg].arg = ADD_PCHARP(data,pos); -  arguments[arg].len=0; -  continue; -  }else{ -  cpp_error_sprintf(this, -  "Too few arguments to macro %S, expected %d.", -  d->name, d->args); -  break; +     } -  } -  } -  arguments[arg].arg = ADD_PCHARP(data,pos); +  arg_start = ADD_PCHARP(data, pos);       while(1)    {    if(pos+1>len)    {    INT_TYPE save_line = this->current_line;    this->current_line = start_line;    cpp_error(this, "End of file in macro call.");    this->current_line = save_line;    break;
pike.git/src/cpp.cmod:3644:       case '(':    pos=find_end_parenthesis(this, data, len, pos);    continue;       case '{':    pos=find_end_brace(this, data, len, pos);    continue;       case ',': -  if((d->flags & CPP_MACRO_VARARGS) && (arg+1 == d->args)) continue; -  /* FALLTHRU */ -  +     case ')':    pos--;    break;    }    break;    } -  arguments[arg].len = SUBTRACT_PCHARP(ADD_PCHARP(data,pos),arguments[arg].arg); -  } +  arg_len = SUBTRACT_PCHARP(ADD_PCHARP(data, pos), arg_start); +  +  push_string(make_shared_binary_pcharp(arg_start, arg_len)); +  DO_AGGREGATE_ARRAY(120); +     SKIPWHITE(); -  +  arg++; +  } +  +  } END_AGGREGATE_ARRAY; +     if(!GOBBLE(')')) {    this->current_line = start_line;    cpp_error_sprintf(this, "Missing ) in the macro %S.", d->name);    } -  +  } else { +  push_undefined();    }    -  if(d->args >= 0 && arg != d->args) -  cpp_error(this, "Wrong number of arguments to macro."); -  -  /* NB: If there have been errors in the loop above, arguments may -  * remain (partially) uninitialized. -  */ -  if (!this->compile_errors) { -  apply_define(this, d, arguments, flags, charset); -  } +  apply_define(this, d, flags, charset);    }else{    if (OUTP())    string_builder_shared_strcat (&this->buf, s);    }    if (s) {    free_string(s);    }    }    break;