Branch: Tag:

2004-12-22

2004-12-22 18:46:15 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Various object subtype related fixes and FIXME:s.

Rev: src/array.c:1.178
Rev: src/backend.cmod:1.148
Rev: src/builtin_functions.c:1.584
Rev: src/cpp.c:1.157
Rev: src/error.c:1.143
Rev: src/interpret.c:1.360
Rev: src/iterators.cmod:1.57
Rev: src/language.yacc:1.352

2:   || 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.583 2004/12/22 12:45:37 grubba Exp $ + || $Id: builtin_functions.c,v 1.584 2004/12/22 18:46:15 grubba Exp $   */      #include "global.h"
856:    return;       case T_OBJECT: -  if (Pike_sp[-args].u.object->prog) { +  { +  struct program *p; +  if ((p = (Pike_sp[-args].u.object->prog))) {    struct object *o = Pike_sp[-args].u.object; -  struct program *p = o->prog; -  /* NOTE: Fake lfun! */ -  int id = low_find_lfun(p, LFUN__SEARCH); +  int id_level = p->inherits[Pike_sp[-args].subtype].identifier_level; +  int id;    int next, ind; -  +  p = p->inherits[Pike_sp[-args].subtype].prog;    -  +  /* NOTE: Fake lfun! */ +  id = low_find_lfun(p, LFUN__SEARCH);    /* First try lfun::_search(). */    if (id >= 0) { -  apply_low(o, id, args-1); +  apply_low(o, id + id_level, args-1);    stack_pop_n_elems_keep_top(1);    return;    }
876:    ((ind = find_identifier("index", p)) >= 0)) {    /* We have an iterator. */    +  id += id_level; +  next += id_level; +  ind += id_level; +     /* Set the start position if needed. */    if (args > 2) { -  apply(o, "set_index", args-2); +  int fun = find_identifier("set_index", p); +  if (fun < 0) +  Pike_error ("Cannot call unknown function \"%s\".\n", fun); +  apply_low(o, fun + id_level, args-2);    pop_stack();    }   
906:    }    }    } +  }    /* FALL_THROUGH */    default:    SIMPLE_BAD_ARG_ERROR("search", 1, "string|array|mapping|object");
1193:    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 +  use `search' directly since it's undefined whether it returns    -1 (array) or 0 (mapping) during e.g. some data type emulation.       Maybe we should use object->_has_value(value) provided that
2424:    break;       case T_OBJECT: +  /* FIXME: Object subtype! */    a=object_indices(Pike_sp[-args].u.object);    break;   
2722:    break;       case T_OBJECT: +  /* FIXME: Object subtype! */    a=object_values(Pike_sp[-args].u.object);    break;   
2830:    if(p)    {    p = p->inherits[Pike_sp[-args].subtype].prog; +  /* FIXME: Does the following actually work for +  * the object subtype case? +  */    if((p->flags & PROGRAM_USES_PARENT) &&    PARENT_INFO(o)->parent &&    PARENT_INFO(o)->parent->prog)
3414:    case 3:    SIMPLE_BAD_ARG_ERROR("compile", 4, "int");    default: -  if(Pike_sp[5-args].type == T_OBJECT) +  if(Pike_sp[5-args].type == T_OBJECT) { +  if (Pike_sp[5-args].subtype) { +  Pike_error("compile: " +  "Subtyped placeholder objects are not supported yet.\n"); +  }    placeholder=Pike_sp[5-args].u.object; -  +  }       case 5:    if(Pike_sp[4-args].type == T_PROGRAM)
3426:    minor=Pike_sp[3-args].u.integer;       case 2: -  if(Pike_sp[1-args].type == T_OBJECT) +  if(Pike_sp[1-args].type == T_OBJECT) { +  if (Pike_sp[5-args].subtype) { +  Pike_error("compile: " +  "Subtyped handler objects are not supported yet.\n"); +  }    o=Pike_sp[1-args].u.object; -  +  }       case 0: case 1: break;    }
3571:    res = 1;    break;    case T_OBJECT: -  if( Pike_sp[-args].u.object->prog && -  FIND_LFUN( Pike_sp[-args].u.object->prog, LFUN_CALL ) != -1 ) +  { +  struct program *p; +  if((p = Pike_sp[-args].u.object->prog) && +  FIND_LFUN(p->inherits[Pike_sp[-args].subtype].prog, +  LFUN_CALL ) != -1)    res = 1; -  +  }    break;    case T_ARRAY: -  +  /* FIXME: What about the recursive case? */    array_fix_type_field(Pike_sp[-args].u.array);    if( (Pike_sp[-args].u.array->type_field==BIT_CALLABLE) ||    !Pike_sp[-args].u.array->type_field) {
3871:   #endif       - #define TYPEP(ID,NAME,TYPE,TYPE_NAME) \ - PMOD_EXPORT void ID(INT32 args) \ - { \ -  int t; \ -  if(args<1) \ + #define TYPEP(ID,NAME,TYPE,TYPE_NAME) \ +  PMOD_EXPORT void ID(INT32 args) \ +  { \ +  int t; \ +  struct program *p; \ +  if (args<1) \    SIMPLE_TOO_FEW_ARGS_ERROR(NAME, 1); \ -  if(Pike_sp[-args].type == T_OBJECT && Pike_sp[-args].u.object->prog) \ -  { \ -  int fun=FIND_LFUN(Pike_sp[-args].u.object->prog,LFUN__IS_TYPE); \ -  if(fun != -1) \ -  { \ -  push_constant_text(TYPE_NAME); \ -  apply_low(Pike_sp[-args-1].u.object,fun,1); \ -  stack_unlink(args); \ -  return; \ -  } \ -  } \ -  t=Pike_sp[-args].type == TYPE; \ -  pop_n_elems(args); \ +  if (Pike_sp[-args].type == T_OBJECT && \ +  (p = Pike_sp[-args].u.object->prog)) \ +  { \ +  int fun = FIND_LFUN(p->inherits[Pike_sp[-args].subtype].prog, \ +  LFUN__IS_TYPE); \ +  if (fun != -1) \ +  { \ +  int id_level = \ +  p->inherits[Pike_sp[-args].subtype].identifier_level; \ +  push_constant_text(TYPE_NAME); \ +  apply_low(Pike_sp[-args-1].u.object, fun + id_level, 1); \ +  stack_unlink(args); \ +  return; \ +  } \ +  } \ +  t = Pike_sp[-args].type == TYPE; \ +  pop_n_elems(args); \    push_int(t); \   }   
6426:    bad_arg_error("replace_master", Pike_sp-args, args, 1, "object", Pike_sp-args,    "Called with destructed object.\n");    +  if (Pike_sp[-args].subtype) +  bad_arg_error("replace_master", Pike_sp-args, args, 1, "object", Pike_sp-args, +  "Subtyped master objects are not supported yet.\n"); +     free_object(master_object);    master_object=Pike_sp[-args].u.object;    add_ref(master_object);
7195:    pop_stack();       push_constant_text("array"); +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_ARRAY)    {
7207:    pop_stack();       push_constant_text("mapping"); +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_MAPPING)    {
7219:    pop_stack();       push_constant_text("multiset"); +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_MULTISET)    {
7623:    pop_stack();       push_constant_text("array"); +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_ARRAY)    {
7635:    pop_stack();       push_constant_text("mapping"); +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_MAPPING)    {
7647:    pop_stack();       push_constant_text("multiset"); +  /* FIXME: Object subtype! */    safe_apply(mysp[-3].u.object,"cast",1);    if (Pike_sp[-1].type==T_MULTISET)    {