summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2012-01-13 04:13:13 (GMT)
committerDavid Malcolm <dmalcolm@redhat.com>2012-01-13 04:13:13 (GMT)
commit533f0201d6de3481d559c13be1822b77f2d7bb64 (patch)
tree9629801acf796eaa457a207fd5c41a6b7be4f980
parent617653735d28f42b9a2a2f703da9f10977debfb7 (diff)
downloadgcc-python-plugin-533f0201d6de3481d559c13be1822b77f2d7bb64.zip
gcc-python-plugin-533f0201d6de3481d559c13be1822b77f2d7bb64.tar.gz
gcc-python-plugin-533f0201d6de3481d559c13be1822b77f2d7bb64.tar.xz
move version handling into its own file
-rw-r--r--Makefile1
-rw-r--r--gcc-python-version.c104
-rw-r--r--gcc-python-wrappers.h10
-rw-r--r--gcc-python.c69
4 files changed, 116 insertions, 68 deletions
diff --git a/Makefile b/Makefile
index 6a8d54d..a2e7421 100644
--- a/Makefile
+++ b/Makefile
@@ -35,6 +35,7 @@ PLUGIN_SOURCE_FILES= \
gcc-python-rtl.c \
gcc-python-tree.c \
gcc-python-variable.c \
+ gcc-python-version.c \
autogenerated-callgraph.c \
autogenerated-cfg.c \
autogenerated-option.c \
diff --git a/gcc-python-version.c b/gcc-python-version.c
new file mode 100644
index 0000000..ea48a89
--- /dev/null
+++ b/gcc-python-version.c
@@ -0,0 +1,104 @@
+/*
+ Copyright 2011, 2012 David Malcolm <dmalcolm@redhat.com>
+ Copyright 2011, 2012 Red Hat, Inc.
+
+ This is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <Python.h>
+#include <structseq.h>
+#include "gcc-python.h"
+#include "plugin-version.h"
+
+/* Version handling: */
+
+static struct plugin_gcc_version *actual_gcc_version;
+
+/* Define a gcc.Version type, as a structseq */
+static struct PyStructSequence_Field gcc_version_fields[] = {
+ {"basever", NULL},
+ {"datestamp", NULL},
+ {"devphase", NULL},
+ {"revision", NULL},
+ {"configuration_arguments", NULL},
+ {0}
+};
+
+static struct PyStructSequence_Desc gcc_version_desc = {
+ "gcc.Version", /* name */
+ NULL, /* doc */
+ gcc_version_fields,
+ 5
+};
+
+PyTypeObject GccVersionType;
+
+void
+gcc_python_version_init(struct plugin_gcc_version *version)
+{
+ actual_gcc_version = version;
+ PyStructSequence_InitType(&GccVersionType, &gcc_version_desc);
+}
+
+
+static PyObject *
+gcc_version_to_object(struct plugin_gcc_version *version)
+{
+ PyObject *obj = PyStructSequence_New(&GccVersionType);
+ if (!obj) {
+ return NULL;
+ }
+
+#define SET_ITEM(IDX, FIELD) \
+ PyStructSequence_SET_ITEM(obj, (IDX), gcc_python_string_or_none(version->FIELD));
+
+ SET_ITEM(0, basever);
+ SET_ITEM(1, datestamp);
+ SET_ITEM(2, devphase);
+ SET_ITEM(3, revision);
+ SET_ITEM(4, configuration_arguments);
+
+#undef SET_ITEM
+
+ return obj;
+}
+
+PyObject *
+gcc_python_get_plugin_gcc_version(PyObject *self, PyObject *args)
+{
+ /*
+ "gcc_version" is compiled in to the plugin, as part of
+ plugin-version.h:
+ */
+ return gcc_version_to_object(&gcc_version);
+}
+
+PyObject *
+gcc_python_get_gcc_version(PyObject *self, PyObject *args)
+{
+ /*
+ "actual_gcc_version" is passed in when the plugin is initialized
+ */
+ return gcc_version_to_object(actual_gcc_version);
+}
+
+
+/*
+ PEP-7
+Local variables:
+c-basic-offset: 4
+indent-tabs-mode: nil
+End:
+*/
diff --git a/gcc-python-wrappers.h b/gcc-python-wrappers.h
index 882a242..7f5438b 100644
--- a/gcc-python-wrappers.h
+++ b/gcc-python-wrappers.h
@@ -305,6 +305,16 @@ gcc_python_tree_make_list_from_tree_list_chain(tree t);
PyObject *
gcc_python_tree_make_list_of_pairs_from_tree_list_chain(tree t);
+/* gcc-python-version.c: */
+void
+gcc_python_version_init(struct plugin_gcc_version *version);
+
+PyObject *
+gcc_python_get_plugin_gcc_version(PyObject *self, PyObject *args);
+
+PyObject *
+gcc_python_get_gcc_version(PyObject *self, PyObject *args);
+
/*
PEP-7
Local variables:
diff --git a/gcc-python.c b/gcc-python.c
index 91070d7..fb5fba9 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -18,7 +18,6 @@
*/
#include <Python.h>
-#include <structseq.h>
#include "gcc-python.h"
#include "gcc-python-closure.h"
@@ -269,70 +268,6 @@ gcc_python_get_translation_units(PyObject *self, PyObject *args)
return VEC_tree_as_PyList(all_translation_units);
}
-/* Version handling: */
-
-/* Define a gcc.Version type, as a structseq */
-static struct PyStructSequence_Field gcc_version_fields[] = {
- {"basever", NULL},
- {"datestamp", NULL},
- {"devphase", NULL},
- {"revision", NULL},
- {"configuration_arguments", NULL},
- {0}
-};
-
-static struct PyStructSequence_Desc gcc_version_desc = {
- "gcc.Version", /* name */
- NULL, /* doc */
- gcc_version_fields,
- 5
-};
-
-PyTypeObject GccVersionType;
-
-static PyObject *
-gcc_version_to_object(struct plugin_gcc_version *version)
-{
- PyObject *obj = PyStructSequence_New(&GccVersionType);
- if (!obj) {
- return NULL;
- }
-
-#define SET_ITEM(IDX, FIELD) \
- PyStructSequence_SET_ITEM(obj, (IDX), gcc_python_string_or_none(version->FIELD));
-
- SET_ITEM(0, basever);
- SET_ITEM(1, datestamp);
- SET_ITEM(2, devphase);
- SET_ITEM(3, revision);
- SET_ITEM(4, configuration_arguments);
-
-#undef SET_ITEM
-
- return obj;
-}
-
-static PyObject *
-gcc_python_get_plugin_gcc_version(PyObject *self, PyObject *args)
-{
- /*
- "gcc_version" is compiled in to the plugin, as part of
- plugin-version.h:
- */
- return gcc_version_to_object(&gcc_version);
-}
-
-static struct plugin_gcc_version *actual_gcc_version;
-
-static PyObject *
-gcc_python_get_gcc_version(PyObject *self, PyObject *args)
-{
- /*
- "actual_gcc_version" is passed in when the plugin is initialized
- */
- return gcc_version_to_object(actual_gcc_version);
-}
-
/* Dump files */
static PyObject *
@@ -738,7 +673,6 @@ plugin_init (struct plugin_name_args *plugin_info,
if (!plugin_default_version_check (version, &gcc_version)) {
return 1;
}
- actual_gcc_version = version;
#if PY_MAJOR_VERSION >= 3
/*
@@ -774,8 +708,7 @@ plugin_init (struct plugin_name_args *plugin_info,
/* Init other modules */
/* FIXME: properly integrate them within the module hierarchy */
-
- PyStructSequence_InitType(&GccVersionType, &gcc_version_desc);
+ gcc_python_version_init(version);
autogenerated_callgraph_init_types(); /* FIXME: error checking! */
autogenerated_cfg_init_types(); /* FIXME: error checking! */