Browse Source

Reworked type map matching.

We now try to find from the most qualified to less qualified type, and to deal correctly with dependent types.
pull/124/head
triton 12 years ago
parent
commit
d1629f7a62
  1. 60
      src/Generator/Types/TypeMap.cs

60
src/Generator/Types/TypeMap.cs

@ -126,30 +126,53 @@ namespace CppSharp.Types
} }
} }
public bool FindTypeMap(Declaration decl, out TypeMap typeMap) public bool FindTypeMap(Declaration decl, Type type, out TypeMap typeMap)
{ {
return FindTypeMap(decl.QualifiedOriginalName, out typeMap); // We try to find type maps from the most qualified to less qualified
// types. Example: '::std::vector', 'std::vector' and 'vector'
var typePrinter = new CppTypePrinter(this)
{
PrintKind = CppTypePrintKind.GlobalQualified
};
if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
{
typeMap.Type = type;
return true;
}
typePrinter.PrintKind = CppTypePrintKind.Qualified;
if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
{
typeMap.Type = type;
return true;
}
typePrinter.PrintKind = CppTypePrintKind.Local;
if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
{
typeMap.Type = type;
return true;
}
return false;
} }
public bool FindTypeMap(Type type, out TypeMap typeMap) public bool FindTypeMap(Type type, out TypeMap typeMap)
{ {
if (type.IsDependent)
{
typeMap = null;
return false;
}
var typePrinter = new CppTypePrinter(this); var typePrinter = new CppTypePrinter(this);
var template = type as TemplateSpecializationType; var template = type as TemplateSpecializationType;
if (template != null) if (template != null)
{ return FindTypeMap(template.Template.TemplatedDecl, type,
if (FindTypeMap(template.Template.TemplatedDecl.Visit(typePrinter), out typeMap)) out typeMap);
{
typeMap.Type = type;
return true;
}
typePrinter.PrintLocalName = true;
if (FindTypeMap(template.Template.TemplatedDecl.Visit(typePrinter), out typeMap))
{
typeMap.Type = type;
return true;
}
}
if (FindTypeMap(type.Visit(typePrinter), out typeMap)) if (FindTypeMap(type.Visit(typePrinter), out typeMap))
{ {
@ -157,7 +180,7 @@ namespace CppSharp.Types
return true; return true;
} }
typePrinter.PrintLocalName = false; typePrinter.PrintKind = CppTypePrintKind.Qualified;
if (FindTypeMap(type.Visit(typePrinter), out typeMap)) if (FindTypeMap(type.Visit(typePrinter), out typeMap))
{ {
typeMap.Type = type; typeMap.Type = type;
@ -167,6 +190,11 @@ namespace CppSharp.Types
return false; return false;
} }
public bool FindTypeMap(Declaration decl, out TypeMap typeMap)
{
return FindTypeMap(decl, null, out typeMap);
}
public bool FindTypeMapRecursive(Type type, out TypeMap typeMap) public bool FindTypeMapRecursive(Type type, out TypeMap typeMap)
{ {
while (true) while (true)

Loading…
Cancel
Save