Difference between revisions of "cpp/language/translation phases"
m (punctuation) |
m (punctuation) |
||
Line 19: | Line 19: | ||
===Phase 2=== | ===Phase 2=== | ||
− | @1@ Whenever backslash appears at the end of a line (immediately followed by the newline character), both backslash and newline are deleted, combining two physical source lines into one logical source line. This is a single-pass operation | + | @1@ Whenever backslash appears at the end of a line (immediately followed by the newline character), both backslash and newline are deleted, combining two physical source lines into one logical source line. This is a single-pass operation; a line ending in two backslashes followed by an empty line does not combine three lines into one. If a universal character name ({{c|\uXXX}}) is formed on this phase, the behavior is undefined. |
@2@ If a non-empty source file does not end with a newline character after this step (whether it had no newline originally, or it ended with a backslash), {{rev inl|until=c++11|the behavior is undefined}}{{rev inl|since=c++11|a terminating newline character is added}} | @2@ If a non-empty source file does not end with a newline character after this step (whether it had no newline originally, or it ended with a backslash), {{rev inl|until=c++11|the behavior is undefined}}{{rev inl|since=c++11|a terminating newline character is added}} | ||
Revision as of 20:41, 15 July 2015
The C++ source file is processed by the compiler as if the following phases take place, in this exact order:
Contents |
Phase 1
- The basic source character set consists of 96 characters:
\u
or \U
) or by some internal form that is handled equivalently.
3) Trigraph sequences are replaced by corresponding single-character representations.
|
(until C++17) |
Phase 2
Phase 3
Any transformations performed at stages 1 and 2 are reverted between the initial and the final double quote of any raw string literal. |
(since C++11) |
Phase 4
Phase 5
Phase 6
Adjacent string literals are concatenated.
Phase 7
Compilation takes place: the tokens are syntactically and semantically analyzed and translated as a translation unit.
Phase 8
Each translation unit is examined to produce a list of required template instantiations, including the ones requested by explicit instantiations. The definitions of the templates are located, and the required instantiations are performed to produce instantiation units.
Phase 9
Translation units, instantiation units, and library components needed to satisfy external references are collected into a program image which contains information needed for execution in its execution environment.
Notes
Some compilers don't implement instantiation units (also known as template repositories or template registries) and simply compile each template instantiation at Phase 7, storing the code in the object file where it is implicitly or explicitly requested, and then the linker collapses these compiled instantiations into one at Phase 9
References
- C++11 standard (ISO/IEC 14882:2011):
- 2.2 Phases of translation [lex.phases]
- C++98 standard (ISO/IEC 14882:1998):
- 2.1 Phases of translation [lex.phases]
See also
C documentation for phases of translation
|