protected override void Analyze(IMultiplicativeExpression expression, ElementProblemAnalyzerData data, IHighlightingConsumer consumer) { var byLeft = MultiplicativeExpressionNavigator.GetByLeftOperand(expression.GetContainingParenthesizedExpression()); if (byLeft != null) { return; } var byRight = MultiplicativeExpressionNavigator.GetByRightOperand(expression.GetContainingParenthesizedExpression()); if (byRight != null) { return; } var(count, hasUnknownType) = CalculateMatrixIntMulCount(expression); if (hasUnknownType) { return; } if (count > GetElementCount(expression.GetExpressionType())) { consumer.AddHighlighting(new InefficientMultiplicationOrderWarning(expression)); } }
protected override void Analyze(ICSharpExpression expression, ElementProblemAnalyzerData data, IHighlightingConsumer consumer) { var parent = expression.GetContainingParenthesizedExpression()?.Parent as ICSharpExpression; if (GetMulOperation(expression) != null || GetMulOperation(parent) == null) { return; } if (IsMatrixType(expression.GetExpressionType())) { var count = 0; ICSharpExpression scalar = null; while (true) { count++; var curExpr = parent.GetContainingParenthesizedExpression(); var byLeft = MultiplicativeExpressionNavigator.GetByLeftOperand(curExpr); var byRight = MultiplicativeExpressionNavigator.GetByRightOperand(curExpr); if (byLeft == null && byRight != null) { scalar = byRight?.LeftOperand; parent = byRight; } else if (byRight == null && byLeft != null) { scalar = byLeft?.RightOperand; parent = byLeft; } else { break; } } // incomplete expression if (scalar == null) { return; } if (count > 1) { Assertion.Assert(scalar != null, "scalar != null"); consumer.AddHighlighting(new InefficientMultiplicationOrderWarning(parent, expression, scalar)); } } }