Skip to content

C++: Fix wobble in PrintAST test #104

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 2 commits into from
Aug 24, 2018
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
32 changes: 27 additions & 5 deletions cpp/ql/src/semmle/code/cpp/PrintAST.qll
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ private Location getRepresentativeLocation(Locatable ast) {
result = rank[1](Location loc | loc = ast.getLocation() | loc order by loc.toString())
}

/**
* Computes the sort keys to sort the given AST node by location. An AST without
* a location gets an empty file name and a zero line and column number.
*/
private predicate locationSortKeys(Locatable ast, string file, int line,
int column) {
if exists(getRepresentativeLocation(ast)) then (
exists(Location loc |
loc = getRepresentativeLocation(ast) and
file = loc.getFile().toString() and
line = loc.getStartLine() and
column = loc.getStartColumn()
)
) else (
file = "" and
line = 0 and
column = 0
)
}

/**
* Most nodes are just a wrapper around `Locatable`, but we do synthesize new
* nodes for things like parameter lists and constructor init lists.
Expand Down Expand Up @@ -482,12 +502,14 @@ class FunctionNode extends ASTNode {
}

private int getOrder() {
this = rank[result](FunctionNode node, Function function, Location loc |
node.getAST() = function and loc = getRepresentativeLocation(function) |
this = rank[result](FunctionNode node, Function function, string file,
int line, int column |
node.getAST() = function and
locationSortKeys(function, file, line, column) |
node order by
loc.getFile().toString(),
loc.getStartLine(),
loc.getStartColumn(),
file,
line,
column,
function.getFullSignature()
)
}
Expand Down
8 changes: 4 additions & 4 deletions cpp/ql/test/examples/expressions/PrintAST.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#-----| params:
#-----| __va_list_tag::operator=() -> __va_list_tag &
#-----| params:
#-----| operator new(unsigned long) -> void *
#-----| params:
#-----| 0: p#0
#-----| Type = unsigned long
#-----| operator delete(void *) -> void
#-----| params:
#-----| 0: p#0
#-----| Type = void *
#-----| operator new(unsigned long) -> void *
#-----| params:
#-----| 0: p#0
#-----| Type = unsigned long
AddressOf.c:
# 1| AddressOf(int) -> void
# 1| params:
Expand Down
16 changes: 8 additions & 8 deletions cpp/ql/test/library-tests/ir/ir/PrintAST.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
#-----| params:
#-----| __va_list_tag::operator=() -> __va_list_tag &
#-----| params:
#-----| operator new(unsigned long) -> void *
#-----| operator delete(void *, unsigned long) -> void
#-----| params:
#-----| 0: p#0
#-----| Type = void *
#-----| 1: p#1
#-----| Type = unsigned long
#-----| operator delete(void *, unsigned long) -> void
#-----| operator delete[](void *, unsigned long) -> void
#-----| params:
#-----| 0: p#0
#-----| Type = void *
#-----| 1: p#1
#-----| Type = unsigned long
#-----| operator new(unsigned long) -> void *
#-----| params:
#-----| 0: p#0
#-----| Type = unsigned long
#-----| operator new(unsigned long, align_val_t) -> void *
#-----| params:
#-----| 0: p#0
Expand All @@ -22,12 +28,6 @@
#-----| params:
#-----| 0: p#0
#-----| Type = unsigned long
#-----| operator delete[](void *, unsigned long) -> void
#-----| params:
#-----| 0: p#0
#-----| Type = void *
#-----| 1: p#1
#-----| Type = unsigned long
#-----| operator new[](unsigned long, align_val_t) -> void *
#-----| params:
#-----| 0: p#0
Expand Down