Add Sema support for C++ classes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52956 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index e49a43c..be7cf06 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -49,3 +49,21 @@
 Sema::ActOnCXXThrow(SourceLocation OpLoc, ExprTy *E) {
   return new CXXThrowExpr((Expr*)E, Context.VoidTy, OpLoc);
 }
+
+Action::ExprResult Sema::ActOnCXXThis(SourceLocation ThisLoc) {
+  /// C++ 9.3.2: In the body of a non-static member function, the keyword this
+  /// is a non-lvalue expression whose value is the address of the object for
+  /// which the function is called.
+
+  if (!isa<FunctionDecl>(CurContext)) {
+    Diag(ThisLoc, diag::err_invalid_this_use);
+    return ExprResult(true);
+  }
+
+  if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext))
+    if (MD->isInstance())
+      return new PreDefinedExpr(ThisLoc, MD->getThisType(Context),
+                                PreDefinedExpr::CXXThis);
+
+  return Diag(ThisLoc, diag::err_invalid_this_use);
+}