A Catalogue of Refactorings to Remove Incomplete Annotations

Developers use the C Preprocessor (CPP) to handle portability and vari- ability in program families of different sizes and domains. However, despite the widely use of the CPP in practice, it is often criticised due to its negative impact on code quality and maintainability, tool development, and its error-prone characteristics. In particular, developers aggravate these problems when using incomplete annotations, i.e., directives encompassing only parts of syntactical units. In a previous work, we performed an empirical study on 41 C program family releases and found that almost 90% of syntax errors occur in incomplete annotations. There are some refactorings to remove incomplete annotations proposed in the literature. However, they clone code and increase Lines of Code (LOC). To avoid incomplete annotations and their intrinsic problems, in this article we propose a catalogue of refactorings that converts incomplete annotations into complete ones without cloning code. We implement an Eclipse plug-in to help developers applying our refactorings automatically. To evaluate our catalogue, we performed a study to analyse questions related to code cloning, LOC, and number of directives. To answer our research questions, we analyse releases of 12 C program families of different domains ranging from 4.9 thousand to 1.5 million LOC. The results show that our catalogue can remove all incomplete annotations without cloning code, and increasing only in 0.04% the LOC and in 2.10% the number of directives.

[1]  Rohit Gheyi,et al.  Making Program Refactoring Safer , 2010, IEEE Software.

[2]  Gunter Saake,et al.  Type checking annotation-based product lines , 2012, TSEM.

[3]  Elmar Jürgens,et al.  Analyzing the Effect of Preprocessor Annotations on Code Clones , 2011, 2011 IEEE 11th International Working Conference on Source Code Analysis and Manipulation.

[4]  Sven Apel,et al.  Does the discipline of preprocessor annotations matter?: a controlled experiment , 2014 .

[5]  Henry Spencer,et al.  #ifdef Considered Harmful, or Portability Experience with C News , 1992, USENIX Summer.

[6]  Shuvendu K. Lahiri,et al.  Finding errors in .net with feedback-directed random testing , 2008, ISSTA '08.

[7]  Sven Apel,et al.  Analyzing the discipline of preprocessor annotations in 30 million lines of C code , 2011, AOSD '11.

[8]  Sebastian Erdweg,et al.  Variability-aware parsing in the presence of lexical macros and conditional compilation , 2011, OOPSLA '11.

[9]  Stéphane S. Somé,et al.  Parsing minimization when extracting information from code in the presence of conditional compilation , 1998, Proceedings. 6th International Workshop on Program Comprehension. IWPC'98 (Cat. No.98TB100242).

[10]  Paulo Borba,et al.  Making Software Product Line Evolution Safer , 2012, 2012 Sixth Brazilian Symposium on Software Components, Architectures and Reuse.

[11]  Sven Apel,et al.  An analysis of the variability in forty preprocessor-based software product lines , 2010, 2010 ACM/IEEE 32nd International Conference on Software Engineering.

[12]  Wolfgang De Meuter,et al.  Can we refactor conditional compilation into aspects? , 2009, AOSD '09.

[13]  Márcio Ribeiro,et al.  Investigating preprocessor-based syntax errors , 2014 .

[14]  William R. Cook,et al.  Fitting the pieces together: a machine-checked model of safe composition , 2009, ESEC/FSE '09.

[15]  David Lorge Parnas,et al.  On the Design and Development of Program Families , 2001, IEEE Transactions on Software Engineering.

[16]  Ralph E. Johnson,et al.  Refactoring C with conditional compilation , 2003, 18th IEEE International Conference on Automated Software Engineering, 2003. Proceedings..

[17]  A. Hoek,et al.  Refactoring Product Line Architectures , 2003 .

[18]  SchelerFabian,et al.  A quantitative analysis of aspects in the eCos kernel , 2006 .

[19]  Márcio Ribeiro,et al.  Investigating preprocessor-based syntax errors , 2014, GPCE '13.

[20]  Ira D. Baxter,et al.  Design maintenance systems , 1991, CACM.

[21]  William R. Cook,et al.  Safe composition of product lines , 2007, GPCE '07.

[22]  William F. Opdyke,et al.  Refactoring object-oriented frameworks , 1992 .

[23]  Rohit Gheyi,et al.  Automated Behavioral Testing of Refactoring Engines , 2013, IEEE Trans. Software Eng..

[24]  H. D. Rombach,et al.  The Goal Question Metric Approach , 1994 .

[25]  Ralph E. Johnson,et al.  Analyzing multiple configurations of a C program , 2005, 21st IEEE International Conference on Software Maintenance (ICSM'05).

[26]  Michael D. Ernst,et al.  An Empirical Analysis of C Preprocessor Use , 2002, IEEE Trans. Software Eng..

[27]  Marian Vittek Refactoring browser with preprocessor , 2003, Seventh European Conference onSoftware Maintenance and Reengineering, 2003. Proceedings..

[28]  Sven Apel,et al.  Does the discipline of preprocessor annotations matter?: a controlled experiment , 2014, GPCE '13.

[29]  Yoann Padioleau,et al.  Parsing C/C++ Code without Pre-processing , 2009, CC.

[30]  Sven Apel,et al.  Type safety for feature-oriented product lines , 2010, Automated Software Engineering.

[31]  Carlos José Pereira de Lucena,et al.  Refactoring product lines , 2006, GPCE '06.

[32]  Robert Grimm,et al.  SuperC: parsing all of C by taming the preprocessor , 2012, PLDI.

[33]  Martin Fowler,et al.  Refactoring - Improving the Design of Existing Code , 1999, Addison Wesley object technology series.

[34]  Paulo Borba,et al.  A theory of software product line refinement , 2010, Theor. Comput. Sci..

[35]  Ralph E. Johnson,et al.  Embracing the C preprocessor during refactoring , 2013, J. Softw. Evol. Process..

[36]  Gustavo Soares Soares Automated behavioral testing of refactoring engines , 2012, SPLASH '12.

[37]  Lowell Jay Arthur Software evolution: the software maintenance challenge , 1988 .

[38]  Wolfgang Schröder-Preikschat,et al.  A quantitative analysis of aspects in the eCos kernel , 2006, EuroSys.

[39]  Ira D. Baxter,et al.  Preprocessor conditional removal by simple partial evaluation , 2001, Proceedings Eighth Working Conference on Reverse Engineering.