Browse Source

Reworked type map handling to not do recursive type map finding by default.

pull/61/merge
triton 12 years ago
parent
commit
741f22d51e
  1. 24
      src/Generator/Types/TypeMap.cs

24
src/Generator/Types/TypeMap.cs

@ -29,6 +29,7 @@ namespace CppSharp.Types
{ {
public Type Type { get; set; } public Type Type { get; set; }
public Declaration Declaration { get; set; } public Declaration Declaration { get; set; }
public ITypeMapDatabase TypeMapDatabase { get; set; }
public virtual bool IsIgnored public virtual bool IsIgnored
{ {
@ -85,7 +86,8 @@ namespace CppSharp.Types
public interface ITypeMapDatabase public interface ITypeMapDatabase
{ {
bool FindTypeMap(Type type, out TypeMap typeMap); bool FindTypeMapRecursive(Type type, out TypeMap typeMap);
bool FindTypeMap(Type decl, out TypeMap typeMap);
bool FindTypeMap(Declaration decl, out TypeMap typeMap); bool FindTypeMap(Declaration decl, out TypeMap typeMap);
bool FindTypeMap(string name, out TypeMap typeMap); bool FindTypeMap(string name, out TypeMap typeMap);
} }
@ -130,22 +132,28 @@ namespace CppSharp.Types
} }
public bool FindTypeMap(Type type, out TypeMap typeMap) public bool FindTypeMap(Type type, out TypeMap typeMap)
{
typeMap = null;
while (true)
{ {
var typePrinter = new CppTypePrinter(this); var typePrinter = new CppTypePrinter(this);
var output = type.Visit(typePrinter); var output = type.Visit(typePrinter);
if (FindTypeMap(output, out typeMap)) if (FindTypeMap(output, out typeMap))
{
typeMap.Type = type;
return true; return true;
}
// Try to strip the global scope resolution operator. // Try to strip the global scope resolution operator.
if (output.StartsWith("::")) if (output.StartsWith("::"))
output = output.Substring(2); output = output.Substring(2);
if (FindTypeMap(output, out typeMap)) return FindTypeMap(output, out typeMap);
}
public bool FindTypeMapRecursive(Type type, out TypeMap typeMap)
{
while (true)
{
if (FindTypeMap(type, out typeMap))
return true; return true;
var desugaredType = type.Desugar(); var desugaredType = type.Desugar();
@ -154,8 +162,6 @@ namespace CppSharp.Types
type = desugaredType; type = desugaredType;
} }
return true;
} }
public bool FindTypeMap(string name, out TypeMap typeMap) public bool FindTypeMap(string name, out TypeMap typeMap)
@ -176,6 +182,8 @@ namespace CppSharp.Types
} }
typeMap = (TypeMap)Activator.CreateInstance(type); typeMap = (TypeMap)Activator.CreateInstance(type);
typeMap.TypeMapDatabase = this;
return true; return true;
} }
} }

Loading…
Cancel
Save