On Thu Jun 26 22:21:22 2008, [EMAIL PROTECTED] wrote:
> On Thursday 26 June 2008 20:02:18 Will Coleda via RT wrote:
> 
> > Attached, find a patch that allows us to specify a ":deprecated"
> flag (post
> > op, ala :flow). It also adds a new parrot warning (configurable with
> > warningson) level called PARROT_WARNING_DEPRECATED_FLAG. The patch
> only
> > applies this flag to getclass.
> >
> > Comments welcome. (Hopefully sooner than it took me to comment on
> kjs's
> > last send on this ticket. =-). The one thing I'm not sure about is
> that I'm
> > just using fprintf as in kjs's original sample. Could probably stand
> to
> > actually use parrot IO. I'm also not happy that it doesn't show the
> > location of the opcode, but I can live with that for now.
> 
> +1 from me as-is.  ParrotIO stuff will likely have to change in the
> medium-term anyway, so we'll probably have to modify this code (if we
> don't
> remove the ops altogether) at some point anyway.
> 
> -- c
> 

Here's a more extensive version of the patch, marking other ops as
deprecated, and updating DEPRECATED.pod.

However, running this, the new deprecation warnings are triggered during
'make test'. Which is nifty, but not something we want turned on by
default yet, I think.

-- 
Will "Coke" Coleda
Index: DEPRECATED.pod
===================================================================
--- DEPRECATED.pod	(revision 28731)
+++ DEPRECATED.pod	(working copy)
@@ -10,6 +10,15 @@
 When deprecated items are removed, all usage of the feature in the
 repository should be updated or removed; including documentation.
 
+When deprecating opcodes, in addition to the ticket, be sure to mark the
+opcode with the :deprecated flag; this will allow users to enable deprecation
+warnings with:
+
+ .include 'include/warnings.pasm'
+ warningson .PARROT_WARNINGS_DEPRECATED_FLAG
+
+And then receive runtime warnings if they are using any deprecated opcodes.
+
 =head1 vtable entries
 
 =over 4
Index: src/ops/pmc.ops
===================================================================
--- src/ops/pmc.ops	(revision 28731)
+++ src/ops/pmc.ops	(working copy)
@@ -680,7 +680,7 @@
 
 =cut
 
-op get_mro(out PMC, invar PMC) {
+op get_mro(out PMC, invar PMC) :deprecated {
   $1 = $2->vtable->mro;
 }
 
Index: src/ops/var.ops
===================================================================
--- src/ops/var.ops	(revision 28731)
+++ src/ops/var.ops	(working copy)
@@ -356,7 +356,7 @@
 
 ###############################################################################
 
-=head2 Deprecated global variable ops
+=head2 Global variable ops
 
 Operations to modify global variables
 
@@ -380,15 +380,15 @@
 
 =cut
 
-op store_global(in STR, invar PMC) {
+op store_global(in STR, invar PMC) :deprecated {
     Parrot_store_global_cur(interp, $1, $2);
 }
 
-op store_global(in STR, in STR, invar PMC) {
+op store_global(in STR, in STR, invar PMC) :deprecated {
     Parrot_store_global_s(interp, $1, $2, $3);
 }
 
-op store_global(in PMC, in STR, invar PMC) {
+op store_global(in PMC, in STR, invar PMC) :deprecated {
     Parrot_store_global_k(interp, $1, $2, $3);
 }
 
@@ -418,19 +418,19 @@
 
 =cut
 
-op find_global(out PMC, in STR) {
+op find_global(out PMC, in STR) :deprecated {
     PMC * const cur_ns = CONTEXT(interp)->current_namespace;
     $1 = Parrot_find_global_op(interp, cur_ns, $2, expr NEXT());
 }
 
-op find_global(out PMC, in STR, in STR) {
+op find_global(out PMC, in STR, in STR) :deprecated {
     PMC * const ns = Parrot_get_namespace_keyed_str(interp,
                                                     Parrot_get_ctx_HLL_namespace(interp),
                                                     $2);
     $1 = Parrot_find_global_op(interp, ns, $3, expr NEXT());
 }
 
-op find_global(out PMC, in PMC, in STR) {
+op find_global(out PMC, in PMC, in STR) :deprecated {
     PMC * const ns = Parrot_get_namespace_keyed(interp,
                                                 Parrot_get_ctx_HLL_namespace(interp),
                                                 $2);
Index: src/ops/core.ops
===================================================================
--- src/ops/core.ops	(revision 28731)
+++ src/ops/core.ops	(working copy)
@@ -974,18 +974,11 @@
 
 Turns on warnings categories. Categories already turned on will stay on.
 Initial setting is currently all warnings off.  Include F<warnings.pasm> to
-access the categories.  They are:
+access the categories. Refer to that file for the current list of warnings
+available.
 
 =over 4
 
-=item .PARROT_WARNINGS_UNDEF_FLAG
-
-=item .PARROT_WARNINGS_IO_FLAG
-
-=item .PARROT_WARNINGS_PLATFORM_FLAG
-
-=item .PARROT_WARNINGS_ALL_FLAG
-
 =back
 
 To turn on multiple categories, OR the category numbers together.
Index: src/ops/object.ops
===================================================================
--- src/ops/object.ops	(revision 28731)
+++ src/ops/object.ops	(working copy)
@@ -366,7 +366,7 @@
 
 =cut
 
-inline op getclass(out PMC, in STR) :object_classes :flow {
+inline op getclass(out PMC, in STR) :object_classes :flow :deprecated {
     PMC      * const _class = Parrot_class_lookup(interp, $2);
     opcode_t * const next   = expr NEXT();
 
@@ -376,11 +376,9 @@
     $1 = _class;
 
   goto ADDRESS(next);
-/*  real_exception(interp, NULL, UNIMPLEMENTED,
-        "The 'getclass' opcode has been deprecated, use 'get_class'. See RT #47972.");*/
 }
 
-inline op getclass(out PMC, in PMC) :object_classes :flow {
+inline op getclass(out PMC, in PMC) :object_classes :flow :deprecated {
   PMC      * const _class = Parrot_class_lookup_p(interp, $2);
   opcode_t * const next   = expr NEXT();
 
@@ -391,8 +389,6 @@
   else
     $1 = _class;
   goto ADDRESS(next);
-/*  real_exception(interp, NULL, UNIMPLEMENTED,
-        "The 'getclass' opcode has been deprecated, use 'get_class'. See RT #47972.");*/
 }
 
 ###############################################################################
Index: src/ops/io.ops
===================================================================
--- src/ops/io.ops	(revision 28731)
+++ src/ops/io.ops	(working copy)
@@ -77,7 +77,7 @@
 
 =cut
 
-inline op getfd(out INT, invar PMC) :advanced_io {
+inline op getfd(out INT, invar PMC) :advanced_io :deprecated {
   $1 = (INTVAL)PIO_getfd(interp, $2);
 }
 
@@ -120,7 +120,7 @@
 
 =cut
 
-inline op pioctl(out INT, invar PMC, in INT, in INT) :advanced_io {
+inline op pioctl(out INT, invar PMC, in INT, in INT) :advanced_io :deprecated {
   $1 = PIO_pioctl(interp, $2, $3, $4);
 }
 
Index: lib/Parrot/Op.pm
===================================================================
--- lib/Parrot/Op.pm	(revision 28731)
+++ lib/Parrot/Op.pm	(working copy)
@@ -168,8 +168,6 @@
 
     $name .= "_" . join( "_", @arg_types ) if @arg_types;
 
-    $name = "deprecated_$name" if ( $self->body =~ /DEPRECATED/ );
-
     return $name;
 }
 
Index: lib/Parrot/OpsFile.pm
===================================================================
--- lib/Parrot/OpsFile.pm	(revision 28731)
+++ lib/Parrot/OpsFile.pm	(working copy)
@@ -89,6 +89,10 @@
 behaviors. For example, the lack of the C<flow> flag will cause the
 op to be implicitly terminated with C<goto NEXT()>. (See next section).
 
+The :deprecated flag will generate a diagnostic to standard error at
+runtime when a deprecated opcode is invoked. (If and only if
+PARROT_WARNINGS_DEPRECATED_FLAG has been set with the warningson)
+
 =back
 
 =head2 Op Body (Macro Substitutions)
@@ -478,6 +482,12 @@
     my $next     = 0;
     my $restart  = 0;
 
+    if (exists($$flags{deprecated})) {
+        $body = <<"END_CODE" . $body;
+void * unused = PARROT_WARNINGS_test(interp,PARROT_WARNINGS_DEPRECATED_FLAG) &&
+  fprintf(stderr,"Warning: instruction '$short_name' is deprecated\\n");
+END_CODE
+}
     unless (exists($$flags{flow})) {
         $body .= "\ngoto NEXT();";
     }
Index: include/parrot/warnings.h
===================================================================
--- include/parrot/warnings.h	(revision 28731)
+++ include/parrot/warnings.h	(working copy)
@@ -11,12 +11,13 @@
 /* Warning flags */
 /* &gen_from_enum(warnings.pasm)  */
 typedef enum {
-    PARROT_WARNINGS_ALL_FLAG      = 0xFF,
-    PARROT_WARNINGS_NONE_FLAG     = 0x00,
-    PARROT_WARNINGS_UNDEF_FLAG    = 0x01,
-    PARROT_WARNINGS_IO_FLAG       = 0x02,
-    PARROT_WARNINGS_PLATFORM_FLAG = 0x04,
-    PARROT_WARNINGS_DYNEXT_FLAG   = 0x08
+    PARROT_WARNINGS_ALL_FLAG        = 0xFF,
+    PARROT_WARNINGS_NONE_FLAG       = 0x00,
+    PARROT_WARNINGS_UNDEF_FLAG      = 0x01,
+    PARROT_WARNINGS_IO_FLAG         = 0x02,
+    PARROT_WARNINGS_PLATFORM_FLAG   = 0x04,
+    PARROT_WARNINGS_DYNEXT_FLAG     = 0x08,
+    PARROT_WARNINGS_DEPRECATED_FLAG = 0x10
 } Warnings_classes;
 
 /* &end_gen */

Reply via email to