lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] svn commit: r1183767 - in /incubator/lucy/branches/clownfish_lemon/clownfish: src/CFCLexHeader.l src/CFCParseHeader.y t/108-composite_type.t t/600-parser.t
Date Sat, 15 Oct 2011 23:24:33 GMT
Author: marvin
Date: Sat Oct 15 23:24:33 2011
New Revision: 1183767

URL: http://svn.apache.org/viewvc?rev=1183767&view=rev
Log:
Add support for composite types to Lemon-based parser.

Modified:
    incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l
    incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y
    incubator/lucy/branches/clownfish_lemon/clownfish/t/108-composite_type.t
    incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t

Modified: incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l?rev=1183767&r1=1183766&r2=1183767&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l Sat Oct 15 23:24:33
2011
@@ -74,6 +74,12 @@ va_list    { PARSE(CFC_TOKENTYPE_VA_LIST
                 PARSE(CFC_TOKENTYPE_OBJECT_TYPE_SPECIFIER, NULL); 
            }
 [*]        { PARSE(CFC_TOKENTYPE_ASTERISK, NULL); }
+[\[]       { PARSE(CFC_TOKENTYPE_LEFT_SQUARE_BRACKET, NULL); }
+[\]]       { PARSE(CFC_TOKENTYPE_RIGHT_SQUARE_BRACKET, NULL); }
+-?[0-9]+   {
+                S_save_yytext();
+                PARSE(CFC_TOKENTYPE_INTEGER_LITERAL, NULL); 
+           }
 
 [ \t\r\n]  /* Skip whitespace. */
 .          { 

Modified: incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y?rev=1183767&r1=1183766&r2=1183767&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y Sat Oct 15 23:24:33
2011
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
+#include <stdlib.h>
 #include "CFC.h"
 #ifndef true
   #define true 1
@@ -63,11 +64,25 @@ static const char KW_DOUBLE[]   = "doubl
     state->cap = 0;
 }
 
-result ::= simple_type(A).
+result ::= type(A).
 {
     state->result = A;
 }
 
+type(A) ::= simple_type(B).            { A = B; }
+type(A) ::= composite_type(B).         { A = B; }
+
+composite_type(A) ::= simple_type(B) asterisk_postfix(C).
+{
+    int indirection = strlen(C);
+    A = (CFCBase*)CFCType_new_composite(0, (CFCType*)B, indirection, NULL);
+}
+
+composite_type(A) ::= simple_type(B) array_postfix(C).
+{
+    A = (CFCBase*)CFCType_new_composite(0, (CFCType*)B, 0, C);
+}
+
 simple_type(A) ::= object_type(B).  { A = B; }
 simple_type(A) ::= void_type(B).    { A = B; }
 simple_type(A) ::= float_type(B).   { A = B; }
@@ -90,11 +105,18 @@ void_type(A) ::= void_type_specifier.
 %type object_type_specifier         {char*}
 %type type_qualifier                {int}
 %type type_qualifier_list           {int}
+%type integer_literal               {long}
+%type asterisk_postfix              {char*}
+%type array_postfix                 {char*}
+%type array_postfix_elem            {char*}
 %destructor float_type_specifier        { }
 %destructor integer_type_specifier      { }
 %destructor object_type_specifier       { FREEMEM($$); }
 %destructor type_qualifier              { }
 %destructor type_qualifier_list         { }
+%destructor asterisk_postfix            { FREEMEM($$); }
+%destructor array_postfix               { FREEMEM($$); }
+%destructor array_postfix_elem          { FREEMEM($$); }
 
 void_type_specifier ::= VOID.
 va_list_specifier         ::= VA_LIST.
@@ -172,3 +194,37 @@ type_qualifier_list(A) ::= type_qualifie
 type_qualifier_list(A) ::= type_qualifier_list INCREMENTED. { A |= CFCTYPE_INCREMENTED; }
 type_qualifier_list(A) ::= type_qualifier_list DECREMENTED. { A |= CFCTYPE_DECREMENTED; }
 
+asterisk_postfix(A) ::= ASTERISK.
+{
+    A = CFCUtil_strdup("*");
+}
+asterisk_postfix(A) ::= asterisk_postfix(B) ASTERISK.
+{
+    A = CFCUtil_cat(B, "*", NULL);
+}
+
+array_postfix_elem(A) ::= LEFT_SQUARE_BRACKET RIGHT_SQUARE_BRACKET.
+{
+    A = CFCUtil_strdup("[]");
+}
+array_postfix_elem(A) ::= LEFT_SQUARE_BRACKET integer_literal(B) RIGHT_SQUARE_BRACKET.
+{
+    char buffer[30];
+    sprintf(buffer, "%ld", B);
+    A = CFCUtil_cat(CFCUtil_strdup(""), "[", buffer, "]", NULL);
+}
+
+array_postfix(A) ::= array_postfix_elem(B). 
+{ 
+    A = B; 
+}
+array_postfix(A) ::= array_postfix(B) array_postfix_elem(C).
+{
+    A = CFCUtil_cat(B, C, NULL);
+}
+
+integer_literal(A) ::= INTEGER_LITERAL.
+{
+    A = strtol(CFCParser_current_state->text, NULL, 10);
+}
+

Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/108-composite_type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/108-composite_type.t?rev=1183767&r1=1183766&r2=1183767&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/108-composite_type.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/108-composite_type.t Sat Oct 15 23:24:33
2011
@@ -16,16 +16,12 @@
 use strict;
 use warnings;
 
-use Test::More tests => 24;
+use Test::More tests => 23;
 use Clownfish::Type;
 use Clownfish::Parser;
 
 my $parser = Clownfish::Parser->new;
 
-is( $parser->type_postfix($_), $_, "postfix: $_" )
-    for ( '[]', '[32]', '*' );
-is( $parser->type_postfix('[ 3 ]'), '[5]', "type_postfix: [ 76 ]" );
-
 my @composite_type_strings = (
     qw(
         char*
@@ -33,6 +29,8 @@ my @composite_type_strings = (
         char***
         int32_t*
         Obj**
+        int8_t[]
+        int8_t[1]
         neato_method_t[]
         neato_method_t[1]
         multi_dimensional_t[1][10]
@@ -40,10 +38,11 @@ my @composite_type_strings = (
     'char * * ',
     'const Obj**',
     'const void*',
+    'int8_t[ 3 ]',
 );
 
 for my $input (@composite_type_strings) {
-    my $type = $parser->type($input);
+    my $type = $parser->parse($input);
     ok( $type && $type->is_composite, $input );
 }
 
@@ -74,20 +73,20 @@ ok( !$composite_type->equals($bar_compos
     "equals spoiled by different child"
 );
 
-my $foo_array = $parser->type("foo_t[]")
+my $foo_array = $parser->parse("foo_t[]")
     or die "Can't parse foo_t[]";
 is( $foo_array->get_array, '[]', "get_array" );
 unlike( $foo_array->to_c, qr/\[\]/, "array subscripts not included by to_c" );
 
-my $foo_array_array = $parser->type("foo_t[][]")
+my $foo_array_array = $parser->parse("foo_t[][]")
     or die "Can't parse foo_t[][]";
 ok( !$foo_array->equals($foo_array_array),
     "equals spoiled by different array postfixes"
 );
 
-my $foo_star = $parser->type("foo_t*")
+my $foo_star = $parser->parse("foo_t*")
     or die "Can't parse foo_t*";
-my $foo_star_star = $parser->type("foo_t**")
+my $foo_star_star = $parser->parse("foo_t**")
     or die "Can't parse foo_t**";
 ok( !$foo_star->equals($foo_star_star),
     "equals spoiled by different levels of indirection" );

Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t?rev=1183767&r1=1183766&r2=1183767&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t Sat Oct 15 23:24:33 2011
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 107;
+use Test::More tests => 103;
 
 BEGIN { use_ok('Clownfish::Parser') }
 
@@ -59,13 +59,9 @@ is( $parser->type_qualifier($_), $_, "ty
 is( $parser->exposure_specifier($_), $_, "exposure_specifier $_" )
     for qw( public private parcel );
 
-is( $parser->type_postfix($_), $_, "postfix: $_" )
-    for ( '[]', '[A_CONSTANT]', '*' );
-is( $parser->type_postfix('[ FOO ]'), '[FOO]', "type_postfix: [ FOO ]" );
-
-isa_ok( $parser->type($_), "Clownfish::Type", "type $_" )
+isa_ok( $parser->parse($_), "Clownfish::Type", "type $_" )
     for ( 'const char *', 'Obj*', 'i32_t', 'char[]', 'long[1]',
-    'i64_t[FOO]' );
+    'i64_t[30]' );
 
 is( $parser->declarator($_), $_, "declarator: $_" )
     for ( 'foo', 'bar_bar_bar' );



Mime
View raw message