Parser.h revision 5354e77e60e82828c7c2361f5c688c2667ab59cc
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 17ad2b804faf29042e6c4e331d0987f103f1e2fd31John McCall#include "clang/Basic/Specifiers.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Lex/Preprocessor.h" 19f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor#include "clang/Lex/CodeCompletionHandler.h" 20f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "clang/Sema/Sema.h" 2119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h" 224726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek#include "llvm/ADT/OwningPtr.h" 23eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski#include "llvm/ADT/SmallVector.h" 24aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 25aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/PrettyStackTrace.h" 2694f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose#include "llvm/Support/SaveAndRestore.h" 274cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis#include <stack> 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 30fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar class PragmaHandler; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Scope; 32c86c40b912e53fb11ff8f745ed616035b8b7259cDouglas Gregor class BalancedDelimiterTracker; 330576681bac125be07f77f66b02a3dba2c3a24557Richard Smith class CorrectionCandidateCallback; 342b5289b6fd7e3d9899868410a498c081c9595662John McCall class DeclGroupRef; 353cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner class DiagnosticBuilder; 360102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner class Parser; 379257664568bf375b7790131a84d9a4fa30a5b7e3John McCall class ParsingDeclRAIIObject; 389257664568bf375b7790131a84d9a4fa30a5b7e3John McCall class ParsingDeclSpec; 399257664568bf375b7790131a84d9a4fa30a5b7e3John McCall class ParsingDeclarator; 40f66a0dda541cd859a928193efba6dc5d7ba8fe54Eli Friedman class ParsingFieldDeclarator; 414726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek class PragmaUnusedHandler; 4208d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner class ColonProtectionRAIIObject; 430fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor class InMessageExpressionRAIIObject; 4428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley class PoisonSEHIdentifiersRAIIObject; 450a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor class VersionTuple; 46a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 470102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// PrettyStackTraceParserEntry - If a crash happens while the parser is active, 480102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// an entry is printed for it. 490102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerclass PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry { 500102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Parser &P; 510102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerpublic: 520102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner PrettyStackTraceParserEntry(const Parser &p) : P(p) {} 538cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner virtual void print(raw_ostream &OS) const; 540102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner}; 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// PrecedenceLevels - These are precedences for the binary/ternary 576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// operators in the C99 grammar. These have been named to relate 586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// with the C99 grammar productions. Low precedences numbers bind 596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// more weakly than high numbers. 606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregornamespace prec { 616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor enum Level { 626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Unknown = 0, // Not binary operator. 636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Comma = 1, // , 646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Assignment = 2, // =, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |= 656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Conditional = 3, // ? 666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor LogicalOr = 4, // || 676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor LogicalAnd = 5, // && 686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor InclusiveOr = 6, // | 696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ExclusiveOr = 7, // ^ 706aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor And = 8, // & 716aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Equality = 9, // ==, != 726aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Relational = 10, // >=, <=, >, < 736aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Shift = 11, // <<, >> 746aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Additive = 12, // -, + 756aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Multiplicative = 13, // *, /, % 766aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor PointerToMember = 14 // .*, ->* 776aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor }; 786aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Parser - This implements a parser for the C family of languages. After 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// parsing units of the grammar, productions are invoked to handle whatever has 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// been read. 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 84f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregorclass Parser : public CodeCompletionHandler { 854726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek friend class PragmaUnusedHandler; 8608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner friend class ColonProtectionRAIIObject; 870fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor friend class InMessageExpressionRAIIObject; 8828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley friend class PoisonSEHIdentifiersRAIIObject; 8994f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose friend class ObjCDeclContextSwitch; 9036d36806f1972f7ec1d2a3f59155187278c56508Argyrios Kyrtzidis friend class ParenBraceBracketBalancer; 91c86c40b912e53fb11ff8f745ed616035b8b7259cDouglas Gregor friend class BalancedDelimiterTracker; 921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Preprocessor &PP; 941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9597d0205d16fef2a783e785459b5f30f6a9dfbcb9Eric Christopher /// Tok - The current token we are peeking ahead. All parsing methods assume 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that this is valid. 97d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner Token Tok; 981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 994b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // PrevTokLocation - The location of the token we previously 1004b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // consumed. This token is used for diagnostics where we expected to 1014b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // see a token following another token (e.g., the ';' at the end of 1024b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // a statement). 1034b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceLocation PrevTokLocation; 1044b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned short ParenCount, BracketCount, BraceCount; 106c86c40b912e53fb11ff8f745ed616035b8b7259cDouglas Gregor 1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Actions - These are the callbacks we invoke as we parse various constructs 108a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// in the file. 109f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &Actions; 1101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 111d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine &Diags; 1121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1139e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner /// ScopeCache - Cache scopes to reduce malloc traffic. 1149e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner enum { ScopeCacheSize = 16 }; 1159e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner unsigned NumCachedScopes; 1169e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner Scope *ScopeCache[ScopeCacheSize]; 117662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 11828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley /// Identifiers used for SEH handling in Borland. These are only 11928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley /// allowed in particular circumstances 120a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie // __except block 121a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie IdentifierInfo *Ident__exception_code, 122a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident___exception_code, 123a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident_GetExceptionCode; 124a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie // __except filter expression 125a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie IdentifierInfo *Ident__exception_info, 126a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident___exception_info, 127a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident_GetExceptionInfo; 128a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie // __finally 129a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie IdentifierInfo *Ident__abnormal_termination, 130a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident___abnormal_termination, 131a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident_AbnormalTermination; 13228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 133b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor /// Contextual keywords for Microsoft extensions. 134b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor IdentifierInfo *Ident__except; 135a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 136662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// Ident_super - IdentifierInfo for "super", to support fast 137662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// comparison. 138662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar IdentifierInfo *Ident_super; 13982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// Ident_vector and Ident_pixel - cached IdentifierInfo's for 14082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// "vector" and "pixel" fast comparison. Only present if 14182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// AltiVec enabled. 14282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_vector; 14382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_pixel; 144662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 145e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor /// Objective-C contextual keywords. 146e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor mutable IdentifierInfo *Ident_instancetype; 147a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1480a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "introduced". 1490a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_introduced; 1500a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 1510a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "deprecated". 1520a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_deprecated; 1530a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 1540a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "obsoleted". 1550a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_obsoleted; 1560a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 157b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor /// \brief Identifier for "unavailable". 158b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor IdentifierInfo *Ident_unavailable; 159006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian 160006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian /// \brief Identifier for "message". 161006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian IdentifierInfo *Ident_message; 162b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor 163a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// C++0x contextual keywords. 1647eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson mutable IdentifierInfo *Ident_final; 1657eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson mutable IdentifierInfo *Ident_override; 1661f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 1676f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> AlignHandler; 1686f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> GCCVisibilityHandler; 1696f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> OptionsHandler; 1706f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> PackHandler; 1716f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> MSStructHandler; 1726f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> UnusedHandler; 1736f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> WeakHandler; 1745f3c163b7b19a0c7e02509a0984ee1256bca890dDavid Chisnall OwningPtr<PragmaHandler> RedefineExtnameHandler; 1756f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> FPContractHandler; 1766f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> OpenCLExtensionHandler; 177056e2c30050a94141150ba561268d90b4d18e378Dmitri Gribenko OwningPtr<CommentHandler> CommentSemaHandler; 1781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// Whether the '>' token acts as an operator or not. This will be 18055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// true except when we are parsing an expression within a C++ 18155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// template argument list, where the '>' closes the template 18255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// argument list. 18355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor bool GreaterThanIsOperator; 184a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 18508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonIsSacred - When this is false, we aggressively try to recover from 18608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not 18708d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// safe in case statements and a few other things. This is managed by the 18808d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonProtectionRAIIObject RAII object. 18908d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner bool ColonIsSacred; 19055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 191a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// \brief When true, we are directly inside an Objective-C messsage 1920fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// send expression. 1930fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// 1940fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// This is managed by the \c InMessageExpressionRAIIObject class, and 1950fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// should not be set directly. 1960fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor bool InMessageExpression; 197a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 198c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor /// The "depth" of the template parameters currently being parsed. 199c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor unsigned TemplateParameterDepth; 200a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 2018113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek /// Factory object for creating AttributeList objects. 2020b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall AttributeFactory AttrFactory; 2031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20413bb701f2f876356400a34b0917a417c66b5d70dBenjamin Kramer /// \brief Gathers and cleans up TemplateIdAnnotations when parsing of a 20513bb701f2f876356400a34b0917a417c66b5d70dBenjamin Kramer /// top-level declaration is finished. 20613bb701f2f876356400a34b0917a417c66b5d70dBenjamin Kramer SmallVector<TemplateIdAnnotation *, 16> TemplateIds; 20725a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 2080576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// \brief Identifiers which have been declared within a tentative parse. 2090576681bac125be07f77f66b02a3dba2c3a24557Richard Smith SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers; 2100576681bac125be07f77f66b02a3dba2c3a24557Richard Smith 211b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor IdentifierInfo *getSEHExceptKeyword(); 212a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 21394f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose /// True if we are within an Objective-C container while parsing C-like decls. 21494f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose /// 21594f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose /// This is necessary because Sema thinks we have left the container 21694f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose /// to parse the C-like decls, meaning Actions.getObjCDeclContext() will 21794f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose /// be NULL. 21894f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose bool ParsingInObjCContainer; 21994f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose 2206a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen bool SkipFunctionBodies; 2216a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2236a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies); 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Parser(); 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2264e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &getLangOpts() const { return PP.getLangOpts(); } 227444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } 2280102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner Preprocessor &getPreprocessor() const { return PP; } 229f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &getActions() const { return Actions; } 2309257664568bf375b7790131a84d9a4fa30a5b7e3John McCall AttributeFactory &getAttrFactory() { return AttrFactory; } 2311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2320102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Token &getCurToken() const { return Tok; } 23323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Scope *getCurScope() const { return Actions.getCurScope(); } 234a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 235a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); } 236a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Type forwarding. All of these are statically 'void*', but they may all be 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // different actual classes based on the actions in place. 2392b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 2402b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<TemplateName> TemplateTy; 2417ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 242686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists; 243c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 2449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::ExprResult ExprResult; 2459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::StmtResult StmtResult; 2469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::BaseResult BaseResult; 2479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::MemInitResult MemInitResult; 2489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::TypeResult TypeResult; 24915faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 2509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef Expr *ExprArg; 2515354e77e60e82828c7c2361f5c688c2667ab59ccBenjamin Kramer typedef llvm::MutableArrayRef<Stmt*> MultiStmtArg; 252f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::FullExprArg FullExprArg; 2531d922960e083906a586609ac6978678147250177Sebastian Redl 25460d7b3a319d84d688752be3870615ac0f111fb16John McCall /// Adorns a ExprResult with Actions to make it an ExprResult 25560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Owned(ExprResult res) { 25660d7b3a319d84d688752be3870615ac0f111fb16John McCall return ExprResult(res); 25761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 25860d7b3a319d84d688752be3870615ac0f111fb16John McCall /// Adorns a StmtResult with Actions to make it an StmtResult 25960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Owned(StmtResult res) { 26060d7b3a319d84d688752be3870615ac0f111fb16John McCall return StmtResult(res); 26161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 26261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 26360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError() { return ExprResult(true); } 26460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError() { return StmtResult(true); } 265d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor 26660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); } 26760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); } 26861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 26960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprEmpty() { return ExprResult(false); } 2705ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Parsing methods. 2721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseTranslationUnit - All in one method that initializes parses, and 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// shuts down the parser. 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseTranslationUnit(); 2761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Initialize - Warm up the parser. 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Initialize(); 2801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if 2821f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff /// the EOF was encountered. 283682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner bool ParseTopLevelDecl(DeclGroupPtrTy &Result); 2841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Low-Level token peeking and consumption methods. 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 2891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenParen - Return true if the cur token is '(' or ')'. 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenParen() const { 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren; 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBracket - Return true if the cur token is '[' or ']'. 2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBracket() const { 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square; 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBrace - Return true if the cur token is '{' or '}'. 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBrace() const { 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace; 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenStringLiteral - True if this token is a string-literal. 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenStringLiteral() const { 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::string_literal || 3075cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::wide_string_literal || 3085cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::utf8_string_literal || 3095cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::utf16_string_literal || 3105cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::utf32_string_literal; 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 312eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 313fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu /// \brief Returns true if the current token is '=' or is a type of '='. 314fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu /// For typos, give a fixit to '=' 315fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu bool isTokenEqualOrEqualTypo(); 316a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeToken - Consume the current 'peek token' and lex the next one. 318d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu /// This does not work with all kinds of tokens: strings and specific other 3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tokens must be consumed with custom methods below. This returns the 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// location of the consumed token. 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeToken() { 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer !isTokenBrace() && 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should consume special tokens with Consume*Token"); 3257d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis 3267d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis if (Tok.is(tok::code_completion)) 3277d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return handleUnexpectedCodeCompletionToken(); 3287d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis 3294b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3314b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeAnyToken - Dispatch to the right Consume* method based on the 3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// current token type. This should only be used in cases where the type of 3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the token really isn't known, e.g. in error recovery. 3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeAnyToken() { 3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isTokenParen()) 3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeParen(); 3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBracket()) 3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBracket(); 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBrace()) 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBrace(); 344d62701bc5321049353017e9abf1963edd57646aaSteve Naroff else if (isTokenStringLiteral()) 345d62701bc5321049353017e9abf1963edd57646aaSteve Naroff return ConsumeStringToken(); 3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeToken(); 3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeParen - This consume method keeps the paren count up-to-date. 3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeParen() { 3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenParen() && "wrong consume method"); 3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_paren) 3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++ParenCount; 3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (ParenCount) 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --ParenCount; // Don't let unbalanced )'s drive the count negative. 3584b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3604b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBracket - This consume method keeps the bracket count up-to-date. 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBracket() { 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBracket() && "wrong consume method"); 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_square) 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BracketCount; 3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BracketCount) 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BracketCount; // Don't let unbalanced ]'s drive the count negative. 3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3724b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3744b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBrace - This consume method keeps the brace count up-to-date. 3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBrace() { 3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBrace() && "wrong consume method"); 3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_brace) 3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BraceCount; 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BraceCount) 3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BraceCount; // Don't let unbalanced }'s drive the count negative. 3851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3864b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3884b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeStringToken - Consume the current 'peek token', lexing a new one 3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and returning the token kind. This method is specific to strings, as it 3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// handles string literal concatenation, as per C99 5.1.1.2, translation 3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// phase #6. 3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeStringToken() { 3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenStringLiteral() && 3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should only consume string literals with this method"); 3984b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 4004b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 403dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// \brief Consume the current code-completion token. 404dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// 405dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// This routine should be called to consume the code-completion token once 406dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// a code-completion action has already been invoked. 407dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor SourceLocation ConsumeCodeCompletionToken() { 408dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor assert(Tok.is(tok::code_completion)); 409dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PrevTokLocation = Tok.getLocation(); 410dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PP.Lex(Tok); 411a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie return PrevTokLocation; 412dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor } 413a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 4147d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis ///\ brief When we are consuming a code-completion token without having 415dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// matched specific position in the grammar, provide code-completion results 416dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// based on context. 4177d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// 4187d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// \returns the source location of the code-completion token. 4197d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis SourceLocation handleUnexpectedCodeCompletionToken(); 4207d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis 4217d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// \brief Abruptly cut off parsing; mainly used when we have reached the 4227d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// code-completion point. 4237d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis void cutOffParsing() { 4247d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis PP.setCodeCompletionReached(); 4257d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis // Cut off parsing by acting as if we reached the end-of-file. 4267d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis Tok.setKind(tok::eof); 4277d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis } 428dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 429b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis /// \brief Handle the annotation token produced for #pragma unused(...) 430b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis void HandlePragmaUnused(); 431b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis 432426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola /// \brief Handle the annotation token produced for 433426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola /// #pragma GCC visibility... 434426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola void HandlePragmaVisibility(); 435426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola 436aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman /// \brief Handle the annotation token produced for 437aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman /// #pragma pack... 438aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman void HandlePragmaPack(); 439aa5ab26ed93382b812147f532dcbf4afb5494040Eli Friedman 4406b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// GetLookAheadToken - This peeks ahead N tokens and returns that token 4416b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1) 4426b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// returns the token after Tok, etc. 4436b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 4446b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// Note that this differs from the Preprocessor's LookAhead method, because 4456b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// the Parser always has one token lexed that the preprocessor doesn't. 4466b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 44703db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis const Token &GetLookAheadToken(unsigned N) { 4486b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (N == 0 || Tok.is(tok::eof)) return Tok; 4496b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return PP.LookAhead(N-1); 4506b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } 451f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis 452f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// NextToken - This peeks ahead one token and returns it without 453f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// consuming it. 454f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis const Token &NextToken() { 45503db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis return PP.LookAhead(0); 456f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis } 4575404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 458b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall /// getTypeAnnotation - Read a parsed type out of an annotation token. 459b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static ParsedType getTypeAnnotation(Token &Tok) { 460b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue()); 461b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 462b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 463b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static void setTypeAnnotation(Token &Tok, ParsedType T) { 464b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Tok.setAnnotationValue(T.getAsOpaquePtr()); 465b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 466a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 4675ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// \brief Read an already-translated primary expression out of an annotation 4685ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// token. 4695ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor static ExprResult getExprAnnotation(Token &Tok) { 4705ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor if (Tok.getAnnotationValue()) 4715ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor return ExprResult((Expr *)Tok.getAnnotationValue()); 472a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 4735ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor return ExprResult(true); 4745ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor } 475a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 4765ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// \brief Set the primary expression corresponding to the given annotation 4775ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// token. 4785ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor static void setExprAnnotation(Token &Tok, ExprResult ER) { 4795ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor if (ER.isInvalid()) 4805ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor Tok.setAnnotationValue(0); 4815ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor else 4825ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor Tok.setAnnotationValue(ER.get()); 4835ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor } 484b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 485fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to 486fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain // find a type name by attempting typo correction. 487fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false, 488fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain bool NeedType = false); 4890576681bac125be07f77f66b02a3dba2c3a24557Richard Smith bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool EnteringContext, 4900576681bac125be07f77f66b02a3dba2c3a24557Richard Smith bool NeedType, 4910576681bac125be07f77f66b02a3dba2c3a24557Richard Smith CXXScopeSpec &SS, 4920576681bac125be07f77f66b02a3dba2c3a24557Richard Smith bool IsNewScope); 493495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateCXXScopeToken(bool EnteringContext = false); 4940576681bac125be07f77f66b02a3dba2c3a24557Richard Smith enum AnnotatedNameKind { 4950576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// Annotation has failed and emitted an error. 4960576681bac125be07f77f66b02a3dba2c3a24557Richard Smith ANK_Error, 4970576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// The identifier is a tentatively-declared name. 4980576681bac125be07f77f66b02a3dba2c3a24557Richard Smith ANK_TentativeDecl, 4990576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// The identifier is a template name. FIXME: Add an annotation for that. 5000576681bac125be07f77f66b02a3dba2c3a24557Richard Smith ANK_TemplateName, 5010576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// The identifier can't be resolved. 5020576681bac125be07f77f66b02a3dba2c3a24557Richard Smith ANK_Unresolved, 5030576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// Annotation was successful. 5040576681bac125be07f77f66b02a3dba2c3a24557Richard Smith ANK_Success 5050576681bac125be07f77f66b02a3dba2c3a24557Richard Smith }; 5060576681bac125be07f77f66b02a3dba2c3a24557Richard Smith AnnotatedNameKind TryAnnotateName(bool IsAddressOfOperand, 5070576681bac125be07f77f66b02a3dba2c3a24557Richard Smith CorrectionCandidateCallback *CCC = 0); 5080576681bac125be07f77f66b02a3dba2c3a24557Richard Smith 5090576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// Push a tok::annot_cxxscope token onto the token stream. 5100576681bac125be07f77f66b02a3dba2c3a24557Richard Smith void AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation); 511eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 51282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens, 51382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// replacing them with the non-context-sensitive keywords. This returns 51482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// true if the token was replaced. 51582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc, 516b3a4e432c90be98c6d918087750397e86d030368Chris Lattner const char *&PrevSpec, unsigned &DiagID, 517b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool &isInvalid) { 5184e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!getLangOpts().AltiVec || 5191b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner (Tok.getIdentifierInfo() != Ident_vector && 5201b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner Tok.getIdentifierInfo() != Ident_pixel)) 5211b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return false; 522a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 5231b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); 52482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 52582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 52682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector 52782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// identifier token, replacing it with the non-context-sensitive __vector. 52882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// This returns true if the token was replaced. 52982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecVectorToken() { 5304e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!getLangOpts().AltiVec || 531b3a4e432c90be98c6d918087750397e86d030368Chris Lattner Tok.getIdentifierInfo() != Ident_vector) return false; 5321b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecVectorTokenOutOfLine(); 53382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 534a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 5351b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecVectorTokenOutOfLine(); 5361b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, 5371b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner const char *&PrevSpec, unsigned &DiagID, 5381b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool &isInvalid); 53925a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 54013bb701f2f876356400a34b0917a417c66b5d70dBenjamin Kramer /// \brief Get the TemplateIdAnnotation from the token. 54125a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok); 54225a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 5435404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TentativeParsingAction - An object that is used as a kind of "tentative 5445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// parsing transaction". It gets instantiated to mark the token position and 5455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// after the token consumption is done, Commit() or Revert() is called to 5465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// either "commit the consumed tokens" or revert to the previously marked 5475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// token position. Example: 5485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 549314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor /// TentativeParsingAction TPA(*this); 5505404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// ConsumeToken(); 5515404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// .... 5525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TPA.Revert(); 5535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 5545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis class TentativeParsingAction { 5555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Parser &P; 5565404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Token PrevTok; 5570576681bac125be07f77f66b02a3dba2c3a24557Richard Smith size_t PrevTentativelyDeclaredIdentifierCount; 558de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount; 5595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isActive; 5605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 5615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis public: 5625404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis explicit TentativeParsingAction(Parser& p) : P(p) { 5635404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis PrevTok = P.Tok; 5640576681bac125be07f77f66b02a3dba2c3a24557Richard Smith PrevTentativelyDeclaredIdentifierCount = 5650576681bac125be07f77f66b02a3dba2c3a24557Richard Smith P.TentativelyDeclaredIdentifiers.size(); 566de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor PrevParenCount = P.ParenCount; 567de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor PrevBracketCount = P.BracketCount; 568de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor PrevBraceCount = P.BraceCount; 5695404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.EnableBacktrackAtThisPos(); 5705404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = true; 5715404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 5725404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Commit() { 5735404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 5740576681bac125be07f77f66b02a3dba2c3a24557Richard Smith P.TentativelyDeclaredIdentifiers.resize( 5750576681bac125be07f77f66b02a3dba2c3a24557Richard Smith PrevTentativelyDeclaredIdentifierCount); 5765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.CommitBacktrackedTokens(); 5775404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 5785404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 5795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Revert() { 5805404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 5815404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.Backtrack(); 5825404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.Tok = PrevTok; 5830576681bac125be07f77f66b02a3dba2c3a24557Richard Smith P.TentativelyDeclaredIdentifiers.resize( 5840576681bac125be07f77f66b02a3dba2c3a24557Richard Smith PrevTentativelyDeclaredIdentifierCount); 585de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor P.ParenCount = PrevParenCount; 586de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor P.BracketCount = PrevBracketCount; 587de88246a7bc57bc4995ad4e6fde8f245d70b130eDouglas Gregor P.BraceCount = PrevBraceCount; 5885404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 5895404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 5905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis ~TentativeParsingAction() { 5915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(!isActive && "Forgot to call Commit or Revert!"); 5925404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 5935404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis }; 5941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5959735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// ObjCDeclContextSwitch - An object used to switch context from 5969735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// an objective-c decl context to its enclosing decl context and 5979735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// back. 5989735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian class ObjCDeclContextSwitch { 5999735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian Parser &P; 6009735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian Decl *DC; 60194f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose SaveAndRestore<bool> WithinObjCContainer; 6029735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian public: 60394f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose explicit ObjCDeclContextSwitch(Parser &p) 60494f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose : P(p), DC(p.getObjCDeclContext()), 60594f29f4bf5d6b49dd1b7fc16cfa1521adc0c71c0Jordan Rose WithinObjCContainer(P.ParsingInObjCContainer, DC != 0) { 6069735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian if (DC) 607458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC)); 6089735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian } 6099735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian ~ObjCDeclContextSwitch() { 6109735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian if (DC) 611458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC)); 6129735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian } 6139735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian }; 6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// input. If so, it is consumed and false is returned. 6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If the input is malformed, this emits the specified diagnostic. Next, if 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is 6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// returned. 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag, 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *DiagMsg = "", 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind SkipToTok = tok::unknown); 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6259ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// \brief The parser expects a semicolon and, if present, will consume it. 6269ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// 6279ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// If the next token is not a semicolon, this emits the specified diagnostic, 6289ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior 6299ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// to the semicolon, consumes that extra token. 6309ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor bool ExpectAndConsumeSemi(unsigned DiagID); 631a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 632eab9d6f9065b042d39fbaf9842c9d8cc968dd6d0Richard Smith /// \brief The kind of extra semi diagnostic to emit. 6334b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu enum ExtraSemiKind { 6344b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu OutsideFunction = 0, 6354b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu InsideStruct = 1, 6364b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu InstanceVariableList = 2, 637eab9d6f9065b042d39fbaf9842c9d8cc968dd6d0Richard Smith AfterMemberFunctionDefinition = 3 6384b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu }; 6394b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu 6404b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu /// \brief Consume any extra semi-colons until the end of the line. 641eab9d6f9065b042d39fbaf9842c9d8cc968dd6d0Richard Smith void ConsumeExtraSemi(ExtraSemiKind Kind, unsigned TST = TST_unspecified); 6424b0e6f1da341510c1ad83eaf4c836f3134d0156aRichard Trieu 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Scope manipulation 6451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6468935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// ParseScope - Introduces a new scope for parsing. The kind of 6478935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// scope is determined by ScopeFlags. Objects of this type should 6488935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// be created on the stack to coincide with the position where the 6498935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// parser enters the new scope, and this object's constructor will 6508935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// create that new scope. Similarly, once the object is destroyed 6518935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// the parser will exit the scope. 6528935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor class ParseScope { 6538935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Parser *Self; 6548935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope(const ParseScope&); // do not implement 6558935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope& operator=(const ParseScope&); // do not implement 6568935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6578935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor public: 6588935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ParseScope - Construct a new object to manage a scope in the 6598935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // parser Self where the new Scope is created with the flags 6608935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ScopeFlags, but only when ManageScope is true (the default). If 6618935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ManageScope is false, this object does nothing. 6621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true) 6638935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor : Self(Self) { 6648935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (ManageScope) 6658935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->EnterScope(ScopeFlags); 6668935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor else 6678935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor this->Self = 0; 6688935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6698935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6708935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // Exit - Exit the scope associated with this object now, rather 6718935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // than waiting until the object is destroyed. 6728935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor void Exit() { 6738935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (Self) { 6748935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->ExitScope(); 6758935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self = 0; 6768935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6778935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6788935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6798935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ~ParseScope() { 6808935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Exit(); 6818935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6828935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor }; 6838935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterScope - Start a new scope. 6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterScope(unsigned ScopeFlags); 6861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExitScope - Pop a scope off the scope stack. 6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ExitScope(); 6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6907a614d8380297fcd2bc23986241905d97222948cRichard Smith /// \brief RAII object used to modify the scope flags for the current scope. 6917a614d8380297fcd2bc23986241905d97222948cRichard Smith class ParseScopeFlags { 6927a614d8380297fcd2bc23986241905d97222948cRichard Smith Scope *CurScope; 6937a614d8380297fcd2bc23986241905d97222948cRichard Smith unsigned OldFlags; 6947a614d8380297fcd2bc23986241905d97222948cRichard Smith ParseScopeFlags(const ParseScopeFlags &); // do not implement 6957a614d8380297fcd2bc23986241905d97222948cRichard Smith void operator=(const ParseScopeFlags &); // do not implement 6967a614d8380297fcd2bc23986241905d97222948cRichard Smith 6977a614d8380297fcd2bc23986241905d97222948cRichard Smith public: 6987a614d8380297fcd2bc23986241905d97222948cRichard Smith ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true); 6997a614d8380297fcd2bc23986241905d97222948cRichard Smith ~ParseScopeFlags(); 7007a614d8380297fcd2bc23986241905d97222948cRichard Smith }; 7017a614d8380297fcd2bc23986241905d97222948cRichard Smith 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Diagnostic Emission and Error recovery. 70415faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 7056aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorpublic: 7063cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 7073cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); 708d73ef135ba029db59c0b5649e6117845d9e39600Jordan Rose DiagnosticBuilder Diag(unsigned DiagID) { 709d73ef135ba029db59c0b5649e6117845d9e39600Jordan Rose return Diag(Tok, DiagID); 710d73ef135ba029db59c0b5649e6117845d9e39600Jordan Rose } 71115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 7126aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorprivate: 7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SuggestParentheses(SourceLocation Loc, unsigned DK, 7144b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceRange ParenRange); 715d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen void CheckNestedObjCContexts(SourceLocation AtLoc); 7164b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipUntil - Read tokens until we get to the specified token, then consume 71882c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff /// it (unless DontConsume is true). Because we cannot guarantee that the 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// token will ever occur, this skips to the next token, or to some likely 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' 7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// character. 7221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If SkipUntil finds the specified token, it returns true, otherwise it 7241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returns false. 7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true, 7263437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis bool DontConsume = false, bool StopAtCodeCompletion = false) { 727eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie return SkipUntil(llvm::makeArrayRef(T), StopAtSemi, DontConsume, 728eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie StopAtCodeCompletion); 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true, 7313437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis bool DontConsume = false, bool StopAtCodeCompletion = false) { 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind TokArray[] = {T1, T2}; 733eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie return SkipUntil(TokArray, StopAtSemi, DontConsume,StopAtCodeCompletion); 7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 735eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3, 7363437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis bool StopAtSemi = true, bool DontConsume = false, 737eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie bool StopAtCodeCompletion = false) { 738eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie tok::TokenKind TokArray[] = {T1, T2, T3}; 739eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie return SkipUntil(TokArray, StopAtSemi, DontConsume,StopAtCodeCompletion); 740eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie } 741eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie bool SkipUntil(ArrayRef<tok::TokenKind> Toks, bool StopAtSemi = true, 742eb52f86a62db523e3c993686b3ed92c55d59d53cDavid Blaikie bool DontConsume = false, bool StopAtCodeCompletion = false); 7437ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 744994d73f8473cb2cd3ce2f69c9575c95015be788aRichard Smith /// SkipMalformedDecl - Read tokens until we get to some likely good stopping 745994d73f8473cb2cd3ce2f69c9575c95015be788aRichard Smith /// point for skipping past a simple-declaration. 746994d73f8473cb2cd3ce2f69c9575c95015be788aRichard Smith void SkipMalformedDecl(); 747994d73f8473cb2cd3ce2f69c9575c95015be788aRichard Smith 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 7494cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Lexing and parsing of C++ inline methods. 7504cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 751d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct ParsingClass; 752d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 753d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// [class.mem]p1: "... the class is regarded as complete within 754d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - function bodies 755d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - default arguments 756d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - exception-specifications (TODO: C++0x) 7577a614d8380297fcd2bc23986241905d97222948cRichard Smith /// - and brace-or-equal-initializers for non-static data members 7587a614d8380297fcd2bc23986241905d97222948cRichard Smith /// (including such things in nested classes)." 759d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarations build the tree of those elements so they can 760d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// be parsed after parsing the top-level class. 761d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor class LateParsedDeclaration { 762d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor public: 763d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual ~LateParsedDeclaration(); 764d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 765d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 7667a614d8380297fcd2bc23986241905d97222948cRichard Smith virtual void ParseLexedMemberInitializers(); 767d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 768eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski virtual void ParseLexedAttributes(); 769d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor }; 770d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 771d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// Inner node of the LateParsedDeclaration tree that parses 772d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// all its members recursively. 773d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor class LateParsedClass : public LateParsedDeclaration { 774d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor public: 775d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateParsedClass(Parser *P, ParsingClass *C); 776d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual ~LateParsedClass(); 777d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 778d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 7797a614d8380297fcd2bc23986241905d97222948cRichard Smith virtual void ParseLexedMemberInitializers(); 780d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 781eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski virtual void ParseLexedAttributes(); 782d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 783d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor private: 784d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser *Self; 785d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor ParsingClass *Class; 786d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor }; 787d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 788a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// Contains the lexed tokens of an attribute with arguments that 789a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// may reference member variables and so need to be parsed at the 790a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// end of the class declaration after parsing all other member 791eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// member declarations. 792eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// FIXME: Perhaps we should change the name of LateParsedDeclaration to 793eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// LateParsedTokens. 794eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski struct LateParsedAttribute : public LateParsedDeclaration { 795eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski Parser *Self; 796eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski CachedTokens Toks; 797eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski IdentifierInfo &AttrName; 798eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation AttrNameLoc; 7992287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins SmallVector<Decl*, 2> Decls; 800eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 801a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name, 802eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation Loc) 8032287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins : Self(P), AttrName(Name), AttrNameLoc(Loc) {} 804eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 805eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski virtual void ParseLexedAttributes(); 806eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 8072287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins void addDecl(Decl *D) { Decls.push_back(D); } 808eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski }; 809eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 810eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// A list of late parsed attributes. Used by ParseGNUAttributes. 811eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski typedef llvm::SmallVector<LateParsedAttribute*, 2> LateParsedAttrList; 812eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 813eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 814d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// Contains the lexed tokens of a member function definition 815d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// which needs to be parsed at the end of the class declaration 816d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// after parsing all other member declarations. 817d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct LexedMethod : public LateParsedDeclaration { 818d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser *Self; 819d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *D; 82072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens Toks; 821d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 822d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 823d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 824d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 825d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 826d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 827d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor explicit LexedMethod(Parser* P, Decl *MD) 828d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor : Self(P), D(MD), TemplateScope(false) {} 829d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 830d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 8314cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis }; 8324cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 83372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedDefaultArgument - Keeps track of a parameter that may 83472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument that cannot be parsed yet because it 83572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// occurs within a member function declaration inside the class 83672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// (C++ [class.mem]p2). 83772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedDefaultArgument { 838d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall explicit LateParsedDefaultArgument(Decl *P, 83972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks = 0) 84072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor : Param(P), Toks(Toks) { } 84172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 84272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Param - The parameter declaration for this parameter. 843d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param; 84472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 84572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Toks - The sequence of tokens that comprises the default 84672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument expression, not including the '=' or the terminating 84772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// ')' or ','. This will be NULL for parameters that have no 84872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// default argument. 84972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks; 85072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDeclaration - A method declaration inside a class that 85372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// contains at least one entity whose parsing needs to be delayed 85472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// until the class itself is completely-defined, such as a default 85572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument (C++ [class.mem]p2). 856d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct LateParsedMethodDeclaration : public LateParsedDeclaration { 857d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor explicit LateParsedMethodDeclaration(Parser *P, Decl *M) 85874e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor : Self(P), Method(M), TemplateScope(false), ExceptionSpecTokens(0) { } 859d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 860d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 861d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 862d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser* Self; 86372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 86472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Method - The method declaration. 865d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Method; 86672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 867d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 868d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 869d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 870d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 8711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// DefaultArgs - Contains the parameters of the function and 87372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// their default arguments. At least one of the parameters will 87472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument, but all of the parameters of the 87572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// method will be stored so that they can be reintroduced into 8761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// scope at the appropriate times. 877686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; 87874e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor 87974e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor /// \brief The set of tokens that make up an exception-specification that 88074e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor /// has not yet been parsed. 88174e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor CachedTokens *ExceptionSpecTokens; 88272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 88372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 8847a614d8380297fcd2bc23986241905d97222948cRichard Smith /// LateParsedMemberInitializer - An initializer for a non-static class data 8857a614d8380297fcd2bc23986241905d97222948cRichard Smith /// member whose parsing must to be delayed until the class is completely 8867a614d8380297fcd2bc23986241905d97222948cRichard Smith /// defined (C++11 [class.mem]p2). 8877a614d8380297fcd2bc23986241905d97222948cRichard Smith struct LateParsedMemberInitializer : public LateParsedDeclaration { 8887a614d8380297fcd2bc23986241905d97222948cRichard Smith LateParsedMemberInitializer(Parser *P, Decl *FD) 8897a614d8380297fcd2bc23986241905d97222948cRichard Smith : Self(P), Field(FD) { } 8907a614d8380297fcd2bc23986241905d97222948cRichard Smith 8917a614d8380297fcd2bc23986241905d97222948cRichard Smith virtual void ParseLexedMemberInitializers(); 8927a614d8380297fcd2bc23986241905d97222948cRichard Smith 8937a614d8380297fcd2bc23986241905d97222948cRichard Smith Parser *Self; 8947a614d8380297fcd2bc23986241905d97222948cRichard Smith 8957a614d8380297fcd2bc23986241905d97222948cRichard Smith /// Field - The field declaration. 8967a614d8380297fcd2bc23986241905d97222948cRichard Smith Decl *Field; 8977a614d8380297fcd2bc23986241905d97222948cRichard Smith 8987a614d8380297fcd2bc23986241905d97222948cRichard Smith /// CachedTokens - The sequence of tokens that comprises the initializer, 8997a614d8380297fcd2bc23986241905d97222948cRichard Smith /// including any leading '='. 9007a614d8380297fcd2bc23986241905d97222948cRichard Smith CachedTokens Toks; 9017a614d8380297fcd2bc23986241905d97222948cRichard Smith }; 9027a614d8380297fcd2bc23986241905d97222948cRichard Smith 903d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarationsContainer - During parsing of a top (non-nested) 904d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// C++ class, its method declarations that contain parts that won't be 905fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// parsed until after the definition is completed (C++ [class.mem]p2), 906d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// the method declarations and possibly attached inline definitions 907a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// will be stored here with the tokens that will be parsed to create those 908a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// entities. 909a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer; 91072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 9116569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Representation of a class that has been parsed, including 9126569d68745c8213709740337d2be52b031384f58Douglas Gregor /// any member function declarations or definitions that need to be 9136569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed after the corresponding top-level class is complete. 9146569d68745c8213709740337d2be52b031384f58Douglas Gregor struct ParsingClass { 915d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParsingClass(Decl *TagOrTemplate, bool TopLevelClass) 9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : TopLevelClass(TopLevelClass), TemplateScope(false), 9176569d68745c8213709740337d2be52b031384f58Douglas Gregor TagOrTemplate(TagOrTemplate) { } 9186569d68745c8213709740337d2be52b031384f58Douglas Gregor 9196569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this is a "top-level" class, meaning that it is 9206569d68745c8213709740337d2be52b031384f58Douglas Gregor /// not nested within another class. 9216569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TopLevelClass : 1; 9226569d68745c8213709740337d2be52b031384f58Douglas Gregor 9236569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this class had an associated template 9246569d68745c8213709740337d2be52b031384f58Douglas Gregor /// scope. When true, TagOrTemplate is a template declaration; 9256569d68745c8213709740337d2be52b031384f58Douglas Gregor /// othewise, it is a tag declaration. 9266569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TemplateScope : 1; 9276569d68745c8213709740337d2be52b031384f58Douglas Gregor 9286569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The class or class template whose definition we are parsing. 929d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagOrTemplate; 93072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 931d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarations - Method declarations, inline definitions and 932d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// nested classes that contain pieces whose parsing will be delayed until 933d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// the top-level class is fully defined. 934d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateParsedDeclarationsContainer LateParsedDeclarations; 93572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 9364cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 9376569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The stack of classes that is currently being 9386569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed. Nested and local classes will be pushed onto this stack 9396569d68745c8213709740337d2be52b031384f58Douglas Gregor /// when they are parsed, and removed afterward. 9406569d68745c8213709740337d2be52b031384f58Douglas Gregor std::stack<ParsingClass *> ClassStack; 9414cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 9426569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingClass &getCurrentClass() { 9436569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "No lexed method stacks!"); 9446569d68745c8213709740337d2be52b031384f58Douglas Gregor return *ClassStack.top(); 9454cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 9464cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 9479257664568bf375b7790131a84d9a4fa30a5b7e3John McCall /// \brief RAII object used to manage the parsing of a class definition. 9486569d68745c8213709740337d2be52b031384f58Douglas Gregor class ParsingClassDefinition { 9496569d68745c8213709740337d2be52b031384f58Douglas Gregor Parser &P; 9506569d68745c8213709740337d2be52b031384f58Douglas Gregor bool Popped; 951eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Sema::ParsingClassState State; 9526569d68745c8213709740337d2be52b031384f58Douglas Gregor 9536569d68745c8213709740337d2be52b031384f58Douglas Gregor public: 954d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass) 955eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall : P(P), Popped(false), 956eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall State(P.PushParsingClass(TagOrTemplate, TopLevelClass)) { 9576569d68745c8213709740337d2be52b031384f58Douglas Gregor } 9586569d68745c8213709740337d2be52b031384f58Douglas Gregor 9596569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Pop this class of the stack. 9601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void Pop() { 9616569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!Popped && "Nested class has already been popped"); 9626569d68745c8213709740337d2be52b031384f58Douglas Gregor Popped = true; 963eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall P.PopParsingClass(State); 9646569d68745c8213709740337d2be52b031384f58Douglas Gregor } 9656569d68745c8213709740337d2be52b031384f58Douglas Gregor 9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ~ParsingClassDefinition() { 9676569d68745c8213709740337d2be52b031384f58Douglas Gregor if (!Popped) 968eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall P.PopParsingClass(State); 9696569d68745c8213709740337d2be52b031384f58Douglas Gregor } 9706569d68745c8213709740337d2be52b031384f58Douglas Gregor }; 9716569d68745c8213709740337d2be52b031384f58Douglas Gregor 9724d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief Contains information about any template-specific 9734d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// information that has been parsed prior to parsing declaration 9744d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// specifiers. 9754d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor struct ParsedTemplateInfo { 9761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsedTemplateInfo() 9774d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { } 9784d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 9794d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ParsedTemplateInfo(TemplateParameterLists *TemplateParams, 980c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool isSpecialization, 981c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool lastParameterListWasEmpty = false) 9824d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(isSpecialization? ExplicitSpecialization : Template), 983a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie TemplateParams(TemplateParams), 984c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(lastParameterListWasEmpty) { } 9854d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 98645f965581935791a018df829a14dff53c1dd8f47Douglas Gregor explicit ParsedTemplateInfo(SourceLocation ExternLoc, 98745f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation TemplateLoc) 9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Kind(ExplicitInstantiation), TemplateParams(0), 989c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), 990c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(false){ } 9914d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 9924d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The kind of template we are parsing. 9934d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor enum { 9944d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are not parsing a template at all. 9954d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor NonTemplate = 0, 9964d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing a template declaration. 9974d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor Template, 9984d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit specialization. 9994d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitSpecialization, 10004d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit instantiation. 10014d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitInstantiation 10024d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } Kind; 10034d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 10044d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The template parameter lists, for template declarations 10054d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// and explicit specializations. 10064d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParameterLists *TemplateParams; 10074d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 100845f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// \brief The location of the 'extern' keyword, if any, for an explicit 100945f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// instantiation 101045f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation ExternLoc; 10111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The location of the 'template' keyword, for an explicit 10134d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// instantiation. 10144d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation TemplateLoc; 1015a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1016c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor /// \brief Whether the last template parameter list was empty. 1017c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool LastParameterListWasEmpty; 101878b810559d89e996e00684335407443936ce34a1John McCall 1019aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 10204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor }; 10211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10228387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet /// \brief Contains a late templated function. 10238387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet /// Will be parsed at the end of the translation unit. 10248387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet struct LateParsedTemplatedFunction { 1025e1fca502e7f1349e9b4520a4ca9a02413bcf2b14Francois Pichet explicit LateParsedTemplatedFunction(Decl *MD) 10268387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet : D(MD) {} 10278387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 10288387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet CachedTokens Toks; 1029a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 10308387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet /// \brief The template function declaration to be late parsed. 1031a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie Decl *D; 10328387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet }; 10338387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 10348387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet void LexTemplateFunctionForLateParsing(CachedTokens &Toks); 10358387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet void ParseLateTemplatedFuncDef(LateParsedTemplatedFunction &LMT); 10368387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet typedef llvm::DenseMap<const FunctionDecl*, LateParsedTemplatedFunction*> 10378387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet LateParsedTemplateMapT; 10388387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet LateParsedTemplateMapT LateParsedTemplateMap; 10398387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 10404a47e8d35dc1778ef7e428d9edd7676be67e725fFrancois Pichet static void LateTemplateParserCallback(void *P, const FunctionDecl *FD); 10414a47e8d35dc1778ef7e428d9edd7676be67e725fFrancois Pichet void LateTemplateParser(const FunctionDecl *FD); 10428387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 1043eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Sema::ParsingClassState 1044eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass); 104537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void DeallocateParsedClasses(ParsingClass *Class); 1046eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall void PopParsingClass(Sema::ParsingClassState); 104737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor 10485f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen Decl *ParseCXXInlineMethodDef(AccessSpecifier AS, AttributeList *AccessAttrs, 10495f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen ParsingDeclarator &D, 10504867347e82648d3baf09524b98b09c297a5a198fNico Weber const ParsedTemplateInfo &TemplateInfo, 1051a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie const VirtSpecifiers& VS, 105245fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor FunctionDefinitionKind DefinitionKind, 105345fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor ExprResult& Init); 10547a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseCXXNonStaticMemberInitializer(Decl *VarD); 1055eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void ParseLexedAttributes(ParsingClass &Class); 1056c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D, 1057c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins bool EnterScope, bool OnDefinition); 1058c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins void ParseLexedAttribute(LateParsedAttribute &LA, 1059c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins bool EnterScope, bool OnDefinition); 106037b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDeclarations(ParsingClass &Class); 1061d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM); 106237b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDefs(ParsingClass &Class); 1063d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor void ParseLexedMethodDef(LexedMethod &LM); 10647a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseLexedMemberInitializers(ParsingClass &Class); 10657a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI); 10666c89eafc90f5c51a0bf185a993961170aee530c2Fariborz Jahanian void ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod); 1067a891a32d3762ee641a29c091d286f2a7432671a5Sebastian Redl bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks); 106814b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeAndStoreUntil(tok::TokenKind T1, 106914b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis CachedTokens &Toks, 107014b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 107114b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeFinalToken = true) { 107214b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken); 107314b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis } 10741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 107537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor CachedTokens &Toks, 107614b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 107737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor bool ConsumeFinalToken = true); 10784d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 10794cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.9: External Definitions. 10817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct ParsedAttributesWithRange : ParsedAttributes { 10820b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange(AttributeFactory &factory) 10830b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall : ParsedAttributes(factory) {} 10840b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 10857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceRange Range; 10867f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall }; 10877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 10887f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs, 108909a63c97b95eb4dc6fd6b2323929e8cf12af03ffDouglas Gregor ParsingDeclSpec *DS = 0); 1090e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt bool isDeclarationAfterDeclarator(); 1091004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); 10922edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt DeclGroupPtrTy ParseDeclarationOrFunctionDefinition( 10932edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt ParsedAttributesWithRange &attrs, 10942edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt ParsingDeclSpec *DS = 0, 10953acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AccessSpecifier AS = AS_none); 10962edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs, 10972edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt ParsingDeclSpec &DS, 10982edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt AccessSpecifier AS); 1099a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1100d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseFunctionDefinition(ParsingDeclarator &D, 1101c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1102c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins LateParsedAttrList *LateParsedAttrs = 0); 11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseKNRParamDeclarations(Declarator &D); 1104ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 1105ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the simple-asm. 110660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0); 110760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAsmStringLiteral(); 11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11093536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Objective-C External Declarations 1110bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor DeclGroupPtrTy ParseObjCAtDirectives(); 1111bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); 1112d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, 11137f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &prefixAttrs); 1114d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseObjCClassInstanceVariables(Decl *interfaceDecl, 111583c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 111660fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc); 1117686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P, 1118686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceLocation> &PLocs, 11191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool WarnOnDeclarations, 112071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, 1121e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SourceLocation &EndProtoLoc); 112246f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor bool ParseObjCProtocolQualifiers(DeclSpec &DS); 11232f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, 11242f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian Decl *CDecl); 1125bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc, 1126bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor ParsedAttributes &prefixAttrs); 11271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1128849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis struct ObjCImplParsingDataRAII { 1129849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Parser &P; 1130849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Decl *Dcl; 11316c89eafc90f5c51a0bf185a993961170aee530c2Fariborz Jahanian bool HasCFunction; 1132849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer; 1133849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis LateParsedObjCMethodContainer LateParsedObjCMethods; 1134849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1135849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ObjCImplParsingDataRAII(Parser &parser, Decl *D) 11366c89eafc90f5c51a0bf185a993961170aee530c2Fariborz Jahanian : P(parser), Dcl(D), HasCFunction(false) { 1137849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis P.CurParsedObjCImpl = this; 1138849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis Finished = false; 1139849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis } 1140849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ~ObjCImplParsingDataRAII(); 1141849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1142849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis void finish(SourceRange AtEnd); 1143849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis bool isFinished() const { return Finished; } 1144849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis 1145849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis private: 1146849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis bool Finished; 1147849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis }; 1148849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis ObjCImplParsingDataRAII *CurParsedObjCImpl; 11496c89eafc90f5c51a0bf185a993961170aee530c2Fariborz Jahanian void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl); 11500416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 1151849639d8b548519cc5a00c0c9253f0c0d525060dArgyrios Kyrtzidis DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc); 1152140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd); 1153d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc); 1154d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertySynthesize(SourceLocation atLoc); 1155d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertyDynamic(SourceLocation atLoc); 11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11572fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); 115834870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner // Definitions for Objective-c context sensitive keywords recognition. 115934870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner enum ObjCTypeQual { 116034870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, 116134870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_NumQuals 116234870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner }; 1163a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; 11641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1165335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian bool isTokIdentifier_in() const; 1166d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 1167cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, Declarator::TheContext Ctx, 1168cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParsedAttributes *ParamAttrs); 1169294494e1cce92043562b4680c613df7fd028c02eSteve Naroff void ParseObjCMethodRequirement(); 1170a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *ParseObjCMethodPrototype( 117190ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 117290ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition = true); 1173d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, 117490ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 117590ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition=true); 1176a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian void ParseObjCPropertyAttribute(ObjCDeclSpec &DS); 11771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1178d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDefinition(); 11791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 11815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.5: Expressions. 1182a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1183cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain /// TypeCastState - State whether an expression is or may be a type cast. 1184cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain enum TypeCastState { 1185cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain NotTypeCast = 0, 1186cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain MaybeTypeCast, 1187cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain IsTypeCast 1188cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain }; 1189cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain 1190cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain ExprResult ParseExpression(TypeCastState isTypeCast = NotTypeCast); 1191e43fe993a079795ac3d2ba7c9ec5e2a0c8069918Kaelyn Uhrain ExprResult ParseConstantExpression(TypeCastState isTypeCast = NotTypeCast); 11922f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl // Expr that doesn't include commas. 1193cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain ExprResult ParseAssignmentExpression(TypeCastState isTypeCast = NotTypeCast); 11942f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 119560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 119760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); 1198adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman 119960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, 1200312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor prec::Level MinPrec); 120160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 1202312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool isAddressOfOperand, 1203312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool &NotCastExpr, 1204cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain TypeCastState isTypeCast); 120560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 1206312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool isAddressOfOperand = false, 1207cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain TypeCastState isTypeCast = NotTypeCast); 12089c72c6088d591ace8503b842d39448c2040f3033John McCall 12099c72c6088d591ace8503b842d39448c2040f3033John McCall /// Returns true if the next token would start a postfix-expression 12109c72c6088d591ace8503b842d39448c2040f3033John McCall /// suffix. 12119c72c6088d591ace8503b842d39448c2040f3033John McCall bool isPostfixExpressionSuffixStart() { 12129c72c6088d591ace8503b842d39448c2040f3033John McCall tok::TokenKind K = Tok.getKind(); 12139c72c6088d591ace8503b842d39448c2040f3033John McCall return (K == tok::l_square || K == tok::l_paren || 12149c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::period || K == tok::arrow || 12159c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::plusplus || K == tok::minusminus); 12169c72c6088d591ace8503b842d39448c2040f3033John McCall } 12179c72c6088d591ace8503b842d39448c2040f3033John McCall 121860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParsePostfixExpressionSuffix(ExprResult LHS); 1219f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult ParseUnaryExprOrTypeTraitExpression(); 122060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBuiltinPrimaryExpression(); 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1222f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, 12235ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis bool &isCastExpr, 1224b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 12255ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis SourceRange &CastRange); 12260cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 1227686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<Expr*, 20> ExprListTy; 1228686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<SourceLocation, 20> CommaLocsTy; 12290cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 12300cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis /// ParseExpressionList - Used for C/C++ (argument-)expression-list. 1231686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool ParseExpressionList(SmallVectorImpl<Expr*> &Exprs, 1232686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceLocation> &CommaLocs, 1233f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall void (Sema::*Completer)(Scope *S, 1234f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Data, 123513a140caba448a66ffcc5ff0d32a87d6e4f4ad3fAhmed Charles llvm::ArrayRef<Expr *> Args) = 0, 1236ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Expr *Data = 0); 1237d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl 12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParenParseOption - Control what ParseParenExpression will parse. 12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ParenParseOption { 12405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SimpleExpr, // Only parse '(' expression ')' 12415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundStmt, // Also allow '(' compound-statement ')' 12425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}' 12435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CastExpr // Also allow '(' type-name ')' <anything> 12445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 124560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseParenExpression(ParenParseOption &ExprType, 12460350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis bool stopIfCastExpr, 12470a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis bool isTypeCast, 1248b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 1249d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl SourceLocation &RParenLoc); 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, 12524a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor ParsedType &CastTy, 12534a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker); 125460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCompoundLiteralExpression(ParsedType Ty, 1255d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation LParenLoc, 1256d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation RParenLoc); 12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125899831e4677a7e2e051af636221694d60ba31fcdbRichard Smith ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral = false); 1259eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1260f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult ParseGenericSelectionExpression(); 1261ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 1262ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCBoolLiteral(); 1263f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1264eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 1265eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // C++ Expressions 126660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); 12674bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis 126819a2702042b7e3ee838cca458b35f607111a3897Richard Smith bool areTokensAdjacent(const Token &A, const Token &B); 126919a2702042b7e3ee838cca458b35f607111a3897Richard Smith 1270950be71c745409e373ae8a834490f9026c8ac222Richard Trieu void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr, 1271950be71c745409e373ae8a834490f9026c8ac222Richard Trieu bool EnteringContext, IdentifierInfo &II, 1272950be71c745409e373ae8a834490f9026c8ac222Richard Trieu CXXScopeSpec &SS); 1273950be71c745409e373ae8a834490f9026c8ac222Richard Trieu 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 1275b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1276b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor bool EnteringContext, 12774147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet bool *MayBePseudoDestructor = 0, 12784147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet bool IsTypename = false); 12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1281ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // C++0x 5.1.2: Lambda expressions 1282ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 1283ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // [...] () -> type {...} 1284ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult ParseLambdaExpression(); 1285ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult TryParseLambdaExpression(); 1286ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor llvm::Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro); 1287ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor bool TryParseLambdaIntroducer(LambdaIntroducer &Intro); 1288ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult ParseLambdaExpressionAfterIntroducer( 1289ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor LambdaIntroducer &Intro); 1290ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 1291ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor //===--------------------------------------------------------------------===// 12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 5.2p1: C++ Casts 129360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXCasts(); 12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1296c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // C++ 5.2p1: C++ Type Identification 129760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeid(); 1298c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 1299c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl //===--------------------------------------------------------------------===// 130001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // C++ : Microsoft __uuidof Expression 130101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult ParseCXXUuidof(); 130201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 130301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet //===--------------------------------------------------------------------===// 1304d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // C++ 5.2.4: C++ Pseudo-Destructor Expressions 130560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, 1306d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor tok::TokenKind OpKind, 1307d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CXXScopeSpec &SS, 1308b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType); 1309d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 1310d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor //===--------------------------------------------------------------------===// 13114cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 9.3.2: C++ 'this' pointer 131260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXThis(); 13134cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 13144cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 131550dd289f45738ed22b7583d52ed2525b927042ffChris Lattner // C++ 15: C++ Throw Expression 131660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseThrowExpression(); 13177acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 131874e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor ExceptionSpecificationType tryParseExceptionSpecification( 13197acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange &SpecificationRange, 1320686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParsedType> &DynamicExceptions, 1321686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceRange> &DynamicExceptionRanges, 1322a058fd4f0a944174295f77169b438510dad389f8Richard Smith ExprResult &NoexceptExpr); 13237acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 1324ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc is filled with the location of the last token of the specification. 13257acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExceptionSpecificationType ParseDynamicExceptionSpecification( 13267acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange &SpecificationRange, 1327686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParsedType> &Exceptions, 1328686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceRange> &Ranges); 132950dd289f45738ed22b7583d52ed2525b927042ffChris Lattner 133050dd289f45738ed22b7583d52ed2525b927042ffChris Lattner //===--------------------------------------------------------------------===// 1331dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // C++0x 8: Function declaration trailing-return-type 1332ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor TypeResult ParseTrailingReturnType(SourceRange &Range); 1333dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 1334dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor //===--------------------------------------------------------------------===// 13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 2.13.5: C++ Boolean Literals 133660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXBoolLiteral(); 13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1339987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // C++ 5.2.3: Explicit type conversion (functional notation) 134060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); 1341987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1342987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 1343987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// This should only be called when the current token is known to be part of 1344987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// simple-type-specifier. 1345987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); 1346987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 13472f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); 13482f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 1349987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 13504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // C++ 5.3.4 and 5.3.5: C++ new and delete 1351686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs, 1352ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Declarator &D); 13534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDirectNewDeclarator(Declarator &D); 135460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); 135560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXDeleteExpression(bool UseGlobal, 135659232d35f5820e334b6c8b007ae8006f4390055dChris Lattner SourceLocation Start); 13574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 13584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl //===--------------------------------------------------------------------===// 135999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor // C++ if/switch/while condition expression. 136060d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult, 1361586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, bool ConvertToBoolean); 136271b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 136371b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 136412e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor // C++ types 136512e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor 136612e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor //===--------------------------------------------------------------------===// 13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7.8: Initialization. 13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13690eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// ParseInitializer 13700eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// initializer: [C99 6.7.8] 13710eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// assignment-expression 13720eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// '{' ... 137360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializer() { 13740eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner if (Tok.isNot(tok::l_brace)) 137520df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ParseAssignmentExpression(); 13760eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner return ParseBraceInitializer(); 13770eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner } 1378b3f323d6c41cb614a249dbc4af7493762786521aDouglas Gregor bool MayBeDesignationStart(); 137960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBraceInitializer(); 138060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializerWithPotentialDesignator(); 13811d922960e083906a586609ac6978678147250177Sebastian Redl 13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1383296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // clang Expressions 13841d922960e083906a586609ac6978678147250177Sebastian Redl 138560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBlockLiteralExpression(); // ^{...} 1386296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff 1387296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff //===--------------------------------------------------------------------===// 13885508518a2702b00be3b15a26d772bde968972f54Anders Carlsson // Objective-C Expressions 138960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCAtExpression(SourceLocation AtLocation); 139060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCStringLiteral(SourceLocation AtLoc); 1391ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc); 1392ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc); 1393ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc, bool ArgValue); 1394ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc); 1395ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc); 1396eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc); 139760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); 139860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); 139960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); 14001b730e847ded503f2e615154035c083c4f94a067Douglas Gregor bool isSimpleObjCMessageExpression(); 140160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpression(); 140260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, 14035cb94a78202ccb1007df0be86884297761f4a53aNico Weber SourceLocation SuperLoc, 14045cb94a78202ccb1007df0be86884297761f4a53aNico Weber ParsedType ReceiverType, 14055cb94a78202ccb1007df0be86884297761f4a53aNico Weber ExprArg ReceiverExpr); 140660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAssignmentExprWithObjCMessageExprStart( 14072725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation LBracloc, SourceLocation SuperLoc, 1408b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, ExprArg ReceiverExpr); 14096aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr); 1410ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 14115508518a2702b00be3b15a26d772bde968972f54Anders Carlsson //===--------------------------------------------------------------------===// 14125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.8: Statements and Blocks. 141361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 14144e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer /// A SmallVector of statements, with stack size 32 (as that is the only one 14154e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer /// used.) 14164e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer typedef SmallVector<Stmt*, 32> StmtVector; 14174e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer /// A SmallVector of expressions, with stack size 12 (the maximum used.) 14184e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer typedef SmallVector<Expr*, 12> ExprVector; 14194e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer /// A SmallVector of types. 14204e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer typedef SmallVector<ParsedType, 12> TypeVector; 14214e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer 1422534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseStatement(SourceLocation *TrailingElseLoc = 0) { 14234e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer StmtVector Stmts; 14245cb94a78202ccb1007df0be86884297761f4a53aNico Weber return ParseStatementOrDeclaration(Stmts, true, TrailingElseLoc); 142561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 1426534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseStatementOrDeclaration(StmtVector &Stmts, 14275cb94a78202ccb1007df0be86884297761f4a53aNico Weber bool OnlyStatement, 1428534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceLocation *TrailingElseLoc = 0); 1429534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseStatementOrDeclarationAfterAttributes( 1430534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtVector &Stmts, 1431534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith bool OnlyStatement, 1432534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceLocation *TrailingElseLoc, 1433534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith ParsedAttributesWithRange &Attrs); 1434534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseExprStatement(); 1435534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs); 1436534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseCaseStatement(bool MissingCase = false, 1437bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu ExprResult Expr = ExprResult()); 1438534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseDefaultStatement(); 1439534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseCompoundStatement(bool isStmtExpr = false); 1440534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseCompoundStatement(bool isStmtExpr, 1441bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor unsigned ScopeFlags); 144260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCompoundStatementBody(bool isStmtExpr = false); 144360d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseParenExprOrCondition(ExprResult &ExprResult, 1444d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *&DeclResult, 1445586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, 144644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis bool ConvertToBoolean); 1447534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc); 1448534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc); 1449534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc); 1450534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseDoStatement(); 1451534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseForStatement(SourceLocation *TrailingElseLoc); 1452534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseGotoStatement(); 1453534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseContinueStatement(); 1454534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseBreakStatement(); 1455534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseReturnStatement(); 145660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseAsmStatement(bool &msAsm); 14573fedbe1f71c18fba01d39109d606f421a0103a2aEli Friedman StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc); 1458a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 14593896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Describes the behavior that should be taken for an __if_exists 14603896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// block. 14613896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor enum IfExistsBehavior { 14623896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Parse the block; this code is always used. 14633896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Parse, 14643896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Skip the block entirely; this code is never used. 14653896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Skip, 14663896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Parse the block as a dependent block, which may be used in 14673896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// some template instantiations but not others. 14683896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Dependent 14693896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor }; 1470a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1471a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// \brief Describes the condition of a Microsoft __if_exists or 14723896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// __if_not_exists block. 14733896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor struct IfExistsCondition { 14743896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The location of the initial keyword. 14753896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor SourceLocation KeywordLoc; 1476a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// \brief Whether this is an __if_exists block (rather than an 14773896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// __if_not_exists block). 14783896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor bool IsIfExists; 1479a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 14803896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Nested-name-specifier preceding the name. 14813896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor CXXScopeSpec SS; 1482a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 14833896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The name we're looking for. 14843896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor UnqualifiedId Name; 14853896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor 14863896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The behavior of this __if_exists or __if_not_exists block 14873896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// should. 14883896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IfExistsBehavior Behavior; 1489534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith }; 1490a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 14913896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result); 14921e862693c63067ae467b0b3884c44f753cd6e821Francois Pichet void ParseMicrosoftIfExistsStatement(StmtVector &Stmts); 1493563a645de82231a55e221fe655b7188bf8369662Francois Pichet void ParseMicrosoftIfExistsExternalDeclaration(); 1494563a645de82231a55e221fe655b7188bf8369662Francois Pichet void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, 1495563a645de82231a55e221fe655b7188bf8369662Francois Pichet AccessSpecifier& CurAS); 14969d24a8be93b28488dbfb9bbe8aa6fe35b21a5b0cFrancois Pichet bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, 14979d24a8be93b28488dbfb9bbe8aa6fe35b21a5b0cFrancois Pichet bool &InitExprsOk); 1498f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names, 1499f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu SmallVectorImpl<Expr *> &Constraints, 1500f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu SmallVectorImpl<Expr *> &Exprs); 1501a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1502a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1503a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // C++ 6: Statements and Blocks 1504a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1505534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseCXXTryBlock(); 150660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc); 150760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXCatchBlock(); 1508a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1509a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 151028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley // MS: SEH Statements and Blocks 151128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1512534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult ParseSEHTryBlock(); 151328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHTryBlockCommon(SourceLocation Loc); 151428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHExceptBlock(SourceLocation Loc); 151528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHFinallyBlock(SourceLocation Loc); 151628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 151728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley //===--------------------------------------------------------------------===// 1518a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // Objective-C Statements 1519a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 152060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCAtStatement(SourceLocation atLoc); 152160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCTryStmt(SourceLocation atLoc); 152260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCThrowStmt(SourceLocation atLoc); 152360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); 1524f85e193739c953358c865005855253af4f68a497John McCall StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc); 1525b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 15285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7: Declarations. 152967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall 153067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// A context for parsing declaration specifiers. TODO: flesh this 153167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// out, there are other significant restrictions on specifiers than 153267d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// would be best implemented in the parser. 153367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall enum DeclSpecContext { 153467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DSC_normal, // normal context 15350efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_class, // class context, enables 'friend' 1536a971d2410fabb093954c4119d2287ac24208ea8dRichard Smith DSC_type_specifier, // C++ type-specifier-seq or C specifier-qualifier-list 15377796eb5643244f3134834253ce5ea89107ac21c1Richard Smith DSC_trailing, // C++11 trailing-type-specifier in a trailing return type 15380efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_top_level // top-level/namespace declaration context 153967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall }; 15401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1541ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Information on a C++0x for-range-initializer found while parsing a 1542ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// declaration which turns out to be a for-range-declaration. 1543ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith struct ForRangeInit { 1544ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation ColonLoc; 1545ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult RangeExpr; 1546ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 1547ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); } 1548ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith }; 1549ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 1550c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts, 1551c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian unsigned Context, SourceLocation &DeclEnd, 15527f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributesWithRange &attrs); 1553c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts, 1554c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian unsigned Context, 1555bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 15562edf0a2520313cde900799b1eb9bd11c9c776afeSean Hunt ParsedAttributesWithRange &attrs, 1557ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool RequireSemi, 1558ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ForRangeInit *FRI = 0); 15590706df40064d4d7559b4304af79d519033414b84Richard Smith bool MightBeDeclarator(unsigned Context); 156054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, 1561d8ac05753dc4506224d445ff98399c01da3136e5John McCall bool AllowFunctionDefinitions, 1562ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation *DeclEnd = 0, 1563ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ForRangeInit *FRI = 0); 1564d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationAfterDeclarator(Declarator &D, 1565e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1566c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins bool ParseAsmAttributesAfterDeclarator(Declarator &D); 1567ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Decl *ParseDeclarationAfterDeclaratorAndAttributes(Declarator &D, 1568ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1569c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope); 1570c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope); 1571d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 15720fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// \brief When in code-completion, skip parsing of the function/method body 15730fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// unless the body contains the code-completion point. 15740fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// 15750fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// \returns true if the function body was skipped. 15766a91d385618ea4d28236c496f540a26877c95525Erik Verbruggen bool trySkippingFunctionBody(); 15770fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis 1578f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, 15794d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 158069730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith AccessSpecifier AS, DeclSpecContext DSC); 15810efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); 15821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseDeclarationSpecifiers(DeclSpec &DS, 15834d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 158467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall AccessSpecifier AS = AS_none, 15852287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins DeclSpecContext DSC = DSC_normal, 15862287c5e2352fc51cd74e8a9a7725cbf87e41c007DeLesley Hutchins LateParsedAttrList *LateAttrs = 0); 15874d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 158869730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith void ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS = AS_none, 158969730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith DeclSpecContext DSC = DSC_normal); 15901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1591cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall void ParseObjCTypeQualifierList(ObjCDeclSpec &DS, 1592cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Declarator::TheContext Context); 15935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15944c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, 159569730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith const ParsedTemplateInfo &TemplateInfo, 159669730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith AccessSpecifier AS, DeclSpecContext DSC); 1597d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl); 15985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, 1599d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 1600bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1601bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct FieldCallback { 1602dcdff46dd8e6d749283fe6c43adfcfe780c1d562Eli Friedman virtual void invoke(ParsingFieldDeclarator &Field) = 0; 16036c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual ~FieldCallback() {} 16046c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall 16056c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall private: 16066c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual void _anchor(); 1607bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall }; 1608d0014540005f2a5ab837365db6bd40f479406758John McCall struct ObjCPropertyCallback; 1609bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1610f66a0dda541cd859a928193efba6dc5d7ba8fe54Eli Friedman void ParseStructDeclaration(ParsingDeclSpec &DS, FieldCallback &Callback); 16111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16129497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false); 1613eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isTypeSpecifierQualifier(); 16145f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff bool isTypeQualifier() const; 1615a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1616b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// isKnownToBeTypeSpecifier - Return true if we know that the specified token 1617b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// is definitely a type-specifier. Return false if it isn't part of a type 1618b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// specifier or if we're not sure. 1619b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool isKnownToBeTypeSpecifier(const Token &Tok) const; 16205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16215404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isDeclarationStatement - Disambiguates between a declaration or an 16225404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// expression statement, when parsing function bodies. 16235404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for declaration, false for expression. 16245404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isDeclarationStatement() { 16254e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 16265404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isCXXDeclarationStatement(); 16279497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return isDeclarationSpecifier(true); 16285404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 16295404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 16309490ab433deef70105d817616928d700f87642d9Eli Friedman /// isForInitDeclaration - Disambiguates between a declaration or an 16319490ab433deef70105d817616928d700f87642d9Eli Friedman /// expression in the context of the C 'clause-1' or the C++ 1632bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis // 'for-init-statement' part of a 'for' statement. 1633bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// Returns true for declaration, false for expression. 16349490ab433deef70105d817616928d700f87642d9Eli Friedman bool isForInitDeclaration() { 16354e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 16369490ab433deef70105d817616928d700f87642d9Eli Friedman return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/true); 16379497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return isDeclarationSpecifier(true); 1638bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis } 1639bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis 16409497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor /// \brief Determine whether we are currently at the start of an Objective-C 16419497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor /// class message that appears to be missing the open bracket '['. 16429497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor bool isStartOfObjCClassMessageMissingOpenBracket(); 1643a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 16440efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief Starting with a scope specifier, identifier, or 16450efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id that refers to the current class, determine whether 16460efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// this is a constructor declarator. 16470efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor bool isConstructorDeclarator(); 16480efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 16498b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// \brief Specifies the context in which type-id/expression 16508b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// disambiguation will occur. 16518b642592a35167a3780074e78674e0bece87c40cDouglas Gregor enum TentativeCXXTypeIdContext { 16528b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdInParens, 16538b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdAsTemplateArgument 16548b642592a35167a3780074e78674e0bece87c40cDouglas Gregor }; 16558b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 16568b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 165778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know 165878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// whether the parens contain an expression or a type-id. 165978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// Returns true for a type-id and false for an expression. 1660f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens(bool &isAmbiguous) { 16614e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 1662f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(TypeIdInParens, isAmbiguous); 1663f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis isAmbiguous = false; 166478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis return isTypeSpecifierQualifier(); 166578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis } 1666f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens() { 1667f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1668f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isTypeIdInParens(isAmbiguous); 1669f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 167078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 16715404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXDeclarationStatement - C++-specialized function that disambiguates 16725404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a declaration or an expression statement, when parsing function 16735404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// bodies. Returns true for declaration, false for expression. 16745404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXDeclarationStatement(); 16755404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 16765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXSimpleDeclaration - C++-specialized function that disambiguates 16775404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a simple-declaration or an expression-statement. 16785404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 16795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 16805404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns false if the statement is disambiguated as expression. 16819490ab433deef70105d817616928d700f87642d9Eli Friedman bool isCXXSimpleDeclaration(bool AllowForRangeDecl); 16825404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 16835404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXFunctionDeclarator - Disambiguates between a function declarator or 16845404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// a constructor-style initializer, when parsing declaration statements. 16855404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for function declarator and false for constructor-style 1686b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith /// initializer. Sets 'IsAmbiguous' to true to indicate that this declaration 1687b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith /// might be a constructor-style initializer. 16885404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 16895404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1690b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith bool isCXXFunctionDeclarator(bool *IsAmbiguous = 0); 16915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1692a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// isCXXConditionDeclaration - Disambiguates between a declaration or an 1693a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// expression for a condition of a if/switch/while/for statement. 1694a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 1695a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1696a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis bool isCXXConditionDeclaration(); 1697a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis 1698f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); 1699f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context) { 1700f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1701f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(Context, isAmbiguous); 1702f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 170378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 1704b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult - Used as the result value for functions whose purpose is to 1705b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// disambiguate C++ constructs by "tentatively parsing" them. 1706b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// This is a class instead of a simple enum because the implicit enum-to-bool 1707b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// conversions may cause subtle bugs. 1708b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis class TPResult { 1709b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis enum Result { 1710b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_true, 1711b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_false, 1712b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_ambiguous, 1713b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_error 1714b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis }; 1715b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis Result Res; 1716b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult(Result result) : Res(result) {} 1717b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis public: 1718b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult True() { return TPR_true; } 1719b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult False() { return TPR_false; } 1720b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Ambiguous() { return TPR_ambiguous; } 1721b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Error() { return TPR_error; } 1722b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis 1723b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator==(const TPResult &RHS) const { return Res == RHS.Res; } 1724b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; } 1725b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis }; 1726b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis 1727a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// \brief Based only on the given token kind, determine whether we know that 1728a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// we're at the start of an expression or a type-specifier-seq (which may 1729a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// be an expression, in C++). 1730a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// 1731a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// This routine does not attempt to resolve any of the trick cases, e.g., 1732a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// those involving lookup of identifiers. 1733a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// 1734a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// \returns \c TPR_true if this token starts an expression, \c TPR_false if 1735a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot 1736a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// tell. 1737a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind); 1738a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor 1739b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a 1740b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// declaration specifier, TPResult::False() if it is not, 1741b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult::Ambiguous() if it could be either a decl-specifier or a 1742b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// function-style cast, and TPResult::Error() if a parsing error was 1743d81e961f905e3ea57f6808e5a5686a8324270984Richard Smith /// encountered. If it could be a braced C++11 function-style cast, returns 1744d81e961f905e3ea57f6808e5a5686a8324270984Richard Smith /// BracedCastResult. 17455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Doesn't consume tokens. 1746d81e961f905e3ea57f6808e5a5686a8324270984Richard Smith TPResult 174725582fc0aeac053cdc115ee95cbed53f28bf592eRichard Smith isCXXDeclarationSpecifier(TPResult BracedCastResult = TPResult::False(), 174825582fc0aeac053cdc115ee95cbed53f28bf592eRichard Smith bool *HasMissingTypename = 0); 1749a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 17500576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// \brief Determine whether an identifier has been tentatively declared as a 17510576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// non-type. Such tentative declarations should not be found to name a type 17520576681bac125be07f77f66b02a3dba2c3a24557Richard Smith /// during a tentative parse, but also should not be annotated as a non-type. 17530576681bac125be07f77f66b02a3dba2c3a24557Richard Smith bool isTentativelyDeclared(IdentifierInfo *II); 17540576681bac125be07f77f66b02a3dba2c3a24557Richard Smith 17555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // "Tentative parsing" functions, used for disambiguation. If a parsing error 1756b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // is encountered they will return TPResult::Error(). 1757b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // Returning TPResult::True()/False() indicates that the ambiguity was 1758b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates 1759b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // that more tentative parsing is necessary for disambiguation. 17605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // They all consume tokens, so backtracking should be used after calling them. 17615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 176225582fc0aeac053cdc115ee95cbed53f28bf592eRichard Smith TPResult TryParseDeclarationSpecifier(bool *HasMissingTypename = 0); 17639490ab433deef70105d817616928d700f87642d9Eli Friedman TPResult TryParseSimpleDeclaration(bool AllowForRangeDecl); 1764b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseTypeofSpecifier(); 17659bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor TPResult TryParseProtocolQualifiers(); 1766b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseInitDeclaratorList(); 176778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); 176825582fc0aeac053cdc115ee95cbed53f28bf592eRichard Smith TPResult TryParseParameterDeclarationClause(bool *InvalidAsDeclaration = 0); 1769b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseFunctionDeclarator(); 1770b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseBracketDeclarator(); 17715404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1772683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor TypeResult ParseTypeName(SourceRange *Range = 0, 1773683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Declarator::TheContext Context 1774f85e193739c953358c865005855253af4f68a497John McCall = Declarator::TypeNameContext, 1775c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith AccessSpecifier AS = AS_none, 1776c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith Decl **OwnedType = 0); 177703f1eb031b84e93415b792c4b45d8da71c88e92dDouglas Gregor void ParseBlockId(SourceLocation CaretLoc); 17787f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 17796ee326af4e77e6f05973486097884d7431f2108dRichard Smith // Check for the start of a C++11 attribute-specifier-seq in a context where 17806ee326af4e77e6f05973486097884d7431f2108dRichard Smith // an attribute is not allowed. 17816ee326af4e77e6f05973486097884d7431f2108dRichard Smith bool CheckProhibitedCXX11Attribute() { 17826ee326af4e77e6f05973486097884d7431f2108dRichard Smith assert(Tok.is(tok::l_square)); 17836ee326af4e77e6f05973486097884d7431f2108dRichard Smith if (!getLangOpts().CPlusPlus0x || NextToken().isNot(tok::l_square)) 17846ee326af4e77e6f05973486097884d7431f2108dRichard Smith return false; 17856ee326af4e77e6f05973486097884d7431f2108dRichard Smith return DiagnoseProhibitedCXX11Attribute(); 17866ee326af4e77e6f05973486097884d7431f2108dRichard Smith } 17876ee326af4e77e6f05973486097884d7431f2108dRichard Smith bool DiagnoseProhibitedCXX11Attribute(); 17886ee326af4e77e6f05973486097884d7431f2108dRichard Smith 17897f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ProhibitAttributes(ParsedAttributesWithRange &attrs) { 17907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (!attrs.Range.isValid()) return; 17917f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DiagnoseProhibitedAttributes(attrs); 1792534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith attrs.clear(); 17937f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 17947f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs); 17957f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 1796eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void MaybeParseGNUAttributes(Declarator &D, 1797eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski LateParsedAttrList *LateAttrs = 0) { 17987f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (Tok.is(tok::kw___attribute)) { 17990b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 18007f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation endLoc; 1801eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski ParseGNUAttributes(attrs, &endLoc, LateAttrs); 18020b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall D.takeAttributes(attrs, endLoc); 18037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18057f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseGNUAttributes(ParsedAttributes &attrs, 1806eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation *endLoc = 0, 1807eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski LateParsedAttrList *LateAttrs = 0) { 18087f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (Tok.is(tok::kw___attribute)) 1809eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski ParseGNUAttributes(attrs, endLoc, LateAttrs); 18107f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18117f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseGNUAttributes(ParsedAttributes &attrs, 1812eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation *endLoc = 0, 1813eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski LateParsedAttrList *LateAttrs = 0); 1814eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void ParseGNUAttributeArgs(IdentifierInfo *AttrName, 1815eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation AttrNameLoc, 1816eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski ParsedAttributes &Attrs, 1817eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation *EndLoc); 18187f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 18197f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseCXX0XAttributes(Declarator &D) { 18206ee326af4e77e6f05973486097884d7431f2108dRichard Smith if (getLangOpts().CPlusPlus0x && isCXX11AttributeSpecifier()) { 18210b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrs(AttrFactory); 18227f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation endLoc; 1823c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith ParseCXX11Attributes(attrs, &endLoc); 18240b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall D.takeAttributes(attrs, endLoc); 18257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18267f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18277f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseCXX0XAttributes(ParsedAttributes &attrs, 18287f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc = 0) { 18296ee326af4e77e6f05973486097884d7431f2108dRichard Smith if (getLangOpts().CPlusPlus0x && isCXX11AttributeSpecifier()) { 18300b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrsWithRange(AttrFactory); 1831c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith ParseCXX11Attributes(attrsWithRange, endLoc); 18320b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall attrs.takeAllFrom(attrsWithRange); 18337f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18347f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18357f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseCXX0XAttributes(ParsedAttributesWithRange &attrs, 18366ee326af4e77e6f05973486097884d7431f2108dRichard Smith SourceLocation *endLoc = 0, 18376ee326af4e77e6f05973486097884d7431f2108dRichard Smith bool OuterMightBeMessageSend = false) { 18386ee326af4e77e6f05973486097884d7431f2108dRichard Smith if (getLangOpts().CPlusPlus0x && 18396ee326af4e77e6f05973486097884d7431f2108dRichard Smith isCXX11AttributeSpecifier(false, OuterMightBeMessageSend)) 1840c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith ParseCXX11Attributes(attrs, endLoc); 18417f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18423497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne 1843c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs, 18443497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne SourceLocation *EndLoc = 0); 1845c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith void ParseCXX11Attributes(ParsedAttributesWithRange &attrs, 18467f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *EndLoc = 0); 1847c56298d87a9df507805a548d7d515e8b511df2c0Richard Smith IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc); 18487f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 18497f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs, 18507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc = 0) { 18514e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().MicrosoftExt && Tok.is(tok::l_square)) 18527f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseMicrosoftAttributes(attrs, endLoc); 18537f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18547f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseMicrosoftAttributes(ParsedAttributes &attrs, 18557f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc = 0); 1856fc685ace387734599c475426b1a8efdb491054b8Aaron Ballman void ParseMicrosoftDeclSpec(ParsedAttributes &Attrs); 1857fc685ace387734599c475426b1a8efdb491054b8Aaron Ballman bool IsSimpleMicrosoftDeclSpec(IdentifierInfo *Ident); 1858fc685ace387734599c475426b1a8efdb491054b8Aaron Ballman void ParseComplexMicrosoftDeclSpec(IdentifierInfo *Ident, 1859fc685ace387734599c475426b1a8efdb491054b8Aaron Ballman SourceLocation Loc, 1860fc685ace387734599c475426b1a8efdb491054b8Aaron Ballman ParsedAttributes &Attrs); 1861fc685ace387734599c475426b1a8efdb491054b8Aaron Ballman void ParseMicrosoftDeclSpecWithSingleArg(IdentifierInfo *AttrName, 1862fc685ace387734599c475426b1a8efdb491054b8Aaron Ballman SourceLocation AttrNameLoc, 1863fc685ace387734599c475426b1a8efdb491054b8Aaron Ballman ParsedAttributes &Attrs); 18647f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs); 1865c052dbb2d8fe0e23e90d81236aab0f864f712b45John McCall void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs); 18667f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseBorlandTypeAttributes(ParsedAttributes &attrs); 1867f315fa81eef1977b3457fd7a7d4639e060fe7278Peter Collingbourne void ParseOpenCLAttributes(ParsedAttributes &attrs); 1868207f4d8543529221932af82836016a2ef066c917Peter Collingbourne void ParseOpenCLQualifiers(DeclSpec &DS); 18697f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 18700a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor VersionTuple ParseVersionTuple(SourceRange &Range); 18710a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor void ParseAvailabilityAttribute(IdentifierInfo &Availability, 18720a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor SourceLocation AvailabilityLoc, 18730a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor ParsedAttributes &attrs, 18740a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor SourceLocation *endLoc); 18750a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 1876b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski bool IsThreadSafetyAttribute(llvm::StringRef AttrName); 1877b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski void ParseThreadSafetyAttribute(IdentifierInfo &AttrName, 1878b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski SourceLocation AttrNameLoc, 1879b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski ParsedAttributes &Attrs, 1880b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski SourceLocation *EndLoc); 1881b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski 18820d5a069f66df09b3308ccfdce84a88170034c657Dmitri Gribenko void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName, 18830d5a069f66df09b3308ccfdce84a88170034c657Dmitri Gribenko SourceLocation AttrNameLoc, 18840d5a069f66df09b3308ccfdce84a88170034c657Dmitri Gribenko ParsedAttributes &Attrs, 18850d5a069f66df09b3308ccfdce84a88170034c657Dmitri Gribenko SourceLocation *EndLoc); 1886b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski 1887d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff void ParseTypeofSpecifier(DeclSpec &DS); 188842d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation ParseDecltypeSpecifier(DeclSpec &DS); 1889534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS, 189042d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation StartLoc, 189142d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation EndLoc); 1892db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt void ParseUnderlyingTypeSpecifier(DeclSpec &DS); 1893b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void ParseAtomicSpecifier(DeclSpec &DS); 1894b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 18950b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne ExprResult ParseAlignArgument(SourceLocation Start, 18960b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne SourceLocation &EllipsisLoc); 189782d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne void ParseAlignmentSpecifier(ParsedAttributes &Attrs, 189882d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne SourceLocation *endLoc = 0); 1899eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 19001c94c16317c1a35c1549e022958188eea2567089Richard Smith VirtSpecifiers::Specifier isCXX0XVirtSpecifier(const Token &Tok) const; 19011c94c16317c1a35c1549e022958188eea2567089Richard Smith VirtSpecifiers::Specifier isCXX0XVirtSpecifier() const { 19021c94c16317c1a35c1549e022958188eea2567089Richard Smith return isCXX0XVirtSpecifier(Tok); 19031c94c16317c1a35c1549e022958188eea2567089Richard Smith } 1904b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson void ParseOptionalCXX0XVirtSpecifierSeq(VirtSpecifiers &VS); 19051f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 19068a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson bool isCXX0XFinalKeyword() const; 1907cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 1908eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to 1909eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// enter a new C++ declarator scope and exit it when the function is 1910eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// finished. 1911eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis class DeclaratorScopeObj { 1912eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis Parser &P; 1913751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis CXXScopeSpec &SS; 1914f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis bool EnteredScope; 1915f7f3d0db754db0500b56d49ac19f795f13965912John McCall bool CreatedScope; 1916eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis public: 1917f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) 1918f7f3d0db754db0500b56d49ac19f795f13965912John McCall : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} 1919eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1920eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis void EnterDeclaratorScope() { 19212bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis assert(!EnteredScope && "Already entered the scope!"); 1922f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was not set!"); 1923f7f3d0db754db0500b56d49ac19f795f13965912John McCall 1924f7f3d0db754db0500b56d49ac19f795f13965912John McCall CreatedScope = true; 1925f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.EnterScope(0); // Not a decl scope. 1926f7f3d0db754db0500b56d49ac19f795f13965912John McCall 192723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS)) 19283fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor EnteredScope = true; 1929eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1930eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1931eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis ~DeclaratorScopeObj() { 1932f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis if (EnteredScope) { 1933f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was cleared ?"); 193423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS); 1935f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis } 1936f7f3d0db754db0500b56d49ac19f795f13965912John McCall if (CreatedScope) 1937f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.ExitScope(); 1938eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1939eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis }; 19401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseDeclarator - Parse and verify a newly-initialized declarator. 19425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDeclarator(Declarator &D); 19434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl /// A function that parses a variant of direct-declarator. 19444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef void (Parser::*DirectDeclParseFunction)(Declarator&); 19454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDeclaratorInternal(Declarator &D, 19464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl DirectDeclParseFunction DirectDeclParser); 19477f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 1948bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, 1949bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool CXX0XAttributesAllowed = true); 19505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDirectDeclarator(Declarator &D); 19515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseParenDeclarator(Declarator &D); 19524a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor void ParseFunctionDeclarator(Declarator &D, 19537f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs, 19544a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker, 1955b9c6261d02f688d0a9a36b736ad5956fbc737854Richard Smith bool IsAmbiguous, 19567399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner bool RequiresArg = false); 19573fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor bool isFunctionDeclaratorIdentifierList(); 19583fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor void ParseFunctionDeclaratorIdentifierList( 19593fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor Declarator &D, 1960686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo); 19613fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor void ParseParameterDeclarationClause( 19623fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor Declarator &D, 19633fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor ParsedAttributes &attrs, 1964686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo, 19653fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor SourceLocation &EllipsisLoc); 19665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseBracketDeclarator(Declarator &D); 19671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19688f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner //===--------------------------------------------------------------------===// 19698f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner // C++ 7: Declarations [dcl.dcl] 19701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19716ee326af4e77e6f05973486097884d7431f2108dRichard Smith /// The kind of attribute specifier we have found. 19726ee326af4e77e6f05973486097884d7431f2108dRichard Smith enum CXX11AttributeKind { 19736ee326af4e77e6f05973486097884d7431f2108dRichard Smith /// This is not an attribute specifier. 19746ee326af4e77e6f05973486097884d7431f2108dRichard Smith CAK_NotAttributeSpecifier, 19756ee326af4e77e6f05973486097884d7431f2108dRichard Smith /// This should be treated as an attribute-specifier. 19766ee326af4e77e6f05973486097884d7431f2108dRichard Smith CAK_AttributeSpecifier, 19776ee326af4e77e6f05973486097884d7431f2108dRichard Smith /// The next tokens are '[[', but this is not an attribute-specifier. This 19786ee326af4e77e6f05973486097884d7431f2108dRichard Smith /// is ill-formed by C++11 [dcl.attr.grammar]p6. 19796ee326af4e77e6f05973486097884d7431f2108dRichard Smith CAK_InvalidAttributeSpecifier 19806ee326af4e77e6f05973486097884d7431f2108dRichard Smith }; 19816ee326af4e77e6f05973486097884d7431f2108dRichard Smith CXX11AttributeKind 19826ee326af4e77e6f05973486097884d7431f2108dRichard Smith isCXX11AttributeSpecifier(bool Disambiguate = false, 19836ee326af4e77e6f05973486097884d7431f2108dRichard Smith bool OuterMightBeMessageSend = false); 1984a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1985d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd, 1986d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation InlineLoc = SourceLocation()); 1987f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc, 1988f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<IdentifierInfo*>& Ident, 1989f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<SourceLocation>& NamespaceLoc, 1990f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu unsigned int index, SourceLocation& InlineLoc, 19914a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor ParsedAttributes& attrs, 19924a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker); 1993d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context); 1994d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseUsingDirectiveOrDeclaration(unsigned Context, 199578b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 1996d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 1997c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith ParsedAttributesWithRange &attrs, 1998c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith Decl **OwnedType = 0); 199978b810559d89e996e00684335407443936ce34a1John McCall Decl *ParseUsingDirective(unsigned Context, 200078b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 20017f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation &DeclEnd, 20027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs); 200378b810559d89e996e00684335407443936ce34a1John McCall Decl *ParseUsingDeclaration(unsigned Context, 200478b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 200578b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 2006d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 2007c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith AccessSpecifier AS = AS_none, 2008c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith Decl **OwnedType = 0); 2009d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd); 2010d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc, 2011d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation AliasLoc, IdentifierInfo *Alias, 2012d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd); 20131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2014e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 2015e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 9: classes [class] and C structs/unions. 2016139be7007eba3bd491ca50297888be507753a95dRichard Smith bool isValidAfterTypeSpecifier(bool CouldBeBitfield); 20174c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, 201869730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo, 201969730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith AccessSpecifier AS, bool EnteringContext, 202069730c115c2d0fec2f20609d905d920a5a41b29bRichard Smith DeclSpecContext DSC); 20214cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType, 2022d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 2023552e29985a710f4ced62b39d70557501bd31ca9bDouglas Gregor ExprResult ParseCXXMemberInitializer(Decl *D, bool IsFunction, 20247a614d8380297fcd2bc23986241905d97222948cRichard Smith SourceLocation &EqualLoc); 20255f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen void ParseCXXClassMemberDeclaration(AccessSpecifier AS, AttributeList *Attr, 2026c9068d7dd94d439cec66c421115d15303e481025John McCall const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 2027c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject *DiagsFromTParams = 0); 2028d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseConstructorInitializer(Decl *ConstructorDecl); 2029d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall MemInitResult ParseMemInitializer(Decl *ConstructorDecl); 203074e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo, 203174e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor Decl *ThisDecl); 2032e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 2033e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 2034e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 10: Derived classes [class.derived] 2035a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc, 203622216eb4fb0936d2488fc03abd285d135c36ff01David Blaikie SourceLocation &EndLocation); 2037d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseBaseClause(Decl *ClassDecl); 2038d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall BaseResult ParseBaseSpecifier(Decl *ClassDecl); 20391b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor AccessSpecifier getAccessSpecifierIfPresent() const; 20401cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor 2041a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 2042e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 20433f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Name, 20443f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation NameLoc, 20453f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool EnteringContext, 2046b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2047d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor UnqualifiedId &Id, 2048e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool AssumeTemplateId); 2049ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, 2050b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2051ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &Result); 20523f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, 205302a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowDestructorName, 205402a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowConstructorName, 2055b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2056e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation& TemplateKWLoc, 20573f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &Result); 2058a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 20591cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor //===--------------------------------------------------------------------===// 2060adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14: Templates [temp] 2061c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 2062adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14.1: Template Parameters [temp.param] 2063d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationStartingWithTemplate(unsigned Context, 20645f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen SourceLocation &DeclEnd, 20655f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AccessSpecifier AS = AS_none, 20665f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AttributeList *AccessAttrs = 0); 2067d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context, 20685f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen SourceLocation &DeclEnd, 20695f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AccessSpecifier AS, 20705f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AttributeList *AccessAttrs); 2071d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseSingleDeclarationAfterTemplate( 20721426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor unsigned Context, 20734d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 2074c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject &DiagsFromParams, 20751426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor SourceLocation &DeclEnd, 20765f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AccessSpecifier AS=AS_none, 20775f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AttributeList *AccessAttrs = 0); 20781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseTemplateParameters(unsigned Depth, 2079686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Decl*> &TemplateParams, 20801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation &LAngleLoc, 2081c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor SourceLocation &RAngleLoc); 2082c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor bool ParseTemplateParameterList(unsigned Depth, 2083686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Decl*> &TemplateParams); 208498440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor bool isStartOfTemplateTypeParameter(); 2085d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateParameter(unsigned Depth, unsigned Position); 2086d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTypeParameter(unsigned Depth, unsigned Position); 2087d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); 2088d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); 2089d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor // C++ 14.3: Template arguments [temp.arg] 2090686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList; 2091cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 20927532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor bool ParseTemplateIdAfterTemplateName(TemplateTy Template, 20931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateNameLoc, 2094059101f922de6eb765601459925f4c8914420b23Douglas Gregor const CXXScopeSpec &SS, 2095cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor bool ConsumeLastToken, 2096cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &LAngleLoc, 2097cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateArgList &TemplateArgs, 2098cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &RAngleLoc); 2099cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 2100c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, 2101059101f922de6eb765601459925f4c8914420b23Douglas Gregor CXXScopeSpec &SS, 2102e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2103ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &TemplateName, 210439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor bool AllowTypeAnnotation = true); 2105059101f922de6eb765601459925f4c8914420b23Douglas Gregor void AnnotateTemplateIdTokenAsType(); 2106d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor bool IsTemplateArgumentList(unsigned Skip = 0); 2107314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); 2108788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor ParsedTemplateArgument ParseTemplateTemplateArgument(); 2109314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor ParsedTemplateArgument ParseTemplateArgument(); 21109241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis Decl *ParseExplicitInstantiation(unsigned Context, 21119241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis SourceLocation ExternLoc, 21129241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis SourceLocation TemplateLoc, 21139241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis SourceLocation &DeclEnd, 21149241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis AccessSpecifier AS = AS_none); 211564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 211664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl //===--------------------------------------------------------------------===// 21176aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor // Modules 21185948ae1021122164b22f74353bb7fe325a64f616Douglas Gregor DeclGroupPtrTy ParseModuleImport(SourceLocation AtLoc); 2119a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 21206aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor //===--------------------------------------------------------------------===// 212164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // GNU G++: Type Traits [Type-Traits.html in the GCC manual] 212260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseUnaryTypeTrait(); 21236ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet ExprResult ParseBinaryTypeTrait(); 21244ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ExprResult ParseTypeTrait(); 21254ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2126f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor //===--------------------------------------------------------------------===// 212721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley // Embarcadero: Arary and Expression Traits 212821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult ParseArrayTypeTrait(); 2129552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult ParseExpressionTrait(); 2130552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2131552622067dc45013d240f73952fece703f5e63bdJohn Wiegley //===--------------------------------------------------------------------===// 2132f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor // Preprocessor code-completion pass-through 2133f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor virtual void CodeCompleteDirective(bool InConditional); 2134f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor virtual void CodeCompleteInConditionalExclusion(); 21351fbb447e9d43c2c676e94081fbfee7eb6cbe933bDouglas Gregor virtual void CodeCompleteMacroName(bool IsDefinition); 2136f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor virtual void CodeCompletePreprocessorExpression(); 2137f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro, 2138f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor MacroInfo *MacroInfo, 2139f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor unsigned ArgumentIndex); 214055817afdf9d453a443262a733f6caf6692dca118Douglas Gregor virtual void CodeCompleteNaturalLanguage(); 21415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 21425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 21445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2146