diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2008-11-11 11:37:55 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2008-11-11 11:37:55 +0000 |
commit | c470476420249d85e6a82275e90d3a8f62312fa1 (patch) | |
tree | a8f9b143310c392c35c5883bd8358da872b63403 /clang/lib/Sema/SemaExprCXX.cpp | |
parent | 8cb2e28e43b99df65c904d87ada93c99660e4fa4 (diff) | |
download | bcm5719-llvm-c470476420249d85e6a82275e90d3a8f62312fa1.tar.gz bcm5719-llvm-c470476420249d85e6a82275e90d3a8f62312fa1.zip |
Implement C++ 'typeid' parsing and sema.
llvm-svn: 59042
Diffstat (limited to 'clang/lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index a6a62a9e377..e420ce59916 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -19,6 +19,34 @@ #include "clang/Basic/Diagnostic.h" using namespace clang; + +/// ActOnCXXTypeidOfType - Parse typeid( type-id ). +Action::ExprResult +Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc, + bool isType, void *TyOrExpr, SourceLocation RParenLoc) { + const NamespaceDecl *StdNs = GetStdNamespace(); + if (!StdNs) { + Diag(OpLoc, diag::err_need_header_before_typeid); + return ExprResult(true); + } + if (!Ident_TypeInfo) { + Ident_TypeInfo = &PP.getIdentifierTable().get("type_info"); + } + Decl *TypeInfoDecl = LookupDecl(Ident_TypeInfo, + Decl::IDNS_Tag | Decl::IDNS_Ordinary, + 0, StdNs, /*createBuiltins=*/false); + RecordDecl *TypeInfoRecordDecl = dyn_cast_or_null<RecordDecl>(TypeInfoDecl); + if (!TypeInfoRecordDecl) { + Diag(OpLoc, diag::err_need_header_before_typeid); + return ExprResult(true); + } + + QualType TypeInfoType = Context.getTypeDeclType(TypeInfoRecordDecl); + + return new CXXTypeidExpr(isType, TyOrExpr, TypeInfoType.withConst(), + SourceRange(OpLoc, RParenLoc)); +} + /// ActOnCXXBoolLiteral - Parse {true,false} literals. Action::ExprResult Sema::ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) { |