<PackageReference Include="Microsoft.CSharp" Version="4.6.0" />

SymbolTable

class SymbolTable
using Microsoft.CSharp.RuntimeBinder.Semantics; using Microsoft.CSharp.RuntimeBinder.Syntax; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; namespace Microsoft.CSharp.RuntimeBinder { internal class SymbolTable { private sealed class NameHashKey { internal readonly Type type; internal readonly string name; public NameHashKey(Type type, string name) { this.type = type; this.name = name; } public override bool Equals(object obj) { NameHashKey nameHashKey = obj as NameHashKey; if (nameHashKey != null && type.Equals(nameHashKey.type)) return name.Equals(nameHashKey.name); return false; } public override int GetHashCode() { return type.GetHashCode() ^ name.GetHashCode(); } } private HashSet<Type> _typesWithConversionsLoaded; private HashSet<NameHashKey> _namesLoadedForEachType; private SYMTBL _symbolTable; private SymFactory _symFactory; private NameManager _nameManager; private TypeManager _typeManager; private BSYMMGR _bsymmgr; private CSemanticChecker _semanticChecker; private NamespaceSymbol _rootNamespace; private InputFile _infile; private static readonly Type s_Sentinel = typeof(SymbolTable); private static Type s_EventRegistrationTokenType = s_Sentinel; private static Type s_WindowsRuntimeMarshal = s_Sentinel; private static Type s_EventRegistrationTokenTable = s_Sentinel; internal static Type EventRegistrationTokenType => GetTypeByName(ref s_EventRegistrationTokenType, "System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken, System.Runtime.InteropServices.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); internal static Type WindowsRuntimeMarshalType => GetTypeByName(ref s_WindowsRuntimeMarshal, "System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal, System.Runtime.InteropServices.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); private static Type EventRegistrationTokenTableType => GetTypeByName(ref s_EventRegistrationTokenTable, "System.Runtime.InteropServices.WindowsRuntime.EventRegistrationTokenTable`1, System.Runtime.InteropServices.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); internal SymbolTable(SYMTBL symTable, SymFactory symFactory, NameManager nameManager, TypeManager typeManager, BSYMMGR bsymmgr, CSemanticChecker semanticChecker, InputFile infile) { _symbolTable = symTable; _symFactory = symFactory; _nameManager = nameManager; _typeManager = typeManager; _bsymmgr = bsymmgr; _semanticChecker = semanticChecker; _infile = infile; ClearCache(); } internal void ClearCache() { _typesWithConversionsLoaded = new HashSet<Type>(); _namesLoadedForEachType = new HashSet<NameHashKey>(); _rootNamespace = _bsymmgr.GetRootNS(); LoadSymbolsFromType(typeof(object)); } internal void PopulateSymbolTableWithName(string name, IEnumerable<Type> typeArguments, Type callingType) { if (callingType.GetTypeInfo().get_IsGenericType()) callingType = callingType.GetTypeInfo().GetGenericTypeDefinition(); if (name == "$Item$") name = (((object)callingType != typeof(string)) ? "Item" : "Chars"); NameHashKey nameHashKey = new NameHashKey(callingType, name); if (!_namesLoadedForEachType.Contains(nameHashKey)) { IEnumerable<MemberInfo> enumerable = AddNamesOnType(nameHashKey); if (enumerable != null) { foreach (MemberInfo item in enumerable) { if (item is MethodInfo) { ParameterInfo[] parameters = (item as MethodInfo).GetParameters(); foreach (ParameterInfo parameterInfo in parameters) { AddConversionsForType(parameterInfo.ParameterType); } } else if (item is ConstructorInfo) { ParameterInfo[] parameters2 = (item as ConstructorInfo).GetParameters(); foreach (ParameterInfo parameterInfo2 in parameters2) { AddConversionsForType(parameterInfo2.ParameterType); } } } } if (typeArguments != null) { foreach (Type typeArgument in typeArguments) { AddConversionsForType(typeArgument); } } } } internal SymWithType LookupMember(string name, EXPR callingObject, ParentSymbol context, int arity, MemberLookup mem, bool allowSpecialNames, bool requireInvocable) { CType cType = callingObject.type; if (cType.IsArrayType()) cType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_ARRAY); if (cType.IsNullableType()) cType = cType.AsNullableType().GetAts(_semanticChecker.GetSymbolLoader().GetErrorContext()); if (!mem.Lookup(_semanticChecker, cType, callingObject, context, GetName(name), arity, (MemLookFlags)(1073741824 | ((!allowSpecialNames) ? 256 : 0) | ((name == "$Item$") ? 4 : 0) | ((name == ".ctor") ? 2 : 0) | (requireInvocable ? 536870912 : 0)))) return null; return mem.SwtFirst(); } private IEnumerable<MemberInfo> AddNamesOnType(NameHashKey key) { List<Type> inheritance = CreateInheritanceHierarchyList(key.type); return AddNamesInInheritanceHierarchy(key.name, inheritance); } private IEnumerable<MemberInfo> AddNamesInInheritanceHierarchy(string name, List<Type> inheritance) { IEnumerable<MemberInfo> enumerable = Array.Empty<MemberInfo>(); foreach (Type item2 in inheritance) { Type type = item2; if (type.GetTypeInfo().get_IsGenericType()) type = type.GetTypeInfo().GetGenericTypeDefinition(); NameHashKey item = new NameHashKey(type, name); IEnumerable<MemberInfo> enumerable2 = TypeExtensions.GetMembers(type, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Where(delegate(MemberInfo member) { if (member.Name == name) return (object)member.DeclaringType == type; return false; }); IEnumerable<MemberInfo> enumerable3 = type.GetRuntimeEvents().Where(delegate(EventInfo member) { if (member.Name == name) return (object)member.DeclaringType == type; return false; }); if (enumerable2.Any()) { CType cTypeFromType = GetCTypeFromType(type); if (!(cTypeFromType is AggregateType)) continue; AggregateSymbol aggregate = (cTypeFromType as AggregateType).getAggregate(); FieldSymbol addedField = null; foreach (MemberInfo item3 in enumerable2) { if (item3 is MethodInfo) { MethodKindEnum kind = MethodKindEnum.Actual; if (item3.Name == "Invoke") kind = MethodKindEnum.Invoke; else if (item3.Name == "op_Implicit") { kind = MethodKindEnum.ImplicitConv; } else if (item3.Name == "op_Explicit") { kind = MethodKindEnum.ExplicitConv; } AddMethodToSymbolTable(item3, aggregate, kind); } else if (item3 is ConstructorInfo) { AddMethodToSymbolTable(item3, aggregate, MethodKindEnum.Constructor); } else if (item3 is PropertyInfo) { AddPropertyToSymbolTable(item3 as PropertyInfo, aggregate); } else if (item3 is FieldInfo) { addedField = AddFieldToSymbolTable(item3 as FieldInfo, aggregate); } } foreach (EventInfo item4 in enumerable3) { AddEventToSymbolTable(item4, aggregate, addedField); } enumerable = enumerable.Concat(enumerable2); } _namesLoadedForEachType.Add(item); } return enumerable; } private List<Type> CreateInheritanceHierarchyList(Type type) { List<Type> list = new List<Type>(); list.Insert(0, type); Type baseType = type.GetTypeInfo().get_BaseType(); while ((object)baseType != null) { LoadSymbolsFromType(baseType); list.Insert(0, baseType); baseType = baseType.GetTypeInfo().get_BaseType(); } CType cTypeFromType = GetCTypeFromType(type); if (cTypeFromType.IsWindowsRuntimeType()) { TypeArray winRTCollectionIfacesAll = cTypeFromType.AsAggregateType().GetWinRTCollectionIfacesAll(_semanticChecker.GetSymbolLoader()); for (int i = 0; i < winRTCollectionIfacesAll.size; i++) { CType cType = winRTCollectionIfacesAll.Item(i); list.Insert(0, cType.AssociatedSystemType); } } return list; } private Name GetName(string p) { if (p == null) p = string.Empty; return GetName(p, _nameManager); } private Name GetName(Type type) { string text = type.get_Name(); if (type.GetTypeInfo().get_IsGenericType()) text = text.Split(new char[1] { '`' })[0]; return GetName(text, _nameManager); } internal static Name GetName(string p, NameManager nameManager) { Name name = nameManager.Lookup(p); if (name == null) return nameManager.Add(p); return name; } private TypeArray GetMethodTypeParameters(MethodInfo method, MethodSymbol parent) { if (method.IsGenericMethod) { Type[] genericArguments = method.GetGenericArguments(); CType[] array = new CType[genericArguments.Length]; for (int i = 0; i < genericArguments.Length; i++) { Type t = genericArguments[i]; array[i] = LoadMethodTypeParameter(parent, t); } for (int j = 0; j < genericArguments.Length; j++) { Type type = genericArguments[j]; array[j].AsTypeParameterType().GetTypeParameterSymbol().SetBounds(_bsymmgr.AllocParams(GetCTypeArrayFromTypes(type.GetTypeInfo().GetGenericParameterConstraints()))); } return _bsymmgr.AllocParams(array.Length, array); } return BSYMMGR.EmptyTypeArray(); } private TypeArray GetAggregateTypeParameters(Type type, AggregateSymbol agg) { if (type.GetTypeInfo().get_IsGenericType()) { Type genericTypeDefinition = type.GetTypeInfo().GetGenericTypeDefinition(); Type[] genericArguments = TypeExtensions.GetGenericArguments(genericTypeDefinition); List<CType> list = new List<CType>(); int num = agg.isNested() ? agg.GetOuterAgg().GetTypeVarsAll().size : 0; foreach (Type type2 in genericArguments) { if (type2.GenericParameterPosition >= num) { CType cType = null; cType = ((!type2.IsGenericParameter || (object)type2.DeclaringType != genericTypeDefinition) ? GetCTypeFromType(type2) : LoadClassTypeParameter(agg, type2)); if (cType.AsTypeParameterType().GetOwningSymbol() == agg) list.Add(cType); } } return _bsymmgr.AllocParams(list.Count, list.ToArray()); } return BSYMMGR.EmptyTypeArray(); } private TypeParameterType LoadClassTypeParameter(AggregateSymbol parent, Type t) { for (AggregateSymbol aggregateSymbol = parent; aggregateSymbol != null; aggregateSymbol = (aggregateSymbol.parent.IsAggregateSymbol() ? aggregateSymbol.parent.AsAggregateSymbol() : null)) { for (TypeParameterSymbol typeParameterSymbol = _bsymmgr.LookupAggMember(GetName(t), aggregateSymbol, symbmask_t.MASK_TypeParameterSymbol) as TypeParameterSymbol; typeParameterSymbol != null; typeParameterSymbol = (BSYMMGR.LookupNextSym(typeParameterSymbol, aggregateSymbol, symbmask_t.MASK_TypeParameterSymbol) as TypeParameterSymbol)) { if (AreTypeParametersEquivalent(typeParameterSymbol.GetTypeParameterType().AssociatedSystemType, t)) return typeParameterSymbol.GetTypeParameterType(); } } return AddTypeParameterToSymbolTable(parent, null, t, true); } private bool AreTypeParametersEquivalent(Type t1, Type t2) { if ((object)t1 == t2) return true; Type originalTypeParameterType = GetOriginalTypeParameterType(t1); Type originalTypeParameterType2 = GetOriginalTypeParameterType(t2); return (object)originalTypeParameterType == originalTypeParameterType2; } private Type GetOriginalTypeParameterType(Type t) { int genericParameterPosition = t.GenericParameterPosition; Type type = t.DeclaringType; if ((object)type != null && type.GetTypeInfo().get_IsGenericType()) type = type.GetTypeInfo().GetGenericTypeDefinition(); if ((object)t.GetTypeInfo().get_DeclaringMethod() != null) { MethodBase declaringMethod = t.GetTypeInfo().get_DeclaringMethod(); if (TypeExtensions.GetGenericArguments(type) == null || genericParameterPosition >= TypeExtensions.GetGenericArguments(type).Length) return t; } while (TypeExtensions.GetGenericArguments(type).Length > genericParameterPosition) { Type type2 = type.DeclaringType; if ((object)type2 != null && type2.GetTypeInfo().get_IsGenericType()) type2 = type2.GetTypeInfo().GetGenericTypeDefinition(); if ((object)type2 == null || TypeExtensions.GetGenericArguments(type2) == null || TypeExtensions.GetGenericArguments(type2).Length <= genericParameterPosition) break; type = type2; } return TypeExtensions.GetGenericArguments(type)[genericParameterPosition]; } private TypeParameterType LoadMethodTypeParameter(MethodSymbol parent, Type t) { for (Symbol symbol = parent.firstChild; symbol != null; symbol = symbol.nextChild) { if (symbol.IsTypeParameterSymbol() && AreTypeParametersEquivalent(symbol.AsTypeParameterSymbol().GetTypeParameterType().AssociatedSystemType, t)) return symbol.AsTypeParameterSymbol().GetTypeParameterType(); } return AddTypeParameterToSymbolTable(null, parent, t, false); } private TypeParameterType AddTypeParameterToSymbolTable(AggregateSymbol agg, MethodSymbol meth, Type t, bool bIsAggregate) { TypeParameterSymbol typeParameterSymbol = (!bIsAggregate) ? _symFactory.CreateMethodTypeParameter(GetName(t), meth, t.GenericParameterPosition, t.GenericParameterPosition) : _symFactory.CreateClassTypeParameter(GetName(t), agg, t.GenericParameterPosition, t.GenericParameterPosition); if ((t.GetTypeInfo().get_GenericParameterAttributes() & GenericParameterAttributes.Covariant) != 0) typeParameterSymbol.Covariant = true; if ((t.GetTypeInfo().get_GenericParameterAttributes() & GenericParameterAttributes.Contravariant) != 0) typeParameterSymbol.Contravariant = true; SpecCons specCons = SpecCons.None; if ((t.GetTypeInfo().get_GenericParameterAttributes() & GenericParameterAttributes.DefaultConstructorConstraint) != 0) specCons |= SpecCons.New; if ((t.GetTypeInfo().get_GenericParameterAttributes() & GenericParameterAttributes.ReferenceTypeConstraint) != 0) specCons |= SpecCons.Ref; if ((t.GetTypeInfo().get_GenericParameterAttributes() & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0) specCons |= SpecCons.Val; typeParameterSymbol.SetConstraints(specCons); typeParameterSymbol.SetAccess(ACCESS.ACC_PUBLIC); return _typeManager.GetTypeParameter(typeParameterSymbol); } private CType LoadSymbolsFromType(Type originalType) { List<object> list = BuildDeclarationChain(originalType); Type type = originalType; CType cType = null; bool isByRef = type.IsByRef; if (isByRef) type = type.GetElementType(); NamespaceOrAggregateSymbol namespaceOrAggregateSymbol = _rootNamespace; NamespaceOrAggregateSymbol namespaceOrAggregateSymbol2 = null; for (int i = 0; i < list.Count; i++) { object obj = list[i]; if (obj is Type) { Type type2 = obj as Type; Name name = null; name = GetName(type2); namespaceOrAggregateSymbol2 = _symbolTable.LookupSym(name, namespaceOrAggregateSymbol, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol(); if (namespaceOrAggregateSymbol2 != null) namespaceOrAggregateSymbol2 = FindSymWithMatchingArity(namespaceOrAggregateSymbol2 as AggregateSymbol, type2); if (namespaceOrAggregateSymbol2 != null && namespaceOrAggregateSymbol2 is AggregateSymbol) { Type associatedSystemType = (namespaceOrAggregateSymbol2 as AggregateSymbol).AssociatedSystemType; Type t = type2.GetTypeInfo().get_IsGenericType() ? type2.GetTypeInfo().GetGenericTypeDefinition() : type2; if (!RuntimeBinderExtensions.IsEquivalentTo(associatedSystemType, t)) throw new ResetBindException(); } if (namespaceOrAggregateSymbol2 == null || type2.IsNullableType()) { CType cType2 = ProcessSpecialTypeInChain(namespaceOrAggregateSymbol, type2); if (cType2 != null) { if (!cType2.IsAggregateType()) { cType = cType2; break; } namespaceOrAggregateSymbol2 = cType2.AsAggregateType().GetOwningAggregate(); } else namespaceOrAggregateSymbol2 = AddAggregateToSymbolTable(namespaceOrAggregateSymbol, type2); } if ((object)type2 == type) { cType = GetConstructedType(type, namespaceOrAggregateSymbol2.AsAggregateSymbol()); break; } } else { if (obj is MethodInfo) { cType = ProcessMethodTypeParameter(obj as MethodInfo, list[++i] as Type, namespaceOrAggregateSymbol as AggregateSymbol); break; } namespaceOrAggregateSymbol2 = AddNamespaceToSymbolTable(namespaceOrAggregateSymbol, obj as string); } namespaceOrAggregateSymbol = namespaceOrAggregateSymbol2; } if (isByRef) cType = _typeManager.GetParameterModifier(cType, false); return cType; } private TypeParameterType ProcessMethodTypeParameter(MethodInfo methinfo, Type t, AggregateSymbol parent) { MethodSymbol methodSymbol = FindMatchingMethod(methinfo, parent); if (methodSymbol == null) methodSymbol = AddMethodToSymbolTable(methinfo, parent, MethodKindEnum.Actual); return LoadMethodTypeParameter(methodSymbol, t); } private CType GetConstructedType(Type type, AggregateSymbol agg) { if (type.GetTypeInfo().get_IsGenericType()) { List<CType> list = new List<CType>(); Type[] genericArguments = TypeExtensions.GetGenericArguments(type); foreach (Type t in genericArguments) { list.Add(GetCTypeFromType(t)); } TypeArray typeArgsAll = _bsymmgr.AllocParams(list.ToArray()); return _typeManager.GetAggregate(agg, typeArgsAll); } return agg.getThisType(); } private CType ProcessSpecialTypeInChain(NamespaceOrAggregateSymbol parent, Type t) { if (t.IsGenericParameter) { AggregateSymbol parent2 = parent as AggregateSymbol; return LoadClassTypeParameter(parent2, t); } if (t.IsArray) return _typeManager.GetArray(GetCTypeFromType(t.GetElementType()), t.GetArrayRank()); if (t.IsPointer) return _typeManager.GetPointer(GetCTypeFromType(t.GetElementType())); if (t.IsNullableType()) { if ((object)TypeExtensions.GetGenericArguments(t)[0].DeclaringType == t) { AggregateSymbol aggregateSymbol = _symbolTable.LookupSym(GetName(t), parent, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol(); if (aggregateSymbol != null) { aggregateSymbol = FindSymWithMatchingArity(aggregateSymbol, t); if (aggregateSymbol != null) return aggregateSymbol.getThisType(); } return AddAggregateToSymbolTable(parent, t).getThisType(); } return _typeManager.GetNullable(GetCTypeFromType(TypeExtensions.GetGenericArguments(t)[0])); } return null; } private static List<object> BuildDeclarationChain(Type callingType) { if (callingType.IsByRef) callingType = callingType.GetElementType(); List<object> list = new List<object>(); Type type = callingType; while ((object)type != null) { list.Add(type); if (type.IsGenericParameter && (object)type.GetTypeInfo().get_DeclaringMethod() != null) { MethodBase methodBase = type.GetTypeInfo().get_DeclaringMethod(); ParameterInfo[] parameters = methodBase.GetParameters(); bool flag = false; foreach (MethodInfo item2 in from m in type.DeclaringType.GetRuntimeMethods() where RuntimeBinderExtensions.HasSameMetadataDefinitionAs(m, methodBase) select m) { if (item2.IsGenericMethod) { list.Add(item2); flag = true; } } } type = type.DeclaringType; } list.Reverse(); if (callingType.Namespace != null) { string[] array = callingType.Namespace.Split(new char[1] { '.' }); int num = 0; string[] array2 = array; foreach (string item in array2) { list.Insert(num++, item); } } return list; } private AggregateSymbol FindSymWithMatchingArity(AggregateSymbol aggregateSymbol, Type type) { for (AggregateSymbol aggregateSymbol2 = aggregateSymbol; aggregateSymbol2 != null; aggregateSymbol2 = (BSYMMGR.LookupNextSym(aggregateSymbol2, aggregateSymbol2.Parent, symbmask_t.MASK_AggregateSymbol) as AggregateSymbol)) { if (aggregateSymbol2.GetTypeVarsAll().size == TypeExtensions.GetGenericArguments(type).Length) return aggregateSymbol2; } return null; } private NamespaceSymbol AddNamespaceToSymbolTable(NamespaceOrAggregateSymbol parent, string sz) { Name name = GetName(sz); NamespaceSymbol namespaceSymbol = _symbolTable.LookupSym(name, parent, symbmask_t.MASK_NamespaceSymbol).AsNamespaceSymbol(); if (namespaceSymbol == null) namespaceSymbol = _symFactory.CreateNamespace(name, parent as NamespaceSymbol); namespaceSymbol.AddAid(KAID.kaidGlobal); namespaceSymbol.AddAid(KAID.kaidThisAssembly); namespaceSymbol.AddAid(_infile.GetAssemblyID()); return namespaceSymbol; } internal CType[] GetCTypeArrayFromTypes(IList<Type> types) { if (types == null) return null; CType[] array = new CType[types.Count]; int num = 0; foreach (Type type in types) { array[num++] = GetCTypeFromType(type); } return array; } internal CType GetCTypeFromType(Type t) { return LoadSymbolsFromType(t); } private AggregateSymbol AddAggregateToSymbolTable(NamespaceOrAggregateSymbol parent, Type type) { AggregateSymbol aggregateSymbol = _symFactory.CreateAggregate(GetName(type), parent, _infile, _typeManager); aggregateSymbol.AssociatedSystemType = (type.GetTypeInfo().get_IsGenericType() ? type.GetTypeInfo().GetGenericTypeDefinition() : type); aggregateSymbol.AssociatedAssembly = type.GetTypeInfo().get_Assembly(); AggKindEnum aggKind; if (type.GetTypeInfo().get_IsInterface()) aggKind = AggKindEnum.Interface; else if (!type.GetTypeInfo().get_IsEnum()) { aggKind = (type.GetTypeInfo().get_IsValueType() ? AggKindEnum.Struct : (((object)type.GetTypeInfo().get_BaseType() == null || (!(type.GetTypeInfo().get_BaseType().FullName == "System.MulticastDelegate") && !(type.GetTypeInfo().get_BaseType().FullName == "System.Delegate")) || !(type.FullName != "System.MulticastDelegate")) ? AggKindEnum.Class : AggKindEnum.Delegate)); } else { aggKind = AggKindEnum.Enum; aggregateSymbol.SetUnderlyingType(GetCTypeFromType(Enum.GetUnderlyingType(type)).AsAggregateType()); } aggregateSymbol.SetAggKind(aggKind); aggregateSymbol.SetTypeVars(BSYMMGR.EmptyTypeArray()); ACCESS access = type.GetTypeInfo().get_IsPublic() ? ACCESS.ACC_PUBLIC : ((!type.GetTypeInfo().get_IsNested()) ? ACCESS.ACC_INTERNAL : ((!type.GetTypeInfo().get_IsNestedAssembly() && !type.GetTypeInfo().get_IsNestedFamANDAssem()) ? (type.GetTypeInfo().get_IsNestedFamORAssem() ? ACCESS.ACC_INTERNALPROTECTED : (type.GetTypeInfo().get_IsNestedPrivate() ? ACCESS.ACC_PRIVATE : ((!type.GetTypeInfo().get_IsNestedFamily()) ? ACCESS.ACC_PUBLIC : ACCESS.ACC_PROTECTED))) : ACCESS.ACC_INTERNAL)); aggregateSymbol.SetAccess(access); if (!type.IsGenericParameter) aggregateSymbol.SetTypeVars(GetAggregateTypeParameters(type, aggregateSymbol)); if (type.GetTypeInfo().get_IsGenericType()) { Type genericTypeDefinition = type.GetTypeInfo().GetGenericTypeDefinition(); Type[] genericArguments = TypeExtensions.GetGenericArguments(genericTypeDefinition); for (int i = 0; i < aggregateSymbol.GetTypeVars().size; i++) { Type type2 = genericArguments[i]; if (aggregateSymbol.GetTypeVars().Item(i).IsTypeParameterType()) aggregateSymbol.GetTypeVars().Item(i).AsTypeParameterType() .GetTypeParameterSymbol() .SetBounds(_bsymmgr.AllocParams(GetCTypeArrayFromTypes(type2.GetTypeInfo().GetGenericParameterConstraints()))); } } aggregateSymbol.SetAnonymousType(false); aggregateSymbol.SetAbstract(type.GetTypeInfo().get_IsAbstract()); string fullName = type.FullName; if (type.GetTypeInfo().get_IsGenericType()) fullName = type.GetTypeInfo().GetGenericTypeDefinition().FullName; if (fullName != null && PredefinedTypeFacts.IsPredefinedType(fullName)) PredefinedTypes.InitializePredefinedType(aggregateSymbol, PredefinedTypeFacts.GetPredefTypeIndex(fullName)); aggregateSymbol.SetLayoutError(false); aggregateSymbol.SetSealed(type.GetTypeInfo().get_IsSealed()); aggregateSymbol.SetUnmanagedStruct(false); aggregateSymbol.SetManagedStruct(false); aggregateSymbol.SetHasExternReference(false); aggregateSymbol.SetComImport(type.GetTypeInfo().get_IsImport()); AggregateType thisType = aggregateSymbol.getThisType(); if ((object)type.GetTypeInfo().get_BaseType() != null) { Type type3 = type.GetTypeInfo().get_BaseType(); if (type3.GetTypeInfo().get_IsGenericType()) type3 = type3.GetTypeInfo().GetGenericTypeDefinition(); aggregateSymbol.SetBaseClass(GetCTypeFromType(type3).AsAggregateType()); } aggregateSymbol.SetTypeManager(_typeManager); aggregateSymbol.SetFirstUDConversion(null); SetInterfacesOnAggregate(aggregateSymbol, type); aggregateSymbol.SetHasPubNoArgCtor(TypeExtensions.GetConstructors(type).Any((ConstructorInfo c) => c.GetParameters().Length == 0)); if (aggregateSymbol.IsDelegate()) { PopulateSymbolTableWithName(".ctor", null, type); PopulateSymbolTableWithName("Invoke", null, type); } return aggregateSymbol; } private void SetInterfacesOnAggregate(AggregateSymbol aggregate, Type type) { if (type.GetTypeInfo().get_IsGenericType()) type = type.GetTypeInfo().GetGenericTypeDefinition(); Type[] array = type.GetTypeInfo().ImplementedInterfaces.ToArray(); aggregate.SetIfaces(_bsymmgr.AllocParams(array.Length, GetCTypeArrayFromTypes(array))); aggregate.SetIfacesAll(aggregate.GetIfaces()); } private FieldSymbol AddFieldToSymbolTable(FieldInfo fieldInfo, AggregateSymbol aggregate) { FieldSymbol fieldSymbol = _symbolTable.LookupSym(GetName(fieldInfo.Name), aggregate, symbmask_t.MASK_FieldSymbol) as FieldSymbol; if (fieldSymbol != null) return fieldSymbol; fieldSymbol = _symFactory.CreateMemberVar(GetName(fieldInfo.Name), aggregate, null, 0); fieldSymbol.AssociatedFieldInfo = fieldInfo; fieldSymbol.isStatic = fieldInfo.IsStatic; ACCESS access = fieldInfo.IsPublic ? ACCESS.ACC_PUBLIC : (fieldInfo.IsPrivate ? ACCESS.ACC_PRIVATE : (fieldInfo.IsFamily ? ACCESS.ACC_PROTECTED : ((!fieldInfo.IsAssembly && !fieldInfo.IsFamilyAndAssembly) ? ACCESS.ACC_INTERNALPROTECTED : ACCESS.ACC_INTERNAL))); fieldSymbol.SetAccess(access); fieldSymbol.isReadOnly = fieldInfo.IsInitOnly; fieldSymbol.isEvent = false; fieldSymbol.isAssigned = true; fieldSymbol.SetType(GetCTypeFromType(fieldInfo.FieldType)); return fieldSymbol; } private static Type GetTypeByName(ref Type cachedResult, string name) { if ((object)cachedResult == s_Sentinel) Interlocked.CompareExchange(ref cachedResult, Type.GetType(name, false), s_Sentinel); return cachedResult; } private EventSymbol AddEventToSymbolTable(EventInfo eventInfo, AggregateSymbol aggregate, FieldSymbol addedField) { EventSymbol eventSymbol = _symbolTable.LookupSym(GetName(eventInfo.Name), aggregate, symbmask_t.MASK_EventSymbol) as EventSymbol; if (eventSymbol != null) return eventSymbol; eventSymbol = _symFactory.CreateEvent(GetName(eventInfo.Name), aggregate, null); eventSymbol.AssociatedEventInfo = eventInfo; ACCESS access = ACCESS.ACC_PRIVATE; if ((object)eventInfo.AddMethod != null) { eventSymbol.methAdd = AddMethodToSymbolTable(eventInfo.AddMethod, aggregate, MethodKindEnum.EventAccessor); eventSymbol.methAdd.SetEvent(eventSymbol); eventSymbol.isOverride = eventSymbol.methAdd.IsOverride(); access = eventSymbol.methAdd.GetAccess(); } if ((object)eventInfo.RemoveMethod != null) { eventSymbol.methRemove = AddMethodToSymbolTable(eventInfo.RemoveMethod, aggregate, MethodKindEnum.EventAccessor); eventSymbol.methRemove.SetEvent(eventSymbol); eventSymbol.isOverride = eventSymbol.methRemove.IsOverride(); access = eventSymbol.methRemove.GetAccess(); } eventSymbol.isStatic = false; eventSymbol.type = GetCTypeFromType(eventInfo.EventHandlerType); eventSymbol.SetAccess(access); Type eventRegistrationTokenType = EventRegistrationTokenType; if ((object)eventRegistrationTokenType != null && (object)WindowsRuntimeMarshalType != null && (object)eventSymbol.methAdd.RetType.AssociatedSystemType == eventRegistrationTokenType && (object)eventSymbol.methRemove.Params.Item(0).AssociatedSystemType == eventRegistrationTokenType) eventSymbol.IsWindowsRuntimeEvent = true; Type eventRegistrationTokenTableType; if (addedField != null && addedField.GetType() != null && (addedField.GetType() == eventSymbol.type || (addedField.GetType().AssociatedSystemType.IsConstructedGenericType && (object)(eventRegistrationTokenTableType = EventRegistrationTokenTableType) != null && (object)addedField.GetType().AssociatedSystemType.GetGenericTypeDefinition() == eventRegistrationTokenTableType && (object)addedField.GetType().AssociatedSystemType.GenericTypeArguments[0] == eventSymbol.type.AssociatedSystemType))) addedField.isEvent = true; return eventSymbol; } internal void AddPredefinedPropertyToSymbolTable(AggregateSymbol type, Name property) { AggregateType thisType = type.getThisType(); Type associatedSystemType = thisType.AssociatedSystemType; IEnumerable<PropertyInfo> enumerable = from x in associatedSystemType.GetRuntimeProperties() where x.Name == property.Text select x; foreach (PropertyInfo item in enumerable) { AddPropertyToSymbolTable(item, type); } } private PropertySymbol AddPropertyToSymbolTable(PropertyInfo property, AggregateSymbol aggregate) { bool flag = property.GetIndexParameters() != null && property.GetIndexParameters().Length != 0; Name name = (!flag) ? GetName(property.Name) : GetName("$Item$"); PropertySymbol propertySymbol = _symbolTable.LookupSym(name, aggregate, symbmask_t.MASK_PropertySymbol) as PropertySymbol; if (propertySymbol != null) { PropertySymbol propertySymbol2 = null; while (propertySymbol != null) { if (propertySymbol.AssociatedPropertyInfo.IsEquivalentTo(property)) return propertySymbol; propertySymbol2 = propertySymbol; propertySymbol = _semanticChecker.SymbolLoader.LookupNextSym(propertySymbol, propertySymbol.parent, symbmask_t.MASK_PropertySymbol).AsPropertySymbol(); } propertySymbol = propertySymbol2; if (flag) propertySymbol = null; } if (propertySymbol == null) { if (flag) { propertySymbol = _semanticChecker.GetSymbolLoader().GetGlobalMiscSymFactory().CreateIndexer(name, aggregate, GetName(property.Name), null); propertySymbol.Params = CreateParameterArray(null, property.GetIndexParameters()); } else { propertySymbol = _symFactory.CreateProperty(GetName(property.Name), aggregate, null); propertySymbol.Params = BSYMMGR.EmptyTypeArray(); } } propertySymbol.AssociatedPropertyInfo = property; propertySymbol.isStatic = (((object)PropertyInfoExtensions.GetGetMethod(property, true) != null) ? PropertyInfoExtensions.GetGetMethod(property, true).IsStatic : PropertyInfoExtensions.GetSetMethod(property, true).IsStatic); propertySymbol.isParamArray = DoesMethodHaveParameterArray(property.GetIndexParameters()); propertySymbol.swtSlot = null; propertySymbol.RetType = GetCTypeFromType(property.PropertyType); propertySymbol.isOperator = flag; if ((object)property.GetMethod != null || (object)property.SetMethod != null) { MethodInfo methodInfo = property.GetMethod ?? property.SetMethod; propertySymbol.isOverride = (methodInfo.IsVirtual && methodInfo.IsHideBySig && (object)methodInfo.GetRuntimeBaseDefinition() != methodInfo); propertySymbol.isHideByName = !methodInfo.IsHideBySig; } SetParameterDataForMethProp(propertySymbol, property.GetIndexParameters()); MethodInfo getMethod = property.GetMethod; MethodInfo setMethod = property.SetMethod; ACCESS aCCESS = ACCESS.ACC_PRIVATE; if ((object)getMethod != null) { propertySymbol.methGet = AddMethodToSymbolTable(getMethod, aggregate, MethodKindEnum.PropAccessor); if (flag || propertySymbol.methGet.Params.size == 0) propertySymbol.methGet.SetProperty(propertySymbol); else { propertySymbol.setBogus(true); propertySymbol.methGet.SetMethKind(MethodKindEnum.Actual); } if (propertySymbol.methGet.GetAccess() > aCCESS) aCCESS = propertySymbol.methGet.GetAccess(); } if ((object)setMethod != null) { propertySymbol.methSet = AddMethodToSymbolTable(setMethod, aggregate, MethodKindEnum.PropAccessor); if (flag || propertySymbol.methSet.Params.size == 1) propertySymbol.methSet.SetProperty(propertySymbol); else { propertySymbol.setBogus(true); propertySymbol.methSet.SetMethKind(MethodKindEnum.Actual); } if (propertySymbol.methSet.GetAccess() > aCCESS) aCCESS = propertySymbol.methSet.GetAccess(); } propertySymbol.SetAccess(aCCESS); return propertySymbol; } internal void AddPredefinedMethodToSymbolTable(AggregateSymbol type, Name methodName) { Type t = type.getThisType().AssociatedSystemType; if (methodName == _nameManager.GetPredefinedName(PredefinedName.PN_CTOR)) { IEnumerable<ConstructorInfo> enumerable = from m in TypeExtensions.GetConstructors(t) where m.Name == methodName.Text select m; foreach (ConstructorInfo item in enumerable) { AddMethodToSymbolTable(item, type, MethodKindEnum.Constructor); } } else { IEnumerable<MethodInfo> enumerable2 = t.GetRuntimeMethods().Where(delegate(MethodInfo m) { if (m.Name == methodName.Text) return (object)m.DeclaringType == t; return false; }); foreach (MethodInfo item2 in enumerable2) { AddMethodToSymbolTable(item2, type, (item2.Name == "Invoke") ? MethodKindEnum.Invoke : MethodKindEnum.Actual); } } } private MethodSymbol AddMethodToSymbolTable(MemberInfo member, AggregateSymbol callingAggregate, MethodKindEnum kind) { MethodInfo methodInfo = member as MethodInfo; ConstructorInfo constructorInfo = member as ConstructorInfo; if (kind == MethodKindEnum.Actual && ((object)methodInfo == null || (!methodInfo.IsStatic && methodInfo.IsSpecialName))) return null; MethodSymbol methodSymbol = FindMatchingMethod(member, callingAggregate); if (methodSymbol != null) return methodSymbol; ParameterInfo[] parameters = ((object)methodInfo != null) ? methodInfo.GetParameters() : constructorInfo.GetParameters(); methodSymbol = _symFactory.CreateMethod(GetName(member.Name), callingAggregate, null); methodSymbol.AssociatedMemberInfo = member; methodSymbol.SetMethKind(kind); if (kind == MethodKindEnum.ExplicitConv || kind == MethodKindEnum.ImplicitConv) { callingAggregate.SetHasConversion(); methodSymbol.SetConvNext(callingAggregate.GetFirstUDConversion()); callingAggregate.SetFirstUDConversion(methodSymbol); } ACCESS access = ((object)methodInfo != null) ? (methodInfo.IsPublic ? ACCESS.ACC_PUBLIC : (methodInfo.IsPrivate ? ACCESS.ACC_PRIVATE : (methodInfo.IsFamily ? ACCESS.ACC_PROTECTED : ((!methodInfo.IsAssembly && !methodInfo.IsFamilyAndAssembly) ? ACCESS.ACC_INTERNALPROTECTED : ACCESS.ACC_INTERNAL)))) : (constructorInfo.IsPublic ? ACCESS.ACC_PUBLIC : (constructorInfo.IsPrivate ? ACCESS.ACC_PRIVATE : (constructorInfo.IsFamily ? ACCESS.ACC_PROTECTED : ((!constructorInfo.IsAssembly && !constructorInfo.IsFamilyAndAssembly) ? ACCESS.ACC_INTERNALPROTECTED : ACCESS.ACC_INTERNAL)))); methodSymbol.SetAccess(access); methodSymbol.isExtension = false; methodSymbol.isExternal = false; if ((object)methodInfo != null) { methodSymbol.typeVars = GetMethodTypeParameters(methodInfo, methodSymbol); methodSymbol.isVirtual = methodInfo.IsVirtual; methodSymbol.isAbstract = methodInfo.IsAbstract; methodSymbol.isStatic = methodInfo.IsStatic; methodSymbol.isOverride = (methodInfo.IsVirtual && methodInfo.IsHideBySig && (object)methodInfo.GetRuntimeBaseDefinition() != methodInfo); methodSymbol.isOperator = IsOperator(methodInfo); methodSymbol.swtSlot = GetSlotForOverride(methodInfo); methodSymbol.isVarargs = ((methodInfo.CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs); methodSymbol.RetType = GetCTypeFromType(methodInfo.ReturnType); } else { methodSymbol.typeVars = BSYMMGR.EmptyTypeArray(); methodSymbol.isVirtual = constructorInfo.IsVirtual; methodSymbol.isAbstract = constructorInfo.IsAbstract; methodSymbol.isStatic = constructorInfo.IsStatic; methodSymbol.isOverride = false; methodSymbol.isOperator = false; methodSymbol.swtSlot = null; methodSymbol.isVarargs = false; methodSymbol.RetType = _typeManager.GetVoid(); } methodSymbol.modOptCount = GetCountOfModOpts(parameters); methodSymbol.useMethInstead = false; methodSymbol.isParamArray = DoesMethodHaveParameterArray(parameters); methodSymbol.isHideByName = false; methodSymbol.errExpImpl = null; methodSymbol.Params = CreateParameterArray(methodSymbol.AssociatedMemberInfo, parameters); methodSymbol.declaration = null; SetParameterDataForMethProp(methodSymbol, parameters); return methodSymbol; } private void SetParameterDataForMethProp(MethodOrPropertySymbol methProp, ParameterInfo[] parameters) { if (parameters.Length != 0) { IEnumerable<Attribute> customAttributes = CustomAttributeExtensions.GetCustomAttributes(parameters[parameters.Length - 1], false); if (customAttributes != null) { foreach (Attribute item in customAttributes) { if (item is ParamArrayAttribute) methProp.isParamArray = true; } } for (int i = 0; i < parameters.Length; i++) { SetParameterAttributes(methProp, parameters, i); methProp.ParameterNames.Add(GetName(parameters[i].Name)); } } } private void SetParameterAttributes(MethodOrPropertySymbol methProp, ParameterInfo[] parameters, int i) { if ((parameters[i].Attributes & ParameterAttributes.Optional) != 0 && !parameters[i].ParameterType.IsByRef) { methProp.SetOptionalParameter(i); PopulateSymbolTableWithName("Value", new Type[1] { typeof(Missing) }, typeof(Missing)); } object[] array; if ((parameters[i].Attributes & ParameterAttributes.HasFieldMarshal) != 0 && (array = CustomAttributeExtensions.GetCustomAttributes(parameters[i], typeof(MarshalAsAttribute), false).ToArray()) != null && array.Length != 0) { MarshalAsAttribute marshalAsAttribute = (MarshalAsAttribute)array[0]; methProp.SetMarshalAsParameter(i, marshalAsAttribute.Value); } if ((array = CustomAttributeExtensions.GetCustomAttributes(parameters[i], typeof(DateTimeConstantAttribute), false).ToArray()) != null && array.Length != 0) { DateTimeConstantAttribute dateTimeConstantAttribute = (DateTimeConstantAttribute)array[0]; ConstValFactory constValFactory = new ConstValFactory(); CONSTVAL cv = constValFactory.Create(((DateTime)dateTimeConstantAttribute.Value).Ticks); CType reqPredefType = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_DATETIME); methProp.SetDefaultParameterValue(i, reqPredefType, cv); } else if ((array = CustomAttributeExtensions.GetCustomAttributes(parameters[i], typeof(DecimalConstantAttribute), false).ToArray()) != null && array.Length != 0) { DecimalConstantAttribute decimalConstantAttribute = (DecimalConstantAttribute)array[0]; ConstValFactory constValFactory2 = new ConstValFactory(); CONSTVAL cv2 = constValFactory2.Create(decimalConstantAttribute.Value); CType optPredefType = _semanticChecker.GetSymbolLoader().GetOptPredefType(PredefinedType.PT_DECIMAL); methProp.SetDefaultParameterValue(i, optPredefType, cv2); } else if ((parameters[i].Attributes & ParameterAttributes.HasDefault) != 0 && !parameters[i].ParameterType.IsByRef) { ConstValFactory constValFactory3 = new ConstValFactory(); CONSTVAL nullRef = nullRef = ConstValFactory.GetNullRef(); CType reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_OBJECT); if (parameters[i].DefaultValue != null) { object defaultValue = parameters[i].DefaultValue; Type type = defaultValue.GetType(); if ((object)type == typeof(byte)) { nullRef = constValFactory3.Create((byte)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_BYTE); } else if ((object)type == typeof(short)) { nullRef = constValFactory3.Create((short)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_SHORT); } else if ((object)type == typeof(int)) { nullRef = constValFactory3.Create((int)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_INT); } else if ((object)type == typeof(long)) { nullRef = constValFactory3.Create((long)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_LONG); } else if ((object)type == typeof(float)) { nullRef = constValFactory3.Create((float)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_FLOAT); } else if ((object)type == typeof(double)) { nullRef = constValFactory3.Create((double)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_DOUBLE); } else if ((object)type == typeof(decimal)) { nullRef = constValFactory3.Create((decimal)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_DECIMAL); } else if ((object)type == typeof(char)) { nullRef = constValFactory3.Create((char)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_CHAR); } else if ((object)type == typeof(bool)) { nullRef = constValFactory3.Create((bool)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_BOOL); } else if ((object)type == typeof(sbyte)) { nullRef = constValFactory3.Create((sbyte)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_SBYTE); } else if ((object)type == typeof(ushort)) { nullRef = constValFactory3.Create((ushort)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_USHORT); } else if ((object)type == typeof(uint)) { nullRef = constValFactory3.Create((uint)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_UINT); } else if ((object)type == typeof(ulong)) { nullRef = constValFactory3.Create((ulong)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_ULONG); } else if ((object)type == typeof(string)) { nullRef = constValFactory3.Create((string)defaultValue); reqPredefType2 = _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_STRING); } } methProp.SetDefaultParameterValue(i, reqPredefType2, nullRef); } } private MethodSymbol FindMatchingMethod(MemberInfo method, AggregateSymbol callingAggregate) { for (MethodSymbol methodSymbol = _bsymmgr.LookupAggMember(GetName(method.Name), callingAggregate, symbmask_t.MASK_MethodSymbol).AsMethodSymbol(); methodSymbol != null; methodSymbol = BSYMMGR.LookupNextSym(methodSymbol, callingAggregate, symbmask_t.MASK_MethodSymbol).AsMethodSymbol()) { if (methodSymbol.AssociatedMemberInfo.IsEquivalentTo(method)) return methodSymbol; } return null; } private uint GetCountOfModOpts(ParameterInfo[] parameters) { return 0; } private TypeArray CreateParameterArray(MemberInfo associatedInfo, ParameterInfo[] parameters) { List<CType> list = new List<CType>(); foreach (ParameterInfo p in parameters) { list.Add(GetTypeOfParameter(p, associatedInfo)); } MethodInfo methodInfo = associatedInfo as MethodInfo; if ((object)methodInfo != null && (methodInfo.CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs) list.Add(_typeManager.GetArgListType()); return _bsymmgr.AllocParams(list.Count, list.ToArray()); } private CType GetTypeOfParameter(ParameterInfo p, MemberInfo m) { Type parameterType = p.ParameterType; CType cType = (!parameterType.IsGenericParameter || (object)parameterType.GetTypeInfo().get_DeclaringMethod() == null || (object)parameterType.GetTypeInfo().get_DeclaringMethod() != m) ? GetCTypeFromType(parameterType) : LoadMethodTypeParameter(FindMethodFromMemberInfo(m), parameterType); if (cType.IsParameterModifierType() && p.IsOut && !p.IsIn) { CType parameterType2 = cType.AsParameterModifierType().GetParameterType(); cType = _typeManager.GetParameterModifier(parameterType2, true); } return cType; } private bool DoesMethodHaveParameterArray(ParameterInfo[] parameters) { if (parameters.Length == 0) return false; ParameterInfo element = parameters[parameters.Length - 1]; IEnumerable<Attribute> customAttributes = CustomAttributeExtensions.GetCustomAttributes(element, false); foreach (Attribute item in customAttributes) { if (item is ParamArrayAttribute) return true; } return false; } private SymWithType GetSlotForOverride(MethodInfo method) { if (method.IsVirtual && method.IsHideBySig) { MethodInfo runtimeBaseDefinition = method.GetRuntimeBaseDefinition(); if ((object)runtimeBaseDefinition == method) return null; AggregateSymbol aggregate = GetCTypeFromType(runtimeBaseDefinition.DeclaringType).getAggregate(); MethodSymbol methodSymbol = FindMethodFromMemberInfo(runtimeBaseDefinition); if (methodSymbol == null) throw Error.InternalCompilerError(); return new SymWithType(methodSymbol, aggregate.getThisType()); } return null; } private MethodSymbol FindMethodFromMemberInfo(MemberInfo baseMemberInfo) { CType cTypeFromType = GetCTypeFromType(baseMemberInfo.DeclaringType); AggregateSymbol aggregate = cTypeFromType.getAggregate(); MethodSymbol methodSymbol = _semanticChecker.SymbolLoader.LookupAggMember(GetName(baseMemberInfo.Name), aggregate, symbmask_t.MASK_MethodSymbol).AsMethodSymbol(); while (methodSymbol != null && !methodSymbol.AssociatedMemberInfo.IsEquivalentTo(baseMemberInfo)) { methodSymbol = _semanticChecker.SymbolLoader.LookupNextSym(methodSymbol, aggregate, symbmask_t.MASK_MethodSymbol).AsMethodSymbol(); } return methodSymbol; } internal bool AggregateContainsMethod(AggregateSymbol agg, string szName, symbmask_t mask) { return _semanticChecker.SymbolLoader.LookupAggMember(GetName(szName), agg, mask) != null; } internal void AddConversionsForType(Type type) { Type type2 = type; while ((object)type2.GetTypeInfo().get_BaseType() != null) { AddConversionsForOneType(type2); type2 = type2.GetTypeInfo().get_BaseType(); } } private void AddConversionsForOneType(Type type) { if (type.GetTypeInfo().get_IsGenericType()) type = type.GetTypeInfo().GetGenericTypeDefinition(); if (!_typesWithConversionsLoaded.Contains(type)) { _typesWithConversionsLoaded.Add(type); CType cType = GetCTypeFromType(type); if (!cType.IsAggregateType()) { CType baseOrParameterOrElementType; while ((baseOrParameterOrElementType = cType.GetBaseOrParameterOrElementType()) != null) { cType = baseOrParameterOrElementType; } } if (cType.IsTypeParameterType()) { CType[] array = cType.AsTypeParameterType().GetBounds().ToArray(); foreach (CType cType2 in array) { AddConversionsForType(cType2.AssociatedSystemType); } } else { AggregateSymbol aggregate = cType.AsAggregateType().getAggregate(); IEnumerable<MethodInfo> enumerable = type.GetRuntimeMethods().Where(delegate(MethodInfo conversion) { if (conversion.IsPublic && conversion.IsStatic && (conversion.Name == "op_Implicit" || conversion.Name == "op_Explicit") && (object)conversion.DeclaringType == type && conversion.IsSpecialName) return !conversion.IsGenericMethod; return false; }); foreach (MethodInfo item in enumerable) { MethodSymbol methodSymbol = AddMethodToSymbolTable(item, aggregate, (item.Name == "op_Implicit") ? MethodKindEnum.ImplicitConv : MethodKindEnum.ExplicitConv); } } } } private bool IsOperator(MethodInfo method) { if (method.IsSpecialName && method.IsStatic) { if (!(method.Name == "op_Implicit") && !(method.Name == "op_Explicit") && !(method.Name == "op_Addition") && !(method.Name == "op_Subtraction") && !(method.Name == "op_Multiply") && !(method.Name == "op_Division") && !(method.Name == "op_Modulus") && !(method.Name == "op_LeftShift") && !(method.Name == "op_RightShift") && !(method.Name == "op_LessThan") && !(method.Name == "op_GreaterThan") && !(method.Name == "op_LessThanOrEqual") && !(method.Name == "op_GreaterThanOrEqual") && !(method.Name == "op_Equality") && !(method.Name == "op_Inequality") && !(method.Name == "op_BitwiseAnd") && !(method.Name == "op_ExclusiveOr") && !(method.Name == "op_BitwiseOr") && !(method.Name == "op_LogicalNot") && !(method.Name == "op_Addition") && !(method.Name == "op_Subtraction") && !(method.Name == "op_Multiply") && !(method.Name == "op_Division") && !(method.Name == "op_Modulus") && !(method.Name == "op_BitwiseAnd") && !(method.Name == "op_ExclusiveOr") && !(method.Name == "op_BitwiseOr") && !(method.Name == "op_LeftShift") && !(method.Name == "op_RightShift") && !(method.Name == "op_UnaryNegation") && !(method.Name == "op_UnaryPlus") && !(method.Name == "op_OnesComplement") && !(method.Name == "op_True") && !(method.Name == "op_False") && !(method.Name == "op_Increment") && !(method.Name == "op_Increment") && !(method.Name == "op_Decrement")) return method.Name == "op_Decrement"; return true; } return false; } } }