@ -5,23 +5,25 @@ using CppSharp.Types;
namespace CppSharp.Generators.CLI
namespace CppSharp.Generators.CLI
{
{
public class CLITypeReference
public class CLITypeReference : TypeReference
{
{
public Include Include ;
public Include Include ;
public string FowardReference ;
public override string ToString ( )
public override string ToString ( )
{
{
return FowardReference ;
if ( ! string . IsNullOrWhiteSpace ( FowardReference ) )
return FowardReference ;
return Include . ToString ( ) ;
}
}
}
}
public class CLITypeReferenceCollector : AstVisitor
public class CLITypeReferenceCollector : AstVisitor
{
{
private Dictionary < Declaration , CLITypeReference > typeReferences ;
private readonly ITypeMapDatabase TypeMapDatabase ;
private readonly ITypeMapDatabase TypeMapDatabase ;
private TranslationUnit TranslationUnit ;
private TranslationUnit TranslationUnit ;
private Dictionary < Declaration , CLITypeReference > typeReferences ;
public IEnumerable < CLITypeReference > TypeReferences
public IEnumerable < CLITypeReference > TypeReferences
{
{
get { return typeReferences . Values ; }
get { return typeReferences . Values ; }
@ -38,8 +40,9 @@ namespace CppSharp.Generators.CLI
if ( typeReferences . ContainsKey ( decl ) )
if ( typeReferences . ContainsKey ( decl ) )
return typeReferences [ decl ] ;
return typeReferences [ decl ] ;
var @ref = new CLITypeReference ( ) ;
var @ref = new CLITypeReference { Declaration = decl } ;
typeReferences . Add ( decl , @ref ) ;
typeReferences . Add ( decl , @ref ) ;
return @ref ;
return @ref ;
}
}
@ -55,13 +58,13 @@ namespace CppSharp.Generators.CLI
return GetEffectiveNamespace ( @namespace ) ;
return GetEffectiveNamespace ( @namespace ) ;
}
}
public void Process ( Namespace @namespace , bool filterNamespaces )
public void Process ( Namespace @namespace , bool filterNamespaces = false )
{
{
var collector = new RecordCollector ( @namespace . TranslationUnit ) ;
@namespace . Visit ( collector ) ;
TranslationUnit = @namespace . TranslationUnit ;
TranslationUnit = @namespace . TranslationUnit ;
var collector = new RecordCollector ( TranslationUnit ) ;
@namespace . Visit ( collector ) ;
foreach ( var record in collector . Declarations )
foreach ( var record in collector . Declarations )
{
{
if ( record . Value is Namespace )
if ( record . Value is Namespace )
@ -69,7 +72,7 @@ namespace CppSharp.Generators.CLI
if ( filterNamespaces )
if ( filterNamespaces )
{
{
var declNamespace = GetEffectiveNamespace ( record . Value . Namespace ) ;
var declNamespace = GetEffectiveNamespace ( record . Value ) ;
var isSameNamespace = declNamespace = = @namespace ;
var isSameNamespace = declNamespace = = @namespace ;
if ( declNamespace ! = null )
if ( declNamespace ! = null )
@ -88,10 +91,9 @@ namespace CppSharp.Generators.CLI
private void ProcessTypeMap ( ASTRecord < Declaration > record )
private void ProcessTypeMap ( ASTRecord < Declaration > record )
{
{
TypeMap typeMap ;
TypeMap typeMap ;
if ( ! TypeMapDatabase . FindTypeMap ( record . Value , out typeMap ) ) return ;
if ( ! TypeMapDatabase . FindTypeMap ( record . Value , out typeMap ) )
return ;
// Typemap must explicitly set the include file when one is required.
GetTypeReference ( record . Value ) . Include . File = "" ;
typeMap . Declaration = record . Value ;
typeMap . Declaration = record . Value ;
typeMap . CLITypeReference ( this , record ) ;
typeMap . CLITypeReference ( this , record ) ;
@ -114,9 +116,6 @@ namespace CppSharp.Generators.CLI
if ( IsBuiltinTypedef ( decl ) )
if ( IsBuiltinTypedef ( decl ) )
return ;
return ;
if ( declFile . Contains ( "String" ) )
return ;
var typeRef = GetTypeReference ( decl ) ;
var typeRef = GetTypeReference ( decl ) ;
typeRef . Include = new Include ( )
typeRef . Include = new Include ( )
{
{