private bool RemoveForgottenIndexer(ISealableDictionary <IFeatureName, IFeatureInstance> featureTable, IInheritance inheritanceItem) { if (inheritanceItem.ForgetIndexer) { bool Removed = false; foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in featureTable) { if (Entry.Key == FeatureName.IndexerFeatureName) { IFeatureInstance CurrentInstance = Entry.Value; CurrentInstance.SetIsForgotten(true); Removed = true; break; } } if (!Removed) { AddSourceError(new ErrorIndexerInheritance(inheritanceItem)); return(false); } } return(true); }
private static bool ResolveCallClass(IPrecursorExpression node, IFeatureInstance selectedPrecursor, List <IExpressionType> mergedArgumentList, TypeArgumentStyles argumentStyle, IErrorList errorList, ref ResolvedExpression resolvedExpression, out ISealableList <IParameter> selectedParameterList, out ISealableList <IParameter> selectedResultList, out List <IExpressionType> resolvedArgumentList) { selectedParameterList = null; selectedResultList = null; resolvedArgumentList = null; IList <IArgument> ArgumentList = node.ArgumentList; if (ArgumentList.Count > 0) { errorList.AddError(new ErrorInvalidExpression(node)); return(false); } else { ICompiledFeature OperatorFeature = selectedPrecursor.Feature; ITypeName OperatorTypeName = OperatorFeature.ResolvedEffectiveTypeName.Item; ICompiledType OperatorType = OperatorFeature.ResolvedEffectiveType.Item; IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); resolvedExpression.ResolvedResult = new ResultType(OperatorTypeName, OperatorType, string.Empty); resolvedExpression.ResolvedException = new ResultException(); selectedParameterList = new SealableList <IParameter>(); selectedResultList = new SealableList <IParameter>(); resolvedArgumentList = new List <IExpressionType>(); } return(true); }
private bool FindSourceItemPrecursor(IClassType instancingClassType, IFeatureInstance featureInstance, IPrecursorInstance precursorInstance, ref ITypeName indexTypeName, ref ICompiledType indexType) { bool IsConformantToEnumerable = false; if (precursorInstance.Ancestor.BaseClass.ClassGuid == LanguageClasses.OverLoopSource.Guid) { if (precursorInstance.Precursor.Feature is IPropertyFeature AsPropertyAncestor) { if (AsPropertyAncestor.ValidFeatureName.Item.Name == "Item") { if (featureInstance.Feature is IPropertyFeature AsPropertyFeature) { Debug.Assert(indexTypeName == null); Debug.Assert(indexType == null); ITypeName IndexResultTypeName = AsPropertyFeature.ResolvedEntityTypeName.Item; ICompiledType IndexResultType = AsPropertyFeature.ResolvedEntityType.Item; IndexResultType.InstanciateType(instancingClassType, ref IndexResultTypeName, ref IndexResultType); IsConformantToEnumerable = true; indexTypeName = IndexResultTypeName; indexType = IndexResultType; } } } } return(IsConformantToEnumerable); }
private static bool ResolveCallFunction(IPrecursorExpression node, IFeatureInstance selectedPrecursor, IFunctionType callType, List <IExpressionType> mergedArgumentList, TypeArgumentStyles argumentStyle, IErrorList errorList, ref ResolvedExpression resolvedExpression, out ISealableList <IParameter> selectedParameterList, out ISealableList <IParameter> selectedResultList, out List <IExpressionType> resolvedArgumentList) { selectedParameterList = null; selectedResultList = null; resolvedArgumentList = null; IList <IArgument> ArgumentList = node.ArgumentList; ICompiledFeature OperatorFeature = selectedPrecursor.Feature; IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); foreach (IQueryOverloadType Overload in callType.OverloadList) { ParameterTableList.Add(Overload.ParameterTable); } if (!Argument.ArgumentsConformToParameters(ParameterTableList, mergedArgumentList, argumentStyle, errorList, node, out int SelectedIndex)) { return(false); } IFunctionFeature AsFunctionFeature = OperatorFeature as IFunctionFeature; Debug.Assert(AsFunctionFeature != null); Debug.Assert(AsFunctionFeature.OverloadList.Count == callType.OverloadList.Count); resolvedExpression.SelectedOverload = AsFunctionFeature.OverloadList[SelectedIndex]; resolvedExpression.SelectedOverloadType = callType.OverloadList[SelectedIndex]; resolvedExpression.ResolvedResult = new ResultType(resolvedExpression.SelectedOverloadType.ResultTypeList); resolvedExpression.ResolvedException = new ResultException(resolvedExpression.SelectedOverloadType.ExceptionIdentifierList); selectedParameterList = resolvedExpression.SelectedOverloadType.ParameterTable; selectedResultList = resolvedExpression.SelectedOverloadType.ResultTable; resolvedArgumentList = mergedArgumentList; return(true); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpFeature{T}"/> class. /// </summary> /// <param name="owner">The class where the feature is declared.</param> /// <param name="instance">The source feature instance.</param> /// <param name="source">The source Easly feature.</param> protected CSharpFeature(ICSharpClass owner, IFeatureInstance instance, T source) : base(source) { Owner = owner; Instance = instance; Debug.Assert(Instance.Feature == Source); }
/// <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) { data = null; bool Success = true; IExpression OverList = (IExpression)node.OverList; IResultType OverTypeList = OverList.ResolvedResult.Item; IScope LoopInstructions = (IScope)node.LoopInstructions; IClass EmbeddingClass = node.EmbeddingClass; bool IsOverLoopSourceTypeAvailable = Expression.IsLanguageTypeAvailable(LanguageClasses.OverLoopSource.Guid, node, out ITypeName OverLoopSourceTypeName, out ICompiledType OverLoopSourceType); bool IsNumberTypeAvailable = Expression.IsLanguageTypeAvailable(LanguageClasses.Number.Guid, node, out ITypeName NumberTypeName, out ICompiledType NumberType); foreach (IExpressionType Item in OverTypeList) { ICompiledType ResultType = Item.ValueType; IErrorList OverSourceErrorList = new ErrorList(); bool IsConformantToEnumerable = false; bool IsConformantToNumericIndexer = false; if (IsOverLoopSourceTypeAvailable && ObjectType.TypeConformToBase(ResultType, OverLoopSourceType, isConversionAllowed: true)) { IsConformantToEnumerable = true; } if (IsNumberTypeAvailable && ResultType.FeatureTable.ContainsKey(FeatureName.IndexerFeatureName)) { IFeatureInstance IndexerInstance = ResultType.FeatureTable[FeatureName.IndexerFeatureName]; IIndexerFeature IndexerFeature = IndexerInstance.Feature as IIndexerFeature; Debug.Assert(IndexerFeature != null); if (IndexerFeature.IndexParameterList.Count == 1) { IEntityDeclaration IndexParameterDeclaration = IndexerFeature.IndexParameterList[0]; if (IndexParameterDeclaration.ValidEntity.Item.ResolvedEffectiveType.Item == NumberType) { IsConformantToNumericIndexer = true; } } } Debug.Assert(IsConformantToEnumerable != IsConformantToNumericIndexer); } IResultException ResolvedException = new ResultException(); ResultException.Merge(ResolvedException, OverList.ResolvedException.Item); ResultException.Merge(ResolvedException, LoopInstructions.ResolvedException.Item); foreach (IAssertion Item in node.InvariantList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } data = ResolvedException; 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> /// 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); }
/// <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(IPrecursorIndexAssignmentInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IExpression SourceExpression = (IExpression)node.Source; IResultType SourceResult = SourceExpression.ResolvedResult.Item; IClass EmbeddingClass = node.EmbeddingClass; ISealableDictionary <string, IImportedClass> ClassTable = EmbeddingClass.ImportedClassTable; ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = EmbeddingClass.FeatureTable; IFeature InnerFeature = node.EmbeddingFeature; if (InnerFeature is IIndexerFeature AsIndexerFeature) { IFeatureInstance Instance = FeatureTable[AsIndexerFeature.ValidFeatureName.Item]; if (!Instance.FindPrecursor(node.AncestorType, ErrorList, node, out IFeatureInstance SelectedPrecursor)) { return(false); } IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); IList <ISealableList <IParameter> > ResultTableList = new List <ISealableList <IParameter> >(); ICompiledFeature OperatorFeature = SelectedPrecursor.Feature; IIndexerType AsIndexerType = OperatorFeature.ResolvedAgentType.Item as IIndexerType; Debug.Assert(AsIndexerType != null); ParameterTableList.Add(AsIndexerType.ParameterTable); ResultTableList.Add(new SealableList <IParameter>()); if (!Argument.CheckAssignmentConformance(ParameterTableList, ResultTableList, node.ArgumentList, SourceExpression, AsIndexerType.ResolvedEntityType.Item, ErrorList, node, out IFeatureCall FeatureCall)) { return(false); } IResultException ResolvedException = new ResultException(); ResultException.Merge(ResolvedException, SourceExpression.ResolvedException.Item); foreach (IArgument Item in node.ArgumentList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } ResultException.Merge(ResolvedException, AsIndexerType.SetExceptionIdentifierList); data = new Tuple <IResultException, IFeatureCall>(ResolvedException, FeatureCall); } else { AddSourceError(new ErrorInvalidInstruction(node)); return(false); } return(Success); }
private bool FindSourceItemPrecursor(IClassType instancingClassType, IFeatureInstance featureInstance, ref ITypeName indexTypeName, ref ICompiledType indexType) { bool IsConformantToEnumerable = false; foreach (IPrecursorInstance PrecursorInstance in featureInstance.PrecursorList) { IsConformantToEnumerable |= FindSourceItemPrecursor(instancingClassType, featureInstance, PrecursorInstance, ref indexTypeName, ref indexType); } return(IsConformantToEnumerable); }
private static bool CreateFeature(ICSharpClass owner, IFeatureInstance instance, out ICSharpFeature result) { result = null; bool IsHandled = false; ICompiledFeature SourceFeature = instance.Feature; switch (SourceFeature) { case IAttributeFeature AsAttributeFeature: result = CSharpAttributeFeature.Create(owner, instance, AsAttributeFeature); IsHandled = true; break; case IConstantFeature AsConstantFeature: result = CSharpConstantFeature.Create(owner, instance, AsConstantFeature); IsHandled = true; break; case ICreationFeature AsCreationFeature: result = CSharpCreationFeature.Create(owner, instance, AsCreationFeature); IsHandled = true; break; case IFunctionFeature AsFunctionFeature: result = CSharpFunctionFeature.Create(owner, instance, AsFunctionFeature); IsHandled = true; break; case IIndexerFeature AsIndexerFeature: result = CSharpIndexerFeature.Create(owner, instance, AsIndexerFeature); IsHandled = true; break; case IProcedureFeature AsProcedureFeature: result = CSharpProcedureFeature.Create(owner, instance, AsProcedureFeature); IsHandled = true; break; case IPropertyFeature AsPropertyFeature: result = CSharpPropertyFeature.Create(owner, instance, AsPropertyFeature); IsHandled = true; break; case IScopeAttributeFeature AsScopeAttributeFeature: result = CSharpScopeAttributeFeature.Create(owner, AsScopeAttributeFeature); IsHandled = true; break; } Debug.Assert(IsHandled); return(result != null); }
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 static bool ResolveCall(IPrecursorExpression node, IFeatureInstance selectedPrecursor, List <IExpressionType> mergedArgumentList, TypeArgumentStyles argumentStyle, IErrorList errorList, ref ResolvedExpression resolvedExpression, out ISealableList <IParameter> selectedParameterList, out ISealableList <IParameter> selectedResultList, out List <IExpressionType> resolvedArgumentList) { selectedParameterList = null; selectedResultList = null; resolvedArgumentList = null; IList <IArgument> ArgumentList = node.ArgumentList; ICompiledFeature OperatorFeature = selectedPrecursor.Feature; IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); bool IsHandled = false; bool Success = false; switch (OperatorFeature) { case IAttributeFeature AsAttributeFeature: case ICreationFeature AsCreationFeature: case IProcedureFeature AsProcedureFeature: case IIndexerFeature AsIndexerFeature: errorList.AddError(new ErrorInvalidExpression(node)); IsHandled = true; break; case IConstantFeature AsConstantFeature: Success = ResolveCallClass(node, selectedPrecursor, mergedArgumentList, argumentStyle, errorList, ref resolvedExpression, out selectedParameterList, out selectedResultList, out resolvedArgumentList); IsHandled = true; break; case IFunctionFeature AsFunctionFeature: IFunctionType FunctionType = AsFunctionFeature.ResolvedAgentType.Item as IFunctionType; Debug.Assert(FunctionType != null); Success = ResolveCallFunction(node, selectedPrecursor, FunctionType, mergedArgumentList, argumentStyle, errorList, ref resolvedExpression, out selectedParameterList, out selectedResultList, out resolvedArgumentList); IsHandled = true; break; case IPropertyFeature AsPropertyFeature: IPropertyType PropertyType = AsPropertyFeature.ResolvedAgentType.Item as IPropertyType; Debug.Assert(PropertyType != null); Success = ResolveCallProperty(node, selectedPrecursor, PropertyType, mergedArgumentList, argumentStyle, errorList, ref resolvedExpression, out selectedParameterList, out selectedResultList, out resolvedArgumentList); IsHandled = true; break; } Debug.Assert(IsHandled); return(Success); }
private void FillPrecursorList(IList <ICompiledFeature> precursorList, IFeatureInstance instance) { foreach (IPrecursorInstance PrecursorItem in instance.PrecursorList) { IFeatureInstance Precursor = PrecursorItem.Precursor; Debug.Assert(Precursor.Feature != null); if (!precursorList.Contains(Precursor.Feature)) { precursorList.Add(Precursor.Feature); } FillPrecursorList(precursorList, Precursor); } }
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 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 static bool ResolveSelectedPrecursor(IPrecursorIndexExpression node, IFeatureInstance selectedPrecursor, IErrorList errorList, ref ResolvedExpression resolvedExpression) { IList <IArgument> ArgumentList = node.ArgumentList; List <IExpressionType> MergedArgumentList = new List <IExpressionType>(); if (!Argument.Validate(ArgumentList, MergedArgumentList, out TypeArgumentStyles TypeArgumentStyle, errorList)) { return(false); } IIndexerFeature OperatorFeature = selectedPrecursor.Feature as IIndexerFeature; Debug.Assert(OperatorFeature != null); IIndexerType OperatorType = OperatorFeature.ResolvedAgentType.Item as IIndexerType; Debug.Assert(OperatorType != null); IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); ParameterTableList.Add(OperatorType.ParameterTable); IList <ISealableList <IParameter> > ResultTableList = new List <ISealableList <IParameter> >(); ResultTableList.Add(new SealableList <IParameter>()); int SelectedIndex; if (!Argument.ArgumentsConformToParameters(ParameterTableList, MergedArgumentList, TypeArgumentStyle, errorList, node, out SelectedIndex)) { return(false); } resolvedExpression.ResolvedResult = new ResultType(OperatorType.ResolvedEntityTypeName.Item, OperatorType.ResolvedEntityType.Item, string.Empty); resolvedExpression.ResolvedException = new ResultException(OperatorType.GetExceptionIdentifierList); resolvedExpression.FeatureCall = new FeatureCall(ParameterTableList[SelectedIndex], ResultTableList[SelectedIndex], ArgumentList, MergedArgumentList, TypeArgumentStyle); resolvedExpression.ResolvedFinalFeature = OperatorFeature; Argument.AddConstantArguments(ArgumentList, resolvedExpression.ConstantSourceList); return(true); }
private static void CreateClassFeatures(ICSharpClass cSharpClass, IList <ICSharpFeature> featureList) { foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in cSharpClass.Source.FeatureTable) { IFeatureInstance Instance = Entry.Value; Debug.Assert(Instance.Feature != null && Instance.Owner != null); // Only create features that belong to this class directly, or are not inherited from a base class. if (!IsDirectOrNotMainParentFeature(Instance, cSharpClass)) { continue; } bool IsCreated = CreateFeature(cSharpClass, Instance, out ICSharpFeature NewFeature); Debug.Assert(IsCreated); featureList.Add(NewFeature); } }
/* * Two precursor index expressions cannot be compared because it happens only when comparing different features, and there can be only one indexer. * public static bool IsExpressionEqual(IPrecursorIndexExpression expression1, IPrecursorIndexExpression expression2) * { * bool Result = true; * * if (expression1.AncestorType.IsAssigned && expression2.AncestorType.IsAssigned) * { * IObjectType AncestorType1 = (IObjectType)expression1.AncestorType; * IObjectType AncestorType2 = (IObjectType)expression2.AncestorType; * * Debug.Assert(AncestorType1.ResolvedType.IsAssigned); * Debug.Assert(AncestorType2.ResolvedType.IsAssigned); * * Result &= AncestorType1.ResolvedType.Item == AncestorType2.ResolvedType.Item; * } * * Result &= expression1.AncestorType.IsAssigned == expression2.AncestorType.IsAssigned; * Result &= Argument.IsArgumentListEqual(expression1.ArgumentList, expression2.ArgumentList); * * return Result; * } */ /// <summary> /// Finds the matching nodes of a <see cref="IPrecursorIndexExpression"/>. /// </summary> /// <param name="node">The agent expression to check.</param> /// <param name="errorList">The list of errors found.</param> /// <param name="resolvedExpression">The result of the search.</param> public static bool ResolveCompilerReferences(IPrecursorIndexExpression node, IErrorList errorList, out ResolvedExpression resolvedExpression) { resolvedExpression = new ResolvedExpression(); IOptionalReference <BaseNode.IObjectType> AncestorType = node.AncestorType; IList <IArgument> ArgumentList = node.ArgumentList; IClass EmbeddingClass = node.EmbeddingClass; ISealableDictionary <string, IImportedClass> ClassTable = EmbeddingClass.ImportedClassTable; ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = EmbeddingClass.FeatureTable; IFeature InnerFeature = node.EmbeddingFeature; if (InnerFeature is IIndexerFeature AsIndexerFeature) { IFeatureInstance Instance = FeatureTable[FeatureName.IndexerFeatureName]; if (!Instance.FindPrecursor(node.AncestorType, errorList, node, out IFeatureInstance SelectedPrecursor)) { return(false); } resolvedExpression.SelectedPrecursor = SelectedPrecursor; if (!ResolveSelectedPrecursor(node, SelectedPrecursor, errorList, ref resolvedExpression)) { return(false); } } else { errorList.AddError(new ErrorIndexPrecursorNotAllowedOutsideIndexer(node)); return(false); } #if COVERAGE Debug.Assert(!node.IsComplex); #endif return(true); }
private static bool IsDirectOrNotMainParentFeature(IFeatureInstance instance, ICSharpClass cSharpClass) { IClass Owner = instance.Owner; // Feature directly implemented in the class? if (Owner == cSharpClass.Source) { return(true); } while (cSharpClass.BaseClass != null) { cSharpClass = cSharpClass.BaseClass; // Feature implemented in one of the base classes? if (Owner == cSharpClass.Source) { return(false); } } return(true); }
private bool FindIndexer(IClassType instancingClassType, ISource source, IFeatureInstance indexerInstance, out ITypeName indexTypeName, out ICompiledType indexType) { bool IsConformantToNumericIndexer = false; indexTypeName = null; indexType = null; IIndexerFeature AsIndexer = indexerInstance.Feature as IIndexerFeature; Debug.Assert(AsIndexer != null); if (AsIndexer.IndexParameterList.Count == 1) { if (Expression.IsLanguageTypeAvailable(LanguageClasses.Number.Guid, source, out ITypeName NumberTypeName, out ICompiledType NumberType)) { IEntityDeclaration IndexParameterDeclaration = AsIndexer.IndexParameterList[0]; ICompiledType IndexParameterType = IndexParameterDeclaration.ValidEntity.Item.ResolvedEffectiveType.Item; if (IndexParameterType is IClassType AsClassIndexType) { if (AsClassIndexType == NumberType) { ITypeName IndexResultTypeName = AsIndexer.ResolvedEntityTypeName.Item; ICompiledType IndexResultType = AsIndexer.ResolvedEntityType.Item; IndexResultType.InstanciateType(instancingClassType, ref IndexResultTypeName, ref IndexResultType); IsConformantToNumericIndexer = true; indexTypeName = IndexResultTypeName; indexType = IndexResultType; } } } } return(IsConformantToNumericIndexer); }
private static bool ResolveCallProperty(IPrecursorExpression node, IFeatureInstance selectedPrecursor, IPropertyType callType, List <IExpressionType> mergedArgumentList, TypeArgumentStyles argumentStyle, IErrorList errorList, ref ResolvedExpression resolvedExpression, out ISealableList <IParameter> selectedParameterList, out ISealableList <IParameter> selectedResultList, out List <IExpressionType> resolvedArgumentList) { selectedParameterList = null; selectedResultList = null; resolvedArgumentList = null; IList <IArgument> ArgumentList = node.ArgumentList; if (ArgumentList.Count > 0) { errorList.AddError(new ErrorInvalidExpression(node)); return(false); } else { ICompiledFeature OperatorFeature = selectedPrecursor.Feature; IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); IPropertyFeature Property = (IPropertyFeature)OperatorFeature; string PropertyName = ((IFeatureWithName)Property).EntityName.Text; resolvedExpression.ResolvedResult = new ResultType(callType.ResolvedEntityTypeName.Item, callType.ResolvedEntityType.Item, PropertyName); resolvedExpression.ResolvedException = new ResultException(); if (Property.GetterBody.IsAssigned) { IBody GetterBody = (IBody)Property.GetterBody.Item; resolvedExpression.ResolvedException = new ResultException(GetterBody.ExceptionIdentifierList); } selectedParameterList = new SealableList <IParameter>(); selectedResultList = new SealableList <IParameter>(); resolvedArgumentList = new List <IExpressionType>(); 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> /// Translates nodes from the compiler to the target language. /// </summary> public override void Translate() { ErrorList.ClearErrors(); if (!CreateClasses(out IDictionary <IClass, ICSharpClass> ClassTable)) { return; } if (!CreateFeatures(ClassTable, out IDictionary <ICompiledFeature, ICSharpFeature> FeatureTable)) { return; } ICSharpContext Context = new CSharpContext(ClassTable, FeatureTable); foreach (KeyValuePair <IClass, ICSharpClass> ClassEntry in ClassTable) { ICSharpClass Class = ClassEntry.Value; IList <ICSharpFeature> ClassFeatureList = new List <ICSharpFeature>(); IList <ICSharpFeature> InheritedFeatureList = new List <ICSharpFeature>(); foreach (KeyValuePair <ICompiledFeature, ICSharpFeature> FeatureEntry in FeatureTable) { ICSharpFeature Feature = FeatureEntry.Value; IFeatureInstance Instance = Feature.Instance; if (Instance.IsDiscontinued) { continue; } if (FeatureEntry.Value.Owner == Class) { ClassFeatureList.Add(Feature); } else if (!IsDirectOrNotMainParentFeature(Instance, Class)) { InheritedFeatureList.Add(Feature); } } Class.SetFeatureList(Context, ClassFeatureList, InheritedFeatureList); } foreach (KeyValuePair <ICompiledFeature, ICSharpFeature> Entry in FeatureTable) { ICSharpFeature Feature = Entry.Value; Feature.InitOverloadsAndBodies(Context); } foreach (KeyValuePair <ICompiledFeature, ICSharpFeature> Entry in FeatureTable) { ICSharpFeature Feature = Entry.Value; Feature.InitHierarchy(Context); } foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable) { ICSharpClass Class = Entry.Value; CheckSharedName(Class, ClassTable); } foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable) { ICSharpClass Class = Entry.Value; Class.CheckOverrides(); } foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable) { ICSharpClass Class = Entry.Value; Class.CheckOverrides(); } bool Continue; do { Continue = false; foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable) { ICSharpClass Class = Entry.Value; Class.CheckForcedReadWrite(FeatureTable, ref Continue); } }while (Continue); foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable) { ICSharpClass Class = Entry.Value; Class.CheckSideBySideAttributes(); } foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable) { ICSharpClass Class = Entry.Value; Class.CheckInheritSideBySideAttributes(FeatureTable); } foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable) { ICSharpClass Class = Entry.Value; Class.CreateDelegates(); } ICSharpFeature SingledClassFeature = null; if (SingledGuid != Guid.Empty || SingledGuid == Guid.Empty) { foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable) { ICSharpClass Class = Entry.Value; if (Class.Source.ClassGuid == SingledGuid || SingledGuid == Guid.Empty || SingledGuid != Guid.Empty) { foreach (ICSharpFeature Feature in Class.FeatureList) { if (Feature is ICSharpFeatureWithName AsWithName && AsWithName.Name == SingledName) { SingledClassFeature = Feature; break; } } } if (SingledClassFeature != null) { break; } } } if (SingledClassFeature == null) { foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable) { ICSharpClass Class = Entry.Value; Class.SetWriteDown(); foreach (ICSharpFeature Feature in Class.FeatureList) { Feature.SetWriteDown(); } foreach (ICSharpAssertion Invariant in Class.InvariantList) { Invariant.SetWriteDown(); } } } else { SingledClassFeature.SetWriteDown(); } if (!Directory.Exists(OutputRootFolder)) { Directory.CreateDirectory(OutputRootFolder); } foreach (KeyValuePair <IClass, ICSharpClass> Entry in ClassTable) { ICSharpClass Class = Entry.Value; if (!CSharpClass.IsLanguageClass(Class.Source) && !IsClassFromLibrary(Class.Source)) { if (Class.WriteDown) { Class.Write(OutputRootFolder, Namespace, SourceFileName, SingledClassFeature); } } } }
/// <summary> /// Create a new C# constructor. /// </summary> /// <param name="owner">The class where the feature is declared.</param> /// <param name="instance">The source feature instance.</param> /// <param name="source">The source Easly feature.</param> public static ICSharpCreationFeature Create(ICSharpClass owner, IFeatureInstance instance, ICreationFeature source) { return(new CSharpCreationFeature(owner, instance, source)); }
public void Register(IFeatureInstance instance) => _instances.Add(instance);
/// <summary> /// Initializes a new instance of the <see cref="CSharpCreationFeature"/> class. /// </summary> /// <param name="owner">The class where the feature is declared.</param> /// <param name="instance">The source feature instance.</param> /// <param name="source">The source Easly feature.</param> protected CSharpCreationFeature(ICSharpClass owner, IFeatureInstance instance, ICreationFeature source) : base(owner, instance, source) { Name = Source.ValidFeatureName.Item.Name; }
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); } }
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 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); } } }