Source Code Comparison via Statement Structure Parsing

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Current tools for comparing source code files are inefficient as they focus on line-by-line changes, failing to effectively identify differences in the underlying structure of source code files, which is crucial for debugging and copyright analysis.

Innovation Solution

A method and system that parse source code files to determine their code statement structures and compare these structures, using language-specific drivers to generate a common internal representation, allowing for the identification and reporting of differences in the file structures rather than line-by-line changes.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Measurement precision

If current text file comparison tools are used to compare source code files line by line, then the comparison process is simple and fast, but the comparison accuracy is insufficient because it fails to identify structural changes in the source code

Engineering Contradiction:
Improvecomparison accuracyVSAvoidcomparison system complexity
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The source code files are segmented into code statements with hierarchical structures (functions, variables, control structures) rather than treating them as plain text lines. The parser divides the code into meaningful units and builds a structured representation that captures the semantic relationships between different code elements, enabling accurate structural comparison.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

An intermediate code statement structure representation is introduced between the raw source code files and the comparison process. This intermediate representation (IR) serves as a mediator that transforms unstructured text into a structured format that preserves code semantics, allowing the comparison tool to accurately identify structural differences without directly comparing raw text lines.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Productivity

If line-by-line comparison is performed on source code files, then the comparison speed is fast, but the comparison effectiveness is reduced because it cannot identify whether underlying code structure has changed

Engineering Contradiction:
Improvecomparison efficiencyVSAvoidstructural information loss
Core Design Contradiction:
ProductivityVSLoss of information

Solution Approach 1:

The source code files are pre-processed by a parser that generates code statement structures before the comparison operation. This preliminary action of parsing and structuring the code enables the subsequent comparison to efficiently operate on meaningful code units rather than raw text lines, preserving structural information while maintaining comparison efficiency.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The comparison approach changes from operating on text-based parameters (lines, characters) to operating on structure-based parameters (code statements, functions, variables). By changing the fundamental parameters of comparison from textual to structural, the system can identify meaningful code differences while maintaining efficiency through systematic traversal of the code statement structures.

Inventive Principle:
Principle #35Parameter changes

Data Source

PatentUS8533668B2Comparing source code using code statement structures
Publication Date: 2013.09.10 RED HAT INC
  • US8533668B2 patent drawing
  • US8533668B2 patent drawing
  • US8533668B2 patent drawing

AI summary

A computer system identifies a plurality of source code files to be compared, parses each source code file to identify a code statement structure present in the file, and compares the plurality of source code files using corresponding code statement structures.