cb22561995-10-11Fredrik Hübinette (Hubbe) /*\
06983f1996-09-22Fredrik Hübinette (Hubbe) ||| This file a part of Pike, and is copyright by Fredrik Hubinette ||| Pike is distributed as GPL (General Public License)
cb22561995-10-11Fredrik Hübinette (Hubbe) ||| See the files COPYING and DISCLAIMER for more information. \*/
8670791999-02-28Henrik Grubbström (Grubba) /**/
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "global.h"
3611422001-02-20Henrik Grubbström (Grubba) RCSID("$Id: pike_types.c,v 1.148 2001/02/20 15:59:50 grubba Exp $");
5267b71995-08-09Fredrik Hübinette (Hubbe) #include <ctype.h> #include "svalue.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "pike_types.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "stralloc.h" #include "stuff.h" #include "array.h" #include "program.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "constants.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "object.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "multiset.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "mapping.h"
bb55f81997-03-16Fredrik Hübinette (Hubbe) #include "pike_macros.h"
b2d3e42000-12-01Fredrik Hübinette (Hubbe) #include "pike_error.h"
b8cda21997-01-21Fredrik Hübinette (Hubbe) #include "las.h" #include "language.h"
93dd411999-11-23Henrik Grubbström (Grubba) #include "lex.h"
9aa6fa1997-05-19Fredrik Hübinette (Hubbe) #include "pike_memory.h"
6c39401999-10-28Fredrik Hübinette (Hubbe) #include "bignum.h"
fbafd01999-12-12Henrik Grubbström (Grubba) #include "main.h"
f76b4c2000-05-11Henrik Grubbström (Grubba) #include "opcodes.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
5528582000-12-01Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG #define PIKE_TYPE_DEBUG #endif /* PIKE_DEBUG */
02f0631999-11-24Fredrik Hübinette (Hubbe) 
1d53281996-11-25Fredrik Hübinette (Hubbe) int max_correct_args;
bce86c1996-02-25Fredrik Hübinette (Hubbe) static void internal_parse_type(char **s);
89da112000-08-15Henrik Grubbström (Grubba) static ptrdiff_t type_length(char *t);
52169d1999-12-21Henrik Grubbström (Grubba) static int low_pike_types_le(char *a, char *b, int array_cnt, unsigned int flags);
2573d11999-12-22Henrik Grubbström (Grubba) static int low_check_indexing(char *type, char *index_type, node *n);
bce86c1996-02-25Fredrik Hübinette (Hubbe) 
9f68471997-03-08Fredrik Hübinette (Hubbe) #define TWOT(X,Y) (((X) << 8)+(Y)) #define EXTRACT_TWOT(X,Y) TWOT(EXTRACT_UCHAR(X), EXTRACT_UCHAR(Y))
5267b71995-08-09Fredrik Hübinette (Hubbe) /* * basic types are represented by just their value in a string
f37dad1999-12-11Henrik Grubbström (Grubba)  * basic type are string, type, int, float, object and program
5267b71995-08-09Fredrik Hübinette (Hubbe)  * 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>
06983f1996-09-22Fredrik Hübinette (Hubbe)  * multiset works similarly to arrays.
5267b71995-08-09Fredrik Hübinette (Hubbe)  * functions are _very_ special: * they are coded like this: * T_FUNCTION <arg type> <arg type> ... <arg type> T_MANY <arg type> <return type> * note that the type after T_MANY can be T_VOID * T_MIXED matches anything except T_VOID
04966d2000-10-03Fredrik Hübinette (Hubbe)  * PIKE_T_UNKNOWN only matches T_MIXED and PIKE_T_UNKNOWN
6bc9281998-04-10Fredrik Hübinette (Hubbe)  * objects are coded thus: * T_OBJECT <0/1> <program_id> * ^
3d5c7d1999-12-12Henrik Grubbström (Grubba)  * 0 means 'implements'
6134591999-12-15Henrik Grubbström (Grubba)  * 1 means 'is' (aka 'clone of')
f37dad1999-12-11Henrik Grubbström (Grubba)  * Integers are encoded as: * T_INT <min> <max>
93dd411999-11-23Henrik Grubbström (Grubba)  * Everything except T_VOID matches T_ZERO.
5267b71995-08-09Fredrik Hübinette (Hubbe)  */
d68a072001-02-20Henrik Grubbström (Grubba) PMOD_EXPORT struct pike_type *string_type_string; PMOD_EXPORT struct pike_type *int_type_string; PMOD_EXPORT struct pike_type *float_type_string; PMOD_EXPORT struct pike_type *function_type_string; PMOD_EXPORT struct pike_type *object_type_string; PMOD_EXPORT struct pike_type *program_type_string; PMOD_EXPORT struct pike_type *array_type_string; PMOD_EXPORT struct pike_type *multiset_type_string; PMOD_EXPORT struct pike_type *mapping_type_string; PMOD_EXPORT struct pike_type *type_type_string; PMOD_EXPORT struct pike_type *mixed_type_string; PMOD_EXPORT struct pike_type *void_type_string; PMOD_EXPORT struct pike_type *zero_type_string; PMOD_EXPORT struct pike_type *any_type_string; PMOD_EXPORT struct pike_type *weak_type_string; /* array|mapping|multiset|function */ static struct pike_type *a_markers[10],*b_markers[10];
9e52381998-03-01Fredrik Hübinette (Hubbe) 
20ea771999-12-15Fredrik Hübinette (Hubbe) static struct program *implements_a; static struct program *implements_b;
22ca071998-04-08Fredrik Hübinette (Hubbe) static void clear_markers(void)
9e52381998-03-01Fredrik Hübinette (Hubbe) { unsigned int e;
a946c71998-03-02Fredrik Hübinette (Hubbe)  for(e=0;e<NELEM(a_markers);e++) { if(a_markers[e]) {
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(a_markers[e]);
a946c71998-03-02Fredrik Hübinette (Hubbe)  a_markers[e]=0; } if(b_markers[e]) {
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(b_markers[e]);
a946c71998-03-02Fredrik Hübinette (Hubbe)  b_markers[e]=0; } }
9e52381998-03-01Fredrik Hübinette (Hubbe) }
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
d68a072001-02-20Henrik Grubbström (Grubba) void check_type_string(struct pike_type *s)
b9e4ba1996-11-18Fredrik Hübinette (Hubbe) { if(debug_findstring(s) != s) fatal("Type string not shared.\n"); if(type_length(s->str) != s->len)
9e52381998-03-01Fredrik Hübinette (Hubbe)  { stupid_describe_type(s->str,s->len);
6f95902000-08-17Henrik Grubbström (Grubba)  fatal("Length of type is wrong. (should be %ld, is %ld)\n", PTRDIFF_T_TO_LONG(type_length(s->str)), PTRDIFF_T_TO_LONG(s->len));
9e52381998-03-01Fredrik Hübinette (Hubbe)  }
b9e4ba1996-11-18Fredrik Hübinette (Hubbe) } #endif
be478c1997-08-30Henrik Grubbström (Grubba) void init_types(void)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
8bd2161999-02-11Fredrik Hübinette (Hubbe)  string_type_string = CONSTTYPE(tString); int_type_string = CONSTTYPE(tInt); object_type_string = CONSTTYPE(tObj);
ed52621999-02-11Fredrik Hübinette (Hubbe)  program_type_string = CONSTTYPE(tPrg);
8bd2161999-02-11Fredrik Hübinette (Hubbe)  float_type_string = CONSTTYPE(tFloat); mixed_type_string=CONSTTYPE(tMix); array_type_string=CONSTTYPE(tArray); multiset_type_string=CONSTTYPE(tMultiset); mapping_type_string=CONSTTYPE(tMapping); function_type_string=CONSTTYPE(tFunction);
bb8d1d1999-12-15Henrik Grubbström (Grubba)  type_type_string=CONSTTYPE(tType);
8bd2161999-02-11Fredrik Hübinette (Hubbe)  void_type_string=CONSTTYPE(tVoid);
93dd411999-11-23Henrik Grubbström (Grubba)  zero_type_string=CONSTTYPE(tZero);
8bd2161999-02-11Fredrik Hübinette (Hubbe)  any_type_string=CONSTTYPE(tOr(tVoid,tMix));
c2a4961999-12-15Henrik Grubbström (Grubba)  weak_type_string=CONSTTYPE(tOr4(tArray,tMultiset,tMapping,
17cc3a1999-12-23Henrik Grubbström (Grubba)  tFuncV(tNone,tZero,tOr(tMix,tVoid))));
5267b71995-08-09Fredrik Hübinette (Hubbe) }
e0755c2000-08-15Henrik Grubbström (Grubba) static ptrdiff_t type_length(char *t)
5267b71995-08-09Fredrik Hübinette (Hubbe) { char *q=t;
1347171998-04-23Fredrik Hübinette (Hubbe) one_more_type:
5267b71995-08-09Fredrik Hübinette (Hubbe)  switch(EXTRACT_UCHAR(t++)) {
9e52381998-03-01Fredrik Hübinette (Hubbe)  default:
a4a1722000-12-05Per Hedbor  fatal("Error in type string %d.\n",EXTRACT_UCHAR(t-1));
9e52381998-03-01Fredrik Hübinette (Hubbe)  /*NOTREACHED*/ break;
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_SCOPE:
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_ASSIGN: t++;
1347171998-04-23Fredrik Hübinette (Hubbe)  goto one_more_type;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_FUNCTION: while(EXTRACT_UCHAR(t)!=T_MANY) t+=type_length(t); /* skip arguments */ t++;
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TUPLE:
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_MAPPING: case T_OR: case T_AND: t+=type_length(t); case T_ARRAY: case T_MULTISET: case T_NOT:
1347171998-04-23Fredrik Hübinette (Hubbe)  goto one_more_type;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case T_FLOAT: case T_STRING:
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TYPE:
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_PROGRAM: case T_MIXED: case T_VOID:
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ZERO:
04966d2000-10-03Fredrik Hübinette (Hubbe)  case PIKE_T_UNKNOWN:
9e52381998-03-01Fredrik Hübinette (Hubbe)  break;
b660c81999-03-01Fredrik Hübinette (Hubbe)  case T_INT: t+=sizeof(INT32)*2; break;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_OBJECT:
6bc9281998-04-10Fredrik Hübinette (Hubbe)  t++;
9e52381998-03-01Fredrik Hübinette (Hubbe)  t+=sizeof(INT32); break;
5267b71995-08-09Fredrik Hübinette (Hubbe)  } return t-q; }
7260711996-06-21Fredrik Hübinette (Hubbe) 
1347171998-04-23Fredrik Hübinette (Hubbe) unsigned char type_stack[PIKE_TYPE_STACK_SIZE]; unsigned char *pike_type_mark_stack[PIKE_TYPE_STACK_SIZE/4];
7260711996-06-21Fredrik Hübinette (Hubbe) 
e0755c2000-08-15Henrik Grubbström (Grubba) ptrdiff_t pop_stack_mark(void)
7260711996-06-21Fredrik Hübinette (Hubbe) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->pike_type_mark_stackp--; if(Pike_compiler->pike_type_mark_stackp<pike_type_mark_stack)
7260711996-06-21Fredrik Hübinette (Hubbe)  fatal("Type mark stack underflow\n");
bad5162000-06-23Fredrik Hübinette (Hubbe)  return Pike_compiler->type_stackp - *Pike_compiler->pike_type_mark_stackp;
7260711996-06-21Fredrik Hübinette (Hubbe) }
be478c1997-08-30Henrik Grubbström (Grubba) void pop_type_stack(void)
7260711996-06-21Fredrik Hübinette (Hubbe) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->type_stackp--; if(Pike_compiler->type_stackp<type_stack)
7260711996-06-21Fredrik Hübinette (Hubbe)  fatal("Type stack underflow\n"); }
be478c1997-08-30Henrik Grubbström (Grubba) void type_stack_pop_to_mark(void)
7260711996-06-21Fredrik Hübinette (Hubbe) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->type_stackp-=pop_stack_mark();
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->type_stackp<type_stack)
36feac1997-03-06Fredrik Hübinette (Hubbe)  fatal("Type stack underflow\n"); #endif
7260711996-06-21Fredrik Hübinette (Hubbe) }
be478c1997-08-30Henrik Grubbström (Grubba) void type_stack_reverse(void)
7260711996-06-21Fredrik Hübinette (Hubbe) {
393a592000-08-16Henrik Grubbström (Grubba)  ptrdiff_t a;
36feac1997-03-06Fredrik Hübinette (Hubbe)  a=pop_stack_mark();
bad5162000-06-23Fredrik Hübinette (Hubbe)  reverse((char *)(Pike_compiler->type_stackp-a),a,1);
7260711996-06-21Fredrik Hübinette (Hubbe) }
3611422001-02-20Henrik Grubbström (Grubba) static void push_type_int(INT32 i)
d2c6081996-11-07Fredrik Hübinette (Hubbe) {
393a592000-08-16Henrik Grubbström (Grubba)  ptrdiff_t e; for(e = 0; e < (ptrdiff_t)sizeof(i); e++) push_type(DO_NOT_WARN((unsigned char)((i>>(e*8)) & 0xff)));
b660c81999-03-01Fredrik Hübinette (Hubbe) }
3611422001-02-20Henrik Grubbström (Grubba) static void push_type_int_backwards(INT32 i)
91aab41999-12-13Martin Stjernholm { int e; for(e=(int)sizeof(i);e-->0;) push_type( (i>>(e*8)) & 0xff ); }
3611422001-02-20Henrik Grubbström (Grubba) void push_int_type(INT32 min, INT32 max) { push_type_int(max); push_type_int(min); push_type(T_INT); } void push_object_type(int flag, INT32 id) { push_type_int(id); push_type(flag); push_type(T_OBJECT); } void push_object_type_backwards(int flag, INT32 id) { unsafe_push_type(T_OBJECT); unsafe_push_type(flag); push_type_int_backwards(id); }
b660c81999-03-01Fredrik Hübinette (Hubbe) INT32 extract_type_int(char *p) { int e; INT32 ret=0; for(e=0;e<(int)sizeof(INT32);e++) ret=(ret<<8) | EXTRACT_UCHAR(p+e); return ret;
d2c6081996-11-07Fredrik Hübinette (Hubbe) }
7260711996-06-21Fredrik Hübinette (Hubbe) void push_unfinished_type(char *s) {
393a592000-08-16Henrik Grubbström (Grubba)  ptrdiff_t e;
7260711996-06-21Fredrik Hübinette (Hubbe)  e=type_length(s); for(e--;e>=0;e--) push_type(s[e]); }
27f6ba1999-11-24Fredrik Hübinette (Hubbe) static void push_unfinished_type_with_markers(char *s,
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type **am)
9e52381998-03-01Fredrik Hübinette (Hubbe) {
89da112000-08-15Henrik Grubbström (Grubba)  int d,e,c; ptrdiff_t len=type_length(s);
2a6d261998-03-25Fredrik Hübinette (Hubbe)  type_stack_mark(); for(e=0;e<len;e++)
9e52381998-03-01Fredrik Hübinette (Hubbe)  {
2a6d261998-03-25Fredrik Hübinette (Hubbe)  switch(c=EXTRACT_UCHAR(s+e))
9e52381998-03-01Fredrik Hübinette (Hubbe)  {
2a6d261998-03-25Fredrik Hübinette (Hubbe) #if 1 case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if(am[c-'0']) { push_finished_type_backwards(am[c-'0']); }else{
02f0631999-11-24Fredrik Hübinette (Hubbe)  push_type(T_ZERO);
2a6d261998-03-25Fredrik Hübinette (Hubbe)  } break; #endif
02f0631999-11-24Fredrik Hübinette (Hubbe)  case T_ASSIGN:
27f6ba1999-11-24Fredrik Hübinette (Hubbe) #if 1 e++; #else
02f0631999-11-24Fredrik Hübinette (Hubbe)  push_type(c); push_type(EXTRACT_UCHAR(s+ ++e));
27f6ba1999-11-24Fredrik Hübinette (Hubbe) #endif
02f0631999-11-24Fredrik Hübinette (Hubbe)  break;
b660c81999-03-01Fredrik Hübinette (Hubbe)  case T_INT: push_type(c); for(d=0;d<(int)sizeof(INT32)*2;d++) push_type(EXTRACT_UCHAR(s+ ++e)); break;
2a6d261998-03-25Fredrik Hübinette (Hubbe)  case T_OBJECT: push_type(c);
b660c81999-03-01Fredrik Hübinette (Hubbe)  for(d=0;d<(int)sizeof(INT32)+1;d++) push_type(EXTRACT_UCHAR(s+ ++e));
2a6d261998-03-25Fredrik Hübinette (Hubbe)  break; default: push_type(c);
9e52381998-03-01Fredrik Hübinette (Hubbe)  } }
2a6d261998-03-25Fredrik Hübinette (Hubbe)  type_stack_reverse();
9e52381998-03-01Fredrik Hübinette (Hubbe) }
d68a072001-02-20Henrik Grubbström (Grubba) void push_finished_type(struct pike_type *type)
7260711996-06-21Fredrik Hübinette (Hubbe) {
e0755c2000-08-15Henrik Grubbström (Grubba)  ptrdiff_t e;
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  check_type_string(type);
7260711996-06-21Fredrik Hübinette (Hubbe)  for(e=type->len-1;e>=0;e--) push_type(type->str[e]); }
d68a072001-02-20Henrik Grubbström (Grubba) void push_finished_type_backwards(struct pike_type *type)
2a6d261998-03-25Fredrik Hübinette (Hubbe) { int e;
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  check_type_string(type);
bad5162000-06-23Fredrik Hübinette (Hubbe)  MEMCPY(Pike_compiler->type_stackp, type->str, type->len); Pike_compiler->type_stackp+=type->len;
2a6d261998-03-25Fredrik Hübinette (Hubbe) }
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *debug_pop_unfinished_type(void)
7260711996-06-21Fredrik Hübinette (Hubbe) {
393a592000-08-16Henrik Grubbström (Grubba)  ptrdiff_t len, e;
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *s;
36feac1997-03-06Fredrik Hübinette (Hubbe)  len=pop_stack_mark();
7260711996-06-21Fredrik Hübinette (Hubbe)  s=begin_shared_string(len);
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->type_stackp-=len; MEMCPY(s->str, Pike_compiler->type_stackp, len);
36feac1997-03-06Fredrik Hübinette (Hubbe)  reverse(s->str, len, 1);
b9e4ba1996-11-18Fredrik Hübinette (Hubbe)  s=end_shared_string(s);
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  check_type_string(s);
b9e4ba1996-11-18Fredrik Hübinette (Hubbe)  return s;
7260711996-06-21Fredrik Hübinette (Hubbe) }
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *debug_pop_type(void)
7260711996-06-21Fredrik Hübinette (Hubbe) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *s;
36feac1997-03-06Fredrik Hübinette (Hubbe)  s=pop_unfinished_type(); type_stack_mark();
7260711996-06-21Fredrik Hübinette (Hubbe)  return s; }
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *debug_compiler_pop_type(void)
4142a61998-05-19Fredrik Hübinette (Hubbe) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->num_parse_error)
4142a61998-05-19Fredrik Hübinette (Hubbe)  { /* This could be fixed to check if the type * is correct and then return it, I just didn't feel * like writing the checking code today. / Hubbe */
fb2f661998-11-05Fredrik Hübinette (Hubbe)  type_stack_pop_to_mark();
4142a61998-05-19Fredrik Hübinette (Hubbe)  type_stack_mark(); reference_shared_string(mixed_type_string); return mixed_type_string; }else{
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *s;
4142a61998-05-19Fredrik Hübinette (Hubbe)  s=pop_unfinished_type(); type_stack_mark(); return s; } }
b432bb1996-10-29Per Hedbor static void internal_parse_typeA(char **_s)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
f044a81996-12-06Fredrik Hübinette (Hubbe)  char buf[80];
5267b71995-08-09Fredrik Hübinette (Hubbe)  unsigned int len;
b432bb1996-10-29Per Hedbor  unsigned char **s = (unsigned char **)_s;
bdb5091996-09-25Fredrik Hübinette (Hubbe)  while(ISSPACE(**s)) ++*s;
5267b71995-08-09Fredrik Hübinette (Hubbe)  len=0;
f044a81996-12-06Fredrik Hübinette (Hubbe)  for(len=0;isidchar(EXTRACT_UCHAR(s[0]+len));len++)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  if(len>=sizeof(buf)) Pike_error("Buffer overflow in parse_type\n");
5267b71995-08-09Fredrik Hübinette (Hubbe)  buf[len] = s[0][len]; } buf[len]=0; *s += len;
1347171998-04-23Fredrik Hübinette (Hubbe)  switch(buf[0])
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
4d7b181999-12-07Fredrik Hübinette (Hubbe)  case 'z':
fc0ad41999-12-11Henrik Grubbström (Grubba)  if(!strcmp(buf,"zero")) { push_type(T_ZERO); break; }
4d7b181999-12-07Fredrik Hübinette (Hubbe)  goto bad_type;
1347171998-04-23Fredrik Hübinette (Hubbe)  case 'i':
b660c81999-03-01Fredrik Hübinette (Hubbe)  if(!strcmp(buf,"int")) { while(ISSPACE(**s)) ++*s; if(**s=='(') { INT32 min,max; ++*s; while(ISSPACE(**s)) ++*s;
01a9572000-02-03Henrik Grubbström (Grubba)  min=STRTOL((char *)*s,(char **)s,0);
b660c81999-03-01Fredrik Hübinette (Hubbe)  while(ISSPACE(**s)) ++*s; if(s[0][0]=='.' && s[0][1]=='.') s[0]+=2; else
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Missing .. in integer type.\n");
b660c81999-03-01Fredrik Hübinette (Hubbe)  while(ISSPACE(**s)) ++*s;
01a9572000-02-03Henrik Grubbström (Grubba)  max=STRTOL((char *)*s,(char **)s,0);
b660c81999-03-01Fredrik Hübinette (Hubbe)  while(ISSPACE(**s)) ++*s;
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  if(**s != ')') Pike_error("Missing ')' in integer range.\n");
b660c81999-03-01Fredrik Hübinette (Hubbe)  ++*s; push_type_int(max); push_type_int(min); }else{ push_type_int(MAX_INT32); push_type_int(MIN_INT32); } push_type(T_INT); break; }
1347171998-04-23Fredrik Hübinette (Hubbe)  goto bad_type; case 'f': if(!strcmp(buf,"function"))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
1347171998-04-23Fredrik Hübinette (Hubbe)  while(ISSPACE(**s)) ++*s; if(**s == '(')
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
1347171998-04-23Fredrik Hübinette (Hubbe)  ++*s; while(ISSPACE(**s)) ++*s; type_stack_mark(); while(1) { if(**s == ':') { push_type(T_MANY); push_type(T_VOID); break; } type_stack_mark(); type_stack_mark(); type_stack_mark(); internal_parse_type(_s); type_stack_reverse(); if(**s==',') { ++*s; while(ISSPACE(**s)) ++*s; } else if(s[0][0]=='.' && s[0][1]=='.' && s[0][2]=='.') { type_stack_reverse(); push_type(T_MANY); type_stack_reverse(); *s+=3; while(ISSPACE(**s)) ++*s;
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  if(**s != ':') Pike_error("Missing ':' after ... in function type.\n");
1347171998-04-23Fredrik Hübinette (Hubbe)  break; } pop_stack_mark(); pop_stack_mark(); } ++*s; type_stack_mark(); internal_parse_type(_s); /* return type */ type_stack_reverse();
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  if(**s != ')') Pike_error("Missing ')' in function type.\n");
1347171998-04-23Fredrik Hübinette (Hubbe)  ++*s; type_stack_reverse(); }else{
3688171999-11-26Fredrik Hübinette (Hubbe)  push_type(T_VOID);
1347171998-04-23Fredrik Hübinette (Hubbe)  push_type(T_MIXED);
3688171999-11-26Fredrik Hübinette (Hubbe)  push_type(T_OR); push_type(T_VOID);
a0b73f2000-01-03Martin Stjernholm  push_type(T_ZERO);
3688171999-11-26Fredrik Hübinette (Hubbe)  push_type(T_OR);
5267b71995-08-09Fredrik Hübinette (Hubbe)  push_type(T_MANY); }
1347171998-04-23Fredrik Hübinette (Hubbe)  push_type(T_FUNCTION); break; } if(!strcmp(buf,"float")) { push_type(T_FLOAT); break; } goto bad_type;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
1347171998-04-23Fredrik Hübinette (Hubbe)  case 'o': if(!strcmp(buf,"object")) { push_type_int(0); push_type(0); push_type(T_OBJECT); break; } goto bad_type; case 'p': if(!strcmp(buf,"program")) { push_type(T_PROGRAM); break; } goto bad_type; case 's': if(!strcmp(buf,"string")) { push_type(T_STRING); break; } goto bad_type; case 'v': if(!strcmp(buf,"void")) { push_type(T_VOID); break; } goto bad_type;
fc0ad41999-12-11Henrik Grubbström (Grubba)  case 't': if (!strcmp(buf,"tuple")) { while(ISSPACE(**s)) ++*s; if(**s == '(') { type_stack_mark(); ++*s; type_stack_mark(); internal_parse_type(_s); type_stack_reverse();
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  if(**s != ',') Pike_error("Expecting ','.\n");
fc0ad41999-12-11Henrik Grubbström (Grubba)  ++*s; type_stack_mark(); internal_parse_type(_s); type_stack_reverse();
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  if(**s != ')') Pike_error("Expecting ')'.\n");
fc0ad41999-12-11Henrik Grubbström (Grubba)  ++*s; type_stack_reverse(); }else{ push_type(T_MIXED); push_type(T_MIXED); } push_type(T_TUPLE); break; } if(!strcmp(buf,"type")) { push_type(T_TYPE); break; } goto bad_type;
1347171998-04-23Fredrik Hübinette (Hubbe)  case 'm': if(!strcmp(buf,"mixed")) { push_type(T_MIXED); break; } if(!strcmp(buf,"mapping")) { while(ISSPACE(**s)) ++*s; if(**s == '(')
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
1347171998-04-23Fredrik Hübinette (Hubbe)  type_stack_mark();
5267b71995-08-09Fredrik Hübinette (Hubbe)  ++*s;
1347171998-04-23Fredrik Hübinette (Hubbe)  type_stack_mark(); internal_parse_type(_s);
5267b71995-08-09Fredrik Hübinette (Hubbe)  type_stack_reverse();
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  if(**s != ':') Pike_error("Expecting ':'.\n");
1347171998-04-23Fredrik Hübinette (Hubbe)  ++*s; type_stack_mark(); internal_parse_type(_s);
5267b71995-08-09Fredrik Hübinette (Hubbe)  type_stack_reverse();
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  if(**s != ')') Pike_error("Expecting ')'.\n");
1347171998-04-23Fredrik Hübinette (Hubbe)  ++*s; type_stack_reverse(); }else{ push_type(T_MIXED); push_type(T_MIXED);
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
1347171998-04-23Fredrik Hübinette (Hubbe)  push_type(T_MAPPING); break;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
1347171998-04-23Fredrik Hübinette (Hubbe)  if(!strcmp(buf,"multiset")) { while(ISSPACE(**s)) ++*s; if(**s == '(') { ++*s; internal_parse_type(_s);
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  if(**s != ')') Pike_error("Expecting ')'.\n");
1347171998-04-23Fredrik Hübinette (Hubbe)  ++*s; }else{ push_type(T_MIXED); } push_type(T_MULTISET); break; } goto bad_type; case 'u':
04966d2000-10-03Fredrik Hübinette (Hubbe)  if(!strcmp(buf,"unknown")) { push_type(PIKE_T_UNKNOWN); break; }
1347171998-04-23Fredrik Hübinette (Hubbe)  goto bad_type; case 'a': if(!strcmp(buf,"array")) { while(ISSPACE(**s)) ++*s; if(**s == '(') { ++*s; internal_parse_type(_s);
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  if(**s != ')') Pike_error("Expecting ')'.\n");
1347171998-04-23Fredrik Hübinette (Hubbe)  ++*s; }else{ push_type(T_MIXED); } push_type(T_ARRAY); break; } goto bad_type; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if(atoi(buf)<10) { while(ISSPACE(**s)) ++*s; if(**s=='=') { ++*s; internal_parse_type(_s); push_type(buf[0]); push_type(T_ASSIGN); }else{ push_type(buf[0]); } break; } default: bad_type:
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  Pike_error("Couldn't parse type. (%s)\n",buf);
9e52381998-03-01Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
bdb5091996-09-25Fredrik Hübinette (Hubbe)  while(ISSPACE(**s)) ++*s;
bce86c1996-02-25Fredrik Hübinette (Hubbe) } static void internal_parse_typeB(char **s) {
2916001998-01-16Henrik Grubbström (Grubba)  while(ISSPACE(**((unsigned char **)s))) ++*s;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  switch(**s) { case '!': ++*s; internal_parse_typeB(s); push_type(T_NOT); break; case '(': ++*s;
a946c71998-03-02Fredrik Hübinette (Hubbe)  internal_parse_type(s);
2916001998-01-16Henrik Grubbström (Grubba)  while(ISSPACE(**((unsigned char **)s))) ++*s;
b2d3e42000-12-01Fredrik Hübinette (Hubbe)  if(**s != ')') Pike_error("Expecting ')'.\n");
4d7b181999-12-07Fredrik Hübinette (Hubbe)  ++*s;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  break; default: internal_parse_typeA(s); } } static void internal_parse_typeCC(char **s) { internal_parse_typeB(s);
2916001998-01-16Henrik Grubbström (Grubba)  while(ISSPACE(**((unsigned char **)s))) ++*s;
bce86c1996-02-25Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  while(**s == '*') { ++*s;
2916001998-01-16Henrik Grubbström (Grubba)  while(ISSPACE(**((unsigned char **)s))) ++*s;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  push_type(T_ARRAY);
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
bce86c1996-02-25Fredrik Hübinette (Hubbe) } static void internal_parse_typeC(char **s) { type_stack_mark(); type_stack_mark(); internal_parse_typeCC(s); type_stack_reverse();
5267b71995-08-09Fredrik Hübinette (Hubbe) 
2916001998-01-16Henrik Grubbström (Grubba)  while(ISSPACE(**((unsigned char **)s))) ++*s;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  if(**s == '&') { ++*s; type_stack_mark(); internal_parse_typeC(s); type_stack_reverse(); type_stack_reverse(); push_type(T_AND); }else{ type_stack_reverse();
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
bce86c1996-02-25Fredrik Hübinette (Hubbe) } static void internal_parse_type(char **s) { internal_parse_typeC(s);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
2916001998-01-16Henrik Grubbström (Grubba)  while(ISSPACE(**((unsigned char **)s))) ++*s;
bce86c1996-02-25Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  while(**s == '|') { ++*s;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  internal_parse_typeC(s);
5267b71995-08-09Fredrik Hübinette (Hubbe)  push_type(T_OR); } } /* This function is used when adding simul efuns so that * the types for the functions can be easily stored in strings.
06983f1996-09-22Fredrik Hübinette (Hubbe)  * It takes a string on the exact same format as Pike and returns a type
5267b71995-08-09Fredrik Hübinette (Hubbe)  * struct. */
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *parse_type(char *s)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *ret;
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
bad5162000-06-23Fredrik Hübinette (Hubbe)  unsigned char *ts=Pike_compiler->type_stackp; unsigned char **ptms=Pike_compiler->pike_type_mark_stackp;
fb2f661998-11-05Fredrik Hübinette (Hubbe) #endif
36feac1997-03-06Fredrik Hübinette (Hubbe)  type_stack_mark();
5267b71995-08-09Fredrik Hübinette (Hubbe)  internal_parse_type(&s); if( *s ) fatal("Extra junk at end of type definition.\n");
fb2f661998-11-05Fredrik Hübinette (Hubbe)  ret=pop_unfinished_type();
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(ts!=Pike_compiler->type_stackp || ptms!=Pike_compiler->pike_type_mark_stackp)
fb2f661998-11-05Fredrik Hübinette (Hubbe)  fatal("Type stack whacked in parse_type.\n"); #endif return ret;
5267b71995-08-09Fredrik Hübinette (Hubbe) }
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
e0755c2000-08-15Henrik Grubbström (Grubba) void stupid_describe_type(char *a, ptrdiff_t len)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
e0755c2000-08-15Henrik Grubbström (Grubba)  ptrdiff_t e;
5267b71995-08-09Fredrik Hübinette (Hubbe)  for(e=0;e<len;e++) { if(e) printf(" "); switch(EXTRACT_UCHAR(a+e)) {
9e52381998-03-01Fredrik Hübinette (Hubbe)  case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': printf("%c",EXTRACT_UCHAR(a+e)); break;
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_SCOPE: printf("scope"); break; case T_TUPLE: printf("tuple"); break;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_ASSIGN: printf("="); break;
b660c81999-03-01Fredrik Hübinette (Hubbe)  case T_INT: { INT32 min=extract_type_int(a+e+1); INT32 max=extract_type_int(a+e+1+sizeof(INT32)); printf("int"); if(min!=MIN_INT32 || max!=MAX_INT32) printf("(%ld..%ld)",(long)min,(long)max); e+=sizeof(INT32)*2; break; }
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_FLOAT: printf("float"); break; case T_STRING: printf("string"); break;
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TYPE: printf("type"); break;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_PROGRAM: printf("program"); break; case T_OBJECT:
6bc9281998-04-10Fredrik Hübinette (Hubbe)  printf("object(%s %ld)",
6134591999-12-15Henrik Grubbström (Grubba)  EXTRACT_UCHAR(a+e+1)?"is":"implements",
b660c81999-03-01Fredrik Hübinette (Hubbe)  (long)extract_type_int(a+e+2));
6bc9281998-04-10Fredrik Hübinette (Hubbe)  e+=sizeof(INT32)+1;
9e52381998-03-01Fredrik Hübinette (Hubbe)  break; case T_FUNCTION: printf("function"); break; case T_ARRAY: printf("array"); break; case T_MAPPING: printf("mapping"); break; case T_MULTISET: printf("multiset"); break;
04966d2000-10-03Fredrik Hübinette (Hubbe)  case PIKE_T_UNKNOWN: printf("unknown"); break;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_MANY: printf("many"); break; case T_OR: printf("or"); break; case T_AND: printf("and"); break; case T_NOT: printf("not"); break; case T_VOID: printf("void"); break;
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ZERO: printf("zero"); break;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_MIXED: printf("mixed"); break; default: printf("%d",EXTRACT_UCHAR(a+e)); break;
5267b71995-08-09Fredrik Hübinette (Hubbe)  } } printf("\n"); }
0d202a1995-10-20Fredrik Hübinette (Hubbe) 
d68a072001-02-20Henrik Grubbström (Grubba) void simple_describe_type(struct pike_type *s)
0d202a1995-10-20Fredrik Hübinette (Hubbe) { stupid_describe_type(s->str,s->len); }
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif char *low_describe_type(char *t) { switch(EXTRACT_UCHAR(t++)) {
9e52381998-03-01Fredrik Hübinette (Hubbe)  case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': my_putchar(EXTRACT_UCHAR(t-1)); break; case T_ASSIGN: my_putchar('('); my_putchar(EXTRACT_UCHAR(t++)); my_putchar('=');
bce86c1996-02-25Fredrik Hübinette (Hubbe)  t=low_describe_type(t);
9e52381998-03-01Fredrik Hübinette (Hubbe)  my_putchar(')'); break;
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_SCOPE: my_putchar('{'); my_putchar(EXTRACT_UCHAR(t++)); my_putchar(','); t = low_describe_type(t); my_putchar('}'); break; case T_TUPLE: my_putchar('['); t = low_describe_type(t); my_putchar(','); t = low_describe_type(t); my_putchar(']'); break;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_VOID: my_strcat("void"); break;
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ZERO: my_strcat("zero"); break;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_MIXED: my_strcat("mixed"); break;
04966d2000-10-03Fredrik Hübinette (Hubbe)  case PIKE_T_UNKNOWN: my_strcat("unknown"); break;
b660c81999-03-01Fredrik Hübinette (Hubbe)  case T_INT: { INT32 min=extract_type_int(t); INT32 max=extract_type_int(t+sizeof(INT32)); my_strcat("int"); if(min!=MIN_INT32 || max!=MAX_INT32) { char buffer[100]; sprintf(buffer,"(%ld..%ld)",(long)min,(long)max); my_strcat(buffer); } t+=sizeof(INT32)*2; break; }
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_FLOAT: my_strcat("float"); break; case T_PROGRAM: my_strcat("program"); break; case T_OBJECT:
b660c81999-03-01Fredrik Hübinette (Hubbe)  if(extract_type_int(t+1))
0ee27b1998-04-14Fredrik Hübinette (Hubbe)  { char buffer[100];
6134591999-12-15Henrik Grubbström (Grubba)  sprintf(buffer,"object(%s %ld)",*t?"is":"implements",
3d5c7d1999-12-12Henrik Grubbström (Grubba)  (long)extract_type_int(t+1));
0ee27b1998-04-14Fredrik Hübinette (Hubbe)  my_strcat(buffer); }else{ my_strcat("object"); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  t+=sizeof(INT32)+1;
9e52381998-03-01Fredrik Hübinette (Hubbe)  /* Prog id */ break; case T_STRING: my_strcat("string"); break;
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TYPE: my_strcat("type"); break;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_FUNCTION:
bce86c1996-02-25Fredrik Hübinette (Hubbe)  {
9e52381998-03-01Fredrik Hübinette (Hubbe)  int s;
4d7b181999-12-07Fredrik Hübinette (Hubbe)  my_strcat("function"); if(EXTRACT_UCHAR(t) == T_MANY &&
a0b73f2000-01-03Martin Stjernholm  ((EXTRACT_UCHAR(t+1) == T_ZERO && EXTRACT_UCHAR(t+2) == T_OR && ((EXTRACT_UCHAR(t+3) == T_MIXED && EXTRACT_UCHAR(t+4) == T_VOID) || (EXTRACT_UCHAR(t+4) == T_MIXED && EXTRACT_UCHAR(t+3) == T_VOID))) || (EXTRACT_UCHAR(t+1) == T_OR && ((EXTRACT_UCHAR(t+2) == T_ZERO && EXTRACT_UCHAR(t+3) == T_VOID) || (EXTRACT_UCHAR(t+3) == T_ZERO && EXTRACT_UCHAR(t+2) == T_VOID)) && EXTRACT_UCHAR(t+4) == T_OR && ((EXTRACT_UCHAR(t+5) == T_MIXED && EXTRACT_UCHAR(t+6) == T_VOID) || (EXTRACT_UCHAR(t+6) == T_MIXED && EXTRACT_UCHAR(t+5) == T_VOID)))))
9e52381998-03-01Fredrik Hübinette (Hubbe)  {
4d7b181999-12-07Fredrik Hübinette (Hubbe)  /* done */
a0b73f2000-01-03Martin Stjernholm  if (EXTRACT_UCHAR(t+1) == T_ZERO) { /* function(zero...:mixed|void) */
e0f7f51999-12-11Henrik Grubbström (Grubba)  t += 5; } else {
a0b73f2000-01-03Martin Stjernholm  /* function(zero|void...mixed|void) */
e0f7f51999-12-11Henrik Grubbström (Grubba)  t += 7; }
4d7b181999-12-07Fredrik Hübinette (Hubbe)  } else { my_strcat("("); s=0; while(EXTRACT_UCHAR(t) != T_MANY) { if(s++) my_strcat(", "); t=low_describe_type(t); }
9e52381998-03-01Fredrik Hübinette (Hubbe)  t++;
4d7b181999-12-07Fredrik Hübinette (Hubbe)  if(EXTRACT_UCHAR(t) == T_VOID) { t++; }else{ if(s++) my_strcat(", "); t=low_describe_type(t); my_strcat(" ..."); } my_strcat(" : ");
9e52381998-03-01Fredrik Hübinette (Hubbe)  t=low_describe_type(t);
4d7b181999-12-07Fredrik Hübinette (Hubbe)  my_strcat(")");
9e52381998-03-01Fredrik Hübinette (Hubbe)  } break;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  }
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_ARRAY:
5ac7661998-04-28Fredrik Hübinette (Hubbe)  my_strcat("array");
9e52381998-03-01Fredrik Hübinette (Hubbe)  if(EXTRACT_UCHAR(t)==T_MIXED) { t++; }else{
5ac7661998-04-28Fredrik Hübinette (Hubbe)  my_strcat("(");
9e52381998-03-01Fredrik Hübinette (Hubbe)  t=low_describe_type(t);
5ac7661998-04-28Fredrik Hübinette (Hubbe)  my_strcat(")");
9e52381998-03-01Fredrik Hübinette (Hubbe)  } break; case T_MULTISET: my_strcat("multiset"); if(EXTRACT_UCHAR(t)!=T_MIXED) { my_strcat("("); t=low_describe_type(t); my_strcat(")"); }else{ t++; } break; case T_NOT: my_strcat("!");
da996d1999-12-19Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(t) > T_NOT) { my_strcat("("); t=low_describe_type(t); my_strcat(")"); } else { t=low_describe_type(t); }
9e52381998-03-01Fredrik Hübinette (Hubbe)  break; case T_OR:
da996d1999-12-19Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(t) > T_OR) { my_strcat("("); t=low_describe_type(t); my_strcat(")"); } else { t=low_describe_type(t); }
9e52381998-03-01Fredrik Hübinette (Hubbe)  my_strcat(" | ");
da996d1999-12-19Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(t) > T_OR) { my_strcat("("); t=low_describe_type(t); my_strcat(")"); } else { t=low_describe_type(t); }
9e52381998-03-01Fredrik Hübinette (Hubbe)  break; case T_AND:
da996d1999-12-19Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(t) > T_AND) { my_strcat("("); t=low_describe_type(t); my_strcat(")"); } else { t=low_describe_type(t); }
9e52381998-03-01Fredrik Hübinette (Hubbe)  my_strcat(" & ");
da996d1999-12-19Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(t) > T_AND) { my_strcat("("); t=low_describe_type(t); my_strcat(")"); } else { t=low_describe_type(t); }
9e52381998-03-01Fredrik Hübinette (Hubbe)  break; case T_MAPPING: my_strcat("mapping"); if(EXTRACT_UCHAR(t)==T_MIXED && EXTRACT_UCHAR(t+1)==T_MIXED) { t+=2; }else{ my_strcat("("); t=low_describe_type(t);
e0f7f51999-12-11Henrik Grubbström (Grubba)  my_strcat(":"); t=low_describe_type(t); my_strcat(")"); } break; default: { char buf[20]; my_strcat("unknown code("); sprintf(buf, "%d", EXTRACT_UCHAR(t-1)); my_strcat(buf); my_strcat(")"); break; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  } return t; }
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_string *describe_type(struct pike_type *type)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
b660c81999-03-01Fredrik Hübinette (Hubbe)  check_type_string(type);
bce86c1996-02-25Fredrik Hübinette (Hubbe)  if(!type) return make_shared_string("mixed"); init_buf(); low_describe_type(type->str); return free_buf(); }
9e52381998-03-01Fredrik Hübinette (Hubbe) static int low_is_same_type(char *a, char *b) { if(type_length(a) != type_length(b)) return 0; return !MEMCMP(a,b,type_length(a)); }
bce86c1996-02-25Fredrik Hübinette (Hubbe) static TYPE_T low_compile_type_to_runtime_type(char *t) { TYPE_T tmp;
5267b71995-08-09Fredrik Hübinette (Hubbe)  switch(EXTRACT_UCHAR(t)) { case T_OR:
bce86c1996-02-25Fredrik Hübinette (Hubbe)  t++; tmp=low_compile_type_to_runtime_type(t); if(tmp == low_compile_type_to_runtime_type(t+type_length(t))) return tmp;
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TUPLE: /* FIXME: Shouldn't occur/should be converted to array? */ /* FALL_THROUGH */
9e52381998-03-01Fredrik Hübinette (Hubbe)  default: return T_MIXED;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ZERO: return T_INT;
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_SCOPE: return low_compile_type_to_runtime_type(t+2);
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_ARRAY: case T_MAPPING: case T_MULTISET: case T_OBJECT: case T_PROGRAM: case T_FUNCTION: case T_STRING:
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TYPE:
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_INT: case T_FLOAT: return EXTRACT_UCHAR(t);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
d68a072001-02-20Henrik Grubbström (Grubba) TYPE_T compile_type_to_runtime_type(struct pike_type *s)
bce86c1996-02-25Fredrik Hübinette (Hubbe) { return low_compile_type_to_runtime_type(s->str); }
a946c71998-03-02Fredrik Hübinette (Hubbe) 
05fe341999-11-20Henrik Grubbström (Grubba) static int low_find_exact_type_match(char *needle, char *haystack, int separator)
a946c71998-03-02Fredrik Hübinette (Hubbe) {
05fe341999-11-20Henrik Grubbström (Grubba)  while(EXTRACT_UCHAR(haystack) == separator)
a946c71998-03-02Fredrik Hübinette (Hubbe)  { haystack++;
05fe341999-11-20Henrik Grubbström (Grubba)  if(low_find_exact_type_match(needle, haystack, separator))
a946c71998-03-02Fredrik Hübinette (Hubbe)  return 1; haystack+=type_length(haystack); } return low_is_same_type(needle, haystack); } static void very_low_or_pike_types(char *to_push, char *not_push) { while(EXTRACT_UCHAR(to_push)==T_OR) { to_push++; very_low_or_pike_types(to_push, not_push); to_push+=type_length(to_push); }
02f0631999-11-24Fredrik Hübinette (Hubbe)  /* FIXME: * this might use the 'le' operator */
05fe341999-11-20Henrik Grubbström (Grubba)  if(!low_find_exact_type_match(to_push, not_push, T_OR))
a946c71998-03-02Fredrik Hübinette (Hubbe)  { push_unfinished_type(to_push); push_type(T_OR); } }
4d7b181999-12-07Fredrik Hübinette (Hubbe) static void low_or_pike_types(char *t1, char *t2, int zero_implied)
a946c71998-03-02Fredrik Hübinette (Hubbe) { if(!t1) { if(!t2) push_type(T_VOID); else push_unfinished_type(t2); }
475ab41999-11-29Fredrik Hübinette (Hubbe)  else if((!t2)
4d7b181999-12-07Fredrik Hübinette (Hubbe)  || (EXTRACT_UCHAR(t2) == T_ZERO && zero_implied)
475ab41999-11-29Fredrik Hübinette (Hubbe)  )
a946c71998-03-02Fredrik Hübinette (Hubbe)  { push_unfinished_type(t1); }
4d7b181999-12-07Fredrik Hübinette (Hubbe)  else if (EXTRACT_UCHAR(t1) == T_ZERO && zero_implied)
93dd411999-11-23Henrik Grubbström (Grubba)  { push_unfinished_type(t2); }
a946c71998-03-02Fredrik Hübinette (Hubbe)  else if(EXTRACT_UCHAR(t1)==T_MIXED || EXTRACT_UCHAR(t2)==T_MIXED) { push_type(T_MIXED); }
b660c81999-03-01Fredrik Hübinette (Hubbe)  else if(EXTRACT_UCHAR(t1)==T_INT && EXTRACT_UCHAR(t2)==T_INT) {
327c051999-11-24Fredrik Hübinette (Hubbe)  /* FIXME: * This should only be done if the ranges are * overlapping or adjecant to each other. /Hubbe */
b660c81999-03-01Fredrik Hübinette (Hubbe)  INT32 i1,i2; i1=extract_type_int(t1+1+sizeof(INT32)); i2=extract_type_int(t2+1+sizeof(INT32)); push_type_int(MAXIMUM(i1,i2)); i1=extract_type_int(t1+1); i2=extract_type_int(t2+1); push_type_int(MINIMUM(i1,i2)); push_type(T_INT); }
fc0ad41999-12-11Henrik Grubbström (Grubba)  else if (EXTRACT_UCHAR(t1) == T_SCOPE) { if (EXTRACT_UCHAR(t2) == T_SCOPE) { low_or_pike_types(t1+2, t2+2, zero_implied); if (EXTRACT_UCHAR(t1+1) > EXTRACT_UCHAR(t2+1)) push_type(EXTRACT_UCHAR(t1+1)); else push_type(EXTRACT_UCHAR(t2+1)); } else { low_or_pike_types(t1+2, t2, zero_implied); push_type(EXTRACT_UCHAR(t1+1)); } push_type(T_SCOPE); } else if (EXTRACT_UCHAR(t2) == T_SCOPE) { low_or_pike_types(t1, t2+2, zero_implied); push_type(EXTRACT_UCHAR(t2+1)); push_type(T_SCOPE); }
a946c71998-03-02Fredrik Hübinette (Hubbe)  else { push_unfinished_type(t1); very_low_or_pike_types(t2,t1); } }
d68a072001-02-20Henrik Grubbström (Grubba) static void medium_or_pike_types(struct pike_type *a, struct pike_type *b,
4d7b181999-12-07Fredrik Hübinette (Hubbe)  int zero_implied)
a946c71998-03-02Fredrik Hübinette (Hubbe) {
4d7b181999-12-07Fredrik Hübinette (Hubbe)  low_or_pike_types( a ? a->str : 0 , b ? b->str : 0 , zero_implied);
a946c71998-03-02Fredrik Hübinette (Hubbe) }
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *or_pike_types(struct pike_type *a, struct pike_type *b, int zero_implied)
a946c71998-03-02Fredrik Hübinette (Hubbe) { type_stack_mark();
fc0ad41999-12-11Henrik Grubbström (Grubba)  medium_or_pike_types(a,b,1 /*zero_implied*/);
a946c71998-03-02Fredrik Hübinette (Hubbe)  return pop_unfinished_type(); }
69b6ab1999-11-20Henrik Grubbström (Grubba) static void very_low_and_pike_types(char *to_push, char *not_push) { while(EXTRACT_UCHAR(to_push)==T_AND) { to_push++; very_low_and_pike_types(to_push, not_push); to_push+=type_length(to_push); }
05fe341999-11-20Henrik Grubbström (Grubba)  if(!low_find_exact_type_match(to_push, not_push, T_AND))
69b6ab1999-11-20Henrik Grubbström (Grubba)  { push_unfinished_type(to_push); push_type(T_AND); } }
85200e1999-11-21Henrik Grubbström (Grubba) static void even_lower_and_pike_types(char *t1, char *t2) { while(EXTRACT_UCHAR(t2) == T_OR) { t2++; even_lower_and_pike_types(t1, t2); t2 += type_length(t2); } if (EXTRACT_UCHAR(t1) == EXTRACT_UCHAR(t2)) { if (EXTRACT_UCHAR(t1) == T_INT) { INT32 i1,i2; INT32 upper_bound,lower_bound; i1=extract_type_int(t1+1+sizeof(INT32)); i2=extract_type_int(t2+1+sizeof(INT32)); upper_bound = MINIMUM(i1,i2); i1=extract_type_int(t1+1); i2=extract_type_int(t2+1); lower_bound = MAXIMUM(i1,i2); if (upper_bound >= lower_bound) { push_type_int(upper_bound); push_type_int(lower_bound); push_type(T_INT); push_type(T_OR); } } else { push_unfinished_type(t1); push_type(T_OR); } } } static int lower_and_pike_types(char *t1, char *t2) { int is_complex = 0; while(EXTRACT_UCHAR(t1)==T_OR) { t1++; is_complex |= lower_and_pike_types(t1, t2); t1 += type_length(t1); } switch(EXTRACT_UCHAR(t1)) {
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ZERO:
85200e1999-11-21Henrik Grubbström (Grubba)  case T_VOID: break;
93dd411999-11-23Henrik Grubbström (Grubba)  case T_PROGRAM:
85200e1999-11-21Henrik Grubbström (Grubba)  case T_STRING:
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TYPE:
85200e1999-11-21Henrik Grubbström (Grubba)  case T_FLOAT: case T_INT: even_lower_and_pike_types(t1, t2); break; default: return 1; } return is_complex; } static int low_and_push_complex_pike_type(char *type) { int is_complex = 0; while(EXTRACT_UCHAR(type) == T_OR) {
e8c6c31999-11-21Henrik Grubbström (Grubba)  int new_complex;
85200e1999-11-21Henrik Grubbström (Grubba)  type++;
b8ba151999-11-21Henrik Grubbström (Grubba)  new_complex = low_and_push_complex_pike_type(type);
e8c6c31999-11-21Henrik Grubbström (Grubba)  if (new_complex) {
bcb32d1999-11-21Henrik Grubbström (Grubba)  if (is_complex) { push_type(T_OR); } else { is_complex = 1; }
e8c6c31999-11-21Henrik Grubbström (Grubba)  }
85200e1999-11-21Henrik Grubbström (Grubba)  type += type_length(type); } switch(EXTRACT_UCHAR(type)) { case T_VOID:
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ZERO: case T_PROGRAM:
85200e1999-11-21Henrik Grubbström (Grubba)  case T_STRING:
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TYPE:
85200e1999-11-21Henrik Grubbström (Grubba)  case T_FLOAT: case T_INT: /* Simple type. Already handled. */ break; default: push_unfinished_type(type); if (is_complex) { push_type(T_OR); } return 1; } return is_complex; }
69b6ab1999-11-20Henrik Grubbström (Grubba) static void low_and_pike_types(char *t1, char *t2) {
93dd411999-11-23Henrik Grubbström (Grubba)  if(!t1 || EXTRACT_UCHAR(t1) == T_VOID || !t2 || EXTRACT_UCHAR(t2) == T_VOID)
69b6ab1999-11-20Henrik Grubbström (Grubba)  {
93dd411999-11-23Henrik Grubbström (Grubba)  push_type(T_VOID);
69b6ab1999-11-20Henrik Grubbström (Grubba)  }
93dd411999-11-23Henrik Grubbström (Grubba)  else if(EXTRACT_UCHAR(t1) == T_ZERO || EXTRACT_UCHAR(t2) == T_ZERO)
69b6ab1999-11-20Henrik Grubbström (Grubba)  {
93dd411999-11-23Henrik Grubbström (Grubba)  push_type(T_ZERO);
69b6ab1999-11-20Henrik Grubbström (Grubba)  }
784c5c1999-11-20Henrik Grubbström (Grubba)  else if(EXTRACT_UCHAR(t1)==T_MIXED)
69b6ab1999-11-20Henrik Grubbström (Grubba)  {
784c5c1999-11-20Henrik Grubbström (Grubba)  push_unfinished_type(t2); } else if(EXTRACT_UCHAR(t2)==T_MIXED) { push_unfinished_type(t1);
69b6ab1999-11-20Henrik Grubbström (Grubba)  } else if(EXTRACT_UCHAR(t1)==T_INT && EXTRACT_UCHAR(t2)==T_INT) { INT32 i1,i2; INT32 upper_bound,lower_bound; i1=extract_type_int(t1+1+sizeof(INT32)); i2=extract_type_int(t2+1+sizeof(INT32)); upper_bound = MINIMUM(i1,i2); i1=extract_type_int(t1+1); i2=extract_type_int(t2+1); lower_bound = MAXIMUM(i1,i2); if (upper_bound >= lower_bound) { push_type_int(upper_bound); push_type_int(lower_bound); push_type(T_INT); } else { /* No overlap! */ /* FIXME: Warn? */ push_type(T_VOID); } }
fc0ad41999-12-11Henrik Grubbström (Grubba)  else if (EXTRACT_UCHAR(t1) == T_SCOPE) { if (EXTRACT_UCHAR(t2) == T_SCOPE) { low_and_pike_types(t1+2, t2+2); if (EXTRACT_UCHAR(t1+1) > EXTRACT_UCHAR(t2+1)) push_type(EXTRACT_UCHAR(t1+1)); else push_type(EXTRACT_UCHAR(t2+1)); } else { low_and_pike_types(t1+2, t2); push_type(EXTRACT_UCHAR(t1+1)); } push_type(T_SCOPE); } else if (EXTRACT_UCHAR(t2) == T_SCOPE) { low_and_pike_types(t1, t2+2); push_type(EXTRACT_UCHAR(t2+1)); push_type(T_SCOPE); }
85200e1999-11-21Henrik Grubbström (Grubba)  else if((EXTRACT_UCHAR(t1)==T_STRING && EXTRACT_UCHAR(t2)==T_STRING) ||
fc0ad41999-12-11Henrik Grubbström (Grubba)  (EXTRACT_UCHAR(t1)==T_TYPE && EXTRACT_UCHAR(t2)==T_TYPE) ||
93dd411999-11-23Henrik Grubbström (Grubba)  (EXTRACT_UCHAR(t1)==T_FLOAT && EXTRACT_UCHAR(t2)==T_FLOAT) || (EXTRACT_UCHAR(t1)==T_PROGRAM && EXTRACT_UCHAR(t2)==T_PROGRAM))
69b6ab1999-11-20Henrik Grubbström (Grubba)  { push_unfinished_type(t1);
85200e1999-11-21Henrik Grubbström (Grubba)  }
52169d1999-12-21Henrik Grubbström (Grubba)  else if(low_pike_types_le(t1, t2, 0, 0))
93dd411999-11-23Henrik Grubbström (Grubba)  { push_unfinished_type(t1); }
52169d1999-12-21Henrik Grubbström (Grubba)  else if(low_pike_types_le(t2, t1, 0, 0))
93dd411999-11-23Henrik Grubbström (Grubba)  { push_unfinished_type(t2); }
85200e1999-11-21Henrik Grubbström (Grubba)  else {
93dd411999-11-23Henrik Grubbström (Grubba)  push_type(T_ZERO);
85200e1999-11-21Henrik Grubbström (Grubba)  if (lower_and_pike_types(t1, t2)) { /* t1 contains complex types. */ if (low_and_push_complex_pike_type(t2)) { /* t2 also contains complex types. */ low_and_push_complex_pike_type(t1); push_type(T_AND); push_type(T_OR); } } /* push_unfinished_type(t1); */ /* very_low_and_pike_types(t2,t1); */
69b6ab1999-11-20Henrik Grubbström (Grubba)  } }
d68a072001-02-20Henrik Grubbström (Grubba) static void medium_and_pike_types(struct pike_type *a, struct pike_type *b)
69b6ab1999-11-20Henrik Grubbström (Grubba) { low_and_pike_types( a ? a->str : 0 , b ? b->str : 0 ); }
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *and_pike_types(struct pike_type *a, struct pike_type *b)
69b6ab1999-11-20Henrik Grubbström (Grubba) { type_stack_mark(); medium_and_pike_types(a,b); return pop_unfinished_type(); }
d68a072001-02-20Henrik Grubbström (Grubba) static struct pike_type *low_object_lfun_type(char *t, short lfun)
6bc9281998-04-10Fredrik Hübinette (Hubbe) { struct program *p; int i;
b660c81999-03-01Fredrik Hübinette (Hubbe)  p=id_to_program(extract_type_int(t+2));
6bc9281998-04-10Fredrik Hübinette (Hubbe)  if(!p) return 0;
1347171998-04-23Fredrik Hübinette (Hubbe)  i=FIND_LFUN(p, lfun); if(i==-1) return 0;
0ee27b1998-04-14Fredrik Hübinette (Hubbe)  return ID_FROM_INT(p, i)->type;
6bc9281998-04-10Fredrik Hübinette (Hubbe) }
a946c71998-03-02Fredrik Hübinette (Hubbe) 
bce86c1996-02-25Fredrik Hübinette (Hubbe) #define A_EXACT 1 #define B_EXACT 2
5b4dd31998-02-23Fredrik Hübinette (Hubbe) #define NO_MAX_ARGS 4
5ac7661998-04-28Fredrik Hübinette (Hubbe) #define NO_SHORTCUTS 8
bce86c1996-02-25Fredrik Hübinette (Hubbe) 
02f0631999-11-24Fredrik Hübinette (Hubbe)  #ifdef PIKE_TYPE_DEBUG static int indent=0; #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) /* * match two type strings, return zero if they don't match, and return * the part of 'a' that _did_ match if it did. */
bce86c1996-02-25Fredrik Hübinette (Hubbe) static char *low_match_types(char *a,char *b, int flags)
02f0631999-11-24Fredrik Hübinette (Hubbe) #ifdef PIKE_TYPE_DEBUG { int e; char *s;
fbafd01999-12-12Henrik Grubbström (Grubba)  static char *low_match_types2(char *a,char *b, int flags);
02f0631999-11-24Fredrik Hübinette (Hubbe) 
6f28352000-01-15Fredrik Hübinette (Hubbe)  if (l_flag>2) {
fbafd01999-12-12Henrik Grubbström (Grubba)  init_buf();
f37dad1999-12-11Henrik Grubbström (Grubba)  for(e=0;e<indent;e++) my_strcat(" ");
fbafd01999-12-12Henrik Grubbström (Grubba)  my_strcat("low_match_types("); low_describe_type(a); if(type_length(a) + type_length(b) > 10) { my_strcat(",\n"); for(e=0;e<indent;e++) my_strcat(" "); my_strcat(" "); low_describe_type(b); my_strcat(",\n"); for(e=0;e<indent;e++) my_strcat(" "); my_strcat(" "); }else{ my_strcat(", "); low_describe_type(b); my_strcat(", ");
f37dad1999-12-11Henrik Grubbström (Grubba)  }
fbafd01999-12-12Henrik Grubbström (Grubba)  if (flags) { int f = 0; if (flags & A_EXACT) { my_strcat("A_EXACT"); f = 1;
f37dad1999-12-11Henrik Grubbström (Grubba)  }
fbafd01999-12-12Henrik Grubbström (Grubba)  if (flags & B_EXACT) { if (f) { my_strcat(" | "); } my_strcat("B_EXACT"); f = 1;
f37dad1999-12-11Henrik Grubbström (Grubba)  }
fbafd01999-12-12Henrik Grubbström (Grubba)  if (flags & NO_MAX_ARGS) { if (f) { my_strcat(" | "); } my_strcat("NO_MAX_ARGS"); f = 1;
f37dad1999-12-11Henrik Grubbström (Grubba)  }
fbafd01999-12-12Henrik Grubbström (Grubba)  if (flags & NO_SHORTCUTS) { if (f) { my_strcat(" | "); } my_strcat("NO_SHORTCUTS"); f = 1; } } else { my_strcat("0");
f37dad1999-12-11Henrik Grubbström (Grubba)  }
fbafd01999-12-12Henrik Grubbström (Grubba)  my_strcat(");\n"); fprintf(stderr,"%s",(s=simple_free_buf())); free(s); indent++;
02f0631999-11-24Fredrik Hübinette (Hubbe)  } a=low_match_types2(a,b,flags);
6f28352000-01-15Fredrik Hübinette (Hubbe)  if (l_flag>2) {
fbafd01999-12-12Henrik Grubbström (Grubba)  indent--; init_buf(); for(e=0;e<indent;e++) my_strcat(" "); my_strcat("= "); if(a) low_describe_type(a); else my_strcat("NULL"); my_strcat("\n"); fprintf(stderr,"%s",(s=simple_free_buf())); free(s); }
02f0631999-11-24Fredrik Hübinette (Hubbe)  return a; } static char *low_match_types2(char *a,char *b, int flags) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) {
1d53281996-11-25Fredrik Hübinette (Hubbe)  int correct_args;
5267b71995-08-09Fredrik Hübinette (Hubbe)  char *ret; if(a == b) return a;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  switch(EXTRACT_UCHAR(a))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
bce86c1996-02-25Fredrik Hübinette (Hubbe)  case T_AND:
5267b71995-08-09Fredrik Hübinette (Hubbe)  a++;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  ret=low_match_types(a,b,flags); if(!ret) return 0; a+=type_length(a); return low_match_types(a,b,flags); case T_OR:
5267b71995-08-09Fredrik Hübinette (Hubbe)  a++;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  ret=low_match_types(a,b,flags);
5ac7661998-04-28Fredrik Hübinette (Hubbe)  if(ret && !(flags & NO_SHORTCUTS)) return ret;
5267b71995-08-09Fredrik Hübinette (Hubbe)  a+=type_length(a);
5ac7661998-04-28Fredrik Hübinette (Hubbe)  if(ret) { low_match_types(a,b,flags); return ret; }else{ return low_match_types(a,b,flags); }
bce86c1996-02-25Fredrik Hübinette (Hubbe)  case T_NOT:
9e52381998-03-01Fredrik Hübinette (Hubbe)  if(low_match_types(a+1,b,(flags ^ B_EXACT ) | NO_MAX_ARGS))
bce86c1996-02-25Fredrik Hübinette (Hubbe)  return 0; return a;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_ASSIGN: ret=low_match_types(a+2,b,flags);
a946c71998-03-02Fredrik Hübinette (Hubbe)  if(ret && EXTRACT_UCHAR(b)!=T_VOID)
9e52381998-03-01Fredrik Hübinette (Hubbe)  { int m=EXTRACT_UCHAR(a+1)-'0';
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *tmp;
02f0631999-11-24Fredrik Hübinette (Hubbe)  type_stack_mark(); push_unfinished_type_with_markers(b, b_markers); tmp=pop_unfinished_type();
a946c71998-03-02Fredrik Hübinette (Hubbe)  type_stack_mark();
4d7b181999-12-07Fredrik Hübinette (Hubbe)  medium_or_pike_types(a_markers[m], tmp, 0);
d68a072001-02-20Henrik Grubbström (Grubba)  if(a_markers[m]) free_type(a_markers[m]); free_type(tmp);
a946c71998-03-02Fredrik Hübinette (Hubbe)  a_markers[m]=pop_unfinished_type();
02f0631999-11-24Fredrik Hübinette (Hubbe)  #ifdef PIKE_TYPE_DEBUG
6f28352000-01-15Fredrik Hübinette (Hubbe)  if (l_flag>2) {
02f0631999-11-24Fredrik Hübinette (Hubbe)  char *s; int e; init_buf(); for(e=0;e<indent;e++) my_strcat(" "); my_strcat("a_markers[");
f258372000-09-08Henrik Grubbström (Grubba)  my_putchar((char)(m+'0'));
02f0631999-11-24Fredrik Hübinette (Hubbe)  my_strcat("]="); low_describe_type(a_markers[m]->str); my_strcat("\n"); fprintf(stderr,"%s",(s=simple_free_buf())); free(s); } #endif #ifdef PIKE_DEBUG if(a_markers[m]->str[0] == m+'0') fatal("Cyclic type!\n"); #endif
9e52381998-03-01Fredrik Hübinette (Hubbe)  } return ret; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { int m=EXTRACT_UCHAR(a)-'0'; if(a_markers[m])
02f0631999-11-24Fredrik Hübinette (Hubbe)  { #ifdef PIKE_DEBUG if(a_markers[m]->str[0] == EXTRACT_UCHAR(a)) fatal("Cyclic type!\n"); if(EXTRACT_UCHAR(a_markers[m]->str) == T_OR && a_markers[m]->str[1] == EXTRACT_UCHAR(a)) fatal("Cyclic type!\n"); #endif
a946c71998-03-02Fredrik Hübinette (Hubbe)  return low_match_types(a_markers[m]->str, b, flags);
02f0631999-11-24Fredrik Hübinette (Hubbe)  }
9e52381998-03-01Fredrik Hübinette (Hubbe)  else return low_match_types(mixed_type_string->str, b, flags); }
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
bce86c1996-02-25Fredrik Hübinette (Hubbe)  switch(EXTRACT_UCHAR(b))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
bce86c1996-02-25Fredrik Hübinette (Hubbe)  case T_AND:
5267b71995-08-09Fredrik Hübinette (Hubbe)  b++;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  ret=low_match_types(a,b,flags); if(!ret) return 0; b+=type_length(b); return low_match_types(a,b,flags); case T_OR:
5267b71995-08-09Fredrik Hübinette (Hubbe)  b++;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  ret=low_match_types(a,b,flags);
5ac7661998-04-28Fredrik Hübinette (Hubbe)  if(ret && !(flags & NO_SHORTCUTS)) return ret;
5267b71995-08-09Fredrik Hübinette (Hubbe)  b+=type_length(b);
5ac7661998-04-28Fredrik Hübinette (Hubbe)  if(ret) { low_match_types(a,b,flags); return ret; }else{ return low_match_types(a,b,flags); }
bce86c1996-02-25Fredrik Hübinette (Hubbe)  case T_NOT:
9e52381998-03-01Fredrik Hübinette (Hubbe)  if(low_match_types(a,b+1, (flags ^ A_EXACT ) | NO_MAX_ARGS))
bce86c1996-02-25Fredrik Hübinette (Hubbe)  return 0; return a;
9e52381998-03-01Fredrik Hübinette (Hubbe)  case T_ASSIGN: ret=low_match_types(a,b+2,flags);
a946c71998-03-02Fredrik Hübinette (Hubbe)  if(ret && EXTRACT_UCHAR(a)!=T_VOID)
9e52381998-03-01Fredrik Hübinette (Hubbe)  { int m=EXTRACT_UCHAR(b+1)-'0';
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *tmp;
a946c71998-03-02Fredrik Hübinette (Hubbe)  type_stack_mark();
02f0631999-11-24Fredrik Hübinette (Hubbe)  push_unfinished_type_with_markers(a, a_markers); tmp=pop_unfinished_type(); type_stack_mark();
4d7b181999-12-07Fredrik Hübinette (Hubbe)  medium_or_pike_types(b_markers[m], tmp, 0);
d68a072001-02-20Henrik Grubbström (Grubba)  if(b_markers[m]) free_type(b_markers[m]); free_type(tmp);
a946c71998-03-02Fredrik Hübinette (Hubbe)  b_markers[m]=pop_unfinished_type();
02f0631999-11-24Fredrik Hübinette (Hubbe) #ifdef PIKE_TYPE_DEBUG
6f28352000-01-15Fredrik Hübinette (Hubbe)  if (l_flag>2) {
02f0631999-11-24Fredrik Hübinette (Hubbe)  char *s; int e; init_buf(); for(e=0;e<indent;e++) my_strcat(" "); my_strcat("b_markers[");
f258372000-09-08Henrik Grubbström (Grubba)  my_putchar((char)(m+'0'));
02f0631999-11-24Fredrik Hübinette (Hubbe)  my_strcat("]="); low_describe_type(b_markers[m]->str); my_strcat("\n"); fprintf(stderr,"%s",(s=simple_free_buf())); free(s); } #endif #ifdef PIKE_DEBUG if(b_markers[m]->str[0] == m+'0') fatal("Cyclic type!\n"); #endif
9e52381998-03-01Fredrik Hübinette (Hubbe)  } return ret; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { int m=EXTRACT_UCHAR(b)-'0'; if(b_markers[m])
02f0631999-11-24Fredrik Hübinette (Hubbe)  { #ifdef PIKE_DEBUG if(b_markers[m]->str[0] == EXTRACT_UCHAR(b)) fatal("Cyclic type!\n"); #endif
a946c71998-03-02Fredrik Hübinette (Hubbe)  return low_match_types(a, b_markers[m]->str, flags);
02f0631999-11-24Fredrik Hübinette (Hubbe)  }
9e52381998-03-01Fredrik Hübinette (Hubbe)  else return low_match_types(a, mixed_type_string->str, flags); }
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
0d202a1995-10-20Fredrik Hübinette (Hubbe)  /* 'mixed' matches anything */
02f0631999-11-24Fredrik Hübinette (Hubbe) 
327c051999-11-24Fredrik Hübinette (Hubbe)  if(((EXTRACT_UCHAR(a) == T_ZERO || EXTRACT_UCHAR(a) == T_MIXED) &&
f37dad1999-12-11Henrik Grubbström (Grubba)  !(flags & (A_EXACT|B_EXACT)) &&
327c051999-11-24Fredrik Hübinette (Hubbe)  EXTRACT_UCHAR(b) != T_VOID))
02f0631999-11-24Fredrik Hübinette (Hubbe)  { #if 1 switch(EXTRACT_UCHAR(b)) { /* These types can contain sub-types */ case T_ARRAY: low_match_types(array_type_string->str,b , flags); break; case T_MAPPING: low_match_types(mapping_type_string->str,b, flags); break; case T_FUNCTION: low_match_types(function_type_string->str,b, flags); break; case T_MULTISET: low_match_types(multiset_type_string->str,b, flags); break; } #endif return a; }
327c051999-11-24Fredrik Hübinette (Hubbe)  if((( EXTRACT_UCHAR(b) == T_ZERO || EXTRACT_UCHAR(b) == T_MIXED) &&
f37dad1999-12-11Henrik Grubbström (Grubba)  !(flags & (A_EXACT|B_EXACT)) &&
02f0631999-11-24Fredrik Hübinette (Hubbe)  EXTRACT_UCHAR(a) != T_VOID)) { #if 1 switch(EXTRACT_UCHAR(a)) { /* These types can contain sub-types */ case T_ARRAY: low_match_types(a , array_type_string->str, flags); break; case T_MAPPING: low_match_types(a , mapping_type_string->str, flags); break; case T_FUNCTION: low_match_types(a , function_type_string->str, flags); break; case T_MULTISET: low_match_types(a , multiset_type_string->str, flags); break; } #endif return a; }
93dd411999-11-23Henrik Grubbström (Grubba) 
fc0ad41999-12-11Henrik Grubbström (Grubba)  /* Convert zero to int(0..0). */ if (EXTRACT_UCHAR(a) == T_ZERO) a = tInt0; if (EXTRACT_UCHAR(b) == T_ZERO) b = tInt0;
d2c6081996-11-07Fredrik Hübinette (Hubbe) 
9f68471997-03-08Fredrik Hübinette (Hubbe)  /* Special cases (tm) */ switch(EXTRACT_TWOT(a,b))
255d351997-01-26Fredrik Hübinette (Hubbe)  {
9f68471997-03-08Fredrik Hübinette (Hubbe)  case TWOT(T_PROGRAM, T_FUNCTION): case TWOT(T_FUNCTION, T_PROGRAM):
255d351997-01-26Fredrik Hübinette (Hubbe)  return a;
f37dad1999-12-11Henrik Grubbström (Grubba) 
9f68471997-03-08Fredrik Hübinette (Hubbe)  case TWOT(T_OBJECT, T_FUNCTION):
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *s;
6bc9281998-04-10Fredrik Hübinette (Hubbe)  if((s=low_object_lfun_type(a, LFUN_CALL)))
f37dad1999-12-11Henrik Grubbström (Grubba)  return low_match_types(s->str,b,flags); if (flags & B_EXACT) { /* A function isn't an object */ return 0; }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  return a; }
9f68471997-03-08Fredrik Hübinette (Hubbe)  case TWOT(T_FUNCTION, T_OBJECT): {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *s;
6bc9281998-04-10Fredrik Hübinette (Hubbe)  if((s=low_object_lfun_type(b, LFUN_CALL)))
f37dad1999-12-11Henrik Grubbström (Grubba)  return low_match_types(a,s->str,flags); if (flags & A_EXACT) { /* A function isn't an object */ return 0; }
9f68471997-03-08Fredrik Hübinette (Hubbe)  return a; } }
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(EXTRACT_UCHAR(a) != EXTRACT_UCHAR(b)) return 0; ret=a; switch(EXTRACT_UCHAR(a)) { case T_FUNCTION:
1d53281996-11-25Fredrik Hübinette (Hubbe)  correct_args=0;
5267b71995-08-09Fredrik Hübinette (Hubbe)  a++; b++; while(EXTRACT_UCHAR(a)!=T_MANY || EXTRACT_UCHAR(b)!=T_MANY) { char *a_tmp,*b_tmp; if(EXTRACT_UCHAR(a)==T_MANY) { a_tmp=a+1; }else{ a_tmp=a; a+=type_length(a); } if(EXTRACT_UCHAR(b)==T_MANY) {
0d202a1995-10-20Fredrik Hübinette (Hubbe)  b_tmp=b+1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{ b_tmp=b; b+=type_length(b); }
fc0ad41999-12-11Henrik Grubbström (Grubba)  if(!low_match_types(a_tmp, b_tmp, (flags | NO_MAX_ARGS) & ~(A_EXACT|B_EXACT))) return 0;
1d53281996-11-25Fredrik Hübinette (Hubbe)  if(++correct_args > max_correct_args)
5b4dd31998-02-23Fredrik Hübinette (Hubbe)  if(!(flags & NO_MAX_ARGS)) max_correct_args=correct_args;
5267b71995-08-09Fredrik Hübinette (Hubbe)  } /* check the 'many' type */ a++; b++;
0d202a1995-10-20Fredrik Hübinette (Hubbe)  if(EXTRACT_UCHAR(b)==T_VOID || EXTRACT_UCHAR(a)==T_VOID)
5267b71995-08-09Fredrik Hübinette (Hubbe)  { a+=type_length(a);
0d202a1995-10-20Fredrik Hübinette (Hubbe)  b+=type_length(b);
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{
fc0ad41999-12-11Henrik Grubbström (Grubba)  if(!low_match_types(a,b, (flags | NO_MAX_ARGS) & ~(A_EXACT|B_EXACT))) return 0;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
5b4dd31998-02-23Fredrik Hübinette (Hubbe)  if(!(flags & NO_MAX_ARGS)) max_correct_args=0x7fffffff;
5267b71995-08-09Fredrik Hübinette (Hubbe)  /* check the returntype */
7eda1d1999-11-26Henrik Grubbström (Grubba)  if ((EXTRACT_UCHAR(b) == T_VOID) && (EXTRACT_UCHAR(a) != T_VOID)) { /* Promote b to a function returning zero. */
fc0ad41999-12-11Henrik Grubbström (Grubba)  if (!low_match_types(a, tZero, flags & ~(A_EXACT|B_EXACT))) return 0;
7eda1d1999-11-26Henrik Grubbström (Grubba)  } else if ((EXTRACT_UCHAR(a) == T_VOID) && (EXTRACT_UCHAR(b) != T_VOID)) { /* Promote a to a function returning zero. */
fc0ad41999-12-11Henrik Grubbström (Grubba)  if(!low_match_types(tZero,b,flags & ~(A_EXACT|B_EXACT))) return 0; } else if(!low_match_types(a,b,flags & ~(A_EXACT|B_EXACT))) return 0;
5267b71995-08-09Fredrik Hübinette (Hubbe)  break; case T_MAPPING:
fc0ad41999-12-11Henrik Grubbström (Grubba)  if(!low_match_types(++a,++b,flags & ~(A_EXACT|B_EXACT))) return 0; if(!low_match_types(a+type_length(a),b+type_length(b), flags & ~(A_EXACT|B_EXACT))) return 0;
5267b71995-08-09Fredrik Hübinette (Hubbe)  break;
d2c6081996-11-07Fredrik Hübinette (Hubbe)  case T_OBJECT:
636e471998-04-15Fredrik Hübinette (Hubbe) #if 0
b660c81999-03-01Fredrik Hübinette (Hubbe)  if(extract_type_int(a+2) || extract_type_int(b+2))
636e471998-04-15Fredrik Hübinette (Hubbe)  { fprintf(stderr,"Type match1: "); stupid_describe_type(a,type_length(a)); fprintf(stderr,"Type match2: "); stupid_describe_type(b,type_length(b)); } #endif
6bc9281998-04-10Fredrik Hübinette (Hubbe)  /* object(* 0) matches any object */
b660c81999-03-01Fredrik Hübinette (Hubbe)  if(!extract_type_int(a+2) || !extract_type_int(b+2)) break;
6bc9281998-04-10Fredrik Hübinette (Hubbe)  /* object(x *) =? object(x *) */ if(EXTRACT_UCHAR(a+1) == EXTRACT_UCHAR(b+1)) { /* x? */ if(EXTRACT_UCHAR(a+1)) { /* object(1 x) =? object(1 x) */
b660c81999-03-01Fredrik Hübinette (Hubbe)  if(extract_type_int(a+2) != extract_type_int(b+2)) return 0;
6bc9281998-04-10Fredrik Hübinette (Hubbe)  }else{ /* object(0 *) =? object(0 *) */
fbafd01999-12-12Henrik Grubbström (Grubba)  /* FIXME: Ought to check the implements relation */
6bc9281998-04-10Fredrik Hübinette (Hubbe)  break; } } { struct program *ap,*bp;
b660c81999-03-01Fredrik Hübinette (Hubbe)  ap=id_to_program(extract_type_int(a+2)); bp=id_to_program(extract_type_int(b+2));
6bc9281998-04-10Fredrik Hübinette (Hubbe)  if(!ap || !bp) break;
636e471998-04-15Fredrik Hübinette (Hubbe) 
0cbc271999-12-14Fredrik Hübinette (Hubbe) #if 0
fbafd01999-12-12Henrik Grubbström (Grubba)  /* FIXME: Temporary kludge. * match_types() currently seems to need to be symetric. */ if (!implements(ap,bp) && !implements(bp,ap)) return 0; #else /* !1 */
6bc9281998-04-10Fredrik Hübinette (Hubbe)  if(EXTRACT_UCHAR(a+1)) {
20ea771999-12-15Fredrik Hübinette (Hubbe)  if(!implements(implements_a=ap,implements_b=bp))
6bc9281998-04-10Fredrik Hübinette (Hubbe)  return 0; }else{
20ea771999-12-15Fredrik Hübinette (Hubbe)  if(!implements(implements_a=bp,implements_b=ap))
6bc9281998-04-10Fredrik Hübinette (Hubbe)  return 0; }
fbafd01999-12-12Henrik Grubbström (Grubba) #endif /* 1 */
6bc9281998-04-10Fredrik Hübinette (Hubbe)  }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  break;
b660c81999-03-01Fredrik Hübinette (Hubbe)  case T_INT: { INT32 amin=extract_type_int(a+1); INT32 amax=extract_type_int(a+1+sizeof(INT32)); INT32 bmin=extract_type_int(b+1); INT32 bmax=extract_type_int(b+1+sizeof(INT32)); if(amin > bmax || bmin > amax) return 0; break; }
06983f1996-09-22Fredrik Hübinette (Hubbe)  case T_MULTISET:
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_ARRAY:
fc0ad41999-12-11Henrik Grubbström (Grubba)  if(!low_match_types(++a,++b,flags & ~(A_EXACT|B_EXACT))) return 0;
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_FLOAT: case T_STRING:
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TYPE:
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_PROGRAM:
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ZERO: case T_VOID: case T_MIXED: break; default:
a4a1722000-12-05Per Hedbor  fatal("Error in type string.\n");
93dd411999-11-23Henrik Grubbström (Grubba)  } return ret; }
52169d1999-12-21Henrik Grubbström (Grubba) /* * Flags used by pike_types_le() */
8fea161999-12-31Henrik Grubbström (Grubba) #define LE_WEAK_OBJECTS 1 /* Perform weaker checking of objects. */
52169d1999-12-21Henrik Grubbström (Grubba) 
93dd411999-11-23Henrik Grubbström (Grubba) /* * Check the partial ordering relation. * * mixed * * int float string program function object * * zero * * void
dfda7e1999-11-25Henrik Grubbström (Grubba)  * * Note that non-destructive operations are assumed. * ie it's assumed that calling a function(mapping(string|int:string|int):void) * with a mapping(int:int) won't change the type of the mapping after the * operation.
93dd411999-11-23Henrik Grubbström (Grubba)  */
52169d1999-12-21Henrik Grubbström (Grubba) static int low_pike_types_le(char *a, char *b, int array_cnt, unsigned int flags)
ae18181999-11-25Henrik Grubbström (Grubba) #ifdef PIKE_TYPE_DEBUG { int e; char *s;
52169d1999-12-21Henrik Grubbström (Grubba)  static int low_pike_types_le2(char *a, char *b, int array_cnt, unsigned int flags);
ae18181999-11-25Henrik Grubbström (Grubba)  int res;
6134591999-12-15Henrik Grubbström (Grubba)  char buf[50];
ae18181999-11-25Henrik Grubbström (Grubba) 
6f28352000-01-15Fredrik Hübinette (Hubbe)  if (l_flag>2) {
fbafd01999-12-12Henrik Grubbström (Grubba)  init_buf();
ae18181999-11-25Henrik Grubbström (Grubba)  for(e=0;e<indent;e++) my_strcat(" ");
fbafd01999-12-12Henrik Grubbström (Grubba)  my_strcat("low_pike_types_le("); low_describe_type(a); if(type_length(a) + type_length(b) > 10) { my_strcat(",\n"); for(e=0;e<indent;e++) my_strcat(" "); my_strcat(" "); low_describe_type(b); }else{ my_strcat(", "); low_describe_type(b); }
6134591999-12-15Henrik Grubbström (Grubba)  if(type_length(a) + type_length(b) > 10) { my_strcat(",\n"); for(e=0;e<indent;e++) my_strcat(" "); my_strcat(" "); }else{ my_strcat(", "); } sprintf(buf, "%d", array_cnt); my_strcat(buf);
52169d1999-12-21Henrik Grubbström (Grubba)  my_strcat(", "); sprintf(buf, "0x%08x", flags); my_strcat(buf);
fbafd01999-12-12Henrik Grubbström (Grubba)  my_strcat(");\n"); fprintf(stderr,"%s",(s=simple_free_buf())); free(s); indent++;
ae18181999-11-25Henrik Grubbström (Grubba)  }
52169d1999-12-21Henrik Grubbström (Grubba)  res=low_pike_types_le2(a, b, array_cnt, flags);
ae18181999-11-25Henrik Grubbström (Grubba) 
6f28352000-01-15Fredrik Hübinette (Hubbe)  if (l_flag>2) {
fbafd01999-12-12Henrik Grubbström (Grubba)  indent--;
ae18181999-11-25Henrik Grubbström (Grubba) 
fbafd01999-12-12Henrik Grubbström (Grubba)  for(e=0;e<indent;e++) fprintf(stderr, " "); fprintf(stderr, "= %d\n", res); }
ae18181999-11-25Henrik Grubbström (Grubba)  return res; }
52169d1999-12-21Henrik Grubbström (Grubba) static int low_pike_types_le2(char *a, char *b, int array_cnt, unsigned int flags)
ae18181999-11-25Henrik Grubbström (Grubba) #endif /* PIKE_TYPE_DEBUG */
93dd411999-11-23Henrik Grubbström (Grubba) { int ret; if(a == b) return 1; switch(EXTRACT_UCHAR(a)) { case T_AND: /* OK if either of the parts is a subset. */ /* FIXME: What if b also contains an AND? */ a++;
52169d1999-12-21Henrik Grubbström (Grubba)  ret = low_pike_types_le(a, b, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  if(ret) return ret; a += type_length(a);
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, b, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  case T_OR: /* OK, if both of the parts are a subset */ a++;
144ce31999-12-19Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(a) == T_VOID) { /* Special case for T_VOID */ /* FIXME: Should probably be handled as T_ZERO. */ a += type_length(a);
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, b, array_cnt, flags);
144ce31999-12-19Henrik Grubbström (Grubba)  } else {
52169d1999-12-21Henrik Grubbström (Grubba)  ret=low_pike_types_le(a, b, array_cnt, flags);
144ce31999-12-19Henrik Grubbström (Grubba)  if (!ret) return 0; a+=type_length(a); if (EXTRACT_UCHAR(a) == T_VOID) { /* Special case for T_VOID */ /* FIXME: Should probably be handled as T_ZERO. */ return 1; } else {
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, b, array_cnt, flags);
144ce31999-12-19Henrik Grubbström (Grubba)  } }
93dd411999-11-23Henrik Grubbström (Grubba)  case T_NOT:
72a1e91999-12-19Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(b) == T_NOT) {
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(b+1, a+1, -array_cnt, flags);
72a1e91999-12-19Henrik Grubbström (Grubba)  }
69a9431999-12-21Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(a+1) == T_NOT) {
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a+2, b, array_cnt, flags);
69a9431999-12-21Henrik Grubbström (Grubba)  }
52169d1999-12-21Henrik Grubbström (Grubba)  if (low_pike_types_le(a+1, b, array_cnt, flags)) {
72a1e91999-12-19Henrik Grubbström (Grubba)  return 0; } /* FIXME: This is wrong... */
52169d1999-12-21Henrik Grubbström (Grubba)  return !low_pike_types_le(b, a+1, -array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ASSIGN:
52169d1999-12-21Henrik Grubbström (Grubba)  ret=low_pike_types_le(a+2, b, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  if(ret && EXTRACT_UCHAR(b)!=T_VOID) { int m=EXTRACT_UCHAR(a+1)-'0';
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *tmp;
6134591999-12-15Henrik Grubbström (Grubba)  int i;
93dd411999-11-23Henrik Grubbström (Grubba)  type_stack_mark();
02f0631999-11-24Fredrik Hübinette (Hubbe)  push_unfinished_type_with_markers(b, b_markers);
6134591999-12-15Henrik Grubbström (Grubba)  for(i=array_cnt; i > 0; i--) push_type(T_ARRAY);
02f0631999-11-24Fredrik Hübinette (Hubbe)  tmp=pop_unfinished_type();
fbafd01999-12-12Henrik Grubbström (Grubba) 
02f0631999-11-24Fredrik Hübinette (Hubbe)  type_stack_mark();
4d7b181999-12-07Fredrik Hübinette (Hubbe)  medium_or_pike_types(a_markers[m], tmp, 0);
d68a072001-02-20Henrik Grubbström (Grubba)  if(a_markers[m]) free_type(a_markers[m]); free_type(tmp);
93dd411999-11-23Henrik Grubbström (Grubba)  a_markers[m]=pop_unfinished_type();
02f0631999-11-24Fredrik Hübinette (Hubbe) #ifdef PIKE_TYPE_DEBUG
6f28352000-01-15Fredrik Hübinette (Hubbe)  if (l_flag>2) {
02f0631999-11-24Fredrik Hübinette (Hubbe)  char *s; int e; init_buf(); for(e=0;e<indent;e++) my_strcat(" "); my_strcat("a_markers[");
f258372000-09-08Henrik Grubbström (Grubba)  my_putchar((char)(m+'0'));
02f0631999-11-24Fredrik Hübinette (Hubbe)  my_strcat("]="); low_describe_type(a_markers[m]->str); my_strcat("\n"); fprintf(stderr,"%s",(s=simple_free_buf())); free(s); } #endif
93dd411999-11-23Henrik Grubbström (Grubba)  } return ret; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { int m=EXTRACT_UCHAR(a)-'0'; if(a_markers[m])
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a_markers[m]->str, b, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  else
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(mixed_type_string->str, b, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  } } switch(EXTRACT_UCHAR(b)) { case T_AND: /* OK, if a is a subset of both parts. */ b++;
52169d1999-12-21Henrik Grubbström (Grubba)  ret = low_pike_types_le(a, b, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  if(!ret) return 0; b+=type_length(b);
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, b, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  case T_OR: /* OK if a is a subset of either of the parts. */ b++;
52169d1999-12-21Henrik Grubbström (Grubba)  ret=low_pike_types_le(a, b, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  if (ret) return ret; b+=type_length(b);
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, b, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  case T_NOT:
69a9431999-12-21Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(b+1) == T_NOT) {
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, b+2, array_cnt, flags);
69a9431999-12-21Henrik Grubbström (Grubba)  }
52169d1999-12-21Henrik Grubbström (Grubba)  if (low_pike_types_le(a, b+1, array_cnt, flags)) {
72a1e91999-12-19Henrik Grubbström (Grubba)  return 0; } /* FIXME: This is wrong... */
52169d1999-12-21Henrik Grubbström (Grubba)  return !low_pike_types_le(b+1, a, -array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ASSIGN:
52169d1999-12-21Henrik Grubbström (Grubba)  ret=low_pike_types_le(a, b+2, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  if(ret && EXTRACT_UCHAR(a)!=T_VOID) { int m=EXTRACT_UCHAR(b+1)-'0';
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *tmp;
6134591999-12-15Henrik Grubbström (Grubba)  int i;
93dd411999-11-23Henrik Grubbström (Grubba)  type_stack_mark();
02f0631999-11-24Fredrik Hübinette (Hubbe)  push_unfinished_type_with_markers(a, a_markers);
6134591999-12-15Henrik Grubbström (Grubba)  for(i = array_cnt; i < 0; i++) push_type(T_ARRAY);
02f0631999-11-24Fredrik Hübinette (Hubbe)  tmp=pop_unfinished_type(); type_stack_mark();
4d7b181999-12-07Fredrik Hübinette (Hubbe)  medium_or_pike_types(b_markers[m], tmp, 0);
d68a072001-02-20Henrik Grubbström (Grubba)  if(b_markers[m]) free_type(b_markers[m]); free_type(tmp);
93dd411999-11-23Henrik Grubbström (Grubba)  b_markers[m]=pop_unfinished_type();
02f0631999-11-24Fredrik Hübinette (Hubbe) #ifdef PIKE_TYPE_DEBUG
6f28352000-01-15Fredrik Hübinette (Hubbe)  if (l_flag>2) {
02f0631999-11-24Fredrik Hübinette (Hubbe)  char *s; int e; init_buf(); for(e=0;e<indent;e++) my_strcat(" "); my_strcat("b_markers[");
f258372000-09-08Henrik Grubbström (Grubba)  my_putchar((char)(m+'0'));
02f0631999-11-24Fredrik Hübinette (Hubbe)  my_strcat("]="); low_describe_type(b_markers[m]->str); my_strcat("\n"); fprintf(stderr,"%s",(s=simple_free_buf())); free(s); } #endif
93dd411999-11-23Henrik Grubbström (Grubba)  } return ret; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { int m=EXTRACT_UCHAR(b)-'0'; if(b_markers[m])
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, b_markers[m]->str, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  else
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, mixed_type_string->str, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  }
6134591999-12-15Henrik Grubbström (Grubba)  }
93dd411999-11-23Henrik Grubbström (Grubba) 
6134591999-12-15Henrik Grubbström (Grubba)  if ((array_cnt < 0) && (EXTRACT_UCHAR(b) == T_ARRAY)) { while (EXTRACT_UCHAR(b) == T_ARRAY) { b++; if (!++array_cnt) break; }
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, b, array_cnt, flags);
6134591999-12-15Henrik Grubbström (Grubba)  } else if ((array_cnt > 0) && (EXTRACT_UCHAR(a) == T_ARRAY)) { while (EXTRACT_UCHAR(a) == T_ARRAY) { a++; if (!--array_cnt) break; }
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, b, array_cnt, flags);
6134591999-12-15Henrik Grubbström (Grubba)  }
8043d51999-12-17Henrik Grubbström (Grubba)  /* NOTE: void only matches void. */ if (EXTRACT_UCHAR(a) == T_VOID) { /* void <= any_type */ if (array_cnt >= 0) { /* !array(void) */ if (!array_cnt && (EXTRACT_UCHAR(b) == T_VOID)) { return 1; } return 0;
6134591999-12-15Henrik Grubbström (Grubba)  }
93dd411999-11-23Henrik Grubbström (Grubba)  }
8043d51999-12-17Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(b) == T_VOID) { if (array_cnt <= 0) { /* !array(void) */
6134591999-12-15Henrik Grubbström (Grubba)  return 0; }
93dd411999-11-23Henrik Grubbström (Grubba)  }
8043d51999-12-17Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(b) == T_MIXED) { /* any_type <= 'mixed' */ if (array_cnt <= 0) { /* !array(mixed) */
6134591999-12-15Henrik Grubbström (Grubba)  return 1; }
93dd411999-11-23Henrik Grubbström (Grubba)  }
8043d51999-12-17Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(a) == T_MIXED) { if (array_cnt >= 0) { /* !array(mixed) */
6134591999-12-15Henrik Grubbström (Grubba)  return 0; }
93dd411999-11-23Henrik Grubbström (Grubba)  } if (EXTRACT_UCHAR(a) == T_ZERO) { /* void <= zero <= any_type */
6134591999-12-15Henrik Grubbström (Grubba)  if (array_cnt >= 0) { /* !array(zero) */ return 1; }
93dd411999-11-23Henrik Grubbström (Grubba)  } if (EXTRACT_UCHAR(b) == T_ZERO) {
6134591999-12-15Henrik Grubbström (Grubba)  if (array_cnt <= 0) { /* !array(zero) */ return 0; }
93dd411999-11-23Henrik Grubbström (Grubba)  } /* Special cases (tm) */ switch(EXTRACT_TWOT(a,b)) { case TWOT(T_PROGRAM, T_FUNCTION): case TWOT(T_FUNCTION, T_PROGRAM): /* FIXME: Not really... Should check the return value. */ return 1; case TWOT(T_OBJECT, T_FUNCTION): {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *s;
93dd411999-11-23Henrik Grubbström (Grubba)  if((s=low_object_lfun_type(a, LFUN_CALL)))
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(s->str, b, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  return 1; } case TWOT(T_FUNCTION, T_OBJECT): {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *s;
93dd411999-11-23Henrik Grubbström (Grubba)  if((s=low_object_lfun_type(b, LFUN_CALL)))
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, s->str, array_cnt, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  return 1; }
6134591999-12-15Henrik Grubbström (Grubba)  case TWOT(T_FUNCTION, T_ARRAY): { while (EXTRACT_UCHAR(b) == T_ARRAY) { b++; array_cnt++; }
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, b, array_cnt, flags);
6134591999-12-15Henrik Grubbström (Grubba)  } case TWOT(T_ARRAY, T_FUNCTION): { while (EXTRACT_UCHAR(a) == T_ARRAY) { a++; array_cnt--; }
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a, b, array_cnt, flags);
6134591999-12-15Henrik Grubbström (Grubba)  }
93dd411999-11-23Henrik Grubbström (Grubba)  } if(EXTRACT_UCHAR(a) != EXTRACT_UCHAR(b)) return 0;
6134591999-12-15Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(a) == T_FUNCTION) {
dfda7e1999-11-25Henrik Grubbström (Grubba)  /* * function(A...:B) <= function(C...:D) iff C <= A && B <= D */
3d12931999-11-25Henrik Grubbström (Grubba)  /* * function(:int) <= function(int:int) * function(int|string:int) <= function(int:int)
7eda1d1999-11-26Henrik Grubbström (Grubba)  * function(:int) <= function(:void)
3d12931999-11-25Henrik Grubbström (Grubba)  * function(string:int) != function(int:int) * function(int:int) != function(:int)
8043d51999-12-17Henrik Grubbström (Grubba)  * * FIXME: Enforcing of all required arguments?
3d12931999-11-25Henrik Grubbström (Grubba)  */
93dd411999-11-23Henrik Grubbström (Grubba)  a++; b++; while(EXTRACT_UCHAR(a)!=T_MANY || EXTRACT_UCHAR(b)!=T_MANY) { char *a_tmp,*b_tmp; if(EXTRACT_UCHAR(a)==T_MANY) { a_tmp=a+1; }else{ a_tmp=a; a+=type_length(a); } if(EXTRACT_UCHAR(b)==T_MANY) { b_tmp=b+1; }else{ b_tmp=b; b+=type_length(b); }
3d12931999-11-25Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(a_tmp) != T_VOID) {
52169d1999-12-21Henrik Grubbström (Grubba)  if (!low_pike_types_le(b_tmp, a_tmp, 0, flags)) {
8fea161999-12-31Henrik Grubbström (Grubba)  return 0;
52169d1999-12-21Henrik Grubbström (Grubba)  }
3d12931999-11-25Henrik Grubbström (Grubba)  }
93dd411999-11-23Henrik Grubbström (Grubba)  } /* check the 'many' type */ a++; b++;
69a9431999-12-21Henrik Grubbström (Grubba)  if ((EXTRACT_UCHAR(a) != T_VOID) && (EXTRACT_UCHAR(b) != T_VOID)) {
52169d1999-12-21Henrik Grubbström (Grubba)  if (!low_pike_types_le(b, a, 0, flags)) {
8fea161999-12-31Henrik Grubbström (Grubba)  return 0;
52169d1999-12-21Henrik Grubbström (Grubba)  }
3d12931999-11-25Henrik Grubbström (Grubba)  }
93dd411999-11-23Henrik Grubbström (Grubba)  a+=type_length(a); b+=type_length(b); /* check the returntype */
95a83d1999-12-26Henrik Grubbström (Grubba)  /* FIXME: Check array_cnt */ if ((EXTRACT_UCHAR(b) != T_VOID) && (EXTRACT_UCHAR(a) != T_VOID)) {
52169d1999-12-21Henrik Grubbström (Grubba)  if(!low_pike_types_le(a, b, array_cnt, flags)) return 0;
438d421999-11-26Henrik Grubbström (Grubba)  }
6134591999-12-15Henrik Grubbström (Grubba)  return 1; } if (array_cnt) return 0;
93dd411999-11-23Henrik Grubbström (Grubba) 
6134591999-12-15Henrik Grubbström (Grubba)  switch(EXTRACT_UCHAR(a)) {
93dd411999-11-23Henrik Grubbström (Grubba)  case T_MAPPING: /*
3ac0d11999-12-12Martin Stjernholm  * mapping(A:B) <= mapping(C:D) iff A <= C && B <= D.
93dd411999-11-23Henrik Grubbström (Grubba)  */
52169d1999-12-21Henrik Grubbström (Grubba)  if(!low_pike_types_le(++a, ++b, 0, flags)) return 0; return low_pike_types_le(a+type_length(a), b+type_length(b), 0, flags);
93dd411999-11-23Henrik Grubbström (Grubba)  case T_OBJECT: #if 0 if(extract_type_int(a+2) || extract_type_int(b+2)) { fprintf(stderr,"Type match1: "); stupid_describe_type(a,type_length(a)); fprintf(stderr,"Type match2: "); stupid_describe_type(b,type_length(b)); } #endif
fbafd01999-12-12Henrik Grubbström (Grubba)  /* * object(0|1 x) <= object(0|1 0) * object(0|1 0) <=! object(0|1 !0) * object(1 x) <= object(0|1 x)
6134591999-12-15Henrik Grubbström (Grubba)  * object(1 x) <= object(1 y) iff x == y
8fea161999-12-31Henrik Grubbström (Grubba)  * object(1 x) <= object(0 y) iff x implements y * Not WEAK_OBJECTS: * object(0 x) <= object(0 y) iff x implements y * WEAK_OBJECTS: * object(0 x) <= object(0 y) iff x is_compatible y
fbafd01999-12-12Henrik Grubbström (Grubba)  */
93dd411999-11-23Henrik Grubbström (Grubba)  /* object(* 0) matches any object */ if(!extract_type_int(b+2)) return 1; if(!extract_type_int(a+2)) return 0;
fbafd01999-12-12Henrik Grubbström (Grubba)  if ((EXTRACT_UCHAR(a+1) || !EXTRACT_UCHAR(b+1)) && (extract_type_int(a+2) == extract_type_int(b+2))) return 1;
93dd411999-11-23Henrik Grubbström (Grubba) 
fbafd01999-12-12Henrik Grubbström (Grubba)  if (EXTRACT_UCHAR(b+1)) {
6134591999-12-15Henrik Grubbström (Grubba)  return 0;
93dd411999-11-23Henrik Grubbström (Grubba)  } {
fbafd01999-12-12Henrik Grubbström (Grubba)  struct program *ap = id_to_program(extract_type_int(a+2)); struct program *bp = id_to_program(extract_type_int(b+2));
93dd411999-11-23Henrik Grubbström (Grubba) 
fbafd01999-12-12Henrik Grubbström (Grubba)  if (!ap || !bp) { /* Shouldn't happen... */ return 0; }
8fea161999-12-31Henrik Grubbström (Grubba)  if ((flags & LE_WEAK_OBJECTS) && (!EXTRACT_UCHAR(a+1))) { return is_compatible(implements_a=ap, implements_b=bp); }
20ea771999-12-15Fredrik Hübinette (Hubbe)  return implements(implements_a=ap, implements_b=bp);
93dd411999-11-23Henrik Grubbström (Grubba)  } break; case T_INT: { INT32 amin=extract_type_int(a+1); INT32 amax=extract_type_int(a+1+sizeof(INT32)); INT32 bmin=extract_type_int(b+1); INT32 bmax=extract_type_int(b+1+sizeof(INT32)); if(amin < bmin || amax > bmax) return 0; break; } case T_MULTISET: case T_ARRAY:
52169d1999-12-21Henrik Grubbström (Grubba)  if(!low_pike_types_le(++a, ++b, 0, flags)) return 0;
93dd411999-11-23Henrik Grubbström (Grubba)  case T_FLOAT: case T_STRING:
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TYPE:
93dd411999-11-23Henrik Grubbström (Grubba)  case T_PROGRAM: case T_ZERO:
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_VOID: case T_MIXED: break; default:
a4a1722000-12-05Per Hedbor  fatal("Error in type string.\n");
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
fbafd01999-12-12Henrik Grubbström (Grubba)  return 1; } /* * Check the function parameters. * Note: The difference between this function, and pike_types_le() * is the more lenient check for T_OR, and the handling of T_ARRAY. */ int strict_check_call(char *fun_type, char *arg_type) { while ((EXTRACT_UCHAR(fun_type) == T_OR) || (EXTRACT_UCHAR(fun_type) == T_ARRAY)) { if (EXTRACT_UCHAR(fun_type++) == T_OR) { int res = strict_check_call(fun_type, arg_type); if (res) return res; fun_type += type_length(fun_type); } }
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(fun_type, arg_type, 0, 0); } /* * Check validity of soft-cast. * Note: This uses a weaker check of function arguments, since * people get confused otherwise. */
d68a072001-02-20Henrik Grubbström (Grubba) int check_soft_cast(struct pike_type *to, struct pike_type *from)
52169d1999-12-21Henrik Grubbström (Grubba) {
8fea161999-12-31Henrik Grubbström (Grubba)  return low_pike_types_le(to->str, from->str, 0, LE_WEAK_OBJECTS);
5267b71995-08-09Fredrik Hübinette (Hubbe) } /* * Return the return type from a function call. */ static int low_get_return_type(char *a,char *b) {
bce86c1996-02-25Fredrik Hübinette (Hubbe)  int tmp; switch(EXTRACT_UCHAR(a))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
bce86c1996-02-25Fredrik Hübinette (Hubbe)  case T_OR:
7260711996-06-21Fredrik Hübinette (Hubbe)  {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *o1, *o2;
7260711996-06-21Fredrik Hübinette (Hubbe)  a++; o1=o2=0; type_stack_mark(); if(low_get_return_type(a,b)) { o1=pop_unfinished_type(); type_stack_mark(); } if(low_get_return_type(a+type_length(a),b)) o2=pop_unfinished_type(); else pop_stack_mark();
a946c71998-03-02Fredrik Hübinette (Hubbe)  if(!o1 && !o2) return 0;
4d7b181999-12-07Fredrik Hübinette (Hubbe)  medium_or_pike_types(o1,o2, 0);
7260711996-06-21Fredrik Hübinette (Hubbe) 
d68a072001-02-20Henrik Grubbström (Grubba)  if(o1) free_type(o1); if(o2) free_type(o2);
7260711996-06-21Fredrik Hübinette (Hubbe)  return 1; }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
bce86c1996-02-25Fredrik Hübinette (Hubbe)  case T_AND:
5267b71995-08-09Fredrik Hübinette (Hubbe)  a++;
bce86c1996-02-25Fredrik Hübinette (Hubbe)  type_stack_mark();
5267b71995-08-09Fredrik Hübinette (Hubbe)  tmp=low_get_return_type(a,b);
bce86c1996-02-25Fredrik Hübinette (Hubbe)  type_stack_pop_to_mark(); if(!tmp) return 0; return low_get_return_type(a+type_length(a),b);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
bce86c1996-02-25Fredrik Hübinette (Hubbe)  case T_ARRAY:
5267b71995-08-09Fredrik Hübinette (Hubbe)  a++; tmp=low_get_return_type(a,b); if(!tmp) return 0; push_type(T_ARRAY); return 1; }
5ac7661998-04-28Fredrik Hübinette (Hubbe)  a=low_match_types(a,b,NO_SHORTCUTS);
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(a) {
fc0ad41999-12-11Henrik Grubbström (Grubba) #if 0 if ((lex.pragmas & ID_STRICT_TYPES) &&
52169d1999-12-21Henrik Grubbström (Grubba)  !low_pike_types_le(a, b, 0, 0)) {
fc0ad41999-12-11Henrik Grubbström (Grubba)  yywarning("Type mismatch"); } #endif /* 0 */
5267b71995-08-09Fredrik Hübinette (Hubbe)  switch(EXTRACT_UCHAR(a)) { case T_FUNCTION: a++; while(EXTRACT_UCHAR(a)!=T_MANY) a+=type_length(a); a++; a+=type_length(a);
9e52381998-03-01Fredrik Hübinette (Hubbe)  push_unfinished_type_with_markers(a, a_markers );
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1;
d2c6081996-11-07Fredrik Hübinette (Hubbe)  case T_PROGRAM: push_type_int(0);
6bc9281998-04-10Fredrik Hübinette (Hubbe)  push_type(0);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  push_type(T_OBJECT); return 1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  default: push_type(T_MIXED); return 1; } } return 0; }
d68a072001-02-20Henrik Grubbström (Grubba) int match_types(struct pike_type *a, struct pike_type *b)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  check_type_string(a); check_type_string(b);
9e52381998-03-01Fredrik Hübinette (Hubbe)  clear_markers();
bce86c1996-02-25Fredrik Hübinette (Hubbe)  return 0!=low_match_types(a->str, b->str,0);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
d68a072001-02-20Henrik Grubbström (Grubba) int pike_types_le(struct pike_type *a, struct pike_type *b)
93dd411999-11-23Henrik Grubbström (Grubba) { check_type_string(a); check_type_string(b); clear_markers();
52169d1999-12-21Henrik Grubbström (Grubba)  return low_pike_types_le(a->str, b->str, 0, 0);
93dd411999-11-23Henrik Grubbström (Grubba) }
2a50961995-08-23Fredrik Hübinette (Hubbe) 
3c0c281998-01-26Fredrik Hübinette (Hubbe) #ifdef DEBUG_MALLOC
d68a072001-02-20Henrik Grubbström (Grubba) #define low_index_type(X,Y,Z) ((struct pike_type *)debug_malloc_pass(debug_low_index_type((X),(Y),(Z))))
3c0c281998-01-26Fredrik Hübinette (Hubbe) #else #define low_index_type debug_low_index_type #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  /* FIXME, add the index */
d68a072001-02-20Henrik Grubbström (Grubba) static struct pike_type *debug_low_index_type(char *t, char *index_type, node *n)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *tmp;
8852cb1999-10-25Fredrik Hübinette (Hubbe)  struct program *p;
fc0ad41999-12-11Henrik Grubbström (Grubba) 
4d7b181999-12-07Fredrik Hübinette (Hubbe)  switch(low_check_indexing(t, index_type, n)) { case 0: return 0; case -1: reference_shared_string(zero_type_string); return zero_type_string; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  switch(EXTRACT_UCHAR(t++)) {
b8cda21997-01-21Fredrik Hübinette (Hubbe)  case T_OBJECT: {
8852cb1999-10-25Fredrik Hübinette (Hubbe)  p=id_to_program(extract_type_int(t+1)); comefrom_int_index:
dcab7e1998-02-19Fredrik Hübinette (Hubbe)  if(p && n)
b8cda21997-01-21Fredrik Hübinette (Hubbe)  {
4d7b181999-12-07Fredrik Hübinette (Hubbe)  INT32 i;
b8cda21997-01-21Fredrik Hübinette (Hubbe)  if(n->token == F_ARROW) {
4d7b181999-12-07Fredrik Hübinette (Hubbe)  /* FIXME: make this stricter */
bc68521999-12-18Martin Stjernholm  if((i=FIND_LFUN(p,LFUN_ARROW))!=-1)
b8cda21997-01-21Fredrik Hübinette (Hubbe)  {
4d7b181999-12-07Fredrik Hübinette (Hubbe)  /* FIXME: function_type_string should be replaced with something * derived from type_string */
46aa641999-12-29Henrik Grubbström (Grubba)  if(i!=-1 && (tmp=check_call(function_type_string, ID_FROM_INT(p, i)->type, 0)))
4d7b181999-12-07Fredrik Hübinette (Hubbe)  return tmp;
b8cda21997-01-21Fredrik Hübinette (Hubbe)  reference_shared_string(mixed_type_string); return mixed_type_string; } }else{
bc68521999-12-18Martin Stjernholm  if((i=FIND_LFUN(p,LFUN_INDEX)) != -1)
b8cda21997-01-21Fredrik Hübinette (Hubbe)  {
4d7b181999-12-07Fredrik Hübinette (Hubbe)  /* FIXME: function_type_string should be replaced with something * derived from type_string */
46aa641999-12-29Henrik Grubbström (Grubba)  if(i!=-1 && (tmp=check_call(function_type_string, ID_FROM_INT(p, i)->type, 0)))
4d7b181999-12-07Fredrik Hübinette (Hubbe)  return tmp;
b8cda21997-01-21Fredrik Hübinette (Hubbe)  reference_shared_string(mixed_type_string); return mixed_type_string; } } if(CDR(n)->token == F_CONSTANT && CDR(n)->u.sval.type==T_STRING) { i=find_shared_string_identifier(CDR(n)->u.sval.u.string, p); if(i==-1) {
b8c29a1998-08-19Fredrik Hübinette (Hubbe)  reference_shared_string(mixed_type_string); return mixed_type_string;
b8cda21997-01-21Fredrik Hübinette (Hubbe)  }else{
da52b71999-11-23Fredrik Hübinette (Hubbe) #if 0
6bc9281998-04-10Fredrik Hübinette (Hubbe)  if(EXTRACT_UCHAR(t) || (p->identifier_references[i].id_flags & ID_NOMASK) || (ID_FROM_INT(p, i)->identifier_flags & IDENTIFIER_PROTOTYPED)) {
da52b71999-11-23Fredrik Hübinette (Hubbe) #endif
6bc9281998-04-10Fredrik Hübinette (Hubbe)  reference_shared_string(ID_FROM_INT(p, i)->type); return ID_FROM_INT(p, i)->type;
da52b71999-11-23Fredrik Hübinette (Hubbe) #if 0
6bc9281998-04-10Fredrik Hübinette (Hubbe)  }else{ reference_shared_string(mixed_type_string); return mixed_type_string; }
da52b71999-11-23Fredrik Hübinette (Hubbe) #endif
b8cda21997-01-21Fredrik Hübinette (Hubbe)  } } } }
5267b71995-08-09Fredrik Hübinette (Hubbe)  default: reference_shared_string(mixed_type_string); return mixed_type_string;
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_MIXED: if (lex.pragmas & ID_STRICT_TYPES) { yywarning("Indexing mixed."); } reference_shared_string(mixed_type_string); return mixed_type_string;
8852cb1999-10-25Fredrik Hübinette (Hubbe)  case T_INT: #ifdef AUTO_BIGNUM /* Don't force Gmp.mpz to be loaded here since this function * is called long before the master object is compiled... * /Hubbe */ p=get_auto_bignum_program_or_zero(); goto comefrom_int_index; #endif
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ZERO:
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TYPE:
fb2f661998-11-05Fredrik Hübinette (Hubbe)  case T_VOID: case T_FLOAT: return 0;
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_OR: {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *a, *b;
4d7b181999-12-07Fredrik Hübinette (Hubbe)  a=low_index_type(t,index_type,n);
5267b71995-08-09Fredrik Hübinette (Hubbe)  t+=type_length(t);
4d7b181999-12-07Fredrik Hübinette (Hubbe)  b=low_index_type(t,index_type,n);
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(!b) return a; if(!a) return b;
a946c71998-03-02Fredrik Hübinette (Hubbe)  type_stack_mark();
4d7b181999-12-07Fredrik Hübinette (Hubbe)  medium_or_pike_types(a,b,1);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(a); free_type(b);
36feac1997-03-06Fredrik Hübinette (Hubbe)  return pop_unfinished_type();
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
bce86c1996-02-25Fredrik Hübinette (Hubbe)  case T_AND:
4d7b181999-12-07Fredrik Hübinette (Hubbe)  return low_index_type(t+type_length(t),index_type,n);
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_STRING: /* always int */
06983f1996-09-22Fredrik Hübinette (Hubbe)  case T_MULTISET: /* always int */
5267b71995-08-09Fredrik Hübinette (Hubbe)  reference_shared_string(int_type_string); return int_type_string; case T_MAPPING: t+=type_length(t);
de2a581997-09-28Fredrik Hübinette (Hubbe)  return make_shared_binary_string(t, type_length(t));
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_ARRAY:
de2a581997-09-28Fredrik Hübinette (Hubbe)  {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *a;
04da272000-03-10Henrik Grubbström (Grubba)  if(low_pike_types_le(tString, index_type, 0, 0) && (a = low_index_type(t, tString, n))) { /* Possible to index the array with a string. */
fc42132000-03-10Henrik Grubbström (Grubba)  type_stack_mark(); push_finished_type(a);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(a);
fc42132000-03-10Henrik Grubbström (Grubba)  push_type(T_ARRAY);
04da272000-03-10Henrik Grubbström (Grubba)  if (low_match_types(tInt, index_type, 0)) { /* Also possible to index the array with an int. */ push_unfinished_type(t); push_type(T_OR); }
fc42132000-03-10Henrik Grubbström (Grubba)  return pop_unfinished_type();
04da272000-03-10Henrik Grubbström (Grubba)  } if (low_match_types(tInt, index_type, 0)) { /* Possible to index the array with an int. */
de2a581997-09-28Fredrik Hübinette (Hubbe)  return make_shared_binary_string(t, type_length(t)); }
04da272000-03-10Henrik Grubbström (Grubba)  /* Bad index type. */ return 0;
de2a581997-09-28Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *index_type(struct pike_type *type, struct pike_type *index_type, node *n)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *t;
9e52381998-03-01Fredrik Hübinette (Hubbe)  clear_markers();
4d7b181999-12-07Fredrik Hübinette (Hubbe)  t=low_index_type(type->str,index_type->str,n);
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(!t) copy_shared_string(t,mixed_type_string); return t; }
1a3e1b1999-04-13Fredrik Hübinette (Hubbe) 
d68a072001-02-20Henrik Grubbström (Grubba) static struct pike_type *low_array_value_type(char *arr_t)
144ce31999-12-19Henrik Grubbström (Grubba) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *res = NULL; struct pike_type *sub_t;
144ce31999-12-19Henrik Grubbström (Grubba)  while (EXTRACT_UCHAR(arr_t) == T_OR) { arr_t++; sub_t = low_array_value_type(arr_t); arr_t += type_length(arr_t); if (sub_t) { if (res) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *new = or_pike_types(res, sub_t, 1); free_type(res); free_type(sub_t);
144ce31999-12-19Henrik Grubbström (Grubba)  res = new; } else { res = sub_t; } } } if (EXTRACT_UCHAR(arr_t) != T_ARRAY) return res; arr_t++; sub_t = make_shared_binary_string(arr_t, type_length(arr_t)); if (res) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *new = or_pike_types(res, sub_t, 1); free_type(res); free_type(sub_t);
144ce31999-12-19Henrik Grubbström (Grubba)  return new; } return sub_t; }
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *array_value_type(struct pike_type *array_type)
144ce31999-12-19Henrik Grubbström (Grubba) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *t = low_array_value_type(array_type->str);
144ce31999-12-19Henrik Grubbström (Grubba)  if (!t) copy_shared_string(t, mixed_type_string); return t; }
1a3e1b1999-04-13Fredrik Hübinette (Hubbe) #ifdef DEBUG_MALLOC
d68a072001-02-20Henrik Grubbström (Grubba) #define low_key_type(X,Y) ((struct pike_type *)debug_malloc_pass(debug_low_key_type((X),(Y))))
1a3e1b1999-04-13Fredrik Hübinette (Hubbe) #else #define low_key_type debug_low_key_type #endif /* FIXME, add the index */
d68a072001-02-20Henrik Grubbström (Grubba) static struct pike_type *debug_low_key_type(char *t, node *n)
1a3e1b1999-04-13Fredrik Hübinette (Hubbe) { switch(EXTRACT_UCHAR(t++)) { case T_OBJECT: { struct program *p=id_to_program(extract_type_int(t+1)); if(p && n) { if(n->token == F_ARROW) { if(FIND_LFUN(p,LFUN_ARROW)!=-1 || FIND_LFUN(p,LFUN_ASSIGN_ARROW)!=-1) { reference_shared_string(mixed_type_string); return mixed_type_string; } }else{ if(FIND_LFUN(p,LFUN_INDEX) != -1 || FIND_LFUN(p,LFUN_ASSIGN_INDEX) != -1) { reference_shared_string(mixed_type_string); return mixed_type_string; } } } reference_shared_string(string_type_string); return string_type_string; } default: reference_shared_string(mixed_type_string); return mixed_type_string; case T_VOID:
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ZERO:
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TYPE:
1a3e1b1999-04-13Fredrik Hübinette (Hubbe)  case T_FLOAT: case T_INT: return 0; case T_OR: {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *a, *b;
1a3e1b1999-04-13Fredrik Hübinette (Hubbe)  a=low_key_type(t,n); t+=type_length(t); b=low_key_type(t,n); if(!b) return a; if(!a) return b; type_stack_mark();
4d7b181999-12-07Fredrik Hübinette (Hubbe)  medium_or_pike_types(a,b,1);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(a); free_type(b);
1a3e1b1999-04-13Fredrik Hübinette (Hubbe)  return pop_unfinished_type(); } case T_AND: return low_key_type(t+type_length(t),n); case T_ARRAY: case T_STRING: /* always int */ reference_shared_string(int_type_string); return int_type_string; case T_MAPPING: case T_MULTISET: return make_shared_binary_string(t, type_length(t)); } }
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *key_type(struct pike_type *type, node *n)
1a3e1b1999-04-13Fredrik Hübinette (Hubbe) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *t;
1a3e1b1999-04-13Fredrik Hübinette (Hubbe)  clear_markers(); t=low_key_type(type->str,n); if(!t) copy_shared_string(t,mixed_type_string); return t; }
b8cda21997-01-21Fredrik Hübinette (Hubbe) static int low_check_indexing(char *type, char *index_type, node *n)
5267b71995-08-09Fredrik Hübinette (Hubbe) { switch(EXTRACT_UCHAR(type++)) { case T_OR:
b8cda21997-01-21Fredrik Hübinette (Hubbe)  return low_check_indexing(type,index_type,n) || low_check_indexing(type+type_length(type),index_type,n);
bce86c1996-02-25Fredrik Hübinette (Hubbe)  case T_AND:
b8cda21997-01-21Fredrik Hübinette (Hubbe)  return low_check_indexing(type,index_type,n) && low_check_indexing(type+type_length(type),index_type,n);
bce86c1996-02-25Fredrik Hübinette (Hubbe)  case T_NOT:
4d7b181999-12-07Fredrik Hübinette (Hubbe)  return low_check_indexing(type,index_type,n)!=1;
bce86c1996-02-25Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_ARRAY:
de2a581997-09-28Fredrik Hübinette (Hubbe)  if(low_match_types(string_type_string->str, index_type,0) && low_check_indexing(type, index_type,n)) return 1; case T_STRING:
bce86c1996-02-25Fredrik Hübinette (Hubbe)  return !!low_match_types(int_type_string->str, index_type,0);
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_OBJECT:
b8cda21997-01-21Fredrik Hübinette (Hubbe)  {
b660c81999-03-01Fredrik Hübinette (Hubbe)  struct program *p=id_to_program(extract_type_int(type+1));
b8cda21997-01-21Fredrik Hübinette (Hubbe)  if(p) { if(n->token == F_ARROW) {
6bc9281998-04-10Fredrik Hübinette (Hubbe)  if(FIND_LFUN(p,LFUN_ARROW)!=-1 || FIND_LFUN(p,LFUN_ASSIGN_ARROW)!=-1) return 1;
b8cda21997-01-21Fredrik Hübinette (Hubbe)  }else{
6bc9281998-04-10Fredrik Hübinette (Hubbe)  if(FIND_LFUN(p,LFUN_INDEX)!=-1 || FIND_LFUN(p,LFUN_ASSIGN_INDEX)!=-1) return 1;
b8cda21997-01-21Fredrik Hübinette (Hubbe)  } return !!low_match_types(string_type_string->str, index_type,0); }else{ return 1; } }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
06983f1996-09-22Fredrik Hübinette (Hubbe)  case T_MULTISET:
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_MAPPING:
4d7b181999-12-07Fredrik Hübinette (Hubbe)  return low_match_types(type,index_type,0) ? 1 : -1;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
8852cb1999-10-25Fredrik Hübinette (Hubbe) #ifdef AUTO_BIGNUM case T_INT: #endif case T_PROGRAM: return !!low_match_types(string_type_string->str, index_type,0);
43f12e1998-09-29Henrik Grubbström (Grubba) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_MIXED: return 1; default: return 0; } }
d68a072001-02-20Henrik Grubbström (Grubba) int check_indexing(struct pike_type *type, struct pike_type *index_type,
b8cda21997-01-21Fredrik Hübinette (Hubbe)  node *n)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  check_type_string(type); check_type_string(index_type);
b9e4ba1996-11-18Fredrik Hübinette (Hubbe) 
b8cda21997-01-21Fredrik Hübinette (Hubbe)  return low_check_indexing(type->str, index_type->str, n);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
5b4dd31998-02-23Fredrik Hübinette (Hubbe) static int low_count_arguments(char *q) { int num,num2;
d429a71998-02-24Fredrik Hübinette (Hubbe) 
5b4dd31998-02-23Fredrik Hübinette (Hubbe)  switch(EXTRACT_UCHAR(q++)) { case T_OR: num=low_count_arguments(q); num2=low_count_arguments(q+type_length(q)); if(num<0 && num2>0) return num; if(num2<0 && num>0) return num2; if(num2<0 && num<0) return ~num>~num2?num:num2; return num>num2?num:num2; case T_AND: num=low_count_arguments(q); num2=low_count_arguments(q+type_length(q)); if(num<0 && num2>0) return num2; if(num2<0 && num>0) return num; if(num2<0 && num<0) return ~num<~num2?num:num2; return num<num2?num:num2;
d429a71998-02-24Fredrik Hübinette (Hubbe)  default: return 0x7fffffff;
5b4dd31998-02-23Fredrik Hübinette (Hubbe)  case T_FUNCTION: num=0; while(EXTRACT_UCHAR(q)!=T_MANY) { num++; q+=type_length(q); } q++; if(EXTRACT_UCHAR(q)!=T_VOID) return ~num; return num; } }
5267b71995-08-09Fredrik Hübinette (Hubbe) /* Count the number of arguments for a funciton type. * return -1-n if the function can take number of arguments * >= n (varargs) */
d68a072001-02-20Henrik Grubbström (Grubba) int count_arguments(struct pike_type *s)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  check_type_string(s);
b9e4ba1996-11-18Fredrik Hübinette (Hubbe) 
5b4dd31998-02-23Fredrik Hübinette (Hubbe)  return low_count_arguments(s->str);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
3aa7831999-06-02Fredrik Hübinette (Hubbe)  static int low_minimum_arguments(char *q) { int num; switch(EXTRACT_UCHAR(q++)) { case T_OR: case T_AND: return MAXIMUM(low_count_arguments(q), low_count_arguments(q+type_length(q))); default: return 0; case T_FUNCTION: num=0; while(EXTRACT_UCHAR(q)!=T_MANY) { if(low_match_types(void_type_string->str, q, B_EXACT)) return num; num++; q+=type_length(q); } return num; } } /* Count the minimum number of arguments for a funciton type. */
d68a072001-02-20Henrik Grubbström (Grubba) int minimum_arguments(struct pike_type *s)
3aa7831999-06-02Fredrik Hübinette (Hubbe) { int ret; check_type_string(s); ret=low_minimum_arguments(s->str); #if 0 fprintf(stderr,"minimum_arguments("); simple_describe_type(s); fprintf(stderr," ) -> %d\n",ret); #endif return ret; }
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *check_call(struct pike_type *args, struct pike_type *type, int strict)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  check_type_string(args); check_type_string(type);
9e52381998-03-01Fredrik Hübinette (Hubbe)  clear_markers();
36feac1997-03-06Fredrik Hübinette (Hubbe)  type_stack_mark();
1d53281996-11-25Fredrik Hübinette (Hubbe)  max_correct_args=0;
36feac1997-03-06Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(low_get_return_type(type->str,args->str)) {
46aa641999-12-29Henrik Grubbström (Grubba)  if (strict) {
6134591999-12-15Henrik Grubbström (Grubba)  if (!strict_check_call(type->str, args->str)) {
fbafd01999-12-12Henrik Grubbström (Grubba)  struct pike_string *type_t = describe_type(type);
6134591999-12-15Henrik Grubbström (Grubba) 
52169d1999-12-21Henrik Grubbström (Grubba)  if (!low_pike_types_le(type->str, tFuncV(tNone,tZero,tMix), 0, 0)) {
6134591999-12-15Henrik Grubbström (Grubba)  yywarning("Calling non-function value."); yywarning("Type called: %s", type_t->str); } else { struct pike_string *arg_t = describe_type(args); yywarning("Arguments not strictly compatible."); yywarning("Expected: %s", type_t->str); yywarning("Got : %s", arg_t->str); free_string(arg_t); }
fbafd01999-12-12Henrik Grubbström (Grubba)  free_string(type_t); } }
36feac1997-03-06Fredrik Hübinette (Hubbe)  return pop_unfinished_type();
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{
36feac1997-03-06Fredrik Hübinette (Hubbe)  pop_stack_mark();
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; } }
d68a072001-02-20Henrik Grubbström (Grubba) INT32 get_max_args(struct pike_type *type)
5b4dd31998-02-23Fredrik Hübinette (Hubbe) { INT32 ret,tmp=max_correct_args;
45ee5d1999-02-10Fredrik Hübinette (Hubbe)  check_type_string(type);
9e52381998-03-01Fredrik Hübinette (Hubbe)  clear_markers();
46aa641999-12-29Henrik Grubbström (Grubba)  type = check_call(function_type_string, type, 0);
d68a072001-02-20Henrik Grubbström (Grubba)  if(type) free_type(type);
5b4dd31998-02-23Fredrik Hübinette (Hubbe)  ret=max_correct_args; max_correct_args=tmp; return tmp; }
b2d75f1999-10-25Fredrik Hübinette (Hubbe) 
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *zzap_function_return(char *a, INT32 id)
b2d75f1999-10-25Fredrik Hübinette (Hubbe) { switch(EXTRACT_UCHAR(a)) { case T_OR: {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *ar, *br, *ret=0;
b2d75f1999-10-25Fredrik Hübinette (Hubbe)  a++; ar=zzap_function_return(a,id); br=zzap_function_return(a+type_length(a),id);
4d7b181999-12-07Fredrik Hübinette (Hubbe)  if(ar && br) ret=or_pike_types(ar,br,0);
d68a072001-02-20Henrik Grubbström (Grubba)  if(ar) free_type(ar); if(br) free_type(br);
b2d75f1999-10-25Fredrik Hübinette (Hubbe)  return ret; } case T_FUNCTION: type_stack_mark(); push_type_int(id); push_type(1); push_type(T_OBJECT); type_stack_mark(); a++; while(EXTRACT_UCHAR(a)!=T_MANY) { type_stack_mark(); push_unfinished_type(a); type_stack_reverse(); a+=type_length(a); } a++; push_type(T_MANY); type_stack_mark(); push_unfinished_type(a); type_stack_reverse(); type_stack_reverse(); push_type(T_FUNCTION); return pop_unfinished_type();
a0b73f2000-01-03Martin Stjernholm  case T_ARRAY: return zzap_function_return(a+1,id);
3002342000-02-29Henrik Grubbström (Grubba)  case T_MIXED: /* I wonder when this occurrs, but apparently it does... */ return zzap_function_return(tFuncV(tVoid,tOr(tMix,tVoid),tObj), id);
b2d75f1999-10-25Fredrik Hübinette (Hubbe)  }
a4a1722000-12-05Per Hedbor /* This error is bogus /Hubbe
6b4a2b1999-10-31Henrik Grubbström (Grubba)  fatal("zzap_function_return() called with unexpected value: %d\n", EXTRACT_UCHAR(a));
2d47b91999-11-27Fredrik Hübinette (Hubbe) */
6b4a2b1999-10-31Henrik Grubbström (Grubba)  return NULL;
b2d75f1999-10-25Fredrik Hübinette (Hubbe) }
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *get_type_of_svalue(struct svalue *s)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *ret;
5267b71995-08-09Fredrik Hübinette (Hubbe)  switch(s->type) { case T_FUNCTION:
bdb5091996-09-25Fredrik Hübinette (Hubbe)  if(s->subtype == FUNCTION_BUILTIN)
5267b71995-08-09Fredrik Hübinette (Hubbe)  { ret=s->u.efun->type; }else{ struct program *p; p=s->u.object->prog; if(!p) {
e5e0d91999-12-13Henrik Grubbström (Grubba)  ret=zero_type_string;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{ ret=ID_FROM_INT(p,s->subtype)->type; } } reference_shared_string(ret); return ret;
e5e0d91999-12-13Henrik Grubbström (Grubba)  case T_MULTISET:
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_ARRAY:
e5e0d91999-12-13Henrik Grubbström (Grubba)  {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *arg_type;
e5e0d91999-12-13Henrik Grubbström (Grubba)  struct array *a; if (s->type == T_MULTISET) { a = s->u.multiset->ind; } else { a = s->u.array; }
502d851999-12-30Martin Stjernholm #if 0 int i;
e5e0d91999-12-13Henrik Grubbström (Grubba)  /* FIXME: Circular structures? */ copy_shared_string(arg_type, zero_type_string); for (i = 0; i < a->size; i++) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *tmp1 = get_type_of_svalue(a->item+i); struct pike_type *tmp2 = or_pike_types(arg_type, tmp1, 1); free_type(arg_type); free_type(tmp1);
e5e0d91999-12-13Henrik Grubbström (Grubba)  arg_type = tmp2; } #else /* !0 */
502d851999-12-30Martin Stjernholm  if (a->size) copy_shared_string(arg_type, mixed_type_string); else copy_shared_string(arg_type, zero_type_string);
e5e0d91999-12-13Henrik Grubbström (Grubba) #endif /* 0 */ type_stack_mark(); push_unfinished_type(arg_type->str);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(arg_type);
e5e0d91999-12-13Henrik Grubbström (Grubba)  push_type(s->type); return pop_unfinished_type(); }
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_MAPPING:
3db32a1997-03-04Fredrik Hübinette (Hubbe)  type_stack_mark();
57a4ab2000-01-27Fredrik Hübinette (Hubbe)  if (m_sizeof(s->u.mapping)) {
502d851999-12-30Martin Stjernholm  push_type(T_MIXED); push_type(T_MIXED); } else { push_type(T_ZERO); push_type(T_ZERO); }
5267b71995-08-09Fredrik Hübinette (Hubbe)  push_type(T_MAPPING);
3db32a1997-03-04Fredrik Hübinette (Hubbe)  return pop_unfinished_type();
5267b71995-08-09Fredrik Hübinette (Hubbe) 
041a731996-11-12Mirar (Pontus Hagland)  case T_OBJECT:
3db32a1997-03-04Fredrik Hübinette (Hubbe)  type_stack_mark(); if(s->u.object->prog) {
b2d75f1999-10-25Fredrik Hübinette (Hubbe) #ifdef AUTO_BIGNUM if(is_bignum_object(s->u.object)) { push_type_int(MAX_INT32); push_type_int(MIN_INT32); push_type(T_INT); } else #endif { push_type_int(s->u.object->prog->id); push_type(1); push_type(T_OBJECT); }
3db32a1997-03-04Fredrik Hübinette (Hubbe)  }else{
e5e0d91999-12-13Henrik Grubbström (Grubba)  /* Destructed object */ push_type(T_ZERO);
3db32a1997-03-04Fredrik Hübinette (Hubbe)  } return pop_unfinished_type();
041a731996-11-12Mirar (Pontus Hagland) 
e82b301997-01-29Fredrik Hübinette (Hubbe)  case T_INT: if(s->u.integer) {
b660c81999-03-01Fredrik Hübinette (Hubbe)  type_stack_mark();
b2d75f1999-10-25Fredrik Hübinette (Hubbe)  /* Fixme, check that the integer is in range of MIN_INT32 .. MAX_INT32! */
b660c81999-03-01Fredrik Hübinette (Hubbe)  push_type_int(s->u.integer); push_type_int(s->u.integer); push_type(T_INT); return pop_unfinished_type();
e82b301997-01-29Fredrik Hübinette (Hubbe)  }else{
93dd411999-11-23Henrik Grubbström (Grubba)  ret=zero_type_string;
e82b301997-01-29Fredrik Hübinette (Hubbe)  } reference_shared_string(ret); return ret;
9f68471997-03-08Fredrik Hübinette (Hubbe)  case T_PROGRAM: { char *a;
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *tmp;
993ba72000-02-15Fredrik Hübinette (Hubbe)  int id;
da77e22000-09-08Fredrik Hübinette (Hubbe)  if(s->u.program->identifiers)
993ba72000-02-15Fredrik Hübinette (Hubbe)  {
da77e22000-09-08Fredrik Hübinette (Hubbe)  id=FIND_LFUN(s->u.program,LFUN_CREATE); if(id>=0) { a=ID_FROM_INT(s->u.program, id)->type->str; if((tmp=zzap_function_return(a, s->u.program->id))) return tmp; tmp=describe_type(ID_FROM_INT(s->u.program, id)->type); /* yywarning("Failed to zzap function return for type: %s.", tmp->str);*/ free_string(tmp); }
81c8202000-09-10Henrik Grubbström (Grubba)  } else { a=function_type_string->str; if((tmp=zzap_function_return(a, s->u.program->id))) return tmp;
9f68471997-03-08Fredrik Hübinette (Hubbe)  }
2d47b91999-11-27Fredrik Hübinette (Hubbe) 
da77e22000-09-08Fredrik Hübinette (Hubbe)  a=tFunc( tNone ,tObj);
2d47b91999-11-27Fredrik Hübinette (Hubbe)  if((tmp=zzap_function_return(a, s->u.program->id))) return tmp; fatal("Completely failed to zzap function return!\n");
9f68471997-03-08Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  default:
3db32a1997-03-04Fredrik Hübinette (Hubbe)  type_stack_mark();
5267b71995-08-09Fredrik Hübinette (Hubbe)  push_type(s->type);
3db32a1997-03-04Fredrik Hübinette (Hubbe)  return pop_unfinished_type();
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
d68a072001-02-20Henrik Grubbström (Grubba) static struct pike_type *low_object_type_to_program_type(char *obj_t)
6334d21999-12-22Henrik Grubbström (Grubba) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *res = NULL; struct pike_type *sub;
6334d21999-12-22Henrik Grubbström (Grubba)  struct svalue sval; int id; while(EXTRACT_UCHAR(obj_t) == T_OR) { obj_t++; sub = low_object_type_to_program_type(obj_t); if (!sub) { if (res) {
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(res);
6334d21999-12-22Henrik Grubbström (Grubba)  } return NULL; } if (res) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *tmp = or_pike_types(res, sub, 1); free_type(res); free_type(sub);
6334d21999-12-22Henrik Grubbström (Grubba)  res = tmp; } else { res = sub; } obj_t += type_length(obj_t); } sval.type = T_PROGRAM; if ((EXTRACT_UCHAR(obj_t) != T_OBJECT) || (!(id = extract_type_int(obj_t + 2))) || (!(sval.u.program = id_to_program(id))) || (!(sub = get_type_of_svalue(&sval)))) { if (res) {
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(res);
6334d21999-12-22Henrik Grubbström (Grubba)  } return NULL; }
0b57922000-03-23Henrik Grubbström (Grubba)  /* FIXME: obj_t + 1 should propagate to the return-type in sub. */
6334d21999-12-22Henrik Grubbström (Grubba)  if (res) {
d68a072001-02-20Henrik Grubbström (Grubba)  struct pike_type *tmp = or_pike_types(res, sub, 1); free_type(res); free_type(sub);
6334d21999-12-22Henrik Grubbström (Grubba)  return tmp; } return sub; } /* Used by fix_object_program_type() */
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *object_type_to_program_type(struct pike_type *obj_t)
6334d21999-12-22Henrik Grubbström (Grubba) { return low_object_type_to_program_type(obj_t->str); }
5267b71995-08-09Fredrik Hübinette (Hubbe) char *get_name_of_type(int t) { switch(t) { case T_ARRAY: return "array";
45c8971997-01-03Fredrik Hübinette (Hubbe)  case T_FLOAT: return "float"; case T_FUNCTION: return "function"; case T_INT: return "int"; case T_LVALUE: return "lvalue";
5267b71995-08-09Fredrik Hübinette (Hubbe)  case T_MAPPING: return "mapping";
06983f1996-09-22Fredrik Hübinette (Hubbe)  case T_MULTISET: return "multiset";
45c8971997-01-03Fredrik Hübinette (Hubbe)  case T_OBJECT: return "object"; case T_PROGRAM: return "program"; case T_STRING: return "string";
fc0ad41999-12-11Henrik Grubbström (Grubba)  case T_TYPE: return "type";
93dd411999-11-23Henrik Grubbström (Grubba)  case T_ZERO: return "zero";
3c04e81997-03-13Fredrik Hübinette (Hubbe)  case T_VOID: return "void";
e080e72000-09-04Martin Stjernholm  case T_MAPPING_DATA: return "mapping_data";
5267b71995-08-09Fredrik Hübinette (Hubbe)  default: return "unknown"; } }
be478c1997-08-30Henrik Grubbström (Grubba) void cleanup_pike_types(void)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(string_type_string); free_type(int_type_string); free_type(float_type_string); free_type(function_type_string); free_type(object_type_string); free_type(program_type_string); free_type(array_type_string); free_type(multiset_type_string); free_type(mapping_type_string); free_type(type_type_string); free_type(mixed_type_string); free_type(void_type_string); free_type(zero_type_string); free_type(any_type_string); free_type(weak_type_string);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
b477901998-06-05Fredrik Hübinette (Hubbe)  int type_may_overload(char *type, int lfun) { switch(EXTRACT_UCHAR(type++)) { case T_ASSIGN: return type_may_overload(type+1,lfun); case T_FUNCTION: case T_ARRAY: /* might want to check for `() */ default: return 0; case T_OR: return type_may_overload(type,lfun) || type_may_overload(type+type_length(type),lfun); case T_AND: return type_may_overload(type,lfun) && type_may_overload(type+type_length(type),lfun); case T_NOT: return !type_may_overload(type,lfun); case T_MIXED: return 1; case T_OBJECT: {
b660c81999-03-01Fredrik Hübinette (Hubbe)  struct program *p=id_to_program(extract_type_int(type+1));
b477901998-06-05Fredrik Hübinette (Hubbe)  if(!p) return 1; return FIND_LFUN(p, lfun)!=-1; } } }
20ea771999-12-15Fredrik Hübinette (Hubbe) 
d68a072001-02-20Henrik Grubbström (Grubba) void yyexplain_nonmatching_types(struct pike_type *type_a, struct pike_type *type_b,
03318e2000-03-16Fredrik Hübinette (Hubbe)  int flags)
20ea771999-12-15Fredrik Hübinette (Hubbe) { implements_a=0; implements_b=0; match_types(type_a,type_b);
0b57922000-03-23Henrik Grubbström (Grubba) #if 0
20ea771999-12-15Fredrik Hübinette (Hubbe)  if(!(implements_a && implements_b && type_a->str[0]==T_OBJECT && type_b->str[0]==T_OBJECT))
0b57922000-03-23Henrik Grubbström (Grubba) #endif /* 0 */
20ea771999-12-15Fredrik Hübinette (Hubbe)  { struct pike_string *s1,*s2; s1=describe_type(type_a); s2=describe_type(type_b);
03318e2000-03-16Fredrik Hübinette (Hubbe)  if(flags & YYTE_IS_WARNING) { yywarning("Expected: %s",s1->str); yywarning("Got : %s",s2->str); }else{ my_yyerror("Expected: %s",s1->str); my_yyerror("Got : %s",s2->str); }
20ea771999-12-15Fredrik Hübinette (Hubbe)  free_string(s1); free_string(s2); } if(implements_a && implements_b)
03318e2000-03-16Fredrik Hübinette (Hubbe)  yyexplain_not_implements(implements_a,implements_b,flags);
20ea771999-12-15Fredrik Hübinette (Hubbe) }
95a83d1999-12-26Henrik Grubbström (Grubba) 
d68a072001-02-20Henrik Grubbström (Grubba) struct pike_type *make_pike_type(char *t)
95a83d1999-12-26Henrik Grubbström (Grubba) { return make_shared_binary_string(t, type_length(t)); }
d4a1362001-02-09Fredrik Hübinette (Hubbe)  int pike_type_allow_premature_toss(char *type) { again: switch(EXTRACT_UCHAR(type++)) { case T_NOT: return !pike_type_allow_premature_toss(type); case T_OBJECT: case T_MIXED: case T_FUNCTION: return 0; case T_SCOPE: case T_ASSIGN: type++; goto again; case T_OR: case T_MAPPING: if(!pike_type_allow_premature_toss(type)) return 0; case T_AND: type+=type_length(type); case T_ARRAY: case T_MULTISET: goto again; case T_PROGRAM: case T_INT: case T_FLOAT: case T_STRING: return 1; }
d68a072001-02-20Henrik Grubbström (Grubba)  /* NOT_REACHED */ return 0;
d4a1362001-02-09Fredrik Hübinette (Hubbe) }