[pygccxml-commit] SF.net SVN: pygccxml:[1529] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2009-01-05 13:29:47
|
Revision: 1529 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1529&view=rev Author: roman_yakovenko Date: 2009-01-05 13:29:42 +0000 (Mon, 05 Jan 2009) Log Message: ----------- adding calling_convention property Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/__init__.py pygccxml_dev/pygccxml/declarations/calldef.py pygccxml_dev/pygccxml/declarations/decl_printer.py pygccxml_dev/unittests/test_all.py Modified: pygccxml_dev/pygccxml/declarations/__init__.py =================================================================== --- pygccxml_dev/pygccxml/declarations/__init__.py 2009-01-04 20:29:35 UTC (rev 1528) +++ pygccxml_dev/pygccxml/declarations/__init__.py 2009-01-05 13:29:42 UTC (rev 1529) @@ -92,6 +92,7 @@ from calldef import VIRTUALITY_TYPES from calldef import FUNCTION_VIRTUALITY_TYPES +from calldef import CALLING_CONVENTION_TYPES from calldef import argument_t from calldef import calldef_t from calldef import member_calldef_t Modified: pygccxml_dev/pygccxml/declarations/calldef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/calldef.py 2009-01-04 20:29:35 UTC (rev 1528) +++ pygccxml_dev/pygccxml/declarations/calldef.py 2009-01-05 13:29:42 UTC (rev 1529) @@ -16,7 +16,7 @@ - constructor - destructor """ - +import re import cpptypes import algorithm import templates @@ -34,6 +34,32 @@ #preserving backward compatebility FUNCTION_VIRTUALITY_TYPES = VIRTUALITY_TYPES +class CALLING_CONVENTION_TYPES: + """class that defines "calling convention" constants""" + UNKNOWN = '' + CDECL = 'cdecl' + STDCALL = 'stdcall' + THISCALL = 'thiscall' + FASTCALL = 'fastcall' + SYSTEM_DEFAULT = '<<<system default>>>' + + ALL = ( UNKNOWN, CDECL, STDCALL, THISCALL, FASTCALL ) + + pattern = re.compile( r'.*(?:^|\s)(?:__)?(?P<cc>cdecl|stdcall|thiscall|fastcall)(?:__)?.*' ) + + @staticmethod + def extract( text, default=UNKNOWN ): + """extracts calling convention from the text. If the calling convention could not be found, the "default"is used""" + if not text: + return default + found = CALLING_CONVENTION_TYPES.pattern.match( text ) + if found: + return found.group( 'cc' ) + else: + return default + + + #First level in hierarchy of calldef class argument_t(object): """ @@ -140,6 +166,7 @@ self._return_type = return_type self._has_extern = has_extern self._demangled_name = None + self._calling_convention = None def _get__cmp__call_items(self): """implementation details""" @@ -321,6 +348,25 @@ , self.exceptions ) return answer + def guess_calling_convention( self ): + """This function should be overriden in the derived classes and return + more-or-less successfull guess about calling convention""" + return CALLING_CONVENTION_TYPES.UNKNOWN + + def get_calling_convention( self ): + if self._calling_convention is None: + self._calling_convention = CALLING_CONVENTION_TYPES.extract( self.attributes ) + if not self._calling_convention: + self._calling_convention = self.guess_calling_convention() + return self._calling_convention + + def set_calling_convention( self, cc ): + self._calling_convention = cc + + calling_convention = property( get_calling_convention, set_calling_convention + , doc="function calling convention. See L{CALLING_CONVENTION_TYPES} class for possible values" ) + + #Second level in hierarchy of calldef class member_calldef_t( calldef_t ): """base class for "callable" declarations that defined within C++ class or struct""" @@ -412,6 +458,12 @@ else: return f_type.partial_decl_string + def guess_calling_convention( self ): + if self.has_static: + return CALLING_CONVENTION_TYPES.SYSTEM_DEFAULT + else: + return CALLING_CONVENTION_TYPES.THISCALL + class free_calldef_t( calldef_t ): """base class for "callable" declarations that defined within C++ namespace""" def __init__( self, *args, **keywords ): @@ -454,7 +506,12 @@ else: return f_type.partial_decl_string + def guess_calling_convention( self ): + """This function should be overriden in the derived classes and return + more-or-less successfull guess about calling convention""" + return CALLING_CONVENTION_TYPES.UNKNOWN + class operator_t(object): """base class for "operator" declarations""" OPERATOR_WORD_LEN = len( 'operator' ) Modified: pygccxml_dev/pygccxml/declarations/decl_printer.py =================================================================== --- pygccxml_dev/pygccxml/declarations/decl_printer.py 2009-01-04 20:29:35 UTC (rev 1528) +++ pygccxml_dev/pygccxml/declarations/decl_printer.py 2009-01-05 13:29:42 UTC (rev 1529) @@ -136,6 +136,7 @@ self.writer( indent + "is extern: " + str(decl.has_extern) + os.linesep) self.writer( indent + "return type: " + str(retval) + os.linesep) self.writer( indent + "arguments type: " + ', '.join(args) + os.linesep) + self.writer( indent + "calling convention: __%s__" % decl.calling_convention + os.linesep) if isinstance( decl, calldef.member_calldef_t ): self.writer( indent + "virtual: " + str(decl.virtuality) + os.linesep) self.writer( indent + "is const: " + str(decl.has_const) + os.linesep) Modified: pygccxml_dev/unittests/test_all.py =================================================================== --- pygccxml_dev/unittests/test_all.py 2009-01-04 20:29:35 UTC (rev 1528) +++ pygccxml_dev/unittests/test_all.py 2009-01-05 13:29:42 UTC (rev 1529) @@ -53,6 +53,7 @@ import better_templates_matcher_tester import declaration_matcher_tester import undname_creator_tester +import calling_convention_tester testers = [ decl_string_tester @@ -102,6 +103,7 @@ , better_templates_matcher_tester , declaration_matcher_tester , undname_creator_tester + , calling_convention_tester ] def create_suite(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |