@@ -15,8 +15,8 @@ private string getACompatibleModelChecksum() {
1515}
1616
1717/**
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.
2020 *
2121 * This is intended to represent a balance in terms of the amount of context we provide to the
2222 * 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() {
2626private int getMaxNumAstNodes ( ) { result = 1024 }
2727
2828/**
29- * Returns the number of AST nodes contained within the specified entity .
29+ * Returns the number of AST nodes contained within the specified function .
3030 */
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 ) )
3635}
3736
3837/**
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.
4041 *
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 .
4445 *
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
4647 * the endpoint.
4748 */
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.
5052 if
51- getNumAstNodesInEntity ( EndpointToEntity :: getAnEntityForEndpoint ( endpoint ) ) <=
53+ getNumAstNodesInFunction ( EndpointToFunction :: getAFunctionForEndpoint ( endpoint ) ) <=
5254 getMaxNumAstNodes ( )
5355 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 .
5658 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
6062 numAstNodes <= getMaxNumAstNodes ( ) and
61- l = entity .getLocation ( )
63+ l = function .getLocation ( )
6264 |
63- entity
65+ function
6466 order by
6567 numAstNodes desc , l .getStartLine ( ) , l .getStartColumn ( ) , l .getEndLine ( ) , l .getEndColumn ( )
6668 )
6769 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 .
7072 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 ( )
7577 |
76- entity
78+ function
7779 order by
7880 numAstNodes , l .getStartLine ( ) , l .getStartColumn ( ) , l .getEndLine ( ) , l .getEndColumn ( )
7981 )
0 commit comments