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 13 years ago
parent
commit
d1629f7a62
  1. 50
      src/Generator/Types/TypeMap.cs

50
src/Generator/Types/TypeMap.cs

@ -126,38 +126,61 @@ 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'
public bool FindTypeMap(Type type, out TypeMap typeMap) var typePrinter = new CppTypePrinter(this)
{ {
var typePrinter = new CppTypePrinter(this); PrintKind = CppTypePrintKind.GlobalQualified
};
var template = type as TemplateSpecializationType; if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
if (template != null)
{ {
if (FindTypeMap(template.Template.TemplatedDecl.Visit(typePrinter), out typeMap)) typeMap.Type = type;
return true;
}
typePrinter.PrintKind = CppTypePrintKind.Qualified;
if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
{ {
typeMap.Type = type; typeMap.Type = type;
return true; return true;
} }
typePrinter.PrintLocalName = true;
if (FindTypeMap(template.Template.TemplatedDecl.Visit(typePrinter), out typeMap)) typePrinter.PrintKind = CppTypePrintKind.Local;
if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
{ {
typeMap.Type = type; typeMap.Type = type;
return true; return true;
} }
return false;
} }
public bool FindTypeMap(Type type, out TypeMap typeMap)
{
if (type.IsDependent)
{
typeMap = null;
return false;
}
var typePrinter = new CppTypePrinter(this);
var template = type as TemplateSpecializationType;
if (template != null)
return FindTypeMap(template.Template.TemplatedDecl, type,
out typeMap);
if (FindTypeMap(type.Visit(typePrinter), out typeMap)) if (FindTypeMap(type.Visit(typePrinter), out typeMap))
{ {
typeMap.Type = type; typeMap.Type = type;
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