[svn:parrot] r39471 - in branches/pmc_pct/compilers/vtdumper: . src src/parser t

cotto at svn.parrot.org cotto at svn.parrot.org
Tue Jun 9 09:27:14 UTC 2009


Author: cotto
Date: Tue Jun  9 09:27:14 2009
New Revision: 39471
URL: https://trac.parrot.org/parrot/changeset/39471

Log:
[vtdumper] s/argument/parameter/ and add some methods to make this code similar to what pmcc expects from vtable_info

Modified:
   branches/pmc_pct/compilers/vtdumper/src/function.pir
   branches/pmc_pct/compilers/vtdumper/src/parser/actions.pm
   branches/pmc_pct/compilers/vtdumper/src/parser/grammar.pg
   branches/pmc_pct/compilers/vtdumper/t/01-functions.t
   branches/pmc_pct/compilers/vtdumper/vtdumper.pir

Modified: branches/pmc_pct/compilers/vtdumper/src/function.pir
==============================================================================
--- branches/pmc_pct/compilers/vtdumper/src/function.pir	Tue Jun  9 08:52:09 2009	(r39470)
+++ branches/pmc_pct/compilers/vtdumper/src/function.pir	Tue Jun  9 09:27:14 2009	(r39471)
@@ -42,7 +42,10 @@
 
     # Initialize various attributes
     $P1 = new 'ResizablePMCArray'
-    res.'attr'('arguments', $P1, 1)
+    res.'attr'('parameters', $P1, 1)
+
+    $P1 = new 'String'
+    res.'attr'('parameter_list', $P1, 1)
 
     $P1 = new 'ResizableStringArray'
     res.'attr'('attributes', $P1, 1)
@@ -53,17 +56,17 @@
     .return (res)
 .end
 
-=item C<add_argument>
+=item C<add_parameter>
 
-Add a function argument to PMC.
+Add a function parameter to PMC.
 
 =cut
 
-.sub 'add_argument' :method
-    .param pmc argument
+.sub 'add_parameter' :method
+    .param pmc parameter
 
-    $P0 = self.'attr'('arguments', 0, 0)
-    push $P0, argument
+    $P0 = self.'attr'('parameters', 0, 0)
+    push $P0, parameter
   done:
     .return ()
 .end
@@ -110,6 +113,47 @@
     .return ()
 .end
 
+=item C<set_parameter_list>
+
+Set the string representing all of this function's parameters.
+
+=cut
+
+.sub 'set_parameter_list' :method
+    .param string list
+
+    $P0 = self.'attr'('parameter_list', 0, 0)
+    $P0 = list
+  done:
+    .return ()
+.end
+
+=item C<has_attribute>
+
+Return 1 if this function has the speficied attribute.
+
+=cut
+
+.sub 'has_attribute' :method
+    .param string name
+
+    .local int elems, i
+
+    $P0 = self.'attr'('attributes', 0, 0)
+    elems = elements $P0
+    i = 0
+  loop_start:
+    if i == elems goto not_found
+    $S0 = $P0[i]
+    if $S0 == name goto found
+    i += 1
+    goto loop_start
+  not_found:
+    .return (0) 
+  found:
+    .return (1)
+.end
+
 =head1 COPYRIGHT
 
 Copyright (C) 2009, Parrot Foundation.

Modified: branches/pmc_pct/compilers/vtdumper/src/parser/actions.pm
==============================================================================
--- branches/pmc_pct/compilers/vtdumper/src/parser/actions.pm	Tue Jun  9 08:52:09 2009	(r39470)
+++ branches/pmc_pct/compilers/vtdumper/src/parser/actions.pm	Tue Jun  9 09:27:14 2009	(r39471)
@@ -46,10 +46,14 @@
         $function.add_attribute(~$_<identifier>);
     }
 
-    for $/<argument> {
-        $function.add_argument($_);
+    my $parameter_list := '';
+    for $/<parameter> {
+        $function.add_parameter($_);
+        $parameter_list := $parameter_list ~ ~$_;
     }
 
+    $function.set_parameter_list($parameter_list);
+
     $function.set_section($?SECTION_NAME);
 
     $?FUNCTIONS.push($function);

Modified: branches/pmc_pct/compilers/vtdumper/src/parser/grammar.pg
==============================================================================
--- branches/pmc_pct/compilers/vtdumper/src/parser/grammar.pg	Tue Jun  9 08:52:09 2009	(r39470)
+++ branches/pmc_pct/compilers/vtdumper/src/parser/grammar.pg	Tue Jun  9 09:27:14 2009	(r39471)
@@ -28,14 +28,14 @@
 }
 
 rule vtable_func {
-    <type> <identifier> '(' <argument>* ')' <attribute>*  {*}
+    <type> <identifier> '(' <parameter>* ')' <attribute>*  {*}
 }
 
 rule type {
     [ 'struct' | 'union' ]? <identifier> '*'?
 }
 
-rule argument {
+rule parameter {
     <type> <identifier> ','?
 }
 

Modified: branches/pmc_pct/compilers/vtdumper/t/01-functions.t
==============================================================================
--- branches/pmc_pct/compilers/vtdumper/t/01-functions.t	Tue Jun  9 08:52:09 2009	(r39470)
+++ branches/pmc_pct/compilers/vtdumper/t/01-functions.t	Tue Jun  9 09:27:14 2009	(r39471)
@@ -6,7 +6,7 @@
     .include 'test_more.pir'
     load_bytecode 'vtdumper.pbc'
 
-    plan(45)
+    plan(48)
     comments()
     valid_functions()
     invalid_functions()
@@ -161,25 +161,28 @@
     $S0 = do_foo['returns']
     is($S0, "PMC0* ", "do_foo return type")
 
-    $I0 = do_foo['arguments']
+    $I0 = do_foo['parameters']
     is($I0, 3, "do_foo arg count")
 
-    $S0 = do_foo['arguments';0;'type';'identifier']
+    $S0 = do_foo['parameter_list']
+    is($S0, "INTVAL i, FLOATVAL j, SPECIALVAL k", "do_foo arg list")
+
+    $S0 = do_foo['parameters';0;'type';'identifier']
     is($S0, "INTVAL", "do_foo first arg type")
 
-    $S0 = do_foo['arguments';0;'identifier']
+    $S0 = do_foo['parameters';0;'identifier']
     is($S0, "i", "do_foo first arg name")
 
-    $S0 = do_foo['arguments';1;'type';'identifier']
+    $S0 = do_foo['parameters';1;'type';'identifier']
     is($S0, "FLOATVAL", "do_foo second arg type")
 
-    $S0 = do_foo['arguments';1;'identifier']
+    $S0 = do_foo['parameters';1;'identifier']
     is($S0, "j", "do_foo second arg name")
 
-    $S0 = do_foo['arguments';2;'type';'identifier']
+    $S0 = do_foo['parameters';2;'type';'identifier']
     is($S0, "SPECIALVAL", "do_foo third arg type")
 
-    $S0 = do_foo['arguments';2;'identifier']
+    $S0 = do_foo['parameters';2;'identifier']
     is($S0, "k", "do_foo third arg name")
 
 
@@ -192,19 +195,22 @@
     $S0 = do_bar['returns']
     is($S0, "INTVAL0 ", "do_bar return type")
 
-    $I0 = do_bar['arguments']
+    $I0 = do_bar['parameters']
     is($I0, 2, "do_bar arg count")
 
-    $S0 = do_bar['arguments';0;'type']
+    $S0 = do_bar['parameter_list']
+    is($S0, "PMC1* p1, PMC2* p2", "do_bar arg list")
+
+    $S0 = do_bar['parameters';0;'type']
     is($S0, "PMC1* ", "do_bar first arg type")
 
-    $S0 = do_bar['arguments';0;'identifier']
+    $S0 = do_bar['parameters';0;'identifier']
     is($S0, "p1", "do_bar first arg name")
 
-    $S0 = do_bar['arguments';1;'type']
+    $S0 = do_bar['parameters';1;'type']
     is($S0, "PMC2* ", "do_bar second arg type")
 
-    $S0 = do_bar['arguments';1;'identifier']
+    $S0 = do_bar['parameters';1;'identifier']
     is($S0, "p2", "do_bar second arg name")
 
 
@@ -217,19 +223,22 @@
     $S0 = quuxle['returns']
     is($S0, "INTVAL1 ", "quuxle return type")
 
-    $I0 = quuxle['arguments']
+    $I0 = quuxle['parameters']
     is($I0, 2, "quuxle arg count")
 
-    $S0 = quuxle['arguments';0;'type']
+    $S0 = quuxle['parameter_list']
+    is($S0, "PMC3* p3, PMC4* p4", "quuxle arg list")
+
+    $S0 = quuxle['parameters';0;'type']
     is($S0, "PMC3* ", "quuxle first arg type")
 
-    $S0 = quuxle['arguments';0;'identifier']
+    $S0 = quuxle['parameters';0;'identifier']
     is($S0, "p3", "quuxle first arg name")
 
-    $S0 = quuxle['arguments';1;'type']
+    $S0 = quuxle['parameters';1;'type']
     is($S0, "PMC4* ", "quuxle second arg type")
 
-    $S0 = quuxle['arguments';1;'identifier']
+    $S0 = quuxle['parameters';1;'identifier']
     is($S0, "p4", "quuxle second arg name")
 
 .end

Modified: branches/pmc_pct/compilers/vtdumper/vtdumper.pir
==============================================================================
--- branches/pmc_pct/compilers/vtdumper/vtdumper.pir	Tue Jun  9 08:52:09 2009	(r39470)
+++ branches/pmc_pct/compilers/vtdumper/vtdumper.pir	Tue Jun  9 09:27:14 2009	(r39471)
@@ -73,7 +73,7 @@
     $S0 = node['section']
     snode['section'] = $S0
 
-    $P0 = node['arguments']
+    $P0 = node['parameters']
     sargs = new ['ResizablePMCArray']
     j = 0
     elems = elements $P0
@@ -83,10 +83,10 @@
 
     $P1 = new ['Hash']
 
-    $S0 = node['arguments';j;'type']
+    $S0 = node['parameters';j;'type']
     $P1['type'] = $S0
 
-    $S0 = node['arguments';j;'identifier']
+    $S0 = node['parameters';j;'identifier']
     $P1['identifier'] = $S0
 
     push sargs, $P1
@@ -96,7 +96,7 @@
 
   args_loop_end:
 
-    snode['arguments'] = sargs
+    snode['parameters'] = sargs
 
     sattrs = node['attributes']
     snode['attributes'] = sattrs


More information about the parrot-commits mailing list