You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/10/18 18:41:49 UTC

[lucy-commits] svn commit: r1185748 - in /incubator/lucy/branches/clownfish_lemon/clownfish: src/CFCLexHeader.l src/CFCParseHeader.y src/CFCParser.c src/CFCParser.h t/300-variable.t t/600-parser.t

Author: marvin
Date: Tue Oct 18 16:41:49 2011
New Revision: 1185748

URL: http://svn.apache.org/viewvc?rev=1185748&view=rev
Log:
Add support for variable declaration statements, exposure specifiers (parcel,
public, private, local).

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/src/CFCParser.c
    incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h
    incubator/lucy/branches/clownfish_lemon/clownfish/t/300-variable.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=1185748&r1=1185747&r2=1185748&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l Tue Oct 18 16:41:49 2011
@@ -79,6 +79,10 @@ false      { PARSE(CFC_TOKENTYPE_FALSE);
 NULL       { PARSE(CFC_TOKENTYPE_NULL); }
 cnick      { PARSE(CFC_TOKENTYPE_CNICK); }
 parcel     { PARSE(CFC_TOKENTYPE_PARCEL); }
+public     { PARSE(CFC_TOKENTYPE_PUBLIC); }
+private    { PARSE(CFC_TOKENTYPE_PRIVATE); }
+local      { PARSE(CFC_TOKENTYPE_LOCAL); }
+inert      { PARSE(CFC_TOKENTYPE_INERT); }
 
 [A-Za-z0-9_]+_t         { SAVE_AND_PARSE(CFC_TOKENTYPE_ARBITRARY); }
 [a-z]+[a-z0-9]*_{CLASS_NAME_COMPONENT} {

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=1185748&r1=1185747&r2=1185748&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y Tue Oct 18 16:41:49 2011
@@ -71,19 +71,63 @@ result ::= param_variable(A).         { 
 result ::= docucomment(A).            { state->result = A; }
 result ::= parcel_definition(A).      { state->result = A; }
 result ::= cblock(A).                 { state->result = A; }
+result ::= var_declaration_statement(A). { state->result = A; }
 
-parcel_definition(A) ::= PARCEL class_name(B) SEMICOLON.
+parcel_definition(A) ::= exposure_specifier(B) class_name(C) SEMICOLON.
 {
-    A = (CFCBase*)CFCParcel_singleton(B, NULL);
+    if (strcmp(B, "parcel") != 0) {
+        /* Instead of this kludgy post-parse error trigger, we should require
+         * PARCEL in this production as opposed to exposure_specifier.
+         * However, that causes a parsing conflict because the keyword
+         * "parcel" has two meanings in the Clownfish header language (parcel
+         * declaration and exposure specifier). */
+         CFCUtil_die("A syntax error was detected when parsing '%s'", B);
+    }
+    A = (CFCBase*)CFCParcel_singleton(C, NULL);
     CFCParser_set_parcel((CFCParcel*)A);
 }
 
-parcel_definition(A) ::= PARCEL class_name(B) cnick(C) SEMICOLON.
+parcel_definition(A) ::= exposure_specifier(B) class_name(C) cnick(D) SEMICOLON.
 {
-    A = (CFCBase*)CFCParcel_singleton(B, C);
+    if (strcmp(B, "parcel") != 0) {
+         CFCUtil_die("A syntax error was detected when parsing '%s'", B);
+    }
+    A = (CFCBase*)CFCParcel_singleton(C, D);
     CFCParser_set_parcel((CFCParcel*)A);
 }
 
+
+var_declaration_statement(A) ::= type(B) declarator(C) SEMICOLON.
+{
+    A = (CFCBase*)CFCVariable_new(CFCParser_get_parcel(), "parcel", 
+                                  CFCParser_get_class_name(state),
+                                  CFCParser_get_class_cnick(state), C,
+                                  (CFCType*)B);
+}
+var_declaration_statement(A) ::= exposure_specifier(B) type(C) declarator(D) SEMICOLON.
+{
+    A = (CFCBase*)CFCVariable_new(CFCParser_get_parcel(), B,
+                                  CFCParser_get_class_name(state),
+                                  CFCParser_get_class_cnick(state), D,
+                                  (CFCType*)C);
+}
+
+/* Discard INERT for now. */
+var_declaration_statement(A) ::= INERT type(B) declarator(C) SEMICOLON.
+{
+    A = (CFCBase*)CFCVariable_new(CFCParser_get_parcel(), "parcel", 
+                                  CFCParser_get_class_name(state),
+                                  CFCParser_get_class_cnick(state), C,
+                                  (CFCType*)B);
+}
+var_declaration_statement(A) ::= exposure_specifier(B) INERT type(C) declarator(D) SEMICOLON.
+{
+    A = (CFCBase*)CFCVariable_new(CFCParser_get_parcel(), B,
+                                  CFCParser_get_class_name(state),
+                                  CFCParser_get_class_cnick(state), D,
+                                  (CFCType*)C);
+}
+
 type(A) ::= simple_type(B).            { A = B; }
 type(A) ::= composite_type(B).         { A = B; }
 
@@ -115,6 +159,7 @@ void_type(A) ::= void_type_specifier.
     A = (CFCBase*)CFCType_new_void(false);
 }
 
+%type exposure_specifier            {char*}
 %type float_type_specifier          {const char*}
 %type integer_type_specifier        {const char*}
 %type object_type_specifier         {char*}
@@ -132,6 +177,7 @@ void_type(A) ::= void_type_specifier.
 %type class_name                    {char*}
 %type cnick                         {char*}
 %type blob                          {char*}
+%destructor exposure_specifier          { FREEMEM($$); }
 %destructor float_type_specifier        { }
 %destructor integer_type_specifier      { }
 %destructor object_type_specifier       { FREEMEM($$); }
@@ -169,6 +215,11 @@ integer_type_specifier(A) ::= BOOL_T.   
 float_type_specifier(A) ::= FLOAT.   { A = KW_FLOAT; }
 float_type_specifier(A) ::= DOUBLE.  { A = KW_DOUBLE; }
 
+exposure_specifier(A) ::= PUBLIC.  { A = CFCUtil_strdup("public"); }
+exposure_specifier(A) ::= PRIVATE. { A = CFCUtil_strdup("private"); }
+exposure_specifier(A) ::= PARCEL.  { A = CFCUtil_strdup("parcel"); }
+exposure_specifier(A) ::= LOCAL.   { A = CFCUtil_strdup("local"); }
+
 integer_type(A) ::= integer_type_specifier(B).
 {
     A = (CFCBase*)CFCType_new_integer(0, B);

Modified: incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c?rev=1185748&r1=1185747&r2=1185748&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c Tue Oct 18 16:41:49 2011
@@ -105,3 +105,35 @@ CFCParser_get_parcel(void) {
     return CFCParser_current_parcel;
 }
 
+void
+CFCParser_set_class_name(CFCParserState *state, const char *class_name) {
+    FREEMEM(state->class_name);
+    if (class_name) {
+        state->class_name = CFCUtil_strdup(class_name);
+    }
+    else {
+        state->class_name = NULL;
+    }
+}
+
+const char*
+CFCParser_get_class_name(CFCParserState *state) {
+    return state->class_name;
+}
+
+void
+CFCParser_set_class_cnick(CFCParserState *state, const char *class_cnick) {
+    FREEMEM(state->class_cnick);
+    if (class_cnick) {
+        state->class_cnick = CFCUtil_strdup(class_cnick);
+    }
+    else {
+        state->class_cnick = NULL;
+    }
+}
+
+const char*
+CFCParser_get_class_cnick(CFCParserState *state) {
+    return state->class_cnick;
+}
+

Modified: incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h?rev=1185748&r1=1185747&r2=1185748&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h Tue Oct 18 16:41:49 2011
@@ -31,6 +31,8 @@ struct CFCParserState 
     int errors;
     char *text;
     size_t cap;
+    char *class_name;
+    char *class_cnick;
 };
 typedef struct CFCParserState CFCParserState;
 
@@ -56,6 +58,18 @@ CFCParser_set_parcel(struct CFCParcel *p
 struct CFCParcel*
 CFCParser_get_parcel(void);
 
+void
+CFCParser_set_class_name(CFCParserState *state, const char *class_name);
+
+const char*
+CFCParser_get_class_name(CFCParserState *state);
+
+void
+CFCParser_set_class_cnick(CFCParserState *state, const char *class_cnick);
+
+const char*
+CFCParser_get_class_cnick(CFCParserState *state);
+
 #ifdef __cplusplus
 }
 #endif

Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/300-variable.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/300-variable.t?rev=1185748&r1=1185747&r2=1185748&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/300-variable.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/300-variable.t Tue Oct 18 16:41:49 2011
@@ -66,8 +66,8 @@ $var = Clownfish::Variable->new(
 );
 is( $var->global_c, 'neato_Foo* neato_LobClaw_foo', "global_c" );
 
-isa_ok( $parser->var_declaration_statement($_)->{declared},
-    "Clownfish::Variable", "var_declaration_statement: $_" )
+isa_ok( $parser->parse($_), "Clownfish::Variable",
+    "var_declaration_statement: $_" )
     for (
     'parcel int foo;',
     'private Obj *obj;',

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=1185748&r1=1185747&r2=1185748&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/600-parser.t Tue Oct 18 16:41:49 2011
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 100;
+use Test::More tests => 96;
 
 BEGIN { use_ok('Clownfish::Parser') }
 
@@ -66,15 +66,6 @@ isa_ok( $parser->parse($_), "Clownfish::
 is( $parser->declarator($_), $_, "declarator: $_" )
     for ( 'foo', 'bar_bar_bar' );
 
-isa_ok( $parser->var_declaration_statement($_)->{declared},
-    "Clownfish::Variable", "var_declaration_statement: $_" )
-    for (
-    'parcel int foo;',
-    'private Obj *obj;',
-    'public inert i32_t **foo;',
-    'Dog *fido;'
-    );
-
 is( $parser->hex_constant($_), $_, "hex_constant: $_" )
     for (qw( 0x1 0x0a 0xFFFFFFFF ));