You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2012/03/31 13:21:19 UTC
[lucy-commits] svn commit: r1307768 - in /lucy/trunk/clownfish: perl/lib/Clownfish/ perl/t/
src/
Author: nwellnhof
Date: Sat Mar 31 11:21:18 2012
New Revision: 1307768
URL: http://svn.apache.org/viewvc?rev=1307768&view=rev
Log:
Use 'path_part' instead of 'source_class' in CFC
This removes some unneeded string processing and is the basis for the next
commit.
Modified:
lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm
lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
lucy/trunk/clownfish/perl/t/400-class.t
lucy/trunk/clownfish/perl/t/403-file.t
lucy/trunk/clownfish/perl/t/501-include_dir.t
lucy/trunk/clownfish/src/CFCClass.c
lucy/trunk/clownfish/src/CFCClass.h
lucy/trunk/clownfish/src/CFCFile.c
lucy/trunk/clownfish/src/CFCFile.h
lucy/trunk/clownfish/src/CFCHierarchy.c
lucy/trunk/clownfish/src/CFCParseHeader.y
lucy/trunk/clownfish/src/CFCParser.c
lucy/trunk/clownfish/src/CFCParser.h
Modified: lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm (original)
+++ lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm Sat Mar 31 11:21:18 2012
@@ -114,7 +114,7 @@ BEGIN { XSLoader::load( 'Clownfish::CFC'
);
our %create_PARAMS = (
- source_class => undef,
+ path_part => undef,
class_name => undef,
cnick => undef,
parent_class_name => undef,
@@ -159,7 +159,7 @@ BEGIN { XSLoader::load( 'Clownfish::CFC'
return _create(
@args{
qw( parcel exposure class_name cnick micro_sym docucomment
- source_class parent_class_name final inert included)
+ path_part parent_class_name final inert included)
}
);
}
@@ -181,13 +181,17 @@ BEGIN { XSLoader::load( 'Clownfish::CFC'
use Clownfish::CFC::Util qw( verify_args );
use Carp;
- our %new_PARAMS = ( source_class => undef, );
+ our %new_PARAMS = (
+ source_dir => undef,
+ path_part => undef,
+ is_included => undef,
+ );
sub new {
my ( $either, %args ) = @_;
confess "no subclassing allowed" unless $either eq __PACKAGE__;
verify_args( \%new_PARAMS, %args ) or confess $@;
- return _new( $args{source_class} );
+ return _new( @args{ qw( source_dir path_part is_included ) } );
}
}
Modified: lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs (original)
+++ lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs Sat Mar 31 11:21:18 2012
@@ -123,14 +123,14 @@ PPCODE:
MODULE = Clownfish::CFC PACKAGE = Clownfish::CFC::Model::Class
SV*
-_create(parcel, exposure_sv, class_name_sv, cnick_sv, micro_sym_sv, docucomment, source_class_sv, parent_class_name_sv, is_final, is_inert, is_included)
+_create(parcel, exposure_sv, class_name_sv, cnick_sv, micro_sym_sv, docucomment, path_part_sv, parent_class_name_sv, is_final, is_inert, is_included)
CFCParcel *parcel;
SV *exposure_sv;
SV *class_name_sv;
SV *cnick_sv;
SV *micro_sym_sv;
CFCDocuComment *docucomment;
- SV *source_class_sv;
+ SV *path_part_sv;
SV *parent_class_name_sv;
bool is_final;
bool is_inert;
@@ -144,12 +144,12 @@ CODE:
SvOK(cnick_sv) ? SvPV_nolen(cnick_sv) : NULL;
const char *micro_sym =
SvOK(micro_sym_sv) ? SvPV_nolen(micro_sym_sv) : NULL;
- const char *source_class =
- SvOK(source_class_sv) ? SvPV_nolen(source_class_sv) : NULL;
+ const char *path_part =
+ SvOK(path_part_sv) ? SvPV_nolen(path_part_sv) : NULL;
const char *parent_class_name =
SvOK(parent_class_name_sv) ? SvPV_nolen(parent_class_name_sv) : NULL;
CFCClass *self = CFCClass_create(parcel, exposure, class_name, cnick,
- micro_sym, docucomment, source_class,
+ micro_sym, docucomment, path_part,
parent_class_name, is_final, is_inert,
is_included);
RETVAL = S_cfcbase_to_perlref(self);
@@ -270,7 +270,7 @@ ALIAS:
set_parent = 5
get_parent = 6
get_autocode = 8
- get_source_class = 10
+ get_path_part = 10
get_parent_class_name = 12
final = 14
inert = 16
@@ -321,8 +321,8 @@ PPCODE:
}
break;
case 10: {
- const char *value = CFCClass_get_source_class(self);
- retval = newSVpvn(value, strlen(value));
+ const char *value = CFCClass_get_path_part(self);
+ retval = value ? newSVpvn(value, strlen(value)) : newSV(0);
}
break;
case 12: {
@@ -515,11 +515,11 @@ PPCODE:
MODULE = Clownfish::CFC PACKAGE = Clownfish::CFC::Model::File
SV*
-_new(source_class, source_dir)
- const char *source_class;
+_new(source_dir, path_part)
const char *source_dir;
+ const char *path_part;
CODE:
- CFCFile *self = CFCFile_new(source_class, source_dir);
+ CFCFile *self = CFCFile_new(source_dir, path_part);
RETVAL = S_cfcbase_to_perlref(self);
CFCBase_decref((CFCBase*)self);
OUTPUT: RETVAL
@@ -537,7 +537,7 @@ _set_or_get(self, ...)
ALIAS:
set_modified = 1
get_modified = 2
- get_source_class = 4
+ get_path_part = 4
guard_name = 6
guard_start = 8
guard_close = 10
@@ -553,7 +553,7 @@ PPCODE:
retval = newSViv(CFCFile_get_modified(self));
break;
case 4: {
- const char *value = CFCFile_get_source_class(self);
+ const char *value = CFCFile_get_path_part(self);
retval = newSVpv(value, strlen(value));
}
break;
@@ -2290,14 +2290,14 @@ CODE:
OUTPUT: RETVAL
SV*
-_parse_file(self, string, source_class, source_dir, included)
+_parse_file(self, string, source_dir, path_part, included)
CFCParser *self;
const char *string;
- const char *source_class;
const char *source_dir;
+ const char *path_part;
bool included;
CODE:
- CFCFile *got = CFCParser_parse_file(self, string, source_class, source_dir,
+ CFCFile *got = CFCParser_parse_file(self, string, source_dir, path_part,
included);
RETVAL = S_cfcbase_to_perlref(got);
CFCBase_decref((CFCBase*)got);
Modified: lucy/trunk/clownfish/perl/t/400-class.t
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/t/400-class.t?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/t/400-class.t (original)
+++ lucy/trunk/clownfish/perl/t/400-class.t Sat Mar 31 11:21:18 2012
@@ -73,12 +73,12 @@ my $final_foo = Clownfish::CFC::Model::C
parcel => 'Neato',
class_name => 'Foo::FooJr::FinalFoo',
parent_class_name => 'Foo::FooJr',
- source_class => 'Foo::FooJr',
+ path_part => 'Foo/FooJr',
final => 1,
);
$final_foo->add_attribute( dumpable => 1 );
ok( $final_foo->final, "final" );
-is( $final_foo->include_h, 'Foo/FooJr.h', "inlude_h uses source_class" );
+is( $final_foo->include_h, 'Foo/FooJr.h', "inlude_h uses path_part" );
is( $final_foo->get_parent_class_name, 'Foo::FooJr',
"get_parent_class_name" );
Modified: lucy/trunk/clownfish/perl/t/403-file.t
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/t/403-file.t?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/t/403-file.t (original)
+++ lucy/trunk/clownfish/perl/t/403-file.t Sat Mar 31 11:21:18 2012
@@ -34,9 +34,9 @@ my $c_block = "__C__\nint foo;\n__END_C_
my $file
= $parser->_parse_file( "$parcel_declaration\n$class_content\n$c_block",
- 'Stuff::Thing', '.', 0 );
+ '.', 'Stuff/Thing', 0 );
-is( $file->get_source_class, "Stuff::Thing", "get_source_class" );
+is( $file->get_path_part, "Stuff/Thing", "get_path_part" );
my $guard_name = $file->guard_name;
is( $guard_name, "H_STUFF_THING", "guard_name" );
@@ -68,7 +68,7 @@ isa_ok( $blocks->[0], "Clownfish::CFC::M
isa_ok( $blocks->[1], "Clownfish::CFC::Model::Class" );
isa_ok( $blocks->[2], "Clownfish::CFC::Model::CBlock" );
-$file = $parser->_parse_file( $class_content, 'Stuff::Thing', '.', 0 );
+$file = $parser->_parse_file( $class_content, '.', 'Stuff/Thing', 0 );
($class) = @{ $file->classes };
( $foo, $bar ) = @{ $class->member_vars };
is( $foo->get_type->get_specifier, 'Foo', 'file production resets parcel' );
Modified: lucy/trunk/clownfish/perl/t/501-include_dir.t
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/t/501-include_dir.t?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/t/501-include_dir.t (original)
+++ lucy/trunk/clownfish/perl/t/501-include_dir.t Sat Mar 31 11:21:18 2012
@@ -122,7 +122,7 @@ my $file_clash = 't/cfclash/file';
eval { $hierarchy->build; };
- like( $@, qr/File for source class Animal::Dog already registered/, "source/source filename clash" );
+ like( $@, qr/File Animal\/Dog.cfh already registered/, "source/source filename clash" );
Clownfish::CFC::Model::Class->_clear_registry();
}
Modified: lucy/trunk/clownfish/src/CFCClass.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCClass.c?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCClass.c (original)
+++ lucy/trunk/clownfish/src/CFCClass.c Sat Mar 31 11:21:18 2012
@@ -70,7 +70,7 @@ struct CFCClass {
CFCClassAttribute **attributes;
size_t num_attributes;
char *autocode;
- char *source_class;
+ char *path_part;
char *parent_class_name;
int is_final;
int is_inert;
@@ -116,11 +116,11 @@ CFCClass*
CFCClass_create(struct CFCParcel *parcel, const char *exposure,
const char *class_name, const char *cnick,
const char *micro_sym, CFCDocuComment *docucomment,
- const char *source_class, const char *parent_class_name,
+ const char *path_part, const char *parent_class_name,
int is_final, int is_inert, int is_included) {
CFCClass *self = (CFCClass*)CFCBase_allocate(&CFCCLASS_META);
return CFCClass_do_create(self, parcel, exposure, class_name, cnick,
- micro_sym, docucomment, source_class,
+ micro_sym, docucomment, path_part,
parent_class_name, is_final, is_inert,
is_included);
}
@@ -129,7 +129,7 @@ CFCClass*
CFCClass_do_create(CFCClass *self, struct CFCParcel *parcel,
const char *exposure, const char *class_name,
const char *cnick, const char *micro_sym,
- CFCDocuComment *docucomment, const char *source_class,
+ CFCDocuComment *docucomment, const char *path_part,
const char *parent_class_name, int is_final, int is_inert,
int is_included) {
CFCUTIL_NULL_CHECK(class_name);
@@ -157,11 +157,6 @@ CFCClass_do_create(CFCClass *self, struc
self->docucomment
= (CFCDocuComment*)CFCBase_incref((CFCBase*)docucomment);
- // Assume that Foo::Bar should be found in Foo/Bar.h.
- self->source_class = source_class
- ? CFCUtil_strdup(source_class)
- : CFCUtil_strdup(class_name);
-
// Cache several derived symbols.
const char *last_colon = strrchr(class_name, ':');
self->struct_sym = last_colon
@@ -190,21 +185,17 @@ CFCClass_do_create(CFCClass *self, struc
sprintf(self->full_vtable_hidden, "%s_vt", self->full_vtable_var);
sprintf(self->privacy_symbol, "C_%s", self->full_vtable_var);
- // Cache the relative path to the autogenerated C header file.
- size_t source_class_len = strlen(self->source_class);
- self->include_h = (char*)MALLOCATE(source_class_len + 3);
- int j;
- for (i = 0, j = 0; i < source_class_len; i++) {
- if (self->source_class[i] == ':') {
- self->include_h[j++] = '/';
- i++;
- }
- else {
- self->include_h[j++] = self->source_class[i];
- }
+ // Build the relative path to the autogenerated C header file.
+ if (path_part) {
+ self->path_part = CFCUtil_strdup(path_part);
+ size_t path_part_len = strlen(path_part);
+ self->include_h = (char*)MALLOCATE(path_part_len + 3);
+ sprintf(self->include_h, "%s.h", path_part);
+ }
+ else {
+ self->path_part = NULL;
+ self->include_h = CFCUtil_strdup("class.h");
}
- self->include_h[j] = '\0';
- strcat(self->include_h, ".h");
self->is_final = !!is_final;
self->is_inert = !!is_inert;
@@ -248,7 +239,7 @@ CFCClass_destroy(CFCClass *self) {
FREEMEM(self->inert_vars);
FREEMEM(self->attributes);
FREEMEM(self->autocode);
- FREEMEM(self->source_class);
+ FREEMEM(self->path_part);
FREEMEM(self->parent_class_name);
FREEMEM(self->struct_sym);
FREEMEM(self->short_vtable_var);
@@ -738,8 +729,8 @@ CFCClass_get_autocode(CFCClass *self) {
}
const char*
-CFCClass_get_source_class(CFCClass *self) {
- return self->source_class;
+CFCClass_get_path_part(CFCClass *self) {
+ return self->path_part;
}
const char*
Modified: lucy/trunk/clownfish/src/CFCClass.h
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCClass.h?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCClass.h (original)
+++ lucy/trunk/clownfish/src/CFCClass.h Sat Mar 31 11:21:18 2012
@@ -45,9 +45,9 @@ struct CFCVariable;
* @param micro_sym Defaults to "class".
* @param docucomment An optional Clownfish::CFC::Model::DocuComment attached
* to this class.
- * @param source_class - The name of the class that owns the file in which
- * this class was declared. Should be "Foo" if "Foo::FooJr" is defined in
- * <code>Foo.cfh</code>.
+ * @param path_part - The path of the file in which this class was declared,
+ * relative to the source directory and excluding the .cfh extension. Should
+ * be "Foo/Bar" if the class is defined in <code>Foo/Bar.cfh</code>.
* @param parent_class_name - The name of this class's parent class. Needed
* in order to establish the class hierarchy.
* @param docucomment A Clownfish::CFC::Model::DocuComment describing this
@@ -61,7 +61,7 @@ CFCClass*
CFCClass_create(struct CFCParcel *parcel, const char *exposure,
const char *class_name, const char *cnick,
const char *micro_sym, struct CFCDocuComment *docucomment,
- const char *source_class, const char *parent_class_name,
+ const char *path_part, const char *parent_class_name,
int is_final, int is_inert, int is_included);
CFCClass*
@@ -69,7 +69,7 @@ CFCClass_do_create(CFCClass *self, struc
const char *exposure, const char *class_name,
const char *cnick, const char *micro_sym,
struct CFCDocuComment *docucomment,
- const char *source_class, const char *parent_class_name,
+ const char *path_part, const char *parent_class_name,
int is_final, int is_inert, int is_included);
void
@@ -220,7 +220,7 @@ const char*
CFCClass_get_autocode(CFCClass *self);
const char*
-CFCClass_get_source_class(CFCClass *self);
+CFCClass_get_path_part(CFCClass *self);
const char*
CFCClass_get_parent_class_name(CFCClass *self);
Modified: lucy/trunk/clownfish/src/CFCFile.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCFile.c?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCFile.c (original)
+++ lucy/trunk/clownfish/src/CFCFile.c Sat Mar 31 11:21:18 2012
@@ -34,12 +34,11 @@ struct CFCFile {
CFCBase **blocks;
CFCClass **classes;
int modified;
- char *source_class;
char *source_dir;
+ char *path_part;
char *guard_name;
char *guard_start;
char *guard_close;
- char *path_part;
};
const static CFCMeta CFCFILE_META = {
@@ -49,37 +48,37 @@ const static CFCMeta CFCFILE_META = {
};
CFCFile*
-CFCFile_new(const char *source_class, const char *source_dir) {
+CFCFile_new(const char *source_dir, const char *path_part) {
CFCFile *self = (CFCFile*)CFCBase_allocate(&CFCFILE_META);
- return CFCFile_init(self, source_class, source_dir);
+ return CFCFile_init(self, source_dir, path_part);
}
CFCFile*
-CFCFile_init(CFCFile *self, const char *source_class, const char *source_dir) {
- CFCUTIL_NULL_CHECK(source_class);
- self->modified = false;
- self->source_class = CFCUtil_strdup(source_class);
- self->source_dir = CFCUtil_strdup(source_dir);
- self->blocks = (CFCBase**)CALLOCATE(1, sizeof(CFCBase*));
- self->classes = (CFCClass**)CALLOCATE(1, sizeof(CFCBase*));
+CFCFile_init(CFCFile *self, const char *source_dir, const char *path_part) {
+ CFCUTIL_NULL_CHECK(source_dir);
+ CFCUTIL_NULL_CHECK(path_part);
+ self->modified = false;
+ self->source_dir = CFCUtil_strdup(source_dir);
+ self->path_part = CFCUtil_strdup(path_part);
+ self->blocks = (CFCBase**)CALLOCATE(1, sizeof(CFCBase*));
+ self->classes = (CFCClass**)CALLOCATE(1, sizeof(CFCBase*));
// Derive include guard name, plus C code for opening and closing the
// guard.
- size_t len = strlen(source_class);
+ size_t len = strlen(path_part);
self->guard_name = (char*)MALLOCATE(len + sizeof("H_") + 1);
self->guard_start = (char*)MALLOCATE(len * 2 + 40);
self->guard_close = (char*)MALLOCATE(len + 20);
memcpy(self->guard_name, "H_", 2);
size_t i, j;
- for (i = 0, j = 2; i < len; i++, j++) {
- char c = source_class[i];
- if (c == ':') {
- self->guard_name[j] = '_';
- i++;
+ for (i = 0, j = 2; i < len; i++) {
+ char c = path_part[i];
+ if (c == CFCUTIL_PATH_SEP_CHAR) {
+ self->guard_name[j++] = '_';
}
- else {
- self->guard_name[j] = toupper(c);
+ else if (isalnum(c)) {
+ self->guard_name[j++] = toupper(c);
}
}
self->guard_name[j] = '\0';
@@ -87,20 +86,6 @@ CFCFile_init(CFCFile *self, const char *
self->guard_name);
sprintf(self->guard_close, "#endif /* %s */\n", self->guard_name);
- // Cache partial path derived from source_class.
- self->path_part = (char*)MALLOCATE(len + 1);
- for (i = 0, j = 0; i < len; i++, j++) {
- char c = source_class[i];
- if (c == ':') {
- self->path_part[j] = CFCUTIL_PATH_SEP_CHAR;
- i++;
- }
- else {
- self->path_part[j] = c;
- }
- }
- self->path_part[j] = '\0';
-
return self;
}
@@ -117,7 +102,6 @@ CFCFile_destroy(CFCFile *self) {
FREEMEM(self->guard_name);
FREEMEM(self->guard_start);
FREEMEM(self->guard_close);
- FREEMEM(self->source_class);
FREEMEM(self->source_dir);
FREEMEM(self->path_part);
CFCBase_destroy((CFCBase*)self);
@@ -240,13 +224,13 @@ CFCFile_get_modified(CFCFile *self) {
}
const char*
-CFCFile_get_source_class(CFCFile *self) {
- return self->source_class;
+CFCFile_get_source_dir(CFCFile *self) {
+ return self->source_dir;
}
const char*
-CFCFile_get_source_dir(CFCFile *self) {
- return self->source_dir;
+CFCFile_get_path_part(CFCFile *self) {
+ return self->path_part;
}
const char*
Modified: lucy/trunk/clownfish/src/CFCFile.h
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCFile.h?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCFile.h (original)
+++ lucy/trunk/clownfish/src/CFCFile.h Sat Mar 31 11:21:18 2012
@@ -32,18 +32,18 @@ struct CFCBase;
struct CFCClass;
/**
- * @param source_class The class name associated with the source file,
- * regardless of how what classes are defined in the source file. Example: If
- * source_class is "Foo::Bar", that implies that the source file could be
- * found at 'Foo/Bar.cfh' within the source directory and that the output C
- * header file should be 'Foo/Bar.h' within the target include directory.
+ * @param path_part - The path of the file, relative to the source directory
+ * and excluding the .cfh extension. Should be "Foo/Bar" if the source file
+ * is found at 'Foo/Bar.cfh' within the source directory. That implies that
+ * the output C header file should be 'Foo/Bar.h' within the target include
+ * directory.
* @param source_dir The source directory in which the file was found.
*/
CFCFile*
-CFCFile_new(const char *source_class, const char *source_dir);
+CFCFile_new(const char *source_dir, const char *path_part);
CFCFile*
-CFCFile_init(CFCFile *self, const char *source_class, const char *source_dir);
+CFCFile_init(CFCFile *self, const char *source_dir, const char *path_part);
void
CFCFile_destroy(CFCFile *self);
@@ -62,7 +62,7 @@ size_t
CFCFile_path_buf_size(CFCFile *self, const char *base_dir);
/** Given a base directory, return a path name derived from the File's
- * source_class with a ".c" extension.
+ * path_part with a ".c" extension.
*/
void
CFCFile_c_path(CFCFile *self, char *buf, size_t buf_size,
@@ -99,7 +99,7 @@ int
CFCFile_get_modified(CFCFile *self);
const char*
-CFCFile_get_source_class(CFCFile *self);
+CFCFile_get_path_part(CFCFile *self);
const char*
CFCFile_get_source_dir(CFCFile *self);
Modified: lucy/trunk/clownfish/src/CFCHierarchy.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCHierarchy.c?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCHierarchy.c (original)
+++ lucy/trunk/clownfish/src/CFCHierarchy.c Sat Mar 31 11:21:18 2012
@@ -70,7 +70,7 @@ static void
S_add_tree(CFCHierarchy *self, CFCClass *klass);
static CFCFile*
-S_fetch_file(CFCHierarchy *self, const char *source_class);
+S_fetch_file(CFCHierarchy *self, const char *path_part);
// Recursive helper function for CFCUtil_propagate_modified.
static int
@@ -236,8 +236,8 @@ S_parse_cf_files(CFCHierarchy *self, con
char **all_source_paths = (char**)CALLOCATE(1, sizeof(char*));
all_source_paths = S_find_cfh(source_dir, all_source_paths, 0);
size_t source_dir_len = strlen(source_dir);
- char *source_class = NULL;
- size_t source_class_max = 0;
+ char *path_part = NULL;
+ size_t path_part_max = 0;
// Process any file that has at least one class declaration.
for (int i = 0; all_source_paths[i] != NULL; i++) {
@@ -248,30 +248,26 @@ S_parse_cf_files(CFCHierarchy *self, con
CFCUtil_die("'%s' doesn't start with '%s'", source_path,
source_dir);
}
- size_t source_class_len = 0;
- if (source_class_max < source_path_len * 2 + 1) {
- source_class_max = source_path_len * 2 + 1;
- source_class = (char*)REALLOCATE(source_class, source_class_max);
- }
- for (size_t j = source_dir_len; j < source_path_len - strlen(".cfh"); j++) {
- char c = source_path[j];
- if (isalnum(c)) {
- source_class[source_class_len++] = c;
- }
- else {
- if (source_class_len != 0) {
- source_class[source_class_len++] = ':';
- source_class[source_class_len++] = ':';
- }
- }
+ size_t path_part_len = source_path_len
+ - source_dir_len
+ - strlen(".cfh");
+ if (path_part_max < path_part_len + 1) {
+ path_part_max = path_part_len + 1;
+ path_part = (char*)REALLOCATE(path_part, path_part_max);
+ }
+ const char *src = source_path + source_dir_len;
+ while (*src == CFCUTIL_PATH_SEP_CHAR) {
+ ++src;
+ --path_part_len;
}
- source_class[source_class_len] = '\0';
+ memcpy(path_part, src, path_part_len);
+ path_part[path_part_len] = '\0';
// Slurp, parse, add parsed file to pool.
size_t unused;
char *content = CFCUtil_slurp_text(source_path, &unused);
CFCFile *file = CFCParser_parse_file(self->parser, content,
- source_class, source_dir,
+ source_dir, path_part,
is_included);
FREEMEM(content);
if (!file) {
@@ -298,7 +294,7 @@ S_parse_cf_files(CFCHierarchy *self, con
FREEMEM(all_source_paths[i]);
}
FREEMEM(all_source_paths);
- FREEMEM(source_class);
+ FREEMEM(path_part);
}
static void
@@ -347,9 +343,12 @@ CFCHierarchy_propagate_modified(CFCHiera
int
S_do_propagate_modified(CFCHierarchy *self, CFCClass *klass, int modified) {
- const char *source_class = CFCClass_get_source_class(klass);
- CFCFile *file = S_fetch_file(self, source_class);
+ const char *path_part = CFCClass_get_path_part(klass);
+ CFCUTIL_NULL_CHECK(path_part);
+ CFCFile *file = S_fetch_file(self, path_part);
+ CFCUTIL_NULL_CHECK(file);
const char *source_dir = CFCFile_get_source_dir(file);
+ CFCUTIL_NULL_CHECK(source_dir);
size_t cfh_buf_size = CFCFile_path_buf_size(file, source_dir);
char *source_path = (char*)MALLOCATE(cfh_buf_size);
CFCFile_cfh_path(file, source_path, cfh_buf_size, source_dir);
@@ -426,10 +425,10 @@ CFCHierarchy_ordered_classes(CFCHierarch
}
static CFCFile*
-S_fetch_file(CFCHierarchy *self, const char *source_class) {
+S_fetch_file(CFCHierarchy *self, const char *path_part) {
for (size_t i = 0; self->files[i] != NULL; i++) {
- const char *existing = CFCFile_get_source_class(self->files[i]);
- if (strcmp(source_class, existing) == 0) {
+ const char *existing = CFCFile_get_path_part(self->files[i]);
+ if (strcmp(path_part, existing) == 0) {
return self->files[i];
}
}
@@ -439,14 +438,14 @@ S_fetch_file(CFCHierarchy *self, const c
static void
S_add_file(CFCHierarchy *self, CFCFile *file) {
CFCUTIL_NULL_CHECK(file);
- const char *source_class = CFCFile_get_source_class(file);
+ const char *path_part = CFCFile_get_path_part(file);
CFCClass **classes = CFCFile_classes(file);
for (size_t i = 0; self->files[i] != NULL; i++) {
CFCFile *existing = self->files[i];
- const char *old_source_class = CFCFile_get_source_class(existing);
- if (strcmp(source_class, old_source_class) == 0) {
- CFCUtil_die("File for source class %s already registered",
- source_class);
+ const char *old_path_part = CFCFile_get_path_part(existing);
+ if (strcmp(path_part, old_path_part) == 0) {
+ CFCUtil_die("File %s.cfh already registered",
+ path_part);
}
CFCClass **existing_classes = CFCFile_classes(existing);
for (size_t j = 0; classes[j] != NULL; j++) {
Modified: lucy/trunk/clownfish/src/CFCParseHeader.y
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCParseHeader.y?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCParseHeader.y (original)
+++ lucy/trunk/clownfish/src/CFCParseHeader.y Sat Mar 31 11:21:18 2012
@@ -36,7 +36,7 @@ static CFCClass*
S_start_class(CFCParser *state, CFCDocuComment *docucomment, char *exposure,
char *declaration_modifier_list, char *class_name,
char *class_cnick, char *inheritance) {
- const char *source_class = CFCParser_get_source_class(state);
+ const char *path_part = CFCParser_get_path_part(state);
int is_final = false;
int is_inert = false;
if (declaration_modifier_list) {
@@ -48,7 +48,7 @@ S_start_class(CFCParser *state, CFCDocuC
CFCParser_set_class_cnick(state, class_cnick);
CFCClass *klass = CFCClass_create(CFCParser_get_parcel(state), exposure,
class_name, class_cnick, NULL,
- docucomment, source_class, inheritance,
+ docucomment, path_part, inheritance,
is_final, is_inert, is_included);
CFCBase_decref((CFCBase*)docucomment);
return klass;
@@ -296,8 +296,8 @@ result ::= file(A).
file(A) ::= FILE_START. /* Pseudo token, not passed by lexer. */
{
- A = CFCFile_new(CFCParser_get_source_class(state),
- CFCParser_get_source_dir(state));
+ A = CFCFile_new(CFCParser_get_source_dir(state),
+ CFCParser_get_path_part(state));
}
file(A) ::= file(B) major_block(C).
{
Modified: lucy/trunk/clownfish/src/CFCParser.c
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCParser.c?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCParser.c (original)
+++ lucy/trunk/clownfish/src/CFCParser.c Sat Mar 31 11:21:18 2012
@@ -39,8 +39,8 @@ struct CFCParser {
int errors;
char *class_name;
char *class_cnick;
- char *source_class;
char *source_dir;
+ char *path_part;
int is_included;
CFCMemPool *pool;
CFCParcel *parcel;
@@ -68,7 +68,9 @@ CFCParser_init(CFCParser *self) {
self->errors = false;
self->class_name = NULL;
self->class_cnick = NULL;
- self->source_class = NULL;
+ self->source_dir = NULL;
+ self->path_part = NULL;
+ self->is_included = 0;
self->pool = NULL;
self->parcel = NULL;
return self;
@@ -117,18 +119,19 @@ CFCParser_parse(CFCParser *self, const c
CFCFile*
CFCParser_parse_file(CFCParser *self, const char *string,
- const char *source_class, const char *source_dir,
+ const char *source_dir, const char *path_part,
int is_included) {
CFCParser_set_parcel(self, NULL);
- self->source_class = CFCUtil_strdup(source_class);
self->source_dir = CFCUtil_strdup(source_dir);
+ self->path_part = CFCUtil_strdup(path_part);
self->is_included = is_included;
CFCParseHeader(self->header_parser, CFC_TOKENTYPE_FILE_START, NULL, self);
CFCFile *result = (CFCFile*)CFCParser_parse(self, string);
- FREEMEM(self->source_class);
+ FREEMEM(self->path_part);
FREEMEM(self->source_dir);
- self->source_class = NULL;
- self->source_dir = NULL;
+ self->source_dir = NULL;
+ self->path_part = NULL;
+ self->is_included = 0;
return result;
}
@@ -201,19 +204,14 @@ CFCParser_get_class_cnick(CFCParser *sel
}
void
-CFCParser_set_source_class(CFCParser *self, const char *source_class) {
- FREEMEM(self->source_class);
- if (source_class) {
- self->source_class = CFCUtil_strdup(source_class);
- }
- else {
- self->source_class = NULL;
- }
+CFCParser_set_path_part(CFCParser *self, const char *path_part) {
+ FREEMEM(self->path_part);
+ self->path_part = CFCUtil_strdup(path_part);
}
const char*
-CFCParser_get_source_class(CFCParser *self) {
- return self->source_class;
+CFCParser_get_path_part(CFCParser *self) {
+ return self->path_part;
}
const char*
Modified: lucy/trunk/clownfish/src/CFCParser.h
URL: http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCParser.h?rev=1307768&r1=1307767&r2=1307768&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCParser.h (original)
+++ lucy/trunk/clownfish/src/CFCParser.h Sat Mar 31 11:21:18 2012
@@ -50,7 +50,7 @@ CFCParser_parse(CFCParser *self, const c
struct CFCFile*
CFCParser_parse_file(CFCParser *self, const char *string,
- const char *source_class, const char *source_dir,
+ const char *source_dir, const char *path_part,
int is_included);
char*
@@ -90,10 +90,10 @@ const char*
CFCParser_get_class_cnick(CFCParser *self);
void
-CFCParser_set_source_class(CFCParser *self, const char *source_class);
+CFCParser_set_path_part(CFCParser *self, const char *path_part);
const char*
-CFCParser_get_source_class(CFCParser *self);
+CFCParser_get_path_part(CFCParser *self);
const char*
CFCParser_get_source_dir(CFCParser *self);