Design: cpp11-migrate

简介: Design: cpp11-migrate This document describes the design of the tool cpp11-migrate used to automatically migrate legacy C++ code to use features of the new C++11 standard.

Design: cpp11-migrate

This document describes the design of the tool cpp11-migrate used to automatically migrate legacy C++ code to use features of the new C++11 standard. The tool is to be based on clang’s LibTooling.

Context

C++11 introduces many new convenience and performance features over past standards of C++. For many of the new features, introduction into an existing C++ codebase would be straightforward and would yield more performant and easier to maintain code. The only drawback is the amount of developer time required to convert existing code.


Fortunately, automatic conversion for many features is possible with clang’s LibTooling. One tool already exists in the clang-tools-extra repository: loop-convert, which attempts to make use of range-based for loops where possible. loop-convert uses AST Matchers and Rewriters. Many other features of C++11 can be addressed in the same way.

Goals

  • A single tool that applies code transformations for all C++11 features with implemented transformations.

  • A framework where adding support for new transformations is minimally invasive to the tool and other transformation implementations.

  • Transformations can be independently enabled/disabled via the command-line.

Non-Goals

  • Refactoring of code to replace hacks and current best-practices with cleaner implementations made available by C++11. e.g. using variadic templates to replace multiple template specializations to support N-argument functions.

Code Location

This tool is built on top of LibTooling and therefore should live in the clang-tools-extra repo.

Implementation

Each transform, an implementation of the application of a particular C++11 feature, is registered with a central framework. Registration happens the same way as for LLVM passes. That is, a global variable of type RegisterTransform<...> is instantiated providing the class name for the transform and an identifying name suitable for use on the command line. Transforms should be subclasses of a base Transform class.


The central framework’s responsibility is the construction of the CompilationDatabase, parsing command-line arguments, and creating each enabled transform by way of registered factories. Each transform is then applied to source files in turn. Syntax checks happen after the application of each transform to identify transforms that failed and abort all changes made so far to failing source files. Transforms are applied in the order they are registered.


Command-Line Interface

Each transform can be enabled or disabled with a command-line switch. e.g.:


cpp11-migrate --loop-convert --nullptr-convert


Transforms requiring arguments, like loop convert, can define their own command-line arguments local to the transformation implementation thanks to the design of the LLVM CommandLine Library. Such arguments should always be named and be named so to not conflict with arguments defined by other transforms.


cpp11-migrate --loop-convert --loop-convert-risk=A0

Future Directions

  • Rewriting to files in memory instead of on disk to improve performance. This is especially useful as the number of times Replacements are applied increases.

  • During registration, transforms can indicate what sort of transformation they provide (e.g. performance, maintenance, etc.). This would enable high-level command-line arguments to enable all transforms of given categories.

  • Support across all transforms for varying levels of risk. Some transforms may have the opportunity to make changes that affect semantics. In such cases a user can specify their tolerance to such changes in a way that affects all transforms that support risk levels. All such transforms no longer need to individually provide command-line arguments for risk levels.

  • Handling dependencies between transformations and controlling the order of transformations.

  • Saving the state of source files after every successful transform so that when an error occurs the work of successful transforms is not lost.

  • Determining a set of transformations enabled by default.

  • An interactive mode to afford transforms that require user input on the level of each replacement for information on intention, style, etc. (e.g. automatic addition of move constructors, using constexpr, adding noexcept to move constructors, etc.) Simpler transforms with risky replacements can also get user approval on a case-by-case basis.

目录
相关文章
|
Android开发
Creating Apps With Material Design —— Working with Drawables
转载请注明 http://blog.csdn.net/eclipsexys 翻译自Developer Android,时间仓促,有翻译问题请留言指出,谢谢 Drawable 通过可绘制了以下功能帮助您实现材料设计你的应用程序:      可绘制着色     突出的颜色提取     矢量可绘 这一课将告诉您如何使用您的应用程序这些功能。
689 0
|
7月前
|
数据库 开发工具 开发者
【Python】已解决:You have 18 unapplied migration(s). Your project may not work properly until you apply t
【Python】已解决:You have 18 unapplied migration(s). Your project may not work properly until you apply t
300 0
|
Python
Chapter 1: Creating the GUI Form and Adding Widgets
# -*- coding: utf-8 -*- # import import tkinter as tk # 1 imports from tkinter import ttk from tkinter import scrolledtext as st win = tk.
1013 0
|
Python
ZetCode PyQt4 tutorial custom widget
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, we create a custom widget.
814 0
|
C语言
Qt Creator新安装后运行一个程序后,出现错误:Error while building/deploying project dict-qt (kit: Desktop Qt 5.10.0 MinGW 32bit) When executing step "qmake"
1、环境介绍:在windows10 Pro下,当前Qt Creator版本,如下图所示: 2、问题描述:当用Qt Creator新建一个工程后,按Ctrl + R 构建/部署时,出现问题,问题截图如下: 3、解决方案:这是由于Qt Creator打开的工程文件夹的绝对路径中存在中文字符,只需将工...
6009 0
|
6月前
|
Dart C语言 Windows
Dart ffi 使用问题之要生成plugin_ffi_sample_bindings_generated.dart文件该如何操作
Dart ffi 使用问题之要生成plugin_ffi_sample_bindings_generated.dart文件该如何操作
|
JavaScript
vue cli3.0创项目报错‘This may cause things to work incorrectly. Make sure to use the same version for b’
vue cli3.0创项目报错‘This may cause things to work incorrectly. Make sure to use the same version for b’
vue cli3.0创项目报错‘This may cause things to work incorrectly. Make sure to use the same version for b’

热门文章

最新文章