[pygccxml-commit] SF.net SVN: pygccxml: [269] pygccxml_dev/pygccxml/parser
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-07-02 17:25:33
|
Revision: 269 Author: roman_yakovenko Date: 2006-07-02 10:25:19 -0700 (Sun, 02 Jul 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=269&view=rev Log Message: ----------- integrating cflags patch from Allen Modified Paths: -------------- pygccxml_dev/pygccxml/parser/config.py pygccxml_dev/pygccxml/parser/declarations_cache.py pygccxml_dev/pygccxml/parser/directory_cache.py pygccxml_dev/pygccxml/parser/source_reader.py Modified: pygccxml_dev/pygccxml/parser/config.py =================================================================== --- pygccxml_dev/pygccxml/parser/config.py 2006-06-29 13:05:12 UTC (rev 268) +++ pygccxml_dev/pygccxml/parser/config.py 2006-07-02 17:25:19 UTC (rev 269) @@ -28,7 +28,8 @@ , undefine_symbols=None , start_with_declarations=None , verbose=False - , ignore_gccxml_output=False): + , ignore_gccxml_output=False + , cflags=""): """Constructor. """ object.__init__( self ) @@ -53,6 +54,7 @@ self.__verbose = verbose self.__ignore_gccxml_output = ignore_gccxml_output + self.__cflags = cflags def clone(self): return config_t( gccxml_path=self.__gccxml_path @@ -62,7 +64,8 @@ , undefine_symbols=self.__undefine_symbols[:] , start_with_declarations=self.__start_with_declarations[:] , verbose=self.verbose - , ignore_gccxml_output=self.ignore_gccxml_output) + , ignore_gccxml_output=self.ignore_gccxml_output + , cflags=self.cflags) def __get_gccxml_path(self): return self.__gccxml_path @@ -103,3 +106,9 @@ def __set_ignore_gccxml_output(self, val=True): self.__ignore_gccxml_output = val ignore_gccxml_output = property( __get_ignore_gccxml_output, __set_ignore_gccxml_output ) + + def __get_cflags(self): + return self.__cflags + def __set_cflags(self, val): + self.__cflags = val + cflags = property( __get_cflags, __set_cflags ) Modified: pygccxml_dev/pygccxml/parser/declarations_cache.py =================================================================== --- pygccxml_dev/pygccxml/parser/declarations_cache.py 2006-06-29 13:05:12 UTC (rev 268) +++ pygccxml_dev/pygccxml/parser/declarations_cache.py 2006-07-02 17:25:19 UTC (rev 269) @@ -25,33 +25,59 @@ f.close() return sig.hexdigest() +def configuration_signature( config ): + """ Return a signature for a configuration (config_t) + object. This can then be used as a key in the cache. + This method must take into account anything about + a configuration that could cause the declarations generated + to be different between runs. + """ + sig = md5.new() + sig.update(str(config.gccxml_path)) + sig.update(str(config.working_directory)) + sig.update(str(config.cflags)) + for p in config.include_paths: + sig.update(str(p)) + for s in config.define_symbols: + sig.update(str(s)) + for u in config.undefine_symbols: + sig.update(str(u)) + return sig.hexdigest() + class cache_base_t( object ): def __init__( self ): object.__init__(self) def flush(self): + """ Flush (write out) the cache to disk if needed. """ raise NotImplementedError() def update(self, source_file, configuration, declarations, included_files): + """ Update cache entry. + @param source_file: path to the C++ source file being parsed + @param configuration: configuration used in parsing (config_t) + @param declarations: declaration tree found when parsing + @param included_files: files included by parsing. + """ raise NotImplementedError() def cached_value(self, source_file, configuration): - #returns declarations, types + """ Return declarations we have cached for the source_file and configuration + given. + @param source_file: path to the C++ source file being parsed. + @param configuration: configuration to use for parsing (config_t) + """ raise NotImplementedError() class record_t( object ): def __init__( self , source_signature - , working_directory - , include_paths - , define_symbols + , config_signature , included_files , included_files_signature , declarations ): self.__source_signature = source_signature - self.__working_directory = working_directory - self.__include_paths = include_paths - self.__define_symbols = define_symbols + self.__config_signature = config_signature self.__included_files = included_files self.__included_files_signature = included_files_signature self.__declarations = declarations @@ -64,16 +90,11 @@ was_hit = property( _get_was_hit, _set_was_hit ) def key(self): - return ( self.__source_signature - , self.__working_directory - , tuple(self.__include_paths) - , tuple(self.__define_symbols ) ) + return ( self.__source_signature, self.__config_signature) def create_key( source_file, configuration ): return ( file_signature(source_file) - , configuration.working_directory - , tuple( configuration.include_paths ) - , tuple( configuration.define_symbols ) ) + , configuration_signature(configuration)) create_key = staticmethod( create_key ) #def value(self): @@ -97,22 +118,10 @@ return self.__source_signature source_signature = property( __source_signature ) - def __source_file(self): - return self.__source_file - source_file = property( __source_file ) - - def __working_directory(self): - return self.__working_directory - working_directory = property( __working_directory ) - - def __include_paths(self): - return self.__include_paths - include_paths = property( __include_paths ) - - def __define_symbols(self): - return self.__define_symbols - define_symbols = property( __define_symbols ) - + def __config_signature(self): + return self.__config_signature + config_signature = property( __config_signature ) + def __included_files(self): return self.__included_files included_files = property( __included_files ) @@ -134,14 +143,18 @@ """ def __init__( self, name ): + """ + @param name: name of the cache file. + """ cache_base_t.__init__( self ) - self.__name = name - self.__cache = self.__load( self.__name ) + self.__name = name # Name of cache file + self.__cache = self.__load( self.__name ) # Map record_key to record_t self.__needs_flushed = not bool( self.__cache ) # If empty then we need to flush for entry in self.__cache.itervalues(): # Clear hit flags entry.was_hit = False - def __load( file_name ): + def __load( file_name ): + " Load pickled cache from file and return the object. " cache = None if os.path.exists( file_name ) and not os.path.isfile( file_name ): raise RuntimeError( 'Cache should be initialized with valid full file name' ) @@ -165,10 +178,12 @@ __load = staticmethod( __load ) def flush(self): - # Remove entries that did not get a cache hit + # If not marked as needing flushed, then return immediately if not self.__needs_flushed: + logger.info("Cache did not change, ignoring flush.") return + # Remove entries that did not get a cache hit num_removed = 0 for key in self.__cache.keys(): if not self.__cache[key].was_hit: @@ -184,9 +199,7 @@ def update(self, source_file, configuration, declarations, included_files): """ Update a cached record with the current key and value contents. """ record = record_t( source_signature=file_signature(source_file) - , working_directory=configuration.working_directory - , include_paths=configuration.include_paths - , define_symbols=configuration.define_symbols + , config_signature=configuration_signature(configuration) , included_files=included_files , included_files_signature=map( file_signature, included_files) , declarations=declarations Modified: pygccxml_dev/pygccxml/parser/directory_cache.py =================================================================== --- pygccxml_dev/pygccxml/parser/directory_cache.py 2006-06-29 13:05:12 UTC (rev 268) +++ pygccxml_dev/pygccxml/parser/directory_cache.py 2006-07-02 17:25:19 UTC (rev 269) @@ -345,6 +345,7 @@ map(lambda p: m.update(p), config.include_paths) map(lambda p: m.update(p), config.define_symbols) map(lambda p: m.update(p), config.undefine_symbols) + map(lambda p: m.update(p), config.cflags) return m.digest() Modified: pygccxml_dev/pygccxml/parser/source_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/source_reader.py 2006-06-29 13:05:12 UTC (rev 268) +++ pygccxml_dev/pygccxml/parser/source_reader.py 2006-07-02 17:25:19 UTC (rev 269) @@ -127,6 +127,9 @@ cmd.append( '"%s"' % os.path.normpath( self.__config.gccxml_path ) ) else: cmd.append( '%s' % os.path.normpath( self.__config.gccxml_path ) ) + # Add all cflags passed + if self.__config.cflags != "": + cmd.append(" %s "%self.__config.cflags) #second all additional includes directories cmd.append( ''.join( [' -I"%s"' % search_dir for search_dir in self.__search_directories] ) ) #third all additional defined symbols This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |