Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1 | //===--- FullExpr.cpp - C++ full expression class ---------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the FullExpr interface, to be used for type safe handling |
| 11 | // of full expressions. |
| 12 | // |
| 13 | // Full expressions are described in C++ [intro.execution]p12. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #include "clang/AST/ASTContext.h" |
| 18 | #include "clang/AST/FullExpr.h" |
Anders Carlsson | d4a0552 | 2009-12-16 06:10:22 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
| 20 | #include "clang/AST/ExprCXX.h" |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 21 | #include "llvm/Support/AlignOf.h" |
| 22 | using namespace clang; |
| 23 | |
Anders Carlsson | d4a0552 | 2009-12-16 06:10:22 +0000 | [diff] [blame] | 24 | FullExpr FullExpr::Create(ASTContext &Context, Expr *SubExpr, |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 25 | CXXTemporary **Temporaries, unsigned NumTemporaries) { |
Anders Carlsson | d4a0552 | 2009-12-16 06:10:22 +0000 | [diff] [blame] | 26 | FullExpr E; |
| 27 | |
| 28 | if (!NumTemporaries) { |
| 29 | E.SubExpr = SubExpr; |
| 30 | return E; |
| 31 | } |
| 32 | |
| 33 | unsigned Size = sizeof(FullExpr) |
| 34 | + sizeof(CXXTemporary *) * NumTemporaries; |
| 35 | |
| 36 | unsigned Align = llvm::AlignOf<ExprAndTemporaries>::Alignment; |
| 37 | ExprAndTemporaries *ET = |
| 38 | static_cast<ExprAndTemporaries *>(Context.Allocate(Size, Align)); |
| 39 | |
| 40 | ET->SubExpr = SubExpr; |
| 41 | std::copy(Temporaries, Temporaries + NumTemporaries, ET->temps_begin()); |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 42 | |
Anders Carlsson | d4a0552 | 2009-12-16 06:10:22 +0000 | [diff] [blame] | 43 | return E; |
| 44 | } |
| 45 | |