/// <inheritdoc /> public virtual IConstant CreateConstantValue(TypeHandle constantTypeHandle) { var nodeType = GetConstantNodeValueType(constantTypeHandle); var instance = (IConstant)Activator.CreateInstance(nodeType); instance.ObjectValue = instance.DefaultValue; return(instance); }
public CreateSystemConstantNodeAction(string name, TypeHandle returnType, TypeHandle declaringType, string identifier, Vector2 position) { Name = name; ReturnType = returnType; DeclaringType = declaringType; Identifier = identifier; Position = position; }
public ITypeMetadata Resolve(TypeHandle th) { if (!m_MetadataCache.TryGetValue(th, out ITypeMetadata metadata)) { metadata = m_MetadataCache[th] = m_Factory.Create(th); } return(metadata); }
public ITypeMetadata Resolve(TypeHandle th) { if (!m_MetadataCache.TryGetValue(th, out ITypeMetadata metadata)) { metadata = m_MetadataCache.GetOrAdd(th, t => new CSharpTypeBasedMetadata(m_GraphContext, t, th.Resolve(m_GraphContext.CSharpTypeSerializer))); } return(metadata); }
public static ValueType TypeHandleToValueTypeOrUnknown(this TypeHandle handle) { if (handle.TryTypeHandleToValueType(out var typeHandleToValueType)) { return(typeHandleToValueType); } return(ValueType.Unknown); }
public static ValueType TypeHandleToValueType(this TypeHandle handle) { if (handle.TryTypeHandleToValueType(out var typeHandleToValueType)) { return(typeHandleToValueType); } throw new ArgumentOutOfRangeException(nameof(handle), "Unknown typehandle"); }
public override bool IsArgPassedByRef(TypeHandle th) { Debug.Assert(!th.IsNull()); Debug.Assert(th.IsValueType()); // Composites greater than 16 bytes are passed by reference return((th.GetSize() > EnregisteredParamTypeMaxSize) && !th.IsHFA()); }
public CSharpTypeBasedMetadata(GraphContext memberConstrainer, TypeHandle typeHandle, Type type) { TypeHandle = typeHandle; m_Serializer = memberConstrainer.CSharpTypeSerializer; m_MemberConstrainer = memberConstrainer; m_Type = type; }
public override void OnConnection(IPortModel selfConnectedPortModel, IPortModel otherConnectedPortModel) { if (ReferenceEquals(InstancePort, selfConnectedPortModel)) { TypeHandle t = otherConnectedPortModel?.DataTypeHandle ?? TypeHandle.Unknown; InstancePort.DataTypeHandle = t; ValuePort.DataTypeHandle = t; } }
public AddComponentToQueryAction(ComponentQueryDeclarationModel componentQueryDeclarationModel, TypeHandle typeHandle, ComponentDefinitionFlags creationFlags ) { ComponentQueryDeclarationModel = componentQueryDeclarationModel; TypeHandle = typeHandle; CreationFlags = creationFlags; }
public SearcherFilter WithIfConditions(TypeHandle inputType, IStackModel stackModel) { this.RegisterControlFlow(data => data.Type == typeof(IfConditionNodeModel) && stackModel.AcceptNode(data.Type) && inputType == TypeHandle.Bool ); return(this); }
public QueryComponent(TypeHandle componentType) { Component = new ComponentDefinition { IsShared = false, TypeHandle = componentType, Subtract = false, }; }
/// <summary> /// Initializes a new CreateGraphVariableDeclarationCommand. /// </summary> /// <remarks>This constructor will create the graph's default variable declaration.</remarks> /// <param name="name">The name of the variable to create.</param> /// <param name="isExposed">Whether or not the variable is exposed.</param> /// <param name="typeHandle">The type of data the new variable declaration to create represents.</param> /// <param name="modifierFlags">The modifiers to apply to the newly created variable.</param> /// <param name="guid">The SerializableGUID to assign to the newly created item. If none is provided, a new /// SerializableGUID will be generated for it.</param> public CreateGraphVariableDeclarationCommand(string name, bool isExposed, TypeHandle typeHandle, ModifierFlags modifierFlags = ModifierFlags.None, SerializableGUID guid = default) : this() { VariableName = name; IsExposed = isExposed; TypeHandle = typeHandle; Guid = guid.Valid ? guid : SerializableGUID.Generate(); ModifierFlags = modifierFlags; }
public PropertySearcherItemsBuilder(int maxRecursiveDepth, TypeHandle rootTypeHandle, ITypeMetadataResolver resolver, HashSet <int> existingMembers) { m_MaxRecursiveDepth = maxRecursiveDepth; m_RootTypeHandle = rootTypeHandle; m_Resolver = resolver; m_RecursiveFlags = BindingFlags.Public | BindingFlags.Instance; m_RootFlags = BindingFlags.NonPublic | m_RecursiveFlags; m_ExistingMembers = existingMembers; }
public override void RecordComponentAccess( RoslynEcsTranslator.IterationContext group, TypeHandle componentType, RoslynEcsTranslator.AccessMode mode) { if (mode > RoslynEcsTranslator.AccessMode.Read) { m_WrittenComponentsPerGroup[group].WrittenComponents.Add(componentType); } }
public TypeMethodHandle ReadMethod(BaseJIT jit, MethodDefinitionHandle methodHandle) { MethodDefinition methodDefinition = this.metadata.GetMethodDefinition(methodHandle); TypeDefinition typeDefinition = this.metadata.GetTypeDefinition(methodDefinition.GetDeclaringType()); TypeHandle typeHandle = this.typeLoader.LoadType(this.metadata, typeDefinition); MethodBodyBlock methodBody = this.peReader.GetMethodBody(methodDefinition.RelativeVirtualAddress); return(typeHandle.LoadMethod(jit, this, this.metadata, methodHandle, methodBody)); }
public void Test_TypeHandleDeserializationOfRegularType() { //Arrange TypeHandle th = typeof(A).GenerateTypeHandle(m_TypeSerializer); //Act Type deserializedTypeHandle = th.Resolve(m_TypeSerializer); //Assert Assert.That(deserializedTypeHandle, Is.EqualTo(typeof(A))); }
public void Test_TypeHandle() { //Arrange var typeMetadata = CreateMetadata(typeof(float)); //Act TypeHandle handle = typeMetadata.TypeHandle; //Assert Assert.That(handle, Is.EqualTo(m_Handle)); }
public void MethodImplEntry() { var text = @" public class A { ~A() { } } "; CompileAndVerify(text, assemblyValidator: (assembly, _) => { var peFileReader = assembly.GetMetadataReader(); // Find the handle and row for A. var pairA = peFileReader.TypeDefinitions.AsEnumerable(). Select(handle => new { handle = handle, row = peFileReader.GetTypeDefinition(handle) }). Single(pair => peFileReader.GetString(pair.row.Name) == "A" && string.IsNullOrEmpty(peFileReader.GetString(pair.row.Namespace))); TypeHandle handleA = pairA.handle; TypeDefinition typeA = pairA.row; // Find the handle for A's destructor. MethodHandle handleDestructorA = typeA.GetMethods().AsEnumerable(). Single(handle => peFileReader.GetString(peFileReader.GetMethod(handle).Name) == WellKnownMemberNames.DestructorName); // Find the handle for System.Object. TypeReferenceHandle handleObject = peFileReader.TypeReferences.AsEnumerable(). Select(handle => new { handle = handle, row = peFileReader.GetTypeReference(handle) }). Single(pair => peFileReader.GetString(pair.row.Name) == "Object" && peFileReader.GetString(pair.row.Namespace) == "System").handle; // Find the handle for System.Object's destructor. MemberReferenceHandle handleDestructorObject = peFileReader.MemberReferences.AsEnumerable(). Select(handle => new { handle = handle, row = peFileReader.GetMemberReference(handle) }). Single(pair => pair.row.Parent == (Handle)handleObject && peFileReader.GetString(pair.row.Name) == WellKnownMemberNames.DestructorName).handle; // Find the MethodImpl row for A. MethodImpl methodImpl = typeA.GetMethodImplementations().AsEnumerable(). Select(handle => peFileReader.GetMethodImplementation(handle)). Single(); // The Class column should point to A. Assert.Equal(handleA, methodImpl.Type); // The MethodDeclaration column should point to System.Object.Finalize. Assert.Equal((Handle)handleDestructorObject, methodImpl.MethodDeclaration); // The MethodDeclarationColumn should point to A's destructor. Assert.Equal((Handle)handleDestructorA, methodImpl.MethodBody); }); }
public void Test_TypeHandle() { //Arrange var graphMetadata = CreateGraphMetadata(); //Act TypeHandle handle = graphMetadata.TypeHandle; //Assert Assert.That(handle, Is.EqualTo(s_GraphTypeHandle)); }
public ITypeMetadata Create(TypeHandle th) { foreach (var factory in m_Factories) { if (factory.CanProcessHandle(th)) { return(factory.Create(th)); } } return(EmptyTypeMetadata.Instance); }
public void SolveTypeArguments(ClassType t, string methodName, Type connectedType, int parameterIndex) { Type methodDeclaringType = t == ClassType.Plain ? typeof(C) : typeof(D <>); MethodBase m = methodDeclaringType.GetMethod(methodName); TypeHandle[] typeReferences = new TypeHandle[1]; Assume.That(m, Is.Not.Null); Type[] genericTypes = null; GenericsInferenceSolver.SolveTypeArguments(Stencil, m, ref genericTypes, ref typeReferences, connectedType, parameterIndex); Assert.That(genericTypes.Length, Is.EqualTo(1)); Assert.That(typeReferences[0].Resolve(Stencil), Is.EqualTo(typeof(float))); }
public GraphElementSearcherDatabase AddGraphsMethods() { string[] assetGUIDs = AssetDatabase.FindAssets($"t:{typeof(VSGraphAssetModel).Name}"); List <Tuple <IGraphModel, FunctionModel> > methods = assetGUIDs.SelectMany(assetGuid => { string assetPath = AssetDatabase.GUIDToAssetPath(assetGuid); VSGraphAssetModel graphAssetModel = AssetDatabase.LoadAssetAtPath <VSGraphAssetModel>(assetPath); if (!graphAssetModel || graphAssetModel.GraphModel == null) { return(Enumerable.Empty <Tuple <IGraphModel, FunctionModel> >()); } var functionModels = graphAssetModel.GraphModel.NodeModels.OfExactType <FunctionModel>() .Select(fm => new Tuple <IGraphModel, FunctionModel>(fm.GraphModel, fm)); return(functionModels.Concat(graphAssetModel.GraphModel.NodeModels.OfExactType <EventFunctionModel>() .Select(fm => new Tuple <IGraphModel, FunctionModel>(fm.GraphModel, fm)))); }).ToList(); if (methods.Count == 0) { return(this); } TypeHandle voidTypeHandle = typeof(void).GenerateTypeHandle(Stencil); foreach (Tuple <IGraphModel, FunctionModel> method in methods) { IGraphModel graphModel = method.Item1; FunctionModel functionModel = method.Item2; string graphName = graphModel.AssetModel.Name; SearcherItem graphRoot = SearcherItemUtility.GetItemFromPath(Items, $"{k_Graphs}/{graphName}"); if (functionModel.ReturnType == voidTypeHandle) { graphRoot.AddChild(new StackNodeModelSearcherItem( new FunctionRefSearcherItemData(graphModel, functionModel), data => data.CreateFunctionRefCallNode(functionModel), () => $"{k_Function} {functionModel.Title}" )); continue; } graphRoot.AddChild(new GraphNodeModelSearcherItem( new FunctionRefSearcherItemData(graphModel, functionModel), data => data.CreateFunctionRefCallNode(functionModel), () => $"{k_Function} {functionModel.Title}" )); } return(this); }
public void Test_TypeHandleDeserializationOfRenamedType() { var typeSerializer = new CSharpTypeSerializer(new Dictionary <string, string> { { typeof(A).AssemblyQualifiedName, typeof(B).AssemblyQualifiedName } }); TypeHandle th = typeof(A).GenerateTypeHandle(typeSerializer); Type deserializedTypeHandle = th.Resolve(typeSerializer); Assert.That(deserializedTypeHandle, Is.EqualTo(typeof(B))); }
static IConstantNodeModel CreateConstantNodeModel(GraphModel graphModel, string constantName, Type nodeType, TypeHandle constantTypeHandle, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default) { void PreDefineSetup(NodeModel model) { if (model is ConstantNodeModel constantModel) { constantModel.PredefineSetup(constantTypeHandle); } } return(graphModel.CreateModel <ConstantNodeModel>(nodeType, constantName, position, spawnFlags, PreDefineSetup)); }
public void RemoveComponent(QueryGroup gc, TypeHandle toRemove) { for (int i = 0; i < gc.ComponentCount; i++) { if (Components[gc.ComponentStartIndex + i].Component.TypeHandle == toRemove) { Components.RemoveAt(gc.ComponentStartIndex + i); gc.ComponentCount--; RecomputeAll(); return; } } }
public void Test_TypeHandle_WithNestedType_Resolve_ChangedAssembly_WithMovedFromAttribute() { var typeStr = typeof(EnclosingType.InnerTypeUnchanged).AssemblyQualifiedName; var originalTypeStr = typeStr? .Replace("NewNamespace", "OldNamespace") .Replace("GraphTools.", "OldAssemblyName."); var typeHandle = new TypeHandle(originalTypeStr); var resolvedType = typeHandle.Resolve(); Assert.AreEqual(typeof(EnclosingType.InnerTypeUnchanged), resolvedType); }
protected override IVariableDeclarationModel InstantiateVariableDeclaration(Type variableTypeToCreate, TypeHandle variableDataType, string variableName, ModifierFlags modifierFlags, bool isExposed, IConstant initializationModel, SerializableGUID guid, Action <IVariableDeclarationModel, IConstant> initializationCallback = null) { var vdm = base.InstantiateVariableDeclaration(variableTypeToCreate, variableDataType, variableName, modifierFlags, isExposed, initializationModel, guid, initializationCallback); if (vdm is VariableDeclarationModel testVdm) { testVdm.SetGraphModel(this); } return(vdm); }
public void ConnectingANonGenericParameterDoesntAffectTypeParameters() { Type methodDeclaringType = typeof(C); MethodBase m = methodDeclaringType.GetMethod("I"); TypeHandle[] typeReferences = new TypeHandle[1]; Assume.That(m, Is.Not.Null); Type[] genericTypes = null; GenericsInferenceSolver.SolveTypeArguments(Stencil, m, ref genericTypes, ref typeReferences, typeof(float), 0); GenericsInferenceSolver.SolveTypeArguments(Stencil, m, ref genericTypes, ref typeReferences, typeof(int), 1); Assert.That(genericTypes.Length, Is.EqualTo(1)); Assert.That(typeReferences[0].Resolve(Stencil), Is.EqualTo(typeof(float))); }
public override IPortModel CreatePort(PortDirection direction, PortOrientation orientation, string portName, PortType portType, TypeHandle dataType, string portId, PortModelOptions options) { return(new FakePortModel(GraphModel) { Direction = direction, Orientation = orientation, Title = portName, PortType = portType, DataTypeHandle = dataType, NodeModel = this }); }
internal override bool TryGetTypeHandle(Cci.ITypeDefinition def, out TypeHandle handle) { var other = this.mapToMetadata.MapDefinition(def) as PENamedTypeSymbol; if ((object)other != null) { handle = other.Handle; return true; } else { handle = default(TypeHandle); return false; } }
/// <summary> /// Returns true if the nested type should be imported. /// </summary> public static bool ShouldImportNestedType(this PEModule module, TypeHandle typeDef) { // Currently, it appears that we must import ALL types, even private ones, // in order to maintain language semantics. This is because a class may implement // private interfaces, and we use the interfaces (even if inaccessible) to determine // conversions. For example: // // public class A: IEnumerable<A.X> // { // private class X: ICloneable {} // } // // Code compiling against A can convert A to IEnumerable<ICloneable>. Knowing this requires // importing the type A.X. return true; }
private static Dictionary<string, EventHandle> GetEventDefs(PEFileReader reader, TypeHandle typeHandle) { var events = new Dictionary<string, EventHandle>(); foreach (var eventHandle in reader.GetTypeDefinition(typeHandle).GetEvents()) { var eventDef = reader.GetEvent(eventHandle); var name = reader.GetString(eventDef.Name); events.Add(name, eventHandle); } return events; }
private TypeInfo GetOrCreateTypeInfo(TypeHandle typeHandle) { TypeInfo typeInfo = null; if (this.compositionTypes.TryGetValue(typeHandle, out typeInfo)) { return typeInfo; } typeInfo = new TypeInfo(isExported: false); typeInfo.MetadataToken = MetadataTokens.GetToken(metadataReader, typeHandle); this.compositionTypes.Add(typeHandle, typeInfo); return typeInfo; }
private TypeDefTreatment GetTypeDefTreatment( TypeHandle typeDef, TypeAttributes flags, string name, string namespaceName, MetadataToken extends) { TypeDefTreatment treatment; // Does the type def have the WindowsRuntime bit set? if (flags.IsWindowsRuntime()) { if (scenario == WinMDScenario.NormalWinMD) { treatment = WinRTProjectedTypes.GetTypeDefinitionTreatment(name, namespaceName); if (treatment != TypeDefTreatment.None) { return treatment; } // Is this an attribute? if (extends.HandleType == HandleType.TypeReference && GetTypeRefTreatment((TypeReferenceHandle)extends) == TypeRefTreatment.SystemAttribute) { treatment = TypeDefTreatment.NormalAttribute; } else { treatment = TypeDefTreatment.NormalNonAttribute; } } else if (scenario == WinMDScenario.WinMDExp && !flags.IsNested() && flags.IsPublic() && flags.IsSpecialName()) { treatment = TypeDefTreatment.PrefixWinRTName; } else { treatment = TypeDefTreatment.None; } // Scan through Custom Attributes on type, looking for interesting bits. We only // need to do this for RuntimeClasses if (treatment == TypeDefTreatment.PrefixWinRTName || treatment == TypeDefTreatment.NormalNonAttribute) { if (!flags.IsInterface() && HasAttribute(typeDef, "Windows.UI.Xaml", "TreatAsAbstractComposableClassAttribute")) { treatment |= TypeDefTreatment.MarkAbstractFlag; } } } else if (this.scenario == WinMDScenario.WinMDExp && IsClrImplementationType(name, flags)) { treatment = TypeDefTreatment.UnmangleWinRTName; } else { treatment = TypeDefTreatment.None; } return treatment; }
public override TypeAttributes GetTypeDefFlags(TypeHandle typeDef) { string name, @namespace; TypeAttributes flags; MetadataToken extends; GetTypeDefProps( typeDef, out name, out @namespace, out flags, out extends); return flags; }
public override void GetTypeDefProps( TypeHandle typeDef, out string name, out string namespaceName, out TypeAttributes flags, out MetadataToken extends) { base.GetTypeDefProps(typeDef, out name, out namespaceName, out flags, out extends); TypeDefTreatment treatment = GetTypeDefTreatment(typeDef, flags, name, namespaceName, extends); switch (treatment & TypeDefTreatment.TreatmentMask) { case TypeDefTreatment.None: break; case TypeDefTreatment.NormalNonAttribute: flags |= TypeAttributes.WindowsRuntime | TypeAttributes.Import; break; case TypeDefTreatment.NormalAttribute: flags |= TypeAttributes.WindowsRuntime | TypeAttributes.Sealed; break; case TypeDefTreatment.UnmangleWinRTName: name = name.Substring(clrPrefix.Length); flags |= TypeAttributes.Public; break; case TypeDefTreatment.PrefixWinRTName: name = winRtPrefix + name; flags &= TypeAttributes.Public; flags |= TypeAttributes.Import; break; case TypeDefTreatment.RedirectedToCLRType: flags &= ~TypeAttributes.Public; flags |= TypeAttributes.Import; break; case TypeDefTreatment.RedirectedToCLRAttribute: flags &= ~TypeAttributes.Public; break; } if (treatment.HasFlag(TypeDefTreatment.MarkAbstractFlag)) { flags |= TypeAttributes.Abstract; } if (treatment.HasFlag(TypeDefTreatment.MarkInternalFlag)) { flags &= ~TypeAttributes.Public; } }
public static string GetFullTypeName(this MetadataReader metadataReader, TypeHandle typeHandle) { var typeDefinition = metadataReader.GetTypeDefinition(typeHandle); return metadataReader.GetFullTypeName(typeDefinition); }
// TODO: Index by signature. private static Dictionary<string, MethodHandle> GetMethodDefs(PEFileReader reader, TypeHandle typeHandle) { var methods = new Dictionary<string, MethodHandle>(); foreach (var methodHandle in reader.GetTypeDefinition(typeHandle).GetMethods()) { var methodDef = reader.GetMethod(methodHandle); var name = reader.GetString(methodDef.Name); methods.Add(name, methodHandle); } return methods; }
private static Dictionary<string, PropertyHandle> GetPropertyDefs(PEFileReader reader, TypeHandle typeHandle) { var properties = new Dictionary<string, PropertyHandle>(); foreach (var propertyHandle in reader.GetTypeDefinition(typeHandle).GetProperties()) { var propertyDef = reader.GetProperty(propertyHandle); var name = reader.GetString(propertyDef.Name); properties.Add(name, propertyHandle); } return properties; }
public TypeFromMetadata(PEFileReader reader, TypeHandle typeHandle) { this.reader = reader; this.typeHandle = typeHandle; }
internal abstract bool TryGetTypeHandle(ITypeDefinition def, out TypeHandle handle);
/// <summary> /// /// Returns the name of the type as specified by the TypeHandle. Note this returns the name as specified by the /// metadata, NOT as you would expect to see it in a C# program. For example, generics are denoted with a ` and /// the number of params. Thus a Dictionary (with two type params) would look like: /// System.Collections.Generics.Dictionary`2 /// </summary> /// <param name="id">The TypeHandle to get the name of.</param> /// <returns>The name of the type, or null on error.</returns> internal string GetTypeName(TypeHandle id) { if (id.MethodTable == FreeMethodTable) return "Free"; if (id.MethodTable == ArrayMethodTable && id.ComponentMethodTable != 0) { string name = GetNameForMT(id.ComponentMethodTable); if (name != null) return name + "[]"; } return GetNameForMT(id.MethodTable); }
private static Dictionary<string, FieldHandle> GetFieldDefs(PEFileReader reader, TypeHandle typeHandle) { var fields = new Dictionary<string, FieldHandle>(); foreach (var fieldHandle in reader.GetTypeDefinition(typeHandle).GetFields()) { var fieldDef = reader.GetField(fieldHandle); var name = reader.GetString(fieldDef.Name); fields.Add(name, fieldHandle); } return fields; }