Download ROSE User Manual - ROSE compiler infrastructure

Transcript
58
CHAPTER 5. SAGE III INTERMEDIATE REPRESENTATION
and appears in the AST (and in the unparsed [generated] code) as
class A a;
class A *aptr = (&a);
class A **aptrptr = (&aptr);
(*aptr)[1];
(*aptr)[1];
(*(*aptrptr))[1];
(*(*aptrptr))[1];
(*aptr -> Aptr)[1];
(*(*aptr -> Aptrptr))[1];
10. Normalization of const ref (const &).
Const references, such as
X<A const & > x3;
are presently normalized to be
X<const A & > x3
11. Template arguments explicitly output.
Template types are output with template arguments. Code such as:
std::string var = std::string("");
is normalized to be
std::string var = std::basic_string < char , std::char_traits< char > , std::allocator< char > > ((""));
12. Constructor calls are really variable declarations.
C++ classes can define constructors. When they do the constructors are represented in the AST as a
member function declaration and marked specifically as a constructor (conversion operators and destructors
are also member function declarations and marked explicitly). However, the call to a constructor is a bit
special in C++ and does not appear in the AST as a member function call. It appears as a variable
declaration within the AST fragment representing the variable declaration a SgConstructorInitializer
is used. So, where a variable of a class type X is written in the code as
X variable;
the form in the AST is more similar to the code represented by
X variable = X();
Semantically the two forms of code are equivalent (since the redundant constructor calls will be optimized
away), and so this represents a form of normalization within the AST.
13. Redundant casts and copy constructors.
The use of redundant casts are represented as nested calls to copy constructors. Code such as:
std::string arg5 = (std::string) (std::string)std::string("");
is normalized to be