@@ -15,8 +15,8 @@ private string getACompatibleModelChecksum() {
15
15
}
16
16
17
17
/**
18
- * The maximum number of AST nodes an entity containing an endpoint should have before we should
19
- * choose a smaller entity to represent the endpoint.
18
+ * The maximum number of AST nodes an function containing an endpoint should have before we should
19
+ * choose a smaller function to represent the endpoint.
20
20
*
21
21
* This is intended to represent a balance in terms of the amount of context we provide to the
22
22
* model: we don't want the function to be too small, because then it doesn't contain very much
@@ -26,54 +26,56 @@ private string getACompatibleModelChecksum() {
26
26
private int getMaxNumAstNodes ( ) { result = 1024 }
27
27
28
28
/**
29
- * Returns the number of AST nodes contained within the specified entity .
29
+ * Returns the number of AST nodes contained within the specified function .
30
30
*/
31
- private int getNumAstNodesInEntity ( DatabaseFeatures:: Entity entity ) {
32
- // Restrict the values `entity` can take on
33
- entity = EndpointToEntity:: getAnEntityForEndpoint ( _) and
34
- result =
35
- count ( DatabaseFeatures:: AstNode astNode | DatabaseFeatures:: astNodes ( entity , _, _, astNode , _) )
31
+ private int getNumAstNodesInFunction ( Function function ) {
32
+ // Restrict the values `function` can take on
33
+ function = EndpointToFunction:: getAFunctionForEndpoint ( _) and
34
+ result = count ( EndpointFeatures:: FunctionBodies:: getAnASTNodeToFeaturize ( function ) )
36
35
}
37
36
38
37
/**
39
- * Get a single entity to use as the representative entity for the endpoint.
38
+ * Get the enclosing function for an endpoint.
39
+ *
40
+ * This is used to compute the `enclosingFunctionBody` and `enclosingFunctionName` features.
40
41
*
41
- * We try to use the largest entity containing the endpoint that's below the AST node limit defined
42
- * in `getMaxNumAstNodes`. In the event of a tie, we use the entity that appears first within the
43
- * source archive .
42
+ * We try to use the largest function containing the endpoint that's below the AST node limit
43
+ * defined in `getMaxNumAstNodes`. In the event of a tie, we use the function that appears first
44
+ * within the source code .
44
45
*
45
- * If no entities are smaller than the AST node limit, then we use the smallest entity containing
46
+ * If no functions are smaller than the AST node limit, then we use the smallest function containing
46
47
* the endpoint.
47
48
*/
48
- DatabaseFeatures:: Entity getRepresentativeEntityForEndpoint ( DataFlow:: Node endpoint ) {
49
- // Check whether there's an entity containing the endpoint that's smaller than the AST node limit.
49
+ Function getRepresentativeFunctionForEndpoint ( DataFlow:: Node endpoint ) {
50
+ // Check whether there's a function containing the endpoint that's smaller than the AST node
51
+ // limit.
50
52
if
51
- getNumAstNodesInEntity ( EndpointToEntity :: getAnEntityForEndpoint ( endpoint ) ) <=
53
+ getNumAstNodesInFunction ( EndpointToFunction :: getAFunctionForEndpoint ( endpoint ) ) <=
52
54
getMaxNumAstNodes ( )
53
55
then
54
- // Use the largest entity smaller than the AST node limit, resolving ties using the entity that
55
- // appears first in the source archive .
56
+ // Use the largest function smaller than the AST node limit, resolving ties using the function
57
+ // that appears first in the source code .
56
58
result =
57
- min ( DatabaseFeatures :: Entity entity , int numAstNodes , Location l |
58
- entity = EndpointToEntity :: getAnEntityForEndpoint ( endpoint ) and
59
- numAstNodes = getNumAstNodesInEntity ( entity ) and
59
+ min ( Function function , int numAstNodes , Location l |
60
+ function = EndpointToFunction :: getAFunctionForEndpoint ( endpoint ) and
61
+ numAstNodes = getNumAstNodesInFunction ( function ) and
60
62
numAstNodes <= getMaxNumAstNodes ( ) and
61
- l = entity .getLocation ( )
63
+ l = function .getLocation ( )
62
64
|
63
- entity
65
+ function
64
66
order by
65
67
numAstNodes desc , l .getStartLine ( ) , l .getStartColumn ( ) , l .getEndLine ( ) , l .getEndColumn ( )
66
68
)
67
69
else
68
- // Use the smallest entity , resolving ties using the entity that
69
- // appears first in the source archive .
70
+ // Use the smallest function , resolving ties using the function that appears first in the source
71
+ // code .
70
72
result =
71
- min ( DatabaseFeatures :: Entity entity , int numAstNodes , Location l |
72
- entity = EndpointToEntity :: getAnEntityForEndpoint ( endpoint ) and
73
- numAstNodes = getNumAstNodesInEntity ( entity ) and
74
- l = entity .getLocation ( )
73
+ min ( Function function , int numAstNodes , Location l |
74
+ function = EndpointToFunction :: getAFunctionForEndpoint ( endpoint ) and
75
+ numAstNodes = getNumAstNodesInFunction ( function ) and
76
+ l = function .getLocation ( )
75
77
|
76
- entity
78
+ function
77
79
order by
78
80
numAstNodes , l .getStartLine ( ) , l .getStartColumn ( ) , l .getEndLine ( ) , l .getEndColumn ( )
79
81
)
0 commit comments