/// <summary> /// Applies the rule. /// </summary> /// <param name="node">The node instance to modify.</param> /// <param name="data">Private data from CheckConsistency().</param> public override void Apply(IPrecursorExpression node, object data) { ILanguageConstant ExpressionConstant = NeutralLanguageConstant.NotConstant; Debug.Assert(node.ConstantSourceList.Count > 0); bool IsConstant = true; foreach (IExpression ConstantSource in node.ConstantSourceList) { IsConstant &= ConstantSource.ExpressionConstant.Item != NeutralLanguageConstant.NotConstant; } if (IsConstant) { ExpressionConstant = new ObjectLanguageConstant(); Debug.Assert(node.ResolvedPrecursor.IsAssigned); ICompiledFeature FinalFeature = node.ResolvedPrecursor.Item.Feature; if (FinalFeature is IConstantFeature AsConstantFeature) { Debug.Assert(node.ConstantSourceList.Count == 1); Debug.Assert(node.ConstantSourceList[0].ExpressionConstant.IsAssigned); ExpressionConstant = node.ConstantSourceList[0].ExpressionConstant.Item; } else { ExpressionConstant = Expression.GetDefaultConstant(node, node.ResolvedResult.Item); } } node.ExpressionConstant.Item = ExpressionConstant; }
/// <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(IInitializedObjectExpression node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; foreach (IAssignmentArgument AssignmentItem in node.AssignmentList) { Debug.Assert(AssignmentItem.ExpressionConstant.IsAssigned); ILanguageConstant ExpressionConstant = AssignmentItem.ExpressionConstant.Item; if (ExpressionConstant == NeutralLanguageConstant.NotConstant) { AddSourceError(new ErrorConstantExpected(AssignmentItem)); Success = false; } } if (Success) { data = new ObjectLanguageConstant(); } return(Success); }
/// <summary> /// Checks if another constant is equal to this instance. /// </summary> /// <param name="other">The other instance.</param> protected virtual bool IsConstantEqual(ObjectLanguageConstant other) { Debug.Assert(other != null); return(ConstantInstance == other.ConstantInstance); }