Source Code Comparison via Abstract Syntax Tree Graph Reduction

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing software development analysis tools lack accuracy in comparing source codes before and after changes, particularly in detecting behavioral differences due to refactoring, leading to potential misidentification of changes in program behavior.

Innovation Solution

An analysis apparatus that generates abstract syntax trees from source codes, converts them into tripartite graphs, fuses and reduces these graphs based on predefined rules, and calculates hash values to compare the reduced graphs, thereby accurately identifying differences between source codes.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Measurement precision

If source code comparison is performed using traditional character string matching methods, then the comparison process is simple, but the accuracy in detecting behavioral differences is low

Engineering Contradiction:
Improveaccuracy in detecting behavioral differencesVSAvoidcomplexity of analysis process
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The source code is segmented into abstract syntax trees (ASTs) that represent the structural components of the code. These ASTs are then converted into tripartite graphs that separate processing flow, data flow, and method information. This segmentation allows for precise comparison of behavioral elements while filtering out irrelevant syntactic differences, thereby improving detection accuracy without requiring overly complex processing of the entire codebase at once.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The patent introduces tripartite graphs as an intermediary representation between the original source code and the comparison result. These graphs serve as a mediator that captures the essential behavioral characteristics (processing flow, data flow, method calls) in a standardized format, enabling accurate comparison while abstracting away the complexity of direct source code analysis.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Measurement precision

If detailed analysis of all code elements is performed, then comparison accuracy is improved, but processing time increases

Engineering Contradiction:
Improvecomparison accuracyVSAvoidprocessing time
Core Design Contradiction:
Measurement precisionVSLoss of time

Solution Approach 1:

The patent extracts only the essential behavioral elements from the source code by converting ASTs into tripartite graphs that focus specifically on processing flow, data flow, and method information. This extraction process filters out non-essential syntactic details and irrelevant code elements, allowing for accurate behavioral comparison while significantly reducing the amount of data that needs to be processed and compared.

Inventive Principle:
Principle #2Taking out (Extraction)

Solution Approach 2:

The patent performs preliminary conversion of source code into abstract syntax trees and then into tripartite graphs before the actual comparison takes place. This preliminary action prepares the code in a standardized, behavior-focused format that facilitates faster and more accurate comparison, avoiding the need for complex real-time analysis during the comparison phase.

Inventive Principle:
Principle #10Preliminary action

3Reliability

If refactoring changes such as method division or composition are detected, then code evolution is tracked, but false positives in behavioral change detection increase

Engineering Contradiction:
Improvereliability of behavioral change detectionVSAvoidfalse positives in behavioral change detection
Core Design Contradiction:
ReliabilityVSObject-generated harmful factors

Solution Approach 1:

The patent applies different analysis qualities to different aspects of the code by using tripartite graphs with distinct components for processing flow, data flow, and method information. Each component is analyzed with appropriate depth and focus, allowing the system to distinguish between genuine behavioral changes and superficial refactoring variations. This localized quality approach ensures that method division or composition changes are recognized as structural modifications rather than behavioral changes.

Inventive Principle:
Principle #3Local quality

Data Source

PatentUS10628139B2Analysis apparatus, analysis method and recording medium on which analysis program is recorded
Publication Date: 2020.04.21 FUJITSU LTD
  • US10628139B2 patent drawing
  • US10628139B2 patent drawing
  • US10628139B2 patent drawing

AI summary

An analysis apparatus, includes: a memory; and a processor coupled to the memory, wherein the processor: acquires two source codes of a comparison target; generates two abstract syntax trees of the two source codes by analyzing the two source codes; graphs, based on the two abstract syntax trees, a flow of processing and a flow of data in methods and between methods in the two source codes, reduces, based on a given rule, one or more redundant portions of the respective graphs of the two graphed source codes; and compares the two reduced graphs and outputs a difference between the two source codes.