Source Code Clone Detection via Abstract Syntax Tree Analysis

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing code clone detection methods fail to accurately identify clones between source code in protected locations and unauthorized locations, as text-based comparisons cannot detect refactored or modified code snippets.

Innovation Solution

A method and system that utilize a temporary clone detection structure and a pre-calculated index to identify code clones by normalizing and tokenizing source code, preventing copying of clones to unauthorized destinations based on predefined thresholds and location authorization.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Measurement precision

If text-based comparison is used to detect code clones, then the detection process is simple and fast, but it cannot detect refactored or modified code snippets

Engineering Contradiction:
Improvecode clone detection accuracyVSAvoiddetection system complexity
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The patent transforms the code comparison from text-based to structure-based by changing the representation parameters of code. It converts code snippets into their abstract syntax tree (AST) representations, which capture the structural essence of the code independent of surface-level text variations. This allows detection of semantically equivalent code even when text has been refactored or modified.

Inventive Principle:
Principle #35Parameter changes

Solution Approach 2:

The patent introduces an intermediary representation layer between the original code text and the comparison process. By converting code snippets into AST representations as an intermediate form, the system can compare the structural representations rather than directly comparing text, enabling detection of refactored code while maintaining detection accuracy.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Productivity

If a pre-calculated clone detection structure is used, then code clone detection within the code storage system is efficient, but it cannot detect clones between files outside the code storage system and protected locations

Engineering Contradiction:
Improvecode clone detection efficiencyVSAvoiddetection scope
Core Design Contradiction:
ProductivityVSAdaptability or versatility

Solution Approach 1:

The patent makes the clone detection structure universal by designing it to handle multiple scenarios: detection within the code storage system, detection between external files and protected locations, and detection across different code bases. The same AST-based comparison mechanism works for all these cases, eliminating the need for separate detection systems for different scopes.

Inventive Principle:
Principle #6Universality (Multi-functionality)

Solution Approach 2:

The patent performs preliminary conversion of code snippets into AST representations before the actual comparison process. By pre-processing and normalizing the code structure representation in advance, the system prepares the code in a standardized format that enables efficient comparison both within and outside the code storage system, improving overall detection efficiency and scope.

Inventive Principle:
Principle #10Preliminary action

3Reliability

If code storage system provides version control and access control, then software protection and tracking are improved, but it cannot prevent copying of code clones to unauthorized locations

Engineering Contradiction:
Improvecode protection reliabilityVSAvoidcode copying and distribution
Core Design Contradiction:
ReliabilityVSObject-generated harmful factors

Solution Approach 1:

The patent implements a feedback mechanism where the system actively monitors for code clone copying attempts. When code snippets are detected in unauthorized locations or when copying behavior is identified, the system provides feedback by generating alerts and notifications to administrators, enabling real-time detection and response to code theft attempts despite the presence of version control and access control mechanisms.

Inventive Principle:
Principle #23Feedback

Solution Approach 2:

The patent replaces the mechanical access control mechanisms (file-level permissions, authentication) with a semantic understanding approach. Instead of relying solely on traditional access control lists to prevent copying, the system uses AST-based semantic analysis to detect and identify code clone copying behavior, providing a more intelligent and effective protection mechanism that can detect sophisticated copying attempts.

Inventive Principle:
Principle #28Mechanics substitution (Replace mechanical system)

Data Source

PatentUS8819856B1Detecting and preventing noncompliant use of source code
Publication Date: 2014.08.26 GOOGLE LLC
  • US8819856B1 patent drawing
  • US8819856B1 patent drawing
  • US8819856B1 patent drawing

AI summary

A system is disclosed for identifying and preventing non-compliant uses of any portion of source code or other protected content. The system includes at least one processor and a memory storing instructions that cause the system to scan files located at a source location for excerpts of protected source code. The instructions may cause the system to create a temporary clone detection structure for the files at the source location. The instructions may cause the system to use the temporary clone structure and a pre-calculated clone structure for source code files in a protected code location, to identify code clones, and to generate data used to alert a user that the source location includes portions of source code from the protected code location. When clones are found, the instructions may optionally cause the system to prevent the copying of the files containing the code clones.