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/05 05:56:25 UTC
[lucy-commits] svn commit: r1179046 - in
/incubator/lucy/branches/clownfish_lemon/clownfish: src/CFCLexHeader.l
src/CFCParseHeader.y src/CFCParser.c src/CFCParser.h t/107-arbitrary_type.t
Author: marvin
Date: Wed Oct 5 03:56:24 2011
New Revision: 1179046
URL: http://svn.apache.org/viewvc?rev=1179046&view=rev
Log:
Support "arbitrary" types.
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/107-arbitrary_type.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=1179046&r1=1179045&r2=1179046&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCLexHeader.l Wed Oct 5 03:56:24 2011
@@ -23,6 +23,16 @@ CFCParseHeader(void *header_parser, int
#define PARSE(token_type, value) \
CFCParseHeader(CFCParser_current_parser, token_type, value, \
CFCParser_current_state)
+static void
+S_save_yytext() {
+ if (yyleng >= CFCParser_current_state->cap) {
+ CFCParser_current_state->text
+ = REALLOCATE(CFCParser_current_state->text, yyleng + 1);
+ CFCParser_current_state->cap = yyleng + 1;
+ }
+ strncpy(CFCParser_current_state->text, yytext, yyleng);
+ CFCParser_current_state->text[yyleng] = '\0';
+}
%}
%option noyywrap
@@ -47,5 +57,9 @@ long { PARSE(CFC_TOKENTYPE_LONG, N
size_t { PARSE(CFC_TOKENTYPE_SIZE_T, NULL); }
bool_t { PARSE(CFC_TOKENTYPE_BOOL_T, NULL); }
va_list { PARSE(CFC_TOKENTYPE_VA_LIST, NULL); }
+[A-Za-z0-9_]+_t {
+ S_save_yytext();
+ PARSE(CFC_TOKENTYPE_ARBITRARY, NULL);
+ }
%%
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=1179046&r1=1179045&r2=1179046&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParseHeader.y Wed Oct 5 03:56:24 2011
@@ -32,6 +32,8 @@
#define false 0
#endif
+static CFCParcel *current_parcel = NULL;
+
static const char KW_INT8_T[] = "int8_t";
static const char KW_INT16_T[] = "int16_t";
static const char KW_INT32_T[] = "int32_t";
@@ -52,6 +54,15 @@ static const char KW_DOUBLE[] = "doubl
%syntax_error {
state->errors = true;
+ FREEMEM(state->text);
+ state->text = NULL;
+ state->cap = 0;
+}
+
+%parse_accept {
+ FREEMEM(state->text);
+ state->text = NULL;
+ state->cap = 0;
}
result ::= simple_type(A).
@@ -63,6 +74,7 @@ simple_type(A) ::= void_type(B). { A
simple_type(A) ::= float_type(B). { A = B; }
simple_type(A) ::= integer_type(B). { A = B; }
simple_type(A) ::= va_list_type(B). { A = B; }
+simple_type(A) ::= arbitrary_type(B). { A = B; }
void_type(A) ::= CONST void_type_specifier.
{
@@ -123,3 +135,8 @@ va_list_type(A) ::= va_list_specifier.
A = (CFCBase*)CFCType_new_va_list();
}
+arbitrary_type(A) ::= ARBITRARY.
+{
+ A = (CFCBase*)CFCType_new_arbitrary(current_parcel, CFCParser_current_state->text);
+}
+
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=1179046&r1=1179045&r2=1179046&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.c Wed Oct 5 03:56:24 2011
@@ -76,6 +76,7 @@ CFCParser_parse(CFCParser *self, const c
CFCParser_current_parser = self->header_parser;
state.result = NULL;
state.errors = false;
+ state.text = NULL;
YY_BUFFER_STATE buffer = yy_scan_bytes(string, (int)strlen(string));
yylex();
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=1179046&r1=1179045&r2=1179046&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCParser.h Wed Oct 5 03:56:24 2011
@@ -28,6 +28,8 @@ struct CFCParserState
{
struct CFCBase *result;
int errors;
+ char *text;
+ size_t cap;
};
typedef struct CFCParserState CFCParserState;
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/t/107-arbitrary_type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/t/107-arbitrary_type.t?rev=1179046&r1=1179045&r2=1179046&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/t/107-arbitrary_type.t (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/t/107-arbitrary_type.t Wed Oct 5 03:56:24 2011
@@ -16,7 +16,7 @@
use strict;
use warnings;
-use Test::More tests => 12;
+use Test::More tests => 10;
use Clownfish::Type;
use Clownfish::Parser;
@@ -47,9 +47,7 @@ ok( !$foo_type->equals($compare_t_type),
my $parser = Clownfish::Parser->new;
for my $specifier (qw( foo_t Sort_compare_t )) {
- is( $parser->arbitrary_type_specifier($specifier),
- $specifier, 'arbitrary_type_specifier' );
- my $type = $parser->arbitrary_type($specifier);
+ my $type = $parser->parse($specifier);
ok( $type && $type->is_arbitrary, "arbitrary_type '$specifier'" );
ok( !$parser->arbitrary_type_specifier( $specifier . "_y_p_e" ),
"arbitrary_type_specifier guards against partial word matches"