[pygccxml-commit] SF.net SVN: pygccxml: [1193] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2007-12-04 20:52:34
|
Revision: 1193
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1193&view=rev
Author: roman_yakovenko
Date: 2007-12-04 12:52:37 -0800 (Tue, 04 Dec 2007)
Log Message:
-----------
adding byte_align, byte_size and byte_offset to the declarations and types
Modified Paths:
--------------
pygccxml_dev/pygccxml/declarations/class_declaration.py
pygccxml_dev/pygccxml/declarations/cpptypes.py
pygccxml_dev/pygccxml/declarations/decl_printer.py
pygccxml_dev/pygccxml/declarations/typedef.py
pygccxml_dev/pygccxml/declarations/variable.py
pygccxml_dev/pygccxml/parser/scanner.py
pygccxml_dev/unittests/core_tester.py
pygccxml_dev/unittests/data/core_cache.hpp
pygccxml_dev/unittests/data/core_types.hpp
Modified: pygccxml_dev/pygccxml/declarations/class_declaration.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/class_declaration.py 2007-12-04 18:44:14 UTC (rev 1192)
+++ pygccxml_dev/pygccxml/declarations/class_declaration.py 2007-12-04 20:52:37 UTC (rev 1193)
@@ -129,6 +129,8 @@
self._private_members = []
self._protected_members = []
self._aliases = []
+ self._byte_size = 0
+ self._byte_align = 0
self._container_traits = None
self._container_traits_set = False
self._recursive_bases = None
@@ -274,6 +276,20 @@
aliases = property( _get_aliases, _set_aliases
, doc="List of L{aliases<typedef_t>} to this instance")
+ def _get_byte_size(self):
+ return self._byte_size
+ def _set_byte_size( self, new_byte_size ):
+ self._byte_size = new_byte_size
+ byte_size = property( _get_byte_size, _set_byte_size
+ , doc="Size of this class in bytes @type: int")
+
+ def _get_byte_align(self):
+ return self._byte_align
+ def _set_byte_align( self, new_byte_align ):
+ self._byte_align = new_byte_align
+ byte_align = property( _get_byte_align, _set_byte_align
+ , doc="Alignment of this class in bytes @type: int")
+
def _get_declarations_impl(self):
return self.get_members()
Modified: pygccxml_dev/pygccxml/declarations/cpptypes.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/cpptypes.py 2007-12-04 18:44:14 UTC (rev 1192)
+++ pygccxml_dev/pygccxml/declarations/cpptypes.py 2007-12-04 20:52:37 UTC (rev 1193)
@@ -14,6 +14,8 @@
def __init__(self):
object.__init__( self )
self.cache = algorithms_cache.type_algs_cache_t()
+ self._byte_size = 0
+ self._byte_align = 0
def __str__(self):
res = self.decl_string
@@ -53,6 +55,21 @@
answer = self._clone_impl()
return answer
+ def _get_byte_size(self):
+ return self._byte_size
+ def _set_byte_size( self, new_byte_size ):
+ self._byte_size = new_byte_size
+ byte_size = property( _get_byte_size, _set_byte_size
+ , doc="Size of this type in bytes @type: int")
+
+ def _get_byte_align(self):
+ return self._byte_align
+ def _set_byte_align( self, new_byte_align ):
+ self._byte_align = new_byte_align
+ byte_align = property( _get_byte_align, _set_byte_align
+ , doc="Alignment of this type in bytes @type: int")
+
+
#There are cases when GCC-XML reports something like this
#<Unimplemented id="_9482" tree_code="188" tree_code_name="template_type_parm" node="0xcc4d5b0"/>
#In this case I will use this as type
@@ -628,6 +645,16 @@
def _clone_impl( self ):
return declarated_t( self._declaration )
+ @property
+ def byte_size (self):
+ "Size of this type in bytes @type: int"
+ return self._declaration.byte_size
+
+ @property
+ def byte_align (self):
+ "alignment of this type in bytes @type: int"
+ return self._declaration.byte_align
+
class type_qualifiers_t( object ):
"""contains additional information about type: mutable, static, extern"""
def __init__(self, has_static=False, has_mutable=False ):
Modified: pygccxml_dev/pygccxml/declarations/decl_printer.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/decl_printer.py 2007-12-04 18:44:14 UTC (rev 1192)
+++ pygccxml_dev/pygccxml/declarations/decl_printer.py 2007-12-04 20:52:37 UTC (rev 1193)
@@ -141,6 +141,11 @@
curr_level = self.level + 1
class_type = 'class type: ' + "'%s'" % str(self.__inst.class_type)
self.writer( ' ' * curr_level * self.INDENT_SIZE + class_type.ljust( self.JUSTIFY ) + os.linesep )
+ if self.__print_details:
+ byte_size = 'size: %d'%(self.__inst.byte_size)
+ self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_size.ljust( self.JUSTIFY ) + os.linesep )
+ byte_align = 'align: %d'%(self.__inst.byte_align)
+ self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_align.ljust( self.JUSTIFY ) + os.linesep )
if self.__inst.aliases:
aliases = map( lambda typedef: typedef.name, self.__inst.aliases )
@@ -201,6 +206,13 @@
self.print_decl_header()
curr_level = self.level + 1
self.writer( ' ' * curr_level * self.INDENT_SIZE + 'type: %s value: %s'%(self.__inst.type.decl_string, self.__inst.value) + os.linesep)
+ if self.__print_details:
+ byte_size = 'size: %d'%(self.__inst.type.byte_size)
+ self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_size.ljust( self.JUSTIFY ) + os.linesep )
+ byte_align = 'align: %d'%(self.__inst.type.byte_align)
+ self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_align.ljust( self.JUSTIFY ) + os.linesep )
+ byte_offset = 'offset: %d'%(self.__inst.byte_offset)
+ self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_offset + os.linesep)
def print_declarations( decls, detailed=True, recursive=True, writer=sys.stdout.write ):
""" Print decl tree rooted at each of the included nodes.
Modified: pygccxml_dev/pygccxml/declarations/typedef.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/typedef.py 2007-12-04 18:44:14 UTC (rev 1192)
+++ pygccxml_dev/pygccxml/declarations/typedef.py 2007-12-04 20:52:37 UTC (rev 1193)
@@ -36,3 +36,13 @@
def i_depend_on_them( self, recursive=True ):
return [ dependencies.dependency_info_t( self, self.type ) ]
+
+ @property
+ def byte_size (self):
+ "Size of this type in bytes @type: int"
+ return self._type.byte_size
+
+ @property
+ def byte_align (self):
+ "alignment of this type in bytes @type: int"
+ return self._type.byte_align
Modified: pygccxml_dev/pygccxml/declarations/variable.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/variable.py 2007-12-04 18:44:14 UTC (rev 1192)
+++ pygccxml_dev/pygccxml/declarations/variable.py 2007-12-04 20:52:37 UTC (rev 1193)
@@ -21,7 +21,8 @@
self._type_qualifiers = type_qualifiers
self._value = value
self._bits = bits
-
+ self._byte_offset = 0
+
def _get__cmp__items( self ):
"""implementation details"""
return [ self.type, self.type_qualifiers, self.value ]
@@ -63,6 +64,14 @@
bits = property( _get_bits, _set_bits
, doc="integer, that contains information about how many bit takes bit field")
+ def _get_byte_offset(self):
+ return self._byte_offset
+ def _set_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):
if not isinstance( self.parent, class_declaration.class_t ):
Modified: pygccxml_dev/pygccxml/parser/scanner.py
===================================================================
--- pygccxml_dev/pygccxml/parser/scanner.py 2007-12-04 18:44:14 UTC (rev 1192)
+++ pygccxml_dev/pygccxml/parser/scanner.py 2007-12-04 20:52:37 UTC (rev 1193)
@@ -18,6 +18,7 @@
#also those constants are sorted for easy searching.
XML_AN_ABSTRACT = "abstract"
XML_AN_ACCESS = "access"
+XML_AN_ALIGN = "align"
XML_AN_ARTIFICIAL = "artificial"
XML_AN_ATTRIBUTES = "attributes"
XML_AN_BASE_TYPE = "basetype"
@@ -39,9 +40,11 @@
XML_AN_MEMBERS = "members"
XML_AN_MUTABLE = "mutable"
XML_AN_NAME = "name"
+XML_AN_OFFSET = "offset"
XML_AN_PURE_VIRTUAL = "pure_virtual"
XML_AN_RESTRICT = "restrict"
XML_AN_RETURNS = "returns"
+XML_AN_SIZE = "size"
XML_AN_STATIC = "static"
XML_AN_THROW = "throw"
XML_AN_TYPE = "type"
@@ -210,9 +213,12 @@
self.__read_artificial(obj, attrs)
self.__read_mangled( obj, attrs)
self.__read_demangled( obj, attrs)
- self.__read_attributes(obj, attrs)
+ self.__read_attributes(obj, attrs)
+
elif isinstance( obj, type_t ):
self.__types[ element_id ] = obj
+ self.__read_byte_size(obj, attrs)
+ self.__read_byte_align(obj, attrs)
elif isinstance( obj, types.StringTypes ):
self.__files[ element_id ] = obj
else:
@@ -260,6 +266,21 @@
def __read_access( self, attrs ):
self.__access[ attrs[XML_AN_ID] ] = attrs.get( XML_AN_ACCESS, ACCESS_TYPES.PUBLIC )
+ def __read_byte_size (self, decl, attrs):
+ "Using duck typing to set the size instead of in constructor"
+ size = attrs.get(XML_AN_SIZE, 0)
+ decl.byte_size = int(size)/8 # Make sure the size is in bytes instead of bits
+
+ def __read_byte_offset (self, decl, attrs):
+ "Using duck typing to set the offset instead of in constructor"
+ offset = attrs.get(XML_AN_OFFSET, 0)
+ decl.byte_offset = int(offset)/8 # Make sure the size is in bytes instead of bits
+
+ def __read_byte_align (self, decl, attrs):
+ "Using duck typing to set the alignment"
+ align = attrs.get(XML_AN_ALIGN, 0)
+ decl.byte_align = int(align)/8 # Make sure the size is in bytes instead of bits
+
def __read_root(self, attrs):
pass
@@ -408,12 +429,14 @@
bits = attrs.get( XML_AN_BITS, None )
if bits:
bits = int( bits )
- return self.__decl_factory.create_variable( name=attrs.get( XML_AN_NAME, '' )
- , type=attrs[XML_AN_TYPE]
- , type_qualifiers=type_qualifiers
- , value=attrs.get( XML_AN_INIT, None )
- , bits=bits)
-
+ decl = self.__decl_factory.create_variable( name=attrs.get( XML_AN_NAME, '' )
+ , type=attrs[XML_AN_TYPE]
+ , type_qualifiers=type_qualifiers
+ , value=attrs.get( XML_AN_INIT, None )
+ , bits=bits)
+ self.__read_byte_offset(decl, attrs)
+ return decl
+
__read_field = __read_variable #just a synonim
def __read_class_impl(self, class_type, attrs):
@@ -429,6 +452,8 @@
decl.is_abstract = True
else:
decl.is_abstract = False
+ self.__read_byte_size(decl, attrs)
+ self.__read_byte_align(decl, attrs)
return decl
def __read_class( self, attrs ):
Modified: pygccxml_dev/unittests/core_tester.py
===================================================================
--- pygccxml_dev/unittests/core_tester.py 2007-12-04 18:44:14 UTC (rev 1192)
+++ pygccxml_dev/unittests/core_tester.py 2007-12-04 20:52:37 UTC (rev 1193)
@@ -297,7 +297,20 @@
def test_versioning(self):
for d in self.global_ns.decls():
self.failUnless( d.compiler )
+
+ def test_byte_size( self ):
+ mptrs = self.global_ns.class_( 'members_pointers_t' )
+ self.failUnless( mptrs.byte_size != 0 )
+
+ def test_byte_align( self ):
+ mptrs = self.global_ns.class_( 'members_pointers_t' )
+ self.failUnless( mptrs.byte_align != 0 )
+ def test_byte_offset( self ):
+ mptrs = self.global_ns.class_( 'members_pointers_t' )
+ self.failUnless( mptrs.var( 'xxx' ).byte_offset != 0 )
+
+
class core_all_at_once_t( core_t ):
COMPILATION_MODE = COMPILATION_MODE.ALL_AT_ONCE
INIT_OPTIMIZER = True
Modified: pygccxml_dev/unittests/data/core_cache.hpp
===================================================================
--- pygccxml_dev/unittests/data/core_cache.hpp 2007-12-04 18:44:14 UTC (rev 1192)
+++ pygccxml_dev/unittests/data/core_cache.hpp 2007-12-04 20:52:37 UTC (rev 1193)
@@ -22,4 +22,4 @@
#endif//__core_cache_hpp__
-//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch
\ No newline at end of file
+//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch
\ No newline at end of file
Modified: pygccxml_dev/unittests/data/core_types.hpp
===================================================================
--- pygccxml_dev/unittests/data/core_types.hpp 2007-12-04 18:44:14 UTC (rev 1192)
+++ pygccxml_dev/unittests/data/core_types.hpp 2007-12-04 20:52:37 UTC (rev 1193)
@@ -46,6 +46,7 @@
struct members_pointers_t{
int some_function( double ) const throw( exception );
int m_some_const_member;
+ int xxx;
};
typedef int (members_pointers_t::*member_function_ptr_t)( double )const;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|