pike.git / src / cpp.cmod

version» Context lines:

pike.git/src/cpp.cmod:3328:    pos=calc1(this,data,len,tmp,flags);    check_destructed(Pike_sp-1);    }    UNSETJMP(recovery);       CALC_DUMPPOS("Done");       return pos;   }    - #if 0 - static void string_builder_append_cpp_quoted_pcharp(struct string_builder *s, -  PCHARP a, -  size_t l) - { -  size_t e; -  for(e=0; e<l;) { -  if (wide_isspace(INDEX_PCHARP(a, e)) || -  INDEX_PCHARP(a, e)=='"' || INDEX_PCHARP(a, e)=='\\') { -  if (e) { -  string_builder_append(s, a, e); -  } -  if (INDEX_PCHARP(a, e) == '"' || INDEX_PCHARP(a, e)=='\\') { -  /* String or quote. */ -  string_builder_putchar(s, '\\'); -  string_builder_putchar(s, INDEX_PCHARP(a, e)); -  if (INDEX_PCHARP(a, e) == '"') { -  for (e++; e < l; e++) { -  if (INDEX_PCHARP(a, e) == '"') { -  e++; -  break; -  } -  string_builder_putchar(s, INDEX_PCHARP(a, e)); -  if (INDEX_PCHARP(a, e) == '\\') { -  string_builder_putchar(s, '\\'); -  e++; -  if (INDEX_PCHARP(a, e) == '\\' || -  INDEX_PCHARP(a, e) == '"') { -  string_builder_putchar(s, '\\'); -  } -  string_builder_putchar(s, INDEX_PCHARP(a, e)); -  } -  } -  string_builder_putchar(s, '\\'); -  string_builder_putchar(s, '"'); -  } -  } else { -  /* White space. */ -  while ((e < l) && wide_isspace(INDEX_PCHARP(a, e))) { -  e++; -  } -  if (e != l) { -  string_builder_putchar(s, ' '); -  } -  } -  INC_PCHARP(a, e); -  l -= e; -  e = 0; -  } else { -  e++; -  } -  } -  if (l) { -  string_builder_append(s,a,l); -  } - } - #endif -  +    /* NB: This function is only called from low_cpp(), which    * means that Pike_fp->current_object is an object(CPP).    */   static void apply_define(struct CPP_struct *this,    struct define_struct *d,    struct define_argument *arguments,    short flags,    struct pike_string *charset)   { - #if 1 +     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;
pike.git/src/cpp.cmod:3429:    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),    charset);       d->flags = save_flags;       pop_n_elems(Pike_sp - save_sp); - #else /* !1 */ -  struct string_builder tmp; -  -  init_string_builder(&tmp, 0); -  if(d->magic) -  { -  int i; -  struct pike_string *a = NULL; -  if (d->args > 0) { -  a = make_shared_binary_pcharp(arguments[0].arg, arguments[0].len); +    } -  d->magic(this, d, a, &tmp); -  /* FIXME: Popping the stack should be moved to -  * the magic functions. -  */ -  if (a) free_string(a); -  }else{ -  struct array *parts = d->parts; -  int e; -  for(e = 0; e < parts->size; e++) -  { -  PCHARP a; -  ptrdiff_t l; +     -  switch(TYPEOF(parts->item[e])) { -  case PIKE_T_INT: -  { -  int argument = parts->item[e].u.integer; -  if((argument & DEF_ARG_MASK) >= d->args) -  { -  cpp_error(this, "Macro not expanded correctly."); -  continue; -  } -  -  a = arguments[argument & DEF_ARG_MASK].arg; -  l = arguments[argument & DEF_ARG_MASK].len; -  -  if (argument & DEF_ARG_NEED_COMMA -  && !(d->flags & CPP_MACRO_VARARGS && d->args-1 -  == (argument & DEF_ARG_MASK) && l == 0)) { -  string_builder_putchar(&tmp, ','); -  string_builder_putchar(&tmp, ' '); -  } -  -  if(!(argument & DEF_ARG_NOPRESPACE)) -  string_builder_putchar(&tmp, ' '); -  -  if(argument & DEF_ARG_STRINGIFY) -  { -  /* NOTE: At entry a[0] is non white-space. */ -  string_builder_putchar(&tmp, '"'); -  string_builder_append_cpp_quoted_pcharp(&tmp, a, l); -  string_builder_putchar(&tmp, '"'); -  }else{ -  /* Strip leading and trailing white-space. */ -  while(l && wide_isspace(EXTRACT_PCHARP(a))) -  INC_PCHARP(a,1),l--; -  -  while(l && wide_isspace(INDEX_PCHARP(a,l-1))) -  l--; -  -  if(argument & (DEF_ARG_NOPRESPACE | DEF_ARG_NOPOSTSPACE)) -  { -  string_builder_append( &tmp, a, l ); -  }else{ -  /* NB: Evaluate the argument before insertion. */ -  struct string_builder save; -  INT_TYPE line = this->current_line; -  int save_flags; -  /* FIXME: Shouldn't we save current_file too? */ -  save=this->buf; -  this->buf=tmp; -  save_flags = d->flags; -  d->flags |= CPP_MACRO_IN_USE; -  low_cpp(this, a, l, -  flags & ~(CPP_EXPECT_ENDIF | CPP_EXPECT_ELSE), -  charset); -  d->flags = save_flags; -  tmp=this->buf; -  this->buf=save; -  this->current_line=line; -  } -  } -  -  if(!(argument & DEF_ARG_NOPOSTSPACE)) -  string_builder_putchar(&tmp, ' '); -  } -  break; -  -  case PIKE_T_STRING: -  string_builder_shared_strcat(&tmp, parts->item[e].u.string); -  break; -  } -  } -  } -  -  /* Remove any newlines from the completed expression. */ -  if (!(d->magic == insert_callback_define || -  d->magic == insert_callback_define_no_args || -  d->magic == insert_pragma)) { -  int e; -  for(e=0; e< (ptrdiff_t)tmp.s->len; e++) -  if(index_shared_string(tmp.s,e)=='\n') -  SET_INDEX_CHARP(tmp.s->str,e,tmp.s->size_shift,' '); -  } -  -  d->flags = CPP_MACRO_DISABLED; -  /* FIXME: Ought to add a ref to d here. */ -  -  string_builder_putchar(&tmp, 0); -  tmp.s->len--; -  low_cpp(this, MKPCHARP_STR(tmp.s),tmp.s->len, -  flags & ~(CPP_EXPECT_ENDIF | CPP_EXPECT_ELSE), -  charset); -  -  d->flags = flags; -  /* FIXME: Ought to free the ref to d here. */ -  -  free_string_builder(&tmp); - #endif /* 1 */ - } -  +    /*    * Preprocessor template.    *    * NB: There are two basic cases where this function is called:    *    * * Either when switching to a new input data string    * (eg macro expansion or #include). The result of    * this is added to the current buffer.    *    * * Or parsing to the end of the line after a directive.