Skip to content

C++: Instantiate model generation library #19295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 23, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
C++: Instantiate inline expectation test framework to test model gene…
…ration.
  • Loading branch information
MathiasVP committed Apr 20, 2025
commit 09ebd6e87dcf8f9f66f96b8854247f814d1d1be0
34 changes: 34 additions & 0 deletions cpp/ql/lib/utils/test/InlineMadTest.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
private import cpp
private import codeql.mad.test.InlineMadTest

class MadRelevantFunction extends Function {
MadRelevantFunction() { not this.isFromUninstantiatedTemplate(_) }
}

private module InlineMadTestLang implements InlineMadTestLangSig {
class Callable = MadRelevantFunction;

/**
* Holds if `c` is the closest `Callable` that suceeds `comment` in the file.
*/
private predicate hasClosestCallable(CppStyleComment comment, Callable c) {
c =
min(Callable cand, int dist |
// This has no good join order, but should hopefully be good enough for tests.
cand.getFile() = comment.getFile() and
dist = cand.getLocation().getStartLine() - comment.getLocation().getStartLine() and
dist > 0
|
cand order by dist
)
}

string getComment(Callable c) {
exists(CppStyleComment comment |
hasClosestCallable(comment, c) and
result = comment.getContents().suffix(2)
)
}
}

import InlineMadTestImpl<InlineMadTestLang>