Parser.h revision ff93dbd887e40588ed55d135037bb9287488b285
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 441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Parser - This implements a parser for the C family of languages. After 465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// parsing units of the grammar, productions are invoked to handle whatever has 475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// been read. 485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Parser { 504726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek friend class PragmaUnusedHandler; 5108d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner friend class ColonProtectionRAIIObject; 520102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner PrettyStackTraceParserEntry CrashInfo; 531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Preprocessor &PP; 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5697d0205d16fef2a783e785459b5f30f6a9dfbcb9Eric Christopher /// Tok - The current token we are peeking ahead. All parsing methods assume 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that this is valid. 58d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner Token Tok; 591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 604b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // PrevTokLocation - The location of the token we previously 614b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // consumed. This token is used for diagnostics where we expected to 624b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // see a token following another token (e.g., the ';' at the end of 634b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // a statement). 644b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceLocation PrevTokLocation; 654b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned short ParenCount, BracketCount, BraceCount; 675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Actions - These are the callbacks we invoke as we parse various constructs 695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// in the file. This refers to the common base class between MinimalActions 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and SemaActions for those uses that don't matter. 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Action &Actions; 721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Scope *CurScope; 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Diagnostic &Diags; 751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 769e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner /// ScopeCache - Cache scopes to reduce malloc traffic. 779e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner enum { ScopeCacheSize = 16 }; 789e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner unsigned NumCachedScopes; 799e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner Scope *ScopeCache[ScopeCacheSize]; 80662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 81662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// Ident_super - IdentifierInfo for "super", to support fast 82662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// comparison. 83662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar IdentifierInfo *Ident_super; 84662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 854726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> PackHandler; 864726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> UnusedHandler; 879991479ad5dde617168cc1e4b18425cdbbfd9fa9Eli Friedman llvm::OwningPtr<PragmaHandler> WeakHandler; 882e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor llvm::OwningPtr<clang::CommentHandler> CommentHandler; 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// Whether the '>' token acts as an operator or not. This will be 9155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// true except when we are parsing an expression within a C++ 9255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// template argument list, where the '>' closes the template 9355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// argument list. 9455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor bool GreaterThanIsOperator; 9508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner 9608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonIsSacred - When this is false, we aggressively try to recover from 9708d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not 9808d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// safe in case statements and a few other things. This is managed by the 9908d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonProtectionRAIIObject RAII object. 10008d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner bool ColonIsSacred; 10155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 102c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor /// The "depth" of the template parameters currently being parsed. 103c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor unsigned TemplateParameterDepth; 1041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Parser(Preprocessor &PP, Action &Actions); 1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Parser(); 1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const LangOptions &getLang() const { return PP.getLangOptions(); } 110444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } 1110102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner Preprocessor &getPreprocessor() const { return PP; } 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Action &getActions() const { return Actions; } 1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1140102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Token &getCurToken() const { return Tok; } 1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Type forwarding. All of these are statically 'void*', but they may all be 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // different actual classes based on the actions in place. 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef Action::ExprTy ExprTy; 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef Action::StmtTy StmtTy; 120b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner typedef Action::DeclPtrTy DeclPtrTy; 121682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner typedef Action::DeclGroupPtrTy DeclGroupPtrTy; 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef Action::TypeTy TypeTy; 123f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor typedef Action::BaseTy BaseTy; 1247ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor typedef Action::MemInitTy MemInitTy; 125eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis typedef Action::CXXScopeTy CXXScopeTy; 126c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor typedef Action::TemplateParamsTy TemplateParamsTy; 1277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor typedef Action::TemplateTy TemplateTy; 1287ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 129c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor typedef llvm::SmallVector<TemplateParamsTy *, 4> TemplateParameterLists; 130c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 131d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::ExprResult ExprResult; 132d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::StmtResult StmtResult; 133d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::BaseResult BaseResult; 134d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::MemInitResult MemInitResult; 135809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor typedef Action::TypeResult TypeResult; 13615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 13715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl typedef Action::OwningExprResult OwningExprResult; 13815faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl typedef Action::OwningStmtResult OwningStmtResult; 13915faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 1401d922960e083906a586609ac6978678147250177Sebastian Redl typedef Action::ExprArg ExprArg; 141a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl typedef Action::MultiStmtArg MultiStmtArg; 142a99fad8ff134273fe85f2970c7d89133d1218900Anders Carlsson typedef Action::FullExprArg FullExprArg; 1431d922960e083906a586609ac6978678147250177Sebastian Redl 14461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl /// Adorns a ExprResult with Actions to make it an OwningExprResult 14561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningExprResult Owned(ExprResult res) { 14661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl return OwningExprResult(Actions, res); 14761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 14861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl /// Adorns a StmtResult with Actions to make it an OwningStmtResult 14961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult Owned(StmtResult res) { 15061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl return OwningStmtResult(Actions, res); 15161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 15261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 15361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningExprResult ExprError() { return OwningExprResult(Actions, true); } 15461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult StmtError() { return OwningStmtResult(Actions, true); } 155d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor 1562f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); } 1572f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningStmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); } 15861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1595ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis OwningExprResult ExprEmpty() { return OwningExprResult(Actions, false); } 1605ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Parsing methods. 1621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseTranslationUnit - All in one method that initializes parses, and 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// shuts down the parser. 1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseTranslationUnit(); 1661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Initialize - Warm up the parser. 1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Initialize(); 1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if 1721f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff /// the EOF was encountered. 173682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner bool ParseTopLevelDecl(DeclGroupPtrTy &Result); 1741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1751ac7104947020a60430ba6f519cd5869af77046fFariborz Jahanian DeclGroupPtrTy RetrievePendingObjCImpDecl(); 17663e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Low-Level token peeking and consumption methods. 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 1811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenParen - Return true if the cur token is '(' or ')'. 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenParen() const { 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren; 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBracket - Return true if the cur token is '[' or ']'. 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBracket() const { 1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square; 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBrace - Return true if the cur token is '{' or '}'. 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBrace() const { 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace; 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenStringLiteral - True if this token is a string-literal. 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenStringLiteral() const { 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::string_literal || 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Tok.getKind() == tok::wide_string_literal; 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 201eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeToken - Consume the current 'peek token' and lex the next one. 203d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu /// This does not work with all kinds of tokens: strings and specific other 2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tokens must be consumed with custom methods below. This returns the 2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// location of the consumed token. 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeToken() { 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer !isTokenBrace() && 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should consume special tokens with Consume*Token"); 2104b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2124b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeAnyToken - Dispatch to the right Consume* method based on the 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// current token type. This should only be used in cases where the type of 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the token really isn't known, e.g. in error recovery. 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeAnyToken() { 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isTokenParen()) 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeParen(); 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBracket()) 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBracket(); 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBrace()) 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBrace(); 225d62701bc5321049353017e9abf1963edd57646aaSteve Naroff else if (isTokenStringLiteral()) 226d62701bc5321049353017e9abf1963edd57646aaSteve Naroff return ConsumeStringToken(); 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeToken(); 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeParen - This consume method keeps the paren count up-to-date. 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeParen() { 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenParen() && "wrong consume method"); 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_paren) 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++ParenCount; 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (ParenCount) 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --ParenCount; // Don't let unbalanced )'s drive the count negative. 2394b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2414b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBracket - This consume method keeps the bracket count up-to-date. 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBracket() { 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBracket() && "wrong consume method"); 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_square) 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BracketCount; 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BracketCount) 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BracketCount; // Don't let unbalanced ]'s drive the count negative. 2521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2534b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2554b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBrace - This consume method keeps the brace count up-to-date. 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBrace() { 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBrace() && "wrong consume method"); 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_brace) 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BraceCount; 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BraceCount) 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BraceCount; // Don't let unbalanced }'s drive the count negative. 2661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2674b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2694b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeStringToken - Consume the current 'peek token', lexing a new one 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and returning the token kind. This method is specific to strings, as it 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// handles string literal concatenation, as per C99 5.1.1.2, translation 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// phase #6. 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeStringToken() { 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenStringLiteral() && 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should only consume string literals with this method"); 2794b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2814b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2846b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// GetLookAheadToken - This peeks ahead N tokens and returns that token 2856b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1) 2866b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// returns the token after Tok, etc. 2876b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 2886b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// Note that this differs from the Preprocessor's LookAhead method, because 2896b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// the Parser always has one token lexed that the preprocessor doesn't. 2906b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 29103db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis const Token &GetLookAheadToken(unsigned N) { 2926b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (N == 0 || Tok.is(tok::eof)) return Tok; 2936b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return PP.LookAhead(N-1); 2946b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } 295f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis 296f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// NextToken - This peeks ahead one token and returns it without 297f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// consuming it. 298f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis const Token &NextToken() { 29903db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis return PP.LookAhead(0); 300f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis } 3015404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 302eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// TryAnnotateTypeOrScopeToken - If the current token position is on a 303eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// typename (possibly qualified in C++) or a C++ scope specifier not followed 304eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens 305eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// with a single annotation token representing the typename or C++ scope 306eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// respectively. 307eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// This simplifies handling of C++ scope specifiers and allows efficient 308eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// backtracking without the need to re-parse and resolve nested-names and 309eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// typenames. 31044802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// It will mainly be called when we expect to treat identifiers as typenames 31144802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// (if they are typenames). For example, in C we do not expect identifiers 31244802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// inside expressions to be treated as typenames so it will not be called 31344802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// for expressions in C. 314a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner /// 315a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner /// This returns true if the token was annotated. 316495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false); 317eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 3184bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only 3195e02c47a7085831586344a9728763cb50540c7f7Chris Lattner /// annotates C++ scope specifiers. This returns true if the token was 3205e02c47a7085831586344a9728763cb50540c7f7Chris Lattner /// annotated. 321495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateCXXScopeToken(bool EnteringContext = false); 322eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 3235404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TentativeParsingAction - An object that is used as a kind of "tentative 3245404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// parsing transaction". It gets instantiated to mark the token position and 3255404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// after the token consumption is done, Commit() or Revert() is called to 3265404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// either "commit the consumed tokens" or revert to the previously marked 3275404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// token position. Example: 3285404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 329314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor /// TentativeParsingAction TPA(*this); 3305404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// ConsumeToken(); 3315404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// .... 3325404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TPA.Revert(); 3335404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 3345404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis class TentativeParsingAction { 3355404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Parser &P; 3365404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Token PrevTok; 3375404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isActive; 3385404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 3395404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis public: 3405404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis explicit TentativeParsingAction(Parser& p) : P(p) { 3415404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis PrevTok = P.Tok; 3425404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.EnableBacktrackAtThisPos(); 3435404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = true; 3445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 3455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Commit() { 3465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 3475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.CommitBacktrackedTokens(); 3485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 3495404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 3505404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Revert() { 3515404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 3525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.Backtrack(); 3535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.Tok = PrevTok; 3545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 3555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 3565404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis ~TentativeParsingAction() { 3575404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(!isActive && "Forgot to call Commit or Revert!"); 3585404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 3595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis }; 3601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'), 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this helper function matches and consumes the specified RHS token if 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// present. If not present, it emits the specified diagnostic indicating 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that the parser failed to match the RHS of the token at LHSLoc. LHSName 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// should be the name of the unmatched LHS token. This returns the location 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the consumed token. 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MatchRHSPunctuation(tok::TokenKind RHSTok, 3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation LHSLoc); 3701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// input. If so, it is consumed and false is returned. 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If the input is malformed, this emits the specified diagnostic. Next, if 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is 3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// returned. 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag, 3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *DiagMsg = "", 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind SkipToTok = tok::unknown); 3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Scope manipulation 3831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3848935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// ParseScope - Introduces a new scope for parsing. The kind of 3858935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// scope is determined by ScopeFlags. Objects of this type should 3868935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// be created on the stack to coincide with the position where the 3878935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// parser enters the new scope, and this object's constructor will 3888935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// create that new scope. Similarly, once the object is destroyed 3898935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// the parser will exit the scope. 3908935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor class ParseScope { 3918935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Parser *Self; 3928935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope(const ParseScope&); // do not implement 3938935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope& operator=(const ParseScope&); // do not implement 3948935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 3958935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor public: 3968935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ParseScope - Construct a new object to manage a scope in the 3978935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // parser Self where the new Scope is created with the flags 3988935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ScopeFlags, but only when ManageScope is true (the default). If 3998935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ManageScope is false, this object does nothing. 4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true) 4018935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor : Self(Self) { 4028935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (ManageScope) 4038935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->EnterScope(ScopeFlags); 4048935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor else 4058935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor this->Self = 0; 4068935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4078935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 4088935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // Exit - Exit the scope associated with this object now, rather 4098935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // than waiting until the object is destroyed. 4108935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor void Exit() { 4118935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (Self) { 4128935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->ExitScope(); 4138935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self = 0; 4148935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4158935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4168935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 4178935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ~ParseScope() { 4188935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Exit(); 4198935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4208935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor }; 4218935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterScope - Start a new scope. 4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterScope(unsigned ScopeFlags); 4241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExitScope - Pop a scope off the scope stack. 4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ExitScope(); 4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Diagnostic Emission and Error recovery. 43015faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 4313cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 4323cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); 43315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 4341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SuggestParentheses(SourceLocation Loc, unsigned DK, 4354b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceRange ParenRange); 4364b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipUntil - Read tokens until we get to the specified token, then consume 43882c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff /// it (unless DontConsume is true). Because we cannot guarantee that the 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// token will ever occur, this skips to the next token, or to some likely 4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// character. 4421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If SkipUntil finds the specified token, it returns true, otherwise it 4441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returns false. 4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true, 4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool DontConsume = false) { 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SkipUntil(&T, 1, StopAtSemi, DontConsume); 4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true, 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool DontConsume = false) { 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind TokArray[] = {T1, T2}; 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SkipUntil(TokArray, 2, StopAtSemi, DontConsume); 4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool StopAtSemi = true, bool DontConsume = false); 4567ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4584cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Lexing and parsing of C++ inline methods. 4594cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 4604cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis struct LexedMethod { 461b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner Action::DeclPtrTy D; 46272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens Toks; 463d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 464d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 465d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 466d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 467d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 468d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 469d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor explicit LexedMethod(Action::DeclPtrTy MD) : D(MD), TemplateScope(false) {} 4704cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis }; 4714cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 47272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedDefaultArgument - Keeps track of a parameter that may 47372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument that cannot be parsed yet because it 47472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// occurs within a member function declaration inside the class 47572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// (C++ [class.mem]p2). 47672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedDefaultArgument { 4771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit LateParsedDefaultArgument(Action::DeclPtrTy P, 47872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks = 0) 47972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor : Param(P), Toks(Toks) { } 48072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 48172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Param - The parameter declaration for this parameter. 482b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner Action::DeclPtrTy Param; 48372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 48472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Toks - The sequence of tokens that comprises the default 48572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument expression, not including the '=' or the terminating 48672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// ')' or ','. This will be NULL for parameters that have no 48772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// default argument. 48872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks; 48972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 4901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDeclaration - A method declaration inside a class that 49272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// contains at least one entity whose parsing needs to be delayed 49372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// until the class itself is completely-defined, such as a default 49472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument (C++ [class.mem]p2). 49572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedMethodDeclaration { 4961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit LateParsedMethodDeclaration(Action::DeclPtrTy M) 497d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor : Method(M), TemplateScope(false) { } 49872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 49972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Method - The method declaration. 500b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner Action::DeclPtrTy Method; 50172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 502d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 503d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 504d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 505d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// DefaultArgs - Contains the parameters of the function and 50872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// their default arguments. At least one of the parameters will 50972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument, but all of the parameters of the 51072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// method will be stored so that they can be reintroduced into 5111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// scope at the appropriate times. 51272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor llvm::SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; 51372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 51472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 51572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDecls - During parsing of a top (non-nested) C++ 51672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// class, its method declarations that contain parts that won't be 51772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// parsed until after the definiton is completed (C++ [class.mem]p2), 51872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// the method declarations will be stored here with the tokens that 51972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// will be parsed to create those entities. 52072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor typedef std::list<LateParsedMethodDeclaration> LateParsedMethodDecls; 52172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 5224cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// LexedMethodsForTopClass - During parsing of a top (non-nested) C++ class, 5234cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// its inline method definitions and the inline method definitions of its 5244cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// nested classes are lexed and stored here. 52572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor typedef std::list<LexedMethod> LexedMethodsForTopClass; 52672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 5276569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Representation of a class that has been parsed, including 5286569d68745c8213709740337d2be52b031384f58Douglas Gregor /// any member function declarations or definitions that need to be 5296569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed after the corresponding top-level class is complete. 5306569d68745c8213709740337d2be52b031384f58Douglas Gregor struct ParsingClass { 5311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass) 5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : TopLevelClass(TopLevelClass), TemplateScope(false), 5336569d68745c8213709740337d2be52b031384f58Douglas Gregor TagOrTemplate(TagOrTemplate) { } 5346569d68745c8213709740337d2be52b031384f58Douglas Gregor 5356569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this is a "top-level" class, meaning that it is 5366569d68745c8213709740337d2be52b031384f58Douglas Gregor /// not nested within another class. 5376569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TopLevelClass : 1; 5386569d68745c8213709740337d2be52b031384f58Douglas Gregor 5396569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this class had an associated template 5406569d68745c8213709740337d2be52b031384f58Douglas Gregor /// scope. When true, TagOrTemplate is a template declaration; 5416569d68745c8213709740337d2be52b031384f58Douglas Gregor /// othewise, it is a tag declaration. 5426569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TemplateScope : 1; 5436569d68745c8213709740337d2be52b031384f58Douglas Gregor 5446569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The class or class template whose definition we are parsing. 5456569d68745c8213709740337d2be52b031384f58Douglas Gregor DeclPtrTy TagOrTemplate; 54672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 54772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// MethodDecls - Method declarations that contain pieces whose 54872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// parsing will be delayed until the class is fully defined. 54972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor LateParsedMethodDecls MethodDecls; 55072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 55172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// MethodDefs - Methods whose definitions will be parsed once the 55272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// class has been fully defined. 55372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor LexedMethodsForTopClass MethodDefs; 5546569d68745c8213709740337d2be52b031384f58Douglas Gregor 5556569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Nested classes inside this class. 5566569d68745c8213709740337d2be52b031384f58Douglas Gregor llvm::SmallVector<ParsingClass*, 4> NestedClasses; 55772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 5584cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 5596569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The stack of classes that is currently being 5606569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed. Nested and local classes will be pushed onto this stack 5616569d68745c8213709740337d2be52b031384f58Douglas Gregor /// when they are parsed, and removed afterward. 5626569d68745c8213709740337d2be52b031384f58Douglas Gregor std::stack<ParsingClass *> ClassStack; 5634cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 5646569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingClass &getCurrentClass() { 5656569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "No lexed method stacks!"); 5666569d68745c8213709740337d2be52b031384f58Douglas Gregor return *ClassStack.top(); 5674cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 5684cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 56954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// \brief RAII object used to inform the actions that we're 57054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// currently parsing a declaration. This is active when parsing a 57154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// variable's initializer, but not when parsing the body of a 57254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// class or function definition. 57354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclRAIIObject { 57454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Action &Actions; 57554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Action::ParsingDeclStackState State; 57654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall bool Popped; 57754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 57854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 57954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) { 58054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 58154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 58254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 58354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ~ParsingDeclRAIIObject() { 58454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 58554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 58654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 58754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Resets the RAII object for a new declaration. 58854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void reset() { 58954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 59054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 59154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 59254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 59354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Signals that the context was completed without an appropriate 59454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// declaration being parsed. 59554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 59654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall pop(DeclPtrTy()); 59754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 59854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 59954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void complete(DeclPtrTy D) { 60054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall assert(!Popped && "ParsingDeclaration has already been popped!"); 60154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall pop(D); 60254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 60354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 60454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall private: 60554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void push() { 60654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall State = Actions.PushParsingDeclaration(); 60754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = false; 60854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 60954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 61054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void pop(DeclPtrTy D) { 61154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall if (!Popped) { 61254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Actions.PopParsingDeclaration(State, D); 61354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = true; 61454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 61554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 61654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 61754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 61854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a DeclSpec. 61954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclSpec : public DeclSpec { 62054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 62154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 62254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 62354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclSpec(Parser &P) : ParsingRAII(P) { 62454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 62554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 62654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void complete(DeclPtrTy D) { 62754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 62854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 62954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 63054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 63154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.abort(); 63254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 63354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 63454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 63554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a declarator. 63654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclarator : public Declarator { 63754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 63854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 63954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 64054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C) 64154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall : Declarator(DS, C), ParsingRAII(P) { 64254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 64354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 64454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall const ParsingDeclSpec &getDeclSpec() const { 64554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec()); 64654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 64754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 64854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclSpec &getMutableDeclSpec() const { 64954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return const_cast<ParsingDeclSpec&>(getDeclSpec()); 65054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 65154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 65254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void clear() { 65354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Declarator::clear(); 65454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.reset(); 65554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 65654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 65754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void complete(DeclPtrTy D) { 65854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 65954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 66054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 66154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 6621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief RAII object used to 6636569d68745c8213709740337d2be52b031384f58Douglas Gregor class ParsingClassDefinition { 6646569d68745c8213709740337d2be52b031384f58Douglas Gregor Parser &P; 6656569d68745c8213709740337d2be52b031384f58Douglas Gregor bool Popped; 6666569d68745c8213709740337d2be52b031384f58Douglas Gregor 6676569d68745c8213709740337d2be52b031384f58Douglas Gregor public: 6681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsingClassDefinition(Parser &P, DeclPtrTy TagOrTemplate, bool TopLevelClass) 6691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : P(P), Popped(false) { 6706569d68745c8213709740337d2be52b031384f58Douglas Gregor P.PushParsingClass(TagOrTemplate, TopLevelClass); 6716569d68745c8213709740337d2be52b031384f58Douglas Gregor } 6726569d68745c8213709740337d2be52b031384f58Douglas Gregor 6736569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Pop this class of the stack. 6741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void Pop() { 6756569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!Popped && "Nested class has already been popped"); 6766569d68745c8213709740337d2be52b031384f58Douglas Gregor Popped = true; 6776569d68745c8213709740337d2be52b031384f58Douglas Gregor P.PopParsingClass(); 6786569d68745c8213709740337d2be52b031384f58Douglas Gregor } 6796569d68745c8213709740337d2be52b031384f58Douglas Gregor 6801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ~ParsingClassDefinition() { 6816569d68745c8213709740337d2be52b031384f58Douglas Gregor if (!Popped) 6821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump P.PopParsingClass(); 6836569d68745c8213709740337d2be52b031384f58Douglas Gregor } 6846569d68745c8213709740337d2be52b031384f58Douglas Gregor }; 6856569d68745c8213709740337d2be52b031384f58Douglas Gregor 6864d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief Contains information about any template-specific 6874d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// information that has been parsed prior to parsing declaration 6884d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// specifiers. 6894d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor struct ParsedTemplateInfo { 6901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsedTemplateInfo() 6914d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { } 6924d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 6934d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ParsedTemplateInfo(TemplateParameterLists *TemplateParams, 694c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool isSpecialization, 695c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool lastParameterListWasEmpty = false) 6964d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(isSpecialization? ExplicitSpecialization : Template), 697c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor TemplateParams(TemplateParams), 698c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(lastParameterListWasEmpty) { } 6994d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 70045f965581935791a018df829a14dff53c1dd8f47Douglas Gregor explicit ParsedTemplateInfo(SourceLocation ExternLoc, 70145f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation TemplateLoc) 7021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Kind(ExplicitInstantiation), TemplateParams(0), 703c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), 704c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(false){ } 7054d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 7064d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The kind of template we are parsing. 7074d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor enum { 7084d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are not parsing a template at all. 7094d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor NonTemplate = 0, 7104d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing a template declaration. 7114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor Template, 7124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit specialization. 7134d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitSpecialization, 7144d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit instantiation. 7154d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitInstantiation 7164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } Kind; 7174d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 7184d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The template parameter lists, for template declarations 7194d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// and explicit specializations. 7204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParameterLists *TemplateParams; 7214d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 72245f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// \brief The location of the 'extern' keyword, if any, for an explicit 72345f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// instantiation 72445f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation ExternLoc; 7251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7264d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The location of the 'template' keyword, for an explicit 7274d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// instantiation. 7284d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation TemplateLoc; 729c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor 730c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor /// \brief Whether the last template parameter list was empty. 731c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool LastParameterListWasEmpty; 7324d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor }; 7331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73437b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void PushParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass); 73537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void DeallocateParsedClasses(ParsingClass *Class); 73637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void PopParsingClass(); 73737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor 73837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor DeclPtrTy ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D, 73937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor const ParsedTemplateInfo &TemplateInfo); 74037b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDeclarations(ParsingClass &Class); 74137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDefs(ParsingClass &Class); 7421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 74337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor CachedTokens &Toks, 74437b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor tok::TokenKind EarlyAbortIf = tok::unknown, 74537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor bool ConsumeFinalToken = true); 7464d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 7474cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.9: External Definitions. 749bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseExternalDeclaration(CXX0XAttributeList Attr); 7501426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor bool isDeclarationAfterDeclarator(); 7511426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor bool isStartOfFunctionDefinition(); 752bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(AttributeList *Attr, 7535aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson AccessSpecifier AS = AS_none); 7543acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS, 7553acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AttributeList *Attr, 7563acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AccessSpecifier AS = AS_none); 7573acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian 75854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclPtrTy ParseFunctionDefinition(ParsingDeclarator &D, 75952591bf224b2c43e2b00e265bb8599a620081925Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseKNRParamDeclarations(Declarator &D); 761ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 762ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the simple-asm. 763ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl OwningExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0); 764effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl OwningExprResult ParseAsmStringLiteral(); 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7663536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Objective-C External Declarations 7671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy ParseObjCAtDirectives(); 768b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); 7691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, 770dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff AttributeList *prefixAttrs = 0); 7711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl, 77260fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc); 773b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &P, 77471b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &PLocs, 7751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool WarnOnDeclarations, 77671b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, 777e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SourceLocation &EndProtoLoc); 778b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl, 779c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner tok::ObjCKeywordKind contextKey); 780b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc, 781b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *prefixAttrs = 0); 7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 783b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ObjCImpDecl; 78463e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian llvm::SmallVector<DeclPtrTy, 4> PendingObjCImpDecl; 7850416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 786b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtImplementationDeclaration(SourceLocation atLoc); 787782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek DeclPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd); 788b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtAliasDeclaration(SourceLocation atLoc); 789b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCPropertySynthesize(SourceLocation atLoc); 790b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCPropertyDynamic(SourceLocation atLoc); 7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7922fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); 79334870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner // Definitions for Objective-c context sensitive keywords recognition. 79434870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner enum ObjCTypeQual { 79534870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, 79634870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_NumQuals 79734870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner }; 798a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; 7991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 800335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian bool isTokIdentifier_in() const; 801d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 802a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek TypeTy *ParseObjCTypeName(ObjCDeclSpec &DS); 803294494e1cce92043562b4680c613df7fd028c02eSteve Naroff void ParseObjCMethodRequirement(); 804b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCMethodPrototype(DeclPtrTy classOrCat, 805c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); 806b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, 807b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy classDecl, 80800933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); 8094ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor void ParseObjCPropertyAttribute(ObjCDeclSpec &DS, DeclPtrTy ClassDecl, 8104ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor DeclPtrTy *Methods, unsigned NumMethods); 8111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 812b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCMethodDefinition(); 8131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.5: Expressions. 8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8172f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParseExpression(); 8182f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParseConstantExpression(); 8192f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl // Expr that doesn't include commas. 8202f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParseAssignmentExpression(); 8212f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 822d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); 8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 824adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman OwningExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); 825adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman 826d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseRHSOfBinaryExpression(OwningExprResult LHS, 827d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl unsigned MinPrec); 828ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl OwningExprResult ParseCastExpression(bool isUnaryExpression, 829f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAddressOfOperand, 8302ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman bool &NotCastExpr, 831f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian TypeTy *TypeOfCast); 832f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis OwningExprResult ParseCastExpression(bool isUnaryExpression, 8332ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman bool isAddressOfOperand = false, 834f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian TypeTy *TypeOfCast = 0); 8352f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParsePostfixExpressionSuffix(OwningExprResult LHS); 836d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseSizeofAlignofExpression(); 837d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseBuiltinPrimaryExpression(); 8381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8395ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis OwningExprResult ParseExprAfterTypeofSizeofAlignof(const Token &OpTok, 8405ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis bool &isCastExpr, 8415ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis TypeTy *&CastTy, 8425ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis SourceRange &CastRange); 8430cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 844a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl static const unsigned ExprListSize = 12; 845a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl typedef llvm::SmallVector<ExprTy*, ExprListSize> ExprListTy; 846a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl typedef llvm::SmallVector<SourceLocation, ExprListSize> CommaLocsTy; 8470cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 8480cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis /// ParseExpressionList - Used for C/C++ (argument-)expression-list. 8499c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor bool ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs, 8509c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor void (Action::*Completer)(Scope *S, void *Data, 8519c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor ExprTy **Args, 8529c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor unsigned NumArgs) = 0, 8539c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor void *Data = 0); 854d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl 8555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParenParseOption - Control what ParseParenExpression will parse. 8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ParenParseOption { 8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SimpleExpr, // Only parse '(' expression ')' 8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundStmt, // Also allow '(' compound-statement ')' 8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}' 8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CastExpr // Also allow '(' type-name ')' <anything> 8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 862d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseParenExpression(ParenParseOption &ExprType, 8630350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis bool stopIfCastExpr, 864f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian TypeTy *TypeOfCast, 865d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl TypeTy *&CastTy, 866d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl SourceLocation &RParenLoc); 8671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 868f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis OwningExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, 869f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis TypeTy *&CastTy, 870f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis SourceLocation LParenLoc, 871f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis SourceLocation &RParenLoc); 8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 873d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis OwningExprResult ParseCompoundLiteralExpression(TypeTy *Ty, 874d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation LParenLoc, 875d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation RParenLoc); 8761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87720df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseStringLiteralExpression(); 878eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 879eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 880eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // C++ Expressions 881ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl OwningExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); 8824bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis 8831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 8842dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor TypeTy *ObjectType, 88508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner bool EnteringContext); 8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 5.2p1: C++ Casts 88920df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXCasts(); 8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 892c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // C++ 5.2p1: C++ Type Identification 89320df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXTypeid(); 894c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 895c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl //===--------------------------------------------------------------------===// 8964cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 9.3.2: C++ 'this' pointer 89720df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXThis(); 8984cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 8994cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 90050dd289f45738ed22b7583d52ed2525b927042ffChris Lattner // C++ 15: C++ Throw Expression 90120df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseThrowExpression(); 902ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc is filled with the location of the last token of the specification. 9037dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl bool ParseExceptionSpecification(SourceLocation &EndLoc, 904ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl llvm::SmallVector<TypeTy*, 2> &Exceptions, 905ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl llvm::SmallVector<SourceRange, 2> &Ranges, 9067dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl bool &hasAnyExceptionSpec); 90750dd289f45738ed22b7583d52ed2525b927042ffChris Lattner 90850dd289f45738ed22b7583d52ed2525b927042ffChris Lattner //===--------------------------------------------------------------------===// 9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 2.13.5: C++ Boolean Literals 91020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXBoolLiteral(); 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 913987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // C++ 5.2.3: Explicit type conversion (functional notation) 91420df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); 915987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 916987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 917987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// This should only be called when the current token is known to be part of 918987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// simple-type-specifier. 919987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); 920987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 9212f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); 9222f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 923987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 9244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // C++ 5.3.4 and 5.3.5: C++ new and delete 925cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl bool ParseExpressionListOrTypeId(ExprListTy &Exprs, Declarator &D); 9264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDirectNewDeclarator(Declarator &D); 92759232d35f5820e334b6c8b007ae8006f4390055dChris Lattner OwningExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); 92859232d35f5820e334b6c8b007ae8006f4390055dChris Lattner OwningExprResult ParseCXXDeleteExpression(bool UseGlobal, 92959232d35f5820e334b6c8b007ae8006f4390055dChris Lattner SourceLocation Start); 9304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 9314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl //===--------------------------------------------------------------------===// 93299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor // C++ if/switch/while condition expression. 93399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor bool ParseCXXCondition(OwningExprResult &ExprResult, DeclPtrTy &DeclResult); 93471b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 93571b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 93612e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor // C++ types 93712e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor 93812e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor //===--------------------------------------------------------------------===// 9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7.8: Initialization. 9401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9410eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// ParseInitializer 9420eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// initializer: [C99 6.7.8] 9430eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// assignment-expression 9440eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// '{' ... 94520df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseInitializer() { 9460eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner if (Tok.isNot(tok::l_brace)) 94720df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ParseAssignmentExpression(); 9480eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner return ParseBraceInitializer(); 9490eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner } 95020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseBraceInitializer(); 9515908a9293b88a3da57ae59b522275d05e1ab11e0Douglas Gregor OwningExprResult ParseInitializerWithPotentialDesignator(); 9521d922960e083906a586609ac6978678147250177Sebastian Redl 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 954296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // clang Expressions 9551d922960e083906a586609ac6978678147250177Sebastian Redl 9561d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseBlockLiteralExpression(); // ^{...} 957296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff 958296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff //===--------------------------------------------------------------------===// 9595508518a2702b00be3b15a26d772bde968972f54Anders Carlsson // Objective-C Expressions 9601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96114dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner bool isTokObjCMessageIdentifierReceiver() const { 96214dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner if (!Tok.is(tok::identifier)) 96314dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner return false; 9641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96547246be8ac5b0ddde6c402b8fc6946b6135487b5Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 966b696ea3a0693798daeafd896d77f0b8f1fec3cc5Douglas Gregor if (Actions.getTypeName(*II, Tok.getLocation(), CurScope)) 96714dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner return true; 9681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96947246be8ac5b0ddde6c402b8fc6946b6135487b5Chris Lattner return II == Ident_super; 97014dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner } 9711d922960e083906a586609ac6978678147250177Sebastian Redl 9721d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCAtExpression(SourceLocation AtLocation); 9731d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCStringLiteral(SourceLocation AtLoc); 9741d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); 9751d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); 9761d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); 9771d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCMessageExpression(); 9781d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, 9791d922960e083906a586609ac6978678147250177Sebastian Redl SourceLocation NameLoc, 9801d922960e083906a586609ac6978678147250177Sebastian Redl IdentifierInfo *ReceiverName, 9811d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr); 9821d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseAssignmentExprWithObjCMessageExprStart( 9831d922960e083906a586609ac6978678147250177Sebastian Redl SourceLocation LBracloc, SourceLocation NameLoc, 9841d922960e083906a586609ac6978678147250177Sebastian Redl IdentifierInfo *ReceiverName, ExprArg ReceiverExpr); 98561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 9865508518a2702b00be3b15a26d772bde968972f54Anders Carlsson //===--------------------------------------------------------------------===// 9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.8: Statements and Blocks. 98861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 98961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult ParseStatement() { 99061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl return ParseStatementOrDeclaration(true); 99161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 99261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult ParseStatementOrDeclaration(bool OnlyStatement = false); 993bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseLabeledStatement(AttributeList *Attr); 994bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseCaseStatement(AttributeList *Attr); 995bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseDefaultStatement(AttributeList *Attr); 996bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseCompoundStatement(AttributeList *Attr, 997bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool isStmtExpr = false); 99861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult ParseCompoundStatementBody(bool isStmtExpr = false); 99999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor bool ParseParenExprOrCondition(OwningExprResult &ExprResult, 100099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor DeclPtrTy &DeclResult); 1001bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseIfStatement(AttributeList *Attr); 1002bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseSwitchStatement(AttributeList *Attr); 1003bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseWhileStatement(AttributeList *Attr); 1004bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseDoStatement(AttributeList *Attr); 1005bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseForStatement(AttributeList *Attr); 1006bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseGotoStatement(AttributeList *Attr); 1007bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseContinueStatement(AttributeList *Attr); 1008bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseBreakStatement(AttributeList *Attr); 1009bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseReturnStatement(AttributeList *Attr); 10109a920342707e384473b464528d2fd286e8c70353Sebastian Redl OwningStmtResult ParseAsmStatement(bool &msAsm); 10119a920342707e384473b464528d2fd286e8c70353Sebastian Redl OwningStmtResult FuzzyParseMicrosoftAsmStatement(); 1012ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<IdentifierInfo *> &Names, 1013ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVectorImpl<ExprTy *> &Constraints, 1014ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVectorImpl<ExprTy *> &Exprs); 1015a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1016a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1017a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // C++ 6: Statements and Blocks 1018a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1019bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseCXXTryBlock(AttributeList *Attr); 1020d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl OwningStmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc); 1021a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl OwningStmtResult ParseCXXCatchBlock(); 1022a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1023a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1024a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // Objective-C Statements 1025a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 102643bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCAtStatement(SourceLocation atLoc); 102743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCTryStmt(SourceLocation atLoc); 102843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCThrowStmt(SourceLocation atLoc); 102943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); 1030b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7: Declarations. 103467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall 103567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// A context for parsing declaration specifiers. TODO: flesh this 103667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// out, there are other significant restrictions on specifiers than 103767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// would be best implemented in the parser. 103867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall enum DeclSpecContext { 103967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DSC_normal, // normal context 10400efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_class, // class context, enables 'friend' 10410efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_top_level // top-level/namespace declaration context 104267d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall }; 10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1044bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseDeclaration(unsigned Context, SourceLocation &DeclEnd, 1045bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList Attr); 1046cd1477562e7cf03279850885583d615e1f631dd4Chris Lattner DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context, 1047bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 1048bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttributeList *Attr); 104954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, 1050d8ac05753dc4506224d445ff98399c01da3136e5John McCall bool AllowFunctionDefinitions, 1051d8ac05753dc4506224d445ff98399c01da3136e5John McCall SourceLocation *DeclEnd = 0); 1052e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor DeclPtrTy ParseDeclarationAfterDeclarator(Declarator &D, 1053e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1054b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseFunctionStatementBody(DeclPtrTy Decl); 1055d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl DeclPtrTy ParseFunctionTryBlock(DeclPtrTy Decl); 1056d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 1057f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, 10584d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 1059e40c295d017a8f75a945fe9ed2aa9d8bb7a7341aChris Lattner AccessSpecifier AS); 10600efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); 10611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseDeclarationSpecifiers(DeclSpec &DS, 10624d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 106367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall AccessSpecifier AS = AS_none, 106467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DeclSpecContext DSC = DSC_normal); 10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid, 10667a0ab5f387722c83e19c7133b46b16988eb19e45Chris Lattner const char *&PrevSpec, 1067fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID, 10684d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 10694d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseSpecifierQualifierList(DeclSpec &DS); 10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1072a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void ParseObjCTypeQualifierList(ObjCDeclSpec &DS); 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10744c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, 10754c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner AccessSpecifier AS = AS_none); 1076b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseEnumBody(SourceLocation StartLoc, DeclPtrTy TagDecl); 10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, 1078b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy TagDecl); 1079bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1080bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct FieldCallback { 1081bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall virtual DeclPtrTy invoke(FieldDeclarator &Field) = 0; 10826c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual ~FieldCallback() {} 10836c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall 10846c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall private: 10856c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual void _anchor(); 1086bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall }; 1087d0014540005f2a5ab837365db6bd40f479406758John McCall struct ObjCPropertyCallback; 1088bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1089bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback); 10901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1091eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isDeclarationSpecifier(); 1092eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isTypeSpecifierQualifier(); 10935f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff bool isTypeQualifier() const; 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isDeclarationStatement - Disambiguates between a declaration or an 10965404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// expression statement, when parsing function bodies. 10975404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for declaration, false for expression. 10985404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isDeclarationStatement() { 10995404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis if (getLang().CPlusPlus) 11005404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isCXXDeclarationStatement(); 11015404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isDeclarationSpecifier(); 11025404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 11035404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1104bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// isSimpleDeclaration - Disambiguates between a declaration or an 1105bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// expression, mainly used for the C 'clause-1' or the C++ 1106bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis // 'for-init-statement' part of a 'for' statement. 1107bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// Returns true for declaration, false for expression. 1108bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis bool isSimpleDeclaration() { 1109bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis if (getLang().CPlusPlus) 1110bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis return isCXXSimpleDeclaration(); 1111bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis return isDeclarationSpecifier(); 1112bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis } 1113bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis 11140efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief Starting with a scope specifier, identifier, or 11150efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id that refers to the current class, determine whether 11160efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// this is a constructor declarator. 11170efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor bool isConstructorDeclarator(); 11180efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 11198b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// \brief Specifies the context in which type-id/expression 11208b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// disambiguation will occur. 11218b642592a35167a3780074e78674e0bece87c40cDouglas Gregor enum TentativeCXXTypeIdContext { 11228b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdInParens, 11238b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdAsTemplateArgument 11248b642592a35167a3780074e78674e0bece87c40cDouglas Gregor }; 11258b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 11268b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 112778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know 112878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// whether the parens contain an expression or a type-id. 112978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// Returns true for a type-id and false for an expression. 1130f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens(bool &isAmbiguous) { 113178c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis if (getLang().CPlusPlus) 1132f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(TypeIdInParens, isAmbiguous); 1133f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis isAmbiguous = false; 113478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis return isTypeSpecifierQualifier(); 113578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis } 1136f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens() { 1137f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1138f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isTypeIdInParens(isAmbiguous); 1139f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 114078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 11415404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXDeclarationStatement - C++-specialized function that disambiguates 11425404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a declaration or an expression statement, when parsing function 11435404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// bodies. Returns true for declaration, false for expression. 11445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXDeclarationStatement(); 11455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 11465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXSimpleDeclaration - C++-specialized function that disambiguates 11475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a simple-declaration or an expression-statement. 11485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 11495404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 11505404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns false if the statement is disambiguated as expression. 11515404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXSimpleDeclaration(); 11525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 11535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXFunctionDeclarator - Disambiguates between a function declarator or 11545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// a constructor-style initializer, when parsing declaration statements. 11555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for function declarator and false for constructor-style 1156e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to 1157259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis /// indicate that the parens were disambiguated as function declarator. 11585404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 11595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1160e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis bool isCXXFunctionDeclarator(bool warnIfAmbiguous); 11615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1162a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// isCXXConditionDeclaration - Disambiguates between a declaration or an 1163a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// expression for a condition of a if/switch/while/for statement. 1164a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 1165a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1166a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis bool isCXXConditionDeclaration(); 1167a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis 1168f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); 1169f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context) { 1170f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1171f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(Context, isAmbiguous); 1172f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 117378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 1174b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult - Used as the result value for functions whose purpose is to 1175b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// disambiguate C++ constructs by "tentatively parsing" them. 1176b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// This is a class instead of a simple enum because the implicit enum-to-bool 1177b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// conversions may cause subtle bugs. 1178b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis class TPResult { 1179b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis enum Result { 1180b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_true, 1181b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_false, 1182b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_ambiguous, 1183b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_error 1184b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis }; 1185b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis Result Res; 1186b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult(Result result) : Res(result) {} 1187b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis public: 1188b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult True() { return TPR_true; } 1189b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult False() { return TPR_false; } 1190b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Ambiguous() { return TPR_ambiguous; } 1191b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Error() { return TPR_error; } 1192b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis 1193b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator==(const TPResult &RHS) const { return Res == RHS.Res; } 1194b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; } 1195b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis }; 1196b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis 1197b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a 1198b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// declaration specifier, TPResult::False() if it is not, 1199b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult::Ambiguous() if it could be either a decl-specifier or a 1200b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// function-style cast, and TPResult::Error() if a parsing error was 1201b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// encountered. 12025404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Doesn't consume tokens. 1203b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult isCXXDeclarationSpecifier(); 12045404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 12055404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // "Tentative parsing" functions, used for disambiguation. If a parsing error 1206b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // is encountered they will return TPResult::Error(). 1207b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // Returning TPResult::True()/False() indicates that the ambiguity was 1208b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates 1209b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // that more tentative parsing is necessary for disambiguation. 12105404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // They all consume tokens, so backtracking should be used after calling them. 12115404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1212b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseDeclarationSpecifier(); 1213b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseSimpleDeclaration(); 1214b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseTypeofSpecifier(); 1215b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseInitDeclaratorList(); 121678c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); 1217b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseParameterDeclarationClause(); 1218b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseFunctionDeclarator(); 1219b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseBracketDeclarator(); 12205404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1221ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl TypeResult ParseTypeName(SourceRange *Range = 0); 122298eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump void ParseBlockId(); 1223ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 1224ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the attribute list. 1225bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList ParseCXX0XAttributes(SourceLocation *EndLoc = 0); 1226bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttributeList *ParseGNUAttributes(SourceLocation *EndLoc = 0); 1227290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0); 1228290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0); 1229d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff void ParseTypeofSpecifier(DeclSpec &DS); 12306fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson void ParseDecltypeSpecifier(DeclSpec &DS); 1231bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 1232bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningExprResult ParseCXX0XAlignArgument(SourceLocation Start); 1233eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1234eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to 1235eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// enter a new C++ declarator scope and exit it when the function is 1236eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// finished. 1237eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis class DeclaratorScopeObj { 1238eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis Parser &P; 1239751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis CXXScopeSpec &SS; 1240f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis bool EnteredScope; 1241f7f3d0db754db0500b56d49ac19f795f13965912John McCall bool CreatedScope; 1242eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis public: 1243f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) 1244f7f3d0db754db0500b56d49ac19f795f13965912John McCall : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} 1245eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1246eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis void EnterDeclaratorScope() { 12472bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis assert(!EnteredScope && "Already entered the scope!"); 1248f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was not set!"); 1249f7f3d0db754db0500b56d49ac19f795f13965912John McCall 1250f7f3d0db754db0500b56d49ac19f795f13965912John McCall CreatedScope = true; 1251f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.EnterScope(0); // Not a decl scope. 1252f7f3d0db754db0500b56d49ac19f795f13965912John McCall 12537a1dc562d4ad59237ed9fe7e8cef56f9eaa7a26cJohn McCall if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS)) 12543fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor EnteredScope = true; 1255eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1256eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1257eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis ~DeclaratorScopeObj() { 1258f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis if (EnteredScope) { 1259f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was cleared ?"); 12600a59acb9ae36077ce46fb2807956c5e84f0f6837Douglas Gregor P.Actions.ActOnCXXExitDeclaratorScope(P.CurScope, SS); 1261f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis } 1262f7f3d0db754db0500b56d49ac19f795f13965912John McCall if (CreatedScope) 1263f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.ExitScope(); 1264eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1265eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis }; 12661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseDeclarator - Parse and verify a newly-initialized declarator. 12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDeclarator(Declarator &D); 12694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl /// A function that parses a variant of direct-declarator. 12704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef void (Parser::*DirectDeclParseFunction)(Declarator&); 12714c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDeclaratorInternal(Declarator &D, 12724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl DirectDeclParseFunction DirectDeclParser); 1273bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, 1274bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool CXX0XAttributesAllowed = true); 12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDirectDeclarator(Declarator &D); 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseParenDeclarator(Declarator &D); 12777399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, 12787399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner AttributeList *AttrList = 0, 12797399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner bool RequiresArg = false); 128066d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc, 128166d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner Declarator &D); 12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseBracketDeclarator(Declarator &D); 12831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12848f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner //===--------------------------------------------------------------------===// 12858f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner // C++ 7: Declarations [dcl.dcl] 12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1287bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool isCXX0XAttributeSpecifier(bool FullLookahead = false, 1288bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt tok::TokenKind *After = 0); 1289bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 129097144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseNamespace(unsigned Context, SourceLocation &DeclEnd); 12913acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian DeclPtrTy ParseLinkage(ParsingDeclSpec &DS, unsigned Context); 129297144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseUsingDirectiveOrDeclaration(unsigned Context, 1293bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 1294bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList Attrs); 129597144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseUsingDirective(unsigned Context, SourceLocation UsingLoc, 1296bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 1297bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttributeList *Attr); 129897144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc, 1299595adc1795cc2c079ef5876100e01acd10a0504aAnders Carlsson SourceLocation &DeclEnd, 1300595adc1795cc2c079ef5876100e01acd10a0504aAnders Carlsson AccessSpecifier AS = AS_none); 130197144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseStaticAssertDeclaration(SourceLocation &DeclEnd); 130203bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson DeclPtrTy ParseNamespaceAlias(SourceLocation NamespaceLoc, 130397144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation AliasLoc, IdentifierInfo *Alias, 130497144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation &DeclEnd); 13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1306e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 1307e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 9: classes [class] and C structs/unions. 13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeResult ParseClassName(SourceLocation &EndLocation, 1309d33c868d386ef47c2942e2dbff0d9955a8591fa9Fariborz Jahanian const CXXScopeSpec *SS = 0, 1310d33c868d386ef47c2942e2dbff0d9955a8591fa9Fariborz Jahanian bool DestrExpected = false); 13114c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, 13121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclSpec &DS, 13134d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 131406c0fecd197fef21e265a41bca8dc5022de1f864Douglas Gregor AccessSpecifier AS = AS_none); 13154cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType, 1316b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy TagDecl); 131737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseCXXClassMemberDeclaration(AccessSpecifier AS, 131837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1319b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseConstructorInitializer(DeclPtrTy ConstructorDecl); 1320b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner MemInitResult ParseMemInitializer(DeclPtrTy ConstructorDecl); 1321d33133cdc1af466f9c276249b2621be03867888bEli Friedman void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, 1322d33133cdc1af466f9c276249b2621be03867888bEli Friedman DeclPtrTy ThisDecl); 1323e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1324e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 1325e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 10: Derived classes [class.derived] 1326b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseBaseClause(DeclPtrTy ClassDecl); 1327b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner BaseResult ParseBaseSpecifier(DeclPtrTy ClassDecl); 13281b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor AccessSpecifier getAccessSpecifierIfPresent() const; 13291cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor 13303f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 13313f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Name, 13323f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation NameLoc, 13333f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool EnteringContext, 13342d1c21414199a7452f122598189363a3922605b1Douglas Gregor TypeTy *ObjectType, 13353f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &Id); 1336ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, 1337ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor TypeTy *ObjectType, 1338ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &Result); 13393f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, 134002a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowDestructorName, 134102a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowConstructorName, 13422d1c21414199a7452f122598189363a3922605b1Douglas Gregor TypeTy *ObjectType, 13433f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &Result); 13443f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 13451cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor //===--------------------------------------------------------------------===// 1346adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14: Templates [temp] 1347b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner typedef llvm::SmallVector<DeclPtrTy, 4> TemplateParameterList; 1348c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 1349adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14.1: Template Parameters [temp.param] 13504d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor DeclPtrTy ParseDeclarationStartingWithTemplate(unsigned Context, 13514d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation &DeclEnd, 13524d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AccessSpecifier AS = AS_none); 1353b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTemplateDeclarationOrSpecialization(unsigned Context, 135497144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation &DeclEnd, 13554d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AccessSpecifier AS); 13561426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor DeclPtrTy ParseSingleDeclarationAfterTemplate( 13571426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor unsigned Context, 13584d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 13591426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor SourceLocation &DeclEnd, 13601426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor AccessSpecifier AS=AS_none); 13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseTemplateParameters(unsigned Depth, 1362c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor TemplateParameterList &TemplateParams, 13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation &LAngleLoc, 1364c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor SourceLocation &RAngleLoc); 1365c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor bool ParseTemplateParameterList(unsigned Depth, 1366c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor TemplateParameterList &TemplateParams); 136798440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor bool isStartOfTemplateTypeParameter(); 1368b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTemplateParameter(unsigned Depth, unsigned Position); 1369b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTypeParameter(unsigned Depth, unsigned Position); 1370b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); 1371b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); 1372d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor // C++ 14.3: Template arguments [temp.arg] 1373314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor typedef llvm::SmallVector<ParsedTemplateArgument, 16> TemplateArgList; 1374cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 13757532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor bool ParseTemplateIdAfterTemplateName(TemplateTy Template, 13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateNameLoc, 1377cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor const CXXScopeSpec *SS, 1378cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor bool ConsumeLastToken, 1379cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &LAngleLoc, 1380cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateArgList &TemplateArgs, 1381cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &RAngleLoc); 1382cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 1383c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, 138439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor const CXXScopeSpec *SS, 1385ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &TemplateName, 138639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor SourceLocation TemplateKWLoc = SourceLocation(), 138739a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor bool AllowTypeAnnotation = true); 138831a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor void AnnotateTemplateIdTokenAsType(const CXXScopeSpec *SS = 0); 1389314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); 1390788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor ParsedTemplateArgument ParseTemplateTemplateArgument(); 1391314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor ParsedTemplateArgument ParseTemplateArgument(); 139245f965581935791a018df829a14dff53c1dd8f47Douglas Gregor DeclPtrTy ParseExplicitInstantiation(SourceLocation ExternLoc, 13931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateLoc, 13944d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation &DeclEnd); 139564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 139664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl //===--------------------------------------------------------------------===// 139764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // GNU G++: Type Traits [Type-Traits.html in the GCC manual] 139864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl OwningExprResult ParseUnaryTypeTrait(); 13995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 14025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1404