private bool IsSingleEffective(ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable, IErrorList errorList) { bool IsSingle = true; foreach (KeyValuePair <IFeatureName, InheritedInstanceInfo> ImportedEntry in byNameTable) { IFeatureName ImportedKey = ImportedEntry.Key; InheritedInstanceInfo ImportedInstance = ImportedEntry.Value; IList <InstanceNameInfo> InstanceList = ImportedInstance.PrecursorInstanceList; foreach (InstanceNameInfo Item in InstanceList) { if (!Item.Instance.IsForgotten) { if (!ImportedInstance.EffectiveInstance.IsAssigned) { ImportedInstance.EffectiveInstance.Item = Item; } else { errorList.AddError(new ErrorMultipleEffectiveFeature(Item.Location, Item.Name.Name)); IsSingle = false; break; } } } } return(IsSingle); }
private bool ResolveFeatureInstancingList(ISealableDictionary <IFeatureName, IFeatureInstance> featureTable, ISealableDictionary <string, IIdentifier> identifierTable, Action <IFeatureInstance> handler) { foreach (KeyValuePair <string, IIdentifier> IdentifierEntry in identifierTable) { string ValidIdentifier = IdentifierEntry.Key; IIdentifier IdentifierItem = IdentifierEntry.Value; OnceReference <IFeatureInstance> CurrentInstance = new OnceReference <IFeatureInstance>(); foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in featureTable) { IFeatureName EntryName = Entry.Key; if (EntryName.Name == ValidIdentifier) { CurrentInstance.Item = Entry.Value; break; } } if (!CurrentInstance.IsAssigned) { AddSourceError(new ErrorUnknownIdentifier(IdentifierItem, ValidIdentifier)); return(false); } handler(CurrentInstance.Item); } return(true); }
private IFeatureInstance MergeCreateNewInstance(IClass item, IFeatureName importedKey, InheritedInstanceInfo importedInstance, out InstanceNameInfo selectedInstanceInfo) { IFeatureInstance NewInstance; if (importedInstance.EffectiveInstance.IsAssigned) { selectedInstanceInfo = importedInstance.EffectiveInstance.Item; } else { IList <InstanceNameInfo> InstancePrecursorList = importedInstance.PrecursorInstanceList; selectedInstanceInfo = null; foreach (InstanceNameInfo Item in InstancePrecursorList) { if (Item.Instance.Owner == item) { selectedInstanceInfo = Item; break; } } if (selectedInstanceInfo == null) { selectedInstanceInfo = InstancePrecursorList[0]; } } NewInstance = new FeatureInstance(selectedInstanceInfo.Instance.Owner, selectedInstanceInfo.Instance.Feature, importedInstance.IsKept, importedInstance.IsDiscontinued); return(NewInstance); }
/// <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(IClass node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; Debug.Assert(node.LocalDiscreteTable.IsSealed); ISealableDictionary <IFeatureName, IDiscrete> MergedDiscreteTable = node.LocalDiscreteTable.CloneUnsealed(); foreach (IInheritance Inheritance in node.InheritanceList) { Debug.Assert(Inheritance.ResolvedType.IsAssigned); Debug.Assert(Inheritance.DiscreteTable.IsAssigned); ISealableDictionary <IFeatureName, IDiscrete> InheritedDiscreteTable = Inheritance.DiscreteTable.Item; foreach (KeyValuePair <IFeatureName, IDiscrete> InstanceEntry in InheritedDiscreteTable) { IFeatureName InstanceName = InstanceEntry.Key; IDiscrete InstanceItem = InstanceEntry.Value; bool ConflictingEntry = false; foreach (KeyValuePair <IFeatureName, IDiscrete> Entry in MergedDiscreteTable) { IFeatureName LocalName = Entry.Key; IDiscrete LocalItem = Entry.Value; if (InstanceName.Name == LocalName.Name) { if (InstanceItem != LocalItem) { AddSourceError(new ErrorDuplicateName(Inheritance, LocalName.Name)); ConflictingEntry = true; Success = false; } } else if (InstanceItem == LocalItem) { AddSourceError(new ErrorDiscreteNameConflict(Inheritance, LocalName.Name, InstanceName.Name)); ConflictingEntry = true; Success = false; } } if (!ConflictingEntry && !MergedDiscreteTable.ContainsKey(InstanceName)) { MergedDiscreteTable.Add(InstanceName, InstanceItem); } } } if (Success) { data = MergedDiscreteTable; } return(Success); }
/// <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(TBody node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IClass EmbeddingClass = node.EmbeddingClass; IFeature InnerFeature = node.EmbeddingFeature; IFeatureName InnerFeatureName = InnerFeature.ValidFeatureName.Item; IFeatureInstance InnerFeatureInstance = EmbeddingClass.FeatureTable[InnerFeatureName]; IList <IPrecursorInstance> PrecursorList = InnerFeatureInstance.PrecursorList; ITypeName AncestorTypeName = null; ICompiledType AncestorType = null; if (node.AncestorType.IsAssigned) { IObjectType DeclaredAncestor = (IObjectType)node.AncestorType.Item; bool Found = false; if (DeclaredAncestor.ResolvedType.Item is IClassType AsClassTypeAncestor) { foreach (IPrecursorInstance Item in PrecursorList) { if (Item.Ancestor.BaseClass == AsClassTypeAncestor.BaseClass) { Found = true; AncestorTypeName = Item.Ancestor.BaseClass.ResolvedClassTypeName.Item; AncestorType = Item.Ancestor.BaseClass.ResolvedClassType.Item; break; } } } if (!Found) { AddSourceError(new ErrorInvalidPrecursor(node)); Success = false; } } else if (PrecursorList.Count > 1) { AddSourceError(new ErrorInvalidPrecursor(node)); Success = false; } else { AncestorTypeName = PrecursorList[0].Ancestor.BaseClass.ResolvedClassTypeName.Item; AncestorType = PrecursorList[0].Ancestor.BaseClass.ResolvedClassType.Item; } if (Success) { data = new Tuple <ITypeName, ICompiledType>(AncestorTypeName, AncestorType); } return(Success); }
/// <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(IIndexerFeature node, object data) { IClass EmbeddingClass = node.EmbeddingClass; IFeatureName FeatureEntityName = FeatureName.IndexerFeatureName; IFeatureInstance NewInstance = new FeatureInstance(EmbeddingClass, node); node.ValidFeatureName.Item = FeatureEntityName; EmbeddingClass.LocalFeatureTable.Add(FeatureEntityName, NewInstance); }
/// <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(IInheritance node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; IClassType ParentTypeWithRename = null; IClassType ResolvedParent = node.ResolvedClassParentType.Item; 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, ISealableDictionary <string, IClass> > RenamedExportTable = ResolvedParent.ExportTable.CloneUnsealed(); ISealableDictionary <IFeatureName, ITypedefType> RenamedTypedefTable = ResolvedParent.TypedefTable.CloneUnsealed(); ISealableDictionary <IFeatureName, IDiscrete> RenamedDiscreteTable = ResolvedParent.DiscreteTable.CloneUnsealed(); ISealableDictionary <IFeatureName, IFeatureInstance> RenamedFeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>(); foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in ResolvedParent.FeatureTable) { IFeatureName AncestorFeatureName = Entry.Key; IFeatureInstance AncestorFeatureInstance = Entry.Value; RenamedFeatureTable.Add(AncestorFeatureName, AncestorFeatureInstance.Clone(ResolvedParent)); } foreach (IRename RenameItem in node.RenameList) { Success &= RenameItem.CheckGenericRename(new IDictionaryIndex <IFeatureName>[] { RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable }, SourceIdentifierTable, DestinationIdentifierTable, (IFeatureName item) => item.Name, (string name) => new FeatureName(name), ErrorList); } if (Success) { Success &= ResolveInstancingAfterRename(node, RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable); if (Success) { IClass EmbeddingClass = node.EmbeddingClass; ParentTypeWithRename = ClassType.Create(ResolvedParent.BaseClass, ResolvedParent.TypeArgumentTable, EmbeddingClass.ResolvedClassType.Item); ParentTypeWithRename.ExportTable.Merge(RenamedExportTable); ParentTypeWithRename.ExportTable.Seal(); ParentTypeWithRename.TypedefTable.Merge(RenamedTypedefTable); ParentTypeWithRename.TypedefTable.Seal(); ParentTypeWithRename.DiscreteTable.Merge(RenamedDiscreteTable); ParentTypeWithRename.DiscreteTable.Seal(); ParentTypeWithRename.FeatureTable.Merge(RenamedFeatureTable); ParentTypeWithRename.FeatureTable.Seal(); } } if (Success) { data = ParentTypeWithRename; } return(Success); }
private bool CheckPrecursorSelected(ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable, ISealableDictionary <IFeatureName, IList <ICompiledFeature> > precursorSet, IErrorList errorList) { bool Success = true; bool IsKept = false; foreach (KeyValuePair <IFeatureName, IList <ICompiledFeature> > SetMemberEntry in precursorSet) { IFeatureName SetMemberKey = SetMemberEntry.Key; InheritedInstanceInfo CorrespondingInstance = byNameTable[SetMemberKey]; if (CorrespondingInstance.IsKept) { if (IsKept) { foreach (InstanceNameInfo Item in CorrespondingInstance.PrecursorInstanceList) { if (Item.Instance.IsKept) { errorList.AddError(new ErrorInheritanceConflict(Item.Location, Item.Name.Name)); Success = false; break; } } } else { IsKept = true; } } } if (!IsKept && precursorSet.Count > 1) { foreach (KeyValuePair <IFeatureName, IList <ICompiledFeature> > SetMemberEntry in precursorSet) { IFeatureName SetMemberKey = SetMemberEntry.Key; InheritedInstanceInfo CorrespondingInstance = byNameTable[SetMemberKey]; foreach (InstanceNameInfo Item in CorrespondingInstance.PrecursorInstanceList) { errorList.AddError(new ErrorMissingSelectedPrecursor(Item.Location, Item.Name.Name)); Success = false; break; } break; } Debug.Assert(!Success); } return(Success); }
private static CSharpExports GetExportStatus(IFeatureName name, IClass sourceClass, ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > exportTable, IFeature sourceFeature) { bool IsExportedToClient; string FeatureExport = sourceFeature.ExportIdentifier.Text; if (FeatureExport == "All") { IsExportedToClient = true; } else if (FeatureExport == "None" || FeatureExport == "Self") { IsExportedToClient = false; } else { bool IsExported = FeatureName.TableContain(exportTable, FeatureExport, out IFeatureName ExportName, out ISealableDictionary <string, IClass> ExportList); Debug.Assert(IsExported); Debug.Assert(ExportList.Count > 0); if (ExportList.Count > 1) { IsExportedToClient = true; } else { if (ExportList.ContainsKey(sourceClass.ValidClassName)) { IsExportedToClient = false; // Export to self = self + descendant = protected } else { IsExportedToClient = true; // export to another = export to all = public } } } if (IsExportedToClient) { return(CSharpExports.Public); } else if (sourceFeature.Export == BaseNode.ExportStatus.Exported) { return(CSharpExports.Protected); } else { return(CSharpExports.Private); } }
private void MergeInheritedFeatures(IClass item, ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable, out ISealableDictionary <IFeatureName, IFeatureInstance> mergedFeatureTable) { mergedFeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>(); foreach (KeyValuePair <IFeatureName, InheritedInstanceInfo> ImportedEntry in byNameTable) { IFeatureName ImportedKey = ImportedEntry.Key; InheritedInstanceInfo ImportedInstance = ImportedEntry.Value; IFeatureInstance NewInstance = MergeCreateNewInstance(item, ImportedKey, ImportedInstance, out InstanceNameInfo SelectedInstanceInfo); StableReference <IPrecursorInstance> OriginalPrecursor = new StableReference <IPrecursorInstance>(); IList <IPrecursorInstance> PrecursorList = new List <IPrecursorInstance>(); foreach (InstanceNameInfo Item in ImportedInstance.PrecursorInstanceList) { if (Item == SelectedInstanceInfo) { foreach (IPrecursorInstance PrecursorInstance in Item.Instance.PrecursorList) { PrecursorList.Add(PrecursorInstance); } } else { IPrecursorInstance NewPrecursor = new PrecursorInstance(Item.Ancestor, Item.Instance); PrecursorList.Add(NewPrecursor); } if (Item.Instance.OriginalPrecursor.IsAssigned) { OriginalPrecursor.Item = Item.Instance.OriginalPrecursor.Item; } } if (OriginalPrecursor.IsAssigned) { NewInstance.OriginalPrecursor.Item = OriginalPrecursor.Item; } else if (PrecursorList.Count > 0) { NewInstance.OriginalPrecursor.Item = PrecursorList[0]; } Debug.Assert(NewInstance.PrecursorList.Count == 0); foreach (IPrecursorInstance PrecursorInstance in PrecursorList) { NewInstance.PrecursorList.Add(PrecursorInstance); } mergedFeatureTable.Add(ImportedKey, NewInstance); } }
private void CheckIfFeatureNameListed(ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable, AncestorFeatureInfo featureInfo, IFeatureName featureName, IFeatureInstance featureInstance) { bool FeatureAlreadyListed = false; bool NameAlreadyListed = false; foreach (KeyValuePair <IFeatureName, InheritedInstanceInfo> ImportedEntry in byNameTable) { IFeatureName ImportedKey = ImportedEntry.Key; InheritedInstanceInfo ImportedInstance = ImportedEntry.Value; IList <InstanceNameInfo> InstanceList = ImportedInstance.PrecursorInstanceList; if (featureName.Name == ImportedKey.Name) { FeatureAlreadyListed = false; Debug.Assert(featureInstance.Feature != null); foreach (InstanceNameInfo Item in InstanceList) { Debug.Assert(Item.Instance.Feature != null); if (featureInstance.Feature == Item.Instance.Feature) { FeatureAlreadyListed = true; break; } } if (!FeatureAlreadyListed) { InstanceNameInfo NewInfo = new InstanceNameInfo(featureInfo, featureInstance, featureName); InstanceList.Add(NewInfo); } NameAlreadyListed = true; break; } } if (!NameAlreadyListed) { IList <InstanceNameInfo> InitList = new List <InstanceNameInfo>(); InstanceNameInfo NewInfo = new InstanceNameInfo(featureInfo, featureInstance, featureName); InitList.Add(NewInfo); InheritedInstanceInfo NewName = new InheritedInstanceInfo(); NewName.PrecursorInstanceList = InitList; byNameTable.Add(featureName, NewName); } }
private void RemoveIdentifierFromTable(IDictionary table, string identifier, ref bool isRemoved) { foreach (DictionaryEntry Entry in table) { IFeatureName EntryName = Entry.Key as IFeatureName; Debug.Assert(EntryName != null); if (EntryName.Name == identifier) { table.Remove(EntryName); isRemoved = true; break; } } }
public InstanceNameInfo(AncestorFeatureInfo item, IFeatureInstance instance, IFeatureName name) { Instance = instance; Name = name; Ancestor = item.Ancestor; if (item.Location.IsAssigned) { Location = item.Location.Item; } else { Location = new Inheritance(); } SameIsKept = true; SameIsDiscontinued = true; }
private bool HasConflictingEntry(IClass node, ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > mergedExportTable) { bool Result = false; foreach (IInheritance Inheritance in node.InheritanceList) { Debug.Assert(Inheritance.ExportTable.IsAssigned); ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > InheritedExportTable = Inheritance.ExportTable.Item; foreach (KeyValuePair <IFeatureName, ISealableDictionary <string, IClass> > InstanceEntry in InheritedExportTable) { IFeatureName InstanceName = InstanceEntry.Key; ISealableDictionary <string, IClass> InstanceItem = InstanceEntry.Value; bool ConflictingEntry = false; foreach (KeyValuePair <IFeatureName, ISealableDictionary <string, IClass> > Entry in mergedExportTable) { IFeatureName LocalName = Entry.Key; ISealableDictionary <string, IClass> LocalItem = Entry.Value; if (InstanceName.Name == LocalName.Name) { if (InstanceItem != LocalItem) { AddSourceError(new ErrorDuplicateName(Inheritance, LocalName.Name)); ConflictingEntry = true; Result = true; } } else if (InstanceItem == LocalItem) { AddSourceError(new ErrorExportNameConflict(Inheritance, LocalName.Name, InstanceName.Name)); ConflictingEntry = true; Result = true; } } if (!ConflictingEntry && !mergedExportTable.ContainsKey(InstanceName)) { mergedExportTable.Add(InstanceName, InstanceItem); } } } return(Result); }
private bool CheckPrecursorBodiesHaveAncestor(ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable, IErrorList errorList) { foreach (KeyValuePair <IFeatureName, InheritedInstanceInfo> ImportedEntry in byNameTable) { IFeatureName ImportedKey = ImportedEntry.Key; InheritedInstanceInfo ImportedInstance = ImportedEntry.Value; if (ImportedInstance.EffectiveInstance.IsAssigned) { InstanceNameInfo Item = ImportedInstance.EffectiveInstance.Item; ICompiledFeature EffectiveFeature = Item.Instance.Feature; if (EffectiveFeature.HasPrecursorBody) { bool HasEffectiveAncestor = false; foreach (InstanceNameInfo AncestorItem in ImportedInstance.PrecursorInstanceList) { if (AncestorItem == Item) { continue; } ICompiledFeature AncestorEffectiveFeature = AncestorItem.Instance.Feature; if (AncestorEffectiveFeature.IsDeferredFeature) { continue; } HasEffectiveAncestor = true; } if (!HasEffectiveAncestor) { IFeature AsFeature = EffectiveFeature as IFeature; Debug.Assert(AsFeature != null); errorList.AddError(new ErrorMissingAncestor(AsFeature, Item.Name.Name)); return(false); } } } } return(true); }
private void SortByFeatureAndByName(IList <AncestorFeatureInfo> featureTableList, out ISealableDictionary <ICompiledFeature, IList <InstanceNameInfo> > byFeatureTable, out ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable) { byFeatureTable = new SealableDictionary <ICompiledFeature, IList <InstanceNameInfo> >(); // ICompiledFeature -> List of InstanceNameInfo byNameTable = new SealableDictionary <IFeatureName, InheritedInstanceInfo>(); // FeatureName -> InheritedInstanceInfo foreach (AncestorFeatureInfo FeatureInfoItem in featureTableList) { foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in FeatureInfoItem.FeatureTable) { IFeatureName Key = Entry.Key; IFeatureInstance Value = Entry.Value; Debug.Assert(Value.Feature != null); CheckIfFeatureListed(byFeatureTable, FeatureInfoItem, Key, Value); CheckIfFeatureNameListed(byNameTable, FeatureInfoItem, Key, Value); } } }
private void CheckAllPrecursorSelectedInNameTable(ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable, IList <ISealableDictionary <IFeatureName, IList <ICompiledFeature> > > precursorSetList) { foreach (KeyValuePair <IFeatureName, InheritedInstanceInfo> Entry in byNameTable) { IFeatureName Key = Entry.Key; InheritedInstanceInfo Value = Entry.Value; IList <ICompiledFeature> PrecursorList = new List <ICompiledFeature>(); foreach (InstanceNameInfo PrecursorItem in Value.PrecursorInstanceList) { FillPrecursorList(PrecursorList, PrecursorItem.Instance); } bool FoundInSet = false; foreach (ISealableDictionary <IFeatureName, IList <ICompiledFeature> > PrecursorSet in precursorSetList) { foreach (KeyValuePair <IFeatureName, IList <ICompiledFeature> > SetMemberEntry in PrecursorSet) { IFeatureName SetMemberKey = SetMemberEntry.Key; IList <ICompiledFeature> SetMemberPrecursorList = SetMemberEntry.Value; if (PrecursorListIntersect(PrecursorList, SetMemberPrecursorList)) { PrecursorSet.Add(Key, PrecursorList); FoundInSet = true; break; } } if (FoundInSet) { break; } } if (!FoundInSet) { ISealableDictionary <IFeatureName, IList <ICompiledFeature> > NewSet = new SealableDictionary <IFeatureName, IList <ICompiledFeature> >(); NewSet.Add(Key, PrecursorList); precursorSetList.Add(NewSet); } } }
/// <summary> /// Creates a tuple type with resolved arguments. /// </summary> /// <param name="entityDeclarationList">The resolved list of fields.</param> /// <param name="sharing">The type sharing.</param> /// <param name="resolvedTypeName">The type name upon return.</param> /// <param name="resolvedType">The type upon return.</param> public static void BuildType(IList <IEntityDeclaration> entityDeclarationList, BaseNode.SharingType sharing, out ITypeName resolvedTypeName, out ICompiledType resolvedType) { ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>(); foreach (IEntityDeclaration Item in entityDeclarationList) { Debug.Assert(Item.ValidEntity.IsAssigned); IScopeAttributeFeature ValidEntity = Item.ValidEntity.Item; Debug.Assert(ValidEntity.ValidFeatureName.IsAssigned); IFeatureName FeatureName = ValidEntity.ValidFeatureName.Item; IClass EmbeddingClass = Item.EmbeddingClass; IFeatureInstance FeatureInstance = new FeatureInstance(EmbeddingClass, ValidEntity); FeatureTable.Add(FeatureName, FeatureInstance); } ITupleType ResolvedTupleType = new TupleType(entityDeclarationList, sharing, FeatureTable); resolvedTypeName = new TypeName(ResolvedTupleType.TypeFriendlyName); resolvedType = ResolvedTupleType; }
private bool CheckInheritanceConsistency(ISealableDictionary <ICompiledFeature, IList <InstanceNameInfo> > byFeatureTable, ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable, IClassType localClassType, IErrorList errorList) { if (!IsKeepDiscontinueConsistent(byFeatureTable, errorList)) { return(false); } if (!IsSingleEffective(byNameTable, errorList)) { return(false); } bool AllRedefineConformant = true; bool AllFlagsTheSame = true; foreach (KeyValuePair <IFeatureName, InheritedInstanceInfo> ImportedEntry in byNameTable) { IFeatureName ImportedKey = ImportedEntry.Key; InheritedInstanceInfo ImportedInstance = ImportedEntry.Value; // If there is no effective instance for this name if (!ImportedInstance.EffectiveInstance.IsAssigned) { AllFlagsTheSame &= CompareNonEffectiveFlags(ImportedInstance, errorList); } else { AllRedefineConformant &= CompareEffectiveFlags(ImportedInstance, errorList, localClassType); } } if (!AllFlagsTheSame || !AllRedefineConformant) { return(false); } return(true); }
private bool RemoveForgottenIdentifiers(ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > exportTable, ISealableDictionary <IFeatureName, ITypedefType> typedefTable, ISealableDictionary <IFeatureName, IDiscrete> discreteTable, ISealableDictionary <IFeatureName, IFeatureInstance> featureTable, ISealableDictionary <string, IIdentifier> forgetTable) { bool Result = true; foreach (KeyValuePair <string, IIdentifier> IdentifierEntry in forgetTable) { string ValidIdentifier = IdentifierEntry.Key; IIdentifier IdentifierItem = IdentifierEntry.Value; bool IsRemoved = false; RemoveIdentifierFromTable(exportTable as IDictionary, ValidIdentifier, ref IsRemoved); RemoveIdentifierFromTable(typedefTable as IDictionary, ValidIdentifier, ref IsRemoved); RemoveIdentifierFromTable(discreteTable as IDictionary, ValidIdentifier, ref IsRemoved); foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in featureTable) { IFeatureName EntryName = Entry.Key; if (EntryName.Name == ValidIdentifier) { IFeatureInstance CurrentInstance = Entry.Value; CurrentInstance.SetIsForgotten(true); IsRemoved = true; break; } } if (!IsRemoved) { AddSourceError(new ErrorUnknownIdentifier(IdentifierItem, ValidIdentifier)); } Result &= IsRemoved; } return(Result); }
/// <summary> /// Writes down the C# conditional instructions. /// </summary> /// <param name="writer">The stream on which to write.</param> public virtual void WriteCSharp(ICSharpWriter writer) { Debug.Assert(WriteDown); foreach (ILanguageConstant Constant in ConstantList) { bool IsHandled = false; switch (Constant) { case INumberLanguageConstant AsManifestConstant: Number AsNumber = AsManifestConstant.Value; if (AsNumber.TryParseInt(out int IntValue)) { writer.WriteIndentedLine($"case {IntValue}:"); IsHandled = true; } break; case IDiscreteLanguageConstant AsDiscreteConstant: IDiscrete DiscreteItem = AsDiscreteConstant.Discrete; IName ClassEntityName = (IName)DiscreteItem.EmbeddingClass.EntityName; string ClassName = CSharpNames.ToCSharpIdentifier(ClassEntityName.ValidText.Item); IFeatureName DiscreteFeatureName = DiscreteItem.ValidDiscreteName.Item; string DiscreteName = CSharpNames.ToCSharpIdentifier(DiscreteFeatureName.Name); writer.WriteIndentedLine($"case {ClassName}.{DiscreteName}:"); IsHandled = true; break; } Debug.Assert(IsHandled); } Instructions.WriteCSharp(writer, CSharpCurlyBracketsInsertions.Indifferent, true); }
private void UpdateNameList(AncestorFeatureInfo featureInfo, IFeatureName featureName, IFeatureInstance featureInstance, IList <InstanceNameInfo> nameList) { OnceReference <InstanceNameInfo> PreviousInstance = new OnceReference <InstanceNameInfo>(); int i; for (i = 0; i < nameList.Count; i++) { InstanceNameInfo Item = nameList[i]; if (featureName.Name == Item.Name.Name) { PreviousInstance.Item = Item; break; } } // C inherit f from A and B, effectively or not, but keep or discontinue flags don't match. if (PreviousInstance.IsAssigned && (PreviousInstance.Item.Instance.IsForgotten == featureInstance.IsForgotten)) { PreviousInstance.Item.SameIsKept = PreviousInstance.Item.Instance.IsKept == featureInstance.IsKept; PreviousInstance.Item.SameIsDiscontinued = PreviousInstance.Item.Instance.IsDiscontinued == featureInstance.IsDiscontinued; } if (!PreviousInstance.IsAssigned || (PreviousInstance.Item.Instance.IsForgotten && !featureInstance.IsForgotten)) { InstanceNameInfo NewInfo = new InstanceNameInfo(featureInfo, featureInstance, featureName); if (i < nameList.Count) { nameList[i] = NewInfo; } else { nameList.Add(NewInfo); } } }
/// <summary> /// Checks if a table of feature names contains a name, and if so returns the corresponding <see cref="IFeatureName"/> and associated value. /// </summary> /// <typeparam name="TValue">The type of the value associated to feature names in the table.</typeparam> /// <param name="table">The table.</param> /// <param name="name">The name to check.</param> /// <param name="key">The feature name found upon return.</param> /// <param name="value">The associated value.</param> public static bool TableContain <TValue>(ISealableDictionary <IFeatureName, TValue> table, string name, out IFeatureName key, out TValue value) { key = null; value = default; bool Result = false; foreach (KeyValuePair <IFeatureName, TValue> Entry in table) { if (Entry.Key.Name == name) { key = Entry.Key; value = Entry.Value; Result = true; break; } } return(Result); }
/// <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(IAssertionTagExpression node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IClass EmbeddingClass = node.EmbeddingClass; Debug.Assert(node.ResolvedAssertion.IsAssigned); IAssertion InnerAssertion = node.ResolvedAssertion.Item; IIdentifier TagIdentifier = (IIdentifier)node.TagIdentifier; string ExpectedTag = TagIdentifier.ValidText.Item; IList <IAssertion> MatchingAssertionList = new List <IAssertion>(); if (InnerAssertion.EmbeddingBody != null) { IFeature Feature = node.EmbeddingFeature; IFeatureName FeatureName = Feature.ValidFeatureName.Item; Debug.Assert(EmbeddingClass.FeatureTable.ContainsKey(FeatureName)); IFeatureInstance FeatureInstance = EmbeddingClass.FeatureTable[FeatureName]; if (FeatureInstance.OriginalPrecursor.IsAssigned) { FeatureInstance = FeatureInstance.OriginalPrecursor.Item.Precursor; } IList <IPrecursorInstance> PrecursorList = FeatureInstance.PrecursorList; foreach (KeyValuePair <IClassType, IList <IBody> > Entry in EmbeddingClass.InheritedBodyTagListTable) { IClass InheritedClass = Entry.Key.BaseClass; foreach (IBody InheritedBody in Entry.Value) { IFeature InheritedFeature = InheritedBody.EmbeddingFeature; IFeatureName InheritedFeatureName = InheritedFeature.ValidFeatureName.Item; Debug.Assert(InheritedClass.FeatureTable.ContainsKey(InheritedFeatureName)); IFeatureInstance InheritedFeatureInstance = InheritedClass.FeatureTable[InheritedFeatureName]; foreach (IPrecursorInstance PrecursorInstance in PrecursorList) { if (PrecursorInstance.Precursor == InheritedFeatureInstance) { FindMatchingAssertions(InheritedBody.RequireList, InnerAssertion, ExpectedTag, MatchingAssertionList); FindMatchingAssertions(InheritedBody.EnsureList, InnerAssertion, ExpectedTag, MatchingAssertionList); } } } } IBody ResolvedBody = InnerAssertion.EmbeddingBody; Debug.Assert(ResolvedBody.RequireList.Count > 0 || ResolvedBody.EnsureList.Count > 0); FindMatchingAssertions(ResolvedBody.RequireList, InnerAssertion, ExpectedTag, MatchingAssertionList); FindMatchingAssertions(ResolvedBody.EnsureList, InnerAssertion, ExpectedTag, MatchingAssertionList); } else { Debug.Assert(EmbeddingClass.InvariantList.Count > 0); foreach (KeyValuePair <IClassType, IObjectType> Entry in EmbeddingClass.InheritedClassTypeTable) { IClass InheritedClass = Entry.Key.BaseClass; FindMatchingAssertions(InheritedClass.InvariantList, InnerAssertion, ExpectedTag, MatchingAssertionList); } FindMatchingAssertions(EmbeddingClass.InvariantList, InnerAssertion, ExpectedTag, MatchingAssertionList); } if (MatchingAssertionList.Count == 0) { AddSourceError(new ErrorInvalidExpression(node)); Success = false; } else if (MatchingAssertionList.Count > 1) { AddSourceError(new ErrorInvalidExpression(node)); Success = false; } else { Debug.Assert(MatchingAssertionList.Count == 1); IAssertion MatchingAssertion = MatchingAssertionList[0]; data = MatchingAssertion.BooleanExpression; } return(Success); }
private bool CheckRename(KeyValuePair <IIdentifier, IIdentifier> entry, IDictionaryIndex <IFeatureName>[] renamedItemTables, ISealableDictionary <string, string> sourceIdentifierTable, ISealableDictionary <string, string> destinationIdentifierTable, Func <IFeatureName, string> key2String, Func <string, IFeatureName> string2Key) { IIdentifier SourceIdentifier = entry.Key; IIdentifier DestinationIdentifier = entry.Value; OnceReference <ISealableDictionary> SourceTable = new OnceReference <ISealableDictionary>(); OnceReference <IFeatureName> SourceKey = new OnceReference <IFeatureName>(); OnceReference <object> SourceItem = new OnceReference <object>(); foreach (ISealableDictionary Table in renamedItemTables) { foreach (System.Collections.DictionaryEntry SourceEntry in (System.Collections.IDictionary)Table) { IFeatureName EntryKey = SourceEntry.Key as IFeatureName; object EntryValue = SourceEntry.Value; string ValidName = key2String(EntryKey); if (ValidName == SourceIdentifier.Text) { SourceTable.Item = Table; SourceKey.Item = EntryKey; SourceItem.Item = EntryValue; break; } } if (SourceTable.IsAssigned) { break; } } if (!SourceTable.IsAssigned) { ErrorList.AddError(new ErrorUnknownIdentifier(SourceIdentifier, SourceIdentifier.Text)); return(false); } foreach (ISealableDictionary Table in renamedItemTables) { foreach (System.Collections.DictionaryEntry SourceEntry in (System.Collections.IDictionary)Table) { IFeatureName EntryKey = SourceEntry.Key as IFeatureName; string ValidName = key2String(EntryKey); if (ValidName == DestinationIdentifier.Text) { ErrorList.AddError(new ErrorIdentifierAlreadyListed(DestinationIdentifier, DestinationIdentifier.Text)); return(false); } } } sourceIdentifierTable.Add(SourceIdentifier.Text, DestinationIdentifier.Text); destinationIdentifierTable.Add(DestinationIdentifier.Text, SourceIdentifier.Text); ((System.Collections.IDictionary)SourceTable.Item).Remove(SourceKey.Item); ((System.Collections.IDictionary)SourceTable.Item).Add(string2Key(DestinationIdentifier.Text), SourceItem.Item); return(true); }
private void CheckIfFeatureListed(ISealableDictionary <ICompiledFeature, IList <InstanceNameInfo> > byFeatureTable, AncestorFeatureInfo featureInfo, IFeatureName featureName, IFeatureInstance featureInstance) { bool FeatureAlreadyListed = false; foreach (KeyValuePair <ICompiledFeature, IList <InstanceNameInfo> > ImportedEntry in byFeatureTable) { ICompiledFeature ImportedKey = ImportedEntry.Key; IList <InstanceNameInfo> NameList = ImportedEntry.Value; // Feature already listed if (featureInstance.Feature == ImportedKey) { UpdateNameList(featureInfo, featureName, featureInstance, NameList); FeatureAlreadyListed = true; break; } } if (!FeatureAlreadyListed) { IList <InstanceNameInfo> InitList = new List <InstanceNameInfo>(); InstanceNameInfo NewInfo = new InstanceNameInfo(featureInfo, featureInstance, featureName); InitList.Add(NewInfo); byFeatureTable.Add(featureInstance.Feature, InitList); } }