2006-11-05 15:46:30 +08:00
|
|
|
//===--- ParseInit.cpp - Initializer Parsing ------------------------------===//
|
2006-08-14 05:54:02 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-08-14 05:54:02 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements initializer parsing as specified by C99 6.7.8.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Parse/Parser.h"
|
2010-09-15 22:51:05 +08:00
|
|
|
#include "RAIIObjectsForParser.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Parse/ParseDiagnostic.h"
|
2010-08-21 02:27:03 +08:00
|
|
|
#include "clang/Sema/Designator.h"
|
|
|
|
#include "clang/Sema/Scope.h"
|
2007-07-19 09:06:55 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2009-10-18 07:52:50 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2006-08-14 05:54:02 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
|
2012-02-17 11:49:44 +08:00
|
|
|
/// MayBeDesignationStart - Return true if the current token might be the start
|
|
|
|
/// of a designator. If we can tell it is impossible that it is a designator,
|
|
|
|
/// return false.
|
|
|
|
bool Parser::MayBeDesignationStart() {
|
|
|
|
switch (Tok.getKind()) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
|
2006-08-14 05:54:02 +08:00
|
|
|
case tok::period: // designator: '.' identifier
|
2012-02-17 11:49:44 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case tok::l_square: { // designator: array-designator
|
2013-01-02 19:42:31 +08:00
|
|
|
if (!PP.getLangOpts().CPlusPlus11)
|
2008-10-27 06:41:58 +08:00
|
|
|
return true;
|
2012-02-17 11:49:44 +08:00
|
|
|
|
|
|
|
// C++11 lambda expressions and C99 designators can be ambiguous all the
|
|
|
|
// way through the closing ']' and to the next character. Handle the easy
|
|
|
|
// cases here, and fall back to tentative parsing if those fail.
|
|
|
|
switch (PP.LookAhead(0).getKind()) {
|
|
|
|
case tok::equal:
|
|
|
|
case tok::r_square:
|
|
|
|
// Definitely starts a lambda expression.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case tok::amp:
|
|
|
|
case tok::kw_this:
|
|
|
|
case tok::identifier:
|
|
|
|
// We have to do additional analysis, because these could be the
|
|
|
|
// start of a constant expression or a lambda capture list.
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Anything not mentioned above cannot occur following a '[' in a
|
|
|
|
// lambda expression.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-18 00:41:16 +08:00
|
|
|
// Handle the complicated case below.
|
|
|
|
break;
|
2012-02-17 11:49:44 +08:00
|
|
|
}
|
2006-08-14 05:54:02 +08:00
|
|
|
case tok::identifier: // designation: identifier ':'
|
2008-10-27 06:41:58 +08:00
|
|
|
return PP.LookAhead(0).is(tok::colon);
|
2006-08-14 05:54:02 +08:00
|
|
|
}
|
2012-02-18 00:41:16 +08:00
|
|
|
|
|
|
|
// Parse up to (at most) the token after the closing ']' to determine
|
2014-04-13 12:31:48 +08:00
|
|
|
// whether this is a C99 designator or a lambda.
|
2012-02-18 00:41:16 +08:00
|
|
|
TentativeParsingAction Tentative(*this);
|
2014-04-13 12:31:48 +08:00
|
|
|
|
|
|
|
LambdaIntroducer Intro;
|
|
|
|
bool SkippedInits = false;
|
|
|
|
Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro, &SkippedInits));
|
|
|
|
|
|
|
|
if (DiagID) {
|
|
|
|
// If this can't be a lambda capture list, it's a designator.
|
|
|
|
Tentative.Revert();
|
|
|
|
return true;
|
2012-02-18 00:41:16 +08:00
|
|
|
}
|
2014-04-13 12:31:48 +08:00
|
|
|
|
|
|
|
// Once we hit the closing square bracket, we look at the next
|
|
|
|
// token. If it's an '=', this is a designator. Otherwise, it's a
|
|
|
|
// lambda expression. This decision favors lambdas over the older
|
|
|
|
// GNU designator syntax, which allows one to omit the '=', but is
|
|
|
|
// consistent with GCC.
|
|
|
|
tok::TokenKind Kind = Tok.getKind();
|
|
|
|
// FIXME: If we didn't skip any inits, parse the lambda from here
|
|
|
|
// rather than throwing away then reparsing the LambdaIntroducer.
|
|
|
|
Tentative.Revert();
|
|
|
|
return Kind == tok::equal;
|
2006-08-14 05:54:02 +08:00
|
|
|
}
|
|
|
|
|
2010-04-22 06:36:40 +08:00
|
|
|
static void CheckArrayDesignatorSyntax(Parser &P, SourceLocation Loc,
|
|
|
|
Designation &Desig) {
|
|
|
|
// If we have exactly one array designator, this used the GNU
|
|
|
|
// 'designation: array-designator' extension, otherwise there should be no
|
|
|
|
// designators at all!
|
|
|
|
if (Desig.getNumDesignators() == 1 &&
|
|
|
|
(Desig.getDesignator(0).isArrayDesignator() ||
|
|
|
|
Desig.getDesignator(0).isArrayRangeDesignator()))
|
|
|
|
P.Diag(Loc, diag::ext_gnu_missing_equal_designator);
|
|
|
|
else if (Desig.getNumDesignators() > 0)
|
|
|
|
P.Diag(Loc, diag::err_expected_equal_designator);
|
|
|
|
}
|
|
|
|
|
2006-08-14 05:54:51 +08:00
|
|
|
/// ParseInitializerWithPotentialDesignator - Parse the 'initializer' production
|
|
|
|
/// checking to see if the token stream starts with a designator.
|
|
|
|
///
|
2006-08-14 05:54:02 +08:00
|
|
|
/// designation:
|
|
|
|
/// designator-list '='
|
|
|
|
/// [GNU] array-designator
|
|
|
|
/// [GNU] identifier ':'
|
|
|
|
///
|
|
|
|
/// designator-list:
|
|
|
|
/// designator
|
|
|
|
/// designator-list designator
|
|
|
|
///
|
|
|
|
/// designator:
|
|
|
|
/// array-designator
|
|
|
|
/// '.' identifier
|
|
|
|
///
|
|
|
|
/// array-designator:
|
|
|
|
/// '[' constant-expression ']'
|
|
|
|
/// [GNU] '[' constant-expression '...' constant-expression ']'
|
|
|
|
///
|
|
|
|
/// NOTE: [OBC] allows '[ objc-receiver objc-message-args ]' as an
|
2008-10-27 05:46:13 +08:00
|
|
|
/// initializer (because it is an expression). We need to consider this case
|
|
|
|
/// when parsing array designators.
|
2006-08-14 05:54:02 +08:00
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseInitializerWithPotentialDesignator() {
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2008-10-27 06:36:07 +08:00
|
|
|
// If this is the old-style GNU extension:
|
|
|
|
// designation ::= identifier ':'
|
|
|
|
// Handle it as a field designator. Otherwise, this must be the start of a
|
|
|
|
// normal expression.
|
|
|
|
if (Tok.is(tok::identifier)) {
|
2009-01-22 08:58:24 +08:00
|
|
|
const IdentifierInfo *FieldName = Tok.getIdentifierInfo();
|
2009-03-28 08:41:23 +08:00
|
|
|
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<256> NewSyntax;
|
2009-10-19 05:17:35 +08:00
|
|
|
llvm::raw_svector_ostream(NewSyntax) << '.' << FieldName->getName()
|
2009-10-18 07:52:50 +08:00
|
|
|
<< " = ";
|
2009-03-28 08:41:23 +08:00
|
|
|
|
2009-01-22 08:58:24 +08:00
|
|
|
SourceLocation NameLoc = ConsumeToken(); // Eat the identifier.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-27 06:49:49 +08:00
|
|
|
assert(Tok.is(tok::colon) && "MayBeDesignationStart not working properly!");
|
2009-01-22 08:58:24 +08:00
|
|
|
SourceLocation ColonLoc = ConsumeToken();
|
|
|
|
|
2011-08-27 08:13:16 +08:00
|
|
|
Diag(NameLoc, diag::ext_gnu_old_style_field_designator)
|
2010-04-01 01:46:05 +08:00
|
|
|
<< FixItHint::CreateReplacement(SourceRange(NameLoc, ColonLoc),
|
2015-03-18 18:17:07 +08:00
|
|
|
NewSyntax);
|
2009-03-28 08:41:23 +08:00
|
|
|
|
2009-03-21 07:11:49 +08:00
|
|
|
Designation D;
|
2009-01-22 08:58:24 +08:00
|
|
|
D.AddDesignator(Designator::getField(FieldName, SourceLocation(), NameLoc));
|
2009-09-09 23:08:12 +08:00
|
|
|
return Actions.ActOnDesignatedInitializer(D, ColonLoc, true,
|
2009-01-22 08:58:24 +08:00
|
|
|
ParseInitializer());
|
2008-10-27 06:36:07 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-27 06:59:19 +08:00
|
|
|
// Desig - This is initialized when we see our first designator. We may have
|
|
|
|
// an objc message send with no designator, so we don't want to create this
|
|
|
|
// eagerly.
|
2009-03-21 07:11:49 +08:00
|
|
|
Designation Desig;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-08-14 05:54:02 +08:00
|
|
|
// Parse each designator in the designator list until we find an initializer.
|
2008-10-27 06:49:49 +08:00
|
|
|
while (Tok.is(tok::period) || Tok.is(tok::l_square)) {
|
|
|
|
if (Tok.is(tok::period)) {
|
2006-08-14 05:54:02 +08:00
|
|
|
// designator: '.' identifier
|
2009-01-22 08:58:24 +08:00
|
|
|
SourceLocation DotLoc = ConsumeToken();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-27 06:59:19 +08:00
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
Diag(Tok.getLocation(), diag::err_expected_field_designator);
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2008-10-27 06:59:19 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-21 07:11:49 +08:00
|
|
|
Desig.AddDesignator(Designator::getField(Tok.getIdentifierInfo(), DotLoc,
|
|
|
|
Tok.getLocation()));
|
2008-10-27 06:59:19 +08:00
|
|
|
ConsumeToken(); // Eat the identifier.
|
2008-10-27 06:49:49 +08:00
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-27 06:49:49 +08:00
|
|
|
// We must have either an array designator now or an objc message send.
|
|
|
|
assert(Tok.is(tok::l_square) && "Unexpected token!");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-27 07:06:54 +08:00
|
|
|
// Handle the two forms of array designator:
|
|
|
|
// array-designator: '[' constant-expression ']'
|
|
|
|
// array-designator: '[' constant-expression '...' constant-expression ']'
|
|
|
|
//
|
|
|
|
// Also, we have to handle the case where the expression after the
|
|
|
|
// designator an an objc message send: '[' objc-message-expr ']'.
|
|
|
|
// Interesting cases are:
|
|
|
|
// [foo bar] -> objc message send
|
|
|
|
// [foo] -> array designator
|
|
|
|
// [foo ... bar] -> array designator
|
|
|
|
// [4][foo bar] -> obsolete GNU designation with objc message send.
|
|
|
|
//
|
2012-04-10 09:32:12 +08:00
|
|
|
// We do not need to check for an expression starting with [[ here. If it
|
|
|
|
// contains an Objective-C message send, then it is not an ill-formed
|
|
|
|
// attribute. If it is a lambda-expression within an array-designator, then
|
|
|
|
// it will be rejected because a constant-expression cannot begin with a
|
|
|
|
// lambda-expression.
|
2010-09-15 22:51:05 +08:00
|
|
|
InMessageExpressionRAIIObject InMessage(*this, true);
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_square);
|
|
|
|
T.consumeOpen();
|
|
|
|
SourceLocation StartLoc = T.getOpenLocation();
|
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Idx;
|
2010-04-22 06:36:40 +08:00
|
|
|
|
|
|
|
// If Objective-C is enabled and this is a typename (class message
|
|
|
|
// send) or send to 'super', parse this as a message send
|
|
|
|
// expression. We handle C++ and C separately, since C++ requires
|
|
|
|
// much more complicated parsing.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC1 && getLangOpts().CPlusPlus) {
|
2010-04-22 06:36:40 +08:00
|
|
|
// Send to 'super'.
|
|
|
|
if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super &&
|
2010-09-15 22:51:05 +08:00
|
|
|
NextToken().isNot(tok::period) &&
|
|
|
|
getCurScope()->isInObjcMethodScope()) {
|
2010-04-22 06:36:40 +08:00
|
|
|
CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
|
2016-01-16 07:43:34 +08:00
|
|
|
return ParseAssignmentExprWithObjCMessageExprStart(
|
|
|
|
StartLoc, ConsumeToken(), nullptr, nullptr);
|
2010-04-22 06:36:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the receiver, which is either a type or an expression.
|
|
|
|
bool IsExpr;
|
|
|
|
void *TypeOrExpr;
|
|
|
|
if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::r_square, StopAtSemi);
|
2010-04-22 06:36:40 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the receiver was a type, we have a class message; parse
|
|
|
|
// the rest of it.
|
|
|
|
if (!IsExpr) {
|
|
|
|
CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
|
|
|
|
return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
|
|
|
|
SourceLocation(),
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType::getFromOpaquePtr(TypeOrExpr),
|
2014-05-21 14:02:52 +08:00
|
|
|
nullptr);
|
2010-04-22 06:36:40 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-04-22 06:36:40 +08:00
|
|
|
// If the receiver was an expression, we still don't know
|
|
|
|
// whether we have a message send or an array designator; just
|
|
|
|
// adopt the expression for further analysis below.
|
|
|
|
// FIXME: potentially-potentially evaluated expression above?
|
2010-08-24 14:29:42 +08:00
|
|
|
Idx = ExprResult(static_cast<Expr*>(TypeOrExpr));
|
2012-03-11 15:00:24 +08:00
|
|
|
} else if (getLangOpts().ObjC1 && Tok.is(tok::identifier)) {
|
2010-04-11 16:28:14 +08:00
|
|
|
IdentifierInfo *II = Tok.getIdentifierInfo();
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
SourceLocation IILoc = Tok.getLocation();
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType ReceiverType;
|
2010-04-12 14:36:00 +08:00
|
|
|
// Three cases. This is a message send to a type: [type foo]
|
|
|
|
// This is a message send to super: [super foo]
|
|
|
|
// This is a message sent to an expr: [super.bar foo]
|
2015-07-07 21:21:26 +08:00
|
|
|
switch (Actions.getObjCMessageKind(
|
|
|
|
getCurScope(), II, IILoc, II == Ident_super,
|
|
|
|
NextToken().is(tok::period), ReceiverType)) {
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::ObjCSuperMessage:
|
Substitute type arguments into uses of Objective-C interface members.
When messaging a method that was defined in an Objective-C class (or
category or extension thereof) that has type parameters, substitute
the type arguments for those type parameters. Similarly, substitute
into property accesses, instance variables, and other references.
This includes general infrastructure for substituting the type
arguments associated with an ObjCObject(Pointer)Type into a type
referenced within a particular context, handling all of the
substitutions required to deal with (e.g.) inheritance involving
parameterized classes. In cases where no type arguments are available
(e.g., because we're messaging via some unspecialized type, id, etc.),
we substitute in the type bounds for the type parameters instead.
Example:
@interface NSSet<T : id<NSCopying>> : NSObject <NSCopying>
- (T)firstObject;
@end
void f(NSSet<NSString *> *stringSet, NSSet *anySet) {
[stringSet firstObject]; // produces NSString*
[anySet firstObject]; // produces id<NSCopying> (the bound)
}
When substituting for the type parameters given an unspecialized
context (i.e., no specific type arguments were given), substituting
the type bounds unconditionally produces type signatures that are too
strong compared to the pre-generics signatures. Instead, use the
following rule:
- In covariant positions, such as method return types, replace type
parameters with “id” or “Class” (the latter only when the type
parameter bound is “Class” or qualified class, e.g,
“Class<NSCopying>”)
- In other positions (e.g., parameter types), replace type
parameters with their type bounds.
- When a specialized Objective-C object or object pointer type
contains a type parameter in its type arguments (e.g.,
NSArray<T>*, but not NSArray<NSString *> *), replace the entire
object/object pointer type with its unspecialized version (e.g.,
NSArray *).
llvm-svn: 241543
2015-07-07 11:57:53 +08:00
|
|
|
CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
|
2016-01-16 07:43:34 +08:00
|
|
|
return ParseAssignmentExprWithObjCMessageExprStart(
|
|
|
|
StartLoc, ConsumeToken(), nullptr, nullptr);
|
Substitute type arguments into uses of Objective-C interface members.
When messaging a method that was defined in an Objective-C class (or
category or extension thereof) that has type parameters, substitute
the type arguments for those type parameters. Similarly, substitute
into property accesses, instance variables, and other references.
This includes general infrastructure for substituting the type
arguments associated with an ObjCObject(Pointer)Type into a type
referenced within a particular context, handling all of the
substitutions required to deal with (e.g.) inheritance involving
parameterized classes. In cases where no type arguments are available
(e.g., because we're messaging via some unspecialized type, id, etc.),
we substitute in the type bounds for the type parameters instead.
Example:
@interface NSSet<T : id<NSCopying>> : NSObject <NSCopying>
- (T)firstObject;
@end
void f(NSSet<NSString *> *stringSet, NSSet *anySet) {
[stringSet firstObject]; // produces NSString*
[anySet firstObject]; // produces id<NSCopying> (the bound)
}
When substituting for the type parameters given an unspecialized
context (i.e., no specific type arguments were given), substituting
the type bounds unconditionally produces type signatures that are too
strong compared to the pre-generics signatures. Instead, use the
following rule:
- In covariant positions, such as method return types, replace type
parameters with “id” or “Class” (the latter only when the type
parameter bound is “Class” or qualified class, e.g,
“Class<NSCopying>”)
- In other positions (e.g., parameter types), replace type
parameters with their type bounds.
- When a specialized Objective-C object or object pointer type
contains a type parameter in its type arguments (e.g.,
NSArray<T>*, but not NSArray<NSString *> *), replace the entire
object/object pointer type with its unspecialized version (e.g.,
NSArray *).
llvm-svn: 241543
2015-07-07 11:57:53 +08:00
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::ObjCClassMessage:
|
2010-04-22 06:36:40 +08:00
|
|
|
CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
|
2010-04-22 04:38:13 +08:00
|
|
|
ConsumeToken(); // the identifier
|
|
|
|
if (!ReceiverType) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::r_square, StopAtSemi);
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
Substitute type arguments into uses of Objective-C interface members.
When messaging a method that was defined in an Objective-C class (or
category or extension thereof) that has type parameters, substitute
the type arguments for those type parameters. Similarly, substitute
into property accesses, instance variables, and other references.
This includes general infrastructure for substituting the type
arguments associated with an ObjCObject(Pointer)Type into a type
referenced within a particular context, handling all of the
substitutions required to deal with (e.g.) inheritance involving
parameterized classes. In cases where no type arguments are available
(e.g., because we're messaging via some unspecialized type, id, etc.),
we substitute in the type bounds for the type parameters instead.
Example:
@interface NSSet<T : id<NSCopying>> : NSObject <NSCopying>
- (T)firstObject;
@end
void f(NSSet<NSString *> *stringSet, NSSet *anySet) {
[stringSet firstObject]; // produces NSString*
[anySet firstObject]; // produces id<NSCopying> (the bound)
}
When substituting for the type parameters given an unspecialized
context (i.e., no specific type arguments were given), substituting
the type bounds unconditionally produces type signatures that are too
strong compared to the pre-generics signatures. Instead, use the
following rule:
- In covariant positions, such as method return types, replace type
parameters with “id” or “Class” (the latter only when the type
parameter bound is “Class” or qualified class, e.g,
“Class<NSCopying>”)
- In other positions (e.g., parameter types), replace type
parameters with their type bounds.
- When a specialized Objective-C object or object pointer type
contains a type parameter in its type arguments (e.g.,
NSArray<T>*, but not NSArray<NSString *> *), replace the entire
object/object pointer type with its unspecialized version (e.g.,
NSArray *).
llvm-svn: 241543
2015-07-07 11:57:53 +08:00
|
|
|
// Parse type arguments and protocol qualifiers.
|
|
|
|
if (Tok.is(tok::less)) {
|
2015-07-07 11:58:14 +08:00
|
|
|
SourceLocation NewEndLoc;
|
Substitute type arguments into uses of Objective-C interface members.
When messaging a method that was defined in an Objective-C class (or
category or extension thereof) that has type parameters, substitute
the type arguments for those type parameters. Similarly, substitute
into property accesses, instance variables, and other references.
This includes general infrastructure for substituting the type
arguments associated with an ObjCObject(Pointer)Type into a type
referenced within a particular context, handling all of the
substitutions required to deal with (e.g.) inheritance involving
parameterized classes. In cases where no type arguments are available
(e.g., because we're messaging via some unspecialized type, id, etc.),
we substitute in the type bounds for the type parameters instead.
Example:
@interface NSSet<T : id<NSCopying>> : NSObject <NSCopying>
- (T)firstObject;
@end
void f(NSSet<NSString *> *stringSet, NSSet *anySet) {
[stringSet firstObject]; // produces NSString*
[anySet firstObject]; // produces id<NSCopying> (the bound)
}
When substituting for the type parameters given an unspecialized
context (i.e., no specific type arguments were given), substituting
the type bounds unconditionally produces type signatures that are too
strong compared to the pre-generics signatures. Instead, use the
following rule:
- In covariant positions, such as method return types, replace type
parameters with “id” or “Class” (the latter only when the type
parameter bound is “Class” or qualified class, e.g,
“Class<NSCopying>”)
- In other positions (e.g., parameter types), replace type
parameters with their type bounds.
- When a specialized Objective-C object or object pointer type
contains a type parameter in its type arguments (e.g.,
NSArray<T>*, but not NSArray<NSString *> *), replace the entire
object/object pointer type with its unspecialized version (e.g.,
NSArray *).
llvm-svn: 241543
2015-07-07 11:57:53 +08:00
|
|
|
TypeResult NewReceiverType
|
2015-07-07 11:58:14 +08:00
|
|
|
= parseObjCTypeArgsAndProtocolQualifiers(IILoc, ReceiverType,
|
|
|
|
/*consumeLastToken=*/true,
|
|
|
|
NewEndLoc);
|
Substitute type arguments into uses of Objective-C interface members.
When messaging a method that was defined in an Objective-C class (or
category or extension thereof) that has type parameters, substitute
the type arguments for those type parameters. Similarly, substitute
into property accesses, instance variables, and other references.
This includes general infrastructure for substituting the type
arguments associated with an ObjCObject(Pointer)Type into a type
referenced within a particular context, handling all of the
substitutions required to deal with (e.g.) inheritance involving
parameterized classes. In cases where no type arguments are available
(e.g., because we're messaging via some unspecialized type, id, etc.),
we substitute in the type bounds for the type parameters instead.
Example:
@interface NSSet<T : id<NSCopying>> : NSObject <NSCopying>
- (T)firstObject;
@end
void f(NSSet<NSString *> *stringSet, NSSet *anySet) {
[stringSet firstObject]; // produces NSString*
[anySet firstObject]; // produces id<NSCopying> (the bound)
}
When substituting for the type parameters given an unspecialized
context (i.e., no specific type arguments were given), substituting
the type bounds unconditionally produces type signatures that are too
strong compared to the pre-generics signatures. Instead, use the
following rule:
- In covariant positions, such as method return types, replace type
parameters with “id” or “Class” (the latter only when the type
parameter bound is “Class” or qualified class, e.g,
“Class<NSCopying>”)
- In other positions (e.g., parameter types), replace type
parameters with their type bounds.
- When a specialized Objective-C object or object pointer type
contains a type parameter in its type arguments (e.g.,
NSArray<T>*, but not NSArray<NSString *> *), replace the entire
object/object pointer type with its unspecialized version (e.g.,
NSArray *).
llvm-svn: 241543
2015-07-07 11:57:53 +08:00
|
|
|
if (!NewReceiverType.isUsable()) {
|
|
|
|
SkipUntil(tok::r_square, StopAtSemi);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
ReceiverType = NewReceiverType.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
SourceLocation(),
|
2010-04-22 04:38:13 +08:00
|
|
|
ReceiverType,
|
2014-05-21 14:02:52 +08:00
|
|
|
nullptr);
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::ObjCInstanceMessage:
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
// Fall through; we'll just parse the expression and
|
|
|
|
// (possibly) treat this like an Objective-C message send
|
|
|
|
// later.
|
|
|
|
break;
|
2010-04-11 16:28:14 +08:00
|
|
|
}
|
2008-10-27 06:49:49 +08:00
|
|
|
}
|
2008-12-13 23:32:12 +08:00
|
|
|
|
2010-04-22 06:36:40 +08:00
|
|
|
// Parse the index expression, if we haven't already gotten one
|
|
|
|
// above (which can only happen in Objective-C++).
|
2008-10-27 06:49:49 +08:00
|
|
|
// Note that we parse this as an assignment expression, not a constant
|
|
|
|
// expression (allowing *=, =, etc) to handle the objc case. Sema needs
|
|
|
|
// to validate that the expression is a constant.
|
2010-04-22 06:36:40 +08:00
|
|
|
// FIXME: We also need to tell Sema that we're in a
|
|
|
|
// potentially-potentially evaluated context.
|
|
|
|
if (!Idx.get()) {
|
|
|
|
Idx = ParseAssignmentExpression();
|
|
|
|
if (Idx.isInvalid()) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::r_square, StopAtSemi);
|
2012-08-24 05:35:17 +08:00
|
|
|
return Idx;
|
2010-04-22 06:36:40 +08:00
|
|
|
}
|
2008-10-27 06:49:49 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-27 06:49:49 +08:00
|
|
|
// Given an expression, we could either have a designator (if the next
|
|
|
|
// tokens are '...' or ']' or an objc message send. If this is an objc
|
2009-09-09 23:08:12 +08:00
|
|
|
// message send, handle it now. An objc-message send is the start of
|
2008-10-27 06:49:49 +08:00
|
|
|
// an assignment-expression production.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC1 && Tok.isNot(tok::ellipsis) &&
|
2008-10-27 06:49:49 +08:00
|
|
|
Tok.isNot(tok::r_square)) {
|
2010-04-22 06:36:40 +08:00
|
|
|
CheckArrayDesignatorSyntax(*this, Tok.getLocation(), Desig);
|
2016-01-16 07:43:34 +08:00
|
|
|
return ParseAssignmentExprWithObjCMessageExprStart(
|
|
|
|
StartLoc, SourceLocation(), nullptr, Idx.get());
|
2008-10-27 06:49:49 +08:00
|
|
|
}
|
2008-10-27 07:06:54 +08:00
|
|
|
|
|
|
|
// If this is a normal array designator, remember it.
|
|
|
|
if (Tok.isNot(tok::ellipsis)) {
|
2014-05-29 18:55:11 +08:00
|
|
|
Desig.AddDesignator(Designator::getArray(Idx.get(), StartLoc));
|
2008-10-27 07:06:54 +08:00
|
|
|
} else {
|
|
|
|
// Handle the gnu array range extension.
|
2008-10-27 06:49:49 +08:00
|
|
|
Diag(Tok, diag::ext_gnu_array_range);
|
2009-01-22 08:58:24 +08:00
|
|
|
SourceLocation EllipsisLoc = ConsumeToken();
|
2008-12-12 05:36:32 +08:00
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult RHS(ParseConstantExpression());
|
2008-12-09 21:15:23 +08:00
|
|
|
if (RHS.isInvalid()) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::r_square, StopAtSemi);
|
2012-08-24 05:35:17 +08:00
|
|
|
return RHS;
|
2008-01-26 03:43:26 +08:00
|
|
|
}
|
2014-05-29 18:55:11 +08:00
|
|
|
Desig.AddDesignator(Designator::getArrayRange(Idx.get(),
|
|
|
|
RHS.get(),
|
2009-03-21 07:11:49 +08:00
|
|
|
StartLoc, EllipsisLoc));
|
2006-08-14 05:54:02 +08:00
|
|
|
}
|
2008-12-09 21:15:23 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
T.consumeClose();
|
|
|
|
Desig.getDesignator(Desig.getNumDesignators() - 1).setRBracketLoc(
|
|
|
|
T.getCloseLocation());
|
2006-08-14 05:54:02 +08:00
|
|
|
}
|
2008-10-27 06:49:49 +08:00
|
|
|
|
2008-10-27 06:59:19 +08:00
|
|
|
// Okay, we're done with the designator sequence. We know that there must be
|
|
|
|
// at least one designator, because the only case we can get into this method
|
|
|
|
// without a designator is when we have an objc message send. That case is
|
|
|
|
// handled and returned from above.
|
2009-03-21 07:11:49 +08:00
|
|
|
assert(!Desig.empty() && "Designator is empty?");
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2008-10-27 06:59:19 +08:00
|
|
|
// Handle a normal designator sequence end, which is an equal.
|
2008-10-27 06:49:49 +08:00
|
|
|
if (Tok.is(tok::equal)) {
|
2009-01-22 08:58:24 +08:00
|
|
|
SourceLocation EqualLoc = ConsumeToken();
|
2009-03-21 07:11:49 +08:00
|
|
|
return Actions.ActOnDesignatedInitializer(Desig, EqualLoc, false,
|
2009-01-22 08:58:24 +08:00
|
|
|
ParseInitializer());
|
2008-10-27 06:49:49 +08:00
|
|
|
}
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2008-10-27 06:59:19 +08:00
|
|
|
// We read some number of designators and found something that isn't an = or
|
2008-10-27 07:22:23 +08:00
|
|
|
// an initializer. If we have exactly one array designator, this
|
2008-10-27 06:59:19 +08:00
|
|
|
// is the GNU 'designation: array-designator' extension. Otherwise, it is a
|
|
|
|
// parse error.
|
2009-09-09 23:08:12 +08:00
|
|
|
if (Desig.getNumDesignators() == 1 &&
|
2009-03-21 07:11:49 +08:00
|
|
|
(Desig.getDesignator(0).isArrayDesignator() ||
|
|
|
|
Desig.getDesignator(0).isArrayRangeDesignator())) {
|
2009-03-28 08:41:23 +08:00
|
|
|
Diag(Tok, diag::ext_gnu_missing_equal_designator)
|
2010-04-01 01:46:05 +08:00
|
|
|
<< FixItHint::CreateInsertion(Tok.getLocation(), "= ");
|
2009-03-28 08:41:23 +08:00
|
|
|
return Actions.ActOnDesignatedInitializer(Desig, Tok.getLocation(),
|
2009-03-28 07:40:29 +08:00
|
|
|
true, ParseInitializer());
|
2008-10-27 07:22:23 +08:00
|
|
|
}
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2008-10-27 07:22:23 +08:00
|
|
|
Diag(Tok, diag::err_expected_equal_designator);
|
2008-12-12 06:51:44 +08:00
|
|
|
return ExprError();
|
2006-08-14 05:54:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-27 06:38:55 +08:00
|
|
|
/// ParseBraceInitializer - Called when parsing an initializer that has a
|
|
|
|
/// leading open brace.
|
|
|
|
///
|
2006-08-14 05:54:02 +08:00
|
|
|
/// initializer: [C99 6.7.8]
|
|
|
|
/// '{' initializer-list '}'
|
|
|
|
/// '{' initializer-list ',' '}'
|
|
|
|
/// [GNU] '{' '}'
|
|
|
|
///
|
|
|
|
/// initializer-list:
|
2011-01-04 03:31:53 +08:00
|
|
|
/// designation[opt] initializer ...[opt]
|
|
|
|
/// initializer-list ',' designation[opt] initializer ...[opt]
|
2006-08-14 05:54:02 +08:00
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Parser::ParseBraceInitializer() {
|
2010-09-15 22:51:05 +08:00
|
|
|
InMessageExpressionRAIIObject InMessage(*this, false);
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_brace);
|
|
|
|
T.consumeOpen();
|
|
|
|
SourceLocation LBraceLoc = T.getOpenLocation();
|
2008-11-26 06:21:31 +08:00
|
|
|
|
2008-10-27 06:36:07 +08:00
|
|
|
/// InitExprs - This is the actual list of expressions contained in the
|
|
|
|
/// initializer.
|
2012-08-24 06:51:59 +08:00
|
|
|
ExprVector InitExprs;
|
2008-11-26 06:21:31 +08:00
|
|
|
|
2008-10-27 07:35:51 +08:00
|
|
|
if (Tok.is(tok::r_brace)) {
|
2009-01-31 06:09:00 +08:00
|
|
|
// Empty initializers are a C++ feature and a GNU extension to C.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!getLangOpts().CPlusPlus)
|
2009-01-31 06:09:00 +08:00
|
|
|
Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
|
2008-10-27 07:35:51 +08:00
|
|
|
// Match the '}'.
|
2013-05-06 04:40:26 +08:00
|
|
|
return Actions.ActOnInitList(LBraceLoc, None, ConsumeBrace());
|
2008-10-27 07:35:51 +08:00
|
|
|
}
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2007-07-19 09:06:55 +08:00
|
|
|
bool InitExprsOk = true;
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2007-07-19 09:06:55 +08:00
|
|
|
while (1) {
|
2011-12-13 07:24:39 +08:00
|
|
|
// Handle Microsoft __if_exists/if_not_exists if necessary.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().MicrosoftExt && (Tok.is(tok::kw___if_exists) ||
|
2011-12-13 07:24:39 +08:00
|
|
|
Tok.is(tok::kw___if_not_exists))) {
|
|
|
|
if (ParseMicrosoftIfExistsBraceInitializer(InitExprs, InitExprsOk)) {
|
|
|
|
if (Tok.isNot(tok::comma)) break;
|
|
|
|
ConsumeToken();
|
|
|
|
}
|
|
|
|
if (Tok.is(tok::r_brace)) break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-07-19 09:06:55 +08:00
|
|
|
// Parse: designation[opt] initializer
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2007-07-19 09:06:55 +08:00
|
|
|
// If we know that this cannot be a designation, just parse the nested
|
|
|
|
// initializer directly.
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult SubElt;
|
2012-02-17 11:49:44 +08:00
|
|
|
if (MayBeDesignationStart())
|
2009-03-21 07:11:49 +08:00
|
|
|
SubElt = ParseInitializerWithPotentialDesignator();
|
|
|
|
else
|
2007-07-19 09:06:55 +08:00
|
|
|
SubElt = ParseInitializer();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-01-04 03:31:53 +08:00
|
|
|
if (Tok.is(tok::ellipsis))
|
|
|
|
SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken());
|
2014-11-22 02:48:04 +08:00
|
|
|
|
|
|
|
SubElt = Actions.CorrectDelayedTyposInExpr(SubElt.get());
|
|
|
|
|
2007-07-19 09:06:55 +08:00
|
|
|
// If we couldn't parse the subelement, bail out.
|
2014-11-22 02:48:04 +08:00
|
|
|
if (SubElt.isUsable()) {
|
2014-05-29 18:55:11 +08:00
|
|
|
InitExprs.push_back(SubElt.get());
|
2008-04-21 03:07:56 +08:00
|
|
|
} else {
|
|
|
|
InitExprsOk = false;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-04-21 03:07:56 +08:00
|
|
|
// We have two ways to try to recover from this error: if the code looks
|
2011-04-15 13:22:18 +08:00
|
|
|
// grammatically ok (i.e. we have a comma coming up) try to continue
|
2008-04-21 03:07:56 +08:00
|
|
|
// parsing the rest of the initializer. This allows us to emit
|
|
|
|
// diagnostics for later elements that we find. If we don't see a comma,
|
|
|
|
// assume there is a parse error, and just skip to recover.
|
2008-11-26 06:21:31 +08:00
|
|
|
// FIXME: This comment doesn't sound right. If there is a r_brace
|
|
|
|
// immediately, it can't be an error, since there is no other way of
|
|
|
|
// leaving this loop except through this if.
|
2008-04-21 03:07:56 +08:00
|
|
|
if (Tok.isNot(tok::comma)) {
|
2013-11-18 16:17:37 +08:00
|
|
|
SkipUntil(tok::r_brace, StopBeforeMatch);
|
2008-04-21 03:07:56 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-09 21:15:23 +08:00
|
|
|
|
2007-07-19 09:06:55 +08:00
|
|
|
// If we don't have a comma continued list, we're done.
|
2007-10-10 01:33:22 +08:00
|
|
|
if (Tok.isNot(tok::comma)) break;
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2008-10-27 06:36:07 +08:00
|
|
|
// TODO: save comma locations if some client cares.
|
2007-07-19 09:06:55 +08:00
|
|
|
ConsumeToken();
|
2008-12-12 06:51:44 +08:00
|
|
|
|
2007-07-19 09:06:55 +08:00
|
|
|
// Handle trailing comma.
|
2007-10-10 01:33:22 +08:00
|
|
|
if (Tok.is(tok::r_brace)) break;
|
2006-08-14 05:54:02 +08:00
|
|
|
}
|
2011-10-13 00:37:45 +08:00
|
|
|
|
|
|
|
bool closed = !T.consumeClose();
|
|
|
|
|
|
|
|
if (InitExprsOk && closed)
|
2012-08-24 05:35:17 +08:00
|
|
|
return Actions.ActOnInitList(LBraceLoc, InitExprs,
|
2011-10-13 00:37:45 +08:00
|
|
|
T.getCloseLocation());
|
2008-12-12 06:51:44 +08:00
|
|
|
|
|
|
|
return ExprError(); // an error occurred.
|
2006-08-14 05:54:02 +08:00
|
|
|
}
|
|
|
|
|
2011-12-13 07:24:39 +08:00
|
|
|
|
|
|
|
// Return true if a comma (or closing brace) is necessary after the
|
|
|
|
// __if_exists/if_not_exists statement.
|
|
|
|
bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
|
|
|
|
bool &InitExprsOk) {
|
|
|
|
bool trailingComma = false;
|
|
|
|
IfExistsCondition Result;
|
|
|
|
if (ParseMicrosoftIfExistsCondition(Result))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
BalancedDelimiterTracker Braces(*this, tok::l_brace);
|
|
|
|
if (Braces.consumeOpen()) {
|
2013-12-24 17:48:30 +08:00
|
|
|
Diag(Tok, diag::err_expected) << tok::l_brace;
|
2011-12-13 07:24:39 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Result.Behavior) {
|
|
|
|
case IEB_Parse:
|
|
|
|
// Parse the declarations below.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IEB_Dependent:
|
|
|
|
Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
|
|
|
|
<< Result.IsIfExists;
|
|
|
|
// Fall through to skip.
|
|
|
|
|
|
|
|
case IEB_Skip:
|
|
|
|
Braces.skipToEnd();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-23 12:06:09 +08:00
|
|
|
while (!isEofOrEom()) {
|
2011-12-13 07:24:39 +08:00
|
|
|
trailingComma = false;
|
|
|
|
// If we know that this cannot be a designation, just parse the nested
|
|
|
|
// initializer directly.
|
|
|
|
ExprResult SubElt;
|
2012-02-17 11:49:44 +08:00
|
|
|
if (MayBeDesignationStart())
|
2011-12-13 07:24:39 +08:00
|
|
|
SubElt = ParseInitializerWithPotentialDesignator();
|
|
|
|
else
|
|
|
|
SubElt = ParseInitializer();
|
|
|
|
|
|
|
|
if (Tok.is(tok::ellipsis))
|
|
|
|
SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken());
|
|
|
|
|
|
|
|
// If we couldn't parse the subelement, bail out.
|
|
|
|
if (!SubElt.isInvalid())
|
2014-05-29 18:55:11 +08:00
|
|
|
InitExprs.push_back(SubElt.get());
|
2011-12-13 07:24:39 +08:00
|
|
|
else
|
|
|
|
InitExprsOk = false;
|
|
|
|
|
|
|
|
if (Tok.is(tok::comma)) {
|
|
|
|
ConsumeToken();
|
|
|
|
trailingComma = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.is(tok::r_brace))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Braces.consumeClose();
|
|
|
|
|
|
|
|
return !trailingComma;
|
|
|
|
}
|