[0x0001] ( Preface ) { Inside the C++ Object Model }

Simplifier

What does a Simplifier do between type checking and code generation? It transforms the internal program representation. There are three general flavors of transformations required by any object model component:

简化器在类型检查和代码生成之间完成什么任务呢?简化器负责转换内部代码。一般有以下三种不同风格但是所有对象模型都需要的转换。

1.Implementation-dependent transformations. These are implementation-specific aspects and vary across compilers. Under ALF, they involved the transformations of what we called "tentative" nodes. For example, when the parser sees the expression
fct();
it doesn't know if this is (a) an invocation of a function represented or pointed to by fct or (b) the application of an overloaded call operator on a class object fct. By default, the expression is represented as a function call. The Simplifier rewrites and replaces the call subtree when case (b) applies.

  1. 基于编译器的转换。这些部分根据编译器的不同具有不同的实现。在ALF下,他们包含我们成为“临时节点”(tentative nodes)的转换。例如,当语法解析器遇到如下表达式
    fct();
    它并不知道这是
    a. 一个由fct表示或指向的函数调用,还是
    b. 一个类对象fct的重载函数调用运算符。
    一般情况下,这个表达式会被编译器解释为一个函数调用,即a策略。而对于采取b策略的编译器,其简化器将重写并替换子调用树。

2.Language semantics transformations. These include constructor/destructor synthesis and augmentation, memberwise initialization and memberwise copy support, and the insertion within program code of conversion operators, temporaries, and constructor/destructor calls.

  1. 语言语义转换。这些转换包含了构造函数或析构函数合成和扩展(augmentation),对成员初始化和成员拷贝的支持,以及向程序中插入运算符变换、临时变量、构造函数或析构函数调用等代码段。

3.Code and object model transformations. These include support for virtual functions, virtual base classes and inheritance in general, operators new and delete, arrays of class objects, local static class instances, and the static initialization of global objects with nonconstant expressions. An implementation goal I aimed for in the Simplifier was to provide an Object Model hierarchy in which the object implementation was a virtual interface supporting multiple object models.

  1. 代码和对象模型转换。这些转换包含了对以下技术的支持:虚函数,虚基类和虚继承,new/delete运算符,类对象数组,局部静态类实例对象,以及用非常量表达式静态初始化全局对象。我为简化器设立(aimed for)的一个目标是提供一个对象模型层级作为可支持多种对象模型的一个虚拟接口层。

These last two categories of transformations form the basis of this book. Does this mean this book is written for compiler writers? No, absolutely not. It is written by a (former) compiler writer (that's me) for intermediate to advanced C++ programmers (ideally, that's you). The assumption behind this book is that the programmer, by understanding the underlying C++ Object Model, can write programs that are both less error prone and more efficient.

后两种的变换构成了这本书的主要内容。是否意味着这本书是写给编译器开发者的?不,绝不是这样。这是我作为前编译器开发者,写给(intermediate to)你们高级C++开发者的。写这本书的初衷(assumption)是通过让诸位通过理解C++底层(underlying)对象模型,写出错误更少(less error prone)且更高效的程序。

你可能感兴趣的:([0x0001] ( Preface ) { Inside the C++ Object Model })