Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- 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" |
Steve Naroff | 210679c | 2007-08-25 14:02:58 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
| 19 | /// ParseCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's. |
| 20 | Action::ExprResult |
| 21 | Sema::ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind, |
| 22 | 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 | |
| 39 | /// ParseCXXBoolLiteral - Parse {true,false} literals. |
| 40 | Action::ExprResult |
| 41 | Sema::ParseCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) { |
| 42 | assert((Kind != tok::kw_true || Kind != tok::kw_false) && |
| 43 | "Unknown C++ Boolean value!"); |
Steve Naroff | 210679c | 2007-08-25 14:02:58 +0000 | [diff] [blame] | 44 | return new CXXBoolLiteralExpr(Kind == tok::kw_true, Context.BoolTy, OpLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 45 | } |