/// <summary> /// Retourne vrai si les 2 types sont égaux. /// </summary> public bool Equals(ClankTypeInstance t2) { if (t2 == null) { return(false); } return(GetFullName() == t2.GetFullName()); }
/// <summary> /// Retourne une valeur indiquant si ce type a des variables d'instance génériques non sérialisables. /// Cad, des variable d'instance de type générique T où T ne supporte pas la sérialisation générique. /// </summary> /// <returns></returns> public bool HasNonSerializableGenericInstanceVariables(ref List <string> reasons, int depth = 0) { if (depth > 50) { string error = "Type circulaire détecté : " + BaseType.ToString() + "."; throw new Semantic.SemanticError(error); } foreach (var kvp in BaseType.InstanceVariables) { Variable var = kvp.Value; if (var.Type.BaseType is Language.GenericParameterType) { ClankTypeInstance inst = var.Type.Instanciate(GenericArguments); Variable newVar = new Variable() { Type = inst, Name = var.Name }; if (!inst.BaseType.SupportSerializationAsGeneric) { reasons.Add(newVar.ToString() + " n'est pas sérialisable en tant que variable générique du type '" + var.Type.ToString() + "'"); return(true); } else if (inst.HasNonSerializableGenericInstanceVariables(ref reasons, depth + 1)) { return(true); } } else if (var.Type.BaseType.HasGenericParameterTypeMembers()) { var type = var.Type.Instanciate(GenericArguments); if (type.HasNonSerializableGenericInstanceVariables(ref reasons, depth + 1)) { return(true); } } } return(false); }
/// <summary> /// Crée une instance de ce type pour laquelle les types génériques (du type de base) sont remplacés par /// les instances de type appropriés, contenus dans genArgs. /// </summary> public ClankTypeInstance Instanciate(List <ClankTypeInstance> genArgs) { ClankTypeInstance newInstance = new ClankTypeInstance(); // Si on est une instance de type générique, on se fait remplacer par // l'argument générique convenable. if (this.BaseType is GenericParameterType) { GenericParameterType parameter = (GenericParameterType)this.BaseType; return(genArgs[parameter.ParamId]); } // Sinon, on instancie tous les arguments génériques. newInstance.GenericArguments = new List <ClankTypeInstance>(); foreach (ClankTypeInstance inst in GenericArguments) { newInstance.GenericArguments.Add(inst.Instanciate(genArgs)); } newInstance.BaseType = BaseType; return(newInstance); }