Font Size: a A A

Code Clone Restructuring Of C Programs Via K-Nearest Neighbor Algorithm

Posted on:2012-03-24Degree:MasterType:Thesis
Country:ChinaCandidate:J H FengFull Text:PDF
GTID:2218330362950441Subject:Computer Science and Technology
Abstract/Summary:PDF Full Text Request
With the development of computer software, the developers begin to reuse the software to reduce the workload. However, this method will cause the software system is flooded with a large number of clone code. Clone code in most cases is harmful to the system, which increases the length of software code and makes software more complex, difficult to maintain. The system will be inefficient and introduced a number of defects. However, clone code can be processed effectively through restructuring so as to reduce the harm of clone code on the system. But current researches on restructuring clone code are very few.According to present situation, we propose a clone restructuring approach based on k-nearest neighbor algorithm. This method first takes the clone code of C programs as input and generates parser tree. Based on parser tree built above, program dependence graph is established and static analysis is performed, through which the control dependence information and data flow information are collected. After that, k-nearest neighbor clustering algorithm based on control dependence graph is performed to analyze the code, which chooses the statements as entities. Then it uses data attributes and control attributes to classify the entities so as to form extractable or functional independent code fragments. And a procedure extraction algorithm based abstract syntax tree is performed on these code fragments, which determines the variant type first, then decides the parameter type and number of the new procedure, return values of the new procedure, finally extracts the code into independent procedures. After that code clones are replaced by the invocations of their corresponding procedures.The clone restructuring approach based on k-nearest neighbor algorithm is tested with codes in published papers and open source codes. The experiment results show that this method can effectively reorganize the structure of code clones with low cohesion or multiple activities and perform the extraction on functional independent code fragments.
Keywords/Search Tags:restructuring, k-nearest neighbor clustering algorithm, procedure extraction, static analysis
PDF Full Text Request
Related items