# New Ticket Created by  Mark Glines 
# Please include the string:  [perl #52506]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=52506 >


Sekana Fernando reported that src/ops/core_ops.c didn't compile under
g++.  It reports an error about "static op_lib_t core_op_lib" being
declared twice, and rightly so, because it is.  There's an initial stub
declaration, and another declaration at the end of the file with an
initializer block.

It seems appropriate to change the order of things output by ops2c, to
avoid the redundant declaration.  So I did so.  Patch attached.

The ops2c libraries are full of values calculated halfway through the
printing process, within functions named like "print_foo".  And other
"print_bar" functions rely on the values calculated by "print_foo",
which makes it difficult to move around sections of output.  Whenever
I found a value calculated within a print_* function, I just moved it
to the end of new(), instead.  A little MVC goes a long way, I think.

This gets g++ to get past core_ops.c, and on to the next error.  It
passes tests on x86-64 linux, and on ppc darwin.  But I'm hoping for a
little more QA and review, before I check in changes to code this vital.

Mark
Index: lib/Parrot/Ops2c/Utils.pm
===================================================================
--- lib/Parrot/Ops2c/Utils.pm   (revision 26793)
+++ lib/Parrot/Ops2c/Utils.pm   (working copy)
@@ -203,6 +203,24 @@
     $argsref->{flag} = $flagref;
     my $self = bless $argsref, $class;
     $self->_iterate_over_ops();
+
+    my ( $op_info, $op_func, $getop );
+    $op_info = $op_func = 'NULL';
+    $getop = '( int (*)(const char *, int) )NULL';
+
+    if ($self->{suffix} eq '') {
+        $op_func = $self->{bs} . "op_func_table";
+        $op_info = $self->{bs} . "op_info_table";
+        if (!$self->{flag}->{dynamic}) {
+            $getop = 'get_op';
+        }
+    }
+    $self->{getop}   = $getop;
+    $self->{op_info} = $op_info;
+    $self->{op_func} = $op_func;
+
+    $self->{names} = {};
+
     return $self;
 }
 
@@ -439,6 +457,12 @@
 
     $self->_print_preamble_source($SOURCE);
 
+    $self->_op_info_table($SOURCE);
+
+    $self->_op_func_table($SOURCE);
+
+    $self->_print_op_lib_descriptor($SOURCE);
+
     $self->_print_ops_addr_decl($SOURCE);
 
     $self->_print_run_core_func_decl_source($SOURCE);
@@ -460,8 +484,9 @@
 #include "$self->{include}"
 
 $self->{defines}
-static op_lib_t $self->{bs}op_lib;
 
+static int get_op(const char * name, int full);
+
 END_C
 
     my $text = $self->{ops}->preamble( $self->{trans} );
@@ -657,21 +682,11 @@
 
 sub print_c_source_bottom {
     my ( $self, $SOURCE ) = @_;
-    my @op_func_table = @{ $self->{op_func_table} };
-    my $bs            = $self->{bs};
-    my $index         = $self->{index};
 
     $SOURCE = $self->_reset_line_number($SOURCE);
 
-    $self->_op_func_table($SOURCE);
-
-    $self->{names} = {};
-    $self->_op_info_table($SOURCE);
-
     $self->_op_lookup($SOURCE);
 
-    $self->_print_op_lib_descriptor($SOURCE);
-
     $self->_generate_init_func($SOURCE);
 
     $self->_print_dynamic_lib_load($SOURCE);
@@ -706,12 +721,7 @@
 sub _op_func_table {
     my ( $self, $fh ) = @_;
 
-    my ( $op_info, $op_func, $getop );
-    $op_info = $op_func = 'NULL';
-    $getop = '( int (*)(const char *, int) )NULL';
-
     if ( $self->{suffix} eq '' ) {
-        $op_func = $self->{bs} . q{op_func_table};
         print $fh <<END_C;
 
 INTVAL $self->{bs}numops$self->{suffix} = $self->{num_ops};
@@ -720,7 +730,7 @@
 ** Op Function Table:
 */
 
-static op_func$self->{suffix}_t ${op_func}\[$self->{num_entries}] = {
+static op_func$self->{suffix}_t $self->{op_func}\[$self->{num_entries}] = {
 END_C
 
         print $fh @{ $self->{op_func_table} };
@@ -732,9 +742,6 @@
 
 END_C
     }
-    $self->{op_info} = $op_info;
-    $self->{op_func} = $op_func;
-    $self->{getop}   = $getop;
 }
 
 sub _op_info_table {
@@ -749,7 +756,6 @@
     );
 
     if ( $self->{suffix} eq '' ) {
-        $self->{op_info} = "$self->{bs}op_info_table";
 
         #
         # Op Info Table:
@@ -826,7 +832,6 @@
     my ( $self, $fh ) = @_;
 
     if ( $self->{suffix} eq '' && !$self->{flag}->{dynamic} ) {
-        $self->{getop} = 'get_op';
         my $hash_size = 3041;
         my $tot       = $self->{index} + scalar keys( %{ $self->{names} } );
         if ( $hash_size < $tot * 1.2 ) {
@@ -878,8 +883,6 @@
  * returns >= 0 (found idx into info_table), -1 if not
  */
 
-static int get_op(const char * name, int full);
-
 static size_t hash_str(const char * str) {
     size_t key = 0;
     const char * s;

Reply via email to