Compare our island to a potential source match. Args: src_ctx (SourceCodeContext): src context representing a source function (potential match) logger (logger): logger instance Return Value: floating point score for the entire match
(self, src_ctx, logger)
| 295 | self.match = match |
| 296 | |
| 297 | def compare(self, src_ctx, logger): |
| 298 | """Compare our island to a potential source match. |
| 299 | |
| 300 | Args: |
| 301 | src_ctx (SourceCodeContext): src context representing a source function (potential match) |
| 302 | logger (logger): logger instance |
| 303 | |
| 304 | Return Value: |
| 305 | floating point score for the entire match |
| 306 | """ |
| 307 | score = 0 |
| 308 | logger.addIndent() |
| 309 | boost_score = len(src_ctx.blocks) <= MINIMAL_BLOCKS_BOOST |
| 310 | # 1. Match constants |
| 311 | const_score = ComparableContext.compareConsts(src_ctx, self) |
| 312 | logger.debug("Const score: %f", const_score) |
| 313 | score += const_score |
| 314 | # 2. Match strings |
| 315 | string_score = ComparableContext.compareString(src_ctx, self) |
| 316 | logger.debug("String score: %f", string_score) |
| 317 | score += string_score |
| 318 | # 3. Match calls |
| 319 | calls_score = ComparableContext.compareCalls(src_ctx, self) |
| 320 | logger.debug("Calls score: %f", calls_score) |
| 321 | score += calls_score |
| 322 | # 4. Match external calls |
| 323 | externals_score = ComparableContext.compareExternals(src_ctx, self) |
| 324 | logger.debug("Externals score: %f", externals_score) |
| 325 | score += externals_score |
| 326 | # 5. Boost the score |
| 327 | if boost_score: |
| 328 | score *= 2 |
| 329 | logger.debug("Score boost") |
| 330 | # Overall result |
| 331 | logger.debug("Overall score is: %f", score) |
| 332 | logger.removeIndent() |
| 333 | return score |
| 334 | |
| 335 | class FunctionContext(ComparableContext): |
| 336 | """Base class representing the full canonical representation of a function. |
no test coverage detected