/// <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> /// 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(IExportChange node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; ISealableDictionary <string, IIdentifier> IdentifierTable = new SealableDictionary <string, IIdentifier>(); foreach (IIdentifier Item in node.IdentifierList) { Debug.Assert(Item.ValidText.IsAssigned); string ValidText = Item.ValidText.Item; if (IdentifierTable.ContainsKey(ValidText)) { AddSourceError(new ErrorDuplicateName(Item, ValidText)); Success = false; } else { IdentifierTable.Add(ValidText, Item); } } if (Success) { data = IdentifierTable; } return(Success); }
/// <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); }
private ISealableDictionary <IFeatureName, IIdentifier> MergeExportClassIdentifiers(IClass node, IExport export, ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > mergedExportTable, ref bool success) { IList <string> ListedClassList = new List <string>(); ISealableDictionary <IFeatureName, IIdentifier> ListedExportList = new SealableDictionary <IFeatureName, IIdentifier>(); for (int i = 0; i < export.ClassIdentifierList.Count; i++) { IIdentifier Identifier = export.ClassIdentifierList[i]; Debug.Assert(Identifier.ValidText.IsAssigned); string ValidText = Identifier.ValidText.Item; if (ValidText.ToUpperInvariant() == LanguageClasses.Any.Name.ToUpperInvariant()) { ListedClassList.Add(LanguageClasses.Any.Name); } else if (node.ImportedClassTable.ContainsKey(ValidText)) { ListedClassList.Add(ValidText); } else if (FeatureName.TableContain(mergedExportTable, ValidText, out IFeatureName Key, out ISealableDictionary <string, IClass> Item)) { if (ListedExportList.ContainsKey(Key)) { AddSourceError(new ErrorIdentifierAlreadyListed(Identifier, ValidText)); success = false; } else { ListedExportList.Add(Key, Identifier); } }
/// <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(ITupleType node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; ISealableDictionary <string, IScopeAttributeFeature> FieldTable = new SealableDictionary <string, IScopeAttributeFeature>(); foreach (IEntityDeclaration Item in node.EntityDeclarationList) { IName FieldName = (IName)Item.EntityName; Debug.Assert(FieldName.ValidText.IsAssigned); string ValidText = FieldName.ValidText.Item; IScopeAttributeFeature FieldAttribute = Item.ValidEntity.Item; if (FieldTable.ContainsKey(ValidText)) { AddSourceError(new ErrorDuplicateName(FieldName, ValidText)); Success = false; } else { FieldTable.Add(ValidText, FieldAttribute); } } if (Success) { data = FieldTable; } 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(IForLoopInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; IClass EmbeddingClass = node.EmbeddingClass; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = new SealableDictionary <string, IScopeAttributeFeature>(); foreach (IEntityDeclaration Item in node.EntityDeclarationList) { IScopeAttributeFeature LocalEntity = Item.ValidEntity.Item; string ValidFeatureName = LocalEntity.ValidFeatureName.Item.Name; if (CheckedScope.ContainsKey(ValidFeatureName)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidFeatureName)); Success = false; } else { CheckedScope.Add(ValidFeatureName, LocalEntity); } } IList <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedScope, node.InnerScopes, ConflictList); foreach (IEntityDeclaration Item in node.EntityDeclarationList) { IScopeAttributeFeature LocalEntity = Item.ValidEntity.Item; string ValidFeatureName = LocalEntity.ValidFeatureName.Item.Name; if (ConflictList.Contains(ValidFeatureName)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidFeatureName)); Success = false; } } IList <IClass> AssignedSingleClassList = new List <IClass>(); IErrorList CheckErrorList = new ErrorList(); if (ScopeHolder.HasConflictingSingleAttributes(CheckedScope, node.InnerScopes, AssignedSingleClassList, node, CheckErrorList)) { AddSourceErrorList(CheckErrorList); Success = false; } if (Success) { data = CheckedScope; } 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(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 static bool ValidateAssignmentStyle(IList <IArgument> argumentList, List <IExpressionType> mergedArgumentList, IErrorList errorList) { ISealableDictionary <string, IArgument> DuplicateNameTable = new SealableDictionary <string, IArgument>(); for (int i = 0; i < argumentList.Count; i++) { IAssignmentArgument Argument = argumentList[i] as IAssignmentArgument; Debug.Assert(Argument != null); IExpression Source = (IExpression)Argument.Source; IList <IIdentifier> ParameterList = Argument.ParameterList; if (ParameterList.Count > 1 && Argument.ResolvedResult.Item.Count == 1) { IExpressionType Item = Argument.ResolvedResult.Item.At(0); for (int j = 0; j < ParameterList.Count; j++) { IExpressionType ItemJ = new ExpressionType(Item.ValueTypeName, Item.ValueType, ParameterList[j].ValidText.Item); ItemJ.SetSource(Source, 0); mergedArgumentList.Add(ItemJ); } } else { for (int j = 0; j < Argument.ResolvedResult.Item.Count; j++) { IExpressionType Item = Argument.ResolvedResult.Item.At(j); Item.SetName(ParameterList[j].ValidText.Item); if (mergedArgumentList.Exists((IExpressionType other) => { return(Item.Name == other.Name); })) { if (!DuplicateNameTable.ContainsKey(Item.Name)) { DuplicateNameTable.Add(Item.Name, Argument); } } Item.SetSource(Source, j); mergedArgumentList.Add(Item); } } } if (DuplicateNameTable.Count > 0) { foreach (KeyValuePair <string, IArgument> Entry in DuplicateNameTable) { errorList.AddError(new ErrorDuplicateName(Entry.Value, Entry.Key)); } return(false); } return(true); }
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); } }
/// <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(ICommandOverload node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = new SealableDictionary <string, IScopeAttributeFeature>(); ISealableList <IParameter> ParameterTable = new SealableList <IParameter>(); foreach (EntityDeclaration Item in node.ParameterList) { IName SourceName = (IName)Item.EntityName; string ValidName = SourceName.ValidText.Item; if (CheckedScope.ContainsKey(ValidName)) { AddSourceError(new ErrorDuplicateName(SourceName, ValidName)); Success = false; } else { CheckedScope.Add(ValidName, Item.ValidEntity.Item); ParameterTable.Add(new Parameter(ValidName, Item.ValidEntity.Item)); } } IList <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedScope, node.InnerScopes, ConflictList); foreach (IEntityDeclaration Item in node.ParameterList) { IScopeAttributeFeature LocalEntity = Item.ValidEntity.Item; string ValidFeatureName = LocalEntity.ValidFeatureName.Item.Name; if (ConflictList.Contains(ValidFeatureName)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidFeatureName)); Success = false; } } if (Success) { data = new Tuple <ISealableDictionary <string, IScopeAttributeFeature>, ISealableList <IParameter> >(CheckedScope, ParameterTable); } 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(IConstraint node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; ISealableDictionary <IIdentifier, IIdentifier> RenameTable = new SealableDictionary <IIdentifier, IIdentifier>(); ISealableDictionary <string, string> SourceToDestinationTable = new SealableDictionary <string, string>(); ISealableDictionary <string, string> DestinationToSourceTable = new SealableDictionary <string, string>(); foreach (IRename Item in node.RenameList) { IIdentifier SourceIdentifier = (IIdentifier)Item.SourceIdentifier; Debug.Assert(SourceIdentifier.ValidText.IsAssigned); string ValidSourceIdentifier = SourceIdentifier.ValidText.Item; Debug.Assert(Item.ValidSourceText.IsAssigned); Debug.Assert(Item.ValidSourceText.Item == ValidSourceIdentifier); IIdentifier DestinationIdentifier = (IIdentifier)Item.DestinationIdentifier; Debug.Assert(DestinationIdentifier.ValidText.IsAssigned); string ValidDestinationIdentifier = DestinationIdentifier.ValidText.Item; Debug.Assert(Item.ValidDestinationText.IsAssigned); Debug.Assert(Item.ValidDestinationText.Item == ValidDestinationIdentifier); if (SourceToDestinationTable.ContainsKey(ValidSourceIdentifier)) { ErrorList.AddError(new ErrorIdentifierAlreadyListed(SourceIdentifier, ValidSourceIdentifier)); Success = false; } else if (DestinationToSourceTable.ContainsKey(ValidDestinationIdentifier)) { ErrorList.AddError(new ErrorDoubleRename(Item, DestinationToSourceTable[ValidDestinationIdentifier], ValidDestinationIdentifier)); Success = false; } else { SourceToDestinationTable.Add(ValidSourceIdentifier, ValidDestinationIdentifier); DestinationToSourceTable.Add(ValidDestinationIdentifier, ValidSourceIdentifier); RenameTable.Add(SourceIdentifier, DestinationIdentifier); } } if (Success) { data = RenameTable; } 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(IOverLoopInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = new SealableDictionary <string, IScopeAttributeFeature>(); IClass EmbeddingClass = node.EmbeddingClass; foreach (IName Item in node.IndexerList) { Debug.Assert(Item.ValidText.IsAssigned); string ValidText = Item.ValidText.Item; if (CheckedScope.ContainsKey(ValidText)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidText)); Success = false; } else { IScopeAttributeFeature NewEntity = ScopeAttributeFeature.Create(Item, ValidText); CheckedScope.Add(ValidText, NewEntity); } } IList <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedScope, node.InnerScopes, ConflictList); foreach (KeyValuePair <string, IScopeAttributeFeature> Item in CheckedScope) { if (ConflictList.Contains(Item.Key)) { AddSourceError(new ErrorVariableAlreadyDefined(Item.Value.Location, Item.Key)); Success = false; } } if (Success) { data = CheckedScope; } return(Success); }
private bool ResolveIdentifierList(IList <IIdentifier> identifierList, out ISealableDictionary <string, IIdentifier> resultTable) { resultTable = new SealableDictionary <string, IIdentifier>(); foreach (IIdentifier IdentifierItem in identifierList) { string ValidText = IdentifierItem.ValidText.Item; if (resultTable.ContainsKey(ValidText)) { AddSourceError(new ErrorIdentifierAlreadyListed(IdentifierItem, ValidText)); return(false); } resultTable.Add(ValidText, IdentifierItem); } return(true); }
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> /// Checks that all overloads in a list have parameters that allow them to be distinguished in a caller. /// </summary> /// <param name="overloadList">The list of overloads.</param> /// <param name="errorList">The list of errors found.</param> public static bool DisjoinedParameterCheck(IList <ICommandOverloadType> overloadList, IErrorList errorList) { ISealableDictionary <int, IList <ICommandOverloadType> > UnmixedOverloadsTable = new SealableDictionary <int, IList <ICommandOverloadType> >(); foreach (ICommandOverloadType Overload in overloadList) { int LastParameterIndex; for (LastParameterIndex = Overload.ParameterTable.Count; LastParameterIndex > 0; LastParameterIndex--) { IParameter p = Overload.ParameterTable[LastParameterIndex - 1]; IScopeAttributeFeature Attribute = p.ResolvedParameter; if (!Attribute.DefaultValue.IsAssigned) { break; } } if (!UnmixedOverloadsTable.ContainsKey(LastParameterIndex)) { UnmixedOverloadsTable.Add(LastParameterIndex, new List <ICommandOverloadType>()); } IList <ICommandOverloadType> ThisOverloadMix = UnmixedOverloadsTable[LastParameterIndex]; ThisOverloadMix.Add(Overload); } bool Success = true; foreach (KeyValuePair <int, IList <ICommandOverloadType> > Entry in UnmixedOverloadsTable) { IList <ICommandOverloadType> ThisOverloadMix = Entry.Value; for (int i = 0; i < Entry.Key; i++) { Success &= DisjoinedParameterCheck(ThisOverloadMix, i, errorList); } } return(Success); }
private bool CheckResultValueConsistency(IIndexerFeature node, IDictionary <ISourceTemplate, object> dataList, IScopeAttributeFeature resultFeature, IScopeAttributeFeature valueFeature, out object data) { data = null; bool Success = true; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = new SealableDictionary <string, IScopeAttributeFeature>(); ISealableDictionary <string, IScopeAttributeFeature> CheckedGetScope = new SealableDictionary <string, IScopeAttributeFeature>(); ISealableDictionary <string, IScopeAttributeFeature> CheckedSetScope = new SealableDictionary <string, IScopeAttributeFeature>(); string NameResult = resultFeature.ValidFeatureName.Item.Name; string NameValue = valueFeature.ValidFeatureName.Item.Name; Success &= CheckParameters(node, resultFeature, valueFeature, CheckedScope); CheckedGetScope.Merge(CheckedScope); CheckedGetScope.Add(NameResult, resultFeature); CheckedSetScope.Merge(CheckedScope); CheckedSetScope.Add(NameValue, valueFeature); List <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedGetScope, node.InnerScopes, ConflictList); ScopeHolder.RecursiveCheck(CheckedSetScope, node.InnerScopes, ConflictList); Debug.Assert(node.InnerScopes.Count == 0); // This has been checked in another rule. Debug.Assert(!ConflictList.Contains(NameResult)); Debug.Assert(!ConflictList.Contains(NameValue)); Success &= CheckIndexerKind(node, out BaseNode.UtilityType IndexerKind); if (Success) { data = new Tuple <BaseNode.UtilityType, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature> >(IndexerKind, CheckedScope, CheckedGetScope, CheckedSetScope); } return(Success); }
/// <summary> /// Apply changes in this instance to arguments. /// </summary> /// <param name="importedClassTable">The table of imported classes</param> /// <param name="exportTable">The list of exports to change.</param> /// <param name="errorList">The list of errors found.</param> public virtual bool ApplyChange(ISealableDictionary <string, IImportedClass> importedClassTable, ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > exportTable, IErrorList errorList) { if (!ExportIdentifierExists(exportTable, errorList, out IFeatureName CurrentExportName, out ISealableDictionary <string, IClass> CurrentClassTable)) { return(false); } ISealableDictionary <string, ISealableDictionary <string, IClass> > ListedExportTable = new SealableDictionary <string, ISealableDictionary <string, IClass> >(); // string (export name) -> hashtable // string (class name) -> Class ISealableDictionary <string, IClass> ListedClassTable = new SealableDictionary <string, IClass>(); // string (class name) -> Class bool InvalidExportChange = false; foreach (IIdentifier IdentifierItem in IdentifierList) { Debug.Assert(IdentifierItem.ValidText.IsAssigned); string ValidIdentifier = IdentifierItem.ValidText.Item; if (FeatureName.TableContain(exportTable, ValidIdentifier, out IFeatureName EntryName, out ISealableDictionary <string, IClass> ListedExport)) { Debug.Assert(!ListedExportTable.ContainsKey(ValidIdentifier)); ListedExportTable.Add(ValidIdentifier, ListedExport); }
/// <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; }
/// <summary> /// Merges an import clause with already imported classes. /// </summary> /// <param name="importedClassTable">Already imported classes.</param> /// <param name="importItem">The merged import.</param> /// <param name="matchingLibrary">The library referenced by <paramref name="importItem"/>.</param> /// <param name="errorList">List of errors found.</param> /// <returns>True if the merge succeeded.</returns> public static bool MergeImports(ISealableDictionary <string, IImportedClass> importedClassTable, IImport importItem, ILibrary matchingLibrary, IErrorList errorList) { // Clone imported class objects from the imported library. ISealableDictionary <string, IImportedClass> MergedClassTable = new SealableDictionary <string, IImportedClass>(); foreach (KeyValuePair <string, IImportedClass> Entry in matchingLibrary.ImportedClassTable) { IImportedClass Clone = new ImportedClass(Entry.Value); MergedClassTable.Add(Entry.Key, Clone); } if (!importItem.CheckRenames(MergedClassTable, errorList)) { return(false); } if (!Class.MergeClassTables(importedClassTable, MergedClassTable, importItem, importItem.Type, errorList)) { return(false); } return(true); }
/// <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(IPropertyFeature node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IClass EmbeddingClass = node.EmbeddingClass; IObjectType TypeToResolve = (IObjectType)node.EntityType; IScopeAttributeFeature Result = ScopeAttributeFeature.CreateResultFeature(TypeToResolve, EmbeddingClass, node); IScopeAttributeFeature Value = ScopeAttributeFeature.CreateValueFeature(TypeToResolve, EmbeddingClass, node); string NameResult = Result.ValidFeatureName.Item.Name; string NameValue = Value.ValidFeatureName.Item.Name; ISealableDictionary <string, IScopeAttributeFeature> CheckedGetScope = new SealableDictionary <string, IScopeAttributeFeature>(); CheckedGetScope.Add(NameResult, Result); ISealableDictionary <string, IScopeAttributeFeature> CheckedSetScope = new SealableDictionary <string, IScopeAttributeFeature>(); CheckedSetScope.Add(NameValue, Value); IList <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedGetScope, node.InnerScopes, ConflictList); ScopeHolder.RecursiveCheck(CheckedSetScope, node.InnerScopes, ConflictList); // This has been checked in another rule. Debug.Assert(!ConflictList.Contains(NameResult)); Debug.Assert(!ConflictList.Contains(NameValue)); IName PropertyName = (IName)((IFeatureWithName)node).EntityName; if (node.GetterBody.IsAssigned && node.SetterBody.IsAssigned) { ICompiledBody AsCompiledGetter = (ICompiledBody)node.GetterBody.Item; ICompiledBody AsCompiledSetter = (ICompiledBody)node.SetterBody.Item; if (AsCompiledGetter.IsDeferredBody != AsCompiledSetter.IsDeferredBody) { AddSourceError(new ErrorBodyTypeMismatch(node, PropertyName.ValidText.Item)); Success = false; } if (node.PropertyKind != BaseNode.UtilityType.ReadWrite) { AddSourceError(new ErrorBodyTypeMismatch(node, PropertyName.ValidText.Item)); Success = false; } } else if (node.GetterBody.IsAssigned) { if (node.PropertyKind == BaseNode.UtilityType.WriteOnly) { AddSourceError(new ErrorBodyTypeMismatch(node, PropertyName.ValidText.Item)); Success = false; } } else if (node.SetterBody.IsAssigned) { if (node.PropertyKind == BaseNode.UtilityType.ReadOnly) { AddSourceError(new ErrorBodyTypeMismatch(node, PropertyName.ValidText.Item)); Success = false; } } if (Success) { data = new Tuple <IScopeAttributeFeature, IScopeAttributeFeature>(Result, Value); } 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(IQueryOverload node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = new SealableDictionary <string, IScopeAttributeFeature>(); Debug.Assert(node.ParameterTable.Count == node.ParameterList.Count); for (int i = 0; i < node.ParameterTable.Count; i++) { IParameter Parameter = node.ParameterTable[i]; IEntityDeclaration EntityDeclaration = node.ParameterList[i]; if (CheckedScope.ContainsKey(Parameter.Name)) { AddSourceError(new ErrorDuplicateName(EntityDeclaration, Parameter.Name)); Success = false; } else { CheckedScope.Add(Parameter.Name, EntityDeclaration.ValidEntity.Item); } } Debug.Assert(node.ResultTable.Count == node.ResultList.Count); for (int i = 0; i < node.ResultTable.Count; i++) { IParameter Result = node.ResultTable[i]; IEntityDeclaration EntityDeclaration = node.ResultList[i]; if (CheckedScope.ContainsKey(Result.Name)) { AddSourceError(new ErrorDuplicateName(EntityDeclaration, Result.Name)); Success = false; } else { CheckedScope.Add(Result.Name, EntityDeclaration.ValidEntity.Item); } } IList <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedScope, node.InnerScopes, ConflictList); foreach (IEntityDeclaration Item in node.ParameterList) { IScopeAttributeFeature LocalEntity = Item.ValidEntity.Item; string ValidFeatureName = LocalEntity.ValidFeatureName.Item.Name; if (ConflictList.Contains(ValidFeatureName)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidFeatureName)); Success = false; } } foreach (IEntityDeclaration Item in node.ResultList) { IScopeAttributeFeature LocalEntity = Item.ValidEntity.Item; string ValidFeatureName = LocalEntity.ValidFeatureName.Item.Name; if (ConflictList.Contains(ValidFeatureName)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidFeatureName)); Success = false; } } if (Success) { data = CheckedScope; } return(Success); }