public static void AddMembers(this IMemberContainer parent, MemberDeclarationSyntax s, SortedSet <FieldInfo> fields = null, SortedSet <PropertyInfo> properties = null, SortedSet <IndexerInfo> indexers = null, SortedSet <MemberInfoBase> methods = null) { // ugly but works switch (s) { case FieldDeclarationSyntax decl: fields?.Add(new FieldInfo(decl, parent)); break; case PropertyDeclarationSyntax decl: properties?.Add(new PropertyInfo(decl, parent)); break; case IndexerDeclarationSyntax decl: indexers?.Add(new IndexerInfo(decl, parent)); break; case MethodDeclarationSyntax decl: methods?.Add(new MethodInfo(decl, parent)); break; case ConstructorDeclarationSyntax decl: methods?.Add(new ConstructorInfo(decl, parent)); break; case OperatorDeclarationSyntax decl: methods?.Add(new OperatorInfo(decl, parent)); break; } }
private void AddMembers(MemberTypes mt, IMemberContainer container) { AddMembers(mt, BindingFlags.Static | BindingFlags.Public, container); AddMembers(mt, BindingFlags.Static | BindingFlags.NonPublic, container); AddMembers(mt, BindingFlags.Instance | BindingFlags.Public, container); AddMembers(mt, BindingFlags.Instance | BindingFlags.NonPublic, container); }
/// <summary>Create a new MemberCache for the given IMemberContainer `container'.</summary> public MemberCache(IMemberContainer container) { Container = container; // If we have a base class (we have a base class unless we're // TypeManager.object_type), we deep-copy its MemberCache here. if (Container.BaseCache != null) { MemberHash = SetupCache(Container.BaseCache); } else { MemberHash = new Hashtable(); } // If this is neither a dynamic type nor an interface, create a special // method cache with all declared and inherited methods. var type = container.Type; if (!(type is TypeBuilder) && !type.IsInterface && !TypeManager.IsGenericType(type) && !TypeManager.IsGenericParameter(type) && (Container.BaseCache == null || Container.BaseCache.MethodHash != null)) { MethodHash = new Hashtable(); AddMethods(type); } // Add all members from the current class. AddMembers(Container); }
public CPythonType(IMemberContainer parent, ITypeDatabaseReader typeDb, string typeName, Dictionary<string, object> typeTable, BuiltinTypeId typeId) { Debug.Assert(parent is CPythonType || parent is CPythonModule); Debug.Assert(!typeId.IsVirtualId()); _typeName = typeName; _typeId = typeId; _module = GetDeclaringModule(parent); object value; if (typeTable.TryGetValue("is_hidden", out value)) { _includeInModule = !Convert.ToBoolean(value); } else { _includeInModule = true; } if (typeTable.TryGetValue("doc", out value)) { _doc = value as string; } if (typeTable.TryGetValue("builtin", out value)) { _isBuiltin = Convert.ToBoolean(value); } else { _isBuiltin = true; } if (typeTable.TryGetValue("bases", out value)) { var basesList = (List<object>)value; if (basesList != null) { _bases = new List<IPythonType>(); foreach (var baseType in basesList) { typeDb.LookupType(baseType, StoreBase); } } } if (typeTable.TryGetValue("mro", out value)) { var mroList = (List<object>)value; if (mroList != null && mroList.Count >= 1) { _mro = new IPythonType[mroList.Count]; // Many scraped types have invalid MRO entries because they // report their own module/name incorrectly. Since the first // item in the MRO is always self, we set it now. If the MRO // has a resolvable entry it will replace this one. _mro[0] = this; for (int i = 0; i < mroList.Count; ++i) { var capturedI = i; typeDb.LookupType(mroList[i], t => _mro[capturedI] = t); } } } if (typeTable.TryGetValue("members", out value)) { var membersTable = (Dictionary<string, object>)value; if (membersTable != null) { LoadMembers(typeDb, membersTable); } } _hasLocation = PythonTypeDatabase.TryGetLocation(typeTable, ref _line, ref _column); }
public IndexerInfo(IndexerDeclarationSyntax decl, IMemberContainer parent) { var paramList = decl.ParameterList.Parameters .Select(p => p.Type.ToString()); if (decl.HasLeadingTrivia) { Documentation = GetDocumentation(decl.GetLeadingTrivia()); } Name = decl.Type.ToString() + $"[{string.Join(", ", paramList)}]"; _parameters = Parse(decl.ParameterList); Parent = parent; _modifiers = decl.Modifiers .ParseModifiers() .WithDefaultVisibility(Parent is InterfaceInfo ? Modifier.Public : Modifier.Private); ReturnType = decl.Type.ToString(); Signature = $"{ReturnType} this[{ParamSyntax()}]"; var accessors = decl.AccessorList?.Accessors .Select(a => new AccessorInfo(a, this)); if (accessors != null) { Setter = accessors.FirstOrDefault(a => a.IsSetter); Getter = accessors.FirstOrDefault(a => a.IsGetter); } else if (decl.ExpressionBody != null) { Getter = new AccessorInfo(this); } }
public CJFunction(ITypeDatabaseReader typeDb, string name, Dictionary<string, object> functionTable, IMemberContainer declaringType, bool isMethod = false) { _name = name; object doc; if (functionTable.TryGetValue("doc", out doc)) { _doc = doc as string; } object value; if (functionTable.TryGetValue("builtin", out value)) { _isBuiltin = Convert.ToBoolean(value); } else { _isBuiltin = true; } if (functionTable.TryGetValue("static", out value)) { _isStatic = Convert.ToBoolean(value); } else { _isStatic = true; } _hasLocation = JTypeDatabase.TryGetLocation(functionTable, ref _line, ref _column); _declaringModule = CJModule.GetDeclaringModuleFromContainer(declaringType); object overloads; functionTable.TryGetValue("overloads", out overloads); _overloads = LoadOverloads(typeDb, overloads, isMethod); _declaringType = declaringType as IJType; }
public IEnumerable <IReferenceable> GetDefinitions(string name, IMemberContainer innerContainer, IModuleContext context) { var res = new List <IReferenceable>(); ReferenceDict references; lock (_references) { _references.TryGetValue(name, out references); } if (references != null) { lock (references) { res.AddRange(references.Values); } } var member = innerContainer.GetMember(context, name) as ILocatedMember; if (member != null) { res.AddRange(member.Locations.MaybeEnumerate().Select(loc => new DefinitionList(loc))); } return(res); }
public MethodInfo(MethodDeclarationSyntax decl, IMemberContainer parent) { var paramTypes = decl.ParameterList.Parameters .Select(p => p.Type.ToString()); var typeParams = Format(decl.TypeParameterList); Name = $"{decl.Identifier.Text}{typeParams}" + $"({string.Join(", ", paramTypes)})"; _parameters = Parse(decl.ParameterList); Parent = parent; _modifiers = decl.Modifiers .ParseModifiers() .WithDefaultVisibility(Parent is InterfaceInfo ? Modifier.Public : Modifier.Private); Signature = $"{decl.ReturnType} {decl.Identifier.Text}" + $"{typeParams}({ParamSyntax()})"; if (decl.HasLeadingTrivia) { Documentation = GetDocumentation(decl.GetLeadingTrivia()); } ReturnType = decl.ReturnType.ToString(); }
public override float Value(IMemberContainer member) { Dictionary <TileNode, RenderedTileInfo> nodes = ((MemberTilePCG)member).renderedTiles; Vector3 maxLoc = Vector3.zero; foreach (KeyValuePair <TileNode, RenderedTileInfo> node in nodes) { if (node.Key.type == TileGraphPCG.tileMap["1Door"]) { if (node.Value.location.magnitude > maxLoc.magnitude) { maxLoc = node.Value.location; } } } float totalDist = 0; foreach (KeyValuePair <TileNode, RenderedTileInfo> node in nodes) { float dist = Vector3.Dot(node.Value.location, maxLoc.normalized); if (dist < 0) { totalDist += node.Value.location.magnitude; } else if (dist > maxLoc.magnitude) { totalDist += (node.Value.location - maxLoc).magnitude; } else { totalDist += (node.Value.location - dist * maxLoc.normalized).magnitude; } } return(totalDist / 10); }
public MemberCache(IMemberContainer container, Type baseClass, Type[] ifaces) { Container = container; // If we have a base class (we have a base class unless we're // TypeManager.object_type), we deep-copy its MemberCache here. if (Container.BaseCache != null) { MemberHash = SetupCache(Container.BaseCache); } else { MemberHash = new Hashtable(); } if (baseClass != null) { AddCacheContents(TypeHandle.GetMemberCache(baseClass)); } if (ifaces != null) { foreach (var itype in ifaces) { var cache = TypeHandle.GetMemberCache(itype); if (cache != null) { AddCacheContents(cache); } } } }
internal IDictionary <string, IAnalysisSet> GetAllMembers(IMemberContainer container, IModuleContext moduleContext) { var names = container.GetMemberNames(moduleContext); var result = new Dictionary <string, IAnalysisSet>(); foreach (var name in names) { result[name] = GetAnalysisValueFromObjects(container.GetMember(moduleContext, name)); } var children = (container as IModule)?.GetChildrenPackages(moduleContext); if (children?.Any() ?? false) { foreach (var child in children) { IAnalysisSet existing; if (result.TryGetValue(child.Key, out existing)) { result[child.Key] = existing.Add(child.Value); } else { result[child.Key] = child.Value; } } } return(result); }
private static void CheckAddFinalCandidate(IMemberContainer m, List <float> vals) { List <IMemberContainer> membersToRemove = new List <IMemberContainer>(); foreach (KeyValuePair <IMemberContainer, List <float> > kvp in finalCandidates) { switch (CompareMembers(m, vals, kvp.Key, kvp.Value)) { case MemberComparison.DOMINATED: return; case MemberComparison.DOMINATES: membersToRemove.Add(kvp.Key); break; case MemberComparison.NEUTRAL: break; } } foreach (IMemberContainer rm in membersToRemove) { finalCandidates.Remove(rm); } finalCandidates.Add(m.CopyGenotype(), vals); }
public EventPropertyNodeWithSymbols( EventDeclarationSyntax declaration, IMemberContainer container, SemanticModel semanticModel) : base(declaration, container) { this.semanticModel = semanticModel; }
public OperatorOverloadNodeWithSymbols( OperatorDeclarationSyntax declaration, IMemberContainer container, SemanticModel semanticModel) : base(declaration, container) { this.semanticModel = semanticModel; }
public ConstructorNodeWithSymbols( ConstructorDeclarationSyntax declaration, IMemberContainer container, SemanticModel semanticModel) : base(declaration, container) { this.semanticModel = semanticModel; }
public CPythonMethodDescriptor(ITypeDatabaseReader typeDb, string name, Dictionary<string, object> valueDict, IMemberContainer declaringType) { _name = name; _func = new CPythonFunction(typeDb, name, valueDict, declaringType, isMethod: true); object value; if (valueDict.TryGetValue("bound", out value)) { _isBound = (value as bool?) ?? false; } }
public FieldNodeWithSymbols( FieldDeclarationSyntax declaration, IMemberContainer container, SemanticModel semanticModel) : base(declaration, container) { this.semanticModel = semanticModel; }
internal CPythonFunction(string name, string doc, bool isBuiltin, bool isStatic, IMemberContainer declaringType) { _name = name; _doc = doc; _isBuiltin = isBuiltin; _isStatic = isStatic; _declaringModule = CPythonModule.GetDeclaringModuleFromContainer(declaringType); _declaringType = declaringType as IPythonType; _overloads = new List<IPythonFunctionOverload>(); }
public CacheEntry( IMemberContainer container, MemberInfo member, MemberTypes mt, BindingFlags bf) { Container = container; Member = member; EntryType = GetEntryType(mt, bf); }
public CJType(IMemberContainer parent, ITypeDatabaseReader typeDb, string typeName, Dictionary<string, object> typeTable, BuiltinTypeId typeId) { Debug.Assert(parent is CJType || parent is CJModule); _typeName = typeName; _typeId = typeId; _module = GetDeclaringModule(parent); object value; if (typeTable.TryGetValue("is_hidden", out value)) { _includeInModule = !Convert.ToBoolean(value); } else { _includeInModule = true; } if (typeTable.TryGetValue("doc", out value)) { _doc = value as string; } if (typeTable.TryGetValue("builtin", out value)) { _isBuiltin = Convert.ToBoolean(value); } else { _isBuiltin = true; } if (typeTable.TryGetValue("bases", out value)) { var basesList = value as List<object>; if (basesList != null) { _bases = new List<IJType>(); foreach (var baseType in basesList) { typeDb.LookupType(baseType, StoreBase); } } } if (typeTable.TryGetValue("mro", out value)) { var mroList = value as List<object>; if (mroList != null) { _mro = new List<CJType>(); foreach (var mroType in mroList) { typeDb.LookupType(mroType, StoreMro); } } } object membersData; if (typeTable.TryGetValue("members", out membersData)) { var membersTable = membersData as Dictionary<string, object>; if (membersTable != null) { LoadMembers(typeDb, membersTable); } } _hasLocation = JTypeDatabase.TryGetLocation(typeTable, ref _line, ref _column); }
public override float Value(IMemberContainer member) { List <RenderedTileInfo> renderedTiles = new List <RenderedTileInfo>(((MemberTilePCG)member).renderedTiles.Values); float distance = 0; foreach (RenderedTileInfo rti in renderedTiles) { distance += rti.location.magnitude; } return(distance / renderedTiles.Count); }
public MemberCache(Type baseType, IMemberContainer container) { Container = container; if (baseType == null) { MemberHash = new Hashtable(); } else { MemberHash = SetupCache(TypeHandle.GetMemberCache(baseType)); } }
internal IDictionary <string, ISet <Namespace> > GetAllMembers(IMemberContainer container, IModuleContext moduleContext) { var names = container.GetMemberNames(moduleContext); var result = new Dictionary <string, ISet <Namespace> >(); foreach (var name in names) { result[name] = GetNamespaceFromObjects(container.GetMember(moduleContext, name)); } return(result); }
public CPythonMultipleMembers(IMemberContainer container, ITypeDatabaseReader typeDb, string name, IEnumerable<object> members) { _members = new List<IMember>(); _memberNames = members.OfType<Dictionary<string, object>>().ToList<object>(); _memberObjects = new IMember[_memberNames.Count]; // Copy the count because _memberNames may be cleared before the // loop finishes executing. int count = _memberNames.Count; for (int i = 0; i < count; ++i) { var capturedI = i; typeDb.ReadMember(name, (Dictionary<string, object>)_memberNames[i], (_, member) => AddType(capturedI, member), container); } }
private IMember[] GetMultipleMembers(string memberName, IMemberContainer container, object[] memsArray) { IMember[] finalMembers = new IMember[memsArray.Length]; for (int i = 0; i < finalMembers.Length; i++) { var curMember = memsArray[i] as Dictionary <string, object>; var tmp = i; // close over the current value of i, not the last one... if (curMember != null) { ReadMember(memberName, curMember, (name, newMemberValue) => finalMembers[tmp] = newMemberValue, container); } } return(finalMembers); }
public override float Value(IMemberContainer member) { List <RenderedTileInfo> renderedNodes = new List <RenderedTileInfo>(((MemberTilePCG)member).renderedTiles.Values); float maxDistance = 0; foreach (RenderedTileInfo n in renderedNodes) { if (n.location.magnitude > maxDistance) { maxDistance = n.location.magnitude; } } return(maxDistance); }
private TypeHandle(Type type) { _type = type; _fullName = type.FullName ?? type.Name; if (type.BaseType != null) { _baseCache = GetMemberCache(type.BaseType); _baseContainer = _baseCache.Container; } else if (type.IsInterface) { _baseCache = TypeManager.LookupBaseInterfacesCache(type); } _isInterface = type.IsInterface || TypeManager.IsGenericParameter(type); _memberCache = new MemberCache(this); }
public CJProperty(ITypeDatabaseReader typeDb, Dictionary<string, object> valueDict, IMemberContainer container) { _declaringModule = CJModule.GetDeclaringModuleFromContainer(container); object value; if (valueDict.TryGetValue("doc", out value)) { _doc = value as string; } object type; valueDict.TryGetValue("type", out type); _hasLocation = JTypeDatabase.TryGetLocation(valueDict, ref _line, ref _column); typeDb.LookupType(type, (typeValue, fromInstanceDb) => _type = typeValue); }
public CPythonMultipleMembers(IMemberContainer container, ITypeDatabaseReader typeDb, string name, IEnumerable <object> members) { _members = new List <IMember>(); _memberNames = members.OfType <Dictionary <string, object> >().ToList <object>(); _memberObjects = new IMember[_memberNames.Count]; // Copy the count because _memberNames may be cleared before the // loop finishes executing. int count = _memberNames.Count; for (int i = 0; i < count; ++i) { var capturedI = i; typeDb.ReadMember(name, (Dictionary <string, object>)_memberNames[i], (_, member) => AddType(capturedI, member), container); } }
public override float Value(IMemberContainer member) { List <TileNode> nodes = ((MemberTilePCG)member).graph.nodes; float val = 0; foreach (TileNode node in nodes) { foreach (TileNode c in node.connectedNodes) { if (node.type != c.type) { val += 1; } } } return(val); }
public override float Value(IMemberContainer member) { Dictionary <TileNode, RenderedTileInfo> nodes = ((MemberTilePCG)member).renderedTiles; Vector3 maxLoc = Vector3.zero; foreach (KeyValuePair <TileNode, RenderedTileInfo> node in nodes) { if (node.Key.type == TileGraphPCG.tileMap["1Door"]) { if (node.Value.location.magnitude > maxLoc.magnitude) { maxLoc = node.Value.location; } } } return(maxLoc.magnitude); }
public CPythonProperty(ITypeDatabaseReader typeDb, Dictionary<string, object> valueDict, IMemberContainer container) { _declaringModule = CPythonModule.GetDeclaringModuleFromContainer(container); object value; if (valueDict.TryGetValue("doc", out value)) { _doc = value as string; } object type; if (!valueDict.TryGetValue("type", out type) || type == null) { type = new[] { null, "object" }; } _hasLocation = PythonTypeDatabase.TryGetLocation(valueDict, ref _line, ref _column); typeDb.LookupType(type, typeValue => _type = typeValue); }
public CPythonType(IMemberContainer parent, TypeDatabase typeDb, string typeName, Dictionary <string, object> typeTable, BuiltinTypeId typeId) { Debug.Assert(parent is CPythonType || parent is CPythonModule); _typeName = typeName; _typeId = typeId; _module = GetDeclaringModule(parent); object value; if (typeTable.TryGetValue("is_hidden", out value)) { _includeInModule = !Convert.ToBoolean(value); } else { _includeInModule = true; } if (typeTable.TryGetValue("doc", out value)) { _doc = value as string; } if (typeTable.TryGetValue("builtin", out value)) { _isBuiltin = Convert.ToBoolean(value); } else { _isBuiltin = true; } object membersData; if (typeTable.TryGetValue("members", out membersData)) { var membersTable = membersData as Dictionary <string, object>; if (membersTable != null) { LoadMembers(typeDb, membersTable); } } }
public MemberCache(Type[] ifaces) { // // The members of this cache all belong to other caches. // So, 'Container' will not be used. // Container = null; MemberHash = new Hashtable(); if (ifaces == null) { return; } foreach (var itype in ifaces) { AddCacheContents(TypeHandle.GetMemberCache(itype)); } }
private static MemberComparison CompareMembers(IMemberContainer m1, List <float> v1, IMemberContainer m2, List <float> v2) { bool isGreaterInOneDimension = false; bool isLessInOneDimension = false; for (int i = 0; i < v1.Count; i++) { if (variables[i].IsPositive()) { if (v1[i] > v2[i]) { isGreaterInOneDimension = true; } else { isLessInOneDimension = true; } } else { if (v1[i] < v2[i]) { isGreaterInOneDimension = true; } else { isLessInOneDimension = true; } } } // The new solution is dominated. if (!isGreaterInOneDimension) { return(MemberComparison.DOMINATED); } // This existing solution is dominated by the new solution. if (!isLessInOneDimension) { return(MemberComparison.DOMINATES); } return(MemberComparison.NEUTRAL); }
/// <summary> /// Add all members from class `container' with the requested MemberTypes and /// BindingFlags to the cache. This method is called multiple times with different /// MemberTypes and BindingFlags. /// </summary> private void AddMembers(MemberTypes mt, BindingFlags bf, IMemberContainer container) { var members = container.GetMembers(mt, bf); foreach (var member in members) { var name = member.Name; AddMember(mt, bf, container, name, member); if (member is MethodInfo) { var gname = TypeManager.GetMethodName((MethodInfo)member); if (gname != name) { AddMember(mt, bf, container, gname, member); } } } }
public PropertyInfo(PropertyDeclarationSyntax decl, IMemberContainer parent) { Name = decl.Identifier.Text; if (decl.HasLeadingTrivia) { Documentation = GetDocumentation(decl.GetLeadingTrivia()); } Parent = parent; _modifiers = decl.Modifiers .ParseModifiers() .WithDefaultVisibility(Parent is InterfaceInfo ? Modifier.Public : Modifier.Private); ReturnType = decl.Type.ToString(); var accessors = decl.AccessorList?.Accessors .Select(a => new AccessorInfo(a, this)); if (accessors != null) { Setter = accessors.FirstOrDefault(a => a.IsSetter); Getter = accessors.FirstOrDefault(a => a.IsGetter); } else if (decl.ExpressionBody != null) { Getter = new AccessorInfo(this); } _parameters = new List <ParameterInfo>(); Signature = $"{ReturnType} {Name} " + "{"; if (HasGetter) { Signature += Getter.ToString(); } if (HasSetter) { Signature += Setter.ToString(); } Signature += " }"; }
/// <summary>Add all members from class `container' to the cache.</summary> private void AddMembers(IMemberContainer container) { // We need to call AddMembers() with a single member type at a time // to get the member type part of CacheEntry.EntryType right. if (!container.IsInterface) { AddMembers(MemberTypes.Constructor, container); AddMembers(MemberTypes.Field, container); } AddMembers(MemberTypes.Method, container); AddMembers(MemberTypes.Property, container); AddMembers(MemberTypes.Event, container); // Nested types are returned by both Static and Instance searches. AddMembers( MemberTypes.NestedType, BindingFlags.Static | BindingFlags.Public, container); AddMembers( MemberTypes.NestedType, BindingFlags.Static | BindingFlags.NonPublic, container); }
public void ReadMember(string memberName, Dictionary<string, object> memberValue, Action<string, IMember> assign, IMemberContainer container, JTypeDatabase instanceDb = null) { object memberKind; object value; Dictionary<string, object> valueDict; if (memberValue.TryGetValue("value", out value) && (valueDict = (value as Dictionary<string, object>)) != null && memberValue.TryGetValue("kind", out memberKind) && memberKind is string) { switch ((string)memberKind) { case "function": if (CheckVersion(valueDict)) { assign(memberName, new CJFunction(this, memberName, valueDict, container)); } break; case "func_ref": string funcName; if (valueDict.TryGetValue("func_name", out value) && (funcName = value as string) != null) { var names = funcName.Split('.'); IJModule mod; if (_modules.TryGetValue(names[0], out mod) || (instanceDb != null && instanceDb._modules.TryGetValue(names[0], out mod))) { if (names.Length == 2) { var mem = mod.GetMember(null, names[1]); if (mem == null) { AddFixup(() => { var tmp = mod.GetMember(null, names[1]); if (tmp != null) { assign(memberName, tmp); } }); } else { assign(memberName, mem); } } else { LookupType(new object[] { names[0], names[1] }, (type, fromInstanceDb) => { var mem = type.GetMember(null, names[2]); if (mem != null) { assign(memberName, mem); } }, instanceDb); } } } break; case "method": if (CheckVersion(valueDict)) { assign(memberName, new CJMethodDescriptor(this, memberName, valueDict, container)); } break; case "property": if (CheckVersion(valueDict)) { assign(memberName, new CJProperty(this, valueDict, container)); } break; case "data": object typeInfo; if (valueDict.TryGetValue("type", out typeInfo) && CheckVersion(valueDict)) { LookupType( typeInfo, (dataType, fromInstanceDb) => { assign(memberName, fromInstanceDb ? instanceDb.GetConstant(dataType) : GetConstant(dataType)); }, instanceDb ); } break; case "type": if (CheckVersion(valueDict)) { assign(memberName, MakeType(memberName, valueDict, container)); } break; case "multiple": object members; object[] memsArray; if (valueDict.TryGetValue("members", out members) && (memsArray = members as object[]) != null) { IMember[] finalMembers = GetMultipleMembers(memberName, container, memsArray, instanceDb); assign(memberName, new CJMultipleMembers(finalMembers)); } break; case "typeref": object typeName; if (valueDict.TryGetValue("type_name", out typeName)) { LookupType(typeName, (dataType, fromInstanceDb) => { assign(memberName, dataType); }, instanceDb); } break; case "moduleref": object modName; if (!valueDict.TryGetValue("module_name", out modName) || !(modName is string)) { throw new InvalidOperationException("Failed to find module name: " + modName); } assign(memberName, GetModule((string)modName, instanceDb)); break; } } }
public void ReadMember( string memberName, Dictionary<string, object> memberValue, Action<string, IMember> assign, IMemberContainer container ) { object memberKind; object value; Dictionary<string, object> valueDict; List<object> valueList; object[] valueArray; if (memberValue.TryGetValue("value", out value) && memberValue.TryGetValue("kind", out memberKind) && memberKind is string) { if ((valueDict = (value as Dictionary<string, object>)) != null) { switch ((string)memberKind) { case "function": if (CheckVersion(memberValue)) { assign(memberName, new CPythonFunction(this, memberName, valueDict, container)); } break; case "funcref": string funcName; if (valueDict.TryGetValue("func_name", out value) && (funcName = value as string) != null) { ResolveMemberRef(funcName.Split('.'), memberName, assign); } break; case "method": if (CheckVersion(memberValue)) { assign(memberName, new CPythonMethodDescriptor(this, memberName, valueDict, container)); } break; case "property": if (CheckVersion(memberValue)) { assign(memberName, new CPythonProperty(this, valueDict, container)); } break; case "data": object typeInfo; if (valueDict.TryGetValue("type", out typeInfo) && CheckVersion(memberValue)) { LookupType( typeInfo, dataType => { if (!(dataType is IPythonSequenceType)) { assign(memberName, GetConstant(dataType)); } else { assign(memberName, dataType); } } ); } break; case "type": if (CheckVersion(memberValue)) { assign(memberName, MakeType(memberName, valueDict, container)); } break; case "multiple": object members; object[] memsArray; if (valueDict.TryGetValue("members", out members) && (memsArray = members as object[]) != null) { assign(memberName, new CPythonMultipleMembers(container, this, memberName, memsArray)); } break; default: Debug.Fail("Unexpected member kind: " + (string)memberKind); break; } } else if ((valueList = value as List<object>) != null) { switch ((string)memberKind) { case "typeref": if (CheckVersion(memberValue)) { LookupType(valueList, dataType => assign(memberName, dataType)); } break; default: Debug.Fail("Unexpected member kind: " + (string)memberKind); break; } } else if ((valueArray = value as object[]) != null) { switch ((string)memberKind) { case "moduleref": string modName; if (valueArray.Length >= 1 && !string.IsNullOrEmpty(modName = valueArray[0] as string)) { var module = GetModule(modName); if (module == null) { List<Action<IMember>> fixups; if (!_moduleFixups.TryGetValue(modName, out fixups)) { _moduleFixups[modName] = fixups = new List<Action<IMember>>(); } fixups.Add(m => assign(memberName, m)); } else { assign(memberName, module); } } break; default: Debug.Fail("Unexpected member kind: " + (string)memberKind); break; } } } }
private CPythonType MakeType(string typeName, Dictionary<string, object> valueDict, IMemberContainer container) { BuiltinTypeId typeId = BuiltinTypeId.Unknown; if (container is IBuiltinPythonModule) { typeId = GetBuiltinTypeId(typeName); } return new CPythonType(container, this, typeName, valueDict, typeId); }
public CacheEntry (IMemberContainer container, MemberInfo member, MemberTypes mt, BindingFlags bf) { this.Container = container; this.Member = member; this.EntryType = GetEntryType (mt, bf); }
private IMember[] GetMultipleMembers(string memberName, IMemberContainer container, object[] memsArray, JTypeDatabase instanceDb = null) { IMember[] finalMembers = new IMember[memsArray.Length]; for (int i = 0; i < finalMembers.Length; i++) { var curMember = memsArray[i] as Dictionary<string, object>; var tmp = i; // close over the current value of i, not the last one... if (curMember != null) { ReadMember(memberName, curMember, (name, newMemberValue) => finalMembers[tmp] = newMemberValue, container, instanceDb); } } return finalMembers; }
void AddMember (MemberTypes mt, BindingFlags bf, IMemberContainer container, string name, MemberInfo member) { // We use a name-based hash table of ArrayList's. ArrayList list = (ArrayList) member_hash [name]; if (list == null) { list = new ArrayList (1); member_hash.Add (name, list); } // When this method is called for the current class, the list will // already contain all inherited members from our base classes. // We cannot add new members in front of the list since this'd be an // expensive operation, that's why the list is sorted in reverse order // (ie. members from the current class are coming last). list.Add (new CacheEntry (container, member, mt, bf)); }
/// <summary> /// Add all members from class `container' with the requested MemberTypes and /// BindingFlags to the cache. This method is called multiple times with different /// MemberTypes and BindingFlags. /// </summary> void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container) { MemberList members = container.GetMembers (mt, bf); foreach (MemberInfo member in members) { string name = member.Name; AddMember (mt, bf, container, name, member); if (member is MethodInfo) { string gname = TypeManager.GetMethodName ((MethodInfo) member); if (gname != name) AddMember (mt, bf, container, gname, member); } } }
internal static CJModule GetDeclaringModuleFromContainer(IMemberContainer declaringType) { return (declaringType as CJModule) ?? (CJModule)((CJType)declaringType).DeclaringModule; }
private CJModule GetDeclaringModule(IMemberContainer parent) { return parent as CJModule ?? (CJModule)((CJType)parent).DeclaringModule; }
/// <summary> /// Populates our TypeBuilder with fields and methods /// </summary> public override bool DefineMembers (TypeContainer parent) { MemberInfo [] defined_names = null; if (interface_order != null){ foreach (Interface iface in interface_order) if ((iface.ModFlags & Modifiers.NEW) == 0) iface.DefineMembers (this); else Error_KeywordNotAllowed (iface.Location); } if (RootContext.WarningLevel > 1){ Type ptype; // // This code throws an exception in the comparer // I guess the string is not an object? // ptype = TypeBuilder.BaseType; if (ptype != null){ defined_names = (MemberInfo []) FindMembers ( ptype, MemberTypes.All & ~MemberTypes.Constructor, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static, null, null); Array.Sort (defined_names, mif_compare); } } if (constants != null) DefineMembers (constants, defined_names); if (fields != null) DefineMembers (fields, defined_names); if (this is Class){ if (instance_constructors == null){ if (default_constructor == null) DefineDefaultConstructor (false); } if (initialized_static_fields != null && default_static_constructor == null) DefineDefaultConstructor (true); } if (this is Struct){ // // Structs can not have initialized instance // fields // if (initialized_static_fields != null && default_static_constructor == null) DefineDefaultConstructor (true); if (initialized_fields != null) ReportStructInitializedInstanceError (); } Pending = PendingImplementation.GetPendingImplementations (this); // // Constructors are not in the defined_names array // if (instance_constructors != null) DefineMembers (instance_constructors, null); if (default_static_constructor != null) default_static_constructor.Define (this); if (methods != null) DefineMembers (methods, defined_names); if (properties != null) DefineMembers (properties, defined_names); if (events != null) DefineMembers (events, defined_names); if (indexers != null) { DefineIndexers (); } else IndexerName = "Item"; if (operators != null){ DefineMembers (operators, null); CheckPairedOperators (); } if (enums != null) DefineMembers (enums, defined_names); if (delegates != null) DefineMembers (delegates, defined_names); #if CACHE if (TypeBuilder.BaseType != null) parent_container = TypeManager.LookupMemberContainer (TypeBuilder.BaseType); member_cache = new MemberCache (this); #endif return true; }
/// <summary> /// Create a new MemberCache for the given IMemberContainer `container'. /// </summary> public MemberCache (IMemberContainer container) { this.Container = container; Timer.IncrementCounter (CounterType.MemberCache); Timer.StartTimer (TimerType.CacheInit); // If we have a base class (we have a base class unless we're // TypeManager.object_type), we deep-copy its MemberCache here. if (Container.BaseCache != null) member_hash = SetupCache (Container.BaseCache); else member_hash = new Hashtable (); // If this is neither a dynamic type nor an interface, create a special // method cache with all declared and inherited methods. Type type = container.Type; if (!(type is TypeBuilder) && !type.IsInterface && // !(type.IsGenericType && (type.GetGenericTypeDefinition () is TypeBuilder)) && !TypeManager.IsGenericType (type) && !TypeManager.IsGenericParameter (type) && (Container.BaseCache == null || Container.BaseCache.method_hash != null)) { method_hash = new Hashtable (); AddMethods (type); } // Add all members from the current class. AddMembers (Container); Timer.StopTimer (TimerType.CacheInit); }
public MemberCache (Type baseType, IMemberContainer container) { this.Container = container; if (baseType == null) this.member_hash = new Hashtable (); else this.member_hash = SetupCache (TypeManager.LookupMemberCache (baseType)); }
public MemberCache (Type[] ifaces) { // // The members of this cache all belong to other caches. // So, 'Container' will not be used. // this.Container = null; member_hash = new Hashtable (); if (ifaces == null) return; foreach (Type itype in ifaces) AddCacheContents (TypeManager.LookupMemberCache (itype)); }
public static IAnalysisItemView Make(IModuleContext context, IMemberContainer members, string name) { return Make(context, name, members.GetMember(context, name)); }
public MemberCache (IMemberContainer container, Type base_class, Type[] ifaces) { this.Container = container; // If we have a base class (we have a base class unless we're // TypeManager.object_type), we deep-copy its MemberCache here. if (Container.BaseCache != null) member_hash = SetupCache (Container.BaseCache); else member_hash = new Hashtable (); if (base_class != null) AddCacheContents (TypeManager.LookupMemberCache (base_class)); if (ifaces != null) { foreach (Type itype in ifaces) { MemberCache cache = TypeManager.LookupMemberCache (itype); if (cache != null) AddCacheContents (cache); } } }
/// <summary> /// Add all members from class `container' to the cache. /// </summary> void AddMembers (IMemberContainer container) { // We need to call AddMembers() with a single member type at a time // to get the member type part of CacheEntry.EntryType right. if (!container.IsInterface) { AddMembers (MemberTypes.Constructor, container); AddMembers (MemberTypes.Field, container); } AddMembers (MemberTypes.Method, container); AddMembers (MemberTypes.Property, container); AddMembers (MemberTypes.Event, container); // Nested types are returned by both Static and Instance searches. AddMembers (MemberTypes.NestedType, BindingFlags.Static | BindingFlags.Public, container); AddMembers (MemberTypes.NestedType, BindingFlags.Static | BindingFlags.NonPublic, container); }
void ITypeDatabaseReader.ReadMember(string memberName, Dictionary<string, object> memberValue, Action<string, IMember> assign, IMemberContainer container) { _sharedState.ReadMember(memberName, memberValue, assign, container); }
void AddMembers (MemberTypes mt, IMemberContainer container) { AddMembers (mt, BindingFlags.Static | BindingFlags.Public, container); AddMembers (mt, BindingFlags.Static | BindingFlags.NonPublic, container); AddMembers (mt, BindingFlags.Instance | BindingFlags.Public, container); AddMembers (mt, BindingFlags.Instance | BindingFlags.NonPublic, container); }
public CJMethodDescriptor(ITypeDatabaseReader typeDb, string name, Dictionary<string, object> valueDict, IMemberContainer declaringType) { _name = name; _func = new CJFunction(typeDb, name, valueDict, declaringType, isMethod: true); }
void ITypeDatabaseReader.ReadMember(string memberName, Dictionary<string, object> memberValue, Action<string, IMember> assign, IMemberContainer container, JTypeDatabase instanceDb) { Debug.Assert(instanceDb == null); _sharedState.ReadMember(memberName, memberValue, assign, container, this); }