1
2
3
4
5
6 import os
7 import time
8 import types
9 import source_reader
10 import declarations_cache
11 import pygccxml.declarations
12 from pygccxml import utils
17
20 """
21 file_configuration_t - a class, that contains some data and description how
22 to treat the data. file_configuration_t can contain reference to the next types
23 of data:
24
25 1) path to C++ source file
26
27 2) path to `GCC-XML`_ generated XML file
28
29 3) path to C++ source file and path to `GCC-XML`_ generated XML file
30
31 In this case, if XML file does not exists, it will be created. Next time
32 you will ask to parse the source file, the XML file will be used instead.
33
34 Small tip: you can setup your makefile to delete XML files every time,
35 the relevant source file has changed.
36
37 4) Python string, that contains valid C++ code
38
39
40 There are few functions, that will help you to construct file_configuration_t
41 object:
42
43 * L{create_source_fc}
44
45 * L{create_gccxml_fc}
46
47 * L{create_cached_source_fc}
48
49 * L{create_text_fc}
50
51 """
53 STANDARD_SOURCE_FILE = 'standard source file'
54 CACHED_SOURCE_FILE = 'cached source file'
55 GCCXML_GENERATED_FILE = 'gccxml generated file'
56 TEXT = 'text'
57
73
74 @property
77
78 @property
80 return self.__start_with_declarations
81
82 @property
83 - def content_type(self):
84 return self.__content_type
85
86 @property
88 return self.__cached_source_file
89
90 -def create_text_fc( text ):
91 """
92 Creates L{file_configuration_t} instance, configured to contain Python string,
93 that contains valid C++ code
94
95 @param text: C++ code
96 @type text: str
97
98 @return: L{file_configuration_t}
99 """
100 return file_configuration_t( data=text
101 , content_type=file_configuration_t.CONTENT_TYPE.TEXT )
102
115
128
130 """
131 Creates L{file_configuration_t} instance, configured to contain path to
132 GCC-XML generated XML file and C++ source file. If XML file does not exists,
133 it will be created and used for parsing. If XML file exists, it will be used
134 for parsing.
135
136 @param header: path to C++ source file
137 @type header: str
138
139 @param cached_source_file: path to GCC-XML generated XML file
140 @type cached_source_file: str
141
142 @return: L{file_configuration_t}
143 """
144 return file_configuration_t( data=header
145 , cached_source_file=cached_source_file
146 , content_type=file_configuration_t.CONTENT_TYPE.CACHED_SOURCE_FILE )
147
149 """Parses header files and returns the contained declarations.
150 """
151 - def __init__( self, config, cache=None, decl_factory=None):
152 """Constructor.
153
154 config is a configuration object that contains the parameters
155 for invoking gccxml. cache specifies the cache to use for
156 caching declarations between separate runs. By default, no
157 cache is used. decl_factory is an object that must provide
158 the same interface than
159 L{decl_factory_t<declarations.decl_factory_t>}, i.e. there must
160 be a set of C{create_*} methods that return an instance of an
161 appropriate declaration class. By default, the declaration
162 classes defined in the L{declarations} package are used.
163
164 @param config: Configuration object
165 @type config: L{config_t}
166 @param cache: Declaration cache (None=no cache)
167 @type cache: L{cache_base_t} or str
168 @param decl_factory: Custom declaration factory object or None
169 @type decl_factory: decl_factory_t
170 """
171 self.__config = config
172 self.__dcache = None
173 if isinstance( cache, declarations_cache.cache_base_t ):
174 self.__dcache = cache
175 elif isinstance( cache, types.StringTypes ):
176 self.__dcache = declarations_cache.file_cache_t(cache)
177 else:
178 self.__dcache = declarations_cache.dummy_cache_t()
179 self.__decl_factory = decl_factory
180 if not decl_factory:
181 self.__decl_factory = pygccxml.declarations.decl_factory_t()
182
183 self.logger = utils.loggers.gccxml
184
185 @staticmethod