Parser.h revision a44724d0d6d03568ec9acadc0781d612163008e1
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" 22f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "llvm/Support/PrettyStackTrace.h" 234726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek#include "llvm/ADT/OwningPtr.h" 244cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis#include <stack> 251100258c19dd8967ba078c0bc81fc06cea9d033fChris Lattner#include <list> 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 28fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar class PragmaHandler; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Scope; 302b5289b6fd7e3d9899868410a498c081c9595662John McCall class DeclGroupRef; 313cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner class DiagnosticBuilder; 320102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner class Parser; 334726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek class PragmaUnusedHandler; 3408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner class ColonProtectionRAIIObject; 350fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor class InMessageExpressionRAIIObject; 360fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 370102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// PrettyStackTraceParserEntry - If a crash happens while the parser is active, 380102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// an entry is printed for it. 390102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerclass PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry { 400102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Parser &P; 410102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerpublic: 420102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner PrettyStackTraceParserEntry(const Parser &p) : P(p) {} 430102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner virtual void print(llvm::raw_ostream &OS) const; 440102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner}; 451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 466aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// PrecedenceLevels - These are precedences for the binary/ternary 476aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// operators in the C99 grammar. These have been named to relate 486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// with the C99 grammar productions. Low precedences numbers bind 496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// more weakly than high numbers. 506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregornamespace prec { 516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor enum Level { 526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Unknown = 0, // Not binary operator. 536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Comma = 1, // , 546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Assignment = 2, // =, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |= 556aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Conditional = 3, // ? 566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor LogicalOr = 4, // || 576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor LogicalAnd = 5, // && 586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor InclusiveOr = 6, // | 596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ExclusiveOr = 7, // ^ 606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor And = 8, // & 616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Equality = 9, // ==, != 626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Relational = 10, // >=, <=, >, < 636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Shift = 11, // <<, >> 646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Additive = 12, // -, + 656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Multiplicative = 13, // *, /, % 666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor PointerToMember = 14 // .*, ->* 676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor }; 686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Parser - This implements a parser for the C family of languages. After 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// parsing units of the grammar, productions are invoked to handle whatever has 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// been read. 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 74f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregorclass Parser : public CodeCompletionHandler { 754726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek friend class PragmaUnusedHandler; 7608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner friend class ColonProtectionRAIIObject; 770fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor friend class InMessageExpressionRAIIObject; 7836d36806f1972f7ec1d2a3f59155187278c56508Argyrios Kyrtzidis friend class ParenBraceBracketBalancer; 790102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner PrettyStackTraceParserEntry CrashInfo; 801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Preprocessor &PP; 821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8397d0205d16fef2a783e785459b5f30f6a9dfbcb9Eric Christopher /// Tok - The current token we are peeking ahead. All parsing methods assume 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that this is valid. 85d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner Token Tok; 861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 874b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // PrevTokLocation - The location of the token we previously 884b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // consumed. This token is used for diagnostics where we expected to 894b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // see a token following another token (e.g., the ';' at the end of 904b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // a statement). 914b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceLocation PrevTokLocation; 924b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned short ParenCount, BracketCount, BraceCount; 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Actions - These are the callbacks we invoke as we parse various constructs 9687c300738174924453648c3b2d6f366c8284fac4Douglas Gregor /// in the file. 97f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &Actions; 981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diagnostic &Diags; 1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1019e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner /// ScopeCache - Cache scopes to reduce malloc traffic. 1029e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner enum { ScopeCacheSize = 16 }; 1039e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner unsigned NumCachedScopes; 1049e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner Scope *ScopeCache[ScopeCacheSize]; 105662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 106662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// Ident_super - IdentifierInfo for "super", to support fast 107662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// comparison. 108662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar IdentifierInfo *Ident_super; 10982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// Ident_vector and Ident_pixel - cached IdentifierInfo's for 11082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// "vector" and "pixel" fast comparison. Only present if 11182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// AltiVec enabled. 11282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_vector; 11382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_pixel; 114662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 115cbb98edd530787c2ac019e437e7c599df8004ba7Daniel Dunbar llvm::OwningPtr<PragmaHandler> AlignHandler; 116aa8b0d19244a6e7e8e5798fcc6aef003c274d3e0Eli Friedman llvm::OwningPtr<PragmaHandler> GCCVisibilityHandler; 117861800c676004eabed5927f0552620d06c80a40aDaniel Dunbar llvm::OwningPtr<PragmaHandler> OptionsHandler; 1184726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> PackHandler; 1194726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> UnusedHandler; 1209991479ad5dde617168cc1e4b18425cdbbfd9fa9Eli Friedman llvm::OwningPtr<PragmaHandler> WeakHandler; 1211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// Whether the '>' token acts as an operator or not. This will be 12355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// true except when we are parsing an expression within a C++ 12455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// template argument list, where the '>' closes the template 12555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// argument list. 12655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor bool GreaterThanIsOperator; 12708d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner 12808d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonIsSacred - When this is false, we aggressively try to recover from 12908d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not 13008d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// safe in case statements and a few other things. This is managed by the 13108d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonProtectionRAIIObject RAII object. 13208d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner bool ColonIsSacred; 13355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1340fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// \brief When true, we are directly inside an Ojective-C messsage 1350fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// send expression. 1360fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// 1370fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// This is managed by the \c InMessageExpressionRAIIObject class, and 1380fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// should not be set directly. 1390fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor bool InMessageExpression; 1400fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 141c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor /// The "depth" of the template parameters currently being parsed. 142c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor unsigned TemplateParameterDepth; 1438113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek 1448113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek /// Factory object for creating AttributeList objects. 1458113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek AttributeList::Factory AttrFactory; 1461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 148f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Parser(Preprocessor &PP, Sema &Actions); 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Parser(); 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const LangOptions &getLang() const { return PP.getLangOptions(); } 152444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } 1530102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner Preprocessor &getPreprocessor() const { return PP; } 154f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &getActions() const { return Actions; } 1551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1560102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Token &getCurToken() const { return Tok; } 15723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Scope *getCurScope() const { return Actions.getCurScope(); } 15823c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor 1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Type forwarding. All of these are statically 'void*', but they may all be 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // different actual classes based on the actions in place. 161ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef Expr ExprTy; 162ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef Stmt StmtTy; 1632b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 164ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef CXXBaseSpecifier BaseTy; 165ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef CXXBaseOrMemberInitializer MemInitTy; 166ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef NestedNameSpecifier CXXScopeTy; 167ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef TemplateParameterList TemplateParamsTy; 1682b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<TemplateName> TemplateTy; 1697ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 170ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef llvm::SmallVector<TemplateParameterList *, 4> TemplateParameterLists; 171c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 1729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::ExprResult ExprResult; 1739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::StmtResult StmtResult; 1749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::BaseResult BaseResult; 1759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::MemInitResult MemInitResult; 1769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::TypeResult TypeResult; 17715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 1789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef Expr *ExprArg; 1799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef ASTMultiPtr<Stmt*> MultiStmtArg; 180f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::FullExprArg FullExprArg; 1811d922960e083906a586609ac6978678147250177Sebastian Redl 18260d7b3a319d84d688752be3870615ac0f111fb16John McCall /// Adorns a ExprResult with Actions to make it an ExprResult 18360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Owned(ExprResult res) { 18460d7b3a319d84d688752be3870615ac0f111fb16John McCall return ExprResult(res); 18561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 18660d7b3a319d84d688752be3870615ac0f111fb16John McCall /// Adorns a StmtResult with Actions to make it an StmtResult 18760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Owned(StmtResult res) { 18860d7b3a319d84d688752be3870615ac0f111fb16John McCall return StmtResult(res); 18961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 19061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 19160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError() { return ExprResult(true); } 19260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError() { return StmtResult(true); } 193d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor 19460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); } 19560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); } 19661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 19760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprEmpty() { return ExprResult(false); } 1985ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Parsing methods. 2001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseTranslationUnit - All in one method that initializes parses, and 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// shuts down the parser. 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseTranslationUnit(); 2041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Initialize - Warm up the parser. 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Initialize(); 2081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if 2101f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff /// the EOF was encountered. 211682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner bool ParseTopLevelDecl(DeclGroupPtrTy &Result); 2121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2133fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian DeclGroupPtrTy FinishPendingObjCActions(); 21463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Low-Level token peeking and consumption methods. 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 2191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenParen - Return true if the cur token is '(' or ')'. 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenParen() const { 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren; 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBracket - Return true if the cur token is '[' or ']'. 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBracket() const { 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square; 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBrace - Return true if the cur token is '{' or '}'. 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBrace() const { 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace; 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenStringLiteral - True if this token is a string-literal. 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenStringLiteral() const { 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::string_literal || 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Tok.getKind() == tok::wide_string_literal; 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 239eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 240a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis /// \brief Returns true if the current token is a '=' or '==' and 241a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis /// false otherwise. If it's '==', we assume that it's a typo and we emit 242a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis /// DiagID and a fixit hint to turn '==' -> '='. 243a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis bool isTokenEqualOrMistypedEqualEqual(unsigned DiagID); 244a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeToken - Consume the current 'peek token' and lex the next one. 246d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu /// This does not work with all kinds of tokens: strings and specific other 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tokens must be consumed with custom methods below. This returns the 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// location of the consumed token. 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeToken() { 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer !isTokenBrace() && 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should consume special tokens with Consume*Token"); 253dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor if (Tok.is(tok::code_completion)) { 254dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor CodeCompletionRecovery(); 255dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor return ConsumeCodeCompletionToken(); 256dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor } 257dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 2584b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2604b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeAnyToken - Dispatch to the right Consume* method based on the 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// current token type. This should only be used in cases where the type of 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the token really isn't known, e.g. in error recovery. 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeAnyToken() { 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isTokenParen()) 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeParen(); 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBracket()) 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBracket(); 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBrace()) 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBrace(); 273d62701bc5321049353017e9abf1963edd57646aaSteve Naroff else if (isTokenStringLiteral()) 274d62701bc5321049353017e9abf1963edd57646aaSteve Naroff return ConsumeStringToken(); 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeToken(); 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeParen - This consume method keeps the paren count up-to-date. 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeParen() { 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenParen() && "wrong consume method"); 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_paren) 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++ParenCount; 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (ParenCount) 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --ParenCount; // Don't let unbalanced )'s drive the count negative. 2874b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2894b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBracket - This consume method keeps the bracket count up-to-date. 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBracket() { 2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBracket() && "wrong consume method"); 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_square) 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BracketCount; 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BracketCount) 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BracketCount; // Don't let unbalanced ]'s drive the count negative. 3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3014b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3034b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBrace - This consume method keeps the brace count up-to-date. 3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBrace() { 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBrace() && "wrong consume method"); 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_brace) 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BraceCount; 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BraceCount) 3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BraceCount; // Don't let unbalanced }'s drive the count negative. 3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3154b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3174b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeStringToken - Consume the current 'peek token', lexing a new one 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and returning the token kind. This method is specific to strings, as it 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// handles string literal concatenation, as per C99 5.1.1.2, translation 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// phase #6. 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeStringToken() { 3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenStringLiteral() && 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should only consume string literals with this method"); 3274b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3294b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 332dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// \brief Consume the current code-completion token. 333dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// 334dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// This routine should be called to consume the code-completion token once 335dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// a code-completion action has already been invoked. 336dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor SourceLocation ConsumeCodeCompletionToken() { 337dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor assert(Tok.is(tok::code_completion)); 338dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PrevTokLocation = Tok.getLocation(); 339dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PP.Lex(Tok); 340dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor return PrevTokLocation; 341dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor } 342dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 343dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ///\ brief When we are consuming a code-completion token within having 344dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// matched specific position in the grammar, provide code-completion results 345dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// based on context. 346dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor void CodeCompletionRecovery(); 347dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 3486b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// GetLookAheadToken - This peeks ahead N tokens and returns that token 3496b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1) 3506b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// returns the token after Tok, etc. 3516b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 3526b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// Note that this differs from the Preprocessor's LookAhead method, because 3536b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// the Parser always has one token lexed that the preprocessor doesn't. 3546b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 35503db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis const Token &GetLookAheadToken(unsigned N) { 3566b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (N == 0 || Tok.is(tok::eof)) return Tok; 3576b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return PP.LookAhead(N-1); 3586b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } 359f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis 360f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// NextToken - This peeks ahead one token and returns it without 361f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// consuming it. 362f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis const Token &NextToken() { 36303db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis return PP.LookAhead(0); 364f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis } 3655404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 366b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall /// getTypeAnnotation - Read a parsed type out of an annotation token. 367b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static ParsedType getTypeAnnotation(Token &Tok) { 368b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue()); 369b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 370b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 371b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static void setTypeAnnotation(Token &Tok, ParsedType T) { 372b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Tok.setAnnotationValue(T.getAsOpaquePtr()); 373b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 374b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 375eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// TryAnnotateTypeOrScopeToken - If the current token position is on a 376eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// typename (possibly qualified in C++) or a C++ scope specifier not followed 377eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens 378eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// with a single annotation token representing the typename or C++ scope 379eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// respectively. 380eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// This simplifies handling of C++ scope specifiers and allows efficient 381eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// backtracking without the need to re-parse and resolve nested-names and 382eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// typenames. 38344802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// It will mainly be called when we expect to treat identifiers as typenames 38444802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// (if they are typenames). For example, in C we do not expect identifiers 38544802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// inside expressions to be treated as typenames so it will not be called 38644802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// for expressions in C. 387a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner /// 388a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner /// This returns true if the token was annotated. 389495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false); 390eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 3919ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but 3929ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// only annotates C++ scope specifiers. This returns true if there 3939ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// was an unrecoverable error. 394495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateCXXScopeToken(bool EnteringContext = false); 395eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 39682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens, 39782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// replacing them with the non-context-sensitive keywords. This returns 39882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// true if the token was replaced. 39982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc, 400b3a4e432c90be98c6d918087750397e86d030368Chris Lattner const char *&PrevSpec, unsigned &DiagID, 401b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool &isInvalid) { 4021b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner if (!getLang().AltiVec || 4031b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner (Tok.getIdentifierInfo() != Ident_vector && 4041b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner Tok.getIdentifierInfo() != Ident_pixel)) 4051b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return false; 4061b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 4071b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); 40882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 40982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 41082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector 41182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// identifier token, replacing it with the non-context-sensitive __vector. 41282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// This returns true if the token was replaced. 41382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecVectorToken() { 414b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (!getLang().AltiVec || 415b3a4e432c90be98c6d918087750397e86d030368Chris Lattner Tok.getIdentifierInfo() != Ident_vector) return false; 4161b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecVectorTokenOutOfLine(); 41782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 4181b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 4191b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecVectorTokenOutOfLine(); 4201b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, 4211b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner const char *&PrevSpec, unsigned &DiagID, 4221b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool &isInvalid); 4231b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 4245404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TentativeParsingAction - An object that is used as a kind of "tentative 4255404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// parsing transaction". It gets instantiated to mark the token position and 4265404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// after the token consumption is done, Commit() or Revert() is called to 4275404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// either "commit the consumed tokens" or revert to the previously marked 4285404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// token position. Example: 4295404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 430314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor /// TentativeParsingAction TPA(*this); 4315404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// ConsumeToken(); 4325404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// .... 4335404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TPA.Revert(); 4345404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 4355404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis class TentativeParsingAction { 4365404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Parser &P; 4375404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Token PrevTok; 4385404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isActive; 4395404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 4405404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis public: 4415404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis explicit TentativeParsingAction(Parser& p) : P(p) { 4425404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis PrevTok = P.Tok; 4435404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.EnableBacktrackAtThisPos(); 4445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = true; 4455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Commit() { 4475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 4485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.CommitBacktrackedTokens(); 4495404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 4505404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4515404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Revert() { 4525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 4535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.Backtrack(); 4545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.Tok = PrevTok; 4555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 4565404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4575404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis ~TentativeParsingAction() { 4585404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(!isActive && "Forgot to call Commit or Revert!"); 4595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis }; 4611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'), 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this helper function matches and consumes the specified RHS token if 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// present. If not present, it emits the specified diagnostic indicating 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that the parser failed to match the RHS of the token at LHSLoc. LHSName 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// should be the name of the unmatched LHS token. This returns the location 4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the consumed token. 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MatchRHSPunctuation(tok::TokenKind RHSTok, 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation LHSLoc); 4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// input. If so, it is consumed and false is returned. 4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If the input is malformed, this emits the specified diagnostic. Next, if 4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// returned. 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag, 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *DiagMsg = "", 4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind SkipToTok = tok::unknown); 4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4829ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// \brief The parser expects a semicolon and, if present, will consume it. 4839ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// 4849ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// If the next token is not a semicolon, this emits the specified diagnostic, 4859ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior 4869ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// to the semicolon, consumes that extra token. 4879ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor bool ExpectAndConsumeSemi(unsigned DiagID); 4889ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor 4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Scope manipulation 4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4928935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// ParseScope - Introduces a new scope for parsing. The kind of 4938935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// scope is determined by ScopeFlags. Objects of this type should 4948935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// be created on the stack to coincide with the position where the 4958935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// parser enters the new scope, and this object's constructor will 4968935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// create that new scope. Similarly, once the object is destroyed 4978935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// the parser will exit the scope. 4988935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor class ParseScope { 4998935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Parser *Self; 5008935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope(const ParseScope&); // do not implement 5018935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope& operator=(const ParseScope&); // do not implement 5028935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 5038935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor public: 5048935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ParseScope - Construct a new object to manage a scope in the 5058935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // parser Self where the new Scope is created with the flags 5068935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ScopeFlags, but only when ManageScope is true (the default). If 5078935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ManageScope is false, this object does nothing. 5081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true) 5098935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor : Self(Self) { 5108935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (ManageScope) 5118935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->EnterScope(ScopeFlags); 5128935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor else 5138935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor this->Self = 0; 5148935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 5158935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 5168935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // Exit - Exit the scope associated with this object now, rather 5178935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // than waiting until the object is destroyed. 5188935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor void Exit() { 5198935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (Self) { 5208935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->ExitScope(); 5218935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self = 0; 5228935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 5238935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 5248935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 5258935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ~ParseScope() { 5268935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Exit(); 5278935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 5288935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor }; 5298935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterScope - Start a new scope. 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterScope(unsigned ScopeFlags); 5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExitScope - Pop a scope off the scope stack. 5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ExitScope(); 5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Diagnostic Emission and Error recovery. 53815faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 5396aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorpublic: 5403cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 5413cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); 54215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 5436aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorprivate: 5441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SuggestParentheses(SourceLocation Loc, unsigned DK, 5454b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceRange ParenRange); 5464b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipUntil - Read tokens until we get to the specified token, then consume 54882c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff /// it (unless DontConsume is true). Because we cannot guarantee that the 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// token will ever occur, this skips to the next token, or to some likely 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// character. 5521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If SkipUntil finds the specified token, it returns true, otherwise it 5541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returns false. 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true, 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool DontConsume = false) { 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SkipUntil(&T, 1, StopAtSemi, DontConsume); 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true, 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool DontConsume = false) { 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind TokArray[] = {T1, T2}; 5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SkipUntil(TokArray, 2, StopAtSemi, DontConsume); 5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, 5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool StopAtSemi = true, bool DontConsume = false); 5667ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 5684cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Lexing and parsing of C++ inline methods. 5694cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 570d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct ParsingClass; 571d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 572d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// [class.mem]p1: "... the class is regarded as complete within 573d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - function bodies 574d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - default arguments 575d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - exception-specifications (TODO: C++0x) 576d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - and brace-or-equal-initializers (TODO: C++0x) 577d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// for non-static data members (including such things in nested classes)." 578d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarations build the tree of those elements so they can 579d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// be parsed after parsing the top-level class. 580d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor class LateParsedDeclaration { 581d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor public: 582d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual ~LateParsedDeclaration(); 583d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 584d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 585d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 586d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor }; 587d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 588d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// Inner node of the LateParsedDeclaration tree that parses 589d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// all its members recursively. 590d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor class LateParsedClass : public LateParsedDeclaration { 591d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor public: 592d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateParsedClass(Parser *P, ParsingClass *C); 593d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual ~LateParsedClass(); 594d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 595d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 596d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 597d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 598d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor private: 599d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser *Self; 600d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor ParsingClass *Class; 601d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor }; 602d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 603d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// Contains the lexed tokens of a member function definition 604d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// which needs to be parsed at the end of the class declaration 605d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// after parsing all other member declarations. 606d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct LexedMethod : public LateParsedDeclaration { 607d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser *Self; 608d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *D; 60972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens Toks; 610d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 611d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 612d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 613d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 614d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 615d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 616d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor explicit LexedMethod(Parser* P, Decl *MD) 617d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor : Self(P), D(MD), TemplateScope(false) {} 618d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 619d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 6204cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis }; 6214cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 62272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedDefaultArgument - Keeps track of a parameter that may 62372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument that cannot be parsed yet because it 62472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// occurs within a member function declaration inside the class 62572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// (C++ [class.mem]p2). 62672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedDefaultArgument { 627d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall explicit LateParsedDefaultArgument(Decl *P, 62872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks = 0) 62972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor : Param(P), Toks(Toks) { } 63072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 63172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Param - The parameter declaration for this parameter. 632d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param; 63372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 63472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Toks - The sequence of tokens that comprises the default 63572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument expression, not including the '=' or the terminating 63672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// ')' or ','. This will be NULL for parameters that have no 63772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// default argument. 63872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks; 63972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 6401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDeclaration - A method declaration inside a class that 64272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// contains at least one entity whose parsing needs to be delayed 64372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// until the class itself is completely-defined, such as a default 64472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument (C++ [class.mem]p2). 645d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct LateParsedMethodDeclaration : public LateParsedDeclaration { 646d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor explicit LateParsedMethodDeclaration(Parser *P, Decl *M) 647d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor : Self(P), Method(M), TemplateScope(false) { } 648d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 649d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 650d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 651d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser* Self; 65272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 65372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Method - The method declaration. 654d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Method; 65572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 656d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 657d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 658d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 659d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// DefaultArgs - Contains the parameters of the function and 66272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// their default arguments. At least one of the parameters will 66372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument, but all of the parameters of the 66472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// method will be stored so that they can be reintroduced into 6651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// scope at the appropriate times. 66672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor llvm::SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; 66772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 66872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 669d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarationsContainer - During parsing of a top (non-nested) 670d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// C++ class, its method declarations that contain parts that won't be 67172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// parsed until after the definiton is completed (C++ [class.mem]p2), 672d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// the method declarations and possibly attached inline definitions 673d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// will be stored here with the tokens that will be parsed to create those entities. 674d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor typedef llvm::SmallVector<LateParsedDeclaration*, 2> LateParsedDeclarationsContainer; 67572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 6766569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Representation of a class that has been parsed, including 6776569d68745c8213709740337d2be52b031384f58Douglas Gregor /// any member function declarations or definitions that need to be 6786569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed after the corresponding top-level class is complete. 6796569d68745c8213709740337d2be52b031384f58Douglas Gregor struct ParsingClass { 680d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParsingClass(Decl *TagOrTemplate, bool TopLevelClass) 6811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : TopLevelClass(TopLevelClass), TemplateScope(false), 6826569d68745c8213709740337d2be52b031384f58Douglas Gregor TagOrTemplate(TagOrTemplate) { } 6836569d68745c8213709740337d2be52b031384f58Douglas Gregor 6846569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this is a "top-level" class, meaning that it is 6856569d68745c8213709740337d2be52b031384f58Douglas Gregor /// not nested within another class. 6866569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TopLevelClass : 1; 6876569d68745c8213709740337d2be52b031384f58Douglas Gregor 6886569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this class had an associated template 6896569d68745c8213709740337d2be52b031384f58Douglas Gregor /// scope. When true, TagOrTemplate is a template declaration; 6906569d68745c8213709740337d2be52b031384f58Douglas Gregor /// othewise, it is a tag declaration. 6916569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TemplateScope : 1; 6926569d68745c8213709740337d2be52b031384f58Douglas Gregor 6936569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The class or class template whose definition we are parsing. 694d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagOrTemplate; 69572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 696d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarations - Method declarations, inline definitions and 697d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// nested classes that contain pieces whose parsing will be delayed until 698d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// the top-level class is fully defined. 699d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateParsedDeclarationsContainer LateParsedDeclarations; 70072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 7014cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 7026569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The stack of classes that is currently being 7036569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed. Nested and local classes will be pushed onto this stack 7046569d68745c8213709740337d2be52b031384f58Douglas Gregor /// when they are parsed, and removed afterward. 7056569d68745c8213709740337d2be52b031384f58Douglas Gregor std::stack<ParsingClass *> ClassStack; 7064cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 7076569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingClass &getCurrentClass() { 7086569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "No lexed method stacks!"); 7096569d68745c8213709740337d2be52b031384f58Douglas Gregor return *ClassStack.top(); 7104cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 7114cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 71254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// \brief RAII object used to inform the actions that we're 71354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// currently parsing a declaration. This is active when parsing a 71454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// variable's initializer, but not when parsing the body of a 71554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// class or function definition. 71654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclRAIIObject { 717f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &Actions; 718f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::ParsingDeclStackState State; 71954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall bool Popped; 720c9068d7dd94d439cec66c421115d15303e481025John McCall 72154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 72254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) { 72354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 72454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 72554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 726c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *Other) 727c9068d7dd94d439cec66c421115d15303e481025John McCall : Actions(P.Actions) { 728c9068d7dd94d439cec66c421115d15303e481025John McCall if (Other) steal(*Other); 729c9068d7dd94d439cec66c421115d15303e481025John McCall else push(); 730c9068d7dd94d439cec66c421115d15303e481025John McCall } 731c9068d7dd94d439cec66c421115d15303e481025John McCall 732c9068d7dd94d439cec66c421115d15303e481025John McCall /// Creates a RAII object which steals the state from a different 733c9068d7dd94d439cec66c421115d15303e481025John McCall /// object instead of pushing. 734c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject(ParsingDeclRAIIObject &Other) 735c9068d7dd94d439cec66c421115d15303e481025John McCall : Actions(Other.Actions) { 736c9068d7dd94d439cec66c421115d15303e481025John McCall steal(Other); 737c9068d7dd94d439cec66c421115d15303e481025John McCall } 738c9068d7dd94d439cec66c421115d15303e481025John McCall 73954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ~ParsingDeclRAIIObject() { 74054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 74154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 74254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 74354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Resets the RAII object for a new declaration. 74454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void reset() { 74554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 74654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 74754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 74854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 74954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Signals that the context was completed without an appropriate 75054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// declaration being parsed. 75154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 752d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall pop(0); 75354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 75454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 755d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 75654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall assert(!Popped && "ParsingDeclaration has already been popped!"); 75754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall pop(D); 75854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 75954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 76054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall private: 761c9068d7dd94d439cec66c421115d15303e481025John McCall void steal(ParsingDeclRAIIObject &Other) { 762c9068d7dd94d439cec66c421115d15303e481025John McCall State = Other.State; 763c9068d7dd94d439cec66c421115d15303e481025John McCall Popped = Other.Popped; 764c9068d7dd94d439cec66c421115d15303e481025John McCall Other.Popped = true; 765c9068d7dd94d439cec66c421115d15303e481025John McCall } 766c9068d7dd94d439cec66c421115d15303e481025John McCall 76754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void push() { 76854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall State = Actions.PushParsingDeclaration(); 76954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = false; 77054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 77154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 772d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void pop(Decl *D) { 77354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall if (!Popped) { 77454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Actions.PopParsingDeclaration(State, D); 77554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = true; 77654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 77754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 77854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 77954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 78054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a DeclSpec. 78154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclSpec : public DeclSpec { 78254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 78354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 78454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 785c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec(Parser &P) : ParsingRAII(P) {} 786c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec(ParsingDeclRAIIObject &RAII) : ParsingRAII(RAII) {} 787c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII) 788c9068d7dd94d439cec66c421115d15303e481025John McCall : ParsingRAII(P, RAII) {} 78954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 790d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 79154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 79254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 79354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 79454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 79554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.abort(); 79654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 79754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 79854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 79954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a declarator. 80054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclarator : public Declarator { 80154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 80254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 80354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 80454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C) 80554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall : Declarator(DS, C), ParsingRAII(P) { 80654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 80754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 80854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall const ParsingDeclSpec &getDeclSpec() const { 80954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec()); 81054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 81154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 81254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclSpec &getMutableDeclSpec() const { 81354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return const_cast<ParsingDeclSpec&>(getDeclSpec()); 81454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 81554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 81654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void clear() { 81754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Declarator::clear(); 81854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.reset(); 81954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 82054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 821d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 82254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 82354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 82454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 82554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 8261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief RAII object used to 8276569d68745c8213709740337d2be52b031384f58Douglas Gregor class ParsingClassDefinition { 8286569d68745c8213709740337d2be52b031384f58Douglas Gregor Parser &P; 8296569d68745c8213709740337d2be52b031384f58Douglas Gregor bool Popped; 8306569d68745c8213709740337d2be52b031384f58Douglas Gregor 8316569d68745c8213709740337d2be52b031384f58Douglas Gregor public: 832d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass) 8331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : P(P), Popped(false) { 8346569d68745c8213709740337d2be52b031384f58Douglas Gregor P.PushParsingClass(TagOrTemplate, TopLevelClass); 8356569d68745c8213709740337d2be52b031384f58Douglas Gregor } 8366569d68745c8213709740337d2be52b031384f58Douglas Gregor 8376569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Pop this class of the stack. 8381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void Pop() { 8396569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!Popped && "Nested class has already been popped"); 8406569d68745c8213709740337d2be52b031384f58Douglas Gregor Popped = true; 8416569d68745c8213709740337d2be52b031384f58Douglas Gregor P.PopParsingClass(); 8426569d68745c8213709740337d2be52b031384f58Douglas Gregor } 8436569d68745c8213709740337d2be52b031384f58Douglas Gregor 8441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ~ParsingClassDefinition() { 8456569d68745c8213709740337d2be52b031384f58Douglas Gregor if (!Popped) 8461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump P.PopParsingClass(); 8476569d68745c8213709740337d2be52b031384f58Douglas Gregor } 8486569d68745c8213709740337d2be52b031384f58Douglas Gregor }; 8496569d68745c8213709740337d2be52b031384f58Douglas Gregor 8504d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief Contains information about any template-specific 8514d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// information that has been parsed prior to parsing declaration 8524d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// specifiers. 8534d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor struct ParsedTemplateInfo { 8541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsedTemplateInfo() 8554d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { } 8564d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 8574d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ParsedTemplateInfo(TemplateParameterLists *TemplateParams, 858c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool isSpecialization, 859c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool lastParameterListWasEmpty = false) 8604d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(isSpecialization? ExplicitSpecialization : Template), 861c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor TemplateParams(TemplateParams), 862c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(lastParameterListWasEmpty) { } 8634d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 86445f965581935791a018df829a14dff53c1dd8f47Douglas Gregor explicit ParsedTemplateInfo(SourceLocation ExternLoc, 86545f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation TemplateLoc) 8661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Kind(ExplicitInstantiation), TemplateParams(0), 867c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), 868c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(false){ } 8694d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 8704d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The kind of template we are parsing. 8714d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor enum { 8724d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are not parsing a template at all. 8734d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor NonTemplate = 0, 8744d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing a template declaration. 8754d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor Template, 8764d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit specialization. 8774d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitSpecialization, 8784d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit instantiation. 8794d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitInstantiation 8804d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } Kind; 8814d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 8824d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The template parameter lists, for template declarations 8834d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// and explicit specializations. 8844d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParameterLists *TemplateParams; 8854d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 88645f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// \brief The location of the 'extern' keyword, if any, for an explicit 88745f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// instantiation 88845f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation ExternLoc; 8891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8904d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The location of the 'template' keyword, for an explicit 8914d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// instantiation. 8924d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation TemplateLoc; 893c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor 894c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor /// \brief Whether the last template parameter list was empty. 895c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool LastParameterListWasEmpty; 89678b810559d89e996e00684335407443936ce34a1John McCall 89778b810559d89e996e00684335407443936ce34a1John McCall SourceRange getSourceRange() const; 8984d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor }; 8991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 900d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass); 90137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void DeallocateParsedClasses(ParsingClass *Class); 90237b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void PopParsingClass(); 90337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor 904d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D, 905d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall const ParsedTemplateInfo &TemplateInfo); 90637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDeclarations(ParsingClass &Class); 907d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM); 90837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDefs(ParsingClass &Class); 909d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor void ParseLexedMethodDef(LexedMethod &LM); 91014b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeAndStoreUntil(tok::TokenKind T1, 91114b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis CachedTokens &Toks, 91214b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 91314b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeFinalToken = true) { 91414b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken); 91514b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis } 9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 91737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor CachedTokens &Toks, 91814b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 91937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor bool ConsumeFinalToken = true); 9204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 9214cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.9: External Definitions. 92309a63c97b95eb4dc6fd6b2323929e8cf12af03ffDouglas Gregor DeclGroupPtrTy ParseExternalDeclaration(CXX0XAttributeList Attr, 92409a63c97b95eb4dc6fd6b2323929e8cf12af03ffDouglas Gregor ParsingDeclSpec *DS = 0); 925c82daefa3062721e98947e08193cd81b4e9df915Chris Lattner bool isDeclarationAfterDeclarator() const; 926004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); 927bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(AttributeList *Attr, 9285aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson AccessSpecifier AS = AS_none); 9293acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS, 9303acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AttributeList *Attr, 9313acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AccessSpecifier AS = AS_none); 9323acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian 933d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseFunctionDefinition(ParsingDeclarator &D, 93452591bf224b2c43e2b00e265bb8599a620081925Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseKNRParamDeclarations(Declarator &D); 936ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 937ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the simple-asm. 93860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0); 93960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAsmStringLiteral(); 9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9413536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Objective-C External Declarations 942d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtDirectives(); 943d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtClassDeclaration(SourceLocation atLoc); 944d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, 945dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff AttributeList *prefixAttrs = 0); 946d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseObjCClassInstanceVariables(Decl *interfaceDecl, 94783c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 94860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc); 949d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Decl *> &P, 95071b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &PLocs, 9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool WarnOnDeclarations, 95271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, 953e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SourceLocation &EndProtoLoc); 95446f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor bool ParseObjCProtocolQualifiers(DeclSpec &DS); 955d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseObjCInterfaceDeclList(Decl *interfaceDecl, 956c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner tok::ObjCKeywordKind contextKey); 957d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtProtocolDeclaration(SourceLocation atLoc, 958b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *prefixAttrs = 0); 9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 960d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ObjCImpDecl; 961d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 4> PendingObjCImpDecl; 9620416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 963d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtImplementationDeclaration(SourceLocation atLoc); 964d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtEndDeclaration(SourceRange atEnd); 965d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc); 966d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertySynthesize(SourceLocation atLoc); 967d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertyDynamic(SourceLocation atLoc); 9681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9692fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); 97034870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner // Definitions for Objective-c context sensitive keywords recognition. 97134870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner enum ObjCTypeQual { 97234870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, 97334870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_NumQuals 97434870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner }; 975a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; 9761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 977335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian bool isTokIdentifier_in() const; 978d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 979b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, bool IsParameter); 980294494e1cce92043562b4680c613df7fd028c02eSteve Naroff void ParseObjCMethodRequirement(); 981d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodPrototype(Decl *classOrCat, 982c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); 983d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, 984d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *classDecl, 98500933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); 986d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl, 987d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl **Methods, unsigned NumMethods); 9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 989d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDefinition(); 9901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.5: Expressions. 9936aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 99460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpression(); 99560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseConstantExpression(); 9962f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl // Expr that doesn't include commas. 99760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAssignmentExpression(); 9982f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 99960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); 10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 100160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); 1002adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman 100360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, 10046aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor prec::Level MinPrec); 100560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 1006f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAddressOfOperand, 10072ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman bool &NotCastExpr, 1008b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType TypeOfCast); 100960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 10102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman bool isAddressOfOperand = false, 1011b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType TypeOfCast = ParsedType()); 10129c72c6088d591ace8503b842d39448c2040f3033John McCall 10139c72c6088d591ace8503b842d39448c2040f3033John McCall /// Returns true if the next token would start a postfix-expression 10149c72c6088d591ace8503b842d39448c2040f3033John McCall /// suffix. 10159c72c6088d591ace8503b842d39448c2040f3033John McCall bool isPostfixExpressionSuffixStart() { 10169c72c6088d591ace8503b842d39448c2040f3033John McCall tok::TokenKind K = Tok.getKind(); 10179c72c6088d591ace8503b842d39448c2040f3033John McCall return (K == tok::l_square || K == tok::l_paren || 10189c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::period || K == tok::arrow || 10199c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::plusplus || K == tok::minusminus); 10209c72c6088d591ace8503b842d39448c2040f3033John McCall } 10219c72c6088d591ace8503b842d39448c2040f3033John McCall 102260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParsePostfixExpressionSuffix(ExprResult LHS); 102360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseSizeofAlignofExpression(); 102460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBuiltinPrimaryExpression(); 10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExprAfterTypeofSizeofAlignof(const Token &OpTok, 10275ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis bool &isCastExpr, 1028b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 10295ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis SourceRange &CastRange); 10300cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 1031ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef llvm::SmallVector<Expr*, 20> ExprListTy; 1032ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef llvm::SmallVector<SourceLocation, 20> CommaLocsTy; 10330cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 10340cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis /// ParseExpressionList - Used for C/C++ (argument-)expression-list. 1035ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall bool ParseExpressionList(llvm::SmallVectorImpl<Expr*> &Exprs, 1036ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall llvm::SmallVectorImpl<SourceLocation> &CommaLocs, 1037f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall void (Sema::*Completer)(Scope *S, 1038f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Data, 1039f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr **Args, 1040f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall unsigned NumArgs) = 0, 1041ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Expr *Data = 0); 1042d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl 10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParenParseOption - Control what ParseParenExpression will parse. 10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ParenParseOption { 10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SimpleExpr, // Only parse '(' expression ')' 10465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundStmt, // Also allow '(' compound-statement ')' 10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}' 10485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CastExpr // Also allow '(' type-name ')' <anything> 10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 105060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseParenExpression(ParenParseOption &ExprType, 10510350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis bool stopIfCastExpr, 1052b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType TypeOfCast, 1053b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 1054d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl SourceLocation &RParenLoc); 10551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 105660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, 1057b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 1058f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis SourceLocation LParenLoc, 1059f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis SourceLocation &RParenLoc); 10601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 106160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCompoundLiteralExpression(ParsedType Ty, 1062d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation LParenLoc, 1063d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation RParenLoc); 10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 106560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseStringLiteralExpression(); 1066eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1067eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 1068eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // C++ Expressions 106960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); 10704bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis 10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 1072b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1073b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor bool EnteringContext, 1074d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool *MayBePseudoDestructor = 0); 10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 5.2p1: C++ Casts 107860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXCasts(); 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1081c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // C++ 5.2p1: C++ Type Identification 108260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeid(); 1083c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 1084c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl //===--------------------------------------------------------------------===// 108501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // C++ : Microsoft __uuidof Expression 108601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult ParseCXXUuidof(); 108701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 108801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet //===--------------------------------------------------------------------===// 1089d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // C++ 5.2.4: C++ Pseudo-Destructor Expressions 109060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, 1091d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor tok::TokenKind OpKind, 1092d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CXXScopeSpec &SS, 1093b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType); 1094d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 1095d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor //===--------------------------------------------------------------------===// 10964cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 9.3.2: C++ 'this' pointer 109760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXThis(); 10984cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 10994cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 110050dd289f45738ed22b7583d52ed2525b927042ffChris Lattner // C++ 15: C++ Throw Expression 110160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseThrowExpression(); 1102ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc is filled with the location of the last token of the specification. 11037dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl bool ParseExceptionSpecification(SourceLocation &EndLoc, 1104b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall llvm::SmallVectorImpl<ParsedType> &Exns, 1105b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall llvm::SmallVectorImpl<SourceRange> &Ranges, 11067dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl bool &hasAnyExceptionSpec); 110750dd289f45738ed22b7583d52ed2525b927042ffChris Lattner 110850dd289f45738ed22b7583d52ed2525b927042ffChris Lattner //===--------------------------------------------------------------------===// 1109dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // C++0x 8: Function declaration trailing-return-type 1110dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor TypeResult ParseTrailingReturnType(); 1111dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 1112dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor //===--------------------------------------------------------------------===// 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 2.13.5: C++ Boolean Literals 111460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXBoolLiteral(); 11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1117987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // C++ 5.2.3: Explicit type conversion (functional notation) 111860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); 1119987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 11206aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool isCXXSimpleTypeSpecifier() const; 11216aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 1122987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 1123987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// This should only be called when the current token is known to be part of 1124987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// simple-type-specifier. 1125987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); 1126987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 11272f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); 11282f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 1129987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 11304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // C++ 5.3.4 and 5.3.5: C++ new and delete 1131ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall bool ParseExpressionListOrTypeId(llvm::SmallVectorImpl<Expr*> &Exprs, 1132ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Declarator &D); 11334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDirectNewDeclarator(Declarator &D); 113460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); 113560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXDeleteExpression(bool UseGlobal, 113659232d35f5820e334b6c8b007ae8006f4390055dChris Lattner SourceLocation Start); 11374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 11384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl //===--------------------------------------------------------------------===// 113999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor // C++ if/switch/while condition expression. 114060d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult, 1141586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, bool ConvertToBoolean); 114271b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 114371b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 114412e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor // C++ types 114512e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor 114612e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor //===--------------------------------------------------------------------===// 11475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7.8: Initialization. 11481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11490eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// ParseInitializer 11500eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// initializer: [C99 6.7.8] 11510eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// assignment-expression 11520eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// '{' ... 115360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializer() { 11540eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner if (Tok.isNot(tok::l_brace)) 115520df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ParseAssignmentExpression(); 11560eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner return ParseBraceInitializer(); 11570eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner } 115860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBraceInitializer(); 115960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializerWithPotentialDesignator(); 11601d922960e083906a586609ac6978678147250177Sebastian Redl 11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1162296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // clang Expressions 11631d922960e083906a586609ac6978678147250177Sebastian Redl 116460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBlockLiteralExpression(); // ^{...} 1165296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff 1166296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff //===--------------------------------------------------------------------===// 11675508518a2702b00be3b15a26d772bde968972f54Anders Carlsson // Objective-C Expressions 116860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCAtExpression(SourceLocation AtLocation); 116960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCStringLiteral(SourceLocation AtLoc); 117060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); 117160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); 117260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); 11731b730e847ded503f2e615154035c083c4f94a067Douglas Gregor bool isSimpleObjCMessageExpression(); 117460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpression(); 117560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, 11762725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation SuperLoc, 1177b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, 11781d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr); 117960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAssignmentExprWithObjCMessageExprStart( 11802725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation LBracloc, SourceLocation SuperLoc, 1181b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, ExprArg ReceiverExpr); 11826aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr); 118361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 11845508518a2702b00be3b15a26d772bde968972f54Anders Carlsson //===--------------------------------------------------------------------===// 11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.8: Statements and Blocks. 118661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 118760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseStatement() { 1188c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian StmtVector Stmts(Actions); 1189c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian return ParseStatementOrDeclaration(Stmts, true); 119061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 1191c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian StmtResult ParseStatementOrDeclaration(StmtVector& Stmts, 1192c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian bool OnlyStatement = false); 119360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseLabeledStatement(AttributeList *Attr); 119460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCaseStatement(AttributeList *Attr); 119560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseDefaultStatement(AttributeList *Attr); 119660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCompoundStatement(AttributeList *Attr, 1197bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool isStmtExpr = false); 119860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCompoundStatementBody(bool isStmtExpr = false); 119960d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseParenExprOrCondition(ExprResult &ExprResult, 1200d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *&DeclResult, 1201586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, 120244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis bool ConvertToBoolean); 120360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseIfStatement(AttributeList *Attr); 120460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseSwitchStatement(AttributeList *Attr); 120560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseWhileStatement(AttributeList *Attr); 120660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseDoStatement(AttributeList *Attr); 120760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseForStatement(AttributeList *Attr); 120860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseGotoStatement(AttributeList *Attr); 120960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseContinueStatement(AttributeList *Attr); 121060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseBreakStatement(AttributeList *Attr); 121160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseReturnStatement(AttributeList *Attr); 121260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseAsmStatement(bool &msAsm); 1213a44724d0d6d03568ec9acadc0781d612163008e1Abramo Bagnara StmtResult FuzzyParseMicrosoftAsmStatement(SourceLocation AsmLoc); 1214ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<IdentifierInfo *> &Names, 1215ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVectorImpl<ExprTy *> &Constraints, 1216ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVectorImpl<ExprTy *> &Exprs); 1217a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1218a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1219a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // C++ 6: Statements and Blocks 1220a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 122160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXTryBlock(AttributeList *Attr); 122260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc); 122360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXCatchBlock(); 1224a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1225a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1226a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // Objective-C Statements 1227a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 122860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCAtStatement(SourceLocation atLoc); 122960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCTryStmt(SourceLocation atLoc); 123060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCThrowStmt(SourceLocation atLoc); 123160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); 1232b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7: Declarations. 123667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall 123767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// A context for parsing declaration specifiers. TODO: flesh this 123867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// out, there are other significant restrictions on specifiers than 123967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// would be best implemented in the parser. 124067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall enum DeclSpecContext { 124167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DSC_normal, // normal context 12420efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_class, // class context, enables 'friend' 12430efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_top_level // top-level/namespace declaration context 124467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall }; 12451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1246c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts, 1247c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian unsigned Context, SourceLocation &DeclEnd, 1248bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList Attr); 1249c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts, 1250c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian unsigned Context, 1251bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 12525c5db553b5c256d0a6f55dde7325c1c829b88e8eChris Lattner AttributeList *Attr, 12535c5db553b5c256d0a6f55dde7325c1c829b88e8eChris Lattner bool RequireSemi); 125454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, 1255d8ac05753dc4506224d445ff98399c01da3136e5John McCall bool AllowFunctionDefinitions, 1256d8ac05753dc4506224d445ff98399c01da3136e5John McCall SourceLocation *DeclEnd = 0); 1257d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationAfterDeclarator(Declarator &D, 1258e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1259d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseFunctionStatementBody(Decl *Decl); 1260d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseFunctionTryBlock(Decl *Decl); 1261d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 1262f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, 12634d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 1264e40c295d017a8f75a945fe9ed2aa9d8bb7a7341aChris Lattner AccessSpecifier AS); 12650efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); 12661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseDeclarationSpecifiers(DeclSpec &DS, 12674d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 126867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall AccessSpecifier AS = AS_none, 126967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DeclSpecContext DSC = DSC_normal); 12701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid, 12717a0ab5f387722c83e19c7133b46b16988eb19e45Chris Lattner const char *&PrevSpec, 1272fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID, 1273d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1274d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 12754d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseSpecifierQualifierList(DeclSpec &DS); 12771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1278d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor void ParseObjCTypeQualifierList(ObjCDeclSpec &DS, bool IsParameter); 12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12804c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, 12819b9edd619a7e616d3287435cb5a3f9b1aea648e8Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), AccessSpecifier AS = AS_none); 1282d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl); 12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, 1284d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 1285bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1286bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct FieldCallback { 1287d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall virtual Decl *invoke(FieldDeclarator &Field) = 0; 12886c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual ~FieldCallback() {} 12896c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall 12906c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall private: 12916c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual void _anchor(); 1292bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall }; 1293d0014540005f2a5ab837365db6bd40f479406758John McCall struct ObjCPropertyCallback; 1294bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1295bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback); 12961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12979497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false); 1298eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isTypeSpecifierQualifier(); 12995f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff bool isTypeQualifier() const; 1300b3a4e432c90be98c6d918087750397e86d030368Chris Lattner 1301b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// isKnownToBeTypeSpecifier - Return true if we know that the specified token 1302b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// is definitely a type-specifier. Return false if it isn't part of a type 1303b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// specifier or if we're not sure. 1304b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool isKnownToBeTypeSpecifier(const Token &Tok) const; 13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13065404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isDeclarationStatement - Disambiguates between a declaration or an 13075404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// expression statement, when parsing function bodies. 13085404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for declaration, false for expression. 13095404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isDeclarationStatement() { 13105404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis if (getLang().CPlusPlus) 13115404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isCXXDeclarationStatement(); 13129497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return isDeclarationSpecifier(true); 13135404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 13145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1315bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// isSimpleDeclaration - Disambiguates between a declaration or an 1316bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// expression, mainly used for the C 'clause-1' or the C++ 1317bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis // 'for-init-statement' part of a 'for' statement. 1318bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// Returns true for declaration, false for expression. 1319bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis bool isSimpleDeclaration() { 1320bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis if (getLang().CPlusPlus) 1321bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis return isCXXSimpleDeclaration(); 13229497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return isDeclarationSpecifier(true); 1323bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis } 1324bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis 13259497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor /// \brief Determine whether we are currently at the start of an Objective-C 13269497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor /// class message that appears to be missing the open bracket '['. 13279497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor bool isStartOfObjCClassMessageMissingOpenBracket(); 13289497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 13290efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief Starting with a scope specifier, identifier, or 13300efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id that refers to the current class, determine whether 13310efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// this is a constructor declarator. 13320efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor bool isConstructorDeclarator(); 13330efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 13348b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// \brief Specifies the context in which type-id/expression 13358b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// disambiguation will occur. 13368b642592a35167a3780074e78674e0bece87c40cDouglas Gregor enum TentativeCXXTypeIdContext { 13378b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdInParens, 13388b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdAsTemplateArgument 13398b642592a35167a3780074e78674e0bece87c40cDouglas Gregor }; 13408b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 13418b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 134278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know 134378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// whether the parens contain an expression or a type-id. 134478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// Returns true for a type-id and false for an expression. 1345f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens(bool &isAmbiguous) { 134678c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis if (getLang().CPlusPlus) 1347f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(TypeIdInParens, isAmbiguous); 1348f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis isAmbiguous = false; 134978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis return isTypeSpecifierQualifier(); 135078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis } 1351f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens() { 1352f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1353f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isTypeIdInParens(isAmbiguous); 1354f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 135578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 13565404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXDeclarationStatement - C++-specialized function that disambiguates 13575404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a declaration or an expression statement, when parsing function 13585404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// bodies. Returns true for declaration, false for expression. 13595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXDeclarationStatement(); 13605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 13615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXSimpleDeclaration - C++-specialized function that disambiguates 13625404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a simple-declaration or an expression-statement. 13635404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 13645404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 13655404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns false if the statement is disambiguated as expression. 13665404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXSimpleDeclaration(); 13675404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 13685404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXFunctionDeclarator - Disambiguates between a function declarator or 13695404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// a constructor-style initializer, when parsing declaration statements. 13705404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for function declarator and false for constructor-style 1371e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to 1372259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis /// indicate that the parens were disambiguated as function declarator. 13735404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 13745404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1375e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis bool isCXXFunctionDeclarator(bool warnIfAmbiguous); 13765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1377a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// isCXXConditionDeclaration - Disambiguates between a declaration or an 1378a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// expression for a condition of a if/switch/while/for statement. 1379a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 1380a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1381a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis bool isCXXConditionDeclaration(); 1382a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis 1383f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); 1384f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context) { 1385f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1386f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(Context, isAmbiguous); 1387f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 138878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 1389b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult - Used as the result value for functions whose purpose is to 1390b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// disambiguate C++ constructs by "tentatively parsing" them. 1391b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// This is a class instead of a simple enum because the implicit enum-to-bool 1392b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// conversions may cause subtle bugs. 1393b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis class TPResult { 1394b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis enum Result { 1395b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_true, 1396b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_false, 1397b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_ambiguous, 1398b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_error 1399b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis }; 1400b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis Result Res; 1401b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult(Result result) : Res(result) {} 1402b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis public: 1403b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult True() { return TPR_true; } 1404b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult False() { return TPR_false; } 1405b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Ambiguous() { return TPR_ambiguous; } 1406b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Error() { return TPR_error; } 1407b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis 1408b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator==(const TPResult &RHS) const { return Res == RHS.Res; } 1409b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; } 1410b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis }; 1411b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis 1412a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// \brief Based only on the given token kind, determine whether we know that 1413a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// we're at the start of an expression or a type-specifier-seq (which may 1414a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// be an expression, in C++). 1415a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// 1416a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// This routine does not attempt to resolve any of the trick cases, e.g., 1417a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// those involving lookup of identifiers. 1418a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// 1419a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// \returns \c TPR_true if this token starts an expression, \c TPR_false if 1420a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot 1421a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// tell. 1422a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind); 1423a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor 1424b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a 1425b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// declaration specifier, TPResult::False() if it is not, 1426b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult::Ambiguous() if it could be either a decl-specifier or a 1427b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// function-style cast, and TPResult::Error() if a parsing error was 1428b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// encountered. 14295404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Doesn't consume tokens. 1430b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult isCXXDeclarationSpecifier(); 1431a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor 14325404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // "Tentative parsing" functions, used for disambiguation. If a parsing error 1433b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // is encountered they will return TPResult::Error(). 1434b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // Returning TPResult::True()/False() indicates that the ambiguity was 1435b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates 1436b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // that more tentative parsing is necessary for disambiguation. 14375404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // They all consume tokens, so backtracking should be used after calling them. 14385404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1439b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseDeclarationSpecifier(); 1440b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseSimpleDeclaration(); 1441b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseTypeofSpecifier(); 14429bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor TPResult TryParseProtocolQualifiers(); 1443b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseInitDeclaratorList(); 144478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); 1445b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseParameterDeclarationClause(); 1446b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseFunctionDeclarator(); 1447b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseBracketDeclarator(); 14485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1449ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl TypeResult ParseTypeName(SourceRange *Range = 0); 145098eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump void ParseBlockId(); 1451ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 1452ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the attribute list. 1453bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList ParseCXX0XAttributes(SourceLocation *EndLoc = 0); 1454334d47e92e9f241576fdeb7477b69a03136ba854Francois Pichet void ParseMicrosoftAttributes(); 1455bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttributeList *ParseGNUAttributes(SourceLocation *EndLoc = 0); 1456290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0); 1457290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0); 145852fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik AttributeList *ParseBorlandTypeAttributes(AttributeList* CurrAttr = 0); 1459d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff void ParseTypeofSpecifier(DeclSpec &DS); 14606fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson void ParseDecltypeSpecifier(DeclSpec &DS); 1461bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 146260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXX0XAlignArgument(SourceLocation Start); 1463eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1464eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to 1465eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// enter a new C++ declarator scope and exit it when the function is 1466eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// finished. 1467eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis class DeclaratorScopeObj { 1468eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis Parser &P; 1469751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis CXXScopeSpec &SS; 1470f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis bool EnteredScope; 1471f7f3d0db754db0500b56d49ac19f795f13965912John McCall bool CreatedScope; 1472eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis public: 1473f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) 1474f7f3d0db754db0500b56d49ac19f795f13965912John McCall : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} 1475eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1476eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis void EnterDeclaratorScope() { 14772bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis assert(!EnteredScope && "Already entered the scope!"); 1478f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was not set!"); 1479f7f3d0db754db0500b56d49ac19f795f13965912John McCall 1480f7f3d0db754db0500b56d49ac19f795f13965912John McCall CreatedScope = true; 1481f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.EnterScope(0); // Not a decl scope. 1482f7f3d0db754db0500b56d49ac19f795f13965912John McCall 148323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS)) 14843fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor EnteredScope = true; 1485eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1486eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1487eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis ~DeclaratorScopeObj() { 1488f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis if (EnteredScope) { 1489f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was cleared ?"); 149023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS); 1491f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis } 1492f7f3d0db754db0500b56d49ac19f795f13965912John McCall if (CreatedScope) 1493f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.ExitScope(); 1494eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1495eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis }; 14961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseDeclarator - Parse and verify a newly-initialized declarator. 14985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDeclarator(Declarator &D); 14994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl /// A function that parses a variant of direct-declarator. 15004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef void (Parser::*DirectDeclParseFunction)(Declarator&); 15014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDeclaratorInternal(Declarator &D, 15024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl DirectDeclParseFunction DirectDeclParser); 1503bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, 1504bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool CXX0XAttributesAllowed = true); 15055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDirectDeclarator(Declarator &D); 15065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseParenDeclarator(Declarator &D); 15077399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, 15087399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner AttributeList *AttrList = 0, 15097399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner bool RequiresArg = false); 151066d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc, 151183a944763b0948c608eb48f101ec10a1ae5da46aChris Lattner IdentifierInfo *FirstIdent, 151283a944763b0948c608eb48f101ec10a1ae5da46aChris Lattner SourceLocation FirstIdentLoc, 151366d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner Declarator &D); 15145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseBracketDeclarator(Declarator &D); 15151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15168f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner //===--------------------------------------------------------------------===// 15178f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner // C++ 7: Declarations [dcl.dcl] 15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1519bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool isCXX0XAttributeSpecifier(bool FullLookahead = false, 1520bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt tok::TokenKind *After = 0); 1521bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 1522d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd, 1523d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation InlineLoc = SourceLocation()); 1524d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context); 1525d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseUsingDirectiveOrDeclaration(unsigned Context, 152678b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 1527d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 1528d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl CXX0XAttributeList Attrs); 152978b810559d89e996e00684335407443936ce34a1John McCall Decl *ParseUsingDirective(unsigned Context, 153078b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 1531d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, AttributeList *Attr); 153278b810559d89e996e00684335407443936ce34a1John McCall Decl *ParseUsingDeclaration(unsigned Context, 153378b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 153478b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 1535d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 1536d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl AccessSpecifier AS = AS_none); 1537d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd); 1538d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc, 1539d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation AliasLoc, IdentifierInfo *Alias, 1540d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd); 15411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1542e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 1543e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 9: classes [class] and C structs/unions. 15441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeResult ParseClassName(SourceLocation &EndLocation, 15459ab14541716928894821cf5d53d6b4c95ffdf3a3Jeffrey Yasskin CXXScopeSpec *SS = 0); 15464c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, 15471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclSpec &DS, 15484d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1549d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl AccessSpecifier AS = AS_none, 1550d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 15514cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType, 1552d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 155337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseCXXClassMemberDeclaration(AccessSpecifier AS, 1554c9068d7dd94d439cec66c421115d15303e481025John McCall const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1555c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject *DiagsFromTParams = 0); 1556d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseConstructorInitializer(Decl *ConstructorDecl); 1557d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall MemInitResult ParseMemInitializer(Decl *ConstructorDecl); 1558d33133cdc1af466f9c276249b2621be03867888bEli Friedman void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, 1559d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ThisDecl); 1560e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1561e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 1562e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 10: Derived classes [class.derived] 1563d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseBaseClause(Decl *ClassDecl); 1564d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall BaseResult ParseBaseSpecifier(Decl *ClassDecl); 15651b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor AccessSpecifier getAccessSpecifierIfPresent() const; 15661cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor 15673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 15683f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Name, 15693f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation NameLoc, 15703f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool EnteringContext, 1571b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1572d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor UnqualifiedId &Id, 15730278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor bool AssumeTemplateId, 15740278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor SourceLocation TemplateKWLoc); 1575ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, 1576b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1577ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &Result); 15783f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, 157902a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowDestructorName, 158002a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowConstructorName, 1581b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 15823f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &Result); 15833f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 15841cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor //===--------------------------------------------------------------------===// 1585adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14: Templates [temp] 1586c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 1587adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14.1: Template Parameters [temp.param] 1588d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationStartingWithTemplate(unsigned Context, 15894d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation &DeclEnd, 15904d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AccessSpecifier AS = AS_none); 1591d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context, 159297144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation &DeclEnd, 15934d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AccessSpecifier AS); 1594d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseSingleDeclarationAfterTemplate( 15951426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor unsigned Context, 15964d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 1597c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject &DiagsFromParams, 15981426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor SourceLocation &DeclEnd, 15991426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor AccessSpecifier AS=AS_none); 16001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseTemplateParameters(unsigned Depth, 16011f58816e6589ef15d1509c6c99bb8fabf2a4cda9John McCall llvm::SmallVectorImpl<Decl*> &TemplateParams, 16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation &LAngleLoc, 1603c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor SourceLocation &RAngleLoc); 1604c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor bool ParseTemplateParameterList(unsigned Depth, 16051f58816e6589ef15d1509c6c99bb8fabf2a4cda9John McCall llvm::SmallVectorImpl<Decl*> &TemplateParams); 160698440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor bool isStartOfTemplateTypeParameter(); 1607d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateParameter(unsigned Depth, unsigned Position); 1608d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTypeParameter(unsigned Depth, unsigned Position); 1609d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); 1610d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); 1611d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor // C++ 14.3: Template arguments [temp.arg] 1612314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor typedef llvm::SmallVector<ParsedTemplateArgument, 16> TemplateArgList; 1613cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 16147532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor bool ParseTemplateIdAfterTemplateName(TemplateTy Template, 16151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateNameLoc, 1616cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor const CXXScopeSpec *SS, 1617cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor bool ConsumeLastToken, 1618cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &LAngleLoc, 1619cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateArgList &TemplateArgs, 1620cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &RAngleLoc); 1621cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 1622c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, 162339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor const CXXScopeSpec *SS, 1624ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &TemplateName, 162539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor SourceLocation TemplateKWLoc = SourceLocation(), 162639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor bool AllowTypeAnnotation = true); 162731a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor void AnnotateTemplateIdTokenAsType(const CXXScopeSpec *SS = 0); 1628d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor bool IsTemplateArgumentList(unsigned Skip = 0); 1629314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); 1630788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor ParsedTemplateArgument ParseTemplateTemplateArgument(); 1631314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor ParsedTemplateArgument ParseTemplateArgument(); 1632d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseExplicitInstantiation(SourceLocation ExternLoc, 1633d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SourceLocation TemplateLoc, 1634d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SourceLocation &DeclEnd); 163564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 163664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl //===--------------------------------------------------------------------===// 163764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // GNU G++: Type Traits [Type-Traits.html in the GCC manual] 163860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseUnaryTypeTrait(); 1639f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor 1640f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor //===--------------------------------------------------------------------===// 1641f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor // Preprocessor code-completion pass-through 1642f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor virtual void CodeCompleteDirective(bool InConditional); 1643f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor virtual void CodeCompleteInConditionalExclusion(); 16441fbb447e9d43c2c676e94081fbfee7eb6cbe933bDouglas Gregor virtual void CodeCompleteMacroName(bool IsDefinition); 1645f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor virtual void CodeCompletePreprocessorExpression(); 1646f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro, 1647f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor MacroInfo *MacroInfo, 1648f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor unsigned ArgumentIndex); 164955817afdf9d453a443262a733f6caf6692dca118Douglas Gregor virtual void CodeCompleteNaturalLanguage(); 16505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 16535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1655