Repository: lucy-clownfish Updated Branches: refs/heads/master 570984e73 -> 1fc8c00a1
Identify convertible core types more robustly. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/978a011e Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/978a011e Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/978a011e Branch: refs/heads/master Commit: 978a011e36d376319e3afb106995f7ca9822e06a Parents: 570984e Author: Marvin Humphrey <[email protected]> Authored: Sat Jul 25 17:51:10 2015 -0700 Committer: Marvin Humphrey <[email protected]> Committed: Fri Jul 31 11:03:02 2015 -0700 ---------------------------------------------------------------------- compiler/src/CFCType.c | 116 ++++++++++++++++++++++++++++++++++---------- compiler/src/CFCType.h | 81 ++++++++++++++++++++++++------- 2 files changed, 154 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/978a011e/compiler/src/CFCType.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCType.c b/compiler/src/CFCType.c index ee04abf..0c882cf 100644 --- a/compiler/src/CFCType.c +++ b/compiler/src/CFCType.c @@ -63,18 +63,25 @@ S_check_flags(int supplied, int acceptable, const char *type_name) { int bad = (supplied & ~acceptable); if (bad) { char bad_flag[20]; - if ((bad & CFCTYPE_CONST)) { strcpy(bad_flag, "CONST"); } - else if ((bad & CFCTYPE_NULLABLE)) { strcpy(bad_flag, "NULLABLE"); } - else if ((bad & CFCTYPE_INCREMENTED)) { strcpy(bad_flag, "INCREMENTED"); } - else if ((bad & CFCTYPE_DECREMENTED)) { strcpy(bad_flag, "DECREMENTED"); } - else if ((bad & CFCTYPE_OBJECT)) { strcpy(bad_flag, "OBJECT"); } - else if ((bad & CFCTYPE_PRIMITIVE)) { strcpy(bad_flag, "PRIMITIVE"); } - else if ((bad & CFCTYPE_INTEGER)) { strcpy(bad_flag, "INTEGER"); } - else if ((bad & CFCTYPE_FLOATING)) { strcpy(bad_flag, "FLOATING"); } - else if ((bad & CFCTYPE_STRING_TYPE)) { strcpy(bad_flag, "STRING_TYPE"); } - else if ((bad & CFCTYPE_VA_LIST)) { strcpy(bad_flag, "VA_LIST"); } - else if ((bad & CFCTYPE_ARBITRARY)) { strcpy(bad_flag, "ARBITRARY"); } - else if ((bad & CFCTYPE_COMPOSITE)) { strcpy(bad_flag, "COMPOSITE"); } + if ((bad & CFCTYPE_CONST)) { strcpy(bad_flag, "CONST"); } + else if ((bad & CFCTYPE_NULLABLE)) { strcpy(bad_flag, "NULLABLE"); } + else if ((bad & CFCTYPE_INCREMENTED)) { strcpy(bad_flag, "INCREMENTED"); } + else if ((bad & CFCTYPE_DECREMENTED)) { strcpy(bad_flag, "DECREMENTED"); } + else if ((bad & CFCTYPE_OBJECT)) { strcpy(bad_flag, "OBJECT"); } + else if ((bad & CFCTYPE_PRIMITIVE)) { strcpy(bad_flag, "PRIMITIVE"); } + else if ((bad & CFCTYPE_INTEGER)) { strcpy(bad_flag, "INTEGER"); } + else if ((bad & CFCTYPE_FLOATING)) { strcpy(bad_flag, "FLOATING"); } + else if ((bad & CFCTYPE_CFISH_OBJ)) { strcpy(bad_flag, "CFISH_OBJ"); } + else if ((bad & CFCTYPE_CFISH_STRING)) { strcpy(bad_flag, "CFISH_STRING"); } + else if ((bad & CFCTYPE_CFISH_BLOB)) { strcpy(bad_flag, "CFISH_BLOB"); } + else if ((bad & CFCTYPE_CFISH_INTEGER)) { strcpy(bad_flag, "CFISH_INTEGER"); } + else if ((bad & CFCTYPE_CFISH_FLOAT)) { strcpy(bad_flag, "CFISH_FLOAT"); } + else if ((bad & CFCTYPE_CFISH_BOOLEAN)) { strcpy(bad_flag, "CFISH_BOOLEAN"); } + else if ((bad & CFCTYPE_CFISH_VECTOR)) { strcpy(bad_flag, "CFISH_VECTOR"); } + else if ((bad & CFCTYPE_CFISH_HASH)) { strcpy(bad_flag, "CFISH_HASH"); } + else if ((bad & CFCTYPE_VA_LIST)) { strcpy(bad_flag, "VA_LIST"); } + else if ((bad & CFCTYPE_ARBITRARY)) { strcpy(bad_flag, "ARBITRARY"); } + else if ((bad & CFCTYPE_COMPOSITE)) { strcpy(bad_flag, "COMPOSITE"); } else { CFCUtil_die("Unknown flags: %d", bad); } @@ -182,12 +189,36 @@ CFCType_new_object(int flags, CFCParcel *parcel, const char *specifier, // Add flags. flags |= CFCTYPE_OBJECT; - if (strcmp(specifier, "String") == 0 - || strcmp(specifier, "cfish_String") == 0 - ) { - // Determine whether this type is a string type. - flags |= CFCTYPE_STRING_TYPE; + static struct { + char *sym; + char *full_sym; + int flag; + } cfish_types[] = { + {"Obj", "cfish_Obj", CFCTYPE_CFISH_OBJ}, + {"String", "cfish_String", CFCTYPE_CFISH_STRING}, + {"Blob", "cfish_Blob", CFCTYPE_CFISH_BLOB}, + {"Integer", "cfish_Integer", CFCTYPE_CFISH_INTEGER}, + {"Float", "cfish_Float", CFCTYPE_CFISH_FLOAT}, + {"Boolean", "cfish_Boolean", CFCTYPE_CFISH_BOOLEAN}, + {"Vector", "cfish_Vector", CFCTYPE_CFISH_VECTOR}, + {"Hash", "cfish_Hash", CFCTYPE_CFISH_HASH} + }; + int count_cfish_types = sizeof(cfish_types) / sizeof(cfish_types[0]); + int acceptable_flags = CFCTYPE_OBJECT + | CFCTYPE_CONST + | CFCTYPE_NULLABLE + | CFCTYPE_INCREMENTED + | CFCTYPE_DECREMENTED; + for (int i = 0; i < count_cfish_types; i++) { + if (strcmp(specifier, cfish_types[i].sym) == 0 + || strcmp(specifier, cfish_types[i].full_sym) == 0 + ) { + flags |= cfish_types[i].flag; + acceptable_flags |= cfish_types[i].flag; + break; + } } + S_check_flags(flags, acceptable_flags, "Object"); // Validate specifier. if (!isalpha(*specifier)) { @@ -204,14 +235,6 @@ CFCType_new_object(int flags, CFCParcel *parcel, const char *specifier, CFCUtil_die("Invalid specifier: '%s'", specifier); } - int acceptable_flags = CFCTYPE_OBJECT - | CFCTYPE_STRING_TYPE - | CFCTYPE_CONST - | CFCTYPE_NULLABLE - | CFCTYPE_INCREMENTED - | CFCTYPE_DECREMENTED; - S_check_flags(flags, acceptable_flags, "Object"); - return CFCType_new(flags, parcel, specifier, 1); } @@ -481,9 +504,50 @@ CFCType_is_floating(CFCType *self) { return !!(self->flags & CFCTYPE_FLOATING); } + +int +CFCType_cfish_obj(CFCType *self) { + return !!(self->flags & CFCTYPE_CFISH_OBJ); +} + int CFCType_is_string_type(CFCType *self) { - return !!(self->flags & CFCTYPE_STRING_TYPE); + return !!(self->flags & CFCTYPE_CFISH_STRING); +} + +int +CFCType_cfish_string(CFCType *self) { + return !!(self->flags & CFCTYPE_CFISH_STRING); +} + +int +CFCType_cfish_blob(CFCType *self) { + return !!(self->flags & CFCTYPE_CFISH_BLOB); +} + +int +CFCType_cfish_integer(CFCType *self) { + return !!(self->flags & CFCTYPE_CFISH_INTEGER); +} + +int +CFCType_cfish_float(CFCType *self) { + return !!(self->flags & CFCTYPE_CFISH_FLOAT); +} + +int +CFCType_cfish_boolean(CFCType *self) { + return !!(self->flags & CFCTYPE_CFISH_BOOLEAN); +} + +int +CFCType_cfish_vector(CFCType *self) { + return !!(self->flags & CFCTYPE_CFISH_VECTOR); +} + +int +CFCType_cfish_hash(CFCType *self) { + return !!(self->flags & CFCTYPE_CFISH_HASH); } int http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/978a011e/compiler/src/CFCType.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCType.h b/compiler/src/CFCType.h index f351eba..31800fc 100644 --- a/compiler/src/CFCType.h +++ b/compiler/src/CFCType.h @@ -28,19 +28,26 @@ typedef struct CFCType CFCType; struct CFCClass; struct CFCParcel; -#define CFCTYPE_CONST 0x00000001 -#define CFCTYPE_NULLABLE 0x00000002 -#define CFCTYPE_VOID 0x00000004 -#define CFCTYPE_INCREMENTED 0x00000008 -#define CFCTYPE_DECREMENTED 0x00000010 -#define CFCTYPE_OBJECT 0x00000020 -#define CFCTYPE_PRIMITIVE 0x00000040 -#define CFCTYPE_INTEGER 0x00000080 -#define CFCTYPE_FLOATING 0x00000100 -#define CFCTYPE_STRING_TYPE 0x00000200 -#define CFCTYPE_VA_LIST 0x00000400 -#define CFCTYPE_ARBITRARY 0x00000800 -#define CFCTYPE_COMPOSITE 0x00001000 +#define CFCTYPE_CONST (1 << 0) +#define CFCTYPE_NULLABLE (1 << 1) +#define CFCTYPE_VOID (1 << 2) +#define CFCTYPE_INCREMENTED (1 << 3) +#define CFCTYPE_DECREMENTED (1 << 4) +#define CFCTYPE_OBJECT (1 << 5) +#define CFCTYPE_PRIMITIVE (1 << 6) +#define CFCTYPE_INTEGER (1 << 7) +#define CFCTYPE_FLOATING (1 << 8) +#define CFCTYPE_CFISH_OBJ (1 << 9) +#define CFCTYPE_CFISH_STRING (1 << 10) +#define CFCTYPE_CFISH_BLOB (1 << 12) +#define CFCTYPE_CFISH_INTEGER (1 << 13) +#define CFCTYPE_CFISH_FLOAT (1 << 14) +#define CFCTYPE_CFISH_BOOLEAN (1 << 15) +#define CFCTYPE_CFISH_VECTOR (1 << 16) +#define CFCTYPE_CFISH_HASH (1 << 17) +#define CFCTYPE_VA_LIST (1 << 18) +#define CFCTYPE_ARBITRARY (1 << 19) +#define CFCTYPE_COMPOSITE (1 << 20) /** Generic constructor. * @@ -104,8 +111,9 @@ CFCType_new_float(int flags, const char *specifier); * * The Parcel's prefix will be prepended to the specifier by new_object(). * - * @param flags Allowed flags: OBJECT, STRING_TYPE, CONST, NULLABLE, - * INCREMENTED, DECREMENTED. + * @param flags Allowed flags: OBJECT, CFISH_OBJ, CFISH_STRING, CFISH_BLOB, + * CFISH_INTEGER, CFISH_FLOAT, CFISH_BOOLEAN, CFISH_VECTOR, CFISH_HASH, CONST, + * NULLABLE, INCREMENTED, DECREMENTED. * @param parcel A Clownfish::CFC::Model::Parcel. * @param specifier Required. Must follow the rules for * Clownfish::CFC::Model::Class class name components. @@ -255,12 +263,51 @@ CFCType_is_integer(CFCType *self); int CFCType_is_floating(CFCType *self); -/** Returns true if $type represents a Clownfish type which holds unicode - * strings. +/** Returns true if the type is Clownfish::Obj. + */ +int +CFCType_cfish_obj(CFCType *self); + +/** Returns true if the type is Clownfish::String. */ int CFCType_is_string_type(CFCType *self); +/** Returns true if the type is Clownfish::String. + */ +int +CFCType_cfish_string(CFCType *self); + +/** Returns true if the type is Clownfish::Blob. + */ +int +CFCType_cfish_blob(CFCType *self); + +/** Returns true if the type is Clownfish::Integer. + */ +int +CFCType_cfish_integer(CFCType *self); + +/** Returns true if the type is Clownfish::Float. + */ +int +CFCType_cfish_float(CFCType *self); + +/** Returns true if the type is Clownfish::Boolean + */ +int +CFCType_cfish_boolean(CFCType *self); + +/** Returns true if the type is Clownfish::Vector. + */ +int +CFCType_cfish_vector(CFCType *self); + +/** Returns true if the type is Clownfish::Hash. + */ +int +CFCType_cfish_hash(CFCType *self); + int CFCType_is_va_list(CFCType *self);
