Parser.h revision aa8b0d19244a6e7e8e5798fcc6aef003c274d3e0
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" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Parse/Action.h" 20eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis#include "clang/Parse/DeclSpec.h" 214726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek#include "llvm/ADT/OwningPtr.h" 224cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis#include <stack> 231100258c19dd8967ba078c0bc81fc06cea9d033fChris Lattner#include <list> 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 26fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar class AttributeList; 27bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt struct CXX0XAttributeList; 28fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar class PragmaHandler; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Scope; 303cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner class DiagnosticBuilder; 310102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner class Parser; 324726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek class PragmaUnusedHandler; 3308d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner class ColonProtectionRAIIObject; 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 350102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// PrettyStackTraceParserEntry - If a crash happens while the parser is active, 360102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// an entry is printed for it. 370102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerclass PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry { 380102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Parser &P; 390102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerpublic: 400102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner PrettyStackTraceParserEntry(const Parser &p) : P(p) {} 410102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner virtual void print(llvm::raw_ostream &OS) const; 420102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner}; 431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 446aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// PrecedenceLevels - These are precedences for the binary/ternary 456aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// operators in the C99 grammar. These have been named to relate 466aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// with the C99 grammar productions. Low precedences numbers bind 476aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// more weakly than high numbers. 486aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregornamespace prec { 496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor enum Level { 506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Unknown = 0, // Not binary operator. 516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Comma = 1, // , 526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Assignment = 2, // =, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |= 536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Conditional = 3, // ? 546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor LogicalOr = 4, // || 556aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor LogicalAnd = 5, // && 566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor InclusiveOr = 6, // | 576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ExclusiveOr = 7, // ^ 586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor And = 8, // & 596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Equality = 9, // ==, != 606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Relational = 10, // >=, <=, >, < 616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Shift = 11, // <<, >> 626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Additive = 12, // -, + 636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Multiplicative = 13, // *, /, % 646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor PointerToMember = 14 // .*, ->* 656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor }; 666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Parser - This implements a parser for the C family of languages. After 695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// parsing units of the grammar, productions are invoked to handle whatever has 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// been read. 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Parser { 734726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek friend class PragmaUnusedHandler; 7408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner friend class ColonProtectionRAIIObject; 7536d36806f1972f7ec1d2a3f59155187278c56508Argyrios Kyrtzidis friend class ParenBraceBracketBalancer; 760102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner PrettyStackTraceParserEntry CrashInfo; 771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Preprocessor &PP; 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8097d0205d16fef2a783e785459b5f30f6a9dfbcb9Eric Christopher /// Tok - The current token we are peeking ahead. All parsing methods assume 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that this is valid. 82d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner Token Tok; 831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 844b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // PrevTokLocation - The location of the token we previously 854b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // consumed. This token is used for diagnostics where we expected to 864b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // see a token following another token (e.g., the ';' at the end of 874b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // a statement). 884b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceLocation PrevTokLocation; 894b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned short ParenCount, BracketCount, BraceCount; 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Actions - These are the callbacks we invoke as we parse various constructs 9387c300738174924453648c3b2d6f366c8284fac4Douglas Gregor /// in the file. 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Action &Actions; 951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diagnostic &Diags; 971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 989e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner /// ScopeCache - Cache scopes to reduce malloc traffic. 999e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner enum { ScopeCacheSize = 16 }; 1009e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner unsigned NumCachedScopes; 1019e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner Scope *ScopeCache[ScopeCacheSize]; 102662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 103662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// Ident_super - IdentifierInfo for "super", to support fast 104662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// comparison. 105662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar IdentifierInfo *Ident_super; 10682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// Ident_vector and Ident_pixel - cached IdentifierInfo's for 10782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// "vector" and "pixel" fast comparison. Only present if 10882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// AltiVec enabled. 10982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_vector; 11082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_pixel; 111662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 112cbb98edd530787c2ac019e437e7c599df8004ba7Daniel Dunbar llvm::OwningPtr<PragmaHandler> AlignHandler; 113aa8b0d19244a6e7e8e5798fcc6aef003c274d3e0Eli Friedman llvm::OwningPtr<PragmaHandler> GCCVisibilityHandler; 114861800c676004eabed5927f0552620d06c80a40aDaniel Dunbar llvm::OwningPtr<PragmaHandler> OptionsHandler; 1154726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> PackHandler; 1164726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> UnusedHandler; 1179991479ad5dde617168cc1e4b18425cdbbfd9fa9Eli Friedman llvm::OwningPtr<PragmaHandler> WeakHandler; 1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// Whether the '>' token acts as an operator or not. This will be 12055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// true except when we are parsing an expression within a C++ 12155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// template argument list, where the '>' closes the template 12255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// argument list. 12355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor bool GreaterThanIsOperator; 12408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner 12508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonIsSacred - When this is false, we aggressively try to recover from 12608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not 12708d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// safe in case statements and a few other things. This is managed by the 12808d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonProtectionRAIIObject RAII object. 12908d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner bool ColonIsSacred; 13055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 131c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor /// The "depth" of the template parameters currently being parsed. 132c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor unsigned TemplateParameterDepth; 1331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Parser(Preprocessor &PP, Action &Actions); 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Parser(); 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const LangOptions &getLang() const { return PP.getLangOptions(); } 139444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } 1400102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner Preprocessor &getPreprocessor() const { return PP; } 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Action &getActions() const { return Actions; } 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1430102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Token &getCurToken() const { return Tok; } 14423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Scope *getCurScope() const { return Actions.getCurScope(); } 14523c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Type forwarding. All of these are statically 'void*', but they may all be 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // different actual classes based on the actions in place. 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef Action::ExprTy ExprTy; 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef Action::StmtTy StmtTy; 150b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner typedef Action::DeclPtrTy DeclPtrTy; 151682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner typedef Action::DeclGroupPtrTy DeclGroupPtrTy; 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef Action::TypeTy TypeTy; 153f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor typedef Action::BaseTy BaseTy; 1547ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor typedef Action::MemInitTy MemInitTy; 155eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis typedef Action::CXXScopeTy CXXScopeTy; 156c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor typedef Action::TemplateParamsTy TemplateParamsTy; 1577532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor typedef Action::TemplateTy TemplateTy; 1587ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 159c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor typedef llvm::SmallVector<TemplateParamsTy *, 4> TemplateParameterLists; 160c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 161d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::ExprResult ExprResult; 162d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::StmtResult StmtResult; 163d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::BaseResult BaseResult; 164d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::MemInitResult MemInitResult; 165809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor typedef Action::TypeResult TypeResult; 16615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 16715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl typedef Action::OwningExprResult OwningExprResult; 16815faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl typedef Action::OwningStmtResult OwningStmtResult; 16915faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 1701d922960e083906a586609ac6978678147250177Sebastian Redl typedef Action::ExprArg ExprArg; 171a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl typedef Action::MultiStmtArg MultiStmtArg; 172a99fad8ff134273fe85f2970c7d89133d1218900Anders Carlsson typedef Action::FullExprArg FullExprArg; 1731d922960e083906a586609ac6978678147250177Sebastian Redl 17461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl /// Adorns a ExprResult with Actions to make it an OwningExprResult 17561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningExprResult Owned(ExprResult res) { 17661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl return OwningExprResult(Actions, res); 17761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 17861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl /// Adorns a StmtResult with Actions to make it an OwningStmtResult 17961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult Owned(StmtResult res) { 18061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl return OwningStmtResult(Actions, res); 18161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 18261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 18361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningExprResult ExprError() { return OwningExprResult(Actions, true); } 18461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult StmtError() { return OwningStmtResult(Actions, true); } 185d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor 1862f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); } 1872f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningStmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); } 18861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1895ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis OwningExprResult ExprEmpty() { return OwningExprResult(Actions, false); } 1905ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Parsing methods. 1921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseTranslationUnit - All in one method that initializes parses, and 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// shuts down the parser. 1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseTranslationUnit(); 1961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Initialize - Warm up the parser. 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Initialize(); 2001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if 2021f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff /// the EOF was encountered. 203682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner bool ParseTopLevelDecl(DeclGroupPtrTy &Result); 2041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2053fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian DeclGroupPtrTy FinishPendingObjCActions(); 20663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Low-Level token peeking and consumption methods. 2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 2111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenParen - Return true if the cur token is '(' or ')'. 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenParen() const { 2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren; 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBracket - Return true if the cur token is '[' or ']'. 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBracket() const { 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square; 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBrace - Return true if the cur token is '{' or '}'. 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBrace() const { 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace; 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenStringLiteral - True if this token is a string-literal. 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenStringLiteral() const { 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::string_literal || 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Tok.getKind() == tok::wide_string_literal; 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 231eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeToken - Consume the current 'peek token' and lex the next one. 233d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu /// This does not work with all kinds of tokens: strings and specific other 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tokens must be consumed with custom methods below. This returns the 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// location of the consumed token. 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeToken() { 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer !isTokenBrace() && 2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should consume special tokens with Consume*Token"); 240dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor if (Tok.is(tok::code_completion)) { 241dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor CodeCompletionRecovery(); 242dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor return ConsumeCodeCompletionToken(); 243dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor } 244dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 2454b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2474b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeAnyToken - Dispatch to the right Consume* method based on the 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// current token type. This should only be used in cases where the type of 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the token really isn't known, e.g. in error recovery. 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeAnyToken() { 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isTokenParen()) 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeParen(); 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBracket()) 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBracket(); 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBrace()) 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBrace(); 260d62701bc5321049353017e9abf1963edd57646aaSteve Naroff else if (isTokenStringLiteral()) 261d62701bc5321049353017e9abf1963edd57646aaSteve Naroff return ConsumeStringToken(); 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeToken(); 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeParen - This consume method keeps the paren count up-to-date. 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeParen() { 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenParen() && "wrong consume method"); 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_paren) 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++ParenCount; 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (ParenCount) 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --ParenCount; // Don't let unbalanced )'s drive the count negative. 2744b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2764b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBracket - This consume method keeps the bracket count up-to-date. 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBracket() { 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBracket() && "wrong consume method"); 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_square) 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BracketCount; 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BracketCount) 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BracketCount; // Don't let unbalanced ]'s drive the count negative. 2871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2884b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2904b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBrace - This consume method keeps the brace count up-to-date. 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBrace() { 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBrace() && "wrong consume method"); 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_brace) 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BraceCount; 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BraceCount) 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BraceCount; // Don't let unbalanced }'s drive the count negative. 3011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3024b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3044b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeStringToken - Consume the current 'peek token', lexing a new one 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and returning the token kind. This method is specific to strings, as it 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// handles string literal concatenation, as per C99 5.1.1.2, translation 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// phase #6. 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeStringToken() { 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenStringLiteral() && 3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should only consume string literals with this method"); 3144b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3164b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 319dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// \brief Consume the current code-completion token. 320dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// 321dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// This routine should be called to consume the code-completion token once 322dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// a code-completion action has already been invoked. 323dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor SourceLocation ConsumeCodeCompletionToken() { 324dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor assert(Tok.is(tok::code_completion)); 325dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PrevTokLocation = Tok.getLocation(); 326dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PP.Lex(Tok); 327dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor return PrevTokLocation; 328dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor } 329dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 330dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor ///\ brief When we are consuming a code-completion token within having 331dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// matched specific position in the grammar, provide code-completion results 332dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// based on context. 333dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor void CodeCompletionRecovery(); 334dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 3356b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// GetLookAheadToken - This peeks ahead N tokens and returns that token 3366b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1) 3376b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// returns the token after Tok, etc. 3386b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 3396b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// Note that this differs from the Preprocessor's LookAhead method, because 3406b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// the Parser always has one token lexed that the preprocessor doesn't. 3416b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 34203db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis const Token &GetLookAheadToken(unsigned N) { 3436b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (N == 0 || Tok.is(tok::eof)) return Tok; 3446b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return PP.LookAhead(N-1); 3456b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } 346f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis 347f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// NextToken - This peeks ahead one token and returns it without 348f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// consuming it. 349f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis const Token &NextToken() { 35003db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis return PP.LookAhead(0); 351f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis } 3525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 353eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// TryAnnotateTypeOrScopeToken - If the current token position is on a 354eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// typename (possibly qualified in C++) or a C++ scope specifier not followed 355eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens 356eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// with a single annotation token representing the typename or C++ scope 357eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// respectively. 358eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// This simplifies handling of C++ scope specifiers and allows efficient 359eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// backtracking without the need to re-parse and resolve nested-names and 360eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// typenames. 36144802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// It will mainly be called when we expect to treat identifiers as typenames 36244802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// (if they are typenames). For example, in C we do not expect identifiers 36344802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// inside expressions to be treated as typenames so it will not be called 36444802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// for expressions in C. 365a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner /// 366a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner /// This returns true if the token was annotated. 367495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false); 368eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 3699ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but 3709ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// only annotates C++ scope specifiers. This returns true if there 3719ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// was an unrecoverable error. 372495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateCXXScopeToken(bool EnteringContext = false); 373eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 37482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens, 37582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// replacing them with the non-context-sensitive keywords. This returns 37682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// true if the token was replaced. 37782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc, 378b3a4e432c90be98c6d918087750397e86d030368Chris Lattner const char *&PrevSpec, unsigned &DiagID, 379b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool &isInvalid) { 3801b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner if (!getLang().AltiVec || 3811b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner (Tok.getIdentifierInfo() != Ident_vector && 3821b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner Tok.getIdentifierInfo() != Ident_pixel)) 3831b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return false; 3841b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 3851b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); 38682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 38782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 38882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector 38982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// identifier token, replacing it with the non-context-sensitive __vector. 39082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// This returns true if the token was replaced. 39182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecVectorToken() { 392b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (!getLang().AltiVec || 393b3a4e432c90be98c6d918087750397e86d030368Chris Lattner Tok.getIdentifierInfo() != Ident_vector) return false; 3941b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecVectorTokenOutOfLine(); 39582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 3961b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 3971b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecVectorTokenOutOfLine(); 3981b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, 3991b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner const char *&PrevSpec, unsigned &DiagID, 4001b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool &isInvalid); 4011b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 4025404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TentativeParsingAction - An object that is used as a kind of "tentative 4035404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// parsing transaction". It gets instantiated to mark the token position and 4045404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// after the token consumption is done, Commit() or Revert() is called to 4055404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// either "commit the consumed tokens" or revert to the previously marked 4065404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// token position. Example: 4075404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 408314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor /// TentativeParsingAction TPA(*this); 4095404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// ConsumeToken(); 4105404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// .... 4115404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TPA.Revert(); 4125404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 4135404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis class TentativeParsingAction { 4145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Parser &P; 4155404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Token PrevTok; 4165404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isActive; 4175404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 4185404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis public: 4195404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis explicit TentativeParsingAction(Parser& p) : P(p) { 4205404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis PrevTok = P.Tok; 4215404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.EnableBacktrackAtThisPos(); 4225404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = true; 4235404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4245404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Commit() { 4255404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 4265404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.CommitBacktrackedTokens(); 4275404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 4285404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4295404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Revert() { 4305404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 4315404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.Backtrack(); 4325404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.Tok = PrevTok; 4335404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 4345404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4355404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis ~TentativeParsingAction() { 4365404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(!isActive && "Forgot to call Commit or Revert!"); 4375404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 4385404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis }; 4391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'), 4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this helper function matches and consumes the specified RHS token if 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// present. If not present, it emits the specified diagnostic indicating 4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that the parser failed to match the RHS of the token at LHSLoc. LHSName 4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// should be the name of the unmatched LHS token. This returns the location 4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the consumed token. 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MatchRHSPunctuation(tok::TokenKind RHSTok, 4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation LHSLoc); 4491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// input. If so, it is consumed and false is returned. 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If the input is malformed, this emits the specified diagnostic. Next, if 4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// returned. 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag, 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *DiagMsg = "", 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind SkipToTok = tok::unknown); 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Scope manipulation 4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4638935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// ParseScope - Introduces a new scope for parsing. The kind of 4648935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// scope is determined by ScopeFlags. Objects of this type should 4658935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// be created on the stack to coincide with the position where the 4668935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// parser enters the new scope, and this object's constructor will 4678935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// create that new scope. Similarly, once the object is destroyed 4688935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// the parser will exit the scope. 4698935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor class ParseScope { 4708935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Parser *Self; 4718935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope(const ParseScope&); // do not implement 4728935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope& operator=(const ParseScope&); // do not implement 4738935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 4748935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor public: 4758935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ParseScope - Construct a new object to manage a scope in the 4768935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // parser Self where the new Scope is created with the flags 4778935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ScopeFlags, but only when ManageScope is true (the default). If 4788935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ManageScope is false, this object does nothing. 4791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true) 4808935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor : Self(Self) { 4818935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (ManageScope) 4828935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->EnterScope(ScopeFlags); 4838935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor else 4848935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor this->Self = 0; 4858935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4868935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 4878935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // Exit - Exit the scope associated with this object now, rather 4888935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // than waiting until the object is destroyed. 4898935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor void Exit() { 4908935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (Self) { 4918935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->ExitScope(); 4928935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self = 0; 4938935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4948935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4958935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 4968935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ~ParseScope() { 4978935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Exit(); 4988935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4998935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor }; 5008935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterScope - Start a new scope. 5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterScope(unsigned ScopeFlags); 5031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExitScope - Pop a scope off the scope stack. 5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ExitScope(); 5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Diagnostic Emission and Error recovery. 50915faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 5106aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorpublic: 5113cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 5123cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); 51315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 5146aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorprivate: 5151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SuggestParentheses(SourceLocation Loc, unsigned DK, 5164b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceRange ParenRange); 5174b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 5185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipUntil - Read tokens until we get to the specified token, then consume 51982c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff /// it (unless DontConsume is true). Because we cannot guarantee that the 5205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// token will ever occur, this skips to the next token, or to some likely 5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' 5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// character. 5231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If SkipUntil finds the specified token, it returns true, otherwise it 5251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returns false. 5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true, 5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool DontConsume = false) { 5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SkipUntil(&T, 1, StopAtSemi, DontConsume); 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true, 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool DontConsume = false) { 5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind TokArray[] = {T1, T2}; 5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SkipUntil(TokArray, 2, StopAtSemi, DontConsume); 5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, 5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool StopAtSemi = true, bool DontConsume = false); 5377ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 5394cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Lexing and parsing of C++ inline methods. 5404cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 5414cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis struct LexedMethod { 542b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner Action::DeclPtrTy D; 54372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens Toks; 544d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 545d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 546d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 547d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 548d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 549d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 550d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor explicit LexedMethod(Action::DeclPtrTy MD) : D(MD), TemplateScope(false) {} 5514cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis }; 5524cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 55372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedDefaultArgument - Keeps track of a parameter that may 55472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument that cannot be parsed yet because it 55572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// occurs within a member function declaration inside the class 55672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// (C++ [class.mem]p2). 55772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedDefaultArgument { 5581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit LateParsedDefaultArgument(Action::DeclPtrTy P, 55972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks = 0) 56072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor : Param(P), Toks(Toks) { } 56172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 56272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Param - The parameter declaration for this parameter. 563b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner Action::DeclPtrTy Param; 56472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 56572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Toks - The sequence of tokens that comprises the default 56672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument expression, not including the '=' or the terminating 56772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// ')' or ','. This will be NULL for parameters that have no 56872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// default argument. 56972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks; 57072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDeclaration - A method declaration inside a class that 57372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// contains at least one entity whose parsing needs to be delayed 57472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// until the class itself is completely-defined, such as a default 57572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument (C++ [class.mem]p2). 57672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedMethodDeclaration { 5771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit LateParsedMethodDeclaration(Action::DeclPtrTy M) 578d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor : Method(M), TemplateScope(false) { } 57972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 58072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Method - The method declaration. 581b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner Action::DeclPtrTy Method; 58272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 583d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 584d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 585d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 586d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 5871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// DefaultArgs - Contains the parameters of the function and 58972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// their default arguments. At least one of the parameters will 59072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument, but all of the parameters of the 59172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// method will be stored so that they can be reintroduced into 5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// scope at the appropriate times. 59372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor llvm::SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; 59472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 59572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 59672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDecls - During parsing of a top (non-nested) C++ 59772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// class, its method declarations that contain parts that won't be 59872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// parsed until after the definiton is completed (C++ [class.mem]p2), 59972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// the method declarations will be stored here with the tokens that 60072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// will be parsed to create those entities. 60172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor typedef std::list<LateParsedMethodDeclaration> LateParsedMethodDecls; 60272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 6034cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// LexedMethodsForTopClass - During parsing of a top (non-nested) C++ class, 6044cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// its inline method definitions and the inline method definitions of its 6054cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// nested classes are lexed and stored here. 60672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor typedef std::list<LexedMethod> LexedMethodsForTopClass; 60772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 6086569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Representation of a class that has been parsed, including 6096569d68745c8213709740337d2be52b031384f58Douglas Gregor /// any member function declarations or definitions that need to be 6106569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed after the corresponding top-level class is complete. 6116569d68745c8213709740337d2be52b031384f58Douglas Gregor struct ParsingClass { 6121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass) 6131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : TopLevelClass(TopLevelClass), TemplateScope(false), 6146569d68745c8213709740337d2be52b031384f58Douglas Gregor TagOrTemplate(TagOrTemplate) { } 6156569d68745c8213709740337d2be52b031384f58Douglas Gregor 6166569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this is a "top-level" class, meaning that it is 6176569d68745c8213709740337d2be52b031384f58Douglas Gregor /// not nested within another class. 6186569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TopLevelClass : 1; 6196569d68745c8213709740337d2be52b031384f58Douglas Gregor 6206569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this class had an associated template 6216569d68745c8213709740337d2be52b031384f58Douglas Gregor /// scope. When true, TagOrTemplate is a template declaration; 6226569d68745c8213709740337d2be52b031384f58Douglas Gregor /// othewise, it is a tag declaration. 6236569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TemplateScope : 1; 6246569d68745c8213709740337d2be52b031384f58Douglas Gregor 6256569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The class or class template whose definition we are parsing. 6266569d68745c8213709740337d2be52b031384f58Douglas Gregor DeclPtrTy TagOrTemplate; 62772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 62872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// MethodDecls - Method declarations that contain pieces whose 62972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// parsing will be delayed until the class is fully defined. 63072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor LateParsedMethodDecls MethodDecls; 63172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 63272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// MethodDefs - Methods whose definitions will be parsed once the 63372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// class has been fully defined. 63472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor LexedMethodsForTopClass MethodDefs; 6356569d68745c8213709740337d2be52b031384f58Douglas Gregor 6366569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Nested classes inside this class. 6376569d68745c8213709740337d2be52b031384f58Douglas Gregor llvm::SmallVector<ParsingClass*, 4> NestedClasses; 63872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 6394cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 6406569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The stack of classes that is currently being 6416569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed. Nested and local classes will be pushed onto this stack 6426569d68745c8213709740337d2be52b031384f58Douglas Gregor /// when they are parsed, and removed afterward. 6436569d68745c8213709740337d2be52b031384f58Douglas Gregor std::stack<ParsingClass *> ClassStack; 6444cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 6456569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingClass &getCurrentClass() { 6466569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "No lexed method stacks!"); 6476569d68745c8213709740337d2be52b031384f58Douglas Gregor return *ClassStack.top(); 6484cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 6494cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 65054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// \brief RAII object used to inform the actions that we're 65154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// currently parsing a declaration. This is active when parsing a 65254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// variable's initializer, but not when parsing the body of a 65354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// class or function definition. 65454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclRAIIObject { 65554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Action &Actions; 65654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Action::ParsingDeclStackState State; 65754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall bool Popped; 658c9068d7dd94d439cec66c421115d15303e481025John McCall 65954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 66054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) { 66154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 66254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 66354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 664c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *Other) 665c9068d7dd94d439cec66c421115d15303e481025John McCall : Actions(P.Actions) { 666c9068d7dd94d439cec66c421115d15303e481025John McCall if (Other) steal(*Other); 667c9068d7dd94d439cec66c421115d15303e481025John McCall else push(); 668c9068d7dd94d439cec66c421115d15303e481025John McCall } 669c9068d7dd94d439cec66c421115d15303e481025John McCall 670c9068d7dd94d439cec66c421115d15303e481025John McCall /// Creates a RAII object which steals the state from a different 671c9068d7dd94d439cec66c421115d15303e481025John McCall /// object instead of pushing. 672c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject(ParsingDeclRAIIObject &Other) 673c9068d7dd94d439cec66c421115d15303e481025John McCall : Actions(Other.Actions) { 674c9068d7dd94d439cec66c421115d15303e481025John McCall steal(Other); 675c9068d7dd94d439cec66c421115d15303e481025John McCall } 676c9068d7dd94d439cec66c421115d15303e481025John McCall 67754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ~ParsingDeclRAIIObject() { 67854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 67954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 68054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 68154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Resets the RAII object for a new declaration. 68254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void reset() { 68354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 68454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 68554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 68654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 68754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Signals that the context was completed without an appropriate 68854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// declaration being parsed. 68954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 69054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall pop(DeclPtrTy()); 69154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 69254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 69354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void complete(DeclPtrTy D) { 69454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall assert(!Popped && "ParsingDeclaration has already been popped!"); 69554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall pop(D); 69654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 69754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 69854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall private: 699c9068d7dd94d439cec66c421115d15303e481025John McCall void steal(ParsingDeclRAIIObject &Other) { 700c9068d7dd94d439cec66c421115d15303e481025John McCall State = Other.State; 701c9068d7dd94d439cec66c421115d15303e481025John McCall Popped = Other.Popped; 702c9068d7dd94d439cec66c421115d15303e481025John McCall Other.Popped = true; 703c9068d7dd94d439cec66c421115d15303e481025John McCall } 704c9068d7dd94d439cec66c421115d15303e481025John McCall 70554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void push() { 70654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall State = Actions.PushParsingDeclaration(); 70754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = false; 70854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 70954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 71054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void pop(DeclPtrTy D) { 71154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall if (!Popped) { 71254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Actions.PopParsingDeclaration(State, D); 71354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = true; 71454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 71554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 71654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 71754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 71854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a DeclSpec. 71954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclSpec : public DeclSpec { 72054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 72154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 72254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 723c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec(Parser &P) : ParsingRAII(P) {} 724c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec(ParsingDeclRAIIObject &RAII) : ParsingRAII(RAII) {} 725c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII) 726c9068d7dd94d439cec66c421115d15303e481025John McCall : ParsingRAII(P, RAII) {} 72754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 72854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void complete(DeclPtrTy D) { 72954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 73054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 73154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 73254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 73354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.abort(); 73454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 73554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 73654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 73754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a declarator. 73854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclarator : public Declarator { 73954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 74054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 74154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 74254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C) 74354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall : Declarator(DS, C), ParsingRAII(P) { 74454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 74554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 74654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall const ParsingDeclSpec &getDeclSpec() const { 74754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec()); 74854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 74954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 75054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclSpec &getMutableDeclSpec() const { 75154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return const_cast<ParsingDeclSpec&>(getDeclSpec()); 75254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 75354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 75454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void clear() { 75554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Declarator::clear(); 75654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.reset(); 75754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 75854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 75954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void complete(DeclPtrTy D) { 76054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 76154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 76254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 76354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 7641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief RAII object used to 7656569d68745c8213709740337d2be52b031384f58Douglas Gregor class ParsingClassDefinition { 7666569d68745c8213709740337d2be52b031384f58Douglas Gregor Parser &P; 7676569d68745c8213709740337d2be52b031384f58Douglas Gregor bool Popped; 7686569d68745c8213709740337d2be52b031384f58Douglas Gregor 7696569d68745c8213709740337d2be52b031384f58Douglas Gregor public: 7701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsingClassDefinition(Parser &P, DeclPtrTy TagOrTemplate, bool TopLevelClass) 7711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : P(P), Popped(false) { 7726569d68745c8213709740337d2be52b031384f58Douglas Gregor P.PushParsingClass(TagOrTemplate, TopLevelClass); 7736569d68745c8213709740337d2be52b031384f58Douglas Gregor } 7746569d68745c8213709740337d2be52b031384f58Douglas Gregor 7756569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Pop this class of the stack. 7761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void Pop() { 7776569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!Popped && "Nested class has already been popped"); 7786569d68745c8213709740337d2be52b031384f58Douglas Gregor Popped = true; 7796569d68745c8213709740337d2be52b031384f58Douglas Gregor P.PopParsingClass(); 7806569d68745c8213709740337d2be52b031384f58Douglas Gregor } 7816569d68745c8213709740337d2be52b031384f58Douglas Gregor 7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ~ParsingClassDefinition() { 7836569d68745c8213709740337d2be52b031384f58Douglas Gregor if (!Popped) 7841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump P.PopParsingClass(); 7856569d68745c8213709740337d2be52b031384f58Douglas Gregor } 7866569d68745c8213709740337d2be52b031384f58Douglas Gregor }; 7876569d68745c8213709740337d2be52b031384f58Douglas Gregor 7884d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief Contains information about any template-specific 7894d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// information that has been parsed prior to parsing declaration 7904d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// specifiers. 7914d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor struct ParsedTemplateInfo { 7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsedTemplateInfo() 7934d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { } 7944d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 7954d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ParsedTemplateInfo(TemplateParameterLists *TemplateParams, 796c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool isSpecialization, 797c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool lastParameterListWasEmpty = false) 7984d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(isSpecialization? ExplicitSpecialization : Template), 799c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor TemplateParams(TemplateParams), 800c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(lastParameterListWasEmpty) { } 8014d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 80245f965581935791a018df829a14dff53c1dd8f47Douglas Gregor explicit ParsedTemplateInfo(SourceLocation ExternLoc, 80345f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation TemplateLoc) 8041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Kind(ExplicitInstantiation), TemplateParams(0), 805c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), 806c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(false){ } 8074d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 8084d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The kind of template we are parsing. 8094d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor enum { 8104d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are not parsing a template at all. 8114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor NonTemplate = 0, 8124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing a template declaration. 8134d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor Template, 8144d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit specialization. 8154d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitSpecialization, 8164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit instantiation. 8174d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitInstantiation 8184d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } Kind; 8194d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 8204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The template parameter lists, for template declarations 8214d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// and explicit specializations. 8224d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParameterLists *TemplateParams; 8234d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 82445f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// \brief The location of the 'extern' keyword, if any, for an explicit 82545f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// instantiation 82645f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation ExternLoc; 8271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8284d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The location of the 'template' keyword, for an explicit 8294d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// instantiation. 8304d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation TemplateLoc; 831c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor 832c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor /// \brief Whether the last template parameter list was empty. 833c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool LastParameterListWasEmpty; 8344d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor }; 8351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void PushParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass); 83737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void DeallocateParsedClasses(ParsingClass *Class); 83837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void PopParsingClass(); 83937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor 84037b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor DeclPtrTy ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D, 84137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor const ParsedTemplateInfo &TemplateInfo); 84237b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDeclarations(ParsingClass &Class); 84337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDefs(ParsingClass &Class); 84414b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeAndStoreUntil(tok::TokenKind T1, 84514b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis CachedTokens &Toks, 84614b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 84714b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeFinalToken = true) { 84814b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken); 84914b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis } 8501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 85137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor CachedTokens &Toks, 85214b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 85337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor bool ConsumeFinalToken = true); 8544d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 8554cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.9: External Definitions. 857bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseExternalDeclaration(CXX0XAttributeList Attr); 858c82daefa3062721e98947e08193cd81b4e9df915Chris Lattner bool isDeclarationAfterDeclarator() const; 859004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); 860bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(AttributeList *Attr, 8615aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson AccessSpecifier AS = AS_none); 8623acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS, 8633acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AttributeList *Attr, 8643acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AccessSpecifier AS = AS_none); 8653acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian 86654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclPtrTy ParseFunctionDefinition(ParsingDeclarator &D, 86752591bf224b2c43e2b00e265bb8599a620081925Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseKNRParamDeclarations(Declarator &D); 869ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 870ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the simple-asm. 871ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl OwningExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0); 872effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl OwningExprResult ParseAsmStringLiteral(); 8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8743536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Objective-C External Declarations 8751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy ParseObjCAtDirectives(); 876b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); 8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, 878dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff AttributeList *prefixAttrs = 0); 8791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl, 88083c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 88160fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc); 882b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &P, 88371b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &PLocs, 8841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool WarnOnDeclarations, 88571b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, 886e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SourceLocation &EndProtoLoc); 887b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl, 888c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner tok::ObjCKeywordKind contextKey); 889b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc, 890b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *prefixAttrs = 0); 8911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 892b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ObjCImpDecl; 89363e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian llvm::SmallVector<DeclPtrTy, 4> PendingObjCImpDecl; 8940416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 895b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtImplementationDeclaration(SourceLocation atLoc); 896782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek DeclPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd); 897b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtAliasDeclaration(SourceLocation atLoc); 898b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCPropertySynthesize(SourceLocation atLoc); 899b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCPropertyDynamic(SourceLocation atLoc); 9001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9012fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); 90234870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner // Definitions for Objective-c context sensitive keywords recognition. 90334870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner enum ObjCTypeQual { 90434870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, 90534870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_NumQuals 90634870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner }; 907a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; 9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 909335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian bool isTokIdentifier_in() const; 910d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 911a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek TypeTy *ParseObjCTypeName(ObjCDeclSpec &DS); 912294494e1cce92043562b4680c613df7fd028c02eSteve Naroff void ParseObjCMethodRequirement(); 913b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCMethodPrototype(DeclPtrTy classOrCat, 914c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); 915b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, 916b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy classDecl, 91700933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); 9184ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor void ParseObjCPropertyAttribute(ObjCDeclSpec &DS, DeclPtrTy ClassDecl, 9194ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor DeclPtrTy *Methods, unsigned NumMethods); 9201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 921b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCMethodDefinition(); 9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.5: Expressions. 9256aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 9262f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParseExpression(); 9272f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParseConstantExpression(); 9282f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl // Expr that doesn't include commas. 9292f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParseAssignmentExpression(); 9302f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 931d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 933adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman OwningExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); 934adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman 935d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseRHSOfBinaryExpression(OwningExprResult LHS, 9366aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor prec::Level MinPrec); 937ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl OwningExprResult ParseCastExpression(bool isUnaryExpression, 938f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAddressOfOperand, 9392ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman bool &NotCastExpr, 940f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian TypeTy *TypeOfCast); 941f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis OwningExprResult ParseCastExpression(bool isUnaryExpression, 9422ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman bool isAddressOfOperand = false, 943f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian TypeTy *TypeOfCast = 0); 9442f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParsePostfixExpressionSuffix(OwningExprResult LHS); 945d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseSizeofAlignofExpression(); 946d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseBuiltinPrimaryExpression(); 9471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9485ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis OwningExprResult ParseExprAfterTypeofSizeofAlignof(const Token &OpTok, 9495ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis bool &isCastExpr, 9505ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis TypeTy *&CastTy, 9515ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis SourceRange &CastRange); 9520cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 953a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl static const unsigned ExprListSize = 12; 954a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl typedef llvm::SmallVector<ExprTy*, ExprListSize> ExprListTy; 955a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl typedef llvm::SmallVector<SourceLocation, ExprListSize> CommaLocsTy; 9560cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 9570cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis /// ParseExpressionList - Used for C/C++ (argument-)expression-list. 9589c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor bool ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs, 9599c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor void (Action::*Completer)(Scope *S, void *Data, 9609c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor ExprTy **Args, 9619c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor unsigned NumArgs) = 0, 9629c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor void *Data = 0); 963d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl 9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParenParseOption - Control what ParseParenExpression will parse. 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ParenParseOption { 9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SimpleExpr, // Only parse '(' expression ')' 9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundStmt, // Also allow '(' compound-statement ')' 9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}' 9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CastExpr // Also allow '(' type-name ')' <anything> 9705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 971d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseParenExpression(ParenParseOption &ExprType, 9720350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis bool stopIfCastExpr, 973f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian TypeTy *TypeOfCast, 974d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl TypeTy *&CastTy, 975d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl SourceLocation &RParenLoc); 9761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 977f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis OwningExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, 978f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis TypeTy *&CastTy, 979f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis SourceLocation LParenLoc, 980f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis SourceLocation &RParenLoc); 9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 982d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis OwningExprResult ParseCompoundLiteralExpression(TypeTy *Ty, 983d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation LParenLoc, 984d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation RParenLoc); 9851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98620df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseStringLiteralExpression(); 987eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 988eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 989eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // C++ Expressions 990ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl OwningExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); 9914bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis 9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 9932dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor TypeTy *ObjectType, 994b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor bool EnteringContext, 995d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool *MayBePseudoDestructor = 0); 9961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 5.2p1: C++ Casts 99920df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXCasts(); 10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1002c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // C++ 5.2p1: C++ Type Identification 100320df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXTypeid(); 1004c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 1005c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl //===--------------------------------------------------------------------===// 1006d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // C++ 5.2.4: C++ Pseudo-Destructor Expressions 1007d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor OwningExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, 1008d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor tok::TokenKind OpKind, 1009d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CXXScopeSpec &SS, 1010d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor Action::TypeTy *ObjectType); 1011d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 1012d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor //===--------------------------------------------------------------------===// 10134cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 9.3.2: C++ 'this' pointer 101420df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXThis(); 10154cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 10164cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 101750dd289f45738ed22b7583d52ed2525b927042ffChris Lattner // C++ 15: C++ Throw Expression 101820df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseThrowExpression(); 1019ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc is filled with the location of the last token of the specification. 10207dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl bool ParseExceptionSpecification(SourceLocation &EndLoc, 1021ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl llvm::SmallVector<TypeTy*, 2> &Exceptions, 1022ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl llvm::SmallVector<SourceRange, 2> &Ranges, 10237dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl bool &hasAnyExceptionSpec); 102450dd289f45738ed22b7583d52ed2525b927042ffChris Lattner 102550dd289f45738ed22b7583d52ed2525b927042ffChris Lattner //===--------------------------------------------------------------------===// 10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 2.13.5: C++ Boolean Literals 102720df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXBoolLiteral(); 10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1030987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // C++ 5.2.3: Explicit type conversion (functional notation) 103120df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); 1032987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 10336aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool isCXXSimpleTypeSpecifier() const; 10346aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 1035987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 1036987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// This should only be called when the current token is known to be part of 1037987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// simple-type-specifier. 1038987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); 1039987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 10402f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); 10412f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 1042987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 10434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // C++ 5.3.4 and 5.3.5: C++ new and delete 1044cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl bool ParseExpressionListOrTypeId(ExprListTy &Exprs, Declarator &D); 10454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDirectNewDeclarator(Declarator &D); 104659232d35f5820e334b6c8b007ae8006f4390055dChris Lattner OwningExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); 104759232d35f5820e334b6c8b007ae8006f4390055dChris Lattner OwningExprResult ParseCXXDeleteExpression(bool UseGlobal, 104859232d35f5820e334b6c8b007ae8006f4390055dChris Lattner SourceLocation Start); 10494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 10504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl //===--------------------------------------------------------------------===// 105199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor // C++ if/switch/while condition expression. 1052586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor bool ParseCXXCondition(OwningExprResult &ExprResult, DeclPtrTy &DeclResult, 1053586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, bool ConvertToBoolean); 105471b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 105571b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 105612e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor // C++ types 105712e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor 105812e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor //===--------------------------------------------------------------------===// 10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7.8: Initialization. 10601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10610eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// ParseInitializer 10620eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// initializer: [C99 6.7.8] 10630eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// assignment-expression 10640eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// '{' ... 106520df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseInitializer() { 10660eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner if (Tok.isNot(tok::l_brace)) 106720df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ParseAssignmentExpression(); 10680eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner return ParseBraceInitializer(); 10690eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner } 107020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseBraceInitializer(); 10715908a9293b88a3da57ae59b522275d05e1ab11e0Douglas Gregor OwningExprResult ParseInitializerWithPotentialDesignator(); 10721d922960e083906a586609ac6978678147250177Sebastian Redl 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1074296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // clang Expressions 10751d922960e083906a586609ac6978678147250177Sebastian Redl 10761d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseBlockLiteralExpression(); // ^{...} 1077296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff 1078296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff //===--------------------------------------------------------------------===// 10795508518a2702b00be3b15a26d772bde968972f54Anders Carlsson // Objective-C Expressions 10801d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCAtExpression(SourceLocation AtLocation); 10811d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCStringLiteral(SourceLocation AtLoc); 10821d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); 10831d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); 10841d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); 10851b730e847ded503f2e615154035c083c4f94a067Douglas Gregor bool isSimpleObjCMessageExpression(); 10861d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCMessageExpression(); 10871d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, 10882725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation SuperLoc, 10892725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor TypeTy *ReceiverType, 10901d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr); 10911d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseAssignmentExprWithObjCMessageExprStart( 10922725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation LBracloc, SourceLocation SuperLoc, 10932725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor TypeTy *ReceiverType, ExprArg ReceiverExpr); 10946aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr); 109561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 10965508518a2702b00be3b15a26d772bde968972f54Anders Carlsson //===--------------------------------------------------------------------===// 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.8: Statements and Blocks. 109861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 109961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult ParseStatement() { 110061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl return ParseStatementOrDeclaration(true); 110161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 110261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult ParseStatementOrDeclaration(bool OnlyStatement = false); 1103bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseLabeledStatement(AttributeList *Attr); 1104bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseCaseStatement(AttributeList *Attr); 1105bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseDefaultStatement(AttributeList *Attr); 1106bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseCompoundStatement(AttributeList *Attr, 1107bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool isStmtExpr = false); 110861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult ParseCompoundStatementBody(bool isStmtExpr = false); 110999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor bool ParseParenExprOrCondition(OwningExprResult &ExprResult, 1110586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor DeclPtrTy &DeclResult, 1111586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, 1112586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor bool ConvertToBoolean); 1113bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseIfStatement(AttributeList *Attr); 1114bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseSwitchStatement(AttributeList *Attr); 1115bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseWhileStatement(AttributeList *Attr); 1116bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseDoStatement(AttributeList *Attr); 1117bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseForStatement(AttributeList *Attr); 1118bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseGotoStatement(AttributeList *Attr); 1119bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseContinueStatement(AttributeList *Attr); 1120bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseBreakStatement(AttributeList *Attr); 1121bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseReturnStatement(AttributeList *Attr); 11229a920342707e384473b464528d2fd286e8c70353Sebastian Redl OwningStmtResult ParseAsmStatement(bool &msAsm); 11239a920342707e384473b464528d2fd286e8c70353Sebastian Redl OwningStmtResult FuzzyParseMicrosoftAsmStatement(); 1124ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<IdentifierInfo *> &Names, 1125ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVectorImpl<ExprTy *> &Constraints, 1126ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVectorImpl<ExprTy *> &Exprs); 1127a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1128a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1129a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // C++ 6: Statements and Blocks 1130a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1131bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseCXXTryBlock(AttributeList *Attr); 1132d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl OwningStmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc); 1133a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl OwningStmtResult ParseCXXCatchBlock(); 1134a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1135a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1136a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // Objective-C Statements 1137a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 113843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCAtStatement(SourceLocation atLoc); 113943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCTryStmt(SourceLocation atLoc); 114043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCThrowStmt(SourceLocation atLoc); 114143bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); 1142b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7: Declarations. 114667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall 114767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// A context for parsing declaration specifiers. TODO: flesh this 114867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// out, there are other significant restrictions on specifiers than 114967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// would be best implemented in the parser. 115067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall enum DeclSpecContext { 115167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DSC_normal, // normal context 11520efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_class, // class context, enables 'friend' 11530efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_top_level // top-level/namespace declaration context 115467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall }; 11551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1156bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseDeclaration(unsigned Context, SourceLocation &DeclEnd, 1157bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList Attr); 1158cd1477562e7cf03279850885583d615e1f631dd4Chris Lattner DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context, 1159bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 11605c5db553b5c256d0a6f55dde7325c1c829b88e8eChris Lattner AttributeList *Attr, 11615c5db553b5c256d0a6f55dde7325c1c829b88e8eChris Lattner bool RequireSemi); 116254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, 1163d8ac05753dc4506224d445ff98399c01da3136e5John McCall bool AllowFunctionDefinitions, 1164d8ac05753dc4506224d445ff98399c01da3136e5John McCall SourceLocation *DeclEnd = 0); 1165e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor DeclPtrTy ParseDeclarationAfterDeclarator(Declarator &D, 1166e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1167b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseFunctionStatementBody(DeclPtrTy Decl); 1168d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl DeclPtrTy ParseFunctionTryBlock(DeclPtrTy Decl); 1169d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 1170f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, 11714d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 1172e40c295d017a8f75a945fe9ed2aa9d8bb7a7341aChris Lattner AccessSpecifier AS); 11730efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); 11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseDeclarationSpecifiers(DeclSpec &DS, 11754d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 117667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall AccessSpecifier AS = AS_none, 117767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DeclSpecContext DSC = DSC_normal); 11781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid, 11797a0ab5f387722c83e19c7133b46b16988eb19e45Chris Lattner const char *&PrevSpec, 1180fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID, 1181d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1182d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 11834d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseSpecifierQualifierList(DeclSpec &DS); 11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1186a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void ParseObjCTypeQualifierList(ObjCDeclSpec &DS); 11875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11884c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, 11899b9edd619a7e616d3287435cb5a3f9b1aea648e8Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), AccessSpecifier AS = AS_none); 1190b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseEnumBody(SourceLocation StartLoc, DeclPtrTy TagDecl); 11915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, 1192b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy TagDecl); 1193bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1194bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct FieldCallback { 1195bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall virtual DeclPtrTy invoke(FieldDeclarator &Field) = 0; 11966c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual ~FieldCallback() {} 11976c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall 11986c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall private: 11996c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual void _anchor(); 1200bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall }; 1201d0014540005f2a5ab837365db6bd40f479406758John McCall struct ObjCPropertyCallback; 1202bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1203bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback); 12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1205eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isDeclarationSpecifier(); 1206eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isTypeSpecifierQualifier(); 12075f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff bool isTypeQualifier() const; 1208b3a4e432c90be98c6d918087750397e86d030368Chris Lattner 1209b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// isKnownToBeTypeSpecifier - Return true if we know that the specified token 1210b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// is definitely a type-specifier. Return false if it isn't part of a type 1211b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// specifier or if we're not sure. 1212b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool isKnownToBeTypeSpecifier(const Token &Tok) const; 12135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isDeclarationStatement - Disambiguates between a declaration or an 12155404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// expression statement, when parsing function bodies. 12165404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for declaration, false for expression. 12175404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isDeclarationStatement() { 12185404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis if (getLang().CPlusPlus) 12195404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isCXXDeclarationStatement(); 12205404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isDeclarationSpecifier(); 12215404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 12225404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1223bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// isSimpleDeclaration - Disambiguates between a declaration or an 1224bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// expression, mainly used for the C 'clause-1' or the C++ 1225bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis // 'for-init-statement' part of a 'for' statement. 1226bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// Returns true for declaration, false for expression. 1227bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis bool isSimpleDeclaration() { 1228bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis if (getLang().CPlusPlus) 1229bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis return isCXXSimpleDeclaration(); 1230bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis return isDeclarationSpecifier(); 1231bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis } 1232bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis 12330efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief Starting with a scope specifier, identifier, or 12340efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id that refers to the current class, determine whether 12350efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// this is a constructor declarator. 12360efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor bool isConstructorDeclarator(); 12370efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 12388b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// \brief Specifies the context in which type-id/expression 12398b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// disambiguation will occur. 12408b642592a35167a3780074e78674e0bece87c40cDouglas Gregor enum TentativeCXXTypeIdContext { 12418b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdInParens, 12428b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdAsTemplateArgument 12438b642592a35167a3780074e78674e0bece87c40cDouglas Gregor }; 12448b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 12458b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 124678c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know 124778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// whether the parens contain an expression or a type-id. 124878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// Returns true for a type-id and false for an expression. 1249f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens(bool &isAmbiguous) { 125078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis if (getLang().CPlusPlus) 1251f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(TypeIdInParens, isAmbiguous); 1252f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis isAmbiguous = false; 125378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis return isTypeSpecifierQualifier(); 125478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis } 1255f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens() { 1256f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1257f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isTypeIdInParens(isAmbiguous); 1258f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 125978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 12605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXDeclarationStatement - C++-specialized function that disambiguates 12615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a declaration or an expression statement, when parsing function 12625404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// bodies. Returns true for declaration, false for expression. 12635404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXDeclarationStatement(); 12645404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 12655404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXSimpleDeclaration - C++-specialized function that disambiguates 12665404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a simple-declaration or an expression-statement. 12675404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 12685404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 12695404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns false if the statement is disambiguated as expression. 12705404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXSimpleDeclaration(); 12715404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 12725404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXFunctionDeclarator - Disambiguates between a function declarator or 12735404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// a constructor-style initializer, when parsing declaration statements. 12745404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for function declarator and false for constructor-style 1275e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to 1276259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis /// indicate that the parens were disambiguated as function declarator. 12775404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 12785404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1279e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis bool isCXXFunctionDeclarator(bool warnIfAmbiguous); 12805404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1281a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// isCXXConditionDeclaration - Disambiguates between a declaration or an 1282a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// expression for a condition of a if/switch/while/for statement. 1283a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 1284a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1285a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis bool isCXXConditionDeclaration(); 1286a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis 1287f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); 1288f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context) { 1289f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1290f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(Context, isAmbiguous); 1291f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 129278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 1293b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult - Used as the result value for functions whose purpose is to 1294b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// disambiguate C++ constructs by "tentatively parsing" them. 1295b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// This is a class instead of a simple enum because the implicit enum-to-bool 1296b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// conversions may cause subtle bugs. 1297b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis class TPResult { 1298b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis enum Result { 1299b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_true, 1300b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_false, 1301b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_ambiguous, 1302b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_error 1303b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis }; 1304b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis Result Res; 1305b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult(Result result) : Res(result) {} 1306b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis public: 1307b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult True() { return TPR_true; } 1308b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult False() { return TPR_false; } 1309b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Ambiguous() { return TPR_ambiguous; } 1310b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Error() { return TPR_error; } 1311b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis 1312b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator==(const TPResult &RHS) const { return Res == RHS.Res; } 1313b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; } 1314b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis }; 1315b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis 1316b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a 1317b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// declaration specifier, TPResult::False() if it is not, 1318b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult::Ambiguous() if it could be either a decl-specifier or a 1319b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// function-style cast, and TPResult::Error() if a parsing error was 1320b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// encountered. 13215404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Doesn't consume tokens. 1322b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult isCXXDeclarationSpecifier(); 13235404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 13245404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // "Tentative parsing" functions, used for disambiguation. If a parsing error 1325b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // is encountered they will return TPResult::Error(). 1326b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // Returning TPResult::True()/False() indicates that the ambiguity was 1327b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates 1328b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // that more tentative parsing is necessary for disambiguation. 13295404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // They all consume tokens, so backtracking should be used after calling them. 13305404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1331b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseDeclarationSpecifier(); 1332b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseSimpleDeclaration(); 1333b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseTypeofSpecifier(); 1334b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseInitDeclaratorList(); 133578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); 1336b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseParameterDeclarationClause(); 1337b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseFunctionDeclarator(); 1338b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseBracketDeclarator(); 13395404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1340ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl TypeResult ParseTypeName(SourceRange *Range = 0); 134198eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump void ParseBlockId(); 1342ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 1343ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the attribute list. 1344bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList ParseCXX0XAttributes(SourceLocation *EndLoc = 0); 1345bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttributeList *ParseGNUAttributes(SourceLocation *EndLoc = 0); 1346290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0); 1347290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0); 1348d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff void ParseTypeofSpecifier(DeclSpec &DS); 13496fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson void ParseDecltypeSpecifier(DeclSpec &DS); 1350bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 1351bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningExprResult ParseCXX0XAlignArgument(SourceLocation Start); 1352eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1353eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to 1354eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// enter a new C++ declarator scope and exit it when the function is 1355eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// finished. 1356eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis class DeclaratorScopeObj { 1357eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis Parser &P; 1358751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis CXXScopeSpec &SS; 1359f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis bool EnteredScope; 1360f7f3d0db754db0500b56d49ac19f795f13965912John McCall bool CreatedScope; 1361eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis public: 1362f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) 1363f7f3d0db754db0500b56d49ac19f795f13965912John McCall : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} 1364eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1365eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis void EnterDeclaratorScope() { 13662bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis assert(!EnteredScope && "Already entered the scope!"); 1367f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was not set!"); 1368f7f3d0db754db0500b56d49ac19f795f13965912John McCall 1369f7f3d0db754db0500b56d49ac19f795f13965912John McCall CreatedScope = true; 1370f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.EnterScope(0); // Not a decl scope. 1371f7f3d0db754db0500b56d49ac19f795f13965912John McCall 137223c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS)) 13733fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor EnteredScope = true; 1374eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1375eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1376eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis ~DeclaratorScopeObj() { 1377f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis if (EnteredScope) { 1378f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was cleared ?"); 137923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS); 1380f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis } 1381f7f3d0db754db0500b56d49ac19f795f13965912John McCall if (CreatedScope) 1382f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.ExitScope(); 1383eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1384eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis }; 13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseDeclarator - Parse and verify a newly-initialized declarator. 13875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDeclarator(Declarator &D); 13884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl /// A function that parses a variant of direct-declarator. 13894c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef void (Parser::*DirectDeclParseFunction)(Declarator&); 13904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDeclaratorInternal(Declarator &D, 13914c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl DirectDeclParseFunction DirectDeclParser); 1392bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, 1393bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool CXX0XAttributesAllowed = true); 13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDirectDeclarator(Declarator &D); 13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseParenDeclarator(Declarator &D); 13967399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, 13977399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner AttributeList *AttrList = 0, 13987399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner bool RequiresArg = false); 139966d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc, 140083a944763b0948c608eb48f101ec10a1ae5da46aChris Lattner IdentifierInfo *FirstIdent, 140183a944763b0948c608eb48f101ec10a1ae5da46aChris Lattner SourceLocation FirstIdentLoc, 140266d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner Declarator &D); 14035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseBracketDeclarator(Declarator &D); 14041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14058f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner //===--------------------------------------------------------------------===// 14068f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner // C++ 7: Declarations [dcl.dcl] 14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1408bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool isCXX0XAttributeSpecifier(bool FullLookahead = false, 1409bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt tok::TokenKind *After = 0); 1410bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 141197144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseNamespace(unsigned Context, SourceLocation &DeclEnd); 14123acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian DeclPtrTy ParseLinkage(ParsingDeclSpec &DS, unsigned Context); 141397144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseUsingDirectiveOrDeclaration(unsigned Context, 1414bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 1415bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList Attrs); 141697144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseUsingDirective(unsigned Context, SourceLocation UsingLoc, 1417bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 1418bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttributeList *Attr); 141997144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc, 1420595adc1795cc2c079ef5876100e01acd10a0504aAnders Carlsson SourceLocation &DeclEnd, 1421595adc1795cc2c079ef5876100e01acd10a0504aAnders Carlsson AccessSpecifier AS = AS_none); 142297144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseStaticAssertDeclaration(SourceLocation &DeclEnd); 142303bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson DeclPtrTy ParseNamespaceAlias(SourceLocation NamespaceLoc, 142497144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation AliasLoc, IdentifierInfo *Alias, 142597144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation &DeclEnd); 14261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1427e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 1428e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 9: classes [class] and C structs/unions. 14291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeResult ParseClassName(SourceLocation &EndLocation, 14309ab14541716928894821cf5d53d6b4c95ffdf3a3Jeffrey Yasskin CXXScopeSpec *SS = 0); 14314c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, 14321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclSpec &DS, 14334d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1434d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl AccessSpecifier AS = AS_none, 1435d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 14364cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType, 1437b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy TagDecl); 143837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseCXXClassMemberDeclaration(AccessSpecifier AS, 1439c9068d7dd94d439cec66c421115d15303e481025John McCall const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1440c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject *DiagsFromTParams = 0); 1441b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseConstructorInitializer(DeclPtrTy ConstructorDecl); 1442b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner MemInitResult ParseMemInitializer(DeclPtrTy ConstructorDecl); 1443d33133cdc1af466f9c276249b2621be03867888bEli Friedman void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, 1444d33133cdc1af466f9c276249b2621be03867888bEli Friedman DeclPtrTy ThisDecl); 1445e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1446e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 1447e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 10: Derived classes [class.derived] 1448b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseBaseClause(DeclPtrTy ClassDecl); 1449b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner BaseResult ParseBaseSpecifier(DeclPtrTy ClassDecl); 14501b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor AccessSpecifier getAccessSpecifierIfPresent() const; 14511cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor 14523f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 14533f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Name, 14543f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation NameLoc, 14553f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool EnteringContext, 14562d1c21414199a7452f122598189363a3922605b1Douglas Gregor TypeTy *ObjectType, 1457d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor UnqualifiedId &Id, 14580278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor bool AssumeTemplateId, 14590278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor SourceLocation TemplateKWLoc); 1460ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, 1461ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor TypeTy *ObjectType, 1462ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &Result); 14633f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, 146402a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowDestructorName, 146502a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowConstructorName, 14662d1c21414199a7452f122598189363a3922605b1Douglas Gregor TypeTy *ObjectType, 14673f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &Result); 14683f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 14691cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor //===--------------------------------------------------------------------===// 1470adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14: Templates [temp] 1471b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner typedef llvm::SmallVector<DeclPtrTy, 4> TemplateParameterList; 1472c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 1473adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14.1: Template Parameters [temp.param] 14744d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor DeclPtrTy ParseDeclarationStartingWithTemplate(unsigned Context, 14754d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation &DeclEnd, 14764d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AccessSpecifier AS = AS_none); 1477b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTemplateDeclarationOrSpecialization(unsigned Context, 147897144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation &DeclEnd, 14794d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AccessSpecifier AS); 14801426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor DeclPtrTy ParseSingleDeclarationAfterTemplate( 14811426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor unsigned Context, 14824d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 1483c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject &DiagsFromParams, 14841426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor SourceLocation &DeclEnd, 14851426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor AccessSpecifier AS=AS_none); 14861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseTemplateParameters(unsigned Depth, 1487c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor TemplateParameterList &TemplateParams, 14881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation &LAngleLoc, 1489c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor SourceLocation &RAngleLoc); 1490c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor bool ParseTemplateParameterList(unsigned Depth, 1491c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor TemplateParameterList &TemplateParams); 149298440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor bool isStartOfTemplateTypeParameter(); 1493b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTemplateParameter(unsigned Depth, unsigned Position); 1494b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTypeParameter(unsigned Depth, unsigned Position); 1495b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); 1496b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); 1497d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor // C++ 14.3: Template arguments [temp.arg] 1498314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor typedef llvm::SmallVector<ParsedTemplateArgument, 16> TemplateArgList; 1499cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 15007532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor bool ParseTemplateIdAfterTemplateName(TemplateTy Template, 15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateNameLoc, 1502cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor const CXXScopeSpec *SS, 1503cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor bool ConsumeLastToken, 1504cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &LAngleLoc, 1505cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateArgList &TemplateArgs, 1506cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &RAngleLoc); 1507cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 1508c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, 150939a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor const CXXScopeSpec *SS, 1510ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &TemplateName, 151139a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor SourceLocation TemplateKWLoc = SourceLocation(), 151239a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor bool AllowTypeAnnotation = true); 151331a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor void AnnotateTemplateIdTokenAsType(const CXXScopeSpec *SS = 0); 1514d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor bool IsTemplateArgumentList(unsigned Skip = 0); 1515314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); 1516788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor ParsedTemplateArgument ParseTemplateTemplateArgument(); 1517314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor ParsedTemplateArgument ParseTemplateArgument(); 151845f965581935791a018df829a14dff53c1dd8f47Douglas Gregor DeclPtrTy ParseExplicitInstantiation(SourceLocation ExternLoc, 15191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateLoc, 15204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation &DeclEnd); 152164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 152264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl //===--------------------------------------------------------------------===// 152364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // GNU G++: Type Traits [Type-Traits.html in the GCC manual] 152464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl OwningExprResult ParseUnaryTypeTrait(); 15255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 15285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1530