This file is indexed.

/usr/lib/python3/dist-packages/pygccxml/declarations/declarations_matchers.py is in python3-pygccxml 1.8.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# Copyright 2014-2016 Insight Software Consortium.
# Copyright 2004-2008 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

import os
import warnings

from . import templates
from . import declaration_utils
from . import matcher_base_t
from . import variable
from . import cpptypes
from . import namespace
from . import calldef
from . import calldef_members
from .. import utils


class declaration_matcher_t(matcher_base_t):

    """
    Instance of this class will match declarations by next criteria:
          - declaration name, also could be fully qualified name
            Example: `wstring` or `::std::wstring`
          - declaration type
            Example: :class:`class_t`, :class:`namespace_t`,
            :class:`enumeration_t`
          - location within file system ( file or directory )
    """

    def __init__(
            self,
            name=None,
            decl_type=None,
            header_dir=None,
            header_file=None):
        """
        :param decl_type: declaration type to match by. For example
        :class:`enumeration_t`.
        :type decl_type: any class that derives from :class:`declaration_t`
        class

        :param name: declaration name, could be full name.
        :type name: str

        :param header_dir: absolute directory path
        :type header_dir: str

        :param header_file: absolute file path
        :type header_file: str

        """
        # An other option is that pygccxml will create absolute path using
        # os.path.abspath function. But I think this is just wrong, because
        # abspath builds path using current working directory. This behavior
        # is fragile and very difficult to find a bug.
        matcher_base_t.__init__(self)
        self.decl_type = decl_type
        self.__name = None
        self.__opt_is_tmpl_inst = None
        self.__opt_tmpl_name = None
        self.__opt_is_full_name = None
        self.__decl_name_only = None

        # Set the name through the setter.
        self.name = name

        self.header_dir = header_dir
        self.header_file = header_file

        if self.header_dir:
            self.header_dir = utils.normalize_path(self.header_dir)
            if not os.path.isabs(self.header_dir):
                raise RuntimeError(
                    "Path to header directory should be absolute!")

        if self.header_file:
            self.header_file = utils.normalize_path(self.header_file)
            if not os.path.isabs(self.header_file):
                raise RuntimeError("Path to header file should be absolute!")

    @property
    def name(self):
        return self.__name

    @name.setter
    def name(self, name):
        self.__name = name
        if not self.__name:
            self.__opt_is_tmpl_inst = None
            self.__opt_tmpl_name = None
            self.__opt_is_full_name = None
            self.__decl_name_only = None
        else:
            self.__opt_is_tmpl_inst = templates.is_instantiation(self.__name)
            self.__opt_tmpl_name = templates.name(self.__name)
            if self.__opt_is_tmpl_inst:
                if '::' in self.__opt_tmpl_name:
                    self.__opt_is_full_name = True
                    self.__decl_name_only = \
                        self.__opt_tmpl_name.split('::')[-1]
                else:
                    self.__opt_is_full_name = False
                    self.__decl_name_only = self.__opt_tmpl_name
                self.__name = templates.normalize(name)
            else:
                if '::' in self.__name:
                    self.__opt_is_full_name = True
                    self.__decl_name_only = self.__name.split('::')[-1]
                else:
                    self.__opt_is_full_name = False
                    self.__decl_name_only = self.__name

    def __str__(self):
        msg = []
        if self.decl_type is not None:
            msg.append('(decl type==%s)' % self.decl_type.__name__)
        if self.name is not None:
            msg.append('(name==%s)' % self.name)
        if self.header_dir is not None:
            msg.append('(header dir==%s)' % self.header_dir)
        if self.header_file is not None:
            msg.append('(header file==%s)' % self.header_file)
        if not msg:
            msg.append('any')
        return ' and '.join(msg)

    def __call__(self, decl):
        if self.decl_type is not None:
            if not isinstance(decl, self.decl_type):
                return False
        if self.name is not None:
            if not self.check_name(decl):
                return False
        if self.header_dir is not None:
            if decl.location:
                decl_dir = os.path.abspath(
                    os.path.dirname(decl.location.file_name))
                decl_dir = utils.normalize_path(decl_dir)
                if decl_dir[:len(self.header_dir)] != self.header_dir:
                    return False
            else:
                return False
        if self.header_file is not None:
            if decl.location:
                decl_file = os.path.abspath(decl.location.file_name)
                decl_file = utils.normalize_path(decl_file)
                if decl_file != self.header_file:
                    return False
            else:
                return False
        return True

    def check_name(self, decl):
        assert self.name is not None
        if self.__opt_is_tmpl_inst:
            if not self.__opt_is_full_name:
                if self.name != templates.normalize_name(decl) \
                   and self.name != templates.normalize_partial_name(decl):
                    return False
            else:
                if self.name != templates.normalize_full_name_true(decl) and \
                        self.name != templates.normalize_full_name_false(decl):
                    return False
        else:
            if not self.__opt_is_full_name:
                if self.name != decl.name and self.name != decl.partial_name:
                    return False
            else:
                if self.name != templates.normalize_full_name_true(decl) and \
                        self.name != templates.normalize_full_name_false(decl):
                    return False
        return True

    def is_full_name(self):
        return self.__opt_is_full_name

    @property
    def decl_name_only(self):
        return self.__decl_name_only


class variable_matcher_t(declaration_matcher_t):

    """
    Instance of this class will match variables by next criteria:
        - :class:`declaration_matcher_t` criteria
        - variable type. Example: :class:`int_t` or 'int'
    """

    def __init__(
            self,
            name=None,
            type=None,
            decl_type=None,
            header_dir=None,
            header_file=None):
        """
        :param decl_type: variable type
        :type decl_type: string or instance of :class:`type_t` derived class
        """

        if type is not None:
            # Deprecated since 1.8.0. Will be removed in 1.9.0
            warnings.warn(
                "The type argument is deprecated. \n" +
                "Please use the decl_type argument instead.",
                DeprecationWarning)
            if decl_type is not None:
                raise (
                    "Please use only either the type or " +
                    "decl_type argument.")
            # Still allow to use the old type for the moment.
            decl_type = type

        declaration_matcher_t.__init__(
            self,
            name=name,
            decl_type=variable.variable_t,
            header_dir=header_dir,
            header_file=header_file)
        self._decl_type = decl_type

    def __call__(self, decl):
        if not super(variable_matcher_t, self).__call__(decl):
            return False
        if self._decl_type is not None:
            if isinstance(self._decl_type, cpptypes.type_t):
                if self._decl_type != decl.decl_type:
                    return False
            else:
                if self._decl_type != decl.decl_type.decl_string:
                    return False
        return True

    def __str__(self):
        msg = [super(variable_matcher_t, self).__str__()]
        if msg == ['any']:
            msg = []
        if self._decl_type is not None:
            msg.append('(value type==%s)' % str(self._decl_type))
        if not msg:
            msg.append('any')
        return ' and '.join(msg)


class namespace_matcher_t(declaration_matcher_t):

    """Instance of this class will match namespaces by name."""

    def __init__(self, name=None):
        declaration_matcher_t.__init__(
            self,
            name=name,
            decl_type=namespace.namespace_t)

    def __call__(self, decl):
        if self.name and decl.name == '':
            # unnamed namespace have same name as thier parent, we should
            # prevent this happens. The price is: user should search for
            # unnamed namespace directly.
            return False
        return super(namespace_matcher_t, self).__call__(decl)


class calldef_matcher_t(declaration_matcher_t):

    """
    Instance of this class will match callable by the following criteria:
       * :class:`declaration_matcher_t` criteria
       * return type. For example: :class:`int_t` or 'int'
       * argument types

    """

    def __init__(
            self,
            name=None,
            return_type=None,
            arg_types=None,
            decl_type=None,
            header_dir=None,
            header_file=None):
        """
        :param return_type: callable return type
        :type return_type: string or instance of :class:`type_t` derived class

        :type arg_types: list
        :param arg_types: list of function argument types. `arg_types` can
                          contain.
                          Any item within the list could be string or instance
                          of :class:`type_t` derived class. If you don't want
                          some argument to participate in match you can put
                          None.

        For example:

          .. code-block:: python

             calldef_matcher_t( arg_types=[ 'int &', None ] )

        will match all functions that takes 2 arguments, where the first one is
        reference to integer and second any
        """
        if None is decl_type:
            decl_type = calldef.calldef_t
        declaration_matcher_t.__init__(
            self,
            name=name,
            decl_type=decl_type,
            header_dir=header_dir,
            header_file=header_file)

        self.return_type = return_type
        self.arg_types = arg_types

    def __call__(self, decl):
        if not super(calldef_matcher_t, self).__call__(decl):
            return False
        if self.return_type is not None \
           and not self.__compare_types(self.return_type, decl.return_type):
            return False
        if self.arg_types:
            if isinstance(self.arg_types, (list, tuple)):
                if len(self.arg_types) != len(decl.arguments):
                    return False
                for type_or_str, arg in zip(self.arg_types, decl.arguments):
                    if type_or_str is None:
                        continue
                    else:
                        if not self.__compare_types(
                                type_or_str, arg.decl_type):
                            return False
        return True

    def __compare_types(self, type_or_str, type):
        assert type_or_str
        if type is None:
            return False
        if isinstance(type_or_str, cpptypes.type_t):
            if type_or_str != type:
                return False
        else:
            if type_or_str != type.decl_string:
                return False
        return True

    def __str__(self):
        msg = [super(calldef_matcher_t, self).__str__()]
        if msg == ['any']:
            msg = []
        if self.return_type is not None:
            msg.append('(return type==%s)' % str(self.return_type))
        if self.arg_types:
            for i, arg_type in enumerate(self.arg_types):
                if arg_type is None:
                    msg.append('(arg %d type==any)' % i)
                else:
                    msg.append('(arg %d type==%s)' % (i, str(arg_type)))
        if not msg:
            msg.append('any')
        return ' and '.join(msg)


class operator_matcher_t(calldef_matcher_t):

    """
    Instance of this class will match operators by next criteria:
        * :class:`calldef_matcher_t` criteria
        * operator symbol: =, !=, (), [] and etc
    """

    def __init__(
            self,
            name=None,
            symbol=None,
            return_type=None,
            arg_types=None,
            decl_type=None,
            header_dir=None,
            header_file=None):
        """
        :param symbol: operator symbol
        :type symbol: str
        """
        if None is decl_type:
            decl_type = calldef_members.operator_t
        calldef_matcher_t.__init__(
            self,
            name=name,
            return_type=return_type,
            arg_types=arg_types,
            decl_type=decl_type,
            header_dir=header_dir,
            header_file=header_file)
        self.symbol = symbol

    def __call__(self, decl):
        if not super(operator_matcher_t, self).__call__(decl):
            return False
        if self.symbol is not None:
            if self.symbol != decl.symbol:
                return False
        return True

    def __str__(self):
        msg = [super(operator_matcher_t, self).__str__()]
        if msg == ['any']:
            msg = []
        if self.symbol is not None:
            msg.append('(symbol==%s)' % str(self.symbol))
        if not msg:
            msg.append('any')
        return ' and '.join(msg)