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. 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.
时间: 2024-09-21 10:49:21

Design: cpp11-migrate的相关文章

使用Android Support Design 控件TabLayout 方便快捷实现选项卡功能

1.概述 TabLayout是在2015年的google大会上,google发布了新的Android Support Design库的新组件之一,以此来全面支持Material Design 设计风格的UI效果,为了可以使用这些新颖MD组件首先必须要在Android Studio的SDK的EXTRA支持库安装Android Support Library支持库,如下所示 该组件在design库中因此还需要在AS中添加依赖库 FILE--project struct 右键app选择Library

Android Support Design 控件 FloatingActionButton

 经常刚可以看到悬浮控件,比如印象笔记的下面那个绿色的悬浮按钮,这个控件非常简单也是来自Design Support Library中同理需要在Android studio中加入依赖库:design库 具体操作可以参考我前一篇http://blog.csdn.net/xsf50717/article/details/49405309 使用起来也很简单,下面是效果图 最下角是我真机的悬浮按钮,直接忽略吧 首先就是布局文件 [html] view plain copy <RelativeLayout

为触控而设计——Design for Touch

自入职以来,一直在做移动端的交互设计,半年多感触最深的便是触屏设备的大规模兴起所带来移动互联 网翻天覆地的变化.我们身边随处可见的触屏手机.平板电脑,证明着移动互联网的狂潮已悄然而至.地铁. 公交.商场.大街,人手一台的移动设备正在改变我们的生活. 作为一名设计人员,自然少不了对行 业的密切关注,最近浏览国外同行的博客,看到一篇关于触控设备设计的个人总结,在此小作翻译,与大家分 享一下. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

网易新闻安卓客户端MATERIAL DESIGN实战

  项目背景 网易新闻安卓版一直以来照搬IOS版的交互和视觉,这在一定程度上保持了不同平台上应用风格和用户体验的一致性,也相应的减少了设计和开发的人力成本.市面上的大部分移动应用也是如此.所以,一直以来给用户的感觉是Android没有独立鲜明的视觉风格,但是事实并非如此.不久前Google推出AndroidL系统,视觉语言Material design也相应诞生.Google为设计师提供了一套完整的官方交互视觉设计指引,扁平化.华丽又稳重的色彩,将卡片的功能发挥到极致. 以此为契机,网易新闻也尝

Material Design学习之 Button(详细分析,传说中的水滴动画)

转载请注明出处:王亟亟的大牛之路       上一篇大致介绍了Material Design的一些基本概念传送门:http://blog.csdn.net/ddwhan0123/article/details/50541561 这一片来具体学习下里面的内容,这篇分为两部分一部分是原理分析,一部分是代码分析. 先简要的介绍一些理论知识,顺便温顾下基础知识 按钮 按钮由文字和/或图标组成,文字及图标必须能让人轻易地和点击后展示的内容联系起来. 主要的按钮有三种: 悬浮响应按钮(Floating ac

Progress Bar Using AJAX: Design Details

ajax Progress Bar Using AJAX: Design Details The sequence diagram below details the participants on both the client and server needed to provide an AJAX progress bar. The details are explained in further detail in the remainder of this document. Trac

Head First Design Patterns

    在更大的计划之前,先温习一下Design Pattern的功课.    看了<Head First Design Patterns>里讲Decorator的样章,发现JOLT大奖不是白拿的,叙事能力之强,表达之清晰,不是那些满腹经伦的老先生可以比的.而且整个Pattern的讲述过程循序渐进,真的可以保证--小白都能学会设计模式.    可惜就只有样章.Head First系列的电子书都不好找,只好还是翻出老先生们的书来看.    这次温习很快做完,其实GOF80%的模式,都是基于一个原

最佳化Table Design三范式

最佳化 Table Design   將 Table 的資料庫分解為較小的 Table 直到每個 table 的每個 field 都 depend on 該 table 的 key why?  降低重複性 (redundancy) ?*指資料之儲存*?   清除不一致性(Consistency) ?*指資料之異動*? 设计三范式: (1)Frist Normal Form (1NF)    "每一資料欄只含一個值."   检查有无具有重复值的属性,有则将其移到新的实体中. (2)Sec

网页设计(Web Design)空格处理方法

文章描述:相信认真做过网页设计(Web Design),或者关注过页面设计的同行都对"空格"不陌生."空格"属于一类细节,很容易被忽略,但又比较影响效果,更麻烦是很不好控制.此问题总结的想法,来自"知乎"上梁海的提问,以及对他提供专业答案的反思和总结. 相信认真做过网页设计(Web Design),或者关注过页面设计的同行都对"空格"不陌生."空格"属于一类细节,很容易被忽略,但又比较影响效果,更麻烦是很不