/// <summary> /// Compares two types. /// </summary> /// <param name="type1">The first type.</param> /// <param name="type2">The second type.</param> public static bool TypesHaveIdenticalSignature(IIndexerType type1, IIndexerType type2) { bool IsIdentical = true; IsIdentical &= ObjectType.TypesHaveIdenticalSignature(type1.ResolvedBaseType.Item, type2.ResolvedBaseType.Item); IsIdentical &= ObjectType.TypesHaveIdenticalSignature(type1.ResolvedEntityType.Item, type2.ResolvedEntityType.Item); IsIdentical &= type1.IndexerKind == type2.IndexerKind; IsIdentical &= type1.IndexParameterList.Count == type2.IndexParameterList.Count; IsIdentical &= type1.ParameterEnd == type2.ParameterEnd; for (int i = 0; i < type1.IndexParameterList.Count && i < type2.IndexParameterList.Count; i++) { Debug.Assert(type1.IndexParameterList[i].ValidEntity.IsAssigned); Debug.Assert(type1.IndexParameterList[i].ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Debug.Assert(type2.IndexParameterList[i].ValidEntity.IsAssigned); Debug.Assert(type2.IndexParameterList[i].ValidEntity.Item.ResolvedEffectiveType.IsAssigned); IsIdentical &= ObjectType.TypesHaveIdenticalSignature(type1.IndexParameterList[i].ValidEntity.Item.ResolvedEffectiveType.Item, type2.IndexParameterList[i].ValidEntity.Item.ResolvedEffectiveType.Item); } IsIdentical &= Assertion.IsAssertionListEqual(type1.GetRequireList, type2.GetRequireList); IsIdentical &= Assertion.IsAssertionListEqual(type1.GetEnsureList, type2.GetEnsureList); IsIdentical &= ExceptionHandler.IdenticalExceptionSignature(type1.GetExceptionIdentifierList, type2.GetExceptionIdentifierList); IsIdentical &= Assertion.IsAssertionListEqual(type1.SetRequireList, type2.SetRequireList); IsIdentical &= Assertion.IsAssertionListEqual(type1.SetEnsureList, type2.SetEnsureList); IsIdentical &= ExceptionHandler.IdenticalExceptionSignature(type1.SetExceptionIdentifierList, type2.SetExceptionIdentifierList); return(IsIdentical); }
/// <summary> /// Initializes a new instance of the <see cref="ErrorParameterMismatchConformance"/> class. /// </summary> /// <param name="source">The error location.</param> /// <param name="derivedType">The derived type</param> /// <param name="baseType">The base type.</param> public ErrorParameterMismatchConformance(ISource source, IIndexerType derivedType, IIndexerType baseType) : base(source) { DerivedParameterList = derivedType.IndexParameterList; DerivedParameterEnd = derivedType.ParameterEnd; BaseParameterList = baseType.IndexParameterList; BaseParameterEnd = baseType.ParameterEnd; }
private static bool IndexerTypeConformToProcedureType(IIndexerType derivedType, IProcedureType baseType, IErrorList errorList, ISource sourceLocation) { bool Result = true; Debug.Assert(derivedType.ResolvedBaseType.IsAssigned); Debug.Assert(baseType.ResolvedBaseType.IsAssigned); Result &= TypeConformToBase(derivedType.ResolvedBaseType.Item, baseType.ResolvedBaseType.Item, errorList, sourceLocation, isConversionAllowed: false); if (derivedType.IndexerKind == BaseNode.UtilityType.ReadOnly) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; } if (baseType.OverloadList.Count > 1) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; } ICommandOverloadType SingleOverload = baseType.OverloadList[0]; if (SingleOverload.ParameterList.Count != derivedType.IndexParameterList.Count + 1 || SingleOverload.ParameterEnd != BaseNode.ParameterEndStatus.Closed) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; } for (int i = 0; i + 1 < SingleOverload.ParameterList.Count && i < derivedType.IndexParameterList.Count; i++) { IEntityDeclaration BaseParameter = SingleOverload.ParameterList[i]; IEntityDeclaration DerivedParameter = derivedType.IndexParameterList[i]; Debug.Assert(BaseParameter.ValidEntity.IsAssigned); Debug.Assert(BaseParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Debug.Assert(DerivedParameter.ValidEntity.IsAssigned); Debug.Assert(DerivedParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Result &= TypeConformToBase(DerivedParameter.ValidEntity.Item.ResolvedEffectiveType.Item, BaseParameter.ValidEntity.Item.ResolvedEffectiveType.Item, errorList, sourceLocation, isConversionAllowed: false); } if (SingleOverload.ParameterList.Count == derivedType.IndexParameterList.Count + 1) { Debug.Assert(derivedType.ResolvedEntityType.IsAssigned); IEntityDeclaration LastParameter = SingleOverload.ParameterList[derivedType.IndexParameterList.Count]; Debug.Assert(LastParameter.ValidEntity.IsAssigned); Debug.Assert(LastParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Result &= TypeConformToBase(derivedType.ResolvedEntityType.Item, LastParameter.ValidEntity.Item.ResolvedEffectiveType.Item, errorList, sourceLocation, isConversionAllowed: false); } Result &= ExceptionListConformToBase(derivedType.SetExceptionIdentifierList, SingleOverload.ExceptionIdentifierList, errorList, sourceLocation); return(Result); }
private static bool IsSameTypes(IIndexerType indexerType, ICompiledType baseType, ICompiledType entityType, BaseNode.UtilityType indexerKind) { bool IsSame = true; IsSame &= indexerType.ResolvedBaseType.Item == baseType; IsSame &= indexerType.ResolvedEntityType.Item == entityType; IsSame &= indexerType.IndexerKind == indexerKind; return(IsSame); }
/// <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 static bool IndexerTypeConformToIndexerType(IIndexerType derivedType, IIndexerType baseType, IErrorList errorList, ISource sourceLocation) { bool Result = true; Debug.Assert(derivedType.ResolvedBaseType.IsAssigned); Debug.Assert(baseType.ResolvedBaseType.IsAssigned); Result &= TypeConformToBase(derivedType.ResolvedBaseType.Item, baseType.ResolvedBaseType.Item, errorList, sourceLocation, isConversionAllowed: false); if ((baseType.IndexerKind == BaseNode.UtilityType.ReadOnly && derivedType.IndexerKind == BaseNode.UtilityType.WriteOnly) || (baseType.IndexerKind == BaseNode.UtilityType.WriteOnly && derivedType.IndexerKind == BaseNode.UtilityType.ReadOnly) || (baseType.IndexerKind == BaseNode.UtilityType.ReadWrite && derivedType.IndexerKind != BaseNode.UtilityType.ReadWrite)) { errorList.AddError(new ErrorGetterSetterConformance(sourceLocation, derivedType, baseType)); Result = false; } if (derivedType.IndexParameterList.Count != baseType.IndexParameterList.Count || derivedType.ParameterEnd != baseType.ParameterEnd) { errorList.AddError(new ErrorParameterMismatchConformance(sourceLocation, derivedType, baseType)); Result = false; } for (int i = 0; i < baseType.IndexParameterList.Count && i < derivedType.IndexParameterList.Count; i++) { IEntityDeclaration BaseParameter = baseType.IndexParameterList[i]; IEntityDeclaration DerivedParameter = derivedType.IndexParameterList[i]; Debug.Assert(DerivedParameter.ValidEntity.IsAssigned); Debug.Assert(DerivedParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Debug.Assert(BaseParameter.ValidEntity.IsAssigned); Debug.Assert(BaseParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Result &= TypeConformToBase(DerivedParameter.ValidEntity.Item.ResolvedEffectiveType.Item, BaseParameter.ValidEntity.Item.ResolvedEffectiveType.Item, errorList, sourceLocation, isConversionAllowed: false); } Debug.Assert(derivedType.ResolvedEntityType.IsAssigned); Debug.Assert(baseType.ResolvedEntityType.IsAssigned); Result &= TypeConformToBase(derivedType.ResolvedEntityType.Item, baseType.ResolvedEntityType.Item, errorList, sourceLocation, isConversionAllowed: false); /* * if (!TypesHaveIdenticalSignature(derivedType.ResolvedEntityType.Item, baseType.ResolvedEntityType.Item)) * { * //errorList.Add(new ConformanceError(sourceLocation)); * return false; * } */ Result &= ExceptionListConformToBase(derivedType.GetExceptionIdentifierList, baseType.GetExceptionIdentifierList, errorList, sourceLocation); Result &= ExceptionListConformToBase(derivedType.SetExceptionIdentifierList, baseType.SetExceptionIdentifierList, errorList, sourceLocation); return(Result); }
private static bool IndexerTypeConformToFunctionType(IIndexerType derivedType, IFunctionType baseType, IErrorList errorList, ISource sourceLocation) { bool Result = true; Debug.Assert(derivedType.ResolvedBaseType.IsAssigned); Debug.Assert(baseType.ResolvedBaseType.IsAssigned); Result &= TypeConformToBase(derivedType.ResolvedBaseType.Item, baseType.ResolvedBaseType.Item, errorList, sourceLocation, isConversionAllowed: false); if (derivedType.IndexerKind == BaseNode.UtilityType.WriteOnly) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; } if (baseType.OverloadList.Count > 1) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; } IQueryOverloadType SingleOverload = baseType.OverloadList[0]; if (SingleOverload.ParameterList.Count != derivedType.IndexParameterList.Count || SingleOverload.ResultList.Count != 1 || SingleOverload.ParameterEnd != derivedType.ParameterEnd) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; } for (int i = 0; i < SingleOverload.ParameterList.Count && i < derivedType.IndexParameterList.Count; i++) { IEntityDeclaration BaseParameter = SingleOverload.ParameterList[i]; IEntityDeclaration DerivedParameter = derivedType.IndexParameterList[i]; Debug.Assert(DerivedParameter.ValidEntity.IsAssigned); Debug.Assert(DerivedParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Debug.Assert(BaseParameter.ValidEntity.IsAssigned); Debug.Assert(BaseParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Result &= TypeConformToBase(DerivedParameter.ValidEntity.Item.ResolvedEffectiveType.Item, BaseParameter.ValidEntity.Item.ResolvedEffectiveType.Item, errorList, sourceLocation, isConversionAllowed: false); } IEntityDeclaration OverloadResult = SingleOverload.ResultList[0]; Debug.Assert(OverloadResult.ValidEntity.IsAssigned); Debug.Assert(OverloadResult.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Debug.Assert(derivedType.ResolvedEntityType.IsAssigned); Result &= TypeConformToBase(OverloadResult.ValidEntity.Item.ResolvedEffectiveType.Item, derivedType.ResolvedEntityType.Item, errorList, sourceLocation, isConversionAllowed: false); Result &= ExceptionListConformToBase(derivedType.GetExceptionIdentifierList, SingleOverload.ExceptionIdentifierList, errorList, sourceLocation); return(Result); }
private static bool IsSameContract(IIndexerType indexerType, IList <IAssertion> getRequireList, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IAssertion> setEnsureList, IList <IIdentifier> setExceptionIdentifierList) { bool IsSame = true; IsSame &= Assertion.IsAssertionListEqual(indexerType.GetRequireList, getRequireList); IsSame &= Assertion.IsAssertionListEqual(indexerType.GetEnsureList, getEnsureList); IsSame &= ExceptionHandler.IdenticalExceptionSignature(indexerType.GetExceptionIdentifierList, getExceptionIdentifierList); IsSame &= Assertion.IsAssertionListEqual(indexerType.SetRequireList, setRequireList); IsSame &= Assertion.IsAssertionListEqual(indexerType.SetEnsureList, setEnsureList); IsSame &= ExceptionHandler.IdenticalExceptionSignature(indexerType.SetExceptionIdentifierList, setExceptionIdentifierList); return(IsSame); }
private static bool IsSameParameters(IIndexerType indexerType, IList <IEntityDeclaration> indexParameterList, BaseNode.ParameterEndStatus parameterEnd) { bool IsSame = true; IsSame &= indexerType.IndexParameterList.Count == indexParameterList.Count; for (int i = 0; i < indexerType.IndexParameterList.Count && i < indexParameterList.Count; i++) { IsSame &= indexParameterList[i].ValidEntity.Item.ResolvedEffectiveType.Item == indexerType.IndexParameterList[i].ValidEntity.Item.ResolvedEffectiveType.Item; } IsSame &= indexerType.ParameterEnd == parameterEnd; return(IsSame); }
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 bool TypeConformToIndexerType(ICompiledType derivedType, IIndexerType baseType, IErrorList errorList, ISource sourceLocation) { bool Result = false; bool IsHandled = false; if (derivedType is IClassType AsClassType) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; IsHandled = true; } else if (derivedType is IFunctionType AsFunctionType) { Result = FunctionTypeConformToIndexerType(AsFunctionType, baseType, errorList, sourceLocation); IsHandled = true; } else if (derivedType is IProcedureType AsProcedureType) { Result = ProcedureTypeConformToIndexerType(AsProcedureType, baseType, errorList, sourceLocation); IsHandled = true; } else if (derivedType is IPropertyType AsPropertyType) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; IsHandled = true; } else if (derivedType is IIndexerType AsIndexerType) { Result = IndexerTypeConformToIndexerType(AsIndexerType, baseType, errorList, sourceLocation); IsHandled = true; } else if (derivedType is ITupleType AsTupleType) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; IsHandled = true; } Debug.Assert(IsHandled); return(Result); }
private static bool ProcedureTypeConformToIndexerType(IProcedureType derivedType, IIndexerType baseType, IErrorList errorList, ISource sourceLocation) { bool Result = true; Debug.Assert(derivedType.ResolvedBaseType.IsAssigned); Debug.Assert(baseType.ResolvedBaseType.IsAssigned); Result &= TypeConformToBase(derivedType.ResolvedBaseType.Item, baseType.ResolvedBaseType.Item, errorList, sourceLocation, isConversionAllowed: false); if (baseType.IndexerKind != BaseNode.UtilityType.WriteOnly) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; } bool MatchingOverload = false; foreach (ICommandOverloadType DerivedOverload in derivedType.OverloadList) { MatchingOverload |= ProcedureTypeConformToIndexerTypeOverloads(DerivedOverload, baseType, errorList, sourceLocation); } if (!MatchingOverload) { errorList.AddError(new ErrorTypeKindConformance(sourceLocation, derivedType, baseType)); Result = false; } return(Result); }
private static bool ProcedureTypeConformToIndexerTypeOverloads(ICommandOverloadType derivedOverload, IIndexerType baseType, IErrorList errorList, ISource sourceLocation) { bool Result = true; Result &= derivedOverload.ParameterList.Count == baseType.IndexParameterList.Count + 1 && derivedOverload.ParameterEnd == BaseNode.ParameterEndStatus.Closed; for (int i = 0; i + 1 < derivedOverload.ParameterList.Count && i < baseType.IndexParameterList.Count; i++) { IEntityDeclaration BaseParameter = baseType.IndexParameterList[i]; IEntityDeclaration DerivedParameter = derivedOverload.ParameterList[i]; Debug.Assert(DerivedParameter.ValidEntity.IsAssigned); Debug.Assert(DerivedParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Debug.Assert(BaseParameter.ValidEntity.IsAssigned); Debug.Assert(BaseParameter.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Result &= TypeConformToBase(DerivedParameter.ValidEntity.Item.ResolvedEffectiveType.Item, BaseParameter.ValidEntity.Item.ResolvedEffectiveType.Item, errorList, sourceLocation, isConversionAllowed: false); } if (derivedOverload.ParameterList.Count == baseType.IndexParameterList.Count + 1) { IEntityDeclaration OverloadValue = derivedOverload.ParameterList[baseType.IndexParameterList.Count]; Debug.Assert(OverloadValue.ValidEntity.IsAssigned); Debug.Assert(OverloadValue.ValidEntity.Item.ResolvedEffectiveType.IsAssigned); Debug.Assert(baseType.ResolvedEntityType.IsAssigned); Result &= TypeConformToBase(OverloadValue.ValidEntity.Item.ResolvedEffectiveType.Item, baseType.ResolvedEntityType.Item, ErrorList.Ignored, ErrorList.NoLocation, isConversionAllowed: false); Result &= ExceptionListConformToBase(derivedOverload.ExceptionIdentifierList, baseType.SetExceptionIdentifierList, errorList, sourceLocation); } return(Result); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpIndexerType"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly type from which the C# type is created.</param> protected CSharpIndexerType(ICSharpContext context, IIndexerType source) : base(context, 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(IIndexAssignmentInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IQualifiedName Destination = (IQualifiedName)node.Destination; IExpression Source = (IExpression)node.Source; IList <IIdentifier> ValidPath = Destination.ValidPath.Item; IClass EmbeddingClass = node.EmbeddingClass; IClassType BaseType = EmbeddingClass.ResolvedClassType.Item; ISealableDictionary <string, IScopeAttributeFeature> LocalScope = Scope.CurrentScope(node); if (!ObjectType.GetQualifiedPathFinalType(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, ErrorList, out ICompiledFeature FinalFeature, out IDiscrete FinalDiscrete, out ITypeName FinalTypeName, out ICompiledType FinalType, out bool InheritBySideAttribute)) { return(false); } Debug.Assert(FinalFeature != null); FinalType = FinalFeature.ResolvedEffectiveType.Item; if (FinalType is IClassType AsClassType) { IClass IndexedBaseClass = AsClassType.BaseClass; ISealableDictionary <IFeatureName, IFeatureInstance> IndexedFeatureTable = IndexedBaseClass.FeatureTable; if (!IndexedFeatureTable.ContainsKey(FeatureName.IndexerFeatureName)) { AddSourceError(new ErrorMissingIndexer(node)); return(false); } IFeatureInstance IndexerInstance = IndexedFeatureTable[FeatureName.IndexerFeatureName]; IIndexerFeature Indexer = (IndexerFeature)IndexerInstance.Feature; IIndexerType AsIndexerType = (IndexerType)Indexer.ResolvedAgentType.Item; bool IsReadOnlyIndexer = Indexer.GetterBody.IsAssigned && !Indexer.SetterBody.IsAssigned; bool IsReadOnlyIndexerType = AsIndexerType.IndexerKind == BaseNode.UtilityType.ReadOnly; Debug.Assert(IsReadOnlyIndexerType == IsReadOnlyIndexer); if (IsReadOnlyIndexer) { AddSourceError(new ErrorInvalidInstruction(node)); return(false); } else { IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); ParameterTableList.Add(AsIndexerType.ParameterTable); IList <ISealableList <IParameter> > ResultTableList = new List <ISealableList <IParameter> >(); ResultTableList.Add(new SealableList <IParameter>()); ICompiledType DestinationType = AsIndexerType.ResolvedEntityType.Item; if (!Argument.CheckAssignmentConformance(ParameterTableList, ResultTableList, node.ArgumentList, Source, DestinationType, ErrorList, node, out IFeatureCall FeatureCall)) { return(false); } ObjectType.FillResultPath(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, Destination.ValidResultTypePath.Item); IResultException ResolvedException = new ResultException(); ResultException.Merge(ResolvedException, AsIndexerType.SetExceptionIdentifierList); foreach (IArgument Item in node.ArgumentList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } data = new Tuple <IResultException, IFeatureCall>(ResolvedException, FeatureCall); } } else { AddSourceError(new ErrorInvalidInstruction(node)); return(false); } return(Success); }
/// <summary> /// Finds the matching nodes of a <see cref="IIndexQueryExpression"/>. /// </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(IIndexQueryExpression node, IErrorList errorList, out ResolvedExpression resolvedExpression) { resolvedExpression = new ResolvedExpression(); IExpression IndexedExpression = (IExpression)node.IndexedExpression; IList <IArgument> ArgumentList = node.ArgumentList; IClass EmbeddingClass = node.EmbeddingClass; IResultType ResolvedIndexerResult = IndexedExpression.ResolvedResult.Item; IExpressionType PreferredIndexerResult = ResolvedIndexerResult.Preferred; ICompiledType IndexedExpressionType; if (PreferredIndexerResult == null) { errorList.AddError(new ErrorInvalidExpression(node)); return(false); } else { IndexedExpressionType = PreferredIndexerResult.ValueType; } if (IndexedExpressionType is IClassType AsClassType) { IClass IndexedBaseClass = AsClassType.BaseClass; ISealableDictionary <IFeatureName, IFeatureInstance> IndexedFeatureTable = IndexedBaseClass.FeatureTable; if (!IndexedFeatureTable.ContainsKey(FeatureName.IndexerFeatureName)) { errorList.AddError(new ErrorMissingIndexer(node)); return(false); } IFeatureInstance IndexerInstance = IndexedFeatureTable[FeatureName.IndexerFeatureName]; IIndexerFeature Indexer = (IndexerFeature)IndexerInstance.Feature; IIndexerType AsIndexerType = (IndexerType)Indexer.ResolvedAgentType.Item; List <IExpressionType> MergedArgumentList = new List <IExpressionType>(); if (!Argument.Validate(ArgumentList, MergedArgumentList, out TypeArgumentStyles TypeArgumentStyle, errorList)) { return(false); } IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); ParameterTableList.Add(AsIndexerType.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.ResolvedFinalFeature = Indexer; resolvedExpression.ResolvedResult = new ResultType(AsIndexerType.ResolvedEntityTypeName.Item, AsIndexerType.ResolvedEntityType.Item, string.Empty); resolvedExpression.ResolvedException = new ResultException(AsIndexerType.GetExceptionIdentifierList); resolvedExpression.FeatureCall = new FeatureCall(ParameterTableList[SelectedIndex], ResultTableList[SelectedIndex], ArgumentList, MergedArgumentList, TypeArgumentStyle); Argument.AddConstantArguments(ArgumentList, resolvedExpression.ConstantSourceList); } else { errorList.AddError(new ErrorInvalidExpression(node)); return(false); } #if COVERAGE Debug.Assert(!node.IsComplex); #endif return(true); }
/// <summary> /// Create a new C# type. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly type from which the C# type is created.</param> public static ICSharpIndexerType Create(ICSharpContext context, IIndexerType source) { return(new CSharpIndexerType(context, source)); }