pike.git / src / pike_types.c

version» Context lines:

pike.git/src/pike_types.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include "global.h" - RCSID("$Id: pike_types.c,v 1.31 1998/02/20 00:55:23 hubbe Exp $"); + RCSID("$Id: pike_types.c,v 1.32 1998/02/23 23:24:04 hubbe Exp $");   #include <ctype.h>   #include "svalue.h"   #include "pike_types.h"   #include "stralloc.h"   #include "stuff.h"   #include "array.h"   #include "program.h"   #include "constants.h"   #include "object.h"   #include "multiset.h"
pike.git/src/pike_types.c:638:    }   }      TYPE_T compile_type_to_runtime_type(struct pike_string *s)   {    return low_compile_type_to_runtime_type(s->str);   }      #define A_EXACT 1   #define B_EXACT 2 + #define NO_MAX_ARGS 4      /*    * match two type strings, return zero if they don't match, and return    * the part of 'a' that _did_ match if it did.    */   static char *low_match_types(char *a,char *b, int flags)   {    int correct_args;    char *ret;    if(a == b) return a;
pike.git/src/pike_types.c:666:    return low_match_types(a,b,flags);       case T_OR:    a++;    ret=low_match_types(a,b,flags);    if(ret) return ret;    a+=type_length(a);    return low_match_types(a,b,flags);       case T_NOT: -  if(low_match_types(a+1,b,flags | B_EXACT)) +  if(low_match_types(a+1,b,flags | B_EXACT | NO_MAX_ARGS))    return 0;    return a;    }       switch(EXTRACT_UCHAR(b))    {    case T_AND:    b++;    ret=low_match_types(a,b,flags);    if(!ret) return 0;
pike.git/src/pike_types.c:688:    return low_match_types(a,b,flags);       case T_OR:    b++;    ret=low_match_types(a,b,flags);    if(ret) return ret;    b+=type_length(b);    return low_match_types(a,b,flags);       case T_NOT: -  if(low_match_types(a,b+1, flags | A_EXACT)) +  if(low_match_types(a,b+1, flags | A_EXACT | NO_MAX_ARGS))    return 0;    return a;    }       /* 'mixed' matches anything */    if(EXTRACT_UCHAR(a) == T_MIXED && !(flags & A_EXACT)) return a;    if(EXTRACT_UCHAR(b) == T_MIXED && !(flags & B_EXACT)) return a;       /* Special cases (tm) */    switch(EXTRACT_TWOT(a,b))
pike.git/src/pike_types.c:756:    }       if(EXTRACT_UCHAR(b)==T_MANY)    {    b_tmp=b+1;    }else{    b_tmp=b;    b+=type_length(b);    }    -  if(!low_match_types(a_tmp, b_tmp, flags)) return 0; +  if(!low_match_types(a_tmp, b_tmp, flags | NO_MAX_ARGS)) return 0;    if(++correct_args > max_correct_args) -  +  if(!(flags & NO_MAX_ARGS))    max_correct_args=correct_args;    }    /* check the 'many' type */    a++;    b++;    if(EXTRACT_UCHAR(b)==T_VOID || EXTRACT_UCHAR(a)==T_VOID)    {    a+=type_length(a);    b+=type_length(b);    }else{ -  if(!low_match_types(a,b,flags)) return 0; +  if(!low_match_types(a,b,flags | NO_MAX_ARGS)) return 0;    } -  +  if(!(flags & NO_MAX_ARGS)) +  max_correct_args=0x7fffffff;    /* check the returntype */    if(!low_match_types(a,b,flags)) return 0;    break;       case T_MAPPING:    if(!low_match_types(++a,++b,flags)) return 0;    if(!low_match_types(a+type_length(a),b+type_length(b),flags)) return 0;    break;       case T_OBJECT:
pike.git/src/pike_types.c:1080:   int check_indexing(struct pike_string *type,    struct pike_string *index_type,    node *n)   {    CHECK_TYPE(type);    CHECK_TYPE(index_type);       return low_check_indexing(type->str, index_type->str, n);   }    - /* Count the number of arguments for a funciton type. -  * return -1-n if the function can take number of arguments -  * >= n (varargs) -  */ - int count_arguments(struct pike_string *s) + static int low_count_arguments(char *q)   { -  int num; -  char *q; +  int num,num2;    -  CHECK_TYPE(s); +  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;    -  q=s->str; -  if(EXTRACT_UCHAR(q) != T_FUNCTION) return MAX_LOCAL; -  q++; +  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; +  +  default: return MAX_LOCAL; +  +  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;    } -  + }    -  + /* Count the number of arguments for a funciton type. +  * return -1-n if the function can take number of arguments +  * >= n (varargs) +  */ + int count_arguments(struct pike_string *s) + { +  CHECK_TYPE(s); +  +  return low_count_arguments(s->str); + } +    struct pike_string *check_call(struct pike_string *args,    struct pike_string *type)   {    CHECK_TYPE(args);    CHECK_TYPE(type);    type_stack_mark();    max_correct_args=0;       if(low_get_return_type(type->str,args->str))    {    return pop_unfinished_type();    }else{    pop_stack_mark();    return 0;    }   }    -  + INT32 get_max_args(struct pike_string *type) + { +  INT32 ret,tmp=max_correct_args; +  CHECK_TYPE(type); +  type=check_call(function_type_string, type); +  if(type) free_string(type); +  ret=max_correct_args; +  max_correct_args=tmp; +  return tmp; + } +    struct pike_string *get_type_of_svalue(struct svalue *s)   {    struct pike_string *ret;    switch(s->type)    {    case T_FUNCTION:    if(s->subtype == FUNCTION_BUILTIN)    {    ret=s->u.efun->type;    }else{