@@ -128,7 +128,7 @@ private CppContainerContext GetOrCreateDeclarationContainer(CXCursor cursor, voi
128128 }
129129 else
130130 {
131- var templateParameters = ParseTemplateParameters ( cursor , cursor . Type , new CXClientData ( ( IntPtr ) data ) ) ;
131+ var templateParameters = ParseTemplateArguments ( cursor , cursor . Type , new CXClientData ( ( IntPtr ) data ) ) ;
132132 if ( templateParameters != null )
133133 {
134134 cppClass . TemplateParameters . AddRange ( templateParameters ) ;
@@ -237,9 +237,13 @@ private CXChildVisitResult VisitMember(CXCursor cursor, CXCursor parent, void* d
237237 break ;
238238
239239 case CXCursorKind . CXCursor_TypedefDecl :
240+ element = VisitTypeDefDecl ( cursor , data ) ;
241+ break ;
242+
240243 case CXCursorKind . CXCursor_TypeAliasDecl :
241244 case CXCursorKind . CXCursor_TypeAliasTemplateDecl :
242- element = VisitTypeDefDecl ( cursor , data ) ;
245+
246+ element = VisitTypeAliasDecl ( cursor , data ) ;
243247 break ;
244248
245249 case CXCursorKind . CXCursor_FunctionTemplate :
@@ -1538,6 +1542,43 @@ private bool ParseAttribute(TokenIterator tokenIt, out CppAttribute attribute)
15381542 return true ;
15391543 }
15401544
1545+ private CppType VisitTypeAliasDecl ( CXCursor cursor , void * data )
1546+ {
1547+ var fulltypeDefName = clang . getCursorUSR ( cursor ) . CString ;
1548+ if ( _typedefs . TryGetValue ( fulltypeDefName , out var type ) )
1549+ {
1550+ return type ;
1551+ }
1552+
1553+ var contextContainer = GetOrCreateDeclarationContainer ( cursor . SemanticParent , data ) ;
1554+ var underlyingTypeDefType = GetCppType ( cursor . TypedefDeclUnderlyingType . Declaration , cursor . TypedefDeclUnderlyingType , cursor , data ) ;
1555+
1556+ var typedefName = GetCursorSpelling ( cursor ) ;
1557+
1558+ if ( AutoSquashTypedef && underlyingTypeDefType is ICppMember cppMember && ( string . IsNullOrEmpty ( cppMember . Name ) || typedefName == cppMember . Name ) )
1559+ {
1560+ cppMember . Name = typedefName ;
1561+ type = ( CppType ) cppMember ;
1562+ }
1563+ else
1564+ {
1565+ var typedef = new CppTypedef ( GetCursorSpelling ( cursor ) , underlyingTypeDefType ) { Visibility = contextContainer . CurrentVisibility } ;
1566+ contextContainer . DeclarationContainer . Typedefs . Add ( typedef ) ;
1567+ type = typedef ;
1568+ }
1569+
1570+ // The type could have been added separately as part of the GetCppType above
1571+ if ( _typedefs . TryGetValue ( fulltypeDefName , out var cppPreviousCppType ) )
1572+ {
1573+ Debug . Assert ( cppPreviousCppType . GetType ( ) == type . GetType ( ) ) ;
1574+ }
1575+ else
1576+ {
1577+ _typedefs . Add ( fulltypeDefName , type ) ;
1578+ }
1579+ return type ;
1580+ }
1581+
15411582 private CppType VisitTypeDefDecl ( CXCursor cursor , void * data )
15421583 {
15431584 var fulltypeDefName = clang . getCursorUSR ( cursor ) . CString ;
@@ -1739,7 +1780,7 @@ private CppType GetCppTypeInternal(CXCursor cursor, CXType type, CXCursor parent
17391780 }
17401781
17411782 var cppUnexposedType = new CppUnexposedType ( type . ToString ( ) ) { SizeOf = ( int ) type . SizeOf } ;
1742- var templateParameters = ParseTemplateParameters ( cursor , type , new CXClientData ( ( IntPtr ) data ) ) ;
1783+ var templateParameters = ParseTemplateArguments ( cursor , type , new CXClientData ( ( IntPtr ) data ) ) ;
17431784 if ( templateParameters != null )
17441785 {
17451786 cppUnexposedType . TemplateParameters . AddRange ( templateParameters ) ;
@@ -1820,17 +1861,37 @@ protected void WarningUnhandled(CXCursor cursor, CXCursor parent)
18201861 RootCompilation . Diagnostics . Warning ( $ "Unhandled declaration: { cursor . Kind } /{ cursor } in { parent } .", cppLocation ) ;
18211862 }
18221863
1823- private List < CppType > ParseTemplateParameters ( CXCursor cursor , CXType type , CXClientData data )
1864+ private List < CppType > ParseTemplateArguments ( CXCursor cursor , CXType type , CXClientData data )
18241865 {
18251866 var numTemplateArguments = type . NumTemplateArguments ;
18261867 if ( numTemplateArguments < 0 ) return null ;
18271868
18281869 var templateCppTypes = new List < CppType > ( ) ;
18291870 for ( var templateIndex = 0 ; templateIndex < numTemplateArguments ; ++ templateIndex )
18301871 {
1831- var templateArg = type . GetTemplateArgumentAsType ( ( uint ) templateIndex ) ;
1832- var templateCppType = GetCppType ( templateArg . Declaration , templateArg , cursor , data ) ;
1833- templateCppTypes . Add ( templateCppType ) ;
1872+ var templateArg = type . GetTemplateArgument ( ( uint ) templateIndex ) ;
1873+
1874+ switch ( templateArg . kind )
1875+ {
1876+ case CXTemplateArgumentKind . CXTemplateArgumentKind_Type :
1877+ var templateArgType = templateArg . AsType ;
1878+ //var templateArg = type.GetTemplateArgumentAsType((uint)templateIndex);
1879+ var templateCppType = GetCppType ( templateArgType . Declaration , templateArgType , cursor , data ) ;
1880+ templateCppTypes . Add ( templateCppType ) ;
1881+ break ;
1882+ case CXTemplateArgumentKind . CXTemplateArgumentKind_Null :
1883+ case CXTemplateArgumentKind . CXTemplateArgumentKind_Declaration :
1884+ case CXTemplateArgumentKind . CXTemplateArgumentKind_NullPtr :
1885+ case CXTemplateArgumentKind . CXTemplateArgumentKind_Integral :
1886+ case CXTemplateArgumentKind . CXTemplateArgumentKind_Template :
1887+ case CXTemplateArgumentKind . CXTemplateArgumentKind_TemplateExpansion :
1888+ case CXTemplateArgumentKind . CXTemplateArgumentKind_Expression :
1889+ case CXTemplateArgumentKind . CXTemplateArgumentKind_Pack :
1890+ case CXTemplateArgumentKind . CXTemplateArgumentKind_Invalid :
1891+ break ;
1892+ default :
1893+ throw new ArgumentOutOfRangeException ( ) ;
1894+ }
18341895 }
18351896
18361897 return templateCppTypes ;
0 commit comments