|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | import javascript
|
8 |
| -private import CodeToFeatures |
9 | 8 | private import FeaturizationConfig
|
10 | 9 |
|
11 | 10 | string getTokenizedAstNode(ASTNode node) {
|
@@ -36,8 +35,8 @@ ASTNode getAnASTNodeToFeaturize(Function f) {
|
36 | 35 | }
|
37 | 36 |
|
38 | 37 | /**
|
39 |
| - * Get a function containing the endpoint that is suitable for featurization. In general, |
40 |
| - * this associates an endpoint to multiple functions, since there may be more than one multiple entities to a single endpoint. |
| 38 | + * Get a function containing the endpoint that is suitable for featurization. In general, this |
| 39 | + * can associate an endpoint to multiple functions, since functions can be nested in JavaScript. |
41 | 40 | */
|
42 | 41 | Function getAFunctionForEndpoint(DataFlow::Node endpoint) {
|
43 | 42 | result = endpoint.getContainer().getEnclosingContainer*()
|
@@ -108,19 +107,19 @@ Function getRepresentativeFunctionForEndpoint(DataFlow::Node endpoint) {
|
108 | 107 | )
|
109 | 108 | }
|
110 | 109 |
|
111 |
| -/** Holds if `location` is the location of an AST node within the entity `entity` and `token` is a node attribute associated with that AST node. */ |
112 |
| -predicate bodyTokens(DatabaseFeatures::Entity entity, Location location, string token) { |
113 |
| - // Performance optimization: Restrict the set of entities to those containing an endpoint to featurize. |
114 |
| - entity.getDefinedFunction() = |
| 110 | +/** Holds if `location` is the location of an AST node within the function `function` and `token` is a node attribute associated with that AST node. */ |
| 111 | +predicate bodyTokens(Function function, Location location, string token) { |
| 112 | + // Performance optimization: Restrict the set of functions to those containing an endpoint to featurize. |
| 113 | + function = |
115 | 114 | getRepresentativeFunctionForEndpoint(any(FeaturizationConfig cfg).getAnEndpointToFeaturize()) and
|
116 | 115 | // Performance optimization: If a function has more than 256 body subtokens, then featurize it as absent. This
|
117 | 116 | // approximates the behavior of the classifer on non-generic body features where large body
|
118 | 117 | // features are replaced by the absent token.
|
119 | 118 | //
|
120 | 119 | // We count nodes instead of tokens because tokens are often not unique.
|
121 |
| - strictcount(getAnASTNodeToFeaturize(entity.getDefinedFunction())) <= 256 and |
| 120 | + strictcount(getAnASTNodeToFeaturize(function)) <= 256 and |
122 | 121 | exists(ASTNode node |
|
123 |
| - node = getAnASTNodeToFeaturize(entity.getDefinedFunction()) and |
| 122 | + node = getAnASTNodeToFeaturize(function) and |
124 | 123 | token = getTokenizedAstNode(node) and
|
125 | 124 | location = node.getLocation()
|
126 | 125 | )
|
|
0 commit comments