Skip to main content

Nobrainer: An Example-Driven Framework for C/C++ Code Transformations

  • Conference paper
  • First Online:

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 11964))

Abstract

Refactoring is a standard part of any modern development cycle. It helps to reduce technical debt and keep software projects healthy. However, in many cases refactoring requires that transformations are applied globally across multiple files. Applying them manually involves large amounts of monotonous work. Nevertheless, automatic tools are severely underused because users find them unreliable, difficult to adopt, and not customizable enough.

This paper presents a new code transformation framework. It delivers an intuitive way to specify the expected outcome of a transformation applied within the whole project. The user provides simple C/C++ code snippets that serve as examples of what the code should look like before and after the transformation. Due to the absence of any additional abstractions (such as domain-specific languages), we believe this approach flattens the learning curve, making adoption easier.

Besides using the source code of the provided snippets, the framework also operates at the AST level. This gives it a deeper understanding of the program, which allows it to validate the correctness of the transformation and match the exact cases required by the user.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 1.

    https://www.merriam-webster.com/dictionary/no-brainer.

  2. 2.

    https://dictionary.cambridge.org/dictionary/english/no-brainer.

  3. 3.

    https://clang.llvm.org/.

  4. 4.

    https://clang.llvm.org/docs/JSONCompilationDatabase.html.

  5. 5.

    https://clang.llvm.org/extra/index.html.

References

  1. Clang documentation: Matching the clang AST. https://clang.llvm.org/docs/LibASTMatchers.html

  2. Brown, N., et al.: Managing technical debt in software-reliant systems. In: Proceedings of the FSE/SDP Workshop on Future of Software Engineering Research, FoSER 2010, pp. 47–52. ACM, New York (2010). https://doi.org/10.1145/1882362.1882373, http://doi.acm.org/10.1145/1882362.1882373

  3. Cunningham, W.: The WyCash portfolio management system. SIGPLAN OOPS Mess. 4(2), 29–30 (1992). https://doi.org/10.1145/157710.157715. http://doi.acm.org/10.1145/157710.157715

    Article  Google Scholar 

  4. Fowler, M., Beck, K., Brant, J., Opdyke, W., Roberts, D.: Refactoring: Improving the Design of Existing Code. Addison-Wesley Professional, Boston (1999)

    Google Scholar 

  5. Waddington, D.G., Yao, B.: High-fidelity C/C++ code transformation. Electron. Notes Theoret. Comput. Sci. 141, 35–56 (2007). https://doi.org/10.1016/j.entcs.2005.04.037

    Article  MATH  Google Scholar 

  6. Graf, E., Zgraggen, G., Sommerlad, P.: Refactoring support for the C++ development tooling. In: OOPSLA Companion (2007)

    Google Scholar 

  7. Lahoda, J., Bečička, J., Ruijs, R.B.: Custom declarative refactoring in NetBeans: tool demonstration. In: Proceedings of the Fifth Workshop on Refactoring Tools, WRT 2012, pp. 63–64. ACM, New York (2012). https://doi.org/10.1145/2328876.2328886, http://doi.acm.org/10.1145/2328876.2328886

  8. Meyerovich, L.A., Rabkin, A.S.: Empirical analysis of programming language adoption. SIGPLAN Not. 48(10), 1–18 (2013). https://doi.org/10.1145/2544173.2509515. http://doi.acm.org/10.1145/2544173.2509515

    Article  Google Scholar 

  9. Murphy-Hill, E.R., Parnin, C., Black, A.P.: How we refactor, and how we know it. In: ICSE, pp. 287–297. IEEE (2009). http://dblp.uni-trier.de/db/conf/icse/icse2009.html#Murphy-HillPB09

  10. Pinto, G.H., Kamei, F.: What programmers say about refactoring tools?: An empirical investigation of stack overflow. In: Proceedings of the 2013 ACM Workshop on Workshop on Refactoring Tools. WRT 2013, pp. 33–36. ACM, New York (2013). https://doi.org/10.1145/2541348.2541357, http://doi.acm.org/10.1145/2541348.2541357

  11. Ray, B., Posnett, D., Devanbu, P., Filkov, V.: A large-scale study of programming languages and code quality in github. Commun. ACM 60(10), 91–100 (2017). https://doi.org/10.1145/3126905. http://doi.acm.org/10.1145/3126905

    Article  Google Scholar 

  12. Tracz, W.: Refactoring for software design smells: managing technical debt by Girish Suryanarayana, Ganesh Samarthyam, and Tushar Sharma. ACM SIGSOFT Softw. Eng. Notes 40(6), 36 (2015). http://dblp.uni-trier.de/db/journals/sigsoft/sigsoft40.html#Tracz15a

    Article  Google Scholar 

  13. Wasserman, L.: Scalable, example-based refactorings with refaster. In: Proceedings of the 2013 ACM Workshop on Workshop on Refactoring Tools, pp. 25–28. ACM (2013)

    Google Scholar 

  14. Wright, H., Jasper, D., Klimek, M., Carruth, C., Wan, Z.: Large-scale automated refactoring using ClangMR. In: Proceedings of the 29th International Conference on Software Maintenance (2013)

    Google Scholar 

Download references

Acknowledgments

This work resulted from a joint project with Samsung Research. The authors of this paper are grateful to the colleagues from Samsung for their valuable ideas and feedback.

Author information

Authors and Affiliations

Authors

Corresponding authors

Correspondence to Valeriy Savchenko , Konstantin Sorokin , Georgiy Pankratenko , Sergey Markov , Alexander Spiridonov , Ilia Alexandrov , Alexander Volkov or Kwangwon Sun .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Savchenko, V. et al. (2019). Nobrainer: An Example-Driven Framework for C/C++ Code Transformations. In: Bjørner, N., Virbitskaite, I., Voronkov, A. (eds) Perspectives of System Informatics. PSI 2019. Lecture Notes in Computer Science(), vol 11964. Springer, Cham. https://doi.org/10.1007/978-3-030-37487-7_12

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-37487-7_12

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-37486-0

  • Online ISBN: 978-3-030-37487-7

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics