Parsing, ASTs, and semantic analysis for the declaration of overloaded
operators in C++. Overloaded operators can be called directly via
their operator-function-ids, e.g., "operator+(foo, bar)", but we don't
yet implement the semantics of operator overloading to handle, e.g.,
"foo + bar".



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58817 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index b737695..49c28ee 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -356,7 +356,8 @@
 /// [GNU]   '__extension__'  '__real'  '__imag'
 ///
 ///       primary-expression: [C99 6.5.1]
-///         identifier
+/// [C99]   identifier
+//  [C++]   id-expression
 ///         constant
 ///         string-literal
 /// [C++]   boolean-literal  [C++ 2.13.5]
@@ -390,6 +391,16 @@
 ///         enumeration-constant -> identifier
 ///         character-constant
 ///
+///       id-expression: [C++ 5.1]
+///                   unqualified-id
+///                   qualified-id           [TODO]
+///
+///       unqualified-id: [C++ 5.1]
+///                   identifier
+///                   operator-function-id
+///                   conversion-function-id [TODO]
+///                   '~' class-name         [TODO]
+///                   template-id            [TODO]
 Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) {
   ExprResult Res;
   tok::TokenKind SavedKind = Tok.getKind();
@@ -461,6 +472,7 @@
     }
     
     // primary-expression: identifier
+    // unqualified-id: identifier
     // constant: enumeration-constant
 
     // Consume the identifier so that we can see if it is followed by a '('.
@@ -589,6 +601,17 @@
     return ParsePostfixExpressionSuffix(Res);
   }
 
+  case tok::kw_operator: {
+    SourceLocation OperatorLoc = Tok.getLocation();
+    if (IdentifierInfo *II = MaybeParseOperatorFunctionId()) {
+      Res = Actions.ActOnIdentifierExpr(CurScope, OperatorLoc, *II, 
+                                        Tok.is(tok::l_paren));
+      // These can be followed by postfix-expr pieces.
+      return ParsePostfixExpressionSuffix(Res);
+    }
+    break;
+  }
+
   case tok::at: {
     SourceLocation AtLoc = ConsumeToken();
     return ParseObjCAtExpression(AtLoc);