Update of /cvsroot/pygccxml/source/pygccxml/declarations
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23403/pygccxml/declarations
Modified Files:
__init__.py algorithm.py
Added Files:
filters.py
Log Message:
Index: __init__.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pygccxml/declarations/__init__.py,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** __init__.py 28 Feb 2006 07:11:09 -0000 1.32
--- __init__.py 2 Mar 2006 05:53:14 -0000 1.33
***************
*** 13,17 ****
from enumeration import enumeration_t
from namespace import namespace_t
- from namespace import namespace_matcher_t
from class_declaration import class_t
--- 13,16 ----
***************
*** 57,61 ****
from variable import variable_t
- from variable import variable_matcher_t
from algorithm import full_name
--- 56,59 ----
***************
*** 136,138 ****
--- 134,142 ----
from decl_factory import decl_factory_t
+ from filters import calldef_matcher_t
+ from filters import namespace_matcher_t
+ from filters import variable_matcher_t
+ from filters import regex_matcher_t
+ from filters import access_type_matcher_t
+
from matcher import matcher
\ No newline at end of file
Index: algorithm.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pygccxml/declarations/algorithm.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** algorithm.py 21 Dec 2005 07:29:23 -0000 1.17
--- algorithm.py 2 Mar 2006 05:53:14 -0000 1.18
***************
*** 7,11 ****
import types
- import pygccxml.utils
from sets import Set as set
--- 7,10 ----
***************
*** 43,47 ****
decl_path = declaration_path( decl )
##Here I have lack of knowledge:
! pygccxml.utils.TODO( "What is the full name of declaration declared in unnamed namespace?" )
result = filter( None, decl_path )
return result[0] + '::'.join( result[1:] )
--- 42,46 ----
decl_path = declaration_path( decl )
##Here I have lack of knowledge:
! ##TODO: "What is the full name of declaration declared in unnamed namespace?"
result = filter( None, decl_path )
return result[0] + '::'.join( result[1:] )
--- NEW FILE: filters.py ---
# Copyright 2004 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import os
import re
import types
import algorithm
import variable
import namespace
import calldef
import cpptypes
import class_declaration
from pygccxml import utils
class declaration_matcher_t( object ):
def __init__( self, decl_type=None, name=None, header_file=None, header_dir=None ):
"""
header and header dir should be absolute!
"""
#An other option is that
#pygccxml will create absolute path using os.path.abspath function.
#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 = decl_type
self.name = name
self.header_dir = header_dir
if self.header_dir:
self.header_dir = utils.normalize_path( header_dir )
self.header_file = header_file
if self.header_file:
self.header_file = utils.normalize_path( header_file )
if self.header_dir and not os.path.isabs( self.header_dir ):
raise RuntimeError( "Path to header directory should be absolute!" )
if self.header_file and not os.path.isabs( self.header_file ):
raise RuntimeError( "Path to header file should be absolute!" )
def __call__( self, decl ):
if None != self.decl_type:
if not isinstance( decl, self.decl_type ):
return False
if None != self.name:
if '::' not in self.name:
if decl.name != self.name:
return False
else:
if self.name != algorithm.full_name( decl ):
return False
if None != self.header_dir:
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
if None != self.header_file:
decl_file = os.path.abspath( decl.location.file_name )
decl_file = utils.normalize_path( decl_file )
if decl_file != self.header_file:
return False
return True
class variable_matcher_t( declaration_matcher_t ):
def __init__( self, type=None, value=None, *arguments, **keywords):
"""
type could be string or instance of class derived from cpptypes.type_t
"""
declaration_matcher_t.__init__( self, variable.variable_t, *arguments, **keywords )
self.type = type
self.value = value
def __call__( self, decl ):
if not super( variable_matcher_t, self ).__call__( decl ):
return False
if None != self.type:
if isinstance( self.type, cpptypes.type_t ):
if self.type != decl.type:
return False
else:
if self.type != decl.type.decl_string:
return False
return True
class namespace_matcher_t( declaration_matcher_t ):
def __init__( self, *arguments, **keywords ):
declaration_matcher_t.__init__( self, namespace.namespace_t, *arguments, **keywords)
def __call__( self, decl ):
return super( namespace_matcher_t, self ).__call__( decl )
class calldef_matcher_t( declaration_matcher_t ):
def __init__( self, return_type=None, arg_types=None, *arguments, **keywords):
"""
return_value_type could be string or instance of class derived from
cpptypes.type_t
arg_types could be a list of strings or cpptypes.type_t.
It could be a mix. In this case you should specify all arguments.
If you don't want to match some argument you can insert None
instead.
In future it should be possible to select function by it's
default argument value and/or exception ....
"""
if not keywords.has_key( 'decl_type' ):
keywords[ 'decl_type' ] = calldef.calldef_t
declaration_matcher_t.__init__( self, *arguments, **keywords )
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 None != self.return_type \
and not self.__compare_types( self.return_type, decl.return_type ):
return False
if self.arg_types:
if isinstance( self.arg_types, (types.ListType, types.TupleType)):
if len(self.arg_types) != len( decl.arguments ):
return False
for type_or_str, arg in zip( self.arg_types, decl.arguments ):
if None == type_or_str:
continue
else:
if not self.__compare_types( type_or_str, arg.type ):
return False
return True
def __compare_types( self, type_or_str, type ):
assert type_or_str
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
class regex_matcher_t:
def __init__( self, regex, function ):
self.regex = re.compile( regex )
self.function = function
def __call__( self, decl ):
text = self.function( decl )
return bool( self.regex.match( text ) )
class access_type_matcher_t:
def __init__( self, access_type ):
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 )
|