blob: 93ee8d136000a8c33a69af068a80e5447f797983 [file] [log] [blame]
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001//===--- 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 Carlssond4a05522009-12-16 06:10:22 +000019#include "clang/AST/Expr.h"
20#include "clang/AST/ExprCXX.h"
Anders Carlsson5ee56e92009-12-16 02:09:40 +000021#include "llvm/Support/AlignOf.h"
22using namespace clang;
23
Anders Carlssond4a05522009-12-16 06:10:22 +000024FullExpr FullExpr::Create(ASTContext &Context, Expr *SubExpr,
Anders Carlsson5ee56e92009-12-16 02:09:40 +000025 CXXTemporary **Temporaries, unsigned NumTemporaries) {
Anders Carlssond4a05522009-12-16 06:10:22 +000026 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 Carlsson5ee56e92009-12-16 02:09:40 +000042
Anders Carlssond4a05522009-12-16 06:10:22 +000043 return E;
44}
45