[pygccxml-commit] SF.net SVN: pygccxml: [210] pygccxml_dev/unittests
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-06-07 20:10:19
|
Revision: 210 Author: roman_yakovenko Date: 2006-06-05 07:09:20 -0700 (Mon, 05 Jun 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=210&view=rev Log Message: ----------- adding is_vector type traits Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/__init__.py pygccxml_dev/pygccxml/declarations/type_traits.py Added Paths: ----------- pygccxml_dev/unittests/data/unnamed_classes.hpp pygccxml_dev/unittests/data/vector_traits.hpp pygccxml_dev/unittests/unnamed_classes_tester.py pygccxml_dev/unittests/vector_traits_tester.py Modified: pygccxml_dev/pygccxml/declarations/__init__.py =================================================================== --- pygccxml_dev/pygccxml/declarations/__init__.py 2006-06-05 09:35:05 UTC (rev 209) +++ pygccxml_dev/pygccxml/declarations/__init__.py 2006-06-05 14:09:20 UTC (rev 210) @@ -142,6 +142,8 @@ from type_traits import find_trivial_constructor from type_traits import has_any_non_copyconstructor +from type_traits import vector_traits + import templates import call_invocation Modified: pygccxml_dev/pygccxml/declarations/type_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/type_traits.py 2006-06-05 09:35:05 UTC (rev 209) +++ pygccxml_dev/pygccxml/declarations/type_traits.py 2006-06-05 14:09:20 UTC (rev 210) @@ -20,6 +20,7 @@ import cpptypes import variable import algorithm +import namespace import enumeration import class_declaration from sets import Set as set @@ -721,14 +722,84 @@ return True return __is_noncopyable_single( class_ ) + + +def is_defined_in_std( cls ): + if not cls.parent: + return False + if not isinstance( cls.parent, namespace.namespace_t ): + return False + if 'std' != cls.parent.name: + return False + + std = cls.parent + if not std.parent: + return False + if not isinstance( std.parent, namespace.namespace_t ): + return False + if '::' != std.parent.name: + return False + global_ns = std.parent + return None is global_ns.parent + +class vector_traits: + + @staticmethod + def declaration_or_none( type ): + global is_defined_in_std + """returns reference to the class declaration or None""" + type = remove_alias( type ) + type = remove_cv( type ) + if not isinstance( type, cpptypes.declarated_t ): + return + + cls = remove_alias( type.declaration ) + if not isinstance( cls, ( class_declaration.class_t, class_declaration.class_declaration_t ) ): + return + + if not cls.name.startswith( 'vector<' ): + return + + if not is_defined_in_std( cls ): + return + return cls + + @staticmethod + def is_vector( type ): + """ + Returns True if type represents instantiation of std class vector, + otherwise False. + """ + return not( None is vector_traits.declaration_or_none( type ) ) + + @staticmethod + def class_declaration( type ): + """returns reference to the class declaration, """ + cls = vector_traits.declaration_or_none( type ) + if not cls: + raise TypeError( 'Type "%s" is not instantiation ov std::vector' % type.decl_string ) + return cls + @staticmethod + def value_type( type ): + """returns reference to value_type of the vector""" + cls = vector_traits.class_declaration( type ) + if isinstance( cls, class_declaration.class_t ): + return cls.typedef( "value_type" ).type + else: + + + + + + \ No newline at end of file Added: pygccxml_dev/unittests/data/unnamed_classes.hpp =================================================================== --- pygccxml_dev/unittests/data/unnamed_classes.hpp (rev 0) +++ pygccxml_dev/unittests/data/unnamed_classes.hpp 2006-06-05 14:09:20 UTC (rev 210) @@ -0,0 +1,51 @@ +// 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) + +#ifndef __unnamed_classes_hpp__ +#define __unnamed_classes_hpp__ + +namespace unnamed{ + +struct S1{ + struct S2{ + union Flags{ + struct{ + unsigned int hasItemIdList : 1; + unsigned int pointsToFileOrDir : 1; + unsigned int hasDescription : 1; + unsigned int hasRelativePath : 1; + unsigned int hasWorkingDir : 1; + unsigned int hasCmdLineArgs : 1; + unsigned int hasCustomIcon : 1; + unsigned int useWorkingDir : 1; // Seems to need to be set to enable working dir + unsigned int unused : 24; + }; + unsigned int raw; + } flags; + + union FileAttribs{ + struct{ + unsigned int isReadOnly : 1; + unsigned int isHidden : 1; + unsigned int isSystem : 1; + unsigned int isVolumeLabel : 1; + unsigned int isDir : 1; + unsigned int isModified : 1; // =archive bit set, ie; is a file normally + unsigned int isEncrypted : 1; + unsigned int isNormal : 1; // Doesn't seem to get set + unsigned int isTemporary : 1; + unsigned int isSparse : 1; + unsigned int hasReparsePoint : 1; + unsigned int isCompressed : 1; + unsigned int isOffline : 1; + unsigned int unused : 19; + }; + unsigned int raw; + } fileattribs; // in GetFileAttributes() format + } header; +}; + +} // namespace +#endif//__unnamed_classes_hpp__ Added: pygccxml_dev/unittests/data/vector_traits.hpp =================================================================== --- pygccxml_dev/unittests/data/vector_traits.hpp (rev 0) +++ pygccxml_dev/unittests/data/vector_traits.hpp 2006-06-05 14:09:20 UTC (rev 210) @@ -0,0 +1,59 @@ +// 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) + +#include <string> +#include <vector> + +struct _0_{}; +typedef std::vector< _0_ > container; + +namespace vector_traits{ +namespace yes{ + struct _1_{ + typedef int value_type; + typedef std::vector< int > container; + }; + + struct _2_{ + typedef _0_ value_type; + typedef std::vector< _0_ > container; + }; + + struct _3_{ + typedef std::string value_type; + typedef std::vector< std::string > container; + }; + + struct _4_{ + typedef std::vector<int> value_type; + typedef std::vector< std::vector<int> > container; + }; + + struct _5_{ + typedef int value_type; + typedef const std::vector< int > container; + }; + + struct _6_{ + typedef const int value_type; + typedef const std::vector< const int > container; + }; + +} + +namespace no{ + struct _1_{ + template< class T > + struct vector{}; + + typedef vector<int> container; + }; + + struct _2_{ + typedef const std::vector< const int >& container; + }; +} + +} \ No newline at end of file Added: pygccxml_dev/unittests/unnamed_classes_tester.py =================================================================== --- pygccxml_dev/unittests/unnamed_classes_tester.py (rev 0) +++ pygccxml_dev/unittests/unnamed_classes_tester.py 2006-06-05 14:09:20 UTC (rev 210) @@ -0,0 +1,40 @@ +# 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 unittest +import autoconfig +import parser_test_case + +from pygccxml import utils +from pygccxml import parser +from pygccxml import declarations + +class tester_t( parser_test_case.parser_test_case_t ): + def __init__(self, *args ): + parser_test_case.parser_test_case_t.__init__( self, *args ) + self.header = 'unnamed_classes.hpp' + self.global_ns = None + + def setUp(self): + if not self.global_ns: + decls = parser.parse( [self.header], self.config ) + self.global_ns = declarations.get_global_namespace( decls ) + self.global_ns.init_optimizer() + + def test( self ): + #bf_x = self.global_ns.variable( 'x' ) + #self.failUnless( bf_x.bits == 1 ) + pass + +def create_suite(): + suite = unittest.TestSuite() + suite.addTest( unittest.makeSuite(tester_t)) + return suite + +def run_suite(): + unittest.TextTestRunner(verbosity=2).run( create_suite() ) + +if __name__ == "__main__": + run_suite() \ No newline at end of file Added: pygccxml_dev/unittests/vector_traits_tester.py =================================================================== --- pygccxml_dev/unittests/vector_traits_tester.py (rev 0) +++ pygccxml_dev/unittests/vector_traits_tester.py 2006-06-05 14:09:20 UTC (rev 210) @@ -0,0 +1,48 @@ +# 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 unittest +import autoconfig +import parser_test_case + +from pygccxml import utils +from pygccxml import parser +from pygccxml import declarations + +class tester_t( parser_test_case.parser_test_case_t ): + COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE + global_ns = None + def __init__(self, *args ): + parser_test_case.parser_test_case_t.__init__( self, *args ) + self.header = 'vector_traits.hpp' + self.global_ns = None + + def setUp(self): + if not tester_t.global_ns: + decls = parser.parse( [self.header], self.config ) + tester_t.global_ns = declarations.get_global_namespace( decls ) + self.global_ns = tester_t.global_ns + + def validate_yes( self, value_type, container ): + traits = declarations.vector_traits + self.failUnless( traits.declaration_or_none( container ) ) + self.failUnless( traits.is_vector( container ) ) + self.failUnless( declarations.is_same( value_type, traits.value_type( container ) ) ) + + def test_global_ns( self ): + value_type = self.global_ns.class_( '_0_' ) + container = self.global_ns.typedef( 'container', recursive=False ) + self.validate_yes( value_type, container ) + +def create_suite(): + suite = unittest.TestSuite() + suite.addTest( unittest.makeSuite(tester_t)) + return suite + +def run_suite(): + unittest.TextTestRunner(verbosity=2).run( create_suite() ) + +if __name__ == "__main__": + run_suite() \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |