diff --git a/cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/PrintIR.qll b/cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/PrintIR.qll index 41e1a4c3082d..7871ddb16189 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/PrintIR.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/PrintIR.qll @@ -396,9 +396,7 @@ private int maxColumnWidth() { } private string getPaddingString(int n) { - n = 0 and result = "" - or - n > 0 and n <= maxColumnWidth() and result = getPaddingString(n - 1) + " " + n = [0 .. maxColumnWidth()] and result = concat(int i | i in [1 .. n] | " ") } /** diff --git a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/PrintIR.qll b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/PrintIR.qll index 41e1a4c3082d..7871ddb16189 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/PrintIR.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/PrintIR.qll @@ -396,9 +396,7 @@ private int maxColumnWidth() { } private string getPaddingString(int n) { - n = 0 and result = "" - or - n > 0 and n <= maxColumnWidth() and result = getPaddingString(n - 1) + " " + n = [0 .. maxColumnWidth()] and result = concat(int i | i in [1 .. n] | " ") } /** diff --git a/cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/PrintIR.qll b/cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/PrintIR.qll index 41e1a4c3082d..7871ddb16189 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/PrintIR.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/PrintIR.qll @@ -396,9 +396,7 @@ private int maxColumnWidth() { } private string getPaddingString(int n) { - n = 0 and result = "" - or - n > 0 and n <= maxColumnWidth() and result = getPaddingString(n - 1) + " " + n = [0 .. maxColumnWidth()] and result = concat(int i | i in [1 .. n] | " ") } /** diff --git a/cpp/ql/test/library-tests/blocks/c/code_blocks.ql b/cpp/ql/test/library-tests/blocks/c/code_blocks.ql index 1662525cae6e..647923eea563 100644 --- a/cpp/ql/test/library-tests/blocks/c/code_blocks.ql +++ b/cpp/ql/test/library-tests/blocks/c/code_blocks.ql @@ -1,20 +1,16 @@ import cpp -predicate paramsString(Function f, int n, string res) { - if n = -1 - then res = "" - else - exists(string sep | - (if n = 0 then sep = "" else sep = ", ") and - exists(string prefixRes | - paramsString(f, n - 1, prefixRes) and - res = prefixRes + sep + f.getParameter(n) + "(" + f.getParameter(n).getType() + ")" - ) +string paramsString(Function f) { + result = + concat(int i | + exists(f.getParameter(i)) + | + f.getParameter(i) + "(" + f.getParameter(i).getType() + ")", ", " order by i ) } from BlockExpr e, Function f, string params where f = e.getFunction() and - paramsString(f, f.getNumberOfParameters() - 1, params) + params = paramsString(f) select e, e.getType() as te, te.explain(), e.getFunction(), f.getType() as tf, tf.explain(), params diff --git a/cpp/ql/test/library-tests/blocks/cpp/code_blocks.ql b/cpp/ql/test/library-tests/blocks/cpp/code_blocks.ql index 1662525cae6e..647923eea563 100644 --- a/cpp/ql/test/library-tests/blocks/cpp/code_blocks.ql +++ b/cpp/ql/test/library-tests/blocks/cpp/code_blocks.ql @@ -1,20 +1,16 @@ import cpp -predicate paramsString(Function f, int n, string res) { - if n = -1 - then res = "" - else - exists(string sep | - (if n = 0 then sep = "" else sep = ", ") and - exists(string prefixRes | - paramsString(f, n - 1, prefixRes) and - res = prefixRes + sep + f.getParameter(n) + "(" + f.getParameter(n).getType() + ")" - ) +string paramsString(Function f) { + result = + concat(int i | + exists(f.getParameter(i)) + | + f.getParameter(i) + "(" + f.getParameter(i).getType() + ")", ", " order by i ) } from BlockExpr e, Function f, string params where f = e.getFunction() and - paramsString(f, f.getNumberOfParameters() - 1, params) + params = paramsString(f) select e, e.getType() as te, te.explain(), e.getFunction(), f.getType() as tf, tf.explain(), params diff --git a/cpp/ql/test/library-tests/cpp11_g/cfg.ql b/cpp/ql/test/library-tests/cpp11_g/cfg.ql index 105b4e709ee7..f4df06adde03 100644 --- a/cpp/ql/test/library-tests/cpp11_g/cfg.ql +++ b/cpp/ql/test/library-tests/cpp11_g/cfg.ql @@ -1,16 +1,12 @@ import cpp -string arguments(Function f, int i) { - result = "," and i = -1 - or - result = "" and i = min(int j | function_template_argument(unresolveElement(f), j, _)) - 1 - or - result = arguments(f, i - 1) + "," + f.getTemplateArgument(i).toString() +string arguments(Function f) { + result = concat(int i | | f.getTemplateArgument(i).toString(), "," order by i) } string name(Function f) { if f.isConstructedFrom(_) - then result = f.toString() + "<" + max(arguments(f, _)).suffix(1) + ">" + then result = f.toString() + "<" + arguments(f) + ">" else if f instanceof TemplateFunction then result = f.toString() + " prototype instantiation" diff --git a/cpp/ql/test/library-tests/dataflow/dataflow-tests/has-parameter-flow-out.ql b/cpp/ql/test/library-tests/dataflow/dataflow-tests/has-parameter-flow-out.ql index 8f534be558d7..a7118463d96a 100644 --- a/cpp/ql/test/library-tests/dataflow/dataflow-tests/has-parameter-flow-out.ql +++ b/cpp/ql/test/library-tests/dataflow/dataflow-tests/has-parameter-flow-out.ql @@ -27,7 +27,7 @@ module IRTest { private string stars(int k) { k = [0 .. max(DataFlow::Node n, int i | n.isFinalValueOfParameter(_, i) | i)] and - (if k = 0 then result = "" else result = "*" + stars(k - 1)) + result = concat(int i | i in [1 .. k] | "*") } module IRParameterDefTest implements TestSig { diff --git a/cpp/ql/test/library-tests/preprocessor/macroinvocations/getanaffectedelement.ql b/cpp/ql/test/library-tests/preprocessor/macroinvocations/getanaffectedelement.ql index 83ab99ccdfd7..a3ff56942431 100644 --- a/cpp/ql/test/library-tests/preprocessor/macroinvocations/getanaffectedelement.ql +++ b/cpp/ql/test/library-tests/preprocessor/macroinvocations/getanaffectedelement.ql @@ -14,20 +14,8 @@ predicate reason(MacroInvocation mi, Element e, string reason) { mi.getEnclosingFunction() = e and reason = "getEnclosingFunction()" } -string reasonspart(MacroInvocation mi, Element e) { - reason(mi, e, result) - or - exists(string a, string b | - a = reasonspart(mi, e) and - reason(mi, e, b) and - not a.splitAt(" ") >= b and - result = a + " " + b - ) -} - string reasons(MacroInvocation mi, Element e) { - result = reasonspart(mi, e) and - not reasonspart(mi, e).length() > result.length() + result = concat(string reason | reason(mi, e, reason) | reason, " " order by reason) } from MacroInvocation mi, Element e diff --git a/cpp/ql/test/library-tests/sideEffects/functions/sideEffects.ql b/cpp/ql/test/library-tests/sideEffects/functions/sideEffects.ql index d2705040373a..d749031f7fb3 100644 --- a/cpp/ql/test/library-tests/sideEffects/functions/sideEffects.ql +++ b/cpp/ql/test/library-tests/sideEffects/functions/sideEffects.ql @@ -1,13 +1,14 @@ import cpp -string functionType(Function f, int i) { - if exists(f.getParameter(i)) - then result = f.getParameter(i).getType().toString() + " -> " + functionType(f, i + 1) - else ( - i = f.getNumberOfParameters() and result = f.getType().toString() - ) +string functionType(Function f) { + if exists(f.getParameter(_)) + then + result = + concat(int i | | f.getParameter(i).getType().toString(), " -> " order by i) + " -> " + + f.getType().toString() + else result = f.getType().toString() } from Function f, boolean b where if f.isSideEffectFree() then b = true else b = false -select f, functionType(f, 0), b +select f, functionType(f), b