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:48 UTC
[lucy-commits] [18/54] [abbrv] Remove bundled Clownfish.
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/perl/t/core/404-file.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/core/404-file.t b/clownfish/compiler/perl/t/core/404-file.t
deleted file mode 100644
index 69c112e..0000000
--- a/clownfish/compiler/perl/t/core/404-file.t
+++ /dev/null
@@ -1,25 +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.
-
-use strict;
-use warnings;
-
-use Clownfish::CFC::Test;
-
-my $test = Clownfish::CFC::Test->new;
-my $passed = $test->run_batch('Clownfish::CFC::Model::File');
-
-exit($passed ? 0 : 1);
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/perl/t/core/500-hierarchy.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/core/500-hierarchy.t b/clownfish/compiler/perl/t/core/500-hierarchy.t
deleted file mode 100644
index 5b60568..0000000
--- a/clownfish/compiler/perl/t/core/500-hierarchy.t
+++ /dev/null
@@ -1,25 +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.
-
-use strict;
-use warnings;
-
-use Clownfish::CFC::Test;
-
-my $test = Clownfish::CFC::Test->new;
-my $passed = $test->run_batch('Clownfish::CFC::Model::Hierarchy');
-
-exit($passed ? 0 : 1);
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/perl/t/core/600-parser.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/core/600-parser.t b/clownfish/compiler/perl/t/core/600-parser.t
deleted file mode 100644
index 0311548..0000000
--- a/clownfish/compiler/perl/t/core/600-parser.t
+++ /dev/null
@@ -1,25 +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.
-
-use strict;
-use warnings;
-
-use Clownfish::CFC::Test;
-
-my $test = Clownfish::CFC::Test->new;
-my $passed = $test->run_batch('Clownfish::CFC::Model::Parser');
-
-exit($passed ? 0 : 1);
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/perl/typemap
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/typemap b/clownfish/compiler/perl/typemap
deleted file mode 100644
index d744071..0000000
--- a/clownfish/compiler/perl/typemap
+++ /dev/null
@@ -1,154 +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.
-
-TYPEMAP
-CFCBase* CLOWNFISH_TYPE
-CFCCBlock* CLOWNFISH_MODEL
-CFCClass* CLOWNFISH_MODEL
-CFCDocuComment* CLOWNFISH_MODEL
-CFCFile* CLOWNFISH_MODEL
-CFCFileSpec* CLOWNFISH_MODEL
-CFCFunction* CLOWNFISH_MODEL
-CFCHierarchy* CLOWNFISH_MODEL
-CFCMethod* CLOWNFISH_MODEL
-CFCMemPool* CLOWNFISH_TYPE
-CFCParamList* CLOWNFISH_MODEL
-CFCParcel* CLOWNFISH_MODEL
-CFCParser* CLOWNFISH_TYPE
-CFCSymbol* CLOWNFISH_MODEL
-CFCTest* CLOWNFISH_TYPE
-CFCType* CLOWNFISH_MODEL
-CFCVariable* CLOWNFISH_MODEL
-CFCVersion* CLOWNFISH_MODEL
-CFCBindCore* CLOWNFISH_BINDING_CORE
-CFCBindClass* CLOWNFISH_BINDING_CORE_TYPE
-CFCPerl* CLOWNFISH_BINDING_PERL
-CFCPerlSub* CLOWNFISH_BINDING_PERL_SUBROUTINE
-CFCPerlClass* CLOWNFISH_BINDING_PERL_COMMON
-CFCPerlConstructor* CLOWNFISH_BINDING_PERL_COMMON
-CFCPerlMethod* CLOWNFISH_BINDING_PERL_COMMON
-CFCPerlPod* CLOWNFISH_BINDING_PERL_COMMON
-
-INPUT
-
-CLOWNFISH_MODEL
- if (!SvOK($arg)) {
- $var = NULL;
- }
- else if (sv_derived_from($arg, \"${(my $t = $type) =~ s/CFC(\w+).*/Clownfish::CFC::Model::$1/;\$t}\")) {
- IV objint = SvIV((SV*)SvRV($arg));
- $var = INT2PTR($type, objint);
- }
- else {
- croak(\"Not a ${(my $t = $type) =~ s/CFC(\w+).*/Clownfish::CFC::Model::$1/;\$t}\");
- }
-
-CLOWNFISH_TYPE
- if (!SvOK($arg)) {
- $var = NULL;
- }
- else if (sv_derived_from($arg, \"${(my $t = $type) =~ s/CFC(\w+).*/Clownfish::CFC::$1/;\$t}\")) {
- IV objint = SvIV((SV*)SvRV($arg));
- $var = INT2PTR($type, objint);
- }
- else {
- croak(\"Not a ${(my $t = $type) =~ s/CFC(\w+).*/Clownfish::CFC::$1/;\$t}\");
- }
-
-CLOWNFISH_BINDING_CORE
- if (!SvOK($arg)) {
- $var = NULL;
- }
- else if (sv_derived_from($arg, \"Clownfish::CFC::Binding::Core\")) {
- IV objint = SvIV((SV*)SvRV($arg));
- $var = INT2PTR($type, objint);
- }
- else {
- croak(\"Not a Clownfish::CFC::Binding::Core\");
- }
-
-CLOWNFISH_BINDING_CORE_TYPE
- if (!SvOK($arg)) {
- $var = NULL;
- }
- else if (sv_derived_from($arg, \"${(my $t = $type) =~ s/CFCBind(\w+).*/Clownfish::CFC::Binding::Core::$1/;\$t}\")) {
- IV objint = SvIV((SV*)SvRV($arg));
- $var = INT2PTR($type, objint);
- }
- else {
- croak(\"Not a ${(my $t = $type) =~ s/CFCBind(\w+).*/Clownfish::CFC::Binding::Core::$1/;\$t}\");
- }
-
-CLOWNFISH_BINDING_PERL
- if (!SvOK($arg)) {
- $var = NULL;
- }
- else if (sv_derived_from($arg, \"Clownfish::CFC::Binding::Perl\")) {
- IV objint = SvIV((SV*)SvRV($arg));
- $var = INT2PTR($type, objint);
- }
- else {
- croak(\"Not a Clownfish::CFC::Binding::Perl\");
- }
-
-
-CLOWNFISH_BINDING_PERL_SUBROUTINE
- if (!SvOK($arg)) {
- $var = NULL;
- }
- else if (sv_derived_from($arg, \"Clownfish::CFC::Binding::Perl::Subroutine\")) {
- IV objint = SvIV((SV*)SvRV($arg));
- $var = INT2PTR($type, objint);
- }
- else {
- croak(\"Not a Clownfish::CFC::Binding::Perl::Subroutine\");
- }
-
-CLOWNFISH_BINDING_PERL_COMMON
- if (!SvOK($arg)) {
- $var = NULL;
- }
- else if (sv_derived_from($arg, \"${(my $t = $type) =~ s/CFCPerl(\w+).*/Clownfish::CFC::Binding::Perl::$1/;\$t}\")) {
- IV objint = SvIV((SV*)SvRV($arg));
- $var = INT2PTR($type, objint);
- }
- else {
- croak(\"Not a ${(my $t = $type) =~ s/CFCPerl(\w+).*/Clownfish::CFC::Binding::Perl::$1/;\$t}\");
- }
-
-
-OUTPUT
-
-CLOWNFISH_MODEL
- sv_setref_pv($arg, \"${(my $t = $type) =~ s/CFC(\w+).*/Clownfish::CFC::Model::$1/;\$t}\", (void*)$var);
-
-CLOWNFISH_TYPE
- sv_setref_pv($arg, \"${(my $t = $type) =~ s/CFC(\w+).*/Clownfish::CFC::$1/;\$t}\", (void*)$var);
-
-CLOWNFISH_BINDING_CORE
- sv_setref_pv($arg, \"Clownfish::CFC::Binding::Core\", (void*)$var);
-
-CLOWNFISH_BINDING_CORE_TYPE
- sv_setref_pv($arg, \"${(my $t = $type) =~ s/CFCBind(\w+).*/Clownfish::CFC::Binding::Core::$1/;\$t}\", (void*)$var);
-
-CLOWNFISH_BINDING_PERL
- sv_setref_pv($arg, \"Clownfish::CFC::Binding::Perl\", (void*)$var);
-
-CLOWNFISH_BINDING_PERL_COMMON
- sv_setref_pv($arg, \"${(my $t = $type) =~ s/CFCPerl(\w+).*/Clownfish::CFC::Binding::Perl::$1/;\$t}\", (void*)$var);
-
-CLOWNFISH_BINDING_PERL_SUBROUTINE
- sv_setref_pv($arg, \"Clownfish::CFC::Binding::Perl::Subroutine\", (void*)$var);
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/python/clownfish/_cfc.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/python/clownfish/_cfc.c b/clownfish/compiler/python/clownfish/_cfc.c
deleted file mode 100644
index 253f23c..0000000
--- a/clownfish/compiler/python/clownfish/_cfc.c
+++ /dev/null
@@ -1,143 +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 "Python.h"
-#include "CFC.h"
-
-typedef struct {
- PyObject_HEAD
- void *cfc_obj;
-} CFCPyWrapper;
-
-static CFCHierarchy*
-S_extract_hierarchy(PyObject *wrapper) {
- return (CFCHierarchy*)((CFCPyWrapper*)wrapper)->cfc_obj;
-}
-
-static CFCPyWrapper*
-S_CFCHierarchy_new(PyTypeObject *type, PyObject *args,
- PyObject *keyword_args) {
- char *dest = NULL;
- char *keywords[] = {"dest", NULL};
- int result = PyArg_ParseTupleAndKeywords(args, keyword_args, "|s",
- keywords, &dest);
- if (!result) { return NULL; }
- if (!dest) {
- PyErr_SetString(PyExc_TypeError, "Missing required arg 'dest'");
- return NULL;
- }
- CFCPyWrapper *wrapper = (CFCPyWrapper*)type->tp_alloc(type, 0);
- if (wrapper) {
- wrapper->cfc_obj = CFCHierarchy_new(dest);
- }
- return wrapper;
-}
-
-static void
-S_CFCHierarchy_dealloc(CFCPyWrapper *wrapper) {
- CFCBase *temp = (CFCBase*)wrapper->cfc_obj;
- wrapper->cfc_obj = NULL;
- CFCBase_decref(temp);
- Py_TYPE(wrapper)->tp_free(wrapper);
-}
-
-static PyObject*
-S_CFCHierarchy_add_include_dir(PyObject *wrapper, PyObject *dir) {
- CFCHierarchy *wrapped = S_extract_hierarchy(wrapper);
- CFCHierarchy_add_include_dir(S_extract_hierarchy(wrapper),
- PyUnicode_AsUTF8(dir));
- Py_RETURN_NONE;
-}
-
-static PyModuleDef cfc_module_def = {
- PyModuleDef_HEAD_INIT,
- "clownfish.cfc",
- "CFC: Clownfish compiler",
- -1,
- NULL, NULL, NULL, NULL, NULL
-};
-
-static PyModuleDef cfc_model_module_def = {
- PyModuleDef_HEAD_INIT,
- "clownfish.cfc.model",
- "CFC classes which model language constructs",
- -1,
- NULL, NULL, NULL, NULL, NULL
-};
-
-static PyMethodDef hierarchy_methods[] = {
- {"add_include_dir", (PyCFunction)S_CFCHierarchy_add_include_dir, METH_O,
- NULL},
- {NULL}
-};
-
-static PyTypeObject CFCHierarchy_pytype = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "clownfish.cfc.model.Hierarchy", // tp_name
- sizeof(CFCPyWrapper), // tp_basicsize
- 0, // tp_itemsize
- (destructor)S_CFCHierarchy_dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_reserved
- 0, // tp_repr
- 0, // tp_as_number
- 0, // tp_as_sequence
- 0, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0, // tp_str
- 0, // tp_getattro
- 0, // tp_setattro
- 0, // tp_as_buffer
- Py_TPFLAGS_DEFAULT, // tp_flags
- "CFCHierarchy", // tp_doc
- 0, // tp_traverse
- 0, // tp_clear
- 0, // tp_richcompare
- 0, // tp_weaklistoffset
- 0, // tp_iter
- 0, // tp_iternext
- hierarchy_methods, // tp_methods
- 0, // tp_members
- 0, // tp_getset
- 0, // tp_base
- 0, // tp_dict
- 0, // tp_descr_get
- 0, // tp_descr_set
- 0, // tp_dictoffset
- 0, // tp_init
- 0, // tp_allow
- (newfunc)S_CFCHierarchy_new // tp_new
-};
-
-PyMODINIT_FUNC
-PyInit__cfc(void) {
- if (PyType_Ready(&CFCHierarchy_pytype) < 0) {
- return NULL;
- }
- PyObject *cfc_module = PyModule_Create(&cfc_module_def);
- PyObject *cfc_model_module = PyModule_Create(&cfc_model_module_def);
- PyModule_AddObject(cfc_module, "model", (PyObject*)cfc_model_module);
- Py_INCREF(&CFCHierarchy_pytype);
- PyModule_AddObject(cfc_model_module, "Hierarchy",
- (PyObject*)&CFCHierarchy_pytype);
-
- return cfc_module;
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/python/clownfish/cfc/__init__.py
----------------------------------------------------------------------
diff --git a/clownfish/compiler/python/clownfish/cfc/__init__.py b/clownfish/compiler/python/clownfish/cfc/__init__.py
deleted file mode 100644
index 8ab5aaf..0000000
--- a/clownfish/compiler/python/clownfish/cfc/__init__.py
+++ /dev/null
@@ -1,17 +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.
-
-from clownfish._cfc import *
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/python/setup.py
----------------------------------------------------------------------
diff --git a/clownfish/compiler/python/setup.py b/clownfish/compiler/python/setup.py
deleted file mode 100644
index c5917e1..0000000
--- a/clownfish/compiler/python/setup.py
+++ /dev/null
@@ -1,203 +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.
-
-from distutils.core import setup, Extension
-from distutils.command.build import build as _build
-from distutils.command.clean import clean as _clean
-from distutils.cmd import Command as _Command
-from distutils.dep_util import newer_group
-import distutils.ccompiler
-import os
-import glob
-import platform
-import re
-import shutil
-import subprocess
-import sysconfig
-
-# Get a compiler object and and strings representing the compiler type and
-# CFLAGS.
-compiler = distutils.ccompiler.new_compiler()
-cflags = sysconfig.get_config_var('CFLAGS')
-compiler_type = distutils.ccompiler.get_default_compiler()
-
-# There's no public way to get a string representing the compiler executable
-# out of distutils, but the member variable has been in the same place for a
-# long time, so violating encapsulation may be ok.
-compiler_name = " ".join(compiler.compiler)
-
-BASE_DIR = os.path.abspath(os.path.join(os.pardir, os.pardir, os.pardir))
-PARENT_DIR = os.path.abspath(os.pardir)
-CFC_SOURCE_DIR = os.path.join(PARENT_DIR, 'src')
-CFC_INCLUDE_DIR = os.path.join(PARENT_DIR, 'include')
-COMMON_SOURCE_DIR = os.path.join(PARENT_DIR, 'common')
-CHARMONIZER_C = os.path.join(COMMON_SOURCE_DIR, 'charmonizer.c')
-CHARMONIZER_EXE_NAME = compiler.executable_filename('charmonizer')
-CHARMONIZER_EXE_PATH = os.path.join(os.curdir, CHARMONIZER_EXE_NAME)
-CHARMONY_H_PATH = 'charmony.h'
-LEMON_DIR = os.path.join(BASE_DIR, 'lemon')
-LEMON_EXE_NAME = compiler.executable_filename('lemon')
-LEMON_EXE_PATH = os.path.join(LEMON_DIR, LEMON_EXE_NAME)
-
-# Accumulate lists of source files and target files.
-c_filepaths = []
-y_filepaths = []
-paths_to_clean = [
- CHARMONIZER_EXE_PATH,
- CHARMONY_H_PATH,
- '_charm*',
-]
-c_filepaths.append(os.path.join('clownfish', '_cfc.c'))
-for (dirpath, dirnames, files) in os.walk(CFC_SOURCE_DIR):
- for filename in files:
- if filename.endswith('.y'):
- path = os.path.join(dirpath, filename)
- y_filepaths.append(path)
- path = re.sub(r'y$', 'h', path)
- paths_to_clean.append(path)
- path = re.sub(r'h$', 'c', path)
- paths_to_clean.append(path)
- c_filepaths.append(path)
- path = compiler.object_filenames([path])[0]
- paths_to_clean.append(path)
- if filename.endswith('.c'):
- path = os.path.join(dirpath, filename)
- c_filepaths.append(path)
- path = compiler.object_filenames([path])[0]
- paths_to_clean.append(path)
-
-def _quotify(text):
- text = text.replace('\\', '\\\\')
- text = text.replace('"', '\\"')
- return '"' + text + '"'
-
-def _run_make(command=[], directory=None):
- current_directory = os.getcwd();
- if (directory != None):
- os.chdir(directory)
- if (compiler_type == 'msvc'):
- command.insert(0, 'Makefile.MSVC')
- command.insert(0, '-f')
- elif (platform.system() == 'Windows'):
- command.insert(0, 'Makefile.MinGW')
- command.insert(0, '-f')
- command.insert(0, "make")
- subprocess.check_call(command)
- if (directory != None):
- os.chdir(current_directory)
-
-class charmony(_Command):
- description = "Build and run charmonizer"
- user_options = []
- def initialize_options(self):
- pass
- def finalize_options(self):
- pass
- def run(self):
- # Compile charmonizer.
- if newer_group([CHARMONIZER_C], CHARMONIZER_EXE_PATH):
- command = [compiler_name]
- if compiler_type == 'msvc':
- command.append('/Fe' + CHARMONIZER_EXE_PATH)
- else:
- command.extend(['-o', CHARMONIZER_EXE_PATH])
- command.append(CHARMONIZER_C)
- print(" ".join(command))
- subprocess.check_call(command)
-
- # Run charmonizer.
- if newer_group([CHARMONIZER_EXE_PATH], CHARMONY_H_PATH):
- command = [
- CHARMONIZER_EXE_PATH,
- '--cc=' + _quotify(compiler_name),
- '--enable-c',
- '--',
- cflags
- ]
- if 'CHARM_VALGRIND' in os.environ:
- command[0:0] = "valgrind", "--leak-check=yes";
- print(" ".join(command))
- subprocess.check_call(command)
-
-class lemon(_Command):
- description = "Compile the Lemon parser generator"
- user_options = []
- def initialize_options(self):
- pass
- def finalize_options(self):
- pass
- def run(self):
- if not os.path.exists(LEMON_EXE_PATH):
- _run_make(['CC=' + _quotify(compiler_name)], directory=LEMON_DIR)
-
-class parsers(_Command):
- description = "Run .y files through lemon"
- user_options = []
- def initialize_options(self):
- pass
- def finalize_options(self):
- pass
- def run(self):
- for y_path in y_filepaths:
- target = re.sub(r'y$', 'c', y_path)
- if newer_group([y_path], target):
- command = [LEMON_EXE_PATH, '-c', y_path]
- subprocess.check_call(command)
-
-class my_clean(_clean):
- def run(self):
- _clean.run(self)
- _run_make(command=['clean'], directory=LEMON_DIR)
- for elem in paths_to_clean:
- for path in glob.glob(elem):
- print("removing " + path)
- if os.path.isdir(path):
- shutil.rmtree(path)
- else:
- os.unlink(path)
-
-class my_build(_build):
- def run(self):
- self.run_command('charmony')
- self.run_command('lemon')
- self.run_command('parsers')
- _build.run(self)
-
-cfc_extension = Extension('clownfish._cfc',
- define_macros = [('CFCPYTHON', None)],
- include_dirs = [
- CFC_INCLUDE_DIR,
- CFC_SOURCE_DIR,
- os.curdir,
- ],
- sources = c_filepaths)
-
-setup(name = 'clownfish-cfc',
- version = '0.3.0',
- description = 'Clownfish compiler',
- author = 'Apache Lucy Project',
- author_email = 'dev at lucy dot apache dot org',
- url = 'http://lucy.apache.org',
- packages = ['clownfish.cfc',
- ],
- cmdclass = {
- 'build': my_build,
- 'clean': my_clean,
- 'lemon': lemon,
- 'charmony': charmony,
- 'parsers': parsers,
- },
- ext_modules = [cfc_extension])
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/ruby/Rakefile
----------------------------------------------------------------------
diff --git a/clownfish/compiler/ruby/Rakefile b/clownfish/compiler/ruby/Rakefile
deleted file mode 100644
index 0811396..0000000
--- a/clownfish/compiler/ruby/Rakefile
+++ /dev/null
@@ -1,184 +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.
-
-require 'rake/clean'
-import '../../runtime/ruby/Rakefile.common'
-
-def rbconfig
- RbConfig::CONFIG
-end
-
-def exe_path(*args)
- File.join(args).ext(RbConfig::CONFIG["EXEEXT"])
-end
-
-BASE_PATH = '..'
-COMMON_SOURCE_DIR = File.join(BASE_PATH, "common")
-CHARMONIZER_C = File.join(COMMON_SOURCE_DIR, 'charmonizer.c')
-CHARMONIZER_EXE_PATH = File.absolute_path(exe_path('charmonizer'))
-CHARMONIZER_ORIG_DIR = File.absolute_path( File.join( BASE_PATH, '..', '..', 'charmonizer' ) )
-CHARMONY_H_PATH = 'charmony.h'
-CHARMONY_RB_PATH = 'Charmony.rb'
-CLOWNFISH_RUBY_DIR = File.absolute_path('.')
-CLOWNFISH_INCLUDE_DIR = File.join(CLOWNFISH_RUBY_DIR,'..','include')
-CLOWNFISH_RUNTIME = File.join('..','..','runtime','ruby')
-CLOWNFISH_SRC_DIR = File.join(CLOWNFISH_RUBY_DIR,'..','src')
-LEMON_SRC_DIR = File.join('..','..','..','lemon')
-RUBY_EXT_CFC = File.join('.','ext','Clownfish')
-
-
-desc "Build lemon"
-task :build_lemon => [:build_charmonizer_tests] do
- puts "Building lemon"
- run_make(LEMON_SRC_DIR,[])
-end
-
-desc "Build Clownfish"
-task :clownfish => [:parse_y_files] do
- Dir.glob(File.join(CLOWNFISH_SRC_DIR, '**', '*.c')).each do|c_file|
- obj_file = c_file.ext(rbconfig['OBJEXT'])
- next if uptodate?(obj_file, [c_file])
- command = "#{cc_command} #{includes} #{extra_ccflags} -o #{obj_file} -c #{c_file}"
- puts command
- if system(command).nil?
- abort "Failed cc compile"
- end
- end
- Rake::Task['cfc_ext'].invoke
-
-end
-
-# Clean up compiled object files.
-obj_glob = File.join(CLOWNFISH_SRC_DIR, '**', '*.' + rbconfig['OBJEXT'])
-Dir.glob(obj_glob).each do |file|
- CLEAN.include(file);
-end
-
-desc "Build CFC Ext"
-task :cfc_ext => [:clownfish] do
- makefile_path = File.join('ext', 'Clownfish', 'Makefile')
- dependencies = Dir.glob(File.join(CLOWNFISH_SRC_DIR, '**', '*.h'))
- dependencies << File.join(RUBY_EXT_CFC, "extconf.rb")
- dependencies << 'Rakefile'
- if !uptodate?(makefile_path, dependencies)
- Dir.chdir(RUBY_EXT_CFC) do
- ruby 'extconf.rb'
- end
- end
- Dir.chdir(RUBY_EXT_CFC) do
- if system('make').nil?
- abort "Failed to make cfc ruby extension"
- end
- end
-end
-
-# Clean up Ruby extension.
-Dir.glob(File.join('ext', '**', '*.' + rbconfig['OBJEXT'])).each do |file|
- CLEAN.include(file);
-end
-Dir.glob(File.join('ext', '**', '*.' + rbconfig['DLEXT'])).each do |file|
- CLEAN.include(file);
-end
-CLEAN.include(File.join('ext', 'Clownfish', 'Makefile'))
-
-desc "Lemonize the y file"
-task :parse_y_files => [:build_lemon] do
- puts "Parsing y files"
- Dir.glob(File.join(CLOWNFISH_SRC_DIR, '**', '*.y')).each do |y_file|
- c_file = y_file.ext('c')
- h_file = y_file.ext('h')
- report_file = y_file.ext('out')
- next if uptodate?(c_file, [y_file]);
- command = File.join(LEMON_SRC_DIR,'lemon') + ' -c ' + y_file
- puts command
- if system(command).nil?
- abort "Problem parsing y file with lemon"
- end
- end
- puts "Done."
-end
-
-desc "Building Charmonizer Tests"
-task :build_charmonizer_tests => [:charmony] do
- puts "Building Charmonizer Tests"
- flags = [
- '-fno-common',
- '-DFCRUBY',
- '-fno-strict-aliasing',
- '-pipe',
- '-fstack-protector',
- '-std=gnu99',
- '-D_GNU_SOURCE',
- '-I' + Dir.pwd
- ].join(" ").gsub(/"/,'\"')
-
- run_make( CHARMONIZER_ORIG_DIR, [ "DEFS=#{flags}", "tests"])
-end
-
-desc "Build and run charmonizer, creating charmony.h and charmony.rb"
-task :charmony do
- # Compile charmonizer executable.
- if !uptodate? CHARMONIZER_EXE_PATH, [CHARMONIZER_C]
- outflag = cc_command.match(/cl\b/) ? "/Fe" : "-o "
- command = "#{cc_command} #{outflag}#{CHARMONIZER_EXE_PATH} #{CHARMONIZER_C}"
- puts command
- if !system(command)
- raise "Failed to compile #{CHARMONIZER_EXE_PATH}"
- end
- end
-
- # Return if charmonizer output is current.
- if uptodate? CHARMONY_RB_PATH, [CHARMONIZER_EXE_PATH]
- next
- end
- puts "Running #{CHARMONIZER_EXE_PATH}...\n"
-
- # Prepare arguments to charmonizer.
- command = [
- CHARMONIZER_EXE_PATH,
- '--cc=' + quotify(cc_command),
- '--enable-c',
- '--enable-ruby',
- '--',
- all_ccflags,
- ]
- if (ENV['CHARM_VALGRIND'])
- command.unshift("valgrind", "--leak-check=yes")
- end
-
- # Run charmonizer.
- puts command.join(" ")
- if !system(*command)
- raise "Failed to run #{CHARMONIZER_EXE_PATH}: " + $?
- end
-end
-CLEAN.include(CHARMONIZER_EXE_PATH)
-CLEAN.include(CHARMONY_H_PATH)
-CLEAN.include(CHARMONY_RB_PATH)
-# Clean up after charmonizer if it doesn't succeed on its own.
-CLEAN.include("_charm*")
-
-# Clean up after Lemonized files.
-Dir.glob(File.join(CLOWNFISH_SRC_DIR, '**', '*.y')).each do |y_file|
- CLEAN.include(y_file.ext('c'))
- CLEAN.include(y_file.ext('h'))
- CLEAN.include(y_file.ext('out'))
-end
-
-task :default => [:clownfish]
-
-def includes
- return "-I#{CLOWNFISH_INCLUDE_DIR} -I#{CLOWNFISH_SRC_DIR} -I#{CLOWNFISH_RUBY_DIR} -I#{CLOWNFISH_RUNTIME}"
-end
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/ruby/ext/Clownfish/CFC.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/ruby/ext/Clownfish/CFC.c b/clownfish/compiler/ruby/ext/Clownfish/CFC.c
deleted file mode 100644
index 4910ebf..0000000
--- a/clownfish/compiler/ruby/ext/Clownfish/CFC.c
+++ /dev/null
@@ -1,203 +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 "ruby.h"
-#include "CFC.h"
-
-static VALUE mClownfish;
-static VALUE mCFC;
-static VALUE mModel;
-static VALUE cHierarchy;
-static VALUE mBinding;
-static VALUE cBindCore;
-static VALUE cBindRuby;
-
-static VALUE
-S_CFC_Binding_Core_Alloc(VALUE klass) {
- void *ptr = NULL;
- return Data_Wrap_Struct(klass, NULL, NULL, ptr);
-}
-
-static VALUE
-S_CFC_Binding_Core_Init(VALUE self_rb, VALUE params) {
-
- CFCHierarchy* hierarchy_obj;
- CFCBindCore* self;
-
- VALUE hierarchy = rb_hash_aref(params, ID2SYM(rb_intern("hierarchy")));
- VALUE header = rb_hash_aref(params, ID2SYM(rb_intern("header")));
- VALUE footer = rb_hash_aref(params, ID2SYM(rb_intern("footer")));
-
- Data_Get_Struct(hierarchy, CFCHierarchy, hierarchy_obj);
- Data_Get_Struct(self_rb, CFCBindCore, self);
-
- self = CFCBindCore_new(hierarchy_obj, StringValuePtr(header), StringValuePtr(footer));
-
- DATA_PTR(self_rb) = self;
- return self_rb;
-}
-
-static VALUE
-S_CFC_Binding_Core_Write_All_Modified(int argc, VALUE *argv, VALUE self_rb) {
- CFCBindCore *self;
-
- int modified = argc > 0 && RTEST(argv[0]) ? 1 : 0;
- Data_Get_Struct(self_rb, CFCBindCore, self);
- return INT2NUM(CFCBindCore_write_all_modified(self, modified));
-}
-
-static void
-S_init_Binding_Core(void) {
- cBindCore = rb_define_class_under(mBinding, "Core", rb_cObject);
- rb_define_alloc_func(cBindCore, S_CFC_Binding_Core_Alloc);
- rb_define_method(cBindCore, "initialize", S_CFC_Binding_Core_Init, 1);
- rb_define_method(cBindCore, "write_all_modified",
- S_CFC_Binding_Core_Write_All_Modified, -1);
-}
-
-static VALUE
-S_CFC_Binding_Ruby_Alloc(VALUE klass) {
- void *ptr = NULL;
- return Data_Wrap_Struct(klass, NULL, NULL, ptr);
-}
-
-static VALUE
-S_CFC_Binding_Ruby_Init(VALUE self_rb, VALUE params) {
-
- CFCHierarchy* hierarchy_obj;
- CFCParcel* parcel_obj;
- CFCRuby* self;
-
- VALUE hierarchy = rb_hash_aref(params, ID2SYM(rb_intern("hierarchy")));
- VALUE parcel = rb_hash_aref(params, ID2SYM(rb_intern("parcel")));
- VALUE lib_dir = rb_hash_aref(params, ID2SYM(rb_intern("lib_dir")));
- VALUE boot_class = rb_hash_aref(params, ID2SYM(rb_intern("boot_class")));
- VALUE header = rb_hash_aref(params, ID2SYM(rb_intern("header")));
- VALUE footer = rb_hash_aref(params, ID2SYM(rb_intern("footer")));
-
- parcel_obj = CFCParcel_new(StringValuePtr(parcel), NULL, NULL);
- Data_Get_Struct(hierarchy, CFCHierarchy, hierarchy_obj);
- Data_Get_Struct(self_rb, CFCRuby, self);
-
- self = CFCRuby_new(parcel_obj, hierarchy_obj, StringValuePtr(lib_dir), StringValuePtr(boot_class),
- StringValuePtr(header), StringValuePtr(footer));
- DATA_PTR(self_rb) = self;
-
- return self_rb;
-}
-
-static VALUE
-S_CFC_Binding_Ruby_Write_Boot(VALUE self_rb) {
-
- CFCRuby *self;
- Data_Get_Struct(self_rb, CFCRuby, self);
- CFCRuby_write_boot(self);
-
- return Qnil;
-}
-
-static VALUE
-S_CFC_Binding_Ruby_Write_Hostdefs(VALUE self_rb) {
-
- CFCRuby *self;
- Data_Get_Struct(self_rb, CFCRuby, self);
- CFCRuby_write_hostdefs(self);
-
- return Qnil;
-}
-
-static void
-S_init_Binding_Ruby(void) {
- cBindRuby = rb_define_class_under(mBinding, "Ruby", rb_cObject);
- rb_define_alloc_func(cBindRuby, S_CFC_Binding_Ruby_Alloc);
- rb_define_method(cBindRuby, "initialize", S_CFC_Binding_Ruby_Init, 1);
- rb_define_method(cBindRuby, "write_boot",
- S_CFC_Binding_Ruby_Write_Boot, 0);
- rb_define_method(cBindRuby, "write_hostdefs",
- S_CFC_Binding_Ruby_Write_Hostdefs, 0);
-}
-
-static VALUE
-S_CFC_Hierarchy_Alloc(VALUE klass) {
- void *ptr = NULL;
- return Data_Wrap_Struct(klass, NULL, NULL, ptr);
-}
-
-static VALUE
-S_CFC_Hierarchy_Init(VALUE self_rb, VALUE params) {
- CFCHierarchy* self;
-
- VALUE dest = rb_hash_aref(params, ID2SYM(rb_intern("dest")));
-
- Data_Get_Struct(self_rb, CFCHierarchy, self);
-
- self = CFCHierarchy_new(StringValuePtr(dest));
-
- DATA_PTR(self_rb) = self;
- return self_rb;
-}
-
-static VALUE
-S_CFC_Hierarchy_Add_Source_Dir(VALUE self_rb, VALUE source_dir) {
- CFCHierarchy *self;
-
- Data_Get_Struct(self_rb, CFCHierarchy, self);
- CFCHierarchy_add_source_dir(self, StringValuePtr(source_dir));
-
- return Qnil;
-}
-
-static VALUE
-S_CFC_Hierarchy_Add_Include_Dir(VALUE self_rb, VALUE include_dir) {
- CFCHierarchy *self;
-
- Data_Get_Struct(self_rb, CFCHierarchy, self);
- CFCHierarchy_add_include_dir(self, StringValuePtr(include_dir));
-
- return Qnil;
-}
-
-static VALUE
-S_CFC_Hierarchy_Build(VALUE self_rb) {
- CFCHierarchy *self;
-
- Data_Get_Struct(self_rb, CFCHierarchy, self);
- CFCHierarchy_build(self);
-
- return Qnil;
-}
-
-static void
-S_init_Hierarchy(void) {
- cHierarchy = rb_define_class_under(mModel, "Hierarchy", rb_cObject);
- rb_define_alloc_func(cHierarchy, S_CFC_Hierarchy_Alloc);
- rb_define_method(cHierarchy, "initialize", S_CFC_Hierarchy_Init, 1);
- rb_define_method(cHierarchy, "build", S_CFC_Hierarchy_Build, 0);
- rb_define_method(cHierarchy, "add_source_dir", S_CFC_Hierarchy_Add_Source_Dir, 1);
- rb_define_method(cHierarchy, "add_include_dir", S_CFC_Hierarchy_Add_Include_Dir, 1);
-}
-
-void
-Init_CFC() {
- mClownfish = rb_define_module("Clownfish");
- mCFC = rb_define_module_under(mClownfish, "CFC");
- mBinding = rb_define_module_under(mCFC, "Binding");
- mModel = rb_define_module_under(mCFC, "Model");
- S_init_Binding_Core();
- S_init_Binding_Ruby();
- S_init_Hierarchy();
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/ruby/ext/Clownfish/extconf.rb
----------------------------------------------------------------------
diff --git a/clownfish/compiler/ruby/ext/Clownfish/extconf.rb b/clownfish/compiler/ruby/ext/Clownfish/extconf.rb
deleted file mode 100644
index e644bcb..0000000
--- a/clownfish/compiler/ruby/ext/Clownfish/extconf.rb
+++ /dev/null
@@ -1,29 +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.
-
-require 'mkmf'
-require 'rbconfig'
-
-CLOWNFISH_INCLUDE_DIR = File.join('..','..','..','include')
-CLOWNFISH_SRC_DIR = File.join('..','..','..','src')
-CLOWNFISH_RUNTIME = File.join('..','..','..','..','runtime','ruby')
-$CFLAGS = "-I#{CLOWNFISH_INCLUDE_DIR} -I#{CLOWNFISH_SRC_DIR} -I#{CLOWNFISH_RUNTIME}"
-$objs = ['CFC.' + RbConfig::CONFIG['OBJEXT']]
-obj_glob = File.join(CLOWNFISH_SRC_DIR, '*.' + RbConfig::CONFIG['OBJEXT'])
-Dir.glob(obj_glob).each do|o|
- $objs.push o
-end
-
-create_makefile 'CFC'
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/ruby/ext/example.rb
----------------------------------------------------------------------
diff --git a/clownfish/compiler/ruby/ext/example.rb b/clownfish/compiler/ruby/ext/example.rb
deleted file mode 100644
index 9cf923e..0000000
--- a/clownfish/compiler/ruby/ext/example.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-#! /usr/bin/env ruby
-
-# 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.
-
-# Simple example on how to call CFC in ruby
-require_relative 'Clownfish/CFC'
-
-hierarchy = Clownfish::CFC::Model::Hierarchy.new(:dest => "autogen")
-hierarchy.build
-
-core_binding = Clownfish::CFC::Binding::Core.new(:hierarchy => hierarchy, :header => 'foobar', :footer => '')
-core_binding.write_all_modified
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCBase.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBase.c b/clownfish/compiler/src/CFCBase.c
deleted file mode 100644
index bce7e70..0000000
--- a/clownfish/compiler/src/CFCBase.c
+++ /dev/null
@@ -1,62 +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.
- */
-
-#define CFC_NEED_BASE_STRUCT_DEF
-#include "CFCBase.h"
-#include "CFCUtil.h"
-
-CFCBase*
-CFCBase_allocate(const CFCMeta *meta) {
- CFCBase *self = (CFCBase*)CALLOCATE(meta->obj_alloc_size, 1);
- self->refcount = 1;
- self->meta = meta;
- return self;
-}
-
-void
-CFCBase_destroy(CFCBase *self) {
- FREEMEM(self);
-}
-
-CFCBase*
-CFCBase_incref(CFCBase *self) {
- if (self) {
- self->refcount++;
- }
- return self;
-}
-
-unsigned
-CFCBase_decref(CFCBase *self) {
- if (!self) { return 0; }
- unsigned modified_refcount = --self->refcount;
- if (modified_refcount == 0) {
- self->meta->destroy(self);
- }
- return modified_refcount;
-}
-
-unsigned
-CFCBase_get_refcount(CFCBase *self) {
- return self->refcount;
-}
-
-const char*
-CFCBase_get_cfc_class(CFCBase *self) {
- return self->meta->cfc_class;
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCBase.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBase.h b/clownfish/compiler/src/CFCBase.h
deleted file mode 100644
index 9117ae2..0000000
--- a/clownfish/compiler/src/CFCBase.h
+++ /dev/null
@@ -1,89 +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_CFCBASE
-#define H_CFCBASE
-
-/** Clownfish::CFC::Base - Base class for all CFC objects.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stddef.h>
-
-typedef struct CFCBase CFCBase;
-typedef struct CFCMeta CFCMeta;
-typedef void (*CFCBase_destroy_t)(CFCBase *self);
-
-#ifdef CFC_NEED_BASE_STRUCT_DEF
-struct CFCBase {
- const CFCMeta *meta;
- int refcount;
-};
-#endif
-struct CFCMeta {
- const char *cfc_class;
- size_t obj_alloc_size;
- CFCBase_destroy_t destroy;
-};
-
-/** Allocate a new CFC object.
- *
- * @param size Size of the desired allocation in bytes.
- * @param klass Class name.
- */
-CFCBase*
-CFCBase_allocate(const CFCMeta *meta);
-
-/** Clean up CFCBase member variables as necessary and free the object blob
- * itself.
- */
-void
-CFCBase_destroy(CFCBase *self);
-
-/** Increment the refcount of the object.
- *
- * @return the object itself, allowing an assignment idiom.
- */
-CFCBase*
-CFCBase_incref(CFCBase *self);
-
-/** Decrement the refcount of the object.
- *
- * @return the modified refcount.
- */
-unsigned
-CFCBase_decref(CFCBase *self);
-
-/** Return the CFC object's refcount.
- */
-unsigned
-CFCBase_get_refcount(CFCBase *self);
-
-/** Return the class name of the CFC object. (Not the class name of any
- * parsed object the CFC object might represent.)
- */
-const char*
-CFCBase_get_cfc_class(CFCBase *self);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_CFCBASE */
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCBindAliases.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindAliases.c b/clownfish/compiler/src/CFCBindAliases.c
deleted file mode 100644
index 91da364..0000000
--- a/clownfish/compiler/src/CFCBindAliases.c
+++ /dev/null
@@ -1,53 +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 "CFCBindAliases.h"
-#include "CFCUtil.h"
-
-struct alias {
- const char *from;
- const char *to;
-};
-
-struct alias aliases[] = {
- {NULL, NULL}
-};
-
-char*
-CFCBindAliases_c_aliases(void) {
- size_t size = 200;
- for (int i = 0; aliases[i].from != NULL; i++) {
- size += strlen(aliases[i].from);
- size += strlen(aliases[i].to);
- size += sizeof("#define %s %s\n");
- }
- char *content = (char*)MALLOCATE(size);
- content[0] = '\0';
-
- strcat(content, "#ifndef CFISH_C_ALIASES\n#define CFISH_C_ALIASES\n\n");
- for (int i = 0; aliases[i].from != NULL; i++) {
- strcat(content, "#define ");
- strcat(content, aliases[i].from);
- strcat(content, " ");
- strcat(content, aliases[i].to);
- strcat(content, "\n");
- }
- strcat(content, "\n#endif /* CFISH_C_ALIASES */\n\n");
-
- return content;
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCBindAliases.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindAliases.h b/clownfish/compiler/src/CFCBindAliases.h
deleted file mode 100644
index f6b6988..0000000
--- a/clownfish/compiler/src/CFCBindAliases.h
+++ /dev/null
@@ -1,33 +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_CFCBINDALIASES
-#define H_CFCBINDALIASES
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-char*
-CFCBindAliases_c_aliases(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_CFCBINDALIASES */
-
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindClass.c b/clownfish/compiler/src/CFCBindClass.c
deleted file mode 100644
index 2b0a53a..0000000
--- a/clownfish/compiler/src/CFCBindClass.c
+++ /dev/null
@@ -1,719 +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.
- */
-
-#define CFC_NEED_BASE_STRUCT_DEF
-
-#include <stdio.h>
-#include <string.h>
-#include "CFCBindClass.h"
-#include "CFCBindFunction.h"
-#include "CFCBindMethod.h"
-#include "CFCBase.h"
-#include "CFCClass.h"
-#include "CFCFunction.h"
-#include "CFCMethod.h"
-#include "CFCParamList.h"
-#include "CFCParcel.h"
-#include "CFCType.h"
-#include "CFCVariable.h"
-#include "CFCUtil.h"
-
-struct CFCBindClass {
- CFCBase base;
- CFCClass *client;
- char *short_names_macro;
-};
-
-// Generate C header for an inert class.
-static char*
-S_to_c_header_inert(CFCBindClass *self);
-
-// Generate C header for a dynamic class.
-static char*
-S_to_c_header_dynamic(CFCBindClass *self);
-
-// Create the definition for the instantiable object struct.
-static char*
-S_struct_definition(CFCBindClass *self);
-
-// Declare typedefs for fresh methods, to ease casting.
-static char*
-S_method_typedefs(CFCBindClass *self);
-
-// If class inherits from something, include the parent class's header.
-static char*
-S_parent_include(CFCBindClass *self);
-
-// Add a C function definition for each method and each function.
-static char*
-S_sub_declarations(CFCBindClass *self);
-
-// Declare class (a.k.a. "inert") variables.
-static char*
-S_inert_var_declarations(CFCBindClass *self);
-
-// Define method invocation inline functions.
-static char*
-S_method_defs(CFCBindClass *self);
-
-// Define short names for all of the symbols associated with this class.
-static char*
-S_short_names(CFCBindClass *self);
-
-static const CFCMeta CFCBINDCLASS_META = {
- "Clownfish::CFC::Binding::Core::Class",
- sizeof(CFCBindClass),
- (CFCBase_destroy_t)CFCBindClass_destroy
-};
-
-CFCBindClass*
-CFCBindClass_new(CFCClass *client) {
- CFCBindClass *self = (CFCBindClass*)CFCBase_allocate(&CFCBINDCLASS_META);
- return CFCBindClass_init(self, client);
-}
-
-CFCBindClass*
-CFCBindClass_init(CFCBindClass *self, CFCClass *client) {
- CFCUTIL_NULL_CHECK(client);
- self->client = (CFCClass*)CFCBase_incref((CFCBase*)client);
-
- const char *PREFIX = CFCClass_get_PREFIX(client);
- self->short_names_macro = CFCUtil_sprintf("%sUSE_SHORT_NAMES", PREFIX);
-
- return self;
-}
-
-void
-CFCBindClass_destroy(CFCBindClass *self) {
- FREEMEM(self->short_names_macro);
- CFCBase_decref((CFCBase*)self->client);
- CFCBase_destroy((CFCBase*)self);
-}
-
-char*
-CFCBindClass_to_c_header(CFCBindClass *self) {
- if (CFCClass_inert(self->client)) {
- // Inert classes only output inert functions and vars.
- return S_to_c_header_inert(self);
- }
- else {
- return S_to_c_header_dynamic(self);
- }
-}
-
-static char*
-S_to_c_header_inert(CFCBindClass *self) {
- char *inert_func_decs = S_sub_declarations(self);
- char *inert_var_defs = S_inert_var_declarations(self);
- char *short_names = S_short_names(self);
-
- char pattern[] =
- "/* Declare this class's inert variables.\n"
- " */\n"
- "\n"
- "%s\n"
- "\n"
- "/* Declare this class's inert functions.\n"
- " */\n"
- "\n"
- "%s\n"
- "\n"
- "/* Define \"short names\" for this class's symbols.\n"
- " */\n"
- "\n"
- "%s\n"
- "\n";
- char *content = CFCUtil_sprintf(pattern, inert_var_defs, inert_func_decs,
- short_names);
-
- FREEMEM(inert_var_defs);
- FREEMEM(inert_func_decs);
- FREEMEM(short_names);
- return content;
-}
-
-static char*
-S_ivars_func(CFCBindClass *self) {
- CFCClass *client = self->client;
- const char *full_type = CFCClass_full_struct_sym(client);
- const char *full_func = CFCClass_full_ivars_func(client);
- const char *short_func = CFCClass_short_ivars_func(client);
- const char *full_struct = CFCClass_full_ivars_struct(client);
- const char *short_struct = CFCClass_short_ivars_struct(client);
- const char *full_offset = CFCClass_full_ivars_offset(client);
- const char *PREFIX = CFCClass_get_PREFIX(client);
- char pattern[] =
- "extern size_t %s;\n"
- "typedef struct %s %s;\n"
- "static CFISH_INLINE %s*\n"
- "%s(%s *self) {\n"
- " char *ptr = (char*)self + %s;\n"
- " return (%s*)ptr;\n"
- "}\n"
- "#ifdef %sUSE_SHORT_NAMES\n"
- " #define %s %s\n"
- " #define %s %s\n"
- "#endif\n";
- char *content = CFCUtil_sprintf(pattern,
- full_offset,
- full_struct, full_struct,
- full_struct,
- full_func, full_type,
- full_offset,
- full_struct,
- PREFIX,
- short_struct, full_struct,
- short_func, full_func);
- return content;
-}
-
-static char*
-S_to_c_header_dynamic(CFCBindClass *self) {
- const char *privacy_symbol = CFCClass_privacy_symbol(self->client);
- const char *vt_var = CFCClass_full_vtable_var(self->client);
- const char *PREFIX = CFCClass_get_PREFIX(self->client);
- char *ivars = S_ivars_func(self);
- char *struct_def = S_struct_definition(self);
- char *parent_include = S_parent_include(self);
- char *sub_declarations = S_sub_declarations(self);
- char *inert_var_defs = S_inert_var_declarations(self);
- char *method_typedefs = S_method_typedefs(self);
- char *method_defs = S_method_defs(self);
- char *short_names = S_short_names(self);
-
- char pattern[] =
- "/* Include the header for this class's parent. \n"
- " */\n"
- "\n"
- "%s\n"
- "\n"
- "/* Define the struct layout for instances of this class.\n"
- " */\n"
- "\n"
- "#ifdef %s\n"
- "%s\n"
- "%s\n"
- "#endif /* %s */\n"
- "\n"
- "/* Declare this class's inert variables.\n"
- " */\n"
- "\n"
- "%s\n"
- "\n"
- "/* Declare both this class's inert functions and the C functions which\n"
- " * implement this class's dynamic methods.\n"
- " */\n"
- "\n"
- "%s\n"
- "\n"
- "/* Define typedefs for each dynamic method, allowing us to cast generic\n"
- " * pointers to the appropriate function pointer type more cleanly.\n"
- " */\n"
- "\n"
- "%s\n"
- "\n"
- "/* Define the inline functions which implement this class's virtual methods.\n"
- " */\n"
- "\n"
- "%s\n"
- "\n"
- "/* Declare the VTable singleton for this class.\n"
- " */\n"
- "\n"
- "extern %sVISIBLE cfish_VTable *%s;\n"
- "\n"
- "/* Define \"short names\" for this class's symbols.\n"
- " */\n"
- "\n"
- "%s\n"
- "\n";
- char *content
- = CFCUtil_sprintf(pattern, parent_include, privacy_symbol, ivars,
- struct_def, privacy_symbol, inert_var_defs,
- sub_declarations, method_typedefs, method_defs,
- PREFIX, vt_var, short_names);
-
- FREEMEM(ivars);
- FREEMEM(struct_def);
- FREEMEM(parent_include);
- FREEMEM(sub_declarations);
- FREEMEM(inert_var_defs);
- FREEMEM(method_typedefs);
- FREEMEM(method_defs);
- FREEMEM(short_names);
- return content;
-}
-
-char*
-CFCBindClass_to_c_data(CFCBindClass *self) {
- CFCClass *client = self->client;
- const char *class_name = CFCClass_get_class_name(client);
-
- if (CFCClass_inert(client)) {
- return CFCUtil_strdup("");
- }
-
- const char *ivars_offset = CFCClass_full_ivars_offset(client);
-
- const char *vt_var = CFCClass_full_vtable_var(client);
-
- CFCMethod **methods = CFCClass_methods(client);
-
- char *offsets = CFCUtil_strdup("");
- char *method_defs = CFCUtil_strdup("");
- char *novel_ms_var = CFCUtil_strdup("");
- char *overridden_ms_var = CFCUtil_strdup("");
- char *inherited_ms_var = CFCUtil_strdup("");
-
- for (int meth_num = 0; methods[meth_num] != NULL; meth_num++) {
- CFCMethod *method = methods[meth_num];
-
- // Define method offset variable.
- char *full_offset_sym = CFCMethod_full_offset_sym(method, client);
- offsets = CFCUtil_cat(offsets, "size_t ", full_offset_sym, ";\n",
- NULL);
- FREEMEM(full_offset_sym);
-
- const char *meth_class_name = CFCMethod_get_class_name(method);
- int is_fresh = strcmp(class_name, meth_class_name) == 0;
-
- // Create a default implementation for abstract methods.
- if (is_fresh && CFCMethod_abstract(method)) {
- char *method_def = CFCBindMeth_abstract_method_def(method);
- method_defs = CFCUtil_cat(method_defs, method_def, "\n", NULL);
- FREEMEM(method_def);
- }
-
- if (is_fresh && CFCMethod_novel(method)) {
- if (novel_ms_var[0] == '\0') {
- // Start an array of cfish_NovelMethSpec structs. Since C89
- // doesn't allow us to initialize a pointer to an anonymous
- // array inside a global struct, we have to give it a real
- // symbol and then store a pointer to that symbol inside the
- // VTableSpec struct.
- novel_ms_var
- = CFCUtil_cat(novel_ms_var,
- "static const cfish_NovelMethSpec ",
- vt_var, "_NOVEL_METHS[] = {\n", NULL);
- }
- else {
- novel_ms_var = CFCUtil_cat(novel_ms_var, ",\n", NULL);
- }
- char *ms_def = CFCBindMeth_novel_spec_def(method);
- novel_ms_var = CFCUtil_cat(novel_ms_var, ms_def, NULL);
- FREEMEM(ms_def);
- }
- else if (is_fresh) {
- if (overridden_ms_var[0] == '\0') {
- // Start an array of cfish_OverriddenMethSpec structs.
- overridden_ms_var
- = CFCUtil_cat(overridden_ms_var,
- "static const cfish_OverriddenMethSpec ",
- vt_var, "_OVERRIDDEN_METHS[] = {\n", NULL);
- }
- else {
- overridden_ms_var
- = CFCUtil_cat(overridden_ms_var, ",\n", NULL);
- }
- char *ms_def = CFCBindMeth_overridden_spec_def(method, client);
- overridden_ms_var = CFCUtil_cat(overridden_ms_var, ms_def, NULL);
- FREEMEM(ms_def);
- }
- else {
- if (inherited_ms_var[0] == '\0') {
- // Start an array of cfish_InheritedMethSpec structs.
- inherited_ms_var
- = CFCUtil_cat(inherited_ms_var,
- "static const cfish_InheritedMethSpec ",
- vt_var, "_INHERITED_METHS[] = {\n", NULL);
- }
- else {
- inherited_ms_var = CFCUtil_cat(inherited_ms_var, ",\n", NULL);
- }
- char *ms_def = CFCBindMeth_inherited_spec_def(method, client);
- inherited_ms_var = CFCUtil_cat(inherited_ms_var, ms_def, NULL);
- FREEMEM(ms_def);
- }
- }
-
- // Close MethSpec array definitions.
- if (novel_ms_var[0] != '\0') {
- novel_ms_var = CFCUtil_cat(novel_ms_var, "\n};\n\n", NULL);
- }
- if (overridden_ms_var[0] != '\0') {
- overridden_ms_var = CFCUtil_cat(overridden_ms_var, "\n};\n\n", NULL);
- }
- if (inherited_ms_var[0] != '\0') {
- inherited_ms_var = CFCUtil_cat(inherited_ms_var, "\n};\n\n", NULL);
- }
-
- const char pattern[] =
- "/* Offset from the top of the object at which the IVARS struct\n"
- " * can be found.\n"
- " */\n"
- "\n"
- "size_t %s;\n"
- "\n"
- "/* Offsets for method pointers, measured in bytes, from the top\n"
- " * of this class's vtable.\n"
- " */\n"
- "\n"
- "%s\n"
- "\n"
- "/* Define abstract methods of this class.\n"
- " */\n"
- "\n"
- "%s\n"
- "\n"
- "/* Define the MethSpec structs used during VTable initialization.\n"
- " */\n"
- "\n"
- "%s"
- "%s"
- "%s"
- "/* Define this class's VTable.\n"
- " */\n"
- "\n"
- "cfish_VTable *%s;\n"
- "\n";
- char *code
- = CFCUtil_sprintf(pattern, ivars_offset, offsets, method_defs,
- novel_ms_var, overridden_ms_var, inherited_ms_var,
- vt_var);
-
- FREEMEM(offsets);
- FREEMEM(method_defs);
- FREEMEM(novel_ms_var);
- FREEMEM(overridden_ms_var);
- FREEMEM(inherited_ms_var);
- return code;
-}
-
-// Create the definition for the instantiable object struct.
-static char*
-S_struct_definition(CFCBindClass *self) {
- CFCClass *const client = self->client;
- const char *struct_sym;
- const char *prefix = CFCClass_get_prefix(client);
- if (strcmp(prefix, "cfish_") == 0) {
- struct_sym = CFCClass_full_struct_sym(client);
- }
- else {
- struct_sym = CFCClass_full_ivars_struct(client);
- }
-
- // Count the number of member variables declared in ancestor classes
- // outside this package so that we can skip over them.
- int num_non_package_members = 0;
- CFCParcel *parcel = CFCClass_get_parcel(client);
- CFCClass *ancestor = CFCClass_get_parent(client);
- while (ancestor && CFCClass_get_parcel(ancestor) == parcel) {
- ancestor = CFCClass_get_parent(ancestor);
- }
- if (ancestor) {
- num_non_package_members = CFCClass_num_member_vars(ancestor);
- }
-
- // Add all member variables declared by classes in this package.
- CFCVariable **member_vars = CFCClass_member_vars(client);
- char *member_decs = CFCUtil_strdup("");
- for (int i = num_non_package_members; member_vars[i] != NULL; i++) {
- const char *member_dec = CFCVariable_local_declaration(member_vars[i]);
- size_t needed = strlen(member_decs) + strlen(member_dec) + 10;
- member_decs = (char*)REALLOCATE(member_decs, needed);
- strcat(member_decs, "\n ");
- strcat(member_decs, member_dec);
- }
-
- char pattern[] = "struct %s {\n CFISH_OBJ_HEAD%s\n};\n";
- char *struct_def = CFCUtil_sprintf(pattern, struct_sym, member_decs);
-
- FREEMEM(member_decs);
- return struct_def;
-}
-
-// Return C definition of the class's VTableSpec.
-char*
-CFCBindClass_spec_def(CFCBindClass *self) {
- CFCClass *client = self->client;
-
- CFCClass *parent = CFCClass_get_parent(client);
- const char *class_name = CFCClass_get_class_name(client);
- const char *vt_var = CFCClass_full_vtable_var(client);
- const char *struct_sym = CFCClass_full_struct_sym(client);
- const char *ivars_struct = CFCClass_full_ivars_struct(client);
- const char *prefix = CFCClass_get_prefix(client);
-
- // Create a pointer to the parent class's vtable.
- char *parent_ref;
- if (parent) {
- parent_ref = CFCUtil_sprintf("&%s", CFCClass_full_vtable_var(parent));
- }
- else {
- // No parent, e.g. Obj or inert classes.
- parent_ref = CFCUtil_strdup("NULL");
- }
-
- int num_novel = 0;
- int num_overridden = 0;
- int num_inherited = 0;
- CFCMethod **methods = CFCClass_methods(client);
-
- for (int meth_num = 0; methods[meth_num] != NULL; meth_num++) {
- CFCMethod *method = methods[meth_num];
- const char *meth_class_name = CFCMethod_get_class_name(method);
-
- if (strcmp(class_name, meth_class_name) == 0) {
- if (CFCMethod_novel(method)) {
- ++num_novel;
- }
- else {
- ++num_overridden;
- }
- }
- else {
- ++num_inherited;
- }
- }
-
- char *novel_ms_var = num_novel
- ? CFCUtil_sprintf("%s_NOVEL_METHS", vt_var)
- : CFCUtil_strdup("NULL");
- char *overridden_ms_var = num_overridden
- ? CFCUtil_sprintf("%s_OVERRIDDEN_METHS", vt_var)
- : CFCUtil_strdup("NULL");
- char *inherited_ms_var = num_inherited
- ? CFCUtil_sprintf("%s_INHERITED_METHS", vt_var)
- : CFCUtil_strdup("NULL");
-
- const char *ivars_or_not = strcmp(prefix, "cfish_") == 0
- ? struct_sym : ivars_struct;
- const char *ivars_offset_name = CFCClass_full_ivars_offset(client);
-
- char pattern[] =
- " {\n"
- " &%s, /* vtable */\n"
- " %s, /* parent */\n"
- " \"%s\", /* name */\n"
- " sizeof(%s), /* ivars_size */\n"
- " &%s, /* ivars_offset_ptr */\n"
- " %d, /* num_novel */\n"
- " %d, /* num_overridden */\n"
- " %d, /* num_inherited */\n"
- " %s, /* novel_meth_specs */\n"
- " %s, /* overridden_meth_specs */\n"
- " %s /* inherited_meth_specs */\n"
- " }";
- char *code
- = CFCUtil_sprintf(pattern, vt_var, parent_ref, class_name,
- ivars_or_not, ivars_offset_name, num_novel,
- num_overridden, num_inherited, novel_ms_var,
- overridden_ms_var, inherited_ms_var);
-
- FREEMEM(parent_ref);
- FREEMEM(novel_ms_var);
- FREEMEM(overridden_ms_var);
- FREEMEM(inherited_ms_var);
- return code;
-}
-
-// Declare host callbacks.
-char*
-CFCBindClass_callback_decs(CFCBindClass *self) {
- CFCClass *client = self->client;
- CFCMethod **fresh_methods = CFCClass_fresh_methods(client);
- char *cb_decs = CFCUtil_strdup("");
-
- for (int meth_num = 0; fresh_methods[meth_num] != NULL; meth_num++) {
- CFCMethod *method = fresh_methods[meth_num];
-
- // Declare callback.
- if (CFCMethod_novel(method) && !CFCMethod_final(method)) {
- char *cb_dec = CFCBindMeth_callback_dec(method);
- cb_decs = CFCUtil_cat(cb_decs, cb_dec, "\n", NULL);
- FREEMEM(cb_dec);
- }
- }
-
- FREEMEM(fresh_methods);
-
- return cb_decs;
-}
-
-// Declare typedefs for every method, to ease casting.
-static char*
-S_method_typedefs(CFCBindClass *self) {
- CFCMethod** methods = CFCClass_methods(self->client);
- char *typedefs = CFCUtil_strdup("");
- for (int i = 0; methods[i] != NULL; i++) {
- CFCMethod *method = methods[i];
- char *typedef_str = CFCBindMeth_typedef_dec(method, self->client);
- typedefs = CFCUtil_cat(typedefs, typedef_str, "\n", NULL);
- FREEMEM(typedef_str);
- }
- return typedefs;
-}
-
-// If class inherits from something, include the parent class's header.
-static char*
-S_parent_include(CFCBindClass *self) {
- char *parent_include = CFCUtil_strdup("");
- CFCClass *parent = CFCClass_get_parent(self->client);
- if (parent) {
- parent_include = CFCUtil_cat(parent_include, "#include \"",
- CFCClass_include_h(parent), "\"", NULL);
- }
- return parent_include;
-}
-
-// Add a C function definition for each method and each function.
-static char*
-S_sub_declarations(CFCBindClass *self) {
- const char *PREFIX = CFCClass_get_PREFIX(self->client);
- CFCFunction **functions = CFCClass_functions(self->client);
- CFCMethod** fresh_methods = CFCClass_fresh_methods(self->client);
- char *declarations = CFCUtil_strdup("");
- for (int i = 0; functions[i] != NULL; i++) {
- CFCFunction *func = functions[i];
- char *dec = CFCBindFunc_func_declaration(func);
- if (!CFCFunction_inline(func)) {
- declarations = CFCUtil_cat(declarations, PREFIX, "VISIBLE ", NULL);
- }
- declarations = CFCUtil_cat(declarations, dec, "\n\n", NULL);
- FREEMEM(dec);
- }
- for (int i = 0; fresh_methods[i] != NULL; i++) {
- CFCMethod *method = fresh_methods[i];
- char *dec = CFCBindMeth_imp_declaration(method);
- if (CFCMethod_final(method)) {
- declarations = CFCUtil_cat(declarations, PREFIX, "VISIBLE ", NULL);
- }
- declarations = CFCUtil_cat(declarations, dec, "\n\n", NULL);
- FREEMEM(dec);
- }
- FREEMEM(fresh_methods);
- return declarations;
-}
-
-// Declare class (a.k.a. "inert") variables.
-static char*
-S_inert_var_declarations(CFCBindClass *self) {
- const char *PREFIX = CFCClass_get_PREFIX(self->client);
- CFCVariable **inert_vars = CFCClass_inert_vars(self->client);
- char *declarations = CFCUtil_strdup("");
- for (int i = 0; inert_vars[i] != NULL; i++) {
- const char *global_c = CFCVariable_global_c(inert_vars[i]);
- declarations = CFCUtil_cat(declarations, "extern ", PREFIX, "VISIBLE ",
- global_c, ";\n", NULL);
- }
- return declarations;
-}
-
-// Define method invocation inline functions.
-static char*
-S_method_defs(CFCBindClass *self) {
- CFCMethod **methods = CFCClass_methods(self->client);
- char *method_defs = CFCUtil_strdup("");
- for (int i = 0; methods[i] != NULL; i++) {
- CFCMethod *method = methods[i];
- char *def = CFCBindMeth_method_def(method, self->client);
- method_defs = CFCUtil_cat(method_defs, def, "\n", NULL);
- FREEMEM(def);
- }
- return method_defs;
-}
-
-
-// Define short names for all of the symbols associated with this class.
-static char*
-S_short_names(CFCBindClass *self) {
- CFCClass *client = self->client;
- char *short_names = CFCUtil_strdup("");
- short_names = CFCUtil_cat(short_names, "#ifdef ", self->short_names_macro,
- "\n", NULL);
-
- if (!CFCClass_inert(client)) {
- const char *short_struct = CFCClass_get_struct_sym(client);
- const char *full_struct = CFCClass_full_struct_sym(client);
- const char *short_vt_var = CFCClass_short_vtable_var(client);
- const char *full_vt_var = CFCClass_full_vtable_var(client);
- short_names = CFCUtil_cat(short_names, " #define ",
- short_struct, " ", full_struct, "\n",
- " #define ", short_vt_var, " ",
- full_vt_var, "\n", NULL);
- }
-
- CFCFunction **functions = CFCClass_functions(client);
- for (int i = 0; functions[i] != NULL; i++) {
- CFCFunction *func = functions[i];
- short_names = CFCUtil_cat(short_names, " #define ",
- CFCFunction_short_func_sym(func), " ",
- CFCFunction_full_func_sym(func), "\n",
- NULL);
- }
-
- CFCVariable **inert_vars = CFCClass_inert_vars(client);
- for (int i = 0; inert_vars[i] != NULL; i++) {
- CFCVariable *var = inert_vars[i];
- short_names = CFCUtil_cat(short_names, " #define ",
- CFCVariable_short_sym(var), " ",
- CFCVariable_full_sym(var), "\n", NULL);
- }
-
- if (!CFCClass_inert(client)) {
- CFCMethod **fresh_methods = CFCClass_fresh_methods(client);
- for (int i = 0; fresh_methods[i] != NULL; i++) {
- CFCMethod *meth = fresh_methods[i];
-
- // Implementing functions.
- const char *short_imp = CFCMethod_short_imp_func(meth);
- const char *full_imp = CFCMethod_imp_func(meth);
- short_names = CFCUtil_cat(short_names, " #define ", short_imp,
- " ", full_imp, "\n", NULL);
- }
- FREEMEM(fresh_methods);
-
- CFCMethod **methods = CFCClass_methods(client);
- for (int i = 0; methods[i] != NULL; i++) {
- CFCMethod *meth = methods[i];
- static const char pattern[] = " #define %s %s\n";
-
- // Method invocation symbols.
- char *short_sym = CFCMethod_short_method_sym(meth, client);
- char *full_sym = CFCMethod_full_method_sym(meth, client);
- char *define_sym = CFCUtil_sprintf(pattern, short_sym, full_sym);
- short_names = CFCUtil_cat(short_names, define_sym, NULL);
- FREEMEM(short_sym);
- FREEMEM(full_sym);
- FREEMEM(define_sym);
-
- // Method typedefs.
- char *short_typedef = CFCMethod_short_typedef(meth, client);
- char *full_typedef = CFCMethod_full_typedef(meth, client);
- char *define_typedef = CFCUtil_sprintf(pattern, short_typedef,
- full_typedef);
- short_names = CFCUtil_cat(short_names, define_typedef, NULL);
- FREEMEM(short_typedef);
- FREEMEM(full_typedef);
- FREEMEM(define_typedef);
- }
- }
- short_names = CFCUtil_cat(short_names, "#endif /* ",
- self->short_names_macro, " */\n", NULL);
-
- return short_names;
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCBindClass.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindClass.h b/clownfish/compiler/src/CFCBindClass.h
deleted file mode 100644
index 6cb9347..0000000
--- a/clownfish/compiler/src/CFCBindClass.h
+++ /dev/null
@@ -1,72 +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::Binding::Core::Class - Generate core C code for a class.
- *
- * Clownfish::CFC::Model::Class is an abstract specification for a class.
- * This module autogenerates the C code with implements that specification.
- */
-
-#ifndef H_CFCBINDCLASS
-#define H_CFCBINDCLASS
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct CFCBindClass CFCBindClass;
-
-struct CFCClass;
-
-/**
- * @param client A Clownfish::CFC::Model::Class.
- */
-struct CFCBindClass*
-CFCBindClass_new(struct CFCClass *client);
-
-struct CFCBindClass*
-CFCBindClass_init(struct CFCBindClass *self, struct CFCClass *client);
-
-void
-CFCBindClass_destroy(CFCBindClass *self);
-
-/** Return the .h file which contains autogenerated C code defining the
- * class's interface: all method invocation functions, etc...
- */
-char*
-CFCBindClass_to_c_header(CFCBindClass *self);
-
-/** Return the C data definitions necessary for the class to function properly.
- */
-char*
-CFCBindClass_to_c_data(CFCBindClass *self);
-
-/** Return the autogenerated C definition of class's VTableSpec.
- */
-char*
-CFCBindClass_spec_def(CFCBindClass *self);
-
-/* Return the declarations of the host callbacks of this class.
- */
-char*
-CFCBindClass_callback_decs(CFCBindClass *self);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_CFCBINDCLASS */
-