Branch: Tag:

2008-05-03

2008-05-03 20:06:07 by Henrik Grubbström (Grubba) <grubba@grubba.org>

First go at warning for deprecated symbols.
Added CompilerEnvironment()->PikeCompiler()->{push,pop}_type_attribute().
pike_types_le() now calls the above when encountering asymmetric attribute types.
Added some tests for the above.

Rev: src/pike_compiler.h:1.11
Rev: src/pike_types.c:1.324
Rev: src/program.c:1.686
Rev: src/testsuite.in:1.804

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: program.c,v 1.685 2008/05/03 15:54:13 grubba Exp $ + || $Id: program.c,v 1.686 2008/05/03 20:06:06 grubba Exp $   */      #include "global.h"
8393:    }   }    + /*! @decl int(0..1) pop_type_attribute(string attribute, @ +  *! type a, type b) +  *! +  *! Type attribute handler. +  *! +  *! Called during type checking when @expr{a <= b@} and +  *! @[a] had the type attribute @[attribute] before the +  *! comparison. +  *! +  *! The default implementation implements the "deprecated" +  *! attribute. +  *! +  *! @returns +  *! Returns @expr{1@} if the type check should be allowed +  *! (ie @expr{__attribute__(attribute, a) <= b@}), and +  *! @expr{0@} (zero) otherwise. +  *! +  *! @seealso +  *! @[push_type_attribute()] +  */ + static void f_compilation_pop_type_attribute(INT32 args) + { +  struct pike_string *attr; +  struct svalue *a, *b; +  struct compilation *c = THIS_COMPILATION; +  struct pike_string *deprecated_string; +  +  get_all_args("pop_type_attribute", args, "%W%*%*", &attr, &a, &b); +  +  if (Pike_compiler->compiler_pass == 2) { +  MAKE_CONST_STRING(deprecated_string, "deprecated"); +  if (attr == deprecated_string) { +  push_int(REPORT_WARNING); +  ref_push_string(c->lex.current_file); +  push_int(c->lex.current_line); +  push_constant_text("type_check"); +  push_constant_text("Using deprecated %O value."); +  push_svalue(a); +  apply_current(PC_REPORT_FUN_NUM, 6); +  args++; +  } +  } +  pop_n_elems(args); +  push_int(1); + } +  + /*! @decl int(0..1) push_type_attribute(string attribute, @ +  *! type a, type b) +  *! +  *! Type attribute handler. +  *! +  *! Called during type checking when @expr{a <= b@} and +  *! @[b] had the type attribute @[attribute] before the +  *! comparison. +  *! +  *! The default implementation implements the "deprecated" +  *! attribute. +  *! +  *! @returns +  *! Returns @expr{1@} if the type check should be allowed +  *! (ie @expr{a <= __attribute__(attribute, b)@}), and +  *! @expr{0@} (zero) otherwise. +  *! +  *! @seealso +  *! @[pop_type_attribute()] +  */ + static void f_compilation_push_type_attribute(INT32 args) + { +  struct pike_string *attr; +  struct svalue *a, *b; +  struct compilation *c = THIS_COMPILATION; +  struct pike_string *deprecated_string; +  +  get_all_args("push_type_attribute", args, "%W%*%*", &attr, &a, &b); +  +  if (Pike_compiler->compiler_pass == 2) { +  MAKE_CONST_STRING(deprecated_string, "deprecated"); +  if (attr == deprecated_string && +  !((a->type == PIKE_T_TYPE) && (a->u.type == zero_type_string))) { +  /* Don't warn about setting deprecated values to zero. */ +  push_int(REPORT_WARNING); +  ref_push_string(c->lex.current_file); +  push_int(c->lex.current_line); +  push_constant_text("type_check"); +  push_constant_text("Using deprecated %O value."); +  push_svalue(b); +  apply_current(PC_REPORT_FUN_NUM, 6); +  args++; +  } +  } +  pop_n_elems(args); +  push_int(1); + } +    static void f_compilation__sprintf(INT32 args)   {    struct compilation *c = THIS_COMPILATION;
8664:    ADD_FUNCTION("handle_inherit", f_compilation_handle_inherit,    tFunc(tStr, tPrg(tObj)), 0);    +  ADD_FUNCTION("pop_type_attribute", f_compilation_pop_type_attribute, +  tFunc(tStr tType(tMix) tType(tMix), tInt01), 0); +  +  ADD_FUNCTION("push_type_attribute", f_compilation_push_type_attribute, +  tFunc(tStr tType(tMix) tType(tMix), tInt01), 0); +     ADD_FUNCTION("_sprintf", f_compilation__sprintf,    tFunc(tInt tOr(tMap(tStr, tMix), tVoid), tStr), ID_STATIC);