/// <summary> /// Creates an instance of a class type, or reuse an existing instance. /// </summary> /// <param name="instancingClassType">The class type to instanciate.</param> /// <param name="resolvedTypeName">The proposed type instance name.</param> /// <param name="resolvedType">The proposed type instance.</param> public void InstanciateType(ICompiledTypeWithFeature instancingClassType, ref ITypeName resolvedTypeName, ref ICompiledType resolvedType) { bool IsNewInstance = false; ISealableDictionary <string, ICompiledType> InstancedTypeArgumentTable = new SealableDictionary <string, ICompiledType>(); foreach (KeyValuePair <string, ICompiledType> TypeArgument in TypeArgumentTable) { ITypeName InstancedTypeArgumentName = null; ICompiledType InstancedTypeArgument = TypeArgument.Value; InstancedTypeArgument.InstanciateType(instancingClassType, ref InstancedTypeArgumentName, ref InstancedTypeArgument); InstancedTypeArgumentTable.Add(TypeArgument.Key, InstancedTypeArgument); if (InstancedTypeArgument != TypeArgument.Value) { IsNewInstance = true; } } if (IsNewInstance) { ISealableDictionary <ITypeName, ICompiledType> InstancingTypeTable = instancingClassType.GetTypeTable(); ResolveType(InstancingTypeTable, BaseClass, InstancedTypeArgumentTable, instancingClassType, out resolvedTypeName, out resolvedType); } }
/// <summary> /// Creates a procedure type with resolved arguments. /// </summary> /// <param name="baseTypeName">Name of the resolved base type.</param> /// <param name="baseType">The base type.</param> /// <param name="resolvedBaseType">The resolved base type.</param> /// <param name="overloadList">The list of resolved overloads.</param> /// <param name="resolvedTypeName">The type name upon return.</param> /// <param name="resolvedType">The type upon return.</param> public static void BuildType(ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, IList <ICommandOverloadType> overloadList, out ITypeName resolvedTypeName, out IProcedureType resolvedType) { IProcedureType ResolvedProcedureType = new ProcedureType(baseTypeName, baseType, resolvedBaseType, overloadList); resolvedTypeName = new TypeName(ResolvedProcedureType.TypeFriendlyName); resolvedType = ResolvedProcedureType; }
/// <summary> /// Creates an instance of a class type, or reuse an existing instance. /// </summary> /// <param name="instancingClassType">The class type to instanciate.</param> /// <param name="resolvedTypeName">The proposed type instance name.</param> /// <param name="resolvedType">The proposed type instance.</param> public void InstanciateType(ICompiledTypeWithFeature instancingClassType, ref ITypeName resolvedTypeName, ref ICompiledType resolvedType) { ISealableDictionary <ITypeName, ICompiledType> TypeTable = GetTypeTable(); Debug.Assert(TypeTable.Count == 0); bool IsNewInstance = false; IList <IEntityDeclaration> InstancedFieldList = new List <IEntityDeclaration>(); foreach (IEntityDeclaration Field in EntityDeclarationList) { Debug.Assert(Field.ValidEntity.IsAssigned); Debug.Assert(Field.ValidEntity.Item.ResolvedEffectiveTypeName.IsAssigned); Debug.Assert(Field.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); ITypeName InstancedFieldTypeName = Field.ValidEntity.Item.ResolvedEffectiveTypeName.Item; ICompiledType InstancedFieldType = Field.ValidEntity.Item.ResolvedEffectiveType.Item; InstancedFieldType.InstanciateType(instancingClassType, ref InstancedFieldTypeName, ref InstancedFieldType); IsNewInstance |= InstancedFieldType != Field.ValidEntity.Item.ResolvedEffectiveType.Item; IEntityDeclaration InstancedField = new EntityDeclaration(Field, InstancedFieldTypeName, InstancedFieldType); InstancedFieldList.Add(InstancedField); } if (IsNewInstance) { ISealableDictionary <ITypeName, ICompiledType> InstancingTypeTable = instancingClassType.GetTypeTable(); ResolveType(InstancingTypeTable, EntityDeclarationList, Sharing, out resolvedTypeName, out resolvedType); } }
/// <summary> /// Creates an instance of a class type, or reuse an existing instance. /// </summary> /// <param name="instancingClassType">The class type to instanciate.</param> /// <param name="resolvedTypeName">The proposed type instance name.</param> /// <param name="resolvedType">The proposed type instance.</param> public void InstanciateType(ICompiledTypeWithFeature instancingClassType, ref ITypeName resolvedTypeName, ref ICompiledType resolvedType) { bool IsNewInstance = false; ITypeName InstancedBaseTypeName = ResolvedBaseTypeName.Item; ICompiledType InstancedBaseType = ResolvedBaseType.Item; InstancedBaseType.InstanciateType(instancingClassType, ref InstancedBaseTypeName, ref InstancedBaseType); IsNewInstance |= InstancedBaseType != ResolvedBaseType.Item; IList <ICommandOverloadType> InstancedOverloadList = new List <ICommandOverloadType>(); foreach (ICommandOverloadType Overload in OverloadList) { ICommandOverloadType InstancedOverload = Overload; CommandOverloadType.InstanciateCommandOverloadType(instancingClassType, ref InstancedOverload); IsNewInstance |= InstancedOverload != Overload; InstancedOverloadList.Add(InstancedOverload); } if (IsNewInstance) { ISealableDictionary <ITypeName, ICompiledType> TypeTable = instancingClassType.GetTypeTable(); ResolveType(TypeTable, InstancedBaseTypeName, (IObjectType)BaseType, (ICompiledTypeWithFeature)InstancedBaseType, InstancedOverloadList, out resolvedTypeName, out IProcedureType ResolvedProcedureType); resolvedType = ResolvedProcedureType; } }
/// <summary> /// Creates a function type with resolved arguments. /// </summary> /// <param name="baseTypeName">The type name of the resolved base type.</param> /// <param name="baseType">The base type.</param> /// <param name="resolvedBaseType">The resolved base type.</param> /// <param name="entityTypeName">The type name of the resolved result type.</param> /// <param name="entityType">The type of the resolved result type.</param> /// <param name="propertyKind">The type of the property.</param> /// <param name="getEnsureList">The list of ensure assertions for the getter.</param> /// <param name="getExceptionIdentifierList">The list of known exceptions thrown for the getter.</param> /// <param name="setRequireList">The list of require assertions for the setter.</param> /// <param name="setExceptionIdentifierList">The list of known exceptions thrown for the setter.</param> /// <param name="resolvedTypeName">The type name upon return.</param> /// <param name="resolvedType">The type upon return.</param> public static void BuildType(ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, ITypeName entityTypeName, ICompiledType entityType, BaseNode.UtilityType propertyKind, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IIdentifier> setExceptionIdentifierList, out ITypeName resolvedTypeName, out ICompiledType resolvedType) { IPropertyType ResolvedPropertyType = new PropertyType(baseTypeName, baseType, resolvedBaseType, entityTypeName, entityType, propertyKind, getEnsureList, getExceptionIdentifierList, setRequireList, setExceptionIdentifierList); resolvedTypeName = new TypeName(ResolvedPropertyType.TypeFriendlyName); resolvedType = ResolvedPropertyType; }
/// <summary> /// Initializes a new instance of the <see cref="ProcedureType"/> class. /// </summary> /// <param name="baseTypeName">Name of the resolved base type.</param> /// <param name="baseType">The base type.</param> /// <param name="resolvedBaseType">The resolved base type.</param> /// <param name="overloadList">The list of resolved overloads.</param> public ProcedureType(ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, IList <ICommandOverloadType> overloadList) : this() { BaseType = baseType; ResolvedBaseTypeName.Item = baseTypeName; ResolvedBaseType.Item = resolvedBaseType; OverloadList = overloadList; }
/// <summary> /// Initializes a new instance of the <see cref="FunctionType"/> class. /// </summary> /// <param name="baseTypeName">Name of the resolved base type.</param> /// <param name="baseType">The base type.</param> /// <param name="resolvedBaseType">The resolved base type.</param> /// <param name="overloadList">The list of resolved overloads.</param> public FunctionType(ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, IList <IQueryOverloadType> overloadList) : this() { BaseType = baseType; ResolvedBaseTypeName.Item = baseTypeName; ResolvedBaseType.Item = resolvedBaseType; OverloadList = overloadList; }
/// <summary> /// Creates an instance of a class type, or reuse an existing instance. /// </summary> /// <param name="instancingClassType">The class type to instanciate.</param> /// <param name="resolvedTypeName">The proposed type instance name.</param> /// <param name="resolvedType">The proposed type instance.</param> public void InstanciateType(ICompiledTypeWithFeature instancingClassType, ref ITypeName resolvedTypeName, ref ICompiledType resolvedType) { bool IsNewInstance = false; ITypeName InstancedBaseTypeName = ResolvedBaseTypeName.Item; ICompiledType InstancedBaseType = ResolvedBaseType.Item; InstancedBaseType.InstanciateType(instancingClassType, ref InstancedBaseTypeName, ref InstancedBaseType); IsNewInstance |= InstancedBaseType != ResolvedBaseType.Item; ITypeName InstancedEntityTypeName = ResolvedEntityTypeName.Item; ICompiledType InstancedEntityType = ResolvedEntityType.Item; InstancedEntityType.InstanciateType(instancingClassType, ref InstancedEntityTypeName, ref InstancedEntityType); IsNewInstance |= InstancedEntityType != ResolvedEntityType.Item; IList <IEntityDeclaration> InstancedIndexParameterList = new List <IEntityDeclaration>(); foreach (IEntityDeclaration Parameter in IndexParameterList) { ITypeName InstancedParameterTypeName = Parameter.ValidEntity.Item.ResolvedEffectiveTypeName.Item; ICompiledType InstancedParameterType = Parameter.ValidEntity.Item.ResolvedEffectiveType.Item; InstancedParameterType.InstanciateType(instancingClassType, ref InstancedParameterTypeName, ref InstancedParameterType); IEntityDeclaration InstancedParameter = new EntityDeclaration(Parameter, InstancedParameterTypeName, InstancedParameterType); IName ParameterName = (Name)Parameter.EntityName; IScopeAttributeFeature NewEntity; if (Parameter.DefaultValue.IsAssigned) { // The default value has already been checked and validated. bool IsCreated = ScopeAttributeFeature.Create(Parameter, ParameterName.ValidText.Item, InstancedParameterTypeName, InstancedParameterType, (IExpression)Parameter.DefaultValue.Item, ErrorList.Ignored, out NewEntity); Debug.Assert(IsCreated); } else { NewEntity = ScopeAttributeFeature.Create(Parameter, ParameterName.ValidText.Item, InstancedParameterTypeName, InstancedParameterType); } IsNewInstance |= InstancedParameterType != Parameter.ValidEntity.Item.ResolvedEffectiveType.Item; InstancedParameter.ValidEntity.Item = NewEntity; InstancedIndexParameterList.Add(InstancedParameter); } if (IsNewInstance) { ISealableDictionary <ITypeName, ICompiledType> TypeTable = instancingClassType.GetTypeTable(); ResolveType(TypeTable, InstancedBaseTypeName, (IClassType)InstancedBaseType, InstancedEntityTypeName, InstancedEntityType, IndexerKind, InstancedIndexParameterList, ParameterEnd, GetRequireList, GetEnsureList, GetExceptionIdentifierList, SetRequireList, SetEnsureList, SetExceptionIdentifierList, out resolvedTypeName, out resolvedType); } }
/// <summary> /// Applies the rule. /// </summary> /// <param name="node">The node instance to modify.</param> /// <param name="data">Private data from CheckConsistency().</param> public override void Apply(IProcedureType node, object data) { IClass EmbeddingClass = node.EmbeddingClass; IObjectType BaseType = (IObjectType)node.BaseType; ITypeName BaseTypeName = BaseType.ResolvedTypeName.Item; ICompiledTypeWithFeature ResolvedBaseType = BaseType.ResolvedType.Item as ICompiledTypeWithFeature; Debug.Assert(BaseType != null); ProcedureType.ResolveType(EmbeddingClass.TypeTable, BaseTypeName, BaseType, ResolvedBaseType, node.OverloadList, out ITypeName ResolvedTypeName, out IProcedureType ResolvedType); node.ResolvedTypeName.Item = ResolvedTypeName; node.ResolvedType.Item = ResolvedType; }
/// <summary> /// Finds or creates an overload type with the corresponding parameters. /// </summary> /// <param name="instancingClassType">The type attempting to find the overload type.</param> /// <param name="instancedOverload">The new overload type upon return if not found.</param> public static void InstanciateCommandOverloadType(ICompiledTypeWithFeature instancingClassType, ref ICommandOverloadType instancedOverload) { bool IsNewInstance = false; IList <IEntityDeclaration> InstancedParameterList = new List <IEntityDeclaration>(); foreach (IEntityDeclaration Parameter in instancedOverload.ParameterList) { ITypeName InstancedParameterTypeName = Parameter.ValidEntity.Item.ResolvedEffectiveTypeName.Item; ICompiledType InstancedParameterType = Parameter.ValidEntity.Item.ResolvedEffectiveType.Item; InstancedParameterType.InstanciateType(instancingClassType, ref InstancedParameterTypeName, ref InstancedParameterType); IEntityDeclaration InstancedParameter = new EntityDeclaration(Parameter, InstancedParameterTypeName, InstancedParameterType); IName ParameterName = (IName)Parameter.EntityName; IScopeAttributeFeature NewEntity; if (Parameter.DefaultValue.IsAssigned) { // The default value has already been checked and validated. bool IsCreated = ScopeAttributeFeature.Create(Parameter, ParameterName.ValidText.Item, InstancedParameterTypeName, InstancedParameterType, (IExpression)Parameter.DefaultValue.Item, ErrorList.Ignored, out NewEntity); Debug.Assert(IsCreated); } else { NewEntity = ScopeAttributeFeature.Create(Parameter, ParameterName.ValidText.Item, InstancedParameterTypeName, InstancedParameterType); } InstancedParameter.ValidEntity.Item = NewEntity; InstancedParameterList.Add(InstancedParameter); if (InstancedParameterType != Parameter.ValidEntity.Item.ResolvedEffectiveType.Item) { IsNewInstance = true; } } if (IsNewInstance) { ICommandOverloadType NewOverloadInstance = new CommandOverloadType(InstancedParameterList, instancedOverload.ParameterEnd, instancedOverload.RequireList, instancedOverload.EnsureList, instancedOverload.ExceptionIdentifierList); foreach (IEntityDeclaration Item in InstancedParameterList) { string ValidName = Item.ValidEntity.Item.ValidFeatureName.Item.Name; NewOverloadInstance.ParameterTable.Add(new Parameter(ValidName, Item.ValidEntity.Item)); } instancedOverload = NewOverloadInstance; } }
/// <summary> /// Initializes a new instance of the <see cref="PropertyType"/> class. /// </summary> /// <param name="baseTypeName">The type name of the resolved base type.</param> /// <param name="baseType">The base type.</param> /// <param name="resolvedBaseType">The resolved base type.</param> /// <param name="entityTypeName">The type name of the resolved result type.</param> /// <param name="entityType">The type of the resolved result type.</param> /// <param name="propertyKind">The type of the property.</param> /// <param name="getEnsureList">The list of ensure assertions for the getter.</param> /// <param name="getExceptionIdentifierList">The list of known exceptions thrown for the getter.</param> /// <param name="setRequireList">The list of require assertions for the setter.</param> /// <param name="setExceptionIdentifierList">The list of known exceptions thrown for the setter.</param> public PropertyType(ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, ITypeName entityTypeName, ICompiledType entityType, BaseNode.UtilityType propertyKind, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IIdentifier> setExceptionIdentifierList) : this() { BaseType = baseType; EntityType = null; PropertyKind = propertyKind; ResolvedBaseTypeName.Item = baseTypeName; ResolvedBaseType.Item = resolvedBaseType; ResolvedEntityTypeName.Item = entityTypeName; ResolvedEntityType.Item = entityType; GetEnsureList = getEnsureList; GetExceptionIdentifierList = getExceptionIdentifierList; SetRequireList = setRequireList; SetExceptionIdentifierList = setExceptionIdentifierList; }
/// <summary> /// Merge inheritance clauses. /// </summary> /// <param name="baseClass">The class with inheritance to merge.</param> /// <param name="resolvedClassType">The type from the class.</param> public static void MergeConformingParentTypes(IClass baseClass, IClassType resolvedClassType) { foreach (IInheritance InheritanceItem in baseClass.InheritanceList) { if (InheritanceItem.Conformance == BaseNode.ConformanceType.Conformant) { ITypeName ParentTypeName = InheritanceItem.ResolvedParentTypeName.Item; ICompiledType ParentType = InheritanceItem.ResolvedParentType.Item; resolvedClassType.ConformanceTable.Add(ParentTypeName, ParentType); } } resolvedClassType.ConformanceTable.Seal(); foreach (TypeInstancingRecord Record in resolvedClassType.InstancingRecordList) { ICompiledTypeWithFeature InstancingClassType = Record.InstancingClassType; ITypeName ResolvedTypeName = Record.ResolvedTypeName; ICompiledType ResolvedType = Record.ResolvedType; ResolvedType.InstanciateType(InstancingClassType, ref ResolvedTypeName, ref ResolvedType); Record.ResolvedTypeName = ResolvedTypeName; Record.ResolvedType = ResolvedType; if (!Record.ResolvedType.ConformanceTable.IsSealed) { IClassType ResolvedInstancingClassType = (IClassType)Record.ResolvedType; foreach (Inheritance InheritanceItem in baseClass.InheritanceList) { if (InheritanceItem.Conformance == BaseNode.ConformanceType.Conformant) { ITypeName ParentTypeName = InheritanceItem.ResolvedParentTypeName.Item; ICompiledType ParentType = InheritanceItem.ResolvedParentType.Item; ParentType.InstanciateType(ResolvedInstancingClassType, ref ParentTypeName, ref ParentType); Record.ResolvedType.ConformanceTable.Add(ParentTypeName, ParentType); } } Record.ResolvedType.ConformanceTable.Seal(); } } }
/// <summary> /// Applies the rule. /// </summary> /// <param name="node">The node instance to modify.</param> /// <param name="data">Private data from CheckConsistency().</param> public override void Apply(IPropertyType node, object data) { IClass EmbeddingClass = node.EmbeddingClass; IObjectType BaseType = (IObjectType)node.BaseType; IObjectType EntityType = (IObjectType)node.EntityType; ITypeName ResolvedBaseTypeName = BaseType.ResolvedTypeName.Item; ICompiledTypeWithFeature ResolvedBaseType = BaseType.ResolvedType.Item as ICompiledTypeWithFeature; Debug.Assert(ResolvedBaseType != null); ITypeName ResolvedEntityTypeName = EntityType.ResolvedTypeName.Item; ICompiledType ResolvedEntityType = EntityType.ResolvedType.Item; PropertyType.ResolveType(EmbeddingClass.TypeTable, ResolvedBaseTypeName, BaseType, ResolvedBaseType, ResolvedEntityTypeName, ResolvedEntityType, node.PropertyKind, node.GetEnsureList, node.GetExceptionIdentifierList, node.SetRequireList, node.SetExceptionIdentifierList, out ITypeName ResolvedTypeName, out ICompiledType ResolvedType); node.ResolvedTypeName.Item = ResolvedTypeName; node.ResolvedType.Item = ResolvedType; }
/// <summary> /// Checks for errors before applying a rule. /// </summary> /// <param name="node">The node instance to check.</param> /// <param name="dataList">Optional data collected during inspection of sources.</param> /// <param name="data">Private data to give to Apply() upon return.</param> /// <returns>True if an error occured.</returns> public override bool CheckConsistency(IPropertyType node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; IObjectType BaseType = (IObjectType)node.BaseType; Debug.Assert(BaseType.ResolvedType.IsAssigned); ICompiledTypeWithFeature ResolvedBaseType = BaseType.ResolvedType.Item as ICompiledTypeWithFeature; if (ResolvedBaseType == null) { AddSourceError(new ErrorClassTypeRequired(node)); Success = false; } return(Success); }
/// <summary> /// Creates a function type with resolved arguments. /// </summary> /// <param name="baseTypeName">Name of the resolved base type.</param> /// <param name="baseType">The base type.</param> /// <param name="resolvedBaseType">The resolved base type.</param> /// <param name="overloadList">The list of resolved overloads.</param> /// <param name="resolvedTypeName">The type name upon return.</param> /// <param name="resolvedType">The type upon return.</param> public static void BuildType(ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, IList <IQueryOverloadType> overloadList, out ITypeName resolvedTypeName, out IFunctionType resolvedType) { FunctionType ResolvedFunctionType = new FunctionType(baseTypeName, baseType, resolvedBaseType, overloadList); foreach (IQueryOverloadType Item in overloadList) { foreach (IEntityDeclaration Entity in Item.ResultList) { ITypeName EntityTypeName = Entity.ValidEntity.Item.ResolvedEffectiveTypeName.Item; ICompiledType EntityType = Entity.ValidEntity.Item.ResolvedEffectiveType.Item; string EntityName = Entity.ValidEntity.Item.ValidFeatureName.Item.Name; IExpressionType ResultExpressionType = new ExpressionType(EntityTypeName, EntityType, EntityName); Item.ResultTypeList.Add(ResultExpressionType); } } resolvedTypeName = new TypeName(ResolvedFunctionType.TypeFriendlyName); resolvedType = ResolvedFunctionType; }
/// <summary> /// Creates an instance of a class type, or reuse an existing instance. /// </summary> /// <param name="instancingClassType">The class type to instanciate.</param> /// <param name="resolvedTypeName">The proposed type instance name.</param> /// <param name="resolvedType">The proposed type instance.</param> public void InstanciateType(ICompiledTypeWithFeature instancingClassType, ref ITypeName resolvedTypeName, ref ICompiledType resolvedType) { ISealableDictionary <ITypeName, ICompiledType> TypeTable = GetTypeTable(); Debug.Assert(TypeTable.Count == 0); if (instancingClassType is IClassType AsClassType) { ISealableDictionary <string, ICompiledType> TypeArgumentTable = AsClassType.TypeArgumentTable; foreach (KeyValuePair <string, ICompiledType> TypeArgument in TypeArgumentTable) { if (TypeArgument.Key == TypeFriendlyName) { resolvedType = TypeArgument.Value; break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="CSharpCommandInstruction"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly instruction from which the C# instruction is created.</param> protected CSharpCommandInstruction(ICSharpContext context, ICSharpFeature parentFeature, ICommandInstruction source) : base(context, parentFeature, source) { Command = CSharpQualifiedName.Create(context, (IQualifiedName)source.Command, parentFeature, null, false); FeatureCall = new CSharpFeatureCall(context, source.FeatureCall.Item); ICompiledFeature SourceFeature = source.SelectedFeature.Item; if (SourceFeature is IScopeAttributeFeature AsScopeAttributeFeature) { FinalFeature = CSharpScopeAttributeFeature.Create(null, AsScopeAttributeFeature); } else { FinalFeature = context.GetFeature(SourceFeature); } ICompiledTypeWithFeature ResolvedBaseType = Source.CommandFinalType.Item.ResolvedBaseType.Item; FinalType = CSharpType.Create(context, ResolvedBaseType) as ICSharpTypeWithFeature; Debug.Assert(FinalType != null); IList <ICSharpClassType> ConformingClassTypeList = FinalType.ConformingClassTypeList; bool InheritFromDotNetEvent = false; bool IsNumberType = false; foreach (ICSharpClassType Item in ConformingClassTypeList) { ICSharpClass CallClass = Item.Class; InheritFromDotNetEvent |= CallClass.InheritFromDotNetEvent; IsNumberType = Item.IsNumberType; } SkipLastInPath = InheritFromDotNetEvent; IsCallingNumberFeature = IsNumberType; }
/// <summary> /// Creates an instance of a class type, or reuse an existing instance. /// </summary> /// <param name="instancingClassType">The class type to instanciate.</param> /// <param name="resolvedTypeName">The proposed type instance name.</param> /// <param name="resolvedType">The proposed type instance.</param> public void InstanciateType(ICompiledTypeWithFeature instancingClassType, ref ITypeName resolvedTypeName, ref ICompiledType resolvedType) { bool IsNewInstance = false; ITypeName InstancedBaseTypeName = ResolvedBaseTypeName.Item; ICompiledType InstancedBaseType = ResolvedBaseType.Item; InstancedBaseType.InstanciateType(instancingClassType, ref InstancedBaseTypeName, ref InstancedBaseType); Debug.Assert(InstancedBaseType is ICompiledTypeWithFeature); IsNewInstance |= InstancedBaseType != ResolvedBaseType.Item; ITypeName InstancedEntityTypeName = ResolvedEntityTypeName.Item; ICompiledType InstancedEntityType = ResolvedEntityType.Item; InstancedEntityType.InstanciateType(instancingClassType, ref InstancedEntityTypeName, ref InstancedEntityType); IsNewInstance |= InstancedEntityType != ResolvedEntityType.Item; if (IsNewInstance) { ISealableDictionary <ITypeName, ICompiledType> TypeTable = instancingClassType.GetTypeTable(); ResolveType(TypeTable, InstancedBaseTypeName, (IObjectType)BaseType, (ICompiledTypeWithFeature)InstancedBaseType, InstancedEntityTypeName, InstancedEntityType, PropertyKind, GetEnsureList, GetExceptionIdentifierList, SetRequireList, SetExceptionIdentifierList, out resolvedTypeName, out resolvedType); } }
/// <summary> /// Checks if a matching procedure type exists in a type table. /// </summary> /// <param name="typeTable">The table of existing types.</param> /// <param name="baseType">The resolved base type.</param> /// <param name="overloadList">The list of resolved overloads.</param> /// <param name="resolvedTypeName">The type name upon return.</param> /// <param name="resolvedType">The type upon return.</param> public static bool TypeTableContaining(ISealableDictionary <ITypeName, ICompiledType> typeTable, ICompiledTypeWithFeature baseType, IList <ICommandOverloadType> overloadList, out ITypeName resolvedTypeName, out IProcedureType resolvedType) { resolvedTypeName = null; resolvedType = null; bool Result = false; foreach (KeyValuePair <ITypeName, ICompiledType> Entry in typeTable) { if (Entry.Value is IProcedureType AsProcedureType) { if (AsProcedureType.ResolvedBaseType.Item == baseType && AsProcedureType.OverloadList.Count == overloadList.Count) { bool AllOverloadsEqual = true; foreach (ICommandOverloadType OverloadItem in overloadList) { AllOverloadsEqual &= IsCommandOverloadMatching(typeTable, OverloadItem, AsProcedureType.OverloadList); } if (AllOverloadsEqual) { Debug.Assert(!Result); resolvedTypeName = Entry.Key; resolvedType = AsProcedureType; Result = true; } } } } return(Result); }
/// <summary> /// Locates, or creates, a resolved property type. /// </summary> /// <param name="typeTable">The table of existing types.</param> /// <param name="baseTypeName">Name of the resolved base type.</param> /// <param name="baseType">The base type.</param> /// <param name="resolvedBaseType">The resolved base type.</param> /// <param name="entityTypeName">The type name of the resolved result type.</param> /// <param name="entityType">The type of the resolved result type.</param> /// <param name="propertyKind">The type of the property.</param> /// <param name="getEnsureList">The list of ensure assertions for the getter.</param> /// <param name="getExceptionIdentifierList">The list of known exceptions thrown for the getter.</param> /// <param name="setRequireList">The list of require assertions for the setter.</param> /// <param name="setExceptionIdentifierList">The list of known exceptions thrown for the setter.</param> /// <param name="resolvedTypeName">The type name upon return.</param> /// <param name="resolvedType">The type upon return.</param> public static void ResolveType(ISealableDictionary <ITypeName, ICompiledType> typeTable, ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, ITypeName entityTypeName, ICompiledType entityType, BaseNode.UtilityType propertyKind, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IIdentifier> setExceptionIdentifierList, out ITypeName resolvedTypeName, out ICompiledType resolvedType) { if (!TypeTableContaining(typeTable, resolvedBaseType, entityType, propertyKind, getEnsureList, getExceptionIdentifierList, setRequireList, setExceptionIdentifierList, out resolvedTypeName, out resolvedType)) { BuildType(baseTypeName, baseType, resolvedBaseType, entityTypeName, entityType, propertyKind, getEnsureList, getExceptionIdentifierList, setRequireList, setExceptionIdentifierList, out resolvedTypeName, out resolvedType); typeTable.Add(resolvedTypeName, resolvedType); } }
/// <summary> /// Locates, or creates, a resolved procedure type. /// </summary> /// <param name="typeTable">The table of existing types.</param> /// <param name="baseTypeName">Name of the resolved base type.</param> /// <param name="baseType">The base type.</param> /// <param name="resolvedBaseType">The resolved base type.</param> /// <param name="overloadList">The list of resolved overloads.</param> /// <param name="resolvedTypeName">The type name upon return.</param> /// <param name="resolvedType">The type upon return.</param> public static void ResolveType(ISealableDictionary <ITypeName, ICompiledType> typeTable, ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, IList <ICommandOverloadType> overloadList, out ITypeName resolvedTypeName, out IProcedureType resolvedType) { if (!TypeTableContaining(typeTable, resolvedBaseType, overloadList, out resolvedTypeName, out resolvedType)) { BuildType(baseTypeName, baseType, resolvedBaseType, overloadList, out resolvedTypeName, out resolvedType); typeTable.Add(resolvedTypeName, resolvedType); } }
/// <summary> /// Creates a class type with resolved arguments. /// </summary> /// <param name="baseClass">The class this is from.</param> /// <param name="typeArgumentTable">The generic arguments used when creating the class type.</param> /// <param name="instancingClassType">The class type to instanciate.</param> /// <param name="resolvedTypeName">The type name upon return.</param> /// <param name="resolvedType">The type upon return.</param> public static void BuildType(IClass baseClass, ISealableDictionary <string, ICompiledType> typeArgumentTable, ICompiledTypeWithFeature instancingClassType, out ITypeName resolvedTypeName, out ICompiledType resolvedType) { resolvedTypeName = null; resolvedType = null; IClassType ResolvedClassType = Create(baseClass, typeArgumentTable, instancingClassType); #if COVERAGE string TypeString = ResolvedClassType.ToString(); #endif resolvedTypeName = new TypeName(ResolvedClassType.TypeFriendlyName); resolvedType = ResolvedClassType; if (baseClass.DiscreteTable.IsSealed) { ResolvedClassType.DiscreteTable.Merge(baseClass.DiscreteTable); ResolvedClassType.DiscreteTable.Seal(); } if (baseClass.ExportTable.IsSealed) { ResolvedClassType.ExportTable.Merge(baseClass.ExportTable); ResolvedClassType.ExportTable.Seal(); } if (baseClass.FeatureTable.IsSealed) { ResolvedClassType.FeatureTable.Merge(baseClass.FeatureTable); ResolvedClassType.FeatureTable.Seal(); } if (baseClass.TypedefTable.IsSealed) { ResolvedClassType.TypedefTable.Merge(baseClass.TypedefTable); ResolvedClassType.TypedefTable.Seal(); } baseClass.GenericInstanceList.Add(ResolvedClassType); }
/// <summary> /// Locates, or creates, a resolved class type. /// </summary> /// <param name="typeTable">The table of existing types.</param> /// <param name="baseClass">The class this is from.</param> /// <param name="typeArgumentTable">The generic arguments used when creating the class type.</param> /// <param name="instancingClassType">The class type to instanciate.</param> /// <param name="resolvedTypeName">The type name upon return.</param> /// <param name="resolvedType">The type upon return.</param> public static void ResolveType(ISealableDictionary <ITypeName, ICompiledType> typeTable, IClass baseClass, ISealableDictionary <string, ICompiledType> typeArgumentTable, ICompiledTypeWithFeature instancingClassType, out ITypeName resolvedTypeName, out ICompiledType resolvedType) { resolvedTypeName = null; resolvedType = null; if (!TypeTableContaining(typeTable, baseClass, typeArgumentTable, out resolvedTypeName, out resolvedType)) { BuildType(baseClass, typeArgumentTable, instancingClassType, out resolvedTypeName, out resolvedType); typeTable.Add(resolvedTypeName, resolvedType); } }
/// <summary> /// Creates a <see cref="ClassType"/>. /// </summary> /// <param name="baseClass">The class used to instanciate this type.</param> /// <param name="typeArgumentTable">Arguments if the class is generic.</param> /// <param name="instancingClassType">The class type if this instance is a derivation (such as renaming).</param> public static IClassType Create(IClass baseClass, ISealableDictionary <string, ICompiledType> typeArgumentTable, ICompiledTypeWithFeature instancingClassType) { ISealableDictionary <ITypeName, ICompiledType> ConformanceTable = new SealableDictionary <ITypeName, ICompiledType>(); if (baseClass.ResolvedClassType.IsAssigned) { IClassType ResolvedClassType = baseClass.ResolvedClassType.Item; if (ResolvedClassType.ConformanceTable.IsSealed) { foreach (IInheritance InheritanceItem in baseClass.InheritanceList) { if (InheritanceItem.Conformance == BaseNode.ConformanceType.Conformant) { ITypeName ParentTypeName = InheritanceItem.ResolvedParentTypeName.Item; ICompiledType ParentType = InheritanceItem.ResolvedParentType.Item; ParentType.InstanciateType(instancingClassType, ref ParentTypeName, ref ParentType); ConformanceTable.Add(ParentTypeName, ParentType); } } ConformanceTable.Seal(); } } IClassType ClassType = new ClassType(baseClass, typeArgumentTable, instancingClassType, ConformanceTable); return(ClassType); }
/// <summary> /// Initializes a new instance of the <see cref="ClassType"/> class. /// </summary> /// <param name="baseClass">The class used to instanciate this type.</param> /// <param name="typeArgumentTable">Arguments if the class is generic.</param> /// <param name="instancingClassType">The class type if this instance is a derivation (such as renaming).</param> /// <param name="conformanceTable">The initialized conformance table.</param> private ClassType(IClass baseClass, ISealableDictionary <string, ICompiledType> typeArgumentTable, ICompiledTypeWithFeature instancingClassType, ISealableDictionary <ITypeName, ICompiledType> conformanceTable) { BaseClass = baseClass; TypeArgumentTable = typeArgumentTable; if (BaseClass.ResolvedClassType.IsAssigned) { if (conformanceTable.IsSealed) { ConformanceTable.Merge(conformanceTable); ConformanceTable.Seal(); } else { TypeInstancingRecord NewRecord = new TypeInstancingRecord(); NewRecord.InstancingClassType = instancingClassType; NewRecord.ResolvedTypeName = BaseClass.ResolvedClassTypeName.Item; NewRecord.ResolvedType = this; BaseClass.ResolvedClassType.Item.InstancingRecordList.Add(NewRecord); } } NumberKind = GetDefaultNumberKind(); }