Refactor the context work, to use composable objects rather than inheritable classes.

This commit is contained in:
Mike Auty
2015-01-19 23:57:49 +00:00
parent 38a85cfc0b
commit 3a28d7ae41
8 changed files with 118 additions and 105 deletions
+7 -27
View File
@@ -45,32 +45,12 @@ class ContextInterface(object, metaclass = ABCMeta):
"""
class ContextFactoryInterface(object, metaclass = ABCMeta):
"""Class to establish and load the appropriate components of the context for a given operating system"""
def __call__(self):
"""Constructs a standard context based on the architecture information
The context is modified
"""
context = self.construct_context()
self.construct_physical_layers(context)
self.construct_architecture(context)
self.construct_os_symbols(context)
return context
class ContextModifierInterface(object, metaclass = ABCMeta):
@classmethod
@abstractmethod
def get_config_options(cls):
"""Returns all the options that might need to be passed to modify the context"""
@abstractmethod
def construct_context(self):
"""Returns a context based on some native types"""
@abstractmethod
def construct_physical_layers(self, context):
"""Adds a 'physical' layer to the context that should be used by the architecture, and any additional layers that might be usable by the architecture"""
@abstractmethod
def construct_architecture(self, context):
"""Applies the architecture mapping layer, using the primary 'physical' layer and any other layers it can additionally make use of"""
@abstractmethod
def construct_os_symbols(self, context):
"""Add the appropriate symbols for the operating system"""
def __call__(self, context):
"""Modifies the context in place"""
+10 -1
View File
@@ -15,7 +15,7 @@ class SymbolTableInterface(validity.ValidityRoutines):
if name:
self._type_check(name, str)
self.name = name or None
self._native_structures = native_structures
self.natives = native_structures
# ## Required Constant symbol functions
@@ -52,6 +52,15 @@ class SymbolTableInterface(validity.ValidityRoutines):
"""Returns None or a symbol_space for handling space specific native types"""
return self._native_structures
@natives.setter
def natives(self, value):
"""Checks the natives value and then applies it internally
WARNING: This allows changing the underlying size of all the other structures referenced in the symbolspace
"""
self._type_check(value, NativeTableInterface)
self._native_structures = value
# ## Functions for overriding classes
def set_structure_class(self, name, clazz):