/usr/lib/python2.7/dist-packages/pygccxml/declarations/matchers.py is in python-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 | # 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
"""
defines all "built-in" classes that implement declarations compare
functionality according to some criteria
"""
import re
from . import class_declaration
class matcher_base_t(object):
"""matcher_base_t class defines interface for classes that will implement
compare functionality according to some criteria.
"""
def __init__(self):
object.__init__(self)
def __call__(self, decl):
raise NotImplementedError(
"matcher must always implement the __call__() method.")
def __invert__(self):
"""not-operator (~)"""
return not_matcher_t(self)
def __and__(self, other):
"""and-operator (&)"""
return and_matcher_t([self, other])
def __or__(self, other):
"""or-operator (|)"""
return or_matcher_t([self, other])
def __str__(self):
return "base class for all matchers"
class and_matcher_t(matcher_base_t):
"""
Combine several other matchers with "&" (and) operator.
For example: find all private functions with name XXX
.. code-block:: python
matcher = access_type_matcher_t( 'private' ) & \
calldef_matcher_t( name='XXX' )
"""
def __init__(self, matchers):
matcher_base_t.__init__(self)
self.matchers = matchers
def __call__(self, decl):
for matcher in self.matchers:
if not matcher(decl):
return False
return True
def __str__(self):
return " & ".join(["(%s)" % str(x) for x in self.matchers])
class or_matcher_t(matcher_base_t):
"""Combine several other matchers with "|" (or) operator.
For example: find all functions and variables with name 'XXX'
.. code-block:: python
matcher = variable_matcher_t( name='XXX' ) | \
calldef_matcher_t( name='XXX' )
"""
def __init__(self, matchers):
matcher_base_t.__init__(self)
self.matchers = matchers
def __call__(self, decl):
for matcher in self.matchers:
if matcher(decl):
return True
return False
def __str__(self):
return " | ".join(["(%s)" % str(x) for x in self.matchers])
class not_matcher_t(matcher_base_t):
"""
return the inverse result of a matcher
For example: find all public and protected declarations
.. code-block:: python
matcher = ~access_type_matcher_t( 'private' )
"""
def __init__(self, matcher):
matcher_base_t.__init__(self)
self.matcher = matcher
def __call__(self, decl):
return not self.matcher(decl)
def __str__(self):
return "~(%s)" % str(self.matcher)
class regex_matcher_t(matcher_base_t):
"""
Instance of this class will match declaration using regular expression.
User should supply a function that will extract from declaration desired
information as string. Later, this matcher will match that string using
user regular expression.
"""
def __init__(self, regex, function=None):
"""
:param regex: regular expression
:type regex: string, an instance of this class will compile it for you
:param function: function that will be called to get an information
from declaration as string. As input this function
takes single argument - reference to a declaration.
Return value should be string. If function is None,
then the matcher will use declaration name.
"""
matcher_base_t.__init__(self)
self.regex = re.compile(regex)
self.function = function
if self.function is None:
self.function = lambda decl: decl.name
def __call__(self, decl):
text = self.function(decl)
return bool(self.regex.match(text))
def __str__(self):
return '(regex=%s)' % self.regex
class custom_matcher_t(matcher_base_t):
"""
Instance of this class will match declaration by user custom criteria.
"""
def __init__(self, function):
"""
:param function: callable, that takes single argument -
declaration instance should return True or False
"""
matcher_base_t.__init__(self)
self.function = function
def __call__(self, decl):
return bool(self.function(decl))
def __str__(self):
return '(user criteria)'
class access_type_matcher_t(matcher_base_t):
"""
Instance of this class will match declaration by its access type: public,
private or protected. If declarations does not have access type, for
example free function, then `False` will be returned.
"""
def __init__(self, access_type):
"""
:param access_type: declaration access type, could be "public",
"private", "protected"
:type access_type: :class: `str`
"""
matcher_base_t.__init__(self)
self.access_type = access_type
def __call__(self, decl):
if not isinstance(decl.parent, class_declaration.class_t):
return False
return (
self.access_type == decl.parent.find_out_member_access_type(decl)
)
def __str__(self):
return '(access type=%s)' % self.access_type
class virtuality_type_matcher_t(matcher_base_t):
"""
Instance of this class will match declaration by its virtual type: not
virtual, virtual or pure virtual. If declarations does not have "virtual"
property, for example free function, then `False` will be returned.
"""
def __init__(self, virtuality_type):
"""
:param access_type: declaration access type
:type access_type: :class:VIRTUALITY_TYPES defines few constants for
your convenience.
"""
matcher_base_t.__init__(self)
self.virtuality_type = virtuality_type
def __call__(self, decl):
if not isinstance(decl.parent, class_declaration.class_t):
return False
return self.virtuality_type == decl.virtuality
def __str__(self):
return '(virtuality type=%s)' % self.virtuality_type
|