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 2014/04/27 01:11:44 UTC
[lucy-commits] [14/54] [abbrv] Remove bundled Clownfish.
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCLexHeader.l
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCLexHeader.l b/clownfish/compiler/src/CFCLexHeader.l
deleted file mode 100644
index 567cbeb..0000000
--- a/clownfish/compiler/src/CFCLexHeader.l
+++ /dev/null
@@ -1,137 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-%{
- #include "CFC.h"
- #include "CFCParseHeader.h"
-
- /* Dupe yytext and invoke Lemon-generated parser. */
- #define PARSE(token_type) \
- CFCParseHeader(CFCParser_current_parser, token_type, \
- CFCParser_dupe(CFCParser_current_state, yytext), \
- CFCParser_current_state)
-
- struct cfc_StringID {
- const char *string;
- int token_type;
- };
- struct cfc_StringID reserved_word_map[] = {
- {"NULL", CFC_TOKENTYPE_NULL },
- {"abstract", CFC_TOKENTYPE_ABSTRACT },
- {"bool", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"char", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"class", CFC_TOKENTYPE_CLASS },
- {"cnick", CFC_TOKENTYPE_CNICK },
- {"const", CFC_TOKENTYPE_CONST },
- {"decremented", CFC_TOKENTYPE_DECREMENTED },
- {"double", CFC_TOKENTYPE_FLOAT_TYPE_NAME },
- {"false", CFC_TOKENTYPE_FALSE },
- {"final", CFC_TOKENTYPE_FINAL },
- {"float", CFC_TOKENTYPE_FLOAT_TYPE_NAME },
- {"incremented", CFC_TOKENTYPE_INCREMENTED },
- {"inert", CFC_TOKENTYPE_INERT },
- {"inherits", CFC_TOKENTYPE_INHERITS },
- {"inline", CFC_TOKENTYPE_INLINE },
- {"int", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"int16_t", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"int32_t", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"int64_t", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"int8_t", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"long", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"nullable", CFC_TOKENTYPE_NULLABLE },
- {"parcel", CFC_TOKENTYPE_PARCEL },
- {"public", CFC_TOKENTYPE_PUBLIC },
- {"short", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"size_t", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"true", CFC_TOKENTYPE_TRUE },
- {"uint16_t", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"uint32_t", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"uint64_t", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"uint8_t", CFC_TOKENTYPE_INTEGER_TYPE_NAME },
- {"va_list", CFC_TOKENTYPE_VA_LIST },
- {"void", CFC_TOKENTYPE_VOID },
- };
- #define NUM_RESERVED_WORDS \
- (sizeof(reserved_word_map) / sizeof(struct cfc_StringID))
-
- static int
- S_compare(const void *va, const void *vb) {
- const char *a = (const char*)va;
- struct cfc_StringID *b
- = (struct cfc_StringID*)vb;
- return strcmp(a, b->string);
- }
-
- static int
- S_identifier_or_keyword(const char *word) {
- struct cfc_StringID *got = (struct cfc_StringID*)
- bsearch(word, reserved_word_map, NUM_RESERVED_WORDS,
- sizeof(struct cfc_StringID), S_compare);
- if (got) {
- return got->token_type;
- }
- else {
- return CFC_TOKENTYPE_IDENTIFIER;
- }
- }
-%}
-
-%option noyywrap
-%option nodefault
-%option yylineno
-%option never-interactive
-
-%x CBLOCK
-
-%%
-:: { PARSE(CFC_TOKENTYPE_SCOPE_OP); }
-[*] { PARSE(CFC_TOKENTYPE_ASTERISK); }
-\{ { PARSE(CFC_TOKENTYPE_LEFT_CURLY_BRACE); }
-\} { PARSE(CFC_TOKENTYPE_RIGHT_CURLY_BRACE); }
-[\[] { PARSE(CFC_TOKENTYPE_LEFT_SQUARE_BRACKET); }
-[\]] { PARSE(CFC_TOKENTYPE_RIGHT_SQUARE_BRACKET); }
-[\(] { PARSE(CFC_TOKENTYPE_LEFT_PAREN); }
-[\)] { PARSE(CFC_TOKENTYPE_RIGHT_PAREN); }
-\.\.\. { PARSE(CFC_TOKENTYPE_ELLIPSIS); }
-, { PARSE(CFC_TOKENTYPE_COMMA); }
-; { PARSE(CFC_TOKENTYPE_SEMICOLON); }
-= { PARSE(CFC_TOKENTYPE_EQUALS); }
-
--?0x[0-9A-Fa-f]+ { PARSE(CFC_TOKENTYPE_HEX_LITERAL); }
--?[0-9]+\.[0-9]+ { PARSE(CFC_TOKENTYPE_FLOAT_LITERAL); }
--?[0-9]+ { PARSE(CFC_TOKENTYPE_INTEGER_LITERAL); }
-\"([^\"\\]|\\.)*\" { PARSE(CFC_TOKENTYPE_STRING_LITERAL); }
-
-[a-zA-Z_][a-zA-Z0-9_]* { PARSE(S_identifier_or_keyword(yytext)); }
-
-__C__[[:space:]]* { BEGIN(CBLOCK); PARSE(CFC_TOKENTYPE_CBLOCK_START); }
-<CBLOCK>__END_C__ { BEGIN(INITIAL); PARSE(CFC_TOKENTYPE_CBLOCK_CLOSE); }
-<CBLOCK>__END_C_[^_] { PARSE(CFC_TOKENTYPE_BLOB); }
-<CBLOCK>[^_]+ { PARSE(CFC_TOKENTYPE_BLOB); }
-<CBLOCK>_+ { PARSE(CFC_TOKENTYPE_BLOB); }
-
- /* Parse docucomments, but skip ordinary comments */
-"/**"([^*]|"*"[^/])*"*/" { PARSE(CFC_TOKENTYPE_DOCUCOMMENT); }
-"/*"([^*]|"*"[^/])*"*/"
-
-[ \t\r\n] /* Skip whitespace. */
-<*>. {
- printf("Bad input character '%s' at line %d\n", yytext, yylineno);
- yyterminate();
- }
-<<EOF>> { yyterminate(); }
-%%
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCMemPool.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCMemPool.c b/clownfish/compiler/src/CFCMemPool.c
deleted file mode 100644
index bf16306..0000000
--- a/clownfish/compiler/src/CFCMemPool.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-
-#define CFC_NEED_BASE_STRUCT_DEF
-#include "CFCBase.h"
-#include "CFCMemPool.h"
-#include "CFCUtil.h"
-
-struct CFCMemPool {
- CFCBase base;
- size_t arena_size;
- size_t remaining;
- char *current;
- size_t num_arenas;
- char **arenas;
-};
-
-static const CFCMeta CFCMEMPOOL_META = {
- "Clownfish::MemPool",
- sizeof(CFCMemPool),
- (CFCBase_destroy_t)CFCMemPool_destroy
-};
-
-CFCMemPool*
-CFCMemPool_new(size_t arena_size) {
- CFCMemPool *self = (CFCMemPool*)CFCBase_allocate(&CFCMEMPOOL_META);
- return CFCMemPool_init(self, arena_size);
-}
-
-CFCMemPool*
-CFCMemPool_init(CFCMemPool *self, size_t arena_size) {
- arena_size = arena_size ? arena_size : 0x400; // 1k
- self->current = NULL;
- self->arena_size = arena_size;
- self->remaining = 0;
- self->num_arenas = 0;
- self->arenas = NULL;
- return self;
-}
-
-void*
-CFCMemPool_allocate(CFCMemPool *self, size_t size) {
- size_t overage = (8 - (size % 8)) % 8;
- size_t amount = size + overage;
- size_t arena_size = self->arena_size > amount
- ? self->arena_size : amount;
- if (amount > self->remaining) {
- self->num_arenas += 1;
- self->arenas = (char**)REALLOCATE(self->arenas,
- self->num_arenas * sizeof(char*));
- self->current = (char*)MALLOCATE(arena_size);
- self->arenas[self->num_arenas - 1] = self->current;
- self->remaining = amount;
- }
- size_t offset = arena_size - self->remaining;
- void *result = self->current + offset;
- self->remaining -= amount;
- return result;
-}
-
-void
-CFCMemPool_destroy(CFCMemPool *self) {
- for (size_t i = 0; i < self->num_arenas; i++) {
- FREEMEM(self->arenas[i]);
- }
- FREEMEM(self->arenas);
- CFCBase_destroy((CFCBase*)self);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCMemPool.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCMemPool.h b/clownfish/compiler/src/CFCMemPool.h
deleted file mode 100644
index c315686..0000000
--- a/clownfish/compiler/src/CFCMemPool.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef H_CFCMEMPOOL
-#define H_CFCMEMPOOL
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct CFCMemPool CFCMemPool;
-
-CFCMemPool*
-CFCMemPool_new(size_t arena_size);
-
-CFCMemPool*
-CFCMemPool_init(CFCMemPool *self, size_t arena_size);
-
-void*
-CFCMemPool_allocate(CFCMemPool *self, size_t size);
-
-void
-CFCMemPool_destroy(CFCMemPool *self);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_CFCMEMPOOL */
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCMethod.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCMethod.c b/clownfish/compiler/src/CFCMethod.c
deleted file mode 100644
index f5780e2..0000000
--- a/clownfish/compiler/src/CFCMethod.c
+++ /dev/null
@@ -1,439 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-#include <ctype.h>
-#include <stdio.h>
-
-#define CFC_NEED_FUNCTION_STRUCT_DEF
-#include "CFCFunction.h"
-#include "CFCMethod.h"
-#include "CFCType.h"
-#include "CFCClass.h"
-#include "CFCUtil.h"
-#include "CFCParamList.h"
-#include "CFCParcel.h"
-#include "CFCDocuComment.h"
-#include "CFCVariable.h"
-
-#ifndef true
- #define true 1
- #define false 0
-#endif
-
-struct CFCMethod {
- CFCFunction function;
- char *macro_sym;
- char *full_override_sym;
- char *host_alias;
- char *short_imp_func;
- char *imp_func;
- int is_final;
- int is_abstract;
- int is_novel;
- int is_excluded;
-};
-
-static const CFCMeta CFCMETHOD_META = {
- "Clownfish::CFC::Model::Method",
- sizeof(CFCMethod),
- (CFCBase_destroy_t)CFCMethod_destroy
-};
-
-CFCMethod*
-CFCMethod_new(CFCParcel *parcel, const char *exposure, const char *class_name,
- const char *class_cnick, const char *macro_sym,
- CFCType *return_type, CFCParamList *param_list,
- CFCDocuComment *docucomment, int is_final, int is_abstract) {
- CFCMethod *self = (CFCMethod*)CFCBase_allocate(&CFCMETHOD_META);
- return CFCMethod_init(self, parcel, exposure, class_name, class_cnick,
- macro_sym, return_type, param_list, docucomment,
- is_final, is_abstract);
-}
-
-static int
-S_validate_macro_sym(const char *macro_sym) {
- if (!macro_sym || !strlen(macro_sym)) { return false; }
-
- int need_upper = true;
- int need_letter = true;
- for (;; macro_sym++) {
- if (need_upper && !isupper(*macro_sym)) { return false; }
- if (need_letter && !isalpha(*macro_sym)) { return false; }
- need_upper = false;
- need_letter = false;
-
- // We've reached NULL-termination without problems, so succeed.
- if (!*macro_sym) { return true; }
-
- if (!isalnum(*macro_sym)) {
- if (*macro_sym != '_') { return false; }
- need_upper = true;
- }
- }
-}
-
-CFCMethod*
-CFCMethod_init(CFCMethod *self, CFCParcel *parcel, const char *exposure,
- const char *class_name, const char *class_cnick,
- const char *macro_sym, CFCType *return_type,
- CFCParamList *param_list, CFCDocuComment *docucomment,
- int is_final, int is_abstract) {
- // Validate macro_sym, derive micro_sym.
- if (!S_validate_macro_sym(macro_sym)) {
- CFCBase_decref((CFCBase*)self);
- CFCUtil_die("Invalid macro_sym: '%s'",
- macro_sym ? macro_sym : "[NULL]");
- }
- char *micro_sym = CFCUtil_strdup(macro_sym);
- for (size_t i = 0; micro_sym[i] != '\0'; i++) {
- micro_sym[i] = tolower(micro_sym[i]);
- }
-
- // Super-init and clean up derived micro_sym.
- CFCFunction_init((CFCFunction*)self, parcel, exposure, class_name,
- class_cnick, micro_sym, return_type, param_list,
- docucomment, false);
- FREEMEM(micro_sym);
-
- // Verify that the first element in the arg list is a self.
- CFCVariable **args = CFCParamList_get_variables(param_list);
- if (!args[0]) { CFCUtil_die("Missing 'self' argument"); }
- CFCType *type = CFCVariable_get_type(args[0]);
- const char *specifier = CFCType_get_specifier(type);
- const char *prefix = CFCMethod_get_prefix(self);
- const char *last_colon = strrchr(class_name, ':');
- const char *struct_sym = last_colon ? last_colon + 1 : class_name;
- if (strcmp(specifier, struct_sym) != 0) {
- char *wanted = CFCUtil_sprintf("%s%s", prefix, struct_sym);
- int mismatch = strcmp(wanted, specifier);
- FREEMEM(wanted);
- if (mismatch) {
- CFCUtil_die("First arg type doesn't match class: '%s' '%s'",
- class_name, specifier);
- }
- }
-
- self->macro_sym = CFCUtil_strdup(macro_sym);
- self->full_override_sym = NULL;
- self->host_alias = NULL;
- self->is_final = is_final;
- self->is_abstract = is_abstract;
- self->is_excluded = false;
-
- // Derive name of implementing function.
- self->short_imp_func
- = CFCUtil_sprintf("%s_%s_IMP", CFCMethod_get_class_cnick(self),
- self->macro_sym);
- self->imp_func = CFCUtil_sprintf("%s%s", CFCMethod_get_PREFIX(self),
- self->short_imp_func);
-
- // Assume that this method is novel until we discover when applying
- // inheritance that it overrides another.
- self->is_novel = true;
-
- return self;
-}
-
-void
-CFCMethod_resolve_types(CFCMethod *self, struct CFCClass **classes) {
- CFCFunction_resolve_types((CFCFunction*)self, classes);
-}
-
-void
-CFCMethod_destroy(CFCMethod *self) {
- FREEMEM(self->macro_sym);
- FREEMEM(self->full_override_sym);
- FREEMEM(self->host_alias);
- FREEMEM(self->short_imp_func);
- FREEMEM(self->imp_func);
- CFCFunction_destroy((CFCFunction*)self);
-}
-
-int
-CFCMethod_compatible(CFCMethod *self, CFCMethod *other) {
- if (!other) { return false; }
- if (strcmp(self->macro_sym, other->macro_sym)) { return false; }
- int my_public = CFCMethod_public(self);
- int other_public = CFCMethod_public(other);
- if (!!my_public != !!other_public) { return false; }
-
- // Check arguments and initial values.
- CFCParamList *my_param_list = self->function.param_list;
- CFCParamList *other_param_list = other->function.param_list;
- CFCVariable **my_args = CFCParamList_get_variables(my_param_list);
- CFCVariable **other_args = CFCParamList_get_variables(other_param_list);
- const char **my_vals = CFCParamList_get_initial_values(my_param_list);
- const char **other_vals = CFCParamList_get_initial_values(other_param_list);
- for (size_t i = 1; ; i++) { // start at 1, skipping self
- if (!!my_args[i] != !!other_args[i]) { return false; }
- if (!!my_vals[i] != !!other_vals[i]) { return false; }
- if (my_vals[i]) {
- if (strcmp(my_vals[i], other_vals[i])) { return false; }
- }
- if (my_args[i]) {
- if (!CFCVariable_equals(my_args[i], other_args[i])) {
- return false;
- }
- }
- else {
- break;
- }
- }
-
- // Check return types.
- CFCType *type = CFCMethod_get_return_type(self);
- CFCType *other_type = CFCMethod_get_return_type(other);
- if (CFCType_is_object(type)) {
- // Weak validation to allow covariant object return types.
- if (!CFCType_is_object(other_type)) { return false; }
- if (!CFCType_similar(type, other_type)) { return false; }
- }
- else {
- if (!CFCType_equals(type, other_type)) { return false; }
- }
-
- return true;
-}
-
-void
-CFCMethod_override(CFCMethod *self, CFCMethod *orig) {
- // Check that the override attempt is legal.
- if (CFCMethod_final(orig)) {
- const char *orig_class = CFCMethod_get_class_name(orig);
- const char *my_class = CFCMethod_get_class_name(self);
- CFCUtil_die("Attempt to override final method '%s' from '%s' by '%s'",
- orig->macro_sym, orig_class, my_class);
- }
- if (!CFCMethod_compatible(self, orig)) {
- const char *func = CFCMethod_imp_func(self);
- const char *orig_func = CFCMethod_imp_func(orig);
- CFCUtil_die("Non-matching signatures for %s and %s", func, orig_func);
- }
-
- // Mark the Method as no longer novel.
- self->is_novel = false;
-}
-
-CFCMethod*
-CFCMethod_finalize(CFCMethod *self) {
- CFCParcel *parcel = CFCMethod_get_parcel(self);
- const char *exposure = CFCMethod_get_exposure(self);
- const char *class_name = CFCMethod_get_class_name(self);
- const char *class_cnick = CFCMethod_get_class_cnick(self);
- CFCMethod *finalized
- = CFCMethod_new(parcel, exposure, class_name, class_cnick,
- self->macro_sym, self->function.return_type,
- self->function.param_list,
- self->function.docucomment, true,
- self->is_abstract);
- finalized->is_novel = self->is_novel;
- return finalized;
-}
-
-void
-CFCMethod_set_host_alias(CFCMethod *self, const char *alias) {
- if (!alias || !alias[0]) {
- CFCUtil_die("Missing required param 'alias'");
- }
- if (!self->is_novel) {
- CFCUtil_die("Can't set_host_alias %s -- method %s not novel in %s",
- alias, self->macro_sym, CFCMethod_get_class_name(self));
- }
- if (self->host_alias) {
- if (strcmp(self->host_alias, alias) == 0) { return; }
- CFCUtil_die("Can't set_host_alias %s -- already set to %s for method"
- " %s in %s", alias, self->host_alias, self->macro_sym,
- CFCMethod_get_class_name(self));
- }
- self->host_alias = CFCUtil_strdup(alias);
-}
-
-const char*
-CFCMethod_get_host_alias(CFCMethod *self) {
- return self->host_alias;
-}
-
-void
-CFCMethod_exclude_from_host(CFCMethod *self) {
- if (!self->is_novel) {
- CFCUtil_die("Can't exclude_from_host -- method %s not novel in %s",
- self->macro_sym, CFCMethod_get_class_name(self));
- }
- self->is_excluded = true;
-}
-
-int
-CFCMethod_excluded_from_host(CFCMethod *self) {
- return self->is_excluded;
-}
-
-static char*
-S_short_method_sym(CFCMethod *self, CFCClass *invoker, const char *postfix) {
- const char *cnick;
- if (invoker) {
- cnick = CFCClass_get_cnick(invoker);
- }
- else {
- cnick = CFCMethod_get_class_cnick(self);
- }
- return CFCUtil_sprintf("%s_%s%s", cnick, self->macro_sym, postfix);
-}
-
-static char*
-S_full_method_sym(CFCMethod *self, CFCClass *invoker, const char *postfix) {
- const char *PREFIX;
- const char *cnick;
- if (invoker) {
- PREFIX = CFCClass_get_PREFIX(invoker);
- cnick = CFCClass_get_cnick(invoker);
- }
- else {
- PREFIX = CFCMethod_get_PREFIX(self);
- cnick = CFCMethod_get_class_cnick(self);
- }
- return CFCUtil_sprintf("%s%s_%s%s", PREFIX, cnick, self->macro_sym,
- postfix);
-}
-
-char*
-CFCMethod_short_method_sym(CFCMethod *self, CFCClass *invoker) {
- return S_short_method_sym(self, invoker, "");
-}
-
-char*
-CFCMethod_full_method_sym(CFCMethod *self, CFCClass *invoker) {
- return S_full_method_sym(self, invoker, "");
-}
-
-char*
-CFCMethod_full_offset_sym(CFCMethod *self, CFCClass *invoker) {
- return S_full_method_sym(self, invoker, "_OFFSET");
-}
-
-const char*
-CFCMethod_get_macro_sym(CFCMethod *self) {
- return self->macro_sym;
-}
-
-const char*
-CFCMethod_micro_sym(CFCMethod *self) {
- return CFCSymbol_micro_sym((CFCSymbol*)self);
-}
-
-char*
-CFCMethod_short_typedef(CFCMethod *self, CFCClass *invoker) {
- return S_short_method_sym(self, invoker, "_t");
-}
-
-char*
-CFCMethod_full_typedef(CFCMethod *self, CFCClass *invoker) {
- return S_full_method_sym(self, invoker, "_t");
-}
-
-const char*
-CFCMethod_full_override_sym(CFCMethod *self) {
- if (!self->full_override_sym) {
- const char *Prefix = CFCMethod_get_Prefix(self);
- const char *cnick = CFCMethod_get_class_cnick(self);
- self->full_override_sym
- = CFCUtil_sprintf("%s%s_%s_OVERRIDE", Prefix, cnick,
- self->macro_sym);
- }
- return self->full_override_sym;
-}
-
-int
-CFCMethod_final(CFCMethod *self) {
- return self->is_final;
-}
-
-int
-CFCMethod_abstract(CFCMethod *self) {
- return self->is_abstract;
-}
-
-int
-CFCMethod_novel(CFCMethod *self) {
- return self->is_novel;
-}
-
-CFCType*
-CFCMethod_self_type(CFCMethod *self) {
- CFCVariable **vars = CFCParamList_get_variables(self->function.param_list);
- return CFCVariable_get_type(vars[0]);
-}
-
-CFCParcel*
-CFCMethod_get_parcel(CFCMethod *self) {
- return CFCSymbol_get_parcel((CFCSymbol*)self);
-}
-
-const char*
-CFCMethod_get_prefix(CFCMethod *self) {
- return CFCSymbol_get_prefix((CFCSymbol*)self);
-}
-
-const char*
-CFCMethod_get_Prefix(CFCMethod *self) {
- return CFCSymbol_get_Prefix((CFCSymbol*)self);
-}
-
-const char*
-CFCMethod_get_PREFIX(CFCMethod *self) {
- return CFCSymbol_get_PREFIX((CFCSymbol*)self);
-}
-
-const char*
-CFCMethod_get_exposure(CFCMethod *self) {
- return CFCSymbol_get_exposure((CFCSymbol*)self);
-}
-
-const char*
-CFCMethod_get_class_name(CFCMethod *self) {
- return CFCSymbol_get_class_name((CFCSymbol*)self);
-}
-
-const char*
-CFCMethod_get_class_cnick(CFCMethod *self) {
- return CFCSymbol_get_class_cnick((CFCSymbol*)self);
-}
-
-int
-CFCMethod_public(CFCMethod *self) {
- return CFCSymbol_public((CFCSymbol*)self);
-}
-
-CFCType*
-CFCMethod_get_return_type(CFCMethod *self) {
- return CFCFunction_get_return_type((CFCFunction*)self);
-}
-
-CFCParamList*
-CFCMethod_get_param_list(CFCMethod *self) {
- return CFCFunction_get_param_list((CFCFunction*)self);
-}
-
-const char*
-CFCMethod_imp_func(CFCMethod *self) {
- return self->imp_func;
-}
-
-const char*
-CFCMethod_short_imp_func(CFCMethod *self) {
- return self->short_imp_func;
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCMethod.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCMethod.h b/clownfish/compiler/src/CFCMethod.h
deleted file mode 100644
index 0c96220..0000000
--- a/clownfish/compiler/src/CFCMethod.h
+++ /dev/null
@@ -1,244 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/** Clownfish::CFC::Model::Method - Metadata describing an instance method.
- *
- * Clownfish::CFC::Model::Method is a specialized subclass of
- * Clownfish::CFC::Model::Function, with the first argument required to be an
- * Obj.
- *
- * When compiling Clownfish code to C, Method objects generate all the code
- * that Function objects do, but also create symbols for indirect invocation via
- * VTable.
- */
-
-#ifndef H_CFCMETHOD
-#define H_CFCMETHOD
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct CFCMethod CFCMethod;
-struct CFCParcel;
-struct CFCType;
-struct CFCClass;
-struct CFCParamList;
-struct CFCDocuComment;
-
-/**
- * @param parcel See Clownfish::CFC::Model::Function.
- * @param exposure See Clownfish::CFC::Model::Function. Defaults to "parcel"
- * if not supplied.
- * @param class_name See Clownfish::CFC::Model::Function.
- * @param class_cnick See Clownfish::CFC::Model::Function.
- * @param macro_sym - The mixed case name which will be used when invoking the
- * method.
- * @param return_type See Clownfish::CFC::Model::Function.
- * @param param_list - A Clownfish::CFC::Model::ParamList. The first element
- * must be an object of the class identified by C<class_name>.
- * @param docucomment see Clownfish::CFC::Model::Function. May be NULL.
- * @param is_final - Indicate whether the method is final.
- * @param is_abstract - Indicate whether the method is abstract.
- */
-CFCMethod*
-CFCMethod_new(struct CFCParcel *parcel, const char *exposure,
- const char *class_name, const char *class_cnick,
- const char *macro_sym, struct CFCType *return_type,
- struct CFCParamList *param_list,
- struct CFCDocuComment *docucomment, int is_final,
- int is_abstract);
-
-CFCMethod*
-CFCMethod_init(CFCMethod *self, struct CFCParcel *parcel,
- const char *exposure, const char *class_name,
- const char *class_cnick, const char *macro_sym,
- struct CFCType *return_type, struct CFCParamList *param_list,
- struct CFCDocuComment *docucomment, int is_final,
- int is_abstract);
-
-void
-CFCMethod_resolve_types(CFCMethod *self, struct CFCClass **classes);
-
-void
-CFCMethod_destroy(CFCMethod *self);
-
-/** Returns true if the methods have signatures and attributes which allow one
- * to override the other.
- */
-int
-CFCMethod_compatible(CFCMethod *self, CFCMethod *other);
-
-/** Let the Method know that it is overriding a method which was defined in a
- * parent class, and verify that the override is valid.
- *
- * All methods start out believing that they are "novel", because we don't
- * know about inheritance until we build the hierarchy after all files have
- * been parsed. override() is a way of going back and relabeling a method as
- * overridden when new information has become available: in this case, that a
- * parent class has defined a method with the same name.
- */
-void
-CFCMethod_override(CFCMethod *self, CFCMethod *orig);
-
-/** As with override, above, this is for going back and changing the nature of
- * a Method after new information has become available -- typically, when we
- * discover that the method has been inherited by a "final" class.
- *
- * However, we don't modify the original Method as with override(). Inherited
- * Method objects are shared between parent and child classes; if a shared
- * Method object were to become final, it would interfere with its own
- * inheritance. So, we make a copy, slightly modified to indicate that it is
- * "final".
- */
-CFCMethod*
-CFCMethod_finalize(CFCMethod *self);
-
-/**
- * Create the symbol used to invoke the method without the parcel Prefix, e.g.
- * "LobClaw_Pinch".
- * @param invoker Class for which the symbol is created. If invoker is NULL,
- * use the class where the method is defined.
- *
- * @return the symbol.
- */
-char*
-CFCMethod_short_method_sym(CFCMethod *self, struct CFCClass *invoker);
-
-/**
- * Create the fully-qualified symbol used to invoke the method, e.g.
- * "Crust_LobClaw_Pinch".
- * @param invoker Class for which the symbol is created. If invoker is NULL,
- * use the class where the method is defined.
- *
- * @return the symbol.
- */
-char*
-CFCMethod_full_method_sym(CFCMethod *self, struct CFCClass *invoker);
-
-/** Create the fully qualified name of the variable which stores the method's
- * vtable offset, e.g. "Crust_LobClaw_Pinch_OFFSET".
- * @param invoker Class for which the symbol is created. If invoker is NULL,
- * use the class where the method is defined.
- *
- * @return the symbol.
- */
-char*
-CFCMethod_full_offset_sym(CFCMethod *self, struct CFCClass *invoker);
-
-const char*
-CFCMethod_get_macro_sym(CFCMethod *self);
-
-const char*
-CFCMethod_micro_sym(CFCMethod *self);
-
-/** Create the typedef symbol for this method, e.g "Claw_Pinch_t".
- * @param invoker Class for which the symbol is created. If invoker is NULL,
- * use the class where the method is defined.
- *
- * @return the symbol.
- */
-char*
-CFCMethod_short_typedef(CFCMethod *self, struct CFCClass *invoker);
-
-/** Create the fully-qualified typedef symbol, e.g. "Crust_Claw_Pinch_t".
- * @param invoker Class for which the symbol is created. If invoker is NULL,
- * use the class where the method is defined.
- *
- * @return the symbol.
- */
-char*
-CFCMethod_full_typedef(CFCMethod *self, struct CFCClass *invoker);
-
-/** Returns the fully qualified name of the function which implements the
- * callback to the host in the event that a host method has been defined which
- * overrides this method, e.g. "crust_LobClaw_pinch_OVERRIDE".
- */
-const char*
-CFCMethod_full_override_sym(CFCMethod *self);
-
-int
-CFCMethod_final(CFCMethod *self);
-
-int
-CFCMethod_abstract(CFCMethod *self);
-
-/** Returns true if this method is the first implemenation in the inheritance
- * hierarchy in which the method was declared.
- */
-int
-CFCMethod_novel(CFCMethod *self);
-
-/** Return the Clownfish::CFC::Model::Type for <code>self</code>.
- */
-
-struct CFCType*
-CFCMethod_self_type(CFCMethod *self);
-
-void
-CFCMethod_set_host_alias(CFCMethod *self, const char *alias);
-
-const char*
-CFCMethod_get_host_alias(CFCMethod *self);
-
-void
-CFCMethod_exclude_from_host(CFCMethod *self);
-
-int
-CFCMethod_excluded_from_host(CFCMethod *self);
-
-struct CFCParcel*
-CFCMethod_get_parcel(CFCMethod *self);
-
-const char*
-CFCMethod_get_prefix(CFCMethod *self);
-
-const char*
-CFCMethod_get_Prefix(CFCMethod *self);
-
-const char*
-CFCMethod_get_PREFIX(CFCMethod *self);
-
-const char*
-CFCMethod_get_exposure(CFCMethod *self);
-
-const char*
-CFCMethod_get_class_name(CFCMethod *self);
-
-const char*
-CFCMethod_get_class_cnick(CFCMethod *self);
-
-int
-CFCMethod_public(CFCMethod *self);
-
-struct CFCType*
-CFCMethod_get_return_type(CFCMethod *self);
-
-struct CFCParamList*
-CFCMethod_get_param_list(CFCMethod *self);
-
-const char*
-CFCMethod_imp_func(CFCMethod *self);
-
-const char*
-CFCMethod_short_imp_func(CFCMethod *self);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_CFCMETHOD */
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCParamList.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCParamList.c b/clownfish/compiler/src/CFCParamList.c
deleted file mode 100644
index 087030c..0000000
--- a/clownfish/compiler/src/CFCParamList.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-
-#define CFC_NEED_BASE_STRUCT_DEF
-#include "CFCBase.h"
-#include "CFCParamList.h"
-#include "CFCVariable.h"
-#include "CFCSymbol.h"
-#include "CFCUtil.h"
-
-struct CFCParamList {
- CFCBase base;
- CFCVariable **variables;
- char **values;
- int variadic;
- size_t num_vars;
- char *c_string;
- char *name_list;
-};
-
-//
-static void
-S_generate_c_strings(CFCParamList *self);
-
-static const CFCMeta CFCPARAMLIST_META = {
- "Clownfish::CFC::Model::ParamList",
- sizeof(CFCParamList),
- (CFCBase_destroy_t)CFCParamList_destroy
-};
-
-CFCParamList*
-CFCParamList_new(int variadic) {
- CFCParamList *self = (CFCParamList*)CFCBase_allocate(&CFCPARAMLIST_META);
- return CFCParamList_init(self, variadic);
-}
-
-CFCParamList*
-CFCParamList_init(CFCParamList *self, int variadic) {
- self->variadic = variadic;
- self->num_vars = 0;
- self->variables = (CFCVariable**)CALLOCATE(1, sizeof(void*));
- self->values = (char**)CALLOCATE(1, sizeof(char*));
- self->c_string = NULL;
- self->name_list = NULL;
- return self;
-}
-
-void
-CFCParamList_resolve_types(CFCParamList *self, struct CFCClass **classes) {
- for (size_t i = 0; self->variables[i]; ++i) {
- CFCVariable_resolve_type(self->variables[i], classes);
- }
-}
-
-void
-CFCParamList_add_param(CFCParamList *self, CFCVariable *variable,
- const char *value) {
- CFCUTIL_NULL_CHECK(variable);
- self->num_vars++;
- size_t amount = (self->num_vars + 1) * sizeof(void*);
- self->variables = (CFCVariable**)REALLOCATE(self->variables, amount);
- self->values = (char**)REALLOCATE(self->values, amount);
- self->variables[self->num_vars - 1]
- = (CFCVariable*)CFCBase_incref((CFCBase*)variable);
- self->values[self->num_vars - 1] = value ? CFCUtil_strdup(value) : NULL;
- self->variables[self->num_vars] = NULL;
- self->values[self->num_vars] = NULL;
-}
-
-void
-CFCParamList_destroy(CFCParamList *self) {
- for (size_t i = 0; i < self->num_vars; i++) {
- CFCBase_decref((CFCBase*)self->variables[i]);
- FREEMEM(self->values[i]);
- }
- FREEMEM(self->variables);
- FREEMEM(self->values);
- FREEMEM(self->c_string);
- FREEMEM(self->name_list);
- CFCBase_destroy((CFCBase*)self);
-}
-
-static void
-S_generate_c_strings(CFCParamList *self) {
- size_t c_string_size = 1;
- size_t name_list_size = 1;
-
- // Calc space requirements and allocate memory.
- for (size_t i = 0; i < self->num_vars; i++) {
- CFCVariable *var = self->variables[i];
- c_string_size += sizeof(", ");
- c_string_size += strlen(CFCVariable_local_c(var));
- name_list_size += sizeof(", ");
- name_list_size += strlen(CFCVariable_micro_sym(var));
- }
- if (self->variadic) {
- c_string_size += sizeof(", ...");
- }
- if (self->num_vars == 0) {
- c_string_size += sizeof("void");
- }
- self->c_string = (char*)MALLOCATE(c_string_size);
- self->name_list = (char*)MALLOCATE(name_list_size);
- self->c_string[0] = '\0';
- self->name_list[0] = '\0';
-
- // Build the strings.
- for (size_t i = 0; i < self->num_vars; i++) {
- CFCVariable *var = self->variables[i];
- strcat(self->c_string, CFCVariable_local_c(var));
- strcat(self->name_list, CFCVariable_micro_sym(var));
- if (i == self->num_vars - 1) {
- if (self->variadic) {
- strcat(self->c_string, ", ...");
- }
- }
- else {
- strcat(self->c_string, ", ");
- strcat(self->name_list, ", ");
- }
- }
- if (self->num_vars == 0) {
- strcat(self->c_string, "void");
- }
-}
-
-CFCVariable**
-CFCParamList_get_variables(CFCParamList *self) {
- return self->variables;
-}
-
-const char**
-CFCParamList_get_initial_values(CFCParamList *self) {
- return (const char**)self->values;
-}
-
-size_t
-CFCParamList_num_vars(CFCParamList *self) {
- return self->num_vars;
-}
-
-void
-CFCParamList_set_variadic(CFCParamList *self, int variadic) {
- self->variadic = !!variadic;
-}
-
-int
-CFCParamList_variadic(CFCParamList *self) {
- return self->variadic;
-}
-
-const char*
-CFCParamList_to_c(CFCParamList *self) {
- if (!self->c_string) { S_generate_c_strings(self); }
- return self->c_string;
-}
-
-const char*
-CFCParamList_name_list(CFCParamList *self) {
- if (!self->name_list) { S_generate_c_strings(self); }
- return self->name_list;
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCParamList.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCParamList.h b/clownfish/compiler/src/CFCParamList.h
deleted file mode 100644
index 886fdfe..0000000
--- a/clownfish/compiler/src/CFCParamList.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/** Clownfish::CFC::Model::ParamList - parameter list.
- */
-
-#ifndef H_CFCPARAMLIST
-#define H_CFCPARAMLIST
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct CFCParamList CFCParamList;
-struct CFCClass;
-struct CFCVariable;
-
-/**
- * @param variadic Should be true if the function is variadic.
- */
-CFCParamList*
-CFCParamList_new(int variadic);
-
-CFCParamList*
-CFCParamList_init(CFCParamList *self, int variadic);
-
-void
-CFCParamList_resolve_types(CFCParamList *self, struct CFCClass **classes);
-
-void
-CFCParamList_destroy(CFCParamList *self);
-
-/** Add a parameter to the ParamList.
- *
- * @param variable A Clownfish::CFC::Model::Variable.
- * @param value The parameter's default value, which should be NULL
- * if there is no default and thus the parameter is required.
- */
-void
-CFCParamList_add_param(CFCParamList *self, struct CFCVariable *variable,
- const char *value);
-
-struct CFCVariable**
-CFCParamList_get_variables(CFCParamList *self);
-
-const char**
-CFCParamList_get_initial_values(CFCParamList *self);
-
-void
-CFCParamList_set_variadic(CFCParamList *self, int variadic);
-
-int
-CFCParamList_variadic(CFCParamList *self);
-
-/** Return the number of variables in the ParamList, including "self" for
- * methods.
- */
-size_t
-CFCParamList_num_vars(CFCParamList *self);
-
-
-/** Return a list of the variable's types and names, joined by commas. For
- * example:
- *
- * Obj* self, Foo* foo, Bar* bar
- */
-const char*
-CFCParamList_to_c(CFCParamList *self);
-
-/** Return the variable's names, joined by commas. For example:
- *
- * self, foo, bar
- */
-const char*
-CFCParamList_name_list(CFCParamList *self);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_CFCPARAMLIST */
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCParcel.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCParcel.c b/clownfish/compiler/src/CFCParcel.c
deleted file mode 100644
index 262a5fc..0000000
--- a/clownfish/compiler/src/CFCParcel.c
+++ /dev/null
@@ -1,626 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-
-#ifndef true
- #define true 1
- #define false 0
-#endif
-
-#define CFC_NEED_BASE_STRUCT_DEF
-#include "CFCBase.h"
-#include "CFCParcel.h"
-#include "CFCVersion.h"
-#include "CFCUtil.h"
-
-struct CFCParcel {
- CFCBase base;
- char *name;
- char *cnick;
- CFCVersion *version;
- char *prefix;
- char *Prefix;
- char *PREFIX;
- char *privacy_sym;
- int is_included;
- char **dependent_parcels;
- size_t num_dependent_parcels;
- char **inherited_parcels;
- size_t num_inherited_parcels;
-};
-
-static CFCParcel *default_parcel = NULL;
-
-#define JSON_STRING 1
-#define JSON_HASH 2
-
-typedef struct JSONNode {
- int type;
- char *string;
- struct JSONNode **kids;
- size_t num_kids;
-} JSONNode;
-
-static JSONNode*
-S_parse_json_for_parcel(const char *json);
-
-static JSONNode*
-S_parse_json_hash(const char **json);
-
-static JSONNode*
-S_parse_json_string(const char **json);
-
-static void
-S_skip_whitespace(const char **json);
-
-static void
-S_destroy_json(JSONNode *node);
-
-static CFCParcel **registry = NULL;
-static size_t num_registered = 0;
-
-CFCParcel*
-CFCParcel_fetch(const char *name) {
- // Return the default parcel for either a blank name or a NULL name.
- if (!name || !strlen(name)) {
- return CFCParcel_default_parcel();
- }
-
- for (size_t i = 0; i < num_registered ; i++) {
- CFCParcel *existing = registry[i];
- if (strcmp(existing->name, name) == 0) {
- return existing;
- }
- }
-
- return NULL;
-}
-
-void
-CFCParcel_register(CFCParcel *self) {
- const char *name = self->name;
- const char *cnick = self->cnick;
-
- for (size_t i = 0; i < num_registered ; i++) {
- CFCParcel *other = registry[i];
-
- if (strcmp(other->name, name) == 0) {
- CFCUtil_die("Parcel '%s' already registered", name);
- }
- if (strcmp(other->cnick, cnick) == 0) {
- CFCUtil_die("Parcel with nickname '%s' already registered", cnick);
- }
- }
-
- if (!num_registered) {
- // Init default parcel as first.
- registry = (CFCParcel**)CALLOCATE(3, sizeof(CFCParcel*));
- CFCParcel *def = CFCParcel_default_parcel();
- registry[0] = (CFCParcel*)CFCBase_incref((CFCBase*)def);
- num_registered++;
- }
-
- size_t size = (num_registered + 2) * sizeof(CFCParcel*);
- registry = (CFCParcel**)REALLOCATE(registry, size);
- registry[num_registered++] = (CFCParcel*)CFCBase_incref((CFCBase*)self);
- registry[num_registered] = NULL;
-}
-
-CFCParcel**
-CFCParcel_all_parcels(void) {
- size_t size = (num_registered + 1) * sizeof(CFCParcel*);
- CFCParcel **parcels = (CFCParcel**)MALLOCATE(size);
- size_t n = 0;
-
- for (size_t i = 0; registry[i]; ++i) {
- CFCParcel *parcel = registry[i];
- const char *prefix = CFCParcel_get_prefix(parcel);
-
- // Skip default parcel.
- if (*prefix) {
- parcels[n++] = parcel;
- }
- }
-
- parcels[n] = NULL;
-
- return parcels;
-}
-
-void
-CFCParcel_reap_singletons(void) {
- for (size_t i = 0; i < num_registered; i++) {
- CFCBase_decref((CFCBase*)registry[i]);
- }
- FREEMEM(registry);
- num_registered = 0;
- registry = NULL;
- CFCBase_decref((CFCBase*)default_parcel);
- default_parcel = NULL;
-}
-
-static int
-S_validate_name_or_cnick(const char *orig) {
- const char *ptr = orig;
- for (; *ptr != 0; ptr++) {
- if (!isalpha(*ptr)) { return false; }
- }
- return true;
-}
-
-static const CFCMeta CFCPARCEL_META = {
- "Clownfish::CFC::Model::Parcel",
- sizeof(CFCParcel),
- (CFCBase_destroy_t)CFCParcel_destroy
-};
-
-CFCParcel*
-CFCParcel_new(const char *name, const char *cnick, CFCVersion *version,
- int is_included) {
- CFCParcel *self = (CFCParcel*)CFCBase_allocate(&CFCPARCEL_META);
- return CFCParcel_init(self, name, cnick, version, is_included);
-}
-
-CFCParcel*
-CFCParcel_init(CFCParcel *self, const char *name, const char *cnick,
- CFCVersion *version, int is_included) {
- // Validate name.
- if (!name || !S_validate_name_or_cnick(name)) {
- CFCUtil_die("Invalid name: '%s'", name ? name : "[NULL]");
- }
- self->name = CFCUtil_strdup(name);
-
- // Validate or derive cnick.
- if (cnick) {
- if (!S_validate_name_or_cnick(cnick)) {
- CFCUtil_die("Invalid cnick: '%s'", cnick);
- }
- self->cnick = CFCUtil_strdup(cnick);
- }
- else {
- // Default cnick to name.
- self->cnick = CFCUtil_strdup(name);
- }
-
- // Default to version v0.
- if (version) {
- self->version = (CFCVersion*)CFCBase_incref((CFCBase*)version);
- }
- else {
- self->version = CFCVersion_new("v0");
- }
-
- // Derive prefix, Prefix, PREFIX.
- size_t cnick_len = strlen(self->cnick);
- size_t prefix_len = cnick_len ? cnick_len + 1 : 0;
- size_t amount = prefix_len + 1;
- self->prefix = (char*)MALLOCATE(amount);
- self->Prefix = (char*)MALLOCATE(amount);
- self->PREFIX = (char*)MALLOCATE(amount);
- memcpy(self->Prefix, self->cnick, cnick_len);
- if (cnick_len) {
- self->Prefix[cnick_len] = '_';
- self->Prefix[cnick_len + 1] = '\0';
- }
- else {
- self->Prefix[cnick_len] = '\0';
- }
- for (size_t i = 0; i < amount; i++) {
- self->prefix[i] = tolower(self->Prefix[i]);
- self->PREFIX[i] = toupper(self->Prefix[i]);
- }
- self->prefix[prefix_len] = '\0';
- self->Prefix[prefix_len] = '\0';
- self->PREFIX[prefix_len] = '\0';
-
- // Derive privacy symbol.
- size_t privacy_sym_len = cnick_len + 4;
- self->privacy_sym = (char*)MALLOCATE(privacy_sym_len + 1);
- memcpy(self->privacy_sym, "CFP_", 4);
- for (size_t i = 0; i < cnick_len; i++) {
- self->privacy_sym[i+4] = toupper(self->cnick[i]);
- }
- self->privacy_sym[privacy_sym_len] = '\0';
-
- // Set is_included.
- self->is_included = is_included;
-
- // Initialize dependencies.
- self->dependent_parcels = (char**)CALLOCATE(1, sizeof(char*));
- self->num_dependent_parcels = 0;
- self->inherited_parcels = (char**)CALLOCATE(1, sizeof(char*));
- self->num_inherited_parcels = 0;
-
- return self;
-}
-
-static CFCParcel*
-S_new_from_json(const char *json, const char *path, int is_included) {
- JSONNode *parsed = S_parse_json_for_parcel(json);
- if (!parsed) {
- CFCUtil_die("Invalid JSON parcel definition in '%s'", path);
- }
- const char *name = NULL;
- const char *nickname = NULL;
- CFCVersion *version = NULL;
- for (size_t i = 0, max = parsed->num_kids; i < max; i += 2) {
- JSONNode *key = parsed->kids[i];
- JSONNode *value = parsed->kids[i + 1];
- if (key->type != JSON_STRING) {
- CFCUtil_die("JSON parsing error (filepath '%s')", path);
- }
- if (strcmp(key->string, "name") == 0) {
- if (value->type != JSON_STRING) {
- CFCUtil_die("'name' must be a string (filepath %s)", path);
- }
- name = value->string;
- }
- else if (strcmp(key->string, "nickname") == 0) {
- if (value->type != JSON_STRING) {
- CFCUtil_die("'nickname' must be a string (filepath %s)",
- path);
- }
- nickname = value->string;
- }
- else if (strcmp(key->string, "version") == 0) {
- if (value->type != JSON_STRING) {
- CFCUtil_die("'version' must be a string (filepath %s)",
- path);
- }
- version = CFCVersion_new(value->string);
- }
- }
- if (!name) {
- CFCUtil_die("Missing required key 'name' (filepath '%s')", path);
- }
- if (!version) {
- CFCUtil_die("Missing required key 'version' (filepath '%s')", path);
- }
- CFCParcel *self = CFCParcel_new(name, nickname, version, is_included);
- CFCBase_decref((CFCBase*)version);
-
- for (size_t i = 0, max = parsed->num_kids; i < max; i += 2) {
- JSONNode *key = parsed->kids[i];
- if (strcmp(key->string, "name") == 0
- || strcmp(key->string, "nickname") == 0
- || strcmp(key->string, "version") == 0
- || strcmp(key->string, "prerequisites") == 0
- ) {
- ;
- }
- else {
- CFCUtil_die("Unrecognized key: '%s' (filepath '%s')",
- key->string, path);
- }
- }
-
- S_destroy_json(parsed);
- return self;
-}
-
-CFCParcel*
-CFCParcel_new_from_json(const char *json, int is_included) {
- return S_new_from_json(json, "[NULL]", is_included);
-}
-
-CFCParcel*
-CFCParcel_new_from_file(const char *path, int is_included) {
- size_t len;
- char *json = CFCUtil_slurp_text(path, &len);
- CFCParcel *self = S_new_from_json(json, path, is_included);
- FREEMEM(json);
- return self;
-}
-
-void
-CFCParcel_destroy(CFCParcel *self) {
- FREEMEM(self->name);
- FREEMEM(self->cnick);
- CFCBase_decref((CFCBase*)self->version);
- FREEMEM(self->prefix);
- FREEMEM(self->Prefix);
- FREEMEM(self->PREFIX);
- FREEMEM(self->privacy_sym);
- for (size_t i = 0; self->dependent_parcels[i]; ++i) {
- FREEMEM(self->dependent_parcels[i]);
- }
- FREEMEM(self->dependent_parcels);
- for (size_t i = 0; self->inherited_parcels[i]; ++i) {
- FREEMEM(self->inherited_parcels[i]);
- }
- FREEMEM(self->inherited_parcels);
- CFCBase_destroy((CFCBase*)self);
-}
-
-CFCParcel*
-CFCParcel_default_parcel(void) {
- if (default_parcel == NULL) {
- default_parcel = CFCParcel_new("", "", NULL, false);
- }
- return default_parcel;
-}
-
-int
-CFCParcel_equals(CFCParcel *self, CFCParcel *other) {
- if (strcmp(self->name, other->name)) { return false; }
- if (strcmp(self->cnick, other->cnick)) { return false; }
- if (CFCVersion_compare_to(self->version, other->version) != 0) {
- return false;
- }
- if (self->is_included != other->is_included) { return false; }
- return true;
-}
-
-const char*
-CFCParcel_get_name(CFCParcel *self) {
- return self->name;
-}
-
-const char*
-CFCParcel_get_cnick(CFCParcel *self) {
- return self->cnick;
-}
-
-CFCVersion*
-CFCParcel_get_version(CFCParcel *self) {
- return self->version;
-}
-
-const char*
-CFCParcel_get_prefix(CFCParcel *self) {
- return self->prefix;
-}
-
-const char*
-CFCParcel_get_Prefix(CFCParcel *self) {
- return self->Prefix;
-}
-
-const char*
-CFCParcel_get_PREFIX(CFCParcel *self) {
- return self->PREFIX;
-}
-
-const char*
-CFCParcel_get_privacy_sym(CFCParcel *self) {
- return self->privacy_sym;
-}
-
-int
-CFCParcel_included(CFCParcel *self) {
- return self->is_included;
-}
-
-void
-CFCParcel_add_dependent_parcel(CFCParcel *self, CFCParcel *dependent) {
- const char *name = CFCParcel_get_name(self);
- const char *dep_name = CFCParcel_get_name(dependent);
-
- if (strcmp(name, dep_name) == 0) { return; }
-
- for (size_t i = 0; self->dependent_parcels[i]; ++i) {
- const char *other_name = self->dependent_parcels[i];
- if (strcmp(other_name, dep_name) == 0) { return; }
- }
-
- size_t num_parcels = self->num_dependent_parcels;
- self->dependent_parcels
- = (char**)REALLOCATE(self->dependent_parcels,
- (num_parcels + 2) * sizeof(char*));
- self->dependent_parcels[num_parcels] = CFCUtil_strdup(dep_name);
- self->dependent_parcels[num_parcels+1] = NULL;
- self->num_dependent_parcels = num_parcels + 1;
-}
-
-void
-CFCParcel_add_inherited_parcel(CFCParcel *self, CFCParcel *inherited) {
- const char *name = CFCParcel_get_name(self);
- const char *inh_name = CFCParcel_get_name(inherited);
-
- if (strcmp(name, inh_name) == 0) { return; }
-
- for (size_t i = 0; self->inherited_parcels[i]; ++i) {
- const char *other_name = self->inherited_parcels[i];
- if (strcmp(other_name, inh_name) == 0) { return; }
- }
-
- size_t num_parcels = self->num_inherited_parcels;
- self->inherited_parcels
- = (char**)REALLOCATE(self->inherited_parcels,
- (num_parcels + 2) * sizeof(char*));
- self->inherited_parcels[num_parcels] = CFCUtil_strdup(inh_name);
- self->inherited_parcels[num_parcels+1] = NULL;
- self->num_inherited_parcels = num_parcels + 1;
-
- // Add to dependent parcels.
- CFCParcel_add_dependent_parcel(self, inherited);
-}
-
-CFCParcel**
-CFCParcel_dependent_parcels(CFCParcel *self) {
- CFCParcel **parcels
- = (CFCParcel**)CALLOCATE(self->num_dependent_parcels + 1,
- sizeof(CFCParcel*));
-
- for (size_t i = 0; self->dependent_parcels[i]; ++i) {
- parcels[i] = CFCParcel_fetch(self->dependent_parcels[i]);
- }
-
- return parcels;
-}
-
-CFCParcel**
-CFCParcel_inherited_parcels(CFCParcel *self) {
- CFCParcel **parcels
- = (CFCParcel**)CALLOCATE(self->num_inherited_parcels + 1,
- sizeof(CFCParcel*));
-
- for (size_t i = 0; self->inherited_parcels[i]; ++i) {
- parcels[i] = CFCParcel_fetch(self->inherited_parcels[i]);
- }
-
- return parcels;
-}
-
-/*****************************************************************************
- * The hack JSON parser coded up below is only meant to parse Clownfish parcel
- * file content. It is limited in its capabilities because so little is legal
- * in a .cfp file.
- */
-
-static JSONNode*
-S_parse_json_for_parcel(const char *json) {
- if (!json) {
- return NULL;
- }
- S_skip_whitespace(&json);
- if (*json != '{') {
- return NULL;
- }
- JSONNode *parsed = S_parse_json_hash(&json);
- S_skip_whitespace(&json);
- if (*json != '\0') {
- S_destroy_json(parsed);
- parsed = NULL;
- }
- return parsed;
-}
-
-static void
-S_append_kid(JSONNode *node, JSONNode *child) {
- size_t size = (node->num_kids + 2) * sizeof(JSONNode*);
- node->kids = (JSONNode**)realloc(node->kids, size);
- node->kids[node->num_kids++] = child;
- node->kids[node->num_kids] = NULL;
-}
-
-static JSONNode*
-S_parse_json_hash(const char **json) {
- const char *text = *json;
- S_skip_whitespace(&text);
- if (*text != '{') {
- return NULL;
- }
- text++;
- JSONNode *node = (JSONNode*)calloc(1, sizeof(JSONNode));
- node->type = JSON_HASH;
- while (1) {
- // Parse key.
- S_skip_whitespace(&text);
- if (*text == '}') {
- text++;
- break;
- }
- else if (*text == '"') {
- JSONNode *key = S_parse_json_string(&text);
- S_skip_whitespace(&text);
- if (!key || *text != ':') {
- S_destroy_json(node);
- return NULL;
- }
- text++;
- S_append_kid(node, key);
- }
- else {
- S_destroy_json(node);
- return NULL;
- }
-
- // Parse value.
- S_skip_whitespace(&text);
- JSONNode *value = NULL;
- if (*text == '"') {
- value = S_parse_json_string(&text);
- }
- else if (*text == '{') {
- value = S_parse_json_hash(&text);
- }
- if (!value) {
- S_destroy_json(node);
- return NULL;
- }
- S_append_kid(node, value);
-
- // Parse comma.
- S_skip_whitespace(&text);
- if (*text == ',') {
- text++;
- }
- else if (*text == '}') {
- text++;
- break;
- }
- else {
- S_destroy_json(node);
- return NULL;
- }
- }
-
- // Move pointer.
- *json = text;
-
- return node;
-}
-
-// Parse a double quoted string. Don't allow escapes.
-static JSONNode*
-S_parse_json_string(const char **json) {
- const char *text = *json;
- if (*text != '\"') {
- return NULL;
- }
- text++;
- const char *start = text;
- while (*text != '"') {
- if (*text == '\\' || *text == '\0') {
- return NULL;
- }
- text++;
- }
- JSONNode *node = (JSONNode*)calloc(1, sizeof(JSONNode));
- node->type = JSON_STRING;
- node->string = CFCUtil_strndup(start, text - start);
-
- // Move pointer.
- text++;
- *json = text;
-
- return node;
-}
-
-static void
-S_skip_whitespace(const char **json) {
- while (isspace(json[0][0])) { *json = *json + 1; }
-}
-
-static void
-S_destroy_json(JSONNode *node) {
- if (!node) {
- return;
- }
- if (node->kids) {
- for (size_t i = 0; node->kids[i] != NULL; i++) {
- S_destroy_json(node->kids[i]);
- }
- }
- free(node->string);
- free(node->kids);
- free(node);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCParcel.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCParcel.h b/clownfish/compiler/src/CFCParcel.h
deleted file mode 100644
index d5cdb5f..0000000
--- a/clownfish/compiler/src/CFCParcel.h
+++ /dev/null
@@ -1,151 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/** Clownfish::CFC::Model::Parcel - Collection of code.
- *
- * A Parcel is a cohesive collection of code, which could, in theory, be
- * published as as a single entity.
- *
- * Clownfish supports two-tier manual namespacing, using a prefix, an optional
- * class nickname, and the local symbol:
- *
- * prefix_ClassNick_local_symbol
- *
- * Clownfish::CFC::Model::Parcel supports the first tier, specifying initial
- * prefixes. These prefixes come in three capitalization variants: prefix_,
- * Prefix_, and PREFIX_.
- */
-
-#ifndef H_CFCPARCEL
-#define H_CFCPARCEL
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct CFCParcel CFCParcel;
-struct CFCVersion;
-
-/** Return the parcel which has been registered for <code>name</code>.
- */
-CFCParcel*
-CFCParcel_fetch(const char *name);
-
-/** Register the supplied parcel. Throws an error if a parcel with the same
- * name has already been registered.
- */
-void
-CFCParcel_register(CFCParcel *self);
-
-/** Return a NULL-terminated list of all registered parcels. Must be freed by
- * the caller.
- */
-CFCParcel**
-CFCParcel_all_parcels(void);
-
-/** Decref all singletons at shutdown.
- */
-void
-CFCParcel_reap_singletons(void);
-
-CFCParcel*
-CFCParcel_new(const char *name, const char *cnick,
- struct CFCVersion *version, int is_included);
-
-CFCParcel*
-CFCParcel_new_from_file(const char *path, int is_included);
-
-CFCParcel*
-CFCParcel_new_from_json(const char *json, int is_included);
-
-CFCParcel*
-CFCParcel_init(CFCParcel *self, const char *name, const char *cnick,
- struct CFCVersion *version, int is_included);
-
-void
-CFCParcel_destroy(CFCParcel *self);
-
-/** Return the singleton for default parcel, which has no prefix.
- */
-CFCParcel*
-CFCParcel_default_parcel(void);
-
-int
-CFCParcel_equals(CFCParcel *self, CFCParcel *other);
-
-const char*
-CFCParcel_get_name(CFCParcel *self);
-
-const char*
-CFCParcel_get_cnick(CFCParcel *self);
-
-struct CFCVersion*
-CFCParcel_get_version(CFCParcel *self);
-
-/** Return the all-lowercase version of the Parcel's prefix.
- */
-const char*
-CFCParcel_get_prefix(CFCParcel *self);
-
-/** Return the Titlecase version of the Parcel's prefix.
- */
-const char*
-CFCParcel_get_Prefix(CFCParcel *self);
-
-/** Return the all-caps version of the Parcel's prefix.
- */
-const char*
-CFCParcel_get_PREFIX(CFCParcel *self);
-
-/* Return the Parcel's privacy symbol.
- */
-const char*
-CFCParcel_get_privacy_sym(CFCParcel *self);
-
-/** Return true if the parcel is from an include directory.
- */
-int
-CFCParcel_included(CFCParcel *self);
-
-/** Add another Parcel that the Parcel depends on.
- */
-void
-CFCParcel_add_dependent_parcel(CFCParcel *self, CFCParcel *dependent);
-
-/** Add another Parcel containing superclasses that subclasses in the Parcel
- * extend. Also adds the other Parcel to the Parcel's dependencies.
- */
-void
-CFCParcel_add_inherited_parcel(CFCParcel *self, CFCParcel *inherited);
-
-/** Return a NULL-terminated array of all Parcels that the Parcel depends on.
- * Must be freed by the caller.
- */
-CFCParcel**
-CFCParcel_dependent_parcels(CFCParcel *self);
-
-/** Return a NULL-terminated array of all Parcels containing superclasses that
- * subclasses in the Parcel extend. Must be freed by the caller.
- */
-CFCParcel**
-CFCParcel_inherited_parcels(CFCParcel *self);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_CFCPARCEL */
-