Merge pull request #104 from dave-bartolomeo/dave/ASTWobble

C++: Fix wobble in PrintAST test
This commit is contained in:
Nick Rolfe
2018-08-24 18:40:51 +01:00
committed by GitHub
3 changed files with 41 additions and 19 deletions

View File

@@ -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.
@@ -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()
)
}

View File

@@ -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:

View File

@@ -2,16 +2,22 @@
#-----| params:
#-----| __va_list_tag::operator=() -> __va_list_tag &
#-----| params:
#-----| operator new(unsigned long) -> void *
#-----| 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 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
@@ -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