idx
int64
0
251k
question
stringlengths
53
3.53k
target
stringlengths
5
1.23k
len_question
int64
20
893
len_target
int64
3
238
235,100
def is_volatile ( type_ ) : nake_type = remove_alias ( type_ ) if isinstance ( nake_type , cpptypes . volatile_t ) : return True elif isinstance ( nake_type , cpptypes . const_t ) : return is_volatile ( nake_type . base ) elif isinstance ( nake_type , cpptypes . array_t ) : return is_volatile ( nake_type . base ) return False
returns True if type represents C ++ volatile type False otherwise
108
12
235,101
def remove_volatile ( type_ ) : nake_type = remove_alias ( type_ ) if not is_volatile ( nake_type ) : return type_ else : if isinstance ( nake_type , cpptypes . array_t ) : is_c = is_const ( nake_type ) if is_c : base_type_ = nake_type . base . base . base else : base_type_ = nake_type . base . base result_type = base_type_ if is_c : result_type = cpptypes . const_t ( result_type ) return cpptypes . array_t ( result_type , nake_type . size ) return nake_type . base
removes volatile from the type definition
162
7
235,102
def remove_cv ( type_ ) : nake_type = remove_alias ( type_ ) if not is_const ( nake_type ) and not is_volatile ( nake_type ) : return type_ result = nake_type if is_const ( result ) : result = remove_const ( result ) if is_volatile ( result ) : result = remove_volatile ( result ) if is_const ( result ) : result = remove_const ( result ) return result
removes const and volatile from the type definition
106
9
235,103
def is_fundamental ( type_ ) : return does_match_definition ( type_ , cpptypes . fundamental_t , ( cpptypes . const_t , cpptypes . volatile_t ) ) or does_match_definition ( type_ , cpptypes . fundamental_t , ( cpptypes . volatile_t , cpptypes . const_t ) )
returns True if type represents C ++ fundamental type
82
10
235,104
def args ( self , decl_string ) : args_begin = decl_string . find ( self . __begin ) args_end = decl_string . rfind ( self . __end ) if - 1 in ( args_begin , args_end ) or args_begin == args_end : raise RuntimeError ( "%s doesn't validate template instantiation string" % decl_string ) args_only = decl_string [ args_begin + 1 : args_end ] . strip ( ) # The list of arguments to be returned args = [ ] parentheses_blocks = [ ] prev_span = 0 if self . __begin == "<" : # In case where we are splitting template names, there # can be parentheses blocks (for arguments) that need to be taken # care of. # Build a regex matching a space (\s) # + something inside parentheses regex = re . compile ( "\\s\\(.*?\\)" ) for m in regex . finditer ( args_only ) : # Store the position and the content parentheses_blocks . append ( [ m . start ( ) - prev_span , m . group ( ) ] ) prev_span = m . end ( ) - m . start ( ) # Cleanup the args_only string by removing the parentheses and # their content. args_only = args_only . replace ( m . group ( ) , "" ) # Now we are trying to split the args_only string in multiple arguments previous_found , found = 0 , 0 while True : found = self . __find_args_separator ( args_only , previous_found ) if found == - 1 : args . append ( args_only [ previous_found : ] . strip ( ) ) # This is the last argument. Break out of the loop. break else : args . append ( args_only [ previous_found : found ] . strip ( ) ) previous_found = found + 1 # skip found separator # Get the size and position for each argument absolute_pos_list = [ ] absolute_pos = 0 for arg in args : absolute_pos += len ( arg ) absolute_pos_list . append ( absolute_pos ) for item in parentheses_blocks : # In case where there are parentheses blocks we add them back # to the right argument parentheses_block_absolute_pos = item [ 0 ] parentheses_block_string = item [ 1 ] current_arg_absolute_pos = 0 for arg_index , arg_absolute_pos in enumerate ( absolute_pos_list ) : current_arg_absolute_pos += arg_absolute_pos if current_arg_absolute_pos >= parentheses_block_absolute_pos : # Add the parentheses block back and break out of the loop. args [ arg_index ] += parentheses_block_string break return args
Extracts a list of arguments from the provided declaration string .
590
13
235,105
def has_public_binary_operator ( type_ , operator_symbol ) : type_ = type_traits . remove_alias ( type_ ) type_ = type_traits . remove_cv ( type_ ) type_ = type_traits . remove_declarated ( type_ ) assert isinstance ( type_ , class_declaration . class_t ) if type_traits . is_std_string ( type_ ) or type_traits . is_std_wstring ( type_ ) : # In some case compare operators of std::basic_string are not # instantiated return True operators = type_ . member_operators ( function = matchers . custom_matcher_t ( lambda decl : not decl . is_artificial ) & matchers . access_type_matcher_t ( 'public' ) , symbol = operator_symbol , allow_empty = True , recursive = False ) if operators : return True declarated = cpptypes . declarated_t ( type_ ) const = cpptypes . const_t ( declarated ) reference = cpptypes . reference_t ( const ) operators = type_ . top_parent . operators ( function = lambda decl : not decl . is_artificial , arg_types = [ reference , None ] , symbol = operator_symbol , allow_empty = True , recursive = True ) if operators : return True for bi in type_ . recursive_bases : assert isinstance ( bi , class_declaration . hierarchy_info_t ) if bi . access_type != class_declaration . ACCESS_TYPES . PUBLIC : continue operators = bi . related_class . member_operators ( function = matchers . custom_matcher_t ( lambda decl : not decl . is_artificial ) & matchers . access_type_matcher_t ( 'public' ) , symbol = operator_symbol , allow_empty = True , recursive = False ) if operators : return True return False
returns True if type_ has public binary operator otherwise False
432
12
235,106
def update ( self , source_file , configuration , declarations , included_files ) : # Normlize all paths... source_file = os . path . normpath ( source_file ) included_files = [ os . path . normpath ( p ) for p in included_files ] # Create the list of dependent files. This is the included_files list # + the source file. Duplicate names are removed. dependent_files = { } for name in [ source_file ] + included_files : dependent_files [ name ] = 1 key = self . _create_cache_key ( source_file ) # Remove an existing entry (if there is one) # After calling this method, it is guaranteed that __index[key] # does not exist anymore. self . _remove_entry ( source_file , key ) # Create a new entry... # Create the sigs of all dependent files... filesigs = [ ] for filename in list ( dependent_files . keys ( ) ) : id_ , sig = self . __filename_rep . acquire_filename ( filename ) filesigs . append ( ( id_ , sig ) ) configsig = self . _create_config_signature ( configuration ) entry = index_entry_t ( filesigs , configsig ) self . __index [ key ] = entry self . __modified_flag = True # Write the declarations into the cache file... cachefilename = self . _create_cache_filename ( source_file ) self . _write_file ( cachefilename , declarations )
Replace a cache entry by a new value .
325
10
235,107
def cached_value ( self , source_file , configuration ) : # Check if the cache contains an entry for source_file key = self . _create_cache_key ( source_file ) entry = self . __index . get ( key ) if entry is None : # print "CACHE: %s: Not cached"%source_file return None # Check if the entry is still valid. It is not valid if: # - the source_file has been updated # - the configuration object has changed (i.e. the header is parsed # by gccxml with different settings which may influence the # declarations) # - the included files have been updated # (this list is part of the cache entry as it cannot be known # by the caller when cached_value() is called. It was instead # passed to update()) # Check if the config is different... configsig = self . _create_config_signature ( configuration ) if configsig != entry . configsig : # print "CACHE: %s: Config mismatch"%source_file return None # Check if any of the dependent files has been modified... for id_ , sig in entry . filesigs : if self . __filename_rep . is_file_modified ( id_ , sig ) : # print "CACHE: %s: Entry not up to date"%source_file return None # Load and return the cached declarations cachefilename = self . _create_cache_filename ( source_file ) decls = self . _read_file ( cachefilename ) # print "CACHE: Using cached decls for",source_file return decls
Return the cached declarations or None .
347
7
235,108
def _load ( self ) : indexfilename = os . path . join ( self . __dir , "index.dat" ) if os . path . exists ( indexfilename ) : data = self . _read_file ( indexfilename ) self . __index = data [ 0 ] self . __filename_rep = data [ 1 ] if self . __filename_rep . _sha1_sigs != self . __sha1_sigs : print ( ( "CACHE: Warning: sha1_sigs stored in the cache is set " + "to %s." ) % self . __filename_rep . _sha1_sigs ) print ( "Please remove the cache to change this setting." ) self . __sha1_sigs = self . __filename_rep . _sha1_sigs else : self . __index = { } self . __filename_rep = filename_repository_t ( self . __sha1_sigs ) self . __modified_flag = False
Load the cache .
215
4
235,109
def _save ( self ) : if self . __modified_flag : self . __filename_rep . update_id_counter ( ) indexfilename = os . path . join ( self . __dir , "index.dat" ) self . _write_file ( indexfilename , ( self . __index , self . __filename_rep ) ) self . __modified_flag = False
save the cache index in case it was modified .
81
10
235,110
def _read_file ( self , filename ) : if self . __compression : f = gzip . GzipFile ( filename , "rb" ) else : f = open ( filename , "rb" ) res = pickle . load ( f ) f . close ( ) return res
read a Python object from a cache file .
61
9
235,111
def _write_file ( self , filename , data ) : if self . __compression : f = gzip . GzipFile ( filename , "wb" ) else : f = open ( filename , "wb" ) pickle . dump ( data , f , pickle . HIGHEST_PROTOCOL ) f . close ( )
Write a data item into a file .
72
8
235,112
def _remove_entry ( self , source_file , key ) : entry = self . __index . get ( key ) if entry is None : return # Release the referenced files... for id_ , _ in entry . filesigs : self . __filename_rep . release_filename ( id_ ) # Remove the cache entry... del self . __index [ key ] self . __modified_flag = True # Delete the corresponding cache file... cachefilename = self . _create_cache_filename ( source_file ) try : os . remove ( cachefilename ) except OSError as e : print ( "Could not remove cache file (%s)" % e )
Remove an entry from the cache .
139
7
235,113
def _create_cache_key ( source_file ) : path , name = os . path . split ( source_file ) return name + str ( hash ( path ) )
return the cache key for a header file .
37
9
235,114
def _create_cache_filename ( self , source_file ) : res = self . _create_cache_key ( source_file ) + ".cache" return os . path . join ( self . __dir , res )
return the cache file name for a header file .
48
10
235,115
def _create_config_signature ( config ) : m = hashlib . sha1 ( ) m . update ( config . working_directory . encode ( "utf-8" ) ) for p in config . include_paths : m . update ( p . encode ( "utf-8" ) ) for p in config . define_symbols : m . update ( p . encode ( "utf-8" ) ) for p in config . undefine_symbols : m . update ( p . encode ( "utf-8" ) ) for p in config . cflags : m . update ( p . encode ( "utf-8" ) ) return m . digest ( )
return the signature for a config object .
149
8
235,116
def acquire_filename ( self , name ) : id_ = self . __id_lut . get ( name ) # Is this a new entry? if id_ is None : # then create one... id_ = self . __next_id self . __next_id += 1 self . __id_lut [ name ] = id_ entry = filename_entry_t ( name ) self . __entries [ id_ ] = entry else : # otherwise obtain the entry... entry = self . __entries [ id_ ] entry . inc_ref_count ( ) return id_ , self . _get_signature ( entry )
Acquire a file name and return its id and its signature .
136
13
235,117
def release_filename ( self , id_ ) : entry = self . __entries . get ( id_ ) if entry is None : raise ValueError ( "Invalid filename id (%d)" % id_ ) # Decrease reference count and check if the entry has to be removed... if entry . dec_ref_count ( ) == 0 : del self . __entries [ id_ ] del self . __id_lut [ entry . filename ]
Release a file name .
95
5
235,118
def is_file_modified ( self , id_ , signature ) : entry = self . __entries . get ( id_ ) if entry is None : raise ValueError ( "Invalid filename id_ (%d)" % id_ ) # Is the signature already known? if entry . sig_valid : # use the cached signature filesig = entry . signature else : # compute the signature and store it filesig = self . _get_signature ( entry ) entry . signature = filesig entry . sig_valid = True return filesig != signature
Check if the file referred to by id_ has been modified .
114
13
235,119
def update_id_counter ( self ) : if not self . __entries : self . __next_id = 1 else : self . __next_id = max ( self . __entries . keys ( ) ) + 1
Update the id_ counter so that it doesn t grow forever .
49
13
235,120
def _get_signature ( self , entry ) : if self . _sha1_sigs : # return sha1 digest of the file content... if not os . path . exists ( entry . filename ) : return None try : with open ( entry . filename , "r" ) as f : data = f . read ( ) return hashlib . sha1 ( data . encode ( "utf-8" ) ) . digest ( ) except IOError as e : print ( "Cannot determine sha1 digest:" , e ) return None else : # return file modification date... try : return os . path . getmtime ( entry . filename ) except OSError : return None
Return the signature of the file stored in entry .
147
10
235,121
def is_union ( declaration ) : if not is_class ( declaration ) : return False decl = class_traits . get_declaration ( declaration ) return decl . class_type == class_declaration . CLASS_TYPES . UNION
Returns True if declaration represents a C ++ union
53
9
235,122
def is_struct ( declaration ) : if not is_class ( declaration ) : return False decl = class_traits . get_declaration ( declaration ) return decl . class_type == class_declaration . CLASS_TYPES . STRUCT
Returns True if declaration represents a C ++ struct
53
9
235,123
def find_trivial_constructor ( type_ ) : assert isinstance ( type_ , class_declaration . class_t ) trivial = type_ . constructors ( lambda x : is_trivial_constructor ( x ) , recursive = False , allow_empty = True ) if trivial : return trivial [ 0 ] return None
Returns reference to trivial constructor .
73
6
235,124
def find_copy_constructor ( type_ ) : copy_ = type_ . constructors ( lambda x : is_copy_constructor ( x ) , recursive = False , allow_empty = True ) if copy_ : return copy_ [ 0 ] return None
Returns reference to copy constructor .
56
6
235,125
def find_noncopyable_vars ( class_type , already_visited_cls_vars = None ) : assert isinstance ( class_type , class_declaration . class_t ) logger = utils . loggers . cxx_parser mvars = class_type . variables ( lambda v : not v . type_qualifiers . has_static , recursive = False , allow_empty = True ) noncopyable_vars = [ ] if already_visited_cls_vars is None : already_visited_cls_vars = [ ] message = ( "__contains_noncopyable_mem_var - %s - TRUE - " + "contains const member variable" ) for mvar in mvars : var_type = type_traits . remove_reference ( mvar . decl_type ) if type_traits . is_const ( var_type ) : no_const = type_traits . remove_const ( var_type ) if type_traits . is_fundamental ( no_const ) or is_enum ( no_const ) : logger . debug ( ( message + "- fundamental or enum" ) , var_type . decl_string ) noncopyable_vars . append ( mvar ) if is_class ( no_const ) : logger . debug ( ( message + " - class" ) , var_type . decl_string ) noncopyable_vars . append ( mvar ) if type_traits . is_array ( no_const ) : logger . debug ( ( message + " - array" ) , var_type . decl_string ) noncopyable_vars . append ( mvar ) if type_traits . is_pointer ( var_type ) : continue if class_traits . is_my_case ( var_type ) : cls = class_traits . get_declaration ( var_type ) # Exclude classes that have already been visited. if cls in already_visited_cls_vars : continue already_visited_cls_vars . append ( cls ) if is_noncopyable ( cls , already_visited_cls_vars ) : logger . debug ( ( message + " - class that is not copyable" ) , var_type . decl_string ) noncopyable_vars . append ( mvar ) logger . debug ( ( "__contains_noncopyable_mem_var - %s - FALSE - doesn't " + "contain noncopyable members" ) , class_type . decl_string ) return noncopyable_vars
Returns list of all noncopyable variables .
573
9
235,126
def has_trivial_constructor ( class_ ) : class_ = class_traits . get_declaration ( class_ ) trivial = find_trivial_constructor ( class_ ) if trivial and trivial . access_type == 'public' : return trivial
if class has public trivial constructor this function will return reference to it None otherwise
59
15
235,127
def has_copy_constructor ( class_ ) : class_ = class_traits . get_declaration ( class_ ) copy_constructor = find_copy_constructor ( class_ ) if copy_constructor and copy_constructor . access_type == 'public' : return copy_constructor
if class has public copy constructor this function will return reference to it None otherwise
67
15
235,128
def has_destructor ( class_ ) : class_ = class_traits . get_declaration ( class_ ) destructor = class_ . decls ( decl_type = calldef_members . destructor_t , recursive = False , allow_empty = True ) if destructor : return destructor [ 0 ]
if class has destructor this function will return reference to it None otherwise
70
14
235,129
def has_public_constructor ( class_ ) : class_ = class_traits . get_declaration ( class_ ) decls = class_ . constructors ( lambda c : not is_copy_constructor ( c ) and c . access_type == 'public' , recursive = False , allow_empty = True ) if decls : return decls
if class has any public constructor this function will return list of them otherwise None
78
15
235,130
def has_public_assign ( class_ ) : class_ = class_traits . get_declaration ( class_ ) decls = class_ . member_operators ( lambda o : o . symbol == '=' and o . access_type == 'public' , recursive = False , allow_empty = True ) return bool ( decls )
returns True if class has public assign operator False otherwise
75
11
235,131
def has_vtable ( decl_type ) : assert isinstance ( decl_type , class_declaration . class_t ) return bool ( decl_type . calldefs ( lambda f : isinstance ( f , calldef_members . member_function_t ) and f . virtuality != calldef_types . VIRTUALITY_TYPES . NOT_VIRTUAL , recursive = False , allow_empty = True ) )
True if class has virtual table False otherwise
98
8
235,132
def is_base_and_derived ( based , derived ) : assert isinstance ( based , class_declaration . class_t ) assert isinstance ( derived , ( class_declaration . class_t , tuple ) ) if isinstance ( derived , class_declaration . class_t ) : all_derived = ( [ derived ] ) else : # tuple all_derived = derived for derived_cls in all_derived : for base_desc in derived_cls . recursive_bases : if base_desc . related_class == based : return True return False
returns True if there is base and derived relationship between classes False otherwise
122
14
235,133
def is_noncopyable ( class_ , already_visited_cls_vars = None ) : logger = utils . loggers . cxx_parser class_decl = class_traits . get_declaration ( class_ ) true_header = "is_noncopyable(TRUE) - %s - " % class_ . decl_string if is_union ( class_ ) : return False if class_decl . is_abstract : logger . debug ( true_header + "abstract client" ) return True # if class has public, user defined copy constructor, than this class is # copyable copy_ = find_copy_constructor ( class_decl ) if copy_ and copy_ . access_type == 'public' and not copy_ . is_artificial : return False if already_visited_cls_vars is None : already_visited_cls_vars = [ ] for base_desc in class_decl . recursive_bases : assert isinstance ( base_desc , class_declaration . hierarchy_info_t ) if base_desc . related_class . decl_string in ( '::boost::noncopyable' , '::boost::noncopyable_::noncopyable' ) : logger . debug ( true_header + "derives from boost::noncopyable" ) return True if not has_copy_constructor ( base_desc . related_class ) : base_copy_ = find_copy_constructor ( base_desc . related_class ) if base_copy_ and base_copy_ . access_type == 'private' : logger . debug ( true_header + "there is private copy constructor" ) return True elif __is_noncopyable_single ( base_desc . related_class , already_visited_cls_vars ) : logger . debug ( true_header + "__is_noncopyable_single returned True" ) return True if __is_noncopyable_single ( base_desc . related_class , already_visited_cls_vars ) : logger . debug ( true_header + "__is_noncopyable_single returned True" ) return True if not has_copy_constructor ( class_decl ) : logger . debug ( true_header + "does not have trivial copy constructor" ) return True elif not has_public_constructor ( class_decl ) : logger . debug ( true_header + "does not have a public constructor" ) return True elif has_destructor ( class_decl ) and not has_public_destructor ( class_decl ) : logger . debug ( true_header + "has private destructor" ) return True return __is_noncopyable_single ( class_decl , already_visited_cls_vars )
Checks if class is non copyable
609
8
235,134
def is_unary_operator ( oper ) : # definition: # member in class # ret-type operator symbol() # ret-type operator [++ --](int) # globally # ret-type operator symbol( arg ) # ret-type operator [++ --](X&, int) symbols = [ '!' , '&' , '~' , '*' , '+' , '++' , '-' , '--' ] if not isinstance ( oper , calldef_members . operator_t ) : return False if oper . symbol not in symbols : return False if isinstance ( oper , calldef_members . member_operator_t ) : if len ( oper . arguments ) == 0 : return True elif oper . symbol in [ '++' , '--' ] and isinstance ( oper . arguments [ 0 ] . decl_type , cpptypes . int_t ) : return True return False if len ( oper . arguments ) == 1 : return True elif oper . symbol in [ '++' , '--' ] and len ( oper . arguments ) == 2 and isinstance ( oper . arguments [ 1 ] . decl_type , cpptypes . int_t ) : # may be I need to add additional check whether first argument is # reference or not? return True return False
returns True if operator is unary operator otherwise False
280
11
235,135
def is_binary_operator ( oper ) : # definition: # member in class # ret-type operator symbol(arg) # globally # ret-type operator symbol( arg1, arg2 ) symbols = [ ',' , '()' , '[]' , '!=' , '%' , '%=' , '&' , '&&' , '&=' , '*' , '*=' , '+' , '+=' , '-' , '-=' , '->' , '->*' , '/' , '/=' , '<' , '<<' , '<<=' , '<=' , '=' , '==' , '>' , '>=' , '>>' , '>>=' , '^' , '^=' , '|' , '|=' , '||' ] if not isinstance ( oper , calldef_members . operator_t ) : return False if oper . symbol not in symbols : return False if isinstance ( oper , calldef_members . member_operator_t ) : if len ( oper . arguments ) == 1 : return True return False if len ( oper . arguments ) == 2 : return True return False
returns True if operator is binary operator otherwise False
253
10
235,136
def is_copy_constructor ( constructor ) : assert isinstance ( constructor , calldef_members . constructor_t ) args = constructor . arguments parent = constructor . parent # A copy constructor has only one argument if len ( args ) != 1 : return False # We have only one argument, get it arg = args [ 0 ] if not isinstance ( arg . decl_type , cpptypes . compound_t ) : # An argument of type declarated_t (a typedef) could be passed to # the constructor; and it could be a reference. # But in c++ you can NOT write : # "typedef class MyClass { MyClass(const MyClass & arg) {} }" # If the argument is a typedef, this is not a copy constructor. # See the hierarchy of declarated_t and coumpound_t. They both # inherit from type_t but are not related so we can discriminate # between them. return False # The argument needs to be passed by reference in a copy constructor if not type_traits . is_reference ( arg . decl_type ) : return False # The argument needs to be const for a copy constructor if not type_traits . is_const ( arg . decl_type . base ) : return False un_aliased = type_traits . remove_alias ( arg . decl_type . base ) # un_aliased now refers to const_t instance if not isinstance ( un_aliased . base , cpptypes . declarated_t ) : # We are looking for a declaration # If "class MyClass { MyClass(const int & arg) {} }" is used, # this is not copy constructor, so we return False here. # -> un_aliased.base == cpptypes.int_t (!= cpptypes.declarated_t) return False # Final check: compare the parent (the class declaration for example) # with the declaration of the type passed as argument. return id ( un_aliased . base . declaration ) == id ( parent )
Check if the declaration is a copy constructor
442
8
235,137
def get_members ( self , access = None ) : if access == ACCESS_TYPES . PUBLIC : return self . public_members elif access == ACCESS_TYPES . PROTECTED : return self . protected_members elif access == ACCESS_TYPES . PRIVATE : return self . private_members all_members = [ ] all_members . extend ( self . public_members ) all_members . extend ( self . protected_members ) all_members . extend ( self . private_members ) return all_members
returns list of members according to access type
118
9
235,138
def adopt_declaration ( self , decl , access ) : if access == ACCESS_TYPES . PUBLIC : self . public_members . append ( decl ) elif access == ACCESS_TYPES . PROTECTED : self . protected_members . append ( decl ) elif access == ACCESS_TYPES . PRIVATE : self . private_members . append ( decl ) else : raise RuntimeError ( "Invalid access type: %s." % access ) decl . parent = self decl . cache . reset ( ) decl . cache . access_type = access
adds new declaration to the class
123
7
235,139
def remove_declaration ( self , decl ) : access_type = self . find_out_member_access_type ( decl ) if access_type == ACCESS_TYPES . PUBLIC : container = self . public_members elif access_type == ACCESS_TYPES . PROTECTED : container = self . protected_members else : # decl.cache.access_type == ACCESS_TYPES.PRVATE container = self . private_members del container [ container . index ( decl ) ] decl . cache . reset ( )
removes decl from members list
119
6
235,140
def find_out_member_access_type ( self , member ) : assert member . parent is self if not member . cache . access_type : if member in self . public_members : access_type = ACCESS_TYPES . PUBLIC elif member in self . protected_members : access_type = ACCESS_TYPES . PROTECTED elif member in self . private_members : access_type = ACCESS_TYPES . PRIVATE else : raise RuntimeError ( "Unable to find member within internal members list." ) member . cache . access_type = access_type return access_type else : return member . cache . access_type
returns member access type
144
5
235,141
def top_class ( self ) : curr = self parent = self . parent while isinstance ( parent , class_t ) : curr = parent parent = parent . parent return curr
reference to a parent class which contains this class and defined within a namespace
40
14
235,142
def append_value ( self , valuename , valuenum = None ) : # No number given? Then use the previous one + 1 if valuenum is None : if not self . _values : valuenum = 0 else : valuenum = self . _values [ - 1 ] [ 1 ] + 1 # Store the new value self . _values . append ( ( valuename , int ( valuenum ) ) )
Append another enumeration value to the enum .
93
10
235,143
def has_value_name ( self , name ) : for val , _ in self . _values : if val == name : return True return False
Check if this enum has a particular name among its values .
31
12
235,144
def update_unnamed_class ( decls ) : for decl in decls : if isinstance ( decl , declarations . typedef_t ) : referent = decl . decl_type if isinstance ( referent , declarations . elaborated_t ) : referent = referent . base if not isinstance ( referent , declarations . declarated_t ) : continue referent = referent . declaration if referent . name or not isinstance ( referent , declarations . class_t ) : continue referent . name = decl . name
Adds name to class_t declarations .
115
8
235,145
def get_os_file_names ( files ) : fnames = [ ] for f in files : if utils . is_str ( f ) : fnames . append ( f ) elif isinstance ( f , file_configuration_t ) : if f . content_type in ( file_configuration_t . CONTENT_TYPE . STANDARD_SOURCE_FILE , file_configuration_t . CONTENT_TYPE . CACHED_SOURCE_FILE ) : fnames . append ( f . data ) else : pass return fnames
returns file names
118
4
235,146
def read_files ( self , files , compilation_mode = COMPILATION_MODE . FILE_BY_FILE ) : if compilation_mode == COMPILATION_MODE . ALL_AT_ONCE and len ( files ) == len ( self . get_os_file_names ( files ) ) : return self . __parse_all_at_once ( files ) else : if compilation_mode == COMPILATION_MODE . ALL_AT_ONCE : msg = '' . join ( [ "Unable to parse files using ALL_AT_ONCE mode. " , "There is some file configuration that is not file. " , "pygccxml.parser.project_reader_t switches to " , "FILE_BY_FILE mode." ] ) self . logger . warning ( msg ) return self . __parse_file_by_file ( files )
parses a set of files
185
7
235,147
def read_xml ( self , file_configuration ) : xml_file_path = None delete_xml_file = True fc = file_configuration reader = source_reader . source_reader_t ( self . __config , None , self . __decl_factory ) try : if fc . content_type == fc . CONTENT_TYPE . STANDARD_SOURCE_FILE : self . logger . info ( 'Parsing source file "%s" ... ' , fc . data ) xml_file_path = reader . create_xml_file ( fc . data ) elif fc . content_type == file_configuration_t . CONTENT_TYPE . GCCXML_GENERATED_FILE : self . logger . info ( 'Parsing xml file "%s" ... ' , fc . data ) xml_file_path = fc . data delete_xml_file = False elif fc . content_type == fc . CONTENT_TYPE . CACHED_SOURCE_FILE : # TODO: raise error when header file does not exist if not os . path . exists ( fc . cached_source_file ) : dir_ = os . path . split ( fc . cached_source_file ) [ 0 ] if dir_ and not os . path . exists ( dir_ ) : os . makedirs ( dir_ ) self . logger . info ( 'Creating xml file "%s" from source file "%s" ... ' , fc . cached_source_file , fc . data ) xml_file_path = reader . create_xml_file ( fc . data , fc . cached_source_file ) else : xml_file_path = fc . cached_source_file else : xml_file_path = reader . create_xml_file_from_string ( fc . data ) with open ( xml_file_path , "r" ) as xml_file : xml = xml_file . read ( ) utils . remove_file_no_raise ( xml_file_path , self . __config ) self . __xml_generator_from_xml_file = reader . xml_generator_from_xml_file return xml finally : if xml_file_path and delete_xml_file : utils . remove_file_no_raise ( xml_file_path , self . __config )
parses C ++ code defined on the file_configurations and returns GCCXML generated file content
518
21
235,148
def get_dependencies_from_decl ( decl , recursive = True ) : result = [ ] if isinstance ( decl , typedef . typedef_t ) or isinstance ( decl , variable . variable_t ) : return [ dependency_info_t ( decl , decl . decl_type ) ] if isinstance ( decl , namespace . namespace_t ) : if recursive : for d in decl . declarations : result . extend ( get_dependencies_from_decl ( d ) ) return result if isinstance ( decl , calldef . calldef_t ) : if decl . return_type : result . append ( dependency_info_t ( decl , decl . return_type , hint = "return type" ) ) for arg in decl . arguments : result . append ( dependency_info_t ( decl , arg . decl_type ) ) for exc in decl . exceptions : result . append ( dependency_info_t ( decl , exc , hint = "exception" ) ) return result if isinstance ( decl , class_declaration . class_t ) : for base in decl . bases : result . append ( dependency_info_t ( decl , base . related_class , base . access_type , "base class" ) ) if recursive : for access_type in class_declaration . ACCESS_TYPES . ALL : result . extend ( __find_out_member_dependencies ( decl . get_members ( access_type ) , access_type ) ) return result return result
Returns the list of all types and declarations the declaration depends on .
322
13
235,149
def find_container_traits ( cls_or_string ) : if utils . is_str ( cls_or_string ) : if not templates . is_instantiation ( cls_or_string ) : return None name = templates . name ( cls_or_string ) if name . startswith ( 'std::' ) : name = name [ len ( 'std::' ) : ] if name . startswith ( 'std::tr1::' ) : name = name [ len ( 'std::tr1::' ) : ] for cls_traits in all_container_traits : if cls_traits . name ( ) == name : return cls_traits else : if isinstance ( cls_or_string , class_declaration . class_types ) : # Look in the cache. if cls_or_string . cache . container_traits is not None : return cls_or_string . cache . container_traits # Look for a container traits for cls_traits in all_container_traits : if cls_traits . is_my_case ( cls_or_string ) : # Store in the cache if isinstance ( cls_or_string , class_declaration . class_types ) : cls_or_string . cache . container_traits = cls_traits return cls_traits
Find the container traits type of a declaration .
309
9
235,150
def get_container_or_none ( self , type_ ) : type_ = type_traits . remove_alias ( type_ ) type_ = type_traits . remove_cv ( type_ ) utils . loggers . queries_engine . debug ( "Container traits: cleaned up search %s" , type_ ) if isinstance ( type_ , cpptypes . declarated_t ) : cls_declaration = type_traits . remove_alias ( type_ . declaration ) elif isinstance ( type_ , class_declaration . class_t ) : cls_declaration = type_ elif isinstance ( type_ , class_declaration . class_declaration_t ) : cls_declaration = type_ else : utils . loggers . queries_engine . debug ( "Container traits: returning None, type not known\n" ) return if not cls_declaration . name . startswith ( self . name ( ) + '<' ) : utils . loggers . queries_engine . debug ( "Container traits: returning None, " + "declaration starts with " + self . name ( ) + '<\n' ) return # When using libstd++, some container traits are defined in # std::tr1::. See remove_template_defaults_tester.py. # In this case the is_defined_in_xxx test needs to be done # on the parent decl = cls_declaration if isinstance ( type_ , class_declaration . class_declaration_t ) : is_ns = isinstance ( type_ . parent , namespace . namespace_t ) if is_ns and type_ . parent . name == "tr1" : decl = cls_declaration . parent elif isinstance ( type_ , cpptypes . declarated_t ) : is_ns = isinstance ( type_ . declaration . parent , namespace . namespace_t ) if is_ns and type_ . declaration . parent . name == "tr1" : decl = cls_declaration . parent for ns in std_namespaces : if traits_impl_details . impl_details . is_defined_in_xxx ( ns , decl ) : utils . loggers . queries_engine . debug ( "Container traits: get_container_or_none() will return " + cls_declaration . name ) # The is_defined_in_xxx check is done on decl, but we return # the original declation so that the rest of the algorithm # is able to work with it. return cls_declaration # This should not happen utils . loggers . queries_engine . debug ( "Container traits: get_container_or_none() will return None\n" )
Returns reference to the class declaration or None .
599
9
235,151
def class_declaration ( self , type_ ) : utils . loggers . queries_engine . debug ( "Container traits: searching class declaration for %s" , type_ ) cls_declaration = self . get_container_or_none ( type_ ) if not cls_declaration : raise TypeError ( 'Type "%s" is not instantiation of std::%s' % ( type_ . decl_string , self . name ( ) ) ) return cls_declaration
Returns reference to the class declaration .
107
7
235,152
def element_type ( self , type_ ) : return self . __find_xxx_type ( type_ , self . element_type_index , self . element_type_typedef , 'container_element_type' )
returns reference to the class value \\ mapped type declaration
50
11
235,153
def key_type ( self , type_ ) : if not self . is_mapping ( type_ ) : raise TypeError ( 'Type "%s" is not "mapping" container' % str ( type_ ) ) return self . __find_xxx_type ( type_ , self . key_type_index , self . key_type_typedef , 'container_key_type' )
returns reference to the class key type declaration
87
9
235,154
def remove_defaults ( self , type_or_string ) : name = type_or_string if not utils . is_str ( type_or_string ) : name = self . class_declaration ( type_or_string ) . name if not self . remove_defaults_impl : return name no_defaults = self . remove_defaults_impl ( name ) if not no_defaults : return name return no_defaults
Removes template defaults from a templated class instantiation .
98
13
235,155
def take_parenting ( self , inst ) : if self is inst : return for decl in inst . declarations : decl . parent = self self . declarations . append ( decl ) inst . declarations = [ ]
Takes parenting from inst and transfers it to self .
43
11
235,156
def remove_declaration ( self , decl ) : del self . declarations [ self . declarations . index ( decl ) ] decl . cache . reset ( )
Removes declaration from members list .
32
7
235,157
def namespace ( self , name = None , function = None , recursive = None ) : return ( self . _find_single ( scopedef . scopedef_t . _impl_matchers [ namespace_t . namespace ] , name = name , function = function , recursive = recursive ) )
Returns reference to namespace declaration that matches a defined criteria .
63
11
235,158
def namespaces ( self , name = None , function = None , recursive = None , allow_empty = None ) : return ( self . _find_multiple ( scopedef . scopedef_t . _impl_matchers [ namespace_t . namespace ] , name = name , function = function , recursive = recursive , allow_empty = allow_empty ) )
Returns a set of namespace declarations that match a defined criteria .
78
12
235,159
def free_function ( self , name = None , function = None , return_type = None , arg_types = None , header_dir = None , header_file = None , recursive = None ) : return ( self . _find_single ( scopedef . scopedef_t . _impl_matchers [ namespace_t . free_function ] , name = name , function = function , decl_type = self . _impl_decl_types [ namespace_t . free_function ] , return_type = return_type , arg_types = arg_types , header_dir = header_dir , header_file = header_file , recursive = recursive ) )
Returns reference to free function declaration that matches a defined criteria .
145
12
235,160
def free_functions ( self , name = None , function = None , return_type = None , arg_types = None , header_dir = None , header_file = None , recursive = None , allow_empty = None ) : return ( self . _find_multiple ( scopedef . scopedef_t . _impl_matchers [ namespace_t . free_function ] , name = name , function = function , decl_type = self . _impl_decl_types [ namespace_t . free_function ] , return_type = return_type , arg_types = arg_types , header_dir = header_dir , header_file = header_file , recursive = recursive , allow_empty = allow_empty ) )
Returns a set of free function declarations that match a defined criteria .
160
13
235,161
def free_operator ( self , name = None , function = None , symbol = None , return_type = None , arg_types = None , header_dir = None , header_file = None , recursive = None ) : return ( self . _find_single ( scopedef . scopedef_t . _impl_matchers [ namespace_t . free_operator ] , name = self . _build_operator_name ( name , function , symbol ) , symbol = symbol , function = self . _build_operator_function ( name , function ) , decl_type = self . _impl_decl_types [ namespace_t . free_operator ] , return_type = return_type , arg_types = arg_types , header_dir = header_dir , header_file = header_file , recursive = recursive ) )
Returns reference to free operator declaration that matches a defined criteria .
179
12
235,162
def extract ( text , default = UNKNOWN ) : if not text : return default found = CALLING_CONVENTION_TYPES . pattern . match ( text ) if found : return found . group ( 'cc' ) return default
extracts calling convention from the text . If the calling convention could not be found the default is used
50
21
235,163
def is_same_function ( f1 , f2 ) : if f1 is f2 : return True if f1 . __class__ is not f2 . __class__ : return False if isinstance ( f1 , calldef_members . member_calldef_t ) and f1 . has_const != f2 . has_const : return False if f1 . name != f2 . name : return False if not is_same_return_type ( f1 , f2 ) : return False if len ( f1 . arguments ) != len ( f2 . arguments ) : return False for f1_arg , f2_arg in zip ( f1 . arguments , f2 . arguments ) : if not type_traits . is_same ( f1_arg . decl_type , f2_arg . decl_type ) : return False return True
returns true if f1 and f2 is same function
188
12
235,164
def make_flatten ( decl_or_decls ) : def proceed_single ( decl ) : answer = [ decl ] if not isinstance ( decl , scopedef_t ) : return answer for elem in decl . declarations : if isinstance ( elem , scopedef_t ) : answer . extend ( proceed_single ( elem ) ) else : answer . append ( elem ) return answer decls = [ ] if isinstance ( decl_or_decls , list ) : decls . extend ( decl_or_decls ) else : decls . append ( decl_or_decls ) answer = [ ] for decl in decls : answer . extend ( proceed_single ( decl ) ) return answer
Converts tree representation of declarations to flatten one .
156
11
235,165
def find_all_declarations ( declarations , decl_type = None , name = None , parent = None , recursive = True , fullname = None ) : if recursive : decls = make_flatten ( declarations ) else : decls = declarations return list ( filter ( algorithm . match_declaration_t ( decl_type = decl_type , name = name , fullname = fullname , parent = parent ) , decls ) )
Returns a list of all declarations that match criteria defined by developer .
94
13
235,166
def find_declaration ( declarations , decl_type = None , name = None , parent = None , recursive = True , fullname = None ) : decl = find_all_declarations ( declarations , decl_type = decl_type , name = name , parent = parent , recursive = recursive , fullname = fullname ) if len ( decl ) == 1 : return decl [ 0 ]
Returns single declaration that match criteria defined by developer . If more the one declaration was found None will be returned .
82
22
235,167
def find_first_declaration ( declarations , decl_type = None , name = None , parent = None , recursive = True , fullname = None ) : decl_matcher = algorithm . match_declaration_t ( decl_type = decl_type , name = name , fullname = fullname , parent = parent ) if recursive : decls = make_flatten ( declarations ) else : decls = declarations for decl in decls : if decl_matcher ( decl ) : return decl return None
Returns first declaration that match criteria defined by developer .
108
10
235,168
def declaration_files ( decl_or_decls ) : files = set ( ) decls = make_flatten ( decl_or_decls ) for decl in decls : if decl . location : files . add ( decl . location . file_name ) return files
Returns set of files
58
4
235,169
def find ( decl_matcher , decls , recursive = True ) : where = [ ] if isinstance ( decls , list ) : where . extend ( decls ) else : where . append ( decls ) if recursive : where = make_flatten ( where ) return list ( filter ( decl_matcher , where ) )
Returns a list of declarations that match decl_matcher defined criteria or None
71
15
235,170
def find_single ( decl_matcher , decls , recursive = True ) : answer = matcher . find ( decl_matcher , decls , recursive ) if len ( answer ) == 1 : return answer [ 0 ]
Returns a reference to the declaration that match decl_matcher defined criteria .
48
15
235,171
def get_single ( decl_matcher , decls , recursive = True ) : answer = matcher . find ( decl_matcher , decls , recursive ) if len ( answer ) == 1 : return answer [ 0 ] elif not answer : raise runtime_errors . declaration_not_found_t ( decl_matcher ) else : raise runtime_errors . multiple_declarations_found_t ( decl_matcher )
Returns a reference to declaration that match decl_matcher defined criteria .
92
14
235,172
def clear_optimizer ( self ) : self . _optimized = False self . _type2decls = { } self . _type2name2decls = { } self . _type2decls_nr = { } self . _type2name2decls_nr = { } self . _all_decls = None self . _all_decls_not_recursive = None for decl in self . declarations : if isinstance ( decl , scopedef_t ) : decl . clear_optimizer ( )
Cleans query optimizer state
115
6
235,173
def init_optimizer ( self ) : if self . name == '::' : self . _logger . debug ( "preparing data structures for query optimizer - started" ) start_time = timeit . default_timer ( ) self . clear_optimizer ( ) for dtype in scopedef_t . _impl_all_decl_types : self . _type2decls [ dtype ] = [ ] self . _type2decls_nr [ dtype ] = [ ] self . _type2name2decls [ dtype ] = { } self . _type2name2decls_nr [ dtype ] = { } self . _all_decls_not_recursive = self . declarations self . _all_decls = make_flatten ( self . _all_decls_not_recursive ) for decl in self . _all_decls : types = self . __decl_types ( decl ) for type_ in types : self . _type2decls [ type_ ] . append ( decl ) name2decls = self . _type2name2decls [ type_ ] if decl . name not in name2decls : name2decls [ decl . name ] = [ ] name2decls [ decl . name ] . append ( decl ) if self is decl . parent : self . _type2decls_nr [ type_ ] . append ( decl ) name2decls_nr = self . _type2name2decls_nr [ type_ ] if decl . name not in name2decls_nr : name2decls_nr [ decl . name ] = [ ] name2decls_nr [ decl . name ] . append ( decl ) for decl in self . _all_decls_not_recursive : if isinstance ( decl , scopedef_t ) : decl . init_optimizer ( ) if self . name == '::' : self . _logger . debug ( ( "preparing data structures for query optimizer - " + "done( %f seconds ). " ) , ( timeit . default_timer ( ) - start_time ) ) self . _optimized = True
Initializes query optimizer state .
472
7
235,174
def decls ( self , name = None , function = None , decl_type = None , header_dir = None , header_file = None , recursive = None , allow_empty = None ) : return ( self . _find_multiple ( self . _impl_matchers [ scopedef_t . decl ] , name = name , function = function , decl_type = decl_type , header_dir = header_dir , header_file = header_file , recursive = recursive , allow_empty = allow_empty ) )
returns a set of declarations that are matched defined criteria
114
11
235,175
def classes ( self , name = None , function = None , header_dir = None , header_file = None , recursive = None , allow_empty = None ) : return ( self . _find_multiple ( self . _impl_matchers [ scopedef_t . class_ ] , name = name , function = function , decl_type = self . _impl_decl_types [ scopedef_t . class_ ] , header_dir = header_dir , header_file = header_file , recursive = recursive , allow_empty = allow_empty ) )
returns a set of class declarations that are matched defined criteria
123
12
235,176
def variable ( self , name = None , function = None , decl_type = None , header_dir = None , header_file = None , recursive = None ) : return ( self . _find_single ( self . _impl_matchers [ scopedef_t . variable ] , name = name , function = function , decl_type = decl_type , header_dir = header_dir , header_file = header_file , recursive = recursive ) )
returns reference to variable declaration that is matched defined criteria
99
11
235,177
def variables ( self , name = None , function = None , decl_type = None , header_dir = None , header_file = None , recursive = None , allow_empty = None ) : return ( self . _find_multiple ( self . _impl_matchers [ scopedef_t . variable ] , name = name , function = function , decl_type = decl_type , header_dir = header_dir , header_file = header_file , recursive = recursive , allow_empty = allow_empty ) )
returns a set of variable declarations that are matched defined criteria
113
12
235,178
def member_functions ( self , name = None , function = None , return_type = None , arg_types = None , header_dir = None , header_file = None , recursive = None , allow_empty = None ) : return ( self . _find_multiple ( self . _impl_matchers [ scopedef_t . member_function ] , name = name , function = function , decl_type = self . _impl_decl_types [ scopedef_t . member_function ] , return_type = return_type , arg_types = arg_types , header_dir = header_dir , header_file = header_file , recursive = recursive , allow_empty = allow_empty ) )
returns a set of member function declarations that are matched defined criteria
156
13
235,179
def constructor ( self , name = None , function = None , return_type = None , arg_types = None , header_dir = None , header_file = None , recursive = None ) : return ( self . _find_single ( self . _impl_matchers [ scopedef_t . constructor ] , name = name , function = function , decl_type = self . _impl_decl_types [ scopedef_t . constructor ] , return_type = return_type , arg_types = arg_types , header_dir = header_dir , header_file = header_file , recursive = recursive ) )
returns reference to constructor declaration that is matched defined criteria
135
11
235,180
def constructors ( self , name = None , function = None , return_type = None , arg_types = None , header_dir = None , header_file = None , recursive = None , allow_empty = None ) : return ( self . _find_multiple ( self . _impl_matchers [ scopedef_t . constructor ] , name = name , function = function , decl_type = self . _impl_decl_types [ scopedef_t . constructor ] , return_type = return_type , arg_types = arg_types , header_dir = header_dir , header_file = header_file , recursive = recursive , allow_empty = allow_empty ) )
returns a set of constructor declarations that are matched defined criteria
150
12
235,181
def casting_operators ( self , name = None , function = None , return_type = None , arg_types = None , header_dir = None , header_file = None , recursive = None , allow_empty = None ) : return ( self . _find_multiple ( self . _impl_matchers [ scopedef_t . casting_operator ] , name = name , function = function , decl_type = self . _impl_decl_types [ scopedef_t . casting_operator ] , return_type = return_type , arg_types = arg_types , header_dir = header_dir , header_file = header_file , recursive = recursive , allow_empty = allow_empty ) )
returns a set of casting operator declarations that are matched defined criteria
156
13
235,182
def enumerations ( self , name = None , function = None , header_dir = None , header_file = None , recursive = None , allow_empty = None ) : return ( self . _find_multiple ( self . _impl_matchers [ scopedef_t . enumeration ] , name = name , function = function , decl_type = self . _impl_decl_types [ scopedef_t . enumeration ] , header_dir = header_dir , header_file = header_file , recursive = recursive , allow_empty = allow_empty ) )
returns a set of enumeration declarations that are matched defined criteria
124
13
235,183
def typedef ( self , name = None , function = None , header_dir = None , header_file = None , recursive = None ) : return ( self . _find_single ( self . _impl_matchers [ scopedef_t . typedef ] , name = name , function = function , decl_type = self . _impl_decl_types [ scopedef_t . typedef ] , header_dir = header_dir , header_file = header_file , recursive = recursive ) )
returns reference to typedef declaration that is matched defined criteria
110
12
235,184
def typedefs ( self , name = None , function = None , header_dir = None , header_file = None , recursive = None , allow_empty = None ) : return ( self . _find_multiple ( self . _impl_matchers [ scopedef_t . typedef ] , name = name , function = function , decl_type = self . _impl_decl_types [ scopedef_t . typedef ] , header_dir = header_dir , header_file = header_file , recursive = recursive , allow_empty = allow_empty ) )
returns a set of typedef declarations that are matched defined criteria
125
13
235,185
def load_xml_generator_configuration ( configuration , * * defaults ) : parser = configuration if utils . is_str ( configuration ) : parser = ConfigParser ( ) parser . read ( configuration ) # Create a new empty configuration cfg = xml_generator_configuration_t ( ) values = defaults if not values : values = { } if parser . has_section ( 'xml_generator' ) : for name , value in parser . items ( 'xml_generator' ) : if value . strip ( ) : values [ name ] = value for name , value in values . items ( ) : if isinstance ( value , str ) : value = value . strip ( ) if name == 'gccxml_path' : cfg . gccxml_path = value if name == 'xml_generator_path' : cfg . xml_generator_path = value elif name == 'working_directory' : cfg . working_directory = value elif name == 'include_paths' : for p in value . split ( ';' ) : p = p . strip ( ) if p : cfg . include_paths . append ( os . path . normpath ( p ) ) elif name == 'compiler' : cfg . compiler = value elif name == 'xml_generator' : cfg . xml_generator = value elif name == 'castxml_epic_version' : cfg . castxml_epic_version = int ( value ) elif name == 'keep_xml' : cfg . keep_xml = value elif name == 'cflags' : cfg . cflags = value elif name == 'flags' : cfg . flags = value elif name == 'compiler_path' : cfg . compiler_path = value else : print ( '\n%s entry was ignored' % name ) # If no compiler path was set and we are using castxml, set the path # Here we overwrite the default configuration done in the cfg because # the xml_generator was set through the setter after the creation of a new # emppty configuration object. cfg . compiler_path = create_compiler_path ( cfg . xml_generator , cfg . compiler_path ) return cfg
Loads CastXML or GCC - XML configuration .
495
11
235,186
def create_compiler_path ( xml_generator , compiler_path ) : if xml_generator == 'castxml' and compiler_path is None : if platform . system ( ) == 'Windows' : # Look for msvc p = subprocess . Popen ( [ 'where' , 'cl' ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) compiler_path = p . stdout . read ( ) . decode ( "utf-8" ) . rstrip ( ) p . wait ( ) p . stdout . close ( ) p . stderr . close ( ) # No msvc found; look for mingw if compiler_path == '' : p = subprocess . Popen ( [ 'where' , 'mingw' ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) compiler_path = p . stdout . read ( ) . decode ( "utf-8" ) . rstrip ( ) p . wait ( ) p . stdout . close ( ) p . stderr . close ( ) else : # OS X or Linux # Look for clang first, then gcc p = subprocess . Popen ( [ 'which' , 'clang++' ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) compiler_path = p . stdout . read ( ) . decode ( "utf-8" ) . rstrip ( ) p . wait ( ) p . stdout . close ( ) p . stderr . close ( ) # No clang found; use gcc if compiler_path == '' : p = subprocess . Popen ( [ 'which' , 'c++' ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) compiler_path = p . stdout . read ( ) . decode ( "utf-8" ) . rstrip ( ) p . wait ( ) p . stdout . close ( ) p . stderr . close ( ) if compiler_path == "" : compiler_path = None return compiler_path
Try to guess a path for the compiler .
467
9
235,187
def raise_on_wrong_settings ( self ) : self . __ensure_dir_exists ( self . working_directory , 'working directory' ) for idir in self . include_paths : self . __ensure_dir_exists ( idir , 'include directory' ) if self . __xml_generator not in [ "castxml" , "gccxml" ] : msg = ( 'xml_generator("%s") should either be ' + '"castxml" or "gccxml".' ) % self . xml_generator raise RuntimeError ( msg )
Validates the configuration settings and raises RuntimeError on error
130
11
235,188
def declaration_path ( decl ) : if not decl : return [ ] if not decl . cache . declaration_path : result = [ decl . name ] parent = decl . parent while parent : if parent . cache . declaration_path : result . reverse ( ) decl . cache . declaration_path = parent . cache . declaration_path + result return decl . cache . declaration_path else : result . append ( parent . name ) parent = parent . parent result . reverse ( ) decl . cache . declaration_path = result return result return decl . cache . declaration_path
Returns a list of parent declarations names .
118
8
235,189
def partial_declaration_path ( decl ) : # TODO: # If parent declaration cache already has declaration_path, reuse it for # calculation. if not decl : return [ ] if not decl . cache . partial_declaration_path : result = [ decl . partial_name ] parent = decl . parent while parent : if parent . cache . partial_declaration_path : result . reverse ( ) decl . cache . partial_declaration_path = parent . cache . partial_declaration_path + result return decl . cache . partial_declaration_path else : result . append ( parent . partial_name ) parent = parent . parent result . reverse ( ) decl . cache . partial_declaration_path = result return result return decl . cache . partial_declaration_path
Returns a list of parent declarations names without template arguments that have default value .
167
15
235,190
def full_name ( decl , with_defaults = True ) : if None is decl : raise RuntimeError ( "Unable to generate full name for None object!" ) if with_defaults : if not decl . cache . full_name : path = declaration_path ( decl ) if path == [ "" ] : # Declarations without names are allowed (for examples class # or struct instances). In this case set an empty name.. decl . cache . full_name = "" else : decl . cache . full_name = full_name_from_declaration_path ( path ) return decl . cache . full_name else : if not decl . cache . full_partial_name : path = partial_declaration_path ( decl ) if path == [ "" ] : # Declarations without names are allowed (for examples class # or struct instances). In this case set an empty name. decl . cache . full_partial_name = "" else : decl . cache . full_partial_name = full_name_from_declaration_path ( path ) return decl . cache . full_partial_name
Returns declaration full qualified name .
233
6
235,191
def get_named_parent ( decl ) : if not decl : return None parent = decl . parent while parent and ( not parent . name or parent . name == '::' ) : parent = parent . parent return parent
Returns a reference to a named parent declaration .
46
9
235,192
def print_declarations ( decls , detailed = True , recursive = True , writer = lambda x : sys . stdout . write ( x + os . linesep ) , verbose = True ) : prn = decl_printer_t ( 0 , detailed , recursive , writer , verbose = verbose ) if not isinstance ( decls , list ) : decls = [ decls ] for d in decls : prn . level = 0 prn . instance = d algorithm . apply_visitor ( prn , d )
print declarations tree rooted at each of the included nodes .
115
11
235,193
def dump_declarations ( declarations , file_path ) : with open ( file_path , "w+" ) as f : print_declarations ( declarations , writer = f . write )
Dump declarations tree rooted at each of the included nodes to the file
41
14
235,194
def __add_symbols ( self , cmd ) : if self . __config . define_symbols : symbols = self . __config . define_symbols cmd . append ( '' . join ( [ ' -D"%s"' % def_symbol for def_symbol in symbols ] ) ) if self . __config . undefine_symbols : un_symbols = self . __config . undefine_symbols cmd . append ( '' . join ( [ ' -U"%s"' % undef_symbol for undef_symbol in un_symbols ] ) ) return cmd
Add all additional defined and undefined symbols .
139
8
235,195
def create_xml_file ( self , source_file , destination = None ) : xml_file = destination # If file specified, remove it to start else create new file name if xml_file : utils . remove_file_no_raise ( xml_file , self . __config ) else : xml_file = utils . create_temp_file_name ( suffix = '.xml' ) ffname = source_file if not os . path . isabs ( ffname ) : ffname = self . __file_full_name ( source_file ) command_line = self . __create_command_line ( ffname , xml_file ) process = subprocess . Popen ( args = command_line , shell = True , stdout = subprocess . PIPE ) try : results = [ ] while process . poll ( ) is None : line = process . stdout . readline ( ) if line . strip ( ) : results . append ( line . rstrip ( ) ) for line in process . stdout . readlines ( ) : if line . strip ( ) : results . append ( line . rstrip ( ) ) exit_status = process . returncode msg = os . linesep . join ( [ str ( s ) for s in results ] ) if self . __config . ignore_gccxml_output : if not os . path . isfile ( xml_file ) : raise RuntimeError ( "Error occurred while running " + self . __config . xml_generator . upper ( ) + ": %s status:%s" % ( msg , exit_status ) ) else : if msg or exit_status or not os . path . isfile ( xml_file ) : if not os . path . isfile ( xml_file ) : raise RuntimeError ( "Error occurred while running " + self . __config . xml_generator . upper ( ) + " xml file does not exist" ) else : raise RuntimeError ( "Error occurred while running " + self . __config . xml_generator . upper ( ) + ": %s status:%s" % ( msg , exit_status ) ) except Exception : utils . remove_file_no_raise ( xml_file , self . __config ) raise finally : process . wait ( ) process . stdout . close ( ) return xml_file
This method will generate a xml file using an external tool .
499
12
235,196
def create_xml_file_from_string ( self , content , destination = None ) : header_file = utils . create_temp_file_name ( suffix = '.h' ) try : with open ( header_file , "w+" ) as header : header . write ( content ) xml_file = self . create_xml_file ( header_file , destination ) finally : utils . remove_file_no_raise ( header_file , self . __config ) return xml_file
Creates XML file from text .
108
7
235,197
def read_cpp_source_file ( self , source_file ) : xml_file = '' try : ffname = self . __file_full_name ( source_file ) self . logger . debug ( "Reading source file: [%s]." , ffname ) decls = self . __dcache . cached_value ( ffname , self . __config ) if not decls : self . logger . debug ( "File has not been found in cache, parsing..." ) xml_file = self . create_xml_file ( ffname ) decls , files = self . __parse_xml_file ( xml_file ) self . __dcache . update ( ffname , self . __config , decls , files ) else : self . logger . debug ( ( "File has not been changed, reading declarations " + "from cache." ) ) except Exception : if xml_file : utils . remove_file_no_raise ( xml_file , self . __config ) raise if xml_file : utils . remove_file_no_raise ( xml_file , self . __config ) return decls
Reads C ++ source file and returns declarations tree
239
10
235,198
def read_xml_file ( self , xml_file ) : assert self . __config is not None ffname = self . __file_full_name ( xml_file ) self . logger . debug ( "Reading xml file: [%s]" , xml_file ) decls = self . __dcache . cached_value ( ffname , self . __config ) if not decls : self . logger . debug ( "File has not been found in cache, parsing..." ) decls , _ = self . __parse_xml_file ( ffname ) self . __dcache . update ( ffname , self . __config , decls , [ ] ) else : self . logger . debug ( "File has not been changed, reading declarations from cache." ) return decls
Read generated XML file .
165
5
235,199
def read_string ( self , content ) : header_file = utils . create_temp_file_name ( suffix = '.h' ) with open ( header_file , "w+" ) as f : f . write ( content ) try : decls = self . read_file ( header_file ) except Exception : utils . remove_file_no_raise ( header_file , self . __config ) raise utils . remove_file_no_raise ( header_file , self . __config ) return decls
Reads a Python string that contains C ++ code and return the declarations tree .
114
16