Update of /cvsroot/pygccxml/source/pygccxml/parser
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26712/pygccxml/parser
Modified Files:
linker.py project_reader.py scanner.py source_reader.py
Log Message:
Adding new feature:
instance of class_t has now references to all it's typedes. This will allow pyplusplus to suggest/set better alais
without user invocation.
Index: linker.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pygccxml/parser/linker.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** linker.py 2 Mar 2006 05:51:39 -0000 1.12
--- linker.py 20 Apr 2006 04:32:16 -0000 1.13
***************
*** 19,23 ****
self.__files = files
self.__inst = None
!
def _get_inst(self):
return self.__inst
--- 19,23 ----
self.__files = files
self.__inst = None
!
def _get_inst(self):
return self.__inst
***************
*** 76,80 ****
def visit_constructor( self ):
self.__link_calldef()
!
def visit_destructor( self ):
self.__link_calldef()
--- 76,80 ----
def visit_constructor( self ):
self.__link_calldef()
!
def visit_destructor( self ):
self.__link_calldef()
***************
*** 98,101 ****
--- 98,113 ----
def visit_class(self ):
self.__link_members()
+ #GCC-XML sometimes generates constructors with names that does not match
+ #class name. I think this is because those constructors are compiler
+ #generated. I need to find out more about this and to talk with Brad
+ for decl in self.__inst.declarations:
+ if not isinstance( decl, constructor_t ):
+ continue
+ if '.' in self.__inst.name or '$' in self.__inst.name:
+ new_name = self.__inst.parent.name
+ if templates.is_instantiation( new_name ):
+ new_name = templates.name( new_name )
+ self.__inst.name = new_name
+
bases = self.__inst.bases.split()
self.__inst.bases = []
***************
*** 109,113 ****
self.__inst.bases.append( hierarchy_info_t( base_decl, access ) )
base_decl.derived.append( hierarchy_info_t( self.__inst, access ) )
!
def visit_enumeration(self ):
pass
--- 121,125 ----
self.__inst.bases.append( hierarchy_info_t( base_decl, access ) )
base_decl.derived.append( hierarchy_info_t( self.__inst, access ) )
!
def visit_enumeration(self ):
pass
Index: scanner.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pygccxml/parser/scanner.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** scanner.py 20 Apr 2006 04:06:41 -0000 1.24
--- scanner.py 20 Apr 2006 04:32:16 -0000 1.25
***************
*** 6,9 ****
--- 6,10 ----
import os
import types
+ import pprint
import xml.sax
import warnings
***************
*** 167,199 ****
def startElement(self, name, attrs):
! if name not in self.__readers:
! return
! obj = self.__readers[name]( attrs )
! if not obj:
! return #it means that we worked on internals
! #for example EnumValue of function argument
! if name in self.deep_declarations:
! self.__inst = obj
! self.__read_access( attrs )
! if isinstance( obj, declaration_t ):
! self.__update_membership( attrs )
! self.__declarations[ attrs[XML_AN_ID] ] = obj
! if not isinstance( obj, namespace_t ):
! self.__read_location( obj, attrs )
! if isinstance( obj, scopedef_t):
! #deprecated
! #self.__read_members( obj, attrs )
! if isinstance( obj, class_t ):
! self.__read_bases( obj, attrs )
! self.__read_artificial(obj, attrs)
! self.__read_mangled( obj, attrs)
! elif isinstance( obj, type_t ):
! self.__types[ attrs[XML_AN_ID] ] = obj
! elif isinstance( obj, types.StringTypes ):
! self.__files[ attrs[XML_AN_ID] ] = obj
! else:
! logger.warning( 'Unknown object type has been found.'
! + ' Please report this bug to pygccxml development team.' )
!
def endElement(self, name):
if name in self.deep_declarations:
--- 168,206 ----
def startElement(self, name, attrs):
! try:
! if name not in self.__readers:
! return
! obj = self.__readers[name]( attrs )
! if not obj:
! return #it means that we worked on internals
! #for example EnumValue of function argument
! if name in self.deep_declarations:
! self.__inst = obj
! self.__read_access( attrs )
! if isinstance( obj, declaration_t ):
! self.__update_membership( attrs )
! self.__declarations[ attrs[XML_AN_ID] ] = obj
! if not isinstance( obj, namespace_t ):
! self.__read_location( obj, attrs )
! if isinstance( obj, scopedef_t):
! #deprecated
! #self.__read_members( obj, attrs )
! if isinstance( obj, class_t ):
! self.__read_bases( obj, attrs )
! self.__read_artificial(obj, attrs)
! self.__read_mangled( obj, attrs)
! elif isinstance( obj, type_t ):
! self.__types[ attrs[XML_AN_ID] ] = obj
! elif isinstance( obj, types.StringTypes ):
! self.__files[ attrs[XML_AN_ID] ] = obj
! else:
! logger.warning( 'Unknown object type has been found.'
! + ' Please report this bug to pygccxml development team.' )
! except Exception, error:
! msg = 'error occured, while parsing element with name "%s" and attrs "%s".'
! msg = msg + os.linesep + 'Error: %s.' % str( error )
! logger.error( msg % ( name, pprint.pformat( attrs.keys() ) ) )
! raise
!
def endElement(self, name):
if name in self.deep_declarations:
***************
*** 230,237 ****
def __read_file( self, attrs ):
! return attrs[XML_AN_NAME]
def __read_namespace(self, attrs):
! ns_name = attrs[XML_AN_NAME]
if '.' in ns_name:
#if '.' in namespace then this is mangled namespace -> in c++ namespace{...}
--- 237,244 ----
def __read_file( self, attrs ):
! return attrs.get( XML_AN_NAME, '' )
def __read_namespace(self, attrs):
! ns_name = attrs.get( XML_AN_NAME, '' )
if '.' in ns_name:
#if '.' in namespace then this is mangled namespace -> in c++ namespace{...}
***************
*** 242,246 ****
def __read_enumeration(self, attrs):
! enum_name = attrs[XML_AN_NAME]
if '$_' in enum_name or '._' in enum_name:
#it means that this is unnamed enum. in c++ enum{ x };
--- 249,253 ----
def __read_enumeration(self, attrs):
! enum_name = attrs.get( XML_AN_NAME, '' )
if '$_' in enum_name or '._' in enum_name:
#it means that this is unnamed enum. in c++ enum{ x };
***************
*** 249,253 ****
def __read_enumeration_value( self, attrs ):
! self.__inst.values[attrs[XML_AN_NAME]] = attrs[XML_AN_INIT]
def __read_array_type( self, attrs ):
--- 256,260 ----
def __read_enumeration_value( self, attrs ):
! self.__inst.values[attrs.get( XML_AN_NAME, '' )] = attrs[XML_AN_INIT]
def __read_array_type( self, attrs ):
***************
*** 285,292 ****
def __read_fundamental_type(self, attrs ):
try:
! return FUNDAMENTAL_TYPES[ attrs[XML_AN_NAME] ]
except KeyError:
raise RuntimeError( "pygccxml error: unable to find fundamental type with name '%s'."
! % attrs[XML_AN_NAME] )
def __read_offset_type( self,attrs ):
--- 292,299 ----
def __read_fundamental_type(self, attrs ):
try:
! return FUNDAMENTAL_TYPES[ attrs.get( XML_AN_NAME, '' ) ]
except KeyError:
raise RuntimeError( "pygccxml error: unable to find fundamental type with name '%s'."
! % attrs.get( XML_AN_NAME, '' ) )
def __read_offset_type( self,attrs ):
***************
*** 311,315 ****
calldef.return_type = attrs.get( XML_AN_RETURNS, None )
if isinstance( calldef, declaration_t ):
! calldef.name = attrs[ XML_AN_NAME ]
calldef.has_extern = attrs.get( XML_AN_EXTERN, False )
calldef.exceptions = attrs.get( XML_AN_THROW, "" ).split()
--- 318,322 ----
calldef.return_type = attrs.get( XML_AN_RETURNS, None )
if isinstance( calldef, declaration_t ):
! calldef.name = attrs.get(XML_AN_NAME, '')
calldef.has_extern = attrs.get( XML_AN_EXTERN, False )
calldef.exceptions = attrs.get( XML_AN_THROW, "" ).split()
***************
*** 340,344 ****
def __read_typedef(self, attrs ):
! return self.__decl_factory.create_typedef( name=attrs[XML_AN_NAME], type=attrs[XML_AN_TYPE])
def __read_variable(self, attrs ):
--- 347,351 ----
def __read_typedef(self, attrs ):
! return self.__decl_factory.create_typedef( name=attrs.get( XML_AN_NAME, '' ), type=attrs[XML_AN_TYPE])
def __read_variable(self, attrs ):
***************
*** 349,353 ****
if bits:
bits = int( bits )
! return self.__decl_factory.create_variable( name=attrs[XML_AN_NAME]
, type=attrs[XML_AN_TYPE]
, type_qualifiers=type_qualifiers
--- 356,360 ----
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
Index: source_reader.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pygccxml/parser/source_reader.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** source_reader.py 6 Apr 2006 06:15:58 -0000 1.28
--- source_reader.py 20 Apr 2006 04:32:16 -0000 1.29
***************
*** 19,24 ****
RuntimeError.__init__( self, msg )
class source_reader_t:
! def __init__( self, config, cache=None, decl_factory=None):
self.__search_directories = []
self.__config = config
--- 19,53 ----
RuntimeError.__init__( self, msg )
+
+ def bind_typedefs( decls ):
+ """
+ This function binds between class and it's typedefs.
+
+ @param decls: list of all declarations
+ @type all_classes: list of L{declaration_t} items
+
+ @return: None
+ """
+ typedefs = []
+ classes = []
+ for decl in decls:
+ if isinstance( decl, class_t ):
+ classes.append( decl )
+ elif isinstance( decl, typedef_t ):
+ typedefs.append( decl )
+ else:
+ pass
+
+
+ for decl in classes:
+ for typedef in typedefs:
+ type_ = remove_alias( typedef.type )
+ if not isinstance( type_, declarated_t ):
+ continue
+ if type_.declaration is decl:
+ decl.typedefs.append( typedef )
+
class source_reader_t:
! def __init__( self, config, cache=None, decl_factory=None, enable_bind_typedefs=True):
self.__search_directories = []
self.__config = config
***************
*** 32,35 ****
--- 61,65 ----
if not decl_factory:
self.__decl_factory = decl_factory_t()
+ self.__enable_bind_typedefs = enable_bind_typedefs
def __raise_on_wrong_settings(self):
***************
*** 90,93 ****
--- 120,124 ----
if 'win' in sys.platform :
cmd_line = '"%s"' % cmd_line
+ logger.debug( 'gccxml cmd: %s' % cmd_line )
return cmd_line
***************
*** 207,211 ****
except Exception:
return file_path
!
def __parse_gccxml_created_file( self, gccxml_file ):
scanner_ = scanner.scanner_t( gccxml_file, self.__decl_factory )
--- 238,242 ----
except Exception:
return file_path
!
def __parse_gccxml_created_file( self, gccxml_file ):
scanner_ = scanner.scanner_t( gccxml_file, self.__decl_factory )
***************
*** 228,231 ****
--- 259,264 ----
linker_.instance = decl
apply_visitor( linker_, decl )
+ if self.__enable_bind_typedefs:
+ bind_typedefs( decls.itervalues() )
decls = filter( lambda inst: isinstance(inst, declaration_t) and not inst.parent, decls.itervalues() )
#some times gccxml report typedefs defined in no namespace
Index: project_reader.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pygccxml/parser/project_reader.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** project_reader.py 20 Apr 2006 04:06:41 -0000 1.30
--- project_reader.py 20 Apr 2006 04:32:16 -0000 1.31
***************
*** 167,171 ****
header = prj_file
content_type = file_configuration_t.CONTENT_TYPE.STANDARD_SOURCE_FILE
! reader = source_reader.source_reader_t( config, self.__dcache, self.__decl_factory )
decls = None
if content_type == file_configuration_t.CONTENT_TYPE.STANDARD_SOURCE_FILE:
--- 167,174 ----
header = prj_file
content_type = file_configuration_t.CONTENT_TYPE.STANDARD_SOURCE_FILE
! reader = source_reader.source_reader_t( config
! , self.__dcache
! , self.__decl_factory
! , False )
decls = None
if content_type == file_configuration_t.CONTENT_TYPE.STANDARD_SOURCE_FILE:
***************
*** 206,209 ****
--- 209,213 ----
logger.info( "Relinking declared types ..." )
self._relink_declarated_types( leaved_classes, types )
+ source_reader.bind_typedefs( pygccxml.declarations.make_flatten( answer ) )
return answer
|