From a97891cbc131bb7fc94fbede286832a675db2cba Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Tue, 19 Mar 2024 12:56:15 +0000 Subject: [PATCH] C++: Add QLDoc to 'getNumberOfBinaryOperands' (and rename it to 'getNumberOfNestedBinaryOperands'). --- .../ir/implementation/raw/internal/TranslatedElement.qll | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll index e96959f5a68..d258056f11f 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll @@ -40,9 +40,14 @@ IRTempVariable getIRTempVariable(Locatable ast, TempVariableTag tag) { result.getTag() = tag } +/** Gets an operand of `binOp`. */ private Expr getAnOperand(BinaryOperation binOp) { result = binOp.getAnOperand() } -private int getNumberOfBinaryOperands(BinaryOperation binOp) { +/** + * Gets the number of nested operands of `binOp`. For example, + * `getNumberOfNestedBinaryOperands((1 + 2) + 3))` is `3`. + */ +private int getNumberOfNestedBinaryOperands(BinaryOperation binOp) { result = count(getAnOperand*(binOp)) } @@ -60,7 +65,7 @@ predicate isIRConstant(Expr expr) { // But to avoid creating an outrageous amount of IR from very large // constant expressions we fall back to constant folding if the operation // has more than 50 operands (i.e., 1 + 2 + 3 + 4 + ... + 50) - if expr instanceof BinaryOperation then getNumberOfBinaryOperands(expr) > 50 else any() + if expr instanceof BinaryOperation then getNumberOfNestedBinaryOperands(expr) > 50 else any() } // Pulled out for performance. See