private AggregateSymbol AddAggregateToSymbolTable(
NamespaceOrAggregateSymbol parent,
Type type)
{
AggregateSymbol agg = _symFactory.CreateAggregate(GetName(type), parent, _infile, _typeManager);
agg.AssociatedSystemType = type.GetTypeInfo().IsGenericType ? type.GetTypeInfo().GetGenericTypeDefinition() : type;
agg.AssociatedAssembly = type.GetTypeInfo().Assembly;
// We have to set the TypeVars, access, and the AggKind before we can set the aggState
// because of the assertion checking the compiler does.
AggKindEnum kind;
if (type.GetTypeInfo().IsInterface)
{
kind = AggKindEnum.Interface;
}
else if (type.GetTypeInfo().IsEnum)
{
kind = AggKindEnum.Enum;
agg.SetUnderlyingType(GetCTypeFromType(Enum.GetUnderlyingType(type)).AsAggregateType());
}
else if (type.GetTypeInfo().IsValueType)
{
kind = AggKindEnum.Struct;
}
else
{
// If it derives from Delegate or MulticastDelegate, then its
// a delegate type. However, MuticastDelegate itself is not a
// delegate type.
if (type.GetTypeInfo().BaseType != null &&
(type.GetTypeInfo().BaseType.FullName == "System.MulticastDelegate" ||
type.GetTypeInfo().BaseType.FullName == "System.Delegate") &&
type.FullName != "System.MulticastDelegate")
{
kind = AggKindEnum.Delegate;
}
else
{
kind = AggKindEnum.Class;
}
}
agg.SetAggKind(kind);
agg.SetTypeVars(BSYMMGR.EmptyTypeArray());
ACCESS access;
if (type.GetTypeInfo().IsPublic)
{
access = ACCESS.ACC_PUBLIC;
}
else if (type.GetTypeInfo().IsNested)
{
// If its nested, we may have other accessibility options.
if (type.GetTypeInfo().IsNestedAssembly || type.GetTypeInfo().IsNestedFamANDAssem)
{
// Note that we don't directly support NestedFamANDAssem, but we're just
// going to default to internal.
access = ACCESS.ACC_INTERNAL;
}
else if (type.GetTypeInfo().IsNestedFamORAssem)
{
access = ACCESS.ACC_INTERNALPROTECTED;
}
else if (type.GetTypeInfo().IsNestedPrivate)
{
access = ACCESS.ACC_PRIVATE;
}
else if (type.GetTypeInfo().IsNestedFamily)
{
access = ACCESS.ACC_PROTECTED;
}
else
{
Debug.Assert(type.GetTypeInfo().IsPublic || type.GetTypeInfo().IsNestedPublic);
access = ACCESS.ACC_PUBLIC;
}
}
else
{
// We're not public and we're not nested - we must be internal.
access = ACCESS.ACC_INTERNAL;
}
agg.SetAccess(access);
if (!type.IsGenericParameter)
{
agg.SetTypeVars(GetAggregateTypeParameters(type, agg));
}
if (type.GetTypeInfo().IsGenericType)
{
Type genericDefinition = type.GetTypeInfo().GetGenericTypeDefinition();
Type[] genericArguments = genericDefinition.GetGenericArguments();
// After we load the type parameters, we need to resolve their bounds.
for (int i = 0; i < agg.GetTypeVars().size; i++)
{
Type t = genericArguments[i];
if (agg.GetTypeVars().Item(i).IsTypeParameterType())
{
agg.GetTypeVars().Item(i).AsTypeParameterType().GetTypeParameterSymbol().SetBounds(
_bsymmgr.AllocParams(
GetCTypeArrayFromTypes(t.GetTypeInfo().GetGenericParameterConstraints())));
}
}
}
agg.SetAnonymousType(false);
agg.SetAbstract(type.GetTypeInfo().IsAbstract);
{
string typeName = type.FullName;
if (type.GetTypeInfo().IsGenericType)
{
typeName = type.GetTypeInfo().GetGenericTypeDefinition().FullName;
}
if (typeName != null && PredefinedTypeFacts.IsPredefinedType(typeName))
{
PredefinedTypes.InitializePredefinedType(agg, PredefinedTypeFacts.GetPredefTypeIndex(typeName));
}
}
agg.SetLayoutError(false);
agg.SetSealed(type.GetTypeInfo().IsSealed);
agg.SetUnmanagedStruct(false);
agg.SetManagedStruct(false);
agg.SetHasExternReference(false);
agg.SetComImport(type.GetTypeInfo().IsImport);
AggregateType baseAggType = agg.getThisType();
if (type.GetTypeInfo().BaseType != null)
{
// type.GetTypeInfo().BaseType can be null for Object or for interface types.
Type t = type.GetTypeInfo().BaseType;
if (t.GetTypeInfo().IsGenericType)
{
t = t.GetTypeInfo().GetGenericTypeDefinition();
}
agg.SetBaseClass(GetCTypeFromType(t).AsAggregateType());
}
agg.SetTypeManager(_typeManager);
agg.SetFirstUDConversion(null);
SetInterfacesOnAggregate(agg, type);
agg.SetHasPubNoArgCtor(Enumerable.Any(type.GetConstructors(), c => c.GetParameters().Length == 0));
// If we have a delegate, get its invoke and constructor methods as well.
if (agg.IsDelegate())
{
PopulateSymbolTableWithName(SpecialNames.Constructor, null, type);
PopulateSymbolTableWithName(SpecialNames.Invoke, null, type);
}
return agg;
}