pike.git / src / pike_types.c

version» Context lines:

pike.git/src/pike_types.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include "global.h" - RCSID("$Id: pike_types.c,v 1.8 1996/11/14 01:36:30 hubbe Exp $"); + RCSID("$Id: pike_types.c,v 1.9 1996/11/18 20:56:25 hubbe Exp $");   #include <ctype.h>   #include "svalue.h"   #include "pike_types.h"   #include "stralloc.h"   #include "stuff.h"   #include "array.h"   #include "program.h"   #include "constants.h"   #include "object.h"   #include "multiset.h"   #include "mapping.h"   #include "macros.h"   #include "error.h"      static void internal_parse_type(char **s); -  + static int type_length(char *t);      /*    * basic types are represented by just their value in a string    * basic type are string, int, float, object and program    * arrays are coded like by the value T_ARRAY followed by the    * data type, if the type is not known it is T_MIXED, ie:    * T_ARRAY <data type>    * mappings are followed by two arguments, the first is the type    * for the indices, and the second is the type of the data, ie:    * T_MAPPING <indice type> <data type>
pike.git/src/pike_types.c:45:   struct pike_string *function_type_string;   struct pike_string *object_type_string;   struct pike_string *program_type_string;   struct pike_string *array_type_string;   struct pike_string *multiset_type_string;   struct pike_string *mapping_type_string;   struct pike_string *mixed_type_string;   struct pike_string *void_type_string;   struct pike_string *any_type_string;    + #ifdef DEBUG + static void CHECK_TYPE(struct pike_string *s) + { +  if(debug_findstring(s) != s) +  fatal("Type string not shared.\n"); +  +  if(type_length(s->str) != s->len) +  fatal("Length of type is wrong.\n"); + } + #else + #define CHECK_TYPE(X) + #endif +    void init_types()   {    string_type_string=parse_type("string");    int_type_string=parse_type("int");    object_type_string=parse_type("object");    program_type_string=parse_type("program");    float_type_string=parse_type("float");    mixed_type_string=parse_type("mixed");    array_type_string=parse_type("array");    multiset_type_string=parse_type("multiset");
pike.git/src/pike_types.c:181:   void push_unfinished_type(char *s)   {    int e;    e=type_length(s);    for(e--;e>=0;e--) push_type(s[e]);   }      void push_finished_type(struct pike_string *type)   {    int e; +  CHECK_TYPE(type);    for(e=type->len-1;e>=0;e--) push_type(type->str[e]);   }      struct pike_string *pop_unfinished_type()   {    int len,e;    struct pike_string *s;    len=type_stackp - pop_stack_mark();    s=begin_shared_string(len);    for(e=0;e<len;e++) s->str[e] = *--type_stackp; -  return end_shared_string(s); +  s=end_shared_string(s); +  CHECK_TYPE(s); +  return s;   }      struct pike_string *pop_type()   {    int len,e;    struct pike_string *s;    len=type_stackp - type_stack;    s=begin_shared_string(len);    for(e=0;e<len;e++) s->str[e] = *--type_stackp;    s=end_shared_string(s);    reset_type_stack(); -  +  CHECK_TYPE(s);    return s;   }            static void internal_parse_typeA(char **_s)   {    unsigned char buf[80];    unsigned int len;    unsigned char **s = (unsigned char **)_s;
pike.git/src/pike_types.c:851:    push_type(T_MIXED);    return 1;    }    }    return 0;   }         int match_types(struct pike_string *a,struct pike_string *b)   { +  CHECK_TYPE(a); +  CHECK_TYPE(b);    return 0!=low_match_types(a->str, b->str,0);   }            /* FIXME, add the index */   static struct pike_string *low_index_type(char *t)   {    switch(EXTRACT_UCHAR(t++))    {
pike.git/src/pike_types.c:940:    return 1;       default:    return 0;    }   }      int check_indexing(struct pike_string *type,    struct pike_string *index_type)   { +  CHECK_TYPE(type); +  CHECK_TYPE(index_type); +     return low_check_indexing(type->str, index_type->str);   }      /* Count the number of arguments for a funciton type.    * return -1-n if the function can take number of arguments    * >= n (varargs)    */   int count_arguments(struct pike_string *s)   {    int num;    char *q;    -  +  CHECK_TYPE(s); +     q=s->str;    if(EXTRACT_UCHAR(q) != T_FUNCTION) return MAX_LOCAL;    q++;    num=0;    while(EXTRACT_UCHAR(q)!=T_MANY)    {    num++;    q+=type_length(q);    }    q++;    if(EXTRACT_UCHAR(q)!=T_VOID) return ~num;    return num;   }      struct pike_string *check_call(struct pike_string *args,    struct pike_string *type)   { -  +  CHECK_TYPE(args); +  CHECK_TYPE(type);    reset_type_stack();    if(low_get_return_type(type->str,args->str))    {    return pop_type();    }else{    return 0;    }   }      void check_array_type(struct array *a)