private bool ResolveTupleTypeRenames(ITupleType tupleType, IConstraint node, out ITypeName destinationTypeName, out ICompiledType destinationType) { bool Success = false; destinationType = null; destinationTypeName = null; IClass EmbeddingClass = node.EmbeddingClass; ISealableDictionary <string, string> SourceIdentifierTable = new SealableDictionary <string, string>(); // string (source) -> string (destination) ISealableDictionary <string, string> DestinationIdentifierTable = new SealableDictionary <string, string>(); // string (destination) -> string (source) ISealableDictionary <IFeatureName, IFeatureInstance> RenamedFieldTable = tupleType.FeatureTable.CloneUnsealed(); bool AllRenameValid = true; foreach (KeyValuePair <IIdentifier, IIdentifier> Entry in node.RenameTable) { if (!CheckRename(Entry, new ISealableDictionary <IFeatureName, IFeatureInstance>[] { RenamedFieldTable }, SourceIdentifierTable, DestinationIdentifierTable, (IFeatureName item) => item.Name, (string name) => new FeatureName(name))) { AllRenameValid = false; } } if (AllRenameValid) { destinationType = tupleType.CloneWithRenames(RenamedFieldTable); destinationTypeName = new TypeName(destinationType.TypeFriendlyName); Success = true; } return(Success); }
private static bool TupleTypeConformToTupleType(ITupleType derivedType, ITupleType baseType, IErrorList errorList, ISource sourceLocation) { bool Result = true; if (derivedType.EntityDeclarationList.Count < baseType.EntityDeclarationList.Count) { errorList.AddError(new ErrorFieldMismatchConformance(sourceLocation, derivedType, baseType)); Result = false; } for (int i = 0; i < derivedType.EntityDeclarationList.Count && i < baseType.EntityDeclarationList.Count; i++) { IEntityDeclaration BaseField = baseType.EntityDeclarationList[i]; IEntityDeclaration DerivedField = derivedType.EntityDeclarationList[i]; Debug.Assert(DerivedField.ValidEntity.IsAssigned); Debug.Assert(DerivedField.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Debug.Assert(BaseField.ValidEntity.IsAssigned); Debug.Assert(BaseField.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Result = TypeConformToBase(DerivedField.ValidEntity.Item.ResolvedEffectiveType.Item, BaseField.ValidEntity.Item.ResolvedEffectiveType.Item, errorList, sourceLocation, isConversionAllowed: false); } return(Result); }
/// <summary> /// Compares two types. /// </summary> /// <param name="type1">The first type.</param> /// <param name="type2">The second type.</param> public static bool TypesHaveIdenticalSignature(ITupleType type1, ITupleType type2) { bool IsIdentical = true; for (int i = 0; i < type1.EntityDeclarationList.Count && i < type2.EntityDeclarationList.Count; i++) { Debug.Assert(type1.EntityDeclarationList[i].ValidEntity.IsAssigned); Debug.Assert(type1.EntityDeclarationList[i].ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Debug.Assert(type2.EntityDeclarationList[i].ValidEntity.IsAssigned); Debug.Assert(type2.EntityDeclarationList[i].ValidEntity.Item.ResolvedEffectiveType.IsAssigned); IsIdentical &= ObjectType.TypesHaveIdenticalSignature(type1.EntityDeclarationList[i].ValidEntity.Item.ResolvedEffectiveType.Item, type2.EntityDeclarationList[i].ValidEntity.Item.ResolvedEffectiveType.Item); } return(IsIdentical); }
private static bool TypeConformToTupleType(ICompiledType derivedType, ITupleType baseType, IErrorList errorList, ISource sourceLocation) { bool Result = false; bool IsHandled = false; if (derivedType is IClassType AsClassType) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; IsHandled = true; } else if (derivedType is IFunctionType AsFunctionType) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; IsHandled = true; } else if (derivedType is IProcedureType AsProcedureType) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; IsHandled = true; } else if (derivedType is IPropertyType AsPropertyType) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; IsHandled = true; } else if (derivedType is IIndexerType AsIndexerType) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; IsHandled = true; } else if (derivedType is ITupleType AsTupleType) { Result = TupleTypeConformToTupleType(AsTupleType, baseType, errorList, sourceLocation); IsHandled = true; } Debug.Assert(IsHandled); return(Result); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpTupleType"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly type from which the C# type is created.</param> protected CSharpTupleType(ICSharpContext context, ITupleType source) : base(context, source) { }
/// <summary> /// Create a new C# type. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly type from which the C# type is created.</param> public static ICSharpTupleType Create(ICSharpContext context, ITupleType source) { return(new CSharpTupleType(context, source)); }