@@ -398,8 +398,14 @@ public AST.ASTContext Convert()
398398 for ( uint i = 0 ; i < Context . TranslationUnitsCount ; ++ i )
399399 {
400400 var unit = Context . GetTranslationUnits ( i ) ;
401- var _unit = declConverter . Visit ( unit ) as AST . TranslationUnit ;
401+ var _unit = ( AST . TranslationUnit ) declConverter . Visit ( unit ) ;
402402 _ctx . TranslationUnits . Add ( _unit ) ;
403+ }
404+
405+ for ( uint i = 0 ; i < Context . TranslationUnitsCount ; i ++ )
406+ {
407+ var unit = Context . GetTranslationUnits ( i ) ;
408+ var _unit = ( AST . TranslationUnit ) declConverter . Visit ( unit ) ;
403409 declConverter . VisitDeclContext ( unit , _unit ) ;
404410 }
405411
@@ -832,12 +838,10 @@ public override AST.Declaration Visit(Declaration decl)
832838
833839 // Check if the declaration was already handled and return its
834840 // existing instance.
835- if ( CheckForDuplicates ( decl ) )
836- if ( Declarations . ContainsKey ( originalPtr ) )
837- return Declarations [ originalPtr ] ;
841+ if ( CheckForDuplicates ( decl ) && Declarations . ContainsKey ( originalPtr ) )
842+ return Declarations [ originalPtr ] ;
838843
839- var newDecl = base . Visit ( decl ) ;
840- return newDecl ;
844+ return base . Visit ( decl ) ;
841845 }
842846
843847 AST . AccessSpecifier VisitAccessSpecifier ( AccessSpecifier access )
@@ -969,13 +973,10 @@ void VisitDeclaration(Declaration decl, AST.Declaration _decl)
969973
970974 public void VisitDeclContext ( DeclarationContext ctx , AST . DeclarationContext _ctx )
971975 {
972- var namespaces = new Dictionary < Namespace , AST . Namespace > ( ) ;
973-
974976 for ( uint i = 0 ; i < ctx . NamespacesCount ; ++ i )
975977 {
976978 var decl = ctx . GetNamespaces ( i ) ;
977979 var _decl = Visit ( decl ) as AST . Namespace ;
978- namespaces . Add ( decl , _decl ) ;
979980 _ctx . Namespaces . Add ( _decl ) ;
980981 }
981982
@@ -1036,12 +1037,20 @@ public void VisitDeclContext(DeclarationContext ctx, AST.DeclarationContext _ctx
10361037 _ctx . Declarations . Add ( _decl ) ;
10371038 }
10381039
1039- foreach ( var @namespace in namespaces )
1040+ for ( uint i = 0 ; i < ctx . NamespacesCount ; ++ i )
10401041 {
1041- VisitDeclContext ( @namespace . Key , @namespace . Value ) ;
1042+ var decl = ctx . GetNamespaces ( i ) ;
1043+ var _decl = ( AST . Namespace ) Visit ( decl ) ;
1044+ VisitDeclContext ( decl , _decl ) ;
10421045 }
10431046
1044- namespaces . Clear ( ) ;
1047+ for ( uint i = 0 , j = 0 ; i < ctx . ClassesCount ; ++ i )
1048+ {
1049+ var decl = ctx . GetClasses ( i ) ;
1050+ var _decl = ( AST . Class ) Visit ( decl ) ;
1051+ if ( ! _decl . IsIncomplete || _decl . IsOpaque )
1052+ VisitClass ( decl , _decl ) ;
1053+ }
10451054
10461055 // Anonymous types
10471056 }
@@ -1487,7 +1496,6 @@ public override AST.Declaration VisitAccessSpecifier(AccessSpecifierDecl decl)
14871496
14881497 void VisitClass ( Class @class , AST . Class _class )
14891498 {
1490- VisitDeclaration ( @class , _class ) ;
14911499 VisitDeclContext ( @class , _class ) ;
14921500
14931501 for ( uint i = 0 ; i < @class . BasesCount ; ++ i )
@@ -1536,7 +1544,7 @@ void VisitClass(Class @class, AST.Class _class)
15361544 public override AST . Declaration VisitClass ( Class @class )
15371545 {
15381546 var _class = new AST . Class ( ) ;
1539- VisitClass ( @class , _class ) ;
1547+ VisitDeclaration ( @class , _class ) ;
15401548
15411549 return _class ;
15421550 }
@@ -1717,6 +1725,7 @@ public override AST.Declaration VisitClassTemplateSpecialization(
17171725 private void VisitClassTemplateSpecialization ( ClassTemplateSpecialization decl ,
17181726 AST . ClassTemplateSpecialization _decl )
17191727 {
1728+ VisitDeclaration ( decl , _decl ) ;
17201729 VisitClass ( decl , _decl ) ;
17211730 _decl . SpecializationKind = VisitSpecializationKind ( decl . SpecializationKind ) ;
17221731 _decl . TemplatedDecl = ( AST . ClassTemplate ) Visit ( decl . TemplatedDecl ) ;
0 commit comments