blob: 74be79aaddf0ba98bf4e5345472ce79ab96cffc2 [file] [log] [blame]
Chris Lattner29375652006-12-04 18:06:35 +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"
Chris Lattner29375652006-12-04 18:06:35 +000016using 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) {
Bill Wendling4073ed52007-02-13 01:51:42 +000028 default: assert(0 && "Unknown C++ cast!");
Chris Lattner29375652006-12-04 18:06:35 +000029 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
Bill Wendlinga6930032007-06-29 18:21:34 +000035 return new CXXCastExpr(Op, QualType::getFromOpaquePtr(Ty), (Expr*)E, OpLoc);
Chris Lattner29375652006-12-04 18:06:35 +000036}
Bill Wendling4073ed52007-02-13 01:51:42 +000037
38/// ParseCXXBoolLiteral - Parse {true,false} literals.
39Action::ExprResult
Steve Naroff53f07dc2007-05-17 21:49:33 +000040Sema::ParseCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) {
Bill Wendling4073ed52007-02-13 01:51:42 +000041 assert((Kind != tok::kw_true || Kind != tok::kw_false) &&
Bill Wendlingbf313b02007-02-13 20:09:46 +000042 "Unknown C++ Boolean value!");
Steve Naroff53f07dc2007-05-17 21:49:33 +000043 return new CXXBoolLiteralExpr(Kind == tok::kw_true, OpLoc);
Bill Wendling4073ed52007-02-13 01:51:42 +000044}