Parser.h revision 9ab14541716928894821cf5d53d6b4c95ffdf3a3
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; 8482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// Ident_vector and Ident_pixel - cached IdentifierInfo's for 8582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// "vector" and "pixel" fast comparison. Only present if 8682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// AltiVec enabled. 8782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_vector; 8882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_pixel; 89662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 904726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> PackHandler; 914726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> UnusedHandler; 929991479ad5dde617168cc1e4b18425cdbbfd9fa9Eli Friedman llvm::OwningPtr<PragmaHandler> WeakHandler; 931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// Whether the '>' token acts as an operator or not. This will be 9555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// true except when we are parsing an expression within a C++ 9655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// template argument list, where the '>' closes the template 9755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// argument list. 9855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor bool GreaterThanIsOperator; 9908d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner 10008d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonIsSacred - When this is false, we aggressively try to recover from 10108d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not 10208d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// safe in case statements and a few other things. This is managed by the 10308d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonProtectionRAIIObject RAII object. 10408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner bool ColonIsSacred; 10555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 106c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor /// The "depth" of the template parameters currently being parsed. 107c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor unsigned TemplateParameterDepth; 1081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Parser(Preprocessor &PP, Action &Actions); 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Parser(); 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const LangOptions &getLang() const { return PP.getLangOptions(); } 114444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } 1150102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner Preprocessor &getPreprocessor() const { return PP; } 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Action &getActions() const { return Actions; } 1171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1180102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Token &getCurToken() const { return Tok; } 1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Type forwarding. All of these are statically 'void*', but they may all be 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // different actual classes based on the actions in place. 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef Action::ExprTy ExprTy; 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef Action::StmtTy StmtTy; 124b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner typedef Action::DeclPtrTy DeclPtrTy; 125682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner typedef Action::DeclGroupPtrTy DeclGroupPtrTy; 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef Action::TypeTy TypeTy; 127f8268ae3196002bbab6adb830302e79b0f368f13Douglas Gregor typedef Action::BaseTy BaseTy; 1287ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor typedef Action::MemInitTy MemInitTy; 129eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis typedef Action::CXXScopeTy CXXScopeTy; 130c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor typedef Action::TemplateParamsTy TemplateParamsTy; 1317532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor typedef Action::TemplateTy TemplateTy; 1327ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 133c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor typedef llvm::SmallVector<TemplateParamsTy *, 4> TemplateParameterLists; 134c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 135d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::ExprResult ExprResult; 136d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::StmtResult StmtResult; 137d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::BaseResult BaseResult; 138d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor typedef Action::MemInitResult MemInitResult; 139809070a886684cb5b92eb0e00a6581ab1fa6b17aDouglas Gregor typedef Action::TypeResult TypeResult; 14015faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 14115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl typedef Action::OwningExprResult OwningExprResult; 14215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl typedef Action::OwningStmtResult OwningStmtResult; 14315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 1441d922960e083906a586609ac6978678147250177Sebastian Redl typedef Action::ExprArg ExprArg; 145a60528cdac7deee3991c2b48af4df4f315e49e9dSebastian Redl typedef Action::MultiStmtArg MultiStmtArg; 146a99fad8ff134273fe85f2970c7d89133d1218900Anders Carlsson typedef Action::FullExprArg FullExprArg; 1471d922960e083906a586609ac6978678147250177Sebastian Redl 14861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl /// Adorns a ExprResult with Actions to make it an OwningExprResult 14961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningExprResult Owned(ExprResult res) { 15061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl return OwningExprResult(Actions, res); 15161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 15261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl /// Adorns a StmtResult with Actions to make it an OwningStmtResult 15361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult Owned(StmtResult res) { 15461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl return OwningStmtResult(Actions, res); 15561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 15661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 15761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningExprResult ExprError() { return OwningExprResult(Actions, true); } 15861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult StmtError() { return OwningStmtResult(Actions, true); } 159d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor 1602f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); } 1612f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningStmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); } 16261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 1635ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis OwningExprResult ExprEmpty() { return OwningExprResult(Actions, false); } 1645ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis 1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Parsing methods. 1661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseTranslationUnit - All in one method that initializes parses, and 1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// shuts down the parser. 1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseTranslationUnit(); 1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Initialize - Warm up the parser. 1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Initialize(); 1741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if 1761f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff /// the EOF was encountered. 177682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner bool ParseTopLevelDecl(DeclGroupPtrTy &Result); 1781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1791ac7104947020a60430ba6f519cd5869af77046fFariborz Jahanian DeclGroupPtrTy RetrievePendingObjCImpDecl(); 18063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Low-Level token peeking and consumption methods. 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 1851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenParen - Return true if the cur token is '(' or ')'. 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenParen() const { 1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren; 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBracket - Return true if the cur token is '[' or ']'. 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBracket() const { 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square; 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBrace - Return true if the cur token is '{' or '}'. 1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBrace() const { 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace; 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenStringLiteral - True if this token is a string-literal. 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenStringLiteral() const { 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::string_literal || 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Tok.getKind() == tok::wide_string_literal; 2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 205eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeToken - Consume the current 'peek token' and lex the next one. 207d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu /// This does not work with all kinds of tokens: strings and specific other 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tokens must be consumed with custom methods below. This returns the 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// location of the consumed token. 2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeToken() { 2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && 2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer !isTokenBrace() && 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should consume special tokens with Consume*Token"); 2144b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2164b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeAnyToken - Dispatch to the right Consume* method based on the 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// current token type. This should only be used in cases where the type of 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the token really isn't known, e.g. in error recovery. 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeAnyToken() { 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isTokenParen()) 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeParen(); 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBracket()) 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBracket(); 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBrace()) 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBrace(); 229d62701bc5321049353017e9abf1963edd57646aaSteve Naroff else if (isTokenStringLiteral()) 230d62701bc5321049353017e9abf1963edd57646aaSteve Naroff return ConsumeStringToken(); 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeToken(); 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeParen - This consume method keeps the paren count up-to-date. 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeParen() { 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenParen() && "wrong consume method"); 2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_paren) 2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++ParenCount; 2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (ParenCount) 2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --ParenCount; // Don't let unbalanced )'s drive the count negative. 2434b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2454b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBracket - This consume method keeps the bracket count up-to-date. 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBracket() { 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBracket() && "wrong consume method"); 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_square) 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BracketCount; 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BracketCount) 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BracketCount; // Don't let unbalanced ]'s drive the count negative. 2561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2574b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2594b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBrace - This consume method keeps the brace count up-to-date. 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBrace() { 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBrace() && "wrong consume method"); 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_brace) 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BraceCount; 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BraceCount) 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BraceCount; // Don't let unbalanced }'s drive the count negative. 2701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2714b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2734b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeStringToken - Consume the current 'peek token', lexing a new one 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and returning the token kind. This method is specific to strings, as it 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// handles string literal concatenation, as per C99 5.1.1.2, translation 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// phase #6. 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeStringToken() { 2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenStringLiteral() && 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should only consume string literals with this method"); 2834b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2854b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2886b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// GetLookAheadToken - This peeks ahead N tokens and returns that token 2896b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1) 2906b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// returns the token after Tok, etc. 2916b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 2926b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// Note that this differs from the Preprocessor's LookAhead method, because 2936b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// the Parser always has one token lexed that the preprocessor doesn't. 2946b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 29503db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis const Token &GetLookAheadToken(unsigned N) { 2966b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (N == 0 || Tok.is(tok::eof)) return Tok; 2976b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return PP.LookAhead(N-1); 2986b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } 299f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis 300f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// NextToken - This peeks ahead one token and returns it without 301f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// consuming it. 302f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis const Token &NextToken() { 30303db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis return PP.LookAhead(0); 304f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis } 3055404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 306eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// TryAnnotateTypeOrScopeToken - If the current token position is on a 307eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// typename (possibly qualified in C++) or a C++ scope specifier not followed 308eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens 309eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// with a single annotation token representing the typename or C++ scope 310eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// respectively. 311eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// This simplifies handling of C++ scope specifiers and allows efficient 312eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// backtracking without the need to re-parse and resolve nested-names and 313eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// typenames. 31444802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// It will mainly be called when we expect to treat identifiers as typenames 31544802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// (if they are typenames). For example, in C we do not expect identifiers 31644802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// inside expressions to be treated as typenames so it will not be called 31744802cc435d5122701e4f1a9354381cff4b171c0Argyrios Kyrtzidis /// for expressions in C. 318a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner /// 319a7bc7c880f86bc180684ef032d06df51bcae7a23Chris Lattner /// This returns true if the token was annotated. 320495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false); 321eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 3229ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but 3239ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// only annotates C++ scope specifiers. This returns true if there 3249ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCall /// was an unrecoverable error. 325495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateCXXScopeToken(bool EnteringContext = false); 326eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 32782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens, 32882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// replacing them with the non-context-sensitive keywords. This returns 32982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// true if the token was replaced. 33082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc, 331b3a4e432c90be98c6d918087750397e86d030368Chris Lattner const char *&PrevSpec, unsigned &DiagID, 332b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool &isInvalid) { 3331b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner if (!getLang().AltiVec || 3341b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner (Tok.getIdentifierInfo() != Ident_vector && 3351b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner Tok.getIdentifierInfo() != Ident_pixel)) 3361b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return false; 3371b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 3381b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); 33982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 34082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 34182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector 34282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// identifier token, replacing it with the non-context-sensitive __vector. 34382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// This returns true if the token was replaced. 34482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecVectorToken() { 345b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (!getLang().AltiVec || 346b3a4e432c90be98c6d918087750397e86d030368Chris Lattner Tok.getIdentifierInfo() != Ident_vector) return false; 3471b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecVectorTokenOutOfLine(); 34882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 3491b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 3501b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecVectorTokenOutOfLine(); 3511b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, 3521b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner const char *&PrevSpec, unsigned &DiagID, 3531b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool &isInvalid); 3541b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 3555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TentativeParsingAction - An object that is used as a kind of "tentative 3565404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// parsing transaction". It gets instantiated to mark the token position and 3575404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// after the token consumption is done, Commit() or Revert() is called to 3585404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// either "commit the consumed tokens" or revert to the previously marked 3595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// token position. Example: 3605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 361314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor /// TentativeParsingAction TPA(*this); 3625404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// ConsumeToken(); 3635404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// .... 3645404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TPA.Revert(); 3655404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 3665404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis class TentativeParsingAction { 3675404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Parser &P; 3685404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Token PrevTok; 3695404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isActive; 3705404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 3715404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis public: 3725404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis explicit TentativeParsingAction(Parser& p) : P(p) { 3735404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis PrevTok = P.Tok; 3745404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.EnableBacktrackAtThisPos(); 3755404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = true; 3765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 3775404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Commit() { 3785404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 3795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.CommitBacktrackedTokens(); 3805404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 3815404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 3825404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Revert() { 3835404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 3845404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.Backtrack(); 3855404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.Tok = PrevTok; 3865404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 3875404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 3885404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis ~TentativeParsingAction() { 3895404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(!isActive && "Forgot to call Commit or Revert!"); 3905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 3915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis }; 3921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'), 3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this helper function matches and consumes the specified RHS token if 3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// present. If not present, it emits the specified diagnostic indicating 3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that the parser failed to match the RHS of the token at LHSLoc. LHSName 3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// should be the name of the unmatched LHS token. This returns the location 3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the consumed token. 4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MatchRHSPunctuation(tok::TokenKind RHSTok, 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation LHSLoc); 4021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the 4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// input. If so, it is consumed and false is returned. 4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If the input is malformed, this emits the specified diagnostic. Next, if 4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is 4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// returned. 4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag, 4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *DiagMsg = "", 4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind SkipToTok = tok::unknown); 4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Scope manipulation 4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4168935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// ParseScope - Introduces a new scope for parsing. The kind of 4178935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// scope is determined by ScopeFlags. Objects of this type should 4188935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// be created on the stack to coincide with the position where the 4198935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// parser enters the new scope, and this object's constructor will 4208935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// create that new scope. Similarly, once the object is destroyed 4218935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// the parser will exit the scope. 4228935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor class ParseScope { 4238935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Parser *Self; 4248935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope(const ParseScope&); // do not implement 4258935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope& operator=(const ParseScope&); // do not implement 4268935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 4278935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor public: 4288935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ParseScope - Construct a new object to manage a scope in the 4298935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // parser Self where the new Scope is created with the flags 4308935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ScopeFlags, but only when ManageScope is true (the default). If 4318935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ManageScope is false, this object does nothing. 4321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true) 4338935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor : Self(Self) { 4348935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (ManageScope) 4358935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->EnterScope(ScopeFlags); 4368935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor else 4378935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor this->Self = 0; 4388935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4398935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 4408935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // Exit - Exit the scope associated with this object now, rather 4418935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // than waiting until the object is destroyed. 4428935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor void Exit() { 4438935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (Self) { 4448935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->ExitScope(); 4458935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self = 0; 4468935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4478935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4488935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 4498935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ~ParseScope() { 4508935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Exit(); 4518935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 4528935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor }; 4538935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterScope - Start a new scope. 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterScope(unsigned ScopeFlags); 4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExitScope - Pop a scope off the scope stack. 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ExitScope(); 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Diagnostic Emission and Error recovery. 46215faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 4633cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 4643cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); 46515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 4661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SuggestParentheses(SourceLocation Loc, unsigned DK, 4674b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceRange ParenRange); 4684b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipUntil - Read tokens until we get to the specified token, then consume 47082c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff /// it (unless DontConsume is true). Because we cannot guarantee that the 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// token will ever occur, this skips to the next token, or to some likely 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// character. 4741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If SkipUntil finds the specified token, it returns true, otherwise it 4761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returns false. 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true, 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool DontConsume = false) { 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SkipUntil(&T, 1, StopAtSemi, DontConsume); 4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true, 4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool DontConsume = false) { 4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind TokArray[] = {T1, T2}; 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SkipUntil(TokArray, 2, StopAtSemi, DontConsume); 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, 4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool StopAtSemi = true, bool DontConsume = false); 4887ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4904cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Lexing and parsing of C++ inline methods. 4914cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 4924cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis struct LexedMethod { 493b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner Action::DeclPtrTy D; 49472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens Toks; 495d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 496d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 497d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 498d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 499d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 500d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 501d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor explicit LexedMethod(Action::DeclPtrTy MD) : D(MD), TemplateScope(false) {} 5024cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis }; 5034cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 50472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedDefaultArgument - Keeps track of a parameter that may 50572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument that cannot be parsed yet because it 50672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// occurs within a member function declaration inside the class 50772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// (C++ [class.mem]p2). 50872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedDefaultArgument { 5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit LateParsedDefaultArgument(Action::DeclPtrTy P, 51072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks = 0) 51172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor : Param(P), Toks(Toks) { } 51272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 51372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Param - The parameter declaration for this parameter. 514b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner Action::DeclPtrTy Param; 51572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 51672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Toks - The sequence of tokens that comprises the default 51772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument expression, not including the '=' or the terminating 51872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// ')' or ','. This will be NULL for parameters that have no 51972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// default argument. 52072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks; 52172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 5221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDeclaration - A method declaration inside a class that 52472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// contains at least one entity whose parsing needs to be delayed 52572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// until the class itself is completely-defined, such as a default 52672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument (C++ [class.mem]p2). 52772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedMethodDeclaration { 5281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit LateParsedMethodDeclaration(Action::DeclPtrTy M) 529d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor : Method(M), TemplateScope(false) { } 53072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 53172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Method - The method declaration. 532b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner Action::DeclPtrTy Method; 53372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 534d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 535d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 536d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 537d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// DefaultArgs - Contains the parameters of the function and 54072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// their default arguments. At least one of the parameters will 54172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument, but all of the parameters of the 54272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// method will be stored so that they can be reintroduced into 5431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// scope at the appropriate times. 54472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor llvm::SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; 54572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 54672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 54772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDecls - During parsing of a top (non-nested) C++ 54872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// class, its method declarations that contain parts that won't be 54972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// parsed until after the definiton is completed (C++ [class.mem]p2), 55072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// the method declarations will be stored here with the tokens that 55172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// will be parsed to create those entities. 55272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor typedef std::list<LateParsedMethodDeclaration> LateParsedMethodDecls; 55372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 5544cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// LexedMethodsForTopClass - During parsing of a top (non-nested) C++ class, 5554cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// its inline method definitions and the inline method definitions of its 5564cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis /// nested classes are lexed and stored here. 55772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor typedef std::list<LexedMethod> LexedMethodsForTopClass; 55872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 5596569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Representation of a class that has been parsed, including 5606569d68745c8213709740337d2be52b031384f58Douglas Gregor /// any member function declarations or definitions that need to be 5616569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed after the corresponding top-level class is complete. 5626569d68745c8213709740337d2be52b031384f58Douglas Gregor struct ParsingClass { 5631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass) 5641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : TopLevelClass(TopLevelClass), TemplateScope(false), 5656569d68745c8213709740337d2be52b031384f58Douglas Gregor TagOrTemplate(TagOrTemplate) { } 5666569d68745c8213709740337d2be52b031384f58Douglas Gregor 5676569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this is a "top-level" class, meaning that it is 5686569d68745c8213709740337d2be52b031384f58Douglas Gregor /// not nested within another class. 5696569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TopLevelClass : 1; 5706569d68745c8213709740337d2be52b031384f58Douglas Gregor 5716569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this class had an associated template 5726569d68745c8213709740337d2be52b031384f58Douglas Gregor /// scope. When true, TagOrTemplate is a template declaration; 5736569d68745c8213709740337d2be52b031384f58Douglas Gregor /// othewise, it is a tag declaration. 5746569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TemplateScope : 1; 5756569d68745c8213709740337d2be52b031384f58Douglas Gregor 5766569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The class or class template whose definition we are parsing. 5776569d68745c8213709740337d2be52b031384f58Douglas Gregor DeclPtrTy TagOrTemplate; 57872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 57972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// MethodDecls - Method declarations that contain pieces whose 58072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// parsing will be delayed until the class is fully defined. 58172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor LateParsedMethodDecls MethodDecls; 58272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 58372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// MethodDefs - Methods whose definitions will be parsed once the 58472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// class has been fully defined. 58572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor LexedMethodsForTopClass MethodDefs; 5866569d68745c8213709740337d2be52b031384f58Douglas Gregor 5876569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Nested classes inside this class. 5886569d68745c8213709740337d2be52b031384f58Douglas Gregor llvm::SmallVector<ParsingClass*, 4> NestedClasses; 58972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 5904cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 5916569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The stack of classes that is currently being 5926569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed. Nested and local classes will be pushed onto this stack 5936569d68745c8213709740337d2be52b031384f58Douglas Gregor /// when they are parsed, and removed afterward. 5946569d68745c8213709740337d2be52b031384f58Douglas Gregor std::stack<ParsingClass *> ClassStack; 5954cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 5966569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingClass &getCurrentClass() { 5976569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "No lexed method stacks!"); 5986569d68745c8213709740337d2be52b031384f58Douglas Gregor return *ClassStack.top(); 5994cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 6004cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 60154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// \brief RAII object used to inform the actions that we're 60254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// currently parsing a declaration. This is active when parsing a 60354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// variable's initializer, but not when parsing the body of a 60454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// class or function definition. 60554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclRAIIObject { 60654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Action &Actions; 60754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Action::ParsingDeclStackState State; 60854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall bool Popped; 60954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 61054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 61154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) { 61254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 61354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 61454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 61554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ~ParsingDeclRAIIObject() { 61654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 61754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 61854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 61954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Resets the RAII object for a new declaration. 62054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void reset() { 62154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 62254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 62354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 62454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 62554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Signals that the context was completed without an appropriate 62654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// declaration being parsed. 62754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 62854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall pop(DeclPtrTy()); 62954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 63054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 63154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void complete(DeclPtrTy D) { 63254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall assert(!Popped && "ParsingDeclaration has already been popped!"); 63354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall pop(D); 63454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 63554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 63654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall private: 63754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void push() { 63854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall State = Actions.PushParsingDeclaration(); 63954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = false; 64054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 64154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 64254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void pop(DeclPtrTy D) { 64354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall if (!Popped) { 64454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Actions.PopParsingDeclaration(State, D); 64554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = true; 64654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 64754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 64854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 64954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 65054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a DeclSpec. 65154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclSpec : public DeclSpec { 65254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 65354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 65454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 65554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclSpec(Parser &P) : ParsingRAII(P) { 65654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 65754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 65854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void complete(DeclPtrTy D) { 65954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 66054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 66154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 66254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 66354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.abort(); 66454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 66554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 66654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 66754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a declarator. 66854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclarator : public Declarator { 66954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 67054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 67154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 67254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C) 67354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall : Declarator(DS, C), ParsingRAII(P) { 67454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 67554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 67654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall const ParsingDeclSpec &getDeclSpec() const { 67754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec()); 67854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 67954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 68054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclSpec &getMutableDeclSpec() const { 68154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return const_cast<ParsingDeclSpec&>(getDeclSpec()); 68254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 68354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 68454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void clear() { 68554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Declarator::clear(); 68654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.reset(); 68754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 68854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 68954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void complete(DeclPtrTy D) { 69054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 69154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 69254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 69354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief RAII object used to 6956569d68745c8213709740337d2be52b031384f58Douglas Gregor class ParsingClassDefinition { 6966569d68745c8213709740337d2be52b031384f58Douglas Gregor Parser &P; 6976569d68745c8213709740337d2be52b031384f58Douglas Gregor bool Popped; 6986569d68745c8213709740337d2be52b031384f58Douglas Gregor 6996569d68745c8213709740337d2be52b031384f58Douglas Gregor public: 7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsingClassDefinition(Parser &P, DeclPtrTy TagOrTemplate, bool TopLevelClass) 7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : P(P), Popped(false) { 7026569d68745c8213709740337d2be52b031384f58Douglas Gregor P.PushParsingClass(TagOrTemplate, TopLevelClass); 7036569d68745c8213709740337d2be52b031384f58Douglas Gregor } 7046569d68745c8213709740337d2be52b031384f58Douglas Gregor 7056569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Pop this class of the stack. 7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void Pop() { 7076569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!Popped && "Nested class has already been popped"); 7086569d68745c8213709740337d2be52b031384f58Douglas Gregor Popped = true; 7096569d68745c8213709740337d2be52b031384f58Douglas Gregor P.PopParsingClass(); 7106569d68745c8213709740337d2be52b031384f58Douglas Gregor } 7116569d68745c8213709740337d2be52b031384f58Douglas Gregor 7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ~ParsingClassDefinition() { 7136569d68745c8213709740337d2be52b031384f58Douglas Gregor if (!Popped) 7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump P.PopParsingClass(); 7156569d68745c8213709740337d2be52b031384f58Douglas Gregor } 7166569d68745c8213709740337d2be52b031384f58Douglas Gregor }; 7176569d68745c8213709740337d2be52b031384f58Douglas Gregor 7184d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief Contains information about any template-specific 7194d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// information that has been parsed prior to parsing declaration 7204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// specifiers. 7214d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor struct ParsedTemplateInfo { 7221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsedTemplateInfo() 7234d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { } 7244d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 7254d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ParsedTemplateInfo(TemplateParameterLists *TemplateParams, 726c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool isSpecialization, 727c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool lastParameterListWasEmpty = false) 7284d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(isSpecialization? ExplicitSpecialization : Template), 729c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor TemplateParams(TemplateParams), 730c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(lastParameterListWasEmpty) { } 7314d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 73245f965581935791a018df829a14dff53c1dd8f47Douglas Gregor explicit ParsedTemplateInfo(SourceLocation ExternLoc, 73345f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation TemplateLoc) 7341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Kind(ExplicitInstantiation), TemplateParams(0), 735c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), 736c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(false){ } 7374d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 7384d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The kind of template we are parsing. 7394d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor enum { 7404d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are not parsing a template at all. 7414d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor NonTemplate = 0, 7424d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing a template declaration. 7434d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor Template, 7444d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit specialization. 7454d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitSpecialization, 7464d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit instantiation. 7474d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitInstantiation 7484d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } Kind; 7494d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 7504d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The template parameter lists, for template declarations 7514d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// and explicit specializations. 7524d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParameterLists *TemplateParams; 7534d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 75445f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// \brief The location of the 'extern' keyword, if any, for an explicit 75545f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// instantiation 75645f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation ExternLoc; 7571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7584d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The location of the 'template' keyword, for an explicit 7594d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// instantiation. 7604d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation TemplateLoc; 761c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor 762c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor /// \brief Whether the last template parameter list was empty. 763c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool LastParameterListWasEmpty; 7644d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor }; 7651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void PushParsingClass(DeclPtrTy TagOrTemplate, bool TopLevelClass); 76737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void DeallocateParsedClasses(ParsingClass *Class); 76837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void PopParsingClass(); 76937b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor 77037b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor DeclPtrTy ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D, 77137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor const ParsedTemplateInfo &TemplateInfo); 77237b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDeclarations(ParsingClass &Class); 77337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDefs(ParsingClass &Class); 7741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 77537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor CachedTokens &Toks, 77637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor tok::TokenKind EarlyAbortIf = tok::unknown, 77737b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor bool ConsumeFinalToken = true); 7784d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 7794cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.9: External Definitions. 781bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseExternalDeclaration(CXX0XAttributeList Attr); 7821426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor bool isDeclarationAfterDeclarator(); 7831426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor bool isStartOfFunctionDefinition(); 784bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(AttributeList *Attr, 7855aeccdbb4bdc94e48c04cacc59fa812af32109b2Anders Carlsson AccessSpecifier AS = AS_none); 7863acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS, 7873acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AttributeList *Attr, 7883acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AccessSpecifier AS = AS_none); 7893acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian 79054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclPtrTy ParseFunctionDefinition(ParsingDeclarator &D, 79152591bf224b2c43e2b00e265bb8599a620081925Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseKNRParamDeclarations(Declarator &D); 793ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 794ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the simple-asm. 795ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl OwningExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0); 796effa8d1c97b00a3f53e972b0e61d9aade5ea1c57Sebastian Redl OwningExprResult ParseAsmStringLiteral(); 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7983536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Objective-C External Declarations 7991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy ParseObjCAtDirectives(); 800b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); 8011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclPtrTy ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, 802dac269b65eed82182fc3e96566dedd6562dfe11eSteve Naroff AttributeList *prefixAttrs = 0); 8031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl, 80483c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 80560fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc); 806b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &P, 80771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis llvm::SmallVectorImpl<SourceLocation> &PLocs, 8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool WarnOnDeclarations, 80971b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, 810e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SourceLocation &EndProtoLoc); 811b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl, 812c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner tok::ObjCKeywordKind contextKey); 813b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc, 814b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner AttributeList *prefixAttrs = 0); 8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 816b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ObjCImpDecl; 81763e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian llvm::SmallVector<DeclPtrTy, 4> PendingObjCImpDecl; 8180416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 819b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtImplementationDeclaration(SourceLocation atLoc); 820782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek DeclPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd); 821b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCAtAliasDeclaration(SourceLocation atLoc); 822b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCPropertySynthesize(SourceLocation atLoc); 823b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCPropertyDynamic(SourceLocation atLoc); 8241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8252fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); 82634870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner // Definitions for Objective-c context sensitive keywords recognition. 82734870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner enum ObjCTypeQual { 82834870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, 82934870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_NumQuals 83034870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner }; 831a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; 8321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 833335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian bool isTokIdentifier_in() const; 834d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 835a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek TypeTy *ParseObjCTypeName(ObjCDeclSpec &DS); 836294494e1cce92043562b4680c613df7fd028c02eSteve Naroff void ParseObjCMethodRequirement(); 837b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCMethodPrototype(DeclPtrTy classOrCat, 838c81c8144a661a49d7b9dae8d2080dee2e43186ecChris Lattner tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); 839b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, 840b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy classDecl, 84100933591a2795d09dd1acff12a2d21bce7cb12c5Fariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword); 8424ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor void ParseObjCPropertyAttribute(ObjCDeclSpec &DS, DeclPtrTy ClassDecl, 8434ad9685b3e2d5e2923c9cda7baaf7973ef0b1c62Douglas Gregor DeclPtrTy *Methods, unsigned NumMethods); 8441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 845b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseObjCMethodDefinition(); 8461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.5: Expressions. 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8502f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParseExpression(); 8512f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParseConstantExpression(); 8522f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl // Expr that doesn't include commas. 8532f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParseAssignmentExpression(); 8542f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 855d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); 8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 857adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman OwningExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); 858adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman 859d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseRHSOfBinaryExpression(OwningExprResult LHS, 860d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl unsigned MinPrec); 861ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl OwningExprResult ParseCastExpression(bool isUnaryExpression, 862f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAddressOfOperand, 8632ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman bool &NotCastExpr, 864f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian TypeTy *TypeOfCast); 865f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis OwningExprResult ParseCastExpression(bool isUnaryExpression, 8662ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman bool isAddressOfOperand = false, 867f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian TypeTy *TypeOfCast = 0); 8682f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl OwningExprResult ParsePostfixExpressionSuffix(OwningExprResult LHS); 869d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseSizeofAlignofExpression(); 870d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseBuiltinPrimaryExpression(); 8711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8725ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis OwningExprResult ParseExprAfterTypeofSizeofAlignof(const Token &OpTok, 8735ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis bool &isCastExpr, 8745ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis TypeTy *&CastTy, 8755ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis SourceRange &CastRange); 8760cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 877a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl static const unsigned ExprListSize = 12; 878a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl typedef llvm::SmallVector<ExprTy*, ExprListSize> ExprListTy; 879a55e52c0802cae3b7c366a05c461d3d15074c1a3Sebastian Redl typedef llvm::SmallVector<SourceLocation, ExprListSize> CommaLocsTy; 8800cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 8810cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis /// ParseExpressionList - Used for C/C++ (argument-)expression-list. 8829c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor bool ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs, 8839c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor void (Action::*Completer)(Scope *S, void *Data, 8849c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor ExprTy **Args, 8859c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor unsigned NumArgs) = 0, 8869c6a0e92dbf89897eae6106b24bfd017f269bfd0Douglas Gregor void *Data = 0); 887d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl 8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParenParseOption - Control what ParseParenExpression will parse. 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ParenParseOption { 8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SimpleExpr, // Only parse '(' expression ')' 8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundStmt, // Also allow '(' compound-statement ')' 8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}' 8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CastExpr // Also allow '(' type-name ')' <anything> 8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 895d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl OwningExprResult ParseParenExpression(ParenParseOption &ExprType, 8960350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis bool stopIfCastExpr, 897f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian TypeTy *TypeOfCast, 898d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl TypeTy *&CastTy, 899d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl SourceLocation &RParenLoc); 9001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 901f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis OwningExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, 902f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis TypeTy *&CastTy, 903f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis SourceLocation LParenLoc, 904f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis SourceLocation &RParenLoc); 9051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 906d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis OwningExprResult ParseCompoundLiteralExpression(TypeTy *Ty, 907d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation LParenLoc, 908d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation RParenLoc); 9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91020df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseStringLiteralExpression(); 911eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 912eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 913eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // C++ Expressions 914ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl OwningExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); 9154bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis 9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 9172dd078ae50ff7be1fb25ebeedde45e9ab691a4f0Douglas Gregor TypeTy *ObjectType, 918b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor bool EnteringContext, 919d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool *MayBePseudoDestructor = 0); 9201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 5.2p1: C++ Casts 92320df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXCasts(); 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 926c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // C++ 5.2p1: C++ Type Identification 92720df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXTypeid(); 928c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 929c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl //===--------------------------------------------------------------------===// 930d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // C++ 5.2.4: C++ Pseudo-Destructor Expressions 931d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor OwningExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, 932d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor tok::TokenKind OpKind, 933d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CXXScopeSpec &SS, 934d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor Action::TypeTy *ObjectType); 935d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 936d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor //===--------------------------------------------------------------------===// 9374cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 9.3.2: C++ 'this' pointer 93820df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXThis(); 9394cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 9404cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 94150dd289f45738ed22b7583d52ed2525b927042ffChris Lattner // C++ 15: C++ Throw Expression 94220df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseThrowExpression(); 943ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc is filled with the location of the last token of the specification. 9447dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl bool ParseExceptionSpecification(SourceLocation &EndLoc, 945ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl llvm::SmallVector<TypeTy*, 2> &Exceptions, 946ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl llvm::SmallVector<SourceRange, 2> &Ranges, 9477dc813462dd9fd3f6f4296f896a12de14264fef8Sebastian Redl bool &hasAnyExceptionSpec); 94850dd289f45738ed22b7583d52ed2525b927042ffChris Lattner 94950dd289f45738ed22b7583d52ed2525b927042ffChris Lattner //===--------------------------------------------------------------------===// 9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 2.13.5: C++ Boolean Literals 95120df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXBoolLiteral(); 9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 954987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // C++ 5.2.3: Explicit type conversion (functional notation) 95520df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); 956987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 957987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 958987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// This should only be called when the current token is known to be part of 959987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// simple-type-specifier. 960987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); 961987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 9622f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); 9632f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 964987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 9654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // C++ 5.3.4 and 5.3.5: C++ new and delete 966cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl bool ParseExpressionListOrTypeId(ExprListTy &Exprs, Declarator &D); 9674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDirectNewDeclarator(Declarator &D); 96859232d35f5820e334b6c8b007ae8006f4390055dChris Lattner OwningExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); 96959232d35f5820e334b6c8b007ae8006f4390055dChris Lattner OwningExprResult ParseCXXDeleteExpression(bool UseGlobal, 97059232d35f5820e334b6c8b007ae8006f4390055dChris Lattner SourceLocation Start); 9714c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 9724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl //===--------------------------------------------------------------------===// 97399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor // C++ if/switch/while condition expression. 97499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor bool ParseCXXCondition(OwningExprResult &ExprResult, DeclPtrTy &DeclResult); 97571b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 97671b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 97712e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor // C++ types 97812e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor 97912e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor //===--------------------------------------------------------------------===// 9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7.8: Initialization. 9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9820eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// ParseInitializer 9830eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// initializer: [C99 6.7.8] 9840eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// assignment-expression 9850eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// '{' ... 98620df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseInitializer() { 9870eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner if (Tok.isNot(tok::l_brace)) 98820df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ParseAssignmentExpression(); 9890eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner return ParseBraceInitializer(); 9900eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner } 99120df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl OwningExprResult ParseBraceInitializer(); 9925908a9293b88a3da57ae59b522275d05e1ab11e0Douglas Gregor OwningExprResult ParseInitializerWithPotentialDesignator(); 9931d922960e083906a586609ac6978678147250177Sebastian Redl 9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 995296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // clang Expressions 9961d922960e083906a586609ac6978678147250177Sebastian Redl 9971d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseBlockLiteralExpression(); // ^{...} 998296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff 999296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff //===--------------------------------------------------------------------===// 10005508518a2702b00be3b15a26d772bde968972f54Anders Carlsson // Objective-C Expressions 10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100214dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner bool isTokObjCMessageIdentifierReceiver() const { 100314dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner if (!Tok.is(tok::identifier)) 100414dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner return false; 10051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100647246be8ac5b0ddde6c402b8fc6946b6135487b5Chris Lattner IdentifierInfo *II = Tok.getIdentifierInfo(); 1007b696ea3a0693798daeafd896d77f0b8f1fec3cc5Douglas Gregor if (Actions.getTypeName(*II, Tok.getLocation(), CurScope)) 100814dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner return true; 10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101047246be8ac5b0ddde6c402b8fc6946b6135487b5Chris Lattner return II == Ident_super; 101114dd98a7952c9559e0d17fff8272bf3be67135afChris Lattner } 10121d922960e083906a586609ac6978678147250177Sebastian Redl 10131d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCAtExpression(SourceLocation AtLocation); 10141d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCStringLiteral(SourceLocation AtLoc); 10151d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); 10161d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); 10171d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); 10181d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCMessageExpression(); 10191d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, 10201d922960e083906a586609ac6978678147250177Sebastian Redl SourceLocation NameLoc, 10211d922960e083906a586609ac6978678147250177Sebastian Redl IdentifierInfo *ReceiverName, 10221d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr); 10231d922960e083906a586609ac6978678147250177Sebastian Redl OwningExprResult ParseAssignmentExprWithObjCMessageExprStart( 10241d922960e083906a586609ac6978678147250177Sebastian Redl SourceLocation LBracloc, SourceLocation NameLoc, 10251d922960e083906a586609ac6978678147250177Sebastian Redl IdentifierInfo *ReceiverName, ExprArg ReceiverExpr); 102661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 10275508518a2702b00be3b15a26d772bde968972f54Anders Carlsson //===--------------------------------------------------------------------===// 10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.8: Statements and Blocks. 102961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 103061364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult ParseStatement() { 103161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl return ParseStatementOrDeclaration(true); 103261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 103361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult ParseStatementOrDeclaration(bool OnlyStatement = false); 1034bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseLabeledStatement(AttributeList *Attr); 1035bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseCaseStatement(AttributeList *Attr); 1036bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseDefaultStatement(AttributeList *Attr); 1037bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseCompoundStatement(AttributeList *Attr, 1038bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool isStmtExpr = false); 103961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl OwningStmtResult ParseCompoundStatementBody(bool isStmtExpr = false); 104099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor bool ParseParenExprOrCondition(OwningExprResult &ExprResult, 104199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor DeclPtrTy &DeclResult); 1042bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseIfStatement(AttributeList *Attr); 1043bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseSwitchStatement(AttributeList *Attr); 1044bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseWhileStatement(AttributeList *Attr); 1045bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseDoStatement(AttributeList *Attr); 1046bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseForStatement(AttributeList *Attr); 1047bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseGotoStatement(AttributeList *Attr); 1048bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseContinueStatement(AttributeList *Attr); 1049bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseBreakStatement(AttributeList *Attr); 1050bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseReturnStatement(AttributeList *Attr); 10519a920342707e384473b464528d2fd286e8c70353Sebastian Redl OwningStmtResult ParseAsmStatement(bool &msAsm); 10529a920342707e384473b464528d2fd286e8c70353Sebastian Redl OwningStmtResult FuzzyParseMicrosoftAsmStatement(); 1053ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<IdentifierInfo *> &Names, 1054ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVectorImpl<ExprTy *> &Constraints, 1055ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVectorImpl<ExprTy *> &Exprs); 1056a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1057a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1058a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // C++ 6: Statements and Blocks 1059a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1060bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningStmtResult ParseCXXTryBlock(AttributeList *Attr); 1061d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl OwningStmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc); 1062a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl OwningStmtResult ParseCXXCatchBlock(); 1063a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1064a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1065a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // Objective-C Statements 1066a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 106743bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCAtStatement(SourceLocation atLoc); 106843bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCTryStmt(SourceLocation atLoc); 106943bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCThrowStmt(SourceLocation atLoc); 107043bc2a0973ffe404fabba6f8280cd6bad2c69fcbSebastian Redl OwningStmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); 1071b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7: Declarations. 107567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall 107667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// A context for parsing declaration specifiers. TODO: flesh this 107767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// out, there are other significant restrictions on specifiers than 107867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// would be best implemented in the parser. 107967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall enum DeclSpecContext { 108067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DSC_normal, // normal context 10810efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_class, // class context, enables 'friend' 10820efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_top_level // top-level/namespace declaration context 108367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall }; 10841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1085bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt DeclGroupPtrTy ParseDeclaration(unsigned Context, SourceLocation &DeclEnd, 1086bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList Attr); 1087cd1477562e7cf03279850885583d615e1f631dd4Chris Lattner DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context, 1088bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 10895c5db553b5c256d0a6f55dde7325c1c829b88e8eChris Lattner AttributeList *Attr, 10905c5db553b5c256d0a6f55dde7325c1c829b88e8eChris Lattner bool RequireSemi); 109154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, 1092d8ac05753dc4506224d445ff98399c01da3136e5John McCall bool AllowFunctionDefinitions, 1093d8ac05753dc4506224d445ff98399c01da3136e5John McCall SourceLocation *DeclEnd = 0); 1094e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor DeclPtrTy ParseDeclarationAfterDeclarator(Declarator &D, 1095e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1096b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseFunctionStatementBody(DeclPtrTy Decl); 1097d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl DeclPtrTy ParseFunctionTryBlock(DeclPtrTy Decl); 1098d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 1099f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, 11004d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 1101e40c295d017a8f75a945fe9ed2aa9d8bb7a7341aChris Lattner AccessSpecifier AS); 11020efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); 11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseDeclarationSpecifiers(DeclSpec &DS, 11044d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 110567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall AccessSpecifier AS = AS_none, 110667d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DeclSpecContext DSC = DSC_normal); 11071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid, 11087a0ab5f387722c83e19c7133b46b16988eb19e45Chris Lattner const char *&PrevSpec, 1109fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID, 1110d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1111d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 11124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseSpecifierQualifierList(DeclSpec &DS); 11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1115a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek void ParseObjCTypeQualifierList(ObjCDeclSpec &DS); 11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11174c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, 11189b9edd619a7e616d3287435cb5a3f9b1aea648e8Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), AccessSpecifier AS = AS_none); 1119b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseEnumBody(SourceLocation StartLoc, DeclPtrTy TagDecl); 11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, 1121b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy TagDecl); 1122bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1123bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct FieldCallback { 1124bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall virtual DeclPtrTy invoke(FieldDeclarator &Field) = 0; 11256c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual ~FieldCallback() {} 11266c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall 11276c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall private: 11286c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual void _anchor(); 1129bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall }; 1130d0014540005f2a5ab837365db6bd40f479406758John McCall struct ObjCPropertyCallback; 1131bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1132bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback); 11331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1134eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isDeclarationSpecifier(); 1135eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isTypeSpecifierQualifier(); 11365f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff bool isTypeQualifier() const; 1137b3a4e432c90be98c6d918087750397e86d030368Chris Lattner 1138b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// isKnownToBeTypeSpecifier - Return true if we know that the specified token 1139b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// is definitely a type-specifier. Return false if it isn't part of a type 1140b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// specifier or if we're not sure. 1141b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool isKnownToBeTypeSpecifier(const Token &Tok) const; 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11435404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isDeclarationStatement - Disambiguates between a declaration or an 11445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// expression statement, when parsing function bodies. 11455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for declaration, false for expression. 11465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isDeclarationStatement() { 11475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis if (getLang().CPlusPlus) 11485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isCXXDeclarationStatement(); 11495404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isDeclarationSpecifier(); 11505404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 11515404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1152bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// isSimpleDeclaration - Disambiguates between a declaration or an 1153bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// expression, mainly used for the C 'clause-1' or the C++ 1154bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis // 'for-init-statement' part of a 'for' statement. 1155bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// Returns true for declaration, false for expression. 1156bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis bool isSimpleDeclaration() { 1157bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis if (getLang().CPlusPlus) 1158bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis return isCXXSimpleDeclaration(); 1159bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis return isDeclarationSpecifier(); 1160bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis } 1161bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis 11620efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief Starting with a scope specifier, identifier, or 11630efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id that refers to the current class, determine whether 11640efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// this is a constructor declarator. 11650efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor bool isConstructorDeclarator(); 11660efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 11678b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// \brief Specifies the context in which type-id/expression 11688b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// disambiguation will occur. 11698b642592a35167a3780074e78674e0bece87c40cDouglas Gregor enum TentativeCXXTypeIdContext { 11708b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdInParens, 11718b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdAsTemplateArgument 11728b642592a35167a3780074e78674e0bece87c40cDouglas Gregor }; 11738b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 11748b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 117578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know 117678c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// whether the parens contain an expression or a type-id. 117778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// Returns true for a type-id and false for an expression. 1178f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens(bool &isAmbiguous) { 117978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis if (getLang().CPlusPlus) 1180f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(TypeIdInParens, isAmbiguous); 1181f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis isAmbiguous = false; 118278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis return isTypeSpecifierQualifier(); 118378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis } 1184f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens() { 1185f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1186f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isTypeIdInParens(isAmbiguous); 1187f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 118878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 11895404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXDeclarationStatement - C++-specialized function that disambiguates 11905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a declaration or an expression statement, when parsing function 11915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// bodies. Returns true for declaration, false for expression. 11925404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXDeclarationStatement(); 11935404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 11945404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXSimpleDeclaration - C++-specialized function that disambiguates 11955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a simple-declaration or an expression-statement. 11965404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 11975404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 11985404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns false if the statement is disambiguated as expression. 11995404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXSimpleDeclaration(); 12005404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 12015404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXFunctionDeclarator - Disambiguates between a function declarator or 12025404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// a constructor-style initializer, when parsing declaration statements. 12035404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for function declarator and false for constructor-style 1204e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to 1205259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis /// indicate that the parens were disambiguated as function declarator. 12065404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 12075404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1208e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis bool isCXXFunctionDeclarator(bool warnIfAmbiguous); 12095404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1210a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// isCXXConditionDeclaration - Disambiguates between a declaration or an 1211a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// expression for a condition of a if/switch/while/for statement. 1212a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 1213a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1214a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis bool isCXXConditionDeclaration(); 1215a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis 1216f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); 1217f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context) { 1218f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1219f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(Context, isAmbiguous); 1220f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 122178c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 1222b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult - Used as the result value for functions whose purpose is to 1223b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// disambiguate C++ constructs by "tentatively parsing" them. 1224b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// This is a class instead of a simple enum because the implicit enum-to-bool 1225b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// conversions may cause subtle bugs. 1226b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis class TPResult { 1227b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis enum Result { 1228b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_true, 1229b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_false, 1230b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_ambiguous, 1231b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_error 1232b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis }; 1233b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis Result Res; 1234b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult(Result result) : Res(result) {} 1235b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis public: 1236b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult True() { return TPR_true; } 1237b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult False() { return TPR_false; } 1238b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Ambiguous() { return TPR_ambiguous; } 1239b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Error() { return TPR_error; } 1240b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis 1241b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator==(const TPResult &RHS) const { return Res == RHS.Res; } 1242b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; } 1243b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis }; 1244b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis 1245b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a 1246b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// declaration specifier, TPResult::False() if it is not, 1247b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult::Ambiguous() if it could be either a decl-specifier or a 1248b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// function-style cast, and TPResult::Error() if a parsing error was 1249b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// encountered. 12505404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Doesn't consume tokens. 1251b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult isCXXDeclarationSpecifier(); 12525404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 12535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // "Tentative parsing" functions, used for disambiguation. If a parsing error 1254b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // is encountered they will return TPResult::Error(). 1255b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // Returning TPResult::True()/False() indicates that the ambiguity was 1256b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates 1257b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // that more tentative parsing is necessary for disambiguation. 12585404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // They all consume tokens, so backtracking should be used after calling them. 12595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1260b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseDeclarationSpecifier(); 1261b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseSimpleDeclaration(); 1262b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseTypeofSpecifier(); 1263b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseInitDeclaratorList(); 126478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); 1265b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseParameterDeclarationClause(); 1266b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseFunctionDeclarator(); 1267b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseBracketDeclarator(); 12685404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1269ef65f06e8e440aec541442cfd73a8a836e9bc842Sebastian Redl TypeResult ParseTypeName(SourceRange *Range = 0); 127098eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump void ParseBlockId(); 1271ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 1272ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the attribute list. 1273bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList ParseCXX0XAttributes(SourceLocation *EndLoc = 0); 1274bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttributeList *ParseGNUAttributes(SourceLocation *EndLoc = 0); 1275290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0); 1276290eeb0ec2b6b91f3621e05ef541deb257fbea73Eli Friedman AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0); 1277d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff void ParseTypeofSpecifier(DeclSpec &DS); 12786fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson void ParseDecltypeSpecifier(DeclSpec &DS); 1279bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 1280bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt OwningExprResult ParseCXX0XAlignArgument(SourceLocation Start); 1281eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1282eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to 1283eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// enter a new C++ declarator scope and exit it when the function is 1284eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// finished. 1285eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis class DeclaratorScopeObj { 1286eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis Parser &P; 1287751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis CXXScopeSpec &SS; 1288f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis bool EnteredScope; 1289f7f3d0db754db0500b56d49ac19f795f13965912John McCall bool CreatedScope; 1290eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis public: 1291f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) 1292f7f3d0db754db0500b56d49ac19f795f13965912John McCall : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} 1293eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1294eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis void EnterDeclaratorScope() { 12952bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis assert(!EnteredScope && "Already entered the scope!"); 1296f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was not set!"); 1297f7f3d0db754db0500b56d49ac19f795f13965912John McCall 1298f7f3d0db754db0500b56d49ac19f795f13965912John McCall CreatedScope = true; 1299f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.EnterScope(0); // Not a decl scope. 1300f7f3d0db754db0500b56d49ac19f795f13965912John McCall 13017a1dc562d4ad59237ed9fe7e8cef56f9eaa7a26cJohn McCall if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS)) 13023fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor EnteredScope = true; 1303eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1304eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1305eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis ~DeclaratorScopeObj() { 1306f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis if (EnteredScope) { 1307f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was cleared ?"); 13080a59acb9ae36077ce46fb2807956c5e84f0f6837Douglas Gregor P.Actions.ActOnCXXExitDeclaratorScope(P.CurScope, SS); 1309f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis } 1310f7f3d0db754db0500b56d49ac19f795f13965912John McCall if (CreatedScope) 1311f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.ExitScope(); 1312eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1313eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis }; 13141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseDeclarator - Parse and verify a newly-initialized declarator. 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDeclarator(Declarator &D); 13174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl /// A function that parses a variant of direct-declarator. 13184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef void (Parser::*DirectDeclParseFunction)(Declarator&); 13194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDeclaratorInternal(Declarator &D, 13204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl DirectDeclParseFunction DirectDeclParser); 1321bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, 1322bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool CXX0XAttributesAllowed = true); 13235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDirectDeclarator(Declarator &D); 13245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseParenDeclarator(Declarator &D); 13257399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, 13267399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner AttributeList *AttrList = 0, 13277399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner bool RequiresArg = false); 132866d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc, 132966d28650752eeac0b02802a1d8cea425cb6b1c0fChris Lattner Declarator &D); 13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseBracketDeclarator(Declarator &D); 13311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13328f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner //===--------------------------------------------------------------------===// 13338f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner // C++ 7: Declarations [dcl.dcl] 13341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1335bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool isCXX0XAttributeSpecifier(bool FullLookahead = false, 1336bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt tok::TokenKind *After = 0); 1337bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 133897144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseNamespace(unsigned Context, SourceLocation &DeclEnd); 13393acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian DeclPtrTy ParseLinkage(ParsingDeclSpec &DS, unsigned Context); 134097144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseUsingDirectiveOrDeclaration(unsigned Context, 1341bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 1342bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt CXX0XAttributeList Attrs); 134397144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseUsingDirective(unsigned Context, SourceLocation UsingLoc, 1344bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 1345bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt AttributeList *Attr); 134697144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc, 1347595adc1795cc2c079ef5876100e01acd10a0504aAnders Carlsson SourceLocation &DeclEnd, 1348595adc1795cc2c079ef5876100e01acd10a0504aAnders Carlsson AccessSpecifier AS = AS_none); 134997144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner DeclPtrTy ParseStaticAssertDeclaration(SourceLocation &DeclEnd); 135003bd5a1e9a54b62b10ae8aeb6eb5245e2031d98bAnders Carlsson DeclPtrTy ParseNamespaceAlias(SourceLocation NamespaceLoc, 135197144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation AliasLoc, IdentifierInfo *Alias, 135297144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation &DeclEnd); 13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1354e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 1355e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 9: classes [class] and C structs/unions. 13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeResult ParseClassName(SourceLocation &EndLocation, 13579ab14541716928894821cf5d53d6b4c95ffdf3a3Jeffrey Yasskin CXXScopeSpec *SS = 0); 13584c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, 13591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclSpec &DS, 13604d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1361d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl AccessSpecifier AS = AS_none, 1362d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 13634cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType, 1364b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy TagDecl); 136537b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseCXXClassMemberDeclaration(AccessSpecifier AS, 136637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1367b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseConstructorInitializer(DeclPtrTy ConstructorDecl); 1368b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner MemInitResult ParseMemInitializer(DeclPtrTy ConstructorDecl); 1369d33133cdc1af466f9c276249b2621be03867888bEli Friedman void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, 1370d33133cdc1af466f9c276249b2621be03867888bEli Friedman DeclPtrTy ThisDecl); 1371e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 1372e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 1373e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 10: Derived classes [class.derived] 1374b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner void ParseBaseClause(DeclPtrTy ClassDecl); 1375b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner BaseResult ParseBaseSpecifier(DeclPtrTy ClassDecl); 13761b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor AccessSpecifier getAccessSpecifierIfPresent() const; 13771cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor 13783f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 13793f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Name, 13803f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation NameLoc, 13813f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool EnteringContext, 13822d1c21414199a7452f122598189363a3922605b1Douglas Gregor TypeTy *ObjectType, 1383d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor UnqualifiedId &Id, 1384d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool AssumeTemplateId = false); 1385ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, 1386ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor TypeTy *ObjectType, 1387ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &Result); 13883f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, 138902a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowDestructorName, 139002a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowConstructorName, 13912d1c21414199a7452f122598189363a3922605b1Douglas Gregor TypeTy *ObjectType, 13923f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &Result); 13933f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 13941cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor //===--------------------------------------------------------------------===// 1395adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14: Templates [temp] 1396b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner typedef llvm::SmallVector<DeclPtrTy, 4> TemplateParameterList; 1397c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 1398adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14.1: Template Parameters [temp.param] 13994d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor DeclPtrTy ParseDeclarationStartingWithTemplate(unsigned Context, 14004d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation &DeclEnd, 14014d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AccessSpecifier AS = AS_none); 1402b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTemplateDeclarationOrSpecialization(unsigned Context, 140397144fc41a9419bf6d74fc9450e8ef3f6e11f7e0Chris Lattner SourceLocation &DeclEnd, 14044d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor AccessSpecifier AS); 14051426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor DeclPtrTy ParseSingleDeclarationAfterTemplate( 14061426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor unsigned Context, 14074d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 14081426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor SourceLocation &DeclEnd, 14091426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor AccessSpecifier AS=AS_none); 14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseTemplateParameters(unsigned Depth, 1411c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor TemplateParameterList &TemplateParams, 14121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation &LAngleLoc, 1413c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor SourceLocation &RAngleLoc); 1414c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor bool ParseTemplateParameterList(unsigned Depth, 1415c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor TemplateParameterList &TemplateParams); 141698440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor bool isStartOfTemplateTypeParameter(); 1417b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTemplateParameter(unsigned Depth, unsigned Position); 1418b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTypeParameter(unsigned Depth, unsigned Position); 1419b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); 1420b28317a8e5e0e2953d1e5406d753d6c3c7f1e7d2Chris Lattner DeclPtrTy ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); 1421d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor // C++ 14.3: Template arguments [temp.arg] 1422314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor typedef llvm::SmallVector<ParsedTemplateArgument, 16> TemplateArgList; 1423cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 14247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor bool ParseTemplateIdAfterTemplateName(TemplateTy Template, 14251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateNameLoc, 1426cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor const CXXScopeSpec *SS, 1427cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor bool ConsumeLastToken, 1428cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &LAngleLoc, 1429cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateArgList &TemplateArgs, 1430cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &RAngleLoc); 1431cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 1432c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, 143339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor const CXXScopeSpec *SS, 1434ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &TemplateName, 143539a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor SourceLocation TemplateKWLoc = SourceLocation(), 143639a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor bool AllowTypeAnnotation = true); 143731a19b6989bbf326d2de5ae12e712e2a65ca9c34Douglas Gregor void AnnotateTemplateIdTokenAsType(const CXXScopeSpec *SS = 0); 1438314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); 1439788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor ParsedTemplateArgument ParseTemplateTemplateArgument(); 1440314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor ParsedTemplateArgument ParseTemplateArgument(); 144145f965581935791a018df829a14dff53c1dd8f47Douglas Gregor DeclPtrTy ParseExplicitInstantiation(SourceLocation ExternLoc, 14421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateLoc, 14434d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation &DeclEnd); 144464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 144564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl //===--------------------------------------------------------------------===// 144664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // GNU G++: Type Traits [Type-Traits.html in the GCC manual] 144764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl OwningExprResult ParseUnaryTypeTrait(); 14485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 14515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1453