/// <summary> /// Compares two expressions. /// </summary> /// <param name="other">The other expression.</param> protected bool IsExpressionEqual(IIndexQueryExpression other) { Debug.Assert(other != null); bool Result = true; Result &= Expression.IsExpressionEqual((IExpression)IndexedExpression, (IExpression)other.IndexedExpression); Result &= Argument.IsArgumentListEqual(ArgumentList, other.ArgumentList); return(Result); }
/// <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> /// Initializes a new instance of the <see cref="CSharpIndexQueryExpression"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly expression from which the C# expression is created.</param> protected CSharpIndexQueryExpression(ICSharpContext context, IIndexQueryExpression source) : base(context, source) { IndexedExpression = Create(context, (IExpression)source.IndexedExpression); FeatureCall = new CSharpFeatureCall(context, source.FeatureCall.Item); }
/// <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 ICSharpIndexQueryExpression Create(ICSharpContext context, IIndexQueryExpression source) { return(new CSharpIndexQueryExpression(context, source)); }