pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.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: builtin_functions.c,v 1.493 2003/05/15 15:33:30 mast Exp $ + || $Id: builtin_functions.c,v 1.494 2003/06/03 18:45:51 mast Exp $   */      #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.493 2003/05/15 15:33:30 mast Exp $"); + RCSID("$Id: builtin_functions.c,v 1.494 2003/06/03 18:45:51 mast Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"   #include "constants.h"   #include "mapping.h"   #include "stralloc.h"
pike.git/src/builtin_functions.c:875:    Pike_error("has_prefix(): Unexpected string shift combination: a:%d, b:%d!\n",    a->size_shift, b->size_shift);    break;    }   #undef CASE_SHIFT   #undef TWO_SHIFTS   }      /*! @decl int has_index(string haystack, int index)    *! @decl int has_index(array haystack, int index) -  *! @decl int has_index(mapping haystack, mixed index) +  *! @decl int has_index(mapping|multiset|object|program haystack, mixed index)    *!    *! Search for @[index] in @[haystack].    *!    *! @returns    *! Returns @expr{1@} if @[index] is in the index domain of @[haystack],    *! or @expr{0@} (zero) if not found.    *!    *! This function is equivalent to (but sometimes faster than):    *!    *! @code
pike.git/src/builtin_functions.c:937:    f_zero_type(1);       if(Pike_sp[-1].type == T_INT)    Pike_sp[-1].u.integer = !Pike_sp[-1].u.integer;    else    PIKE_ERROR("has_index",    "Function `zero_type' gave incorrect result.\n", Pike_sp, args);    break;       case T_OBJECT: +  case T_PROGRAM:    /* FIXME: If the object behaves like an array, it will throw an    error for non-valid indices. Therefore it's not a good idea    to use the index operator.       Maybe we should use object->_has_index(index) provided that    the object implements it.       /Noring */    -  /* Fall-through. */ -  -  default: +     stack_swap();    f_indices(1);    stack_swap();    f_search(2);       if(Pike_sp[-1].type == T_INT)    Pike_sp[-1].u.integer = (Pike_sp[-1].u.integer != -1);    else    PIKE_ERROR("has_index",    "Function `search' gave incorrect result.\n", Pike_sp, args); -  +  break; +  +  default: +  SIMPLE_ARG_TYPE_ERROR ("has_index", 1, +  "string|array|mapping|multiset|object|program");    }   }      /*! @decl int has_value(string haystack, string value)    *! @decl int has_value(string haystack, int value) -  *! @decl int has_value(array haystack, int value) -  *! @decl int has_value(mapping haystack, mixed value) +  *! @decl int has_value(array|mapping|object|program haystack, mixed value)    *!    *! Search for @[value] in @[haystack].    *!    *! @returns    *! Returns @expr{1@} if @[value] is in the value domain of @[haystack],    *! or @expr{0@} (zero) if not found.    *!    *! This function is in all cases except when both arguments are strings    *! equivalent to (but sometimes faster than):    *!
pike.git/src/builtin_functions.c:1009:    f_search(2);    f_zero_type(1);       if(Pike_sp[-1].type == T_INT)    Pike_sp[-1].u.integer = !Pike_sp[-1].u.integer;    else    PIKE_ERROR("has_value",    "Function `zero_type' gave incorrect result.\n", Pike_sp, args);    break;    +  case T_PROGRAM:    case T_OBJECT:    /* FIXME: It's very sad that we always have to do linear search    with `values' in case of objects. The problem is that we cannot    use `search' directly since it's undefined weather it returns    -1 (array) or 0 (mapping) during e.g. some data type emulation.       Maybe we should use object->_has_value(value) provided that    the object implements it.       /Noring */       /* FALL_THROUGH */    -  default: +  case T_MULTISET: +  /* FIXME: This behavior for multisets isn't clean. It should be +  * compat only. */    stack_swap();    f_values(1);    stack_swap();    -  +  /* FALL_THROUGH */ +     case T_STRING: /* Strings are odd. /Noring */    case T_ARRAY:    f_search(2);       if(Pike_sp[-1].type == T_INT)    Pike_sp[-1].u.integer = (Pike_sp[-1].u.integer != -1);    else    PIKE_ERROR("has_value", "Search gave incorrect result.\n", Pike_sp, args); -  +  break; +  +  default: +  SIMPLE_ARG_TYPE_ERROR ("has_value", 1, "string|array|mapping|object|program");    }   }      /*! @decl void add_constant(string name, mixed value)    *! @decl void add_constant(string name)    *!    *! Add a new predefined constant.    *!    *! This function is often used to add builtin functions.    *! All programs compiled after the @[add_constant()] function has been