gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/asobj/gen-asclass.pl


From: Ann Barcomb
Subject: [Gnash-commit] gnash ChangeLog server/asobj/gen-asclass.pl
Date: Tue, 20 Mar 2007 18:47:53 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Ann Barcomb <ann>       07/03/20 18:47:53

Modified files:
        .              : ChangeLog 
Added files:
        server/asobj   : gen-asclass.pl 

Log message:
        gen-asclass.pl is a rewrite of gen-asclass.sh.
        
        The primary goals of the rewrite were:
           (a) Make it easier to change the code which is being output
           (b) Add features so that it can be used to generate arbitrary AS 
classes
        
        The secondary goal was to add a cleaner user interface; for example, it
        now responds to --help.
        
        The change of language is a side-effect of lack of skill at shell 
scripting.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2653&r2=1.2654
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/gen-asclass.pl?cvsroot=gnash&rev=1.1

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2653
retrieving revision 1.2654
diff -u -b -r1.2653 -r1.2654
--- ChangeLog   20 Mar 2007 18:41:18 -0000      1.2653
+++ ChangeLog   20 Mar 2007 18:47:53 -0000      1.2654
@@ -1,3 +1,8 @@
+2007-03-20 Ann Barcomb <address@hidden>
+
+       * server/asobj/gen-asclass.pl: Produces exactly the same output
+         as gen-asclass.sh with some extra features.
+
 2007-03-20 Sandro Santilli <address@hidden>
 
        * server/builtin_function.h (ctor): add a 'constructor'

Index: server/asobj/gen-asclass.pl
===================================================================
RCS file: server/asobj/gen-asclass.pl
diff -N server/asobj/gen-asclass.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ server/asobj/gen-asclass.pl 20 Mar 2007 18:47:53 -0000      1.1
@@ -0,0 +1,355 @@
+#!perl
+
+use strict;
+use warnings;
+use Getopt::Long;
+use Pod::Usage;
+
+our $VERBOSE = 0;
+
+our $LICENSE = q|
+// 
+// Copyright (C) | . (join ', ', (2005..((localtime)[5]+1900))) .
+q| Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+|;
+
+my %args = %{process_arguments()};
+create_headerfile(%args);
+create_cppfile(%args);
+
+########################### Output Functions #######################
+
+## Create the ClassName.h file
+sub create_headerfile {
+    my %args = @_;
+
+    my $fh;
+    open ($fh, '>', $args{headerfile}) or die
+        "Cannot open file '$args{headerfile}': $!\n";
+    notify("Creating file '$args{headerfile}'.");
+
+    print $fh $LICENSE;
+    print $fh <<EOF;
+
+#ifndef __GNASH_ASOBJ_$args{up}_H__
+#define __GNASH_ASOBJ_$args{up}_H__
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <memory> // for auto_ptr
+
+namespace gnash {
+
+class as_object;
+
+/// Initialize the global $args{class} class
+void $args{lc}_class_init(as_object& global);
+
+/// Return a $args{class} instance (in case the core lib needs it)
+//std::auto_ptr<as_object> init_$args{lc}_instance();
+  
+} // end of gnash namespace
+
+// __GNASH_ASOBJ_$args{up}_H__
+#endif
+
+EOF
+
+    close $fh;
+    return;
+}
+
+## Create the ClassName.cpp file
+sub create_cppfile {
+    my %args = @_;
+
+    my $fh;
+    open ($fh, '>', $args{cppfile}) or die
+        "Cannot open file '$args{cppfile}': $!\n";
+    notify("Creating file '$args{cppfile}'.");
+
+    ## Create code for each method
+    my ($declarations, $registrations, $implementations);
+    foreach my $m (@{$args{methods}}) {
+
+        $declarations .= 
+          qq|\nstatic void $args{lc}_| .$m. qq|(const fn_call& fn);|;
+
+        $registrations .= 
+          qq|\n    o.init_member("$m", new builtin_function($args{lc}_$m));|;
+
+        $implementations .=
+          qq|static as_value\n$args{lc}_| .$m. 
+          qq|(const fn_call& fn) 
+{   
+        $args{lc}_as_object* ptr = 
ensureType<$args{lc}_as_object>(fn.this_ptr);  
+        UNUSED(ptr);
+        log_warning("%s: unimplemented", __FUNCTION__);
+        return as_value();
+}
+|;
+
+    }
+
+    print $fh $LICENSE;
+    print $fh <<EOF;
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "$args{class}.h"
+#include "as_object.h" // for inheritance
+#include "log.h"
+#include "fn_call.h"
+#include "smart_ptr.h" // for boost intrusive_ptr
+#include "builtin_function.h" // need builtin_function
+#include "GnashException.h" // for ActionException
+
+namespace gnash {
+$declarations
+void $args{lc}_ctor(const fn_call& fn);
+
+static void
+attach$args{class}Interface(as_object& o)
+{
+$registrations
+
+}
+
+static as_object*
+get$args{class}Interface()
+{
+       static boost::intrusive_ptr<as_object> o;
+       if ( ! o )
+       {
+               o = new as_object();
+               attach$args{class}Interface(*o);
+       }
+       return o.get();
+}
+
+class $args{lc}_as_object: public as_object
+{
+
+public:
+
+       $args{lc}_as_object()
+               :
+               as_object(get$args{class}Interface())
+       {}
+
+       // override from as_object ?
+       //const char* get_text_value() const { return "$args{class}"; }
+
+       // override from as_object ?
+       //double get_numeric_value() const { return 0; }
+};
+
+$implementations
+
+as_value
+$args{lc}_ctor(const fn_call& fn)
+{
+       boost::intrusive_ptr<as_object> obj = new $args{lc}_as_object;
+       
+       return as_value(obj.get()); // will keep alive
+}
+
+// extern (used by Global.cpp)
+void $args{lc}_class_init(as_object& global)
+{
+       // This is going to be the global $args{class} "class"/"function"
+       static boost::intrusive_ptr<builtin_function> cl;
+
+       if ( cl == NULL )
+       {
+               cl=new builtin_function(&$args{lc}_ctor, 
get$args{class}Interface());
+               // replicate all interface to class, to be able to access
+               // all methods as static functions
+               attach$args{class}Interface(*cl);
+                    
+       }
+
+       // Register _global.$args{class}
+       global.init_member("$args{class}", cl.get());
+
+}
+
+} // end of gnash namespace
+
+EOF
+
+    close $fh;
+    return;
+}
+
+
+
+########################### Helper Functions #######################
+
+## Accept and process the user's arguments
+sub accept_arguments {
+    my %args;
+    GetOptions(
+        "class=s"   => \$args{class},
+        "help"      => \$args{help},
+        "verbose!"  => \$VERBOSE,
+        "force!"    => \$args{force},
+        "notes=s"   => \$args{datafile},
+    );
+
+    ## Class is a required argument
+    pod2usage(-verbose => 0), exit if ($args{help} || !$args{class}); 
+    delete $args{help};
+
+    ## Output files should not already exist.
+    $args{headerfile} = "$args{class}.h";
+    $args{cppfile}    = "$args{class}.cpp";
+    unless($args{force}) {
+        die "$args{headerfile} exists!  Aborting.\n" if (-e $args{headerfile});
+        die "$args{cppfile} exists!  Aborting.\n" if (-e $args{cppfile});
+    }
+    notify("The following files will be written: '$args{headerfile}', ".
+      "'$args{cppfile}'");
+
+    ## Use the default note file unless one was specified; ensure it exists.
+    $args{datafile} = '../../doc/C/NOTES' if (!$args{datafile});
+    die "Could not find file '$args{datafile}'; aborting.\n"
+        unless (-e $args{datafile});
+    notify("Using notes file '$args{datafile}'");
+
+    return \%args;
+}
+
+## Create a hash containing data which will be of use throughout the script.
+sub process_arguments {
+    my %args = %{accept_arguments()};
+
+    ## Find our methods and properties
+    %args = (%args, %{parse_notefile(%args)});
+ 
+    ## Add some extra variables we'll use often
+    $args{lc} = lc($args{class});
+    $args{up} = uc($args{class});
+
+    return \%args;
+}
+
+## Report a message if the user has enabled verbose.
+sub notify {
+    return unless ($VERBOSE);
+    my $message = shift;
+    print "$message\n";
+}
+
+## Take all property names out of notefile data.
+sub get_properties {
+    my %args = @_;
+    my @want;
+    foreach my $row (@{$args{notes}}) {
+        push @want, $1 if ($row =~ /^$args{class}\.(\w+)$/);
+    }
+    return address@hidden;
+}
+
+## Take all method names out of notefile data.
+sub get_methods {
+    my %args = @_;
+    my @want;
+
+    ## Note that case should not be converted, as SWF7 is case-sensitive
+    foreach my $row (@{$args{notes}}) {
+        push @want, $1 if ($row =~ /^$args{class}\.(\w+)\(\)$/);
+    }
+    return address@hidden;
+}
+
+## Get references to the class out of the notefile
+sub parse_notefile {
+    my %args = @_;
+    my $fh;
+    my @data;
+
+    open($fh, '<', $args{datafile}) or die
+        "Cannot open file '$args{datafile}': $!\n";
+
+    while (<$fh>) {
+        push @data, $_ if ($_ =~ /^$args{class}\b/);
+    }
+
+    close $fh;
+
+    my $methods = get_methods(%args, notes => address@hidden);
+    my $props   = get_properties(%args, notes => address@hidden);
+    return { methods => $methods, properties => $props };
+}
+
+########################### Documentation ############################
+=pod
+
+=head1 SYNOPSIS
+
+    perl gen-asclass.pl --class <classname> [--verbose] [--notes <filename>] 
[--force]
+
+=over 4
+
+=item --class <classname>
+
+This required argument specifies the name of the class you wish to create.
+
+=item --notes <filename>
+
+This allows you to specify the 'notes' where method names and (static) 
+properties are specified.  By default, the file is F<../../doc/C/NOTES>,
+but if you wish to create a custom class, you should create your own version
+of this file following the same format.
+
+=item --force
+
+With this option enabled, any pre-existing class files of the same name
+will be overwritten.
+
+=item --verbose
+
+This is an optional argument.  If you enable it, the script will 
+inform you of its progress.
+
+=back
+
+=head1 LICENSE
+
+Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+=cut




reply via email to

[Prev in Thread] Current Thread [Next in Thread]