pike.git / src / pike_types.c

version» Context lines:

pike.git/src/pike_types.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: pike_types.c,v 1.329 2008/05/08 15:28:40 grubba Exp $ + || $Id: pike_types.c,v 1.330 2008/05/10 11:53:41 grubba Exp $   */      #include "global.h"   #include <ctype.h>   #include "svalue.h"   #include "pike_types.h"   #include "stralloc.h"   #include "stuff.h"   #include "array.h"   #include "program.h"
pike.git/src/pike_types.c:3439:    {    case TWOT(T_PROGRAM, T_FUNCTION):    case TWOT(T_FUNCTION, T_PROGRAM):    case TWOT(T_PROGRAM, T_MANY):    case TWOT(T_MANY, T_PROGRAM):    /* FIXME: Should look at the sub-type of the program    * to determine the prototype to use.    */    return a;    +  case TWOT(PIKE_T_TYPE, T_FUNCTION): +  case TWOT(PIKE_T_TYPE, T_MANY): +  /* Convert the type to a casting function. */ +  type_stack_mark(); +  push_finished_type(a->car); +  push_type(T_VOID); +  push_type(T_MANY); +  push_type(T_MIXED); +  push_type(T_FUNCTION); +  ret = a; +  a = pop_unfinished_type(); +  if (low_match_types(a, b, flags)) { +  free_type(a); +  return ret; +  } +  free_type(a); +  return NULL; +  +  case TWOT(T_FUNCTION, PIKE_T_TYPE): +  case TWOT(T_MANY, PIKE_T_TYPE): +  /* Convert the type to a casting function. */ +  type_stack_mark(); +  push_finished_type(b->car); +  push_type(T_VOID); +  push_type(T_MANY); +  push_type(T_MIXED); +  push_type(T_FUNCTION); +  b = pop_unfinished_type(); +  ret = low_match_types(a, b, flags); +  free_type(b); +  return ret; +  +  case TWOT(PIKE_T_TYPE, T_PROGRAM): +  case TWOT(T_PROGRAM, PIKE_T_TYPE): +  return low_match_types(a->car, b->car, flags); +     case TWOT(T_OBJECT, T_FUNCTION):    case TWOT(T_OBJECT, T_MANY):    {    struct pike_type *s;    if((s = low_object_lfun_type(a, LFUN_CALL)))    return low_match_types(s, b, flags);    if (flags & B_EXACT) {    /* A function isn't an object */    return 0;    }
pike.git/src/pike_types.c:4094:    switch(TWOT(a->type, b->type))    {    case TWOT(T_PROGRAM, T_FUNCTION):    case TWOT(T_FUNCTION, T_PROGRAM):    case TWOT(T_PROGRAM, T_MANY):    case TWOT(T_MANY, T_PROGRAM):    /* FIXME: Not really... Should check the return value. */    /* FIXME: Should also look at the subtype of the program. */    return 1;    +  case TWOT(PIKE_T_TYPE, T_FUNCTION): +  case TWOT(PIKE_T_TYPE, T_MANY): +  /* Convert the type to a casting function. */ +  type_stack_mark(); +  push_finished_type(a->car); +  push_type(T_VOID); +  push_type(T_MANY); +  push_type(T_MIXED); +  push_type(T_FUNCTION); +  a = pop_unfinished_type(); +  if (low_pike_types_le(a, b, array_cnt, flags)) { +  free_type(a); +  return 1; +  } +  free_type(a); +  return 0; +  +  case TWOT(T_FUNCTION, PIKE_T_TYPE): +  case TWOT(T_MANY, PIKE_T_TYPE): +  /* Convert the type to a casting function. */ +  type_stack_mark(); +  push_finished_type(b->car); +  push_type(T_VOID); +  push_type(T_MANY); +  push_type(T_MIXED); +  push_type(T_FUNCTION); +  b = pop_unfinished_type(); +  if (low_pike_types_le(a, b, array_cnt, flags)) { +  free_type(b); +  return 1; +  } +  free_type(b); +  return 0; +  +  case TWOT(PIKE_T_TYPE, T_PROGRAM): +  case TWOT(T_PROGRAM, PIKE_T_TYPE): +  return low_pike_types_le(a->car, b->car, array_cnt, flags); +     case TWOT(T_OBJECT, T_FUNCTION):    case TWOT(T_OBJECT, T_MANY):    {    if((a = low_object_lfun_type(a, LFUN_CALL))) {    goto recurse;    }    return 1;    }       case TWOT(T_FUNCTION, T_OBJECT):
pike.git/src/pike_types.c:4462:    a = a->cdr;    while(a->type == T_FUNCTION) {    a = a->cdr;    }    /* FALL_THROUGH */    case T_MANY:    a = a->cdr;    push_finished_type_with_markers(a, a_markers, 0);    return 1;    +  case T_TYPE:    case T_PROGRAM:    push_finished_type(a->car);    return 1;       default:    push_type(T_MIXED);    return 1;    }    }    return 0;
pike.git/src/pike_types.c:5436:    }    if (!res) {    switch(soft_type->type) {    case T_VOID:    if (orig_type->type == T_VOID) {    copy_pike_type(res, soft_type);    } else {    return NULL;    }    break; +  case T_TYPE: +  /* Convert to a function returning the subtype and retry. */ +  type_stack_mark(); +  push_finished_type(soft_type->car); +  push_type(T_VOID); +  push_type(T_MANY); +  push_type(T_MIXED); +  push_type(T_FUNCTION); +  tmp = pop_unfinished_type(); +  res = soft_cast(tmp, orig_type, flags); +  break; +     case T_PROGRAM:    /* Convert to a function returning an object. */    copy_pike_type(tmp3, soft_type->car); /* Return type */    if ((tmp2 = low_object_lfun_type(tmp3, LFUN_CREATE))) {    soft_type = tmp2;    tmp2 = NULL;    } else {    /* FIXME: Multiple cases. */    soft_type = function_type_string;    }
pike.git/src/pike_types.c:5866:    }    } else if (!(flags & CALL_LAST_ARG) &&    (fun_type->car->type == T_MANY)) {    /* The next argument might match. */    add_ref(fun_type);    res = fun_type;    }    }    break;    +  case PIKE_T_TYPE: +  /* FIXME: Check that the cast is valid. */ +  type_stack_mark(); +  push_finished_type(fun_type->car); +  push_type(T_VOID); +  push_type(T_MANY); +  res = pop_unfinished_type(); +  break; +     case PIKE_T_PROGRAM:    tmp = low_object_lfun_type(fun_type->car, LFUN_CREATE);    if (!tmp) {    /* No create() -- No arguments. */    /* FIXME: Multiple cases:    * Untyped object. function(mixed|void...:obj)    * Failed to lookup program id. function(mixed|void...:obj)    * Program does not have a create(). function(:obj)    *    * We simply ignore the args.
pike.git/src/pike_types.c:6265:    res = NULL;    break;    }    res = and_pike_types(tmp2 = res, tmp);    free_type(tmp);    free_type(tmp2);    break;    case T_NOT:    /* Doesn't match. */    break; +  case PIKE_T_TYPE: +  /* Casting requires an argument... */ +  res = NULL; +  break;    case PIKE_T_PROGRAM:    tmp = low_object_lfun_type(fun_type->car, LFUN_CREATE);    if (!tmp) {    /* No create(). */    add_ref(fun_type->car);    res = fun_type->car;    break;    } else {    fun_type = zzap_function_return(tmp, fun_type->car);    }
pike.git/src/pike_types.c:6531:    free_type(res);    res = tmp;    } else {    type_stack_mark();    push_finished_type(res);    free_type(res);    push_type(T_NOT);    res = pop_unfinished_type();    }    break; +  case PIKE_T_TYPE: +  /* FIXME: Limit to valid cast operations. */ +  copy_pike_type(res, mixed_type_string); +  break;    case PIKE_T_PROGRAM:    if ((fun_type = low_object_lfun_type(fun_type->car, LFUN_CREATE))) {    /* No need to adjust the return type, since we're only    * looking at the arguments.    */    goto loop;    }    /* FIXME: Multiple cases:    * Untyped object. function(mixed...:object)    * Failed to lookup program id. function(mixed...:object)