/// <summary> /// Initializes a new instance of the <see cref="CSharpPrecursorIndexExpression"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly expression from which the C# expression is created.</param> protected CSharpPrecursorIndexExpression(ICSharpContext context, IPrecursorIndexExpression source) : base(context, source) { ParentFeature = context.GetFeature((ICompiledFeature)source.EmbeddingFeature) as ICSharpIndexerFeature; Debug.Assert(ParentFeature != null); FeatureCall = new CSharpFeatureCall(context, source.FeatureCall.Item); }
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); }
/* * 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); }
/// <summary> /// Creates a new C# expression. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly expression from which the C# expression is created.</param> public static ICSharpPrecursorIndexExpression Create(ICSharpContext context, IPrecursorIndexExpression source) { return(new CSharpPrecursorIndexExpression(context, source)); }