Source Code Indexing via Linearized Abstract Syntax Trees

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing methods for indexing abstract syntax trees (ASTs) in source code are inefficient for detecting code clones, as they require rebuilding the index structure after each change, making real-time detection in Integrated Development Environments (IDEs) challenging and less precise.

Innovation Solution

A system and method that processes source code to build index structures by generating ASTs, linearizing subtrees, and constructing tries or compressed tries, allowing for precise and efficient detection of code clones by associating positions of elements with edges and nodes, enabling online reporting of code clones.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If suffix tree is used for indexing ASTs, then the index structure can be built, but it requires rebuilding the index after each change, reducing efficiency and preventing real-time detection

Engineering Contradiction:
Improveindex building efficiencyVSAvoidtime for index rebuilding
Core Design Contradiction:
ProductivityVSLoss of time

Solution Approach 1:

The patent transforms the static suffix tree into a dynamic structure by introducing a trie-based index that can be incrementally updated. The trie structure allows for dynamic insertion and deletion of code fragments without requiring complete index reconstruction, enabling real-time code clone detection as source code changes.

Inventive Principle:
Principle #15Dynamics

Solution Approach 2:

The patent segments the monolithic suffix tree index into multiple trie structures organized by code fragment positions. Each trie represents a specific position in the source code, allowing independent updates to individual positions without affecting the entire index structure.

Inventive Principle:
Principle #1Segmentation

2Measurement precision

If traditional indexing methods are used, then code clones can be detected, but precision and recall are insufficient for real-time IDE integration

Engineering Contradiction:
Improvecode clone detection precisionVSAvoidindex structure complexity
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The patent applies local quality by creating position-specific trie structures where each position in the source code has its own dedicated trie. This allows the index to capture local structural patterns at each position, improving detection precision by considering the specific context of each code fragment location rather than treating all positions uniformly.

Inventive Principle:
Principle #3Local quality

Solution Approach 2:

The patent adds a positional dimension to the traditional indexing approach by organizing tries according to their position in the source code. This transforms the flat index structure into a multi-dimensional structure that considers both the code fragment content and its location, enabling more precise real-time detection.

Inventive Principle:
Principle #17Another dimension (Dimensionality change)

3Reliability

If the index structure is rebuilt after each change, then the index reflects current state, but real-time reporting in IDE becomes challenging

Engineering Contradiction:
Improveindex accuracyVSAvoidreal-time reporting capability
Core Design Contradiction:
ReliabilityVSEase of operation

Solution Approach 1:

The patent performs preliminary actions by pre-building trie structures for each possible position in the source code before actual editing occurs. When code changes happen, the system only needs to update the specific trie corresponding to the changed position rather than rebuilding the entire index, maintaining both accuracy and real-time responsiveness.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The trie-based index structure serves itself through incremental updates. When source code changes, the system automatically updates only the affected portion of the index without requiring external intervention or complete reconstruction, enabling seamless real-time code clone detection in IDEs.

Inventive Principle:
Principle #25Self-service

Data Source

PatentUS20240184549A1System and method for indexing source code
Publication Date: 2024.06.06 THE RES FOUNDATION FOR THE STATE UNIV OF NEW YORK
  • US20240184549A1 patent drawing
  • US20240184549A1 patent drawing
  • US20240184549A1 patent drawing

AI summary

A system and computer-implemented method of indexing source code where the source code is processed into abstract syntax trees, the abstract syntax trees are linearized, and the linearizations are used to build an index structure. The index structure enables the look up of the pattern tree in time linear in its length. Further, the index structure can be used to identify code clones. Two alternate variants of the index structure can be used. One is based on a trie which builds a plain index structure, and the other index structure is based on a compressed trie which builds a compressed index structure.