//////////////////////////////////////////////////////////////////////////
// Util
//////////////////////////////////////////////////////////////////////////
/// <summary>
/// Find the Type instance for this fully qualified type name.
/// </summary>
internal PERWAPI.Type findType(string qname)
{
// Always convert voids to native
if (qname == "Fan.Sys.Void")
{
qname = "System.Void";
}
PERWAPI.Type type = (PERWAPI.Type)types[qname];
if (type == null)
{
string aname = FanUtil.getPodName(qname);
if (aname == null)
{
aname = "mscorlib";
}
if (qname.StartsWith("Fanx."))
{
aname = "sys"; // hack for support classes
}
if (qname.EndsWith("Peer"))
{
aname += "Native_"; // TODO
}
// first check if this is a type in this pod that
// hasn't been defined yet
if (aname == assemblyName)
{
// stub out type - fill get filled in later (we hope)
string[] sn = FanUtil.splitQName(qname);
ClassDef stub = null;
if (qname.IndexOf("/") != -1)
{
// Nested class
PERWAPI.ClassDef cdef = (PERWAPI.ClassDef)findType(sn[0]);
stub = cdef.AddNestedClass(PERWAPI.TypeAttr.NestedPublic, sn[1]);
}
else
{
// Normal class
stub = peFile.AddClass(PERWAPI.TypeAttr.Public, sn[0], sn[1]);
}
types[qname] = stub;
return(stub);
}
AssemblyRef aref = (AssemblyRef)assemblies[aname];
if (aref == null)
{
aref = peFile.MakeExternAssembly(aname);
assemblies[aname] = aref;
}
string[] s = FanUtil.splitQName(qname);
if (qname.IndexOf("/") != -1)
{
// Nested class
PERWAPI.ClassRef cref = (PERWAPI.ClassRef)findType(s[0]);
type = cref.AddNestedClass(s[1]);
}
/*
* else if (qname.IndexOf("<") != -1)
* {
* // Generic type
* //if (type == null) type = aref.AddClass(s[0], s[1]);
* PERWAPI.ClassRef cref = (PERWAPI.ClassRef)findType(s[0]);
* cref.SetGenericParams(new GenericParam[] { cref.GetGenericParam(0) });
* type = cref;
* }
*/
else
{
// Normal class, get/add type
type = aref.GetClass(s[0], s[1]);
if (type == null)
{
type = aref.AddClass(s[0], s[1]);
}
}
types[qname] = type;
}
return(type);
}