From a3b5cdaac47c3be5cf81a2116ede72225899d5eb Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 23 Feb 2011 11:53:15 -0500 Subject: [PATCH] Move CtxAttributes from Cython.Compiler.Parsing to Cython.Compiler.Binding. This will avoid cyclic dependencies when we start messing with CSource, CBinding, and PythonBinding in Cython.Compiler.Symtab and friends. --- Cython/Compiler/Binding.py | 72 ++++++++++++++++++++++++++++++++++++++ Cython/Compiler/Parsing.py | 70 +----------------------------------- 2 files changed, 73 insertions(+), 69 deletions(-) create mode 100644 Cython/Compiler/Binding.py diff --git a/Cython/Compiler/Binding.py b/Cython/Compiler/Binding.py new file mode 100644 index 00000000..a14cca17 --- /dev/null +++ b/Cython/Compiler/Binding.py @@ -0,0 +1,72 @@ +# +# Classes defining binding interfaces. +# + + +class CtxAttribute(object): + """Base class for complicated Ctx attributes. + + Having a single base class makes it easier to generate child + contexts. + """ + def deepcopy(self): + cls = type(self) + cpy = cls() + cpy.__dict__.update(self.__dict__) + return cpy + + +class CSource(CtxAttribute): + """Configure the location of an object's C source. + + * name (string): Source symbol name (if the symbol is external) + * namespace (string): C++ namespace (`None` for C objects, set if + the symbol is external) + * cdef_flag (boolean): Symbol (data) has a C definition. + * extern (boolean): Symbol is defined elsewhere (otherwise a local + defition is created). + """ + name = None + namespace = None + cdef_flag = 0 + extern = 0 + + +class CBinding(CtxAttribute): + """Configure the presence and behaviour of an object's C bindings. + + * name (string): Generated symbol name + * namespace (string): C++ namespace (`None` for C objects) + * api (boolean): Add to generated header file + * visibility ('private'|'public'): + + * private: Symbol is not accessible to external C code + * public: Symbol is accessible to external C code + + * const (boolean): Symbol data is readonly. + """ + name = None + namespace = None + api = 0 + visibility = 'private' + const = 0 + + +class PythonBinding(CtxAttribute): + """Configure the presence and behaviour of an object's Python bindings. + + * name (string): Name to which the object is bound (if the object + is visible) + * visibility ('private'|'public'|'readonly'): + + * private: Object is not exposed to Python code. + * public: Python can read/write to the object's data. + * readonly: Python can read (but nut write) the object's data. + + * overridable (boolean): Python references can be overridden in + Python (if the object is visible). This is only supported in + class methods. + """ + name = None + visibility = 'private' + overridable = 0 diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 29407a91..5395b9c3 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -13,6 +13,7 @@ import re import sys from Cython.Compiler.Scanning import PyrexScanner, FileSourceDescriptor +from Binding import CtxAttribute, CSource, CBinding, PythonBinding import Nodes import ExprNodes import StringEncoding @@ -31,75 +32,6 @@ _LOG.addHandler(logging.StreamHandler()) _LOG.handlers[-1].setLevel(logging.DEBUG) -class CtxAttribute(object): - """Base class for complicated Ctx attributes. - - Having a single base class makes it easier to generate child - contexts. - """ - def deepcopy(self): - cls = type(self) - cpy = cls() - cpy.__dict__.update(self.__dict__) - return cpy - - -class CSource(CtxAttribute): - """Configure the location of an object's C source. - - * name (string): Source symbol name (if the symbol is external) - * namespace (string): C++ namespace (`None` for C objects, set if - the symbol is external) - * cdef_flag (boolean): Symbol (data) has a C definition. - * extern (boolean): Symbol is defined elsewhere (otherwise a local - defition is created). - """ - name = None - namespace = None - cdef_flag = 0 - extern = 0 - - -class CBinding(CtxAttribute): - """Configure the presence and behaviour of an object's C bindings. - - * name (string): Generated symbol name - * namespace (string): C++ namespace (`None` for C objects) - * api (boolean): Add to generated header file - * visibility ('private'|'public'): - - * private: Symbol is not accessible to external C code - * public: Symbol is accessible to external C code - - * const (boolean): Symbol data is readonly. - """ - name = None - namespace = None - api = 0 - visibility = 'private' - const = 0 - - -class PythonBinding(CtxAttribute): - """Configure the presence and behaviour of an object's Python bindings. - - * name (string): Name to which the object is bound (if the object - is visible) - * visibility ('private'|'public'|'readonly'): - - * private: Object is not exposed to Python code. - * public: Python can read/write to the object's data. - * readonly: Python can read (but nut write) the object's data. - - * overridable (boolean): Python references can be overridden in - Python (if the object is visible). This is only supported in - class methods. - """ - name = None - visibility = 'private' - overridable = 0 - - class Ctx(object): # Parsing context level = 'other' -- 2.26.2