1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #ifndef LLVM_CLANG_PARSE_PARSER_H |
14 | #define LLVM_CLANG_PARSE_PARSER_H |
15 | |
16 | #include "clang/AST/OpenMPClause.h" |
17 | #include "clang/AST/Availability.h" |
18 | #include "clang/Basic/BitmaskEnum.h" |
19 | #include "clang/Basic/OpenMPKinds.h" |
20 | #include "clang/Basic/OperatorPrecedence.h" |
21 | #include "clang/Basic/Specifiers.h" |
22 | #include "clang/Lex/CodeCompletionHandler.h" |
23 | #include "clang/Lex/Preprocessor.h" |
24 | #include "clang/Sema/DeclSpec.h" |
25 | #include "clang/Sema/Sema.h" |
26 | #include "llvm/ADT/SmallVector.h" |
27 | #include "llvm/Support/Compiler.h" |
28 | #include "llvm/Support/PrettyStackTrace.h" |
29 | #include "llvm/Support/SaveAndRestore.h" |
30 | #include <memory> |
31 | #include <stack> |
32 | |
33 | namespace clang { |
34 | class PragmaHandler; |
35 | class Scope; |
36 | class BalancedDelimiterTracker; |
37 | class CorrectionCandidateCallback; |
38 | class DeclGroupRef; |
39 | class DiagnosticBuilder; |
40 | struct LoopHint; |
41 | class Parser; |
42 | class ParsingDeclRAIIObject; |
43 | class ParsingDeclSpec; |
44 | class ParsingDeclarator; |
45 | class ParsingFieldDeclarator; |
46 | class ColonProtectionRAIIObject; |
47 | class InMessageExpressionRAIIObject; |
48 | class PoisonSEHIdentifiersRAIIObject; |
49 | class OMPClause; |
50 | class ObjCTypeParamList; |
51 | class ObjCTypeParameter; |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | class Parser : public CodeCompletionHandler { |
58 | friend class ColonProtectionRAIIObject; |
59 | friend class InMessageExpressionRAIIObject; |
60 | friend class PoisonSEHIdentifiersRAIIObject; |
61 | friend class ObjCDeclContextSwitch; |
62 | friend class ParenBraceBracketBalancer; |
63 | friend class BalancedDelimiterTracker; |
64 | |
65 | Preprocessor &PP; |
66 | |
67 | |
68 | |
69 | Token Tok; |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | SourceLocation PrevTokLocation; |
76 | |
77 | |
78 | |
79 | PreferredTypeBuilder PreferredType; |
80 | |
81 | unsigned short ParenCount = 0, BracketCount = 0, BraceCount = 0; |
82 | unsigned short MisplacedModuleBeginCount = 0; |
83 | |
84 | |
85 | |
86 | Sema &Actions; |
87 | |
88 | DiagnosticsEngine &Diags; |
89 | |
90 | |
91 | enum { ScopeCacheSize = 16 }; |
92 | unsigned NumCachedScopes; |
93 | Scope *ScopeCache[ScopeCacheSize]; |
94 | |
95 | |
96 | |
97 | |
98 | IdentifierInfo *Ident__exception_code, |
99 | *Ident___exception_code, |
100 | *Ident_GetExceptionCode; |
101 | |
102 | IdentifierInfo *Ident__exception_info, |
103 | *Ident___exception_info, |
104 | *Ident_GetExceptionInfo; |
105 | |
106 | IdentifierInfo *Ident__abnormal_termination, |
107 | *Ident___abnormal_termination, |
108 | *Ident_AbnormalTermination; |
109 | |
110 | |
111 | IdentifierInfo *Ident__except; |
112 | mutable IdentifierInfo *Ident_sealed; |
113 | |
114 | |
115 | |
116 | IdentifierInfo *Ident_super; |
117 | |
118 | |
119 | IdentifierInfo *Ident_vector; |
120 | IdentifierInfo *Ident_bool; |
121 | |
122 | |
123 | IdentifierInfo *Ident_pixel; |
124 | |
125 | |
126 | IdentifierInfo *Ident_instancetype; |
127 | |
128 | |
129 | IdentifierInfo *Ident_introduced; |
130 | |
131 | |
132 | IdentifierInfo *Ident_deprecated; |
133 | |
134 | |
135 | IdentifierInfo *Ident_obsoleted; |
136 | |
137 | |
138 | IdentifierInfo *Ident_unavailable; |
139 | |
140 | |
141 | IdentifierInfo *Ident_message; |
142 | |
143 | |
144 | IdentifierInfo *Ident_strict; |
145 | |
146 | |
147 | IdentifierInfo *Ident_replacement; |
148 | |
149 | |
150 | IdentifierInfo *Ident_language, *Ident_defined_in, |
151 | *Ident_generated_declaration; |
152 | |
153 | |
154 | mutable IdentifierInfo *Ident_final; |
155 | mutable IdentifierInfo *Ident_GNU_final; |
156 | mutable IdentifierInfo *Ident_override; |
157 | |
158 | |
159 | |
160 | llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits; |
161 | |
162 | std::unique_ptr<PragmaHandler> AlignHandler; |
163 | std::unique_ptr<PragmaHandler> GCCVisibilityHandler; |
164 | std::unique_ptr<PragmaHandler> OptionsHandler; |
165 | std::unique_ptr<PragmaHandler> PackHandler; |
166 | std::unique_ptr<PragmaHandler> MSStructHandler; |
167 | std::unique_ptr<PragmaHandler> UnusedHandler; |
168 | std::unique_ptr<PragmaHandler> WeakHandler; |
169 | std::unique_ptr<PragmaHandler> RedefineExtnameHandler; |
170 | std::unique_ptr<PragmaHandler> FPContractHandler; |
171 | std::unique_ptr<PragmaHandler> OpenCLExtensionHandler; |
172 | std::unique_ptr<PragmaHandler> OpenMPHandler; |
173 | std::unique_ptr<PragmaHandler> PCSectionHandler; |
174 | std::unique_ptr<PragmaHandler> MSCommentHandler; |
175 | std::unique_ptr<PragmaHandler> MSDetectMismatchHandler; |
176 | std::unique_ptr<PragmaHandler> MSPointersToMembers; |
177 | std::unique_ptr<PragmaHandler> MSVtorDisp; |
178 | std::unique_ptr<PragmaHandler> MSInitSeg; |
179 | std::unique_ptr<PragmaHandler> MSDataSeg; |
180 | std::unique_ptr<PragmaHandler> MSBSSSeg; |
181 | std::unique_ptr<PragmaHandler> MSConstSeg; |
182 | std::unique_ptr<PragmaHandler> MSCodeSeg; |
183 | std::unique_ptr<PragmaHandler> MSSection; |
184 | std::unique_ptr<PragmaHandler> MSRuntimeChecks; |
185 | std::unique_ptr<PragmaHandler> MSIntrinsic; |
186 | std::unique_ptr<PragmaHandler> MSOptimize; |
187 | std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler; |
188 | std::unique_ptr<PragmaHandler> OptimizeHandler; |
189 | std::unique_ptr<PragmaHandler> LoopHintHandler; |
190 | std::unique_ptr<PragmaHandler> UnrollHintHandler; |
191 | std::unique_ptr<PragmaHandler> NoUnrollHintHandler; |
192 | std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler; |
193 | std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler; |
194 | std::unique_ptr<PragmaHandler> FPHandler; |
195 | std::unique_ptr<PragmaHandler> STDCFENVHandler; |
196 | std::unique_ptr<PragmaHandler> STDCCXLIMITHandler; |
197 | std::unique_ptr<PragmaHandler> STDCUnknownHandler; |
198 | std::unique_ptr<PragmaHandler> AttributePragmaHandler; |
199 | |
200 | std::unique_ptr<CommentHandler> CommentSemaHandler; |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | bool GreaterThanIsOperator; |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | bool ColonIsSacred; |
213 | |
214 | |
215 | |
216 | |
217 | |
218 | |
219 | bool InMessageExpression; |
220 | |
221 | |
222 | |
223 | |
224 | bool CalledSignatureHelp = false; |
225 | |
226 | |
227 | unsigned TemplateParameterDepth; |
228 | |
229 | |
230 | class TemplateParameterDepthRAII { |
231 | unsigned &Depth; |
232 | unsigned AddedLevels; |
233 | public: |
234 | explicit TemplateParameterDepthRAII(unsigned &Depth) |
235 | : Depth(Depth), AddedLevels(0) {} |
236 | |
237 | ~TemplateParameterDepthRAII() { |
238 | Depth -= AddedLevels; |
239 | } |
240 | |
241 | void operator++() { |
242 | ++Depth; |
243 | ++AddedLevels; |
244 | } |
245 | void addDepth(unsigned D) { |
246 | Depth += D; |
247 | AddedLevels += D; |
248 | } |
249 | unsigned getDepth() const { return Depth; } |
250 | }; |
251 | |
252 | |
253 | AttributeFactory AttrFactory; |
254 | |
255 | |
256 | |
257 | SmallVector<TemplateIdAnnotation *, 16> TemplateIds; |
258 | |
259 | |
260 | SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers; |
261 | |
262 | |
263 | |
264 | |
265 | |
266 | |
267 | |
268 | |
269 | |
270 | |
271 | |
272 | struct AngleBracketTracker { |
273 | |
274 | |
275 | enum Priority : unsigned short { |
276 | |
277 | PotentialTypo = 0x0, |
278 | |
279 | DependentName = 0x2, |
280 | |
281 | |
282 | SpaceBeforeLess = 0x0, |
283 | |
284 | NoSpaceBeforeLess = 0x1, |
285 | |
286 | LLVM_MARK_AS_BITMASK_ENUM( DependentName) |
287 | }; |
288 | |
289 | struct Loc { |
290 | Expr *TemplateName; |
291 | SourceLocation LessLoc; |
292 | AngleBracketTracker::Priority Priority; |
293 | unsigned short ParenCount, BracketCount, BraceCount; |
294 | |
295 | bool isActive(Parser &P) const { |
296 | return P.ParenCount == ParenCount && P.BracketCount == BracketCount && |
297 | P.BraceCount == BraceCount; |
298 | } |
299 | |
300 | bool isActiveOrNested(Parser &P) const { |
301 | return isActive(P) || P.ParenCount > ParenCount || |
302 | P.BracketCount > BracketCount || P.BraceCount > BraceCount; |
303 | } |
304 | }; |
305 | |
306 | SmallVector<Loc, 8> Locs; |
307 | |
308 | |
309 | |
310 | |
311 | |
312 | |
313 | void add(Parser &P, Expr *TemplateName, SourceLocation LessLoc, |
314 | Priority Prio) { |
315 | if (!Locs.empty() && Locs.back().isActive(P)) { |
316 | if (Locs.back().Priority <= Prio) { |
317 | Locs.back().TemplateName = TemplateName; |
318 | Locs.back().LessLoc = LessLoc; |
319 | Locs.back().Priority = Prio; |
320 | } |
321 | } else { |
322 | Locs.push_back({TemplateName, LessLoc, Prio, |
323 | P.ParenCount, P.BracketCount, P.BraceCount}); |
324 | } |
325 | } |
326 | |
327 | |
328 | |
329 | |
330 | void clear(Parser &P) { |
331 | while (!Locs.empty() && Locs.back().isActiveOrNested(P)) |
332 | Locs.pop_back(); |
333 | } |
334 | |
335 | |
336 | |
337 | Loc *getCurrent(Parser &P) { |
338 | if (!Locs.empty() && Locs.back().isActive(P)) |
339 | return &Locs.back(); |
340 | return nullptr; |
341 | } |
342 | }; |
343 | |
344 | AngleBracketTracker AngleBrackets; |
345 | |
346 | IdentifierInfo *getSEHExceptKeyword(); |
347 | |
348 | |
349 | |
350 | |
351 | |
352 | |
353 | bool ParsingInObjCContainer; |
354 | |
355 | |
356 | |
357 | |
358 | |
359 | bool SkipFunctionBodies; |
360 | |
361 | |
362 | |
363 | |
364 | SourceLocation ExprStatementTokLoc; |
365 | |
366 | |
367 | enum class ParsedStmtContext { |
368 | |
369 | |
370 | AllowDeclarationsInC = 0x1, |
371 | |
372 | AllowStandaloneOpenMPDirectives = 0x2, |
373 | |
374 | InStmtExpr = 0x4, |
375 | |
376 | |
377 | SubStmt = 0, |
378 | |
379 | Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives, |
380 | |
381 | LLVM_MARK_AS_BITMASK_ENUM(InStmtExpr) |
382 | }; |
383 | |
384 | |
385 | |
386 | |
387 | StmtResult handleExprStmt(ExprResult E, ParsedStmtContext StmtCtx); |
388 | |
389 | public: |
390 | Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies); |
391 | ~Parser() override; |
392 | |
393 | const LangOptions &getLangOpts() const { return PP.getLangOpts(); } |
394 | const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } |
395 | Preprocessor &getPreprocessor() const { return PP; } |
396 | Sema &getActions() const { return Actions; } |
397 | AttributeFactory &getAttrFactory() { return AttrFactory; } |
398 | |
399 | const Token &getCurToken() const { return Tok; } |
400 | Scope *getCurScope() const { return Actions.getCurScope(); } |
401 | void incrementMSManglingNumber() const { |
402 | return Actions.incrementMSManglingNumber(); |
403 | } |
404 | |
405 | Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); } |
406 | |
407 | |
408 | |
409 | typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; |
410 | typedef OpaquePtr<TemplateName> TemplateTy; |
411 | |
412 | typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists; |
413 | |
414 | typedef Sema::FullExprArg FullExprArg; |
415 | |
416 | |
417 | |
418 | |
419 | |
420 | void Initialize(); |
421 | |
422 | |
423 | bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result); |
424 | |
425 | |
426 | |
427 | bool ParseTopLevelDecl(DeclGroupPtrTy &Result); |
428 | bool ParseTopLevelDecl() { |
429 | DeclGroupPtrTy Result; |
430 | return ParseTopLevelDecl(Result); |
431 | } |
432 | |
433 | |
434 | |
435 | |
436 | |
437 | |
438 | SourceLocation ConsumeToken() { |
439 | (0) . __assert_fail ("!isTokenSpecial() && \"Should consume special tokens with Consume*Token\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 440, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isTokenSpecial() && |
440 | (0) . __assert_fail ("!isTokenSpecial() && \"Should consume special tokens with Consume*Token\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 440, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Should consume special tokens with Consume*Token"); |
441 | PrevTokLocation = Tok.getLocation(); |
442 | PP.Lex(Tok); |
443 | return PrevTokLocation; |
444 | } |
445 | |
446 | bool TryConsumeToken(tok::TokenKind Expected) { |
447 | if (Tok.isNot(Expected)) |
448 | return false; |
449 | (0) . __assert_fail ("!isTokenSpecial() && \"Should consume special tokens with Consume*Token\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 450, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isTokenSpecial() && |
450 | (0) . __assert_fail ("!isTokenSpecial() && \"Should consume special tokens with Consume*Token\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 450, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Should consume special tokens with Consume*Token"); |
451 | PrevTokLocation = Tok.getLocation(); |
452 | PP.Lex(Tok); |
453 | return true; |
454 | } |
455 | |
456 | bool TryConsumeToken(tok::TokenKind Expected, SourceLocation &Loc) { |
457 | if (!TryConsumeToken(Expected)) |
458 | return false; |
459 | Loc = PrevTokLocation; |
460 | return true; |
461 | } |
462 | |
463 | |
464 | |
465 | |
466 | SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok = false) { |
467 | if (isTokenParen()) |
468 | return ConsumeParen(); |
469 | if (isTokenBracket()) |
470 | return ConsumeBracket(); |
471 | if (isTokenBrace()) |
472 | return ConsumeBrace(); |
473 | if (isTokenStringLiteral()) |
474 | return ConsumeStringToken(); |
475 | if (Tok.is(tok::code_completion)) |
476 | return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken() |
477 | : handleUnexpectedCodeCompletionToken(); |
478 | if (Tok.isAnnotation()) |
479 | return ConsumeAnnotationToken(); |
480 | return ConsumeToken(); |
481 | } |
482 | |
483 | |
484 | SourceLocation getEndOfPreviousToken() { |
485 | return PP.getLocForEndOfToken(PrevTokLocation); |
486 | } |
487 | |
488 | |
489 | |
490 | IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability) { |
491 | return Actions.getNullabilityKeyword(nullability); |
492 | } |
493 | |
494 | private: |
495 | |
496 | |
497 | |
498 | |
499 | |
500 | bool isTokenParen() const { |
501 | return Tok.isOneOf(tok::l_paren, tok::r_paren); |
502 | } |
503 | |
504 | bool isTokenBracket() const { |
505 | return Tok.isOneOf(tok::l_square, tok::r_square); |
506 | } |
507 | |
508 | bool isTokenBrace() const { |
509 | return Tok.isOneOf(tok::l_brace, tok::r_brace); |
510 | } |
511 | |
512 | bool isTokenStringLiteral() const { |
513 | return tok::isStringLiteral(Tok.getKind()); |
514 | } |
515 | |
516 | bool isTokenSpecial() const { |
517 | return isTokenStringLiteral() || isTokenParen() || isTokenBracket() || |
518 | isTokenBrace() || Tok.is(tok::code_completion) || Tok.isAnnotation(); |
519 | } |
520 | |
521 | |
522 | |
523 | bool isTokenEqualOrEqualTypo(); |
524 | |
525 | |
526 | |
527 | void UnconsumeToken(Token &Consumed) { |
528 | Token Next = Tok; |
529 | PP.EnterToken(Consumed); |
530 | PP.Lex(Tok); |
531 | PP.EnterToken(Next); |
532 | } |
533 | |
534 | SourceLocation ConsumeAnnotationToken() { |
535 | (0) . __assert_fail ("Tok.isAnnotation() && \"wrong consume method\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 535, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Tok.isAnnotation() && "wrong consume method"); |
536 | SourceLocation Loc = Tok.getLocation(); |
537 | PrevTokLocation = Tok.getAnnotationEndLoc(); |
538 | PP.Lex(Tok); |
539 | return Loc; |
540 | } |
541 | |
542 | |
543 | |
544 | SourceLocation ConsumeParen() { |
545 | (0) . __assert_fail ("isTokenParen() && \"wrong consume method\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 545, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isTokenParen() && "wrong consume method"); |
546 | if (Tok.getKind() == tok::l_paren) |
547 | ++ParenCount; |
548 | else if (ParenCount) { |
549 | AngleBrackets.clear(*this); |
550 | --ParenCount; |
551 | } |
552 | PrevTokLocation = Tok.getLocation(); |
553 | PP.Lex(Tok); |
554 | return PrevTokLocation; |
555 | } |
556 | |
557 | |
558 | |
559 | SourceLocation ConsumeBracket() { |
560 | (0) . __assert_fail ("isTokenBracket() && \"wrong consume method\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 560, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isTokenBracket() && "wrong consume method"); |
561 | if (Tok.getKind() == tok::l_square) |
562 | ++BracketCount; |
563 | else if (BracketCount) { |
564 | AngleBrackets.clear(*this); |
565 | --BracketCount; |
566 | } |
567 | |
568 | PrevTokLocation = Tok.getLocation(); |
569 | PP.Lex(Tok); |
570 | return PrevTokLocation; |
571 | } |
572 | |
573 | |
574 | |
575 | SourceLocation ConsumeBrace() { |
576 | (0) . __assert_fail ("isTokenBrace() && \"wrong consume method\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 576, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isTokenBrace() && "wrong consume method"); |
577 | if (Tok.getKind() == tok::l_brace) |
578 | ++BraceCount; |
579 | else if (BraceCount) { |
580 | AngleBrackets.clear(*this); |
581 | --BraceCount; |
582 | } |
583 | |
584 | PrevTokLocation = Tok.getLocation(); |
585 | PP.Lex(Tok); |
586 | return PrevTokLocation; |
587 | } |
588 | |
589 | |
590 | |
591 | |
592 | |
593 | SourceLocation ConsumeStringToken() { |
594 | (0) . __assert_fail ("isTokenStringLiteral() && \"Should only consume string literals with this method\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 595, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isTokenStringLiteral() && |
595 | (0) . __assert_fail ("isTokenStringLiteral() && \"Should only consume string literals with this method\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 595, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Should only consume string literals with this method"); |
596 | PrevTokLocation = Tok.getLocation(); |
597 | PP.Lex(Tok); |
598 | return PrevTokLocation; |
599 | } |
600 | |
601 | |
602 | |
603 | |
604 | |
605 | |
606 | SourceLocation ConsumeCodeCompletionToken() { |
607 | assert(Tok.is(tok::code_completion)); |
608 | PrevTokLocation = Tok.getLocation(); |
609 | PP.Lex(Tok); |
610 | return PrevTokLocation; |
611 | } |
612 | |
613 | |
614 | |
615 | |
616 | |
617 | |
618 | SourceLocation handleUnexpectedCodeCompletionToken(); |
619 | |
620 | |
621 | |
622 | void cutOffParsing() { |
623 | if (PP.isCodeCompletionEnabled()) |
624 | PP.setCodeCompletionReached(); |
625 | |
626 | Tok.setKind(tok::eof); |
627 | } |
628 | |
629 | |
630 | |
631 | bool isEofOrEom() { |
632 | tok::TokenKind Kind = Tok.getKind(); |
633 | return Kind == tok::eof || Kind == tok::annot_module_begin || |
634 | Kind == tok::annot_module_end || Kind == tok::annot_module_include; |
635 | } |
636 | |
637 | |
638 | bool isFoldOperator(prec::Level Level) const; |
639 | |
640 | |
641 | bool isFoldOperator(tok::TokenKind Kind) const; |
642 | |
643 | |
644 | void initializePragmaHandlers(); |
645 | |
646 | |
647 | void resetPragmaHandlers(); |
648 | |
649 | |
650 | void HandlePragmaUnused(); |
651 | |
652 | |
653 | |
654 | void HandlePragmaVisibility(); |
655 | |
656 | |
657 | |
658 | void HandlePragmaPack(); |
659 | |
660 | |
661 | |
662 | void HandlePragmaMSStruct(); |
663 | |
664 | |
665 | |
666 | void HandlePragmaMSComment(); |
667 | |
668 | void HandlePragmaMSPointersToMembers(); |
669 | |
670 | void HandlePragmaMSVtorDisp(); |
671 | |
672 | void HandlePragmaMSPragma(); |
673 | bool HandlePragmaMSSection(StringRef PragmaName, |
674 | SourceLocation PragmaLocation); |
675 | bool HandlePragmaMSSegment(StringRef PragmaName, |
676 | SourceLocation PragmaLocation); |
677 | bool HandlePragmaMSInitSeg(StringRef PragmaName, |
678 | SourceLocation PragmaLocation); |
679 | |
680 | |
681 | |
682 | void HandlePragmaAlign(); |
683 | |
684 | |
685 | |
686 | void HandlePragmaDump(); |
687 | |
688 | |
689 | |
690 | void HandlePragmaWeak(); |
691 | |
692 | |
693 | |
694 | void HandlePragmaWeakAlias(); |
695 | |
696 | |
697 | |
698 | void HandlePragmaRedefineExtname(); |
699 | |
700 | |
701 | |
702 | void HandlePragmaFPContract(); |
703 | |
704 | |
705 | |
706 | void HandlePragmaFEnvAccess(); |
707 | |
708 | |
709 | |
710 | void HandlePragmaFP(); |
711 | |
712 | |
713 | |
714 | void HandlePragmaOpenCLExtension(); |
715 | |
716 | |
717 | |
718 | StmtResult HandlePragmaCaptured(); |
719 | |
720 | |
721 | |
722 | bool HandlePragmaLoopHint(LoopHint &Hint); |
723 | |
724 | bool ParsePragmaAttributeSubjectMatchRuleSet( |
725 | attr::ParsedSubjectMatchRuleSet &SubjectMatchRules, |
726 | SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc); |
727 | |
728 | void HandlePragmaAttribute(); |
729 | |
730 | |
731 | |
732 | |
733 | |
734 | |
735 | |
736 | |
737 | const Token &GetLookAheadToken(unsigned N) { |
738 | if (N == 0 || Tok.is(tok::eof)) return Tok; |
739 | return PP.LookAhead(N-1); |
740 | } |
741 | |
742 | public: |
743 | |
744 | |
745 | const Token &NextToken() { |
746 | return PP.LookAhead(0); |
747 | } |
748 | |
749 | |
750 | static ParsedType getTypeAnnotation(const Token &Tok) { |
751 | return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue()); |
752 | } |
753 | |
754 | private: |
755 | static void setTypeAnnotation(Token &Tok, ParsedType T) { |
756 | Tok.setAnnotationValue(T.getAsOpaquePtr()); |
757 | } |
758 | |
759 | |
760 | |
761 | static ExprResult getExprAnnotation(const Token &Tok) { |
762 | return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue()); |
763 | } |
764 | |
765 | |
766 | |
767 | static void setExprAnnotation(Token &Tok, ExprResult ER) { |
768 | Tok.setAnnotationValue(ER.getAsOpaquePointer()); |
769 | } |
770 | |
771 | public: |
772 | |
773 | |
774 | bool TryAnnotateTypeOrScopeToken(); |
775 | bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(CXXScopeSpec &SS, |
776 | bool IsNewScope); |
777 | bool TryAnnotateCXXScopeToken(bool EnteringContext = false); |
778 | |
779 | private: |
780 | enum AnnotatedNameKind { |
781 | |
782 | ANK_Error, |
783 | |
784 | ANK_TentativeDecl, |
785 | |
786 | ANK_TemplateName, |
787 | |
788 | ANK_Unresolved, |
789 | |
790 | ANK_Success |
791 | }; |
792 | AnnotatedNameKind TryAnnotateName(bool IsAddressOfOperand, |
793 | CorrectionCandidateCallback *CCC = nullptr); |
794 | |
795 | |
796 | void AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation); |
797 | |
798 | |
799 | |
800 | |
801 | bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc, |
802 | const char *&PrevSpec, unsigned &DiagID, |
803 | bool &isInvalid) { |
804 | if (!getLangOpts().AltiVec && !getLangOpts().ZVector) |
805 | return false; |
806 | |
807 | if (Tok.getIdentifierInfo() != Ident_vector && |
808 | Tok.getIdentifierInfo() != Ident_bool && |
809 | (!getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel)) |
810 | return false; |
811 | |
812 | return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); |
813 | } |
814 | |
815 | |
816 | |
817 | |
818 | bool TryAltiVecVectorToken() { |
819 | if ((!getLangOpts().AltiVec && !getLangOpts().ZVector) || |
820 | Tok.getIdentifierInfo() != Ident_vector) return false; |
821 | return TryAltiVecVectorTokenOutOfLine(); |
822 | } |
823 | |
824 | bool TryAltiVecVectorTokenOutOfLine(); |
825 | bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, |
826 | const char *&PrevSpec, unsigned &DiagID, |
827 | bool &isInvalid); |
828 | |
829 | |
830 | |
831 | |
832 | bool isObjCInstancetype() { |
833 | assert(getLangOpts().ObjC); |
834 | if (Tok.isAnnotation()) |
835 | return false; |
836 | if (!Ident_instancetype) |
837 | Ident_instancetype = PP.getIdentifierInfo("instancetype"); |
838 | return Tok.getIdentifierInfo() == Ident_instancetype; |
839 | } |
840 | |
841 | |
842 | |
843 | |
844 | |
845 | |
846 | bool TryKeywordIdentFallback(bool DisableKeyword); |
847 | |
848 | |
849 | TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok); |
850 | |
851 | |
852 | |
853 | |
854 | |
855 | |
856 | |
857 | |
858 | |
859 | |
860 | |
861 | |
862 | class TentativeParsingAction { |
863 | Parser &P; |
864 | PreferredTypeBuilder PrevPreferredType; |
865 | Token PrevTok; |
866 | size_t PrevTentativelyDeclaredIdentifierCount; |
867 | unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount; |
868 | bool isActive; |
869 | |
870 | public: |
871 | explicit TentativeParsingAction(Parser& p) : P(p) { |
872 | PrevPreferredType = P.PreferredType; |
873 | PrevTok = P.Tok; |
874 | PrevTentativelyDeclaredIdentifierCount = |
875 | P.TentativelyDeclaredIdentifiers.size(); |
876 | PrevParenCount = P.ParenCount; |
877 | PrevBracketCount = P.BracketCount; |
878 | PrevBraceCount = P.BraceCount; |
879 | P.PP.EnableBacktrackAtThisPos(); |
880 | isActive = true; |
881 | } |
882 | void Commit() { |
883 | (0) . __assert_fail ("isActive && \"Parsing action was finished!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 883, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isActive && "Parsing action was finished!"); |
884 | P.TentativelyDeclaredIdentifiers.resize( |
885 | PrevTentativelyDeclaredIdentifierCount); |
886 | P.PP.CommitBacktrackedTokens(); |
887 | isActive = false; |
888 | } |
889 | void Revert() { |
890 | (0) . __assert_fail ("isActive && \"Parsing action was finished!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 890, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isActive && "Parsing action was finished!"); |
891 | P.PP.Backtrack(); |
892 | P.PreferredType = PrevPreferredType; |
893 | P.Tok = PrevTok; |
894 | P.TentativelyDeclaredIdentifiers.resize( |
895 | PrevTentativelyDeclaredIdentifierCount); |
896 | P.ParenCount = PrevParenCount; |
897 | P.BracketCount = PrevBracketCount; |
898 | P.BraceCount = PrevBraceCount; |
899 | isActive = false; |
900 | } |
901 | ~TentativeParsingAction() { |
902 | (0) . __assert_fail ("!isActive && \"Forgot to call Commit or Revert!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 902, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isActive && "Forgot to call Commit or Revert!"); |
903 | } |
904 | }; |
905 | |
906 | |
907 | class RevertingTentativeParsingAction |
908 | : private Parser::TentativeParsingAction { |
909 | public: |
910 | RevertingTentativeParsingAction(Parser &P) |
911 | : Parser::TentativeParsingAction(P) {} |
912 | ~RevertingTentativeParsingAction() { Revert(); } |
913 | }; |
914 | |
915 | class UnannotatedTentativeParsingAction; |
916 | |
917 | |
918 | |
919 | |
920 | class ObjCDeclContextSwitch { |
921 | Parser &P; |
922 | Decl *DC; |
923 | SaveAndRestore<bool> WithinObjCContainer; |
924 | public: |
925 | explicit ObjCDeclContextSwitch(Parser &p) |
926 | : P(p), DC(p.getObjCDeclContext()), |
927 | WithinObjCContainer(P.ParsingInObjCContainer, DC != nullptr) { |
928 | if (DC) |
929 | P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC)); |
930 | } |
931 | ~ObjCDeclContextSwitch() { |
932 | if (DC) |
933 | P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC)); |
934 | } |
935 | }; |
936 | |
937 | |
938 | |
939 | |
940 | |
941 | |
942 | |
943 | |
944 | |
945 | bool ExpectAndConsume(tok::TokenKind ExpectedTok, |
946 | unsigned Diag = diag::err_expected, |
947 | StringRef DiagMsg = ""); |
948 | |
949 | |
950 | |
951 | |
952 | |
953 | |
954 | bool ExpectAndConsumeSemi(unsigned DiagID); |
955 | |
956 | |
957 | enum { |
958 | OutsideFunction = 0, |
959 | InsideStruct = 1, |
960 | InstanceVariableList = 2, |
961 | AfterMemberFunctionDefinition = 3 |
962 | }; |
963 | |
964 | |
965 | void (ExtraSemiKind Kind, unsigned TST = TST_unspecified); |
966 | |
967 | |
968 | |
969 | |
970 | |
971 | |
972 | |
973 | bool expectIdentifier(); |
974 | |
975 | public: |
976 | |
977 | |
978 | |
979 | |
980 | |
981 | |
982 | |
983 | |
984 | |
985 | class ParseScope { |
986 | Parser *Self; |
987 | ParseScope(const ParseScope &) = delete; |
988 | void operator=(const ParseScope &) = delete; |
989 | |
990 | public: |
991 | |
992 | |
993 | |
994 | ParseScope(Parser *Self, unsigned ScopeFlags, bool EnteredScope = true, |
995 | bool BeforeCompoundStmt = false) |
996 | : Self(Self) { |
997 | if (EnteredScope && !BeforeCompoundStmt) |
998 | Self->EnterScope(ScopeFlags); |
999 | else { |
1000 | if (BeforeCompoundStmt) |
1001 | Self->incrementMSManglingNumber(); |
1002 | |
1003 | this->Self = nullptr; |
1004 | } |
1005 | } |
1006 | |
1007 | |
1008 | |
1009 | void Exit() { |
1010 | if (Self) { |
1011 | Self->ExitScope(); |
1012 | Self = nullptr; |
1013 | } |
1014 | } |
1015 | |
1016 | ~ParseScope() { |
1017 | Exit(); |
1018 | } |
1019 | }; |
1020 | |
1021 | |
1022 | void EnterScope(unsigned ScopeFlags); |
1023 | |
1024 | |
1025 | void ExitScope(); |
1026 | |
1027 | private: |
1028 | |
1029 | class ParseScopeFlags { |
1030 | Scope *CurScope; |
1031 | unsigned OldFlags; |
1032 | ParseScopeFlags(const ParseScopeFlags &) = delete; |
1033 | void operator=(const ParseScopeFlags &) = delete; |
1034 | |
1035 | public: |
1036 | ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true); |
1037 | ~ParseScopeFlags(); |
1038 | }; |
1039 | |
1040 | |
1041 | |
1042 | |
1043 | public: |
1044 | DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); |
1045 | DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); |
1046 | DiagnosticBuilder Diag(unsigned DiagID) { |
1047 | return Diag(Tok, DiagID); |
1048 | } |
1049 | |
1050 | private: |
1051 | void SuggestParentheses(SourceLocation Loc, unsigned DK, |
1052 | SourceRange ParenRange); |
1053 | void CheckNestedObjCContexts(SourceLocation AtLoc); |
1054 | |
1055 | public: |
1056 | |
1057 | |
1058 | enum SkipUntilFlags { |
1059 | StopAtSemi = 1 << 0, |
1060 | |
1061 | StopBeforeMatch = 1 << 1, |
1062 | StopAtCodeCompletion = 1 << 2 |
1063 | }; |
1064 | |
1065 | friend constexpr SkipUntilFlags operator|(SkipUntilFlags L, |
1066 | SkipUntilFlags R) { |
1067 | return static_cast<SkipUntilFlags>(static_cast<unsigned>(L) | |
1068 | static_cast<unsigned>(R)); |
1069 | } |
1070 | |
1071 | |
1072 | |
1073 | |
1074 | |
1075 | |
1076 | |
1077 | |
1078 | |
1079 | bool SkipUntil(tok::TokenKind T, |
1080 | SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) { |
1081 | return SkipUntil(llvm::makeArrayRef(T), Flags); |
1082 | } |
1083 | bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, |
1084 | SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) { |
1085 | tok::TokenKind TokArray[] = {T1, T2}; |
1086 | return SkipUntil(TokArray, Flags); |
1087 | } |
1088 | bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3, |
1089 | SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) { |
1090 | tok::TokenKind TokArray[] = {T1, T2, T3}; |
1091 | return SkipUntil(TokArray, Flags); |
1092 | } |
1093 | bool SkipUntil(ArrayRef<tok::TokenKind> Toks, |
1094 | SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)); |
1095 | |
1096 | |
1097 | |
1098 | void SkipMalformedDecl(); |
1099 | |
1100 | private: |
1101 | |
1102 | |
1103 | |
1104 | struct ParsingClass; |
1105 | |
1106 | |
1107 | |
1108 | |
1109 | |
1110 | |
1111 | |
1112 | |
1113 | |
1114 | class LateParsedDeclaration { |
1115 | public: |
1116 | virtual ~LateParsedDeclaration(); |
1117 | |
1118 | virtual void ParseLexedMethodDeclarations(); |
1119 | virtual void ParseLexedMemberInitializers(); |
1120 | virtual void ParseLexedMethodDefs(); |
1121 | virtual void ParseLexedAttributes(); |
1122 | }; |
1123 | |
1124 | |
1125 | |
1126 | class LateParsedClass : public LateParsedDeclaration { |
1127 | public: |
1128 | LateParsedClass(Parser *P, ParsingClass *C); |
1129 | ~LateParsedClass() override; |
1130 | |
1131 | void ParseLexedMethodDeclarations() override; |
1132 | void ParseLexedMemberInitializers() override; |
1133 | void ParseLexedMethodDefs() override; |
1134 | void ParseLexedAttributes() override; |
1135 | |
1136 | private: |
1137 | Parser *Self; |
1138 | ParsingClass *Class; |
1139 | }; |
1140 | |
1141 | |
1142 | |
1143 | |
1144 | |
1145 | |
1146 | |
1147 | struct LateParsedAttribute : public LateParsedDeclaration { |
1148 | Parser *Self; |
1149 | CachedTokens Toks; |
1150 | IdentifierInfo &AttrName; |
1151 | SourceLocation AttrNameLoc; |
1152 | SmallVector<Decl*, 2> Decls; |
1153 | |
1154 | explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name, |
1155 | SourceLocation Loc) |
1156 | : Self(P), AttrName(Name), AttrNameLoc(Loc) {} |
1157 | |
1158 | void ParseLexedAttributes() override; |
1159 | |
1160 | void addDecl(Decl *D) { Decls.push_back(D); } |
1161 | }; |
1162 | |
1163 | |
1164 | class LateParsedAttrList: public SmallVector<LateParsedAttribute *, 2> { |
1165 | public: |
1166 | LateParsedAttrList(bool PSoon = false) : ParseSoon(PSoon) { } |
1167 | |
1168 | bool parseSoon() { return ParseSoon; } |
1169 | |
1170 | private: |
1171 | bool ParseSoon; |
1172 | }; |
1173 | |
1174 | |
1175 | |
1176 | |
1177 | struct LexedMethod : public LateParsedDeclaration { |
1178 | Parser *Self; |
1179 | Decl *D; |
1180 | CachedTokens Toks; |
1181 | |
1182 | |
1183 | |
1184 | |
1185 | bool TemplateScope; |
1186 | |
1187 | explicit LexedMethod(Parser* P, Decl *MD) |
1188 | : Self(P), D(MD), TemplateScope(false) {} |
1189 | |
1190 | void ParseLexedMethodDefs() override; |
1191 | }; |
1192 | |
1193 | |
1194 | |
1195 | |
1196 | |
1197 | struct LateParsedDefaultArgument { |
1198 | explicit LateParsedDefaultArgument(Decl *P, |
1199 | std::unique_ptr<CachedTokens> Toks = nullptr) |
1200 | : Param(P), Toks(std::move(Toks)) { } |
1201 | |
1202 | |
1203 | Decl *Param; |
1204 | |
1205 | |
1206 | |
1207 | |
1208 | |
1209 | std::unique_ptr<CachedTokens> Toks; |
1210 | }; |
1211 | |
1212 | |
1213 | |
1214 | |
1215 | |
1216 | struct LateParsedMethodDeclaration : public LateParsedDeclaration { |
1217 | explicit LateParsedMethodDeclaration(Parser *P, Decl *M) |
1218 | : Self(P), Method(M), TemplateScope(false), |
1219 | ExceptionSpecTokens(nullptr) {} |
1220 | |
1221 | void ParseLexedMethodDeclarations() override; |
1222 | |
1223 | Parser* Self; |
1224 | |
1225 | |
1226 | Decl *Method; |
1227 | |
1228 | |
1229 | |
1230 | |
1231 | bool TemplateScope; |
1232 | |
1233 | |
1234 | |
1235 | |
1236 | |
1237 | |
1238 | SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; |
1239 | |
1240 | |
1241 | |
1242 | CachedTokens *ExceptionSpecTokens; |
1243 | }; |
1244 | |
1245 | |
1246 | |
1247 | |
1248 | struct LateParsedMemberInitializer : public LateParsedDeclaration { |
1249 | LateParsedMemberInitializer(Parser *P, Decl *FD) |
1250 | : Self(P), Field(FD) { } |
1251 | |
1252 | void ParseLexedMemberInitializers() override; |
1253 | |
1254 | Parser *Self; |
1255 | |
1256 | |
1257 | Decl *Field; |
1258 | |
1259 | |
1260 | |
1261 | CachedTokens Toks; |
1262 | }; |
1263 | |
1264 | |
1265 | |
1266 | |
1267 | |
1268 | |
1269 | |
1270 | typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer; |
1271 | |
1272 | |
1273 | |
1274 | |
1275 | struct ParsingClass { |
1276 | ParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface) |
1277 | : TopLevelClass(TopLevelClass), TemplateScope(false), |
1278 | IsInterface(IsInterface), TagOrTemplate(TagOrTemplate) { } |
1279 | |
1280 | |
1281 | |
1282 | bool TopLevelClass : 1; |
1283 | |
1284 | |
1285 | |
1286 | |
1287 | bool TemplateScope : 1; |
1288 | |
1289 | |
1290 | bool IsInterface : 1; |
1291 | |
1292 | |
1293 | Decl *TagOrTemplate; |
1294 | |
1295 | |
1296 | |
1297 | |
1298 | LateParsedDeclarationsContainer LateParsedDeclarations; |
1299 | }; |
1300 | |
1301 | |
1302 | |
1303 | |
1304 | std::stack<ParsingClass *> ClassStack; |
1305 | |
1306 | ParsingClass &getCurrentClass() { |
1307 | (0) . __assert_fail ("!ClassStack.empty() && \"No lexed method stacks!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 1307, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!ClassStack.empty() && "No lexed method stacks!"); |
1308 | return *ClassStack.top(); |
1309 | } |
1310 | |
1311 | |
1312 | class ParsingClassDefinition { |
1313 | Parser &P; |
1314 | bool Popped; |
1315 | Sema::ParsingClassState State; |
1316 | |
1317 | public: |
1318 | ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass, |
1319 | bool IsInterface) |
1320 | : P(P), Popped(false), |
1321 | State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) { |
1322 | } |
1323 | |
1324 | |
1325 | void Pop() { |
1326 | (0) . __assert_fail ("!Popped && \"Nested class has already been popped\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 1326, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!Popped && "Nested class has already been popped"); |
1327 | Popped = true; |
1328 | P.PopParsingClass(State); |
1329 | } |
1330 | |
1331 | ~ParsingClassDefinition() { |
1332 | if (!Popped) |
1333 | P.PopParsingClass(State); |
1334 | } |
1335 | }; |
1336 | |
1337 | |
1338 | |
1339 | |
1340 | struct ParsedTemplateInfo { |
1341 | ParsedTemplateInfo() |
1342 | : Kind(NonTemplate), TemplateParams(nullptr), TemplateLoc() { } |
1343 | |
1344 | ParsedTemplateInfo(TemplateParameterLists *TemplateParams, |
1345 | bool isSpecialization, |
1346 | bool lastParameterListWasEmpty = false) |
1347 | : Kind(isSpecialization? ExplicitSpecialization : Template), |
1348 | TemplateParams(TemplateParams), |
1349 | LastParameterListWasEmpty(lastParameterListWasEmpty) { } |
1350 | |
1351 | explicit ParsedTemplateInfo(SourceLocation ExternLoc, |
1352 | SourceLocation TemplateLoc) |
1353 | : Kind(ExplicitInstantiation), TemplateParams(nullptr), |
1354 | ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), |
1355 | LastParameterListWasEmpty(false){ } |
1356 | |
1357 | |
1358 | enum { |
1359 | |
1360 | NonTemplate = 0, |
1361 | |
1362 | Template, |
1363 | |
1364 | ExplicitSpecialization, |
1365 | |
1366 | ExplicitInstantiation |
1367 | } Kind; |
1368 | |
1369 | |
1370 | |
1371 | TemplateParameterLists *TemplateParams; |
1372 | |
1373 | |
1374 | |
1375 | SourceLocation ExternLoc; |
1376 | |
1377 | |
1378 | |
1379 | SourceLocation TemplateLoc; |
1380 | |
1381 | |
1382 | bool LastParameterListWasEmpty; |
1383 | |
1384 | SourceRange getSourceRange() const LLVM_READONLY; |
1385 | }; |
1386 | |
1387 | void LexTemplateFunctionForLateParsing(CachedTokens &Toks); |
1388 | void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT); |
1389 | |
1390 | static void LateTemplateParserCallback(void *P, LateParsedTemplate &LPT); |
1391 | static void LateTemplateParserCleanupCallback(void *P); |
1392 | |
1393 | Sema::ParsingClassState |
1394 | PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface); |
1395 | void DeallocateParsedClasses(ParsingClass *Class); |
1396 | void PopParsingClass(Sema::ParsingClassState); |
1397 | |
1398 | enum CachedInitKind { |
1399 | CIK_DefaultArgument, |
1400 | CIK_DefaultInitializer |
1401 | }; |
1402 | |
1403 | NamedDecl *ParseCXXInlineMethodDef(AccessSpecifier AS, |
1404 | ParsedAttributes &AccessAttrs, |
1405 | ParsingDeclarator &D, |
1406 | const ParsedTemplateInfo &TemplateInfo, |
1407 | const VirtSpecifiers &VS, |
1408 | SourceLocation PureSpecLoc); |
1409 | void ParseCXXNonStaticMemberInitializer(Decl *VarD); |
1410 | void ParseLexedAttributes(ParsingClass &Class); |
1411 | void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D, |
1412 | bool EnterScope, bool OnDefinition); |
1413 | void ParseLexedAttribute(LateParsedAttribute &LA, |
1414 | bool EnterScope, bool OnDefinition); |
1415 | void ParseLexedMethodDeclarations(ParsingClass &Class); |
1416 | void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM); |
1417 | void ParseLexedMethodDefs(ParsingClass &Class); |
1418 | void ParseLexedMethodDef(LexedMethod &LM); |
1419 | void ParseLexedMemberInitializers(ParsingClass &Class); |
1420 | void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI); |
1421 | void ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod); |
1422 | bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks); |
1423 | bool ConsumeAndStoreInitializer(CachedTokens &Toks, CachedInitKind CIK); |
1424 | bool ConsumeAndStoreConditional(CachedTokens &Toks); |
1425 | bool ConsumeAndStoreUntil(tok::TokenKind T1, |
1426 | CachedTokens &Toks, |
1427 | bool StopAtSemi = true, |
1428 | bool ConsumeFinalToken = true) { |
1429 | return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken); |
1430 | } |
1431 | bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, |
1432 | CachedTokens &Toks, |
1433 | bool StopAtSemi = true, |
1434 | bool ConsumeFinalToken = true); |
1435 | |
1436 | |
1437 | |
1438 | struct ParsedAttributesWithRange : ParsedAttributes { |
1439 | ParsedAttributesWithRange(AttributeFactory &factory) |
1440 | : ParsedAttributes(factory) {} |
1441 | |
1442 | void clear() { |
1443 | ParsedAttributes::clear(); |
1444 | Range = SourceRange(); |
1445 | } |
1446 | |
1447 | SourceRange Range; |
1448 | }; |
1449 | struct ParsedAttributesViewWithRange : ParsedAttributesView { |
1450 | ParsedAttributesViewWithRange() : ParsedAttributesView() {} |
1451 | void clearListOnly() { |
1452 | ParsedAttributesView::clearListOnly(); |
1453 | Range = SourceRange(); |
1454 | } |
1455 | |
1456 | SourceRange Range; |
1457 | }; |
1458 | |
1459 | DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs, |
1460 | ParsingDeclSpec *DS = nullptr); |
1461 | bool isDeclarationAfterDeclarator(); |
1462 | bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); |
1463 | DeclGroupPtrTy ParseDeclarationOrFunctionDefinition( |
1464 | ParsedAttributesWithRange &attrs, |
1465 | ParsingDeclSpec *DS = nullptr, |
1466 | AccessSpecifier AS = AS_none); |
1467 | DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs, |
1468 | ParsingDeclSpec &DS, |
1469 | AccessSpecifier AS); |
1470 | |
1471 | void SkipFunctionBody(); |
1472 | Decl *ParseFunctionDefinition(ParsingDeclarator &D, |
1473 | const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), |
1474 | LateParsedAttrList *LateParsedAttrs = nullptr); |
1475 | void ParseKNRParamDeclarations(Declarator &D); |
1476 | |
1477 | |
1478 | ExprResult ParseSimpleAsm(SourceLocation *EndLoc = nullptr); |
1479 | ExprResult ParseAsmStringLiteral(); |
1480 | |
1481 | |
1482 | void MaybeSkipAttributes(tok::ObjCKeywordKind Kind); |
1483 | DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributesWithRange &Attrs); |
1484 | DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); |
1485 | Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, |
1486 | ParsedAttributes &prefixAttrs); |
1487 | class ObjCTypeParamListScope; |
1488 | ObjCTypeParamList *parseObjCTypeParamList(); |
1489 | ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs( |
1490 | ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc, |
1491 | SmallVectorImpl<IdentifierLocPair> &protocolIdents, |
1492 | SourceLocation &rAngleLoc, bool mayBeProtocolList = true); |
1493 | |
1494 | void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc, |
1495 | BalancedDelimiterTracker &T, |
1496 | SmallVectorImpl<Decl *> &AllIvarDecls, |
1497 | bool RBraceMissing); |
1498 | void ParseObjCClassInstanceVariables(Decl *interfaceDecl, |
1499 | tok::ObjCKeywordKind visibility, |
1500 | SourceLocation atLoc); |
1501 | bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P, |
1502 | SmallVectorImpl<SourceLocation> &PLocs, |
1503 | bool WarnOnDeclarations, |
1504 | bool ForObjCContainer, |
1505 | SourceLocation &LAngleLoc, |
1506 | SourceLocation &EndProtoLoc, |
1507 | bool consumeLastToken); |
1508 | |
1509 | |
1510 | |
1511 | |
1512 | void parseObjCTypeArgsOrProtocolQualifiers( |
1513 | ParsedType baseType, |
1514 | SourceLocation &typeArgsLAngleLoc, |
1515 | SmallVectorImpl<ParsedType> &typeArgs, |
1516 | SourceLocation &typeArgsRAngleLoc, |
1517 | SourceLocation &protocolLAngleLoc, |
1518 | SmallVectorImpl<Decl *> &protocols, |
1519 | SmallVectorImpl<SourceLocation> &protocolLocs, |
1520 | SourceLocation &protocolRAngleLoc, |
1521 | bool consumeLastToken, |
1522 | bool warnOnIncompleteProtocols); |
1523 | |
1524 | |
1525 | |
1526 | void parseObjCTypeArgsAndProtocolQualifiers( |
1527 | ParsedType baseType, |
1528 | SourceLocation &typeArgsLAngleLoc, |
1529 | SmallVectorImpl<ParsedType> &typeArgs, |
1530 | SourceLocation &typeArgsRAngleLoc, |
1531 | SourceLocation &protocolLAngleLoc, |
1532 | SmallVectorImpl<Decl *> &protocols, |
1533 | SmallVectorImpl<SourceLocation> &protocolLocs, |
1534 | SourceLocation &protocolRAngleLoc, |
1535 | bool consumeLastToken); |
1536 | |
1537 | |
1538 | |
1539 | TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc); |
1540 | |
1541 | |
1542 | |
1543 | TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc, |
1544 | ParsedType type, |
1545 | bool consumeLastToken, |
1546 | SourceLocation &endLoc); |
1547 | |
1548 | void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, |
1549 | Decl *CDecl); |
1550 | DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc, |
1551 | ParsedAttributes &prefixAttrs); |
1552 | |
1553 | struct ObjCImplParsingDataRAII { |
1554 | Parser &P; |
1555 | Decl *Dcl; |
1556 | bool HasCFunction; |
1557 | typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer; |
1558 | LateParsedObjCMethodContainer LateParsedObjCMethods; |
1559 | |
1560 | ObjCImplParsingDataRAII(Parser &parser, Decl *D) |
1561 | : P(parser), Dcl(D), HasCFunction(false) { |
1562 | P.CurParsedObjCImpl = this; |
1563 | Finished = false; |
1564 | } |
1565 | ~ObjCImplParsingDataRAII(); |
1566 | |
1567 | void finish(SourceRange AtEnd); |
1568 | bool isFinished() const { return Finished; } |
1569 | |
1570 | private: |
1571 | bool Finished; |
1572 | }; |
1573 | ObjCImplParsingDataRAII *CurParsedObjCImpl; |
1574 | void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl); |
1575 | |
1576 | DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc); |
1577 | DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd); |
1578 | Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc); |
1579 | Decl *ParseObjCPropertySynthesize(SourceLocation atLoc); |
1580 | Decl *ParseObjCPropertyDynamic(SourceLocation atLoc); |
1581 | |
1582 | IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); |
1583 | |
1584 | enum ObjCTypeQual { |
1585 | objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, |
1586 | objc_nonnull, objc_nullable, objc_null_unspecified, |
1587 | objc_NumQuals |
1588 | }; |
1589 | IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; |
1590 | |
1591 | bool isTokIdentifier_in() const; |
1592 | |
1593 | ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, DeclaratorContext Ctx, |
1594 | ParsedAttributes *ParamAttrs); |
1595 | void ParseObjCMethodRequirement(); |
1596 | Decl *ParseObjCMethodPrototype( |
1597 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, |
1598 | bool MethodDefinition = true); |
1599 | Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, |
1600 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, |
1601 | bool MethodDefinition=true); |
1602 | void ParseObjCPropertyAttribute(ObjCDeclSpec &DS); |
1603 | |
1604 | Decl *ParseObjCMethodDefinition(); |
1605 | |
1606 | public: |
1607 | |
1608 | |
1609 | |
1610 | |
1611 | enum TypeCastState { |
1612 | NotTypeCast = 0, |
1613 | MaybeTypeCast, |
1614 | IsTypeCast |
1615 | }; |
1616 | |
1617 | ExprResult ParseExpression(TypeCastState isTypeCast = NotTypeCast); |
1618 | ExprResult ParseConstantExpressionInExprEvalContext( |
1619 | TypeCastState isTypeCast = NotTypeCast); |
1620 | ExprResult ParseConstantExpression(TypeCastState isTypeCast = NotTypeCast); |
1621 | ExprResult ParseCaseExpression(SourceLocation CaseLoc); |
1622 | ExprResult ParseConstraintExpression(); |
1623 | |
1624 | ExprResult ParseAssignmentExpression(TypeCastState isTypeCast = NotTypeCast); |
1625 | |
1626 | ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl<Token> &LineToks, |
1627 | unsigned &NumLineToksConsumed, |
1628 | bool IsUnevaluated); |
1629 | |
1630 | private: |
1631 | ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); |
1632 | |
1633 | ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); |
1634 | |
1635 | ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, |
1636 | prec::Level MinPrec); |
1637 | ExprResult ParseCastExpression(bool isUnaryExpression, |
1638 | bool isAddressOfOperand, |
1639 | bool &NotCastExpr, |
1640 | TypeCastState isTypeCast, |
1641 | bool isVectorLiteral = false); |
1642 | ExprResult ParseCastExpression(bool isUnaryExpression, |
1643 | bool isAddressOfOperand = false, |
1644 | TypeCastState isTypeCast = NotTypeCast, |
1645 | bool isVectorLiteral = false); |
1646 | |
1647 | |
1648 | bool isNotExpressionStart(); |
1649 | |
1650 | |
1651 | |
1652 | bool isPostfixExpressionSuffixStart() { |
1653 | tok::TokenKind K = Tok.getKind(); |
1654 | return (K == tok::l_square || K == tok::l_paren || |
1655 | K == tok::period || K == tok::arrow || |
1656 | K == tok::plusplus || K == tok::minusminus); |
1657 | } |
1658 | |
1659 | bool diagnoseUnknownTemplateId(ExprResult TemplateName, SourceLocation Less); |
1660 | void checkPotentialAngleBracket(ExprResult &PotentialTemplateName); |
1661 | bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &, |
1662 | const Token &OpToken); |
1663 | bool checkPotentialAngleBracketDelimiter(const Token &OpToken) { |
1664 | if (auto *Info = AngleBrackets.getCurrent(*this)) |
1665 | return checkPotentialAngleBracketDelimiter(*Info, OpToken); |
1666 | return false; |
1667 | } |
1668 | |
1669 | ExprResult ParsePostfixExpressionSuffix(ExprResult LHS); |
1670 | ExprResult ParseUnaryExprOrTypeTraitExpression(); |
1671 | ExprResult ParseBuiltinPrimaryExpression(); |
1672 | |
1673 | ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, |
1674 | bool &isCastExpr, |
1675 | ParsedType &CastTy, |
1676 | SourceRange &CastRange); |
1677 | |
1678 | typedef SmallVector<Expr*, 20> ExprListTy; |
1679 | typedef SmallVector<SourceLocation, 20> CommaLocsTy; |
1680 | |
1681 | |
1682 | bool ParseExpressionList(SmallVectorImpl<Expr *> &Exprs, |
1683 | SmallVectorImpl<SourceLocation> &CommaLocs, |
1684 | llvm::function_ref<void()> ExpressionStarts = |
1685 | llvm::function_ref<void()>()); |
1686 | |
1687 | |
1688 | |
1689 | bool ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs, |
1690 | SmallVectorImpl<SourceLocation> &CommaLocs); |
1691 | |
1692 | |
1693 | |
1694 | enum ParenParseOption { |
1695 | SimpleExpr, |
1696 | FoldExpr, |
1697 | CompoundStmt, |
1698 | CompoundLiteral, |
1699 | CastExpr |
1700 | }; |
1701 | ExprResult ParseParenExpression(ParenParseOption &ExprType, |
1702 | bool stopIfCastExpr, |
1703 | bool isTypeCast, |
1704 | ParsedType &CastTy, |
1705 | SourceLocation &RParenLoc); |
1706 | |
1707 | ExprResult ParseCXXAmbiguousParenExpression( |
1708 | ParenParseOption &ExprType, ParsedType &CastTy, |
1709 | BalancedDelimiterTracker &Tracker, ColonProtectionRAIIObject &ColonProt); |
1710 | ExprResult ParseCompoundLiteralExpression(ParsedType Ty, |
1711 | SourceLocation LParenLoc, |
1712 | SourceLocation RParenLoc); |
1713 | |
1714 | ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral = false); |
1715 | |
1716 | ExprResult ParseGenericSelectionExpression(); |
1717 | |
1718 | ExprResult ParseObjCBoolLiteral(); |
1719 | |
1720 | ExprResult ParseFoldExpression(ExprResult LHS, BalancedDelimiterTracker &T); |
1721 | |
1722 | |
1723 | |
1724 | ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS, bool isAddressOfOperand, |
1725 | Token &Replacement); |
1726 | ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); |
1727 | |
1728 | bool areTokensAdjacent(const Token &A, const Token &B); |
1729 | |
1730 | void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr, |
1731 | bool EnteringContext, IdentifierInfo &II, |
1732 | CXXScopeSpec &SS); |
1733 | |
1734 | bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, |
1735 | ParsedType ObjectType, |
1736 | bool EnteringContext, |
1737 | bool *MayBePseudoDestructor = nullptr, |
1738 | bool IsTypename = false, |
1739 | IdentifierInfo **LastII = nullptr, |
1740 | bool OnlyNamespace = false); |
1741 | |
1742 | |
1743 | |
1744 | |
1745 | |
1746 | ExprResult ParseLambdaExpression(); |
1747 | ExprResult TryParseLambdaExpression(); |
1748 | Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro, |
1749 | bool *SkippedInits = nullptr); |
1750 | bool TryParseLambdaIntroducer(LambdaIntroducer &Intro); |
1751 | ExprResult ParseLambdaExpressionAfterIntroducer( |
1752 | LambdaIntroducer &Intro); |
1753 | |
1754 | |
1755 | |
1756 | ExprResult ParseCXXCasts(); |
1757 | |
1758 | |
1759 | |
1760 | ExprResult ParseCXXTypeid(); |
1761 | |
1762 | |
1763 | |
1764 | ExprResult ParseCXXUuidof(); |
1765 | |
1766 | |
1767 | |
1768 | ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc, |
1769 | tok::TokenKind OpKind, |
1770 | CXXScopeSpec &SS, |
1771 | ParsedType ObjectType); |
1772 | |
1773 | |
1774 | |
1775 | ExprResult ParseCXXThis(); |
1776 | |
1777 | |
1778 | |
1779 | ExprResult ParseThrowExpression(); |
1780 | |
1781 | ExceptionSpecificationType tryParseExceptionSpecification( |
1782 | bool Delayed, |
1783 | SourceRange &SpecificationRange, |
1784 | SmallVectorImpl<ParsedType> &DynamicExceptions, |
1785 | SmallVectorImpl<SourceRange> &DynamicExceptionRanges, |
1786 | ExprResult &NoexceptExpr, |
1787 | CachedTokens *&ExceptionSpecTokens); |
1788 | |
1789 | |
1790 | ExceptionSpecificationType ParseDynamicExceptionSpecification( |
1791 | SourceRange &SpecificationRange, |
1792 | SmallVectorImpl<ParsedType> &Exceptions, |
1793 | SmallVectorImpl<SourceRange> &Ranges); |
1794 | |
1795 | |
1796 | |
1797 | TypeResult ParseTrailingReturnType(SourceRange &Range, |
1798 | bool MayBeFollowedByDirectInit); |
1799 | |
1800 | |
1801 | |
1802 | ExprResult ParseCXXBoolLiteral(); |
1803 | |
1804 | |
1805 | |
1806 | ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); |
1807 | |
1808 | |
1809 | |
1810 | |
1811 | void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); |
1812 | |
1813 | bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); |
1814 | |
1815 | |
1816 | |
1817 | bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs, |
1818 | Declarator &D); |
1819 | void ParseDirectNewDeclarator(Declarator &D); |
1820 | ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); |
1821 | ExprResult ParseCXXDeleteExpression(bool UseGlobal, |
1822 | SourceLocation Start); |
1823 | |
1824 | |
1825 | |
1826 | struct ForRangeInfo; |
1827 | Sema::ConditionResult ParseCXXCondition(StmtResult *InitStmt, |
1828 | SourceLocation Loc, |
1829 | Sema::ConditionKind CK, |
1830 | ForRangeInfo *FRI = nullptr); |
1831 | |
1832 | |
1833 | |
1834 | |
1835 | ExprResult ParseCoyieldExpression(); |
1836 | |
1837 | |
1838 | |
1839 | |
1840 | |
1841 | |
1842 | |
1843 | |
1844 | ExprResult ParseInitializer() { |
1845 | if (Tok.isNot(tok::l_brace)) |
1846 | return ParseAssignmentExpression(); |
1847 | return ParseBraceInitializer(); |
1848 | } |
1849 | bool MayBeDesignationStart(); |
1850 | ExprResult ParseBraceInitializer(); |
1851 | ExprResult ParseInitializerWithPotentialDesignator(); |
1852 | |
1853 | |
1854 | |
1855 | |
1856 | ExprResult ParseBlockLiteralExpression(); |
1857 | |
1858 | |
1859 | |
1860 | ExprResult ParseObjCAtExpression(SourceLocation AtLocation); |
1861 | ExprResult ParseObjCStringLiteral(SourceLocation AtLoc); |
1862 | ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc); |
1863 | ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc); |
1864 | ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc, bool ArgValue); |
1865 | ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc); |
1866 | ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc); |
1867 | ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc); |
1868 | ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); |
1869 | ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); |
1870 | ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); |
1871 | bool isSimpleObjCMessageExpression(); |
1872 | ExprResult ParseObjCMessageExpression(); |
1873 | ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, |
1874 | SourceLocation SuperLoc, |
1875 | ParsedType ReceiverType, |
1876 | Expr *ReceiverExpr); |
1877 | ExprResult ParseAssignmentExprWithObjCMessageExprStart( |
1878 | SourceLocation LBracloc, SourceLocation SuperLoc, |
1879 | ParsedType ReceiverType, Expr *ReceiverExpr); |
1880 | bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr); |
1881 | |
1882 | |
1883 | |
1884 | |
1885 | |
1886 | |
1887 | typedef SmallVector<Stmt*, 32> StmtVector; |
1888 | |
1889 | typedef SmallVector<Expr*, 12> ExprVector; |
1890 | |
1891 | typedef SmallVector<ParsedType, 12> TypeVector; |
1892 | |
1893 | StmtResult |
1894 | ParseStatement(SourceLocation *TrailingElseLoc = nullptr, |
1895 | ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt); |
1896 | StmtResult ParseStatementOrDeclaration( |
1897 | StmtVector &Stmts, ParsedStmtContext StmtCtx, |
1898 | SourceLocation *TrailingElseLoc = nullptr); |
1899 | StmtResult ParseStatementOrDeclarationAfterAttributes( |
1900 | StmtVector &Stmts, |
1901 | ParsedStmtContext StmtCtx, |
1902 | SourceLocation *TrailingElseLoc, |
1903 | ParsedAttributesWithRange &Attrs); |
1904 | StmtResult ParseExprStatement(ParsedStmtContext StmtCtx); |
1905 | StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs, |
1906 | ParsedStmtContext StmtCtx); |
1907 | StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx, |
1908 | bool MissingCase = false, |
1909 | ExprResult Expr = ExprResult()); |
1910 | StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx); |
1911 | StmtResult ParseCompoundStatement(bool isStmtExpr = false); |
1912 | StmtResult ParseCompoundStatement(bool isStmtExpr, |
1913 | unsigned ScopeFlags); |
1914 | void ParseCompoundStatementLeadingPragmas(); |
1915 | bool (StmtVector &Stmts); |
1916 | StmtResult ParseCompoundStatementBody(bool isStmtExpr = false); |
1917 | bool ParseParenExprOrCondition(StmtResult *InitStmt, |
1918 | Sema::ConditionResult &CondResult, |
1919 | SourceLocation Loc, |
1920 | Sema::ConditionKind CK); |
1921 | StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc); |
1922 | StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc); |
1923 | StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc); |
1924 | StmtResult ParseDoStatement(); |
1925 | StmtResult ParseForStatement(SourceLocation *TrailingElseLoc); |
1926 | StmtResult ParseGotoStatement(); |
1927 | StmtResult ParseContinueStatement(); |
1928 | StmtResult ParseBreakStatement(); |
1929 | StmtResult ParseReturnStatement(); |
1930 | StmtResult ParseAsmStatement(bool &msAsm); |
1931 | StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc); |
1932 | StmtResult ParsePragmaLoopHint(StmtVector &Stmts, |
1933 | ParsedStmtContext StmtCtx, |
1934 | SourceLocation *TrailingElseLoc, |
1935 | ParsedAttributesWithRange &Attrs); |
1936 | |
1937 | |
1938 | |
1939 | enum IfExistsBehavior { |
1940 | |
1941 | IEB_Parse, |
1942 | |
1943 | IEB_Skip, |
1944 | |
1945 | |
1946 | IEB_Dependent |
1947 | }; |
1948 | |
1949 | |
1950 | |
1951 | struct IfExistsCondition { |
1952 | |
1953 | SourceLocation KeywordLoc; |
1954 | |
1955 | |
1956 | bool IsIfExists; |
1957 | |
1958 | |
1959 | CXXScopeSpec SS; |
1960 | |
1961 | |
1962 | UnqualifiedId Name; |
1963 | |
1964 | |
1965 | |
1966 | IfExistsBehavior Behavior; |
1967 | }; |
1968 | |
1969 | bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result); |
1970 | void ParseMicrosoftIfExistsStatement(StmtVector &Stmts); |
1971 | void ParseMicrosoftIfExistsExternalDeclaration(); |
1972 | void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, |
1973 | ParsedAttributes &AccessAttrs, |
1974 | AccessSpecifier &CurAS); |
1975 | bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, |
1976 | bool &InitExprsOk); |
1977 | bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names, |
1978 | SmallVectorImpl<Expr *> &Constraints, |
1979 | SmallVectorImpl<Expr *> &Exprs); |
1980 | |
1981 | |
1982 | |
1983 | |
1984 | StmtResult ParseCXXTryBlock(); |
1985 | StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc, bool FnTry = false); |
1986 | StmtResult ParseCXXCatchBlock(bool FnCatch = false); |
1987 | |
1988 | |
1989 | |
1990 | |
1991 | StmtResult ParseSEHTryBlock(); |
1992 | StmtResult ParseSEHExceptBlock(SourceLocation Loc); |
1993 | StmtResult ParseSEHFinallyBlock(SourceLocation Loc); |
1994 | StmtResult ParseSEHLeaveStatement(); |
1995 | |
1996 | |
1997 | |
1998 | |
1999 | StmtResult ParseObjCAtStatement(SourceLocation atLoc, |
2000 | ParsedStmtContext StmtCtx); |
2001 | StmtResult ParseObjCTryStmt(SourceLocation atLoc); |
2002 | StmtResult ParseObjCThrowStmt(SourceLocation atLoc); |
2003 | StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); |
2004 | StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc); |
2005 | |
2006 | |
2007 | |
2008 | |
2009 | |
2010 | |
2011 | |
2012 | |
2013 | enum class DeclSpecContext { |
2014 | DSC_normal, |
2015 | DSC_class, |
2016 | DSC_type_specifier, |
2017 | DSC_trailing, |
2018 | DSC_alias_declaration, |
2019 | DSC_top_level, |
2020 | DSC_template_param, |
2021 | DSC_template_type_arg, |
2022 | DSC_objc_method_result, |
2023 | DSC_condition |
2024 | }; |
2025 | |
2026 | |
2027 | |
2028 | static bool isTypeSpecifier(DeclSpecContext DSC) { |
2029 | switch (DSC) { |
2030 | case DeclSpecContext::DSC_normal: |
2031 | case DeclSpecContext::DSC_template_param: |
2032 | case DeclSpecContext::DSC_class: |
2033 | case DeclSpecContext::DSC_top_level: |
2034 | case DeclSpecContext::DSC_objc_method_result: |
2035 | case DeclSpecContext::DSC_condition: |
2036 | return false; |
2037 | |
2038 | case DeclSpecContext::DSC_template_type_arg: |
2039 | case DeclSpecContext::DSC_type_specifier: |
2040 | case DeclSpecContext::DSC_trailing: |
2041 | case DeclSpecContext::DSC_alias_declaration: |
2042 | return true; |
2043 | } |
2044 | llvm_unreachable("Missing DeclSpecContext case"); |
2045 | } |
2046 | |
2047 | |
2048 | |
2049 | static bool isClassTemplateDeductionContext(DeclSpecContext DSC) { |
2050 | switch (DSC) { |
2051 | case DeclSpecContext::DSC_normal: |
2052 | case DeclSpecContext::DSC_template_param: |
2053 | case DeclSpecContext::DSC_class: |
2054 | case DeclSpecContext::DSC_top_level: |
2055 | case DeclSpecContext::DSC_condition: |
2056 | case DeclSpecContext::DSC_type_specifier: |
2057 | return true; |
2058 | |
2059 | case DeclSpecContext::DSC_objc_method_result: |
2060 | case DeclSpecContext::DSC_template_type_arg: |
2061 | case DeclSpecContext::DSC_trailing: |
2062 | case DeclSpecContext::DSC_alias_declaration: |
2063 | return false; |
2064 | } |
2065 | llvm_unreachable("Missing DeclSpecContext case"); |
2066 | } |
2067 | |
2068 | |
2069 | |
2070 | struct ForRangeInit { |
2071 | SourceLocation ColonLoc; |
2072 | ExprResult RangeExpr; |
2073 | |
2074 | bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); } |
2075 | }; |
2076 | struct ForRangeInfo : ForRangeInit { |
2077 | StmtResult LoopVar; |
2078 | }; |
2079 | |
2080 | DeclGroupPtrTy ParseDeclaration(DeclaratorContext Context, |
2081 | SourceLocation &DeclEnd, |
2082 | ParsedAttributesWithRange &attrs); |
2083 | DeclGroupPtrTy ParseSimpleDeclaration(DeclaratorContext Context, |
2084 | SourceLocation &DeclEnd, |
2085 | ParsedAttributesWithRange &attrs, |
2086 | bool RequireSemi, |
2087 | ForRangeInit *FRI = nullptr); |
2088 | bool MightBeDeclarator(DeclaratorContext Context); |
2089 | DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, DeclaratorContext Context, |
2090 | SourceLocation *DeclEnd = nullptr, |
2091 | ForRangeInit *FRI = nullptr); |
2092 | Decl *ParseDeclarationAfterDeclarator(Declarator &D, |
2093 | const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); |
2094 | bool ParseAsmAttributesAfterDeclarator(Declarator &D); |
2095 | Decl *ParseDeclarationAfterDeclaratorAndAttributes( |
2096 | Declarator &D, |
2097 | const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), |
2098 | ForRangeInit *FRI = nullptr); |
2099 | Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope); |
2100 | Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope); |
2101 | |
2102 | |
2103 | |
2104 | |
2105 | |
2106 | bool trySkippingFunctionBody(); |
2107 | |
2108 | bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, |
2109 | const ParsedTemplateInfo &TemplateInfo, |
2110 | AccessSpecifier AS, DeclSpecContext DSC, |
2111 | ParsedAttributesWithRange &Attrs); |
2112 | DeclSpecContext |
2113 | getDeclSpecContextFromDeclaratorContext(DeclaratorContext Context); |
2114 | void ParseDeclarationSpecifiers( |
2115 | DeclSpec &DS, |
2116 | const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), |
2117 | AccessSpecifier AS = AS_none, |
2118 | DeclSpecContext DSC = DeclSpecContext::DSC_normal, |
2119 | LateParsedAttrList *LateAttrs = nullptr); |
2120 | bool DiagnoseMissingSemiAfterTagDefinition( |
2121 | DeclSpec &DS, AccessSpecifier AS, DeclSpecContext DSContext, |
2122 | LateParsedAttrList *LateAttrs = nullptr); |
2123 | |
2124 | void ParseSpecifierQualifierList( |
2125 | DeclSpec &DS, AccessSpecifier AS = AS_none, |
2126 | DeclSpecContext DSC = DeclSpecContext::DSC_normal); |
2127 | |
2128 | void ParseObjCTypeQualifierList(ObjCDeclSpec &DS, |
2129 | DeclaratorContext Context); |
2130 | |
2131 | void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, |
2132 | const ParsedTemplateInfo &TemplateInfo, |
2133 | AccessSpecifier AS, DeclSpecContext DSC); |
2134 | void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl); |
2135 | void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, |
2136 | Decl *TagDecl); |
2137 | |
2138 | void ParseStructDeclaration( |
2139 | ParsingDeclSpec &DS, |
2140 | llvm::function_ref<void(ParsingFieldDeclarator &)> FieldsCallback); |
2141 | |
2142 | bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false); |
2143 | bool isTypeSpecifierQualifier(); |
2144 | |
2145 | |
2146 | |
2147 | |
2148 | bool isKnownToBeTypeSpecifier(const Token &Tok) const; |
2149 | |
2150 | |
2151 | |
2152 | |
2153 | bool isKnownToBeDeclarationSpecifier() { |
2154 | if (getLangOpts().CPlusPlus) |
2155 | return isCXXDeclarationSpecifier() == TPResult::True; |
2156 | return isDeclarationSpecifier(true); |
2157 | } |
2158 | |
2159 | |
2160 | |
2161 | |
2162 | bool isDeclarationStatement() { |
2163 | if (getLangOpts().CPlusPlus) |
2164 | return isCXXDeclarationStatement(); |
2165 | return isDeclarationSpecifier(true); |
2166 | } |
2167 | |
2168 | |
2169 | |
2170 | |
2171 | |
2172 | bool isForInitDeclaration() { |
2173 | if (getLangOpts().OpenMP) |
2174 | Actions.startOpenMPLoop(); |
2175 | if (getLangOpts().CPlusPlus) |
2176 | return isCXXSimpleDeclaration(); |
2177 | return isDeclarationSpecifier(true); |
2178 | } |
2179 | |
2180 | |
2181 | bool isForRangeIdentifier(); |
2182 | |
2183 | |
2184 | |
2185 | bool isStartOfObjCClassMessageMissingOpenBracket(); |
2186 | |
2187 | |
2188 | |
2189 | |
2190 | bool isConstructorDeclarator(bool Unqualified, bool DeductionGuide = false); |
2191 | |
2192 | |
2193 | |
2194 | enum TentativeCXXTypeIdContext { |
2195 | TypeIdInParens, |
2196 | TypeIdUnambiguous, |
2197 | TypeIdAsTemplateArgument |
2198 | }; |
2199 | |
2200 | |
2201 | |
2202 | |
2203 | |
2204 | bool isTypeIdInParens(bool &isAmbiguous) { |
2205 | if (getLangOpts().CPlusPlus) |
2206 | return isCXXTypeId(TypeIdInParens, isAmbiguous); |
2207 | isAmbiguous = false; |
2208 | return isTypeSpecifierQualifier(); |
2209 | } |
2210 | bool isTypeIdInParens() { |
2211 | bool isAmbiguous; |
2212 | return isTypeIdInParens(isAmbiguous); |
2213 | } |
2214 | |
2215 | |
2216 | |
2217 | |
2218 | bool isTypeIdUnambiguously() { |
2219 | bool IsAmbiguous; |
2220 | if (getLangOpts().CPlusPlus) |
2221 | return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous); |
2222 | return isTypeSpecifierQualifier(); |
2223 | } |
2224 | |
2225 | |
2226 | |
2227 | |
2228 | bool isCXXDeclarationStatement(); |
2229 | |
2230 | |
2231 | |
2232 | |
2233 | |
2234 | |
2235 | bool isCXXSimpleDeclaration(bool AllowForRangeDecl); |
2236 | |
2237 | |
2238 | |
2239 | |
2240 | |
2241 | |
2242 | |
2243 | |
2244 | bool isCXXFunctionDeclarator(bool *IsAmbiguous = nullptr); |
2245 | |
2246 | struct ConditionDeclarationOrInitStatementState; |
2247 | enum class ConditionOrInitStatement { |
2248 | Expression, |
2249 | ConditionDecl, |
2250 | InitStmtDecl, |
2251 | ForRangeDecl, |
2252 | Error |
2253 | }; |
2254 | |
2255 | |
2256 | |
2257 | ConditionOrInitStatement |
2258 | isCXXConditionDeclarationOrInitStatement(bool CanBeInitStmt, |
2259 | bool CanBeForRangeDecl); |
2260 | |
2261 | bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); |
2262 | bool isCXXTypeId(TentativeCXXTypeIdContext Context) { |
2263 | bool isAmbiguous; |
2264 | return isCXXTypeId(Context, isAmbiguous); |
2265 | } |
2266 | |
2267 | |
2268 | |
2269 | enum class TPResult { |
2270 | True, False, Ambiguous, Error |
2271 | }; |
2272 | |
2273 | |
2274 | |
2275 | |
2276 | |
2277 | |
2278 | |
2279 | |
2280 | |
2281 | |
2282 | |
2283 | TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind); |
2284 | |
2285 | |
2286 | |
2287 | |
2288 | |
2289 | |
2290 | |
2291 | |
2292 | TPResult |
2293 | isCXXDeclarationSpecifier(TPResult BracedCastResult = TPResult::False, |
2294 | bool *HasMissingTypename = nullptr); |
2295 | |
2296 | |
2297 | |
2298 | |
2299 | bool isCXXDeclarationSpecifierAType(); |
2300 | |
2301 | |
2302 | |
2303 | |
2304 | bool isTentativelyDeclared(IdentifierInfo *II); |
2305 | |
2306 | |
2307 | |
2308 | |
2309 | |
2310 | |
2311 | |
2312 | |
2313 | TPResult TryParseSimpleDeclaration(bool AllowForRangeDecl); |
2314 | TPResult TryParseTypeofSpecifier(); |
2315 | TPResult TryParseProtocolQualifiers(); |
2316 | TPResult TryParsePtrOperatorSeq(); |
2317 | TPResult TryParseOperatorId(); |
2318 | TPResult TryParseInitDeclaratorList(); |
2319 | TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier = true, |
2320 | bool mayHaveDirectInit = false); |
2321 | TPResult |
2322 | TryParseParameterDeclarationClause(bool *InvalidAsDeclaration = nullptr, |
2323 | bool VersusTemplateArg = false); |
2324 | TPResult TryParseFunctionDeclarator(); |
2325 | TPResult TryParseBracketDeclarator(); |
2326 | TPResult TryConsumeDeclarationSpecifier(); |
2327 | |
2328 | public: |
2329 | TypeResult ParseTypeName(SourceRange *Range = nullptr, |
2330 | DeclaratorContext Context |
2331 | = DeclaratorContext::TypeNameContext, |
2332 | AccessSpecifier AS = AS_none, |
2333 | Decl **OwnedType = nullptr, |
2334 | ParsedAttributes *Attrs = nullptr); |
2335 | |
2336 | private: |
2337 | void ParseBlockId(SourceLocation CaretLoc); |
2338 | |
2339 | |
2340 | bool standardAttributesAllowed() const { |
2341 | const LangOptions &LO = getLangOpts(); |
2342 | return LO.DoubleSquareBracketAttributes; |
2343 | } |
2344 | |
2345 | |
2346 | |
2347 | bool CheckProhibitedCXX11Attribute() { |
2348 | assert(Tok.is(tok::l_square)); |
2349 | if (!standardAttributesAllowed() || NextToken().isNot(tok::l_square)) |
2350 | return false; |
2351 | return DiagnoseProhibitedCXX11Attribute(); |
2352 | } |
2353 | |
2354 | bool DiagnoseProhibitedCXX11Attribute(); |
2355 | void CheckMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs, |
2356 | SourceLocation CorrectLocation) { |
2357 | if (!standardAttributesAllowed()) |
2358 | return; |
2359 | if ((Tok.isNot(tok::l_square) || NextToken().isNot(tok::l_square)) && |
2360 | Tok.isNot(tok::kw_alignas)) |
2361 | return; |
2362 | DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation); |
2363 | } |
2364 | void DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs, |
2365 | SourceLocation CorrectLocation); |
2366 | |
2367 | void stripTypeAttributesOffDeclSpec(ParsedAttributesWithRange &Attrs, |
2368 | DeclSpec &DS, Sema::TagUseKind TUK); |
2369 | |
2370 | |
2371 | void ProhibitAttributes(ParsedAttributesWithRange &Attrs, |
2372 | SourceLocation FixItLoc = SourceLocation()) { |
2373 | if (Attrs.Range.isInvalid()) |
2374 | return; |
2375 | DiagnoseProhibitedAttributes(Attrs.Range, FixItLoc); |
2376 | Attrs.clear(); |
2377 | } |
2378 | |
2379 | void ProhibitAttributes(ParsedAttributesViewWithRange &Attrs, |
2380 | SourceLocation FixItLoc = SourceLocation()) { |
2381 | if (Attrs.Range.isInvalid()) |
2382 | return; |
2383 | DiagnoseProhibitedAttributes(Attrs.Range, FixItLoc); |
2384 | Attrs.clearListOnly(); |
2385 | } |
2386 | void DiagnoseProhibitedAttributes(const SourceRange &Range, |
2387 | SourceLocation FixItLoc); |
2388 | |
2389 | |
2390 | |
2391 | |
2392 | void ProhibitCXX11Attributes(ParsedAttributesWithRange &Attrs, |
2393 | unsigned DiagID); |
2394 | |
2395 | |
2396 | |
2397 | |
2398 | SourceLocation SkipCXX11Attributes(); |
2399 | |
2400 | |
2401 | |
2402 | void DiagnoseAndSkipCXX11Attributes(); |
2403 | |
2404 | |
2405 | |
2406 | |
2407 | |
2408 | unsigned |
2409 | ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc, |
2410 | ParsedAttributes &Attrs, SourceLocation *EndLoc, |
2411 | IdentifierInfo *ScopeName, SourceLocation ScopeLoc, |
2412 | ParsedAttr::Syntax Syntax); |
2413 | |
2414 | void MaybeParseGNUAttributes(Declarator &D, |
2415 | LateParsedAttrList *LateAttrs = nullptr) { |
2416 | if (Tok.is(tok::kw___attribute)) { |
2417 | ParsedAttributes attrs(AttrFactory); |
2418 | SourceLocation endLoc; |
2419 | ParseGNUAttributes(attrs, &endLoc, LateAttrs, &D); |
2420 | D.takeAttributes(attrs, endLoc); |
2421 | } |
2422 | } |
2423 | void MaybeParseGNUAttributes(ParsedAttributes &attrs, |
2424 | SourceLocation *endLoc = nullptr, |
2425 | LateParsedAttrList *LateAttrs = nullptr) { |
2426 | if (Tok.is(tok::kw___attribute)) |
2427 | ParseGNUAttributes(attrs, endLoc, LateAttrs); |
2428 | } |
2429 | void ParseGNUAttributes(ParsedAttributes &attrs, |
2430 | SourceLocation *endLoc = nullptr, |
2431 | LateParsedAttrList *LateAttrs = nullptr, |
2432 | Declarator *D = nullptr); |
2433 | void ParseGNUAttributeArgs(IdentifierInfo *AttrName, |
2434 | SourceLocation AttrNameLoc, |
2435 | ParsedAttributes &Attrs, SourceLocation *EndLoc, |
2436 | IdentifierInfo *ScopeName, SourceLocation ScopeLoc, |
2437 | ParsedAttr::Syntax Syntax, Declarator *D); |
2438 | IdentifierLoc *ParseIdentifierLoc(); |
2439 | |
2440 | unsigned |
2441 | ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc, |
2442 | ParsedAttributes &Attrs, SourceLocation *EndLoc, |
2443 | IdentifierInfo *ScopeName, SourceLocation ScopeLoc, |
2444 | ParsedAttr::Syntax Syntax); |
2445 | |
2446 | void MaybeParseCXX11Attributes(Declarator &D) { |
2447 | if (standardAttributesAllowed() && isCXX11AttributeSpecifier()) { |
2448 | ParsedAttributesWithRange attrs(AttrFactory); |
2449 | SourceLocation endLoc; |
2450 | ParseCXX11Attributes(attrs, &endLoc); |
2451 | D.takeAttributes(attrs, endLoc); |
2452 | } |
2453 | } |
2454 | void MaybeParseCXX11Attributes(ParsedAttributes &attrs, |
2455 | SourceLocation *endLoc = nullptr) { |
2456 | if (standardAttributesAllowed() && isCXX11AttributeSpecifier()) { |
2457 | ParsedAttributesWithRange attrsWithRange(AttrFactory); |
2458 | ParseCXX11Attributes(attrsWithRange, endLoc); |
2459 | attrs.takeAllFrom(attrsWithRange); |
2460 | } |
2461 | } |
2462 | void MaybeParseCXX11Attributes(ParsedAttributesWithRange &attrs, |
2463 | SourceLocation *endLoc = nullptr, |
2464 | bool OuterMightBeMessageSend = false) { |
2465 | if (standardAttributesAllowed() && |
2466 | isCXX11AttributeSpecifier(false, OuterMightBeMessageSend)) |
2467 | ParseCXX11Attributes(attrs, endLoc); |
2468 | } |
2469 | |
2470 | void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs, |
2471 | SourceLocation *EndLoc = nullptr); |
2472 | void ParseCXX11Attributes(ParsedAttributesWithRange &attrs, |
2473 | SourceLocation *EndLoc = nullptr); |
2474 | |
2475 | |
2476 | bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName, |
2477 | SourceLocation AttrNameLoc, |
2478 | ParsedAttributes &Attrs, SourceLocation *EndLoc, |
2479 | IdentifierInfo *ScopeName, |
2480 | SourceLocation ScopeLoc); |
2481 | |
2482 | IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc); |
2483 | |
2484 | void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs, |
2485 | SourceLocation *endLoc = nullptr) { |
2486 | if (getLangOpts().MicrosoftExt && Tok.is(tok::l_square)) |
2487 | ParseMicrosoftAttributes(attrs, endLoc); |
2488 | } |
2489 | void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs); |
2490 | void ParseMicrosoftAttributes(ParsedAttributes &attrs, |
2491 | SourceLocation *endLoc = nullptr); |
2492 | void MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs, |
2493 | SourceLocation *End = nullptr) { |
2494 | const auto &LO = getLangOpts(); |
2495 | if (LO.DeclSpecKeyword && Tok.is(tok::kw___declspec)) |
2496 | ParseMicrosoftDeclSpecs(Attrs, End); |
2497 | } |
2498 | void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs, |
2499 | SourceLocation *End = nullptr); |
2500 | bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName, |
2501 | SourceLocation AttrNameLoc, |
2502 | ParsedAttributes &Attrs); |
2503 | void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs); |
2504 | void DiagnoseAndSkipExtendedMicrosoftTypeAttributes(); |
2505 | SourceLocation SkipExtendedMicrosoftTypeAttributes(); |
2506 | void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs); |
2507 | void ParseBorlandTypeAttributes(ParsedAttributes &attrs); |
2508 | void ParseOpenCLKernelAttributes(ParsedAttributes &attrs); |
2509 | void ParseOpenCLQualifiers(ParsedAttributes &Attrs); |
2510 | |
2511 | |
2512 | |
2513 | bool MaybeParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs) { |
2514 | if (getLangOpts().OpenCL) |
2515 | return ParseOpenCLUnrollHintAttribute(Attrs); |
2516 | return true; |
2517 | } |
2518 | |
2519 | |
2520 | bool ParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs); |
2521 | void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs); |
2522 | |
2523 | VersionTuple ParseVersionTuple(SourceRange &Range); |
2524 | void ParseAvailabilityAttribute(IdentifierInfo &Availability, |
2525 | SourceLocation AvailabilityLoc, |
2526 | ParsedAttributes &attrs, |
2527 | SourceLocation *endLoc, |
2528 | IdentifierInfo *ScopeName, |
2529 | SourceLocation ScopeLoc, |
2530 | ParsedAttr::Syntax Syntax); |
2531 | |
2532 | Optional<AvailabilitySpec> ParseAvailabilitySpec(); |
2533 | ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc); |
2534 | |
2535 | void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol, |
2536 | SourceLocation Loc, |
2537 | ParsedAttributes &Attrs, |
2538 | SourceLocation *EndLoc, |
2539 | IdentifierInfo *ScopeName, |
2540 | SourceLocation ScopeLoc, |
2541 | ParsedAttr::Syntax Syntax); |
2542 | |
2543 | void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated, |
2544 | SourceLocation ObjCBridgeRelatedLoc, |
2545 | ParsedAttributes &attrs, |
2546 | SourceLocation *endLoc, |
2547 | IdentifierInfo *ScopeName, |
2548 | SourceLocation ScopeLoc, |
2549 | ParsedAttr::Syntax Syntax); |
2550 | |
2551 | void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName, |
2552 | SourceLocation AttrNameLoc, |
2553 | ParsedAttributes &Attrs, |
2554 | SourceLocation *EndLoc, |
2555 | IdentifierInfo *ScopeName, |
2556 | SourceLocation ScopeLoc, |
2557 | ParsedAttr::Syntax Syntax); |
2558 | |
2559 | void |
2560 | ParseAttributeWithTypeArg(IdentifierInfo &AttrName, |
2561 | SourceLocation AttrNameLoc, ParsedAttributes &Attrs, |
2562 | SourceLocation *EndLoc, IdentifierInfo *ScopeName, |
2563 | SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax); |
2564 | |
2565 | void ParseTypeofSpecifier(DeclSpec &DS); |
2566 | SourceLocation ParseDecltypeSpecifier(DeclSpec &DS); |
2567 | void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS, |
2568 | SourceLocation StartLoc, |
2569 | SourceLocation EndLoc); |
2570 | void ParseUnderlyingTypeSpecifier(DeclSpec &DS); |
2571 | void ParseAtomicSpecifier(DeclSpec &DS); |
2572 | |
2573 | ExprResult ParseAlignArgument(SourceLocation Start, |
2574 | SourceLocation &EllipsisLoc); |
2575 | void ParseAlignmentSpecifier(ParsedAttributes &Attrs, |
2576 | SourceLocation *endLoc = nullptr); |
2577 | |
2578 | VirtSpecifiers::Specifier isCXX11VirtSpecifier(const Token &Tok) const; |
2579 | VirtSpecifiers::Specifier isCXX11VirtSpecifier() const { |
2580 | return isCXX11VirtSpecifier(Tok); |
2581 | } |
2582 | void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, bool IsInterface, |
2583 | SourceLocation FriendLoc); |
2584 | |
2585 | bool isCXX11FinalKeyword() const; |
2586 | |
2587 | |
2588 | |
2589 | |
2590 | class DeclaratorScopeObj { |
2591 | Parser &P; |
2592 | CXXScopeSpec &SS; |
2593 | bool EnteredScope; |
2594 | bool CreatedScope; |
2595 | public: |
2596 | DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) |
2597 | : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} |
2598 | |
2599 | void EnterDeclaratorScope() { |
2600 | (0) . __assert_fail ("!EnteredScope && \"Already entered the scope!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 2600, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!EnteredScope && "Already entered the scope!"); |
2601 | (0) . __assert_fail ("SS.isSet() && \"C++ scope was not set!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 2601, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(SS.isSet() && "C++ scope was not set!"); |
2602 | |
2603 | CreatedScope = true; |
2604 | P.EnterScope(0); |
2605 | |
2606 | if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS)) |
2607 | EnteredScope = true; |
2608 | } |
2609 | |
2610 | ~DeclaratorScopeObj() { |
2611 | if (EnteredScope) { |
2612 | (0) . __assert_fail ("SS.isSet() && \"C++ scope was cleared ?\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Parse/Parser.h", 2612, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(SS.isSet() && "C++ scope was cleared ?"); |
2613 | P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS); |
2614 | } |
2615 | if (CreatedScope) |
2616 | P.ExitScope(); |
2617 | } |
2618 | }; |
2619 | |
2620 | |
2621 | void ParseDeclarator(Declarator &D); |
2622 | |
2623 | typedef void (Parser::*DirectDeclParseFunction)(Declarator&); |
2624 | void ParseDeclaratorInternal(Declarator &D, |
2625 | DirectDeclParseFunction DirectDeclParser); |
2626 | |
2627 | enum AttrRequirements { |
2628 | AR_NoAttributesParsed = 0, |
2629 | AR_GNUAttributesParsedAndRejected = 1 << 0, |
2630 | AR_GNUAttributesParsed = 1 << 1, |
2631 | AR_CXX11AttributesParsed = 1 << 2, |
2632 | AR_DeclspecAttributesParsed = 1 << 3, |
2633 | AR_AllAttributesParsed = AR_GNUAttributesParsed | |
2634 | AR_CXX11AttributesParsed | |
2635 | AR_DeclspecAttributesParsed, |
2636 | AR_VendorAttributesParsed = AR_GNUAttributesParsed | |
2637 | AR_DeclspecAttributesParsed |
2638 | }; |
2639 | |
2640 | void ParseTypeQualifierListOpt( |
2641 | DeclSpec &DS, unsigned AttrReqs = AR_AllAttributesParsed, |
2642 | bool AtomicAllowed = true, bool IdentifierRequired = false, |
2643 | Optional<llvm::function_ref<void()>> CodeCompletionHandler = None); |
2644 | void ParseDirectDeclarator(Declarator &D); |
2645 | void ParseDecompositionDeclarator(Declarator &D); |
2646 | void ParseParenDeclarator(Declarator &D); |
2647 | void ParseFunctionDeclarator(Declarator &D, |
2648 | ParsedAttributes &attrs, |
2649 | BalancedDelimiterTracker &Tracker, |
2650 | bool IsAmbiguous, |
2651 | bool RequiresArg = false); |
2652 | bool ParseRefQualifier(bool &RefQualifierIsLValueRef, |
2653 | SourceLocation &RefQualifierLoc); |
2654 | bool isFunctionDeclaratorIdentifierList(); |
2655 | void ParseFunctionDeclaratorIdentifierList( |
2656 | Declarator &D, |
2657 | SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo); |
2658 | void ParseParameterDeclarationClause( |
2659 | Declarator &D, |
2660 | ParsedAttributes &attrs, |
2661 | SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo, |
2662 | SourceLocation &EllipsisLoc); |
2663 | void ParseBracketDeclarator(Declarator &D); |
2664 | void ParseMisplacedBracketDeclarator(Declarator &D); |
2665 | |
2666 | |
2667 | |
2668 | |
2669 | |
2670 | enum CXX11AttributeKind { |
2671 | |
2672 | CAK_NotAttributeSpecifier, |
2673 | |
2674 | CAK_AttributeSpecifier, |
2675 | |
2676 | |
2677 | CAK_InvalidAttributeSpecifier |
2678 | }; |
2679 | CXX11AttributeKind |
2680 | isCXX11AttributeSpecifier(bool Disambiguate = false, |
2681 | bool OuterMightBeMessageSend = false); |
2682 | |
2683 | void DiagnoseUnexpectedNamespace(NamedDecl *Context); |
2684 | |
2685 | DeclGroupPtrTy ParseNamespace(DeclaratorContext Context, |
2686 | SourceLocation &DeclEnd, |
2687 | SourceLocation InlineLoc = SourceLocation()); |
2688 | |
2689 | struct InnerNamespaceInfo { |
2690 | SourceLocation NamespaceLoc; |
2691 | SourceLocation InlineLoc; |
2692 | SourceLocation IdentLoc; |
2693 | IdentifierInfo *Ident; |
2694 | }; |
2695 | using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>; |
2696 | |
2697 | void ParseInnerNamespace(const InnerNamespaceInfoList &InnerNSs, |
2698 | unsigned int index, SourceLocation &InlineLoc, |
2699 | ParsedAttributes &attrs, |
2700 | BalancedDelimiterTracker &Tracker); |
2701 | Decl *ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context); |
2702 | Decl *ParseExportDeclaration(); |
2703 | DeclGroupPtrTy ParseUsingDirectiveOrDeclaration( |
2704 | DeclaratorContext Context, const ParsedTemplateInfo &TemplateInfo, |
2705 | SourceLocation &DeclEnd, ParsedAttributesWithRange &attrs); |
2706 | Decl *ParseUsingDirective(DeclaratorContext Context, |
2707 | SourceLocation UsingLoc, |
2708 | SourceLocation &DeclEnd, |
2709 | ParsedAttributes &attrs); |
2710 | |
2711 | struct UsingDeclarator { |
2712 | SourceLocation TypenameLoc; |
2713 | CXXScopeSpec SS; |
2714 | UnqualifiedId Name; |
2715 | SourceLocation EllipsisLoc; |
2716 | |
2717 | void clear() { |
2718 | TypenameLoc = EllipsisLoc = SourceLocation(); |
2719 | SS.clear(); |
2720 | Name.clear(); |
2721 | } |
2722 | }; |
2723 | |
2724 | bool ParseUsingDeclarator(DeclaratorContext Context, UsingDeclarator &D); |
2725 | DeclGroupPtrTy ParseUsingDeclaration(DeclaratorContext Context, |
2726 | const ParsedTemplateInfo &TemplateInfo, |
2727 | SourceLocation UsingLoc, |
2728 | SourceLocation &DeclEnd, |
2729 | AccessSpecifier AS = AS_none); |
2730 | Decl *ParseAliasDeclarationAfterDeclarator( |
2731 | const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc, |
2732 | UsingDeclarator &D, SourceLocation &DeclEnd, AccessSpecifier AS, |
2733 | ParsedAttributes &Attrs, Decl **OwnedType = nullptr); |
2734 | |
2735 | Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd); |
2736 | Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc, |
2737 | SourceLocation AliasLoc, IdentifierInfo *Alias, |
2738 | SourceLocation &DeclEnd); |
2739 | |
2740 | |
2741 | |
2742 | bool isValidAfterTypeSpecifier(bool CouldBeBitfield); |
2743 | void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, |
2744 | DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo, |
2745 | AccessSpecifier AS, bool EnteringContext, |
2746 | DeclSpecContext DSC, |
2747 | ParsedAttributesWithRange &Attributes); |
2748 | void SkipCXXMemberSpecification(SourceLocation StartLoc, |
2749 | SourceLocation AttrFixitLoc, |
2750 | unsigned TagType, |
2751 | Decl *TagDecl); |
2752 | void ParseCXXMemberSpecification(SourceLocation StartLoc, |
2753 | SourceLocation AttrFixitLoc, |
2754 | ParsedAttributesWithRange &Attrs, |
2755 | unsigned TagType, |
2756 | Decl *TagDecl); |
2757 | ExprResult ParseCXXMemberInitializer(Decl *D, bool IsFunction, |
2758 | SourceLocation &EqualLoc); |
2759 | bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo, |
2760 | VirtSpecifiers &VS, |
2761 | ExprResult &BitfieldSize, |
2762 | LateParsedAttrList &LateAttrs); |
2763 | void MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D, |
2764 | VirtSpecifiers &VS); |
2765 | DeclGroupPtrTy ParseCXXClassMemberDeclaration( |
2766 | AccessSpecifier AS, ParsedAttributes &Attr, |
2767 | const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), |
2768 | ParsingDeclRAIIObject *DiagsFromTParams = nullptr); |
2769 | DeclGroupPtrTy ParseCXXClassMemberDeclarationWithPragmas( |
2770 | AccessSpecifier &AS, ParsedAttributesWithRange &AccessAttrs, |
2771 | DeclSpec::TST TagType, Decl *Tag); |
2772 | void ParseConstructorInitializer(Decl *ConstructorDecl); |
2773 | MemInitResult ParseMemInitializer(Decl *ConstructorDecl); |
2774 | void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo, |
2775 | Decl *ThisDecl); |
2776 | |
2777 | |
2778 | |
2779 | TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc, |
2780 | SourceLocation &EndLocation); |
2781 | void ParseBaseClause(Decl *ClassDecl); |
2782 | BaseResult ParseBaseSpecifier(Decl *ClassDecl); |
2783 | AccessSpecifier getAccessSpecifierIfPresent() const; |
2784 | |
2785 | bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, |
2786 | SourceLocation TemplateKWLoc, |
2787 | IdentifierInfo *Name, |
2788 | SourceLocation NameLoc, |
2789 | bool EnteringContext, |
2790 | ParsedType ObjectType, |
2791 | UnqualifiedId &Id, |
2792 | bool AssumeTemplateId); |
2793 | bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, |
2794 | ParsedType ObjectType, |
2795 | UnqualifiedId &Result); |
2796 | |
2797 | |
2798 | |
2799 | |
2800 | DeclGroupPtrTy ParseOMPDeclareSimdClauses(DeclGroupPtrTy Ptr, |
2801 | CachedTokens &Toks, |
2802 | SourceLocation Loc); |
2803 | |
2804 | DeclGroupPtrTy ParseOMPDeclareTargetClauses(); |
2805 | |
2806 | void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind DKind, |
2807 | SourceLocation Loc); |
2808 | |
2809 | DeclGroupPtrTy ParseOpenMPDeclarativeDirectiveWithExtDecl( |
2810 | AccessSpecifier &AS, ParsedAttributesWithRange &Attrs, |
2811 | DeclSpec::TST TagType = DeclSpec::TST_unspecified, |
2812 | Decl *TagDecl = nullptr); |
2813 | |
2814 | DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS); |
2815 | |
2816 | |
2817 | void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm); |
2818 | |
2819 | |
2820 | DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS); |
2821 | |
2822 | TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range, |
2823 | DeclarationName &Name, |
2824 | AccessSpecifier AS = AS_none); |
2825 | |
2826 | |
2827 | |
2828 | |
2829 | |
2830 | |
2831 | |
2832 | |
2833 | bool ParseOpenMPSimpleVarList( |
2834 | OpenMPDirectiveKind Kind, |
2835 | const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)> & |
2836 | Callback, |
2837 | bool AllowScopeSpecifier); |
2838 | |
2839 | |
2840 | |
2841 | StmtResult |
2842 | ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx); |
2843 | |
2844 | |
2845 | |
2846 | |
2847 | |
2848 | |
2849 | |
2850 | OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind, |
2851 | OpenMPClauseKind CKind, bool FirstClause); |
2852 | |
2853 | |
2854 | |
2855 | |
2856 | |
2857 | |
2858 | OMPClause *ParseOpenMPSingleExprClause(OpenMPClauseKind Kind, |
2859 | bool ParseOnly); |
2860 | |
2861 | |
2862 | |
2863 | |
2864 | |
2865 | |
2866 | OMPClause *ParseOpenMPSimpleClause(OpenMPClauseKind Kind, bool ParseOnly); |
2867 | |
2868 | |
2869 | |
2870 | |
2871 | |
2872 | |
2873 | |
2874 | OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind, |
2875 | bool ParseOnly); |
2876 | |
2877 | |
2878 | |
2879 | |
2880 | |
2881 | |
2882 | OMPClause *ParseOpenMPClause(OpenMPClauseKind Kind, bool ParseOnly = false); |
2883 | |
2884 | |
2885 | |
2886 | |
2887 | |
2888 | |
2889 | OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, |
2890 | OpenMPClauseKind Kind, bool ParseOnly); |
2891 | |
2892 | public: |
2893 | |
2894 | |
2895 | |
2896 | ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc); |
2897 | |
2898 | |
2899 | struct OpenMPVarListDataTy { |
2900 | Expr *TailExpr = nullptr; |
2901 | SourceLocation ColonLoc; |
2902 | SourceLocation RLoc; |
2903 | CXXScopeSpec ReductionOrMapperIdScopeSpec; |
2904 | DeclarationNameInfo ReductionOrMapperId; |
2905 | OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown; |
2906 | OpenMPLinearClauseKind LinKind = OMPC_LINEAR_val; |
2907 | SmallVector<OpenMPMapModifierKind, OMPMapClause::NumberOfModifiers> |
2908 | MapTypeModifiers; |
2909 | SmallVector<SourceLocation, OMPMapClause::NumberOfModifiers> |
2910 | MapTypeModifiersLoc; |
2911 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown; |
2912 | bool IsMapTypeImplicit = false; |
2913 | SourceLocation DepLinMapLoc; |
2914 | }; |
2915 | |
2916 | |
2917 | bool ParseOpenMPVarList(OpenMPDirectiveKind DKind, OpenMPClauseKind Kind, |
2918 | SmallVectorImpl<Expr *> &Vars, |
2919 | OpenMPVarListDataTy &Data); |
2920 | bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, |
2921 | bool AllowDestructorName, |
2922 | bool AllowConstructorName, |
2923 | bool AllowDeductionGuide, |
2924 | ParsedType ObjectType, |
2925 | SourceLocation *TemplateKWLoc, |
2926 | UnqualifiedId &Result); |
2927 | |
2928 | bool parseMapperModifier(OpenMPVarListDataTy &Data); |
2929 | |
2930 | |
2931 | |
2932 | bool parseMapTypeModifiers(OpenMPVarListDataTy &Data); |
2933 | |
2934 | private: |
2935 | |
2936 | |
2937 | |
2938 | |
2939 | Decl *ParseDeclarationStartingWithTemplate(DeclaratorContext Context, |
2940 | SourceLocation &DeclEnd, |
2941 | ParsedAttributes &AccessAttrs, |
2942 | AccessSpecifier AS = AS_none); |
2943 | Decl *ParseTemplateDeclarationOrSpecialization(DeclaratorContext Context, |
2944 | SourceLocation &DeclEnd, |
2945 | ParsedAttributes &AccessAttrs, |
2946 | AccessSpecifier AS); |
2947 | Decl *ParseSingleDeclarationAfterTemplate( |
2948 | DeclaratorContext Context, const ParsedTemplateInfo &TemplateInfo, |
2949 | ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd, |
2950 | ParsedAttributes &AccessAttrs, AccessSpecifier AS = AS_none); |
2951 | bool ParseTemplateParameters(unsigned Depth, |
2952 | SmallVectorImpl<NamedDecl *> &TemplateParams, |
2953 | SourceLocation &LAngleLoc, |
2954 | SourceLocation &RAngleLoc); |
2955 | bool ParseTemplateParameterList(unsigned Depth, |
2956 | SmallVectorImpl<NamedDecl*> &TemplateParams); |
2957 | bool isStartOfTemplateTypeParameter(); |
2958 | NamedDecl *ParseTemplateParameter(unsigned Depth, unsigned Position); |
2959 | NamedDecl *ParseTypeParameter(unsigned Depth, unsigned Position); |
2960 | NamedDecl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); |
2961 | NamedDecl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); |
2962 | void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc, |
2963 | SourceLocation CorrectLoc, |
2964 | bool AlreadyHasEllipsis, |
2965 | bool IdentifierHasName); |
2966 | void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc, |
2967 | Declarator &D); |
2968 | |
2969 | typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList; |
2970 | |
2971 | bool ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc, |
2972 | bool ConsumeLastToken, |
2973 | bool ObjCGenericList); |
2974 | bool ParseTemplateIdAfterTemplateName(bool ConsumeLastToken, |
2975 | SourceLocation &LAngleLoc, |
2976 | TemplateArgList &TemplateArgs, |
2977 | SourceLocation &RAngleLoc); |
2978 | |
2979 | bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, |
2980 | CXXScopeSpec &SS, |
2981 | SourceLocation TemplateKWLoc, |
2982 | UnqualifiedId &TemplateName, |
2983 | bool AllowTypeAnnotation = true); |
2984 | void AnnotateTemplateIdTokenAsType(bool IsClassName = false); |
2985 | bool IsTemplateArgumentList(unsigned Skip = 0); |
2986 | bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); |
2987 | ParsedTemplateArgument ParseTemplateTemplateArgument(); |
2988 | ParsedTemplateArgument ParseTemplateArgument(); |
2989 | Decl *ParseExplicitInstantiation(DeclaratorContext Context, |
2990 | SourceLocation ExternLoc, |
2991 | SourceLocation TemplateLoc, |
2992 | SourceLocation &DeclEnd, |
2993 | ParsedAttributes &AccessAttrs, |
2994 | AccessSpecifier AS = AS_none); |
2995 | |
2996 | |
2997 | |
2998 | DeclGroupPtrTy ParseModuleDecl(); |
2999 | Decl *ParseModuleImport(SourceLocation AtLoc); |
3000 | bool parseMisplacedModuleImport(); |
3001 | bool tryParseMisplacedModuleImport() { |
3002 | tok::TokenKind Kind = Tok.getKind(); |
3003 | if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end || |
3004 | Kind == tok::annot_module_include) |
3005 | return parseMisplacedModuleImport(); |
3006 | return false; |
3007 | } |
3008 | |
3009 | bool ParseModuleName( |
3010 | SourceLocation UseLoc, |
3011 | SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path, |
3012 | bool IsImport); |
3013 | |
3014 | |
3015 | |
3016 | ExprResult ParseTypeTrait(); |
3017 | |
3018 | |
3019 | |
3020 | ExprResult ParseArrayTypeTrait(); |
3021 | ExprResult ParseExpressionTrait(); |
3022 | |
3023 | |
3024 | |
3025 | void CodeCompleteDirective(bool InConditional) override; |
3026 | void CodeCompleteInConditionalExclusion() override; |
3027 | void CodeCompleteMacroName(bool IsDefinition) override; |
3028 | void CodeCompletePreprocessorExpression() override; |
3029 | void CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo, |
3030 | unsigned ArgumentIndex) override; |
3031 | void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled) override; |
3032 | void CodeCompleteNaturalLanguage() override; |
3033 | }; |
3034 | |
3035 | } |
3036 | |
3037 | #endif |
3038 | |