Update of /cvsroot/pygccxml/source/pygccxml/declarations
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10238/pygccxml/declarations
Modified Files:
__init__.py filters.py
Log Message:
adding [or|and|not]_matcher_t classes and test cases to pygccxml
Index: __init__.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pygccxml/declarations/__init__.py,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** __init__.py 15 Mar 2006 09:27:06 -0000 1.36
--- __init__.py 16 Mar 2006 06:31:29 -0000 1.37
***************
*** 135,138 ****
--- 135,142 ----
from decl_factory import decl_factory_t
+ from filters import matcher_base_t
+ from filters import or_matcher_t
+ from filters import and_matcher_t
+ from filters import not_matcher_t
from filters import declaration_matcher_t
from filters import calldef_matcher_t
Index: filters.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pygccxml/declarations/filters.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** filters.py 15 Mar 2006 09:27:06 -0000 1.3
--- filters.py 16 Mar 2006 06:31:29 -0000 1.4
***************
*** 15,20 ****
from pygccxml import utils
! class declaration_matcher_t( object ):
def __init__( self, *args, **keywds ):
"""
--- 15,71 ----
from pygccxml import utils
+ class matcher_base_t(object):
+ 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])
!
! class and_matcher_t(matcher_base_t):
! """Combine several other filters with "and"."""
! 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
!
! class or_matcher_t(matcher_base_t):
! """Combine several other filters with "or"."""
! 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
!
! class not_matcher_t(matcher_base_t):
! """Combine several other filters with "or"."""
! def __init__(self, matcher):
! matcher_base_t.__init__(self)
! self.matcher = matcher
!
! def __call__(self, decl):
! return not self.matcher(decl)
!
! class declaration_matcher_t( matcher_base_t ):
def __init__( self, *args, **keywds ):
"""
***************
*** 30,34 ****
#But I think this is just wrong, because abspath wbuilds path using
#cwd and this behaviour is fragile and not so easy to find the bug.
! object.__init__( self )
self.decl_type = keywds.get('decl_type', None)
self.name = keywds.get('name', None)
--- 81,85 ----
#But I think this is just wrong, because abspath wbuilds path using
#cwd and this behaviour is fragile and not so easy to find the bug.
! matcher_base_t.__init__( self )
self.decl_type = keywds.get('decl_type', None)
self.name = keywds.get('name', None)
***************
*** 74,78 ****
type could be string or instance of class derived from cpptypes.type_t
"""
! keywds.update(decl_type=variable.variable_t)
declaration_matcher_t.__init__( self, *args, **keywds )
self.type = keywds.get('type', None)
--- 125,129 ----
type could be string or instance of class derived from cpptypes.type_t
"""
! keywds['decl_type'] = variable.variable_t
declaration_matcher_t.__init__( self, *args, **keywds )
self.type = keywds.get('type', None)
***************
*** 93,97 ****
class namespace_matcher_t( declaration_matcher_t ):
def __init__( self, *args, **keywds ):
! keywds.update(decl_type=namespace.namespace_t)
declaration_matcher_t.__init__( self, namespace.namespace_t, *args, **keywds)
--- 144,148 ----
class namespace_matcher_t( declaration_matcher_t ):
def __init__( self, *args, **keywds ):
! keywds['decl_type'] = namespace.namespace_t
declaration_matcher_t.__init__( self, namespace.namespace_t, *args, **keywds)
***************
*** 114,118 ****
"""
if not keywds.has_key( 'decl_type' ):
! keywds.update( decl_type=calldef.calldef_t )
declaration_matcher_t.__init__( self, *args, **keywds )
--- 165,169 ----
"""
if not keywds.has_key( 'decl_type' ):
! keywds[ 'decl_type' ] = calldef.calldef_t
declaration_matcher_t.__init__( self, *args, **keywds )
***************
*** 149,155 ****
class operator_matcher_t( calldef_matcher_t ):
! def __init__( self, symbol=None, *args, **keywds):
if not keywds.has_key( 'decl_type' ):
! keywds.update( decl_type=calldef.operator_t )
calldef_matcher_t.__init__( self, *args, **keywds )
self.symbol = keywds.get( 'symbol', None )
--- 200,206 ----
class operator_matcher_t( calldef_matcher_t ):
! def __init__( self, *args, **keywds):
if not keywds.has_key( 'decl_type' ):
! keywds['decl_type'] = calldef.operator_t
calldef_matcher_t.__init__( self, *args, **keywds )
self.symbol = keywds.get( 'symbol', None )
***************
*** 160,167 ****
return None != self.symbol and self.symbol == decl.symbol
! class regex_matcher_t:
! def __init__( self, regex, function ):
self.regex = re.compile( regex )
self.function = function
def __call__( self, decl ):
--- 211,221 ----
return None != self.symbol and self.symbol == decl.symbol
! class regex_matcher_t( matcher_base_t ):
! def __init__( self, regex, function=None ):
! matcher_base_t.__init__(self)
self.regex = re.compile( regex )
self.function = function
+ if None is self.function:
+ self.function = lambda decl: decl.name
def __call__( self, decl ):
***************
*** 169,174 ****
return bool( self.regex.match( text ) )
! class access_type_matcher_t:
def __init__( self, access_type ):
self.access_type = access_type
--- 223,229 ----
return bool( self.regex.match( text ) )
! class access_type_matcher_t( matcher_base_t ):
def __init__( self, access_type ):
+ matcher_base_t.__init__( self )
self.access_type = access_type
|