Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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] | " ")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] | " ")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] | " ")
}

/**
Expand Down
18 changes: 7 additions & 11 deletions cpp/ql/test/library-tests/blocks/c/code_blocks.ql
Original file line number Diff line number Diff line change
@@ -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
18 changes: 7 additions & 11 deletions cpp/ql/test/library-tests/blocks/cpp/code_blocks.ql
Original file line number Diff line number Diff line change
@@ -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
10 changes: 3 additions & 7 deletions cpp/ql/test/library-tests/cpp11_g/cfg.ql
Original file line number Diff line number Diff line change
@@ -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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was quite an odd implementation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.

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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions cpp/ql/test/library-tests/sideEffects/functions/sideEffects.ql
Original file line number Diff line number Diff line change
@@ -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
Loading