Abstract
In this work we provide an algorithm capable of searching for semantic clones in CLP program code. Two code fragments are considered semantically cloned (at least to some extent) when they can both be transformed into a single code fragment thus representing the functionality that is shared between the fragments. While the framework of what constitutes such semantic clones has been established before, it is parametrized by a set of admissible program transformations and no algorithm exists that effectively performs the search with a concrete set of allowed transformations. In this work we use the well-known unfolding and slicing transformations to establish such an algorithm, and we show how the generalization of CLP goals can be a driving factor both for controlling the search process (i.e. keeping it finite) as for guiding the search (i.e. choosing what transformation(s) to apply at what moment).
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
References
Alias, C., Barthou, D.: Algorithm recognition based on demand-driven data-flow analysis. In: Proceedings of the 10th Working Conference on Reverse Engineering (WCRE), pp. 296–305 (2003). https://doi.org/10.1109/WCRE.2003.1287260
Brown, C., Thompson, S.: Clone detection and elimination for Haskell. In: Proceedings of the 2010 SIGPLAN Workshop on Partial Evaluation and Program Manipulation (PEPM 2010), pp. 111–120. ACM (2010). https://doi.org/10.1145/1706356.1706378
Dandois, C., Vanhoof, W.: Semantic code clones in logic programs. In: Albert, E. (ed.) LOPSTR 2012. LNCS, vol. 7844, pp. 35–50. Springer, Heidelberg (2013). https://doi.org/10.1007/978-3-642-38197-3_4
Dandois, C., Vanhoof, W.: Clones in logic programs and how to detect them. In: Vidal, G. (ed.) LOPSTR 2011. LNCS, vol. 7225, pp. 90–105. Springer, Heidelberg (2012). https://doi.org/10.1007/978-3-642-32211-2_7
Gange, G., Navas, J.A., Schachte, P., Søndergaard, H., Stuckey, P.J.: Horn clauses as an intermediate representation for program analysis and transformation. TPLP 15(4–5), 526–542 (2015). https://doi.org/10.1017/S1471068415000204
Green, C., Luckham, D., Balzer, R., Cheatham, T., Rich, C.: Report on a knowledge-based software assistant. Technical report, Kestrel Institute (1983). https://doi.org/10.5555/31870.31893
Jaffar, J., Maher, M.J., Marriott, K., Stuckey, P.J.: The semantics of constraint logic programs. J. Logic Program. 37(1–3), 1–46 (1998). https://doi.org/10.1016/S0743-1066(98)10002-X
Leuschel, M., Bruynooghe, M.: Logic program specialisation through partial deduction: control issues. Theory Pract. Logic Program. 2(4–5), 461–515 (2002). https://doi.org/10.1017/S147106840200145X
Li, H., Thompson, S.: Clone detection and removal for Erlang/OTP within a refactoring environment. In: Proceedings of the 2009 SIGPLAN Workshop on Partial Evaluation and Program Manipulation (PEPM 2009), pp. 169–178. ACM (2009). https://doi.org/10.1145/1480945.1480971
Martino, B.D., Iannello, G.: PAP recognizer: a tool for automatic recognition of parallelizable patterns. In: 4th International Workshop on Program Comprehension (WPC), p. 164 (1996). https://doi.org/10.1109/WPC.1996.501131
Mesnard, F., Payet, E., Vanhoof, W.: Towards a framework for algorithm recognition in binary code. In: Proceedings of the 18th International Symposium on Principles and Practice of Declarative Programming, pp. 202–213. PPDP 2016, ACM, New York (2016). https://doi.org/10.1145/2967973.2968600
Metzger, R., Wen, Z.: Automatic Algorithm Recognition and Replacement. MIT Press, Cambridge (2000)
Pettorossi, A., Proietti, M.: Transformation of logic programs. In: Gabbay, D.M., Hogger, C.J., Robinson, J.A. (eds.) Handbook of Logic in Artificial Intelligence and Logic Programming, vol. 5, pp. 697–787. Oxford University Press, Oxford (1998)
Rattan, D., Bhatia, R.K., Singh, M.: Software clone detection: a systematic review. Inf. Softw. Technol. 55(7), 1165–1199 (2013). https://doi.org/10.1016/j.infsof.2013.01.008
Rich, C., Shrobe, H.E., Waters, R.C.: Overview of the programmer’s apprentice. In: Proceedings of the Sixth International Joint Conference on Artificial Intelligence (IJCAI), pp. 827–828 (1979). https://doi.org/10.5555/1623050.1623101
Roy, C.K., Cordy, J.R., Koschke, R.: Comparison and evaluation of code clone detection techniques and tools: a qualitative approach. Sci. Comput. Program. 74(7), 470–495 (2009). https://doi.org/10.1016/j.scico.2009.02.007
Sørensen, M.H., Glück, R.: An algorithm of generalization in positive supercompilation. In: Logic Programming, Proceedings of the 1995 International Symposium, Portland, Oregon, USA, 4–7 December 1995, pp. 465–479 (1995). https://doi.org/10.7551/mitpress/4301.003.0048
Storey, M.D.: Theories, methods and tools in program comprehension: past, present and future. In: 13th International Workshop on Program Comprehension (IWPC), pp. 181–191 (2005). https://doi.org/10.1007/s11219-006-9216-4
Szilágyi, G., Gyimóthy, T., Małuszyński, J.: Static and dynamic slicing of constraint logic programs. Autom. Softw. Eng. 9(1), 41–65 (2002). https://doi.org/10.1023/A:1013280119003
Taherkhani, A.: Using decision tree classifiers in source code analysis to recognize algorithms: an experiment with sorting algorithms. Comput. J. 54(11), 1845–1860 (2011). https://doi.org/10.1093/comjnl/bxr025
Taherkhani, A., Malmi, L.: Beacon- and schema-based method for recognizing algorithms from students’ source code. J. Educ. Data Min. 5(2), 69–101 (2013). https://doi.org/10.5281/zenodo.3554635
Yernaux, G., Vanhoof, W.: Anti-unification in constraint logic programming. Theory Pract. Logic Program. 19(5–6), 773–789 (2019). https://doi.org/10.1017/S1471068419000188
Zhang, F., Huang, H., Zhu, S., Wu, D., Liu, P.: Viewdroid: towards obfuscation-resilient mobile application repackaging detection. In: Proceedings of the 2014 ACM Conference on Security and Privacy in Wireless and Mobile Networks, WiSec 2014, pp. 25–36. ACM (2014). https://doi.org/10.1145/2627393.2627395
Zhang, F., Jhi, Y.C., Wu, D., Liu, P., Zhu, S.: A first step towards algorithm plagiarism detection. In: Proceedings of the 2012 International Symposium on Software Testing and Analysis, ISSTA 2012, pp. 111–121. ACM (2012). https://doi.org/10.1145/2338965.2336767
Acknowledgements
We thank anonymous reviewers and the participants of LOPSTR 2019 for their constructive input and remarks.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2020 Springer Nature Switzerland AG
About this paper
Cite this paper
Vanhoof, W., Yernaux, G. (2020). Generalization-Driven Semantic Clone Detection in CLP. In: Gabbrielli, M. (eds) Logic-Based Program Synthesis and Transformation. LOPSTR 2019. Lecture Notes in Computer Science(), vol 12042. Springer, Cham. https://doi.org/10.1007/978-3-030-45260-5_14
Download citation
DOI: https://doi.org/10.1007/978-3-030-45260-5_14
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-45259-9
Online ISBN: 978-3-030-45260-5
eBook Packages: Computer ScienceComputer Science (R0)