Accurate and Language Agnostic Code Clone Detection by Measuring Edit Distance of ANTLR Parse Tree

Accurate and Language Agnostic Code Clone Detection by Measuring Edit Distance of ANTLR Parse Tree

Sanjay B. Ankali, Latha Parthiban
Copyright: © 2022 |Pages: 22
DOI: 10.4018/IJSI.297915
OnDemand:
(Individual Articles)
Available
$37.50
No Current Special Offers
TOTAL SAVINGS: $37.50

Abstract

In spite of significant research done in the past 3 decades introducing more than 250 clone detection tools/ techniques for finding the same language clones, there exists no single framework to detect and classify all 4 basic types of clones with great accuracy (precision and recall). In this paper, we propose an accurate and language agnostic technique to classify 4 types of clones. The method first generates an ANTLR parse tree for the input program file using freely available ANTLR grammar files then finds the edit distance between the two parse trees using the Levenshtein distance algorithm and converts the edit distance into similarity using. We obtained 100% precision and recall in detecting type 1 & 2 clone types and achieve 98.50 and 98.12 respectively for type 3 and 4 clone types for our datasets containing microprograms of C, CPP, and Java. This paper provides evidence that the Levenshtein distance on ANTLR parse tree is the good choice to build a complete and accurate software clone detector and act as proper validation tools to detect code plagiarism.
Article Preview
Top

1. Introduction

Code cloning is the process of creating functionally similar codes with syntactic modification. Or it can be defined as semantically similar code fragment pairs with or without syntactical change (Wang et al, 2020). Many researchers refer this process with different terms like similar code (Krinke, 2001), identical code (Baxter et al, 1998) or duplicate code (Ducasse, 1999), (Godfrey, 2006) these two articles respectively mentioned that large systems contain 10-15% and 20-50% of duplicate code in the codebase. Based on the milestone, literature like (Roy & Cordy, 2007), (Roy & Cody, 2009), (Rattan et al, 2013), (Ain et al, 2019), (Walker, 2020) the code clones are of 4 types that can be categorized as

Syntactic: clone types of 1, 2, and 3 are syntactic clones that are based on different editing taxonomies. Semantic: Type 4 is semantically similar codes that are different in syntax. A Major issue related to previous clone detections we find is because of the semantic factor involved in detecting Type 4 clone, many great clone detection tools like VUDDY (Kim et al, 2017), scalable SourcererCC (Sajnani, 2016) and Siamese (Ragkhitwetsagul et al, 2019), did not consider finding type 4 clones. These tools scale well on large repositories with excellent precision and recall. VUDDY is designed to detect vulnerabilities in the function of Github repositories. VUDDY is based on fingerprint matching of hash values of the function a body that completely relies on syntactic details of the function. Results show that it takes approximately 5 days to preprocess 8.7 BLOC from 13.2 MLOC files of Github projects; it took less than 1 sec to identify 133,812 vulnerable functions for each project (Sajnani, 2016). It detects only Type1, 2 clones. SourcerrerCC is the token-based clone detector operates in 2 stages, partial index creation and clone detection. The approach apply filtering heuristics using sub-block overlap filtering, and token position filtering to reduce the number of false-positive clone pairs (Sajnani, 2016). The tool SourcererCC can detect Type 1, 2, and 3 clones from 250 MLOC on a single machine in 4.5 days (Sajnani, 2016). Whereas Siamese achieve scalability through code indexing, code retrieval and text search engine “Elasticsearch” (Ragkhitwetsagul et al, 2019). It works in 2 phases, an index and a query phase by incorporating multiple code representation, query reduction, and ranking function to improve clone search performance. Siamese return a more number of near miss clones from a corpus of 365 million lines of codes in less than 8 seconds (Ragkhitwetsagul et al, 2019). Along with these 3 tools (Livieri, 2007), (Koschke, 2014), addresses the most important factor of scalability, but is not complete in terms of Type 4 clone detection. Among these (Livieri, 2007) took 2 days to analyze 400MLOC on 80 workstations of expensive student laboratories. Achieving precision, recall, and scalability at a time is always difficult (Ragkhitwetsagul et al, 2019). This paper aims to classify 4 types of clones accurately and scalability is out of the scope of our work.

There are many reasons for performing code cloning that mainly involves the development strategy of reusing good system designs, code, and logic (Roy & Cordy, 2007). Software forking leads to cloning. Lack of language support like inheritance, polymorphism leads to copy and paste the code (Kim,2004). The Internet contains several MLOC available that prompt software developers to search for the code online (Ragkhitwetsagul et al, 2019) in a survey conducted by (Saini, 2016) involving 72 developers, 96% of developed prefer searching and reusing code before any coding task. 33% of the students across the university search for the code as a solution for programming assignments (Joy, 2008). Existing clone detection studies have ignored micro clones or small clones. In a recent comparative study of a software bug in regular and small clones (Islam, 2019) found that 80% of consistent updates occur in micro clones and these consistent bug fix updates a large number of files pervasively and micro clones contain more sever bugs compared to regular bugs (Islam, 2019). The objective of the research paper are as follows:

Complete Article List

Search this Journal:
Reset
Volume 12: 1 Issue (2024)
Volume 11: 1 Issue (2023)
Volume 10: 4 Issues (2022): 2 Released, 2 Forthcoming
Volume 9: 4 Issues (2021)
Volume 8: 4 Issues (2020)
Volume 7: 4 Issues (2019)
Volume 6: 4 Issues (2018)
Volume 5: 4 Issues (2017)
Volume 4: 4 Issues (2016)
Volume 3: 4 Issues (2015)
Volume 2: 4 Issues (2014)
Volume 1: 4 Issues (2013)
View Complete Journal Contents Listing