@@ -39,6 +39,26 @@ private Location getRepresentativeLocation(Locatable ast) {
3939 result = rank [ 1 ] ( Location loc | loc = ast .getLocation ( ) | loc order by loc .toString ( ) )
4040}
4141
42+ /**
43+ * Computes the sort keys to sort the given AST node by location. An AST without
44+ * a location gets an empty file name and a zero line and column number.
45+ */
46+ private predicate locationSortKeys ( Locatable ast , string file , int line ,
47+ int column ) {
48+ if exists ( getRepresentativeLocation ( ast ) ) then (
49+ exists ( Location loc |
50+ loc = getRepresentativeLocation ( ast ) and
51+ file = loc .getFile ( ) .toString ( ) and
52+ line = loc .getStartLine ( ) and
53+ column = loc .getStartColumn ( )
54+ )
55+ ) else (
56+ file = "" and
57+ line = 0 and
58+ column = 0
59+ )
60+ }
61+
4262/**
4363 * Most nodes are just a wrapper around `Locatable`, but we do synthesize new
4464 * nodes for things like parameter lists and constructor init lists.
@@ -482,12 +502,14 @@ class FunctionNode extends ASTNode {
482502 }
483503
484504 private int getOrder ( ) {
485- this = rank [ result ] ( FunctionNode node , Function function , Location loc |
486- node .getAST ( ) = function and loc = getRepresentativeLocation ( function ) |
505+ this = rank [ result ] ( FunctionNode node , Function function , string file ,
506+ int line , int column |
507+ node .getAST ( ) = function and
508+ locationSortKeys ( function , file , line , column ) |
487509 node order by
488- loc . getFile ( ) . toString ( ) ,
489- loc . getStartLine ( ) ,
490- loc . getStartColumn ( ) ,
510+ file ,
511+ line ,
512+ column ,
491513 function .getFullSignature ( )
492514 )
493515 }
0 commit comments