/// <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(IProcedureFeature node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IName EntityName = (IName)((IFeatureWithName)node).EntityName; // This is ensured because the root node is valid. Debug.Assert(node.OverloadList.Count > 0); ICommandOverload FirstOverload = node.OverloadList[0]; ICompiledBody FirstOverloadBody = (ICompiledBody)FirstOverload.CommandBody; for (int i = 1; i < node.OverloadList.Count; i++) { ICommandOverload ThisOverload = node.OverloadList[i]; ICompiledBody ThisOverloadBody = (ICompiledBody)ThisOverload.CommandBody; if (ThisOverloadBody.IsDeferredBody != FirstOverloadBody.IsDeferredBody) { ErrorList.AddError(new ErrorBodyTypeMismatch(ThisOverload, EntityName.ValidText.Item)); Success = false; break; } } IList <ICommandOverloadType> OverloadTypeList = new List <ICommandOverloadType>(); foreach (ICommandOverload Overload in node.OverloadList) { Debug.Assert(Overload.ResolvedAssociatedType.IsAssigned); OverloadTypeList.Add(Overload.ResolvedAssociatedType.Item); } if (!Feature.DisjoinedParameterCheck(OverloadTypeList, ErrorList)) { Debug.Assert(!ErrorList.IsEmpty); Success = false; } 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(IRename node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; IIdentifier SourceIdentifier = (IIdentifier)node.SourceIdentifier; IIdentifier DestinationIdentifier = (IIdentifier)node.DestinationIdentifier; Debug.Assert(SourceIdentifier.ValidText.IsAssigned); Debug.Assert(DestinationIdentifier.ValidText.IsAssigned); if (SourceIdentifier.ValidText.Item == DestinationIdentifier.ValidText.Item) { ErrorList.AddError(new ErrorNameUnchanged(node, SourceIdentifier.ValidText.Item)); Success = false; } return(Success); }
/// <summary></summary> protected virtual bool CheckClassNames(IRoot root) { IList <IClass> ValidatedClassList = new List <IClass>(); bool IsClassNamesValid = true; // Basic name checks. foreach (IClass Class in root.ClassList) { IsClassNamesValid &= Class.CheckClassNames(ClassTable, ValidatedClassList, ErrorList); } foreach (KeyValuePair <string, ISealableDictionary <string, IClass> > Entry in ClassTable) { string ValidClassName = Entry.Key; // List all classes with the same name and no source. List <IClass> DuplicateClassList = new List <IClass>(); foreach (IClass Item in ValidatedClassList) { if (Item.ValidClassName == ValidClassName && !Item.FromIdentifier.IsAssigned) { DuplicateClassList.Add(Item); } } // If more than one, report an error for each of them. if (DuplicateClassList.Count > 1) { IsClassNamesValid = false; foreach (IClass Item in DuplicateClassList) { ErrorList.AddError(new ErrorSourceRequired((IName)Item.EntityName)); } } } Debug.Assert(IsClassNamesValid || !ErrorList.IsEmpty); return(IsClassNamesValid); }
/// <summary></summary> protected virtual bool CheckLibrariesConsistency(IRoot root) { List <ILibrary> ResolvedLibraryList = new List <ILibrary>(); List <ILibrary> UnresolvedLibraryList = new List <ILibrary>(root.LibraryList); bool Success = true; bool Continue = true; while (UnresolvedLibraryList.Count > 0 && Success && Continue) { // Continue while there is a library to process. Continue = false; foreach (ILibrary Library in UnresolvedLibraryList) { Success &= Library.Resolve(LibraryTable, ResolvedLibraryList, ref Continue, ErrorList); } MoveResolvedLibraries(UnresolvedLibraryList, ResolvedLibraryList, ref Continue); } // If we're stuck at processing remaining libraries, it's because they are referencing each other in a cycle. if (UnresolvedLibraryList.Count > 0 && Success) { Success = false; IList <string> NameList = new List <string>(); foreach (ILibrary Library in UnresolvedLibraryList) { NameList.Add(Library.ValidLibraryName); } ErrorList.AddError(new ErrorCyclicDependency(NameList, "Library")); } Debug.Assert(Success || !ErrorList.IsEmpty); return(Success); }
/// <summary> /// Compiles the file. The file must contain a serialized Easly Root object. /// </summary> /// <param name="fileName">The file to compile.</param> public virtual void Compile(string fileName) { FileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); ErrorList.ClearErrors(); if (File.Exists(FileName)) { try { using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { Compile(fs); } } catch (Exception e) { ErrorList.AddError(new ErrorInputFileInvalid(e)); } } else { ErrorList.AddError(new ErrorInputFileNotFound(FileName)); } }
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); }