Skip to content

Commit

Permalink
Use new style decorators for getters and setters
Browse files Browse the repository at this point in the history
  • Loading branch information
iMichka committed Jun 1, 2014
1 parent 190c37d commit 9745244
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 78 deletions.
56 changes: 26 additions & 30 deletions pygccxml/declarations/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,55 +47,51 @@ def __eq__(self, other):
def __hash__(self):
return super.__hash__(self)

def _get_type(self):
@property
def type(self):
"""reference to the variable :class:`type <type_t>`"""
return self._type

def _set_type(self, type):
@type.setter
def type(self, type):
self._type = type
type = property(
_get_type,
_set_type,
doc="reference to the variable :class:`type <type_t>`")

def _get_type_qualifiers(self):
@property
def type_qualifiers(self):
"""reference to the :class:`type_qualifiers_t` instance"""
return self._type_qualifiers

def _set_type_qualifiers(self, type_qualifiers):
@type_qualifiers.setter
def type_qualifiers(self, type_qualifiers):
self._type_qualifiers = type_qualifiers
type_qualifiers = property(
_get_type_qualifiers,
_set_type_qualifiers,
doc="reference to the :class:`type_qualifiers_t` instance")

def _get_value(self):
@property
def value(self):
"""string, that contains the variable value"""
return self._value

def _set_value(self, value):
@value.setter
def value(self, value):
self._value = value
value = property(
_get_value,
_set_value,
doc="string, that contains the variable value")

def _get_bits(self):
@property
def bits(self):
"""integer, that contains information about how many bit takes
bit field"""
return self._bits

def _set_bits(self, bits):
@bits.setter
def bits(self, bits):
self._bits = bits
bits = property(
_get_bits, _set_bits, doc=(
"integer, that contains information about how many bit takes " +
"bit field"))

def _get_byte_offset(self):
@property
def byte_offset(self):
"""integer, offset of the field from the beginning of class."""
return self._byte_offset

def _set_byte_offset(self, byte_offset):
@byte_offset.setter
def byte_offset(self, byte_offset):
self._byte_offset = byte_offset
byte_offset = property(
_get_byte_offset,
_set_byte_offset,
doc="integer, offset of the field from the beginning of class.")

@property
def access_type(self):
Expand Down
57 changes: 25 additions & 32 deletions pygccxml/parser/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ def __init__(
def clone(self):
raise NotImplementedError(self.__class__.__name__)

def __get_working_directory(self):
@property
def working_directory(self):
return self.__working_directory

def __set_working_directory(self, working_dir):
@working_directory.setter
def working_directory(self, working_dir):
self.__working_directory = working_dir
working_directory = property(
__get_working_directory,
__set_working_directory)

@property
def include_paths(self):
Expand All @@ -87,27 +86,24 @@ def undefine_symbols(self):
"""list of "undefine" directives """
return self.__undefine_symbols

def get_compiler(self):
@property
def compiler(self):
"""get compiler name to simulate"""
return self.__compiler

def set_compiler(self, compiler):
@compiler.setter
def compiler(self, compiler):
"""set compiler name to simulate"""
self.__compiler = compiler
compiler = property(
get_compiler,
set_compiler,
doc="compiler name to simulate")

def __get_cflags(self):
@property
def cflags(self):
"additional flags to pass to compiler"
return self.__cflags

def __set_cflags(self, val):
@cflags.setter
def cflags(self, val):
self.__cflags = val
cflags = property(
__get_cflags,
__set_cflags,
doc="additional flags to pass to compiler")

def append_cflags(self, val):
self.__cflags = self.__cflags + ' ' + val
Expand Down Expand Up @@ -172,33 +168,30 @@ def __init__(
def clone(self):
return copy.deepcopy(self)

def __get_gccxml_path(self):
@property
def gccxml_path(self):
"gccxml binary location"
return self.__gccxml_path

def __set_gccxml_path(self, new_path):
@gccxml_path.setter
def gccxml_path(self, new_path):
self.__gccxml_path = new_path
gccxml_path = property(
__get_gccxml_path,
__set_gccxml_path,
doc="gccxml binary location")

@property
def start_with_declarations(self):
"""list of declarations gccxml should start with, when it dumps
declaration tree"""
return self.__start_with_declarations

def __get_ignore_gccxml_output(self):
@property
def ignore_gccxml_output(self):
"""set this property to True, if you want pygccxml to ignore any
error warning that comes from gccxml"""
return self.__ignore_gccxml_output

def __set_ignore_gccxml_output(self, val=True):
@ignore_gccxml_output.setter
def ignore_gccxml_output(self, val=True):
self.__ignore_gccxml_output = val
ignore_gccxml_output = property(
__get_ignore_gccxml_output,
__set_ignore_gccxml_output,
doc=(
"set this property to True, if you want pygccxml to ignore any" +
"error\\warning that comes from gccxml"))

def raise_on_wrong_settings(self):
super(gccxml_configuration_t, self).raise_on_wrong_settings()
Expand Down Expand Up @@ -256,7 +249,7 @@ def load_gccxml_configuration(configuration, **defaults):
:rtype: :class:`.gccxml_configuration_t`
Configuration file sceleton::
Configuration file skeleton::
[gccxml]
#path to gccxml executable file - optional, if not provided,
Expand Down
27 changes: 14 additions & 13 deletions pygccxml/parser/declarations_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ def __init__(
self.__declarations = declarations
self.__was_hit = True # Track if there was a cache hit

def _get_was_hit(self):
@property
def was_hit(self):
return self.__was_hit

def _set_was_hit(self, was_hit):
@was_hit.setter
def was_hit(self, was_hit):
self.__was_hit = was_hit
was_hit = property(_get_was_hit, _set_was_hit)

def key(self):
return (self.__source_signature, self.__config_signature)
Expand All @@ -122,25 +123,25 @@ def create_key(source_file, configuration):
file_signature(source_file),
configuration_signature(configuration))

def __source_signature(self):
@property
def source_signature(self):
return self.__source_signature
source_signature = property(__source_signature)

def __config_signature(self):
@property
def config_signature(self):
return self.__config_signature
config_signature = property(__config_signature)

def __included_files(self):
@property
def included_files(self):
return self.__included_files
included_files = property(__included_files)

def __included_files_signature(self):
@property
def included_files_signature(self):
return self.__included_files_signature
included_files_signature = property(__included_files_signature)

def __declarations(self):
@property
def declarations(self):
return self.__declarations
declarations = property(__declarations)


class file_cache_t(cache_base_t):
Expand Down
7 changes: 4 additions & 3 deletions pygccxml/parser/linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ def __init__(self, decls, types, access, membership, files):
self.__compiler = d.compiler
break

def _get_inst(self):
@property
def instance(self):
return self.__inst

def _set_inst(self, inst):
@instance.setter
def instance(self, inst):
self.__inst = inst
# use inst, to reduce attribute access time
if isinstance(inst, declaration_t) and inst.location:
inst.location.file_name = self.__files[inst.location.file_name]
instance = property(_get_inst, _set_inst)

def __link_type(self, type_id):
if type_id is None:
Expand Down

0 comments on commit 9745244

Please sign in to comment.