[pygccxml-commit] SF.net SVN: pygccxml:[1485] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2008-12-22 22:52:25
|
Revision: 1485
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1485&view=rev
Author: roman_yakovenko
Date: 2008-12-22 22:52:20 +0000 (Mon, 22 Dec 2008)
Log Message:
-----------
adding ability to format function names, so they will be similar to ones, ctreated by UnDecorateSymbolName
Modified Paths:
--------------
pygccxml_dev/pygccxml/declarations/__init__.py
pygccxml_dev/pygccxml/declarations/calldef.py
pygccxml_dev/pygccxml/msvc/mspdb/enums.py
pygccxml_dev/pygccxml/msvc/mspdb/loader.py
pygccxml_dev/pygccxml/utils/__init__.py
pygccxml_dev/unittests/mspdb_playground.py
Added Paths:
-----------
pygccxml_dev/unittests/data/msvc/
pygccxml_dev/unittests/data/msvc/mydll.90.vcproj
pygccxml_dev/unittests/data/msvc/mydll.cpp
pygccxml_dev/unittests/data/msvc/mydll.h
Modified: pygccxml_dev/pygccxml/declarations/__init__.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/__init__.py 2008-12-22 22:11:51 UTC (rev 1484)
+++ pygccxml_dev/pygccxml/declarations/__init__.py 2008-12-22 22:52:20 UTC (rev 1485)
@@ -104,7 +104,9 @@
from calldef import casting_operator_t
from calldef import free_function_t
from calldef import free_operator_t
+from calldef import create_undecorated_name
+
from decl_visitor import decl_visitor_t
from type_visitor import type_visitor_t
Modified: pygccxml_dev/pygccxml/declarations/calldef.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/calldef.py 2008-12-22 22:11:51 UTC (rev 1484)
+++ pygccxml_dev/pygccxml/declarations/calldef.py 2008-12-22 22:52:20 UTC (rev 1485)
@@ -19,6 +19,7 @@
import cpptypes
import algorithm
+import templates
import declaration
import type_traits
import dependencies
@@ -44,11 +45,11 @@
self._name = name
self._default_value = default_value
self._type = type
- self._attributes = attributes
+ self._attributes = attributes
def clone( self, **keywd ):
"""constructs new argument_t instance
-
+
return argument_t( name=keywd.get( 'name', self.name )
, type=keywd.get( 'type', self.type )
, default_value=keywd.get( 'default_value', self.default_value )
@@ -59,7 +60,7 @@
, type=keywd.get( 'type', self.type )
, default_value=keywd.get( 'default_value', self.default_value )
, attributes=keywd.get( 'attributes', self.attributes ) )
-
+
def __str__(self):
if self.ellipsis:
return "..."
@@ -114,7 +115,7 @@
type = property( _get_type, _set_type
, doc="""The type of the argument.
@type: L{type_t}""")
-
+
def _get_attributes( self ):
return self._attributes
def _set_attributes( self, attributes ):
@@ -203,7 +204,7 @@
self._does_throw = does_throw
does_throw = property( _get_does_throw, _set_does_throw,
doc="""If False, than function does not throw any exception.
- In this case, function was declared with empty throw
+ In this case, function was declared with empty throw
statement.
""")
@@ -226,9 +227,9 @@
@property
def overloads(self):
"""A list of overloaded "callables" (i.e. other callables with the same name within the same scope.
-
+
@type: list of L{calldef_t}
- """
+ """
if not self.parent:
return []
# finding all functions with the same name
@@ -313,7 +314,7 @@
report_dependency = lambda *args, **keywd: dependencies.dependency_info_t( self, *args, **keywd )
answer = []
if self.return_type:
- answer.append( report_dependency( self.return_type, hint="return type" ) )
+ answer.append( report_dependency( self.return_type, hint="return type" ) )
map( lambda arg: answer.append( report_dependency( arg.type ) )
, self.arguments )
map( lambda exception: answer.append( report_dependency( exception, hint="exception" ) )
@@ -506,12 +507,12 @@
if not isinstance( unaliased.base, cpptypes.declarated_t ):
return False
return id(unaliased.base.declaration) == id(self.parent)
-
+
@property
def is_trivial_constructor(self):
return not bool( self.arguments )
-
+
class destructor_t( member_calldef_t ):
"""describes deconstructor declaration"""
def __init__( self, *args, **keywords ):
@@ -541,7 +542,7 @@
free_calldef_t.__init__( self, *args, **keywords )
operator_t.__init__( self, *args, **keywords )
self.__class_types = None
-
+
@property
def class_types( self ):
"""list of class/class declaration types, extracted from the operator arguments"""
@@ -559,3 +560,56 @@
if decl:
self.__class_types.append( decl )
return self.__class_types
+
+
+def __remove_leading_scope( s ):
+ if s and s.startswith( '::' ):
+ return s[2:]
+ else:
+ return s
+
+def __format_type_as_undecorated( type_ ):
+ result = []
+ type_ = type_traits.remove_alias( type_ )
+ base_type_ = type_traits.base_type( type_ )
+ base_type_ = type_traits.remove_declarated( base_type_ )
+ if type_traits.is_class( base_type_ ) and base_type_.class_type == "struct":
+ result.append('struct ')
+ result.append( __remove_leading_scope( type_.decl_string ) )
+ return ' '.join( result )
+
+def __format_args_as_undecorated( argtypes ):
+ if not argtypes:
+ return 'void'
+ else:
+ return ','.join( map( __format_type_as_undecorated, argtypes ) )
+
+def create_undecorated_name(calldef):
+ """returns string, which contains full function name formatted exactly as
+ result of dbghelp.UnDecorateSymbolName, with UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_ACCESS_SPECIFIERS | UNDNAME_NO_ECSU
+ options.
+ """
+ calldef_type = calldef.function_type()
+
+ result = []
+ is_mem_fun = isinstance( calldef, member_calldef_t )
+ if is_mem_fun and calldef.virtuality != VIRTUALITY_TYPES.NOT_VIRTUAL:
+ result.append( 'virtual ' )
+ if calldef_type.return_type:
+ result.append( __format_type_as_undecorated( calldef.return_type ) )
+ result.append( ' ' )
+ if isinstance( calldef, member_calldef_t ):
+ result.append( __remove_leading_scope( calldef.parent.decl_string ) + '::')
+
+ result.append( calldef.name )
+ if isinstance( calldef, ( constructor_t, destructor_t) ) \
+ and templates.is_instantiation( calldef.parent.name ):
+ result.append( '<%s>' % ','.join( templates.args( calldef.parent.name ) ) )
+
+ result.append( '(%s)' % __format_args_as_undecorated( calldef_type.arguments_types ) )
+ if is_mem_fun and calldef.has_const:
+ result.append( 'const' )
+ return ''.join( result )
+
+
+
Modified: pygccxml_dev/pygccxml/msvc/mspdb/enums.py
===================================================================
--- pygccxml_dev/pygccxml/msvc/mspdb/enums.py 2008-12-22 22:11:51 UTC (rev 1484)
+++ pygccxml_dev/pygccxml/msvc/mspdb/enums.py 2008-12-22 22:52:20 UTC (rev 1485)
@@ -92,12 +92,11 @@
| UNDNAME_NO_ECSU \
| UNDNAME_NO_IDENT_CHAR_CHECK
- UNDNAME_SHORT_UNIQUE = UNDNAME_NO_LEADING_UNDERSCORES \
- | UNDNAME_NO_MS_KEYWORDS \
- | UNDNAME_NO_ALLOCATION_MODEL \
- | UNDNAME_NO_ALLOCATION_LANGUAGE \
- | UNDNAME_NO_ACCESS_SPECIFIERS \
- | UNDNAME_NO_THROW_SIGNATURES \
- | UNDNAME_NO_MEMBER_TYPE \
- | UNDNAME_NO_ECSU \
- | UNDNAME_NO_IDENT_CHAR_CHECK
+ UNDNAME_SHORT_UNIQUE = UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_ACCESS_SPECIFIERS
+ #~ UNDNAME_NO_LEADING_UNDERSCORES \
+ #~ | UNDNAME_NO_ALLOCATION_MODEL \
+ #~ | UNDNAME_NO_ALLOCATION_LANGUAGE \
+ #~ | UNDNAME_NO_THROW_SIGNATURES \
+ #~ | UNDNAME_NO_MEMBER_TYPE \
+ #~ | UNDNAME_NO_ECSU \
+ #~ | UNDNAME_NO_IDENT_CHAR_CHECK
Modified: pygccxml_dev/pygccxml/msvc/mspdb/loader.py
===================================================================
--- pygccxml_dev/pygccxml/msvc/mspdb/loader.py 2008-12-22 22:11:51 UTC (rev 1484)
+++ pygccxml_dev/pygccxml/msvc/mspdb/loader.py 2008-12-22 22:52:20 UTC (rev 1485)
@@ -1,6 +1,5 @@
import os
import re
-import pdb
import sys
import ctypes
import pprint
@@ -89,10 +88,9 @@
for smbl in itertools.imap( as_symbol, as_enum_variant( self.symbols_table._NewEnum ) ):
if smbl.symTag in useless:
continue
- smbl.uname = msvc_utils.undecorate_name( smbl.name, msvc_utils.UNDECORATE_NAME_OPTIONS.UNDNAME_SCOPES_ONLY )
- def smbl_undecorate_name( options=None ):
- return msvc_utils.undecorate_name( smbl.name, options )
- smbl.undecorate_name = smbl_undecorate_name
+ smbl.uname = smbl.get_undecoratedNameEx( enums.UNDECORATE_NAME_OPTIONS.UNDNAME_SHORT_UNIQUE )
+ if smbl.uname is None:
+ smbl.uname = smbl.name
smbls[ smbl.symIndexId ] = smbl
self.logger.info( 'loading symbols(%d) from the file - done', len( smbls ) )
return smbls
@@ -223,8 +221,6 @@
self.logger.debug( 'scanning symbols table - done' )
def __update_decls_tree( self, decl ):
- #~ if decl.name == 'money_base' and isinstance( decl, declarations.class_t ):
- #~ pdb.set_trace()
smbl = decl.dia_symbols[0]
if smbl.classParentId in self.__id2decl:
self.__adopt_declaration( self.__id2decl[smbl.classParentId], decl )
@@ -236,13 +232,14 @@
parent_name = '::' + name_splitter.scope_names[-1]
try:
parent = self.global_ns.decl( parent_name )
- except:
- declarations.print_declarations( self.global_ns )
- print 'identifiers:'
- for index, identifier in enumerate(name_splitter.identifiers):
- print index, ':', identifier
- raise
- self.__adopt_declaration( parent, decl )
+ self.__adopt_declaration( parent, decl )
+ except declarations.matcher.declaration_not_found_t:
+ pass
+ #~ declarations.print_declarations( self.global_ns )
+ #~ print 'identifiers:'
+ #~ for index, identifier in enumerate(name_splitter.identifiers):
+ #~ print index, ':', identifier
+ #~ raise
def __adopt_declaration( self, parent, decl ):
smbl = decl.dia_symbols[0]
@@ -272,10 +269,11 @@
elif enums.CV_access_e.CV_protected == smbl.access:
return declarations.ACCESS_TYPES.PROTECTED
else:
- fully_undecorated_name = smbl.undecorate_name()
- if fully_undecorated_name.startswith( 'private:' ):
+ if not smbl.undecoratedName:
+ return declarations.ACCESS_TYPES.PUBLIC
+ elif smbl.undecoratedName.startswith( 'private:' ):
declarations.ACCESS_TYPES.PRIVATE
- elif fully_undecorated_name.startswith( 'protected:' ):
+ elif smbl.undecoratedName.startswith( 'protected:' ):
declarations.ACCESS_TYPES.PROTECTED
else:
return declarations.ACCESS_TYPES.PUBLIC
@@ -348,7 +346,7 @@
#~ self.__load_enums()
#~ self.__load_vars()
#~ self.__load_typedefs()
- #~ self.__load_calldefs()
+ self.__load_calldefs()
map( self.__normalize_name, self.global_ns.decls(recursive=True) )
self.__join_unnamed_nss( self.global_ns )
self.__remove_empty_nss( self.global_ns )
@@ -538,11 +536,15 @@
return decl
def __load_calldefs( self ):
+ compiler_defined_mmem_funs = [ '__vecDelDtor'
+ ,
+ ]
self.logger.info( 'building function objects' )
is_function = lambda smbl: smbl.symTag == msdia.SymTagFunction
for functions_count, function_smbl in enumerate( itertools.ifilter( is_function, self.symbols.itervalues() ) ):
if function_smbl.classParent and function_smbl.classParentId not in self.public_classes: #what about base classes
continue
+ if
function_decl = self.__create_calldef(function_smbl)
if function_decl:
self.__update_decls_tree( function_decl )
@@ -579,6 +581,8 @@
calldef_type = self.create_type( smbl.type ) #what does happen with constructor?
decl = None
if isinstance( calldef_type, declarations.member_function_type_t ):
+ if isinstance( calldef_type.class_inst, declarations.unknown_t ):
+ return
could_be_static = False
could_be_const = False
if '~' in smbl.uname:
@@ -630,7 +634,6 @@
try:
class_ = self.create_type( smbl.objectPointerType )
class_ = declarations.base_type( class_ )
- #~ pdb.set_trace()
return declarations.member_function_type_t( class_, return_type, args_types )
except:
self.logger.warning( 'unable to find out the type of the object pointer for a class method.' )
Modified: pygccxml_dev/pygccxml/utils/__init__.py
===================================================================
--- pygccxml_dev/pygccxml/utils/__init__.py 2008-12-22 22:11:51 UTC (rev 1484)
+++ pygccxml_dev/pygccxml/utils/__init__.py 2008-12-22 22:52:20 UTC (rev 1485)
@@ -171,6 +171,9 @@
if not compiler:
return None
else:
- return compiler[0] + compiler[1].replace( '.', '' )
+ n = compiler[1].replace( '.', '' )
+ if n.endswith('0'):
+ n = n[:-1]
+ return compiler[0] + n.replace( '.', '' )
Added: pygccxml_dev/unittests/data/msvc/mydll.90.vcproj
===================================================================
--- pygccxml_dev/unittests/data/msvc/mydll.90.vcproj (rev 0)
+++ pygccxml_dev/unittests/data/msvc/mydll.90.vcproj 2008-12-22 22:52:20 UTC (rev 1485)
@@ -0,0 +1,182 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="mydll"
+ ProjectGUID="{E7A34C45-534F-43A6-AF95-3CA2428619E2}"
+ RootNamespace="mydll"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="2"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ BrowseInformation="1"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ GenerateMapFile="true"
+ MapExports="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath=".\mydll.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\mydll.h"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Added: pygccxml_dev/unittests/data/msvc/mydll.cpp
===================================================================
--- pygccxml_dev/unittests/data/msvc/mydll.cpp (rev 0)
+++ pygccxml_dev/unittests/data/msvc/mydll.cpp 2008-12-22 22:52:20 UTC (rev 1485)
@@ -0,0 +1,59 @@
+#include "mydll.h"
+#include "windows.h"
+#include <iostream>
+
+number_t::number_t()
+: m_value(0)
+{
+// std::cout << "{C++} number_t( 0 )" << std::endl;
+}
+
+
+number_t::number_t(int value)
+: m_value(value)
+{
+// std::cout << "{C++} number_t( " << value << " )" << std::endl;
+}
+
+number_t::~number_t() {
+// std::cout << "{C++} ~number_t()" << std::endl;
+}
+void number_t::print_it() const {
+ std::cout << "{C++} value: " << m_value << std::endl;
+}
+
+int number_t::get_value() const{
+ return m_value;
+}
+
+void number_t::set_value(int x){
+ m_value = x;
+}
+
+number_t number_t::clone() const{
+ return number_t(*this);
+}
+
+std::auto_ptr<number_t> number_t::clone_ptr() const{
+ return std::auto_ptr<number_t>( new number_t( *this ) );
+}
+
+void do_smth( number_aptr_t& ){
+}
+
+BOOL APIENTRY DllMain( HMODULE hModule,
+ DWORD ul_reason_for_call,
+ LPVOID lpReserved
+ )
+{
+ switch (ul_reason_for_call)
+ {
+ case DLL_PROCESS_ATTACH:
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+ return TRUE;
+}
+
Added: pygccxml_dev/unittests/data/msvc/mydll.h
===================================================================
--- pygccxml_dev/unittests/data/msvc/mydll.h (rev 0)
+++ pygccxml_dev/unittests/data/msvc/mydll.h 2008-12-22 22:52:20 UTC (rev 1485)
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <memory>
+
+class __declspec(dllexport) number_t{
+public:
+ number_t();
+ explicit number_t(int value);
+ virtual ~number_t();
+ void print_it() const;
+ int get_value() const;
+ int get_value(){ return m_value; }
+ void set_value(int x);
+
+ number_t clone() const;
+ std::auto_ptr<number_t> clone_ptr() const;
+private:
+ int m_value;
+};
+
+template class __declspec(dllexport) std::auto_ptr< number_t >;
+
+typedef std::auto_ptr< number_t > number_aptr_t;
+
+void __declspec(dllexport) do_smth( number_aptr_t& );
\ No newline at end of file
Modified: pygccxml_dev/unittests/mspdb_playground.py
===================================================================
--- pygccxml_dev/unittests/mspdb_playground.py 2008-12-22 22:11:51 UTC (rev 1484)
+++ pygccxml_dev/unittests/mspdb_playground.py 2008-12-22 22:52:20 UTC (rev 1485)
@@ -11,6 +11,7 @@
reader = mspdb.decl_loader_t( pdb_file )
opt = mspdb.enums.UNDECORATE_NAME_OPTIONS.UNDNAME_SHORT_UNIQUE
+opt = 0
public_smbls = {}
for smbl in reader.public_symbols.iterkeys():
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|