blob: e49a43c4728cc6cfcd97026a01eca21d11677eed [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- SemaExprCXX.cpp - Semantic Analysis for Expressions --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements semantic analysis for C++ expressions.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Sema.h"
15#include "clang/AST/ExprCXX.h"
Steve Naroff210679c2007-08-25 14:02:58 +000016#include "clang/AST/ASTContext.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000017using namespace clang;
18
Steve Naroff1b273c42007-09-16 14:56:35 +000019/// ActOnCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
Reid Spencer5f016e22007-07-11 17:01:13 +000020Action::ExprResult
Steve Naroff1b273c42007-09-16 14:56:35 +000021Sema::ActOnCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
Reid Spencer5f016e22007-07-11 17:01:13 +000022 SourceLocation LAngleBracketLoc, TypeTy *Ty,
23 SourceLocation RAngleBracketLoc,
24 SourceLocation LParenLoc, ExprTy *E,
25 SourceLocation RParenLoc) {
26 CXXCastExpr::Opcode Op;
27
28 switch (Kind) {
29 default: assert(0 && "Unknown C++ cast!");
30 case tok::kw_const_cast: Op = CXXCastExpr::ConstCast; break;
31 case tok::kw_dynamic_cast: Op = CXXCastExpr::DynamicCast; break;
32 case tok::kw_reinterpret_cast: Op = CXXCastExpr::ReinterpretCast; break;
33 case tok::kw_static_cast: Op = CXXCastExpr::StaticCast; break;
34 }
35
36 return new CXXCastExpr(Op, QualType::getFromOpaquePtr(Ty), (Expr*)E, OpLoc);
37}
38
Steve Naroff1b273c42007-09-16 14:56:35 +000039/// ActOnCXXBoolLiteral - Parse {true,false} literals.
Reid Spencer5f016e22007-07-11 17:01:13 +000040Action::ExprResult
Steve Naroff1b273c42007-09-16 14:56:35 +000041Sema::ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) {
Reid Spencer5f016e22007-07-11 17:01:13 +000042 assert((Kind != tok::kw_true || Kind != tok::kw_false) &&
43 "Unknown C++ Boolean value!");
Steve Naroff210679c2007-08-25 14:02:58 +000044 return new CXXBoolLiteralExpr(Kind == tok::kw_true, Context.BoolTy, OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +000045}
Chris Lattner50dd2892008-02-26 00:51:44 +000046
47/// ActOnCXXThrow - Parse throw expressions.
48Action::ExprResult
49Sema::ActOnCXXThrow(SourceLocation OpLoc, ExprTy *E) {
50 return new CXXThrowExpr((Expr*)E, Context.VoidTy, OpLoc);
51}