Parser.h revision 0fbda68b50ce17d7ad36ef7a5ed77518a5cd272e
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 AttributeList; 29bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt struct CXX0XAttributeList; 30fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar class PragmaHandler; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Scope; 322b5289b6fd7e3d9899868410a498c081c9595662John McCall class DeclGroupRef; 333cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner class DiagnosticBuilder; 340102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner class Parser; 354726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek class PragmaUnusedHandler; 3608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner class ColonProtectionRAIIObject; 370fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor class InMessageExpressionRAIIObject; 380fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 390102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// PrettyStackTraceParserEntry - If a crash happens while the parser is active, 400102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// an entry is printed for it. 410102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerclass PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry { 420102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Parser &P; 430102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerpublic: 440102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner PrettyStackTraceParserEntry(const Parser &p) : P(p) {} 450102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner virtual void print(llvm::raw_ostream &OS) const; 460102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner}; 471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// PrecedenceLevels - These are precedences for the binary/ternary 496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// operators in the C99 grammar. These have been named to relate 506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// with the C99 grammar productions. Low precedences numbers bind 516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// more weakly than high numbers. 526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregornamespace prec { 536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor enum Level { 546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Unknown = 0, // Not binary operator. 556aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Comma = 1, // , 566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Assignment = 2, // =, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |= 576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Conditional = 3, // ? 586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor LogicalOr = 4, // || 596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor LogicalAnd = 5, // && 606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor InclusiveOr = 6, // | 616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ExclusiveOr = 7, // ^ 626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor And = 8, // & 636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Equality = 9, // ==, != 646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Relational = 10, // >=, <=, >, < 656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Shift = 11, // <<, >> 666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Additive = 12, // -, + 676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Multiplicative = 13, // *, /, % 686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor PointerToMember = 14 // .*, ->* 696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor }; 706aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Parser - This implements a parser for the C family of languages. After 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// parsing units of the grammar, productions are invoked to handle whatever has 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// been read. 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 76f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregorclass Parser : public CodeCompletionHandler { 774726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek friend class PragmaUnusedHandler; 7808d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner friend class ColonProtectionRAIIObject; 790fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor friend class InMessageExpressionRAIIObject; 8036d36806f1972f7ec1d2a3f59155187278c56508Argyrios Kyrtzidis friend class ParenBraceBracketBalancer; 810102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner PrettyStackTraceParserEntry CrashInfo; 821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Preprocessor &PP; 841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8597d0205d16fef2a783e785459b5f30f6a9dfbcb9Eric Christopher /// Tok - The current token we are peeking ahead. All parsing methods assume 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that this is valid. 87d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner Token Tok; 881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 894b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // PrevTokLocation - The location of the token we previously 904b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // consumed. This token is used for diagnostics where we expected to 914b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // see a token following another token (e.g., the ';' at the end of 924b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // a statement). 934b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceLocation PrevTokLocation; 944b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned short ParenCount, BracketCount, BraceCount; 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Actions - These are the callbacks we invoke as we parse various constructs 9887c300738174924453648c3b2d6f366c8284fac4Douglas Gregor /// in the file. 99f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &Actions; 1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diagnostic &Diags; 1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1039e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner /// ScopeCache - Cache scopes to reduce malloc traffic. 1049e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner enum { ScopeCacheSize = 16 }; 1059e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner unsigned NumCachedScopes; 1069e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner Scope *ScopeCache[ScopeCacheSize]; 107662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 108662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// Ident_super - IdentifierInfo for "super", to support fast 109662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// comparison. 110662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar IdentifierInfo *Ident_super; 11182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// Ident_vector and Ident_pixel - cached IdentifierInfo's for 11282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// "vector" and "pixel" fast comparison. Only present if 11382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// AltiVec enabled. 11482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_vector; 11582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_pixel; 116662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 117cbb98edd530787c2ac019e437e7c599df8004ba7Daniel Dunbar llvm::OwningPtr<PragmaHandler> AlignHandler; 118aa8b0d19244a6e7e8e5798fcc6aef003c274d3e0Eli Friedman llvm::OwningPtr<PragmaHandler> GCCVisibilityHandler; 119861800c676004eabed5927f0552620d06c80a40aDaniel Dunbar llvm::OwningPtr<PragmaHandler> OptionsHandler; 1204726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> PackHandler; 1214726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> UnusedHandler; 1229991479ad5dde617168cc1e4b18425cdbbfd9fa9Eli Friedman llvm::OwningPtr<PragmaHandler> WeakHandler; 1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// Whether the '>' token acts as an operator or not. This will be 12555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// true except when we are parsing an expression within a C++ 12655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// template argument list, where the '>' closes the template 12755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// argument list. 12855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor bool GreaterThanIsOperator; 12908d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner 13008d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonIsSacred - When this is false, we aggressively try to recover from 13108d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not 13208d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// safe in case statements and a few other things. This is managed by the 13308d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonProtectionRAIIObject RAII object. 13408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner bool ColonIsSacred; 13555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1360fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// \brief When true, we are directly inside an Ojective-C messsage 1370fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// send expression. 1380fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// 1390fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// This is managed by the \c InMessageExpressionRAIIObject class, and 1400fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// should not be set directly. 1410fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor bool InMessageExpression; 1420fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 143c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor /// The "depth" of the template parameters currently being parsed. 144c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor unsigned TemplateParameterDepth; 1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 147f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Parser(Preprocessor &PP, Sema &Actions); 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Parser(); 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const LangOptions &getLang() const { return PP.getLangOptions(); } 151444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } 1520102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner Preprocessor &getPreprocessor() const { return PP; } 153f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &getActions() const { return Actions; } 1541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1550102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Token &getCurToken() const { return Tok; } 15623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Scope *getCurScope() const { return Actions.getCurScope(); } 15723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Type forwarding. All of these are statically 'void*', but they may all be 1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // different actual classes based on the actions in place. 160ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef Expr ExprTy; 161ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef Stmt StmtTy; 1622b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 163ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef CXXBaseSpecifier BaseTy; 164ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef CXXBaseOrMemberInitializer MemInitTy; 165ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef NestedNameSpecifier CXXScopeTy; 166ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef TemplateParameterList TemplateParamsTy; 1672b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<TemplateName> TemplateTy; 1687ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 169ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef llvm::SmallVector<TemplateParameterList *, 4> TemplateParameterLists; 170c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 1719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::ExprResult ExprResult; 1729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::StmtResult StmtResult; 1739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::BaseResult BaseResult; 1749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::MemInitResult MemInitResult; 1759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::TypeResult TypeResult; 17615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 1779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef Expr *ExprArg; 1789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef ASTMultiPtr<Stmt*> MultiStmtArg; 179f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::FullExprArg FullExprArg; 1801d922960e083906a586609ac6978678147250177Sebastian Redl 18160d7b3a319d84d688752be3870615ac0f111fb16John McCall /// Adorns a ExprResult with Actions to make it an ExprResult 18260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Owned(ExprResult res) { 18360d7b3a319d84d688752be3870615ac0f111fb16John McCall return ExprResult(res); 18461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 18560d7b3a319d84d688752be3870615ac0f111fb16John McCall /// Adorns a StmtResult with Actions to make it an StmtResult 18660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Owned(StmtResult res) { 18760d7b3a319d84d688752be3870615ac0f111fb16John McCall return StmtResult(res); 18861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 18961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 19060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError() { return ExprResult(true); } 19160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError() { return StmtResult(true); } 192d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor 19360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); } 19460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); } 19561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 19660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprEmpty() { return ExprResult(false); } 1975ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Parsing methods. 1991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseTranslationUnit - All in one method that initializes parses, and 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// shuts down the parser. 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseTranslationUnit(); 2031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Initialize - Warm up the parser. 2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Initialize(); 2071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if 2091f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff /// the EOF was encountered. 210682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner bool ParseTopLevelDecl(DeclGroupPtrTy &Result); 2111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2123fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian DeclGroupPtrTy FinishPendingObjCActions(); 21363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Low-Level token peeking and consumption methods. 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 2181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenParen - Return true if the cur token is '(' or ')'. 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenParen() const { 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren; 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBracket - Return true if the cur token is '[' or ']'. 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBracket() const { 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square; 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBrace - Return true if the cur token is '{' or '}'. 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBrace() const { 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace; 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenStringLiteral - True if this token is a string-literal. 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenStringLiteral() const { 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::string_literal || 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Tok.getKind() == tok::wide_string_literal; 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 238eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeToken - Consume the current 'peek token' and lex the next one. 240d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu /// This does not work with all kinds of tokens: strings and specific other 2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tokens must be consumed with custom methods below. This returns the 2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// location of the consumed token. 2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeToken() { 2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer !isTokenBrace() && 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should consume special tokens with Consume*Token"); 247dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor if (Tok.is(tok::code_completion)) { 248dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor CodeCompletionRecovery(); 249dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor return ConsumeCodeCompletionToken(); 250dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor } 251dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 2524b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2544b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeAnyToken - Dispatch to the right Consume* method based on the 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// current token type. This should only be used in cases where the type of 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the token really isn't known, e.g. in error recovery. 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeAnyToken() { 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isTokenParen()) 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeParen(); 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBracket()) 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBracket(); 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBrace()) 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBrace(); 267d62701bc5321049353017e9abf1963edd57646aaSteve Naroff else if (isTokenStringLiteral()) 268d62701bc5321049353017e9abf1963edd57646aaSteve Naroff return ConsumeStringToken(); 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeToken(); 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeParen - This consume method keeps the paren count up-to-date. 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeParen() { 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenParen() && "wrong consume method"); 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_paren) 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++ParenCount; 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (ParenCount) 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --ParenCount; // Don't let unbalanced )'s drive the count negative. 2814b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2834b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBracket - This consume method keeps the bracket count up-to-date. 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBracket() { 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBracket() && "wrong consume method"); 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_square) 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BracketCount; 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BracketCount) 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BracketCount; // Don't let unbalanced ]'s drive the count negative. 2941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2954b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2974b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBrace - This consume method keeps the brace count up-to-date. 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBrace() { 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBrace() && "wrong consume method"); 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_brace) 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BraceCount; 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BraceCount) 3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BraceCount; // Don't let unbalanced }'s drive the count negative. 3081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3094b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3114b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeStringToken - Consume the current 'peek token', lexing a new one 3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and returning the token kind. This method is specific to strings, as it 3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// handles string literal concatenation, as per C99 5.1.1.2, translation 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// phase #6. 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeStringToken() { 3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenStringLiteral() && 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should only consume string literals with this method"); 3214b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3234b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 326dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// \brief Consume the current code-completion token. 327dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// 328dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// This routine should be called to consume the code-completion token once 329dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// a code-completion action has already been invoked. 330dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor SourceLocation ConsumeCodeCompletionToken() { 331dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor assert(Tok.is(tok::code_completion)); 332dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PrevTokLocation = Tok.getLocation(); 333dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PP.Lex(Tok); 334dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor return PrevTokLocation; 335dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor } 336dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 337dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ///\ brief When we are consuming a code-completion token within having 338dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// matched specific position in the grammar, provide code-completion results 339dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// based on context. 340dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor void CodeCompletionRecovery(); 341dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 3426b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// GetLookAheadToken - This peeks ahead N tokens and returns that token 3436b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1) 3446b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// returns the token after Tok, etc. 3456b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 3466b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// Note that this differs from the Preprocessor's LookAhead method, because 3476b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// the Parser always has one token lexed that the preprocessor doesn't. 3486b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 34903db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis const Token &GetLookAheadToken(unsigned N) { 3506b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (N == 0 || Tok.is(tok::eof)) return Tok; 3516b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return PP.LookAhead(N-1); 3526b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } 353f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis 354f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// NextToken - This peeks ahead one token and returns it without 355f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// consuming it. 356f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis const Token &NextToken() { 35703db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis return PP.LookAhead(0); 358f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis } 3595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 360b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall /// getTypeAnnotation - Read a parsed type out of an annotation token. 361b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static ParsedType getTypeAnnotation(Token &Tok) { 362b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue()); 363b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 364b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 365b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static void setTypeAnnotation(Token &Tok, ParsedType T) { 366b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Tok.setAnnotationValue(T.getAsOpaquePtr()); 367b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 368b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 369eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// TryAnnotateTypeOrScopeToken - If the current token position is on a 370eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// typename (possibly qualified in C++) or a C++ scope specifier not followed 371eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens 372eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// with a single annotation token representing the typename or C++ scope 373eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// respectively. 374eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// This simplifies handling of C++ scope specifiers and allows efficient 375eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// backtracking without the need to re-parse and resolve nested-names and 376eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// typenames. 37744802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// It will mainly be called when we expect to treat identifiers as typenames 37844802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// (if they are typenames). For example, in C we do not expect identifiers 37944802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// inside expressions to be treated as typenames so it will not be called 38044802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// for expressions in C. 381a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner /// 382a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner /// This returns true if the token was annotated. 383495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false); 384eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 3859ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but 3869ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// only annotates C++ scope specifiers. This returns true if there 3879ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// was an unrecoverable error. 388495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateCXXScopeToken(bool EnteringContext = false); 389eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 39082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens, 39182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// replacing them with the non-context-sensitive keywords. This returns 39282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// true if the token was replaced. 39382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc, 394b3a4e432c90be98c6d918087750397e86d030368Chris Lattner const char *&PrevSpec, unsigned &DiagID, 395b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool &isInvalid) { 3961b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner if (!getLang().AltiVec || 3971b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner (Tok.getIdentifierInfo() != Ident_vector && 3981b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner Tok.getIdentifierInfo() != Ident_pixel)) 3991b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return false; 4001b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 4011b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); 40282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 40382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 40482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector 40582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// identifier token, replacing it with the non-context-sensitive __vector. 40682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// This returns true if the token was replaced. 40782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecVectorToken() { 408b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (!getLang().AltiVec || 409b3a4e432c90be98c6d918087750397e86d030368Chris Lattner Tok.getIdentifierInfo() != Ident_vector) return false; 4101b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecVectorTokenOutOfLine(); 41182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 4121b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 4131b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecVectorTokenOutOfLine(); 4141b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, 4151b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner const char *&PrevSpec, unsigned &DiagID, 4161b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool &isInvalid); 4171b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 4185404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TentativeParsingAction - An object that is used as a kind of "tentative 4195404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// parsing transaction". It gets instantiated to mark the token position and 4205404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// after the token consumption is done, Commit() or Revert() is called to 4215404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// either "commit the consumed tokens" or revert to the previously marked 4225404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// token position. Example: 4235404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 424314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor /// TentativeParsingAction TPA(*this); 4255404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// ConsumeToken(); 4265404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// .... 4275404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TPA.Revert(); 4285404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 4295404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis class TentativeParsingAction { 4305404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Parser &P; 4315404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Token PrevTok; 4325404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isActive; 4335404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 4345404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis public: 4355404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis explicit TentativeParsingAction(Parser& p) : P(p) { 4365404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis PrevTok = P.Tok; 4375404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.EnableBacktrackAtThisPos(); 4385404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = true; 4395404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4405404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Commit() { 4415404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 4425404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.CommitBacktrackedTokens(); 4435404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 4445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Revert() { 4465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 4475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.Backtrack(); 4485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.Tok = PrevTok; 4495404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 4505404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4515404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis ~TentativeParsingAction() { 4525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(!isActive && "Forgot to call Commit or Revert!"); 4535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis }; 4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'), 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this helper function matches and consumes the specified RHS token if 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// present. If not present, it emits the specified diagnostic indicating 4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that the parser failed to match the RHS of the token at LHSLoc. LHSName 4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// should be the name of the unmatched LHS token. This returns the location 4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the consumed token. 4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MatchRHSPunctuation(tok::TokenKind RHSTok, 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation LHSLoc); 4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// input. If so, it is consumed and false is returned. 4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If the input is malformed, this emits the specified diagnostic. Next, if 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// returned. 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag, 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *DiagMsg = "", 4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind SkipToTok = tok::unknown); 4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4769ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// \brief The parser expects a semicolon and, if present, will consume it. 4779ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// 4789ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// If the next token is not a semicolon, this emits the specified diagnostic, 4799ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior 4809ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// to the semicolon, consumes that extra token. 4819ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor bool ExpectAndConsumeSemi(unsigned DiagID); 4829ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor 4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Scope manipulation 4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4868935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// ParseScope - Introduces a new scope for parsing. The kind of 4878935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// scope is determined by ScopeFlags. Objects of this type should 4888935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// be created on the stack to coincide with the position where the 4898935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// parser enters the new scope, and this object's constructor will 4908935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// create that new scope. Similarly, once the object is destroyed 4918935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// the parser will exit the scope. 4928935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor class ParseScope { 4938935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Parser *Self; 4948935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope(const ParseScope&); // do not implement 4958935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope& operator=(const ParseScope&); // do not implement 4968935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 4978935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor public: 4988935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ParseScope - Construct a new object to manage a scope in the 4998935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // parser Self where the new Scope is created with the flags 5008935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ScopeFlags, but only when ManageScope is true (the default). If 5018935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ManageScope is false, this object does nothing. 5021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true) 5038935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor : Self(Self) { 5048935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (ManageScope) 5058935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->EnterScope(ScopeFlags); 5068935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor else 5078935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor this->Self = 0; 5088935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 5098935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 5108935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // Exit - Exit the scope associated with this object now, rather 5118935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // than waiting until the object is destroyed. 5128935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor void Exit() { 5138935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (Self) { 5148935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->ExitScope(); 5158935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self = 0; 5168935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 5178935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 5188935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 5198935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ~ParseScope() { 5208935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Exit(); 5218935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 5228935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor }; 5238935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterScope - Start a new scope. 5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterScope(unsigned ScopeFlags); 5261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExitScope - Pop a scope off the scope stack. 5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ExitScope(); 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Diagnostic Emission and Error recovery. 53215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 5336aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorpublic: 5343cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 5353cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); 53615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 5376aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorprivate: 5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SuggestParentheses(SourceLocation Loc, unsigned DK, 5394b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceRange ParenRange); 5404b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipUntil - Read tokens until we get to the specified token, then consume 54282c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff /// it (unless DontConsume is true). Because we cannot guarantee that the 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// token will ever occur, this skips to the next token, or to some likely 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// character. 5461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If SkipUntil finds the specified token, it returns true, otherwise it 5481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returns false. 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true, 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool DontConsume = false) { 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SkipUntil(&T, 1, StopAtSemi, DontConsume); 5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true, 5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool DontConsume = false) { 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind TokArray[] = {T1, T2}; 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SkipUntil(TokArray, 2, StopAtSemi, DontConsume); 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool StopAtSemi = true, bool DontConsume = false); 5607ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 5624cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Lexing and parsing of C++ inline methods. 5634cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 5644cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis struct LexedMethod { 565d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *D; 56672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens Toks; 567d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 568d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 569d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 570d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 571d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 572d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 573d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall explicit LexedMethod(Decl *MD) : D(MD), TemplateScope(false) {} 5744cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis }; 5754cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 57672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedDefaultArgument - Keeps track of a parameter that may 57772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument that cannot be parsed yet because it 57872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// occurs within a member function declaration inside the class 57972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// (C++ [class.mem]p2). 58072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedDefaultArgument { 581d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall explicit LateParsedDefaultArgument(Decl *P, 58272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks = 0) 58372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor : Param(P), Toks(Toks) { } 58472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 58572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Param - The parameter declaration for this parameter. 586d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param; 58772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 58872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Toks - The sequence of tokens that comprises the default 58972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument expression, not including the '=' or the terminating 59072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// ')' or ','. This will be NULL for parameters that have no 59172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// default argument. 59272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks; 59372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 5941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDeclaration - A method declaration inside a class that 59672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// contains at least one entity whose parsing needs to be delayed 59772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// until the class itself is completely-defined, such as a default 59872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument (C++ [class.mem]p2). 59972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedMethodDeclaration { 600d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall explicit LateParsedMethodDeclaration(Decl *M) 601d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor : Method(M), TemplateScope(false) { } 60272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 60372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Method - The method declaration. 604d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Method; 60572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 606d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 607d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 608d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 609d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// DefaultArgs - Contains the parameters of the function and 61272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// their default arguments. At least one of the parameters will 61372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument, but all of the parameters of the 61472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// method will be stored so that they can be reintroduced into 6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// scope at the appropriate times. 61672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor llvm::SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; 61772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 61872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 61972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDecls - During parsing of a top (non-nested) C++ 62072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// class, its method declarations that contain parts that won't be 62172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// parsed until after the definiton is completed (C++ [class.mem]p2), 62272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// the method declarations will be stored here with the tokens that 62372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// will be parsed to create those entities. 62472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor typedef std::list<LateParsedMethodDeclaration> LateParsedMethodDecls; 62572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 6264cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// LexedMethodsForTopClass - During parsing of a top (non-nested) C++ class, 6274cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// its inline method definitions and the inline method definitions of its 6284cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// nested classes are lexed and stored here. 62972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor typedef std::list<LexedMethod> LexedMethodsForTopClass; 63072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 6316569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Representation of a class that has been parsed, including 6326569d68745c8213709740337d2be52b031384f58Douglas Gregor /// any member function declarations or definitions that need to be 6336569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed after the corresponding top-level class is complete. 6346569d68745c8213709740337d2be52b031384f58Douglas Gregor struct ParsingClass { 635d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParsingClass(Decl *TagOrTemplate, bool TopLevelClass) 6361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : TopLevelClass(TopLevelClass), TemplateScope(false), 6376569d68745c8213709740337d2be52b031384f58Douglas Gregor TagOrTemplate(TagOrTemplate) { } 6386569d68745c8213709740337d2be52b031384f58Douglas Gregor 6396569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this is a "top-level" class, meaning that it is 6406569d68745c8213709740337d2be52b031384f58Douglas Gregor /// not nested within another class. 6416569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TopLevelClass : 1; 6426569d68745c8213709740337d2be52b031384f58Douglas Gregor 6436569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this class had an associated template 6446569d68745c8213709740337d2be52b031384f58Douglas Gregor /// scope. When true, TagOrTemplate is a template declaration; 6456569d68745c8213709740337d2be52b031384f58Douglas Gregor /// othewise, it is a tag declaration. 6466569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TemplateScope : 1; 6476569d68745c8213709740337d2be52b031384f58Douglas Gregor 6486569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The class or class template whose definition we are parsing. 649d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagOrTemplate; 65072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 65172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// MethodDecls - Method declarations that contain pieces whose 65272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// parsing will be delayed until the class is fully defined. 65372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor LateParsedMethodDecls MethodDecls; 65472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 65572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// MethodDefs - Methods whose definitions will be parsed once the 65672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// class has been fully defined. 65772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor LexedMethodsForTopClass MethodDefs; 6586569d68745c8213709740337d2be52b031384f58Douglas Gregor 6596569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Nested classes inside this class. 6606569d68745c8213709740337d2be52b031384f58Douglas Gregor llvm::SmallVector<ParsingClass*, 4> NestedClasses; 66172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 6624cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 6636569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The stack of classes that is currently being 6646569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed. Nested and local classes will be pushed onto this stack 6656569d68745c8213709740337d2be52b031384f58Douglas Gregor /// when they are parsed, and removed afterward. 6666569d68745c8213709740337d2be52b031384f58Douglas Gregor std::stack<ParsingClass *> ClassStack; 6674cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 6686569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingClass &getCurrentClass() { 6696569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "No lexed method stacks!"); 6706569d68745c8213709740337d2be52b031384f58Douglas Gregor return *ClassStack.top(); 6714cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 6724cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 67354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// \brief RAII object used to inform the actions that we're 67454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// currently parsing a declaration. This is active when parsing a 67554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// variable's initializer, but not when parsing the body of a 67654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// class or function definition. 67754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclRAIIObject { 678f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &Actions; 679f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::ParsingDeclStackState State; 68054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall bool Popped; 681c9068d7dd94d439cec66c421115d15303e481025John McCall 68254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 68354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) { 68454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 68554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 68654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 687c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *Other) 688c9068d7dd94d439cec66c421115d15303e481025John McCall : Actions(P.Actions) { 689c9068d7dd94d439cec66c421115d15303e481025John McCall if (Other) steal(*Other); 690c9068d7dd94d439cec66c421115d15303e481025John McCall else push(); 691c9068d7dd94d439cec66c421115d15303e481025John McCall } 692c9068d7dd94d439cec66c421115d15303e481025John McCall 693c9068d7dd94d439cec66c421115d15303e481025John McCall /// Creates a RAII object which steals the state from a different 694c9068d7dd94d439cec66c421115d15303e481025John McCall /// object instead of pushing. 695c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject(ParsingDeclRAIIObject &Other) 696c9068d7dd94d439cec66c421115d15303e481025John McCall : Actions(Other.Actions) { 697c9068d7dd94d439cec66c421115d15303e481025John McCall steal(Other); 698c9068d7dd94d439cec66c421115d15303e481025John McCall } 699c9068d7dd94d439cec66c421115d15303e481025John McCall 70054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ~ParsingDeclRAIIObject() { 70154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 70254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 70354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 70454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Resets the RAII object for a new declaration. 70554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void reset() { 70654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 70754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 70854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 70954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 71054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Signals that the context was completed without an appropriate 71154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// declaration being parsed. 71254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 713d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall pop(0); 71454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 71554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 716d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 71754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall assert(!Popped && "ParsingDeclaration has already been popped!"); 71854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall pop(D); 71954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 72054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 72154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall private: 722c9068d7dd94d439cec66c421115d15303e481025John McCall void steal(ParsingDeclRAIIObject &Other) { 723c9068d7dd94d439cec66c421115d15303e481025John McCall State = Other.State; 724c9068d7dd94d439cec66c421115d15303e481025John McCall Popped = Other.Popped; 725c9068d7dd94d439cec66c421115d15303e481025John McCall Other.Popped = true; 726c9068d7dd94d439cec66c421115d15303e481025John McCall } 727c9068d7dd94d439cec66c421115d15303e481025John McCall 72854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void push() { 72954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall State = Actions.PushParsingDeclaration(); 73054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = false; 73154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 73254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 733d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void pop(Decl *D) { 73454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall if (!Popped) { 73554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Actions.PopParsingDeclaration(State, D); 73654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = true; 73754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 73854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 73954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 74054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 74154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a DeclSpec. 74254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclSpec : public DeclSpec { 74354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 74454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 74554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 746c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec(Parser &P) : ParsingRAII(P) {} 747c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec(ParsingDeclRAIIObject &RAII) : ParsingRAII(RAII) {} 748c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII) 749c9068d7dd94d439cec66c421115d15303e481025John McCall : ParsingRAII(P, RAII) {} 75054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 751d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 75254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 75354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 75454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 75554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 75654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.abort(); 75754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 75854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 75954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 76054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a declarator. 76154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclarator : public Declarator { 76254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 76354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 76454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 76554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C) 76654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall : Declarator(DS, C), ParsingRAII(P) { 76754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 76854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 76954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall const ParsingDeclSpec &getDeclSpec() const { 77054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec()); 77154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 77254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 77354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclSpec &getMutableDeclSpec() const { 77454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return const_cast<ParsingDeclSpec&>(getDeclSpec()); 77554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 77654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 77754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void clear() { 77854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Declarator::clear(); 77954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.reset(); 78054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 78154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 782d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 78354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 78454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 78554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 78654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 7871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief RAII object used to 7886569d68745c8213709740337d2be52b031384f58Douglas Gregor class ParsingClassDefinition { 7896569d68745c8213709740337d2be52b031384f58Douglas Gregor Parser &P; 7906569d68745c8213709740337d2be52b031384f58Douglas Gregor bool Popped; 7916569d68745c8213709740337d2be52b031384f58Douglas Gregor 7926569d68745c8213709740337d2be52b031384f58Douglas Gregor public: 793d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass) 7941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : P(P), Popped(false) { 7956569d68745c8213709740337d2be52b031384f58Douglas Gregor P.PushParsingClass(TagOrTemplate, TopLevelClass); 7966569d68745c8213709740337d2be52b031384f58Douglas Gregor } 7976569d68745c8213709740337d2be52b031384f58Douglas Gregor 7986569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Pop this class of the stack. 7991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void Pop() { 8006569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!Popped && "Nested class has already been popped"); 8016569d68745c8213709740337d2be52b031384f58Douglas Gregor Popped = true; 8026569d68745c8213709740337d2be52b031384f58Douglas Gregor P.PopParsingClass(); 8036569d68745c8213709740337d2be52b031384f58Douglas Gregor } 8046569d68745c8213709740337d2be52b031384f58Douglas Gregor 8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ~ParsingClassDefinition() { 8066569d68745c8213709740337d2be52b031384f58Douglas Gregor if (!Popped) 8071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump P.PopParsingClass(); 8086569d68745c8213709740337d2be52b031384f58Douglas Gregor } 8096569d68745c8213709740337d2be52b031384f58Douglas Gregor }; 8106569d68745c8213709740337d2be52b031384f58Douglas Gregor 8114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief Contains information about any template-specific 8124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// information that has been parsed prior to parsing declaration 8134d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// specifiers. 8144d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor struct ParsedTemplateInfo { 8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsedTemplateInfo() 8164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { } 8174d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 8184d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ParsedTemplateInfo(TemplateParameterLists *TemplateParams, 819c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool isSpecialization, 820c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool lastParameterListWasEmpty = false) 8214d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(isSpecialization? ExplicitSpecialization : Template), 822c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor TemplateParams(TemplateParams), 823c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(lastParameterListWasEmpty) { } 8244d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 82545f965581935791a018df829a14dff53c1dd8f47Douglas Gregor explicit ParsedTemplateInfo(SourceLocation ExternLoc, 82645f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation TemplateLoc) 8271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Kind(ExplicitInstantiation), TemplateParams(0), 828c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), 829c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(false){ } 8304d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 8314d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The kind of template we are parsing. 8324d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor enum { 8334d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are not parsing a template at all. 8344d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor NonTemplate = 0, 8354d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing a template declaration. 8364d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor Template, 8374d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit specialization. 8384d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitSpecialization, 8394d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit instantiation. 8404d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitInstantiation 8414d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } Kind; 8424d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 8434d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The template parameter lists, for template declarations 8444d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// and explicit specializations. 8454d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParameterLists *TemplateParams; 8464d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 84745f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// \brief The location of the 'extern' keyword, if any, for an explicit 84845f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// instantiation 84945f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation ExternLoc; 8501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8514d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The location of the 'template' keyword, for an explicit 8524d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// instantiation. 8534d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation TemplateLoc; 854c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor 855c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor /// \brief Whether the last template parameter list was empty. 856c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool LastParameterListWasEmpty; 8574d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor }; 8581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 859d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass); 86037b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void DeallocateParsedClasses(ParsingClass *Class); 86137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void PopParsingClass(); 86237b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor 863d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D, 864d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall const ParsedTemplateInfo &TemplateInfo); 86537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDeclarations(ParsingClass &Class); 86637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDefs(ParsingClass &Class); 86714b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeAndStoreUntil(tok::TokenKind T1, 86814b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis CachedTokens &Toks, 86914b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 87014b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeFinalToken = true) { 87114b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken); 87214b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis } 8731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 87437b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor CachedTokens &Toks, 87514b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 87637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor bool ConsumeFinalToken = true); 8774d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 8784cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.9: External Definitions. 88009a63c97b95eb4dc6fd6b2323929e8cf12af03ffDouglas Gregor DeclGroupPtrTy ParseExternalDeclaration(CXX0XAttributeList Attr, 88109a63c97b95eb4dc6fd6b2323929e8cf12af03ffDouglas Gregor ParsingDeclSpec *DS = 0); 882c82daefa3062721e98947e08193cd81b4e9df915Chris Lattner bool isDeclarationAfterDeclarator() const; 883004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); 884bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(AttributeList *Attr, 8855aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson AccessSpecifier AS = AS_none); 8863acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS, 8873acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AttributeList *Attr, 8883acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AccessSpecifier AS = AS_none); 8893acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian 890d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseFunctionDefinition(ParsingDeclarator &D, 89152591bf224b2c43e2b00e265bb8599a620081925Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseKNRParamDeclarations(Declarator &D); 893ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 894ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the simple-asm. 89560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0); 89660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAsmStringLiteral(); 8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8983536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Objective-C External Declarations 899d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtDirectives(); 900d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtClassDeclaration(SourceLocation atLoc); 901d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, 902dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff AttributeList *prefixAttrs = 0); 903d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseObjCClassInstanceVariables(Decl *interfaceDecl, 90483c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 90560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc); 906d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Decl *> &P, 90771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &PLocs, 9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool WarnOnDeclarations, 90971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, 910e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SourceLocation &EndProtoLoc); 911d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseObjCInterfaceDeclList(Decl *interfaceDecl, 912c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner tok::ObjCKeywordKind contextKey); 913d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtProtocolDeclaration(SourceLocation atLoc, 914b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *prefixAttrs = 0); 9151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 916d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ObjCImpDecl; 917d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall llvm::SmallVector<Decl *, 4> PendingObjCImpDecl; 9180416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 919d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtImplementationDeclaration(SourceLocation atLoc); 920d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtEndDeclaration(SourceRange atEnd); 921d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc); 922d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertySynthesize(SourceLocation atLoc); 923d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertyDynamic(SourceLocation atLoc); 9241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9252fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); 92634870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner // Definitions for Objective-c context sensitive keywords recognition. 92734870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner enum ObjCTypeQual { 92834870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, 92934870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_NumQuals 93034870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner }; 931a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; 9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 933335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian bool isTokIdentifier_in() const; 934d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 935b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, bool IsParameter); 936294494e1cce92043562b4680c613df7fd028c02eSteve Naroff void ParseObjCMethodRequirement(); 937d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodPrototype(Decl *classOrCat, 938c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); 939d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, 940d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *classDecl, 94100933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); 942d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl, 943d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl **Methods, unsigned NumMethods); 9441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 945d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDefinition(); 9461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.5: Expressions. 9496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 95060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpression(); 95160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseConstantExpression(); 9522f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl // Expr that doesn't include commas. 95360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAssignmentExpression(); 9542f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 95560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); 9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 95760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); 958adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman 95960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, 9606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor prec::Level MinPrec); 96160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 962f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAddressOfOperand, 9632ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman bool &NotCastExpr, 964b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType TypeOfCast); 96560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 9662ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman bool isAddressOfOperand = false, 967b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType TypeOfCast = ParsedType()); 9689c72c6088d591ace8503b842d39448c2040f3033John McCall 9699c72c6088d591ace8503b842d39448c2040f3033John McCall /// Returns true if the next token would start a postfix-expression 9709c72c6088d591ace8503b842d39448c2040f3033John McCall /// suffix. 9719c72c6088d591ace8503b842d39448c2040f3033John McCall bool isPostfixExpressionSuffixStart() { 9729c72c6088d591ace8503b842d39448c2040f3033John McCall tok::TokenKind K = Tok.getKind(); 9739c72c6088d591ace8503b842d39448c2040f3033John McCall return (K == tok::l_square || K == tok::l_paren || 9749c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::period || K == tok::arrow || 9759c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::plusplus || K == tok::minusminus); 9769c72c6088d591ace8503b842d39448c2040f3033John McCall } 9779c72c6088d591ace8503b842d39448c2040f3033John McCall 97860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParsePostfixExpressionSuffix(ExprResult LHS); 97960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseSizeofAlignofExpression(); 98060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBuiltinPrimaryExpression(); 9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExprAfterTypeofSizeofAlignof(const Token &OpTok, 9835ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis bool &isCastExpr, 984b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 9855ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis SourceRange &CastRange); 9860cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 987ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef llvm::SmallVector<Expr*, 20> ExprListTy; 988ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall typedef llvm::SmallVector<SourceLocation, 20> CommaLocsTy; 9890cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 9900cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis /// ParseExpressionList - Used for C/C++ (argument-)expression-list. 991ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall bool ParseExpressionList(llvm::SmallVectorImpl<Expr*> &Exprs, 992ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall llvm::SmallVectorImpl<SourceLocation> &CommaLocs, 993f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall void (Sema::*Completer)(Scope *S, 994f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Data, 995f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr **Args, 996f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall unsigned NumArgs) = 0, 997ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Expr *Data = 0); 998d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl 9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParenParseOption - Control what ParseParenExpression will parse. 10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ParenParseOption { 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SimpleExpr, // Only parse '(' expression ')' 10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundStmt, // Also allow '(' compound-statement ')' 10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}' 10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CastExpr // Also allow '(' type-name ')' <anything> 10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 100660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseParenExpression(ParenParseOption &ExprType, 10070350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis bool stopIfCastExpr, 1008b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType TypeOfCast, 1009b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 1010d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl SourceLocation &RParenLoc); 10111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, 1013b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 1014f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis SourceLocation LParenLoc, 1015f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis SourceLocation &RParenLoc); 10161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCompoundLiteralExpression(ParsedType Ty, 1018d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation LParenLoc, 1019d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation RParenLoc); 10201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseStringLiteralExpression(); 1022eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1023eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 1024eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // C++ Expressions 102560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); 10264bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis 10271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 1028b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1029b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor bool EnteringContext, 1030d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool *MayBePseudoDestructor = 0); 10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 5.2p1: C++ Casts 103460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXCasts(); 10355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1037c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // C++ 5.2p1: C++ Type Identification 103860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeid(); 1039c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 1040c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl //===--------------------------------------------------------------------===// 104101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // C++ : Microsoft __uuidof Expression 104201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult ParseCXXUuidof(); 104301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 104401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet //===--------------------------------------------------------------------===// 1045d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // C++ 5.2.4: C++ Pseudo-Destructor Expressions 104660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, 1047d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor tok::TokenKind OpKind, 1048d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CXXScopeSpec &SS, 1049b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType); 1050d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 1051d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor //===--------------------------------------------------------------------===// 10524cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 9.3.2: C++ 'this' pointer 105360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXThis(); 10544cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 10554cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 105650dd289f45738ed22b7583d52ed2525b927042ffChris Lattner // C++ 15: C++ Throw Expression 105760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseThrowExpression(); 1058ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc is filled with the location of the last token of the specification. 10597dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl bool ParseExceptionSpecification(SourceLocation &EndLoc, 1060b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall llvm::SmallVectorImpl<ParsedType> &Exns, 1061b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall llvm::SmallVectorImpl<SourceRange> &Ranges, 10627dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl bool &hasAnyExceptionSpec); 106350dd289f45738ed22b7583d52ed2525b927042ffChris Lattner 106450dd289f45738ed22b7583d52ed2525b927042ffChris Lattner //===--------------------------------------------------------------------===// 10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 2.13.5: C++ Boolean Literals 106660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXBoolLiteral(); 10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1069987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // C++ 5.2.3: Explicit type conversion (functional notation) 107060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); 1071987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 10726aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool isCXXSimpleTypeSpecifier() const; 10736aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 1074987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 1075987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// This should only be called when the current token is known to be part of 1076987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// simple-type-specifier. 1077987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); 1078987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 10792f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); 10802f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 1081987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 10824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // C++ 5.3.4 and 5.3.5: C++ new and delete 1083ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall bool ParseExpressionListOrTypeId(llvm::SmallVectorImpl<Expr*> &Exprs, 1084ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Declarator &D); 10854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDirectNewDeclarator(Declarator &D); 108660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); 108760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXDeleteExpression(bool UseGlobal, 108859232d35f5820e334b6c8b007ae8006f4390055dChris Lattner SourceLocation Start); 10894c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 10904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl //===--------------------------------------------------------------------===// 109199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor // C++ if/switch/while condition expression. 109260d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult, 1093586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, bool ConvertToBoolean); 109471b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 109571b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 109612e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor // C++ types 109712e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor 109812e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor //===--------------------------------------------------------------------===// 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7.8: Initialization. 11001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11010eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// ParseInitializer 11020eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// initializer: [C99 6.7.8] 11030eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// assignment-expression 11040eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// '{' ... 110560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializer() { 11060eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner if (Tok.isNot(tok::l_brace)) 110720df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ParseAssignmentExpression(); 11080eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner return ParseBraceInitializer(); 11090eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner } 111060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBraceInitializer(); 111160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializerWithPotentialDesignator(); 11121d922960e083906a586609ac6978678147250177Sebastian Redl 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1114296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // clang Expressions 11151d922960e083906a586609ac6978678147250177Sebastian Redl 111660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBlockLiteralExpression(); // ^{...} 1117296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff 1118296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff //===--------------------------------------------------------------------===// 11195508518a2702b00be3b15a26d772bde968972f54Anders Carlsson // Objective-C Expressions 112060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCAtExpression(SourceLocation AtLocation); 112160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCStringLiteral(SourceLocation AtLoc); 112260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); 112360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); 112460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); 11251b730e847ded503f2e615154035c083c4f94a067Douglas Gregor bool isSimpleObjCMessageExpression(); 112660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpression(); 112760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, 11282725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation SuperLoc, 1129b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, 11301d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr); 113160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAssignmentExprWithObjCMessageExprStart( 11322725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation LBracloc, SourceLocation SuperLoc, 1133b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, ExprArg ReceiverExpr); 11346aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr); 113561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 11365508518a2702b00be3b15a26d772bde968972f54Anders Carlsson //===--------------------------------------------------------------------===// 11375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.8: Statements and Blocks. 113861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 113960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseStatement() { 114061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl return ParseStatementOrDeclaration(true); 114161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 114260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseStatementOrDeclaration(bool OnlyStatement = false); 114360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseLabeledStatement(AttributeList *Attr); 114460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCaseStatement(AttributeList *Attr); 114560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseDefaultStatement(AttributeList *Attr); 114660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCompoundStatement(AttributeList *Attr, 1147bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool isStmtExpr = false); 114860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCompoundStatementBody(bool isStmtExpr = false); 114960d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseParenExprOrCondition(ExprResult &ExprResult, 1150d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *&DeclResult, 1151586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, 1152586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor bool ConvertToBoolean); 115360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseIfStatement(AttributeList *Attr); 115460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseSwitchStatement(AttributeList *Attr); 115560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseWhileStatement(AttributeList *Attr); 115660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseDoStatement(AttributeList *Attr); 115760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseForStatement(AttributeList *Attr); 115860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseGotoStatement(AttributeList *Attr); 115960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseContinueStatement(AttributeList *Attr); 116060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseBreakStatement(AttributeList *Attr); 116160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseReturnStatement(AttributeList *Attr); 116260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseAsmStatement(bool &msAsm); 116360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult FuzzyParseMicrosoftAsmStatement(); 1164ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<IdentifierInfo *> &Names, 1165ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVectorImpl<ExprTy *> &Constraints, 1166ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVectorImpl<ExprTy *> &Exprs); 1167a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1168a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1169a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // C++ 6: Statements and Blocks 1170a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 117160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXTryBlock(AttributeList *Attr); 117260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc); 117360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXCatchBlock(); 1174a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1175a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1176a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // Objective-C Statements 1177a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 117860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCAtStatement(SourceLocation atLoc); 117960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCTryStmt(SourceLocation atLoc); 118060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCThrowStmt(SourceLocation atLoc); 118160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); 1182b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7: Declarations. 118667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall 118767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// A context for parsing declaration specifiers. TODO: flesh this 118867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// out, there are other significant restrictions on specifiers than 118967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// would be best implemented in the parser. 119067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall enum DeclSpecContext { 119167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DSC_normal, // normal context 11920efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_class, // class context, enables 'friend' 11930efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_top_level // top-level/namespace declaration context 119467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall }; 11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1196bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseDeclaration(unsigned Context, SourceLocation &DeclEnd, 1197bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList Attr); 1198cd1477562e7cf03279850885583d615e1f631dd4Chris Lattner DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context, 1199bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 12005c5db553b5c256d0a6f55dde7325c1c829b88e8eChris Lattner AttributeList *Attr, 12015c5db553b5c256d0a6f55dde7325c1c829b88e8eChris Lattner bool RequireSemi); 120254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, 1203d8ac05753dc4506224d445ff98399c01da3136e5John McCall bool AllowFunctionDefinitions, 1204d8ac05753dc4506224d445ff98399c01da3136e5John McCall SourceLocation *DeclEnd = 0); 1205d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationAfterDeclarator(Declarator &D, 1206e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1207d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseFunctionStatementBody(Decl *Decl); 1208d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseFunctionTryBlock(Decl *Decl); 1209d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 1210f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, 12114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 1212e40c295d017a8f75a945fe9ed2aa9d8bb7a7341aChris Lattner AccessSpecifier AS); 12130efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); 12141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseDeclarationSpecifiers(DeclSpec &DS, 12154d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 121667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall AccessSpecifier AS = AS_none, 121767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DeclSpecContext DSC = DSC_normal); 12181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid, 12197a0ab5f387722c83e19c7133b46b16988eb19e45Chris Lattner const char *&PrevSpec, 1220fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID, 1221d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1222d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 12234d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseSpecifierQualifierList(DeclSpec &DS); 12251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1226d32b0225e29fcafb2b2b2a4b1c51dcb1518af9c6Douglas Gregor void ParseObjCTypeQualifierList(ObjCDeclSpec &DS, bool IsParameter); 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12284c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, 12299b9edd619a7e616d3287435cb5a3f9b1aea648e8Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), AccessSpecifier AS = AS_none); 1230d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl); 12315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, 1232d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 1233bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1234bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct FieldCallback { 1235d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall virtual Decl *invoke(FieldDeclarator &Field) = 0; 12366c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual ~FieldCallback() {} 12376c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall 12386c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall private: 12396c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual void _anchor(); 1240bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall }; 1241d0014540005f2a5ab837365db6bd40f479406758John McCall struct ObjCPropertyCallback; 1242bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1243bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback); 12441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1245eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isDeclarationSpecifier(); 1246eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isTypeSpecifierQualifier(); 12475f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff bool isTypeQualifier() const; 1248b3a4e432c90be98c6d918087750397e86d030368Chris Lattner 1249b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// isKnownToBeTypeSpecifier - Return true if we know that the specified token 1250b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// is definitely a type-specifier. Return false if it isn't part of a type 1251b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// specifier or if we're not sure. 1252b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool isKnownToBeTypeSpecifier(const Token &Tok) const; 12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isDeclarationStatement - Disambiguates between a declaration or an 12555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// expression statement, when parsing function bodies. 12565404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for declaration, false for expression. 12575404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isDeclarationStatement() { 12585404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis if (getLang().CPlusPlus) 12595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isCXXDeclarationStatement(); 12605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isDeclarationSpecifier(); 12615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 12625404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1263bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// isSimpleDeclaration - Disambiguates between a declaration or an 1264bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// expression, mainly used for the C 'clause-1' or the C++ 1265bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis // 'for-init-statement' part of a 'for' statement. 1266bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// Returns true for declaration, false for expression. 1267bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis bool isSimpleDeclaration() { 1268bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis if (getLang().CPlusPlus) 1269bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis return isCXXSimpleDeclaration(); 1270bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis return isDeclarationSpecifier(); 1271bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis } 1272bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis 12730efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief Starting with a scope specifier, identifier, or 12740efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id that refers to the current class, determine whether 12750efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// this is a constructor declarator. 12760efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor bool isConstructorDeclarator(); 12770efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 12788b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// \brief Specifies the context in which type-id/expression 12798b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// disambiguation will occur. 12808b642592a35167a3780074e78674e0bece87c40cDouglas Gregor enum TentativeCXXTypeIdContext { 12818b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdInParens, 12828b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdAsTemplateArgument 12838b642592a35167a3780074e78674e0bece87c40cDouglas Gregor }; 12848b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 12858b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 128678c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know 128778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// whether the parens contain an expression or a type-id. 128878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// Returns true for a type-id and false for an expression. 1289f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens(bool &isAmbiguous) { 129078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis if (getLang().CPlusPlus) 1291f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(TypeIdInParens, isAmbiguous); 1292f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis isAmbiguous = false; 129378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis return isTypeSpecifierQualifier(); 129478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis } 1295f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens() { 1296f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1297f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isTypeIdInParens(isAmbiguous); 1298f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 129978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 13005404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXDeclarationStatement - C++-specialized function that disambiguates 13015404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a declaration or an expression statement, when parsing function 13025404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// bodies. Returns true for declaration, false for expression. 13035404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXDeclarationStatement(); 13045404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 13055404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXSimpleDeclaration - C++-specialized function that disambiguates 13065404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a simple-declaration or an expression-statement. 13075404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 13085404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 13095404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns false if the statement is disambiguated as expression. 13105404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXSimpleDeclaration(); 13115404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 13125404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXFunctionDeclarator - Disambiguates between a function declarator or 13135404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// a constructor-style initializer, when parsing declaration statements. 13145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for function declarator and false for constructor-style 1315e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to 1316259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis /// indicate that the parens were disambiguated as function declarator. 13175404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 13185404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1319e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis bool isCXXFunctionDeclarator(bool warnIfAmbiguous); 13205404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1321a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// isCXXConditionDeclaration - Disambiguates between a declaration or an 1322a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// expression for a condition of a if/switch/while/for statement. 1323a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 1324a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1325a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis bool isCXXConditionDeclaration(); 1326a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis 1327f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); 1328f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context) { 1329f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1330f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(Context, isAmbiguous); 1331f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 133278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 1333b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult - Used as the result value for functions whose purpose is to 1334b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// disambiguate C++ constructs by "tentatively parsing" them. 1335b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// This is a class instead of a simple enum because the implicit enum-to-bool 1336b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// conversions may cause subtle bugs. 1337b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis class TPResult { 1338b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis enum Result { 1339b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_true, 1340b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_false, 1341b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_ambiguous, 1342b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_error 1343b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis }; 1344b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis Result Res; 1345b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult(Result result) : Res(result) {} 1346b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis public: 1347b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult True() { return TPR_true; } 1348b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult False() { return TPR_false; } 1349b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Ambiguous() { return TPR_ambiguous; } 1350b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Error() { return TPR_error; } 1351b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis 1352b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator==(const TPResult &RHS) const { return Res == RHS.Res; } 1353b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; } 1354b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis }; 1355b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis 1356b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a 1357b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// declaration specifier, TPResult::False() if it is not, 1358b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult::Ambiguous() if it could be either a decl-specifier or a 1359b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// function-style cast, and TPResult::Error() if a parsing error was 1360b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// encountered. 13615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Doesn't consume tokens. 1362b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult isCXXDeclarationSpecifier(); 13635404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 13645404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // "Tentative parsing" functions, used for disambiguation. If a parsing error 1365b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // is encountered they will return TPResult::Error(). 1366b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // Returning TPResult::True()/False() indicates that the ambiguity was 1367b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates 1368b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // that more tentative parsing is necessary for disambiguation. 13695404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // They all consume tokens, so backtracking should be used after calling them. 13705404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1371b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseDeclarationSpecifier(); 1372b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseSimpleDeclaration(); 1373b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseTypeofSpecifier(); 1374b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseInitDeclaratorList(); 137578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); 1376b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseParameterDeclarationClause(); 1377b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseFunctionDeclarator(); 1378b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseBracketDeclarator(); 13795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1380ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl TypeResult ParseTypeName(SourceRange *Range = 0); 138198eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump void ParseBlockId(); 1382ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 1383ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the attribute list. 1384bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList ParseCXX0XAttributes(SourceLocation *EndLoc = 0); 1385bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttributeList *ParseGNUAttributes(SourceLocation *EndLoc = 0); 1386290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0); 1387290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0); 138852fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik AttributeList *ParseBorlandTypeAttributes(AttributeList* CurrAttr = 0); 1389d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff void ParseTypeofSpecifier(DeclSpec &DS); 13906fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson void ParseDecltypeSpecifier(DeclSpec &DS); 1391bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 139260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXX0XAlignArgument(SourceLocation Start); 1393eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1394eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to 1395eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// enter a new C++ declarator scope and exit it when the function is 1396eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// finished. 1397eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis class DeclaratorScopeObj { 1398eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis Parser &P; 1399751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis CXXScopeSpec &SS; 1400f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis bool EnteredScope; 1401f7f3d0db754db0500b56d49ac19f795f13965912John McCall bool CreatedScope; 1402eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis public: 1403f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) 1404f7f3d0db754db0500b56d49ac19f795f13965912John McCall : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} 1405eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1406eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis void EnterDeclaratorScope() { 14072bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis assert(!EnteredScope && "Already entered the scope!"); 1408f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was not set!"); 1409f7f3d0db754db0500b56d49ac19f795f13965912John McCall 1410f7f3d0db754db0500b56d49ac19f795f13965912John McCall CreatedScope = true; 1411f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.EnterScope(0); // Not a decl scope. 1412f7f3d0db754db0500b56d49ac19f795f13965912John McCall 141323c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS)) 14143fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor EnteredScope = true; 1415eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1416eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1417eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis ~DeclaratorScopeObj() { 1418f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis if (EnteredScope) { 1419f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was cleared ?"); 142023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS); 1421f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis } 1422f7f3d0db754db0500b56d49ac19f795f13965912John McCall if (CreatedScope) 1423f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.ExitScope(); 1424eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1425eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis }; 14261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseDeclarator - Parse and verify a newly-initialized declarator. 14285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDeclarator(Declarator &D); 14294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl /// A function that parses a variant of direct-declarator. 14304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef void (Parser::*DirectDeclParseFunction)(Declarator&); 14314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDeclaratorInternal(Declarator &D, 14324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl DirectDeclParseFunction DirectDeclParser); 1433bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, 1434bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool CXX0XAttributesAllowed = true); 14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDirectDeclarator(Declarator &D); 14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseParenDeclarator(Declarator &D); 14377399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, 14387399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner AttributeList *AttrList = 0, 14397399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner bool RequiresArg = false); 144066d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc, 144183a944763b0948c608eb48f101ec10a1ae5da46aChris Lattner IdentifierInfo *FirstIdent, 144283a944763b0948c608eb48f101ec10a1ae5da46aChris Lattner SourceLocation FirstIdentLoc, 144366d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner Declarator &D); 14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseBracketDeclarator(Declarator &D); 14451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14468f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner //===--------------------------------------------------------------------===// 14478f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner // C++ 7: Declarations [dcl.dcl] 14481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1449bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool isCXX0XAttributeSpecifier(bool FullLookahead = false, 1450bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt tok::TokenKind *After = 0); 1451bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 1452d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd, 1453d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation InlineLoc = SourceLocation()); 1454d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context); 1455d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseUsingDirectiveOrDeclaration(unsigned Context, 1456d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 1457d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl CXX0XAttributeList Attrs); 1458d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseUsingDirective(unsigned Context, SourceLocation UsingLoc, 1459d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, AttributeList *Attr); 1460d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc, 1461d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 1462d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl AccessSpecifier AS = AS_none); 1463d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd); 1464d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc, 1465d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation AliasLoc, IdentifierInfo *Alias, 1466d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd); 14671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1468e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 1469e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 9: classes [class] and C structs/unions. 14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeResult ParseClassName(SourceLocation &EndLocation, 14719ab14541716928894821cf5d53d6b4c95ffdf3a3Jeffrey Yasskin CXXScopeSpec *SS = 0); 14724c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, 14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclSpec &DS, 14744d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1475d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl AccessSpecifier AS = AS_none, 1476d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 14774cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType, 1478d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 147937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseCXXClassMemberDeclaration(AccessSpecifier AS, 1480c9068d7dd94d439cec66c421115d15303e481025John McCall const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1481c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject *DiagsFromTParams = 0); 1482d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseConstructorInitializer(Decl *ConstructorDecl); 1483d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall MemInitResult ParseMemInitializer(Decl *ConstructorDecl); 1484d33133cdc1af466f9c276249b2621be03867888bEli Friedman void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, 1485d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ThisDecl); 1486e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1487e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 1488e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 10: Derived classes [class.derived] 1489d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseBaseClause(Decl *ClassDecl); 1490d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall BaseResult ParseBaseSpecifier(Decl *ClassDecl); 14911b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor AccessSpecifier getAccessSpecifierIfPresent() const; 14921cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor 14933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 14943f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Name, 14953f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation NameLoc, 14963f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool EnteringContext, 1497b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1498d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor UnqualifiedId &Id, 14990278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor bool AssumeTemplateId, 15000278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor SourceLocation TemplateKWLoc); 1501ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, 1502b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1503ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &Result); 15043f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, 150502a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowDestructorName, 150602a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowConstructorName, 1507b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 15083f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &Result); 15093f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 15101cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor //===--------------------------------------------------------------------===// 1511adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14: Templates [temp] 1512c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 1513adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14.1: Template Parameters [temp.param] 1514d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationStartingWithTemplate(unsigned Context, 15154d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation &DeclEnd, 15164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AccessSpecifier AS = AS_none); 1517d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context, 151897144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation &DeclEnd, 15194d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AccessSpecifier AS); 1520d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseSingleDeclarationAfterTemplate( 15211426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor unsigned Context, 15224d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 1523c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject &DiagsFromParams, 15241426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor SourceLocation &DeclEnd, 15251426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor AccessSpecifier AS=AS_none); 15261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseTemplateParameters(unsigned Depth, 15271f58816e6589ef15d1509c6c99bb8fabf2a4cda9John McCall llvm::SmallVectorImpl<Decl*> &TemplateParams, 15281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation &LAngleLoc, 1529c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor SourceLocation &RAngleLoc); 1530c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor bool ParseTemplateParameterList(unsigned Depth, 15311f58816e6589ef15d1509c6c99bb8fabf2a4cda9John McCall llvm::SmallVectorImpl<Decl*> &TemplateParams); 153298440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor bool isStartOfTemplateTypeParameter(); 1533d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateParameter(unsigned Depth, unsigned Position); 1534d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTypeParameter(unsigned Depth, unsigned Position); 1535d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); 1536d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); 1537d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor // C++ 14.3: Template arguments [temp.arg] 1538314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor typedef llvm::SmallVector<ParsedTemplateArgument, 16> TemplateArgList; 1539cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 15407532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor bool ParseTemplateIdAfterTemplateName(TemplateTy Template, 15411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateNameLoc, 1542cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor const CXXScopeSpec *SS, 1543cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor bool ConsumeLastToken, 1544cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &LAngleLoc, 1545cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateArgList &TemplateArgs, 1546cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &RAngleLoc); 1547cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 1548c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, 154939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor const CXXScopeSpec *SS, 1550ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &TemplateName, 155139a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor SourceLocation TemplateKWLoc = SourceLocation(), 155239a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor bool AllowTypeAnnotation = true); 155331a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor void AnnotateTemplateIdTokenAsType(const CXXScopeSpec *SS = 0); 1554d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor bool IsTemplateArgumentList(unsigned Skip = 0); 1555314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); 1556788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor ParsedTemplateArgument ParseTemplateTemplateArgument(); 1557314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor ParsedTemplateArgument ParseTemplateArgument(); 1558d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseExplicitInstantiation(SourceLocation ExternLoc, 1559d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SourceLocation TemplateLoc, 1560d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SourceLocation &DeclEnd); 156164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 156264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl //===--------------------------------------------------------------------===// 156364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // GNU G++: Type Traits [Type-Traits.html in the GCC manual] 156460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseUnaryTypeTrait(); 1565f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor 1566f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor //===--------------------------------------------------------------------===// 1567f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor // Preprocessor code-completion pass-through 1568f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor virtual void CodeCompleteDirective(bool InConditional); 1569f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor virtual void CodeCompleteInConditionalExclusion(); 15701fbb447e9d43c2c676e94081fbfee7eb6cbe933bDouglas Gregor virtual void CodeCompleteMacroName(bool IsDefinition); 1571f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor virtual void CodeCompletePreprocessorExpression(); 1572f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro, 1573f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor MacroInfo *MacroInfo, 1574f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor unsigned ArgumentIndex); 157555817afdf9d453a443262a733f6caf6692dca118Douglas Gregor virtual void CodeCompleteNaturalLanguage(); 15765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 15795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1581