Branch: Tag:

2013-04-28

2013-04-28 18:03:09 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler: Repurposed reference_inherited_identifier().

The previously unused function reference_inherited_identifier() is
now analogous to the low_* and really_low_* variants, and exported.

1978:    }       /* Find ::name in the parent. */ -  i = -1; -  for (e = parent->num_inherits; e--;) { -  if (parent->inherits[e].inherit_level != 1) continue; -  i = low_reference_inherited_identifier(state->previous, e, -  name, SEE_PROTECTED); -  if (i != -1) break; -  } +  i = reference_inherited_identifier(state->previous, NULL, name);    if (i == -1) {    my_yyerror("Failed to find previous inherited definition of %S "    "in parent.", name);
4334:    return 0;   }    - /* Reference the symbol super_name::function_name */ - node *reference_inherited_identifier(struct pike_string *super_name, -  struct pike_string *function_name) + /* Reference the symbol inherit::name in the lexical context +  * specified by state. +  * +  * Returns the reference in state->new_program if found. +  */ + PMOD_EXPORT int reference_inherited_identifier(struct program_state *state, +  struct pike_string *inherit, +  struct pike_string *name)   { -  int n,e,id; -  struct compilation *c = THIS_COMPILATION; -  struct program_state *state=Pike_compiler->previous; -  +  int e, id;    struct program *p;    -  +    #ifdef PIKE_DEBUG -  if(function_name!=debug_findstring(function_name)) -  Pike_fatal("reference_inherited_function on nonshared string.\n"); +  if (name != debug_findstring(name)) +  Pike_fatal("reference_inherited_identifier on nonshared string.\n");   #endif    -  p=Pike_compiler->new_program; +  if (!state) state = Pike_compiler;    -  /* FIXME: This loop could be optimized by advancing by the number -  * of inherits in the inherit. But in that case the loop -  * would have to go the other way. -  */ -  for(e=p->num_inherits-1;e>0;e--) -  { -  if(p->inherits[e].inherit_level!=1) continue; -  if(!p->inherits[e].name) continue; +  p = Pike_compiler->new_program;    -  if(super_name) -  if(super_name != p->inherits[e].name) -  continue; -  -  id=low_reference_inherited_identifier(0, -  e, -  function_name, -  SEE_PROTECTED); -  -  if(id!=-1) -  return mkidentifiernode(id); -  -  if(ISCONSTSTR(function_name,"`->") || -  ISCONSTSTR(function_name,"`[]")) -  { -  return mknode(F_MAGIC_INDEX,mknewintnode(e),mknewintnode(0)); -  } -  -  if(ISCONSTSTR(function_name,"`->=") || -  ISCONSTSTR(function_name,"`[]=")) -  { -  return mknode(F_MAGIC_SET_INDEX,mknewintnode(e),mknewintnode(0)); -  } -  -  if(ISCONSTSTR(function_name,"_indices")) -  { -  return mknode(F_MAGIC_INDICES,mknewintnode(e),mknewintnode(0)); -  } -  -  if(ISCONSTSTR(function_name,"_values")) -  { -  return mknode(F_MAGIC_VALUES,mknewintnode(e),mknewintnode(0)); -  } -  } -  -  -  for(n=0;n<c->compilation_depth;n++,state=state->previous) -  { -  struct program *p=state->new_program; -  +     /* FIXME: This loop could be optimized by advancing by the number    * of inherits in the inherit. But in that case the loop    * would have to go the other way.    */ -  for(e=p->num_inherits-1;e>0;e--) -  { -  if(p->inherits[e].inherit_level!=1) continue; -  if(!p->inherits[e].name) continue; +  for (e = p->num_inherits; e--;) { +  if (p->inherits[e].inherit_level != 1) continue; +  if (!p->inherits[e].name) continue;    -  if(super_name) -  if(super_name != p->inherits[e].name) -  continue; +  if (inherit && (inherit != p->inherits[e].name)) continue;    -  id=low_reference_inherited_identifier(state,e,function_name,SEE_PROTECTED); +  id = low_reference_inherited_identifier(state, e, name, SEE_PROTECTED);    -  if(id!=-1) -  return mkexternalnode(p, id); -  -  if(ISCONSTSTR(function_name,"`->") || -  ISCONSTSTR(function_name,"`[]")) -  { -  return mknode(F_MAGIC_INDEX, -  mknewintnode(e),mknewintnode(n+1)); +  if (id != -1) return id;    }    -  if(ISCONSTSTR(function_name,"`->=") || -  ISCONSTSTR(function_name,"`[]=")) -  { -  return mknode(F_MAGIC_SET_INDEX, -  mknewintnode(e),mknewintnode(n+1)); +  return -1;   }    -  if(ISCONSTSTR(function_name,"_indices")) -  { -  return mknode(F_MAGIC_INDICES, -  mknewintnode(e),mknewintnode(n+1)); -  } -  -  if(ISCONSTSTR(function_name,"_values")) -  { -  return mknode(F_MAGIC_VALUES, -  mknewintnode(e),mknewintnode(n+1)); -  } -  } -  } -  -  return 0; - } -  +    /* FIXME: This function probably doesn't do what it is intended to do    * if the last inherit had inherits of its own. Consider removal.    */