15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Parser.h - C Language Parser ---------------------------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Parser interface. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_PARSE_PARSER_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_PARSE_PARSER_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#include "clang/Basic/OpenMPKinds.h" 18909610266e67ce40a9d8a4df8be81b3de999b120Daniel Jasper#include "clang/Basic/OperatorPrecedence.h" 19ad2b804faf29042e6c4e331d0987f103f1e2fd31John McCall#include "clang/Basic/Specifiers.h" 20f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor#include "clang/Lex/CodeCompletionHandler.h" 2130a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Lex/Preprocessor.h" 2219510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h" 23ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#include "clang/Sema/LoopHint.h" 2430a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Sema/Sema.h" 25eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski#include "llvm/ADT/SmallVector.h" 26aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 27aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/PrettyStackTrace.h" 2894f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose#include "llvm/Support/SaveAndRestore.h" 29651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include <memory> 304cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis#include <stack> 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 33fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar class PragmaHandler; 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Scope; 35c86c40b912e53fb11ff8f745ed616035b8b7259cDouglas Gregor class BalancedDelimiterTracker; 360576681bac125be07f77f66b02a3dba2c3a24557Richard Smith class CorrectionCandidateCallback; 372b5289b6fd7e3d9899868410a498c081c9595662John McCall class DeclGroupRef; 383cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner class DiagnosticBuilder; 390102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner class Parser; 409257664568bf375b7790131a84d9a4fa30a5b7e3John McCall class ParsingDeclRAIIObject; 419257664568bf375b7790131a84d9a4fa30a5b7e3John McCall class ParsingDeclSpec; 429257664568bf375b7790131a84d9a4fa30a5b7e3John McCall class ParsingDeclarator; 43f66a0dda541cd859a928193efba6dc5d7ba8fe54Eli Friedman class ParsingFieldDeclarator; 4408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner class ColonProtectionRAIIObject; 450fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor class InMessageExpressionRAIIObject; 4628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley class PoisonSEHIdentifiersRAIIObject; 470a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor class VersionTuple; 484fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev class OMPClause; 49a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Parser - This implements a parser for the C family of languages. After 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// parsing units of the grammar, productions are invoked to handle whatever has 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// been read. 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 54f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregorclass Parser : public CodeCompletionHandler { 5508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner friend class ColonProtectionRAIIObject; 560fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor friend class InMessageExpressionRAIIObject; 5728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley friend class PoisonSEHIdentifiersRAIIObject; 5894f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose friend class ObjCDeclContextSwitch; 5936d36806f1972f7ec1d2a3f59155187278c56508Argyrios Kyrtzidis friend class ParenBraceBracketBalancer; 60c86c40b912e53fb11ff8f745ed616035b8b7259cDouglas Gregor friend class BalancedDelimiterTracker; 611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Preprocessor &PP; 631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6497d0205d16fef2a783e785459b5f30f6a9dfbcb9Eric Christopher /// Tok - The current token we are peeking ahead. All parsing methods assume 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that this is valid. 66d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner Token Tok; 671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 684b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // PrevTokLocation - The location of the token we previously 694b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // consumed. This token is used for diagnostics where we expected to 704b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // see a token following another token (e.g., the ';' at the end of 714b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // a statement). 724b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceLocation PrevTokLocation; 734b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned short ParenCount, BracketCount, BraceCount; 75651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Actions - These are the callbacks we invoke as we parse various constructs 77a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// in the file. 78f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &Actions; 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 80d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine &Diags; 811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 829e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner /// ScopeCache - Cache scopes to reduce malloc traffic. 839e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner enum { ScopeCacheSize = 16 }; 849e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner unsigned NumCachedScopes; 859e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner Scope *ScopeCache[ScopeCacheSize]; 86662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 8728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley /// Identifiers used for SEH handling in Borland. These are only 8828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley /// allowed in particular circumstances 89a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie // __except block 90a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie IdentifierInfo *Ident__exception_code, 91a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident___exception_code, 92a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident_GetExceptionCode; 93a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie // __except filter expression 94a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie IdentifierInfo *Ident__exception_info, 95a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident___exception_info, 96a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident_GetExceptionInfo; 97a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie // __finally 98a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie IdentifierInfo *Ident__abnormal_termination, 99a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident___abnormal_termination, 100a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident_AbnormalTermination; 10128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 102b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor /// Contextual keywords for Microsoft extensions. 103b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor IdentifierInfo *Ident__except; 1047121bdb91b86f6053765bda18dd0a8a118929aceDavid Majnemer mutable IdentifierInfo *Ident_sealed; 105a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 106662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// Ident_super - IdentifierInfo for "super", to support fast 107662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// comparison. 108662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar IdentifierInfo *Ident_super; 1093e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt /// Ident_vector, Ident_pixel, Ident_bool - cached IdentifierInfo's 1103e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt /// for "vector", "pixel", and "bool" fast comparison. Only present 1113e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt /// if AltiVec enabled. 11282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_vector; 11382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_pixel; 1143e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt IdentifierInfo *Ident_bool; 115662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 116e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor /// Objective-C contextual keywords. 117e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor mutable IdentifierInfo *Ident_instancetype; 118a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1190a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "introduced". 1200a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_introduced; 1210a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 1220a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "deprecated". 1230a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_deprecated; 1240a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 1250a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "obsoleted". 1260a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_obsoleted; 1270a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 128b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor /// \brief Identifier for "unavailable". 129b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor IdentifierInfo *Ident_unavailable; 130006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian 131006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian /// \brief Identifier for "message". 132006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian IdentifierInfo *Ident_message; 133b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor 134a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// C++0x contextual keywords. 1357eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson mutable IdentifierInfo *Ident_final; 1367eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson mutable IdentifierInfo *Ident_override; 1371f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 138651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // Some token kinds such as C++ type traits can be reverted to identifiers and 139651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // still get used as keywords depending on context. 140651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines llvm::SmallDenseMap<const IdentifierInfo *, tok::TokenKind> 141651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ContextualKeywords; 142651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 143651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> AlignHandler; 144651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> GCCVisibilityHandler; 145651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> OptionsHandler; 146651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> PackHandler; 147651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> MSStructHandler; 148651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> UnusedHandler; 149651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> WeakHandler; 150651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> RedefineExtnameHandler; 151651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> FPContractHandler; 152651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> OpenCLExtensionHandler; 153651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> OpenMPHandler; 154651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> MSCommentHandler; 155651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> MSDetectMismatchHandler; 156651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> MSPointersToMembers; 157651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<PragmaHandler> MSVtorDisp; 1586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines std::unique_ptr<PragmaHandler> MSInitSeg; 1596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines std::unique_ptr<PragmaHandler> MSDataSeg; 1606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines std::unique_ptr<PragmaHandler> MSBSSSeg; 1616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines std::unique_ptr<PragmaHandler> MSConstSeg; 1626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines std::unique_ptr<PragmaHandler> MSCodeSeg; 1636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines std::unique_ptr<PragmaHandler> MSSection; 1646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines std::unique_ptr<PragmaHandler> OptimizeHandler; 165ef8225444452a1486bd721f3285301fe84643b00Stephen Hines std::unique_ptr<PragmaHandler> LoopHintHandler; 166651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 167651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<CommentHandler> CommentSemaHandler; 1681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// Whether the '>' token acts as an operator or not. This will be 17055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// true except when we are parsing an expression within a C++ 17155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// template argument list, where the '>' closes the template 17255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// argument list. 17355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor bool GreaterThanIsOperator; 174a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 17508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonIsSacred - When this is false, we aggressively try to recover from 17608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not 17708d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// safe in case statements and a few other things. This is managed by the 17808d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonProtectionRAIIObject RAII object. 17908d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner bool ColonIsSacred; 18055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 181651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief When true, we are directly inside an Objective-C message 1820fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// send expression. 1830fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// 1840fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// This is managed by the \c InMessageExpressionRAIIObject class, and 1850fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// should not be set directly. 1860fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor bool InMessageExpression; 187a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 188c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor /// The "depth" of the template parameters currently being parsed. 189c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor unsigned TemplateParameterDepth; 190a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 191098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith /// \brief RAII class that manages the template parameter depth. 192098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith class TemplateParameterDepthRAII { 193098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith unsigned &Depth; 194098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith unsigned AddedLevels; 195098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith public: 196098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith explicit TemplateParameterDepthRAII(unsigned &Depth) 197098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith : Depth(Depth), AddedLevels(0) {} 198098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith 199098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith ~TemplateParameterDepthRAII() { 200098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith Depth -= AddedLevels; 201098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith } 202098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith 203098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith void operator++() { 204098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith ++Depth; 205098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith ++AddedLevels; 206098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith } 207651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void addDepth(unsigned D) { 208651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Depth += D; 209651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines AddedLevels += D; 210651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 211098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith unsigned getDepth() const { return Depth; } 212098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith }; 213098b8140c082e5a69b18ca83ef2eb3091939d54fRichard Smith 2148113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek /// Factory object for creating AttributeList objects. 2150b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall AttributeFactory AttrFactory; 2161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21713bb701f2f876356400a34b0917a417c66b5d70dBenjamin Kramer /// \brief Gathers and cleans up TemplateIdAnnotations when parsing of a 21813bb701f2f876356400a34b0917a417c66b5d70dBenjamin Kramer /// top-level declaration is finished. 21913bb701f2f876356400a34b0917a417c66b5d70dBenjamin Kramer SmallVector<TemplateIdAnnotation *, 16> TemplateIds; 22025a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 2210576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// \brief Identifiers which have been declared within a tentative parse. 2220576681bac125be07f77f66b02a3dba2c3a24557Richard Smith SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers; 2230576681bac125be07f77f66b02a3dba2c3a24557Richard Smith 224b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor IdentifierInfo *getSEHExceptKeyword(); 225a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 22694f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose /// True if we are within an Objective-C container while parsing C-like decls. 22794f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose /// 22894f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose /// This is necessary because Sema thinks we have left the container 22994f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose /// to parse the C-like decls, meaning Actions.getObjCDeclContext() will 23094f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose /// be NULL. 23194f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose bool ParsingInObjCContainer; 23294f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose 2336a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen bool SkipFunctionBodies; 2346a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2366a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies); 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Parser(); 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2394e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &getLangOpts() const { return PP.getLangOpts(); } 240444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } 2410102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner Preprocessor &getPreprocessor() const { return PP; } 242f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &getActions() const { return Actions; } 2439257664568bf375b7790131a84d9a4fa30a5b7e3John McCall AttributeFactory &getAttrFactory() { return AttrFactory; } 2441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2450102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Token &getCurToken() const { return Tok; } 24623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Scope *getCurScope() const { return Actions.getCurScope(); } 247651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void incrementMSLocalManglingNumber() const { 248651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return Actions.incrementMSLocalManglingNumber(); 249651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 250a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 251a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); } 252a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Type forwarding. All of these are statically 'void*', but they may all be 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // different actual classes based on the actions in place. 2552b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 2562b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<TemplateName> TemplateTy; 2577ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 258686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists; 259c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 2609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::ExprResult ExprResult; 2619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::StmtResult StmtResult; 2629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::BaseResult BaseResult; 2639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::MemInitResult MemInitResult; 2649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::TypeResult TypeResult; 26515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 2669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef Expr *ExprArg; 267ef8225444452a1486bd721f3285301fe84643b00Stephen Hines typedef MutableArrayRef<Stmt*> MultiStmtArg; 268f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::FullExprArg FullExprArg; 2691d922960e083906a586609ac6978678147250177Sebastian Redl 27060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError() { return ExprResult(true); } 27160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError() { return StmtResult(true); } 272d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor 27360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); } 27460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); } 27561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 27660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprEmpty() { return ExprResult(false); } 2775ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Parsing methods. 2791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Initialize - Warm up the parser. 2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Initialize(); 2831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if 2851f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff /// the EOF was encountered. 286682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner bool ParseTopLevelDecl(DeclGroupPtrTy &Result); 287651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool ParseTopLevelDecl() { 288651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines DeclGroupPtrTy Result; 289651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return ParseTopLevelDecl(Result); 290651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 2911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2926944e20065955414a56a6aab9b7e271e3e826a88Axel Naumann /// ConsumeToken - Consume the current 'peek token' and lex the next one. 293651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// This does not work with special tokens: string literals, code completion 294651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// and balanced tokens must be handled using the specific consume methods. 295651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// Returns the location of the consumed token. 296651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SourceLocation ConsumeToken() { 297651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines assert(!isTokenSpecial() && 2986944e20065955414a56a6aab9b7e271e3e826a88Axel Naumann "Should consume special tokens with Consume*Token"); 2996944e20065955414a56a6aab9b7e271e3e826a88Axel Naumann PrevTokLocation = Tok.getLocation(); 3006944e20065955414a56a6aab9b7e271e3e826a88Axel Naumann PP.Lex(Tok); 3016944e20065955414a56a6aab9b7e271e3e826a88Axel Naumann return PrevTokLocation; 3026944e20065955414a56a6aab9b7e271e3e826a88Axel Naumann } 3036944e20065955414a56a6aab9b7e271e3e826a88Axel Naumann 304651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool TryConsumeToken(tok::TokenKind Expected) { 305651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (Tok.isNot(Expected)) 306651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return false; 307651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines assert(!isTokenSpecial() && 308651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines "Should consume special tokens with Consume*Token"); 309651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines PrevTokLocation = Tok.getLocation(); 310651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines PP.Lex(Tok); 311651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return true; 312651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 313651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 314651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool TryConsumeToken(tok::TokenKind Expected, SourceLocation &Loc) { 315651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (!TryConsumeToken(Expected)) 316651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return false; 317651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Loc = PrevTokLocation; 318651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return true; 319651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 320651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Low-Level token peeking and consumption methods. 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenParen - Return true if the cur token is '(' or ')'. 3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenParen() const { 3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren; 3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBracket - Return true if the cur token is '[' or ']'. 3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBracket() const { 3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square; 3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBrace - Return true if the cur token is '{' or '}'. 3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBrace() const { 3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace; 3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenStringLiteral - True if this token is a string-literal. 3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenStringLiteral() const { 3400b91cc47a5642de2e1f567fe0f29420acdcdebbeRichard Smith return tok::isStringLiteral(Tok.getKind()); 3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 342651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// isTokenSpecial - True if this token requires special consumption methods. 343651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool isTokenSpecial() const { 344651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return isTokenStringLiteral() || isTokenParen() || isTokenBracket() || 345651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines isTokenBrace() || Tok.is(tok::code_completion); 346651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 347eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 348fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu /// \brief Returns true if the current token is '=' or is a type of '='. 349fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu /// For typos, give a fixit to '=' 350fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu bool isTokenEqualOrEqualTypo(); 351a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis 3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeAnyToken - Dispatch to the right Consume* method based on the 3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// current token type. This should only be used in cases where the type of 3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the token really isn't known, e.g. in error recovery. 355ab2d09b6287a5dc6fa94d78739444f46f9a78bfbArgyrios Kyrtzidis SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok = false) { 3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isTokenParen()) 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeParen(); 358651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (isTokenBracket()) 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBracket(); 360651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (isTokenBrace()) 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBrace(); 362651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (isTokenStringLiteral()) 363d62701bc5321049353017e9abf1963edd57646aaSteve Naroff return ConsumeStringToken(); 364651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (Tok.is(tok::code_completion)) 365651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken() 366651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines : handleUnexpectedCodeCompletionToken(); 367651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return ConsumeToken(); 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeParen - This consume method keeps the paren count up-to-date. 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeParen() { 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenParen() && "wrong consume method"); 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_paren) 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++ParenCount; 3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (ParenCount) 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --ParenCount; // Don't let unbalanced )'s drive the count negative. 3784b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3804b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBracket - This consume method keeps the bracket count up-to-date. 3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBracket() { 3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBracket() && "wrong consume method"); 3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_square) 3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BracketCount; 3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BracketCount) 3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BracketCount; // Don't let unbalanced ]'s drive the count negative. 3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3924b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3944b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBrace - This consume method keeps the brace count up-to-date. 3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBrace() { 4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBrace() && "wrong consume method"); 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_brace) 4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BraceCount; 4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BraceCount) 4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BraceCount; // Don't let unbalanced }'s drive the count negative. 4051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4064b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 4084b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeStringToken - Consume the current 'peek token', lexing a new one 4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and returning the token kind. This method is specific to strings, as it 4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// handles string literal concatenation, as per C99 5.1.1.2, translation 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// phase #6. 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeStringToken() { 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenStringLiteral() && 4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should only consume string literals with this method"); 4184b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 4204b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 423dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// \brief Consume the current code-completion token. 424dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// 4256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// This routine can be called to consume the code-completion token and 4266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// continue processing in special cases where \c cutOffParsing() isn't 4276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// desired, such as token caching or completion with lookahead. 428dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor SourceLocation ConsumeCodeCompletionToken() { 429dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor assert(Tok.is(tok::code_completion)); 430dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PrevTokLocation = Tok.getLocation(); 431dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PP.Lex(Tok); 432a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie return PrevTokLocation; 433dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor } 434a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 4357d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis ///\ brief When we are consuming a code-completion token without having 436dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// matched specific position in the grammar, provide code-completion results 437dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// based on context. 4387d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// 4397d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// \returns the source location of the code-completion token. 4407d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis SourceLocation handleUnexpectedCodeCompletionToken(); 4417d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis 4427d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// \brief Abruptly cut off parsing; mainly used when we have reached the 4437d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// code-completion point. 4447d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis void cutOffParsing() { 4453b7deda7137e62810a810ce25b062927a9fc7c71Argyrios Kyrtzidis if (PP.isCodeCompletionEnabled()) 4463b7deda7137e62810a810ce25b062927a9fc7c71Argyrios Kyrtzidis PP.setCodeCompletionReached(); 4477d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis // Cut off parsing by acting as if we reached the end-of-file. 4487d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis Tok.setKind(tok::eof); 4497d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis } 450dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 451651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Determine if we're at the end of the file or at a transition 452651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// between modules. 453651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool isEofOrEom() { 454651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines tok::TokenKind Kind = Tok.getKind(); 455651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return Kind == tok::eof || Kind == tok::annot_module_begin || 456651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Kind == tok::annot_module_end || Kind == tok::annot_module_include; 457651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 458651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 459651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Initialize all pragma handlers. 460651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void initializePragmaHandlers(); 461651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 462651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Destroy and reset all pragma handlers. 463651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void resetPragmaHandlers(); 464651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 465b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis /// \brief Handle the annotation token produced for #pragma unused(...) 466b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis void HandlePragmaUnused(); 467b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis 468426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola /// \brief Handle the annotation token produced for 469426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola /// #pragma GCC visibility... 470426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola void HandlePragmaVisibility(); 471426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola 472aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman /// \brief Handle the annotation token produced for 473aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman /// #pragma pack... 474aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman void HandlePragmaPack(); 475aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman 4769595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// \brief Handle the annotation token produced for 4779595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// #pragma ms_struct... 4789595c7e2533c836537dc300e75d059c29feb7094Eli Friedman void HandlePragmaMSStruct(); 4799595c7e2533c836537dc300e75d059c29feb7094Eli Friedman 4809595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// \brief Handle the annotation token produced for 4813190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner /// #pragma comment... 4823190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner void HandlePragmaMSComment(); 4833190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner 484651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void HandlePragmaMSPointersToMembers(); 485651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 486651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void HandlePragmaMSVtorDisp(); 487651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 4886bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void HandlePragmaMSPragma(); 4896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines unsigned HandlePragmaMSSection(llvm::StringRef PragmaName, 4906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation PragmaLocation); 4916bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines unsigned HandlePragmaMSSegment(llvm::StringRef PragmaName, 4926bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation PragmaLocation); 4936bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines unsigned HandlePragmaMSInitSeg(llvm::StringRef PragmaName, 4946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation PragmaLocation); 4956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 4963190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner /// \brief Handle the annotation token produced for 4979595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// #pragma align... 4989595c7e2533c836537dc300e75d059c29feb7094Eli Friedman void HandlePragmaAlign(); 4999595c7e2533c836537dc300e75d059c29feb7094Eli Friedman 5009595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// \brief Handle the annotation token produced for 5019595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// #pragma weak id... 5029595c7e2533c836537dc300e75d059c29feb7094Eli Friedman void HandlePragmaWeak(); 5039595c7e2533c836537dc300e75d059c29feb7094Eli Friedman 5049595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// \brief Handle the annotation token produced for 5059595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// #pragma weak id = id... 5069595c7e2533c836537dc300e75d059c29feb7094Eli Friedman void HandlePragmaWeakAlias(); 5079595c7e2533c836537dc300e75d059c29feb7094Eli Friedman 5089595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// \brief Handle the annotation token produced for 5099595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// #pragma redefine_extname... 5109595c7e2533c836537dc300e75d059c29feb7094Eli Friedman void HandlePragmaRedefineExtname(); 5119595c7e2533c836537dc300e75d059c29feb7094Eli Friedman 5129595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// \brief Handle the annotation token produced for 5139595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// #pragma STDC FP_CONTRACT... 5149595c7e2533c836537dc300e75d059c29feb7094Eli Friedman void HandlePragmaFPContract(); 5159595c7e2533c836537dc300e75d059c29feb7094Eli Friedman 5169595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// \brief Handle the annotation token produced for 5179595c7e2533c836537dc300e75d059c29feb7094Eli Friedman /// #pragma OPENCL EXTENSION... 5189595c7e2533c836537dc300e75d059c29feb7094Eli Friedman void HandlePragmaOpenCLExtension(); 5199595c7e2533c836537dc300e75d059c29feb7094Eli Friedman 52085192c7fe187d5486e12dbc6960af28f16a558a0Tareq A. Siraj /// \brief Handle the annotation token produced for 52185192c7fe187d5486e12dbc6960af28f16a558a0Tareq A. Siraj /// #pragma clang __debug captured 52285192c7fe187d5486e12dbc6960af28f16a558a0Tareq A. Siraj StmtResult HandlePragmaCaptured(); 52385192c7fe187d5486e12dbc6960af28f16a558a0Tareq A. Siraj 524ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// \brief Handle the annotation token produced for 525ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// #pragma vectorize... 526ef8225444452a1486bd721f3285301fe84643b00Stephen Hines LoopHint HandlePragmaLoopHint(); 527ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 5286b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// GetLookAheadToken - This peeks ahead N tokens and returns that token 5296b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1) 5306b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// returns the token after Tok, etc. 5316b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 5326b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// Note that this differs from the Preprocessor's LookAhead method, because 5336b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// the Parser always has one token lexed that the preprocessor doesn't. 5346b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 53503db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis const Token &GetLookAheadToken(unsigned N) { 5366b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (N == 0 || Tok.is(tok::eof)) return Tok; 5376b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return PP.LookAhead(N-1); 5386b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } 539f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis 5406944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannpublic: 541f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// NextToken - This peeks ahead one token and returns it without 542f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// consuming it. 543f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis const Token &NextToken() { 54403db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis return PP.LookAhead(0); 545f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis } 5465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 547b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall /// getTypeAnnotation - Read a parsed type out of an annotation token. 548b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static ParsedType getTypeAnnotation(Token &Tok) { 549b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue()); 550b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 551b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 5526944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannprivate: 553b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static void setTypeAnnotation(Token &Tok, ParsedType T) { 554b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Tok.setAnnotationValue(T.getAsOpaquePtr()); 555b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 556a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 5575ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// \brief Read an already-translated primary expression out of an annotation 5585ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// token. 5595ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor static ExprResult getExprAnnotation(Token &Tok) { 560a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue()); 5615ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor } 562a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 5635ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// \brief Set the primary expression corresponding to the given annotation 5645ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// token. 5655ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor static void setExprAnnotation(Token &Tok, ExprResult ER) { 566a2c3646c35dd09d21b74826240aa916545b1873fRichard Smith Tok.setAnnotationValue(ER.getAsOpaquePointer()); 5675ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor } 568b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 5696944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannpublic: 570fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to 571fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain // find a type name by attempting typo correction. 572fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false, 573fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain bool NeedType = false); 5740576681bac125be07f77f66b02a3dba2c3a24557Richard Smith bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool EnteringContext, 5750576681bac125be07f77f66b02a3dba2c3a24557Richard Smith bool NeedType, 5760576681bac125be07f77f66b02a3dba2c3a24557Richard Smith CXXScopeSpec &SS, 5770576681bac125be07f77f66b02a3dba2c3a24557Richard Smith bool IsNewScope); 578495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateCXXScopeToken(bool EnteringContext = false); 5796944e20065955414a56a6aab9b7e271e3e826a88Axel Naumann 5806944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannprivate: 5810576681bac125be07f77f66b02a3dba2c3a24557Richard Smith enum AnnotatedNameKind { 5820576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// Annotation has failed and emitted an error. 5830576681bac125be07f77f66b02a3dba2c3a24557Richard Smith ANK_Error, 5840576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// The identifier is a tentatively-declared name. 5850576681bac125be07f77f66b02a3dba2c3a24557Richard Smith ANK_TentativeDecl, 5860576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// The identifier is a template name. FIXME: Add an annotation for that. 5870576681bac125be07f77f66b02a3dba2c3a24557Richard Smith ANK_TemplateName, 5880576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// The identifier can't be resolved. 5890576681bac125be07f77f66b02a3dba2c3a24557Richard Smith ANK_Unresolved, 5900576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// Annotation was successful. 5910576681bac125be07f77f66b02a3dba2c3a24557Richard Smith ANK_Success 5920576681bac125be07f77f66b02a3dba2c3a24557Richard Smith }; 5930576681bac125be07f77f66b02a3dba2c3a24557Richard Smith AnnotatedNameKind TryAnnotateName(bool IsAddressOfOperand, 5946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines CorrectionCandidateCallback *CCC = nullptr); 5950576681bac125be07f77f66b02a3dba2c3a24557Richard Smith 5960576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// Push a tok::annot_cxxscope token onto the token stream. 5970576681bac125be07f77f66b02a3dba2c3a24557Richard Smith void AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation); 598eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 59982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens, 60082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// replacing them with the non-context-sensitive keywords. This returns 60182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// true if the token was replaced. 60282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc, 603b3a4e432c90be98c6d918087750397e86d030368Chris Lattner const char *&PrevSpec, unsigned &DiagID, 604b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool &isInvalid) { 6054e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!getLangOpts().AltiVec || 6061b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner (Tok.getIdentifierInfo() != Ident_vector && 6073e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt Tok.getIdentifierInfo() != Ident_pixel && 6083e3d20b2b26a885fcae855bb0b02dbc42d7c5739Bill Schmidt Tok.getIdentifierInfo() != Ident_bool)) 6091b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return false; 610a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 6111b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); 61282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 61382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 61482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector 61582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// identifier token, replacing it with the non-context-sensitive __vector. 61682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// This returns true if the token was replaced. 61782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecVectorToken() { 6184e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!getLangOpts().AltiVec || 619b3a4e432c90be98c6d918087750397e86d030368Chris Lattner Tok.getIdentifierInfo() != Ident_vector) return false; 6201b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecVectorTokenOutOfLine(); 62182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 622a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 6231b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecVectorTokenOutOfLine(); 6241b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, 6251b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner const char *&PrevSpec, unsigned &DiagID, 6261b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool &isInvalid); 62725a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 62803e463e293f5ecf62cb8c807d00edb9fbb1f99d7Bill Wendling /// TryKeywordIdentFallback - For compatibility with system headers using 62903e463e293f5ecf62cb8c807d00edb9fbb1f99d7Bill Wendling /// keywords as identifiers, attempt to convert the current token to an 63003e463e293f5ecf62cb8c807d00edb9fbb1f99d7Bill Wendling /// identifier and optionally disable the keyword for the remainder of the 63103e463e293f5ecf62cb8c807d00edb9fbb1f99d7Bill Wendling /// translation unit. This returns false if the token was not replaced, 63203e463e293f5ecf62cb8c807d00edb9fbb1f99d7Bill Wendling /// otherwise emits a diagnostic and returns true. 63303e463e293f5ecf62cb8c807d00edb9fbb1f99d7Bill Wendling bool TryKeywordIdentFallback(bool DisableKeyword); 63403e463e293f5ecf62cb8c807d00edb9fbb1f99d7Bill Wendling 635651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// TryIdentKeywordUpgrade - Convert the current identifier token back to 636651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// its original kind and return true if it was disabled by 637651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// TryKeywordIdentFallback(), otherwise return false. Use this to 638651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// contextually enable keywords. 639651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool TryIdentKeywordUpgrade(); 640651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 64113bb701f2f876356400a34b0917a417c66b5d70dBenjamin Kramer /// \brief Get the TemplateIdAnnotation from the token. 64225a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok); 64325a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 6445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TentativeParsingAction - An object that is used as a kind of "tentative 6455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// parsing transaction". It gets instantiated to mark the token position and 6465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// after the token consumption is done, Commit() or Revert() is called to 6475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// either "commit the consumed tokens" or revert to the previously marked 6485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// token position. Example: 6495404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 650314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor /// TentativeParsingAction TPA(*this); 6515404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// ConsumeToken(); 6525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// .... 6535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TPA.Revert(); 6545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 6555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis class TentativeParsingAction { 6565404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Parser &P; 6575404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Token PrevTok; 6580576681bac125be07f77f66b02a3dba2c3a24557Richard Smith size_t PrevTentativelyDeclaredIdentifierCount; 659de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount; 6605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isActive; 6615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 6625404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis public: 6635404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis explicit TentativeParsingAction(Parser& p) : P(p) { 6645404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis PrevTok = P.Tok; 6650576681bac125be07f77f66b02a3dba2c3a24557Richard Smith PrevTentativelyDeclaredIdentifierCount = 6660576681bac125be07f77f66b02a3dba2c3a24557Richard Smith P.TentativelyDeclaredIdentifiers.size(); 667de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor PrevParenCount = P.ParenCount; 668de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor PrevBracketCount = P.BracketCount; 669de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor PrevBraceCount = P.BraceCount; 6705404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.EnableBacktrackAtThisPos(); 6715404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = true; 6725404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 6735404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Commit() { 6745404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 6750576681bac125be07f77f66b02a3dba2c3a24557Richard Smith P.TentativelyDeclaredIdentifiers.resize( 6760576681bac125be07f77f66b02a3dba2c3a24557Richard Smith PrevTentativelyDeclaredIdentifierCount); 6775404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.CommitBacktrackedTokens(); 6785404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 6795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 6805404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Revert() { 6815404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 6825404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.Backtrack(); 6835404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.Tok = PrevTok; 6840576681bac125be07f77f66b02a3dba2c3a24557Richard Smith P.TentativelyDeclaredIdentifiers.resize( 6850576681bac125be07f77f66b02a3dba2c3a24557Richard Smith PrevTentativelyDeclaredIdentifierCount); 686de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor P.ParenCount = PrevParenCount; 687de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor P.BracketCount = PrevBracketCount; 688de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor P.BraceCount = PrevBraceCount; 6895404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 6905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 6915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis ~TentativeParsingAction() { 6925404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(!isActive && "Forgot to call Commit or Revert!"); 6935404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 6945404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis }; 6959bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith class UnannotatedTentativeParsingAction; 6961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6979735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// ObjCDeclContextSwitch - An object used to switch context from 6989735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// an objective-c decl context to its enclosing decl context and 6999735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// back. 7009735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian class ObjCDeclContextSwitch { 7019735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian Parser &P; 7029735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian Decl *DC; 70394f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose SaveAndRestore<bool> WithinObjCContainer; 7049735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian public: 70594f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose explicit ObjCDeclContextSwitch(Parser &p) 70694f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose : P(p), DC(p.getObjCDeclContext()), 7076bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines WithinObjCContainer(P.ParsingInObjCContainer, DC != nullptr) { 7089735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian if (DC) 709458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC)); 7109735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian } 7119735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian ~ObjCDeclContextSwitch() { 7129735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian if (DC) 713458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC)); 7149735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian } 7159735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian }; 7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the 7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// input. If so, it is consumed and false is returned. 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 720651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// If a trivial punctuator misspelling is encountered, a FixIt error 721651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// diagnostic is issued and false is returned after recovery. 722651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// 723651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// If the input is malformed, this emits the specified diagnostic and true is 7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// returned. 725651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool ExpectAndConsume(tok::TokenKind ExpectedTok, 726651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned Diag = diag::err_expected, 727651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const char *DiagMsg = ""); 7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7299ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// \brief The parser expects a semicolon and, if present, will consume it. 7309ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// 7319ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// If the next token is not a semicolon, this emits the specified diagnostic, 7329ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior 7339ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// to the semicolon, consumes that extra token. 7349ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor bool ExpectAndConsumeSemi(unsigned DiagID); 735a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 736eab9d6f9065b042d39fbaf9842c9d8cc968dd6d0Richard Smith /// \brief The kind of extra semi diagnostic to emit. 7374b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu enum ExtraSemiKind { 7384b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu OutsideFunction = 0, 7394b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu InsideStruct = 1, 7404b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu InstanceVariableList = 2, 741eab9d6f9065b042d39fbaf9842c9d8cc968dd6d0Richard Smith AfterMemberFunctionDefinition = 3 7424b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu }; 7434b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu 7444b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu /// \brief Consume any extra semi-colons until the end of the line. 745eab9d6f9065b042d39fbaf9842c9d8cc968dd6d0Richard Smith void ConsumeExtraSemi(ExtraSemiKind Kind, unsigned TST = TST_unspecified); 7464b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu 7476944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannpublic: 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Scope manipulation 7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7518935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// ParseScope - Introduces a new scope for parsing. The kind of 7528935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// scope is determined by ScopeFlags. Objects of this type should 7538935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// be created on the stack to coincide with the position where the 7548935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// parser enters the new scope, and this object's constructor will 7558935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// create that new scope. Similarly, once the object is destroyed 7568935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// the parser will exit the scope. 7578935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor class ParseScope { 7588935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Parser *Self; 759f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko ParseScope(const ParseScope &) LLVM_DELETED_FUNCTION; 760f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko void operator=(const ParseScope &) LLVM_DELETED_FUNCTION; 7618935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 7628935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor public: 7638935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ParseScope - Construct a new object to manage a scope in the 7648935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // parser Self where the new Scope is created with the flags 765651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // ScopeFlags, but only when we aren't about to enter a compound statement. 766651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ParseScope(Parser *Self, unsigned ScopeFlags, bool EnteredScope = true, 767651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool BeforeCompoundStmt = false) 7688935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor : Self(Self) { 769651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (EnteredScope && !BeforeCompoundStmt) 7708935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->EnterScope(ScopeFlags); 771651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines else { 772651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (BeforeCompoundStmt) 773651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Self->incrementMSLocalManglingNumber(); 774651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 7756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines this->Self = nullptr; 776651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 7778935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 7788935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 7798935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // Exit - Exit the scope associated with this object now, rather 7808935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // than waiting until the object is destroyed. 7818935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor void Exit() { 7828935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (Self) { 7838935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->ExitScope(); 7846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Self = nullptr; 7858935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 7868935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 7878935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 7888935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ~ParseScope() { 7898935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Exit(); 7908935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 7918935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor }; 7928935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterScope - Start a new scope. 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterScope(unsigned ScopeFlags); 7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExitScope - Pop a scope off the scope stack. 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ExitScope(); 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7996944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannprivate: 8007a614d8380297fcd2bc23986241905d97222948cRichard Smith /// \brief RAII object used to modify the scope flags for the current scope. 8017a614d8380297fcd2bc23986241905d97222948cRichard Smith class ParseScopeFlags { 8027a614d8380297fcd2bc23986241905d97222948cRichard Smith Scope *CurScope; 8037a614d8380297fcd2bc23986241905d97222948cRichard Smith unsigned OldFlags; 804f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko ParseScopeFlags(const ParseScopeFlags &) LLVM_DELETED_FUNCTION; 805f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko void operator=(const ParseScopeFlags &) LLVM_DELETED_FUNCTION; 8067a614d8380297fcd2bc23986241905d97222948cRichard Smith 8077a614d8380297fcd2bc23986241905d97222948cRichard Smith public: 8087a614d8380297fcd2bc23986241905d97222948cRichard Smith ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true); 8097a614d8380297fcd2bc23986241905d97222948cRichard Smith ~ParseScopeFlags(); 8107a614d8380297fcd2bc23986241905d97222948cRichard Smith }; 8117a614d8380297fcd2bc23986241905d97222948cRichard Smith 8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Diagnostic Emission and Error recovery. 81415faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 8156aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorpublic: 8163cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 8173cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); 818d73ef135ba029db59c0b5649e6117845d9e39600Jordan Rose DiagnosticBuilder Diag(unsigned DiagID) { 819d73ef135ba029db59c0b5649e6117845d9e39600Jordan Rose return Diag(Tok, DiagID); 820d73ef135ba029db59c0b5649e6117845d9e39600Jordan Rose } 82115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 8226aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorprivate: 8231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SuggestParentheses(SourceLocation Loc, unsigned DK, 8244b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceRange ParenRange); 825d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen void CheckNestedObjCContexts(SourceLocation AtLoc); 8264b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 8276944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannpublic: 8288fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev 829155c877e2010845fb4d168bc59e55256bcb486a7NAKAMURA Takumi /// \brief Control flags for SkipUntil functions. 8308fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev enum SkipUntilFlags { 831155c877e2010845fb4d168bc59e55256bcb486a7NAKAMURA Takumi StopAtSemi = 1 << 0, ///< Stop skipping at semicolon 8328fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev /// \brief Stop skipping at specified token, but don't skip the token itself 8338fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev StopBeforeMatch = 1 << 1, 834155c877e2010845fb4d168bc59e55256bcb486a7NAKAMURA Takumi StopAtCodeCompletion = 1 << 2 ///< Stop at code completion 8358fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev }; 8368fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev 8378fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev friend LLVM_CONSTEXPR SkipUntilFlags operator|(SkipUntilFlags L, 8388fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntilFlags R) { 8398fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev return static_cast<SkipUntilFlags>(static_cast<unsigned>(L) | 8408fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev static_cast<unsigned>(R)); 8418fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev } 8428fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev 8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipUntil - Read tokens until we get to the specified token, then consume 8448fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev /// it (unless StopBeforeMatch is specified). Because we cannot guarantee 8458fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev /// that the token will ever occur, this skips to the next token, or to some 8468fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev /// likely good stopping point. If Flags has StopAtSemi flag, skipping will 8478fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev /// stop at a ';' character. 8481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If SkipUntil finds the specified token, it returns true, otherwise it 8501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returns false. 8518fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev bool SkipUntil(tok::TokenKind T, 8528fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) { 8538fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev return SkipUntil(llvm::makeArrayRef(T), Flags); 8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8558fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, 8568fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) { 8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind TokArray[] = {T1, T2}; 8588fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev return SkipUntil(TokArray, Flags); 8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 860eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3, 8618fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) { 862eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie tok::TokenKind TokArray[] = {T1, T2, T3}; 8638fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev return SkipUntil(TokArray, Flags); 864eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie } 8658fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev bool SkipUntil(ArrayRef<tok::TokenKind> Toks, 8668fe2475a4b4c00475709c13d43eb9a57cce87cbcAlexey Bataev SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)); 8677ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 868994d73f8473cb2cd3ce2f69c9575c95015be788aRichard Smith /// SkipMalformedDecl - Read tokens until we get to some likely good stopping 869994d73f8473cb2cd3ce2f69c9575c95015be788aRichard Smith /// point for skipping past a simple-declaration. 870994d73f8473cb2cd3ce2f69c9575c95015be788aRichard Smith void SkipMalformedDecl(); 871994d73f8473cb2cd3ce2f69c9575c95015be788aRichard Smith 8726944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannprivate: 8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 8744cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Lexing and parsing of C++ inline methods. 8754cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 876d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct ParsingClass; 877d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 878d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// [class.mem]p1: "... the class is regarded as complete within 879d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - function bodies 880d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - default arguments 881d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - exception-specifications (TODO: C++0x) 8827a614d8380297fcd2bc23986241905d97222948cRichard Smith /// - and brace-or-equal-initializers for non-static data members 8837a614d8380297fcd2bc23986241905d97222948cRichard Smith /// (including such things in nested classes)." 884d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarations build the tree of those elements so they can 885d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// be parsed after parsing the top-level class. 886d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor class LateParsedDeclaration { 887d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor public: 888d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual ~LateParsedDeclaration(); 889d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 890d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 8917a614d8380297fcd2bc23986241905d97222948cRichard Smith virtual void ParseLexedMemberInitializers(); 892d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 893eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski virtual void ParseLexedAttributes(); 894d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor }; 895d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 896d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// Inner node of the LateParsedDeclaration tree that parses 897d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// all its members recursively. 898d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor class LateParsedClass : public LateParsedDeclaration { 899d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor public: 900d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateParsedClass(Parser *P, ParsingClass *C); 901d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual ~LateParsedClass(); 902d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 903651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void ParseLexedMethodDeclarations() override; 904651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void ParseLexedMemberInitializers() override; 905651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void ParseLexedMethodDefs() override; 906651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void ParseLexedAttributes() override; 907d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 908d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor private: 909d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser *Self; 910d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor ParsingClass *Class; 911d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor }; 912d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 913a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// Contains the lexed tokens of an attribute with arguments that 914a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// may reference member variables and so need to be parsed at the 915a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// end of the class declaration after parsing all other member 916eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// member declarations. 917eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// FIXME: Perhaps we should change the name of LateParsedDeclaration to 918eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// LateParsedTokens. 919eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski struct LateParsedAttribute : public LateParsedDeclaration { 920eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski Parser *Self; 921eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski CachedTokens Toks; 922eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski IdentifierInfo &AttrName; 923eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation AttrNameLoc; 9242287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins SmallVector<Decl*, 2> Decls; 925eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 926a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name, 927eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation Loc) 9282287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins : Self(P), AttrName(Name), AttrNameLoc(Loc) {} 929eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 930651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void ParseLexedAttributes() override; 931eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 9322287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins void addDecl(Decl *D) { Decls.push_back(D); } 933eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski }; 934eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 935161db02a747e0c8e717f542674c0581c03fc3c93DeLesley Hutchins // A list of late-parsed attributes. Used by ParseGNUAttributes. 936cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko class LateParsedAttrList: public SmallVector<LateParsedAttribute *, 2> { 937161db02a747e0c8e717f542674c0581c03fc3c93DeLesley Hutchins public: 938161db02a747e0c8e717f542674c0581c03fc3c93DeLesley Hutchins LateParsedAttrList(bool PSoon = false) : ParseSoon(PSoon) { } 939161db02a747e0c8e717f542674c0581c03fc3c93DeLesley Hutchins 940161db02a747e0c8e717f542674c0581c03fc3c93DeLesley Hutchins bool parseSoon() { return ParseSoon; } 941eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 942161db02a747e0c8e717f542674c0581c03fc3c93DeLesley Hutchins private: 943161db02a747e0c8e717f542674c0581c03fc3c93DeLesley Hutchins bool ParseSoon; // Are we planning to parse these shortly after creation? 944161db02a747e0c8e717f542674c0581c03fc3c93DeLesley Hutchins }; 945eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 946d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// Contains the lexed tokens of a member function definition 947d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// which needs to be parsed at the end of the class declaration 948d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// after parsing all other member declarations. 949d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct LexedMethod : public LateParsedDeclaration { 950d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser *Self; 951d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *D; 95272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens Toks; 953d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 954d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 955d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 956f5e9d035840a4539222708032d75a0515e2508a8Nico Weber /// otherwise, it is a member function declaration. 957d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 958d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 959d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor explicit LexedMethod(Parser* P, Decl *MD) 960d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor : Self(P), D(MD), TemplateScope(false) {} 961d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 962651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void ParseLexedMethodDefs() override; 9634cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis }; 9644cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 96572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedDefaultArgument - Keeps track of a parameter that may 96672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument that cannot be parsed yet because it 96772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// occurs within a member function declaration inside the class 96872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// (C++ [class.mem]p2). 96972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedDefaultArgument { 970d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall explicit LateParsedDefaultArgument(Decl *P, 9716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines CachedTokens *Toks = nullptr) 97272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor : Param(P), Toks(Toks) { } 97372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 97472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Param - The parameter declaration for this parameter. 975d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param; 97672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 97772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Toks - The sequence of tokens that comprises the default 97872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument expression, not including the '=' or the terminating 97972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// ')' or ','. This will be NULL for parameters that have no 98072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// default argument. 98172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks; 98272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDeclaration - A method declaration inside a class that 98572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// contains at least one entity whose parsing needs to be delayed 98672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// until the class itself is completely-defined, such as a default 98772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument (C++ [class.mem]p2). 988d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct LateParsedMethodDeclaration : public LateParsedDeclaration { 989d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor explicit LateParsedMethodDeclaration(Parser *P, Decl *M) 9906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines : Self(P), Method(M), TemplateScope(false), 9916bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ExceptionSpecTokens(nullptr) {} 992d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 993651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void ParseLexedMethodDeclarations() override; 994d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 995d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser* Self; 99672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 99772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Method - The method declaration. 998d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Method; 99972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 1000d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 1001d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 1002d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 1003d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 10041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// DefaultArgs - Contains the parameters of the function and 100672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// their default arguments. At least one of the parameters will 100772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument, but all of the parameters of the 100872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// method will be stored so that they can be reintroduced into 10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// scope at the appropriate times. 1010686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; 101174e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor 101274e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor /// \brief The set of tokens that make up an exception-specification that 101374e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor /// has not yet been parsed. 101474e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor CachedTokens *ExceptionSpecTokens; 101572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 101672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 10177a614d8380297fcd2bc23986241905d97222948cRichard Smith /// LateParsedMemberInitializer - An initializer for a non-static class data 10187a614d8380297fcd2bc23986241905d97222948cRichard Smith /// member whose parsing must to be delayed until the class is completely 10197a614d8380297fcd2bc23986241905d97222948cRichard Smith /// defined (C++11 [class.mem]p2). 10207a614d8380297fcd2bc23986241905d97222948cRichard Smith struct LateParsedMemberInitializer : public LateParsedDeclaration { 10217a614d8380297fcd2bc23986241905d97222948cRichard Smith LateParsedMemberInitializer(Parser *P, Decl *FD) 10227a614d8380297fcd2bc23986241905d97222948cRichard Smith : Self(P), Field(FD) { } 10237a614d8380297fcd2bc23986241905d97222948cRichard Smith 1024651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void ParseLexedMemberInitializers() override; 10257a614d8380297fcd2bc23986241905d97222948cRichard Smith 10267a614d8380297fcd2bc23986241905d97222948cRichard Smith Parser *Self; 10277a614d8380297fcd2bc23986241905d97222948cRichard Smith 10287a614d8380297fcd2bc23986241905d97222948cRichard Smith /// Field - The field declaration. 10297a614d8380297fcd2bc23986241905d97222948cRichard Smith Decl *Field; 10307a614d8380297fcd2bc23986241905d97222948cRichard Smith 10317a614d8380297fcd2bc23986241905d97222948cRichard Smith /// CachedTokens - The sequence of tokens that comprises the initializer, 10327a614d8380297fcd2bc23986241905d97222948cRichard Smith /// including any leading '='. 10337a614d8380297fcd2bc23986241905d97222948cRichard Smith CachedTokens Toks; 10347a614d8380297fcd2bc23986241905d97222948cRichard Smith }; 10357a614d8380297fcd2bc23986241905d97222948cRichard Smith 1036d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarationsContainer - During parsing of a top (non-nested) 1037d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// C++ class, its method declarations that contain parts that won't be 1038fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// parsed until after the definition is completed (C++ [class.mem]p2), 1039d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// the method declarations and possibly attached inline definitions 1040a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// will be stored here with the tokens that will be parsed to create those 1041a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// entities. 1042a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer; 104372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 10446569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Representation of a class that has been parsed, including 10456569d68745c8213709740337d2be52b031384f58Douglas Gregor /// any member function declarations or definitions that need to be 10466569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed after the corresponding top-level class is complete. 10476569d68745c8213709740337d2be52b031384f58Douglas Gregor struct ParsingClass { 1048e402e72273cde2a64fa6097c1fe93f500038675dJohn McCall ParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface) 10491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : TopLevelClass(TopLevelClass), TemplateScope(false), 1050e402e72273cde2a64fa6097c1fe93f500038675dJohn McCall IsInterface(IsInterface), TagOrTemplate(TagOrTemplate) { } 10516569d68745c8213709740337d2be52b031384f58Douglas Gregor 10526569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this is a "top-level" class, meaning that it is 10536569d68745c8213709740337d2be52b031384f58Douglas Gregor /// not nested within another class. 10546569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TopLevelClass : 1; 10556569d68745c8213709740337d2be52b031384f58Douglas Gregor 10566569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this class had an associated template 10576569d68745c8213709740337d2be52b031384f58Douglas Gregor /// scope. When true, TagOrTemplate is a template declaration; 10586569d68745c8213709740337d2be52b031384f58Douglas Gregor /// othewise, it is a tag declaration. 10596569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TemplateScope : 1; 10606569d68745c8213709740337d2be52b031384f58Douglas Gregor 1061e402e72273cde2a64fa6097c1fe93f500038675dJohn McCall /// \brief Whether this class is an __interface. 1062e402e72273cde2a64fa6097c1fe93f500038675dJohn McCall bool IsInterface : 1; 1063e402e72273cde2a64fa6097c1fe93f500038675dJohn McCall 10646569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The class or class template whose definition we are parsing. 1065d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagOrTemplate; 106672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 1067d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarations - Method declarations, inline definitions and 1068d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// nested classes that contain pieces whose parsing will be delayed until 1069d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// the top-level class is fully defined. 1070d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateParsedDeclarationsContainer LateParsedDeclarations; 107172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 10724cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 10736569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The stack of classes that is currently being 10746569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed. Nested and local classes will be pushed onto this stack 10756569d68745c8213709740337d2be52b031384f58Douglas Gregor /// when they are parsed, and removed afterward. 10766569d68745c8213709740337d2be52b031384f58Douglas Gregor std::stack<ParsingClass *> ClassStack; 10774cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 10786569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingClass &getCurrentClass() { 10796569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "No lexed method stacks!"); 10806569d68745c8213709740337d2be52b031384f58Douglas Gregor return *ClassStack.top(); 10814cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 10824cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 10839257664568bf375b7790131a84d9a4fa30a5b7e3John McCall /// \brief RAII object used to manage the parsing of a class definition. 10846569d68745c8213709740337d2be52b031384f58Douglas Gregor class ParsingClassDefinition { 10856569d68745c8213709740337d2be52b031384f58Douglas Gregor Parser &P; 10866569d68745c8213709740337d2be52b031384f58Douglas Gregor bool Popped; 1087eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Sema::ParsingClassState State; 10886569d68745c8213709740337d2be52b031384f58Douglas Gregor 10896569d68745c8213709740337d2be52b031384f58Douglas Gregor public: 1090e402e72273cde2a64fa6097c1fe93f500038675dJohn McCall ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass, 1091e402e72273cde2a64fa6097c1fe93f500038675dJohn McCall bool IsInterface) 1092eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall : P(P), Popped(false), 1093e402e72273cde2a64fa6097c1fe93f500038675dJohn McCall State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) { 10946569d68745c8213709740337d2be52b031384f58Douglas Gregor } 10956569d68745c8213709740337d2be52b031384f58Douglas Gregor 10966569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Pop this class of the stack. 10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void Pop() { 10986569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!Popped && "Nested class has already been popped"); 10996569d68745c8213709740337d2be52b031384f58Douglas Gregor Popped = true; 1100eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall P.PopParsingClass(State); 11016569d68745c8213709740337d2be52b031384f58Douglas Gregor } 11026569d68745c8213709740337d2be52b031384f58Douglas Gregor 11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ~ParsingClassDefinition() { 11046569d68745c8213709740337d2be52b031384f58Douglas Gregor if (!Popped) 1105eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall P.PopParsingClass(State); 11066569d68745c8213709740337d2be52b031384f58Douglas Gregor } 11076569d68745c8213709740337d2be52b031384f58Douglas Gregor }; 11086569d68745c8213709740337d2be52b031384f58Douglas Gregor 11094d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief Contains information about any template-specific 11104d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// information that has been parsed prior to parsing declaration 11114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// specifiers. 11124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor struct ParsedTemplateInfo { 11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsedTemplateInfo() 11146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines : Kind(NonTemplate), TemplateParams(nullptr), TemplateLoc() { } 11154d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ParsedTemplateInfo(TemplateParameterLists *TemplateParams, 1117c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool isSpecialization, 1118c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool lastParameterListWasEmpty = false) 11194d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(isSpecialization? ExplicitSpecialization : Template), 1120a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie TemplateParams(TemplateParams), 1121c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(lastParameterListWasEmpty) { } 11224d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 112345f965581935791a018df829a14dff53c1dd8f47Douglas Gregor explicit ParsedTemplateInfo(SourceLocation ExternLoc, 112445f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation TemplateLoc) 11256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines : Kind(ExplicitInstantiation), TemplateParams(nullptr), 1126c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), 1127c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(false){ } 11284d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11294d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The kind of template we are parsing. 11304d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor enum { 11314d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are not parsing a template at all. 11324d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor NonTemplate = 0, 11334d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing a template declaration. 11344d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor Template, 11354d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit specialization. 11364d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitSpecialization, 11374d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit instantiation. 11384d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitInstantiation 11394d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } Kind; 11404d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11414d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The template parameter lists, for template declarations 11424d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// and explicit specializations. 11434d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParameterLists *TemplateParams; 11444d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 114545f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// \brief The location of the 'extern' keyword, if any, for an explicit 114645f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// instantiation 114745f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation ExternLoc; 11481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11494d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The location of the 'template' keyword, for an explicit 11504d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// instantiation. 11514d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation TemplateLoc; 1152a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1153c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor /// \brief Whether the last template parameter list was empty. 1154c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool LastParameterListWasEmpty; 115578b810559d89e996e00684335407443936ce34a1John McCall 1156aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 11574d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor }; 11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11598387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet void LexTemplateFunctionForLateParsing(CachedTokens &Toks); 1160ac32d9044b9c1e7492cef929a322d23ce899d276Richard Smith void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT); 11618387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 1162ac32d9044b9c1e7492cef929a322d23ce899d276Richard Smith static void LateTemplateParserCallback(void *P, LateParsedTemplate &LPT); 11638387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 1164eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Sema::ParsingClassState 1165e402e72273cde2a64fa6097c1fe93f500038675dJohn McCall PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface); 116637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void DeallocateParsedClasses(ParsingClass *Class); 1167eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall void PopParsingClass(Sema::ParsingClassState); 116837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor 11699bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith enum CachedInitKind { 11709bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith CIK_DefaultArgument, 11719bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith CIK_DefaultInitializer 11729bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith }; 11739bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith 11740777cf5fcb8ca53bdc7e6455e9068742fbcc14dbRafael Espindola NamedDecl *ParseCXXInlineMethodDef(AccessSpecifier AS, 11750777cf5fcb8ca53bdc7e6455e9068742fbcc14dbRafael Espindola AttributeList *AccessAttrs, 11765f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen ParsingDeclarator &D, 11774867347e82648d3baf09524b98b09c297a5a198fNico Weber const ParsedTemplateInfo &TemplateInfo, 1178a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie const VirtSpecifiers& VS, 117945fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor FunctionDefinitionKind DefinitionKind, 118045fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor ExprResult& Init); 11817a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseCXXNonStaticMemberInitializer(Decl *VarD); 1182eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void ParseLexedAttributes(ParsingClass &Class); 1183c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D, 1184c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins bool EnterScope, bool OnDefinition); 1185c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins void ParseLexedAttribute(LateParsedAttribute &LA, 1186c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins bool EnterScope, bool OnDefinition); 118737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDeclarations(ParsingClass &Class); 1188d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM); 118937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDefs(ParsingClass &Class); 1190d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor void ParseLexedMethodDef(LexedMethod &LM); 11917a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseLexedMemberInitializers(ParsingClass &Class); 11927a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI); 11936c89eafc90f5c51a0bf185a993961170aee530c2Fariborz Jahanian void ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod); 1194a891a32d3762ee641a29c091d286f2a7432671a5Sebastian Redl bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks); 11959bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith bool ConsumeAndStoreInitializer(CachedTokens &Toks, CachedInitKind CIK); 11969bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith bool ConsumeAndStoreConditional(CachedTokens &Toks); 119714b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeAndStoreUntil(tok::TokenKind T1, 119814b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis CachedTokens &Toks, 119914b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 120014b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeFinalToken = true) { 120114b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken); 120214b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis } 12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 120437b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor CachedTokens &Toks, 120514b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 120637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor bool ConsumeFinalToken = true); 12074d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 12084cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.9: External Definitions. 12107f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct ParsedAttributesWithRange : ParsedAttributes { 12110b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange(AttributeFactory &factory) 12120b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall : ParsedAttributes(factory) {} 12130b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 12147f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceRange Range; 12157f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall }; 12167f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 12177f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs, 12186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ParsingDeclSpec *DS = nullptr); 1219e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt bool isDeclarationAfterDeclarator(); 1220004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); 12212edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt DeclGroupPtrTy ParseDeclarationOrFunctionDefinition( 12222edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt ParsedAttributesWithRange &attrs, 12236bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ParsingDeclSpec *DS = nullptr, 12243acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AccessSpecifier AS = AS_none); 12252edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs, 12262edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt ParsingDeclSpec &DS, 12272edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt AccessSpecifier AS); 1228a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1229d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseFunctionDefinition(ParsingDeclarator &D, 1230c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 12316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines LateParsedAttrList *LateParsedAttrs = nullptr); 12325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseKNRParamDeclarations(Declarator &D); 1233ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 1234ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the simple-asm. 12356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ExprResult ParseSimpleAsm(SourceLocation *EndLoc = nullptr); 123660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAsmStringLiteral(); 12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12383536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Objective-C External Declarations 1239e145bfd06c7eaf0cff0f7d825d1c6244127c26dfNico Weber void MaybeSkipAttributes(tok::ObjCKeywordKind Kind); 1240bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor DeclGroupPtrTy ParseObjCAtDirectives(); 1241bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); 1242d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, 12437f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &prefixAttrs); 12444cc0cf1a54541b26b258c45cd7a3c80c9401eaadFariborz Jahanian void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc, 12454cc0cf1a54541b26b258c45cd7a3c80c9401eaadFariborz Jahanian BalancedDelimiterTracker &T, 12464cc0cf1a54541b26b258c45cd7a3c80c9401eaadFariborz Jahanian SmallVectorImpl<Decl *> &AllIvarDecls, 12474cc0cf1a54541b26b258c45cd7a3c80c9401eaadFariborz Jahanian bool RBraceMissing); 1248d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseObjCClassInstanceVariables(Decl *interfaceDecl, 124983c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 125060fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc); 1251686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P, 1252686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceLocation> &PLocs, 12531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool WarnOnDeclarations, 125471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, 1255e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SourceLocation &EndProtoLoc); 125646f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor bool ParseObjCProtocolQualifiers(DeclSpec &DS); 12572f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, 12582f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian Decl *CDecl); 1259bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc, 1260bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor ParsedAttributes &prefixAttrs); 12611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1262849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis struct ObjCImplParsingDataRAII { 1263849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Parser &P; 1264849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Decl *Dcl; 12656c89eafc90f5c51a0bf185a993961170aee530c2Fariborz Jahanian bool HasCFunction; 1266849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer; 1267849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis LateParsedObjCMethodContainer LateParsedObjCMethods; 1268849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1269849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ObjCImplParsingDataRAII(Parser &parser, Decl *D) 12706c89eafc90f5c51a0bf185a993961170aee530c2Fariborz Jahanian : P(parser), Dcl(D), HasCFunction(false) { 1271849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis P.CurParsedObjCImpl = this; 1272849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Finished = false; 1273849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } 1274849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ~ObjCImplParsingDataRAII(); 1275849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1276849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis void finish(SourceRange AtEnd); 1277849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis bool isFinished() const { return Finished; } 1278849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1279849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis private: 1280849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis bool Finished; 1281849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis }; 1282849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ObjCImplParsingDataRAII *CurParsedObjCImpl; 12836c89eafc90f5c51a0bf185a993961170aee530c2Fariborz Jahanian void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl); 12840416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 1285849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc); 1286140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd); 1287d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc); 1288d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertySynthesize(SourceLocation atLoc); 1289d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertyDynamic(SourceLocation atLoc); 12901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12912fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); 129234870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner // Definitions for Objective-c context sensitive keywords recognition. 129334870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner enum ObjCTypeQual { 129434870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, 129534870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_NumQuals 129634870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner }; 1297a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; 12981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1299335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian bool isTokIdentifier_in() const; 1300d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 1301cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, Declarator::TheContext Ctx, 1302cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParsedAttributes *ParamAttrs); 1303294494e1cce92043562b4680c613df7fd028c02eSteve Naroff void ParseObjCMethodRequirement(); 1304a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *ParseObjCMethodPrototype( 130590ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 130690ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition = true); 1307d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, 130890ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 130990ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition=true); 1310a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian void ParseObjCPropertyAttribute(ObjCDeclSpec &DS); 13111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1312d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDefinition(); 13131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13146944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannpublic: 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.5: Expressions. 1317a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1318cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain /// TypeCastState - State whether an expression is or may be a type cast. 1319cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain enum TypeCastState { 1320cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain NotTypeCast = 0, 1321cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain MaybeTypeCast, 1322cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain IsTypeCast 1323cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain }; 1324cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain 1325cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain ExprResult ParseExpression(TypeCastState isTypeCast = NotTypeCast); 1326e43fe993a079795ac3d2ba7c9ec5e2a0c8069918Kaelyn Uhrain ExprResult ParseConstantExpression(TypeCastState isTypeCast = NotTypeCast); 13272f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl // Expr that doesn't include commas. 1328cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain ExprResult ParseAssignmentExpression(TypeCastState isTypeCast = NotTypeCast); 13292f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 1330aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl<Token> &LineToks, 1331aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall unsigned &NumLineToksConsumed, 1332aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall void *Info, 1333aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall bool IsUnevaluated); 1334aeeacf725c9e0ddd64ea9764bd008e5b6873ce51John McCall 13356944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannprivate: 133660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); 13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 133860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); 1339adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman 134060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, 1341312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor prec::Level MinPrec); 134260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 1343312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool isAddressOfOperand, 1344312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool &NotCastExpr, 1345cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain TypeCastState isTypeCast); 134660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 1347312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool isAddressOfOperand = false, 1348cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain TypeCastState isTypeCast = NotTypeCast); 13499c72c6088d591ace8503b842d39448c2040f3033John McCall 13504b0824229b96d024a96f3c7dd75ab70652c05c5bRichard Smith /// Returns true if the next token cannot start an expression. 13514b0824229b96d024a96f3c7dd75ab70652c05c5bRichard Smith bool isNotExpressionStart(); 13524b0824229b96d024a96f3c7dd75ab70652c05c5bRichard Smith 13539c72c6088d591ace8503b842d39448c2040f3033John McCall /// Returns true if the next token would start a postfix-expression 13549c72c6088d591ace8503b842d39448c2040f3033John McCall /// suffix. 13559c72c6088d591ace8503b842d39448c2040f3033John McCall bool isPostfixExpressionSuffixStart() { 13569c72c6088d591ace8503b842d39448c2040f3033John McCall tok::TokenKind K = Tok.getKind(); 13579c72c6088d591ace8503b842d39448c2040f3033John McCall return (K == tok::l_square || K == tok::l_paren || 13589c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::period || K == tok::arrow || 13599c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::plusplus || K == tok::minusminus); 13609c72c6088d591ace8503b842d39448c2040f3033John McCall } 13619c72c6088d591ace8503b842d39448c2040f3033John McCall 136260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParsePostfixExpressionSuffix(ExprResult LHS); 1363f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult ParseUnaryExprOrTypeTraitExpression(); 136460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBuiltinPrimaryExpression(); 13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1366f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, 13675ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis bool &isCastExpr, 1368b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 13695ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis SourceRange &CastRange); 13700cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 1371686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<Expr*, 20> ExprListTy; 1372686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<SourceLocation, 20> CommaLocsTy; 13730cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 13740cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis /// ParseExpressionList - Used for C/C++ (argument-)expression-list. 13756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool 13766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ParseExpressionList(SmallVectorImpl<Expr *> &Exprs, 13776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SmallVectorImpl<SourceLocation> &CommaLocs, 13786bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void (Sema::*Completer)(Scope *S, Expr *Data, 13796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ArrayRef<Expr *> Args) = nullptr, 13806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Expr *Data = nullptr); 1381d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl 13824fce06cd52a8f4714524baa13b544ead9fd298a4Eli Friedman /// ParseSimpleExpressionList - A simple comma-separated list of expressions, 13834fce06cd52a8f4714524baa13b544ead9fd298a4Eli Friedman /// used for misc language extensions. 13844fce06cd52a8f4714524baa13b544ead9fd298a4Eli Friedman bool ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs, 13854fce06cd52a8f4714524baa13b544ead9fd298a4Eli Friedman SmallVectorImpl<SourceLocation> &CommaLocs); 13864fce06cd52a8f4714524baa13b544ead9fd298a4Eli Friedman 13874fce06cd52a8f4714524baa13b544ead9fd298a4Eli Friedman 13885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParenParseOption - Control what ParseParenExpression will parse. 13895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ParenParseOption { 13905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SimpleExpr, // Only parse '(' expression ')' 13915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundStmt, // Also allow '(' compound-statement ')' 13925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}' 13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CastExpr // Also allow '(' type-name ')' <anything> 13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 139560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseParenExpression(ParenParseOption &ExprType, 13960350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis bool stopIfCastExpr, 13970a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis bool isTypeCast, 1398b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 1399d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl SourceLocation &RParenLoc); 14001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14016bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ExprResult ParseCXXAmbiguousParenExpression( 14026bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ParenParseOption &ExprType, ParsedType &CastTy, 14036bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines BalancedDelimiterTracker &Tracker, ColonProtectionRAIIObject &ColonProt); 140460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCompoundLiteralExpression(ParsedType Ty, 1405d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation LParenLoc, 1406d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation RParenLoc); 14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 140899831e4677a7e2e051af636221694d60ba31fcdbRichard Smith ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral = false); 1409eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1410f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult ParseGenericSelectionExpression(); 1411ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 1412ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCBoolLiteral(); 1413f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1414eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 1415eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // C++ Expressions 141660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); 14174bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis 141819a2702042b7e3ee838cca458b35f607111a3897Richard Smith bool areTokensAdjacent(const Token &A, const Token &B); 141919a2702042b7e3ee838cca458b35f607111a3897Richard Smith 1420950be71c745409e373ae8a834490f9026c8ac222Richard Trieu void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr, 1421950be71c745409e373ae8a834490f9026c8ac222Richard Trieu bool EnteringContext, IdentifierInfo &II, 1422950be71c745409e373ae8a834490f9026c8ac222Richard Trieu CXXScopeSpec &SS); 1423950be71c745409e373ae8a834490f9026c8ac222Richard Trieu 14241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 1425b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1426b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor bool EnteringContext, 14276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool *MayBePseudoDestructor = nullptr, 14282db075b1d3b16f0100fe06408dfb4ab7d50700a4Richard Smith bool IsTypename = false, 14296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines IdentifierInfo **LastII = nullptr); 14301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1431919b9557b4f0155dfaaea309493ff2a702fca676Richard Trieu void CheckForLParenAfterColonColon(); 1432919b9557b4f0155dfaaea309493ff2a702fca676Richard Trieu 14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1434ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // C++0x 5.1.2: Lambda expressions 1435ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 1436ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // [...] () -> type {...} 1437ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult ParseLambdaExpression(); 1438ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult TryParseLambdaExpression(); 1439440d456c5cf9613a3ee6a3297f892ddd8da5b8f8Richard Smith Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro, 14406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool *SkippedInits = nullptr); 1441ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor bool TryParseLambdaIntroducer(LambdaIntroducer &Intro); 1442ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult ParseLambdaExpressionAfterIntroducer( 1443ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor LambdaIntroducer &Intro); 1444ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 1445ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor //===--------------------------------------------------------------------===// 14465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 5.2p1: C++ Casts 144760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXCasts(); 14485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1450c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // C++ 5.2p1: C++ Type Identification 145160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeid(); 1452c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 1453c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl //===--------------------------------------------------------------------===// 145401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // C++ : Microsoft __uuidof Expression 145501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult ParseCXXUuidof(); 145601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 145701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet //===--------------------------------------------------------------------===// 1458d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // C++ 5.2.4: C++ Pseudo-Destructor Expressions 145960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, 1460d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor tok::TokenKind OpKind, 1461d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CXXScopeSpec &SS, 1462b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType); 1463d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 1464d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor //===--------------------------------------------------------------------===// 14654cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 9.3.2: C++ 'this' pointer 146660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXThis(); 14674cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 14684cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 146950dd289f45738ed22b7583d52ed2525b927042ffChris Lattner // C++ 15: C++ Throw Expression 147060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseThrowExpression(); 14717acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 147274e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor ExceptionSpecificationType tryParseExceptionSpecification( 14737acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange &SpecificationRange, 1474686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParsedType> &DynamicExceptions, 1475686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceRange> &DynamicExceptionRanges, 1476a058fd4f0a944174295f77169b438510dad389f8Richard Smith ExprResult &NoexceptExpr); 14777acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 1478ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc is filled with the location of the last token of the specification. 14797acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExceptionSpecificationType ParseDynamicExceptionSpecification( 14807acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange &SpecificationRange, 1481686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParsedType> &Exceptions, 1482686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceRange> &Ranges); 148350dd289f45738ed22b7583d52ed2525b927042ffChris Lattner 148450dd289f45738ed22b7583d52ed2525b927042ffChris Lattner //===--------------------------------------------------------------------===// 1485dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // C++0x 8: Function declaration trailing-return-type 1486ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor TypeResult ParseTrailingReturnType(SourceRange &Range); 1487dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 1488dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor //===--------------------------------------------------------------------===// 14895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 2.13.5: C++ Boolean Literals 149060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXBoolLiteral(); 14915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1493987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // C++ 5.2.3: Explicit type conversion (functional notation) 149460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); 1495987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1496987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 1497987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// This should only be called when the current token is known to be part of 1498987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// simple-type-specifier. 1499987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); 1500987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 15012f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); 15022f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 1503987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 15044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // C++ 5.3.4 and 5.3.5: C++ new and delete 1505686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs, 1506ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Declarator &D); 15074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDirectNewDeclarator(Declarator &D); 150860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); 150960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXDeleteExpression(bool UseGlobal, 151059232d35f5820e334b6c8b007ae8006f4390055dChris Lattner SourceLocation Start); 15114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl //===--------------------------------------------------------------------===// 151399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor // C++ if/switch/while condition expression. 151460d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult, 1515586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, bool ConvertToBoolean); 151671b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 151771b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 151812e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor // C++ types 151912e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor 152012e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor //===--------------------------------------------------------------------===// 15215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7.8: Initialization. 15221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15230eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// ParseInitializer 15240eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// initializer: [C99 6.7.8] 15250eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// assignment-expression 15260eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// '{' ... 152760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializer() { 15280eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner if (Tok.isNot(tok::l_brace)) 152920df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ParseAssignmentExpression(); 15300eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner return ParseBraceInitializer(); 15310eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner } 1532b3f323d6c41cb614a249dbc4af7493762786521aDouglas Gregor bool MayBeDesignationStart(); 153360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBraceInitializer(); 153460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializerWithPotentialDesignator(); 15351d922960e083906a586609ac6978678147250177Sebastian Redl 15365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1537296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // clang Expressions 15381d922960e083906a586609ac6978678147250177Sebastian Redl 153960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBlockLiteralExpression(); // ^{...} 1540296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff 1541296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff //===--------------------------------------------------------------------===// 15425508518a2702b00be3b15a26d772bde968972f54Anders Carlsson // Objective-C Expressions 154360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCAtExpression(SourceLocation AtLocation); 154460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCStringLiteral(SourceLocation AtLoc); 1545ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc); 1546ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc); 1547ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc, bool ArgValue); 1548ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc); 1549ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc); 1550eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc); 155160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); 155248f3cc2b2be1d32df14234904539b34e6e387e4aFariborz Jahanian ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); 155360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); 15541b730e847ded503f2e615154035c083c4f94a067Douglas Gregor bool isSimpleObjCMessageExpression(); 155560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpression(); 155660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, 15575cb94a78202ccb1007df0be86884297761f4a53aNico Weber SourceLocation SuperLoc, 15585cb94a78202ccb1007df0be86884297761f4a53aNico Weber ParsedType ReceiverType, 15595cb94a78202ccb1007df0be86884297761f4a53aNico Weber ExprArg ReceiverExpr); 156060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAssignmentExprWithObjCMessageExprStart( 15612725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation LBracloc, SourceLocation SuperLoc, 1562b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, ExprArg ReceiverExpr); 15636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr); 1564ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 15655508518a2702b00be3b15a26d772bde968972f54Anders Carlsson //===--------------------------------------------------------------------===// 15665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.8: Statements and Blocks. 156761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 15684e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer /// A SmallVector of statements, with stack size 32 (as that is the only one 15694e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer /// used.) 15704e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer typedef SmallVector<Stmt*, 32> StmtVector; 15714e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer /// A SmallVector of expressions, with stack size 12 (the maximum used.) 15724e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer typedef SmallVector<Expr*, 12> ExprVector; 15734e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer /// A SmallVector of types. 15744e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer typedef SmallVector<ParsedType, 12> TypeVector; 15754e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer 15766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines StmtResult ParseStatement(SourceLocation *TrailingElseLoc = nullptr); 15776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines StmtResult 15786bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ParseStatementOrDeclaration(StmtVector &Stmts, bool OnlyStatement, 15796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation *TrailingElseLoc = nullptr); 1580534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseStatementOrDeclarationAfterAttributes( 1581534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtVector &Stmts, 1582534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith bool OnlyStatement, 1583534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceLocation *TrailingElseLoc, 1584534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith ParsedAttributesWithRange &Attrs); 1585534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseExprStatement(); 1586534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs); 1587534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseCaseStatement(bool MissingCase = false, 1588bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu ExprResult Expr = ExprResult()); 1589534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseDefaultStatement(); 1590534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseCompoundStatement(bool isStmtExpr = false); 1591534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseCompoundStatement(bool isStmtExpr, 1592bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor unsigned ScopeFlags); 1593a60d21d9ffd2a995c58dc5c5a4e3d9a014e3bc60Lang Hames void ParseCompoundStatementLeadingPragmas(); 159460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCompoundStatementBody(bool isStmtExpr = false); 159560d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseParenExprOrCondition(ExprResult &ExprResult, 1596d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *&DeclResult, 1597586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, 159844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis bool ConvertToBoolean); 1599534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc); 1600534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc); 1601534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc); 1602534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseDoStatement(); 1603534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseForStatement(SourceLocation *TrailingElseLoc); 1604534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseGotoStatement(); 1605534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseContinueStatement(); 1606534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseBreakStatement(); 1607534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseReturnStatement(); 160860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseAsmStatement(bool &msAsm); 16093fedbe1f71c18fba01d39109d606f421a0103a2aEli Friedman StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc); 1610ef8225444452a1486bd721f3285301fe84643b00Stephen Hines StmtResult ParsePragmaLoopHint(StmtVector &Stmts, bool OnlyStatement, 1611ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SourceLocation *TrailingElseLoc, 1612ef8225444452a1486bd721f3285301fe84643b00Stephen Hines ParsedAttributesWithRange &Attrs); 1613a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 16143896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Describes the behavior that should be taken for an __if_exists 16153896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// block. 16163896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor enum IfExistsBehavior { 16173896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Parse the block; this code is always used. 16183896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Parse, 16193896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Skip the block entirely; this code is never used. 16203896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Skip, 16213896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Parse the block as a dependent block, which may be used in 16223896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// some template instantiations but not others. 16233896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Dependent 16243896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor }; 1625a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1626a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// \brief Describes the condition of a Microsoft __if_exists or 16273896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// __if_not_exists block. 16283896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor struct IfExistsCondition { 16293896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The location of the initial keyword. 16303896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor SourceLocation KeywordLoc; 1631a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// \brief Whether this is an __if_exists block (rather than an 16323896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// __if_not_exists block). 16333896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor bool IsIfExists; 1634a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 16353896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Nested-name-specifier preceding the name. 16363896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor CXXScopeSpec SS; 1637a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 16383896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The name we're looking for. 16393896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor UnqualifiedId Name; 16403896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor 16413896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The behavior of this __if_exists or __if_not_exists block 16423896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// should. 16433896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IfExistsBehavior Behavior; 1644534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith }; 1645a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 16463896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result); 16471e862693c63067ae467b0b3884c44f753cd6e821Francois Pichet void ParseMicrosoftIfExistsStatement(StmtVector &Stmts); 1648563a645de82231a55e221fe655b7188bf8369662Francois Pichet void ParseMicrosoftIfExistsExternalDeclaration(); 1649563a645de82231a55e221fe655b7188bf8369662Francois Pichet void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, 1650563a645de82231a55e221fe655b7188bf8369662Francois Pichet AccessSpecifier& CurAS); 16519d24a8be93b28488dbfb9bbe8aa6fe35b21a5b0cFrancois Pichet bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, 16529d24a8be93b28488dbfb9bbe8aa6fe35b21a5b0cFrancois Pichet bool &InitExprsOk); 1653f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names, 1654f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu SmallVectorImpl<Expr *> &Constraints, 1655f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu SmallVectorImpl<Expr *> &Exprs); 1656a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1657a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1658a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // C++ 6: Statements and Blocks 1659a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1660534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseCXXTryBlock(); 1661c4027c82ad4a61f2da1b893ac8fe47bf11e5d50dDavid Blaikie StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc, bool FnTry = false); 1662c4027c82ad4a61f2da1b893ac8fe47bf11e5d50dDavid Blaikie StmtResult ParseCXXCatchBlock(bool FnCatch = false); 1663a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1664a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 166528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley // MS: SEH Statements and Blocks 166628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1667534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseSEHTryBlock(); 166828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHTryBlockCommon(SourceLocation Loc); 166928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHExceptBlock(SourceLocation Loc); 167028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHFinallyBlock(SourceLocation Loc); 1671ef8225444452a1486bd721f3285301fe84643b00Stephen Hines StmtResult ParseSEHLeaveStatement(); 167228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 167328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley //===--------------------------------------------------------------------===// 1674a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // Objective-C Statements 1675a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 167660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCAtStatement(SourceLocation atLoc); 167760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCTryStmt(SourceLocation atLoc); 167860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCThrowStmt(SourceLocation atLoc); 167960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); 1680f85e193739c953358c865005855253af4f68a497John McCall StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc); 1681b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 16825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 16845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7: Declarations. 168567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall 168667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// A context for parsing declaration specifiers. TODO: flesh this 168767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// out, there are other significant restrictions on specifiers than 168867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// would be best implemented in the parser. 168967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall enum DeclSpecContext { 169067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DSC_normal, // normal context 16910efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_class, // class context, enables 'friend' 1692a971d2410fabb093954c4119d2287ac24208ea8dRichard Smith DSC_type_specifier, // C++ type-specifier-seq or C specifier-qualifier-list 16937796eb5643244f3134834253ce5ea89107ac21c1Richard Smith DSC_trailing, // C++11 trailing-type-specifier in a trailing return type 1694651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines DSC_alias_declaration, // C++11 type-specifier-seq in an alias-declaration 1695ef8225444452a1486bd721f3285301fe84643b00Stephen Hines DSC_top_level, // top-level/namespace declaration context 1696ef8225444452a1486bd721f3285301fe84643b00Stephen Hines DSC_template_type_arg // template type argument context 169767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall }; 16981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1699651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// Is this a context in which we are parsing just a type-specifier (or 1700651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// trailing-type-specifier)? 1701651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines static bool isTypeSpecifier(DeclSpecContext DSC) { 1702651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines switch (DSC) { 1703651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case DSC_normal: 1704651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case DSC_class: 1705651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case DSC_top_level: 1706651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return false; 1707651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1708ef8225444452a1486bd721f3285301fe84643b00Stephen Hines case DSC_template_type_arg: 1709651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case DSC_type_specifier: 1710651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case DSC_trailing: 1711651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case DSC_alias_declaration: 1712651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return true; 1713651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 1714651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines llvm_unreachable("Missing DeclSpecContext case"); 1715651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 1716651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1717ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Information on a C++0x for-range-initializer found while parsing a 1718ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// declaration which turns out to be a for-range-declaration. 1719ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith struct ForRangeInit { 1720ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation ColonLoc; 1721ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult RangeExpr; 1722ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 1723ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); } 1724ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith }; 1725ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 1726c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts, 1727c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian unsigned Context, SourceLocation &DeclEnd, 17287f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributesWithRange &attrs); 1729c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts, 1730c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian unsigned Context, 1731bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 17322edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt ParsedAttributesWithRange &attrs, 1733ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool RequireSemi, 17346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ForRangeInit *FRI = nullptr); 17350706df40064d4d7559b4304af79d519033414b84Richard Smith bool MightBeDeclarator(unsigned Context); 173654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, 1737d8ac05753dc4506224d445ff98399c01da3136e5John McCall bool AllowFunctionDefinitions, 17386bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation *DeclEnd = nullptr, 17396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ForRangeInit *FRI = nullptr); 1740d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationAfterDeclarator(Declarator &D, 1741e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1742c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins bool ParseAsmAttributesAfterDeclarator(Declarator &D); 17436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Decl *ParseDeclarationAfterDeclaratorAndAttributes( 17446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Declarator &D, 17456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 17466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ForRangeInit *FRI = nullptr); 1747c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope); 1748c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope); 1749d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 17500fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// \brief When in code-completion, skip parsing of the function/method body 17510fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// unless the body contains the code-completion point. 17520fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// 17530fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// \returns true if the function body was skipped. 17546a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen bool trySkippingFunctionBody(); 17550fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis 1756f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, 17574d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 17582e39713a3d72c243a2bcd13cc8f5036ba6b487d9Michael Han AccessSpecifier AS, DeclSpecContext DSC, 17592e39713a3d72c243a2bcd13cc8f5036ba6b487d9Michael Han ParsedAttributesWithRange &Attrs); 17600efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); 17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseDeclarationSpecifiers(DeclSpec &DS, 17624d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 176367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall AccessSpecifier AS = AS_none, 17642287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins DeclSpecContext DSC = DSC_normal, 17656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines LateParsedAttrList *LateAttrs = nullptr); 1766f0cc19f43d5e05dbd22d00faca8c093b7005be3fBill Wendling bool DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS, AccessSpecifier AS, 17676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines DeclSpecContext DSContext, 17686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines LateParsedAttrList *LateAttrs = nullptr); 17694d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 177069730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith void ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS = AS_none, 177169730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith DeclSpecContext DSC = DSC_normal); 17721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1773cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall void ParseObjCTypeQualifierList(ObjCDeclSpec &DS, 1774cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Declarator::TheContext Context); 17755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17764c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, 177769730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith const ParsedTemplateInfo &TemplateInfo, 177869730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith AccessSpecifier AS, DeclSpecContext DSC); 1779d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl); 17805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, 1781d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 1782bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1783bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct FieldCallback { 1784dcdff46dd8e6d749283fe6c43adfcfe780c1d562Eli Friedman virtual void invoke(ParsingFieldDeclarator &Field) = 0; 17856c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual ~FieldCallback() {} 17866c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall 17876c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall private: 17886c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual void _anchor(); 1789bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall }; 1790d0014540005f2a5ab837365db6bd40f479406758John McCall struct ObjCPropertyCallback; 1791bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1792f66a0dda541cd859a928193efba6dc5d7ba8fe54Eli Friedman void ParseStructDeclaration(ParsingDeclSpec &DS, FieldCallback &Callback); 17931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17949497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false); 1795eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isTypeSpecifierQualifier(); 17965f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff bool isTypeQualifier() const; 1797a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1798b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// isKnownToBeTypeSpecifier - Return true if we know that the specified token 1799b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// is definitely a type-specifier. Return false if it isn't part of a type 1800b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// specifier or if we're not sure. 1801b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool isKnownToBeTypeSpecifier(const Token &Tok) const; 18025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18034b0824229b96d024a96f3c7dd75ab70652c05c5bRichard Smith /// \brief Return true if we know that we are definitely looking at a 18044b0824229b96d024a96f3c7dd75ab70652c05c5bRichard Smith /// decl-specifier, and isn't part of an expression such as a function-style 18054b0824229b96d024a96f3c7dd75ab70652c05c5bRichard Smith /// cast. Return false if it's no a decl-specifier, or we're not sure. 18064b0824229b96d024a96f3c7dd75ab70652c05c5bRichard Smith bool isKnownToBeDeclarationSpecifier() { 18074b0824229b96d024a96f3c7dd75ab70652c05c5bRichard Smith if (getLangOpts().CPlusPlus) 18086bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return isCXXDeclarationSpecifier() == TPResult::True; 18094b0824229b96d024a96f3c7dd75ab70652c05c5bRichard Smith return isDeclarationSpecifier(true); 18104b0824229b96d024a96f3c7dd75ab70652c05c5bRichard Smith } 18114b0824229b96d024a96f3c7dd75ab70652c05c5bRichard Smith 18125404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isDeclarationStatement - Disambiguates between a declaration or an 18135404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// expression statement, when parsing function bodies. 18145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for declaration, false for expression. 18155404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isDeclarationStatement() { 18164e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 18175404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isCXXDeclarationStatement(); 18189497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return isDeclarationSpecifier(true); 18195404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 18205404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 18219490ab433deef70105d817616928d700f87642d9Eli Friedman /// isForInitDeclaration - Disambiguates between a declaration or an 18229490ab433deef70105d817616928d700f87642d9Eli Friedman /// expression in the context of the C 'clause-1' or the C++ 1823bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis // 'for-init-statement' part of a 'for' statement. 1824bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// Returns true for declaration, false for expression. 18259490ab433deef70105d817616928d700f87642d9Eli Friedman bool isForInitDeclaration() { 18264e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 18279490ab433deef70105d817616928d700f87642d9Eli Friedman return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/true); 18289497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return isDeclarationSpecifier(true); 1829bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis } 1830bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis 1831ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// \brief Determine whether this is a C++1z for-range-identifier. 1832ef8225444452a1486bd721f3285301fe84643b00Stephen Hines bool isForRangeIdentifier(); 1833ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 18349497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor /// \brief Determine whether we are currently at the start of an Objective-C 18359497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor /// class message that appears to be missing the open bracket '['. 18369497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor bool isStartOfObjCClassMessageMissingOpenBracket(); 1837a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 18380efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief Starting with a scope specifier, identifier, or 18390efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id that refers to the current class, determine whether 18400efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// this is a constructor declarator. 1841651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool isConstructorDeclarator(bool Unqualified); 18420efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 18438b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// \brief Specifies the context in which type-id/expression 18448b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// disambiguation will occur. 18458b642592a35167a3780074e78674e0bece87c40cDouglas Gregor enum TentativeCXXTypeIdContext { 18468b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdInParens, 1847651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines TypeIdUnambiguous, 18488b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdAsTemplateArgument 18498b642592a35167a3780074e78674e0bece87c40cDouglas Gregor }; 18508b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 18518b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 185278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know 185378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// whether the parens contain an expression or a type-id. 185478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// Returns true for a type-id and false for an expression. 1855f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens(bool &isAmbiguous) { 18564e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 1857f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(TypeIdInParens, isAmbiguous); 1858f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis isAmbiguous = false; 185978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis return isTypeSpecifierQualifier(); 186078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis } 1861f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens() { 1862f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1863f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isTypeIdInParens(isAmbiguous); 1864f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 186578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 1866651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Checks if the current tokens form type-id or expression. 1867651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// It is similar to isTypeIdInParens but does not suppose that type-id 1868651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// is in parenthesis. 1869651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool isTypeIdUnambiguously() { 1870651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool IsAmbiguous; 1871651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (getLangOpts().CPlusPlus) 1872651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous); 1873651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return isTypeSpecifierQualifier(); 1874651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 1875651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 18765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXDeclarationStatement - C++-specialized function that disambiguates 18775404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a declaration or an expression statement, when parsing function 18785404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// bodies. Returns true for declaration, false for expression. 18795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXDeclarationStatement(); 18805404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 18815404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXSimpleDeclaration - C++-specialized function that disambiguates 18825404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a simple-declaration or an expression-statement. 18835404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 18845404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 18855404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns false if the statement is disambiguated as expression. 18869490ab433deef70105d817616928d700f87642d9Eli Friedman bool isCXXSimpleDeclaration(bool AllowForRangeDecl); 18875404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 18885404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXFunctionDeclarator - Disambiguates between a function declarator or 18895404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// a constructor-style initializer, when parsing declaration statements. 18905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for function declarator and false for constructor-style 1891b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith /// initializer. Sets 'IsAmbiguous' to true to indicate that this declaration 1892b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith /// might be a constructor-style initializer. 18935404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 18945404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 18956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isCXXFunctionDeclarator(bool *IsAmbiguous = nullptr); 18965404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1897a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// isCXXConditionDeclaration - Disambiguates between a declaration or an 1898a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// expression for a condition of a if/switch/while/for statement. 1899a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 1900a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1901a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis bool isCXXConditionDeclaration(); 1902a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis 1903f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); 1904f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context) { 1905f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1906f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(Context, isAmbiguous); 1907f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 190878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 1909b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult - Used as the result value for functions whose purpose is to 1910b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// disambiguate C++ constructs by "tentatively parsing" them. 19116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines enum class TPResult { 19126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines True, False, Ambiguous, Error 1913b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis }; 1914b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis 1915a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// \brief Based only on the given token kind, determine whether we know that 1916a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// we're at the start of an expression or a type-specifier-seq (which may 1917a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// be an expression, in C++). 1918a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// 1919a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// This routine does not attempt to resolve any of the trick cases, e.g., 1920a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// those involving lookup of identifiers. 1921a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// 1922a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// \returns \c TPR_true if this token starts an expression, \c TPR_false if 1923a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot 1924a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// tell. 1925a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind); 1926a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor 19276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// isCXXDeclarationSpecifier - Returns TPResult::True if it is a 19286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// declaration specifier, TPResult::False if it is not, 19296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// TPResult::Ambiguous if it could be either a decl-specifier or a 19306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// function-style cast, and TPResult::Error if a parsing error was 1931d81e961f905e3ea57f6808e5a5686a8324270984Richard Smith /// encountered. If it could be a braced C++11 function-style cast, returns 1932d81e961f905e3ea57f6808e5a5686a8324270984Richard Smith /// BracedCastResult. 19335404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Doesn't consume tokens. 1934d81e961f905e3ea57f6808e5a5686a8324270984Richard Smith TPResult 19356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines isCXXDeclarationSpecifier(TPResult BracedCastResult = TPResult::False, 19366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool *HasMissingTypename = nullptr); 1937a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 19389bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith /// Given that isCXXDeclarationSpecifier returns \c TPResult::True or 19399bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith /// \c TPResult::Ambiguous, determine whether the decl-specifier would be 19409bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith /// a type-specifier other than a cv-qualifier. 19419bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith bool isCXXDeclarationSpecifierAType(); 19429bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith 19430576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// \brief Determine whether an identifier has been tentatively declared as a 19440576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// non-type. Such tentative declarations should not be found to name a type 19450576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// during a tentative parse, but also should not be annotated as a non-type. 19460576681bac125be07f77f66b02a3dba2c3a24557Richard Smith bool isTentativelyDeclared(IdentifierInfo *II); 19470576681bac125be07f77f66b02a3dba2c3a24557Richard Smith 19485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // "Tentative parsing" functions, used for disambiguation. If a parsing error 19496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // is encountered they will return TPResult::Error. 19506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // Returning TPResult::True/False indicates that the ambiguity was 19516bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines // resolved and tentative parsing may stop. TPResult::Ambiguous indicates 1952b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // that more tentative parsing is necessary for disambiguation. 19535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // They all consume tokens, so backtracking should be used after calling them. 19545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 19559490ab433deef70105d817616928d700f87642d9Eli Friedman TPResult TryParseSimpleDeclaration(bool AllowForRangeDecl); 1956b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseTypeofSpecifier(); 19579bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor TPResult TryParseProtocolQualifiers(); 19589bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith TPResult TryParsePtrOperatorSeq(); 19599bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith TPResult TryParseOperatorId(); 1960b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseInitDeclaratorList(); 196178c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); 19626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines TPResult 19636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines TryParseParameterDeclarationClause(bool *InvalidAsDeclaration = nullptr, 19646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool VersusTemplateArg = false); 1965b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseFunctionDeclarator(); 1966b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseBracketDeclarator(); 19679bd3cdc3b78653275a36f15df81e1def3b2db8dbRichard Smith TPResult TryConsumeDeclarationSpecifier(); 19685404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 19696944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannpublic: 19706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines TypeResult ParseTypeName(SourceRange *Range = nullptr, 1971683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Declarator::TheContext Context 1972f85e193739c953358c865005855253af4f68a497John McCall = Declarator::TypeNameContext, 1973c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith AccessSpecifier AS = AS_none, 19746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Decl **OwnedType = nullptr, 19756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ParsedAttributes *Attrs = nullptr); 19766944e20065955414a56a6aab9b7e271e3e826a88Axel Naumann 19776944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannprivate: 197803f1eb031b84e93415b792c4b45d8da71c88e92dDouglas Gregor void ParseBlockId(SourceLocation CaretLoc); 19797f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 19806ee326af4e77e6f05973486097884d7431f2108dRichard Smith // Check for the start of a C++11 attribute-specifier-seq in a context where 19816ee326af4e77e6f05973486097884d7431f2108dRichard Smith // an attribute is not allowed. 19826ee326af4e77e6f05973486097884d7431f2108dRichard Smith bool CheckProhibitedCXX11Attribute() { 19836ee326af4e77e6f05973486097884d7431f2108dRichard Smith assert(Tok.is(tok::l_square)); 198480ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith if (!getLangOpts().CPlusPlus11 || NextToken().isNot(tok::l_square)) 19856ee326af4e77e6f05973486097884d7431f2108dRichard Smith return false; 19866ee326af4e77e6f05973486097884d7431f2108dRichard Smith return DiagnoseProhibitedCXX11Attribute(); 19876ee326af4e77e6f05973486097884d7431f2108dRichard Smith } 19886ee326af4e77e6f05973486097884d7431f2108dRichard Smith bool DiagnoseProhibitedCXX11Attribute(); 1989053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith void CheckMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs, 1990053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith SourceLocation CorrectLocation) { 1991053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith if (!getLangOpts().CPlusPlus11) 1992053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith return; 1993053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith if ((Tok.isNot(tok::l_square) || NextToken().isNot(tok::l_square)) && 1994053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith Tok.isNot(tok::kw_alignas)) 1995053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith return; 1996053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation); 1997053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith } 1998053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith void DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs, 1999053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith SourceLocation CorrectLocation); 20006ee326af4e77e6f05973486097884d7431f2108dRichard Smith 20017f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ProhibitAttributes(ParsedAttributesWithRange &attrs) { 20027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (!attrs.Range.isValid()) return; 20037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DiagnoseProhibitedAttributes(attrs); 2004534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith attrs.clear(); 20057f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 20067f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs); 20077f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 2008f64231e9f47234826fbcdc3b4fe0370ef6c9961dMichael Han // Forbid C++11 attributes that appear on certain syntactic 2009f64231e9f47234826fbcdc3b4fe0370ef6c9961dMichael Han // locations which standard permits but we don't supported yet, 2010f64231e9f47234826fbcdc3b4fe0370ef6c9961dMichael Han // for example, attributes appertain to decl specifiers. 2011f64231e9f47234826fbcdc3b4fe0370ef6c9961dMichael Han void ProhibitCXX11Attributes(ParsedAttributesWithRange &attrs); 2012f64231e9f47234826fbcdc3b4fe0370ef6c9961dMichael Han 2013ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// \brief Skip C++11 attributes and return the end location of the last one. 2014ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// \returns SourceLocation() if there are no attributes. 2015ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SourceLocation SkipCXX11Attributes(); 2016ef8225444452a1486bd721f3285301fe84643b00Stephen Hines 20175eed7e00b4ac8d589ca83e126dafa8767e8a0358Richard Smith /// \brief Diagnose and skip C++11 attributes that appear in syntactic 20185eed7e00b4ac8d589ca83e126dafa8767e8a0358Richard Smith /// locations where attributes are not allowed. 20195eed7e00b4ac8d589ca83e126dafa8767e8a0358Richard Smith void DiagnoseAndSkipCXX11Attributes(); 20205eed7e00b4ac8d589ca83e126dafa8767e8a0358Richard Smith 2021651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Parses syntax-generic attribute arguments for attributes which are 2022651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// known to the implementation, and adds them to the given ParsedAttributes 20236bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// list with the given attribute syntax. Returns the number of arguments 20246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// parsed for the attribute. 20256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines unsigned 20266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc, 20276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ParsedAttributes &Attrs, SourceLocation *EndLoc, 20286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines IdentifierInfo *ScopeName, SourceLocation ScopeLoc, 20296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines AttributeList::Syntax Syntax); 2030651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 2031eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void MaybeParseGNUAttributes(Declarator &D, 20326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines LateParsedAttrList *LateAttrs = nullptr) { 20337f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (Tok.is(tok::kw___attribute)) { 20340b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 20357f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation endLoc; 2036651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ParseGNUAttributes(attrs, &endLoc, LateAttrs, &D); 20370b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall D.takeAttributes(attrs, endLoc); 20387f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 20397f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 20407f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseGNUAttributes(ParsedAttributes &attrs, 20416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation *endLoc = nullptr, 20426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines LateParsedAttrList *LateAttrs = nullptr) { 20437f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (Tok.is(tok::kw___attribute)) 2044eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski ParseGNUAttributes(attrs, endLoc, LateAttrs); 20457f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 20467f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseGNUAttributes(ParsedAttributes &attrs, 20476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation *endLoc = nullptr, 20486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines LateParsedAttrList *LateAttrs = nullptr, 20496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Declarator *D = nullptr); 2050eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void ParseGNUAttributeArgs(IdentifierInfo *AttrName, 2051eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation AttrNameLoc, 2052eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski ParsedAttributes &Attrs, 20536880f492365cc4fa4c941aa83688635003ee7498Michael Han SourceLocation *EndLoc, 20546880f492365cc4fa4c941aa83688635003ee7498Michael Han IdentifierInfo *ScopeName, 20556880f492365cc4fa4c941aa83688635003ee7498Michael Han SourceLocation ScopeLoc, 2056651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines AttributeList::Syntax Syntax, 2057651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Declarator *D); 20588edabd95dd4c9099fd124c5e50322730b9200d23Richard Smith IdentifierLoc *ParseIdentifierLoc(); 20597f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 20604e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith void MaybeParseCXX11Attributes(Declarator &D) { 206180ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { 20620b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrs(AttrFactory); 20637f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation endLoc; 2064c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith ParseCXX11Attributes(attrs, &endLoc); 20650b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall D.takeAttributes(attrs, endLoc); 20667f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 20677f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 20684e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith void MaybeParseCXX11Attributes(ParsedAttributes &attrs, 20696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation *endLoc = nullptr) { 207080ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { 20710b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrsWithRange(AttrFactory); 2072c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith ParseCXX11Attributes(attrsWithRange, endLoc); 20730b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall attrs.takeAllFrom(attrsWithRange); 20747f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 20757f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 20764e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith void MaybeParseCXX11Attributes(ParsedAttributesWithRange &attrs, 20776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation *endLoc = nullptr, 20786ee326af4e77e6f05973486097884d7431f2108dRichard Smith bool OuterMightBeMessageSend = false) { 207980ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith if (getLangOpts().CPlusPlus11 && 20806ee326af4e77e6f05973486097884d7431f2108dRichard Smith isCXX11AttributeSpecifier(false, OuterMightBeMessageSend)) 2081c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith ParseCXX11Attributes(attrs, endLoc); 20827f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 20833497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne 2084c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs, 20856bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation *EndLoc = nullptr); 2086c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith void ParseCXX11Attributes(ParsedAttributesWithRange &attrs, 20876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation *EndLoc = nullptr); 2088651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Parses a C++-style attribute argument list. Returns true if this 2089651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// results in adding an attribute to the ParsedAttributes list. 2090651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName, 2091651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SourceLocation AttrNameLoc, 2092651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ParsedAttributes &Attrs, SourceLocation *EndLoc, 2093651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines IdentifierInfo *ScopeName, 2094651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SourceLocation ScopeLoc); 20956880f492365cc4fa4c941aa83688635003ee7498Michael Han 2096c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc); 20977f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 20987f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs, 20996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation *endLoc = nullptr) { 21004e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().MicrosoftExt && Tok.is(tok::l_square)) 21017f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseMicrosoftAttributes(attrs, endLoc); 21027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 21037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseMicrosoftAttributes(ParsedAttributes &attrs, 21046bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation *endLoc = nullptr); 2105fc685ace387734599c475426b1a8efdb491054b8Aaron Ballman void ParseMicrosoftDeclSpec(ParsedAttributes &Attrs); 2106651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName, 2107651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SourceLocation AttrNameLoc, 2108651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ParsedAttributes &Attrs); 21097f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs); 2110c052dbb2d8fe0e23e90d81236aab0f864f712b45John McCall void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs); 21117f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseBorlandTypeAttributes(ParsedAttributes &attrs); 2112f315fa81eef1977b3457fd7a7d4639e060fe7278Peter Collingbourne void ParseOpenCLAttributes(ParsedAttributes &attrs); 2113651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void ParseOpenCLQualifiers(ParsedAttributes &Attrs); 21147f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 21150a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor VersionTuple ParseVersionTuple(SourceRange &Range); 21160a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor void ParseAvailabilityAttribute(IdentifierInfo &Availability, 21170a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor SourceLocation AvailabilityLoc, 21180a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor ParsedAttributes &attrs, 21190a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor SourceLocation *endLoc); 2120651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 2121651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated, 2122651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SourceLocation ObjCBridgeRelatedLoc, 2123651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ParsedAttributes &attrs, 2124651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SourceLocation *endLoc); 2125b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski 21260d5a069f66df09b3308ccfdce84a88170034c657Dmitri Gribenko void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName, 21270d5a069f66df09b3308ccfdce84a88170034c657Dmitri Gribenko SourceLocation AttrNameLoc, 21280d5a069f66df09b3308ccfdce84a88170034c657Dmitri Gribenko ParsedAttributes &Attrs, 21290d5a069f66df09b3308ccfdce84a88170034c657Dmitri Gribenko SourceLocation *EndLoc); 2130b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski 2131d386fef64f1fd00fc9a97efb963d8ec393fd1aceRichard Smith void ParseAttributeWithTypeArg(IdentifierInfo &AttrName, 2132d386fef64f1fd00fc9a97efb963d8ec393fd1aceRichard Smith SourceLocation AttrNameLoc, 2133d386fef64f1fd00fc9a97efb963d8ec393fd1aceRichard Smith ParsedAttributes &Attrs, 2134d386fef64f1fd00fc9a97efb963d8ec393fd1aceRichard Smith SourceLocation *EndLoc); 2135d386fef64f1fd00fc9a97efb963d8ec393fd1aceRichard Smith 2136d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff void ParseTypeofSpecifier(DeclSpec &DS); 213742d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation ParseDecltypeSpecifier(DeclSpec &DS); 2138534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS, 213942d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation StartLoc, 214042d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation EndLoc); 2141db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt void ParseUnderlyingTypeSpecifier(DeclSpec &DS); 2142b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void ParseAtomicSpecifier(DeclSpec &DS); 2143b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 21440b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne ExprResult ParseAlignArgument(SourceLocation Start, 21450b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne SourceLocation &EllipsisLoc); 214682d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne void ParseAlignmentSpecifier(ParsedAttributes &Attrs, 21476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation *endLoc = nullptr); 2148eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 21494e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith VirtSpecifiers::Specifier isCXX11VirtSpecifier(const Token &Tok) const; 21504e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith VirtSpecifiers::Specifier isCXX11VirtSpecifier() const { 21514e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith return isCXX11VirtSpecifier(Tok); 21521c94c16317c1a35c1549e022958188eea2567089Richard Smith } 21534e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, bool IsInterface); 21541f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 21554e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith bool isCXX11FinalKeyword() const; 2156cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 2157eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to 2158eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// enter a new C++ declarator scope and exit it when the function is 2159eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// finished. 2160eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis class DeclaratorScopeObj { 2161eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis Parser &P; 2162751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis CXXScopeSpec &SS; 2163f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis bool EnteredScope; 2164f7f3d0db754db0500b56d49ac19f795f13965912John McCall bool CreatedScope; 2165eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis public: 2166f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) 2167f7f3d0db754db0500b56d49ac19f795f13965912John McCall : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} 2168eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 2169eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis void EnterDeclaratorScope() { 21702bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis assert(!EnteredScope && "Already entered the scope!"); 2171f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was not set!"); 2172f7f3d0db754db0500b56d49ac19f795f13965912John McCall 2173f7f3d0db754db0500b56d49ac19f795f13965912John McCall CreatedScope = true; 2174f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.EnterScope(0); // Not a decl scope. 2175f7f3d0db754db0500b56d49ac19f795f13965912John McCall 217623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS)) 21773fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor EnteredScope = true; 2178eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 2179eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 2180eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis ~DeclaratorScopeObj() { 2181f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis if (EnteredScope) { 2182f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was cleared ?"); 218323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS); 2184f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis } 2185f7f3d0db754db0500b56d49ac19f795f13965912John McCall if (CreatedScope) 2186f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.ExitScope(); 2187eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 2188eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis }; 21891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseDeclarator - Parse and verify a newly-initialized declarator. 21915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDeclarator(Declarator &D); 21924c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl /// A function that parses a variant of direct-declarator. 21934c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef void (Parser::*DirectDeclParseFunction)(Declarator&); 21944c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDeclaratorInternal(Declarator &D, 21954c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl DirectDeclParseFunction DirectDeclParser); 21967f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 2197bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, 21984cf4a5e96ab0babd13774b17112e7c1d83042ea7Richard Smith bool CXX11AttributesAllowed = true, 21997f3ec66c405045ae67abf54f728845f36e91baa9Bill Wendling bool AtomicAllowed = true, 22007f3ec66c405045ae67abf54f728845f36e91baa9Bill Wendling bool IdentifierRequired = false); 22015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDirectDeclarator(Declarator &D); 22025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseParenDeclarator(Declarator &D); 22034a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor void ParseFunctionDeclarator(Declarator &D, 22047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs, 22054a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker, 2206b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith bool IsAmbiguous, 22077399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner bool RequiresArg = false); 22083fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor bool isFunctionDeclaratorIdentifierList(); 22093fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor void ParseFunctionDeclaratorIdentifierList( 22103fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor Declarator &D, 22116b9240e058bf3451685df73fc8ce181b3046e92bCraig Topper SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo); 22123fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor void ParseParameterDeclarationClause( 22133fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor Declarator &D, 22143fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor ParsedAttributes &attrs, 22156b9240e058bf3451685df73fc8ce181b3046e92bCraig Topper SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo, 22163fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor SourceLocation &EllipsisLoc); 22175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseBracketDeclarator(Declarator &D); 2218ef8225444452a1486bd721f3285301fe84643b00Stephen Hines void ParseMisplacedBracketDeclarator(Declarator &D); 22191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22208f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner //===--------------------------------------------------------------------===// 22218f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner // C++ 7: Declarations [dcl.dcl] 22221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22236ee326af4e77e6f05973486097884d7431f2108dRichard Smith /// The kind of attribute specifier we have found. 22246ee326af4e77e6f05973486097884d7431f2108dRichard Smith enum CXX11AttributeKind { 22256ee326af4e77e6f05973486097884d7431f2108dRichard Smith /// This is not an attribute specifier. 22266ee326af4e77e6f05973486097884d7431f2108dRichard Smith CAK_NotAttributeSpecifier, 22276ee326af4e77e6f05973486097884d7431f2108dRichard Smith /// This should be treated as an attribute-specifier. 22286ee326af4e77e6f05973486097884d7431f2108dRichard Smith CAK_AttributeSpecifier, 22296ee326af4e77e6f05973486097884d7431f2108dRichard Smith /// The next tokens are '[[', but this is not an attribute-specifier. This 22306ee326af4e77e6f05973486097884d7431f2108dRichard Smith /// is ill-formed by C++11 [dcl.attr.grammar]p6. 22316ee326af4e77e6f05973486097884d7431f2108dRichard Smith CAK_InvalidAttributeSpecifier 22326ee326af4e77e6f05973486097884d7431f2108dRichard Smith }; 22336ee326af4e77e6f05973486097884d7431f2108dRichard Smith CXX11AttributeKind 22346ee326af4e77e6f05973486097884d7431f2108dRichard Smith isCXX11AttributeSpecifier(bool Disambiguate = false, 22356ee326af4e77e6f05973486097884d7431f2108dRichard Smith bool OuterMightBeMessageSend = false); 2236a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 22377faf81ff1dc8f8dc724e928ba90ccbfad0fdc2bcRichard Smith void DiagnoseUnexpectedNamespace(NamedDecl *Context); 2238b310439121c875937d78cc49cc969bc1197fc025Richard Smith 2239d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd, 2240d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation InlineLoc = SourceLocation()); 2241f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc, 2242f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<IdentifierInfo*>& Ident, 2243f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<SourceLocation>& NamespaceLoc, 2244f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu unsigned int index, SourceLocation& InlineLoc, 22454a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor ParsedAttributes& attrs, 22464a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker); 2247d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context); 2248d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseUsingDirectiveOrDeclaration(unsigned Context, 224978b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 2250d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 2251c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith ParsedAttributesWithRange &attrs, 22526bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Decl **OwnedType = nullptr); 225378b810559d89e996e00684335407443936ce34a1John McCall Decl *ParseUsingDirective(unsigned Context, 225478b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 22557f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation &DeclEnd, 22567f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs); 225778b810559d89e996e00684335407443936ce34a1John McCall Decl *ParseUsingDeclaration(unsigned Context, 225878b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 225978b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 2260d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 2261c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith AccessSpecifier AS = AS_none, 22626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Decl **OwnedType = nullptr); 2263d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd); 2264d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc, 2265d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation AliasLoc, IdentifierInfo *Alias, 2266d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd); 22671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2268e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 2269e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 9: classes [class] and C structs/unions. 2270139be7007eba3bd491ca50297888be507753a95dRichard Smith bool isValidAfterTypeSpecifier(bool CouldBeBitfield); 22714c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, 227269730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo, 227369730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith AccessSpecifier AS, bool EnteringContext, 22742e39713a3d72c243a2bcd13cc8f5036ba6b487d9Michael Han DeclSpecContext DSC, 2275ad017fa7a4df7389d245d02a49b3c79ed70bedb9Bill Wendling ParsedAttributesWithRange &Attributes); 227607fc1ba7553f2f5bf26984091197311decd9028eMichael Han void ParseCXXMemberSpecification(SourceLocation StartLoc, 227707fc1ba7553f2f5bf26984091197311decd9028eMichael Han SourceLocation AttrFixitLoc, 2278053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith ParsedAttributesWithRange &Attrs, 227907fc1ba7553f2f5bf26984091197311decd9028eMichael Han unsigned TagType, 2280d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 2281552e29985a710f4ced62b39d70557501bd31ca9bDouglas Gregor ExprResult ParseCXXMemberInitializer(Decl *D, bool IsFunction, 22827a614d8380297fcd2bc23986241905d97222948cRichard Smith SourceLocation &EqualLoc); 2283651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo, 2284651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines VirtSpecifiers &VS, 2285651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ExprResult &BitfieldSize, 2286651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines LateParsedAttrList &LateAttrs); 22875f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen void ParseCXXClassMemberDeclaration(AccessSpecifier AS, AttributeList *Attr, 22886bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 22896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines ParsingDeclRAIIObject *DiagsFromTParams = nullptr); 2290d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseConstructorInitializer(Decl *ConstructorDecl); 2291d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall MemInitResult ParseMemInitializer(Decl *ConstructorDecl); 229274e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo, 229374e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor Decl *ThisDecl); 2294e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 2295e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 2296e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 10: Derived classes [class.derived] 2297a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc, 229822216eb4fb0936d2488fc03abd285d135c36ff01David Blaikie SourceLocation &EndLocation); 2299d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseBaseClause(Decl *ClassDecl); 2300d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall BaseResult ParseBaseSpecifier(Decl *ClassDecl); 23011b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor AccessSpecifier getAccessSpecifierIfPresent() const; 23021cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor 2303a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 2304e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 23053f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Name, 23063f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation NameLoc, 23073f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool EnteringContext, 2308b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2309d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor UnqualifiedId &Id, 2310e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool AssumeTemplateId); 2311ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, 2312b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2313ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &Result); 23146944e20065955414a56a6aab9b7e271e3e826a88Axel Naumann 2315c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev //===--------------------------------------------------------------------===// 2316c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev // OpenMP: Directives and clauses. 23176af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev /// \brief Parses declarative OpenMP directives. 2318c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev DeclGroupPtrTy ParseOpenMPDeclarativeDirective(); 23196af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev /// \brief Parses simple list of variables. 23206af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev /// 23216af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev /// \param Kind Kind of the directive. 23226af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev /// \param [out] VarList List of referenced variables. 23236af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev /// \param AllowScopeSpecifier true, if the variables can have fully 23246af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev /// qualified names. 23256af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev /// 2326c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev bool ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, 23276af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev SmallVectorImpl<Expr *> &VarList, 23286af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev bool AllowScopeSpecifier); 23294fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// \brief Parses declarative or executable directive. 23304fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev StmtResult ParseOpenMPDeclarativeOrExecutableDirective(); 23314fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// \brief Parses clause of kind \a CKind for directive of a kind \a Kind. 23324fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// 23334fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// \param DKind Kind of current directive. 23344fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// \param CKind Kind of current clause. 23354fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// \param FirstClause true, if this is the first clause of a kind \a CKind 23364fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// in current directive. 23374fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// 23384fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind, 23394fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev OpenMPClauseKind CKind, bool FirstClause); 23404fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// \brief Parses clause with a single expression of a kind \a Kind. 23414fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// 23424fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// \param Kind Kind of current clause. 23434fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// 23444fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev OMPClause *ParseOpenMPSingleExprClause(OpenMPClauseKind Kind); 23454fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// \brief Parses simple clause of a kind \a Kind. 23464fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// 23474fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// \param Kind Kind of current clause. 23484fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// 23494fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev OMPClause *ParseOpenMPSimpleClause(OpenMPClauseKind Kind); 2350ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// \brief Parses clause with a single expression and an additional argument 2351ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// of a kind \a Kind. 2352ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// 2353ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// \param Kind Kind of current clause. 2354ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// 2355ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind); 2356ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// \brief Parses clause without any additional arguments. 2357ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// 2358ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// \param Kind Kind of current clause. 2359ef8225444452a1486bd721f3285301fe84643b00Stephen Hines /// 2360ef8225444452a1486bd721f3285301fe84643b00Stephen Hines OMPClause *ParseOpenMPClause(OpenMPClauseKind Kind); 23614fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// \brief Parses clause with the list of variables of a kind \a Kind. 23624fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// 23634fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// \param Kind Kind of current clause. 23644fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev /// 23654fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev OMPClause *ParseOpenMPVarListClause(OpenMPClauseKind Kind); 23666944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannpublic: 23673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, 236802a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowDestructorName, 236902a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowConstructorName, 2370b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2371e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation& TemplateKWLoc, 23723f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &Result); 2373a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 23746944e20065955414a56a6aab9b7e271e3e826a88Axel Naumannprivate: 23751cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor //===--------------------------------------------------------------------===// 2376adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14: Templates [temp] 2377c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 2378adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14.1: Template Parameters [temp.param] 2379d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationStartingWithTemplate(unsigned Context, 23806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation &DeclEnd, 23816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines AccessSpecifier AS = AS_none, 23826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines AttributeList *AccessAttrs = nullptr); 2383d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context, 23845f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen SourceLocation &DeclEnd, 23855f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AccessSpecifier AS, 23865f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AttributeList *AccessAttrs); 2387d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseSingleDeclarationAfterTemplate( 23881426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor unsigned Context, 23894d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 2390c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject &DiagsFromParams, 23911426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor SourceLocation &DeclEnd, 23925f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AccessSpecifier AS=AS_none, 23936bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines AttributeList *AccessAttrs = nullptr); 23941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseTemplateParameters(unsigned Depth, 2395686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Decl*> &TemplateParams, 23961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation &LAngleLoc, 2397c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor SourceLocation &RAngleLoc); 2398c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor bool ParseTemplateParameterList(unsigned Depth, 2399686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Decl*> &TemplateParams); 240098440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor bool isStartOfTemplateTypeParameter(); 2401d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateParameter(unsigned Depth, unsigned Position); 2402d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTypeParameter(unsigned Depth, unsigned Position); 2403d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); 2404d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); 2405ef8225444452a1486bd721f3285301fe84643b00Stephen Hines void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc, 2406ef8225444452a1486bd721f3285301fe84643b00Stephen Hines SourceLocation CorrectLoc, 2407ef8225444452a1486bd721f3285301fe84643b00Stephen Hines bool AlreadyHasEllipsis, 2408ef8225444452a1486bd721f3285301fe84643b00Stephen Hines bool IdentifierHasName); 2409ef8225444452a1486bd721f3285301fe84643b00Stephen Hines void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc, 2410ef8225444452a1486bd721f3285301fe84643b00Stephen Hines Declarator &D); 2411d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor // C++ 14.3: Template arguments [temp.arg] 2412686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList; 2413cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 2414b707a4762fcc47c12b5f487856ba0781c9399295Nico Weber bool ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc, 2415b707a4762fcc47c12b5f487856ba0781c9399295Nico Weber bool ConsumeLastToken); 24167532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor bool ParseTemplateIdAfterTemplateName(TemplateTy Template, 24171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateNameLoc, 2418059101f922de6eb765601459925f4c8914420b23Douglas Gregor const CXXScopeSpec &SS, 2419cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor bool ConsumeLastToken, 2420cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &LAngleLoc, 2421cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateArgList &TemplateArgs, 2422cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &RAngleLoc); 2423cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 2424c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, 2425059101f922de6eb765601459925f4c8914420b23Douglas Gregor CXXScopeSpec &SS, 2426e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2427ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &TemplateName, 242839a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor bool AllowTypeAnnotation = true); 2429059101f922de6eb765601459925f4c8914420b23Douglas Gregor void AnnotateTemplateIdTokenAsType(); 2430d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor bool IsTemplateArgumentList(unsigned Skip = 0); 2431314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); 2432788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor ParsedTemplateArgument ParseTemplateTemplateArgument(); 2433314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor ParsedTemplateArgument ParseTemplateArgument(); 24349241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis Decl *ParseExplicitInstantiation(unsigned Context, 24359241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis SourceLocation ExternLoc, 24369241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis SourceLocation TemplateLoc, 24379241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis SourceLocation &DeclEnd, 24389241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis AccessSpecifier AS = AS_none); 243964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 244064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl //===--------------------------------------------------------------------===// 24416aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor // Modules 24425948ae1021122164b22f74353bb7fe325a64f616Douglas Gregor DeclGroupPtrTy ParseModuleImport(SourceLocation AtLoc); 2443a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 24446aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor //===--------------------------------------------------------------------===// 2445651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // C++11/G++: Type Traits [Type-Traits.html in the GCC manual] 24464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ExprResult ParseTypeTrait(); 24474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2448f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor //===--------------------------------------------------------------------===// 244921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley // Embarcadero: Arary and Expression Traits 245021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult ParseArrayTypeTrait(); 2451552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult ParseExpressionTrait(); 2452552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2453552622067dc45013d240f73952fece703f5e63bdJohn Wiegley //===--------------------------------------------------------------------===// 2454f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor // Preprocessor code-completion pass-through 2455651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void CodeCompleteDirective(bool InConditional) override; 2456651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void CodeCompleteInConditionalExclusion() override; 2457651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void CodeCompleteMacroName(bool IsDefinition) override; 2458651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void CodeCompletePreprocessorExpression() override; 2459651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo, 2460651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned ArgumentIndex) override; 2461651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void CodeCompleteNaturalLanguage() override; 24625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 24655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2467