/// <summary> /// Compares two expressions. /// </summary> /// <param name="other">The other expression.</param> protected bool IsExpressionEqual(IAgentExpression other) { Debug.Assert(other != null); bool Result = true; Result &= Delegated.Text == other.Delegated.Text; return(Result); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpAgentExpression"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly expression from which the C# expression is created.</param> protected CSharpAgentExpression(ICSharpContext context, IAgentExpression source) : base(context, source) { string DelegatedName = ((IIdentifier)Source.Delegated).ValidText.Item; if (source.BaseType.IsAssigned) { IObjectType SourceBaseType = (IObjectType)source.BaseType.Item; ICompiledType ResolvedBaseType = SourceBaseType.ResolvedType.Item; BaseType = CSharpType.Create(context, ResolvedBaseType) as ICSharpTypeWithFeature; Debug.Assert(BaseType != null); EffectiveBaseType = BaseType; foreach (ICSharpClassType ClassType in BaseType.ConformingClassTypeList) { foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in ClassType.Source.FeatureTable) { if (Entry.Key.Name == DelegatedName) { Debug.Assert(Delegated == null); ICompiledFeature Feature = Entry.Value.Feature; Delegated = context.GetFeature(Feature) as ICSharpFeatureWithName; if (ResolvedBaseType is IFormalGenericType) { EffectiveBaseType = ClassType; } } } } } else { Delegated = context.GetFeature(source.ResolvedFeature.Item) as ICSharpFeatureWithName; } Debug.Assert(Delegated != null); }
/// <summary> /// Finds the matching nodes of a <see cref="IAgentExpression"/>. /// </summary> /// <param name="node">The agent expression to check.</param> /// <param name="errorList">The list of errors found.</param> /// <param name="resolvedResult">The expression result types upon return.</param> /// <param name="resolvedException">Exceptions the expression can throw upon return.</param> /// <param name="constantSourceList">Sources of the constant expression upon return, if any.</param> /// <param name="expressionConstant">The constant value upon return, if any.</param> /// <param name="resolvedFeature">The feature found upon return.</param> public static bool ResolveCompilerReferences(IAgentExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant, out ICompiledFeature resolvedFeature) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; resolvedFeature = null; IIdentifier Delegated = (IIdentifier)node.Delegated; Debug.Assert(Delegated.ValidText.IsAssigned); string ValidText = Delegated.ValidText.Item; IFeatureInstance FeatureInstance; if (node.BaseType.IsAssigned) { IObjectType BaseType = (IObjectType)node.BaseType.Item; ICompiledType ResolvedBaseType = BaseType.ResolvedType.Item; ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = null; switch (ResolvedBaseType) { case IClassType AsClassType: FeatureTable = AsClassType.FeatureTable; break; case IFormalGenericType AsFormalGenericType: foreach (IConstraint Item in AsFormalGenericType.FormalGeneric.ConstraintList) { if (Item.ResolvedTypeWithRename.Item is IClassType Parent) { FeatureTable = Parent.FeatureTable; if (FeatureName.TableContain(FeatureTable, ValidText, out IFeatureName ParentKey, out IFeatureInstance ParentFeatureInstance)) { break; } } } break; } if (FeatureTable == null) { errorList.AddError(new ErrorClassTypeRequired(node)); return(false); } if (!FeatureName.TableContain(FeatureTable, ValidText, out IFeatureName Key, out FeatureInstance)) { errorList.AddError(new ErrorUnknownIdentifier(node, ValidText)); return(false); } } else { IClass EmbeddingClass = node.EmbeddingClass; if (!FeatureName.TableContain(EmbeddingClass.FeatureTable, ValidText, out IFeatureName Key, out FeatureInstance)) { errorList.AddError(new ErrorUnknownIdentifier(node, ValidText)); return(false); } } Debug.Assert(FeatureInstance.Feature != null); resolvedFeature = FeatureInstance.Feature; resolvedResult = new ResultType(resolvedFeature.ResolvedAgentTypeName.Item, resolvedFeature.ResolvedAgentType.Item, string.Empty); resolvedException = new ResultException(); expressionConstant = new AgentLanguageConstant(resolvedFeature); #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 ICSharpAgentExpression Create(ICSharpContext context, IAgentExpression source) { return(new CSharpAgentExpression(context, source)); }