///////////////////////////////////////////////////////////////////////////////// public AggregateSymbol CreateAggregate(Name name, NamespaceOrAggregateSymbol parent, InputFile infile, TypeManager typeManager) { if (name == null || parent == null || infile == null || typeManager == null) { throw Error.InternalCompilerError(); } AggregateSymbol sym = null; if (infile.GetAssemblyID() == KAID.kaidUnresolved) { // Unresolved aggs need extra storage. sym = CreateUnresolvedAggregate(name, parent, typeManager); } else { sym = newBasicSym(SYMKIND.SK_AggregateSymbol, name, parent).AsAggregateSymbol(); sym.name = name; sym.SetTypeManager(typeManager); sym.SetSealed(false); sym.SetAccess(ACCESS.ACC_UNKNOWN); sym.initBogus(); sym.SetIfaces(null); sym.SetIfacesAll(null); sym.SetTypeVars(null); } sym.InitFromInfile(infile); return sym; }
///////////////////////////////////////////////////////////////////////////////// public AggregateSymbol CreateAggregate(Name name, NamespaceOrAggregateSymbol parent, InputFile infile, TypeManager typeManager) { if (name == null || parent == null || infile == null || typeManager == null) { throw Error.InternalCompilerError(); } AggregateSymbol sym = null; if (infile.GetAssemblyID() == KAID.kaidUnresolved) { // Unresolved aggs need extra storage. sym = CreateUnresolvedAggregate(name, parent, typeManager); } else { sym = newBasicSym(SYMKIND.SK_AggregateSymbol, name, parent).AsAggregateSymbol(); sym.name = name; sym.SetTypeManager(typeManager); sym.SetSealed(false); sym.SetAccess(ACCESS.ACC_UNKNOWN); sym.initBogus(); sym.SetIfaces(null); sym.SetIfacesAll(null); sym.SetTypeVars(null); } sym.InitFromInfile(infile); return(sym); }
///////////////////////////////////////////////////////////////////////////////// public static AggregateSymbol CreateAggregate(Name name, NamespaceOrAggregateSymbol parent) { Debug.Assert(name != null); Debug.Assert(parent != null); AggregateSymbol sym = (AggregateSymbol)NewBasicSymbol(SYMKIND.SK_AggregateSymbol, name, parent); sym.name = name; sym.SetSealed(false); sym.SetAccess(ACCESS.ACC_UNKNOWN); sym.SetIfaces(null); sym.SetIfacesAll(null); sym.SetTypeVars(null); return(sym); }
///////////////////////////////////////////////////////////////////////////////// public AggregateSymbol CreateAggregate(Name name, NamespaceOrAggregateSymbol parent, TypeManager typeManager) { if (name == null || parent == null || typeManager == null) { throw Error.InternalCompilerError(); } AggregateSymbol sym = (AggregateSymbol)newBasicSym(SYMKIND.SK_AggregateSymbol, name, parent); sym.name = name; sym.SetTypeManager(typeManager); sym.SetSealed(false); sym.SetAccess(ACCESS.ACC_UNKNOWN); sym.SetIfaces(null); sym.SetIfacesAll(null); sym.SetTypeVars(null); return(sym); }
private AggregateSymbol FindPredefinedTypeCore(Name name, NamespaceOrAggregateSymbol bag, KAID aid, AggKindEnum aggKind, int arity, out AggregateSymbol paggAmbig, out AggregateSymbol paggBad) { AggregateSymbol aggFound = null; paggAmbig = null; paggBad = null; for (AggregateSymbol aggCur = _pBSymmgr.LookupGlobalSymCore(name, bag, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol(); aggCur != null; aggCur = BSYMMGR.LookupNextSym(aggCur, bag, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol()) { if (!aggCur.InAlias(aid) || aggCur.GetTypeVarsAll().size != arity) { continue; } if (aggCur.AggKind() != aggKind) { if (paggBad == null) { paggBad = aggCur; } continue; } if (aggFound != null) { Debug.Assert(paggAmbig == null); paggAmbig = aggCur; break; } aggFound = aggCur; if (paggAmbig == null) { break; } } return(aggFound); }
///////////////////////////////////////////////////////////////////////////////// private NamespaceSymbol AddNamespaceToSymbolTable(NamespaceOrAggregateSymbol parent, string sz) { Name name = GetName(sz); NamespaceSymbol ns = _symbolTable.LookupSym(name, parent, symbmask_t.MASK_NamespaceSymbol).AsNamespaceSymbol(); if (ns == null) { ns = _symFactory.CreateNamespace(name, parent as NamespaceSymbol); } ns.AddAid(KAID.kaidGlobal); ns.AddAid(KAID.kaidThisAssembly); ns.AddAid(_infile.GetAssemblyID()); return ns; }
///////////////////////////////////////////////////////////////////////////////// private CType ProcessSpecialTypeInChain(NamespaceOrAggregateSymbol parent, Type t) { CType ctype; if (t.IsGenericParameter) { AggregateSymbol agg = parent as AggregateSymbol; Debug.Assert(agg != null); ctype = LoadClassTypeParameter(agg, t); return ctype; } else if (t.IsArray) { // Now we return an array of nesting level corresponding to the rank. ctype = _typeManager.GetArray(GetCTypeFromType(t.GetElementType()), t.GetArrayRank()); return ctype; } else if (t.IsPointer) { // Now we return the pointer type that we want. ctype = _typeManager.GetPointer(GetCTypeFromType(t.GetElementType())); return ctype; } else if (t.IsNullableType()) { // Get a nullable type of the underlying type. if (t.GetGenericArguments()[0].DeclaringType == t) { // If the generic argument for nullable is our child, then we're // declaring the initial Nullable<T>. AggregateSymbol agg = _symbolTable.LookupSym( GetName(t), parent, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol(); if (agg != null) { agg = FindSymWithMatchingArity(agg, t); if (agg != null) { Debug.Assert(agg.getThisType().AssociatedSystemType == t); return agg.getThisType(); } } return AddAggregateToSymbolTable(parent, t).getThisType(); } ctype = _typeManager.GetNullable(GetCTypeFromType(t.GetGenericArguments()[0])); return ctype; } return null; }
///////////////////////////////////////////////////////////////////////////////// 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; }
private AggregateSymbol FindPredefinedTypeCore(Name name, NamespaceOrAggregateSymbol bag, KAID aid, AggKindEnum aggKind, int arity, out AggregateSymbol paggAmbig, out AggregateSymbol paggBad) { AggregateSymbol aggFound = null; paggAmbig = null; paggBad = null; for (AggregateSymbol aggCur = _pBSymmgr.LookupGlobalSymCore(name, bag, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol(); aggCur != null; aggCur = BSYMMGR.LookupNextSym(aggCur, bag, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol()) { if (!aggCur.InAlias(aid) || aggCur.GetTypeVarsAll().size != arity) { continue; } if (aggCur.AggKind() != aggKind) { if (paggBad == null) { paggBad = aggCur; } continue; } if (aggFound != null) { Debug.Assert(paggAmbig == null); paggAmbig = aggCur; break; } aggFound = aggCur; if (paggAmbig == null) { break; } } return aggFound; }
private AggregateSymbol FindPredefinedType(ErrorHandling errorContext, string pszType, KAID aid, AggKindEnum aggKind, int arity, bool isRequired) { Debug.Assert(!string.IsNullOrEmpty(pszType)); // Shouldn't be the empty string! NamespaceOrAggregateSymbol bagCur = _pBSymmgr.GetRootNS(); Name name = null; string[] nameParts = pszType.Split(s_nameSeparators); for (int i = 0, n = nameParts.Length; i < n; i++) { name = _pBSymmgr.GetNameManager().Add(nameParts[i]); if (i == n - 1) { // This is the last component. Handle it special below. break; } // first search for an outer type which is also predefined // this must be first because we always create a namespace for // outer names, even for nested types AggregateSymbol aggNext = _pBSymmgr.LookupGlobalSymCore(name, bagCur, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol(); if (aggNext != null && aggNext.InAlias(aid) && aggNext.IsPredefined()) { bagCur = aggNext; } else { // ... if no outer type, then search for namespaces NamespaceSymbol nsNext = _pBSymmgr.LookupGlobalSymCore(name, bagCur, symbmask_t.MASK_NamespaceSymbol).AsNamespaceSymbol(); bool bIsInAlias = true; if (nsNext == null) { bIsInAlias = false; } else { bIsInAlias = nsNext.InAlias(aid); } if (!bIsInAlias) { // Didn't find the namespace in this aid. if (isRequired) { errorContext.Error(ErrorCode.ERR_PredefinedTypeNotFound, pszType); } return(null); } bagCur = nsNext; } } AggregateSymbol aggAmbig; AggregateSymbol aggBad; AggregateSymbol aggFound = FindPredefinedTypeCore(name, bagCur, aid, aggKind, arity, out aggAmbig, out aggBad); if (aggFound == null) { // Didn't find the AggregateSymbol. if (aggBad != null && (isRequired || aid == KAID.kaidGlobal && aggBad.IsSource())) { errorContext.ErrorRef(ErrorCode.ERR_PredefinedTypeBadType, aggBad); } else if (isRequired) { errorContext.Error(ErrorCode.ERR_PredefinedTypeNotFound, pszType); } return(null); } if (aggAmbig == null && aid != KAID.kaidGlobal) { // Look in kaidGlobal to make sure there isn't a conflicting one. AggregateSymbol tmp; AggregateSymbol agg2 = FindPredefinedTypeCore(name, bagCur, KAID.kaidGlobal, aggKind, arity, out aggAmbig, out tmp); Debug.Assert(agg2 != null); if (agg2 != aggFound) { aggAmbig = agg2; } } return(aggFound); }