blob: 74be79aaddf0ba98bf4e5345472ce79ab96cffc2 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- SemaExprCXX.cpp - Semantic Analysis for Expressions --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Bill Wendling and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements semantic analysis for C++ expressions.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Sema.h"
15#include "clang/AST/ExprCXX.h"
16using namespace clang;
17
18/// ParseCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
19Action::ExprResult
20Sema::ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
21 SourceLocation LAngleBracketLoc, TypeTy *Ty,
22 SourceLocation RAngleBracketLoc,
23 SourceLocation LParenLoc, ExprTy *E,
24 SourceLocation RParenLoc) {
25 CXXCastExpr::Opcode Op;
26
27 switch (Kind) {
28 default: assert(0 && "Unknown C++ cast!");
29 case tok::kw_const_cast: Op = CXXCastExpr::ConstCast; break;
30 case tok::kw_dynamic_cast: Op = CXXCastExpr::DynamicCast; break;
31 case tok::kw_reinterpret_cast: Op = CXXCastExpr::ReinterpretCast; break;
32 case tok::kw_static_cast: Op = CXXCastExpr::StaticCast; break;
33 }
34
35 return new CXXCastExpr(Op, QualType::getFromOpaquePtr(Ty), (Expr*)E, OpLoc);
36}
37
38/// ParseCXXBoolLiteral - Parse {true,false} literals.
39Action::ExprResult
40Sema::ParseCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) {
41 assert((Kind != tok::kw_true || Kind != tok::kw_false) &&
42 "Unknown C++ Boolean value!");
43 return new CXXBoolLiteralExpr(Kind == tok::kw_true, OpLoc);
44}