Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Parser.h - C Language Parser ---------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 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 Bataev | c640058 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 17 | #include "clang/Basic/OpenMPKinds.h" |
Daniel Jasper | 9096102 | 2012-12-20 20:25:19 +0000 | [diff] [blame] | 18 | #include "clang/Basic/OperatorPrecedence.h" |
John McCall | ad2b804 | 2010-01-18 23:21:37 +0000 | [diff] [blame] | 19 | #include "clang/Basic/Specifiers.h" |
Douglas Gregor | f44e854 | 2010-08-24 19:08:16 +0000 | [diff] [blame] | 20 | #include "clang/Lex/CodeCompletionHandler.h" |
Chandler Carruth | 30a2e16 | 2012-12-04 09:18:49 +0000 | [diff] [blame] | 21 | #include "clang/Lex/Preprocessor.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 22 | #include "clang/Sema/DeclSpec.h" |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 23 | #include "clang/Sema/LoopHint.h" |
Chandler Carruth | 30a2e16 | 2012-12-04 09:18:49 +0000 | [diff] [blame] | 24 | #include "clang/Sema/Sema.h" |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | aa49a7d | 2012-03-09 19:35:29 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Compiler.h" |
| 27 | #include "llvm/Support/PrettyStackTrace.h" |
Jordan Rose | 94f29f4 | 2012-07-09 16:54:53 +0000 | [diff] [blame] | 28 | #include "llvm/Support/SaveAndRestore.h" |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 29 | #include <memory> |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 30 | #include <stack> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 31 | |
| 32 | namespace clang { |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 33 | class PragmaHandler; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 34 | class Scope; |
Douglas Gregor | c86c40b | 2012-06-06 21:18:07 +0000 | [diff] [blame] | 35 | class BalancedDelimiterTracker; |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 36 | class CorrectionCandidateCallback; |
John McCall | 2b5289b | 2010-08-23 07:28:44 +0000 | [diff] [blame] | 37 | class DeclGroupRef; |
Chris Lattner | 3cbfe2c | 2008-11-22 00:59:29 +0000 | [diff] [blame] | 38 | class DiagnosticBuilder; |
Chris Lattner | 0102c30 | 2009-03-05 07:24:28 +0000 | [diff] [blame] | 39 | class Parser; |
John McCall | 9257664 | 2012-05-07 06:16:41 +0000 | [diff] [blame] | 40 | class ParsingDeclRAIIObject; |
| 41 | class ParsingDeclSpec; |
| 42 | class ParsingDeclarator; |
Eli Friedman | f66a0dd | 2012-08-08 23:04:35 +0000 | [diff] [blame] | 43 | class ParsingFieldDeclarator; |
Chris Lattner | 08d92ec | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 44 | class ColonProtectionRAIIObject; |
Douglas Gregor | 0fbda68 | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 45 | class InMessageExpressionRAIIObject; |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 46 | class PoisonSEHIdentifiersRAIIObject; |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 47 | class VersionTuple; |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 48 | class OMPClause; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 49 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 50 | /// 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 Gregor | f44e854 | 2010-08-24 19:08:16 +0000 | [diff] [blame] | 54 | class Parser : public CodeCompletionHandler { |
Chris Lattner | 08d92ec | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 55 | friend class ColonProtectionRAIIObject; |
Douglas Gregor | 0fbda68 | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 56 | friend class InMessageExpressionRAIIObject; |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 57 | friend class PoisonSEHIdentifiersRAIIObject; |
Jordan Rose | 94f29f4 | 2012-07-09 16:54:53 +0000 | [diff] [blame] | 58 | friend class ObjCDeclContextSwitch; |
Argyrios Kyrtzidis | 36d3680 | 2010-06-17 10:52:18 +0000 | [diff] [blame] | 59 | friend class ParenBraceBracketBalancer; |
Douglas Gregor | c86c40b | 2012-06-06 21:18:07 +0000 | [diff] [blame] | 60 | friend class BalancedDelimiterTracker; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 61 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 62 | Preprocessor &PP; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | |
Eric Christopher | 97d0205 | 2008-04-10 05:23:15 +0000 | [diff] [blame] | 64 | /// Tok - The current token we are peeking ahead. All parsing methods assume |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 65 | /// that this is valid. |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 66 | Token Tok; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 67 | |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 68 | // 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 Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 74 | unsigned short ParenCount, BracketCount, BraceCount; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 75 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 76 | /// Actions - These are the callbacks we invoke as we parse various constructs |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 77 | /// in the file. |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 78 | Sema &Actions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 79 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 80 | DiagnosticsEngine &Diags; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | |
Chris Lattner | 9e344c6 | 2007-07-15 00:04:39 +0000 | [diff] [blame] | 82 | /// ScopeCache - Cache scopes to reduce malloc traffic. |
| 83 | enum { ScopeCacheSize = 16 }; |
| 84 | unsigned NumCachedScopes; |
| 85 | Scope *ScopeCache[ScopeCacheSize]; |
Daniel Dunbar | 662e8b5 | 2008-08-14 22:04:54 +0000 | [diff] [blame] | 86 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 87 | /// Identifiers used for SEH handling in Borland. These are only |
| 88 | /// allowed in particular circumstances |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 89 | // __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 Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 101 | |
Douglas Gregor | b57791e | 2011-10-21 03:57:52 +0000 | [diff] [blame] | 102 | /// Contextual keywords for Microsoft extensions. |
| 103 | IdentifierInfo *Ident__except; |
David Majnemer | 7121bdb | 2013-10-18 00:33:31 +0000 | [diff] [blame] | 104 | mutable IdentifierInfo *Ident_sealed; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 105 | |
Daniel Dunbar | 662e8b5 | 2008-08-14 22:04:54 +0000 | [diff] [blame] | 106 | /// Ident_super - IdentifierInfo for "super", to support fast |
| 107 | /// comparison. |
| 108 | IdentifierInfo *Ident_super; |
Bill Schmidt | 3e3d20b | 2013-07-03 20:54:09 +0000 | [diff] [blame] | 109 | /// Ident_vector, Ident_pixel, Ident_bool - cached IdentifierInfo's |
| 110 | /// for "vector", "pixel", and "bool" fast comparison. Only present |
| 111 | /// if AltiVec enabled. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 112 | IdentifierInfo *Ident_vector; |
| 113 | IdentifierInfo *Ident_pixel; |
Bill Schmidt | 3e3d20b | 2013-07-03 20:54:09 +0000 | [diff] [blame] | 114 | IdentifierInfo *Ident_bool; |
Daniel Dunbar | 662e8b5 | 2008-08-14 22:04:54 +0000 | [diff] [blame] | 115 | |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 116 | /// Objective-C contextual keywords. |
| 117 | mutable IdentifierInfo *Ident_instancetype; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 118 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 119 | /// \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 Gregor | b53e417 | 2011-03-26 03:35:55 +0000 | [diff] [blame] | 128 | /// \brief Identifier for "unavailable". |
| 129 | IdentifierInfo *Ident_unavailable; |
Fariborz Jahanian | 006e42f | 2011-12-10 00:28:41 +0000 | [diff] [blame] | 130 | |
| 131 | /// \brief Identifier for "message". |
| 132 | IdentifierInfo *Ident_message; |
Douglas Gregor | b53e417 | 2011-03-26 03:35:55 +0000 | [diff] [blame] | 133 | |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 134 | /// C++0x contextual keywords. |
Anders Carlsson | 7eeb4ec | 2011-01-20 03:47:08 +0000 | [diff] [blame] | 135 | mutable IdentifierInfo *Ident_final; |
| 136 | mutable IdentifierInfo *Ident_override; |
Anders Carlsson | 1f3b6fd | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 137 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 138 | // 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 Gregor | d295970 | 2012-08-30 20:04:43 +0000 | [diff] [blame] | 141 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 142 | 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 Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 157 | 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 Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 164 | std::unique_ptr<PragmaHandler> LoopHintHandler; |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 165 | std::unique_ptr<PragmaHandler> UnrollHintHandler; |
| 166 | std::unique_ptr<PragmaHandler> NoUnrollHintHandler; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 167 | |
| 168 | std::unique_ptr<CommentHandler> CommentSemaHandler; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 169 | |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 170 | /// 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 Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 175 | |
Chris Lattner | 08d92ec | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 176 | /// 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 Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 181 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 182 | /// \brief When true, we are directly inside an Objective-C message |
Douglas Gregor | 0fbda68 | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 183 | /// send expression. |
| 184 | /// |
| 185 | /// This is managed by the \c InMessageExpressionRAIIObject class, and |
| 186 | /// should not be set directly. |
| 187 | bool InMessageExpression; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 188 | |
Douglas Gregor | c305833 | 2009-08-24 23:03:25 +0000 | [diff] [blame] | 189 | /// The "depth" of the template parameters currently being parsed. |
| 190 | unsigned TemplateParameterDepth; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 191 | |
Richard Smith | 098b814 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 192 | /// \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 Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 208 | void addDepth(unsigned D) { |
| 209 | Depth += D; |
| 210 | AddedLevels += D; |
| 211 | } |
Richard Smith | 098b814 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 212 | unsigned getDepth() const { return Depth; } |
| 213 | }; |
| 214 | |
Ted Kremenek | 8113ecf | 2010-11-10 05:59:39 +0000 | [diff] [blame] | 215 | /// Factory object for creating AttributeList objects. |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 216 | AttributeFactory AttrFactory; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 217 | |
Benjamin Kramer | 13bb701 | 2012-04-14 12:14:03 +0000 | [diff] [blame] | 218 | /// \brief Gathers and cleans up TemplateIdAnnotations when parsing of a |
| 219 | /// top-level declaration is finished. |
| 220 | SmallVector<TemplateIdAnnotation *, 16> TemplateIds; |
Argyrios Kyrtzidis | 25a7676 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 221 | |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 222 | /// \brief Identifiers which have been declared within a tentative parse. |
| 223 | SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers; |
| 224 | |
Douglas Gregor | b57791e | 2011-10-21 03:57:52 +0000 | [diff] [blame] | 225 | IdentifierInfo *getSEHExceptKeyword(); |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 226 | |
Jordan Rose | 94f29f4 | 2012-07-09 16:54:53 +0000 | [diff] [blame] | 227 | /// 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 Verbruggen | 6a91d38 | 2012-04-12 10:11:59 +0000 | [diff] [blame] | 234 | bool SkipFunctionBodies; |
| 235 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 236 | public: |
Erik Verbruggen | 6a91d38 | 2012-04-12 10:11:59 +0000 | [diff] [blame] | 237 | Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies); |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame] | 238 | ~Parser() override; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 239 | |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 240 | const LangOptions &getLangOpts() const { return PP.getLangOpts(); } |
Daniel Dunbar | 444be73 | 2009-11-13 05:51:54 +0000 | [diff] [blame] | 241 | const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } |
Chris Lattner | 0102c30 | 2009-03-05 07:24:28 +0000 | [diff] [blame] | 242 | Preprocessor &getPreprocessor() const { return PP; } |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 243 | Sema &getActions() const { return Actions; } |
John McCall | 9257664 | 2012-05-07 06:16:41 +0000 | [diff] [blame] | 244 | AttributeFactory &getAttrFactory() { return AttrFactory; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 245 | |
Chris Lattner | 0102c30 | 2009-03-05 07:24:28 +0000 | [diff] [blame] | 246 | const Token &getCurToken() const { return Tok; } |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 247 | Scope *getCurScope() const { return Actions.getCurScope(); } |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 248 | void incrementMSManglingNumber() const { |
| 249 | return Actions.incrementMSManglingNumber(); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 250 | } |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 251 | |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 252 | Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); } |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 253 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 254 | // Type forwarding. All of these are statically 'void*', but they may all be |
| 255 | // different actual classes based on the actions in place. |
John McCall | 2b5289b | 2010-08-23 07:28:44 +0000 | [diff] [blame] | 256 | typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; |
John McCall | 2b5289b | 2010-08-23 07:28:44 +0000 | [diff] [blame] | 257 | typedef OpaquePtr<TemplateName> TemplateTy; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 258 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 259 | typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists; |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 260 | |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 261 | typedef Sema::FullExprArg FullExprArg; |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 262 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 263 | // Parsing methods. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 264 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 265 | /// Initialize - Warm up the parser. |
| 266 | /// |
| 267 | void Initialize(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 268 | |
| 269 | /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if |
Steve Naroff | 1f64432 | 2007-11-28 22:54:11 +0000 | [diff] [blame] | 270 | /// the EOF was encountered. |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 271 | bool ParseTopLevelDecl(DeclGroupPtrTy &Result); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 272 | bool ParseTopLevelDecl() { |
| 273 | DeclGroupPtrTy Result; |
| 274 | return ParseTopLevelDecl(Result); |
| 275 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 276 | |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 277 | /// ConsumeToken - Consume the current 'peek token' and lex the next one. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 278 | /// 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 Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 283 | "Should consume special tokens with Consume*Token"); |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 284 | PrevTokLocation = Tok.getLocation(); |
| 285 | PP.Lex(Tok); |
| 286 | return PrevTokLocation; |
| 287 | } |
| 288 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 289 | 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 Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 306 | private: |
| 307 | //===--------------------------------------------------------------------===// |
| 308 | // Low-Level token peeking and consumption methods. |
| 309 | // |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 310 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 311 | /// 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 Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 323 | /// isTokenStringLiteral - True if this token is a string-literal. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 324 | bool isTokenStringLiteral() const { |
Richard Smith | 0b91cc4 | 2013-03-09 23:30:15 +0000 | [diff] [blame] | 325 | return tok::isStringLiteral(Tok.getKind()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 326 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 327 | /// 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 Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 332 | |
Richard Trieu | fcaf27e | 2012-01-19 22:01:51 +0000 | [diff] [blame] | 333 | /// \brief Returns true if the current token is '=' or is a type of '='. |
| 334 | /// For typos, give a fixit to '=' |
| 335 | bool isTokenEqualOrEqualTypo(); |
Argyrios Kyrtzidis | a6eb5f8 | 2010-10-08 02:39:23 +0000 | [diff] [blame] | 336 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 337 | /// \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 Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 342 | PP.Lex(Tok); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 343 | PP.EnterToken(Next); |
| 344 | } |
| 345 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 346 | /// 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 Kyrtzidis | ab2d09b | 2013-03-27 23:58:17 +0000 | [diff] [blame] | 349 | SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok = false) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 350 | if (isTokenParen()) |
| 351 | return ConsumeParen(); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 352 | if (isTokenBracket()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 353 | return ConsumeBracket(); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 354 | if (isTokenBrace()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 355 | return ConsumeBrace(); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 356 | if (isTokenStringLiteral()) |
Steve Naroff | d62701b | 2008-02-07 03:50:06 +0000 | [diff] [blame] | 357 | return ConsumeStringToken(); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 358 | if (Tok.is(tok::code_completion)) |
| 359 | return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken() |
| 360 | : handleUnexpectedCodeCompletionToken(); |
| 361 | return ConsumeToken(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 362 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 364 | /// 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 Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 372 | PrevTokLocation = Tok.getLocation(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 373 | PP.Lex(Tok); |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 374 | return PrevTokLocation; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 375 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 376 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 377 | /// 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 Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 385 | |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 386 | PrevTokLocation = Tok.getLocation(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 387 | PP.Lex(Tok); |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 388 | return PrevTokLocation; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 389 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 390 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 391 | /// 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 Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 400 | PrevTokLocation = Tok.getLocation(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 401 | PP.Lex(Tok); |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 402 | return PrevTokLocation; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 403 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 405 | /// 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 Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 412 | PrevTokLocation = Tok.getLocation(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 413 | PP.Lex(Tok); |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 414 | return PrevTokLocation; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 415 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | |
Douglas Gregor | dc84534 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 417 | /// \brief Consume the current code-completion token. |
| 418 | /// |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 419 | /// 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 Gregor | dc84534 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 422 | SourceLocation ConsumeCodeCompletionToken() { |
| 423 | assert(Tok.is(tok::code_completion)); |
| 424 | PrevTokLocation = Tok.getLocation(); |
| 425 | PP.Lex(Tok); |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 426 | return PrevTokLocation; |
Douglas Gregor | dc84534 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 427 | } |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 428 | |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 429 | ///\ brief When we are consuming a code-completion token without having |
Douglas Gregor | dc84534 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 430 | /// matched specific position in the grammar, provide code-completion results |
| 431 | /// based on context. |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 432 | /// |
| 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 Kyrtzidis | 3b7deda | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 439 | if (PP.isCodeCompletionEnabled()) |
| 440 | PP.setCodeCompletionReached(); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 441 | // Cut off parsing by acting as if we reached the end-of-file. |
| 442 | Tok.setKind(tok::eof); |
| 443 | } |
Douglas Gregor | dc84534 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 444 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 445 | /// \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 Kyrtzidis | b918d0f | 2011-01-17 18:58:44 +0000 | [diff] [blame] | 459 | /// \brief Handle the annotation token produced for #pragma unused(...) |
| 460 | void HandlePragmaUnused(); |
| 461 | |
Rafael Espindola | 426fc94 | 2012-01-26 02:02:57 +0000 | [diff] [blame] | 462 | /// \brief Handle the annotation token produced for |
| 463 | /// #pragma GCC visibility... |
| 464 | void HandlePragmaVisibility(); |
| 465 | |
Eli Friedman | aa5ab26 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 466 | /// \brief Handle the annotation token produced for |
| 467 | /// #pragma pack... |
| 468 | void HandlePragmaPack(); |
| 469 | |
Eli Friedman | 9595c7e | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 470 | /// \brief Handle the annotation token produced for |
| 471 | /// #pragma ms_struct... |
| 472 | void HandlePragmaMSStruct(); |
| 473 | |
| 474 | /// \brief Handle the annotation token produced for |
Reid Kleckner | 3190ca9 | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 475 | /// #pragma comment... |
| 476 | void HandlePragmaMSComment(); |
| 477 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 478 | void HandlePragmaMSPointersToMembers(); |
| 479 | |
| 480 | void HandlePragmaMSVtorDisp(); |
| 481 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 482 | void HandlePragmaMSPragma(); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 483 | bool HandlePragmaMSSection(StringRef PragmaName, |
| 484 | SourceLocation PragmaLocation); |
| 485 | bool HandlePragmaMSSegment(StringRef PragmaName, |
| 486 | SourceLocation PragmaLocation); |
| 487 | bool HandlePragmaMSInitSeg(StringRef PragmaName, |
| 488 | SourceLocation PragmaLocation); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 489 | |
Reid Kleckner | 3190ca9 | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 490 | /// \brief Handle the annotation token produced for |
Eli Friedman | 9595c7e | 2012-10-04 02:36:51 +0000 | [diff] [blame] | 491 | /// #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. Siraj | 85192c7 | 2013-04-16 18:41:26 +0000 | [diff] [blame] | 514 | /// \brief Handle the annotation token produced for |
| 515 | /// #pragma clang __debug captured |
| 516 | StmtResult HandlePragmaCaptured(); |
| 517 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 518 | /// \brief Handle the annotation token produced for |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 519 | /// #pragma clang loop and #pragma unroll. |
| 520 | bool HandlePragmaLoopHint(LoopHint &Hint); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 521 | |
Chris Lattner | 6b88450 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 522 | /// 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 Kyrtzidis | 03db1b3 | 2008-08-10 13:15:22 +0000 | [diff] [blame] | 529 | const Token &GetLookAheadToken(unsigned N) { |
Chris Lattner | 6b88450 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 530 | if (N == 0 || Tok.is(tok::eof)) return Tok; |
| 531 | return PP.LookAhead(N-1); |
| 532 | } |
Argyrios Kyrtzidis | f7da726 | 2008-07-09 22:53:07 +0000 | [diff] [blame] | 533 | |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 534 | public: |
Argyrios Kyrtzidis | f7da726 | 2008-07-09 22:53:07 +0000 | [diff] [blame] | 535 | /// NextToken - This peeks ahead one token and returns it without |
| 536 | /// consuming it. |
| 537 | const Token &NextToken() { |
Argyrios Kyrtzidis | 03db1b3 | 2008-08-10 13:15:22 +0000 | [diff] [blame] | 538 | return PP.LookAhead(0); |
Argyrios Kyrtzidis | f7da726 | 2008-07-09 22:53:07 +0000 | [diff] [blame] | 539 | } |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 540 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 541 | /// 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 Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 546 | private: |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 547 | static void setTypeAnnotation(Token &Tok, ParsedType T) { |
| 548 | Tok.setAnnotationValue(T.getAsOpaquePtr()); |
| 549 | } |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 550 | |
Douglas Gregor | 5ecdd78 | 2011-04-27 06:18:01 +0000 | [diff] [blame] | 551 | /// \brief Read an already-translated primary expression out of an annotation |
| 552 | /// token. |
| 553 | static ExprResult getExprAnnotation(Token &Tok) { |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 554 | return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue()); |
Douglas Gregor | 5ecdd78 | 2011-04-27 06:18:01 +0000 | [diff] [blame] | 555 | } |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 556 | |
Douglas Gregor | 5ecdd78 | 2011-04-27 06:18:01 +0000 | [diff] [blame] | 557 | /// \brief Set the primary expression corresponding to the given annotation |
| 558 | /// token. |
| 559 | static void setExprAnnotation(Token &Tok, ExprResult ER) { |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 560 | Tok.setAnnotationValue(ER.getAsOpaquePointer()); |
Douglas Gregor | 5ecdd78 | 2011-04-27 06:18:01 +0000 | [diff] [blame] | 561 | } |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 562 | |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 563 | public: |
Kaelyn Uhrain | fac9467 | 2011-10-11 01:02:41 +0000 | [diff] [blame] | 564 | // 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 Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 568 | bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool EnteringContext, |
| 569 | bool NeedType, |
| 570 | CXXScopeSpec &SS, |
| 571 | bool IsNewScope); |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 572 | bool TryAnnotateCXXScopeToken(bool EnteringContext = false); |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 573 | |
| 574 | private: |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 575 | 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 Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 587 | AnnotatedNameKind |
| 588 | TryAnnotateName(bool IsAddressOfOperand, |
| 589 | std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr); |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 590 | |
| 591 | /// Push a tok::annot_cxxscope token onto the token stream. |
| 592 | void AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 593 | |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 594 | /// 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 Lattner | b3a4e43 | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 598 | const char *&PrevSpec, unsigned &DiagID, |
| 599 | bool &isInvalid) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 600 | if (!getLangOpts().AltiVec || |
Chris Lattner | 1b49242 | 2010-02-28 18:33:55 +0000 | [diff] [blame] | 601 | (Tok.getIdentifierInfo() != Ident_vector && |
Bill Schmidt | 3e3d20b | 2013-07-03 20:54:09 +0000 | [diff] [blame] | 602 | Tok.getIdentifierInfo() != Ident_pixel && |
| 603 | Tok.getIdentifierInfo() != Ident_bool)) |
Chris Lattner | 1b49242 | 2010-02-28 18:33:55 +0000 | [diff] [blame] | 604 | return false; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 605 | |
Chris Lattner | 1b49242 | 2010-02-28 18:33:55 +0000 | [diff] [blame] | 606 | return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 607 | } |
| 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 Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 613 | if (!getLangOpts().AltiVec || |
Chris Lattner | b3a4e43 | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 614 | Tok.getIdentifierInfo() != Ident_vector) return false; |
Chris Lattner | 1b49242 | 2010-02-28 18:33:55 +0000 | [diff] [blame] | 615 | return TryAltiVecVectorTokenOutOfLine(); |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 616 | } |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 617 | |
Chris Lattner | 1b49242 | 2010-02-28 18:33:55 +0000 | [diff] [blame] | 618 | bool TryAltiVecVectorTokenOutOfLine(); |
| 619 | bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, |
| 620 | const char *&PrevSpec, unsigned &DiagID, |
| 621 | bool &isInvalid); |
Argyrios Kyrtzidis | 25a7676 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 622 | |
Bill Wendling | 03e463e | 2013-12-16 02:32:55 +0000 | [diff] [blame] | 623 | /// 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 Kramer | 13bb701 | 2012-04-14 12:14:03 +0000 | [diff] [blame] | 630 | /// \brief Get the TemplateIdAnnotation from the token. |
Argyrios Kyrtzidis | 25a7676 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 631 | TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok); |
| 632 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 633 | /// 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 Gregor | 314b97f | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 639 | /// TentativeParsingAction TPA(*this); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 640 | /// ConsumeToken(); |
| 641 | /// .... |
| 642 | /// TPA.Revert(); |
| 643 | /// |
| 644 | class TentativeParsingAction { |
| 645 | Parser &P; |
| 646 | Token PrevTok; |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 647 | size_t PrevTentativelyDeclaredIdentifierCount; |
Douglas Gregor | de88246 | 2012-04-30 16:20:27 +0000 | [diff] [blame] | 648 | unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount; |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 649 | bool isActive; |
| 650 | |
| 651 | public: |
| 652 | explicit TentativeParsingAction(Parser& p) : P(p) { |
| 653 | PrevTok = P.Tok; |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 654 | PrevTentativelyDeclaredIdentifierCount = |
| 655 | P.TentativelyDeclaredIdentifiers.size(); |
Douglas Gregor | de88246 | 2012-04-30 16:20:27 +0000 | [diff] [blame] | 656 | PrevParenCount = P.ParenCount; |
| 657 | PrevBracketCount = P.BracketCount; |
| 658 | PrevBraceCount = P.BraceCount; |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 659 | P.PP.EnableBacktrackAtThisPos(); |
| 660 | isActive = true; |
| 661 | } |
| 662 | void Commit() { |
| 663 | assert(isActive && "Parsing action was finished!"); |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 664 | P.TentativelyDeclaredIdentifiers.resize( |
| 665 | PrevTentativelyDeclaredIdentifierCount); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 666 | 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 Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 673 | P.TentativelyDeclaredIdentifiers.resize( |
| 674 | PrevTentativelyDeclaredIdentifierCount); |
Douglas Gregor | de88246 | 2012-04-30 16:20:27 +0000 | [diff] [blame] | 675 | P.ParenCount = PrevParenCount; |
| 676 | P.BracketCount = PrevBracketCount; |
| 677 | P.BraceCount = PrevBraceCount; |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 678 | isActive = false; |
| 679 | } |
| 680 | ~TentativeParsingAction() { |
| 681 | assert(!isActive && "Forgot to call Commit or Revert!"); |
| 682 | } |
| 683 | }; |
Richard Smith | 9bd3cdc | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 684 | class UnannotatedTentativeParsingAction; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 685 | |
Fariborz Jahanian | 9735c5e | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 686 | /// 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 Rose | 94f29f4 | 2012-07-09 16:54:53 +0000 | [diff] [blame] | 692 | SaveAndRestore<bool> WithinObjCContainer; |
Fariborz Jahanian | 9735c5e | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 693 | public: |
Jordan Rose | 94f29f4 | 2012-07-09 16:54:53 +0000 | [diff] [blame] | 694 | explicit ObjCDeclContextSwitch(Parser &p) |
| 695 | : P(p), DC(p.getObjCDeclContext()), |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 696 | WithinObjCContainer(P.ParsingInObjCContainer, DC != nullptr) { |
Fariborz Jahanian | 9735c5e | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 697 | if (DC) |
Argyrios Kyrtzidis | 458bacf | 2011-10-27 00:09:34 +0000 | [diff] [blame] | 698 | P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC)); |
Fariborz Jahanian | 9735c5e | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 699 | } |
| 700 | ~ObjCDeclContextSwitch() { |
| 701 | if (DC) |
Argyrios Kyrtzidis | 458bacf | 2011-10-27 00:09:34 +0000 | [diff] [blame] | 702 | P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC)); |
Fariborz Jahanian | 9735c5e | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 703 | } |
| 704 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 706 | /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the |
| 707 | /// input. If so, it is consumed and false is returned. |
| 708 | /// |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 709 | /// 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 Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 713 | /// returned. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 714 | bool ExpectAndConsume(tok::TokenKind ExpectedTok, |
| 715 | unsigned Diag = diag::err_expected, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 716 | StringRef DiagMsg = ""); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 717 | |
Douglas Gregor | 9ba23b4 | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 718 | /// \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 Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 724 | |
Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 725 | /// \brief The kind of extra semi diagnostic to emit. |
Richard Trieu | 4b0e6f1 | 2012-05-16 19:04:59 +0000 | [diff] [blame] | 726 | enum ExtraSemiKind { |
| 727 | OutsideFunction = 0, |
| 728 | InsideStruct = 1, |
| 729 | InstanceVariableList = 2, |
Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 730 | AfterMemberFunctionDefinition = 3 |
Richard Trieu | 4b0e6f1 | 2012-05-16 19:04:59 +0000 | [diff] [blame] | 731 | }; |
| 732 | |
| 733 | /// \brief Consume any extra semi-colons until the end of the line. |
Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 734 | void ConsumeExtraSemi(ExtraSemiKind Kind, unsigned TST = TST_unspecified); |
Richard Trieu | 4b0e6f1 | 2012-05-16 19:04:59 +0000 | [diff] [blame] | 735 | |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 736 | public: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 737 | //===--------------------------------------------------------------------===// |
| 738 | // Scope manipulation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 740 | /// 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 Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 748 | ParseScope(const ParseScope &) = delete; |
| 749 | void operator=(const ParseScope &) = delete; |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 750 | |
| 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 Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 754 | // 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 Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 757 | : Self(Self) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 758 | if (EnteredScope && !BeforeCompoundStmt) |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 759 | Self->EnterScope(ScopeFlags); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 760 | else { |
| 761 | if (BeforeCompoundStmt) |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 762 | Self->incrementMSManglingNumber(); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 763 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 764 | this->Self = nullptr; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 765 | } |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 766 | } |
| 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 Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 773 | Self = nullptr; |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | |
| 777 | ~ParseScope() { |
| 778 | Exit(); |
| 779 | } |
| 780 | }; |
| 781 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 782 | /// EnterScope - Start a new scope. |
| 783 | void EnterScope(unsigned ScopeFlags); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 784 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 785 | /// ExitScope - Pop a scope off the scope stack. |
| 786 | void ExitScope(); |
| 787 | |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 788 | private: |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 789 | /// \brief RAII object used to modify the scope flags for the current scope. |
| 790 | class ParseScopeFlags { |
| 791 | Scope *CurScope; |
| 792 | unsigned OldFlags; |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 793 | ParseScopeFlags(const ParseScopeFlags &) = delete; |
| 794 | void operator=(const ParseScopeFlags &) = delete; |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 795 | |
| 796 | public: |
| 797 | ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true); |
| 798 | ~ParseScopeFlags(); |
| 799 | }; |
| 800 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 801 | //===--------------------------------------------------------------------===// |
| 802 | // Diagnostic Emission and Error recovery. |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 803 | |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 804 | public: |
Chris Lattner | 3cbfe2c | 2008-11-22 00:59:29 +0000 | [diff] [blame] | 805 | DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); |
| 806 | DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); |
Jordan Rose | d73ef13 | 2012-06-06 17:25:21 +0000 | [diff] [blame] | 807 | DiagnosticBuilder Diag(unsigned DiagID) { |
| 808 | return Diag(Tok, DiagID); |
| 809 | } |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 810 | |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 811 | private: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 812 | void SuggestParentheses(SourceLocation Loc, unsigned DK, |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 813 | SourceRange ParenRange); |
Erik Verbruggen | d64251f | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 814 | void CheckNestedObjCContexts(SourceLocation AtLoc); |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 815 | |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 816 | public: |
Alexey Bataev | 8fe2475 | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 817 | |
NAKAMURA Takumi | 155c877 | 2013-11-18 10:38:28 +0000 | [diff] [blame] | 818 | /// \brief Control flags for SkipUntil functions. |
Alexey Bataev | 8fe2475 | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 819 | enum SkipUntilFlags { |
NAKAMURA Takumi | 155c877 | 2013-11-18 10:38:28 +0000 | [diff] [blame] | 820 | StopAtSemi = 1 << 0, ///< Stop skipping at semicolon |
Alexey Bataev | 8fe2475 | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 821 | /// \brief Stop skipping at specified token, but don't skip the token itself |
| 822 | StopBeforeMatch = 1 << 1, |
NAKAMURA Takumi | 155c877 | 2013-11-18 10:38:28 +0000 | [diff] [blame] | 823 | StopAtCodeCompletion = 1 << 2 ///< Stop at code completion |
Alexey Bataev | 8fe2475 | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 824 | }; |
| 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 Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 832 | /// SkipUntil - Read tokens until we get to the specified token, then consume |
Alexey Bataev | 8fe2475 | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 833 | /// 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 Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 837 | /// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 838 | /// If SkipUntil finds the specified token, it returns true, otherwise it |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 839 | /// returns false. |
Alexey Bataev | 8fe2475 | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 840 | bool SkipUntil(tok::TokenKind T, |
| 841 | SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) { |
| 842 | return SkipUntil(llvm::makeArrayRef(T), Flags); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 843 | } |
Alexey Bataev | 8fe2475 | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 844 | bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, |
| 845 | SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 846 | tok::TokenKind TokArray[] = {T1, T2}; |
Alexey Bataev | 8fe2475 | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 847 | return SkipUntil(TokArray, Flags); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 848 | } |
David Blaikie | eb52f86a | 2012-04-09 16:37:11 +0000 | [diff] [blame] | 849 | bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3, |
Alexey Bataev | 8fe2475 | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 850 | SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) { |
David Blaikie | eb52f86a | 2012-04-09 16:37:11 +0000 | [diff] [blame] | 851 | tok::TokenKind TokArray[] = {T1, T2, T3}; |
Alexey Bataev | 8fe2475 | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 852 | return SkipUntil(TokArray, Flags); |
David Blaikie | eb52f86a | 2012-04-09 16:37:11 +0000 | [diff] [blame] | 853 | } |
Alexey Bataev | 8fe2475 | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 854 | bool SkipUntil(ArrayRef<tok::TokenKind> Toks, |
| 855 | SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 856 | |
Richard Smith | 994d73f | 2012-04-11 20:59:20 +0000 | [diff] [blame] | 857 | /// SkipMalformedDecl - Read tokens until we get to some likely good stopping |
| 858 | /// point for skipping past a simple-declaration. |
| 859 | void SkipMalformedDecl(); |
| 860 | |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 861 | private: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 862 | //===--------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 863 | // Lexing and parsing of C++ inline methods. |
| 864 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 865 | 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 Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 871 | /// - and brace-or-equal-initializers for non-static data members |
| 872 | /// (including such things in nested classes)." |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 873 | /// 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 Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 880 | virtual void ParseLexedMemberInitializers(); |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 881 | virtual void ParseLexedMethodDefs(); |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 882 | virtual void ParseLexedAttributes(); |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 883 | }; |
| 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 Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame] | 890 | ~LateParsedClass() override; |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 891 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 892 | void ParseLexedMethodDeclarations() override; |
| 893 | void ParseLexedMemberInitializers() override; |
| 894 | void ParseLexedMethodDefs() override; |
| 895 | void ParseLexedAttributes() override; |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 896 | |
| 897 | private: |
| 898 | Parser *Self; |
| 899 | ParsingClass *Class; |
| 900 | }; |
| 901 | |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 902 | /// 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 Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 905 | /// 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 Hutchins | 2287c5e | 2012-03-02 22:12:59 +0000 | [diff] [blame] | 913 | SmallVector<Decl*, 2> Decls; |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 914 | |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 915 | explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name, |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 916 | SourceLocation Loc) |
DeLesley Hutchins | 2287c5e | 2012-03-02 22:12:59 +0000 | [diff] [blame] | 917 | : Self(P), AttrName(Name), AttrNameLoc(Loc) {} |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 918 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 919 | void ParseLexedAttributes() override; |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 920 | |
DeLesley Hutchins | 2287c5e | 2012-03-02 22:12:59 +0000 | [diff] [blame] | 921 | void addDecl(Decl *D) { Decls.push_back(D); } |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 922 | }; |
| 923 | |
DeLesley Hutchins | 161db02 | 2012-11-02 21:44:32 +0000 | [diff] [blame] | 924 | // A list of late-parsed attributes. Used by ParseGNUAttributes. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 925 | class LateParsedAttrList: public SmallVector<LateParsedAttribute *, 2> { |
DeLesley Hutchins | 161db02 | 2012-11-02 21:44:32 +0000 | [diff] [blame] | 926 | public: |
| 927 | LateParsedAttrList(bool PSoon = false) : ParseSoon(PSoon) { } |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 928 | |
DeLesley Hutchins | 161db02 | 2012-11-02 21:44:32 +0000 | [diff] [blame] | 929 | bool parseSoon() { return ParseSoon; } |
| 930 | |
| 931 | private: |
| 932 | bool ParseSoon; // Are we planning to parse these shortly after creation? |
| 933 | }; |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 934 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 935 | /// 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 McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 940 | Decl *D; |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 941 | CachedTokens Toks; |
Douglas Gregor | d83d040 | 2009-08-22 00:34:47 +0000 | [diff] [blame] | 942 | |
| 943 | /// \brief Whether this member function had an associated template |
| 944 | /// scope. When true, D is a template declaration. |
Nico Weber | f5e9d03 | 2012-12-14 02:41:18 +0000 | [diff] [blame] | 945 | /// otherwise, it is a member function declaration. |
Douglas Gregor | d83d040 | 2009-08-22 00:34:47 +0000 | [diff] [blame] | 946 | bool TemplateScope; |
| 947 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 948 | explicit LexedMethod(Parser* P, Decl *MD) |
| 949 | : Self(P), D(MD), TemplateScope(false) {} |
| 950 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 951 | void ParseLexedMethodDefs() override; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 952 | }; |
| 953 | |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 954 | /// 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 McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 959 | explicit LateParsedDefaultArgument(Decl *P, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 960 | CachedTokens *Toks = nullptr) |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 961 | : Param(P), Toks(Toks) { } |
| 962 | |
| 963 | /// Param - The parameter declaration for this parameter. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 964 | Decl *Param; |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 965 | |
| 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 Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 972 | |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 973 | /// 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 Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 977 | struct LateParsedMethodDeclaration : public LateParsedDeclaration { |
| 978 | explicit LateParsedMethodDeclaration(Parser *P, Decl *M) |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 979 | : Self(P), Method(M), TemplateScope(false), |
| 980 | ExceptionSpecTokens(nullptr) {} |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 981 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 982 | void ParseLexedMethodDeclarations() override; |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 983 | |
| 984 | Parser* Self; |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 985 | |
| 986 | /// Method - The method declaration. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 987 | Decl *Method; |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 988 | |
Douglas Gregor | d83d040 | 2009-08-22 00:34:47 +0000 | [diff] [blame] | 989 | /// \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 Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 993 | |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 994 | /// 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 Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 998 | /// scope at the appropriate times. |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 999 | SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; |
Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 1000 | |
| 1001 | /// \brief The set of tokens that make up an exception-specification that |
| 1002 | /// has not yet been parsed. |
| 1003 | CachedTokens *ExceptionSpecTokens; |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1004 | }; |
| 1005 | |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1006 | /// 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 Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1013 | void ParseLexedMemberInitializers() override; |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1014 | |
| 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 Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 1025 | /// LateParsedDeclarationsContainer - During parsing of a top (non-nested) |
| 1026 | /// C++ class, its method declarations that contain parts that won't be |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 1027 | /// parsed until after the definition is completed (C++ [class.mem]p2), |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 1028 | /// the method declarations and possibly attached inline definitions |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1029 | /// will be stored here with the tokens that will be parsed to create those |
| 1030 | /// entities. |
| 1031 | typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1032 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1033 | /// \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 McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1037 | ParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | : TopLevelClass(TopLevelClass), TemplateScope(false), |
John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1039 | IsInterface(IsInterface), TagOrTemplate(TagOrTemplate) { } |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1040 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1041 | /// \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 McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1050 | /// \brief Whether this class is an __interface. |
| 1051 | bool IsInterface : 1; |
| 1052 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1053 | /// \brief The class or class template whose definition we are parsing. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1054 | Decl *TagOrTemplate; |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1055 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 1056 | /// 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 Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1060 | }; |
| 1061 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1062 | /// \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 Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1066 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1067 | ParsingClass &getCurrentClass() { |
| 1068 | assert(!ClassStack.empty() && "No lexed method stacks!"); |
| 1069 | return *ClassStack.top(); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
John McCall | 9257664 | 2012-05-07 06:16:41 +0000 | [diff] [blame] | 1072 | /// \brief RAII object used to manage the parsing of a class definition. |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1073 | class ParsingClassDefinition { |
| 1074 | Parser &P; |
| 1075 | bool Popped; |
John McCall | eee1d54 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 1076 | Sema::ParsingClassState State; |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1077 | |
| 1078 | public: |
John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1079 | ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass, |
| 1080 | bool IsInterface) |
John McCall | eee1d54 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 1081 | : P(P), Popped(false), |
John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1082 | State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) { |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | /// \brief Pop this class of the stack. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1086 | void Pop() { |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1087 | assert(!Popped && "Nested class has already been popped"); |
| 1088 | Popped = true; |
John McCall | eee1d54 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 1089 | P.PopParsingClass(State); |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | ~ParsingClassDefinition() { |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1093 | if (!Popped) |
John McCall | eee1d54 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 1094 | P.PopParsingClass(State); |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1095 | } |
| 1096 | }; |
| 1097 | |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1098 | /// \brief Contains information about any template-specific |
| 1099 | /// information that has been parsed prior to parsing declaration |
| 1100 | /// specifiers. |
| 1101 | struct ParsedTemplateInfo { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | ParsedTemplateInfo() |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1103 | : Kind(NonTemplate), TemplateParams(nullptr), TemplateLoc() { } |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1104 | |
| 1105 | ParsedTemplateInfo(TemplateParameterLists *TemplateParams, |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 1106 | bool isSpecialization, |
| 1107 | bool lastParameterListWasEmpty = false) |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1108 | : Kind(isSpecialization? ExplicitSpecialization : Template), |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1109 | TemplateParams(TemplateParams), |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 1110 | LastParameterListWasEmpty(lastParameterListWasEmpty) { } |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1111 | |
Douglas Gregor | 45f9655 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 1112 | explicit ParsedTemplateInfo(SourceLocation ExternLoc, |
| 1113 | SourceLocation TemplateLoc) |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1114 | : Kind(ExplicitInstantiation), TemplateParams(nullptr), |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 1115 | ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), |
| 1116 | LastParameterListWasEmpty(false){ } |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1117 | |
| 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 Gregor | 45f9655 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 1134 | /// \brief The location of the 'extern' keyword, if any, for an explicit |
| 1135 | /// instantiation |
| 1136 | SourceLocation ExternLoc; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1138 | /// \brief The location of the 'template' keyword, for an explicit |
| 1139 | /// instantiation. |
| 1140 | SourceLocation TemplateLoc; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1141 | |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 1142 | /// \brief Whether the last template parameter list was empty. |
| 1143 | bool LastParameterListWasEmpty; |
John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 1144 | |
Daniel Dunbar | aa49a7d | 2012-03-09 19:35:29 +0000 | [diff] [blame] | 1145 | SourceRange getSourceRange() const LLVM_READONLY; |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1146 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1147 | |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 1148 | void LexTemplateFunctionForLateParsing(CachedTokens &Toks); |
Richard Smith | ac32d90 | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1149 | void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 1150 | |
Richard Smith | ac32d90 | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1151 | static void LateTemplateParserCallback(void *P, LateParsedTemplate &LPT); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1152 | static void LateTemplateParserCleanupCallback(void *P); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 1153 | |
John McCall | eee1d54 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 1154 | Sema::ParsingClassState |
John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1155 | PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface); |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1156 | void DeallocateParsedClasses(ParsingClass *Class); |
John McCall | eee1d54 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 1157 | void PopParsingClass(Sema::ParsingClassState); |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1158 | |
Richard Smith | 9bd3cdc | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1159 | enum CachedInitKind { |
| 1160 | CIK_DefaultArgument, |
| 1161 | CIK_DefaultInitializer |
| 1162 | }; |
| 1163 | |
Rafael Espindola | 0777cf5 | 2013-01-08 21:00:12 +0000 | [diff] [blame] | 1164 | NamedDecl *ParseCXXInlineMethodDef(AccessSpecifier AS, |
| 1165 | AttributeList *AccessAttrs, |
Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 1166 | ParsingDeclarator &D, |
Nico Weber | 4867347 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 1167 | const ParsedTemplateInfo &TemplateInfo, |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1168 | const VirtSpecifiers& VS, |
Douglas Gregor | 45fa560 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 1169 | ExprResult& Init); |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1170 | void ParseCXXNonStaticMemberInitializer(Decl *VarD); |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 1171 | void ParseLexedAttributes(ParsingClass &Class); |
DeLesley Hutchins | c24a233 | 2012-02-16 16:50:43 +0000 | [diff] [blame] | 1172 | void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D, |
| 1173 | bool EnterScope, bool OnDefinition); |
| 1174 | void ParseLexedAttribute(LateParsedAttribute &LA, |
| 1175 | bool EnterScope, bool OnDefinition); |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1176 | void ParseLexedMethodDeclarations(ParsingClass &Class); |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 1177 | void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM); |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1178 | void ParseLexedMethodDefs(ParsingClass &Class); |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 1179 | void ParseLexedMethodDef(LexedMethod &LM); |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1180 | void ParseLexedMemberInitializers(ParsingClass &Class); |
| 1181 | void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI); |
Fariborz Jahanian | 6c89eaf | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 1182 | void ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod); |
Sebastian Redl | a891a32 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 1183 | bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks); |
Richard Smith | 9bd3cdc | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1184 | bool ConsumeAndStoreInitializer(CachedTokens &Toks, CachedInitKind CIK); |
| 1185 | bool ConsumeAndStoreConditional(CachedTokens &Toks); |
Argyrios Kyrtzidis | 14b9162 | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 1186 | 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 Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1193 | CachedTokens &Toks, |
Argyrios Kyrtzidis | 14b9162 | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 1194 | bool StopAtSemi = true, |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1195 | bool ConsumeFinalToken = true); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1196 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1197 | //===--------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1198 | // C99 6.9: External Definitions. |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1199 | struct ParsedAttributesWithRange : ParsedAttributes { |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1200 | ParsedAttributesWithRange(AttributeFactory &factory) |
| 1201 | : ParsedAttributes(factory) {} |
| 1202 | |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1203 | SourceRange Range; |
| 1204 | }; |
| 1205 | |
| 1206 | DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1207 | ParsingDeclSpec *DS = nullptr); |
Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 1208 | bool isDeclarationAfterDeclarator(); |
Chris Lattner | 004659a | 2010-07-11 22:42:07 +0000 | [diff] [blame] | 1209 | bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); |
Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1210 | DeclGroupPtrTy ParseDeclarationOrFunctionDefinition( |
| 1211 | ParsedAttributesWithRange &attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1212 | ParsingDeclSpec *DS = nullptr, |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1213 | AccessSpecifier AS = AS_none); |
Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1214 | DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs, |
| 1215 | ParsingDeclSpec &DS, |
| 1216 | AccessSpecifier AS); |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1217 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1218 | Decl *ParseFunctionDefinition(ParsingDeclarator &D, |
DeLesley Hutchins | c24a233 | 2012-02-16 16:50:43 +0000 | [diff] [blame] | 1219 | const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1220 | LateParsedAttrList *LateParsedAttrs = nullptr); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1221 | void ParseKNRParamDeclarations(Declarator &D); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1222 | // EndLoc, if non-NULL, is filled with the location of the last token of |
| 1223 | // the simple-asm. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1224 | ExprResult ParseSimpleAsm(SourceLocation *EndLoc = nullptr); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1225 | ExprResult ParseAsmStringLiteral(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1226 | |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1227 | // Objective-C External Declarations |
Nico Weber | e145bfd | 2013-04-04 00:15:10 +0000 | [diff] [blame] | 1228 | void MaybeSkipAttributes(tok::ObjCKeywordKind Kind); |
Douglas Gregor | bd9482d | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 1229 | DeclGroupPtrTy ParseObjCAtDirectives(); |
| 1230 | DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); |
Erik Verbruggen | d64251f | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 1231 | Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1232 | ParsedAttributes &prefixAttrs); |
Fariborz Jahanian | 4cc0cf1 | 2013-03-20 18:09:33 +0000 | [diff] [blame] | 1233 | void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc, |
| 1234 | BalancedDelimiterTracker &T, |
| 1235 | SmallVectorImpl<Decl *> &AllIvarDecls, |
| 1236 | bool RBraceMissing); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1237 | void ParseObjCClassInstanceVariables(Decl *interfaceDecl, |
Fariborz Jahanian | 83c481a | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 1238 | tok::ObjCKeywordKind visibility, |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1239 | SourceLocation atLoc); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 1240 | bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P, |
| 1241 | SmallVectorImpl<SourceLocation> &PLocs, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | bool WarnOnDeclarations, |
Argyrios Kyrtzidis | 71b0add | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1243 | SourceLocation &LAngleLoc, |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1244 | SourceLocation &EndProtoLoc); |
Douglas Gregor | 46f936e | 2010-11-19 17:10:50 +0000 | [diff] [blame] | 1245 | bool ParseObjCProtocolQualifiers(DeclSpec &DS); |
Fariborz Jahanian | 2f64cfe | 2011-08-22 21:44:58 +0000 | [diff] [blame] | 1246 | void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, |
| 1247 | Decl *CDecl); |
Douglas Gregor | bd9482d | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 1248 | DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc, |
| 1249 | ParsedAttributes &prefixAttrs); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1250 | |
Argyrios Kyrtzidis | 849639d | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1251 | struct ObjCImplParsingDataRAII { |
| 1252 | Parser &P; |
| 1253 | Decl *Dcl; |
Fariborz Jahanian | 6c89eaf | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 1254 | bool HasCFunction; |
Argyrios Kyrtzidis | 849639d | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1255 | typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer; |
| 1256 | LateParsedObjCMethodContainer LateParsedObjCMethods; |
Steve Naroff | 0416fb9 | 2007-11-11 17:19:15 +0000 | [diff] [blame] | 1257 | |
Argyrios Kyrtzidis | 849639d | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1258 | ObjCImplParsingDataRAII(Parser &parser, Decl *D) |
Fariborz Jahanian | 6c89eaf | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 1259 | : P(parser), Dcl(D), HasCFunction(false) { |
Argyrios Kyrtzidis | 849639d | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1260 | 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 Jahanian | 6c89eaf | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 1272 | void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl); |
Argyrios Kyrtzidis | 849639d | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1273 | |
| 1274 | DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc); |
Fariborz Jahanian | 140ab23 | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 1275 | DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1276 | Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc); |
| 1277 | Decl *ParseObjCPropertySynthesize(SourceLocation atLoc); |
| 1278 | Decl *ParseObjCPropertyDynamic(SourceLocation atLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1279 | |
Chris Lattner | 2fc5c24 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 1280 | IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); |
Chris Lattner | 34870da | 2007-08-29 22:54:08 +0000 | [diff] [blame] | 1281 | // 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 Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1286 | IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1287 | |
Fariborz Jahanian | 335a2d4 | 2008-01-04 23:04:08 +0000 | [diff] [blame] | 1288 | bool isTokIdentifier_in() const; |
Fariborz Jahanian | d0f97d1 | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 1289 | |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 1290 | ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, Declarator::TheContext Ctx, |
| 1291 | ParsedAttributes *ParamAttrs); |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 1292 | void ParseObjCMethodRequirement(); |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1293 | Decl *ParseObjCMethodPrototype( |
Fariborz Jahanian | 90ba78c | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 1294 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, |
| 1295 | bool MethodDefinition = true); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1296 | Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, |
Fariborz Jahanian | 90ba78c | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 1297 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, |
| 1298 | bool MethodDefinition=true); |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1299 | void ParseObjCPropertyAttribute(ObjCDeclSpec &DS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1300 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1301 | Decl *ParseObjCMethodDefinition(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1302 | |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 1303 | public: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1304 | //===--------------------------------------------------------------------===// |
| 1305 | // C99 6.5: Expressions. |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1306 | |
Kaelyn Uhrain | cd78e61 | 2012-01-25 20:49:08 +0000 | [diff] [blame] | 1307 | /// 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 Uhrain | e43fe99 | 2012-02-22 01:03:07 +0000 | [diff] [blame] | 1315 | ExprResult ParseConstantExpression(TypeCastState isTypeCast = NotTypeCast); |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 1316 | // Expr that doesn't include commas. |
Kaelyn Uhrain | cd78e61 | 2012-01-25 20:49:08 +0000 | [diff] [blame] | 1317 | ExprResult ParseAssignmentExpression(TypeCastState isTypeCast = NotTypeCast); |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 1318 | |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1319 | ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl<Token> &LineToks, |
| 1320 | unsigned &NumLineToksConsumed, |
| 1321 | void *Info, |
| 1322 | bool IsUnevaluated); |
| 1323 | |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 1324 | private: |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1325 | ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1326 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1327 | ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); |
Eli Friedman | adf077f | 2009-01-27 08:43:38 +0000 | [diff] [blame] | 1328 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1329 | ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, |
Douglas Gregor | 312eadb | 2011-04-24 05:37:28 +0000 | [diff] [blame] | 1330 | prec::Level MinPrec); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1331 | ExprResult ParseCastExpression(bool isUnaryExpression, |
Douglas Gregor | 312eadb | 2011-04-24 05:37:28 +0000 | [diff] [blame] | 1332 | bool isAddressOfOperand, |
| 1333 | bool &NotCastExpr, |
Kaelyn Uhrain | cd78e61 | 2012-01-25 20:49:08 +0000 | [diff] [blame] | 1334 | TypeCastState isTypeCast); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1335 | ExprResult ParseCastExpression(bool isUnaryExpression, |
Douglas Gregor | 312eadb | 2011-04-24 05:37:28 +0000 | [diff] [blame] | 1336 | bool isAddressOfOperand = false, |
Kaelyn Uhrain | cd78e61 | 2012-01-25 20:49:08 +0000 | [diff] [blame] | 1337 | TypeCastState isTypeCast = NotTypeCast); |
John McCall | 9c72c60 | 2010-08-27 09:08:28 +0000 | [diff] [blame] | 1338 | |
Richard Smith | 4b08242 | 2012-09-18 00:52:05 +0000 | [diff] [blame] | 1339 | /// Returns true if the next token cannot start an expression. |
| 1340 | bool isNotExpressionStart(); |
| 1341 | |
John McCall | 9c72c60 | 2010-08-27 09:08:28 +0000 | [diff] [blame] | 1342 | /// 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 McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1351 | ExprResult ParsePostfixExpressionSuffix(ExprResult LHS); |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1352 | ExprResult ParseUnaryExprOrTypeTraitExpression(); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1353 | ExprResult ParseBuiltinPrimaryExpression(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1354 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1355 | ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, |
Argyrios Kyrtzidis | 5ab0640 | 2009-05-22 10:22:50 +0000 | [diff] [blame] | 1356 | bool &isCastExpr, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1357 | ParsedType &CastTy, |
Argyrios Kyrtzidis | 5ab0640 | 2009-05-22 10:22:50 +0000 | [diff] [blame] | 1358 | SourceRange &CastRange); |
Argyrios Kyrtzidis | 0cd5b42 | 2008-08-16 20:03:01 +0000 | [diff] [blame] | 1359 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 1360 | typedef SmallVector<Expr*, 20> ExprListTy; |
| 1361 | typedef SmallVector<SourceLocation, 20> CommaLocsTy; |
Argyrios Kyrtzidis | 0cd5b42 | 2008-08-16 20:03:01 +0000 | [diff] [blame] | 1362 | |
| 1363 | /// ParseExpressionList - Used for C/C++ (argument-)expression-list. |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1364 | bool ParseExpressionList(SmallVectorImpl<Expr *> &Exprs, |
| 1365 | SmallVectorImpl<SourceLocation> &CommaLocs, |
| 1366 | std::function<void()> Completer = nullptr); |
Sebastian Redl | d8c4e15 | 2008-12-11 22:33:27 +0000 | [diff] [blame] | 1367 | |
Eli Friedman | 4fce06c | 2013-08-13 23:38:34 +0000 | [diff] [blame] | 1368 | /// 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 Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1374 | /// 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 McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1381 | ExprResult ParseParenExpression(ParenParseOption &ExprType, |
Argyrios Kyrtzidis | 0350ca5 | 2009-05-22 10:23:40 +0000 | [diff] [blame] | 1382 | bool stopIfCastExpr, |
Argyrios Kyrtzidis | 0a85183 | 2011-07-01 22:22:59 +0000 | [diff] [blame] | 1383 | bool isTypeCast, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1384 | ParsedType &CastTy, |
Sebastian Redl | d8c4e15 | 2008-12-11 22:33:27 +0000 | [diff] [blame] | 1385 | SourceLocation &RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1386 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1387 | ExprResult ParseCXXAmbiguousParenExpression( |
| 1388 | ParenParseOption &ExprType, ParsedType &CastTy, |
| 1389 | BalancedDelimiterTracker &Tracker, ColonProtectionRAIIObject &ColonProt); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1390 | ExprResult ParseCompoundLiteralExpression(ParsedType Ty, |
Argyrios Kyrtzidis | d974a7b | 2009-05-22 10:24:05 +0000 | [diff] [blame] | 1391 | SourceLocation LParenLoc, |
| 1392 | SourceLocation RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1393 | |
Richard Smith | 99831e4 | 2012-03-06 03:21:47 +0000 | [diff] [blame] | 1394 | ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral = false); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1395 | |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1396 | ExprResult ParseGenericSelectionExpression(); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1397 | |
| 1398 | ExprResult ParseObjCBoolLiteral(); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1399 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1400 | ExprResult ParseFoldExpression(ExprResult LHS, BalancedDelimiterTracker &T); |
| 1401 | |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1402 | //===--------------------------------------------------------------------===// |
| 1403 | // C++ Expressions |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1404 | ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS, bool isAddressOfOperand, |
| 1405 | Token &Replacement); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1406 | ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); |
Argyrios Kyrtzidis | 4bdd91c | 2008-11-26 21:41:52 +0000 | [diff] [blame] | 1407 | |
Richard Smith | 19a2702 | 2012-06-18 06:11:04 +0000 | [diff] [blame] | 1408 | bool areTokensAdjacent(const Token &A, const Token &B); |
| 1409 | |
Richard Trieu | 950be71 | 2011-09-19 19:01:00 +0000 | [diff] [blame] | 1410 | void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr, |
| 1411 | bool EnteringContext, IdentifierInfo &II, |
| 1412 | CXXScopeSpec &SS); |
| 1413 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1415 | ParsedType ObjectType, |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 1416 | bool EnteringContext, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1417 | bool *MayBePseudoDestructor = nullptr, |
Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 1418 | bool IsTypename = false, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1419 | IdentifierInfo **LastII = nullptr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1420 | |
Richard Trieu | 919b955 | 2012-11-02 01:08:58 +0000 | [diff] [blame] | 1421 | void CheckForLParenAfterColonColon(); |
| 1422 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1423 | //===--------------------------------------------------------------------===// |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 1424 | // C++0x 5.1.2: Lambda expressions |
| 1425 | |
| 1426 | // [...] () -> type {...} |
| 1427 | ExprResult ParseLambdaExpression(); |
| 1428 | ExprResult TryParseLambdaExpression(); |
Richard Smith | 440d456 | 2013-05-21 22:21:19 +0000 | [diff] [blame] | 1429 | Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1430 | bool *SkippedInits = nullptr); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 1431 | bool TryParseLambdaIntroducer(LambdaIntroducer &Intro); |
| 1432 | ExprResult ParseLambdaExpressionAfterIntroducer( |
| 1433 | LambdaIntroducer &Intro); |
| 1434 | |
| 1435 | //===--------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1436 | // C++ 5.2p1: C++ Casts |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1437 | ExprResult ParseCXXCasts(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1438 | |
| 1439 | //===--------------------------------------------------------------------===// |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1440 | // C++ 5.2p1: C++ Type Identification |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1441 | ExprResult ParseCXXTypeid(); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1442 | |
| 1443 | //===--------------------------------------------------------------------===// |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1444 | // C++ : Microsoft __uuidof Expression |
| 1445 | ExprResult ParseCXXUuidof(); |
| 1446 | |
| 1447 | //===--------------------------------------------------------------------===// |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1448 | // C++ 5.2.4: C++ Pseudo-Destructor Expressions |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1449 | ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1450 | tok::TokenKind OpKind, |
| 1451 | CXXScopeSpec &SS, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1452 | ParsedType ObjectType); |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1453 | |
| 1454 | //===--------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1455 | // C++ 9.3.2: C++ 'this' pointer |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1456 | ExprResult ParseCXXThis(); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1457 | |
| 1458 | //===--------------------------------------------------------------------===// |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1459 | // C++ 15: C++ Throw Expression |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1460 | ExprResult ParseThrowExpression(); |
Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 1461 | |
Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 1462 | ExceptionSpecificationType tryParseExceptionSpecification( |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1463 | bool Delayed, |
Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 1464 | SourceRange &SpecificationRange, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 1465 | SmallVectorImpl<ParsedType> &DynamicExceptions, |
| 1466 | SmallVectorImpl<SourceRange> &DynamicExceptionRanges, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1467 | ExprResult &NoexceptExpr, |
| 1468 | CachedTokens *&ExceptionSpecTokens); |
Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 1469 | |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1470 | // EndLoc is filled with the location of the last token of the specification. |
Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 1471 | ExceptionSpecificationType ParseDynamicExceptionSpecification( |
| 1472 | SourceRange &SpecificationRange, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 1473 | SmallVectorImpl<ParsedType> &Exceptions, |
| 1474 | SmallVectorImpl<SourceRange> &Ranges); |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1475 | |
| 1476 | //===--------------------------------------------------------------------===// |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 1477 | // C++0x 8: Function declaration trailing-return-type |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 1478 | TypeResult ParseTrailingReturnType(SourceRange &Range); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 1479 | |
| 1480 | //===--------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1481 | // C++ 2.13.5: C++ Boolean Literals |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1482 | ExprResult ParseCXXBoolLiteral(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1483 | |
| 1484 | //===--------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1485 | // C++ 5.2.3: Explicit type conversion (functional notation) |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1486 | ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1487 | |
| 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 Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1493 | bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); |
| 1494 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1495 | //===--------------------------------------------------------------------===// |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1496 | // C++ 5.3.4 and 5.3.5: C++ new and delete |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 1497 | bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs, |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 1498 | Declarator &D); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1499 | void ParseDirectNewDeclarator(Declarator &D); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1500 | ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); |
| 1501 | ExprResult ParseCXXDeleteExpression(bool UseGlobal, |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 1502 | SourceLocation Start); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1503 | |
| 1504 | //===--------------------------------------------------------------------===// |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1505 | // C++ if/switch/while condition expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1506 | bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult, |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 1507 | SourceLocation Loc, bool ConvertToBoolean); |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 1508 | |
| 1509 | //===--------------------------------------------------------------------===// |
Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 1510 | // C++ types |
| 1511 | |
| 1512 | //===--------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1513 | // C99 6.7.8: Initialization. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1514 | |
Chris Lattner | 0eec2b5 | 2008-10-26 22:38:55 +0000 | [diff] [blame] | 1515 | /// ParseInitializer |
| 1516 | /// initializer: [C99 6.7.8] |
| 1517 | /// assignment-expression |
| 1518 | /// '{' ... |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1519 | ExprResult ParseInitializer() { |
Chris Lattner | 0eec2b5 | 2008-10-26 22:38:55 +0000 | [diff] [blame] | 1520 | if (Tok.isNot(tok::l_brace)) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 1521 | return ParseAssignmentExpression(); |
Chris Lattner | 0eec2b5 | 2008-10-26 22:38:55 +0000 | [diff] [blame] | 1522 | return ParseBraceInitializer(); |
| 1523 | } |
Douglas Gregor | b3f323d | 2012-02-17 03:49:44 +0000 | [diff] [blame] | 1524 | bool MayBeDesignationStart(); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1525 | ExprResult ParseBraceInitializer(); |
| 1526 | ExprResult ParseInitializerWithPotentialDesignator(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1527 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1528 | //===--------------------------------------------------------------------===// |
Steve Naroff | 296e8d5 | 2008-08-28 19:20:44 +0000 | [diff] [blame] | 1529 | // clang Expressions |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1530 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1531 | ExprResult ParseBlockLiteralExpression(); // ^{...} |
Steve Naroff | 296e8d5 | 2008-08-28 19:20:44 +0000 | [diff] [blame] | 1532 | |
| 1533 | //===--------------------------------------------------------------------===// |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1534 | // Objective-C Expressions |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1535 | ExprResult ParseObjCAtExpression(SourceLocation AtLocation); |
| 1536 | ExprResult ParseObjCStringLiteral(SourceLocation AtLoc); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1537 | 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 Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 1542 | ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1543 | ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); |
Fariborz Jahanian | 48f3cc2 | 2013-01-22 18:35:43 +0000 | [diff] [blame] | 1544 | ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1545 | ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); |
Douglas Gregor | 1b730e8 | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 1546 | bool isSimpleObjCMessageExpression(); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1547 | ExprResult ParseObjCMessageExpression(); |
| 1548 | ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, |
Nico Weber | 5cb94a7 | 2011-12-22 23:26:17 +0000 | [diff] [blame] | 1549 | SourceLocation SuperLoc, |
| 1550 | ParsedType ReceiverType, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1551 | Expr *ReceiverExpr); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1552 | ExprResult ParseAssignmentExprWithObjCMessageExprStart( |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 1553 | SourceLocation LBracloc, SourceLocation SuperLoc, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1554 | ParsedType ReceiverType, Expr *ReceiverExpr); |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1555 | bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1556 | |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1557 | //===--------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1558 | // C99 6.8: Statements and Blocks. |
Sebastian Redl | 61364dd | 2008-12-11 19:30:53 +0000 | [diff] [blame] | 1559 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 1560 | /// 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 Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1568 | StmtResult ParseStatement(SourceLocation *TrailingElseLoc = nullptr); |
| 1569 | StmtResult |
| 1570 | ParseStatementOrDeclaration(StmtVector &Stmts, bool OnlyStatement, |
| 1571 | SourceLocation *TrailingElseLoc = nullptr); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1572 | 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 Trieu | bb9b80c | 2011-04-21 21:44:26 +0000 | [diff] [blame] | 1580 | ExprResult Expr = ExprResult()); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1581 | StmtResult ParseDefaultStatement(); |
| 1582 | StmtResult ParseCompoundStatement(bool isStmtExpr = false); |
| 1583 | StmtResult ParseCompoundStatement(bool isStmtExpr, |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 1584 | unsigned ScopeFlags); |
Lang Hames | a60d21d | 2012-11-03 22:29:05 +0000 | [diff] [blame] | 1585 | void ParseCompoundStatementLeadingPragmas(); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1586 | StmtResult ParseCompoundStatementBody(bool isStmtExpr = false); |
| 1587 | bool ParseParenExprOrCondition(ExprResult &ExprResult, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1588 | Decl *&DeclResult, |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 1589 | SourceLocation Loc, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1590 | bool ConvertToBoolean); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1591 | 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 McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1600 | StmtResult ParseAsmStatement(bool &msAsm); |
Eli Friedman | 3fedbe1 | 2011-09-30 01:13:51 +0000 | [diff] [blame] | 1601 | StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1602 | StmtResult ParsePragmaLoopHint(StmtVector &Stmts, bool OnlyStatement, |
| 1603 | SourceLocation *TrailingElseLoc, |
| 1604 | ParsedAttributesWithRange &Attrs); |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1605 | |
Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 1606 | /// \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 Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1617 | |
| 1618 | /// \brief Describes the condition of a Microsoft __if_exists or |
Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 1619 | /// __if_not_exists block. |
| 1620 | struct IfExistsCondition { |
| 1621 | /// \brief The location of the initial keyword. |
| 1622 | SourceLocation KeywordLoc; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1623 | /// \brief Whether this is an __if_exists block (rather than an |
Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 1624 | /// __if_not_exists block). |
| 1625 | bool IsIfExists; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1626 | |
Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 1627 | /// \brief Nested-name-specifier preceding the name. |
| 1628 | CXXScopeSpec SS; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1629 | |
Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 1630 | /// \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 Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1636 | }; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1637 | |
Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 1638 | bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result); |
Francois Pichet | 1e86269 | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 1639 | void ParseMicrosoftIfExistsStatement(StmtVector &Stmts); |
Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 1640 | void ParseMicrosoftIfExistsExternalDeclaration(); |
| 1641 | void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, |
| 1642 | AccessSpecifier& CurAS); |
Francois Pichet | 9d24a8b | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 1643 | bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, |
| 1644 | bool &InitExprsOk); |
Richard Trieu | f81e5a9 | 2011-09-09 02:00:50 +0000 | [diff] [blame] | 1645 | bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names, |
| 1646 | SmallVectorImpl<Expr *> &Constraints, |
| 1647 | SmallVectorImpl<Expr *> &Exprs); |
Sebastian Redl | a0fd865 | 2008-12-21 16:41:36 +0000 | [diff] [blame] | 1648 | |
| 1649 | //===--------------------------------------------------------------------===// |
| 1650 | // C++ 6: Statements and Blocks |
| 1651 | |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1652 | StmtResult ParseCXXTryBlock(); |
David Blaikie | c4027c8 | 2012-11-10 01:04:23 +0000 | [diff] [blame] | 1653 | StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc, bool FnTry = false); |
| 1654 | StmtResult ParseCXXCatchBlock(bool FnCatch = false); |
Sebastian Redl | a0fd865 | 2008-12-21 16:41:36 +0000 | [diff] [blame] | 1655 | |
| 1656 | //===--------------------------------------------------------------------===// |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1657 | // MS: SEH Statements and Blocks |
| 1658 | |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1659 | StmtResult ParseSEHTryBlock(); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1660 | StmtResult ParseSEHExceptBlock(SourceLocation Loc); |
| 1661 | StmtResult ParseSEHFinallyBlock(SourceLocation Loc); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1662 | StmtResult ParseSEHLeaveStatement(); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1663 | |
| 1664 | //===--------------------------------------------------------------------===// |
Sebastian Redl | a0fd865 | 2008-12-21 16:41:36 +0000 | [diff] [blame] | 1665 | // Objective-C Statements |
| 1666 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1667 | StmtResult ParseObjCAtStatement(SourceLocation atLoc); |
| 1668 | StmtResult ParseObjCTryStmt(SourceLocation atLoc); |
| 1669 | StmtResult ParseObjCThrowStmt(SourceLocation atLoc); |
| 1670 | StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1671 | StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc); |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 1672 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1673 | |
| 1674 | //===--------------------------------------------------------------------===// |
| 1675 | // C99 6.7: Declarations. |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1676 | |
| 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 Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1682 | DSC_class, // class context, enables 'friend' |
Richard Smith | a971d24 | 2012-05-09 20:55:26 +0000 | [diff] [blame] | 1683 | DSC_type_specifier, // C++ type-specifier-seq or C specifier-qualifier-list |
Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 1684 | DSC_trailing, // C++11 trailing-type-specifier in a trailing return type |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1685 | DSC_alias_declaration, // C++11 type-specifier-seq in an alias-declaration |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1686 | DSC_top_level, // top-level/namespace declaration context |
| 1687 | DSC_template_type_arg // template type argument context |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1688 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1689 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1690 | /// 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 Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1699 | case DSC_template_type_arg: |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1700 | 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 Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1708 | /// 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 Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1717 | DeclGroupPtrTy ParseDeclaration(unsigned Context, SourceLocation &DeclEnd, |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1718 | ParsedAttributesWithRange &attrs); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1719 | DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1720 | SourceLocation &DeclEnd, |
Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1721 | ParsedAttributesWithRange &attrs, |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1722 | bool RequireSemi, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1723 | ForRangeInit *FRI = nullptr); |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 1724 | bool MightBeDeclarator(unsigned Context); |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1725 | DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1726 | SourceLocation *DeclEnd = nullptr, |
| 1727 | ForRangeInit *FRI = nullptr); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1728 | Decl *ParseDeclarationAfterDeclarator(Declarator &D, |
Douglas Gregor | e542c86 | 2009-06-23 23:11:28 +0000 | [diff] [blame] | 1729 | const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); |
DeLesley Hutchins | c24a233 | 2012-02-16 16:50:43 +0000 | [diff] [blame] | 1730 | bool ParseAsmAttributesAfterDeclarator(Declarator &D); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1731 | Decl *ParseDeclarationAfterDeclaratorAndAttributes( |
| 1732 | Declarator &D, |
| 1733 | const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), |
| 1734 | ForRangeInit *FRI = nullptr); |
Douglas Gregor | c9977d0 | 2011-03-16 17:05:57 +0000 | [diff] [blame] | 1735 | Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope); |
| 1736 | Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope); |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 1737 | |
Argyrios Kyrtzidis | 0fe5397 | 2011-01-03 22:33:06 +0000 | [diff] [blame] | 1738 | /// \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 Verbruggen | 6a91d38 | 2012-04-12 10:11:59 +0000 | [diff] [blame] | 1742 | bool trySkippingFunctionBody(); |
Argyrios Kyrtzidis | 0fe5397 | 2011-01-03 22:33:06 +0000 | [diff] [blame] | 1743 | |
Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1744 | bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1745 | const ParsedTemplateInfo &TemplateInfo, |
Michael Han | 2e39713 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1746 | AccessSpecifier AS, DeclSpecContext DSC, |
| 1747 | ParsedAttributesWithRange &Attrs); |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1748 | DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1749 | void ParseDeclarationSpecifiers(DeclSpec &DS, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1750 | const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1751 | AccessSpecifier AS = AS_none, |
DeLesley Hutchins | 2287c5e | 2012-03-02 22:12:59 +0000 | [diff] [blame] | 1752 | DeclSpecContext DSC = DSC_normal, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1753 | LateParsedAttrList *LateAttrs = nullptr); |
Bill Wendling | f0cc19f | 2013-11-19 22:56:43 +0000 | [diff] [blame] | 1754 | bool DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS, AccessSpecifier AS, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1755 | DeclSpecContext DSContext, |
| 1756 | LateParsedAttrList *LateAttrs = nullptr); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1757 | |
Richard Smith | 69730c1 | 2012-03-12 07:56:15 +0000 | [diff] [blame] | 1758 | void ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS = AS_none, |
| 1759 | DeclSpecContext DSC = DSC_normal); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 1761 | void ParseObjCTypeQualifierList(ObjCDeclSpec &DS, |
| 1762 | Declarator::TheContext Context); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1763 | |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 1764 | void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, |
Richard Smith | 69730c1 | 2012-03-12 07:56:15 +0000 | [diff] [blame] | 1765 | const ParsedTemplateInfo &TemplateInfo, |
| 1766 | AccessSpecifier AS, DeclSpecContext DSC); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1767 | void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1768 | void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1769 | Decl *TagDecl); |
John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1770 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1771 | void ParseStructDeclaration( |
| 1772 | ParsingDeclSpec &DS, |
| 1773 | llvm::function_ref<void(ParsingFieldDeclarator &)> FieldsCallback); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1774 | |
Douglas Gregor | 9497a73 | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 1775 | bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1776 | bool isTypeSpecifierQualifier(); |
Steve Naroff | 5f8aa69 | 2008-02-11 23:15:56 +0000 | [diff] [blame] | 1777 | bool isTypeQualifier() const; |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1778 | |
Chris Lattner | b3a4e43 | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1779 | /// 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 Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1783 | |
Richard Smith | 4b08242 | 2012-09-18 00:52:05 +0000 | [diff] [blame] | 1784 | /// \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 Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1789 | return isCXXDeclarationSpecifier() == TPResult::True; |
Richard Smith | 4b08242 | 2012-09-18 00:52:05 +0000 | [diff] [blame] | 1790 | return isDeclarationSpecifier(true); |
| 1791 | } |
| 1792 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1793 | /// 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 Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1797 | if (getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1798 | return isCXXDeclarationStatement(); |
Douglas Gregor | 9497a73 | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 1799 | return isDeclarationSpecifier(true); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1800 | } |
| 1801 | |
Eli Friedman | 9490ab4 | 2011-12-20 01:50:37 +0000 | [diff] [blame] | 1802 | /// isForInitDeclaration - Disambiguates between a declaration or an |
| 1803 | /// expression in the context of the C 'clause-1' or the C++ |
Argyrios Kyrtzidis | bbc70c0 | 2008-10-05 15:50:46 +0000 | [diff] [blame] | 1804 | // 'for-init-statement' part of a 'for' statement. |
| 1805 | /// Returns true for declaration, false for expression. |
Eli Friedman | 9490ab4 | 2011-12-20 01:50:37 +0000 | [diff] [blame] | 1806 | bool isForInitDeclaration() { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1807 | if (getLangOpts().CPlusPlus) |
Eli Friedman | 9490ab4 | 2011-12-20 01:50:37 +0000 | [diff] [blame] | 1808 | return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/true); |
Douglas Gregor | 9497a73 | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 1809 | return isDeclarationSpecifier(true); |
Argyrios Kyrtzidis | bbc70c0 | 2008-10-05 15:50:46 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1812 | /// \brief Determine whether this is a C++1z for-range-identifier. |
| 1813 | bool isForRangeIdentifier(); |
| 1814 | |
Douglas Gregor | 9497a73 | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 1815 | /// \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 Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1818 | |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1819 | /// \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 Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1822 | bool isConstructorDeclarator(bool Unqualified); |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1823 | |
Douglas Gregor | 8b64259 | 2009-02-10 00:53:15 +0000 | [diff] [blame] | 1824 | /// \brief Specifies the context in which type-id/expression |
| 1825 | /// disambiguation will occur. |
| 1826 | enum TentativeCXXTypeIdContext { |
| 1827 | TypeIdInParens, |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1828 | TypeIdUnambiguous, |
Douglas Gregor | 8b64259 | 2009-02-10 00:53:15 +0000 | [diff] [blame] | 1829 | TypeIdAsTemplateArgument |
| 1830 | }; |
| 1831 | |
| 1832 | |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 1833 | /// 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 Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1836 | bool isTypeIdInParens(bool &isAmbiguous) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1837 | if (getLangOpts().CPlusPlus) |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1838 | return isCXXTypeId(TypeIdInParens, isAmbiguous); |
| 1839 | isAmbiguous = false; |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 1840 | return isTypeSpecifierQualifier(); |
| 1841 | } |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1842 | bool isTypeIdInParens() { |
| 1843 | bool isAmbiguous; |
| 1844 | return isTypeIdInParens(isAmbiguous); |
| 1845 | } |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 1846 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1847 | /// \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 Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1857 | /// 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 Friedman | 9490ab4 | 2011-12-20 01:50:37 +0000 | [diff] [blame] | 1867 | bool isCXXSimpleDeclaration(bool AllowForRangeDecl); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1868 | |
| 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 Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 1872 | /// initializer. Sets 'IsAmbiguous' to true to indicate that this declaration |
| 1873 | /// might be a constructor-style initializer. |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1874 | /// If during the disambiguation process a parsing error is encountered, |
| 1875 | /// the function returns true to let the declaration parsing code handle it. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1876 | bool isCXXFunctionDeclarator(bool *IsAmbiguous = nullptr); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1877 | |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 1878 | /// 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 Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1884 | bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); |
| 1885 | bool isCXXTypeId(TentativeCXXTypeIdContext Context) { |
| 1886 | bool isAmbiguous; |
| 1887 | return isCXXTypeId(Context, isAmbiguous); |
| 1888 | } |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 1889 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1890 | /// TPResult - Used as the result value for functions whose purpose is to |
| 1891 | /// disambiguate C++ constructs by "tentatively parsing" them. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1892 | enum class TPResult { |
| 1893 | True, False, Ambiguous, Error |
Argyrios Kyrtzidis | b47e386 | 2008-10-05 17:02:44 +0000 | [diff] [blame] | 1894 | }; |
| 1895 | |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 1896 | /// \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 Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1908 | /// 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 Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 1912 | /// encountered. If it could be a braced C++11 function-style cast, returns |
| 1913 | /// BracedCastResult. |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1914 | /// Doesn't consume tokens. |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 1915 | TPResult |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1916 | isCXXDeclarationSpecifier(TPResult BracedCastResult = TPResult::False, |
| 1917 | bool *HasMissingTypename = nullptr); |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 1918 | |
Richard Smith | 9bd3cdc | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1919 | /// 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 Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 1924 | /// \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 Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1929 | // "Tentative parsing" functions, used for disambiguation. If a parsing error |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1930 | // 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 Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1933 | // that more tentative parsing is necessary for disambiguation. |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1934 | // They all consume tokens, so backtracking should be used after calling them. |
| 1935 | |
Eli Friedman | 9490ab4 | 2011-12-20 01:50:37 +0000 | [diff] [blame] | 1936 | TPResult TryParseSimpleDeclaration(bool AllowForRangeDecl); |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1937 | TPResult TryParseTypeofSpecifier(); |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1938 | TPResult TryParseProtocolQualifiers(); |
Richard Smith | 9bd3cdc | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1939 | TPResult TryParsePtrOperatorSeq(); |
| 1940 | TPResult TryParseOperatorId(); |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1941 | TPResult TryParseInitDeclaratorList(); |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 1942 | TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1943 | TPResult |
| 1944 | TryParseParameterDeclarationClause(bool *InvalidAsDeclaration = nullptr, |
| 1945 | bool VersusTemplateArg = false); |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1946 | TPResult TryParseFunctionDeclarator(); |
| 1947 | TPResult TryParseBracketDeclarator(); |
Richard Smith | 9bd3cdc | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1948 | TPResult TryConsumeDeclarationSpecifier(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1949 | |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 1950 | public: |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1951 | TypeResult ParseTypeName(SourceRange *Range = nullptr, |
Douglas Gregor | 683a81f | 2011-01-31 16:09:46 +0000 | [diff] [blame] | 1952 | Declarator::TheContext Context |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1953 | = Declarator::TypeNameContext, |
Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 1954 | AccessSpecifier AS = AS_none, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1955 | Decl **OwnedType = nullptr, |
| 1956 | ParsedAttributes *Attrs = nullptr); |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 1957 | |
| 1958 | private: |
Douglas Gregor | 03f1eb0 | 2012-06-15 16:59:29 +0000 | [diff] [blame] | 1959 | void ParseBlockId(SourceLocation CaretLoc); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1960 | |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 1961 | // 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 Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 1965 | if (!getLangOpts().CPlusPlus11 || NextToken().isNot(tok::l_square)) |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 1966 | return false; |
| 1967 | return DiagnoseProhibitedCXX11Attribute(); |
| 1968 | } |
| 1969 | bool DiagnoseProhibitedCXX11Attribute(); |
Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1970 | 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 Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 1981 | |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1982 | void ProhibitAttributes(ParsedAttributesWithRange &attrs) { |
| 1983 | if (!attrs.Range.isValid()) return; |
| 1984 | DiagnoseProhibitedAttributes(attrs); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1985 | attrs.clear(); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1986 | } |
| 1987 | void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs); |
| 1988 | |
Michael Han | f64231e | 2012-11-06 19:34:54 +0000 | [diff] [blame] | 1989 | // 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 Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1994 | /// \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 Smith | 5eed7e0 | 2013-10-15 01:34:54 +0000 | [diff] [blame] | 1998 | /// \brief Diagnose and skip C++11 attributes that appear in syntactic |
| 1999 | /// locations where attributes are not allowed. |
| 2000 | void DiagnoseAndSkipCXX11Attributes(); |
| 2001 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2002 | /// \brief Parses syntax-generic attribute arguments for attributes which are |
| 2003 | /// known to the implementation, and adds them to the given ParsedAttributes |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2004 | /// 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 Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2011 | |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2012 | void MaybeParseGNUAttributes(Declarator &D, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2013 | LateParsedAttrList *LateAttrs = nullptr) { |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2014 | if (Tok.is(tok::kw___attribute)) { |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2015 | ParsedAttributes attrs(AttrFactory); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2016 | SourceLocation endLoc; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2017 | ParseGNUAttributes(attrs, &endLoc, LateAttrs, &D); |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2018 | D.takeAttributes(attrs, endLoc); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2019 | } |
| 2020 | } |
| 2021 | void MaybeParseGNUAttributes(ParsedAttributes &attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2022 | SourceLocation *endLoc = nullptr, |
| 2023 | LateParsedAttrList *LateAttrs = nullptr) { |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2024 | if (Tok.is(tok::kw___attribute)) |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2025 | ParseGNUAttributes(attrs, endLoc, LateAttrs); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2026 | } |
| 2027 | void ParseGNUAttributes(ParsedAttributes &attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2028 | SourceLocation *endLoc = nullptr, |
| 2029 | LateParsedAttrList *LateAttrs = nullptr, |
| 2030 | Declarator *D = nullptr); |
Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2031 | void ParseGNUAttributeArgs(IdentifierInfo *AttrName, |
| 2032 | SourceLocation AttrNameLoc, |
| 2033 | ParsedAttributes &Attrs, |
Michael Han | 6880f49 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 2034 | SourceLocation *EndLoc, |
| 2035 | IdentifierInfo *ScopeName, |
| 2036 | SourceLocation ScopeLoc, |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2037 | AttributeList::Syntax Syntax, |
| 2038 | Declarator *D); |
Richard Smith | 8edabd9 | 2013-09-03 18:01:40 +0000 | [diff] [blame] | 2039 | IdentifierLoc *ParseIdentifierLoc(); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2040 | |
Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 2041 | void MaybeParseCXX11Attributes(Declarator &D) { |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2042 | if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2043 | ParsedAttributesWithRange attrs(AttrFactory); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2044 | SourceLocation endLoc; |
Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 2045 | ParseCXX11Attributes(attrs, &endLoc); |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2046 | D.takeAttributes(attrs, endLoc); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2047 | } |
| 2048 | } |
Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 2049 | void MaybeParseCXX11Attributes(ParsedAttributes &attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2050 | SourceLocation *endLoc = nullptr) { |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2051 | if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2052 | ParsedAttributesWithRange attrsWithRange(AttrFactory); |
Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 2053 | ParseCXX11Attributes(attrsWithRange, endLoc); |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2054 | attrs.takeAllFrom(attrsWithRange); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2055 | } |
| 2056 | } |
Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 2057 | void MaybeParseCXX11Attributes(ParsedAttributesWithRange &attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2058 | SourceLocation *endLoc = nullptr, |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 2059 | bool OuterMightBeMessageSend = false) { |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2060 | if (getLangOpts().CPlusPlus11 && |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 2061 | isCXX11AttributeSpecifier(false, OuterMightBeMessageSend)) |
Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 2062 | ParseCXX11Attributes(attrs, endLoc); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2063 | } |
Peter Collingbourne | 3497fdf | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 2064 | |
Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 2065 | void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2066 | SourceLocation *EndLoc = nullptr); |
Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 2067 | void ParseCXX11Attributes(ParsedAttributesWithRange &attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2068 | SourceLocation *EndLoc = nullptr); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2069 | /// \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 Han | 6880f49 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 2076 | |
Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 2077 | IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2078 | |
| 2079 | void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2080 | SourceLocation *endLoc = nullptr) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2081 | if (getLangOpts().MicrosoftExt && Tok.is(tok::l_square)) |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2082 | ParseMicrosoftAttributes(attrs, endLoc); |
| 2083 | } |
| 2084 | void ParseMicrosoftAttributes(ParsedAttributes &attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2085 | SourceLocation *endLoc = nullptr); |
Aaron Ballman | fc685ac | 2012-06-19 22:09:27 +0000 | [diff] [blame] | 2086 | void ParseMicrosoftDeclSpec(ParsedAttributes &Attrs); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2087 | bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName, |
| 2088 | SourceLocation AttrNameLoc, |
| 2089 | ParsedAttributes &Attrs); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2090 | void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 2091 | void DiagnoseAndSkipExtendedMicrosoftTypeAttributes(); |
| 2092 | SourceLocation SkipExtendedMicrosoftTypeAttributes(); |
John McCall | c052dbb | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 2093 | void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2094 | void ParseBorlandTypeAttributes(ParsedAttributes &attrs); |
Peter Collingbourne | f315fa8 | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 2095 | void ParseOpenCLAttributes(ParsedAttributes &attrs); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2096 | void ParseOpenCLQualifiers(ParsedAttributes &Attrs); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2097 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 2098 | VersionTuple ParseVersionTuple(SourceRange &Range); |
| 2099 | void ParseAvailabilityAttribute(IdentifierInfo &Availability, |
| 2100 | SourceLocation AvailabilityLoc, |
| 2101 | ParsedAttributes &attrs, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 2102 | SourceLocation *endLoc, |
| 2103 | IdentifierInfo *ScopeName, |
| 2104 | SourceLocation ScopeLoc, |
| 2105 | AttributeList::Syntax Syntax); |
| 2106 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2107 | void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated, |
| 2108 | SourceLocation ObjCBridgeRelatedLoc, |
| 2109 | ParsedAttributes &attrs, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 2110 | SourceLocation *endLoc, |
| 2111 | IdentifierInfo *ScopeName, |
| 2112 | SourceLocation ScopeLoc, |
| 2113 | AttributeList::Syntax Syntax); |
Caitlin Sadowski | b51e031 | 2011-08-09 17:59:31 +0000 | [diff] [blame] | 2114 | |
Dmitri Gribenko | 0d5a069 | 2012-08-17 00:08:38 +0000 | [diff] [blame] | 2115 | void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName, |
| 2116 | SourceLocation AttrNameLoc, |
| 2117 | ParsedAttributes &Attrs, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 2118 | SourceLocation *EndLoc, |
| 2119 | IdentifierInfo *ScopeName, |
| 2120 | SourceLocation ScopeLoc, |
| 2121 | AttributeList::Syntax Syntax); |
Caitlin Sadowski | b51e031 | 2011-08-09 17:59:31 +0000 | [diff] [blame] | 2122 | |
Richard Smith | d386fef | 2013-10-31 01:56:18 +0000 | [diff] [blame] | 2123 | void ParseAttributeWithTypeArg(IdentifierInfo &AttrName, |
| 2124 | SourceLocation AttrNameLoc, |
| 2125 | ParsedAttributes &Attrs, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 2126 | SourceLocation *EndLoc, |
| 2127 | IdentifierInfo *ScopeName, |
| 2128 | SourceLocation ScopeLoc, |
| 2129 | AttributeList::Syntax Syntax); |
Richard Smith | d386fef | 2013-10-31 01:56:18 +0000 | [diff] [blame] | 2130 | |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 2131 | void ParseTypeofSpecifier(DeclSpec &DS); |
David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 2132 | SourceLocation ParseDecltypeSpecifier(DeclSpec &DS); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 2133 | void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS, |
David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 2134 | SourceLocation StartLoc, |
| 2135 | SourceLocation EndLoc); |
Sean Hunt | db5d44b | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 2136 | void ParseUnderlyingTypeSpecifier(DeclSpec &DS); |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 2137 | void ParseAtomicSpecifier(DeclSpec &DS); |
| 2138 | |
Peter Collingbourne | 0b64ba9 | 2011-10-23 20:07:52 +0000 | [diff] [blame] | 2139 | ExprResult ParseAlignArgument(SourceLocation Start, |
| 2140 | SourceLocation &EllipsisLoc); |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 2141 | void ParseAlignmentSpecifier(ParsedAttributes &Attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2142 | SourceLocation *endLoc = nullptr); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2143 | |
Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 2144 | VirtSpecifiers::Specifier isCXX11VirtSpecifier(const Token &Tok) const; |
| 2145 | VirtSpecifiers::Specifier isCXX11VirtSpecifier() const { |
| 2146 | return isCXX11VirtSpecifier(Tok); |
Richard Smith | 1c94c16 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 2147 | } |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 2148 | void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, bool IsInterface, |
| 2149 | SourceLocation FriendLoc); |
Anders Carlsson | 1f3b6fd | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 2150 | |
Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 2151 | bool isCXX11FinalKeyword() const; |
Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 2152 | |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2153 | /// 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 Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2157 | Parser &P; |
Argyrios Kyrtzidis | 7518102 | 2008-11-08 16:47:38 +0000 | [diff] [blame] | 2158 | CXXScopeSpec &SS; |
Argyrios Kyrtzidis | f37006b | 2009-07-21 06:43:26 +0000 | [diff] [blame] | 2159 | bool EnteredScope; |
John McCall | f7f3d0d | 2009-11-11 00:21:18 +0000 | [diff] [blame] | 2160 | bool CreatedScope; |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2161 | public: |
Argyrios Kyrtzidis | f37006b | 2009-07-21 06:43:26 +0000 | [diff] [blame] | 2162 | DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) |
John McCall | f7f3d0d | 2009-11-11 00:21:18 +0000 | [diff] [blame] | 2163 | : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2164 | |
| 2165 | void EnterDeclaratorScope() { |
Argyrios Kyrtzidis | 2bcb343 | 2009-07-21 06:48:06 +0000 | [diff] [blame] | 2166 | assert(!EnteredScope && "Already entered the scope!"); |
Argyrios Kyrtzidis | f37006b | 2009-07-21 06:43:26 +0000 | [diff] [blame] | 2167 | assert(SS.isSet() && "C++ scope was not set!"); |
John McCall | f7f3d0d | 2009-11-11 00:21:18 +0000 | [diff] [blame] | 2168 | |
| 2169 | CreatedScope = true; |
| 2170 | P.EnterScope(0); // Not a decl scope. |
| 2171 | |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2172 | if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS)) |
Douglas Gregor | 3fdbed5 | 2009-07-21 18:59:28 +0000 | [diff] [blame] | 2173 | EnteredScope = true; |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | ~DeclaratorScopeObj() { |
Argyrios Kyrtzidis | f37006b | 2009-07-21 06:43:26 +0000 | [diff] [blame] | 2177 | if (EnteredScope) { |
| 2178 | assert(SS.isSet() && "C++ scope was cleared ?"); |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2179 | P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS); |
Argyrios Kyrtzidis | f37006b | 2009-07-21 06:43:26 +0000 | [diff] [blame] | 2180 | } |
John McCall | f7f3d0d | 2009-11-11 00:21:18 +0000 | [diff] [blame] | 2181 | if (CreatedScope) |
| 2182 | P.ExitScope(); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2183 | } |
| 2184 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2185 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2186 | /// ParseDeclarator - Parse and verify a newly-initialized declarator. |
| 2187 | void ParseDeclarator(Declarator &D); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2188 | /// A function that parses a variant of direct-declarator. |
| 2189 | typedef void (Parser::*DirectDeclParseFunction)(Declarator&); |
| 2190 | void ParseDeclaratorInternal(Declarator &D, |
| 2191 | DirectDeclParseFunction DirectDeclParser); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2192 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 2193 | 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 Wendling | 7f3ec66 | 2013-11-26 04:10:07 +0000 | [diff] [blame] | 2208 | bool AtomicAllowed = true, |
| 2209 | bool IdentifierRequired = false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2210 | void ParseDirectDeclarator(Declarator &D); |
| 2211 | void ParseParenDeclarator(Declarator &D); |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2212 | void ParseFunctionDeclarator(Declarator &D, |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2213 | ParsedAttributes &attrs, |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2214 | BalancedDelimiterTracker &Tracker, |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 2215 | bool IsAmbiguous, |
Chris Lattner | 7399ee0 | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 2216 | bool RequiresArg = false); |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 2217 | bool ParseRefQualifier(bool &RefQualifierIsLValueRef, |
| 2218 | SourceLocation &RefQualifierLoc); |
Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 2219 | bool isFunctionDeclaratorIdentifierList(); |
| 2220 | void ParseFunctionDeclaratorIdentifierList( |
| 2221 | Declarator &D, |
Craig Topper | 6b9240e | 2013-07-05 19:34:19 +0000 | [diff] [blame] | 2222 | SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo); |
Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 2223 | void ParseParameterDeclarationClause( |
| 2224 | Declarator &D, |
| 2225 | ParsedAttributes &attrs, |
Craig Topper | 6b9240e | 2013-07-05 19:34:19 +0000 | [diff] [blame] | 2226 | SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo, |
Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 2227 | SourceLocation &EllipsisLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2228 | void ParseBracketDeclarator(Declarator &D); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 2229 | void ParseMisplacedBracketDeclarator(Declarator &D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2230 | |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 2231 | //===--------------------------------------------------------------------===// |
| 2232 | // C++ 7: Declarations [dcl.dcl] |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2233 | |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 2234 | /// 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 Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 2247 | |
Richard Smith | 7faf81f | 2013-11-15 23:00:02 +0000 | [diff] [blame] | 2248 | void DiagnoseUnexpectedNamespace(NamedDecl *Context); |
Richard Smith | b310439 | 2013-11-09 04:52:51 +0000 | [diff] [blame] | 2249 | |
Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 2250 | Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd, |
| 2251 | SourceLocation InlineLoc = SourceLocation()); |
Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 2252 | void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc, |
| 2253 | std::vector<IdentifierInfo*>& Ident, |
| 2254 | std::vector<SourceLocation>& NamespaceLoc, |
| 2255 | unsigned int index, SourceLocation& InlineLoc, |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2256 | ParsedAttributes& attrs, |
| 2257 | BalancedDelimiterTracker &Tracker); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2258 | Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context); |
| 2259 | Decl *ParseUsingDirectiveOrDeclaration(unsigned Context, |
John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 2260 | const ParsedTemplateInfo &TemplateInfo, |
Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 2261 | SourceLocation &DeclEnd, |
Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 2262 | ParsedAttributesWithRange &attrs, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2263 | Decl **OwnedType = nullptr); |
John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 2264 | Decl *ParseUsingDirective(unsigned Context, |
| 2265 | SourceLocation UsingLoc, |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2266 | SourceLocation &DeclEnd, |
| 2267 | ParsedAttributes &attrs); |
John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 2268 | Decl *ParseUsingDeclaration(unsigned Context, |
| 2269 | const ParsedTemplateInfo &TemplateInfo, |
| 2270 | SourceLocation UsingLoc, |
Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 2271 | SourceLocation &DeclEnd, |
Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 2272 | AccessSpecifier AS = AS_none, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2273 | Decl **OwnedType = nullptr); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2274 | Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd); |
| 2275 | Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc, |
Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 2276 | SourceLocation AliasLoc, IdentifierInfo *Alias, |
| 2277 | SourceLocation &DeclEnd); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2278 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 2279 | //===--------------------------------------------------------------------===// |
| 2280 | // C++ 9: classes [class] and C structs/unions. |
Richard Smith | 139be70 | 2012-07-02 19:14:01 +0000 | [diff] [blame] | 2281 | bool isValidAfterTypeSpecifier(bool CouldBeBitfield); |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 2282 | void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, |
Richard Smith | 69730c1 | 2012-03-12 07:56:15 +0000 | [diff] [blame] | 2283 | DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo, |
| 2284 | AccessSpecifier AS, bool EnteringContext, |
Michael Han | 2e39713 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 2285 | DeclSpecContext DSC, |
Bill Wendling | ad017fa | 2012-12-20 19:22:21 +0000 | [diff] [blame] | 2286 | ParsedAttributesWithRange &Attributes); |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 2287 | void SkipCXXMemberSpecification(SourceLocation StartLoc, |
| 2288 | SourceLocation AttrFixitLoc, |
| 2289 | unsigned TagType, |
| 2290 | Decl *TagDecl); |
Michael Han | 07fc1ba | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 2291 | void ParseCXXMemberSpecification(SourceLocation StartLoc, |
| 2292 | SourceLocation AttrFixitLoc, |
Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 2293 | ParsedAttributesWithRange &Attrs, |
Michael Han | 07fc1ba | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 2294 | unsigned TagType, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2295 | Decl *TagDecl); |
Douglas Gregor | 552e299 | 2012-02-21 02:22:07 +0000 | [diff] [blame] | 2296 | ExprResult ParseCXXMemberInitializer(Decl *D, bool IsFunction, |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2297 | SourceLocation &EqualLoc); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 2298 | bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo, |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2299 | VirtSpecifiers &VS, |
| 2300 | ExprResult &BitfieldSize, |
| 2301 | LateParsedAttrList &LateAttrs); |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 2302 | void MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D, |
| 2303 | VirtSpecifiers &VS); |
Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2304 | void ParseCXXClassMemberDeclaration(AccessSpecifier AS, AttributeList *Attr, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2305 | const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), |
| 2306 | ParsingDeclRAIIObject *DiagsFromTParams = nullptr); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2307 | void ParseConstructorInitializer(Decl *ConstructorDecl); |
| 2308 | MemInitResult ParseMemInitializer(Decl *ConstructorDecl); |
Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 2309 | void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo, |
| 2310 | Decl *ThisDecl); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 2311 | |
| 2312 | //===--------------------------------------------------------------------===// |
| 2313 | // C++ 10: Derived classes [class.derived] |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 2314 | TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc, |
David Blaikie | 22216eb | 2011-10-25 17:10:12 +0000 | [diff] [blame] | 2315 | SourceLocation &EndLocation); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2316 | void ParseBaseClause(Decl *ClassDecl); |
| 2317 | BaseResult ParseBaseSpecifier(Decl *ClassDecl); |
Douglas Gregor | 1b7f898 | 2008-04-14 00:13:42 +0000 | [diff] [blame] | 2318 | AccessSpecifier getAccessSpecifierIfPresent() const; |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 2319 | |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 2320 | bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2321 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2322 | IdentifierInfo *Name, |
| 2323 | SourceLocation NameLoc, |
| 2324 | bool EnteringContext, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2325 | ParsedType ObjectType, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 2326 | UnqualifiedId &Id, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2327 | bool AssumeTemplateId); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2328 | bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2329 | ParsedType ObjectType, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2330 | UnqualifiedId &Result); |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 2331 | |
Alexey Bataev | c640058 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2332 | //===--------------------------------------------------------------------===// |
| 2333 | // OpenMP: Directives and clauses. |
Alexey Bataev | 6af701f | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2334 | /// \brief Parses declarative OpenMP directives. |
Alexey Bataev | c640058 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2335 | DeclGroupPtrTy ParseOpenMPDeclarativeDirective(); |
Alexey Bataev | 6af701f | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2336 | /// \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 Bataev | c640058 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2343 | bool ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, |
Alexey Bataev | 6af701f | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2344 | SmallVectorImpl<Expr *> &VarList, |
| 2345 | bool AllowScopeSpecifier); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2346 | /// \brief Parses declarative or executable directive. |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 2347 | /// |
| 2348 | /// \param StandAloneAllowed true if allowed stand-alone directives, |
| 2349 | /// false - otherwise |
| 2350 | /// |
| 2351 | StmtResult |
| 2352 | ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2353 | /// \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 Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 2372 | /// \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 Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2383 | /// \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 Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 2388 | public: |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2389 | bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, |
Douglas Gregor | 02a24ee | 2009-11-03 16:56:39 +0000 | [diff] [blame] | 2390 | bool AllowDestructorName, |
| 2391 | bool AllowConstructorName, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2392 | ParsedType ObjectType, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2393 | SourceLocation& TemplateKWLoc, |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2394 | UnqualifiedId &Result); |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 2395 | |
Axel Naumann | 6944e20 | 2012-09-17 13:14:34 +0000 | [diff] [blame] | 2396 | private: |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 2397 | //===--------------------------------------------------------------------===// |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 2398 | // C++ 14: Templates [temp] |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 2399 | |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 2400 | // C++ 14.1: Template Parameters [temp.param] |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2401 | Decl *ParseDeclarationStartingWithTemplate(unsigned Context, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2402 | SourceLocation &DeclEnd, |
| 2403 | AccessSpecifier AS = AS_none, |
| 2404 | AttributeList *AccessAttrs = nullptr); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2405 | Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context, |
Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2406 | SourceLocation &DeclEnd, |
| 2407 | AccessSpecifier AS, |
| 2408 | AttributeList *AccessAttrs); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2409 | Decl *ParseSingleDeclarationAfterTemplate( |
Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 2410 | unsigned Context, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 2411 | const ParsedTemplateInfo &TemplateInfo, |
John McCall | c9068d7 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 2412 | ParsingDeclRAIIObject &DiagsFromParams, |
Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 2413 | SourceLocation &DeclEnd, |
Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2414 | AccessSpecifier AS=AS_none, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 2415 | AttributeList *AccessAttrs = nullptr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2416 | bool ParseTemplateParameters(unsigned Depth, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2417 | SmallVectorImpl<Decl*> &TemplateParams, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2418 | SourceLocation &LAngleLoc, |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 2419 | SourceLocation &RAngleLoc); |
| 2420 | bool ParseTemplateParameterList(unsigned Depth, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2421 | SmallVectorImpl<Decl*> &TemplateParams); |
Douglas Gregor | 98440b4 | 2009-11-21 02:07:55 +0000 | [diff] [blame] | 2422 | bool isStartOfTemplateTypeParameter(); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2423 | 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 Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 2427 | void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc, |
| 2428 | SourceLocation CorrectLoc, |
| 2429 | bool AlreadyHasEllipsis, |
| 2430 | bool IdentifierHasName); |
| 2431 | void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc, |
| 2432 | Declarator &D); |
Douglas Gregor | d6fb7ef | 2008-12-18 19:37:40 +0000 | [diff] [blame] | 2433 | // C++ 14.3: Template arguments [temp.arg] |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2434 | typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList; |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 2435 | |
Nico Weber | b707a47 | 2012-12-14 18:22:38 +0000 | [diff] [blame] | 2436 | bool ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc, |
| 2437 | bool ConsumeLastToken); |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 2438 | bool ParseTemplateIdAfterTemplateName(TemplateTy Template, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2439 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 2440 | const CXXScopeSpec &SS, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 2441 | bool ConsumeLastToken, |
| 2442 | SourceLocation &LAngleLoc, |
| 2443 | TemplateArgList &TemplateArgs, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 2444 | SourceLocation &RAngleLoc); |
| 2445 | |
Chris Lattner | c8e27cc | 2009-06-26 04:27:47 +0000 | [diff] [blame] | 2446 | bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, |
Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 2447 | CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2448 | SourceLocation TemplateKWLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2449 | UnqualifiedId &TemplateName, |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 2450 | bool AllowTypeAnnotation = true); |
Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 2451 | void AnnotateTemplateIdTokenAsType(); |
Douglas Gregor | d5ab9b0 | 2010-05-21 23:43:39 +0000 | [diff] [blame] | 2452 | bool IsTemplateArgumentList(unsigned Skip = 0); |
Douglas Gregor | 314b97f | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 2453 | bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2454 | ParsedTemplateArgument ParseTemplateTemplateArgument(); |
Douglas Gregor | 314b97f | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 2455 | ParsedTemplateArgument ParseTemplateArgument(); |
Argyrios Kyrtzidis | 9241057 | 2011-12-23 02:16:45 +0000 | [diff] [blame] | 2456 | Decl *ParseExplicitInstantiation(unsigned Context, |
| 2457 | SourceLocation ExternLoc, |
| 2458 | SourceLocation TemplateLoc, |
| 2459 | SourceLocation &DeclEnd, |
| 2460 | AccessSpecifier AS = AS_none); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2461 | |
| 2462 | //===--------------------------------------------------------------------===// |
Douglas Gregor | 6aa52ec | 2011-08-26 23:56:07 +0000 | [diff] [blame] | 2463 | // Modules |
Douglas Gregor | 5948ae1 | 2012-01-03 18:04:46 +0000 | [diff] [blame] | 2464 | DeclGroupPtrTy ParseModuleImport(SourceLocation AtLoc); |
David Blaikie | a8fbc05 | 2011-11-09 05:30:24 +0000 | [diff] [blame] | 2465 | |
Douglas Gregor | 6aa52ec | 2011-08-26 23:56:07 +0000 | [diff] [blame] | 2466 | //===--------------------------------------------------------------------===// |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2467 | // C++11/G++: Type Traits [Type-Traits.html in the GCC manual] |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2468 | ExprResult ParseTypeTrait(); |
| 2469 | |
Douglas Gregor | f44e854 | 2010-08-24 19:08:16 +0000 | [diff] [blame] | 2470 | //===--------------------------------------------------------------------===// |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2471 | // Embarcadero: Arary and Expression Traits |
| 2472 | ExprResult ParseArrayTypeTrait(); |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2473 | ExprResult ParseExpressionTrait(); |
| 2474 | |
| 2475 | //===--------------------------------------------------------------------===// |
Douglas Gregor | f44e854 | 2010-08-24 19:08:16 +0000 | [diff] [blame] | 2476 | // Preprocessor code-completion pass-through |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 2477 | 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 Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2484 | }; |
| 2485 | |
| 2486 | } // end namespace clang |
| 2487 | |
| 2488 | #endif |