blob: f4487c1d9d497230a7cc360555f847e19f598163 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Parser.h - C Language Parser ---------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the Parser interface.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_PARSE_PARSER_H
15#define LLVM_CLANG_PARSE_PARSER_H
16
Alexey Bataevc6400582013-03-22 06:34:35 +000017#include "clang/Basic/OpenMPKinds.h"
Daniel Jasper90961022012-12-20 20:25:19 +000018#include "clang/Basic/OperatorPrecedence.h"
John McCallad2b8042010-01-18 23:21:37 +000019#include "clang/Basic/Specifiers.h"
Douglas Gregorf44e8542010-08-24 19:08:16 +000020#include "clang/Lex/CodeCompletionHandler.h"
Chandler Carruth30a2e162012-12-04 09:18:49 +000021#include "clang/Lex/Preprocessor.h"
John McCall19510852010-08-20 18:27:03 +000022#include "clang/Sema/DeclSpec.h"
Stephen Hinesc568f1e2014-07-21 00:47:37 -070023#include "clang/Sema/LoopHint.h"
Chandler Carruth30a2e162012-12-04 09:18:49 +000024#include "clang/Sema/Sema.h"
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +000025#include "llvm/ADT/SmallVector.h"
Daniel Dunbaraa49a7d2012-03-09 19:35:29 +000026#include "llvm/Support/Compiler.h"
27#include "llvm/Support/PrettyStackTrace.h"
Jordan Rose94f29f42012-07-09 16:54:53 +000028#include "llvm/Support/SaveAndRestore.h"
Stephen Hines651f13c2014-04-23 16:59:28 -070029#include <memory>
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +000030#include <stack>
Reid Spencer5f016e22007-07-11 17:01:13 +000031
32namespace clang {
Daniel Dunbarfcdd8fe2008-10-04 19:21:03 +000033 class PragmaHandler;
Reid Spencer5f016e22007-07-11 17:01:13 +000034 class Scope;
Douglas Gregorc86c40b2012-06-06 21:18:07 +000035 class BalancedDelimiterTracker;
Richard Smith05766812012-08-18 00:55:03 +000036 class CorrectionCandidateCallback;
John McCall2b5289b2010-08-23 07:28:44 +000037 class DeclGroupRef;
Chris Lattner3cbfe2c2008-11-22 00:59:29 +000038 class DiagnosticBuilder;
Chris Lattner0102c302009-03-05 07:24:28 +000039 class Parser;
John McCall92576642012-05-07 06:16:41 +000040 class ParsingDeclRAIIObject;
41 class ParsingDeclSpec;
42 class ParsingDeclarator;
Eli Friedmanf66a0dd2012-08-08 23:04:35 +000043 class ParsingFieldDeclarator;
Chris Lattner08d92ec2009-12-10 00:32:41 +000044 class ColonProtectionRAIIObject;
Douglas Gregor0fbda682010-09-15 14:51:05 +000045 class InMessageExpressionRAIIObject;
John Wiegley28bbe4b2011-04-28 01:08:34 +000046 class PoisonSEHIdentifiersRAIIObject;
Douglas Gregor0a0d2b12011-03-23 00:50:03 +000047 class VersionTuple;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +000048 class OMPClause;
David Blaikiea8fbc052011-11-09 05:30:24 +000049
Reid Spencer5f016e22007-07-11 17:01:13 +000050/// Parser - This implements a parser for the C family of languages. After
51/// parsing units of the grammar, productions are invoked to handle whatever has
52/// been read.
53///
Douglas Gregorf44e8542010-08-24 19:08:16 +000054class Parser : public CodeCompletionHandler {
Chris Lattner08d92ec2009-12-10 00:32:41 +000055 friend class ColonProtectionRAIIObject;
Douglas Gregor0fbda682010-09-15 14:51:05 +000056 friend class InMessageExpressionRAIIObject;
John Wiegley28bbe4b2011-04-28 01:08:34 +000057 friend class PoisonSEHIdentifiersRAIIObject;
Jordan Rose94f29f42012-07-09 16:54:53 +000058 friend class ObjCDeclContextSwitch;
Argyrios Kyrtzidis36d36802010-06-17 10:52:18 +000059 friend class ParenBraceBracketBalancer;
Douglas Gregorc86c40b2012-06-06 21:18:07 +000060 friend class BalancedDelimiterTracker;
Mike Stump1eb44332009-09-09 15:08:12 +000061
Reid Spencer5f016e22007-07-11 17:01:13 +000062 Preprocessor &PP;
Mike Stump1eb44332009-09-09 15:08:12 +000063
Eric Christopher97d02052008-04-10 05:23:15 +000064 /// Tok - The current token we are peeking ahead. All parsing methods assume
Reid Spencer5f016e22007-07-11 17:01:13 +000065 /// that this is valid.
Chris Lattnerd2177732007-07-20 16:59:19 +000066 Token Tok;
Mike Stump1eb44332009-09-09 15:08:12 +000067
Douglas Gregor4b2d3f72009-02-26 21:00:50 +000068 // PrevTokLocation - The location of the token we previously
69 // consumed. This token is used for diagnostics where we expected to
70 // see a token following another token (e.g., the ';' at the end of
71 // a statement).
72 SourceLocation PrevTokLocation;
73
Reid Spencer5f016e22007-07-11 17:01:13 +000074 unsigned short ParenCount, BracketCount, BraceCount;
Stephen Hines651f13c2014-04-23 16:59:28 -070075
Reid Spencer5f016e22007-07-11 17:01:13 +000076 /// Actions - These are the callbacks we invoke as we parse various constructs
David Blaikiea8fbc052011-11-09 05:30:24 +000077 /// in the file.
John McCallf312b1e2010-08-26 23:41:50 +000078 Sema &Actions;
Mike Stump1eb44332009-09-09 15:08:12 +000079
David Blaikied6471f72011-09-25 23:23:43 +000080 DiagnosticsEngine &Diags;
Mike Stump1eb44332009-09-09 15:08:12 +000081
Chris Lattner9e344c62007-07-15 00:04:39 +000082 /// ScopeCache - Cache scopes to reduce malloc traffic.
83 enum { ScopeCacheSize = 16 };
84 unsigned NumCachedScopes;
85 Scope *ScopeCache[ScopeCacheSize];
Daniel Dunbar662e8b52008-08-14 22:04:54 +000086
John Wiegley28bbe4b2011-04-28 01:08:34 +000087 /// Identifiers used for SEH handling in Borland. These are only
88 /// allowed in particular circumstances
David Blaikiea8fbc052011-11-09 05:30:24 +000089 // __except block
90 IdentifierInfo *Ident__exception_code,
91 *Ident___exception_code,
92 *Ident_GetExceptionCode;
93 // __except filter expression
94 IdentifierInfo *Ident__exception_info,
95 *Ident___exception_info,
96 *Ident_GetExceptionInfo;
97 // __finally
98 IdentifierInfo *Ident__abnormal_termination,
99 *Ident___abnormal_termination,
100 *Ident_AbnormalTermination;
John Wiegley28bbe4b2011-04-28 01:08:34 +0000101
Douglas Gregorb57791e2011-10-21 03:57:52 +0000102 /// Contextual keywords for Microsoft extensions.
103 IdentifierInfo *Ident__except;
David Majnemer7121bdb2013-10-18 00:33:31 +0000104 mutable IdentifierInfo *Ident_sealed;
David Blaikiea8fbc052011-11-09 05:30:24 +0000105
Daniel Dunbar662e8b52008-08-14 22:04:54 +0000106 /// Ident_super - IdentifierInfo for "super", to support fast
107 /// comparison.
108 IdentifierInfo *Ident_super;
Bill Schmidt3e3d20b2013-07-03 20:54:09 +0000109 /// Ident_vector, Ident_pixel, Ident_bool - cached IdentifierInfo's
110 /// for "vector", "pixel", and "bool" fast comparison. Only present
111 /// if AltiVec enabled.
John Thompson82287d12010-02-05 00:12:22 +0000112 IdentifierInfo *Ident_vector;
113 IdentifierInfo *Ident_pixel;
Bill Schmidt3e3d20b2013-07-03 20:54:09 +0000114 IdentifierInfo *Ident_bool;
Daniel Dunbar662e8b52008-08-14 22:04:54 +0000115
Douglas Gregore97179c2011-09-08 01:46:34 +0000116 /// Objective-C contextual keywords.
117 mutable IdentifierInfo *Ident_instancetype;
David Blaikiea8fbc052011-11-09 05:30:24 +0000118
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000119 /// \brief Identifier for "introduced".
120 IdentifierInfo *Ident_introduced;
121
122 /// \brief Identifier for "deprecated".
123 IdentifierInfo *Ident_deprecated;
124
125 /// \brief Identifier for "obsoleted".
126 IdentifierInfo *Ident_obsoleted;
127
Douglas Gregorb53e4172011-03-26 03:35:55 +0000128 /// \brief Identifier for "unavailable".
129 IdentifierInfo *Ident_unavailable;
Fariborz Jahanian006e42f2011-12-10 00:28:41 +0000130
131 /// \brief Identifier for "message".
132 IdentifierInfo *Ident_message;
Douglas Gregorb53e4172011-03-26 03:35:55 +0000133
David Blaikiea8fbc052011-11-09 05:30:24 +0000134 /// C++0x contextual keywords.
Anders Carlsson7eeb4ec2011-01-20 03:47:08 +0000135 mutable IdentifierInfo *Ident_final;
136 mutable IdentifierInfo *Ident_override;
Anders Carlsson1f3b6fd2011-01-16 23:56:42 +0000137
Stephen Hines176edba2014-12-01 14:53:08 -0800138 // C++ type trait keywords that can be reverted to identifiers and still be
139 // used as type traits.
140 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
Douglas Gregord2959702012-08-30 20:04:43 +0000141
Stephen Hines651f13c2014-04-23 16:59:28 -0700142 std::unique_ptr<PragmaHandler> AlignHandler;
143 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
144 std::unique_ptr<PragmaHandler> OptionsHandler;
145 std::unique_ptr<PragmaHandler> PackHandler;
146 std::unique_ptr<PragmaHandler> MSStructHandler;
147 std::unique_ptr<PragmaHandler> UnusedHandler;
148 std::unique_ptr<PragmaHandler> WeakHandler;
149 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
150 std::unique_ptr<PragmaHandler> FPContractHandler;
151 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
152 std::unique_ptr<PragmaHandler> OpenMPHandler;
153 std::unique_ptr<PragmaHandler> MSCommentHandler;
154 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
155 std::unique_ptr<PragmaHandler> MSPointersToMembers;
156 std::unique_ptr<PragmaHandler> MSVtorDisp;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700157 std::unique_ptr<PragmaHandler> MSInitSeg;
158 std::unique_ptr<PragmaHandler> MSDataSeg;
159 std::unique_ptr<PragmaHandler> MSBSSSeg;
160 std::unique_ptr<PragmaHandler> MSConstSeg;
161 std::unique_ptr<PragmaHandler> MSCodeSeg;
162 std::unique_ptr<PragmaHandler> MSSection;
163 std::unique_ptr<PragmaHandler> OptimizeHandler;
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700164 std::unique_ptr<PragmaHandler> LoopHintHandler;
Stephen Hines176edba2014-12-01 14:53:08 -0800165 std::unique_ptr<PragmaHandler> UnrollHintHandler;
166 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
Stephen Hines651f13c2014-04-23 16:59:28 -0700167
168 std::unique_ptr<CommentHandler> CommentSemaHandler;
Mike Stump1eb44332009-09-09 15:08:12 +0000169
Douglas Gregor55f6b142009-02-09 18:46:07 +0000170 /// Whether the '>' token acts as an operator or not. This will be
171 /// true except when we are parsing an expression within a C++
172 /// template argument list, where the '>' closes the template
173 /// argument list.
174 bool GreaterThanIsOperator;
David Blaikiea8fbc052011-11-09 05:30:24 +0000175
Chris Lattner08d92ec2009-12-10 00:32:41 +0000176 /// ColonIsSacred - When this is false, we aggressively try to recover from
177 /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not
178 /// safe in case statements and a few other things. This is managed by the
179 /// ColonProtectionRAIIObject RAII object.
180 bool ColonIsSacred;
Douglas Gregor55f6b142009-02-09 18:46:07 +0000181
Stephen Hines651f13c2014-04-23 16:59:28 -0700182 /// \brief When true, we are directly inside an Objective-C message
Douglas Gregor0fbda682010-09-15 14:51:05 +0000183 /// send expression.
184 ///
185 /// This is managed by the \c InMessageExpressionRAIIObject class, and
186 /// should not be set directly.
187 bool InMessageExpression;
David Blaikiea8fbc052011-11-09 05:30:24 +0000188
Douglas Gregorc3058332009-08-24 23:03:25 +0000189 /// The "depth" of the template parameters currently being parsed.
190 unsigned TemplateParameterDepth;
David Blaikiea8fbc052011-11-09 05:30:24 +0000191
Richard Smith098b8142013-04-29 11:55:38 +0000192 /// \brief RAII class that manages the template parameter depth.
193 class TemplateParameterDepthRAII {
194 unsigned &Depth;
195 unsigned AddedLevels;
196 public:
197 explicit TemplateParameterDepthRAII(unsigned &Depth)
198 : Depth(Depth), AddedLevels(0) {}
199
200 ~TemplateParameterDepthRAII() {
201 Depth -= AddedLevels;
202 }
203
204 void operator++() {
205 ++Depth;
206 ++AddedLevels;
207 }
Stephen Hines651f13c2014-04-23 16:59:28 -0700208 void addDepth(unsigned D) {
209 Depth += D;
210 AddedLevels += D;
211 }
Richard Smith098b8142013-04-29 11:55:38 +0000212 unsigned getDepth() const { return Depth; }
213 };
214
Ted Kremenek8113ecf2010-11-10 05:59:39 +0000215 /// Factory object for creating AttributeList objects.
John McCall0b7e6782011-03-24 11:26:52 +0000216 AttributeFactory AttrFactory;
Mike Stump1eb44332009-09-09 15:08:12 +0000217
Benjamin Kramer13bb7012012-04-14 12:14:03 +0000218 /// \brief Gathers and cleans up TemplateIdAnnotations when parsing of a
219 /// top-level declaration is finished.
220 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
Argyrios Kyrtzidis25a76762011-06-22 06:09:49 +0000221
Richard Smith05766812012-08-18 00:55:03 +0000222 /// \brief Identifiers which have been declared within a tentative parse.
223 SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
224
Douglas Gregorb57791e2011-10-21 03:57:52 +0000225 IdentifierInfo *getSEHExceptKeyword();
David Blaikiea8fbc052011-11-09 05:30:24 +0000226
Jordan Rose94f29f42012-07-09 16:54:53 +0000227 /// True if we are within an Objective-C container while parsing C-like decls.
228 ///
229 /// This is necessary because Sema thinks we have left the container
230 /// to parse the C-like decls, meaning Actions.getObjCDeclContext() will
231 /// be NULL.
232 bool ParsingInObjCContainer;
233
Erik Verbruggen6a91d382012-04-12 10:11:59 +0000234 bool SkipFunctionBodies;
235
Reid Spencer5f016e22007-07-11 17:01:13 +0000236public:
Erik Verbruggen6a91d382012-04-12 10:11:59 +0000237 Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies);
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700238 ~Parser() override;
Reid Spencer5f016e22007-07-11 17:01:13 +0000239
David Blaikie4e4d0842012-03-11 07:00:24 +0000240 const LangOptions &getLangOpts() const { return PP.getLangOpts(); }
Daniel Dunbar444be732009-11-13 05:51:54 +0000241 const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
Chris Lattner0102c302009-03-05 07:24:28 +0000242 Preprocessor &getPreprocessor() const { return PP; }
John McCallf312b1e2010-08-26 23:41:50 +0000243 Sema &getActions() const { return Actions; }
John McCall92576642012-05-07 06:16:41 +0000244 AttributeFactory &getAttrFactory() { return AttrFactory; }
Mike Stump1eb44332009-09-09 15:08:12 +0000245
Chris Lattner0102c302009-03-05 07:24:28 +0000246 const Token &getCurToken() const { return Tok; }
Douglas Gregor23c94db2010-07-02 17:43:08 +0000247 Scope *getCurScope() const { return Actions.getCurScope(); }
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700248 void incrementMSManglingNumber() const {
249 return Actions.incrementMSManglingNumber();
Stephen Hines651f13c2014-04-23 16:59:28 -0700250 }
David Blaikiea8fbc052011-11-09 05:30:24 +0000251
Fariborz Jahaniana28948f2011-08-22 15:54:49 +0000252 Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); }
David Blaikiea8fbc052011-11-09 05:30:24 +0000253
Reid Spencer5f016e22007-07-11 17:01:13 +0000254 // Type forwarding. All of these are statically 'void*', but they may all be
255 // different actual classes based on the actions in place.
John McCall2b5289b2010-08-23 07:28:44 +0000256 typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
John McCall2b5289b2010-08-23 07:28:44 +0000257 typedef OpaquePtr<TemplateName> TemplateTy;
Douglas Gregor7ad83902008-11-05 04:29:56 +0000258
Chris Lattner686775d2011-07-20 06:58:45 +0000259 typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists;
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +0000260
John McCallf312b1e2010-08-26 23:41:50 +0000261 typedef Sema::FullExprArg FullExprArg;
Sebastian Redl1d922962008-12-13 15:32:12 +0000262
Reid Spencer5f016e22007-07-11 17:01:13 +0000263 // Parsing methods.
Mike Stump1eb44332009-09-09 15:08:12 +0000264
Reid Spencer5f016e22007-07-11 17:01:13 +0000265 /// Initialize - Warm up the parser.
266 ///
267 void Initialize();
Mike Stump1eb44332009-09-09 15:08:12 +0000268
269 /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
Steve Naroff1f644322007-11-28 22:54:11 +0000270 /// the EOF was encountered.
Chris Lattner682bf922009-03-29 16:50:03 +0000271 bool ParseTopLevelDecl(DeclGroupPtrTy &Result);
Stephen Hines651f13c2014-04-23 16:59:28 -0700272 bool ParseTopLevelDecl() {
273 DeclGroupPtrTy Result;
274 return ParseTopLevelDecl(Result);
275 }
Mike Stump1eb44332009-09-09 15:08:12 +0000276
Axel Naumann6944e202012-09-17 13:14:34 +0000277 /// ConsumeToken - Consume the current 'peek token' and lex the next one.
Stephen Hines651f13c2014-04-23 16:59:28 -0700278 /// This does not work with special tokens: string literals, code completion
279 /// and balanced tokens must be handled using the specific consume methods.
280 /// Returns the location of the consumed token.
281 SourceLocation ConsumeToken() {
282 assert(!isTokenSpecial() &&
Axel Naumann6944e202012-09-17 13:14:34 +0000283 "Should consume special tokens with Consume*Token");
Axel Naumann6944e202012-09-17 13:14:34 +0000284 PrevTokLocation = Tok.getLocation();
285 PP.Lex(Tok);
286 return PrevTokLocation;
287 }
288
Stephen Hines651f13c2014-04-23 16:59:28 -0700289 bool TryConsumeToken(tok::TokenKind Expected) {
290 if (Tok.isNot(Expected))
291 return false;
292 assert(!isTokenSpecial() &&
293 "Should consume special tokens with Consume*Token");
294 PrevTokLocation = Tok.getLocation();
295 PP.Lex(Tok);
296 return true;
297 }
298
299 bool TryConsumeToken(tok::TokenKind Expected, SourceLocation &Loc) {
300 if (!TryConsumeToken(Expected))
301 return false;
302 Loc = PrevTokLocation;
303 return true;
304 }
305
Reid Spencer5f016e22007-07-11 17:01:13 +0000306private:
307 //===--------------------------------------------------------------------===//
308 // Low-Level token peeking and consumption methods.
309 //
Mike Stump1eb44332009-09-09 15:08:12 +0000310
Reid Spencer5f016e22007-07-11 17:01:13 +0000311 /// isTokenParen - Return true if the cur token is '(' or ')'.
312 bool isTokenParen() const {
313 return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren;
314 }
315 /// isTokenBracket - Return true if the cur token is '[' or ']'.
316 bool isTokenBracket() const {
317 return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square;
318 }
319 /// isTokenBrace - Return true if the cur token is '{' or '}'.
320 bool isTokenBrace() const {
321 return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace;
322 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000323 /// isTokenStringLiteral - True if this token is a string-literal.
Reid Spencer5f016e22007-07-11 17:01:13 +0000324 bool isTokenStringLiteral() const {
Richard Smith0b91cc42013-03-09 23:30:15 +0000325 return tok::isStringLiteral(Tok.getKind());
Reid Spencer5f016e22007-07-11 17:01:13 +0000326 }
Stephen Hines651f13c2014-04-23 16:59:28 -0700327 /// isTokenSpecial - True if this token requires special consumption methods.
328 bool isTokenSpecial() const {
329 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
330 isTokenBrace() || Tok.is(tok::code_completion);
331 }
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000332
Richard Trieufcaf27e2012-01-19 22:01:51 +0000333 /// \brief Returns true if the current token is '=' or is a type of '='.
334 /// For typos, give a fixit to '='
335 bool isTokenEqualOrEqualTypo();
Argyrios Kyrtzidisa6eb5f82010-10-08 02:39:23 +0000336
Stephen Hines176edba2014-12-01 14:53:08 -0800337 /// \brief Return the current token to the token stream and make the given
338 /// token the current token.
339 void UnconsumeToken(Token &Consumed) {
340 Token Next = Tok;
341 PP.EnterToken(Consumed);
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700342 PP.Lex(Tok);
Stephen Hines176edba2014-12-01 14:53:08 -0800343 PP.EnterToken(Next);
344 }
345
Reid Spencer5f016e22007-07-11 17:01:13 +0000346 /// ConsumeAnyToken - Dispatch to the right Consume* method based on the
347 /// current token type. This should only be used in cases where the type of
348 /// the token really isn't known, e.g. in error recovery.
Argyrios Kyrtzidisab2d09b2013-03-27 23:58:17 +0000349 SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok = false) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000350 if (isTokenParen())
351 return ConsumeParen();
Stephen Hines651f13c2014-04-23 16:59:28 -0700352 if (isTokenBracket())
Reid Spencer5f016e22007-07-11 17:01:13 +0000353 return ConsumeBracket();
Stephen Hines651f13c2014-04-23 16:59:28 -0700354 if (isTokenBrace())
Reid Spencer5f016e22007-07-11 17:01:13 +0000355 return ConsumeBrace();
Stephen Hines651f13c2014-04-23 16:59:28 -0700356 if (isTokenStringLiteral())
Steve Naroffd62701b2008-02-07 03:50:06 +0000357 return ConsumeStringToken();
Stephen Hines651f13c2014-04-23 16:59:28 -0700358 if (Tok.is(tok::code_completion))
359 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
360 : handleUnexpectedCodeCompletionToken();
361 return ConsumeToken();
Reid Spencer5f016e22007-07-11 17:01:13 +0000362 }
Mike Stump1eb44332009-09-09 15:08:12 +0000363
Reid Spencer5f016e22007-07-11 17:01:13 +0000364 /// ConsumeParen - This consume method keeps the paren count up-to-date.
365 ///
366 SourceLocation ConsumeParen() {
367 assert(isTokenParen() && "wrong consume method");
368 if (Tok.getKind() == tok::l_paren)
369 ++ParenCount;
370 else if (ParenCount)
371 --ParenCount; // Don't let unbalanced )'s drive the count negative.
Douglas Gregor4b2d3f72009-02-26 21:00:50 +0000372 PrevTokLocation = Tok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000373 PP.Lex(Tok);
Douglas Gregor4b2d3f72009-02-26 21:00:50 +0000374 return PrevTokLocation;
Reid Spencer5f016e22007-07-11 17:01:13 +0000375 }
Mike Stump1eb44332009-09-09 15:08:12 +0000376
Reid Spencer5f016e22007-07-11 17:01:13 +0000377 /// ConsumeBracket - This consume method keeps the bracket count up-to-date.
378 ///
379 SourceLocation ConsumeBracket() {
380 assert(isTokenBracket() && "wrong consume method");
381 if (Tok.getKind() == tok::l_square)
382 ++BracketCount;
383 else if (BracketCount)
384 --BracketCount; // Don't let unbalanced ]'s drive the count negative.
Mike Stump1eb44332009-09-09 15:08:12 +0000385
Douglas Gregor4b2d3f72009-02-26 21:00:50 +0000386 PrevTokLocation = Tok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000387 PP.Lex(Tok);
Douglas Gregor4b2d3f72009-02-26 21:00:50 +0000388 return PrevTokLocation;
Reid Spencer5f016e22007-07-11 17:01:13 +0000389 }
Mike Stump1eb44332009-09-09 15:08:12 +0000390
Reid Spencer5f016e22007-07-11 17:01:13 +0000391 /// ConsumeBrace - This consume method keeps the brace count up-to-date.
392 ///
393 SourceLocation ConsumeBrace() {
394 assert(isTokenBrace() && "wrong consume method");
395 if (Tok.getKind() == tok::l_brace)
396 ++BraceCount;
397 else if (BraceCount)
398 --BraceCount; // Don't let unbalanced }'s drive the count negative.
Mike Stump1eb44332009-09-09 15:08:12 +0000399
Douglas Gregor4b2d3f72009-02-26 21:00:50 +0000400 PrevTokLocation = Tok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000401 PP.Lex(Tok);
Douglas Gregor4b2d3f72009-02-26 21:00:50 +0000402 return PrevTokLocation;
Reid Spencer5f016e22007-07-11 17:01:13 +0000403 }
Mike Stump1eb44332009-09-09 15:08:12 +0000404
Reid Spencer5f016e22007-07-11 17:01:13 +0000405 /// ConsumeStringToken - Consume the current 'peek token', lexing a new one
406 /// and returning the token kind. This method is specific to strings, as it
407 /// handles string literal concatenation, as per C99 5.1.1.2, translation
408 /// phase #6.
409 SourceLocation ConsumeStringToken() {
410 assert(isTokenStringLiteral() &&
411 "Should only consume string literals with this method");
Douglas Gregor4b2d3f72009-02-26 21:00:50 +0000412 PrevTokLocation = Tok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000413 PP.Lex(Tok);
Douglas Gregor4b2d3f72009-02-26 21:00:50 +0000414 return PrevTokLocation;
Reid Spencer5f016e22007-07-11 17:01:13 +0000415 }
Mike Stump1eb44332009-09-09 15:08:12 +0000416
Douglas Gregordc845342010-05-25 05:58:43 +0000417 /// \brief Consume the current code-completion token.
418 ///
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700419 /// This routine can be called to consume the code-completion token and
420 /// continue processing in special cases where \c cutOffParsing() isn't
421 /// desired, such as token caching or completion with lookahead.
Douglas Gregordc845342010-05-25 05:58:43 +0000422 SourceLocation ConsumeCodeCompletionToken() {
423 assert(Tok.is(tok::code_completion));
424 PrevTokLocation = Tok.getLocation();
425 PP.Lex(Tok);
David Blaikiea8fbc052011-11-09 05:30:24 +0000426 return PrevTokLocation;
Douglas Gregordc845342010-05-25 05:58:43 +0000427 }
David Blaikiea8fbc052011-11-09 05:30:24 +0000428
Argyrios Kyrtzidis7d100872011-09-04 03:32:15 +0000429 ///\ brief When we are consuming a code-completion token without having
Douglas Gregordc845342010-05-25 05:58:43 +0000430 /// matched specific position in the grammar, provide code-completion results
431 /// based on context.
Argyrios Kyrtzidis7d100872011-09-04 03:32:15 +0000432 ///
433 /// \returns the source location of the code-completion token.
434 SourceLocation handleUnexpectedCodeCompletionToken();
435
436 /// \brief Abruptly cut off parsing; mainly used when we have reached the
437 /// code-completion point.
438 void cutOffParsing() {
Argyrios Kyrtzidis3b7deda2013-05-24 05:44:08 +0000439 if (PP.isCodeCompletionEnabled())
440 PP.setCodeCompletionReached();
Argyrios Kyrtzidis7d100872011-09-04 03:32:15 +0000441 // Cut off parsing by acting as if we reached the end-of-file.
442 Tok.setKind(tok::eof);
443 }
Douglas Gregordc845342010-05-25 05:58:43 +0000444
Stephen Hines651f13c2014-04-23 16:59:28 -0700445 /// \brief Determine if we're at the end of the file or at a transition
446 /// between modules.
447 bool isEofOrEom() {
448 tok::TokenKind Kind = Tok.getKind();
449 return Kind == tok::eof || Kind == tok::annot_module_begin ||
450 Kind == tok::annot_module_end || Kind == tok::annot_module_include;
451 }
452
453 /// \brief Initialize all pragma handlers.
454 void initializePragmaHandlers();
455
456 /// \brief Destroy and reset all pragma handlers.
457 void resetPragmaHandlers();
458
Argyrios Kyrtzidisb918d0f2011-01-17 18:58:44 +0000459 /// \brief Handle the annotation token produced for #pragma unused(...)
460 void HandlePragmaUnused();
461
Rafael Espindola426fc942012-01-26 02:02:57 +0000462 /// \brief Handle the annotation token produced for
463 /// #pragma GCC visibility...
464 void HandlePragmaVisibility();
465
Eli Friedmanaa5ab262012-02-23 23:47:16 +0000466 /// \brief Handle the annotation token produced for
467 /// #pragma pack...
468 void HandlePragmaPack();
469
Eli Friedman9595c7e2012-10-04 02:36:51 +0000470 /// \brief Handle the annotation token produced for
471 /// #pragma ms_struct...
472 void HandlePragmaMSStruct();
473
474 /// \brief Handle the annotation token produced for
Reid Kleckner3190ca92013-05-08 13:44:39 +0000475 /// #pragma comment...
476 void HandlePragmaMSComment();
477
Stephen Hines651f13c2014-04-23 16:59:28 -0700478 void HandlePragmaMSPointersToMembers();
479
480 void HandlePragmaMSVtorDisp();
481
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700482 void HandlePragmaMSPragma();
Stephen Hines176edba2014-12-01 14:53:08 -0800483 bool HandlePragmaMSSection(StringRef PragmaName,
484 SourceLocation PragmaLocation);
485 bool HandlePragmaMSSegment(StringRef PragmaName,
486 SourceLocation PragmaLocation);
487 bool HandlePragmaMSInitSeg(StringRef PragmaName,
488 SourceLocation PragmaLocation);
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700489
Reid Kleckner3190ca92013-05-08 13:44:39 +0000490 /// \brief Handle the annotation token produced for
Eli Friedman9595c7e2012-10-04 02:36:51 +0000491 /// #pragma align...
492 void HandlePragmaAlign();
493
494 /// \brief Handle the annotation token produced for
495 /// #pragma weak id...
496 void HandlePragmaWeak();
497
498 /// \brief Handle the annotation token produced for
499 /// #pragma weak id = id...
500 void HandlePragmaWeakAlias();
501
502 /// \brief Handle the annotation token produced for
503 /// #pragma redefine_extname...
504 void HandlePragmaRedefineExtname();
505
506 /// \brief Handle the annotation token produced for
507 /// #pragma STDC FP_CONTRACT...
508 void HandlePragmaFPContract();
509
510 /// \brief Handle the annotation token produced for
511 /// #pragma OPENCL EXTENSION...
512 void HandlePragmaOpenCLExtension();
513
Tareq A. Siraj85192c72013-04-16 18:41:26 +0000514 /// \brief Handle the annotation token produced for
515 /// #pragma clang __debug captured
516 StmtResult HandlePragmaCaptured();
517
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700518 /// \brief Handle the annotation token produced for
Stephen Hines176edba2014-12-01 14:53:08 -0800519 /// #pragma clang loop and #pragma unroll.
520 bool HandlePragmaLoopHint(LoopHint &Hint);
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700521
Chris Lattner6b884502008-03-10 06:06:04 +0000522 /// GetLookAheadToken - This peeks ahead N tokens and returns that token
523 /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1)
524 /// returns the token after Tok, etc.
525 ///
526 /// Note that this differs from the Preprocessor's LookAhead method, because
527 /// the Parser always has one token lexed that the preprocessor doesn't.
528 ///
Argyrios Kyrtzidis03db1b32008-08-10 13:15:22 +0000529 const Token &GetLookAheadToken(unsigned N) {
Chris Lattner6b884502008-03-10 06:06:04 +0000530 if (N == 0 || Tok.is(tok::eof)) return Tok;
531 return PP.LookAhead(N-1);
532 }
Argyrios Kyrtzidisf7da7262008-07-09 22:53:07 +0000533
Axel Naumann6944e202012-09-17 13:14:34 +0000534public:
Argyrios Kyrtzidisf7da7262008-07-09 22:53:07 +0000535 /// NextToken - This peeks ahead one token and returns it without
536 /// consuming it.
537 const Token &NextToken() {
Argyrios Kyrtzidis03db1b32008-08-10 13:15:22 +0000538 return PP.LookAhead(0);
Argyrios Kyrtzidisf7da7262008-07-09 22:53:07 +0000539 }
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000540
John McCallb3d87482010-08-24 05:47:05 +0000541 /// getTypeAnnotation - Read a parsed type out of an annotation token.
542 static ParsedType getTypeAnnotation(Token &Tok) {
543 return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue());
544 }
545
Axel Naumann6944e202012-09-17 13:14:34 +0000546private:
John McCallb3d87482010-08-24 05:47:05 +0000547 static void setTypeAnnotation(Token &Tok, ParsedType T) {
548 Tok.setAnnotationValue(T.getAsOpaquePtr());
549 }
David Blaikiea8fbc052011-11-09 05:30:24 +0000550
Douglas Gregor5ecdd782011-04-27 06:18:01 +0000551 /// \brief Read an already-translated primary expression out of an annotation
552 /// token.
553 static ExprResult getExprAnnotation(Token &Tok) {
Richard Smitha2c36462013-04-26 16:15:35 +0000554 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
Douglas Gregor5ecdd782011-04-27 06:18:01 +0000555 }
David Blaikiea8fbc052011-11-09 05:30:24 +0000556
Douglas Gregor5ecdd782011-04-27 06:18:01 +0000557 /// \brief Set the primary expression corresponding to the given annotation
558 /// token.
559 static void setExprAnnotation(Token &Tok, ExprResult ER) {
Richard Smitha2c36462013-04-26 16:15:35 +0000560 Tok.setAnnotationValue(ER.getAsOpaquePointer());
Douglas Gregor5ecdd782011-04-27 06:18:01 +0000561 }
John McCallb3d87482010-08-24 05:47:05 +0000562
Axel Naumann6944e202012-09-17 13:14:34 +0000563public:
Kaelyn Uhrainfac94672011-10-11 01:02:41 +0000564 // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to
565 // find a type name by attempting typo correction.
566 bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false,
567 bool NeedType = false);
Richard Smith05766812012-08-18 00:55:03 +0000568 bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool EnteringContext,
569 bool NeedType,
570 CXXScopeSpec &SS,
571 bool IsNewScope);
Douglas Gregor495c35d2009-08-25 22:51:20 +0000572 bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
Axel Naumann6944e202012-09-17 13:14:34 +0000573
574private:
Richard Smith05766812012-08-18 00:55:03 +0000575 enum AnnotatedNameKind {
576 /// Annotation has failed and emitted an error.
577 ANK_Error,
578 /// The identifier is a tentatively-declared name.
579 ANK_TentativeDecl,
580 /// The identifier is a template name. FIXME: Add an annotation for that.
581 ANK_TemplateName,
582 /// The identifier can't be resolved.
583 ANK_Unresolved,
584 /// Annotation was successful.
585 ANK_Success
586 };
Stephen Hines176edba2014-12-01 14:53:08 -0800587 AnnotatedNameKind
588 TryAnnotateName(bool IsAddressOfOperand,
589 std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr);
Richard Smith05766812012-08-18 00:55:03 +0000590
591 /// Push a tok::annot_cxxscope token onto the token stream.
592 void AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation);
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000593
John Thompson82287d12010-02-05 00:12:22 +0000594 /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens,
595 /// replacing them with the non-context-sensitive keywords. This returns
596 /// true if the token was replaced.
597 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
Chris Lattnerb3a4e432010-02-28 18:18:36 +0000598 const char *&PrevSpec, unsigned &DiagID,
599 bool &isInvalid) {
David Blaikie4e4d0842012-03-11 07:00:24 +0000600 if (!getLangOpts().AltiVec ||
Chris Lattner1b492422010-02-28 18:33:55 +0000601 (Tok.getIdentifierInfo() != Ident_vector &&
Bill Schmidt3e3d20b2013-07-03 20:54:09 +0000602 Tok.getIdentifierInfo() != Ident_pixel &&
603 Tok.getIdentifierInfo() != Ident_bool))
Chris Lattner1b492422010-02-28 18:33:55 +0000604 return false;
David Blaikiea8fbc052011-11-09 05:30:24 +0000605
Chris Lattner1b492422010-02-28 18:33:55 +0000606 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid);
John Thompson82287d12010-02-05 00:12:22 +0000607 }
608
609 /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector
610 /// identifier token, replacing it with the non-context-sensitive __vector.
611 /// This returns true if the token was replaced.
612 bool TryAltiVecVectorToken() {
David Blaikie4e4d0842012-03-11 07:00:24 +0000613 if (!getLangOpts().AltiVec ||
Chris Lattnerb3a4e432010-02-28 18:18:36 +0000614 Tok.getIdentifierInfo() != Ident_vector) return false;
Chris Lattner1b492422010-02-28 18:33:55 +0000615 return TryAltiVecVectorTokenOutOfLine();
John Thompson82287d12010-02-05 00:12:22 +0000616 }
David Blaikiea8fbc052011-11-09 05:30:24 +0000617
Chris Lattner1b492422010-02-28 18:33:55 +0000618 bool TryAltiVecVectorTokenOutOfLine();
619 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
620 const char *&PrevSpec, unsigned &DiagID,
621 bool &isInvalid);
Argyrios Kyrtzidis25a76762011-06-22 06:09:49 +0000622
Bill Wendling03e463e2013-12-16 02:32:55 +0000623 /// TryKeywordIdentFallback - For compatibility with system headers using
624 /// keywords as identifiers, attempt to convert the current token to an
625 /// identifier and optionally disable the keyword for the remainder of the
626 /// translation unit. This returns false if the token was not replaced,
627 /// otherwise emits a diagnostic and returns true.
628 bool TryKeywordIdentFallback(bool DisableKeyword);
629
Benjamin Kramer13bb7012012-04-14 12:14:03 +0000630 /// \brief Get the TemplateIdAnnotation from the token.
Argyrios Kyrtzidis25a76762011-06-22 06:09:49 +0000631 TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok);
632
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000633 /// TentativeParsingAction - An object that is used as a kind of "tentative
634 /// parsing transaction". It gets instantiated to mark the token position and
635 /// after the token consumption is done, Commit() or Revert() is called to
636 /// either "commit the consumed tokens" or revert to the previously marked
637 /// token position. Example:
638 ///
Douglas Gregor314b97f2009-11-10 19:49:08 +0000639 /// TentativeParsingAction TPA(*this);
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000640 /// ConsumeToken();
641 /// ....
642 /// TPA.Revert();
643 ///
644 class TentativeParsingAction {
645 Parser &P;
646 Token PrevTok;
Richard Smith05766812012-08-18 00:55:03 +0000647 size_t PrevTentativelyDeclaredIdentifierCount;
Douglas Gregorde882462012-04-30 16:20:27 +0000648 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000649 bool isActive;
650
651 public:
652 explicit TentativeParsingAction(Parser& p) : P(p) {
653 PrevTok = P.Tok;
Richard Smith05766812012-08-18 00:55:03 +0000654 PrevTentativelyDeclaredIdentifierCount =
655 P.TentativelyDeclaredIdentifiers.size();
Douglas Gregorde882462012-04-30 16:20:27 +0000656 PrevParenCount = P.ParenCount;
657 PrevBracketCount = P.BracketCount;
658 PrevBraceCount = P.BraceCount;
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000659 P.PP.EnableBacktrackAtThisPos();
660 isActive = true;
661 }
662 void Commit() {
663 assert(isActive && "Parsing action was finished!");
Richard Smith05766812012-08-18 00:55:03 +0000664 P.TentativelyDeclaredIdentifiers.resize(
665 PrevTentativelyDeclaredIdentifierCount);
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000666 P.PP.CommitBacktrackedTokens();
667 isActive = false;
668 }
669 void Revert() {
670 assert(isActive && "Parsing action was finished!");
671 P.PP.Backtrack();
672 P.Tok = PrevTok;
Richard Smith05766812012-08-18 00:55:03 +0000673 P.TentativelyDeclaredIdentifiers.resize(
674 PrevTentativelyDeclaredIdentifierCount);
Douglas Gregorde882462012-04-30 16:20:27 +0000675 P.ParenCount = PrevParenCount;
676 P.BracketCount = PrevBracketCount;
677 P.BraceCount = PrevBraceCount;
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000678 isActive = false;
679 }
680 ~TentativeParsingAction() {
681 assert(!isActive && "Forgot to call Commit or Revert!");
682 }
683 };
Richard Smith9bd3cdc2013-09-12 23:28:08 +0000684 class UnannotatedTentativeParsingAction;
Mike Stump1eb44332009-09-09 15:08:12 +0000685
Fariborz Jahanian9735c5e2011-08-22 17:59:19 +0000686 /// ObjCDeclContextSwitch - An object used to switch context from
687 /// an objective-c decl context to its enclosing decl context and
688 /// back.
689 class ObjCDeclContextSwitch {
690 Parser &P;
691 Decl *DC;
Jordan Rose94f29f42012-07-09 16:54:53 +0000692 SaveAndRestore<bool> WithinObjCContainer;
Fariborz Jahanian9735c5e2011-08-22 17:59:19 +0000693 public:
Jordan Rose94f29f42012-07-09 16:54:53 +0000694 explicit ObjCDeclContextSwitch(Parser &p)
695 : P(p), DC(p.getObjCDeclContext()),
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700696 WithinObjCContainer(P.ParsingInObjCContainer, DC != nullptr) {
Fariborz Jahanian9735c5e2011-08-22 17:59:19 +0000697 if (DC)
Argyrios Kyrtzidis458bacf2011-10-27 00:09:34 +0000698 P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC));
Fariborz Jahanian9735c5e2011-08-22 17:59:19 +0000699 }
700 ~ObjCDeclContextSwitch() {
701 if (DC)
Argyrios Kyrtzidis458bacf2011-10-27 00:09:34 +0000702 P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC));
Fariborz Jahanian9735c5e2011-08-22 17:59:19 +0000703 }
704 };
Mike Stump1eb44332009-09-09 15:08:12 +0000705
Reid Spencer5f016e22007-07-11 17:01:13 +0000706 /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
707 /// input. If so, it is consumed and false is returned.
708 ///
Stephen Hines651f13c2014-04-23 16:59:28 -0700709 /// If a trivial punctuator misspelling is encountered, a FixIt error
710 /// diagnostic is issued and false is returned after recovery.
711 ///
712 /// If the input is malformed, this emits the specified diagnostic and true is
Reid Spencer5f016e22007-07-11 17:01:13 +0000713 /// returned.
Stephen Hines651f13c2014-04-23 16:59:28 -0700714 bool ExpectAndConsume(tok::TokenKind ExpectedTok,
715 unsigned Diag = diag::err_expected,
Stephen Hines176edba2014-12-01 14:53:08 -0800716 StringRef DiagMsg = "");
Reid Spencer5f016e22007-07-11 17:01:13 +0000717
Douglas Gregor9ba23b42010-09-07 15:23:11 +0000718 /// \brief The parser expects a semicolon and, if present, will consume it.
719 ///
720 /// If the next token is not a semicolon, this emits the specified diagnostic,
721 /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior
722 /// to the semicolon, consumes that extra token.
723 bool ExpectAndConsumeSemi(unsigned DiagID);
David Blaikiea8fbc052011-11-09 05:30:24 +0000724
Richard Smitheab9d6f2012-07-23 05:45:25 +0000725 /// \brief The kind of extra semi diagnostic to emit.
Richard Trieu4b0e6f12012-05-16 19:04:59 +0000726 enum ExtraSemiKind {
727 OutsideFunction = 0,
728 InsideStruct = 1,
729 InstanceVariableList = 2,
Richard Smitheab9d6f2012-07-23 05:45:25 +0000730 AfterMemberFunctionDefinition = 3
Richard Trieu4b0e6f12012-05-16 19:04:59 +0000731 };
732
733 /// \brief Consume any extra semi-colons until the end of the line.
Richard Smitheab9d6f2012-07-23 05:45:25 +0000734 void ConsumeExtraSemi(ExtraSemiKind Kind, unsigned TST = TST_unspecified);
Richard Trieu4b0e6f12012-05-16 19:04:59 +0000735
Axel Naumann6944e202012-09-17 13:14:34 +0000736public:
Reid Spencer5f016e22007-07-11 17:01:13 +0000737 //===--------------------------------------------------------------------===//
738 // Scope manipulation
Mike Stump1eb44332009-09-09 15:08:12 +0000739
Douglas Gregor8935b8b2008-12-10 06:34:36 +0000740 /// ParseScope - Introduces a new scope for parsing. The kind of
741 /// scope is determined by ScopeFlags. Objects of this type should
742 /// be created on the stack to coincide with the position where the
743 /// parser enters the new scope, and this object's constructor will
744 /// create that new scope. Similarly, once the object is destroyed
745 /// the parser will exit the scope.
746 class ParseScope {
747 Parser *Self;
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700748 ParseScope(const ParseScope &) = delete;
749 void operator=(const ParseScope &) = delete;
Douglas Gregor8935b8b2008-12-10 06:34:36 +0000750
751 public:
752 // ParseScope - Construct a new object to manage a scope in the
753 // parser Self where the new Scope is created with the flags
Stephen Hines651f13c2014-04-23 16:59:28 -0700754 // ScopeFlags, but only when we aren't about to enter a compound statement.
755 ParseScope(Parser *Self, unsigned ScopeFlags, bool EnteredScope = true,
756 bool BeforeCompoundStmt = false)
Douglas Gregor8935b8b2008-12-10 06:34:36 +0000757 : Self(Self) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700758 if (EnteredScope && !BeforeCompoundStmt)
Douglas Gregor8935b8b2008-12-10 06:34:36 +0000759 Self->EnterScope(ScopeFlags);
Stephen Hines651f13c2014-04-23 16:59:28 -0700760 else {
761 if (BeforeCompoundStmt)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700762 Self->incrementMSManglingNumber();
Stephen Hines651f13c2014-04-23 16:59:28 -0700763
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700764 this->Self = nullptr;
Stephen Hines651f13c2014-04-23 16:59:28 -0700765 }
Douglas Gregor8935b8b2008-12-10 06:34:36 +0000766 }
767
768 // Exit - Exit the scope associated with this object now, rather
769 // than waiting until the object is destroyed.
770 void Exit() {
771 if (Self) {
772 Self->ExitScope();
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700773 Self = nullptr;
Douglas Gregor8935b8b2008-12-10 06:34:36 +0000774 }
775 }
776
777 ~ParseScope() {
778 Exit();
779 }
780 };
781
Reid Spencer5f016e22007-07-11 17:01:13 +0000782 /// EnterScope - Start a new scope.
783 void EnterScope(unsigned ScopeFlags);
Mike Stump1eb44332009-09-09 15:08:12 +0000784
Reid Spencer5f016e22007-07-11 17:01:13 +0000785 /// ExitScope - Pop a scope off the scope stack.
786 void ExitScope();
787
Axel Naumann6944e202012-09-17 13:14:34 +0000788private:
Richard Smith7a614d82011-06-11 17:19:42 +0000789 /// \brief RAII object used to modify the scope flags for the current scope.
790 class ParseScopeFlags {
791 Scope *CurScope;
792 unsigned OldFlags;
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700793 ParseScopeFlags(const ParseScopeFlags &) = delete;
794 void operator=(const ParseScopeFlags &) = delete;
Richard Smith7a614d82011-06-11 17:19:42 +0000795
796 public:
797 ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true);
798 ~ParseScopeFlags();
799 };
800
Reid Spencer5f016e22007-07-11 17:01:13 +0000801 //===--------------------------------------------------------------------===//
802 // Diagnostic Emission and Error recovery.
Sebastian Redl15faa7f2008-12-09 20:22:58 +0000803
Douglas Gregor6aa14d82010-04-21 22:36:40 +0000804public:
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000805 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
806 DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID);
Jordan Rosed73ef132012-06-06 17:25:21 +0000807 DiagnosticBuilder Diag(unsigned DiagID) {
808 return Diag(Tok, DiagID);
809 }
Sebastian Redl15faa7f2008-12-09 20:22:58 +0000810
Douglas Gregor6aa14d82010-04-21 22:36:40 +0000811private:
Mike Stump1eb44332009-09-09 15:08:12 +0000812 void SuggestParentheses(SourceLocation Loc, unsigned DK,
Douglas Gregor4b2d3f72009-02-26 21:00:50 +0000813 SourceRange ParenRange);
Erik Verbruggend64251f2011-12-06 09:25:23 +0000814 void CheckNestedObjCContexts(SourceLocation AtLoc);
Douglas Gregor4b2d3f72009-02-26 21:00:50 +0000815
Axel Naumann6944e202012-09-17 13:14:34 +0000816public:
Alexey Bataev8fe24752013-11-18 08:17:37 +0000817
NAKAMURA Takumi155c8772013-11-18 10:38:28 +0000818 /// \brief Control flags for SkipUntil functions.
Alexey Bataev8fe24752013-11-18 08:17:37 +0000819 enum SkipUntilFlags {
NAKAMURA Takumi155c8772013-11-18 10:38:28 +0000820 StopAtSemi = 1 << 0, ///< Stop skipping at semicolon
Alexey Bataev8fe24752013-11-18 08:17:37 +0000821 /// \brief Stop skipping at specified token, but don't skip the token itself
822 StopBeforeMatch = 1 << 1,
NAKAMURA Takumi155c8772013-11-18 10:38:28 +0000823 StopAtCodeCompletion = 1 << 2 ///< Stop at code completion
Alexey Bataev8fe24752013-11-18 08:17:37 +0000824 };
825
826 friend LLVM_CONSTEXPR SkipUntilFlags operator|(SkipUntilFlags L,
827 SkipUntilFlags R) {
828 return static_cast<SkipUntilFlags>(static_cast<unsigned>(L) |
829 static_cast<unsigned>(R));
830 }
831
Reid Spencer5f016e22007-07-11 17:01:13 +0000832 /// SkipUntil - Read tokens until we get to the specified token, then consume
Alexey Bataev8fe24752013-11-18 08:17:37 +0000833 /// it (unless StopBeforeMatch is specified). Because we cannot guarantee
834 /// that the token will ever occur, this skips to the next token, or to some
835 /// likely good stopping point. If Flags has StopAtSemi flag, skipping will
836 /// stop at a ';' character.
Mike Stump1eb44332009-09-09 15:08:12 +0000837 ///
Reid Spencer5f016e22007-07-11 17:01:13 +0000838 /// If SkipUntil finds the specified token, it returns true, otherwise it
Mike Stump1eb44332009-09-09 15:08:12 +0000839 /// returns false.
Alexey Bataev8fe24752013-11-18 08:17:37 +0000840 bool SkipUntil(tok::TokenKind T,
841 SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) {
842 return SkipUntil(llvm::makeArrayRef(T), Flags);
Reid Spencer5f016e22007-07-11 17:01:13 +0000843 }
Alexey Bataev8fe24752013-11-18 08:17:37 +0000844 bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2,
845 SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000846 tok::TokenKind TokArray[] = {T1, T2};
Alexey Bataev8fe24752013-11-18 08:17:37 +0000847 return SkipUntil(TokArray, Flags);
Reid Spencer5f016e22007-07-11 17:01:13 +0000848 }
David Blaikieeb52f86a2012-04-09 16:37:11 +0000849 bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3,
Alexey Bataev8fe24752013-11-18 08:17:37 +0000850 SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) {
David Blaikieeb52f86a2012-04-09 16:37:11 +0000851 tok::TokenKind TokArray[] = {T1, T2, T3};
Alexey Bataev8fe24752013-11-18 08:17:37 +0000852 return SkipUntil(TokArray, Flags);
David Blaikieeb52f86a2012-04-09 16:37:11 +0000853 }
Alexey Bataev8fe24752013-11-18 08:17:37 +0000854 bool SkipUntil(ArrayRef<tok::TokenKind> Toks,
855 SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0));
Douglas Gregor7ad83902008-11-05 04:29:56 +0000856
Richard Smith994d73f2012-04-11 20:59:20 +0000857 /// SkipMalformedDecl - Read tokens until we get to some likely good stopping
858 /// point for skipping past a simple-declaration.
859 void SkipMalformedDecl();
860
Axel Naumann6944e202012-09-17 13:14:34 +0000861private:
Reid Spencer5f016e22007-07-11 17:01:13 +0000862 //===--------------------------------------------------------------------===//
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000863 // Lexing and parsing of C++ inline methods.
864
Douglas Gregord54eb442010-10-12 16:25:54 +0000865 struct ParsingClass;
866
867 /// [class.mem]p1: "... the class is regarded as complete within
868 /// - function bodies
869 /// - default arguments
870 /// - exception-specifications (TODO: C++0x)
Richard Smith7a614d82011-06-11 17:19:42 +0000871 /// - and brace-or-equal-initializers for non-static data members
872 /// (including such things in nested classes)."
Douglas Gregord54eb442010-10-12 16:25:54 +0000873 /// LateParsedDeclarations build the tree of those elements so they can
874 /// be parsed after parsing the top-level class.
875 class LateParsedDeclaration {
876 public:
877 virtual ~LateParsedDeclaration();
878
879 virtual void ParseLexedMethodDeclarations();
Richard Smith7a614d82011-06-11 17:19:42 +0000880 virtual void ParseLexedMemberInitializers();
Douglas Gregord54eb442010-10-12 16:25:54 +0000881 virtual void ParseLexedMethodDefs();
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +0000882 virtual void ParseLexedAttributes();
Douglas Gregord54eb442010-10-12 16:25:54 +0000883 };
884
885 /// Inner node of the LateParsedDeclaration tree that parses
886 /// all its members recursively.
887 class LateParsedClass : public LateParsedDeclaration {
888 public:
889 LateParsedClass(Parser *P, ParsingClass *C);
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700890 ~LateParsedClass() override;
Douglas Gregord54eb442010-10-12 16:25:54 +0000891
Stephen Hines651f13c2014-04-23 16:59:28 -0700892 void ParseLexedMethodDeclarations() override;
893 void ParseLexedMemberInitializers() override;
894 void ParseLexedMethodDefs() override;
895 void ParseLexedAttributes() override;
Douglas Gregord54eb442010-10-12 16:25:54 +0000896
897 private:
898 Parser *Self;
899 ParsingClass *Class;
900 };
901
David Blaikiea8fbc052011-11-09 05:30:24 +0000902 /// Contains the lexed tokens of an attribute with arguments that
903 /// may reference member variables and so need to be parsed at the
904 /// end of the class declaration after parsing all other member
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +0000905 /// member declarations.
906 /// FIXME: Perhaps we should change the name of LateParsedDeclaration to
907 /// LateParsedTokens.
908 struct LateParsedAttribute : public LateParsedDeclaration {
909 Parser *Self;
910 CachedTokens Toks;
911 IdentifierInfo &AttrName;
912 SourceLocation AttrNameLoc;
DeLesley Hutchins2287c5e2012-03-02 22:12:59 +0000913 SmallVector<Decl*, 2> Decls;
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +0000914
David Blaikiea8fbc052011-11-09 05:30:24 +0000915 explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name,
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +0000916 SourceLocation Loc)
DeLesley Hutchins2287c5e2012-03-02 22:12:59 +0000917 : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +0000918
Stephen Hines651f13c2014-04-23 16:59:28 -0700919 void ParseLexedAttributes() override;
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +0000920
DeLesley Hutchins2287c5e2012-03-02 22:12:59 +0000921 void addDecl(Decl *D) { Decls.push_back(D); }
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +0000922 };
923
DeLesley Hutchins161db022012-11-02 21:44:32 +0000924 // A list of late-parsed attributes. Used by ParseGNUAttributes.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000925 class LateParsedAttrList: public SmallVector<LateParsedAttribute *, 2> {
DeLesley Hutchins161db022012-11-02 21:44:32 +0000926 public:
927 LateParsedAttrList(bool PSoon = false) : ParseSoon(PSoon) { }
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +0000928
DeLesley Hutchins161db022012-11-02 21:44:32 +0000929 bool parseSoon() { return ParseSoon; }
930
931 private:
932 bool ParseSoon; // Are we planning to parse these shortly after creation?
933 };
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +0000934
Douglas Gregord54eb442010-10-12 16:25:54 +0000935 /// Contains the lexed tokens of a member function definition
936 /// which needs to be parsed at the end of the class declaration
937 /// after parsing all other member declarations.
938 struct LexedMethod : public LateParsedDeclaration {
939 Parser *Self;
John McCalld226f652010-08-21 09:40:31 +0000940 Decl *D;
Douglas Gregor72b505b2008-12-16 21:30:33 +0000941 CachedTokens Toks;
Douglas Gregord83d0402009-08-22 00:34:47 +0000942
943 /// \brief Whether this member function had an associated template
944 /// scope. When true, D is a template declaration.
Nico Weberf5e9d032012-12-14 02:41:18 +0000945 /// otherwise, it is a member function declaration.
Douglas Gregord83d0402009-08-22 00:34:47 +0000946 bool TemplateScope;
947
Douglas Gregord54eb442010-10-12 16:25:54 +0000948 explicit LexedMethod(Parser* P, Decl *MD)
949 : Self(P), D(MD), TemplateScope(false) {}
950
Stephen Hines651f13c2014-04-23 16:59:28 -0700951 void ParseLexedMethodDefs() override;
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000952 };
953
Douglas Gregor72b505b2008-12-16 21:30:33 +0000954 /// LateParsedDefaultArgument - Keeps track of a parameter that may
955 /// have a default argument that cannot be parsed yet because it
956 /// occurs within a member function declaration inside the class
957 /// (C++ [class.mem]p2).
958 struct LateParsedDefaultArgument {
John McCalld226f652010-08-21 09:40:31 +0000959 explicit LateParsedDefaultArgument(Decl *P,
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700960 CachedTokens *Toks = nullptr)
Douglas Gregor72b505b2008-12-16 21:30:33 +0000961 : Param(P), Toks(Toks) { }
962
963 /// Param - The parameter declaration for this parameter.
John McCalld226f652010-08-21 09:40:31 +0000964 Decl *Param;
Douglas Gregor72b505b2008-12-16 21:30:33 +0000965
966 /// Toks - The sequence of tokens that comprises the default
967 /// argument expression, not including the '=' or the terminating
968 /// ')' or ','. This will be NULL for parameters that have no
969 /// default argument.
970 CachedTokens *Toks;
971 };
Mike Stump1eb44332009-09-09 15:08:12 +0000972
Douglas Gregor72b505b2008-12-16 21:30:33 +0000973 /// LateParsedMethodDeclaration - A method declaration inside a class that
974 /// contains at least one entity whose parsing needs to be delayed
975 /// until the class itself is completely-defined, such as a default
976 /// argument (C++ [class.mem]p2).
Douglas Gregord54eb442010-10-12 16:25:54 +0000977 struct LateParsedMethodDeclaration : public LateParsedDeclaration {
978 explicit LateParsedMethodDeclaration(Parser *P, Decl *M)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700979 : Self(P), Method(M), TemplateScope(false),
980 ExceptionSpecTokens(nullptr) {}
Douglas Gregord54eb442010-10-12 16:25:54 +0000981
Stephen Hines651f13c2014-04-23 16:59:28 -0700982 void ParseLexedMethodDeclarations() override;
Douglas Gregord54eb442010-10-12 16:25:54 +0000983
984 Parser* Self;
Douglas Gregor72b505b2008-12-16 21:30:33 +0000985
986 /// Method - The method declaration.
John McCalld226f652010-08-21 09:40:31 +0000987 Decl *Method;
Douglas Gregor72b505b2008-12-16 21:30:33 +0000988
Douglas Gregord83d0402009-08-22 00:34:47 +0000989 /// \brief Whether this member function had an associated template
990 /// scope. When true, D is a template declaration.
991 /// othewise, it is a member function declaration.
992 bool TemplateScope;
Mike Stump1eb44332009-09-09 15:08:12 +0000993
Douglas Gregor72b505b2008-12-16 21:30:33 +0000994 /// DefaultArgs - Contains the parameters of the function and
995 /// their default arguments. At least one of the parameters will
996 /// have a default argument, but all of the parameters of the
997 /// method will be stored so that they can be reintroduced into
Mike Stump1eb44332009-09-09 15:08:12 +0000998 /// scope at the appropriate times.
Chris Lattner686775d2011-07-20 06:58:45 +0000999 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
Douglas Gregor74e2fc32012-04-16 18:27:27 +00001000
1001 /// \brief The set of tokens that make up an exception-specification that
1002 /// has not yet been parsed.
1003 CachedTokens *ExceptionSpecTokens;
Douglas Gregor72b505b2008-12-16 21:30:33 +00001004 };
1005
Richard Smith7a614d82011-06-11 17:19:42 +00001006 /// LateParsedMemberInitializer - An initializer for a non-static class data
1007 /// member whose parsing must to be delayed until the class is completely
1008 /// defined (C++11 [class.mem]p2).
1009 struct LateParsedMemberInitializer : public LateParsedDeclaration {
1010 LateParsedMemberInitializer(Parser *P, Decl *FD)
1011 : Self(P), Field(FD) { }
1012
Stephen Hines651f13c2014-04-23 16:59:28 -07001013 void ParseLexedMemberInitializers() override;
Richard Smith7a614d82011-06-11 17:19:42 +00001014
1015 Parser *Self;
1016
1017 /// Field - The field declaration.
1018 Decl *Field;
1019
1020 /// CachedTokens - The sequence of tokens that comprises the initializer,
1021 /// including any leading '='.
1022 CachedTokens Toks;
1023 };
1024
Douglas Gregord54eb442010-10-12 16:25:54 +00001025 /// LateParsedDeclarationsContainer - During parsing of a top (non-nested)
1026 /// C++ class, its method declarations that contain parts that won't be
Chris Lattnerfc8f0e12011-04-15 05:22:18 +00001027 /// parsed until after the definition is completed (C++ [class.mem]p2),
Douglas Gregord54eb442010-10-12 16:25:54 +00001028 /// the method declarations and possibly attached inline definitions
David Blaikiea8fbc052011-11-09 05:30:24 +00001029 /// will be stored here with the tokens that will be parsed to create those
1030 /// entities.
1031 typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer;
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +00001032
Douglas Gregor6569d682009-05-27 23:11:45 +00001033 /// \brief Representation of a class that has been parsed, including
1034 /// any member function declarations or definitions that need to be
1035 /// parsed after the corresponding top-level class is complete.
1036 struct ParsingClass {
John McCalle402e722012-09-25 07:32:39 +00001037 ParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface)
Mike Stump1eb44332009-09-09 15:08:12 +00001038 : TopLevelClass(TopLevelClass), TemplateScope(false),
John McCalle402e722012-09-25 07:32:39 +00001039 IsInterface(IsInterface), TagOrTemplate(TagOrTemplate) { }
Douglas Gregor72b505b2008-12-16 21:30:33 +00001040
Douglas Gregor6569d682009-05-27 23:11:45 +00001041 /// \brief Whether this is a "top-level" class, meaning that it is
1042 /// not nested within another class.
1043 bool TopLevelClass : 1;
1044
1045 /// \brief Whether this class had an associated template
1046 /// scope. When true, TagOrTemplate is a template declaration;
1047 /// othewise, it is a tag declaration.
1048 bool TemplateScope : 1;
1049
John McCalle402e722012-09-25 07:32:39 +00001050 /// \brief Whether this class is an __interface.
1051 bool IsInterface : 1;
1052
Douglas Gregor6569d682009-05-27 23:11:45 +00001053 /// \brief The class or class template whose definition we are parsing.
John McCalld226f652010-08-21 09:40:31 +00001054 Decl *TagOrTemplate;
Douglas Gregor6569d682009-05-27 23:11:45 +00001055
Douglas Gregord54eb442010-10-12 16:25:54 +00001056 /// LateParsedDeclarations - Method declarations, inline definitions and
1057 /// nested classes that contain pieces whose parsing will be delayed until
1058 /// the top-level class is fully defined.
1059 LateParsedDeclarationsContainer LateParsedDeclarations;
Douglas Gregor72b505b2008-12-16 21:30:33 +00001060 };
1061
Douglas Gregor6569d682009-05-27 23:11:45 +00001062 /// \brief The stack of classes that is currently being
1063 /// parsed. Nested and local classes will be pushed onto this stack
1064 /// when they are parsed, and removed afterward.
1065 std::stack<ParsingClass *> ClassStack;
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +00001066
Douglas Gregor6569d682009-05-27 23:11:45 +00001067 ParsingClass &getCurrentClass() {
1068 assert(!ClassStack.empty() && "No lexed method stacks!");
1069 return *ClassStack.top();
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +00001070 }
1071
John McCall92576642012-05-07 06:16:41 +00001072 /// \brief RAII object used to manage the parsing of a class definition.
Douglas Gregor6569d682009-05-27 23:11:45 +00001073 class ParsingClassDefinition {
1074 Parser &P;
1075 bool Popped;
John McCalleee1d542011-02-14 07:13:47 +00001076 Sema::ParsingClassState State;
Douglas Gregor6569d682009-05-27 23:11:45 +00001077
1078 public:
John McCalle402e722012-09-25 07:32:39 +00001079 ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass,
1080 bool IsInterface)
John McCalleee1d542011-02-14 07:13:47 +00001081 : P(P), Popped(false),
John McCalle402e722012-09-25 07:32:39 +00001082 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
Douglas Gregor6569d682009-05-27 23:11:45 +00001083 }
1084
1085 /// \brief Pop this class of the stack.
Mike Stump1eb44332009-09-09 15:08:12 +00001086 void Pop() {
Douglas Gregor6569d682009-05-27 23:11:45 +00001087 assert(!Popped && "Nested class has already been popped");
1088 Popped = true;
John McCalleee1d542011-02-14 07:13:47 +00001089 P.PopParsingClass(State);
Douglas Gregor6569d682009-05-27 23:11:45 +00001090 }
1091
Mike Stump1eb44332009-09-09 15:08:12 +00001092 ~ParsingClassDefinition() {
Douglas Gregor6569d682009-05-27 23:11:45 +00001093 if (!Popped)
John McCalleee1d542011-02-14 07:13:47 +00001094 P.PopParsingClass(State);
Douglas Gregor6569d682009-05-27 23:11:45 +00001095 }
1096 };
1097
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00001098 /// \brief Contains information about any template-specific
1099 /// information that has been parsed prior to parsing declaration
1100 /// specifiers.
1101 struct ParsedTemplateInfo {
Mike Stump1eb44332009-09-09 15:08:12 +00001102 ParsedTemplateInfo()
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001103 : Kind(NonTemplate), TemplateParams(nullptr), TemplateLoc() { }
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00001104
1105 ParsedTemplateInfo(TemplateParameterLists *TemplateParams,
Douglas Gregorc78c06d2009-10-30 22:09:44 +00001106 bool isSpecialization,
1107 bool lastParameterListWasEmpty = false)
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00001108 : Kind(isSpecialization? ExplicitSpecialization : Template),
David Blaikiea8fbc052011-11-09 05:30:24 +00001109 TemplateParams(TemplateParams),
Douglas Gregorc78c06d2009-10-30 22:09:44 +00001110 LastParameterListWasEmpty(lastParameterListWasEmpty) { }
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00001111
Douglas Gregor45f96552009-09-04 06:33:52 +00001112 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
1113 SourceLocation TemplateLoc)
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001114 : Kind(ExplicitInstantiation), TemplateParams(nullptr),
Douglas Gregorc78c06d2009-10-30 22:09:44 +00001115 ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
1116 LastParameterListWasEmpty(false){ }
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00001117
1118 /// \brief The kind of template we are parsing.
1119 enum {
1120 /// \brief We are not parsing a template at all.
1121 NonTemplate = 0,
1122 /// \brief We are parsing a template declaration.
1123 Template,
1124 /// \brief We are parsing an explicit specialization.
1125 ExplicitSpecialization,
1126 /// \brief We are parsing an explicit instantiation.
1127 ExplicitInstantiation
1128 } Kind;
1129
1130 /// \brief The template parameter lists, for template declarations
1131 /// and explicit specializations.
1132 TemplateParameterLists *TemplateParams;
1133
Douglas Gregor45f96552009-09-04 06:33:52 +00001134 /// \brief The location of the 'extern' keyword, if any, for an explicit
1135 /// instantiation
1136 SourceLocation ExternLoc;
Mike Stump1eb44332009-09-09 15:08:12 +00001137
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00001138 /// \brief The location of the 'template' keyword, for an explicit
1139 /// instantiation.
1140 SourceLocation TemplateLoc;
David Blaikiea8fbc052011-11-09 05:30:24 +00001141
Douglas Gregorc78c06d2009-10-30 22:09:44 +00001142 /// \brief Whether the last template parameter list was empty.
1143 bool LastParameterListWasEmpty;
John McCall78b81052010-11-10 02:40:36 +00001144
Daniel Dunbaraa49a7d2012-03-09 19:35:29 +00001145 SourceRange getSourceRange() const LLVM_READONLY;
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00001146 };
Mike Stump1eb44332009-09-09 15:08:12 +00001147
Francois Pichet8387e2a2011-04-22 22:18:13 +00001148 void LexTemplateFunctionForLateParsing(CachedTokens &Toks);
Richard Smithac32d902013-08-07 21:41:30 +00001149 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
Francois Pichet8387e2a2011-04-22 22:18:13 +00001150
Richard Smithac32d902013-08-07 21:41:30 +00001151 static void LateTemplateParserCallback(void *P, LateParsedTemplate &LPT);
Stephen Hines176edba2014-12-01 14:53:08 -08001152 static void LateTemplateParserCleanupCallback(void *P);
Francois Pichet8387e2a2011-04-22 22:18:13 +00001153
John McCalleee1d542011-02-14 07:13:47 +00001154 Sema::ParsingClassState
John McCalle402e722012-09-25 07:32:39 +00001155 PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface);
Douglas Gregor37b372b2009-08-20 22:52:58 +00001156 void DeallocateParsedClasses(ParsingClass *Class);
John McCalleee1d542011-02-14 07:13:47 +00001157 void PopParsingClass(Sema::ParsingClassState);
Douglas Gregor37b372b2009-08-20 22:52:58 +00001158
Richard Smith9bd3cdc2013-09-12 23:28:08 +00001159 enum CachedInitKind {
1160 CIK_DefaultArgument,
1161 CIK_DefaultInitializer
1162 };
1163
Rafael Espindola0777cf52013-01-08 21:00:12 +00001164 NamedDecl *ParseCXXInlineMethodDef(AccessSpecifier AS,
1165 AttributeList *AccessAttrs,
Erik Verbruggen5f1c8222011-10-13 09:41:32 +00001166 ParsingDeclarator &D,
Nico Weber48673472011-01-28 06:07:34 +00001167 const ParsedTemplateInfo &TemplateInfo,
David Blaikiea8fbc052011-11-09 05:30:24 +00001168 const VirtSpecifiers& VS,
Douglas Gregor45fa5602011-11-07 20:56:01 +00001169 ExprResult& Init);
Richard Smith7a614d82011-06-11 17:19:42 +00001170 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +00001171 void ParseLexedAttributes(ParsingClass &Class);
DeLesley Hutchinsc24a2332012-02-16 16:50:43 +00001172 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1173 bool EnterScope, bool OnDefinition);
1174 void ParseLexedAttribute(LateParsedAttribute &LA,
1175 bool EnterScope, bool OnDefinition);
Douglas Gregor37b372b2009-08-20 22:52:58 +00001176 void ParseLexedMethodDeclarations(ParsingClass &Class);
Douglas Gregord54eb442010-10-12 16:25:54 +00001177 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
Douglas Gregor37b372b2009-08-20 22:52:58 +00001178 void ParseLexedMethodDefs(ParsingClass &Class);
Douglas Gregord54eb442010-10-12 16:25:54 +00001179 void ParseLexedMethodDef(LexedMethod &LM);
Richard Smith7a614d82011-06-11 17:19:42 +00001180 void ParseLexedMemberInitializers(ParsingClass &Class);
1181 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
Fariborz Jahanian6c89eaf2012-07-02 23:37:09 +00001182 void ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod);
Sebastian Redla891a322011-09-30 08:32:17 +00001183 bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks);
Richard Smith9bd3cdc2013-09-12 23:28:08 +00001184 bool ConsumeAndStoreInitializer(CachedTokens &Toks, CachedInitKind CIK);
1185 bool ConsumeAndStoreConditional(CachedTokens &Toks);
Argyrios Kyrtzidis14b91622010-04-23 21:20:12 +00001186 bool ConsumeAndStoreUntil(tok::TokenKind T1,
1187 CachedTokens &Toks,
1188 bool StopAtSemi = true,
1189 bool ConsumeFinalToken = true) {
1190 return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken);
1191 }
Mike Stump1eb44332009-09-09 15:08:12 +00001192 bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
Douglas Gregor37b372b2009-08-20 22:52:58 +00001193 CachedTokens &Toks,
Argyrios Kyrtzidis14b91622010-04-23 21:20:12 +00001194 bool StopAtSemi = true,
Douglas Gregor37b372b2009-08-20 22:52:58 +00001195 bool ConsumeFinalToken = true);
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00001196
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +00001197 //===--------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +00001198 // C99 6.9: External Definitions.
John McCall7f040a92010-12-24 02:08:15 +00001199 struct ParsedAttributesWithRange : ParsedAttributes {
John McCall0b7e6782011-03-24 11:26:52 +00001200 ParsedAttributesWithRange(AttributeFactory &factory)
1201 : ParsedAttributes(factory) {}
1202
John McCall7f040a92010-12-24 02:08:15 +00001203 SourceRange Range;
1204 };
1205
1206 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001207 ParsingDeclSpec *DS = nullptr);
Sean Hunte4246a62011-05-12 06:15:49 +00001208 bool isDeclarationAfterDeclarator();
Chris Lattner004659a2010-07-11 22:42:07 +00001209 bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator);
Sean Hunt2edf0a22012-06-23 05:07:58 +00001210 DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(
1211 ParsedAttributesWithRange &attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001212 ParsingDeclSpec *DS = nullptr,
John McCall7f040a92010-12-24 02:08:15 +00001213 AccessSpecifier AS = AS_none);
Sean Hunt2edf0a22012-06-23 05:07:58 +00001214 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,
1215 ParsingDeclSpec &DS,
1216 AccessSpecifier AS);
David Blaikiea8fbc052011-11-09 05:30:24 +00001217
John McCalld226f652010-08-21 09:40:31 +00001218 Decl *ParseFunctionDefinition(ParsingDeclarator &D,
DeLesley Hutchinsc24a2332012-02-16 16:50:43 +00001219 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001220 LateParsedAttrList *LateParsedAttrs = nullptr);
Reid Spencer5f016e22007-07-11 17:01:13 +00001221 void ParseKNRParamDeclarations(Declarator &D);
Sebastian Redlab197ba2009-02-09 18:23:29 +00001222 // EndLoc, if non-NULL, is filled with the location of the last token of
1223 // the simple-asm.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001224 ExprResult ParseSimpleAsm(SourceLocation *EndLoc = nullptr);
John McCall60d7b3a2010-08-24 06:29:42 +00001225 ExprResult ParseAsmStringLiteral();
Reid Spencer5f016e22007-07-11 17:01:13 +00001226
Steve Naroff3536b442007-09-06 21:24:23 +00001227 // Objective-C External Declarations
Nico Webere145bfd2013-04-04 00:15:10 +00001228 void MaybeSkipAttributes(tok::ObjCKeywordKind Kind);
Douglas Gregorbd9482d2012-01-01 21:23:57 +00001229 DeclGroupPtrTy ParseObjCAtDirectives();
1230 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
Erik Verbruggend64251f2011-12-06 09:25:23 +00001231 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
John McCall7f040a92010-12-24 02:08:15 +00001232 ParsedAttributes &prefixAttrs);
Fariborz Jahanian4cc0cf12013-03-20 18:09:33 +00001233 void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc,
1234 BalancedDelimiterTracker &T,
1235 SmallVectorImpl<Decl *> &AllIvarDecls,
1236 bool RBraceMissing);
John McCalld226f652010-08-21 09:40:31 +00001237 void ParseObjCClassInstanceVariables(Decl *interfaceDecl,
Fariborz Jahanian83c481a2010-02-22 23:04:20 +00001238 tok::ObjCKeywordKind visibility,
Steve Naroff60fccee2007-10-29 21:38:07 +00001239 SourceLocation atLoc);
Chris Lattner686775d2011-07-20 06:58:45 +00001240 bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P,
1241 SmallVectorImpl<SourceLocation> &PLocs,
Mike Stump1eb44332009-09-09 15:08:12 +00001242 bool WarnOnDeclarations,
Argyrios Kyrtzidis71b0add2009-09-29 19:41:44 +00001243 SourceLocation &LAngleLoc,
Chris Lattnere13b9592008-07-26 04:03:38 +00001244 SourceLocation &EndProtoLoc);
Douglas Gregor46f936e2010-11-19 17:10:50 +00001245 bool ParseObjCProtocolQualifiers(DeclSpec &DS);
Fariborz Jahanian2f64cfe2011-08-22 21:44:58 +00001246 void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey,
1247 Decl *CDecl);
Douglas Gregorbd9482d2012-01-01 21:23:57 +00001248 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
1249 ParsedAttributes &prefixAttrs);
Mike Stump1eb44332009-09-09 15:08:12 +00001250
Argyrios Kyrtzidis849639d2012-02-07 16:50:53 +00001251 struct ObjCImplParsingDataRAII {
1252 Parser &P;
1253 Decl *Dcl;
Fariborz Jahanian6c89eaf2012-07-02 23:37:09 +00001254 bool HasCFunction;
Argyrios Kyrtzidis849639d2012-02-07 16:50:53 +00001255 typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer;
1256 LateParsedObjCMethodContainer LateParsedObjCMethods;
Steve Naroff0416fb92007-11-11 17:19:15 +00001257
Argyrios Kyrtzidis849639d2012-02-07 16:50:53 +00001258 ObjCImplParsingDataRAII(Parser &parser, Decl *D)
Fariborz Jahanian6c89eaf2012-07-02 23:37:09 +00001259 : P(parser), Dcl(D), HasCFunction(false) {
Argyrios Kyrtzidis849639d2012-02-07 16:50:53 +00001260 P.CurParsedObjCImpl = this;
1261 Finished = false;
1262 }
1263 ~ObjCImplParsingDataRAII();
1264
1265 void finish(SourceRange AtEnd);
1266 bool isFinished() const { return Finished; }
1267
1268 private:
1269 bool Finished;
1270 };
1271 ObjCImplParsingDataRAII *CurParsedObjCImpl;
Fariborz Jahanian6c89eaf2012-07-02 23:37:09 +00001272 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
Argyrios Kyrtzidis849639d2012-02-07 16:50:53 +00001273
1274 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc);
Fariborz Jahanian140ab232011-08-31 17:37:55 +00001275 DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd);
John McCalld226f652010-08-21 09:40:31 +00001276 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
1277 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
1278 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001279
Chris Lattner2fc5c242009-04-11 18:13:45 +00001280 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
Chris Lattner34870da2007-08-29 22:54:08 +00001281 // Definitions for Objective-c context sensitive keywords recognition.
1282 enum ObjCTypeQual {
1283 objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
1284 objc_NumQuals
1285 };
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001286 IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
Mike Stump1eb44332009-09-09 15:08:12 +00001287
Fariborz Jahanian335a2d42008-01-04 23:04:08 +00001288 bool isTokIdentifier_in() const;
Fariborz Jahaniand0f97d12007-08-31 16:11:31 +00001289
John McCallcdda47f2011-10-01 09:56:14 +00001290 ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, Declarator::TheContext Ctx,
1291 ParsedAttributes *ParamAttrs);
Steve Naroff294494e2007-08-22 16:35:03 +00001292 void ParseObjCMethodRequirement();
Fariborz Jahaniana28948f2011-08-22 15:54:49 +00001293 Decl *ParseObjCMethodPrototype(
Fariborz Jahanian90ba78c2011-03-12 18:54:30 +00001294 tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
1295 bool MethodDefinition = true);
John McCalld226f652010-08-21 09:40:31 +00001296 Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
Fariborz Jahanian90ba78c2011-03-12 18:54:30 +00001297 tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
1298 bool MethodDefinition=true);
Fariborz Jahaniana28948f2011-08-22 15:54:49 +00001299 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
Mike Stump1eb44332009-09-09 15:08:12 +00001300
John McCalld226f652010-08-21 09:40:31 +00001301 Decl *ParseObjCMethodDefinition();
Mike Stump1eb44332009-09-09 15:08:12 +00001302
Axel Naumann6944e202012-09-17 13:14:34 +00001303public:
Reid Spencer5f016e22007-07-11 17:01:13 +00001304 //===--------------------------------------------------------------------===//
1305 // C99 6.5: Expressions.
David Blaikiea8fbc052011-11-09 05:30:24 +00001306
Kaelyn Uhraincd78e612012-01-25 20:49:08 +00001307 /// TypeCastState - State whether an expression is or may be a type cast.
1308 enum TypeCastState {
1309 NotTypeCast = 0,
1310 MaybeTypeCast,
1311 IsTypeCast
1312 };
1313
1314 ExprResult ParseExpression(TypeCastState isTypeCast = NotTypeCast);
Kaelyn Uhraine43fe992012-02-22 01:03:07 +00001315 ExprResult ParseConstantExpression(TypeCastState isTypeCast = NotTypeCast);
Sebastian Redl2f7ece72008-12-11 21:36:32 +00001316 // Expr that doesn't include commas.
Kaelyn Uhraincd78e612012-01-25 20:49:08 +00001317 ExprResult ParseAssignmentExpression(TypeCastState isTypeCast = NotTypeCast);
Sebastian Redl2f7ece72008-12-11 21:36:32 +00001318
John McCallaeeacf72013-05-03 00:10:13 +00001319 ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl<Token> &LineToks,
1320 unsigned &NumLineToksConsumed,
1321 void *Info,
1322 bool IsUnevaluated);
1323
Axel Naumann6944e202012-09-17 13:14:34 +00001324private:
John McCall60d7b3a2010-08-24 06:29:42 +00001325 ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00001326
John McCall60d7b3a2010-08-24 06:29:42 +00001327 ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc);
Eli Friedmanadf077f2009-01-27 08:43:38 +00001328
John McCall60d7b3a2010-08-24 06:29:42 +00001329 ExprResult ParseRHSOfBinaryExpression(ExprResult LHS,
Douglas Gregor312eadb2011-04-24 05:37:28 +00001330 prec::Level MinPrec);
John McCall60d7b3a2010-08-24 06:29:42 +00001331 ExprResult ParseCastExpression(bool isUnaryExpression,
Douglas Gregor312eadb2011-04-24 05:37:28 +00001332 bool isAddressOfOperand,
1333 bool &NotCastExpr,
Kaelyn Uhraincd78e612012-01-25 20:49:08 +00001334 TypeCastState isTypeCast);
John McCall60d7b3a2010-08-24 06:29:42 +00001335 ExprResult ParseCastExpression(bool isUnaryExpression,
Douglas Gregor312eadb2011-04-24 05:37:28 +00001336 bool isAddressOfOperand = false,
Kaelyn Uhraincd78e612012-01-25 20:49:08 +00001337 TypeCastState isTypeCast = NotTypeCast);
John McCall9c72c602010-08-27 09:08:28 +00001338
Richard Smith4b082422012-09-18 00:52:05 +00001339 /// Returns true if the next token cannot start an expression.
1340 bool isNotExpressionStart();
1341
John McCall9c72c602010-08-27 09:08:28 +00001342 /// Returns true if the next token would start a postfix-expression
1343 /// suffix.
1344 bool isPostfixExpressionSuffixStart() {
1345 tok::TokenKind K = Tok.getKind();
1346 return (K == tok::l_square || K == tok::l_paren ||
1347 K == tok::period || K == tok::arrow ||
1348 K == tok::plusplus || K == tok::minusminus);
1349 }
1350
John McCall60d7b3a2010-08-24 06:29:42 +00001351 ExprResult ParsePostfixExpressionSuffix(ExprResult LHS);
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001352 ExprResult ParseUnaryExprOrTypeTraitExpression();
John McCall60d7b3a2010-08-24 06:29:42 +00001353 ExprResult ParseBuiltinPrimaryExpression();
Mike Stump1eb44332009-09-09 15:08:12 +00001354
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001355 ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
Argyrios Kyrtzidis5ab06402009-05-22 10:22:50 +00001356 bool &isCastExpr,
John McCallb3d87482010-08-24 05:47:05 +00001357 ParsedType &CastTy,
Argyrios Kyrtzidis5ab06402009-05-22 10:22:50 +00001358 SourceRange &CastRange);
Argyrios Kyrtzidis0cd5b422008-08-16 20:03:01 +00001359
Chris Lattner686775d2011-07-20 06:58:45 +00001360 typedef SmallVector<Expr*, 20> ExprListTy;
1361 typedef SmallVector<SourceLocation, 20> CommaLocsTy;
Argyrios Kyrtzidis0cd5b422008-08-16 20:03:01 +00001362
1363 /// ParseExpressionList - Used for C/C++ (argument-)expression-list.
Stephen Hines0e2c34f2015-03-23 12:09:02 -07001364 bool ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
1365 SmallVectorImpl<SourceLocation> &CommaLocs,
1366 std::function<void()> Completer = nullptr);
Sebastian Redld8c4e152008-12-11 22:33:27 +00001367
Eli Friedman4fce06c2013-08-13 23:38:34 +00001368 /// ParseSimpleExpressionList - A simple comma-separated list of expressions,
1369 /// used for misc language extensions.
1370 bool ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
1371 SmallVectorImpl<SourceLocation> &CommaLocs);
1372
1373
Reid Spencer5f016e22007-07-11 17:01:13 +00001374 /// ParenParseOption - Control what ParseParenExpression will parse.
1375 enum ParenParseOption {
1376 SimpleExpr, // Only parse '(' expression ')'
1377 CompoundStmt, // Also allow '(' compound-statement ')'
1378 CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
1379 CastExpr // Also allow '(' type-name ')' <anything>
1380 };
John McCall60d7b3a2010-08-24 06:29:42 +00001381 ExprResult ParseParenExpression(ParenParseOption &ExprType,
Argyrios Kyrtzidis0350ca52009-05-22 10:23:40 +00001382 bool stopIfCastExpr,
Argyrios Kyrtzidis0a851832011-07-01 22:22:59 +00001383 bool isTypeCast,
John McCallb3d87482010-08-24 05:47:05 +00001384 ParsedType &CastTy,
Sebastian Redld8c4e152008-12-11 22:33:27 +00001385 SourceLocation &RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001386
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001387 ExprResult ParseCXXAmbiguousParenExpression(
1388 ParenParseOption &ExprType, ParsedType &CastTy,
1389 BalancedDelimiterTracker &Tracker, ColonProtectionRAIIObject &ColonProt);
John McCall60d7b3a2010-08-24 06:29:42 +00001390 ExprResult ParseCompoundLiteralExpression(ParsedType Ty,
Argyrios Kyrtzidisd974a7b2009-05-22 10:24:05 +00001391 SourceLocation LParenLoc,
1392 SourceLocation RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001393
Richard Smith99831e42012-03-06 03:21:47 +00001394 ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral = false);
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001395
Peter Collingbournef111d932011-04-15 00:35:48 +00001396 ExprResult ParseGenericSelectionExpression();
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001397
1398 ExprResult ParseObjCBoolLiteral();
Peter Collingbournef111d932011-04-15 00:35:48 +00001399
Stephen Hines176edba2014-12-01 14:53:08 -08001400 ExprResult ParseFoldExpression(ExprResult LHS, BalancedDelimiterTracker &T);
1401
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001402 //===--------------------------------------------------------------------===//
1403 // C++ Expressions
Stephen Hines176edba2014-12-01 14:53:08 -08001404 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS, bool isAddressOfOperand,
1405 Token &Replacement);
John McCall60d7b3a2010-08-24 06:29:42 +00001406 ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false);
Argyrios Kyrtzidis4bdd91c2008-11-26 21:41:52 +00001407
Richard Smith19a27022012-06-18 06:11:04 +00001408 bool areTokensAdjacent(const Token &A, const Token &B);
1409
Richard Trieu950be712011-09-19 19:01:00 +00001410 void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr,
1411 bool EnteringContext, IdentifierInfo &II,
1412 CXXScopeSpec &SS);
1413
Mike Stump1eb44332009-09-09 15:08:12 +00001414 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
John McCallb3d87482010-08-24 05:47:05 +00001415 ParsedType ObjectType,
Douglas Gregorb10cd042010-02-21 18:36:56 +00001416 bool EnteringContext,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001417 bool *MayBePseudoDestructor = nullptr,
Richard Smith2db075b2013-03-26 01:15:19 +00001418 bool IsTypename = false,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001419 IdentifierInfo **LastII = nullptr);
Mike Stump1eb44332009-09-09 15:08:12 +00001420
Richard Trieu919b9552012-11-02 01:08:58 +00001421 void CheckForLParenAfterColonColon();
1422
Reid Spencer5f016e22007-07-11 17:01:13 +00001423 //===--------------------------------------------------------------------===//
Douglas Gregorae7902c2011-08-04 15:30:47 +00001424 // C++0x 5.1.2: Lambda expressions
1425
1426 // [...] () -> type {...}
1427 ExprResult ParseLambdaExpression();
1428 ExprResult TryParseLambdaExpression();
Richard Smith440d4562013-05-21 22:21:19 +00001429 Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001430 bool *SkippedInits = nullptr);
Douglas Gregorae7902c2011-08-04 15:30:47 +00001431 bool TryParseLambdaIntroducer(LambdaIntroducer &Intro);
1432 ExprResult ParseLambdaExpressionAfterIntroducer(
1433 LambdaIntroducer &Intro);
1434
1435 //===--------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +00001436 // C++ 5.2p1: C++ Casts
John McCall60d7b3a2010-08-24 06:29:42 +00001437 ExprResult ParseCXXCasts();
Reid Spencer5f016e22007-07-11 17:01:13 +00001438
1439 //===--------------------------------------------------------------------===//
Sebastian Redlc42e1182008-11-11 11:37:55 +00001440 // C++ 5.2p1: C++ Type Identification
John McCall60d7b3a2010-08-24 06:29:42 +00001441 ExprResult ParseCXXTypeid();
Sebastian Redlc42e1182008-11-11 11:37:55 +00001442
1443 //===--------------------------------------------------------------------===//
Francois Pichet01b7c302010-09-08 12:20:18 +00001444 // C++ : Microsoft __uuidof Expression
1445 ExprResult ParseCXXUuidof();
1446
1447 //===--------------------------------------------------------------------===//
Douglas Gregord4dca082010-02-24 18:44:31 +00001448 // C++ 5.2.4: C++ Pseudo-Destructor Expressions
Stephen Hines176edba2014-12-01 14:53:08 -08001449 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
Douglas Gregord4dca082010-02-24 18:44:31 +00001450 tok::TokenKind OpKind,
1451 CXXScopeSpec &SS,
John McCallb3d87482010-08-24 05:47:05 +00001452 ParsedType ObjectType);
Douglas Gregord4dca082010-02-24 18:44:31 +00001453
1454 //===--------------------------------------------------------------------===//
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +00001455 // C++ 9.3.2: C++ 'this' pointer
John McCall60d7b3a2010-08-24 06:29:42 +00001456 ExprResult ParseCXXThis();
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +00001457
1458 //===--------------------------------------------------------------------===//
Chris Lattner50dd2892008-02-26 00:51:44 +00001459 // C++ 15: C++ Throw Expression
John McCall60d7b3a2010-08-24 06:29:42 +00001460 ExprResult ParseThrowExpression();
Sebastian Redl7acafd02011-03-05 14:45:16 +00001461
Douglas Gregor74e2fc32012-04-16 18:27:27 +00001462 ExceptionSpecificationType tryParseExceptionSpecification(
Stephen Hines176edba2014-12-01 14:53:08 -08001463 bool Delayed,
Sebastian Redl7acafd02011-03-05 14:45:16 +00001464 SourceRange &SpecificationRange,
Chris Lattner686775d2011-07-20 06:58:45 +00001465 SmallVectorImpl<ParsedType> &DynamicExceptions,
1466 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
Stephen Hines176edba2014-12-01 14:53:08 -08001467 ExprResult &NoexceptExpr,
1468 CachedTokens *&ExceptionSpecTokens);
Sebastian Redl7acafd02011-03-05 14:45:16 +00001469
Sebastian Redlab197ba2009-02-09 18:23:29 +00001470 // EndLoc is filled with the location of the last token of the specification.
Sebastian Redl7acafd02011-03-05 14:45:16 +00001471 ExceptionSpecificationType ParseDynamicExceptionSpecification(
1472 SourceRange &SpecificationRange,
Chris Lattner686775d2011-07-20 06:58:45 +00001473 SmallVectorImpl<ParsedType> &Exceptions,
1474 SmallVectorImpl<SourceRange> &Ranges);
Chris Lattner50dd2892008-02-26 00:51:44 +00001475
1476 //===--------------------------------------------------------------------===//
Douglas Gregordab60ad2010-10-01 18:44:50 +00001477 // C++0x 8: Function declaration trailing-return-type
Douglas Gregorae7902c2011-08-04 15:30:47 +00001478 TypeResult ParseTrailingReturnType(SourceRange &Range);
Douglas Gregordab60ad2010-10-01 18:44:50 +00001479
1480 //===--------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +00001481 // C++ 2.13.5: C++ Boolean Literals
John McCall60d7b3a2010-08-24 06:29:42 +00001482 ExprResult ParseCXXBoolLiteral();
Reid Spencer5f016e22007-07-11 17:01:13 +00001483
1484 //===--------------------------------------------------------------------===//
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +00001485 // C++ 5.2.3: Explicit type conversion (functional notation)
John McCall60d7b3a2010-08-24 06:29:42 +00001486 ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS);
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +00001487
1488 /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
1489 /// This should only be called when the current token is known to be part of
1490 /// simple-type-specifier.
1491 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
1492
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001493 bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
1494
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +00001495 //===--------------------------------------------------------------------===//
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001496 // C++ 5.3.4 and 5.3.5: C++ new and delete
Chris Lattner686775d2011-07-20 06:58:45 +00001497 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs,
John McCallca0408f2010-08-23 06:44:23 +00001498 Declarator &D);
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001499 void ParseDirectNewDeclarator(Declarator &D);
John McCall60d7b3a2010-08-24 06:29:42 +00001500 ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start);
1501 ExprResult ParseCXXDeleteExpression(bool UseGlobal,
Chris Lattner59232d32009-01-04 21:25:24 +00001502 SourceLocation Start);
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001503
1504 //===--------------------------------------------------------------------===//
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00001505 // C++ if/switch/while condition expression.
John McCall60d7b3a2010-08-24 06:29:42 +00001506 bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult,
Douglas Gregor586596f2010-05-06 17:25:47 +00001507 SourceLocation Loc, bool ConvertToBoolean);
Argyrios Kyrtzidis71b914b2008-09-09 20:38:47 +00001508
1509 //===--------------------------------------------------------------------===//
Douglas Gregor12e083c2008-11-07 15:42:26 +00001510 // C++ types
1511
1512 //===--------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +00001513 // C99 6.7.8: Initialization.
Mike Stump1eb44332009-09-09 15:08:12 +00001514
Chris Lattner0eec2b52008-10-26 22:38:55 +00001515 /// ParseInitializer
1516 /// initializer: [C99 6.7.8]
1517 /// assignment-expression
1518 /// '{' ...
John McCall60d7b3a2010-08-24 06:29:42 +00001519 ExprResult ParseInitializer() {
Chris Lattner0eec2b52008-10-26 22:38:55 +00001520 if (Tok.isNot(tok::l_brace))
Sebastian Redl20df9b72008-12-11 22:51:44 +00001521 return ParseAssignmentExpression();
Chris Lattner0eec2b52008-10-26 22:38:55 +00001522 return ParseBraceInitializer();
1523 }
Douglas Gregorb3f323d2012-02-17 03:49:44 +00001524 bool MayBeDesignationStart();
John McCall60d7b3a2010-08-24 06:29:42 +00001525 ExprResult ParseBraceInitializer();
1526 ExprResult ParseInitializerWithPotentialDesignator();
Sebastian Redl1d922962008-12-13 15:32:12 +00001527
Reid Spencer5f016e22007-07-11 17:01:13 +00001528 //===--------------------------------------------------------------------===//
Steve Naroff296e8d52008-08-28 19:20:44 +00001529 // clang Expressions
Sebastian Redl1d922962008-12-13 15:32:12 +00001530
John McCall60d7b3a2010-08-24 06:29:42 +00001531 ExprResult ParseBlockLiteralExpression(); // ^{...}
Steve Naroff296e8d52008-08-28 19:20:44 +00001532
1533 //===--------------------------------------------------------------------===//
Anders Carlsson55085182007-08-21 17:43:55 +00001534 // Objective-C Expressions
John McCall60d7b3a2010-08-24 06:29:42 +00001535 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
1536 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001537 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
1538 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
1539 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc, bool ArgValue);
1540 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
1541 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
Patrick Beardeb382ec2012-04-19 00:25:12 +00001542 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001543 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
Fariborz Jahanian48f3cc22013-01-22 18:35:43 +00001544 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00001545 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
Douglas Gregor1b730e82010-05-31 14:40:22 +00001546 bool isSimpleObjCMessageExpression();
John McCall60d7b3a2010-08-24 06:29:42 +00001547 ExprResult ParseObjCMessageExpression();
1548 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
Nico Weber5cb94a72011-12-22 23:26:17 +00001549 SourceLocation SuperLoc,
1550 ParsedType ReceiverType,
Stephen Hines176edba2014-12-01 14:53:08 -08001551 Expr *ReceiverExpr);
John McCall60d7b3a2010-08-24 06:29:42 +00001552 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
Douglas Gregor2725ca82010-04-21 19:57:20 +00001553 SourceLocation LBracloc, SourceLocation SuperLoc,
Stephen Hines176edba2014-12-01 14:53:08 -08001554 ParsedType ReceiverType, Expr *ReceiverExpr);
Douglas Gregor6aa14d82010-04-21 22:36:40 +00001555 bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001556
Anders Carlsson55085182007-08-21 17:43:55 +00001557 //===--------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +00001558 // C99 6.8: Statements and Blocks.
Sebastian Redl61364dd2008-12-11 19:30:53 +00001559
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00001560 /// A SmallVector of statements, with stack size 32 (as that is the only one
1561 /// used.)
1562 typedef SmallVector<Stmt*, 32> StmtVector;
1563 /// A SmallVector of expressions, with stack size 12 (the maximum used.)
1564 typedef SmallVector<Expr*, 12> ExprVector;
1565 /// A SmallVector of types.
1566 typedef SmallVector<ParsedType, 12> TypeVector;
1567
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001568 StmtResult ParseStatement(SourceLocation *TrailingElseLoc = nullptr);
1569 StmtResult
1570 ParseStatementOrDeclaration(StmtVector &Stmts, bool OnlyStatement,
1571 SourceLocation *TrailingElseLoc = nullptr);
Richard Smith534986f2012-04-14 00:33:13 +00001572 StmtResult ParseStatementOrDeclarationAfterAttributes(
1573 StmtVector &Stmts,
1574 bool OnlyStatement,
1575 SourceLocation *TrailingElseLoc,
1576 ParsedAttributesWithRange &Attrs);
1577 StmtResult ParseExprStatement();
1578 StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs);
1579 StmtResult ParseCaseStatement(bool MissingCase = false,
Richard Trieubb9b80c2011-04-21 21:44:26 +00001580 ExprResult Expr = ExprResult());
Richard Smith534986f2012-04-14 00:33:13 +00001581 StmtResult ParseDefaultStatement();
1582 StmtResult ParseCompoundStatement(bool isStmtExpr = false);
1583 StmtResult ParseCompoundStatement(bool isStmtExpr,
Douglas Gregorbca01b42011-07-06 22:04:06 +00001584 unsigned ScopeFlags);
Lang Hamesa60d21d2012-11-03 22:29:05 +00001585 void ParseCompoundStatementLeadingPragmas();
John McCall60d7b3a2010-08-24 06:29:42 +00001586 StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
1587 bool ParseParenExprOrCondition(ExprResult &ExprResult,
John McCalld226f652010-08-21 09:40:31 +00001588 Decl *&DeclResult,
Douglas Gregor586596f2010-05-06 17:25:47 +00001589 SourceLocation Loc,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001590 bool ConvertToBoolean);
Richard Smith534986f2012-04-14 00:33:13 +00001591 StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
1592 StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
1593 StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);
1594 StmtResult ParseDoStatement();
1595 StmtResult ParseForStatement(SourceLocation *TrailingElseLoc);
1596 StmtResult ParseGotoStatement();
1597 StmtResult ParseContinueStatement();
1598 StmtResult ParseBreakStatement();
1599 StmtResult ParseReturnStatement();
John McCall60d7b3a2010-08-24 06:29:42 +00001600 StmtResult ParseAsmStatement(bool &msAsm);
Eli Friedman3fedbe12011-09-30 01:13:51 +00001601 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001602 StmtResult ParsePragmaLoopHint(StmtVector &Stmts, bool OnlyStatement,
1603 SourceLocation *TrailingElseLoc,
1604 ParsedAttributesWithRange &Attrs);
David Blaikiea8fbc052011-11-09 05:30:24 +00001605
Douglas Gregor3896fc52011-10-24 22:31:10 +00001606 /// \brief Describes the behavior that should be taken for an __if_exists
1607 /// block.
1608 enum IfExistsBehavior {
1609 /// \brief Parse the block; this code is always used.
1610 IEB_Parse,
1611 /// \brief Skip the block entirely; this code is never used.
1612 IEB_Skip,
1613 /// \brief Parse the block as a dependent block, which may be used in
1614 /// some template instantiations but not others.
1615 IEB_Dependent
1616 };
David Blaikiea8fbc052011-11-09 05:30:24 +00001617
1618 /// \brief Describes the condition of a Microsoft __if_exists or
Douglas Gregor3896fc52011-10-24 22:31:10 +00001619 /// __if_not_exists block.
1620 struct IfExistsCondition {
1621 /// \brief The location of the initial keyword.
1622 SourceLocation KeywordLoc;
David Blaikiea8fbc052011-11-09 05:30:24 +00001623 /// \brief Whether this is an __if_exists block (rather than an
Douglas Gregor3896fc52011-10-24 22:31:10 +00001624 /// __if_not_exists block).
1625 bool IsIfExists;
David Blaikiea8fbc052011-11-09 05:30:24 +00001626
Douglas Gregor3896fc52011-10-24 22:31:10 +00001627 /// \brief Nested-name-specifier preceding the name.
1628 CXXScopeSpec SS;
David Blaikiea8fbc052011-11-09 05:30:24 +00001629
Douglas Gregor3896fc52011-10-24 22:31:10 +00001630 /// \brief The name we're looking for.
1631 UnqualifiedId Name;
1632
1633 /// \brief The behavior of this __if_exists or __if_not_exists block
1634 /// should.
1635 IfExistsBehavior Behavior;
Richard Smith534986f2012-04-14 00:33:13 +00001636 };
David Blaikiea8fbc052011-11-09 05:30:24 +00001637
Douglas Gregor3896fc52011-10-24 22:31:10 +00001638 bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result);
Francois Pichet1e862692011-05-06 20:48:22 +00001639 void ParseMicrosoftIfExistsStatement(StmtVector &Stmts);
Francois Pichet563a6452011-05-25 10:19:49 +00001640 void ParseMicrosoftIfExistsExternalDeclaration();
1641 void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType,
1642 AccessSpecifier& CurAS);
Francois Pichet9d24a8b2011-12-12 23:24:39 +00001643 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
1644 bool &InitExprsOk);
Richard Trieuf81e5a92011-09-09 02:00:50 +00001645 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
1646 SmallVectorImpl<Expr *> &Constraints,
1647 SmallVectorImpl<Expr *> &Exprs);
Sebastian Redla0fd8652008-12-21 16:41:36 +00001648
1649 //===--------------------------------------------------------------------===//
1650 // C++ 6: Statements and Blocks
1651
Richard Smith534986f2012-04-14 00:33:13 +00001652 StmtResult ParseCXXTryBlock();
David Blaikiec4027c82012-11-10 01:04:23 +00001653 StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc, bool FnTry = false);
1654 StmtResult ParseCXXCatchBlock(bool FnCatch = false);
Sebastian Redla0fd8652008-12-21 16:41:36 +00001655
1656 //===--------------------------------------------------------------------===//
John Wiegley28bbe4b2011-04-28 01:08:34 +00001657 // MS: SEH Statements and Blocks
1658
Richard Smith534986f2012-04-14 00:33:13 +00001659 StmtResult ParseSEHTryBlock();
John Wiegley28bbe4b2011-04-28 01:08:34 +00001660 StmtResult ParseSEHExceptBlock(SourceLocation Loc);
1661 StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001662 StmtResult ParseSEHLeaveStatement();
John Wiegley28bbe4b2011-04-28 01:08:34 +00001663
1664 //===--------------------------------------------------------------------===//
Sebastian Redla0fd8652008-12-21 16:41:36 +00001665 // Objective-C Statements
1666
John McCall60d7b3a2010-08-24 06:29:42 +00001667 StmtResult ParseObjCAtStatement(SourceLocation atLoc);
1668 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
1669 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
1670 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
John McCallf85e1932011-06-15 23:02:42 +00001671 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
Anders Carlssonb235fc22007-11-22 01:36:19 +00001672
Reid Spencer5f016e22007-07-11 17:01:13 +00001673
1674 //===--------------------------------------------------------------------===//
1675 // C99 6.7: Declarations.
John McCall67d1a672009-08-06 02:15:43 +00001676
1677 /// A context for parsing declaration specifiers. TODO: flesh this
1678 /// out, there are other significant restrictions on specifiers than
1679 /// would be best implemented in the parser.
1680 enum DeclSpecContext {
1681 DSC_normal, // normal context
Douglas Gregor0efc2c12010-01-13 17:31:36 +00001682 DSC_class, // class context, enables 'friend'
Richard Smitha971d242012-05-09 20:55:26 +00001683 DSC_type_specifier, // C++ type-specifier-seq or C specifier-qualifier-list
Richard Smith7796eb52012-03-12 08:56:40 +00001684 DSC_trailing, // C++11 trailing-type-specifier in a trailing return type
Stephen Hines651f13c2014-04-23 16:59:28 -07001685 DSC_alias_declaration, // C++11 type-specifier-seq in an alias-declaration
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001686 DSC_top_level, // top-level/namespace declaration context
1687 DSC_template_type_arg // template type argument context
John McCall67d1a672009-08-06 02:15:43 +00001688 };
Mike Stump1eb44332009-09-09 15:08:12 +00001689
Stephen Hines651f13c2014-04-23 16:59:28 -07001690 /// Is this a context in which we are parsing just a type-specifier (or
1691 /// trailing-type-specifier)?
1692 static bool isTypeSpecifier(DeclSpecContext DSC) {
1693 switch (DSC) {
1694 case DSC_normal:
1695 case DSC_class:
1696 case DSC_top_level:
1697 return false;
1698
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001699 case DSC_template_type_arg:
Stephen Hines651f13c2014-04-23 16:59:28 -07001700 case DSC_type_specifier:
1701 case DSC_trailing:
1702 case DSC_alias_declaration:
1703 return true;
1704 }
1705 llvm_unreachable("Missing DeclSpecContext case");
1706 }
1707
Richard Smithad762fc2011-04-14 22:09:26 +00001708 /// Information on a C++0x for-range-initializer found while parsing a
1709 /// declaration which turns out to be a for-range-declaration.
1710 struct ForRangeInit {
1711 SourceLocation ColonLoc;
1712 ExprResult RangeExpr;
1713
1714 bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); }
1715 };
1716
Stephen Hines176edba2014-12-01 14:53:08 -08001717 DeclGroupPtrTy ParseDeclaration(unsigned Context, SourceLocation &DeclEnd,
John McCall7f040a92010-12-24 02:08:15 +00001718 ParsedAttributesWithRange &attrs);
Stephen Hines176edba2014-12-01 14:53:08 -08001719 DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context,
Sean Huntbbd37c62009-11-21 08:43:09 +00001720 SourceLocation &DeclEnd,
Sean Hunt2edf0a22012-06-23 05:07:58 +00001721 ParsedAttributesWithRange &attrs,
Richard Smithad762fc2011-04-14 22:09:26 +00001722 bool RequireSemi,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001723 ForRangeInit *FRI = nullptr);
Richard Smith0706df42011-10-19 21:33:05 +00001724 bool MightBeDeclarator(unsigned Context);
John McCall54abf7d2009-11-04 02:18:39 +00001725 DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001726 SourceLocation *DeclEnd = nullptr,
1727 ForRangeInit *FRI = nullptr);
John McCalld226f652010-08-21 09:40:31 +00001728 Decl *ParseDeclarationAfterDeclarator(Declarator &D,
Douglas Gregore542c862009-06-23 23:11:28 +00001729 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
DeLesley Hutchinsc24a2332012-02-16 16:50:43 +00001730 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001731 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1732 Declarator &D,
1733 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1734 ForRangeInit *FRI = nullptr);
Douglas Gregorc9977d02011-03-16 17:05:57 +00001735 Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope);
1736 Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope);
Sebastian Redld3a413d2009-04-26 20:35:05 +00001737
Argyrios Kyrtzidis0fe53972011-01-03 22:33:06 +00001738 /// \brief When in code-completion, skip parsing of the function/method body
1739 /// unless the body contains the code-completion point.
1740 ///
1741 /// \returns true if the function body was skipped.
Erik Verbruggen6a91d382012-04-12 10:11:59 +00001742 bool trySkippingFunctionBody();
Argyrios Kyrtzidis0fe53972011-01-03 22:33:06 +00001743
Chris Lattnerf4382f52009-04-14 22:17:06 +00001744 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00001745 const ParsedTemplateInfo &TemplateInfo,
Michael Han2e397132012-11-26 22:54:45 +00001746 AccessSpecifier AS, DeclSpecContext DSC,
1747 ParsedAttributesWithRange &Attrs);
Douglas Gregor0efc2c12010-01-13 17:31:36 +00001748 DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context);
Mike Stump1eb44332009-09-09 15:08:12 +00001749 void ParseDeclarationSpecifiers(DeclSpec &DS,
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00001750 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
John McCall67d1a672009-08-06 02:15:43 +00001751 AccessSpecifier AS = AS_none,
DeLesley Hutchins2287c5e2012-03-02 22:12:59 +00001752 DeclSpecContext DSC = DSC_normal,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001753 LateParsedAttrList *LateAttrs = nullptr);
Bill Wendlingf0cc19f2013-11-19 22:56:43 +00001754 bool DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS, AccessSpecifier AS,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001755 DeclSpecContext DSContext,
1756 LateParsedAttrList *LateAttrs = nullptr);
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00001757
Richard Smith69730c12012-03-12 07:56:15 +00001758 void ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS = AS_none,
1759 DeclSpecContext DSC = DSC_normal);
Mike Stump1eb44332009-09-09 15:08:12 +00001760
John McCallcdda47f2011-10-01 09:56:14 +00001761 void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
1762 Declarator::TheContext Context);
Reid Spencer5f016e22007-07-11 17:01:13 +00001763
Chris Lattner4c97d762009-04-12 21:49:30 +00001764 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
Richard Smith69730c12012-03-12 07:56:15 +00001765 const ParsedTemplateInfo &TemplateInfo,
1766 AccessSpecifier AS, DeclSpecContext DSC);
John McCalld226f652010-08-21 09:40:31 +00001767 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
Reid Spencer5f016e22007-07-11 17:01:13 +00001768 void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
John McCalld226f652010-08-21 09:40:31 +00001769 Decl *TagDecl);
John McCallbdd563e2009-11-03 02:38:08 +00001770
Stephen Hines176edba2014-12-01 14:53:08 -08001771 void ParseStructDeclaration(
1772 ParsingDeclSpec &DS,
1773 llvm::function_ref<void(ParsingFieldDeclarator &)> FieldsCallback);
Mike Stump1eb44332009-09-09 15:08:12 +00001774
Douglas Gregor9497a732010-09-16 01:51:54 +00001775 bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001776 bool isTypeSpecifierQualifier();
Steve Naroff5f8aa692008-02-11 23:15:56 +00001777 bool isTypeQualifier() const;
David Blaikiea8fbc052011-11-09 05:30:24 +00001778
Chris Lattnerb3a4e432010-02-28 18:18:36 +00001779 /// isKnownToBeTypeSpecifier - Return true if we know that the specified token
1780 /// is definitely a type-specifier. Return false if it isn't part of a type
1781 /// specifier or if we're not sure.
1782 bool isKnownToBeTypeSpecifier(const Token &Tok) const;
Reid Spencer5f016e22007-07-11 17:01:13 +00001783
Richard Smith4b082422012-09-18 00:52:05 +00001784 /// \brief Return true if we know that we are definitely looking at a
1785 /// decl-specifier, and isn't part of an expression such as a function-style
1786 /// cast. Return false if it's no a decl-specifier, or we're not sure.
1787 bool isKnownToBeDeclarationSpecifier() {
1788 if (getLangOpts().CPlusPlus)
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001789 return isCXXDeclarationSpecifier() == TPResult::True;
Richard Smith4b082422012-09-18 00:52:05 +00001790 return isDeclarationSpecifier(true);
1791 }
1792
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001793 /// isDeclarationStatement - Disambiguates between a declaration or an
1794 /// expression statement, when parsing function bodies.
1795 /// Returns true for declaration, false for expression.
1796 bool isDeclarationStatement() {
David Blaikie4e4d0842012-03-11 07:00:24 +00001797 if (getLangOpts().CPlusPlus)
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001798 return isCXXDeclarationStatement();
Douglas Gregor9497a732010-09-16 01:51:54 +00001799 return isDeclarationSpecifier(true);
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001800 }
1801
Eli Friedman9490ab42011-12-20 01:50:37 +00001802 /// isForInitDeclaration - Disambiguates between a declaration or an
1803 /// expression in the context of the C 'clause-1' or the C++
Argyrios Kyrtzidisbbc70c02008-10-05 15:50:46 +00001804 // 'for-init-statement' part of a 'for' statement.
1805 /// Returns true for declaration, false for expression.
Eli Friedman9490ab42011-12-20 01:50:37 +00001806 bool isForInitDeclaration() {
David Blaikie4e4d0842012-03-11 07:00:24 +00001807 if (getLangOpts().CPlusPlus)
Eli Friedman9490ab42011-12-20 01:50:37 +00001808 return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/true);
Douglas Gregor9497a732010-09-16 01:51:54 +00001809 return isDeclarationSpecifier(true);
Argyrios Kyrtzidisbbc70c02008-10-05 15:50:46 +00001810 }
1811
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001812 /// \brief Determine whether this is a C++1z for-range-identifier.
1813 bool isForRangeIdentifier();
1814
Douglas Gregor9497a732010-09-16 01:51:54 +00001815 /// \brief Determine whether we are currently at the start of an Objective-C
1816 /// class message that appears to be missing the open bracket '['.
1817 bool isStartOfObjCClassMessageMissingOpenBracket();
David Blaikiea8fbc052011-11-09 05:30:24 +00001818
Douglas Gregor0efc2c12010-01-13 17:31:36 +00001819 /// \brief Starting with a scope specifier, identifier, or
1820 /// template-id that refers to the current class, determine whether
1821 /// this is a constructor declarator.
Stephen Hines651f13c2014-04-23 16:59:28 -07001822 bool isConstructorDeclarator(bool Unqualified);
Douglas Gregor0efc2c12010-01-13 17:31:36 +00001823
Douglas Gregor8b642592009-02-10 00:53:15 +00001824 /// \brief Specifies the context in which type-id/expression
1825 /// disambiguation will occur.
1826 enum TentativeCXXTypeIdContext {
1827 TypeIdInParens,
Stephen Hines651f13c2014-04-23 16:59:28 -07001828 TypeIdUnambiguous,
Douglas Gregor8b642592009-02-10 00:53:15 +00001829 TypeIdAsTemplateArgument
1830 };
1831
1832
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +00001833 /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know
1834 /// whether the parens contain an expression or a type-id.
1835 /// Returns true for a type-id and false for an expression.
Argyrios Kyrtzidisf58f45e2009-05-22 10:24:42 +00001836 bool isTypeIdInParens(bool &isAmbiguous) {
David Blaikie4e4d0842012-03-11 07:00:24 +00001837 if (getLangOpts().CPlusPlus)
Argyrios Kyrtzidisf58f45e2009-05-22 10:24:42 +00001838 return isCXXTypeId(TypeIdInParens, isAmbiguous);
1839 isAmbiguous = false;
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +00001840 return isTypeSpecifierQualifier();
1841 }
Argyrios Kyrtzidisf58f45e2009-05-22 10:24:42 +00001842 bool isTypeIdInParens() {
1843 bool isAmbiguous;
1844 return isTypeIdInParens(isAmbiguous);
1845 }
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +00001846
Stephen Hines651f13c2014-04-23 16:59:28 -07001847 /// \brief Checks if the current tokens form type-id or expression.
1848 /// It is similar to isTypeIdInParens but does not suppose that type-id
1849 /// is in parenthesis.
1850 bool isTypeIdUnambiguously() {
1851 bool IsAmbiguous;
1852 if (getLangOpts().CPlusPlus)
1853 return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous);
1854 return isTypeSpecifierQualifier();
1855 }
1856
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001857 /// isCXXDeclarationStatement - C++-specialized function that disambiguates
1858 /// between a declaration or an expression statement, when parsing function
1859 /// bodies. Returns true for declaration, false for expression.
1860 bool isCXXDeclarationStatement();
1861
1862 /// isCXXSimpleDeclaration - C++-specialized function that disambiguates
1863 /// between a simple-declaration or an expression-statement.
1864 /// If during the disambiguation process a parsing error is encountered,
1865 /// the function returns true to let the declaration parsing code handle it.
1866 /// Returns false if the statement is disambiguated as expression.
Eli Friedman9490ab42011-12-20 01:50:37 +00001867 bool isCXXSimpleDeclaration(bool AllowForRangeDecl);
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001868
1869 /// isCXXFunctionDeclarator - Disambiguates between a function declarator or
1870 /// a constructor-style initializer, when parsing declaration statements.
1871 /// Returns true for function declarator and false for constructor-style
Richard Smithb9c62612012-07-30 21:30:52 +00001872 /// initializer. Sets 'IsAmbiguous' to true to indicate that this declaration
1873 /// might be a constructor-style initializer.
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001874 /// If during the disambiguation process a parsing error is encountered,
1875 /// the function returns true to let the declaration parsing code handle it.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001876 bool isCXXFunctionDeclarator(bool *IsAmbiguous = nullptr);
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001877
Argyrios Kyrtzidisa8a45982008-10-05 15:03:47 +00001878 /// isCXXConditionDeclaration - Disambiguates between a declaration or an
1879 /// expression for a condition of a if/switch/while/for statement.
1880 /// If during the disambiguation process a parsing error is encountered,
1881 /// the function returns true to let the declaration parsing code handle it.
1882 bool isCXXConditionDeclaration();
1883
Argyrios Kyrtzidisf58f45e2009-05-22 10:24:42 +00001884 bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous);
1885 bool isCXXTypeId(TentativeCXXTypeIdContext Context) {
1886 bool isAmbiguous;
1887 return isCXXTypeId(Context, isAmbiguous);
1888 }
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +00001889
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +00001890 /// TPResult - Used as the result value for functions whose purpose is to
1891 /// disambiguate C++ constructs by "tentatively parsing" them.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001892 enum class TPResult {
1893 True, False, Ambiguous, Error
Argyrios Kyrtzidisb47e3862008-10-05 17:02:44 +00001894 };
1895
Douglas Gregora61b3e72010-12-01 17:42:47 +00001896 /// \brief Based only on the given token kind, determine whether we know that
1897 /// we're at the start of an expression or a type-specifier-seq (which may
1898 /// be an expression, in C++).
1899 ///
1900 /// This routine does not attempt to resolve any of the trick cases, e.g.,
1901 /// those involving lookup of identifiers.
1902 ///
1903 /// \returns \c TPR_true if this token starts an expression, \c TPR_false if
1904 /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot
1905 /// tell.
1906 TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind);
1907
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001908 /// isCXXDeclarationSpecifier - Returns TPResult::True if it is a
1909 /// declaration specifier, TPResult::False if it is not,
1910 /// TPResult::Ambiguous if it could be either a decl-specifier or a
1911 /// function-style cast, and TPResult::Error if a parsing error was
Richard Smithd81e9612012-02-23 01:36:12 +00001912 /// encountered. If it could be a braced C++11 function-style cast, returns
1913 /// BracedCastResult.
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001914 /// Doesn't consume tokens.
Richard Smithd81e9612012-02-23 01:36:12 +00001915 TPResult
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001916 isCXXDeclarationSpecifier(TPResult BracedCastResult = TPResult::False,
1917 bool *HasMissingTypename = nullptr);
David Blaikiea8fbc052011-11-09 05:30:24 +00001918
Richard Smith9bd3cdc2013-09-12 23:28:08 +00001919 /// Given that isCXXDeclarationSpecifier returns \c TPResult::True or
1920 /// \c TPResult::Ambiguous, determine whether the decl-specifier would be
1921 /// a type-specifier other than a cv-qualifier.
1922 bool isCXXDeclarationSpecifierAType();
1923
Richard Smith05766812012-08-18 00:55:03 +00001924 /// \brief Determine whether an identifier has been tentatively declared as a
1925 /// non-type. Such tentative declarations should not be found to name a type
1926 /// during a tentative parse, but also should not be annotated as a non-type.
1927 bool isTentativelyDeclared(IdentifierInfo *II);
1928
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001929 // "Tentative parsing" functions, used for disambiguation. If a parsing error
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001930 // is encountered they will return TPResult::Error.
1931 // Returning TPResult::True/False indicates that the ambiguity was
1932 // resolved and tentative parsing may stop. TPResult::Ambiguous indicates
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +00001933 // that more tentative parsing is necessary for disambiguation.
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001934 // They all consume tokens, so backtracking should be used after calling them.
1935
Eli Friedman9490ab42011-12-20 01:50:37 +00001936 TPResult TryParseSimpleDeclaration(bool AllowForRangeDecl);
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +00001937 TPResult TryParseTypeofSpecifier();
Douglas Gregor9bd1d8d2010-10-21 23:17:00 +00001938 TPResult TryParseProtocolQualifiers();
Richard Smith9bd3cdc2013-09-12 23:28:08 +00001939 TPResult TryParsePtrOperatorSeq();
1940 TPResult TryParseOperatorId();
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +00001941 TPResult TryParseInitDeclaratorList();
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +00001942 TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true);
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001943 TPResult
1944 TryParseParameterDeclarationClause(bool *InvalidAsDeclaration = nullptr,
1945 bool VersusTemplateArg = false);
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +00001946 TPResult TryParseFunctionDeclarator();
1947 TPResult TryParseBracketDeclarator();
Richard Smith9bd3cdc2013-09-12 23:28:08 +00001948 TPResult TryConsumeDeclarationSpecifier();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001949
Axel Naumann6944e202012-09-17 13:14:34 +00001950public:
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001951 TypeResult ParseTypeName(SourceRange *Range = nullptr,
Douglas Gregor683a81f2011-01-31 16:09:46 +00001952 Declarator::TheContext Context
John McCallf85e1932011-06-15 23:02:42 +00001953 = Declarator::TypeNameContext,
Richard Smithc89edf52011-07-01 19:46:12 +00001954 AccessSpecifier AS = AS_none,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001955 Decl **OwnedType = nullptr,
1956 ParsedAttributes *Attrs = nullptr);
Axel Naumann6944e202012-09-17 13:14:34 +00001957
1958private:
Douglas Gregor03f1eb02012-06-15 16:59:29 +00001959 void ParseBlockId(SourceLocation CaretLoc);
John McCall7f040a92010-12-24 02:08:15 +00001960
Richard Smith6ee326a2012-04-10 01:32:12 +00001961 // Check for the start of a C++11 attribute-specifier-seq in a context where
1962 // an attribute is not allowed.
1963 bool CheckProhibitedCXX11Attribute() {
1964 assert(Tok.is(tok::l_square));
Richard Smith80ad52f2013-01-02 11:42:31 +00001965 if (!getLangOpts().CPlusPlus11 || NextToken().isNot(tok::l_square))
Richard Smith6ee326a2012-04-10 01:32:12 +00001966 return false;
1967 return DiagnoseProhibitedCXX11Attribute();
1968 }
1969 bool DiagnoseProhibitedCXX11Attribute();
Richard Smith05321402013-02-19 23:47:15 +00001970 void CheckMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
1971 SourceLocation CorrectLocation) {
1972 if (!getLangOpts().CPlusPlus11)
1973 return;
1974 if ((Tok.isNot(tok::l_square) || NextToken().isNot(tok::l_square)) &&
1975 Tok.isNot(tok::kw_alignas))
1976 return;
1977 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
1978 }
1979 void DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
1980 SourceLocation CorrectLocation);
Richard Smith6ee326a2012-04-10 01:32:12 +00001981
John McCall7f040a92010-12-24 02:08:15 +00001982 void ProhibitAttributes(ParsedAttributesWithRange &attrs) {
1983 if (!attrs.Range.isValid()) return;
1984 DiagnoseProhibitedAttributes(attrs);
Richard Smith534986f2012-04-14 00:33:13 +00001985 attrs.clear();
John McCall7f040a92010-12-24 02:08:15 +00001986 }
1987 void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs);
1988
Michael Hanf64231e2012-11-06 19:34:54 +00001989 // Forbid C++11 attributes that appear on certain syntactic
1990 // locations which standard permits but we don't supported yet,
1991 // for example, attributes appertain to decl specifiers.
1992 void ProhibitCXX11Attributes(ParsedAttributesWithRange &attrs);
1993
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001994 /// \brief Skip C++11 attributes and return the end location of the last one.
1995 /// \returns SourceLocation() if there are no attributes.
1996 SourceLocation SkipCXX11Attributes();
1997
Richard Smith5eed7e02013-10-15 01:34:54 +00001998 /// \brief Diagnose and skip C++11 attributes that appear in syntactic
1999 /// locations where attributes are not allowed.
2000 void DiagnoseAndSkipCXX11Attributes();
2001
Stephen Hines651f13c2014-04-23 16:59:28 -07002002 /// \brief Parses syntax-generic attribute arguments for attributes which are
2003 /// known to the implementation, and adds them to the given ParsedAttributes
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002004 /// list with the given attribute syntax. Returns the number of arguments
2005 /// parsed for the attribute.
2006 unsigned
2007 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2008 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2009 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2010 AttributeList::Syntax Syntax);
Stephen Hines651f13c2014-04-23 16:59:28 -07002011
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +00002012 void MaybeParseGNUAttributes(Declarator &D,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002013 LateParsedAttrList *LateAttrs = nullptr) {
John McCall7f040a92010-12-24 02:08:15 +00002014 if (Tok.is(tok::kw___attribute)) {
John McCall0b7e6782011-03-24 11:26:52 +00002015 ParsedAttributes attrs(AttrFactory);
John McCall7f040a92010-12-24 02:08:15 +00002016 SourceLocation endLoc;
Stephen Hines651f13c2014-04-23 16:59:28 -07002017 ParseGNUAttributes(attrs, &endLoc, LateAttrs, &D);
John McCall0b7e6782011-03-24 11:26:52 +00002018 D.takeAttributes(attrs, endLoc);
John McCall7f040a92010-12-24 02:08:15 +00002019 }
2020 }
2021 void MaybeParseGNUAttributes(ParsedAttributes &attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002022 SourceLocation *endLoc = nullptr,
2023 LateParsedAttrList *LateAttrs = nullptr) {
John McCall7f040a92010-12-24 02:08:15 +00002024 if (Tok.is(tok::kw___attribute))
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +00002025 ParseGNUAttributes(attrs, endLoc, LateAttrs);
John McCall7f040a92010-12-24 02:08:15 +00002026 }
2027 void ParseGNUAttributes(ParsedAttributes &attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002028 SourceLocation *endLoc = nullptr,
2029 LateParsedAttrList *LateAttrs = nullptr,
2030 Declarator *D = nullptr);
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +00002031 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2032 SourceLocation AttrNameLoc,
2033 ParsedAttributes &Attrs,
Michael Han6880f492012-10-03 01:56:22 +00002034 SourceLocation *EndLoc,
2035 IdentifierInfo *ScopeName,
2036 SourceLocation ScopeLoc,
Stephen Hines651f13c2014-04-23 16:59:28 -07002037 AttributeList::Syntax Syntax,
2038 Declarator *D);
Richard Smith8edabd92013-09-03 18:01:40 +00002039 IdentifierLoc *ParseIdentifierLoc();
John McCall7f040a92010-12-24 02:08:15 +00002040
Richard Smith4e24f0f2013-01-02 12:01:23 +00002041 void MaybeParseCXX11Attributes(Declarator &D) {
Richard Smith80ad52f2013-01-02 11:42:31 +00002042 if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {
John McCall0b7e6782011-03-24 11:26:52 +00002043 ParsedAttributesWithRange attrs(AttrFactory);
John McCall7f040a92010-12-24 02:08:15 +00002044 SourceLocation endLoc;
Richard Smithc56298d2012-04-10 03:25:07 +00002045 ParseCXX11Attributes(attrs, &endLoc);
John McCall0b7e6782011-03-24 11:26:52 +00002046 D.takeAttributes(attrs, endLoc);
John McCall7f040a92010-12-24 02:08:15 +00002047 }
2048 }
Richard Smith4e24f0f2013-01-02 12:01:23 +00002049 void MaybeParseCXX11Attributes(ParsedAttributes &attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002050 SourceLocation *endLoc = nullptr) {
Richard Smith80ad52f2013-01-02 11:42:31 +00002051 if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {
John McCall0b7e6782011-03-24 11:26:52 +00002052 ParsedAttributesWithRange attrsWithRange(AttrFactory);
Richard Smithc56298d2012-04-10 03:25:07 +00002053 ParseCXX11Attributes(attrsWithRange, endLoc);
John McCall0b7e6782011-03-24 11:26:52 +00002054 attrs.takeAllFrom(attrsWithRange);
John McCall7f040a92010-12-24 02:08:15 +00002055 }
2056 }
Richard Smith4e24f0f2013-01-02 12:01:23 +00002057 void MaybeParseCXX11Attributes(ParsedAttributesWithRange &attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002058 SourceLocation *endLoc = nullptr,
Richard Smith6ee326a2012-04-10 01:32:12 +00002059 bool OuterMightBeMessageSend = false) {
Richard Smith80ad52f2013-01-02 11:42:31 +00002060 if (getLangOpts().CPlusPlus11 &&
Richard Smith6ee326a2012-04-10 01:32:12 +00002061 isCXX11AttributeSpecifier(false, OuterMightBeMessageSend))
Richard Smithc56298d2012-04-10 03:25:07 +00002062 ParseCXX11Attributes(attrs, endLoc);
John McCall7f040a92010-12-24 02:08:15 +00002063 }
Peter Collingbourne3497fdf2011-09-29 18:04:05 +00002064
Richard Smithc56298d2012-04-10 03:25:07 +00002065 void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002066 SourceLocation *EndLoc = nullptr);
Richard Smithc56298d2012-04-10 03:25:07 +00002067 void ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002068 SourceLocation *EndLoc = nullptr);
Stephen Hines651f13c2014-04-23 16:59:28 -07002069 /// \brief Parses a C++-style attribute argument list. Returns true if this
2070 /// results in adding an attribute to the ParsedAttributes list.
2071 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
2072 SourceLocation AttrNameLoc,
2073 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2074 IdentifierInfo *ScopeName,
2075 SourceLocation ScopeLoc);
Michael Han6880f492012-10-03 01:56:22 +00002076
Richard Smithc56298d2012-04-10 03:25:07 +00002077 IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc);
John McCall7f040a92010-12-24 02:08:15 +00002078
2079 void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002080 SourceLocation *endLoc = nullptr) {
David Blaikie4e4d0842012-03-11 07:00:24 +00002081 if (getLangOpts().MicrosoftExt && Tok.is(tok::l_square))
John McCall7f040a92010-12-24 02:08:15 +00002082 ParseMicrosoftAttributes(attrs, endLoc);
2083 }
2084 void ParseMicrosoftAttributes(ParsedAttributes &attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002085 SourceLocation *endLoc = nullptr);
Aaron Ballmanfc685ac2012-06-19 22:09:27 +00002086 void ParseMicrosoftDeclSpec(ParsedAttributes &Attrs);
Stephen Hines651f13c2014-04-23 16:59:28 -07002087 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2088 SourceLocation AttrNameLoc,
2089 ParsedAttributes &Attrs);
John McCall7f040a92010-12-24 02:08:15 +00002090 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
Stephen Hines0e2c34f2015-03-23 12:09:02 -07002091 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2092 SourceLocation SkipExtendedMicrosoftTypeAttributes();
John McCallc052dbb2012-05-22 21:28:12 +00002093 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
John McCall7f040a92010-12-24 02:08:15 +00002094 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
Peter Collingbournef315fa82011-02-14 01:42:53 +00002095 void ParseOpenCLAttributes(ParsedAttributes &attrs);
Stephen Hines651f13c2014-04-23 16:59:28 -07002096 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
John McCall7f040a92010-12-24 02:08:15 +00002097
Douglas Gregor0a0d2b12011-03-23 00:50:03 +00002098 VersionTuple ParseVersionTuple(SourceRange &Range);
2099 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2100 SourceLocation AvailabilityLoc,
2101 ParsedAttributes &attrs,
Stephen Hines176edba2014-12-01 14:53:08 -08002102 SourceLocation *endLoc,
2103 IdentifierInfo *ScopeName,
2104 SourceLocation ScopeLoc,
2105 AttributeList::Syntax Syntax);
2106
Stephen Hines651f13c2014-04-23 16:59:28 -07002107 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2108 SourceLocation ObjCBridgeRelatedLoc,
2109 ParsedAttributes &attrs,
Stephen Hines176edba2014-12-01 14:53:08 -08002110 SourceLocation *endLoc,
2111 IdentifierInfo *ScopeName,
2112 SourceLocation ScopeLoc,
2113 AttributeList::Syntax Syntax);
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00002114
Dmitri Gribenko0d5a0692012-08-17 00:08:38 +00002115 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2116 SourceLocation AttrNameLoc,
2117 ParsedAttributes &Attrs,
Stephen Hines176edba2014-12-01 14:53:08 -08002118 SourceLocation *EndLoc,
2119 IdentifierInfo *ScopeName,
2120 SourceLocation ScopeLoc,
2121 AttributeList::Syntax Syntax);
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00002122
Richard Smithd386fef2013-10-31 01:56:18 +00002123 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2124 SourceLocation AttrNameLoc,
2125 ParsedAttributes &Attrs,
Stephen Hines176edba2014-12-01 14:53:08 -08002126 SourceLocation *EndLoc,
2127 IdentifierInfo *ScopeName,
2128 SourceLocation ScopeLoc,
2129 AttributeList::Syntax Syntax);
Richard Smithd386fef2013-10-31 01:56:18 +00002130
Steve Naroffd1861fd2007-07-31 12:34:36 +00002131 void ParseTypeofSpecifier(DeclSpec &DS);
David Blaikie42d6d0c2011-12-04 05:04:18 +00002132 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
Richard Smith534986f2012-04-14 00:33:13 +00002133 void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS,
David Blaikie42d6d0c2011-12-04 05:04:18 +00002134 SourceLocation StartLoc,
2135 SourceLocation EndLoc);
Sean Huntdb5d44b2011-05-19 05:37:45 +00002136 void ParseUnderlyingTypeSpecifier(DeclSpec &DS);
Eli Friedmanb001de72011-10-06 23:00:33 +00002137 void ParseAtomicSpecifier(DeclSpec &DS);
2138
Peter Collingbourne0b64ba92011-10-23 20:07:52 +00002139 ExprResult ParseAlignArgument(SourceLocation Start,
2140 SourceLocation &EllipsisLoc);
Peter Collingbourne82d0b0a2011-09-29 18:04:28 +00002141 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002142 SourceLocation *endLoc = nullptr);
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00002143
Richard Smith4e24f0f2013-01-02 12:01:23 +00002144 VirtSpecifiers::Specifier isCXX11VirtSpecifier(const Token &Tok) const;
2145 VirtSpecifiers::Specifier isCXX11VirtSpecifier() const {
2146 return isCXX11VirtSpecifier(Tok);
Richard Smith1c94c162012-01-09 22:31:44 +00002147 }
Stephen Hines176edba2014-12-01 14:53:08 -08002148 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, bool IsInterface,
2149 SourceLocation FriendLoc);
Anders Carlsson1f3b6fd2011-01-16 23:56:42 +00002150
Richard Smith4e24f0f2013-01-02 12:01:23 +00002151 bool isCXX11FinalKeyword() const;
Anders Carlssoncc54d592011-01-22 16:56:46 +00002152
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00002153 /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
2154 /// enter a new C++ declarator scope and exit it when the function is
2155 /// finished.
2156 class DeclaratorScopeObj {
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00002157 Parser &P;
Argyrios Kyrtzidis75181022008-11-08 16:47:38 +00002158 CXXScopeSpec &SS;
Argyrios Kyrtzidisf37006b2009-07-21 06:43:26 +00002159 bool EnteredScope;
John McCallf7f3d0d2009-11-11 00:21:18 +00002160 bool CreatedScope;
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00002161 public:
Argyrios Kyrtzidisf37006b2009-07-21 06:43:26 +00002162 DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss)
John McCallf7f3d0d2009-11-11 00:21:18 +00002163 : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {}
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00002164
2165 void EnterDeclaratorScope() {
Argyrios Kyrtzidis2bcb3432009-07-21 06:48:06 +00002166 assert(!EnteredScope && "Already entered the scope!");
Argyrios Kyrtzidisf37006b2009-07-21 06:43:26 +00002167 assert(SS.isSet() && "C++ scope was not set!");
John McCallf7f3d0d2009-11-11 00:21:18 +00002168
2169 CreatedScope = true;
2170 P.EnterScope(0); // Not a decl scope.
2171
Douglas Gregor23c94db2010-07-02 17:43:08 +00002172 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
Douglas Gregor3fdbed52009-07-21 18:59:28 +00002173 EnteredScope = true;
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00002174 }
2175
2176 ~DeclaratorScopeObj() {
Argyrios Kyrtzidisf37006b2009-07-21 06:43:26 +00002177 if (EnteredScope) {
2178 assert(SS.isSet() && "C++ scope was cleared ?");
Douglas Gregor23c94db2010-07-02 17:43:08 +00002179 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
Argyrios Kyrtzidisf37006b2009-07-21 06:43:26 +00002180 }
John McCallf7f3d0d2009-11-11 00:21:18 +00002181 if (CreatedScope)
2182 P.ExitScope();
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00002183 }
2184 };
Mike Stump1eb44332009-09-09 15:08:12 +00002185
Reid Spencer5f016e22007-07-11 17:01:13 +00002186 /// ParseDeclarator - Parse and verify a newly-initialized declarator.
2187 void ParseDeclarator(Declarator &D);
Sebastian Redl4c5d3202008-11-21 19:14:01 +00002188 /// A function that parses a variant of direct-declarator.
2189 typedef void (Parser::*DirectDeclParseFunction)(Declarator&);
2190 void ParseDeclaratorInternal(Declarator &D,
2191 DirectDeclParseFunction DirectDeclParser);
John McCall7f040a92010-12-24 02:08:15 +00002192
Stephen Hines176edba2014-12-01 14:53:08 -08002193 enum AttrRequirements {
2194 AR_NoAttributesParsed = 0, ///< No attributes are diagnosed.
2195 AR_GNUAttributesParsedAndRejected = 1 << 0, ///< Diagnose GNU attributes.
2196 AR_GNUAttributesParsed = 1 << 1,
2197 AR_CXX11AttributesParsed = 1 << 2,
2198 AR_DeclspecAttributesParsed = 1 << 3,
2199 AR_AllAttributesParsed = AR_GNUAttributesParsed |
2200 AR_CXX11AttributesParsed |
2201 AR_DeclspecAttributesParsed,
2202 AR_VendorAttributesParsed = AR_GNUAttributesParsed |
2203 AR_DeclspecAttributesParsed
2204 };
2205
2206 void ParseTypeQualifierListOpt(DeclSpec &DS,
2207 unsigned AttrReqs = AR_AllAttributesParsed,
Bill Wendling7f3ec662013-11-26 04:10:07 +00002208 bool AtomicAllowed = true,
2209 bool IdentifierRequired = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00002210 void ParseDirectDeclarator(Declarator &D);
2211 void ParseParenDeclarator(Declarator &D);
Douglas Gregor4a8dfb52011-10-12 16:37:45 +00002212 void ParseFunctionDeclarator(Declarator &D,
John McCall7f040a92010-12-24 02:08:15 +00002213 ParsedAttributes &attrs,
Douglas Gregor4a8dfb52011-10-12 16:37:45 +00002214 BalancedDelimiterTracker &Tracker,
Richard Smithb9c62612012-07-30 21:30:52 +00002215 bool IsAmbiguous,
Chris Lattner7399ee02008-10-20 02:05:46 +00002216 bool RequiresArg = false);
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -07002217 bool ParseRefQualifier(bool &RefQualifierIsLValueRef,
2218 SourceLocation &RefQualifierLoc);
Douglas Gregor3fd1ba02011-07-05 16:44:18 +00002219 bool isFunctionDeclaratorIdentifierList();
2220 void ParseFunctionDeclaratorIdentifierList(
2221 Declarator &D,
Craig Topper6b9240e2013-07-05 19:34:19 +00002222 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
Douglas Gregor3fd1ba02011-07-05 16:44:18 +00002223 void ParseParameterDeclarationClause(
2224 Declarator &D,
2225 ParsedAttributes &attrs,
Craig Topper6b9240e2013-07-05 19:34:19 +00002226 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
Douglas Gregor3fd1ba02011-07-05 16:44:18 +00002227 SourceLocation &EllipsisLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00002228 void ParseBracketDeclarator(Declarator &D);
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002229 void ParseMisplacedBracketDeclarator(Declarator &D);
Mike Stump1eb44332009-09-09 15:08:12 +00002230
Chris Lattner8f08cb72007-08-25 06:57:03 +00002231 //===--------------------------------------------------------------------===//
2232 // C++ 7: Declarations [dcl.dcl]
Mike Stump1eb44332009-09-09 15:08:12 +00002233
Richard Smith6ee326a2012-04-10 01:32:12 +00002234 /// The kind of attribute specifier we have found.
2235 enum CXX11AttributeKind {
2236 /// This is not an attribute specifier.
2237 CAK_NotAttributeSpecifier,
2238 /// This should be treated as an attribute-specifier.
2239 CAK_AttributeSpecifier,
2240 /// The next tokens are '[[', but this is not an attribute-specifier. This
2241 /// is ill-formed by C++11 [dcl.attr.grammar]p6.
2242 CAK_InvalidAttributeSpecifier
2243 };
2244 CXX11AttributeKind
2245 isCXX11AttributeSpecifier(bool Disambiguate = false,
2246 bool OuterMightBeMessageSend = false);
David Blaikiea8fbc052011-11-09 05:30:24 +00002247
Richard Smith7faf81f2013-11-15 23:00:02 +00002248 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
Richard Smithb3104392013-11-09 04:52:51 +00002249
Sebastian Redld078e642010-08-27 23:12:46 +00002250 Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd,
2251 SourceLocation InlineLoc = SourceLocation());
Richard Trieuf858bd82011-05-26 20:11:09 +00002252 void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc,
2253 std::vector<IdentifierInfo*>& Ident,
2254 std::vector<SourceLocation>& NamespaceLoc,
2255 unsigned int index, SourceLocation& InlineLoc,
Douglas Gregor4a8dfb52011-10-12 16:37:45 +00002256 ParsedAttributes& attrs,
2257 BalancedDelimiterTracker &Tracker);
John McCalld226f652010-08-21 09:40:31 +00002258 Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context);
2259 Decl *ParseUsingDirectiveOrDeclaration(unsigned Context,
John McCall78b81052010-11-10 02:40:36 +00002260 const ParsedTemplateInfo &TemplateInfo,
Sebastian Redld078e642010-08-27 23:12:46 +00002261 SourceLocation &DeclEnd,
Richard Smithc89edf52011-07-01 19:46:12 +00002262 ParsedAttributesWithRange &attrs,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002263 Decl **OwnedType = nullptr);
John McCall78b81052010-11-10 02:40:36 +00002264 Decl *ParseUsingDirective(unsigned Context,
2265 SourceLocation UsingLoc,
John McCall7f040a92010-12-24 02:08:15 +00002266 SourceLocation &DeclEnd,
2267 ParsedAttributes &attrs);
John McCall78b81052010-11-10 02:40:36 +00002268 Decl *ParseUsingDeclaration(unsigned Context,
2269 const ParsedTemplateInfo &TemplateInfo,
2270 SourceLocation UsingLoc,
Sebastian Redld078e642010-08-27 23:12:46 +00002271 SourceLocation &DeclEnd,
Richard Smithc89edf52011-07-01 19:46:12 +00002272 AccessSpecifier AS = AS_none,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002273 Decl **OwnedType = nullptr);
John McCalld226f652010-08-21 09:40:31 +00002274 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
2275 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
Sebastian Redld078e642010-08-27 23:12:46 +00002276 SourceLocation AliasLoc, IdentifierInfo *Alias,
2277 SourceLocation &DeclEnd);
Mike Stump1eb44332009-09-09 15:08:12 +00002278
Douglas Gregore37ac4f2008-04-13 21:30:24 +00002279 //===--------------------------------------------------------------------===//
2280 // C++ 9: classes [class] and C structs/unions.
Richard Smith139be702012-07-02 19:14:01 +00002281 bool isValidAfterTypeSpecifier(bool CouldBeBitfield);
Chris Lattner4c97d762009-04-12 21:49:30 +00002282 void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc,
Richard Smith69730c12012-03-12 07:56:15 +00002283 DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo,
2284 AccessSpecifier AS, bool EnteringContext,
Michael Han2e397132012-11-26 22:54:45 +00002285 DeclSpecContext DSC,
Bill Wendlingad017fa2012-12-20 19:22:21 +00002286 ParsedAttributesWithRange &Attributes);
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -07002287 void SkipCXXMemberSpecification(SourceLocation StartLoc,
2288 SourceLocation AttrFixitLoc,
2289 unsigned TagType,
2290 Decl *TagDecl);
Michael Han07fc1ba2013-01-07 16:57:11 +00002291 void ParseCXXMemberSpecification(SourceLocation StartLoc,
2292 SourceLocation AttrFixitLoc,
Richard Smith05321402013-02-19 23:47:15 +00002293 ParsedAttributesWithRange &Attrs,
Michael Han07fc1ba2013-01-07 16:57:11 +00002294 unsigned TagType,
John McCalld226f652010-08-21 09:40:31 +00002295 Decl *TagDecl);
Douglas Gregor552e2992012-02-21 02:22:07 +00002296 ExprResult ParseCXXMemberInitializer(Decl *D, bool IsFunction,
Richard Smith7a614d82011-06-11 17:19:42 +00002297 SourceLocation &EqualLoc);
Stephen Hines0e2c34f2015-03-23 12:09:02 -07002298 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
Stephen Hines651f13c2014-04-23 16:59:28 -07002299 VirtSpecifiers &VS,
2300 ExprResult &BitfieldSize,
2301 LateParsedAttrList &LateAttrs);
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -07002302 void MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
2303 VirtSpecifiers &VS);
Erik Verbruggen5f1c8222011-10-13 09:41:32 +00002304 void ParseCXXClassMemberDeclaration(AccessSpecifier AS, AttributeList *Attr,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002305 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2306 ParsingDeclRAIIObject *DiagsFromTParams = nullptr);
John McCalld226f652010-08-21 09:40:31 +00002307 void ParseConstructorInitializer(Decl *ConstructorDecl);
2308 MemInitResult ParseMemInitializer(Decl *ConstructorDecl);
Douglas Gregor74e2fc32012-04-16 18:27:27 +00002309 void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo,
2310 Decl *ThisDecl);
Douglas Gregore37ac4f2008-04-13 21:30:24 +00002311
2312 //===--------------------------------------------------------------------===//
2313 // C++ 10: Derived classes [class.derived]
David Blaikiea8fbc052011-11-09 05:30:24 +00002314 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
David Blaikie22216eb2011-10-25 17:10:12 +00002315 SourceLocation &EndLocation);
John McCalld226f652010-08-21 09:40:31 +00002316 void ParseBaseClause(Decl *ClassDecl);
2317 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
Douglas Gregor1b7f8982008-04-14 00:13:42 +00002318 AccessSpecifier getAccessSpecifierIfPresent() const;
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +00002319
David Blaikiea8fbc052011-11-09 05:30:24 +00002320 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002321 SourceLocation TemplateKWLoc,
Douglas Gregor3f9a0562009-11-03 01:35:08 +00002322 IdentifierInfo *Name,
2323 SourceLocation NameLoc,
2324 bool EnteringContext,
John McCallb3d87482010-08-24 05:47:05 +00002325 ParsedType ObjectType,
Douglas Gregord4dca082010-02-24 18:44:31 +00002326 UnqualifiedId &Id,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002327 bool AssumeTemplateId);
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002328 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
John McCallb3d87482010-08-24 05:47:05 +00002329 ParsedType ObjectType,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002330 UnqualifiedId &Result);
Axel Naumann6944e202012-09-17 13:14:34 +00002331
Alexey Bataevc6400582013-03-22 06:34:35 +00002332 //===--------------------------------------------------------------------===//
2333 // OpenMP: Directives and clauses.
Alexey Bataev6af701f2013-05-13 04:18:18 +00002334 /// \brief Parses declarative OpenMP directives.
Alexey Bataevc6400582013-03-22 06:34:35 +00002335 DeclGroupPtrTy ParseOpenMPDeclarativeDirective();
Alexey Bataev6af701f2013-05-13 04:18:18 +00002336 /// \brief Parses simple list of variables.
2337 ///
2338 /// \param Kind Kind of the directive.
2339 /// \param [out] VarList List of referenced variables.
2340 /// \param AllowScopeSpecifier true, if the variables can have fully
2341 /// qualified names.
2342 ///
Alexey Bataevc6400582013-03-22 06:34:35 +00002343 bool ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
Alexey Bataev6af701f2013-05-13 04:18:18 +00002344 SmallVectorImpl<Expr *> &VarList,
2345 bool AllowScopeSpecifier);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002346 /// \brief Parses declarative or executable directive.
Stephen Hines176edba2014-12-01 14:53:08 -08002347 ///
2348 /// \param StandAloneAllowed true if allowed stand-alone directives,
2349 /// false - otherwise
2350 ///
2351 StmtResult
2352 ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002353 /// \brief Parses clause of kind \a CKind for directive of a kind \a Kind.
2354 ///
2355 /// \param DKind Kind of current directive.
2356 /// \param CKind Kind of current clause.
2357 /// \param FirstClause true, if this is the first clause of a kind \a CKind
2358 /// in current directive.
2359 ///
2360 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
2361 OpenMPClauseKind CKind, bool FirstClause);
2362 /// \brief Parses clause with a single expression of a kind \a Kind.
2363 ///
2364 /// \param Kind Kind of current clause.
2365 ///
2366 OMPClause *ParseOpenMPSingleExprClause(OpenMPClauseKind Kind);
2367 /// \brief Parses simple clause of a kind \a Kind.
2368 ///
2369 /// \param Kind Kind of current clause.
2370 ///
2371 OMPClause *ParseOpenMPSimpleClause(OpenMPClauseKind Kind);
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002372 /// \brief Parses clause with a single expression and an additional argument
2373 /// of a kind \a Kind.
2374 ///
2375 /// \param Kind Kind of current clause.
2376 ///
2377 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind);
2378 /// \brief Parses clause without any additional arguments.
2379 ///
2380 /// \param Kind Kind of current clause.
2381 ///
2382 OMPClause *ParseOpenMPClause(OpenMPClauseKind Kind);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002383 /// \brief Parses clause with the list of variables of a kind \a Kind.
2384 ///
2385 /// \param Kind Kind of current clause.
2386 ///
2387 OMPClause *ParseOpenMPVarListClause(OpenMPClauseKind Kind);
Axel Naumann6944e202012-09-17 13:14:34 +00002388public:
Douglas Gregor3f9a0562009-11-03 01:35:08 +00002389 bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
Douglas Gregor02a24ee2009-11-03 16:56:39 +00002390 bool AllowDestructorName,
2391 bool AllowConstructorName,
John McCallb3d87482010-08-24 05:47:05 +00002392 ParsedType ObjectType,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002393 SourceLocation& TemplateKWLoc,
Douglas Gregor3f9a0562009-11-03 01:35:08 +00002394 UnqualifiedId &Result);
David Blaikiea8fbc052011-11-09 05:30:24 +00002395
Axel Naumann6944e202012-09-17 13:14:34 +00002396private:
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +00002397 //===--------------------------------------------------------------------===//
Douglas Gregoradcac882008-12-01 23:54:00 +00002398 // C++ 14: Templates [temp]
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00002399
Douglas Gregoradcac882008-12-01 23:54:00 +00002400 // C++ 14.1: Template Parameters [temp.param]
John McCalld226f652010-08-21 09:40:31 +00002401 Decl *ParseDeclarationStartingWithTemplate(unsigned Context,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002402 SourceLocation &DeclEnd,
2403 AccessSpecifier AS = AS_none,
2404 AttributeList *AccessAttrs = nullptr);
John McCalld226f652010-08-21 09:40:31 +00002405 Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context,
Erik Verbruggen5f1c8222011-10-13 09:41:32 +00002406 SourceLocation &DeclEnd,
2407 AccessSpecifier AS,
2408 AttributeList *AccessAttrs);
John McCalld226f652010-08-21 09:40:31 +00002409 Decl *ParseSingleDeclarationAfterTemplate(
Douglas Gregor1426e532009-05-12 21:31:51 +00002410 unsigned Context,
Douglas Gregor4d9a16f2009-05-12 23:25:50 +00002411 const ParsedTemplateInfo &TemplateInfo,
John McCallc9068d72010-07-16 08:13:16 +00002412 ParsingDeclRAIIObject &DiagsFromParams,
Douglas Gregor1426e532009-05-12 21:31:51 +00002413 SourceLocation &DeclEnd,
Erik Verbruggen5f1c8222011-10-13 09:41:32 +00002414 AccessSpecifier AS=AS_none,
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002415 AttributeList *AccessAttrs = nullptr);
Mike Stump1eb44332009-09-09 15:08:12 +00002416 bool ParseTemplateParameters(unsigned Depth,
Chris Lattner686775d2011-07-20 06:58:45 +00002417 SmallVectorImpl<Decl*> &TemplateParams,
Mike Stump1eb44332009-09-09 15:08:12 +00002418 SourceLocation &LAngleLoc,
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00002419 SourceLocation &RAngleLoc);
2420 bool ParseTemplateParameterList(unsigned Depth,
Chris Lattner686775d2011-07-20 06:58:45 +00002421 SmallVectorImpl<Decl*> &TemplateParams);
Douglas Gregor98440b42009-11-21 02:07:55 +00002422 bool isStartOfTemplateTypeParameter();
John McCalld226f652010-08-21 09:40:31 +00002423 Decl *ParseTemplateParameter(unsigned Depth, unsigned Position);
2424 Decl *ParseTypeParameter(unsigned Depth, unsigned Position);
2425 Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
2426 Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002427 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
2428 SourceLocation CorrectLoc,
2429 bool AlreadyHasEllipsis,
2430 bool IdentifierHasName);
2431 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
2432 Declarator &D);
Douglas Gregord6fb7ef2008-12-18 19:37:40 +00002433 // C++ 14.3: Template arguments [temp.arg]
Chris Lattner686775d2011-07-20 06:58:45 +00002434 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
Douglas Gregorcc636682009-02-17 23:15:12 +00002435
Nico Weberb707a472012-12-14 18:22:38 +00002436 bool ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc,
2437 bool ConsumeLastToken);
Douglas Gregor7532dc62009-03-30 22:58:21 +00002438 bool ParseTemplateIdAfterTemplateName(TemplateTy Template,
Mike Stump1eb44332009-09-09 15:08:12 +00002439 SourceLocation TemplateNameLoc,
Douglas Gregor059101f2011-03-02 00:47:37 +00002440 const CXXScopeSpec &SS,
Douglas Gregorcc636682009-02-17 23:15:12 +00002441 bool ConsumeLastToken,
2442 SourceLocation &LAngleLoc,
2443 TemplateArgList &TemplateArgs,
Douglas Gregorcc636682009-02-17 23:15:12 +00002444 SourceLocation &RAngleLoc);
2445
Chris Lattnerc8e27cc2009-06-26 04:27:47 +00002446 bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
Douglas Gregor059101f2011-03-02 00:47:37 +00002447 CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002448 SourceLocation TemplateKWLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002449 UnqualifiedId &TemplateName,
Douglas Gregor39a8de12009-02-25 19:37:18 +00002450 bool AllowTypeAnnotation = true);
Douglas Gregor059101f2011-03-02 00:47:37 +00002451 void AnnotateTemplateIdTokenAsType();
Douglas Gregord5ab9b02010-05-21 23:43:39 +00002452 bool IsTemplateArgumentList(unsigned Skip = 0);
Douglas Gregor314b97f2009-11-10 19:49:08 +00002453 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs);
Douglas Gregor788cd062009-11-11 01:00:40 +00002454 ParsedTemplateArgument ParseTemplateTemplateArgument();
Douglas Gregor314b97f2009-11-10 19:49:08 +00002455 ParsedTemplateArgument ParseTemplateArgument();
Argyrios Kyrtzidis92410572011-12-23 02:16:45 +00002456 Decl *ParseExplicitInstantiation(unsigned Context,
2457 SourceLocation ExternLoc,
2458 SourceLocation TemplateLoc,
2459 SourceLocation &DeclEnd,
2460 AccessSpecifier AS = AS_none);
Sebastian Redl64b45f72009-01-05 20:52:13 +00002461
2462 //===--------------------------------------------------------------------===//
Douglas Gregor6aa52ec2011-08-26 23:56:07 +00002463 // Modules
Douglas Gregor5948ae12012-01-03 18:04:46 +00002464 DeclGroupPtrTy ParseModuleImport(SourceLocation AtLoc);
David Blaikiea8fbc052011-11-09 05:30:24 +00002465
Douglas Gregor6aa52ec2011-08-26 23:56:07 +00002466 //===--------------------------------------------------------------------===//
Stephen Hines651f13c2014-04-23 16:59:28 -07002467 // C++11/G++: Type Traits [Type-Traits.html in the GCC manual]
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002468 ExprResult ParseTypeTrait();
2469
Douglas Gregorf44e8542010-08-24 19:08:16 +00002470 //===--------------------------------------------------------------------===//
John Wiegley21ff2e52011-04-28 00:16:57 +00002471 // Embarcadero: Arary and Expression Traits
2472 ExprResult ParseArrayTypeTrait();
John Wiegley55262202011-04-25 06:54:41 +00002473 ExprResult ParseExpressionTrait();
2474
2475 //===--------------------------------------------------------------------===//
Douglas Gregorf44e8542010-08-24 19:08:16 +00002476 // Preprocessor code-completion pass-through
Stephen Hines651f13c2014-04-23 16:59:28 -07002477 void CodeCompleteDirective(bool InConditional) override;
2478 void CodeCompleteInConditionalExclusion() override;
2479 void CodeCompleteMacroName(bool IsDefinition) override;
2480 void CodeCompletePreprocessorExpression() override;
2481 void CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo,
2482 unsigned ArgumentIndex) override;
2483 void CodeCompleteNaturalLanguage() override;
Reid Spencer5f016e22007-07-11 17:01:13 +00002484};
2485
2486} // end namespace clang
2487
2488#endif