pike.git / src / cpp.cmod

version» Context lines:

pike.git/src/cpp.cmod:87:    int argument;    struct pike_string *postfix;   };      struct define_argument {    PCHARP arg;    ptrdiff_t len;   };      struct cpp; - struct define; + struct define_struct;   typedef void (*magic_define_fun)(struct cpp *, -  struct define *, +  struct define_struct *,    struct pike_string *,    struct string_builder *);    - struct define + struct define_struct   {    struct hash_entry link; /* must be first */    magic_define_fun magic;    int args;    ptrdiff_t num_parts;    short inside; /* 1 - Don't expand. 2 - In use. */    short varargs;    struct pike_string *first;    struct define_part *parts;   };      static void init_define_struct(struct object *UNUSED(o))   { -  struct define *def = (struct define *)(Pike_fp->current_storage); +  struct define_struct *def = (struct define_struct *)(Pike_fp->current_storage);    def->magic=0;    def->args=-1;    def->inside=0;    def->varargs=0;    def->parts = NULL;    def->num_parts=0;    def->first=0;    def->link.s = NULL;   }      static void exit_define_struct(struct object *UNUSED(o))   { -  struct define *d = (struct define *)(Pike_fp->current_storage); +  struct define_struct *d = (struct define_struct *)(Pike_fp->current_storage);    INT32 e;    for (e = 0; e < d->num_parts; e++)    free_string(d->parts[e].postfix);    if (d->parts)    free(d->parts);    if (d->link.s)    free_string(d->link.s);    if(d->first)    free_string(d->first);   }
pike.git/src/cpp.cmod:152:    struct object *compat_handler;    INT_TYPE compat_major;    INT_TYPE compat_minor;    struct pike_string *data;    struct pike_string *prefix;    INT_TYPE picky_cpp, keep_comments, dependencies_fail;   };      #define FIND_DEFINE(N) find_define(this, (N))    - static struct define *find_define(struct cpp *this, struct pike_string *n) + static struct define_struct *find_define(struct cpp *this, struct pike_string *n)   {    struct svalue *s;    if (!this->defines) return NULL;    if (!(s = low_mapping_string_lookup(this->defines, n))) return NULL;    if (TYPEOF(*s) != T_OBJECT) return NULL; -  return (struct define *)get_storage(s->u.object, define_program); +  return (struct define_struct *)get_storage(s->u.object, define_program);   }      DECLARE_STORAGE;      static void cpp_error(struct cpp *this, const char *err) ATTRIBUTE((noinline));   static void cpp_error_vsprintf (struct cpp *this, const char *fmt,    va_list args) ATTRIBUTE((noinline));   static void cpp_error_sprintf(struct cpp *this, const char *fmt, ...) ATTRIBUTE((noinline));   static void cpp_handle_exception(struct cpp *this,    const char *cpp_error_fmt, ...) ATTRIBUTE((noinline));   static void cpp_warning(struct cpp *this, const char *cpp_warn_fmt, ...) ATTRIBUTE((noinline)); - struct define *defined_macro =0; + struct define_struct *defined_macro = NULL;   static struct svalue defined_macro_sval;      static void cpp_error(struct cpp *this, const char *err)   {    this->compile_errors++;    if(this->compile_errors > 10) return;    if((this->handler && this->handler->prog) || get_master())    {    ref_push_string(this->current_file);    push_int(this->current_line);
pike.git/src/cpp.cmod:913:    *! is defined.    *!    *! @note    *! @tt{#if defined(MY_DEF)@} is equvivalent to    *! @tt{#ifdef MY_DEF@}.    *!    *! @seealso    *! @[#if], @[#ifdef], @[constant()]    */   static void check_defined(struct cpp *this, -  struct define *UNUSED(def), +  struct define_struct *UNUSED(def),    struct pike_string *arg,    struct string_builder *tmp)   {    if(arg && FIND_DEFINE(arg))    string_builder_binary_strcat(tmp, " 1 ", 3);    else    string_builder_binary_strcat(tmp, " 0 ", 3);   }      static int do_safe_index_call(struct cpp *this, struct pike_string *s)
pike.git/src/cpp.cmod:1578:    if (p != *pos) {    *pos = p;    return finish_string_builder (&sb);    }    free_string_builder (&sb);    return NULL;   }      /* devours one reference to 'name'! */   /* The reference to the define is held by the stack on return. */ - static struct define *alloc_empty_define(struct pike_string *name, + static struct define_struct *alloc_empty_define(struct pike_string *name,    ptrdiff_t parts)   { -  struct define *def; +  struct define_struct *def;    struct object *o;       push_object(o = clone_object(define_program, 0)); -  def = (struct define *)get_storage(o, define_program); +  def = (struct define_struct *)get_storage(o, define_program);    def->link.s=name;    debug_malloc_touch(name);    if (parts) {    def->parts = xalloc(sizeof(struct define_part) * parts);    def->num_parts = parts;    }    return def;   }      /*! @directive #undef
pike.git/src/cpp.cmod:1622:    *! @[#define], @[defined()]    */   static void undefine(struct cpp *this, struct pike_string *name)   {    ref_push_string(name);    push_int(0);    map_delete_no_free(this->defines, Pike_sp - 2, Pike_sp - 1);       if (TYPEOF(Pike_sp[-1]) == PIKE_T_OBJECT) {    struct object *o = Pike_sp[-1].u.object; -  struct define *def = (struct define *)get_storage(o, define_program); +  struct define_struct *def = (struct define_struct *)get_storage(o, define_program);    if (def->inside) {    /* Restore the #define. */    mapping_insert(this->defines, Pike_sp - 2, Pike_sp - 1);    cpp_error(this, "Illegal to undefine a macro during its expansion.");    pop_n_elems(2);    return;    }    }       pop_n_elems(2);
pike.git/src/cpp.cmod:1661:    *! #define @b{@i{<identifier>@}@}(arg1, arg2) @i{<replacement string>@}    *! @endcode    *!    *! would cause @tt{@b{@i{<identifer>@}@}@} to be a macro. All occurances of    *! '@tt{@b{@i{<identifier>@}@}(something1,something2d)@}' would be replaced    *! with the @tt{@i{<replacement string>@}@}.    *! And in the @tt{@i{<replacement string>@}@}, @tt{arg1@} and @tt{arg2@}    *! will be replaced with @tt{something1@} and @tt{something2@}.    */    - static struct define *do_magic_define(struct cpp *this, + static struct define_struct *do_magic_define(struct cpp *this,    const char *name,    magic_define_fun fun)   { -  struct define* def; +  struct define_struct* def;       if (this->prefix) {    struct string_builder s;    int len = strlen(name);       init_string_builder(&s, 0);    string_builder_append(&s, MKPCHARP_STR(this->prefix),    this->prefix->len);    string_builder_putchar(&s, '_');    string_builder_binary_strcat(&s, name, len);
pike.git/src/cpp.cmod:1690:    mapping_string_insert(this->defines, def->link.s, Pike_sp-1);    pop_stack();       return def;   }      static void add_define(struct cpp *this,    struct pike_string *name,    struct pike_string *what)   { -  struct define* def; +  struct define_struct* def;    add_ref (name);    def=alloc_empty_define(name,0);    add_ref (def->first = what);    mapping_string_insert(this->defines, def->link.s, Pike_sp-1);    pop_stack();   }      static void simple_add_define(struct cpp *this,    const char *name,    const char *what)   { -  struct define* def; +  struct define_struct* def;       if (this->prefix) {    struct string_builder s;    int len = strlen(name);       init_string_builder(&s, 0);    string_builder_append(&s, MKPCHARP_STR(this->prefix),    this->prefix->len);    string_builder_putchar(&s, '_');    string_builder_binary_strcat(&s, name, len);
pike.git/src/cpp.cmod:2208:    return 1;   }      static ptrdiff_t low_cpp(struct cpp *this,    PCHARP data,    ptrdiff_t len,    int flags,    int auto_convert,    struct pike_string *charset);   static void insert_callback_define(struct cpp *this, -  struct define *def, +  struct define_struct *def,    struct pike_string *arg,    struct string_builder *tmp);   static void insert_callback_define_no_args(struct cpp *this, -  struct define *def, +  struct define_struct *def,    struct pike_string *arg,    struct string_builder *tmp);   static void insert_pragma(struct cpp *this, -  struct define *def, +  struct define_struct *def,    struct pike_string *arg,    struct string_builder *tmp);      static ptrdiff_t calc1(struct cpp *this, PCHARP data, ptrdiff_t len,    ptrdiff_t pos, int flags);      static ptrdiff_t calcC(struct cpp *this, PCHARP data, ptrdiff_t len,    ptrdiff_t pos, int flags)   {    SKIPWHITE();
pike.git/src/cpp.cmod:2848:   #include "preprocessor.h"      /*** Magic defines ***/      /*! @decl constant __LINE__    *!    *! This define contains the current line number, represented as an    *! integer, in the source file.    */   static void insert_current_line(struct cpp *this, -  struct define *UNUSED(def), +  struct define_struct *UNUSED(def),    struct pike_string *UNUSED(arg),    struct string_builder *tmp)   {    string_builder_sprintf(tmp, " %ld ", (long)this->current_line);   }      /*! @decl constant __FILE__    *!    *! This define contains the file path and name of the source file.    */   static void insert_current_file_as_string(struct cpp *this, -  struct define *UNUSED(def), +  struct define_struct *UNUSED(def),    struct pike_string *UNUSED(arg),    struct string_builder *tmp)   {    PUSH_STRING_SHIFT(this->current_file->str, this->current_file->len,    this->current_file->size_shift, tmp);   }      /*! @decl constant __DIR__    *!    *! This define contains the directory path of the source file.    */   static void insert_current_dir_as_string(struct cpp *this, -  struct define *UNUSED(def), +  struct define_struct *UNUSED(def),    struct pike_string *UNUSED(arg),    struct string_builder *tmp)   {    ref_push_string(this->current_file);    /* FIXME: This isn't safe if the master hasn't been compiled yet. */    SAFE_APPLY_MASTER("dirname",1);    PUSH_STRING_SHIFT(Pike_sp[-1].u.string->str, Pike_sp[-1].u.string->len,    Pike_sp[-1].u.string->size_shift, tmp);    pop_stack();   }      /*! @decl constant __TIME__    *!    *! This define contains the current time at the time of compilation,    *! e.g. "12:20:51".    */   static void insert_current_time_as_string(struct cpp *UNUSED(this), -  struct define *UNUSED(def), +  struct define_struct *UNUSED(def),    struct pike_string *UNUSED(arg),    struct string_builder *tmp)   {    /* FIXME: Is this code safe? */    time_t tmp2;    char *buf;    time(&tmp2);    buf=ctime(&tmp2);       PUSH_STRING0((p_wchar0 *)buf+11, 8, tmp);   }      /*! @decl constant __DATE__    *!    *! This define contains the current date at the time of compilation,    *! e.g. "Jul 28 2001".    */   static void insert_current_date_as_string(struct cpp *UNUSED(this), -  struct define *UNUSED(def), +  struct define_struct *UNUSED(def),    struct pike_string *UNUSED(arg),    struct string_builder *tmp)   {    /* FIXME: Is this code safe? */    time_t tmp2;    char *buf;    time(&tmp2);    buf=ctime(&tmp2);       PUSH_STRING0((p_wchar0 *)buf+4, 6, tmp);
pike.git/src/cpp.cmod:2934:   /*! @decl constant __VERSION__    *!    *! This define contains the current Pike version as a float. If    *! another Pike version is emulated, this define is updated    *! accordingly.    *!    *! @seealso    *! @[__REAL_VERSION__]    */   static void insert_current_version(struct cpp *this, -  struct define *UNUSED(def), +  struct define_struct *UNUSED(def),    struct pike_string *UNUSED(arg),    struct string_builder *tmp)   {    string_builder_sprintf(tmp, " %d.%d ", this->compat_major,    this->compat_minor);   }         /*! @decl constant __MINOR__    *! This define contains the minor part of the current Pike version,    *! represented as an integer. If another Pike version is emulated,    *! this define is updated accordingly.    *!    *! @seealso    *! @[__REAL_MINOR__]    */   static void insert_current_minor(struct cpp *this, -  struct define *UNUSED(def), +  struct define_struct *UNUSED(def),    struct pike_string *UNUSED(arg),    struct string_builder *tmp)   {    string_builder_sprintf(tmp, " %d ", this->compat_minor);   }      /*! @decl int(1..) __COUNTER__    *! This define contains a unique counter (unless it has been expanded    *! Int.NATIVE_MAX times) represented as an integer.    *!    */   static void insert_current_counter(struct cpp *UNUSED(this), -  struct define *UNUSED(def), +  struct define_struct *UNUSED(def),    struct pike_string *UNUSED(arg),    struct string_builder *tmp)   {    static int counter = 0;    string_builder_sprintf(tmp, " %d ", ++counter);   }      /*! @decl constant __MAJOR__    *!    *! This define contains the major part of the current Pike version,    *! represented as an integer. If another Pike version is emulated,    *! this define is updated accordingly.    *!    *! @seealso    *! @[__REAL_MAJOR__]    */   static void insert_current_major(struct cpp *this, -  struct define *UNUSED(def), +  struct define_struct *UNUSED(def),    struct pike_string *UNUSED(arg),    struct string_builder *tmp)   {    string_builder_sprintf(tmp, " %d ", this->compat_major);   }      /* _Pragma(STRING) */   /*! @decl void _Pragma(string directive)    *!    *! This macro inserts the corresponding @[#pragma] @[directive]    *! in the source.    *!    *! e.g. @expr{_Pragma("strict_types")@} is the same    *! as @expr{#pragma strict_types@} .    *!    *! @seealso    *! @[#pragma]    */   static void insert_pragma(struct cpp *this, -  struct define *UNUSED(def), +  struct define_struct *UNUSED(def),    struct pike_string *arg,    struct string_builder *tmp)   {    int i;    int in_string = 0;       /* Make some reasonable amount of space. */    string_build_mkspace(tmp, arg->len + 20, arg->size_shift);       string_builder_strcat(tmp, "\n#pragma ");
pike.git/src/cpp.cmod:3062:       string_builder_sprintf(tmp, "\n#line %ld ", (long)this->current_line);    PUSH_STRING_SHIFT(this->current_file->str,    this->current_file->len,    this->current_file->size_shift,    tmp);    string_builder_putchar(tmp, '\n');   }      static void insert_callback_define(struct cpp *this, -  struct define *def, +  struct define_struct *def,    struct pike_string *arg,    struct string_builder *tmp)   {    ref_push_string( def->link.s );    ref_push_string( arg );    if (safe_apply_handler( "evaluate_define",    this->handler, this->compat_handler, 2, 0 ) &&    TYPEOF(sp[-1]) == T_STRING ) {    string_builder_shared_strcat(tmp, sp[-1].u.string);    if( !this->prefix ){
pike.git/src/cpp.cmod:3087:    string_builder_sprintf(tmp, "\n#line %ld ", (long)this->current_line);    insert_current_file_as_string( this,def,arg,tmp);    string_builder_putchar(tmp, '\n');    }    }    pop_stack();    }   }      static void insert_callback_define_no_args(struct cpp *this, -  struct define *def, +  struct define_struct *def,    struct pike_string *UNUSED(arg),    struct string_builder *tmp)   {    struct svalue *save_sp = Pike_sp;    ref_push_string( def->link.s );    if (safe_apply_handler( "evaluate_define",    this->handler, this->compat_handler, 1, 0 ) &&    TYPEOF(sp[-1]) == T_STRING )    string_builder_shared_strcat(tmp, sp[-1].u.string);    if (Pike_sp > save_sp) pop_n_elems(Pike_sp-save_sp);
pike.git/src/cpp.cmod:3470:       /* These are Pike extensions. */    do_magic_define(&this,"__DIR__",insert_current_dir_as_string);    do_magic_define(&this,"__VERSION__",insert_current_version);    do_magic_define(&this,"__MAJOR__",insert_current_major);    do_magic_define(&this,"__MINOR__",insert_current_minor);       {   #if 0    /* Left in place for documentation reference purposes. */ -  struct define *def = +  struct define_struct *def =    alloc_empty_define(make_shared_string("__deprecated__"), 1);    def->args = 1;    REF_MAKE_CONST_STRING(def->first, "__attribute__(\"deprecated\", ");    def->parts[0].argument = 0;    REF_MAKE_CONST_STRING(def->parts[0].postfix, ")");    mapping_string_insert(this.defines, def->link.s, Pike_sp-1);    pop_stack();   #endif /* 0 */       simple_add_define(&this, "__PIKE__", " 1 ");
pike.git/src/cpp.cmod:3520:    }       if (predefs) {    struct keypair *k;    int e;    NEW_MAPPING_LOOP (predefs->data) {    if (TYPEOF(k->val) == T_STRING)    add_define (&this, k->ind.u.string, k->val.u.string);    else if(TYPEOF(k->val) == T_FUNCTION || TYPEOF(k->val) == T_OBJECT)    { -  struct define *def; +  struct define_struct *def;    if( index_shared_string( k->ind.u.string, k->ind.u.string->len-1) == ')' )    {    struct pike_string *s = string_slice( k->ind.u.string, 0, k->ind.u.string->len-2);    def = alloc_empty_define( s, 0 );    def->magic = insert_callback_define;    def->varargs=1;    def->args=1;    }    else    {
pike.git/src/cpp.cmod:3616:   }      /*! @endmodule    */      void init_cpp()   {    struct svalue s;       start_new_program(); -  ADD_STORAGE(struct define); +  ADD_STORAGE(struct define_struct);    set_init_callback(init_define_struct);    set_exit_callback(exit_define_struct);    define_program = end_program();       defined_macro=alloc_empty_define(make_shared_string("defined"),0);    defined_macro->magic=check_defined;    defined_macro->args=1;    defined_macro_sval = Pike_sp[-1];    Pike_sp--;