Parser.h revision efaa93aaa2653f4eb40e6a22e504a448da94aaf8
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" 1825a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis#include "clang/Basic/DelayedCleanupPool.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Lex/Preprocessor.h" 20f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor#include "clang/Lex/CodeCompletionHandler.h" 21f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "clang/Sema/Sema.h" 2219510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/DeclSpec.h" 23f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall#include "llvm/Support/PrettyStackTrace.h" 244726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek#include "llvm/ADT/OwningPtr.h" 25eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski#include "llvm/ADT/SmallVector.h" 264cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis#include <stack> 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 29fcdd8fe26de3eee44927600bf1853e21bd90dd84Daniel Dunbar class PragmaHandler; 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Scope; 312b5289b6fd7e3d9899868410a498c081c9595662John McCall class DeclGroupRef; 323cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner class DiagnosticBuilder; 330102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner class Parser; 344726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek class PragmaUnusedHandler; 3508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner class ColonProtectionRAIIObject; 360fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor class InMessageExpressionRAIIObject; 3728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley class PoisonSEHIdentifiersRAIIObject; 380a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor class VersionTuple; 3928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 400102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// PrettyStackTraceParserEntry - If a crash happens while the parser is active, 410102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner/// an entry is printed for it. 420102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerclass PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry { 430102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Parser &P; 440102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattnerpublic: 450102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner PrettyStackTraceParserEntry(const Parser &p) : P(p) {} 468cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner virtual void print(raw_ostream &OS) const; 470102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner}; 481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 496aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// PrecedenceLevels - These are precedences for the binary/ternary 506aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// operators in the C99 grammar. These have been named to relate 516aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// with the C99 grammar productions. Low precedences numbers bind 526aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor/// more weakly than high numbers. 536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregornamespace prec { 546aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor enum Level { 556aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Unknown = 0, // Not binary operator. 566aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Comma = 1, // , 576aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Assignment = 2, // =, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |= 586aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Conditional = 3, // ? 596aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor LogicalOr = 4, // || 606aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor LogicalAnd = 5, // && 616aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor InclusiveOr = 6, // | 626aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor ExclusiveOr = 7, // ^ 636aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor And = 8, // & 646aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Equality = 9, // ==, != 656aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Relational = 10, // >=, <=, >, < 666aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Shift = 11, // <<, >> 676aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Additive = 12, // -, + 686aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor Multiplicative = 13, // *, /, % 696aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor PointerToMember = 14 // .*, ->* 706aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor }; 716aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor} 721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Parser - This implements a parser for the C family of languages. After 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// parsing units of the grammar, productions are invoked to handle whatever has 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// been read. 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 77f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregorclass Parser : public CodeCompletionHandler { 784726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek friend class PragmaUnusedHandler; 7908d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner friend class ColonProtectionRAIIObject; 800fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor friend class InMessageExpressionRAIIObject; 8128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley friend class PoisonSEHIdentifiersRAIIObject; 8236d36806f1972f7ec1d2a3f59155187278c56508Argyrios Kyrtzidis friend class ParenBraceBracketBalancer; 831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Preprocessor &PP; 851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8697d0205d16fef2a783e785459b5f30f6a9dfbcb9Eric Christopher /// Tok - The current token we are peeking ahead. All parsing methods assume 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// that this is valid. 88d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner Token Tok; 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 904b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // PrevTokLocation - The location of the token we previously 914b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // consumed. This token is used for diagnostics where we expected to 924b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // see a token following another token (e.g., the ';' at the end of 934b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor // a statement). 944b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceLocation PrevTokLocation; 954b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned short ParenCount, BracketCount, BraceCount; 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Actions - These are the callbacks we invoke as we parse various constructs 9987c300738174924453648c3b2d6f366c8284fac4Douglas Gregor /// in the file. 100f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &Actions; 1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine &Diags; 1031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1049e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner /// ScopeCache - Cache scopes to reduce malloc traffic. 1059e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner enum { ScopeCacheSize = 16 }; 1069e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner unsigned NumCachedScopes; 1079e344c65b1e8b83e1d3ada507cf653526ff2c005Chris Lattner Scope *ScopeCache[ScopeCacheSize]; 108662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 10928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley /// Identifiers used for SEH handling in Borland. These are only 11028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley /// allowed in particular circumstances 11128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley IdentifierInfo *Ident__exception_code, *Ident___exception_code, *Ident_GetExceptionCode; // __except block 11228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley IdentifierInfo *Ident__exception_info, *Ident___exception_info, *Ident_GetExceptionInfo; // __except filter expression 11328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley IdentifierInfo *Ident__abnormal_termination, *Ident___abnormal_termination, *Ident_AbnormalTermination; // __finally 11428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 115b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor /// Contextual keywords for Microsoft extensions. 116b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor IdentifierInfo *Ident__except; 117b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor 118662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// Ident_super - IdentifierInfo for "super", to support fast 119662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// comparison. 120662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar IdentifierInfo *Ident_super; 12182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// Ident_vector and Ident_pixel - cached IdentifierInfo's for 12282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// "vector" and "pixel" fast comparison. Only present if 12382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// AltiVec enabled. 12482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_vector; 12582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_pixel; 126662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 127e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor /// Objective-C contextual keywords. 128e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor mutable IdentifierInfo *Ident_instancetype; 129e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor 1300a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "introduced". 1310a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_introduced; 1320a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 1330a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "deprecated". 1340a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_deprecated; 1350a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 1360a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "obsoleted". 1370a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_obsoleted; 1380a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 139b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor /// \brief Identifier for "unavailable". 140b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor IdentifierInfo *Ident_unavailable; 141b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor 1421f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson /// C++0x contextual keywords. 1437eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson mutable IdentifierInfo *Ident_final; 1447eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson mutable IdentifierInfo *Ident_override; 1451f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 146cbb98edd530787c2ac019e437e7c599df8004ba7Daniel Dunbar llvm::OwningPtr<PragmaHandler> AlignHandler; 147aa8b0d19244a6e7e8e5798fcc6aef003c274d3e0Eli Friedman llvm::OwningPtr<PragmaHandler> GCCVisibilityHandler; 148861800c676004eabed5927f0552620d06c80a40aDaniel Dunbar llvm::OwningPtr<PragmaHandler> OptionsHandler; 1494726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> PackHandler; 15062c9258f4a71569a66d805fc7776526a2c76b34eFariborz Jahanian llvm::OwningPtr<PragmaHandler> MSStructHandler; 1514726d03ab3abce41911c31d1354a18f1258cae4dTed Kremenek llvm::OwningPtr<PragmaHandler> UnusedHandler; 1529991479ad5dde617168cc1e4b18425cdbbfd9fa9Eli Friedman llvm::OwningPtr<PragmaHandler> WeakHandler; 153321b8179afaf803dcc56b2a19f7b0891a03c92c8Peter Collingbourne llvm::OwningPtr<PragmaHandler> FPContractHandler; 154f315fa81eef1977b3457fd7a7d4639e060fe7278Peter Collingbourne llvm::OwningPtr<PragmaHandler> OpenCLExtensionHandler; 1551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// Whether the '>' token acts as an operator or not. This will be 15755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// true except when we are parsing an expression within a C++ 15855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// template argument list, where the '>' closes the template 15955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// argument list. 16055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor bool GreaterThanIsOperator; 16108d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner 16208d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonIsSacred - When this is false, we aggressively try to recover from 16308d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not 16408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// safe in case statements and a few other things. This is managed by the 16508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonProtectionRAIIObject RAII object. 16608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner bool ColonIsSacred; 16755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 168d9d75e57dfa22366c0379c92beac1db82db34e9aDouglas Gregor /// \brief When true, we are directly inside an Objective-C messsage 1690fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// send expression. 1700fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// 1710fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// This is managed by the \c InMessageExpressionRAIIObject class, and 1720fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// should not be set directly. 1730fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor bool InMessageExpression; 1740fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor 175c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor /// The "depth" of the template parameters currently being parsed. 176c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor unsigned TemplateParameterDepth; 1778113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek 1788113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek /// Factory object for creating AttributeList objects. 1790b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall AttributeFactory AttrFactory; 1801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18125a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis /// \brief Gathers and cleans up objects when parsing of a top-level 18225a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis /// declaration is finished. 18325a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis DelayedCleanupPool TopLevelDeclCleanupPool; 18425a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 185b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor IdentifierInfo *getSEHExceptKeyword(); 186b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 188f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Parser(Preprocessor &PP, Sema &Actions); 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Parser(); 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const LangOptions &getLang() const { return PP.getLangOptions(); } 192444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } 1930102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner Preprocessor &getPreprocessor() const { return PP; } 194f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &getActions() const { return Actions; } 1951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1960102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Token &getCurToken() const { return Tok; } 19723c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Scope *getCurScope() const { return Actions.getCurScope(); } 198a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 199a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); } 20023c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Type forwarding. All of these are statically 'void*', but they may all be 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // different actual classes based on the actions in place. 2032b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 2042b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<TemplateName> TemplateTy; 2057ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 206686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists; 207c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 2089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::ExprResult ExprResult; 2099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::StmtResult StmtResult; 2109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::BaseResult BaseResult; 2119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::MemInitResult MemInitResult; 2129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::TypeResult TypeResult; 21315faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 2149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef Expr *ExprArg; 2159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef ASTMultiPtr<Stmt*> MultiStmtArg; 216f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::FullExprArg FullExprArg; 2171d922960e083906a586609ac6978678147250177Sebastian Redl 21860d7b3a319d84d688752be3870615ac0f111fb16John McCall /// Adorns a ExprResult with Actions to make it an ExprResult 21960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Owned(ExprResult res) { 22060d7b3a319d84d688752be3870615ac0f111fb16John McCall return ExprResult(res); 22161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 22260d7b3a319d84d688752be3870615ac0f111fb16John McCall /// Adorns a StmtResult with Actions to make it an StmtResult 22360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Owned(StmtResult res) { 22460d7b3a319d84d688752be3870615ac0f111fb16John McCall return StmtResult(res); 22561364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 22661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 22760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError() { return ExprResult(true); } 22860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError() { return StmtResult(true); } 229d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor 23060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); } 23160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); } 23261364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 23360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprEmpty() { return ExprResult(false); } 2345ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Parsing methods. 2361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseTranslationUnit - All in one method that initializes parses, and 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// shuts down the parser. 2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseTranslationUnit(); 2401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Initialize - Warm up the parser. 2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Initialize(); 2441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if 2461f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff /// the EOF was encountered. 247682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner bool ParseTopLevelDecl(DeclGroupPtrTy &Result); 2481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2493fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian DeclGroupPtrTy FinishPendingObjCActions(); 25063e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Low-Level token peeking and consumption methods. 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 2551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenParen - Return true if the cur token is '(' or ')'. 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenParen() const { 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren; 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBracket - Return true if the cur token is '[' or ']'. 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBracket() const { 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square; 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBrace - Return true if the cur token is '{' or '}'. 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBrace() const { 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace; 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenStringLiteral - True if this token is a string-literal. 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenStringLiteral() const { 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::string_literal || 2735cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::wide_string_literal || 2745cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::utf8_string_literal || 2755cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::utf16_string_literal || 2765cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::utf32_string_literal; 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 278eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 279a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis /// \brief Returns true if the current token is a '=' or '==' and 280a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis /// false otherwise. If it's '==', we assume that it's a typo and we emit 281a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis /// DiagID and a fixit hint to turn '==' -> '='. 282a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis bool isTokenEqualOrMistypedEqualEqual(unsigned DiagID); 283a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeToken - Consume the current 'peek token' and lex the next one. 285d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu /// This does not work with all kinds of tokens: strings and specific other 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tokens must be consumed with custom methods below. This returns the 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// location of the consumed token. 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeToken() { 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer !isTokenBrace() && 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should consume special tokens with Consume*Token"); 2927d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis 2937d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis if (Tok.is(tok::code_completion)) 2947d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return handleUnexpectedCodeCompletionToken(); 2957d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis 2964b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 2984b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeAnyToken - Dispatch to the right Consume* method based on the 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// current token type. This should only be used in cases where the type of 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the token really isn't known, e.g. in error recovery. 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeAnyToken() { 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isTokenParen()) 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeParen(); 3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBracket()) 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBracket(); 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBrace()) 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBrace(); 311d62701bc5321049353017e9abf1963edd57646aaSteve Naroff else if (isTokenStringLiteral()) 312d62701bc5321049353017e9abf1963edd57646aaSteve Naroff return ConsumeStringToken(); 3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeToken(); 3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeParen - This consume method keeps the paren count up-to-date. 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeParen() { 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenParen() && "wrong consume method"); 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_paren) 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++ParenCount; 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (ParenCount) 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --ParenCount; // Don't let unbalanced )'s drive the count negative. 3254b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3274b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBracket - This consume method keeps the bracket count up-to-date. 3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBracket() { 3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBracket() && "wrong consume method"); 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_square) 3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BracketCount; 3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BracketCount) 3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BracketCount; // Don't let unbalanced ]'s drive the count negative. 3381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3394b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3414b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBrace - This consume method keeps the brace count up-to-date. 3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBrace() { 3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBrace() && "wrong consume method"); 3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_brace) 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BraceCount; 3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BraceCount) 3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BraceCount; // Don't let unbalanced }'s drive the count negative. 3521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3534b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3554b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeStringToken - Consume the current 'peek token', lexing a new one 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and returning the token kind. This method is specific to strings, as it 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// handles string literal concatenation, as per C99 5.1.1.2, translation 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// phase #6. 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeStringToken() { 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenStringLiteral() && 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should only consume string literals with this method"); 3654b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3674b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 370dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// \brief Consume the current code-completion token. 371dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// 372dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// This routine should be called to consume the code-completion token once 373dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// a code-completion action has already been invoked. 374dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor SourceLocation ConsumeCodeCompletionToken() { 375dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor assert(Tok.is(tok::code_completion)); 376dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PrevTokLocation = Tok.getLocation(); 377dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PP.Lex(Tok); 378dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor return PrevTokLocation; 379dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor } 380dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 3817d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis ///\ brief When we are consuming a code-completion token without having 382dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// matched specific position in the grammar, provide code-completion results 383dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// based on context. 3847d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// 3857d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// \returns the source location of the code-completion token. 3867d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis SourceLocation handleUnexpectedCodeCompletionToken(); 3877d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis 3887d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// \brief Abruptly cut off parsing; mainly used when we have reached the 3897d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// code-completion point. 3907d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis void cutOffParsing() { 3917d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis PP.setCodeCompletionReached(); 3927d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis // Cut off parsing by acting as if we reached the end-of-file. 3937d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis Tok.setKind(tok::eof); 3947d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis } 395dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 396b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis /// \brief Handle the annotation token produced for #pragma unused(...) 397b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis void HandlePragmaUnused(); 398b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis 3996b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// GetLookAheadToken - This peeks ahead N tokens and returns that token 4006b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1) 4016b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// returns the token after Tok, etc. 4026b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 4036b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// Note that this differs from the Preprocessor's LookAhead method, because 4046b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// the Parser always has one token lexed that the preprocessor doesn't. 4056b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 40603db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis const Token &GetLookAheadToken(unsigned N) { 4076b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (N == 0 || Tok.is(tok::eof)) return Tok; 4086b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return PP.LookAhead(N-1); 4096b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } 410f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis 411f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// NextToken - This peeks ahead one token and returns it without 412f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// consuming it. 413f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis const Token &NextToken() { 41403db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis return PP.LookAhead(0); 415f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis } 4165404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 4174a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor /// \brief Tracks information about the current nesting depth of 4184a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor /// opening delimiters of each kind. 4194a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor class DelimiterTracker { 4204a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor private: 4214a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor friend class Parser; 4224a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4234a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor unsigned Paren, Brace, Square, Less, LLLess; 4244a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor unsigned& get(tok::TokenKind t) { 4254a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor switch (t) { 4264a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor default: llvm_unreachable("Unexpected balanced token"); 4274a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_brace: return Brace; 4284a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_paren: return Paren; 4294a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_square: return Square; 4304a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::less: return Less; 4314a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::lesslessless: return LLLess; 4324a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4334a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4344a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4354a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor void push(tok::TokenKind t) { 4364a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor get(t)++; 4374a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4384a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4394a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor void pop(tok::TokenKind t) { 4404a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor get(t)--; 4414a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4424a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4434a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor unsigned getDepth(tok::TokenKind t) { 4444a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor return get(t); 4454a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4464a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4474a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor public: 4484a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor DelimiterTracker() : Paren(0), Brace(0), Square(0), Less(0), LLLess(0) { } 4494a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor }; 4504a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4514a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor /// \brief RAII class that helps handle the parsing of an open/close delimiter 4524a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor /// pair, such as braces { ... } or parentheses ( ... ). 4534a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor class BalancedDelimiterTracker { 4544a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor tok::TokenKind Kind, Close; 4554a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Parser& P; 4564a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor bool Cleanup; 4574a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor const unsigned MaxDepth; 4584a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceLocation LOpen, LClose; 4594a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4604a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor void assignClosingDelimiter() { 4614a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor switch (Kind) { 4624a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor default: llvm_unreachable("Unexpected balanced token"); 4634a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_brace: Close = tok::r_brace; break; 4644a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_paren: Close = tok::r_paren; break; 4654a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_square: Close = tok::r_square; break; 4664a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::less: Close = tok::greater; break; 4674a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::lesslessless: Close = tok::greatergreatergreater; break; 4684a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4694a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4704a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4714a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor public: 4724a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker(Parser& p, tok::TokenKind k) 4734a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor : Kind(k), P(p), Cleanup(false), MaxDepth(256) { 4744a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor assignClosingDelimiter(); 4754a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4764a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4774a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor ~BalancedDelimiterTracker() { 4784a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (Cleanup) 4794a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor P.QuantityTracker.pop(Kind); 4804a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4814a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4824a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceLocation getOpenLocation() const { return LOpen; } 4834a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceLocation getCloseLocation() const { return LClose; } 4844a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceRange getRange() const { return SourceRange(LOpen, LClose); } 4854a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4864a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor bool consumeOpen(); 4874a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor bool expectAndConsume(unsigned DiagID, 4884a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor const char *Msg = "", 4894a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor tok::TokenKind SkipToTok = tok::unknown); 4904a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor bool consumeClose(); 4913896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor void skipToEnd(); 4924a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor }; 4934a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4944a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor DelimiterTracker QuantityTracker; 4954a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 496b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall /// getTypeAnnotation - Read a parsed type out of an annotation token. 497b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static ParsedType getTypeAnnotation(Token &Tok) { 498b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue()); 499b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 500b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 501b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static void setTypeAnnotation(Token &Tok, ParsedType T) { 502b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Tok.setAnnotationValue(T.getAsOpaquePtr()); 503b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 5045ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor 5055ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// \brief Read an already-translated primary expression out of an annotation 5065ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// token. 5075ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor static ExprResult getExprAnnotation(Token &Tok) { 5085ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor if (Tok.getAnnotationValue()) 5095ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor return ExprResult((Expr *)Tok.getAnnotationValue()); 5105ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor 5115ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor return ExprResult(true); 5125ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor } 5135ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor 5145ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// \brief Set the primary expression corresponding to the given annotation 5155ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// token. 5165ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor static void setExprAnnotation(Token &Tok, ExprResult ER) { 5175ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor if (ER.isInvalid()) 5185ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor Tok.setAnnotationValue(0); 5195ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor else 5205ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor Tok.setAnnotationValue(ER.get()); 5215ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor } 522b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 523fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to 524fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain // find a type name by attempting typo correction. 525fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false, 526fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain bool NeedType = false); 527495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateCXXScopeToken(bool EnteringContext = false); 528eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 52982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens, 53082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// replacing them with the non-context-sensitive keywords. This returns 53182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// true if the token was replaced. 53282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc, 533b3a4e432c90be98c6d918087750397e86d030368Chris Lattner const char *&PrevSpec, unsigned &DiagID, 534b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool &isInvalid) { 5351b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner if (!getLang().AltiVec || 5361b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner (Tok.getIdentifierInfo() != Ident_vector && 5371b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner Tok.getIdentifierInfo() != Ident_pixel)) 5381b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return false; 5391b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 5401b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); 54182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 54282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 54382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector 54482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// identifier token, replacing it with the non-context-sensitive __vector. 54582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// This returns true if the token was replaced. 54682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecVectorToken() { 547b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (!getLang().AltiVec || 548b3a4e432c90be98c6d918087750397e86d030368Chris Lattner Tok.getIdentifierInfo() != Ident_vector) return false; 5491b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecVectorTokenOutOfLine(); 55082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 5511b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner 5521b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecVectorTokenOutOfLine(); 5531b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, 5541b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner const char *&PrevSpec, unsigned &DiagID, 5551b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool &isInvalid); 55625a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 55725a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis /// \brief Get the TemplateIdAnnotation from the token and put it in the 55825a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis /// cleanup pool so that it gets destroyed when parsing the current top level 55925a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis /// declaration is finished. 56025a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok); 56125a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 5625404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TentativeParsingAction - An object that is used as a kind of "tentative 5635404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// parsing transaction". It gets instantiated to mark the token position and 5645404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// after the token consumption is done, Commit() or Revert() is called to 5655404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// either "commit the consumed tokens" or revert to the previously marked 5665404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// token position. Example: 5675404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 568314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor /// TentativeParsingAction TPA(*this); 5695404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// ConsumeToken(); 5705404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// .... 5715404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TPA.Revert(); 5725404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 5735404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis class TentativeParsingAction { 5745404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Parser &P; 5755404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Token PrevTok; 5765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isActive; 5775404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 5785404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis public: 5795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis explicit TentativeParsingAction(Parser& p) : P(p) { 5805404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis PrevTok = P.Tok; 5815404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.EnableBacktrackAtThisPos(); 5825404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = true; 5835404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 5845404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Commit() { 5855404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 5865404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.CommitBacktrackedTokens(); 5875404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 5885404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 5895404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Revert() { 5905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 5915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.Backtrack(); 5925404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.Tok = PrevTok; 5935404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 5945404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 5955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis ~TentativeParsingAction() { 5965404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(!isActive && "Forgot to call Commit or Revert!"); 5975404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 5985404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis }; 5991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6009735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// ObjCDeclContextSwitch - An object used to switch context from 6019735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// an objective-c decl context to its enclosing decl context and 6029735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// back. 6039735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian class ObjCDeclContextSwitch { 6049735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian Parser &P; 6059735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian Decl *DC; 6069735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian public: 6079735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian explicit ObjCDeclContextSwitch(Parser &p) : P(p), 6089735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian DC(p.getObjCDeclContext()) { 6099735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian if (DC) 610458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC)); 6119735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian } 6129735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian ~ObjCDeclContextSwitch() { 6139735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian if (DC) 614458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC)); 6159735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian } 6169735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian }; 6171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// input. If so, it is consumed and false is returned. 6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If the input is malformed, this emits the specified diagnostic. Next, if 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// returned. 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag, 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *DiagMsg = "", 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind SkipToTok = tok::unknown); 6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6289ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// \brief The parser expects a semicolon and, if present, will consume it. 6299ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// 6309ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// If the next token is not a semicolon, this emits the specified diagnostic, 6319ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior 6329ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// to the semicolon, consumes that extra token. 6339ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor bool ExpectAndConsumeSemi(unsigned DiagID); 6349ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Scope manipulation 6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6388935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// ParseScope - Introduces a new scope for parsing. The kind of 6398935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// scope is determined by ScopeFlags. Objects of this type should 6408935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// be created on the stack to coincide with the position where the 6418935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// parser enters the new scope, and this object's constructor will 6428935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// create that new scope. Similarly, once the object is destroyed 6438935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// the parser will exit the scope. 6448935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor class ParseScope { 6458935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Parser *Self; 6468935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope(const ParseScope&); // do not implement 6478935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope& operator=(const ParseScope&); // do not implement 6488935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6498935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor public: 6508935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ParseScope - Construct a new object to manage a scope in the 6518935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // parser Self where the new Scope is created with the flags 6528935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ScopeFlags, but only when ManageScope is true (the default). If 6538935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ManageScope is false, this object does nothing. 6541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true) 6558935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor : Self(Self) { 6568935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (ManageScope) 6578935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->EnterScope(ScopeFlags); 6588935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor else 6598935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor this->Self = 0; 6608935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6618935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6628935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // Exit - Exit the scope associated with this object now, rather 6638935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // than waiting until the object is destroyed. 6648935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor void Exit() { 6658935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (Self) { 6668935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->ExitScope(); 6678935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self = 0; 6688935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6698935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6708935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6718935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ~ParseScope() { 6728935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Exit(); 6738935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6748935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor }; 6758935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterScope - Start a new scope. 6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterScope(unsigned ScopeFlags); 6781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExitScope - Pop a scope off the scope stack. 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ExitScope(); 6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6827a614d8380297fcd2bc23986241905d97222948cRichard Smith /// \brief RAII object used to modify the scope flags for the current scope. 6837a614d8380297fcd2bc23986241905d97222948cRichard Smith class ParseScopeFlags { 6847a614d8380297fcd2bc23986241905d97222948cRichard Smith Scope *CurScope; 6857a614d8380297fcd2bc23986241905d97222948cRichard Smith unsigned OldFlags; 6867a614d8380297fcd2bc23986241905d97222948cRichard Smith ParseScopeFlags(const ParseScopeFlags &); // do not implement 6877a614d8380297fcd2bc23986241905d97222948cRichard Smith void operator=(const ParseScopeFlags &); // do not implement 6887a614d8380297fcd2bc23986241905d97222948cRichard Smith 6897a614d8380297fcd2bc23986241905d97222948cRichard Smith public: 6907a614d8380297fcd2bc23986241905d97222948cRichard Smith ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true); 6917a614d8380297fcd2bc23986241905d97222948cRichard Smith ~ParseScopeFlags(); 6927a614d8380297fcd2bc23986241905d97222948cRichard Smith }; 6937a614d8380297fcd2bc23986241905d97222948cRichard Smith 6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Diagnostic Emission and Error recovery. 69615faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 6976aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorpublic: 6983cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 6993cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); 70015faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 7016aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorprivate: 7021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SuggestParentheses(SourceLocation Loc, unsigned DK, 7034b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceRange ParenRange); 7044b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipUntil - Read tokens until we get to the specified token, then consume 70682c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff /// it (unless DontConsume is true). Because we cannot guarantee that the 7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// token will ever occur, this skips to the next token, or to some likely 7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' 7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// character. 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 7115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If SkipUntil finds the specified token, it returns true, otherwise it 7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returns false. 7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true, 7143437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis bool DontConsume = false, bool StopAtCodeCompletion = false) { 7153437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis return SkipUntil(&T, 1, StopAtSemi, DontConsume, StopAtCodeCompletion); 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true, 7183437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis bool DontConsume = false, bool StopAtCodeCompletion = false) { 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind TokArray[] = {T1, T2}; 7203437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis return SkipUntil(TokArray, 2, StopAtSemi, DontConsume,StopAtCodeCompletion); 7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, 7233437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis bool StopAtSemi = true, bool DontConsume = false, 7243437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis bool StopAtCodeCompletion = false); 7257ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 7274cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Lexing and parsing of C++ inline methods. 7284cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 729d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct ParsingClass; 730d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 731d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// [class.mem]p1: "... the class is regarded as complete within 732d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - function bodies 733d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - default arguments 734d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - exception-specifications (TODO: C++0x) 7357a614d8380297fcd2bc23986241905d97222948cRichard Smith /// - and brace-or-equal-initializers for non-static data members 7367a614d8380297fcd2bc23986241905d97222948cRichard Smith /// (including such things in nested classes)." 737d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarations build the tree of those elements so they can 738d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// be parsed after parsing the top-level class. 739d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor class LateParsedDeclaration { 740d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor public: 741d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual ~LateParsedDeclaration(); 742d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 743d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 7447a614d8380297fcd2bc23986241905d97222948cRichard Smith virtual void ParseLexedMemberInitializers(); 745d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 746eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski virtual void ParseLexedAttributes(); 747d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor }; 748d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 749d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// Inner node of the LateParsedDeclaration tree that parses 750d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// all its members recursively. 751d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor class LateParsedClass : public LateParsedDeclaration { 752d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor public: 753d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateParsedClass(Parser *P, ParsingClass *C); 754d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual ~LateParsedClass(); 755d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 756d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 7577a614d8380297fcd2bc23986241905d97222948cRichard Smith virtual void ParseLexedMemberInitializers(); 758d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 759eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski virtual void ParseLexedAttributes(); 760d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 761d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor private: 762d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser *Self; 763d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor ParsingClass *Class; 764d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor }; 765d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 766eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// Contains the lexed tokens of an attribute with arguments that 767eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// may reference member variables and so need to be parsed at the 768eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// end of the class declaration after parsing all other member 769eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// member declarations. 770eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// FIXME: Perhaps we should change the name of LateParsedDeclaration to 771eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// LateParsedTokens. 772eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski struct LateParsedAttribute : public LateParsedDeclaration { 773eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski Parser *Self; 774eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski CachedTokens Toks; 775eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski IdentifierInfo &AttrName; 776eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation AttrNameLoc; 777eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski Decl *D; 778eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 779eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name, 780eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation Loc) 781eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski : Self(P), AttrName(Name), AttrNameLoc(Loc), D(0) {} 782eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 783eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski virtual void ParseLexedAttributes(); 784eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 785eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void setDecl(Decl *Dec) { D = Dec; } 786eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski }; 787eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 788eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// A list of late parsed attributes. Used by ParseGNUAttributes. 789eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski typedef llvm::SmallVector<LateParsedAttribute*, 2> LateParsedAttrList; 790eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 791eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 792d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// Contains the lexed tokens of a member function definition 793d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// which needs to be parsed at the end of the class declaration 794d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// after parsing all other member declarations. 795d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct LexedMethod : public LateParsedDeclaration { 796d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser *Self; 797d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *D; 79872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens Toks; 799d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 800d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 801d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 802d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 803d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 804d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 805d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor explicit LexedMethod(Parser* P, Decl *MD) 806d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor : Self(P), D(MD), TemplateScope(false) {} 807d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 808d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 8094cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis }; 8104cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 81172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedDefaultArgument - Keeps track of a parameter that may 81272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument that cannot be parsed yet because it 81372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// occurs within a member function declaration inside the class 81472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// (C++ [class.mem]p2). 81572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedDefaultArgument { 816d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall explicit LateParsedDefaultArgument(Decl *P, 81772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks = 0) 81872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor : Param(P), Toks(Toks) { } 81972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 82072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Param - The parameter declaration for this parameter. 821d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param; 82272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 82372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Toks - The sequence of tokens that comprises the default 82472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument expression, not including the '=' or the terminating 82572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// ')' or ','. This will be NULL for parameters that have no 82672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// default argument. 82772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks; 82872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDeclaration - A method declaration inside a class that 83172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// contains at least one entity whose parsing needs to be delayed 83272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// until the class itself is completely-defined, such as a default 83372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument (C++ [class.mem]p2). 834d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct LateParsedMethodDeclaration : public LateParsedDeclaration { 835d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor explicit LateParsedMethodDeclaration(Parser *P, Decl *M) 836d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor : Self(P), Method(M), TemplateScope(false) { } 837d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 838d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 839d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 840d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser* Self; 84172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 84272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Method - The method declaration. 843d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Method; 84472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 845d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 846d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 847d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 848d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// DefaultArgs - Contains the parameters of the function and 85172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// their default arguments. At least one of the parameters will 85272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument, but all of the parameters of the 85372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// method will be stored so that they can be reintroduced into 8541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// scope at the appropriate times. 855686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; 85672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 85772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 8587a614d8380297fcd2bc23986241905d97222948cRichard Smith /// LateParsedMemberInitializer - An initializer for a non-static class data 8597a614d8380297fcd2bc23986241905d97222948cRichard Smith /// member whose parsing must to be delayed until the class is completely 8607a614d8380297fcd2bc23986241905d97222948cRichard Smith /// defined (C++11 [class.mem]p2). 8617a614d8380297fcd2bc23986241905d97222948cRichard Smith struct LateParsedMemberInitializer : public LateParsedDeclaration { 8627a614d8380297fcd2bc23986241905d97222948cRichard Smith LateParsedMemberInitializer(Parser *P, Decl *FD) 8637a614d8380297fcd2bc23986241905d97222948cRichard Smith : Self(P), Field(FD) { } 8647a614d8380297fcd2bc23986241905d97222948cRichard Smith 8657a614d8380297fcd2bc23986241905d97222948cRichard Smith virtual void ParseLexedMemberInitializers(); 8667a614d8380297fcd2bc23986241905d97222948cRichard Smith 8677a614d8380297fcd2bc23986241905d97222948cRichard Smith Parser *Self; 8687a614d8380297fcd2bc23986241905d97222948cRichard Smith 8697a614d8380297fcd2bc23986241905d97222948cRichard Smith /// Field - The field declaration. 8707a614d8380297fcd2bc23986241905d97222948cRichard Smith Decl *Field; 8717a614d8380297fcd2bc23986241905d97222948cRichard Smith 8727a614d8380297fcd2bc23986241905d97222948cRichard Smith /// CachedTokens - The sequence of tokens that comprises the initializer, 8737a614d8380297fcd2bc23986241905d97222948cRichard Smith /// including any leading '='. 8747a614d8380297fcd2bc23986241905d97222948cRichard Smith CachedTokens Toks; 8757a614d8380297fcd2bc23986241905d97222948cRichard Smith }; 8767a614d8380297fcd2bc23986241905d97222948cRichard Smith 877d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarationsContainer - During parsing of a top (non-nested) 878d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// C++ class, its method declarations that contain parts that won't be 879fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// parsed until after the definition is completed (C++ [class.mem]p2), 880d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// the method declarations and possibly attached inline definitions 881d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// will be stored here with the tokens that will be parsed to create those entities. 882686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<LateParsedDeclaration*, 2> LateParsedDeclarationsContainer; 88372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 8846569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Representation of a class that has been parsed, including 8856569d68745c8213709740337d2be52b031384f58Douglas Gregor /// any member function declarations or definitions that need to be 8866569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed after the corresponding top-level class is complete. 8876569d68745c8213709740337d2be52b031384f58Douglas Gregor struct ParsingClass { 888d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParsingClass(Decl *TagOrTemplate, bool TopLevelClass) 8891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : TopLevelClass(TopLevelClass), TemplateScope(false), 8906569d68745c8213709740337d2be52b031384f58Douglas Gregor TagOrTemplate(TagOrTemplate) { } 8916569d68745c8213709740337d2be52b031384f58Douglas Gregor 8926569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this is a "top-level" class, meaning that it is 8936569d68745c8213709740337d2be52b031384f58Douglas Gregor /// not nested within another class. 8946569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TopLevelClass : 1; 8956569d68745c8213709740337d2be52b031384f58Douglas Gregor 8966569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this class had an associated template 8976569d68745c8213709740337d2be52b031384f58Douglas Gregor /// scope. When true, TagOrTemplate is a template declaration; 8986569d68745c8213709740337d2be52b031384f58Douglas Gregor /// othewise, it is a tag declaration. 8996569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TemplateScope : 1; 9006569d68745c8213709740337d2be52b031384f58Douglas Gregor 9016569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The class or class template whose definition we are parsing. 902d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagOrTemplate; 90372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 904d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarations - Method declarations, inline definitions and 905d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// nested classes that contain pieces whose parsing will be delayed until 906d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// the top-level class is fully defined. 907d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateParsedDeclarationsContainer LateParsedDeclarations; 90872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 9094cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 9106569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The stack of classes that is currently being 9116569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed. Nested and local classes will be pushed onto this stack 9126569d68745c8213709740337d2be52b031384f58Douglas Gregor /// when they are parsed, and removed afterward. 9136569d68745c8213709740337d2be52b031384f58Douglas Gregor std::stack<ParsingClass *> ClassStack; 9144cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 9156569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingClass &getCurrentClass() { 9166569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "No lexed method stacks!"); 9176569d68745c8213709740337d2be52b031384f58Douglas Gregor return *ClassStack.top(); 9184cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 9194cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 92054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// \brief RAII object used to inform the actions that we're 92154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// currently parsing a declaration. This is active when parsing a 92254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// variable's initializer, but not when parsing the body of a 92354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// class or function definition. 92454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclRAIIObject { 925f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &Actions; 926eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Sema::ParsingDeclState State; 92754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall bool Popped; 928c9068d7dd94d439cec66c421115d15303e481025John McCall 92954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 93054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) { 93154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 93254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 93354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 934c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *Other) 935c9068d7dd94d439cec66c421115d15303e481025John McCall : Actions(P.Actions) { 936c9068d7dd94d439cec66c421115d15303e481025John McCall if (Other) steal(*Other); 937c9068d7dd94d439cec66c421115d15303e481025John McCall else push(); 938c9068d7dd94d439cec66c421115d15303e481025John McCall } 939c9068d7dd94d439cec66c421115d15303e481025John McCall 940c9068d7dd94d439cec66c421115d15303e481025John McCall /// Creates a RAII object which steals the state from a different 941c9068d7dd94d439cec66c421115d15303e481025John McCall /// object instead of pushing. 942c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject(ParsingDeclRAIIObject &Other) 943c9068d7dd94d439cec66c421115d15303e481025John McCall : Actions(Other.Actions) { 944c9068d7dd94d439cec66c421115d15303e481025John McCall steal(Other); 945c9068d7dd94d439cec66c421115d15303e481025John McCall } 946c9068d7dd94d439cec66c421115d15303e481025John McCall 94754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ~ParsingDeclRAIIObject() { 94854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 94954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 95054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 95154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Resets the RAII object for a new declaration. 95254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void reset() { 95354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 95454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 95554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 95654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 95754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Signals that the context was completed without an appropriate 95854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// declaration being parsed. 95954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 960d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall pop(0); 96154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 96254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 963d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 96454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall assert(!Popped && "ParsingDeclaration has already been popped!"); 96554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall pop(D); 96654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 96754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 96854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall private: 969c9068d7dd94d439cec66c421115d15303e481025John McCall void steal(ParsingDeclRAIIObject &Other) { 970c9068d7dd94d439cec66c421115d15303e481025John McCall State = Other.State; 971c9068d7dd94d439cec66c421115d15303e481025John McCall Popped = Other.Popped; 972c9068d7dd94d439cec66c421115d15303e481025John McCall Other.Popped = true; 973c9068d7dd94d439cec66c421115d15303e481025John McCall } 974c9068d7dd94d439cec66c421115d15303e481025John McCall 97554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void push() { 97654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall State = Actions.PushParsingDeclaration(); 97754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = false; 97854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 97954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 980d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void pop(Decl *D) { 98154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall if (!Popped) { 98254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Actions.PopParsingDeclaration(State, D); 98354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = true; 98454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 98554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 98654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 98754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 98854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a DeclSpec. 98954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclSpec : public DeclSpec { 99054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 99154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 99254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 9930b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsingDeclSpec(Parser &P) : DeclSpec(P.AttrFactory), ParsingRAII(P) {} 994c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII) 9950b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall : DeclSpec(P.AttrFactory), ParsingRAII(P, RAII) {} 99654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 997d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 99854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 99954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 100054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 100154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 100254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.abort(); 100354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 100454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 100554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 100654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a declarator. 100754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclarator : public Declarator { 100854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 100954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 101054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 101154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C) 101254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall : Declarator(DS, C), ParsingRAII(P) { 101354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 101454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 101554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall const ParsingDeclSpec &getDeclSpec() const { 101654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec()); 101754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 101854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 101954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclSpec &getMutableDeclSpec() const { 102054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return const_cast<ParsingDeclSpec&>(getDeclSpec()); 102154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 102254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 102354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void clear() { 102454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Declarator::clear(); 102554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.reset(); 102654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 102754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 1028d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 102954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 103054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 103154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 103254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief RAII object used to 10346569d68745c8213709740337d2be52b031384f58Douglas Gregor class ParsingClassDefinition { 10356569d68745c8213709740337d2be52b031384f58Douglas Gregor Parser &P; 10366569d68745c8213709740337d2be52b031384f58Douglas Gregor bool Popped; 1037eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Sema::ParsingClassState State; 10386569d68745c8213709740337d2be52b031384f58Douglas Gregor 10396569d68745c8213709740337d2be52b031384f58Douglas Gregor public: 1040d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass) 1041eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall : P(P), Popped(false), 1042eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall State(P.PushParsingClass(TagOrTemplate, TopLevelClass)) { 10436569d68745c8213709740337d2be52b031384f58Douglas Gregor } 10446569d68745c8213709740337d2be52b031384f58Douglas Gregor 10456569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Pop this class of the stack. 10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void Pop() { 10476569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!Popped && "Nested class has already been popped"); 10486569d68745c8213709740337d2be52b031384f58Douglas Gregor Popped = true; 1049eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall P.PopParsingClass(State); 10506569d68745c8213709740337d2be52b031384f58Douglas Gregor } 10516569d68745c8213709740337d2be52b031384f58Douglas Gregor 10521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ~ParsingClassDefinition() { 10536569d68745c8213709740337d2be52b031384f58Douglas Gregor if (!Popped) 1054eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall P.PopParsingClass(State); 10556569d68745c8213709740337d2be52b031384f58Douglas Gregor } 10566569d68745c8213709740337d2be52b031384f58Douglas Gregor }; 10576569d68745c8213709740337d2be52b031384f58Douglas Gregor 10584d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief Contains information about any template-specific 10594d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// information that has been parsed prior to parsing declaration 10604d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// specifiers. 10614d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor struct ParsedTemplateInfo { 10621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsedTemplateInfo() 10634d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { } 10644d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 10654d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ParsedTemplateInfo(TemplateParameterLists *TemplateParams, 1066c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool isSpecialization, 1067c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool lastParameterListWasEmpty = false) 10684d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(isSpecialization? ExplicitSpecialization : Template), 1069c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor TemplateParams(TemplateParams), 1070c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(lastParameterListWasEmpty) { } 10714d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 107245f965581935791a018df829a14dff53c1dd8f47Douglas Gregor explicit ParsedTemplateInfo(SourceLocation ExternLoc, 107345f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation TemplateLoc) 10741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Kind(ExplicitInstantiation), TemplateParams(0), 1075c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), 1076c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(false){ } 10774d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 10784d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The kind of template we are parsing. 10794d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor enum { 10804d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are not parsing a template at all. 10814d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor NonTemplate = 0, 10824d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing a template declaration. 10834d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor Template, 10844d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit specialization. 10854d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitSpecialization, 10864d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit instantiation. 10874d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitInstantiation 10884d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } Kind; 10894d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 10904d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The template parameter lists, for template declarations 10914d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// and explicit specializations. 10924d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParameterLists *TemplateParams; 10934d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 109445f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// \brief The location of the 'extern' keyword, if any, for an explicit 109545f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// instantiation 109645f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation ExternLoc; 10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10984d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The location of the 'template' keyword, for an explicit 10994d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// instantiation. 11004d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation TemplateLoc; 1101c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor 1102c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor /// \brief Whether the last template parameter list was empty. 1103c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool LastParameterListWasEmpty; 110478b810559d89e996e00684335407443936ce34a1John McCall 110578b810559d89e996e00684335407443936ce34a1John McCall SourceRange getSourceRange() const; 11064d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor }; 11071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11088387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet /// \brief Contains a late templated function. 11098387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet /// Will be parsed at the end of the translation unit. 11108387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet struct LateParsedTemplatedFunction { 11118387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet explicit LateParsedTemplatedFunction(Parser* P, Decl *MD) 11128387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet : D(MD) {} 11138387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 11148387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet CachedTokens Toks; 11158387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 11168387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet /// \brief The template function declaration to be late parsed. 11178387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet Decl *D; 11188387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet }; 11198387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 11208387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet void LexTemplateFunctionForLateParsing(CachedTokens &Toks); 11218387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet void ParseLateTemplatedFuncDef(LateParsedTemplatedFunction &LMT); 11228387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet typedef llvm::DenseMap<const FunctionDecl*, LateParsedTemplatedFunction*> 11238387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet LateParsedTemplateMapT; 11248387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet LateParsedTemplateMapT LateParsedTemplateMap; 11258387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 11264a47e8d35dc1778ef7e428d9edd7676be67e725fFrancois Pichet static void LateTemplateParserCallback(void *P, const FunctionDecl *FD); 11274a47e8d35dc1778ef7e428d9edd7676be67e725fFrancois Pichet void LateTemplateParser(const FunctionDecl *FD); 11288387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 1129eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Sema::ParsingClassState 1130eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass); 113137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void DeallocateParsedClasses(ParsingClass *Class); 1132eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall void PopParsingClass(Sema::ParsingClassState); 113337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor 11345f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen Decl *ParseCXXInlineMethodDef(AccessSpecifier AS, AttributeList *AccessAttrs, 11355f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen ParsingDeclarator &D, 11364867347e82648d3baf09524b98b09c297a5a198fNico Weber const ParsedTemplateInfo &TemplateInfo, 11376a24747beed797b2f1184c66ca45beb4db20eb08Francois Pichet const VirtSpecifiers& VS, ExprResult& Init); 11387a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseCXXNonStaticMemberInitializer(Decl *VarD); 1139eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void ParseLexedAttributes(ParsingClass &Class); 1140eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void ParseLexedAttribute(LateParsedAttribute &LA); 114137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDeclarations(ParsingClass &Class); 1142d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM); 114337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDefs(ParsingClass &Class); 1144d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor void ParseLexedMethodDef(LexedMethod &LM); 11457a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseLexedMemberInitializers(ParsingClass &Class); 11467a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI); 1147140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian Decl *ParseLexedObjCMethodDefs(LexedMethod &LM); 1148a891a32d3762ee641a29c091d286f2a7432671a5Sebastian Redl bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks); 114914b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeAndStoreUntil(tok::TokenKind T1, 115014b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis CachedTokens &Toks, 115114b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 115214b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeFinalToken = true) { 115314b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken); 115414b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis } 11551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 115637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor CachedTokens &Toks, 115714b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 115837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor bool ConsumeFinalToken = true); 11594d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11604cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.9: External Definitions. 11627f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct ParsedAttributesWithRange : ParsedAttributes { 11630b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange(AttributeFactory &factory) 11640b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall : ParsedAttributes(factory) {} 11650b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 11667f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceRange Range; 11677f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall }; 11687f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 11697f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs, 117009a63c97b95eb4dc6fd6b2323929e8cf12af03ffDouglas Gregor ParsingDeclSpec *DS = 0); 1171e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt bool isDeclarationAfterDeclarator(); 1172004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); 11737f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsedAttributes &attrs, 11747f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall AccessSpecifier AS = AS_none); 11753acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS, 11763acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AccessSpecifier AS = AS_none); 11773acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian 1178d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseFunctionDefinition(ParsingDeclarator &D, 117952591bf224b2c43e2b00e265bb8599a620081925Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseKNRParamDeclarations(Declarator &D); 1181ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 1182ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the simple-asm. 118360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0); 118460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAsmStringLiteral(); 11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11863536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Objective-C External Declarations 118795ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian Parser::DeclGroupPtrTy ParseObjCAtDirectives(); 118895ed7784a335aca53b0c6e952cf31a4cfb633360Fariborz Jahanian Parser::DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); 1189d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, 11907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &prefixAttrs); 1191d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseObjCClassInstanceVariables(Decl *interfaceDecl, 119283c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 119360fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc); 1194686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P, 1195686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceLocation> &PLocs, 11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool WarnOnDeclarations, 119771b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, 1198e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SourceLocation &EndProtoLoc); 119946f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor bool ParseObjCProtocolQualifiers(DeclSpec &DS); 12002f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, 12012f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian Decl *CDecl); 1202d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtProtocolDeclaration(SourceLocation atLoc, 12037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &prefixAttrs); 12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1205d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ObjCImpDecl; 1206686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Decl *, 4> PendingObjCImpDecl; 1207140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian typedef SmallVector<LexedMethod*, 2> LateParsedObjCMethodContainer; 1208140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian LateParsedObjCMethodContainer LateParsedObjCMethods; 12090416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 1210d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtImplementationDeclaration(SourceLocation atLoc); 1211140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd); 1212d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc); 1213d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertySynthesize(SourceLocation atLoc); 1214d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertyDynamic(SourceLocation atLoc); 12151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12162fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); 121734870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner // Definitions for Objective-c context sensitive keywords recognition. 121834870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner enum ObjCTypeQual { 121934870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, 122034870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_NumQuals 122134870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner }; 1222a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; 12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1224335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian bool isTokIdentifier_in() const; 1225d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 1226cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, Declarator::TheContext Ctx, 1227cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParsedAttributes *ParamAttrs); 1228294494e1cce92043562b4680c613df7fd028c02eSteve Naroff void ParseObjCMethodRequirement(); 1229a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *ParseObjCMethodPrototype( 123090ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 123190ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition = true); 1232d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, 123390ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 123490ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition=true); 1235a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian void ParseObjCPropertyAttribute(ObjCDeclSpec &DS); 12361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1237d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDefinition(); 12381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 12405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.5: Expressions. 12416aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 12425ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor ExprResult ParseExpression(); 124360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseConstantExpression(); 12442f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl // Expr that doesn't include commas. 12455ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor ExprResult ParseAssignmentExpression(); 12462f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 124760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); 12485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 124960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); 1250adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman 125160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, 1252312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor prec::Level MinPrec); 125360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 1254312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool isAddressOfOperand, 1255312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool &NotCastExpr, 12560a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis bool isTypeCast); 125760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 1258312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool isAddressOfOperand = false, 12590a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis bool isTypeCast = false); 12609c72c6088d591ace8503b842d39448c2040f3033John McCall 12619c72c6088d591ace8503b842d39448c2040f3033John McCall /// Returns true if the next token would start a postfix-expression 12629c72c6088d591ace8503b842d39448c2040f3033John McCall /// suffix. 12639c72c6088d591ace8503b842d39448c2040f3033John McCall bool isPostfixExpressionSuffixStart() { 12649c72c6088d591ace8503b842d39448c2040f3033John McCall tok::TokenKind K = Tok.getKind(); 12659c72c6088d591ace8503b842d39448c2040f3033John McCall return (K == tok::l_square || K == tok::l_paren || 12669c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::period || K == tok::arrow || 12679c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::plusplus || K == tok::minusminus); 12689c72c6088d591ace8503b842d39448c2040f3033John McCall } 12699c72c6088d591ace8503b842d39448c2040f3033John McCall 127060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParsePostfixExpressionSuffix(ExprResult LHS); 1271f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult ParseUnaryExprOrTypeTraitExpression(); 127260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBuiltinPrimaryExpression(); 12731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1274f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, 12755ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis bool &isCastExpr, 1276b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 12775ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis SourceRange &CastRange); 12780cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 1279686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<Expr*, 20> ExprListTy; 1280686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<SourceLocation, 20> CommaLocsTy; 12810cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 12820cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis /// ParseExpressionList - Used for C/C++ (argument-)expression-list. 1283686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool ParseExpressionList(SmallVectorImpl<Expr*> &Exprs, 1284686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceLocation> &CommaLocs, 1285f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall void (Sema::*Completer)(Scope *S, 1286f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Data, 1287f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr **Args, 1288f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall unsigned NumArgs) = 0, 1289ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Expr *Data = 0); 1290d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl 12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParenParseOption - Control what ParseParenExpression will parse. 12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ParenParseOption { 12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SimpleExpr, // Only parse '(' expression ')' 12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundStmt, // Also allow '(' compound-statement ')' 12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}' 12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CastExpr // Also allow '(' type-name ')' <anything> 12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 129860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseParenExpression(ParenParseOption &ExprType, 12990350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis bool stopIfCastExpr, 13000a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis bool isTypeCast, 1301b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 1302d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl SourceLocation &RParenLoc); 13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 130460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, 13054a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor ParsedType &CastTy, 13064a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker); 130760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCompoundLiteralExpression(ParsedType Ty, 1308d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation LParenLoc, 1309d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation RParenLoc); 13101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 131160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseStringLiteralExpression(); 1312eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1313f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult ParseGenericSelectionExpression(); 1314f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1315eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 1316eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // C++ Expressions 131760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); 13184bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis 1319950be71c745409e373ae8a834490f9026c8ac222Richard Trieu void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr, 1320950be71c745409e373ae8a834490f9026c8ac222Richard Trieu bool EnteringContext, IdentifierInfo &II, 1321950be71c745409e373ae8a834490f9026c8ac222Richard Trieu CXXScopeSpec &SS); 1322950be71c745409e373ae8a834490f9026c8ac222Richard Trieu 13231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 1324b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1325b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor bool EnteringContext, 13264147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet bool *MayBePseudoDestructor = 0, 13274147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet bool IsTypename = false); 13281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1330ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // C++0x 5.1.2: Lambda expressions 1331ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 1332ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // [...] () -> type {...} 1333ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult ParseLambdaExpression(); 1334ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult TryParseLambdaExpression(); 1335ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor llvm::Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro); 1336ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor bool TryParseLambdaIntroducer(LambdaIntroducer &Intro); 1337ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult ParseLambdaExpressionAfterIntroducer( 1338ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor LambdaIntroducer &Intro); 1339ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 1340ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor //===--------------------------------------------------------------------===// 13415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 5.2p1: C++ Casts 134260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXCasts(); 13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1345c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // C++ 5.2p1: C++ Type Identification 134660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeid(); 1347c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 1348c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl //===--------------------------------------------------------------------===// 134901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // C++ : Microsoft __uuidof Expression 135001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult ParseCXXUuidof(); 135101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 135201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet //===--------------------------------------------------------------------===// 1353d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // C++ 5.2.4: C++ Pseudo-Destructor Expressions 135460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, 1355d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor tok::TokenKind OpKind, 1356d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CXXScopeSpec &SS, 1357b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType); 1358d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 1359d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor //===--------------------------------------------------------------------===// 13604cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 9.3.2: C++ 'this' pointer 136160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXThis(); 13624cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 13634cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 136450dd289f45738ed22b7583d52ed2525b927042ffChris Lattner // C++ 15: C++ Throw Expression 136560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseThrowExpression(); 13667acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 13677acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExceptionSpecificationType MaybeParseExceptionSpecification( 13687acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange &SpecificationRange, 1369686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParsedType> &DynamicExceptions, 1370686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceRange> &DynamicExceptionRanges, 13717acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExprResult &NoexceptExpr); 13727acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 1373ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc is filled with the location of the last token of the specification. 13747acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExceptionSpecificationType ParseDynamicExceptionSpecification( 13757acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange &SpecificationRange, 1376686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParsedType> &Exceptions, 1377686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceRange> &Ranges); 137850dd289f45738ed22b7583d52ed2525b927042ffChris Lattner 137950dd289f45738ed22b7583d52ed2525b927042ffChris Lattner //===--------------------------------------------------------------------===// 1380dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // C++0x 8: Function declaration trailing-return-type 1381ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor TypeResult ParseTrailingReturnType(SourceRange &Range); 1382dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 1383dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor //===--------------------------------------------------------------------===// 13845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 2.13.5: C++ Boolean Literals 138560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXBoolLiteral(); 13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1388987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // C++ 5.2.3: Explicit type conversion (functional notation) 138960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); 1390987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 13916aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool isCXXSimpleTypeSpecifier() const; 13926aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 1393987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 1394987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// This should only be called when the current token is known to be part of 1395987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// simple-type-specifier. 1396987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); 1397987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 13982f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); 13992f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 1400987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 14014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // C++ 5.3.4 and 5.3.5: C++ new and delete 1402686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs, 1403ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Declarator &D); 14044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDirectNewDeclarator(Declarator &D); 140560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); 140660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXDeleteExpression(bool UseGlobal, 140759232d35f5820e334b6c8b007ae8006f4390055dChris Lattner SourceLocation Start); 14084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 14094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl //===--------------------------------------------------------------------===// 141099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor // C++ if/switch/while condition expression. 141160d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult, 1412586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, bool ConvertToBoolean); 141371b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 141471b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 141512e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor // C++ types 141612e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor 141712e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor //===--------------------------------------------------------------------===// 14185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7.8: Initialization. 14191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14200eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// ParseInitializer 14210eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// initializer: [C99 6.7.8] 14220eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// assignment-expression 14230eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// '{' ... 142460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializer() { 14250eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner if (Tok.isNot(tok::l_brace)) 142620df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ParseAssignmentExpression(); 14270eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner return ParseBraceInitializer(); 14280eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner } 142960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBraceInitializer(); 143060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializerWithPotentialDesignator(); 14311d922960e083906a586609ac6978678147250177Sebastian Redl 14325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1433296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // clang Expressions 14341d922960e083906a586609ac6978678147250177Sebastian Redl 143560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBlockLiteralExpression(); // ^{...} 1436296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff 1437296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff //===--------------------------------------------------------------------===// 14385508518a2702b00be3b15a26d772bde968972f54Anders Carlsson // Objective-C Expressions 143960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCAtExpression(SourceLocation AtLocation); 144060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCStringLiteral(SourceLocation AtLoc); 144160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); 144260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); 144360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); 14441b730e847ded503f2e615154035c083c4f94a067Douglas Gregor bool isSimpleObjCMessageExpression(); 144560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpression(); 144660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, 14472725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation SuperLoc, 1448b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, 14491d922960e083906a586609ac6978678147250177Sebastian Redl ExprArg ReceiverExpr); 145060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAssignmentExprWithObjCMessageExprStart( 14512725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation LBracloc, SourceLocation SuperLoc, 1452b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, ExprArg ReceiverExpr); 14536aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr); 145461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 14555508518a2702b00be3b15a26d772bde968972f54Anders Carlsson //===--------------------------------------------------------------------===// 14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.8: Statements and Blocks. 145761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 145860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseStatement() { 1459c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian StmtVector Stmts(Actions); 1460c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian return ParseStatementOrDeclaration(Stmts, true); 146161364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 1462c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian StmtResult ParseStatementOrDeclaration(StmtVector& Stmts, 1463c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian bool OnlyStatement = false); 14645ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor StmtResult ParseExprStatement(ParsedAttributes &Attrs); 14657f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseLabeledStatement(ParsedAttributes &Attr); 1466bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu StmtResult ParseCaseStatement(ParsedAttributes &Attr, 1467bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu bool MissingCase = false, 1468bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu ExprResult Expr = ExprResult()); 14697f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseDefaultStatement(ParsedAttributes &Attr); 14707f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseCompoundStatement(ParsedAttributes &Attr, 1471312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool isStmtExpr = false); 1472bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor StmtResult ParseCompoundStatement(ParsedAttributes &Attr, 1473bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool isStmtExpr, 1474bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor unsigned ScopeFlags); 147560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCompoundStatementBody(bool isStmtExpr = false); 147660d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseParenExprOrCondition(ExprResult &ExprResult, 1477d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *&DeclResult, 1478586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, 147944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis bool ConvertToBoolean); 14807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseIfStatement(ParsedAttributes &Attr); 14817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseSwitchStatement(ParsedAttributes &Attr); 14827f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseWhileStatement(ParsedAttributes &Attr); 14837f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseDoStatement(ParsedAttributes &Attr); 14847f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseForStatement(ParsedAttributes &Attr); 14857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseGotoStatement(ParsedAttributes &Attr); 14867f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseContinueStatement(ParsedAttributes &Attr); 14877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseBreakStatement(ParsedAttributes &Attr); 14887f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseReturnStatement(ParsedAttributes &Attr); 148960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseAsmStatement(bool &msAsm); 14903fedbe1f71c18fba01d39109d606f421a0103a2aEli Friedman StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc); 14913896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor 14923896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Describes the behavior that should be taken for an __if_exists 14933896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// block. 14943896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor enum IfExistsBehavior { 14953896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Parse the block; this code is always used. 14963896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Parse, 14973896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Skip the block entirely; this code is never used. 14983896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Skip, 14993896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Parse the block as a dependent block, which may be used in 15003896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// some template instantiations but not others. 15013896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Dependent 15023896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor }; 15033896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor 15043896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Describes the condition of a Microsoft __if_exists or 15053896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// __if_not_exists block. 15063896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor struct IfExistsCondition { 15073896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The location of the initial keyword. 15083896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor SourceLocation KeywordLoc; 15093896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Whether this is an __if_exists block (rather than an 15103896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// __if_not_exists block). 15113896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor bool IsIfExists; 15123896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor 15133896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Nested-name-specifier preceding the name. 15143896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor CXXScopeSpec SS; 15153896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor 15163896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The name we're looking for. 15173896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor UnqualifiedId Name; 15183896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor 15193896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The behavior of this __if_exists or __if_not_exists block 15203896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// should. 15213896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IfExistsBehavior Behavior; 15223896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor}; 15233896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor 15243896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result); 15251e862693c63067ae467b0b3884c44f753cd6e821Francois Pichet void ParseMicrosoftIfExistsStatement(StmtVector &Stmts); 1526563a645de82231a55e221fe655b7188bf8369662Francois Pichet void ParseMicrosoftIfExistsExternalDeclaration(); 1527563a645de82231a55e221fe655b7188bf8369662Francois Pichet void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, 1528563a645de82231a55e221fe655b7188bf8369662Francois Pichet AccessSpecifier& CurAS); 1529f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names, 1530f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu SmallVectorImpl<Expr *> &Constraints, 1531f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu SmallVectorImpl<Expr *> &Exprs); 1532a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1533a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1534a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // C++ 6: Statements and Blocks 1535a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 15367f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseCXXTryBlock(ParsedAttributes &Attr); 153760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc); 153860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXCatchBlock(); 1539a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1540a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 154128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley // MS: SEH Statements and Blocks 154228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 154328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHTryBlock(ParsedAttributes &Attr); 154428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHTryBlockCommon(SourceLocation Loc); 154528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHExceptBlock(SourceLocation Loc); 154628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHFinallyBlock(SourceLocation Loc); 154728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 154828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley //===--------------------------------------------------------------------===// 1549a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // Objective-C Statements 1550a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 155160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCAtStatement(SourceLocation atLoc); 155260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCTryStmt(SourceLocation atLoc); 155360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCThrowStmt(SourceLocation atLoc); 155460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); 1555f85e193739c953358c865005855253af4f68a497John McCall StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc); 1556b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 15575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 15595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7: Declarations. 156067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall 156167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// A context for parsing declaration specifiers. TODO: flesh this 156267d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// out, there are other significant restrictions on specifiers than 156367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// would be best implemented in the parser. 156467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall enum DeclSpecContext { 156567d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DSC_normal, // normal context 15660efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_class, // class context, enables 'friend' 15670efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_top_level // top-level/namespace declaration context 156867d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall }; 15691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1570ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Information on a C++0x for-range-initializer found while parsing a 1571ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// declaration which turns out to be a for-range-declaration. 1572ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith struct ForRangeInit { 1573ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation ColonLoc; 1574ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult RangeExpr; 1575ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 1576ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); } 1577ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith }; 1578ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 1579c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts, 1580c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian unsigned Context, SourceLocation &DeclEnd, 15817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributesWithRange &attrs); 1582c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts, 1583c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian unsigned Context, 1584bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 15857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs, 1586ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool RequireSemi, 1587ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ForRangeInit *FRI = 0); 15880706df40064d4d7559b4304af79d519033414b84Richard Smith bool MightBeDeclarator(unsigned Context); 158954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, 1590d8ac05753dc4506224d445ff98399c01da3136e5John McCall bool AllowFunctionDefinitions, 1591ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation *DeclEnd = 0, 1592ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ForRangeInit *FRI = 0); 1593d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationAfterDeclarator(Declarator &D, 1594e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1595ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool ParseAttributesAfterDeclarator(Declarator &D); 1596ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Decl *ParseDeclarationAfterDeclaratorAndAttributes(Declarator &D, 1597ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1598c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope); 1599c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope); 1600d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 16010fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// \brief When in code-completion, skip parsing of the function/method body 16020fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// unless the body contains the code-completion point. 16030fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// 16040fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// \returns true if the function body was skipped. 1605b162054ba8f5b64fe87fbc4837933ab23eebd52bArgyrios Kyrtzidis bool trySkippingFunctionBodyForCodeCompletion(); 16060fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis 1607f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, 16084d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 1609e40c295d017a8f75a945fe9ed2aa9d8bb7a7341aChris Lattner AccessSpecifier AS); 16100efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); 16111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseDeclarationSpecifiers(DeclSpec &DS, 16124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 161367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall AccessSpecifier AS = AS_none, 161467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DeclSpecContext DSC = DSC_normal); 16151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid, 16167a0ab5f387722c83e19c7133b46b16988eb19e45Chris Lattner const char *&PrevSpec, 1617fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID, 1618d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1619d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 16204d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 1621c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith void ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS = AS_none); 16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1623cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall void ParseObjCTypeQualifierList(ObjCDeclSpec &DS, 1624cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Declarator::TheContext Context); 16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16264c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, 16271b21391b3b1b7dd829c35f9b69199ed2a67da25aArgyrios Kyrtzidis const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 16281b21391b3b1b7dd829c35f9b69199ed2a67da25aArgyrios Kyrtzidis AccessSpecifier AS = AS_none); 1629d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl); 16305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, 1631d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 1632bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1633bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct FieldCallback { 1634d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall virtual Decl *invoke(FieldDeclarator &Field) = 0; 16356c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual ~FieldCallback() {} 16366c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall 16376c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall private: 16386c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual void _anchor(); 1639bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall }; 1640d0014540005f2a5ab837365db6bd40f479406758John McCall struct ObjCPropertyCallback; 1641bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1642bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback); 16431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16449497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false); 1645eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isTypeSpecifierQualifier(); 16465f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff bool isTypeQualifier() const; 1647b3a4e432c90be98c6d918087750397e86d030368Chris Lattner 1648b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// isKnownToBeTypeSpecifier - Return true if we know that the specified token 1649b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// is definitely a type-specifier. Return false if it isn't part of a type 1650b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// specifier or if we're not sure. 1651b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool isKnownToBeTypeSpecifier(const Token &Tok) const; 16525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isDeclarationStatement - Disambiguates between a declaration or an 16545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// expression statement, when parsing function bodies. 16555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for declaration, false for expression. 16565404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isDeclarationStatement() { 16575404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis if (getLang().CPlusPlus) 16585404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isCXXDeclarationStatement(); 16599497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return isDeclarationSpecifier(true); 16605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 16615404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1662bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// isSimpleDeclaration - Disambiguates between a declaration or an 1663bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// expression, mainly used for the C 'clause-1' or the C++ 1664bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis // 'for-init-statement' part of a 'for' statement. 1665bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// Returns true for declaration, false for expression. 1666bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis bool isSimpleDeclaration() { 1667bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis if (getLang().CPlusPlus) 1668bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis return isCXXSimpleDeclaration(); 16699497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return isDeclarationSpecifier(true); 1670bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis } 1671bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis 16729497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor /// \brief Determine whether we are currently at the start of an Objective-C 16739497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor /// class message that appears to be missing the open bracket '['. 16749497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor bool isStartOfObjCClassMessageMissingOpenBracket(); 16759497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor 16760efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief Starting with a scope specifier, identifier, or 16770efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id that refers to the current class, determine whether 16780efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// this is a constructor declarator. 16790efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor bool isConstructorDeclarator(); 16800efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 16818b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// \brief Specifies the context in which type-id/expression 16828b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// disambiguation will occur. 16838b642592a35167a3780074e78674e0bece87c40cDouglas Gregor enum TentativeCXXTypeIdContext { 16848b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdInParens, 16858b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdAsTemplateArgument 16868b642592a35167a3780074e78674e0bece87c40cDouglas Gregor }; 16878b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 16888b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 168978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know 169078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// whether the parens contain an expression or a type-id. 169178c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// Returns true for a type-id and false for an expression. 1692f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens(bool &isAmbiguous) { 169378c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis if (getLang().CPlusPlus) 1694f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(TypeIdInParens, isAmbiguous); 1695f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis isAmbiguous = false; 169678c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis return isTypeSpecifierQualifier(); 169778c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis } 1698f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens() { 1699f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1700f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isTypeIdInParens(isAmbiguous); 1701f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 170278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 17035404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXDeclarationStatement - C++-specialized function that disambiguates 17045404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a declaration or an expression statement, when parsing function 17055404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// bodies. Returns true for declaration, false for expression. 17065404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXDeclarationStatement(); 17075404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 17085404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXSimpleDeclaration - C++-specialized function that disambiguates 17095404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a simple-declaration or an expression-statement. 17105404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 17115404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 17125404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns false if the statement is disambiguated as expression. 17135404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXSimpleDeclaration(); 17145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 17155404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXFunctionDeclarator - Disambiguates between a function declarator or 17165404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// a constructor-style initializer, when parsing declaration statements. 17175404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for function declarator and false for constructor-style 1718e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to 1719259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis /// indicate that the parens were disambiguated as function declarator. 17205404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 17215404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1722e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis bool isCXXFunctionDeclarator(bool warnIfAmbiguous); 17235404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1724a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// isCXXConditionDeclaration - Disambiguates between a declaration or an 1725a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// expression for a condition of a if/switch/while/for statement. 1726a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 1727a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1728a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis bool isCXXConditionDeclaration(); 1729a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis 1730f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); 1731f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context) { 1732f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1733f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(Context, isAmbiguous); 1734f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 173578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 1736b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult - Used as the result value for functions whose purpose is to 1737b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// disambiguate C++ constructs by "tentatively parsing" them. 1738b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// This is a class instead of a simple enum because the implicit enum-to-bool 1739b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// conversions may cause subtle bugs. 1740b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis class TPResult { 1741b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis enum Result { 1742b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_true, 1743b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_false, 1744b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_ambiguous, 1745b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_error 1746b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis }; 1747b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis Result Res; 1748b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult(Result result) : Res(result) {} 1749b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis public: 1750b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult True() { return TPR_true; } 1751b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult False() { return TPR_false; } 1752b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Ambiguous() { return TPR_ambiguous; } 1753b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Error() { return TPR_error; } 1754b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis 1755b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator==(const TPResult &RHS) const { return Res == RHS.Res; } 1756b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; } 1757b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis }; 1758b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis 1759a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// \brief Based only on the given token kind, determine whether we know that 1760a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// we're at the start of an expression or a type-specifier-seq (which may 1761a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// be an expression, in C++). 1762a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// 1763a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// This routine does not attempt to resolve any of the trick cases, e.g., 1764a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// those involving lookup of identifiers. 1765a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// 1766a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// \returns \c TPR_true if this token starts an expression, \c TPR_false if 1767a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot 1768a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// tell. 1769a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind); 1770a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor 1771b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a 1772b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// declaration specifier, TPResult::False() if it is not, 1773b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult::Ambiguous() if it could be either a decl-specifier or a 1774b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// function-style cast, and TPResult::Error() if a parsing error was 1775b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// encountered. 17765404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Doesn't consume tokens. 1777b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult isCXXDeclarationSpecifier(); 1778a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor 17795404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // "Tentative parsing" functions, used for disambiguation. If a parsing error 1780b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // is encountered they will return TPResult::Error(). 1781b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // Returning TPResult::True()/False() indicates that the ambiguity was 1782b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates 1783b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // that more tentative parsing is necessary for disambiguation. 17845404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // They all consume tokens, so backtracking should be used after calling them. 17855404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1786b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseDeclarationSpecifier(); 1787b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseSimpleDeclaration(); 1788b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseTypeofSpecifier(); 17899bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor TPResult TryParseProtocolQualifiers(); 1790b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseInitDeclaratorList(); 179178c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); 1792b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseParameterDeclarationClause(); 1793b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseFunctionDeclarator(); 1794b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseBracketDeclarator(); 17955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1796683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor TypeResult ParseTypeName(SourceRange *Range = 0, 1797683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Declarator::TheContext Context 1798f85e193739c953358c865005855253af4f68a497John McCall = Declarator::TypeNameContext, 1799c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith AccessSpecifier AS = AS_none, 1800c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith Decl **OwnedType = 0); 180198eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump void ParseBlockId(); 18027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 18037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ProhibitAttributes(ParsedAttributesWithRange &attrs) { 18047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (!attrs.Range.isValid()) return; 18057f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DiagnoseProhibitedAttributes(attrs); 18067f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18077f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs); 18087f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 1809eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void MaybeParseGNUAttributes(Declarator &D, 1810eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski LateParsedAttrList *LateAttrs = 0) { 18117f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (Tok.is(tok::kw___attribute)) { 18120b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 18137f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation endLoc; 1814eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski ParseGNUAttributes(attrs, &endLoc, LateAttrs); 18150b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall D.takeAttributes(attrs, endLoc); 18167f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18177f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18187f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseGNUAttributes(ParsedAttributes &attrs, 1819eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation *endLoc = 0, 1820eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski LateParsedAttrList *LateAttrs = 0) { 18217f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (Tok.is(tok::kw___attribute)) 1822eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski ParseGNUAttributes(attrs, endLoc, LateAttrs); 18237f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseGNUAttributes(ParsedAttributes &attrs, 1825eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation *endLoc = 0, 1826eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski LateParsedAttrList *LateAttrs = 0); 1827eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void ParseGNUAttributeArgs(IdentifierInfo *AttrName, 1828eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation AttrNameLoc, 1829eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski ParsedAttributes &Attrs, 1830eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation *EndLoc); 18317f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 18327f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseCXX0XAttributes(Declarator &D) { 18337f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) { 18340b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrs(AttrFactory); 18357f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation endLoc; 18367f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseCXX0XAttributes(attrs, &endLoc); 18370b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall D.takeAttributes(attrs, endLoc); 18387f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18397f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18407f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseCXX0XAttributes(ParsedAttributes &attrs, 18417f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc = 0) { 18427f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) { 18430b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrsWithRange(AttrFactory); 18447f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseCXX0XAttributes(attrsWithRange, endLoc); 18450b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall attrs.takeAllFrom(attrsWithRange); 18467f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18477f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18487f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseCXX0XAttributes(ParsedAttributesWithRange &attrs, 18497f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc = 0) { 18507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) 18517f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseCXX0XAttributes(attrs, endLoc); 18527f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18533497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne 18543497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne void ParseCXX0XAttributeSpecifier(ParsedAttributes &attrs, 18553497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne SourceLocation *EndLoc = 0); 18567f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseCXX0XAttributes(ParsedAttributesWithRange &attrs, 18577f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *EndLoc = 0); 18587f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 18597f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs, 18607f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc = 0) { 186162ec1f2fd7368542bb926c04797fb07023547694Francois Pichet if (getLang().MicrosoftExt && Tok.is(tok::l_square)) 18627f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseMicrosoftAttributes(attrs, endLoc); 18637f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18647f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseMicrosoftAttributes(ParsedAttributes &attrs, 18657f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc = 0); 18667f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseMicrosoftDeclSpec(ParsedAttributes &attrs); 18677f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs); 18687f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseBorlandTypeAttributes(ParsedAttributes &attrs); 1869f315fa81eef1977b3457fd7a7d4639e060fe7278Peter Collingbourne void ParseOpenCLAttributes(ParsedAttributes &attrs); 1870207f4d8543529221932af82836016a2ef066c917Peter Collingbourne void ParseOpenCLQualifiers(DeclSpec &DS); 18717f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 18720a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor VersionTuple ParseVersionTuple(SourceRange &Range); 18730a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor void ParseAvailabilityAttribute(IdentifierInfo &Availability, 18740a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor SourceLocation AvailabilityLoc, 18750a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor ParsedAttributes &attrs, 18760a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor SourceLocation *endLoc); 18770a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 1878b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski bool IsThreadSafetyAttribute(llvm::StringRef AttrName); 1879b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski void ParseThreadSafetyAttribute(IdentifierInfo &AttrName, 1880b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski SourceLocation AttrNameLoc, 1881b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski ParsedAttributes &Attrs, 1882b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski SourceLocation *EndLoc); 1883b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski 1884b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski 1885d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff void ParseTypeofSpecifier(DeclSpec &DS); 18866fd634f4ac59f5923cffadadb99d19f23c18707aAnders Carlsson void ParseDecltypeSpecifier(DeclSpec &DS); 1887db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt void ParseUnderlyingTypeSpecifier(DeclSpec &DS); 1888b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void ParseAtomicSpecifier(DeclSpec &DS); 1889b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 18900b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne ExprResult ParseAlignArgument(SourceLocation Start, 18910b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne SourceLocation &EllipsisLoc); 189282d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne void ParseAlignmentSpecifier(ParsedAttributes &Attrs, 189382d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne SourceLocation *endLoc = 0); 1894eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1895cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson VirtSpecifiers::Specifier isCXX0XVirtSpecifier() const; 1896b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson void ParseOptionalCXX0XVirtSpecifierSeq(VirtSpecifiers &VS); 18971f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 18988a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson bool isCXX0XFinalKeyword() const; 1899cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 1900eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to 1901eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// enter a new C++ declarator scope and exit it when the function is 1902eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// finished. 1903eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis class DeclaratorScopeObj { 1904eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis Parser &P; 1905751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis CXXScopeSpec &SS; 1906f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis bool EnteredScope; 1907f7f3d0db754db0500b56d49ac19f795f13965912John McCall bool CreatedScope; 1908eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis public: 1909f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) 1910f7f3d0db754db0500b56d49ac19f795f13965912John McCall : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} 1911eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1912eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis void EnterDeclaratorScope() { 19132bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis assert(!EnteredScope && "Already entered the scope!"); 1914f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was not set!"); 1915f7f3d0db754db0500b56d49ac19f795f13965912John McCall 1916f7f3d0db754db0500b56d49ac19f795f13965912John McCall CreatedScope = true; 1917f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.EnterScope(0); // Not a decl scope. 1918f7f3d0db754db0500b56d49ac19f795f13965912John McCall 191923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS)) 19203fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor EnteredScope = true; 1921eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1922eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1923eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis ~DeclaratorScopeObj() { 1924f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis if (EnteredScope) { 1925f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was cleared ?"); 192623c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS); 1927f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis } 1928f7f3d0db754db0500b56d49ac19f795f13965912John McCall if (CreatedScope) 1929f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.ExitScope(); 1930eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1931eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis }; 19321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseDeclarator - Parse and verify a newly-initialized declarator. 19345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDeclarator(Declarator &D); 19354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl /// A function that parses a variant of direct-declarator. 19364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef void (Parser::*DirectDeclParseFunction)(Declarator&); 19374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDeclaratorInternal(Declarator &D, 19384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl DirectDeclParseFunction DirectDeclParser); 19397f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 1940bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, 1941bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool CXX0XAttributesAllowed = true); 19425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDirectDeclarator(Declarator &D); 19435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseParenDeclarator(Declarator &D); 19444a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor void ParseFunctionDeclarator(Declarator &D, 19457f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs, 19464a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker, 19477399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner bool RequiresArg = false); 19483fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor bool isFunctionDeclaratorIdentifierList(); 19493fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor void ParseFunctionDeclaratorIdentifierList( 19503fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor Declarator &D, 1951686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo); 19523fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor void ParseParameterDeclarationClause( 19533fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor Declarator &D, 19543fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor ParsedAttributes &attrs, 1955686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo, 19563fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor SourceLocation &EllipsisLoc); 19575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseBracketDeclarator(Declarator &D); 19581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19598f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner //===--------------------------------------------------------------------===// 19608f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner // C++ 7: Declarations [dcl.dcl] 19611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1962bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool isCXX0XAttributeSpecifier(bool FullLookahead = false, 1963bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt tok::TokenKind *After = 0); 1964bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt 1965d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd, 1966d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation InlineLoc = SourceLocation()); 1967f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc, 1968f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<IdentifierInfo*>& Ident, 1969f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<SourceLocation>& NamespaceLoc, 1970f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu unsigned int index, SourceLocation& InlineLoc, 19714a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor ParsedAttributes& attrs, 19724a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker); 1973d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context); 1974d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseUsingDirectiveOrDeclaration(unsigned Context, 197578b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 1976d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 1977c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith ParsedAttributesWithRange &attrs, 1978c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith Decl **OwnedType = 0); 197978b810559d89e996e00684335407443936ce34a1John McCall Decl *ParseUsingDirective(unsigned Context, 198078b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 19817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation &DeclEnd, 19827f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs); 198378b810559d89e996e00684335407443936ce34a1John McCall Decl *ParseUsingDeclaration(unsigned Context, 198478b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 198578b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 1986d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 1987c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith AccessSpecifier AS = AS_none, 1988c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith Decl **OwnedType = 0); 1989d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd); 1990d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc, 1991d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation AliasLoc, IdentifierInfo *Alias, 1992d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd); 19931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1994e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 1995e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 9: classes [class] and C structs/unions. 19964c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, 19971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclSpec &DS, 19984d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1999d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl AccessSpecifier AS = AS_none, 2000efaa93aaa2653f4eb40e6a22e504a448da94aaf8Douglas Gregor bool EnteringContext = false, 2001d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 20024cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType, 2003d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 20047a614d8380297fcd2bc23986241905d97222948cRichard Smith ExprResult ParseCXXMemberInitializer(bool IsFunction, 20057a614d8380297fcd2bc23986241905d97222948cRichard Smith SourceLocation &EqualLoc); 20065f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen void ParseCXXClassMemberDeclaration(AccessSpecifier AS, AttributeList *Attr, 2007c9068d7dd94d439cec66c421115d15303e481025John McCall const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 2008c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject *DiagsFromTParams = 0); 2009d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseConstructorInitializer(Decl *ConstructorDecl); 2010d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall MemInitResult ParseMemInitializer(Decl *ConstructorDecl); 2011d33133cdc1af466f9c276249b2621be03867888bEli Friedman void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, 2012d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ThisDecl); 2013e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 2014e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 2015e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 10: Derived classes [class.derived] 201622216eb4fb0936d2488fc03abd285d135c36ff01David Blaikie TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc, 201722216eb4fb0936d2488fc03abd285d135c36ff01David Blaikie SourceLocation &EndLocation); 2018d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseBaseClause(Decl *ClassDecl); 2019d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall BaseResult ParseBaseSpecifier(Decl *ClassDecl); 20201b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor AccessSpecifier getAccessSpecifierIfPresent() const; 20211cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor 20223f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 20233f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Name, 20243f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation NameLoc, 20253f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool EnteringContext, 2026b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2027d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor UnqualifiedId &Id, 20280278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor bool AssumeTemplateId, 20290278e123b4606ea15dbfa717e9c5a76a5ef2bc7dDouglas Gregor SourceLocation TemplateKWLoc); 2030ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, 2031b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2032ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &Result); 20333f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, 203402a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowDestructorName, 203502a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowConstructorName, 2036b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 20373f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &Result); 20383f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor 20391cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor //===--------------------------------------------------------------------===// 2040adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14: Templates [temp] 2041c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 2042adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14.1: Template Parameters [temp.param] 2043d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationStartingWithTemplate(unsigned Context, 20445f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen SourceLocation &DeclEnd, 20455f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AccessSpecifier AS = AS_none, 20465f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AttributeList *AccessAttrs = 0); 2047d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context, 20485f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen SourceLocation &DeclEnd, 20495f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AccessSpecifier AS, 20505f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AttributeList *AccessAttrs); 2051d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseSingleDeclarationAfterTemplate( 20521426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor unsigned Context, 20534d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 2054c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject &DiagsFromParams, 20551426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor SourceLocation &DeclEnd, 20565f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AccessSpecifier AS=AS_none, 20575f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AttributeList *AccessAttrs = 0); 20581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseTemplateParameters(unsigned Depth, 2059686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Decl*> &TemplateParams, 20601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation &LAngleLoc, 2061c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor SourceLocation &RAngleLoc); 2062c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor bool ParseTemplateParameterList(unsigned Depth, 2063686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Decl*> &TemplateParams); 206498440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor bool isStartOfTemplateTypeParameter(); 2065d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateParameter(unsigned Depth, unsigned Position); 2066d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTypeParameter(unsigned Depth, unsigned Position); 2067d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); 2068d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); 2069d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor // C++ 14.3: Template arguments [temp.arg] 2070686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList; 2071cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 20727532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor bool ParseTemplateIdAfterTemplateName(TemplateTy Template, 20731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateNameLoc, 2074059101f922de6eb765601459925f4c8914420b23Douglas Gregor const CXXScopeSpec &SS, 2075cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor bool ConsumeLastToken, 2076cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &LAngleLoc, 2077cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateArgList &TemplateArgs, 2078cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &RAngleLoc); 2079cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 2080c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, 2081059101f922de6eb765601459925f4c8914420b23Douglas Gregor CXXScopeSpec &SS, 2082ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &TemplateName, 208339a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor SourceLocation TemplateKWLoc = SourceLocation(), 208439a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor bool AllowTypeAnnotation = true); 2085059101f922de6eb765601459925f4c8914420b23Douglas Gregor void AnnotateTemplateIdTokenAsType(); 2086d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor bool IsTemplateArgumentList(unsigned Skip = 0); 2087314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); 2088788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor ParsedTemplateArgument ParseTemplateTemplateArgument(); 2089314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor ParsedTemplateArgument ParseTemplateArgument(); 2090d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseExplicitInstantiation(SourceLocation ExternLoc, 2091d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SourceLocation TemplateLoc, 2092d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SourceLocation &DeclEnd); 209364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 209464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl //===--------------------------------------------------------------------===// 20956aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor // Modules 20966aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor DeclGroupPtrTy ParseModuleImport(); 20976aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor 20986aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor //===--------------------------------------------------------------------===// 209964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // GNU G++: Type Traits [Type-Traits.html in the GCC manual] 210060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseUnaryTypeTrait(); 21016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet ExprResult ParseBinaryTypeTrait(); 2102f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor 2103f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor //===--------------------------------------------------------------------===// 210421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley // Embarcadero: Arary and Expression Traits 210521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult ParseArrayTypeTrait(); 2106552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult ParseExpressionTrait(); 2107552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2108552622067dc45013d240f73952fece703f5e63bdJohn Wiegley //===--------------------------------------------------------------------===// 2109f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor // Preprocessor code-completion pass-through 2110f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor virtual void CodeCompleteDirective(bool InConditional); 2111f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor virtual void CodeCompleteInConditionalExclusion(); 21121fbb447e9d43c2c676e94081fbfee7eb6cbe933bDouglas Gregor virtual void CodeCompleteMacroName(bool IsDefinition); 2113f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor virtual void CodeCompletePreprocessorExpression(); 2114f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro, 2115f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor MacroInfo *MacroInfo, 2116f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor unsigned ArgumentIndex); 211755817afdf9d453a443262a733f6caf6692dca118Douglas Gregor virtual void CodeCompleteNaturalLanguage(); 21185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 21195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 21215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2123