Main Page | Class List | Directories | File List | Class Members | File Members

pike_types.h

Go to the documentation of this file.
00001 /*
00002 || This file is part of Pike. For copyright information see COPYRIGHT.
00003 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
00004 || for more information.
00005 || $Id: pike_types.h,v 1.94 2005/04/08 16:57:11 grubba Exp $
00006 */
00007 
00008 #ifndef PIKE_TYPES_H
00009 #define PIKE_TYPES_H
00010 
00011 #include "svalue.h"
00012 
00013 #define PIKE_TYPE_STACK_SIZE 100000
00014 
00015 #ifdef PIKE_DEBUG
00016 void TYPE_STACK_DEBUG(const char *fun);
00017 #else /* !PIKE_DEBUG */
00018 #define TYPE_STACK_DEBUG(X)
00019 #endif /* PIKE_DEBUG */
00020 
00021 /*
00022  * The new type type.
00023  */
00024 struct pike_type
00025 {
00026   INT32 refs;
00027   unsigned INT32 hash;
00028   struct pike_type *next;
00029   unsigned INT16 flags;
00030   unsigned INT16 type;
00031   struct pike_type *car;
00032   struct pike_type *cdr;
00033 };
00034 
00035 extern struct pike_type **pike_type_hash;
00036 extern size_t pike_type_hash_size;
00037 
00038 #define CAR_TO_INT(TYPE) ((char *) (TYPE)->car - (char *) 0)
00039 #define CDR_TO_INT(TYPE) ((char *) (TYPE)->cdr - (char *) 0)
00040 
00041 #include "block_alloc_h.h"
00042 BLOCK_ALLOC(pike_type, n/a);
00043 
00044 /* pike_type flags: */
00045 #define PT_FLAG_MARKER  1       /* Type contains markers. */
00046 
00047 void debug_free_type(struct pike_type *t);
00048 #ifdef DEBUG_MALLOC
00049 #define copy_pike_type(D, S) add_ref((struct pike_type *)debug_malloc_pass(D = (S)))
00050 #else /* !DEBUG_MALLOC */
00051 #define copy_pike_type(D, S)    add_ref(D = (S))
00052 #endif /* DEBUG_MALLOC */
00053 #define CONSTTYPE(X) make_pike_type(X)
00054 
00055 extern struct pike_type *type_stack[PIKE_TYPE_STACK_SIZE];
00056 extern struct pike_type **pike_type_mark_stack[PIKE_TYPE_STACK_SIZE/4];
00057 
00058 #ifdef DEBUG_MALLOC
00059 #define free_type(T)    debug_free_type((struct pike_type *)debug_malloc_pass(T))
00060 #define check_type_string(T) debug_check_type_string((struct pike_type *)debug_malloc_pass(T))
00061 #else /* !DEBUG_MALLOC */
00062 #define free_type debug_free_type
00063 #ifdef PIKE_DEBUG
00064 #define check_type_string debug_check_type_string
00065 #endif /* PIKE_DEBUG */
00066 #endif /* DEBUG_MALLOC */
00067 
00068 
00069 extern int max_correct_args;
00070 PMOD_EXPORT extern struct pike_type *string_type_string;
00071 PMOD_EXPORT extern struct pike_type *int_type_string;
00072 PMOD_EXPORT extern struct pike_type *float_type_string;
00073 PMOD_EXPORT extern struct pike_type *object_type_string;
00074 PMOD_EXPORT extern struct pike_type *function_type_string;
00075 PMOD_EXPORT extern struct pike_type *program_type_string;
00076 PMOD_EXPORT extern struct pike_type *array_type_string;
00077 PMOD_EXPORT extern struct pike_type *multiset_type_string;
00078 PMOD_EXPORT extern struct pike_type *mapping_type_string;
00079 PMOD_EXPORT extern struct pike_type *type_type_string;
00080 PMOD_EXPORT extern struct pike_type *mixed_type_string;
00081 PMOD_EXPORT extern struct pike_type *void_type_string;
00082 PMOD_EXPORT extern struct pike_type *zero_type_string;
00083 PMOD_EXPORT extern struct pike_type *any_type_string;
00084 PMOD_EXPORT extern struct pike_type *weak_type_string;
00085 
00086 #define CONSTTYPE(X) make_pike_type(X)
00087 #ifdef DEBUG_MALLOC
00088 struct pike_type_location
00089 {
00090   struct pike_type *t;
00091   struct pike_type_location *next;
00092 };
00093 
00094 extern struct pike_type_location *all_pike_type_locations;
00095 
00096 #define MAKE_CONSTANT_TYPE(T, X) do {           \
00097     static struct pike_type_location type_;     \
00098     if (!type_.t) {                             \
00099       type_.t = CONSTTYPE(X);                   \
00100       type_.next = all_pike_type_locations;     \
00101       all_pike_type_locations = &type_;         \
00102     }                                           \
00103     copy_pike_type((T), type_.t);               \
00104   } while(0)
00105 #else /* !DEBUG_MALLOC */
00106 #define MAKE_CONSTANT_TYPE(T, X) do {   \
00107     static struct pike_type *type_;     \
00108     if (!type_) {                       \
00109       type_ = CONSTTYPE(X);             \
00110     }                                   \
00111     copy_pike_type((T), type_);         \
00112   } while(0)
00113 #endif /* DEBUG_MALLOC */
00114 
00115 #ifdef PIKE_DEBUG
00116 #define init_type_stack() type_stack_mark()
00117 #define exit_type_stack() do {\
00118     ptrdiff_t q_q_q_q = pop_stack_mark(); \
00119     if(q_q_q_q) Pike_fatal("Type stack out of wack! %ld\n", \
00120                       PTRDIFF_T_TO_LONG(q_q_q_q)); \
00121   } while(0)
00122 #else
00123 #define init_type_stack type_stack_mark
00124 #define exit_type_stack pop_stack_mark
00125 #endif
00126 
00127 void debug_push_type(unsigned int type);
00128 void debug_push_reverse_type(unsigned int type);
00129 #ifdef DEBUG_MALLOC
00130 #define push_type(T) do { debug_push_type(T); debug_malloc_pass(debug_peek_type_stack()); } while(0)
00131 #define push_reverse_type(T) do { debug_push_reverse_type(T); debug_malloc_pass(debug_peek_type_stack()); } while(0)
00132 #else /* !DEBUG_MALLOC */
00133 #define push_type debug_push_type
00134 #define push_reverse_type debug_push_reverse_type
00135 #endif /* DEBUG_MALLOC */
00136 
00137 #define type_stack_mark() do {                          \
00138   if(Pike_compiler->pike_type_mark_stackp >= pike_type_mark_stack + NELEM(pike_type_mark_stack))        \
00139     Pike_fatal("Type mark stack overflow.\n");          \
00140   else {                                                \
00141     *Pike_compiler->pike_type_mark_stackp=Pike_compiler->type_stackp;                           \
00142     Pike_compiler->pike_type_mark_stackp++;                                     \
00143   }                                                     \
00144   TYPE_STACK_DEBUG("type_stack_mark");                  \
00145 } while(0)
00146 
00147 #define reset_type_stack() do {                 \
00148    type_stack_pop_to_mark();                    \
00149   type_stack_mark();                            \
00150 } while(0)
00151 
00152 /* Prototypes begin here */
00153 void debug_check_type_string(struct pike_type *s);
00154 void init_types(void);
00155 ptrdiff_t pop_stack_mark(void);
00156 void debug_pop_type_stack(unsigned int expected);
00157 void type_stack_pop_to_mark(void);
00158 void type_stack_reverse(void);
00159 struct pike_type *debug_peek_type_stack(void);
00160 void debug_push_int_type(INT_TYPE min, INT_TYPE max);
00161 void debug_push_object_type(int flag, INT32 id);
00162 void debug_push_object_type_backwards(int flag, INT32 id);
00163 void debug_push_type_name(struct pike_string *name);
00164 INT32 extract_type_int(char *p);
00165 void debug_push_unfinished_type(char *s);
00166 void debug_push_assign_type(int marker);
00167 void debug_push_finished_type(struct pike_type *type);
00168 void debug_push_finished_type_backwards(struct pike_type *type);
00169 struct pike_type *debug_pop_unfinished_type(void);
00170 struct pike_type *debug_pop_type(void);
00171 struct pike_type *debug_compiler_pop_type(void);
00172 struct pike_type *parse_type(const char *s);
00173 void stupid_describe_type(char *a, ptrdiff_t len);
00174 void simple_describe_type(struct pike_type *s);
00175 void my_describe_type(struct pike_type *type);
00176 struct pike_string *describe_type(struct pike_type *type);
00177 TYPE_T compile_type_to_runtime_type(struct pike_type *s);
00178 struct pike_type *or_pike_types(struct pike_type *a,
00179                                 struct pike_type *b,
00180                                 int zero_implied);
00181 struct pike_type *and_pike_types(struct pike_type *a,
00182                                  struct pike_type *b);
00183 int strict_check_call(struct pike_type *fun_type, struct pike_type *arg_type);
00184 int check_soft_cast(struct pike_type *to, struct pike_type *from);
00185 int match_types(struct pike_type *a,struct pike_type *b);
00186 int pike_types_le(struct pike_type *a, struct pike_type *b);
00187 struct pike_type *index_type(struct pike_type *type,
00188                              struct pike_type *type_of_index,
00189                              node *n);
00190 struct pike_type *range_type(struct pike_type *type,
00191                              struct pike_type *index1_type,
00192                              struct pike_type *index2_type);
00193 struct pike_type *array_value_type(struct pike_type *array_type);
00194 struct pike_type *key_type(struct pike_type *type, node *n);
00195 int check_indexing(struct pike_type *type,
00196                    struct pike_type *type_of_index,
00197                    node *n);
00198 int count_arguments(struct pike_type *s);
00199 int minimum_arguments(struct pike_type *s);
00200 struct pike_type *check_call(struct pike_type *args,
00201                              struct pike_type *type,
00202                              int strict);
00203 struct pike_type *zzap_function_return(struct pike_type *t, INT32 id);
00204 struct pike_type *get_type_of_svalue(struct svalue *s);
00205 struct pike_type *object_type_to_program_type(struct pike_type *obj_t);
00206 char *get_name_of_type(TYPE_T t);
00207 void cleanup_pike_types(void);
00208 void cleanup_pike_type_table(void);
00209 int type_may_overload(struct pike_type *type, int lfun);
00210 void yyexplain_nonmatching_types(struct pike_type *type_a,
00211                                  struct pike_type *type_b,
00212                                  int flags);
00213 struct pike_type *debug_make_pike_type(const char *t);
00214 struct pike_string *type_to_string(struct pike_type *t);
00215 int pike_type_allow_premature_toss(struct pike_type *type);
00216 /* Prototypes end here */
00217 
00218 #if 0 /* FIXME: Not supported under USE_PIKE_TYPE yet. */
00219 /* "Dynamic types" - use with ADD_FUNCTION_DTYPE */
00220 #define dtStore(TYPE) {int e; for (e=0; e<CONSTANT_STRLEN(TYPE); e++) unsafe_push_type((TYPE)[e]);}
00221 #define dtArr(VAL) {unsafe_push_type(PIKE_T_ARRAY); {VAL}}
00222 #define dtArray dtArr(dtMix)
00223 #define dtMap(IND,VAL) {unsafe_push_type(PIKE_T_MAPPING); {VAL} {IND}}
00224 #define dtMapping dtMap(dtMix,dtMix)
00225 #define dtSet(IND) {unsafe_push_type(PIKE_T_MULTISET); {IND}}
00226 #define dtMultiset dtSet(dtMix)
00227 #define dtObjImpl(PROGRAM) {push_object_type_backwards(0, (PROGRAM)->id);}
00228 #define dtObjIs(PROGRAM) {push_object_type_backwards(1, (PROGRAM)->id);}
00229 #define dtObj dtStore(tObj)
00230 #define dtFuncV(ARGS,REST,RET) MagicdtFuncV(RET,REST,ARGS)
00231 #define dtFunc(ARGS,RET) MagicdtFunc(RET,ARGS)
00232 #define MagicdtFuncV(RET,REST,ARGS) {unsafe_push_type(PIKE_T_FUNCTION); {ARGS} unsafe_push_type(T_MANY); {REST} {RET}}
00233 #define MagicdtFunc(RET,ARGS) dtFuncV(ARGS {}, dtVoid, RET)
00234 #define dtFunction dtFuncV({},dtAny,dtAny)
00235 #define dtNone {}
00236 #define dtPrg {unsafe_push_type(PIKE_T_PROGRAM);}
00237 #define dtProgram {unsafe_push_type(PIKE_T_PROGRAM);}
00238 #define dtStr {unsafe_push_type(PIKE_T_STRING);}
00239 #define dtString {unsafe_push_type(PIKE_T_STRING);}
00240 #define dtType {unsafe_push_type(PIKE_T_TYPE);}
00241 #define dtFlt {unsafe_push_type(PIKE_T_FLOAT);}
00242 #define dtFloat {unsafe_push_type(PIKE_T_FLOAT);}
00243 #define dtIntRange(LOW,HIGH) {unsafe_push_type(PIKE_T_INT); push_type_int_backwards(LOW); push_type_int_backwards(HIGH);}
00244 #define dtInt dtStore(tInt)
00245 #define dtZero {unsafe_push_type(PIKE_T_ZERO);}
00246 #define dtVoid {unsafe_push_type(T_VOID);}
00247 #define dtVar(X) {unsafe_push_type(X);}
00248 #define dtSetvar(X,TYPE) {unsafe_push_type(T_ASSIGN); {TYPE}}
00249 #define dtNot(TYPE) {unsafe_push_type(T_NOT); {TYPE}}
00250 #define dtAnd(A,B) {unsafe_push_type(T_AND); {A} {B}}
00251 #define dtOr(A,B) {unsafe_push_type(T_OR); {A} {B}}
00252 #define dtOr3(A,B,C) dtOr(A,dtOr(B,C))
00253 #define dtOr4(A,B,C,D) dtOr(A,dtOr3(B,C,D))
00254 #define dtOr5(A,B,C,D,E) dtOr(A,dtOr4(B,C,D,E))
00255 #define dtOr6(A,B,C,D,E,F) dtOr(A,dtOr5(B,C,D,E,F))
00256 #define dtMix {unsafe_push_type(PIKE_T_MIXED);}
00257 #define dtMixed {unsafe_push_type(PIKE_T_MIXED);}
00258 #define dtComplex dtStore(tComplex)
00259 #define dtStringIndicable dtStore(tStringIndicable)
00260 #define dtRef dtStore(tRef)
00261 #define dtIfnot(A,B) dtAnd(dtNot(A),B)
00262 #define dtAny dtStore(tAny)
00263 #define DTYPE_START do {                                                \
00264   unsafe_type_stack_mark();                                             \
00265   unsafe_type_stack_mark();                                             \
00266 } while (0)
00267 #define DTYPE_END(TYPESTR) do {                                         \
00268   if(Pike_compiler->type_stackp >= type_stack + sizeof(type_stack))     \
00269     Pike_fatal("Type stack overflow.\n");                               \
00270   type_stack_reverse();                                                 \
00271   (TYPESTR)=pop_unfinished_type();                                      \
00272 } while (0)
00273 #endif /* 0 */
00274 
00275 #ifdef DEBUG_MALLOC
00276 void describe_all_types(void);
00277 #define pop_type() ((struct pike_type *)debug_malloc_pass(debug_pop_type()))
00278 #define compiler_pop_type() ((struct pike_type *)debug_malloc_pass(debug_compiler_pop_type()))
00279 #define pop_unfinished_type() \
00280  ((struct pike_type *)debug_malloc_pass(debug_pop_unfinished_type()))
00281 #define make_pike_type(X) \
00282  ((struct pike_type *)debug_malloc_pass(debug_make_pike_type(X)))
00283 #define pop_type_stack(E) do { debug_malloc_pass(debug_peek_type_stack()); debug_pop_type_stack(E); } while(0)
00284 #define push_int_type(MIN,MAX) do { debug_push_int_type(MIN,MAX);debug_malloc_pass(debug_peek_type_stack()); } while(0)
00285 #define push_object_type(FLAG,ID) do { debug_push_object_type(FLAG,ID);debug_malloc_pass(debug_peek_type_stack()); } while(0)
00286 #define push_object_type_backwards(FLAG,ID) do { debug_push_object_type_backwards(FLAG,ID);debug_malloc_pass(debug_peek_type_stack()); } while(0)
00287 #define push_scope_type(LEVEL) do { debug_push_scope_type(LEVEL);debug_malloc_pass(debug_peek_type_stack()); } while(0)
00288 #define push_type_name(NAME) do { debug_push_type_name((struct pike_string *)debug_malloc_pass(NAME));debug_malloc_pass(debug_peek_type_stack()); } while(0)
00289 #define push_unfinished_type(S) ERROR
00290 #define push_assign_type(MARKER) do { debug_push_assign_type(MARKER);debug_malloc_pass(debug_peek_type_stack()); } while(0)
00291 #define push_finished_type(T) do { debug_push_finished_type((struct pike_type *)debug_malloc_pass(T));debug_malloc_pass(debug_peek_type_stack()); } while(0)
00292 #define push_finished_type_with_markers(T,M) do { debug_push_finished_type_with_markers((struct pike_type *)debug_malloc_pass(T),M);debug_malloc_pass(debug_peek_type_stack()); } while(0)
00293 #define push_finished_type_backwards(T) ERROR
00294 #else
00295 #define make_pike_type debug_make_pike_type
00296 #define pop_type debug_pop_type
00297 #define compiler_pop_type debug_compiler_pop_type
00298 #define pop_unfinished_type debug_pop_unfinished_type
00299 #define pop_type_stack debug_pop_type_stack
00300 #define push_int_type debug_push_int_type
00301 #define push_object_type debug_push_object_type
00302 #define push_object_type_backwards debug_push_object_type_backwards
00303 #define push_scope_type debug_push_scope_type
00304 #define push_type_name debug_push_type_name
00305 #define push_unfinished_type debug_push_unfinished_type
00306 #define push_assign_type debug_push_assign_type
00307 #define push_finished_type debug_push_finished_type
00308 #define push_finished_type_with_markers debug_push_finished_type_with_markers
00309 #define push_finished_type_backwards debug_push_finished_type_backwards
00310 #endif
00311 
00312 #ifndef PIKE_DEBUG
00313 #define check_type_string(X)
00314 #endif
00315 
00316 #endif

Generated on Fri Jul 22 23:44:26 2005 for Pike by  doxygen 1.3.9.1