Parser.h revision 6f42b62b6194f53bcbc349f5d17388e1936535d7
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; 39a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 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 99a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// 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 111a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie // __except block 112a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie IdentifierInfo *Ident__exception_code, 113a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident___exception_code, 114a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident_GetExceptionCode; 115a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie // __except filter expression 116a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie IdentifierInfo *Ident__exception_info, 117a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident___exception_info, 118a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident_GetExceptionInfo; 119a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie // __finally 120a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie IdentifierInfo *Ident__abnormal_termination, 121a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident___abnormal_termination, 122a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie *Ident_AbnormalTermination; 12328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 124b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor /// Contextual keywords for Microsoft extensions. 125b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor IdentifierInfo *Ident__except; 126a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 127662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// Ident_super - IdentifierInfo for "super", to support fast 128662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar /// comparison. 129662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar IdentifierInfo *Ident_super; 13082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// Ident_vector and Ident_pixel - cached IdentifierInfo's for 13182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// "vector" and "pixel" fast comparison. Only present if 13282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// AltiVec enabled. 13382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_vector; 13482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson IdentifierInfo *Ident_pixel; 135662e8b5647adbb1bc9eeceece7b64600cfa87471Daniel Dunbar 136e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor /// Objective-C contextual keywords. 137e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor mutable IdentifierInfo *Ident_instancetype; 138a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1390a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "introduced". 1400a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_introduced; 1410a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 1420a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "deprecated". 1430a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_deprecated; 1440a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 1450a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Identifier for "obsoleted". 1460a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor IdentifierInfo *Ident_obsoleted; 1470a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 148b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor /// \brief Identifier for "unavailable". 149b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor IdentifierInfo *Ident_unavailable; 150006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian 151006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian /// \brief Identifier for "message". 152006e42f0c8b65b783d565ef10b938a9e82fc02e3Fariborz Jahanian IdentifierInfo *Ident_message; 153b53e417ba487f4193ef3b0485b420e0fdae643a2Douglas Gregor 154a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// C++0x contextual keywords. 1557eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson mutable IdentifierInfo *Ident_final; 1567eeb4ec11043d4860361348f2b19299d957d47a9Anders Carlsson mutable IdentifierInfo *Ident_override; 1571f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 1586f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> AlignHandler; 1596f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> GCCVisibilityHandler; 1606f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> OptionsHandler; 1616f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> PackHandler; 1626f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> MSStructHandler; 1636f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> UnusedHandler; 1646f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> WeakHandler; 1656f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> FPContractHandler; 1666f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<PragmaHandler> OpenCLExtensionHandler; 1671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// Whether the '>' token acts as an operator or not. This will be 16955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// true except when we are parsing an expression within a C++ 17055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// template argument list, where the '>' closes the template 17155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// argument list. 17255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor bool GreaterThanIsOperator; 173a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 17408d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonIsSacred - When this is false, we aggressively try to recover from 17508d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not 17608d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// safe in case statements and a few other things. This is managed by the 17708d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner /// ColonProtectionRAIIObject RAII object. 17808d92ecf6e5b1fd23177a08c2312b58d63d863dbChris Lattner bool ColonIsSacred; 17955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 180a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// \brief When true, we are directly inside an Objective-C messsage 1810fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// send expression. 1820fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// 1830fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// This is managed by the \c InMessageExpressionRAIIObject class, and 1840fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor /// should not be set directly. 1850fbda68b50ce17d7ad36ef7a5ed77518a5cd272eDouglas Gregor bool InMessageExpression; 186a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 187c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor /// The "depth" of the template parameters currently being parsed. 188c3058338075a2132e057f1249a13b55a81fe021cDouglas Gregor unsigned TemplateParameterDepth; 189a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1908113ecfa4e41e2c888b1794389dfe3bce6386493Ted Kremenek /// Factory object for creating AttributeList objects. 1910b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall AttributeFactory AttrFactory; 1921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19325a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis /// \brief Gathers and cleans up objects when parsing of a top-level 19425a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis /// declaration is finished. 19525a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis DelayedCleanupPool TopLevelDeclCleanupPool; 19625a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 197b57791e5b40afa6691063c83d0e95c416fb19fdeDouglas Gregor IdentifierInfo *getSEHExceptKeyword(); 198a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 200f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Parser(Preprocessor &PP, Sema &Actions); 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ~Parser(); 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const LangOptions &getLang() const { return PP.getLangOptions(); } 204444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); } 2050102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner Preprocessor &getPreprocessor() const { return PP; } 206f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &getActions() const { return Actions; } 2071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2080102c30896c83f70cf6b6519fd5c674cb981c0b5Chris Lattner const Token &getCurToken() const { return Tok; } 20923c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor Scope *getCurScope() const { return Actions.getCurScope(); } 210a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 211a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); } 212a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Type forwarding. All of these are statically 'void*', but they may all be 2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // different actual classes based on the actions in place. 2152b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 2162b5289b6fd7e3d9899868410a498c081c9595662John McCall typedef OpaquePtr<TemplateName> TemplateTy; 2177ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 218686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists; 219c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 2209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::ExprResult ExprResult; 2219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::StmtResult StmtResult; 2229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::BaseResult BaseResult; 2239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::MemInitResult MemInitResult; 2249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef clang::TypeResult TypeResult; 22515faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 2269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef Expr *ExprArg; 2279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall typedef ASTMultiPtr<Stmt*> MultiStmtArg; 228f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::FullExprArg FullExprArg; 2291d922960e083906a586609ac6978678147250177Sebastian Redl 23060d7b3a319d84d688752be3870615ac0f111fb16John McCall /// Adorns a ExprResult with Actions to make it an ExprResult 23160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Owned(ExprResult res) { 23260d7b3a319d84d688752be3870615ac0f111fb16John McCall return ExprResult(res); 23361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 23460d7b3a319d84d688752be3870615ac0f111fb16John McCall /// Adorns a StmtResult with Actions to make it an StmtResult 23560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Owned(StmtResult res) { 23660d7b3a319d84d688752be3870615ac0f111fb16John McCall return StmtResult(res); 23761364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 23861364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 23960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError() { return ExprResult(true); } 24060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError() { return StmtResult(true); } 241d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor 24260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprError(const DiagnosticBuilder &) { return ExprError(); } 24360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult StmtError(const DiagnosticBuilder &) { return StmtError(); } 24461364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 24560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ExprEmpty() { return ExprResult(false); } 2465ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Parsing methods. 2481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseTranslationUnit - All in one method that initializes parses, and 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// shuts down the parser. 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseTranslationUnit(); 2521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Initialize - Warm up the parser. 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Initialize(); 2561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if 2581f6443255894429fba384de0d5b6389ef578a5e9Steve Naroff /// the EOF was encountered. 259682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner bool ParseTopLevelDecl(DeclGroupPtrTy &Result); 2601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2613fe104154dd2e8ffb351142d74f308938b5c99bfFariborz Jahanian DeclGroupPtrTy FinishPendingObjCActions(); 26263e963cdffca9530f920dbab58b9b4eecb2a582cFariborz Jahanian 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Low-Level token peeking and consumption methods. 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 2671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenParen - Return true if the cur token is '(' or ')'. 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenParen() const { 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_paren || Tok.getKind() == tok::r_paren; 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBracket - Return true if the cur token is '[' or ']'. 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBracket() const { 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_square || Tok.getKind() == tok::r_square; 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenBrace - Return true if the cur token is '{' or '}'. 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenBrace() const { 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::l_brace || Tok.getKind() == tok::r_brace; 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isTokenStringLiteral - True if this token is a string-literal. 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isTokenStringLiteral() const { 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Tok.getKind() == tok::string_literal || 2855cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::wide_string_literal || 2865cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::utf8_string_literal || 2875cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::utf16_string_literal || 2885cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Tok.getKind() == tok::utf32_string_literal; 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 290eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 291fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu /// \brief Returns true if the current token is '=' or is a type of '='. 292fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu /// For typos, give a fixit to '=' 293fcaf27e185695bdf755e202aeba9632e0a8ef3c6Richard Trieu bool isTokenEqualOrEqualTypo(); 294a6eb5f81d13bacac01faff70a947047725b4413fArgyrios Kyrtzidis 2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeToken - Consume the current 'peek token' and lex the next one. 296d6ecc5cf945ccdf2b931137e364a69cde59ab18bZhongxing Xu /// This does not work with all kinds of tokens: strings and specific other 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tokens must be consumed with custom methods below. This returns the 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// location of the consumed token. 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeToken() { 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer !isTokenBrace() && 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should consume special tokens with Consume*Token"); 3037d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis 3047d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis if (Tok.is(tok::code_completion)) 3057d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis return handleUnexpectedCodeCompletionToken(); 3067d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis 3074b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3094b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeAnyToken - Dispatch to the right Consume* method based on the 3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// current token type. This should only be used in cases where the type of 3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the token really isn't known, e.g. in error recovery. 3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeAnyToken() { 3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isTokenParen()) 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeParen(); 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBracket()) 3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBracket(); 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (isTokenBrace()) 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeBrace(); 322d62701bc5321049353017e9abf1963edd57646aaSteve Naroff else if (isTokenStringLiteral()) 323d62701bc5321049353017e9abf1963edd57646aaSteve Naroff return ConsumeStringToken(); 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ConsumeToken(); 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeParen - This consume method keeps the paren count up-to-date. 3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeParen() { 3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenParen() && "wrong consume method"); 3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_paren) 3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++ParenCount; 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (ParenCount) 3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --ParenCount; // Don't let unbalanced )'s drive the count negative. 3364b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3384b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBracket - This consume method keeps the bracket count up-to-date. 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBracket() { 3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBracket() && "wrong consume method"); 3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_square) 3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BracketCount; 3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BracketCount) 3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BracketCount; // Don't let unbalanced ]'s drive the count negative. 3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3504b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3524b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeBrace - This consume method keeps the brace count up-to-date. 3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeBrace() { 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenBrace() && "wrong consume method"); 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Tok.getKind() == tok::l_brace) 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ++BraceCount; 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else if (BraceCount) 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer --BraceCount; // Don't let unbalanced }'s drive the count negative. 3631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3644b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3664b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ConsumeStringToken - Consume the current 'peek token', lexing a new one 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and returning the token kind. This method is specific to strings, as it 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// handles string literal concatenation, as per C99 5.1.1.2, translation 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// phase #6. 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation ConsumeStringToken() { 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isTokenStringLiteral() && 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Should only consume string literals with this method"); 3764b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor PrevTokLocation = Tok.getLocation(); 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PP.Lex(Tok); 3784b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return PrevTokLocation; 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 381dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// \brief Consume the current code-completion token. 382dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// 383dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// This routine should be called to consume the code-completion token once 384dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// a code-completion action has already been invoked. 385dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor SourceLocation ConsumeCodeCompletionToken() { 386dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor assert(Tok.is(tok::code_completion)); 387dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PrevTokLocation = Tok.getLocation(); 388dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor PP.Lex(Tok); 389a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie return PrevTokLocation; 390dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor } 391a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 3927d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis ///\ brief When we are consuming a code-completion token without having 393dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// matched specific position in the grammar, provide code-completion results 394dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor /// based on context. 3957d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// 3967d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// \returns the source location of the code-completion token. 3977d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis SourceLocation handleUnexpectedCodeCompletionToken(); 3987d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis 3997d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// \brief Abruptly cut off parsing; mainly used when we have reached the 4007d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis /// code-completion point. 4017d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis void cutOffParsing() { 4027d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis PP.setCodeCompletionReached(); 4037d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis // Cut off parsing by acting as if we reached the end-of-file. 4047d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis Tok.setKind(tok::eof); 4057d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis } 406dc8453422bec3bbf70c03920e01498d75783d122Douglas Gregor 4072fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis /// \brief Clear and free the cached objc methods. 4082fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis void clearLateParsedObjCMethods(); 4092fea2242fe7e7c37df1e96316616febeaf4e29ebArgyrios Kyrtzidis 410b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis /// \brief Handle the annotation token produced for #pragma unused(...) 411b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis void HandlePragmaUnused(); 412b918d0f5d8f147e1e26c34e6cf42a79af2d2ec41Argyrios Kyrtzidis 413426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola /// \brief Handle the annotation token produced for 414426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola /// #pragma GCC visibility... 415426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola void HandlePragmaVisibility(); 416426fc94ed3bce15b55c43692537e3833388f0352Rafael Espindola 4176b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// GetLookAheadToken - This peeks ahead N tokens and returns that token 4186b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1) 4196b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// returns the token after Tok, etc. 4206b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 4216b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// Note that this differs from the Preprocessor's LookAhead method, because 4226b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// the Parser always has one token lexed that the preprocessor doesn't. 4236b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner /// 42403db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis const Token &GetLookAheadToken(unsigned N) { 4256b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner if (N == 0 || Tok.is(tok::eof)) return Tok; 4266b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner return PP.LookAhead(N-1); 4276b884508c3bc97cc9df9516adb92fbf88dd0a2e4Chris Lattner } 428f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis 429f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// NextToken - This peeks ahead one token and returns it without 430f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis /// consuming it. 431f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis const Token &NextToken() { 43203db1b31dd926409b7defc1c90b66549464652c0Argyrios Kyrtzidis return PP.LookAhead(0); 433f7da726f09a6b7c5b9f5308e9690cb015398e671Argyrios Kyrtzidis } 4345404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 435d3891e9fb7eb25436e5c537189030bed0d5a1dcfDouglas Gregor class BalancedDelimiterTracker; 436d3891e9fb7eb25436e5c537189030bed0d5a1dcfDouglas Gregor 437a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// \brief Tracks information about the current nesting depth of 4384a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor /// opening delimiters of each kind. 4394a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor class DelimiterTracker { 4404a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor private: 4414a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor friend class Parser; 442d3891e9fb7eb25436e5c537189030bed0d5a1dcfDouglas Gregor friend class BalancedDelimiterTracker; 4434a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4444a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor unsigned Paren, Brace, Square, Less, LLLess; 4454a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor unsigned& get(tok::TokenKind t) { 4464a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor switch (t) { 4474a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor default: llvm_unreachable("Unexpected balanced token"); 4484a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_brace: return Brace; 4494a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_paren: return Paren; 4504a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_square: return Square; 4514a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::less: return Less; 4524a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::lesslessless: return LLLess; 4534a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4544a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4554a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4564a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor void push(tok::TokenKind t) { 4574a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor get(t)++; 4584a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4594a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4604a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor void pop(tok::TokenKind t) { 4614a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor get(t)--; 4624a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4634a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4644a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor unsigned getDepth(tok::TokenKind t) { 4654a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor return get(t); 4664a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4674a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4684a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor public: 4694a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor DelimiterTracker() : Paren(0), Brace(0), Square(0), Less(0), LLLess(0) { } 4704a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor }; 4714a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4724a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor /// \brief RAII class that helps handle the parsing of an open/close delimiter 4734a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor /// pair, such as braces { ... } or parentheses ( ... ). 4744a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor class BalancedDelimiterTracker { 4754a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor tok::TokenKind Kind, Close; 4764a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor Parser& P; 4774a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor bool Cleanup; 4784a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor const unsigned MaxDepth; 4794a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceLocation LOpen, LClose; 480a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 4814a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor void assignClosingDelimiter() { 4824a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor switch (Kind) { 4834a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor default: llvm_unreachable("Unexpected balanced token"); 4844a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_brace: Close = tok::r_brace; break; 4854a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_paren: Close = tok::r_paren; break; 4864a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::l_square: Close = tok::r_square; break; 4874a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::less: Close = tok::greater; break; 4884a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor case tok::lesslessless: Close = tok::greatergreatergreater; break; 4894a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4904a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4914a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4924a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor public: 493a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie BalancedDelimiterTracker(Parser& p, tok::TokenKind k) 4944a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor : Kind(k), P(p), Cleanup(false), MaxDepth(256) { 4954a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor assignClosingDelimiter(); 4964a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 4974a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 4984a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor ~BalancedDelimiterTracker() { 4994a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor if (Cleanup) 5004a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor P.QuantityTracker.pop(Kind); 5014a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor } 5024a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 5034a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceLocation getOpenLocation() const { return LOpen; } 5044a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceLocation getCloseLocation() const { return LClose; } 5054a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor SourceRange getRange() const { return SourceRange(LOpen, LClose); } 5064a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 5074a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor bool consumeOpen(); 508a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie bool expectAndConsume(unsigned DiagID, 509a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie const char *Msg = "", 5104a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor tok::TokenKind SkipToTok = tok::unknown); 5114a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor bool consumeClose(); 5123896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor void skipToEnd(); 5134a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor }; 5144a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 5154a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor DelimiterTracker QuantityTracker; 5164a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor 517b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall /// getTypeAnnotation - Read a parsed type out of an annotation token. 518b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static ParsedType getTypeAnnotation(Token &Tok) { 519b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue()); 520b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 521b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 522b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall static void setTypeAnnotation(Token &Tok, ParsedType T) { 523b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall Tok.setAnnotationValue(T.getAsOpaquePtr()); 524b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall } 525a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 5265ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// \brief Read an already-translated primary expression out of an annotation 5275ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// token. 5285ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor static ExprResult getExprAnnotation(Token &Tok) { 5295ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor if (Tok.getAnnotationValue()) 5305ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor return ExprResult((Expr *)Tok.getAnnotationValue()); 531a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 5325ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor return ExprResult(true); 5335ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor } 534a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 5355ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// \brief Set the primary expression corresponding to the given annotation 5365ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor /// token. 5375ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor static void setExprAnnotation(Token &Tok, ExprResult ER) { 5385ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor if (ER.isInvalid()) 5395ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor Tok.setAnnotationValue(0); 5405ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor else 5415ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor Tok.setAnnotationValue(ER.get()); 5425ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor } 543b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall 544fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to 545fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain // find a type name by attempting typo correction. 546fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false, 547fac9467d1676dc05761e12e41e13e01a3a3da52bKaelyn Uhrain bool NeedType = false); 548495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor bool TryAnnotateCXXScopeToken(bool EnteringContext = false); 549eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 55082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens, 55182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// replacing them with the non-context-sensitive keywords. This returns 55282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// true if the token was replaced. 55382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc, 554b3a4e432c90be98c6d918087750397e86d030368Chris Lattner const char *&PrevSpec, unsigned &DiagID, 555b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool &isInvalid) { 5561b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner if (!getLang().AltiVec || 5571b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner (Tok.getIdentifierInfo() != Ident_vector && 5581b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner Tok.getIdentifierInfo() != Ident_pixel)) 5591b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return false; 560a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 5611b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid); 56282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 56382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson 56482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector 56582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// identifier token, replacing it with the non-context-sensitive __vector. 56682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson /// This returns true if the token was replaced. 56782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson bool TryAltiVecVectorToken() { 568b3a4e432c90be98c6d918087750397e86d030368Chris Lattner if (!getLang().AltiVec || 569b3a4e432c90be98c6d918087750397e86d030368Chris Lattner Tok.getIdentifierInfo() != Ident_vector) return false; 5701b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner return TryAltiVecVectorTokenOutOfLine(); 57182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson } 572a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 5731b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecVectorTokenOutOfLine(); 5741b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, 5751b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner const char *&PrevSpec, unsigned &DiagID, 5761b49242de4e8bc718d7611c33a1d76ce35864020Chris Lattner bool &isInvalid); 57725a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 57825a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis /// \brief Get the TemplateIdAnnotation from the token and put it in the 57925a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis /// cleanup pool so that it gets destroyed when parsing the current top level 58025a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis /// declaration is finished. 58125a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok); 58225a767651d14db87aa03dd5fe3e011d877dd4100Argyrios Kyrtzidis 5835404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TentativeParsingAction - An object that is used as a kind of "tentative 5845404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// parsing transaction". It gets instantiated to mark the token position and 5855404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// after the token consumption is done, Commit() or Revert() is called to 5865404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// either "commit the consumed tokens" or revert to the previously marked 5875404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// token position. Example: 5885404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 589314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor /// TentativeParsingAction TPA(*this); 5905404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// ConsumeToken(); 5915404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// .... 5925404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// TPA.Revert(); 5935404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// 5945404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis class TentativeParsingAction { 5955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Parser &P; 5965404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis Token PrevTok; 5975404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isActive; 5985404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 5995404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis public: 6005404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis explicit TentativeParsingAction(Parser& p) : P(p) { 6015404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis PrevTok = P.Tok; 6025404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.EnableBacktrackAtThisPos(); 6035404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = true; 6045404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 6055404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Commit() { 6065404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 6075404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.CommitBacktrackedTokens(); 6085404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 6095404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 6105404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis void Revert() { 6115404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(isActive && "Parsing action was finished!"); 6125404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.PP.Backtrack(); 6135404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis P.Tok = PrevTok; 6145404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis isActive = false; 6155404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 6165404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis ~TentativeParsingAction() { 6175404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis assert(!isActive && "Forgot to call Commit or Revert!"); 6185404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 6195404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis }; 6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6219735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// ObjCDeclContextSwitch - An object used to switch context from 6229735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// an objective-c decl context to its enclosing decl context and 6239735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian /// back. 6249735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian class ObjCDeclContextSwitch { 6259735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian Parser &P; 6269735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian Decl *DC; 6279735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian public: 628a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie explicit ObjCDeclContextSwitch(Parser &p) : P(p), 6299735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian DC(p.getObjCDeclContext()) { 6309735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian if (DC) 631458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC)); 6329735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian } 6339735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian ~ObjCDeclContextSwitch() { 6349735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian if (DC) 635458bacff986ed8d30e7ae191c823d4db6cfaf16bArgyrios Kyrtzidis P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC)); 6369735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian } 6379735c5e60027b26a809df19677ff16a4d13f1321Fariborz Jahanian }; 6381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// input. If so, it is consumed and false is returned. 6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If the input is malformed, this emits the specified diagnostic. Next, if 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is 6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// returned. 6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned Diag, 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *DiagMsg = "", 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind SkipToTok = tok::unknown); 6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6499ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// \brief The parser expects a semicolon and, if present, will consume it. 6509ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// 6519ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// If the next token is not a semicolon, this emits the specified diagnostic, 6529ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior 6539ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor /// to the semicolon, consumes that extra token. 6549ba23b4ceacd77cd264501690a7a9e94184ef71bDouglas Gregor bool ExpectAndConsumeSemi(unsigned DiagID); 655a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Scope manipulation 6581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6598935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// ParseScope - Introduces a new scope for parsing. The kind of 6608935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// scope is determined by ScopeFlags. Objects of this type should 6618935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// be created on the stack to coincide with the position where the 6628935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// parser enters the new scope, and this object's constructor will 6638935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// create that new scope. Similarly, once the object is destroyed 6648935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor /// the parser will exit the scope. 6658935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor class ParseScope { 6668935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Parser *Self; 6678935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope(const ParseScope&); // do not implement 6688935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ParseScope& operator=(const ParseScope&); // do not implement 6698935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6708935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor public: 6718935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ParseScope - Construct a new object to manage a scope in the 6728935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // parser Self where the new Scope is created with the flags 6738935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ScopeFlags, but only when ManageScope is true (the default). If 6748935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // ManageScope is false, this object does nothing. 6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParseScope(Parser *Self, unsigned ScopeFlags, bool ManageScope = true) 6768935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor : Self(Self) { 6778935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (ManageScope) 6788935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->EnterScope(ScopeFlags); 6798935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor else 6808935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor this->Self = 0; 6818935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6828935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6838935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // Exit - Exit the scope associated with this object now, rather 6848935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor // than waiting until the object is destroyed. 6858935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor void Exit() { 6868935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor if (Self) { 6878935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self->ExitScope(); 6888935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Self = 0; 6898935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6908935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6918935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6928935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor ~ParseScope() { 6938935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor Exit(); 6948935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor } 6958935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor }; 6968935b8b49053122ddd3ab4cd59af0fe5eb9c23cfDouglas Gregor 6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EnterScope - Start a new scope. 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EnterScope(unsigned ScopeFlags); 6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ExitScope - Pop a scope off the scope stack. 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ExitScope(); 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7037a614d8380297fcd2bc23986241905d97222948cRichard Smith /// \brief RAII object used to modify the scope flags for the current scope. 7047a614d8380297fcd2bc23986241905d97222948cRichard Smith class ParseScopeFlags { 7057a614d8380297fcd2bc23986241905d97222948cRichard Smith Scope *CurScope; 7067a614d8380297fcd2bc23986241905d97222948cRichard Smith unsigned OldFlags; 7077a614d8380297fcd2bc23986241905d97222948cRichard Smith ParseScopeFlags(const ParseScopeFlags &); // do not implement 7087a614d8380297fcd2bc23986241905d97222948cRichard Smith void operator=(const ParseScopeFlags &); // do not implement 7097a614d8380297fcd2bc23986241905d97222948cRichard Smith 7107a614d8380297fcd2bc23986241905d97222948cRichard Smith public: 7117a614d8380297fcd2bc23986241905d97222948cRichard Smith ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true); 7127a614d8380297fcd2bc23986241905d97222948cRichard Smith ~ParseScopeFlags(); 7137a614d8380297fcd2bc23986241905d97222948cRichard Smith }; 7147a614d8380297fcd2bc23986241905d97222948cRichard Smith 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Diagnostic Emission and Error recovery. 71715faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 7186aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorpublic: 7193cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 7203cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID); 72115faa7fdfb496489dec9470aa5eb699b29ecdaccSebastian Redl 7226aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregorprivate: 7231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SuggestParentheses(SourceLocation Loc, unsigned DK, 7244b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor SourceRange ParenRange); 725d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen void CheckNestedObjCContexts(SourceLocation AtLoc); 7264b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SkipUntil - Read tokens until we get to the specified token, then consume 72882c7e6d8215567935d3d52741ccca9876a8ea461Steve Naroff /// it (unless DontConsume is true). Because we cannot guarantee that the 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// token will ever occur, this skips to the next token, or to some likely 7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' 7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// character. 7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If SkipUntil finds the specified token, it returns true, otherwise it 7341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returns false. 7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true, 7363437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis bool DontConsume = false, bool StopAtCodeCompletion = false) { 7373437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis return SkipUntil(&T, 1, StopAtSemi, DontConsume, StopAtCodeCompletion); 7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true, 7403437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis bool DontConsume = false, bool StopAtCodeCompletion = false) { 7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer tok::TokenKind TokArray[] = {T1, T2}; 7423437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis return SkipUntil(TokArray, 2, StopAtSemi, DontConsume,StopAtCodeCompletion); 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, 7453437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis bool StopAtSemi = true, bool DontConsume = false, 7463437f1f1294499d4ef306c1089fcb3e29ec2aa68Argyrios Kyrtzidis bool StopAtCodeCompletion = false); 7477ad8390f7992ab7f19b1460c5f0b9d96f165c4e9Douglas Gregor 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 7494cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // Lexing and parsing of C++ inline methods. 7504cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 751d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct ParsingClass; 752d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 753d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// [class.mem]p1: "... the class is regarded as complete within 754d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - function bodies 755d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - default arguments 756d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// - exception-specifications (TODO: C++0x) 7577a614d8380297fcd2bc23986241905d97222948cRichard Smith /// - and brace-or-equal-initializers for non-static data members 7587a614d8380297fcd2bc23986241905d97222948cRichard Smith /// (including such things in nested classes)." 759d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarations build the tree of those elements so they can 760d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// be parsed after parsing the top-level class. 761d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor class LateParsedDeclaration { 762d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor public: 763d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual ~LateParsedDeclaration(); 764d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 765d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 7667a614d8380297fcd2bc23986241905d97222948cRichard Smith virtual void ParseLexedMemberInitializers(); 767d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 768eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski virtual void ParseLexedAttributes(); 769d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor }; 770d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 771d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// Inner node of the LateParsedDeclaration tree that parses 772d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// all its members recursively. 773d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor class LateParsedClass : public LateParsedDeclaration { 774d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor public: 775d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateParsedClass(Parser *P, ParsingClass *C); 776d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual ~LateParsedClass(); 777d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 778d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 7797a614d8380297fcd2bc23986241905d97222948cRichard Smith virtual void ParseLexedMemberInitializers(); 780d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 781eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski virtual void ParseLexedAttributes(); 782d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 783d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor private: 784d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser *Self; 785d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor ParsingClass *Class; 786d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor }; 787d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 788a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// Contains the lexed tokens of an attribute with arguments that 789a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// may reference member variables and so need to be parsed at the 790a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// end of the class declaration after parsing all other member 791eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// member declarations. 792eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// FIXME: Perhaps we should change the name of LateParsedDeclaration to 793eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// LateParsedTokens. 794eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski struct LateParsedAttribute : public LateParsedDeclaration { 795eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski Parser *Self; 796eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski CachedTokens Toks; 797eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski IdentifierInfo &AttrName; 798eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation AttrNameLoc; 799eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski Decl *D; 800eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 801a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name, 802eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation Loc) 803eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski : Self(P), AttrName(Name), AttrNameLoc(Loc), D(0) {} 804eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 805eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski virtual void ParseLexedAttributes(); 806eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 807eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void setDecl(Decl *Dec) { D = Dec; } 808eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski }; 809eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 810eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski /// A list of late parsed attributes. Used by ParseGNUAttributes. 811eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski typedef llvm::SmallVector<LateParsedAttribute*, 2> LateParsedAttrList; 812eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 813eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski 814d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// Contains the lexed tokens of a member function definition 815d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// which needs to be parsed at the end of the class declaration 816d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// after parsing all other member declarations. 817d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct LexedMethod : public LateParsedDeclaration { 818d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser *Self; 819d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *D; 82072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens Toks; 821d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 822d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 823d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 824d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 825d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 826d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor 827d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor explicit LexedMethod(Parser* P, Decl *MD) 828d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor : Self(P), D(MD), TemplateScope(false) {} 829d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 830d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDefs(); 8314cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis }; 8324cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 83372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedDefaultArgument - Keeps track of a parameter that may 83472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument that cannot be parsed yet because it 83572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// occurs within a member function declaration inside the class 83672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// (C++ [class.mem]p2). 83772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor struct LateParsedDefaultArgument { 838d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall explicit LateParsedDefaultArgument(Decl *P, 83972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks = 0) 84072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor : Param(P), Toks(Toks) { } 84172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 84272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Param - The parameter declaration for this parameter. 843d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Param; 84472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 84572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Toks - The sequence of tokens that comprises the default 84672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument expression, not including the '=' or the terminating 84772b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// ')' or ','. This will be NULL for parameters that have no 84872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// default argument. 84972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor CachedTokens *Toks; 85072b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// LateParsedMethodDeclaration - A method declaration inside a class that 85372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// contains at least one entity whose parsing needs to be delayed 85472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// until the class itself is completely-defined, such as a default 85572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// argument (C++ [class.mem]p2). 856d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor struct LateParsedMethodDeclaration : public LateParsedDeclaration { 857d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor explicit LateParsedMethodDeclaration(Parser *P, Decl *M) 858d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor : Self(P), Method(M), TemplateScope(false) { } 859d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 860d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor virtual void ParseLexedMethodDeclarations(); 861d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor 862d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor Parser* Self; 86372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 86472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// Method - The method declaration. 865d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *Method; 86672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 867d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// \brief Whether this member function had an associated template 868d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// scope. When true, D is a template declaration. 869d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor /// othewise, it is a member function declaration. 870d83d04041f64a2c89123d227fa8003b482391279Douglas Gregor bool TemplateScope; 8711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87272b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// DefaultArgs - Contains the parameters of the function and 87372b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// their default arguments. At least one of the parameters will 87472b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// have a default argument, but all of the parameters of the 87572b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor /// method will be stored so that they can be reintroduced into 8761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// scope at the appropriate times. 877686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<LateParsedDefaultArgument, 8> DefaultArgs; 87872b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 87972b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 8807a614d8380297fcd2bc23986241905d97222948cRichard Smith /// LateParsedMemberInitializer - An initializer for a non-static class data 8817a614d8380297fcd2bc23986241905d97222948cRichard Smith /// member whose parsing must to be delayed until the class is completely 8827a614d8380297fcd2bc23986241905d97222948cRichard Smith /// defined (C++11 [class.mem]p2). 8837a614d8380297fcd2bc23986241905d97222948cRichard Smith struct LateParsedMemberInitializer : public LateParsedDeclaration { 8847a614d8380297fcd2bc23986241905d97222948cRichard Smith LateParsedMemberInitializer(Parser *P, Decl *FD) 8857a614d8380297fcd2bc23986241905d97222948cRichard Smith : Self(P), Field(FD) { } 8867a614d8380297fcd2bc23986241905d97222948cRichard Smith 8877a614d8380297fcd2bc23986241905d97222948cRichard Smith virtual void ParseLexedMemberInitializers(); 8887a614d8380297fcd2bc23986241905d97222948cRichard Smith 8897a614d8380297fcd2bc23986241905d97222948cRichard Smith Parser *Self; 8907a614d8380297fcd2bc23986241905d97222948cRichard Smith 8917a614d8380297fcd2bc23986241905d97222948cRichard Smith /// Field - The field declaration. 8927a614d8380297fcd2bc23986241905d97222948cRichard Smith Decl *Field; 8937a614d8380297fcd2bc23986241905d97222948cRichard Smith 8947a614d8380297fcd2bc23986241905d97222948cRichard Smith /// CachedTokens - The sequence of tokens that comprises the initializer, 8957a614d8380297fcd2bc23986241905d97222948cRichard Smith /// including any leading '='. 8967a614d8380297fcd2bc23986241905d97222948cRichard Smith CachedTokens Toks; 8977a614d8380297fcd2bc23986241905d97222948cRichard Smith }; 8987a614d8380297fcd2bc23986241905d97222948cRichard Smith 899d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarationsContainer - During parsing of a top (non-nested) 900d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// C++ class, its method declarations that contain parts that won't be 901fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// parsed until after the definition is completed (C++ [class.mem]p2), 902d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// the method declarations and possibly attached inline definitions 903a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// will be stored here with the tokens that will be parsed to create those 904a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// entities. 905a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer; 90672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 9076569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Representation of a class that has been parsed, including 9086569d68745c8213709740337d2be52b031384f58Douglas Gregor /// any member function declarations or definitions that need to be 9096569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed after the corresponding top-level class is complete. 9106569d68745c8213709740337d2be52b031384f58Douglas Gregor struct ParsingClass { 911d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParsingClass(Decl *TagOrTemplate, bool TopLevelClass) 9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : TopLevelClass(TopLevelClass), TemplateScope(false), 9136569d68745c8213709740337d2be52b031384f58Douglas Gregor TagOrTemplate(TagOrTemplate) { } 9146569d68745c8213709740337d2be52b031384f58Douglas Gregor 9156569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this is a "top-level" class, meaning that it is 9166569d68745c8213709740337d2be52b031384f58Douglas Gregor /// not nested within another class. 9176569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TopLevelClass : 1; 9186569d68745c8213709740337d2be52b031384f58Douglas Gregor 9196569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Whether this class had an associated template 9206569d68745c8213709740337d2be52b031384f58Douglas Gregor /// scope. When true, TagOrTemplate is a template declaration; 9216569d68745c8213709740337d2be52b031384f58Douglas Gregor /// othewise, it is a tag declaration. 9226569d68745c8213709740337d2be52b031384f58Douglas Gregor bool TemplateScope : 1; 9236569d68745c8213709740337d2be52b031384f58Douglas Gregor 9246569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The class or class template whose definition we are parsing. 925d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagOrTemplate; 92672b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor 927d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// LateParsedDeclarations - Method declarations, inline definitions and 928d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// nested classes that contain pieces whose parsing will be delayed until 929d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor /// the top-level class is fully defined. 930d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor LateParsedDeclarationsContainer LateParsedDeclarations; 93172b505b7904b3c9320a1312998800ba76e4f5841Douglas Gregor }; 9324cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 9336569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief The stack of classes that is currently being 9346569d68745c8213709740337d2be52b031384f58Douglas Gregor /// parsed. Nested and local classes will be pushed onto this stack 9356569d68745c8213709740337d2be52b031384f58Douglas Gregor /// when they are parsed, and removed afterward. 9366569d68745c8213709740337d2be52b031384f58Douglas Gregor std::stack<ParsingClass *> ClassStack; 9374cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 9386569d68745c8213709740337d2be52b031384f58Douglas Gregor ParsingClass &getCurrentClass() { 9396569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!ClassStack.empty() && "No lexed method stacks!"); 9406569d68745c8213709740337d2be52b031384f58Douglas Gregor return *ClassStack.top(); 9414cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis } 9424cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 94354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// \brief RAII object used to inform the actions that we're 94454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// currently parsing a declaration. This is active when parsing a 94554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// variable's initializer, but not when parsing the body of a 94654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// class or function definition. 94754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclRAIIObject { 948f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema &Actions; 949eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Sema::ParsingDeclState State; 95054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall bool Popped; 951c9068d7dd94d439cec66c421115d15303e481025John McCall 95254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 95354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) { 95454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 95554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 95654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 957c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *Other) 958c9068d7dd94d439cec66c421115d15303e481025John McCall : Actions(P.Actions) { 959c9068d7dd94d439cec66c421115d15303e481025John McCall if (Other) steal(*Other); 960c9068d7dd94d439cec66c421115d15303e481025John McCall else push(); 961c9068d7dd94d439cec66c421115d15303e481025John McCall } 962c9068d7dd94d439cec66c421115d15303e481025John McCall 963c9068d7dd94d439cec66c421115d15303e481025John McCall /// Creates a RAII object which steals the state from a different 964c9068d7dd94d439cec66c421115d15303e481025John McCall /// object instead of pushing. 965c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject(ParsingDeclRAIIObject &Other) 966c9068d7dd94d439cec66c421115d15303e481025John McCall : Actions(Other.Actions) { 967c9068d7dd94d439cec66c421115d15303e481025John McCall steal(Other); 968c9068d7dd94d439cec66c421115d15303e481025John McCall } 969c9068d7dd94d439cec66c421115d15303e481025John McCall 97054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ~ParsingDeclRAIIObject() { 97154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 97254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 97354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 97454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Resets the RAII object for a new declaration. 97554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void reset() { 97654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall abort(); 97754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall push(); 97854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 97954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 98054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// Signals that the context was completed without an appropriate 98154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// declaration being parsed. 98254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 983d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall pop(0); 98454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 98554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 986d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 98754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall assert(!Popped && "ParsingDeclaration has already been popped!"); 98854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall pop(D); 98954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 99054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 99154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall private: 992c9068d7dd94d439cec66c421115d15303e481025John McCall void steal(ParsingDeclRAIIObject &Other) { 993c9068d7dd94d439cec66c421115d15303e481025John McCall State = Other.State; 994c9068d7dd94d439cec66c421115d15303e481025John McCall Popped = Other.Popped; 995c9068d7dd94d439cec66c421115d15303e481025John McCall Other.Popped = true; 996c9068d7dd94d439cec66c421115d15303e481025John McCall } 997a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 99854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void push() { 99954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall State = Actions.PushParsingDeclaration(); 100054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = false; 100154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 100254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 1003d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void pop(Decl *D) { 100454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall if (!Popped) { 100554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Actions.PopParsingDeclaration(State, D); 100654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Popped = true; 100754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 100854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 100954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 101054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 101154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a DeclSpec. 101254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclSpec : public DeclSpec { 101354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 101454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 101554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 10160b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsingDeclSpec(Parser &P) : DeclSpec(P.AttrFactory), ParsingRAII(P) {} 1017c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII) 10180b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall : DeclSpec(P.AttrFactory), ParsingRAII(P, RAII) {} 101954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 1020d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 102154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 102254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 102354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 102454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void abort() { 102554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.abort(); 102654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 102754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 102854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 102954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall /// A class for parsing a declarator. 103054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall class ParsingDeclarator : public Declarator { 103154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclRAIIObject ParsingRAII; 103254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 103354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall public: 103454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C) 103554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall : Declarator(DS, C), ParsingRAII(P) { 103654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 103754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 103854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall const ParsingDeclSpec &getDeclSpec() const { 103954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec()); 104054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 104154abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 104254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingDeclSpec &getMutableDeclSpec() const { 104354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall return const_cast<ParsingDeclSpec&>(getDeclSpec()); 104454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 104554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 104654abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall void clear() { 104754abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall Declarator::clear(); 104854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.reset(); 104954abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 105054abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 1051d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void complete(Decl *D) { 105254abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall ParsingRAII.complete(D); 105354abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall } 105454abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall }; 105554abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall 10561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief RAII object used to 10576569d68745c8213709740337d2be52b031384f58Douglas Gregor class ParsingClassDefinition { 10586569d68745c8213709740337d2be52b031384f58Douglas Gregor Parser &P; 10596569d68745c8213709740337d2be52b031384f58Douglas Gregor bool Popped; 1060eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Sema::ParsingClassState State; 10616569d68745c8213709740337d2be52b031384f58Douglas Gregor 10626569d68745c8213709740337d2be52b031384f58Douglas Gregor public: 1063d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass) 1064eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall : P(P), Popped(false), 1065eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall State(P.PushParsingClass(TagOrTemplate, TopLevelClass)) { 10666569d68745c8213709740337d2be52b031384f58Douglas Gregor } 10676569d68745c8213709740337d2be52b031384f58Douglas Gregor 10686569d68745c8213709740337d2be52b031384f58Douglas Gregor /// \brief Pop this class of the stack. 10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void Pop() { 10706569d68745c8213709740337d2be52b031384f58Douglas Gregor assert(!Popped && "Nested class has already been popped"); 10716569d68745c8213709740337d2be52b031384f58Douglas Gregor Popped = true; 1072eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall P.PopParsingClass(State); 10736569d68745c8213709740337d2be52b031384f58Douglas Gregor } 10746569d68745c8213709740337d2be52b031384f58Douglas Gregor 10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ~ParsingClassDefinition() { 10766569d68745c8213709740337d2be52b031384f58Douglas Gregor if (!Popped) 1077eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall P.PopParsingClass(State); 10786569d68745c8213709740337d2be52b031384f58Douglas Gregor } 10796569d68745c8213709740337d2be52b031384f58Douglas Gregor }; 10806569d68745c8213709740337d2be52b031384f58Douglas Gregor 10814d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief Contains information about any template-specific 10824d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// information that has been parsed prior to parsing declaration 10834d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// specifiers. 10844d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor struct ParsedTemplateInfo { 10851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParsedTemplateInfo() 10864d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(NonTemplate), TemplateParams(0), TemplateLoc() { } 10874d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 10884d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ParsedTemplateInfo(TemplateParameterLists *TemplateParams, 1089c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool isSpecialization, 1090c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool lastParameterListWasEmpty = false) 10914d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor : Kind(isSpecialization? ExplicitSpecialization : Template), 1092a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie TemplateParams(TemplateParams), 1093c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(lastParameterListWasEmpty) { } 10944d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 109545f965581935791a018df829a14dff53c1dd8f47Douglas Gregor explicit ParsedTemplateInfo(SourceLocation ExternLoc, 109645f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation TemplateLoc) 10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Kind(ExplicitInstantiation), TemplateParams(0), 1098c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor ExternLoc(ExternLoc), TemplateLoc(TemplateLoc), 1099c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor LastParameterListWasEmpty(false){ } 11004d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11014d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The kind of template we are parsing. 11024d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor enum { 11034d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are not parsing a template at all. 11044d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor NonTemplate = 0, 11054d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing a template declaration. 11064d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor Template, 11074d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit specialization. 11084d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitSpecialization, 11094d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief We are parsing an explicit instantiation. 11104d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor ExplicitInstantiation 11114d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor } Kind; 11124d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11134d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The template parameter lists, for template declarations 11144d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// and explicit specializations. 11154d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor TemplateParameterLists *TemplateParams; 11164d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 111745f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// \brief The location of the 'extern' keyword, if any, for an explicit 111845f965581935791a018df829a14dff53c1dd8f47Douglas Gregor /// instantiation 111945f965581935791a018df829a14dff53c1dd8f47Douglas Gregor SourceLocation ExternLoc; 11201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11214d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// \brief The location of the 'template' keyword, for an explicit 11224d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor /// instantiation. 11234d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor SourceLocation TemplateLoc; 1124a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1125c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor /// \brief Whether the last template parameter list was empty. 1126c78c06d81f9838aea4198e4965cc1b26bb0bf838Douglas Gregor bool LastParameterListWasEmpty; 112778b810559d89e996e00684335407443936ce34a1John McCall 112878b810559d89e996e00684335407443936ce34a1John McCall SourceRange getSourceRange() const; 11294d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor }; 11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11318387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet /// \brief Contains a late templated function. 11328387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet /// Will be parsed at the end of the translation unit. 11338387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet struct LateParsedTemplatedFunction { 1134e1fca502e7f1349e9b4520a4ca9a02413bcf2b14Francois Pichet explicit LateParsedTemplatedFunction(Decl *MD) 11358387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet : D(MD) {} 11368387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 11378387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet CachedTokens Toks; 1138a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 11398387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet /// \brief The template function declaration to be late parsed. 1140a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie Decl *D; 11418387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet }; 11428387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 11438387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet void LexTemplateFunctionForLateParsing(CachedTokens &Toks); 11448387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet void ParseLateTemplatedFuncDef(LateParsedTemplatedFunction &LMT); 11458387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet typedef llvm::DenseMap<const FunctionDecl*, LateParsedTemplatedFunction*> 11468387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet LateParsedTemplateMapT; 11478387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet LateParsedTemplateMapT LateParsedTemplateMap; 11488387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 11494a47e8d35dc1778ef7e428d9edd7676be67e725fFrancois Pichet static void LateTemplateParserCallback(void *P, const FunctionDecl *FD); 11504a47e8d35dc1778ef7e428d9edd7676be67e725fFrancois Pichet void LateTemplateParser(const FunctionDecl *FD); 11518387e2a41eef6fa17fb140a18c29b6eee9dd2b8aFrancois Pichet 1152eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall Sema::ParsingClassState 1153eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass); 115437b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void DeallocateParsedClasses(ParsingClass *Class); 1155eee1d5434ebfa955ffc3c493aecd68bb7b3f4838John McCall void PopParsingClass(Sema::ParsingClassState); 115637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor 11575f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen Decl *ParseCXXInlineMethodDef(AccessSpecifier AS, AttributeList *AccessAttrs, 11585f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen ParsingDeclarator &D, 11594867347e82648d3baf09524b98b09c297a5a198fNico Weber const ParsedTemplateInfo &TemplateInfo, 1160a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie const VirtSpecifiers& VS, 116145fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor FunctionDefinitionKind DefinitionKind, 116245fa560c72441069d9e4eb1e66efd87349caa552Douglas Gregor ExprResult& Init); 11637a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseCXXNonStaticMemberInitializer(Decl *VarD); 1164eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void ParseLexedAttributes(ParsingClass &Class); 1165eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void ParseLexedAttribute(LateParsedAttribute &LA); 116637b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDeclarations(ParsingClass &Class); 1167d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM); 116837b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor void ParseLexedMethodDefs(ParsingClass &Class); 1169d54eb4410330383f48d3cc22b2ad8d23f120836bDouglas Gregor void ParseLexedMethodDef(LexedMethod &LM); 11707a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseLexedMemberInitializers(ParsingClass &Class); 11717a614d8380297fcd2bc23986241905d97222948cRichard Smith void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI); 1172140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian Decl *ParseLexedObjCMethodDefs(LexedMethod &LM); 1173a891a32d3762ee641a29c091d286f2a7432671a5Sebastian Redl bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks); 117414b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeAndStoreUntil(tok::TokenKind T1, 117514b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis CachedTokens &Toks, 117614b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 117714b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool ConsumeFinalToken = true) { 117814b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken); 117914b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis } 11801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, 118137b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor CachedTokens &Toks, 118214b91628961ab50cc6e724bbcd408fdee100662dArgyrios Kyrtzidis bool StopAtSemi = true, 118337b372b76a3fafe77186d7e6079e5642e2017478Douglas Gregor bool ConsumeFinalToken = true); 11844d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 11854cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 11865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.9: External Definitions. 11877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall struct ParsedAttributesWithRange : ParsedAttributes { 11880b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange(AttributeFactory &factory) 11890b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall : ParsedAttributes(factory) {} 11900b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall 11917f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceRange Range; 11927f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall }; 11937f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 11947f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs, 119509a63c97b95eb4dc6fd6b2323929e8cf12af03ffDouglas Gregor ParsingDeclSpec *DS = 0); 1196e4246a633b13197634225971b25df0cbdcec0c5dSean Hunt bool isDeclarationAfterDeclarator(); 1197004659a56916f2f81ede507c12516c146d6c0df3Chris Lattner bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); 11987f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsedAttributes &attrs, 11997f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall AccessSpecifier AS = AS_none); 12003acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS, 12013acd9aaa4ddd14afecb4f1c02ca6f585a6d51849Fariborz Jahanian AccessSpecifier AS = AS_none); 1202a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1203d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseFunctionDefinition(ParsingDeclarator &D, 120452591bf224b2c43e2b00e265bb8599a620081925Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseKNRParamDeclarations(Declarator &D); 1206ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc, if non-NULL, is filled with the location of the last token of 1207ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // the simple-asm. 120860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseSimpleAsm(SourceLocation *EndLoc = 0); 120960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAsmStringLiteral(); 12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12113536b443bc50d58a79f14fca9b6842541a434854Steve Naroff // Objective-C External Declarations 1212bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor DeclGroupPtrTy ParseObjCAtDirectives(); 1213bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); 1214d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, 12157f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &prefixAttrs); 1216d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseObjCClassInstanceVariables(Decl *interfaceDecl, 121783c481ade785a919ba21a33f9a8b1b21c1212fb3Fariborz Jahanian tok::ObjCKeywordKind visibility, 121860fcceeedbfc8b4a99cb942e2bc5aeb9e2f92a1fSteve Naroff SourceLocation atLoc); 1219686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P, 1220686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceLocation> &PLocs, 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool WarnOnDeclarations, 122271b0addffbdeed29cc062c962e236c34107755d6Argyrios Kyrtzidis SourceLocation &LAngleLoc, 1223e13b9595dc1e2f4288bec34f3412359f648e84a5Chris Lattner SourceLocation &EndProtoLoc); 122446f936e055d763437accd1e5a1bc49e7e5dbc0a3Douglas Gregor bool ParseObjCProtocolQualifiers(DeclSpec &DS); 12252f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, 12262f64cfe19e8bf6b6ba1660e38da8c421440457feFariborz Jahanian Decl *CDecl); 1227bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc, 1228bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor ParsedAttributes &prefixAttrs); 12291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1230d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ObjCImpDecl; 1231686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Decl *, 4> PendingObjCImpDecl; 1232140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian typedef SmallVector<LexedMethod*, 2> LateParsedObjCMethodContainer; 1233140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian LateParsedObjCMethodContainer LateParsedObjCMethods; 12340416fb9f379b49abb3eb0c1cb2ca75107e5a71d1Steve Naroff 1235d64251fd56577dd5c78903454632361e094c6dc1Erik Verbruggen Decl *ParseObjCAtImplementationDeclaration(SourceLocation AtLoc); 1236140ab234c23f392d5422691c5de1ee3c15026defFariborz Jahanian DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd); 1237d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc); 1238d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertySynthesize(SourceLocation atLoc); 1239d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCPropertyDynamic(SourceLocation atLoc); 12401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12412fc5c2428ecb450a3256c8316b93b8655cb76a0fChris Lattner IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation); 124234870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner // Definitions for Objective-c context sensitive keywords recognition. 124334870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner enum ObjCTypeQual { 124434870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref, 124534870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner objc_NumQuals 124634870da70fa42b0391b79627ebd0cfc6eb22213bChris Lattner }; 1247a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek IdentifierInfo *ObjCTypeQuals[objc_NumQuals]; 12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1249335a2d4122e41343fe11a775889b8bec5b14be60Fariborz Jahanian bool isTokIdentifier_in() const; 1250d0f97d1716a138a8d9e0df8e5af77334663723d8Fariborz Jahanian 1251cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, Declarator::TheContext Ctx, 1252cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall ParsedAttributes *ParamAttrs); 1253294494e1cce92043562b4680c613df7fd028c02eSteve Naroff void ParseObjCMethodRequirement(); 1254a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian Decl *ParseObjCMethodPrototype( 125590ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 125690ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition = true); 1257d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType, 125890ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword, 125990ba78c64d0c24cfbc1bf88728db9775d44d7f9fFariborz Jahanian bool MethodDefinition=true); 1260a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian void ParseObjCPropertyAttribute(ObjCDeclSpec &DS); 12611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1262d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseObjCMethodDefinition(); 12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.5: Expressions. 1266a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1267cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain /// TypeCastState - State whether an expression is or may be a type cast. 1268cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain enum TypeCastState { 1269cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain NotTypeCast = 0, 1270cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain MaybeTypeCast, 1271cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain IsTypeCast 1272cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain }; 1273cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain 1274cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain ExprResult ParseExpression(TypeCastState isTypeCast = NotTypeCast); 127560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseConstantExpression(); 12762f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl // Expr that doesn't include commas. 1277cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain ExprResult ParseAssignmentExpression(TypeCastState isTypeCast = NotTypeCast); 12782f7ece7c77eb17e24e8f0f4e1b7fb01aa5111f96Sebastian Redl 127960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc); 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 128160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc); 1282adf077f46ba5cddcd801a647a5e9a3eb97060df4Eli Friedman 128360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, 1284312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor prec::Level MinPrec); 128560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 1286312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool isAddressOfOperand, 1287312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool &NotCastExpr, 1288cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain TypeCastState isTypeCast); 128960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCastExpression(bool isUnaryExpression, 1290312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool isAddressOfOperand = false, 1291cd78e612d6fa8e214e6a6bb0e739a0c3e419df91Kaelyn Uhrain TypeCastState isTypeCast = NotTypeCast); 12929c72c6088d591ace8503b842d39448c2040f3033John McCall 12939c72c6088d591ace8503b842d39448c2040f3033John McCall /// Returns true if the next token would start a postfix-expression 12949c72c6088d591ace8503b842d39448c2040f3033John McCall /// suffix. 12959c72c6088d591ace8503b842d39448c2040f3033John McCall bool isPostfixExpressionSuffixStart() { 12969c72c6088d591ace8503b842d39448c2040f3033John McCall tok::TokenKind K = Tok.getKind(); 12979c72c6088d591ace8503b842d39448c2040f3033John McCall return (K == tok::l_square || K == tok::l_paren || 12989c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::period || K == tok::arrow || 12999c72c6088d591ace8503b842d39448c2040f3033John McCall K == tok::plusplus || K == tok::minusminus); 13009c72c6088d591ace8503b842d39448c2040f3033John McCall } 13019c72c6088d591ace8503b842d39448c2040f3033John McCall 130260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParsePostfixExpressionSuffix(ExprResult LHS); 1303f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult ParseUnaryExprOrTypeTraitExpression(); 130460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBuiltinPrimaryExpression(); 13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1306f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, 13075ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis bool &isCastExpr, 1308b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 13095ab0640efb436a721d408c853b771932d1a6ffceArgyrios Kyrtzidis SourceRange &CastRange); 13100cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 1311686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<Expr*, 20> ExprListTy; 1312686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<SourceLocation, 20> CommaLocsTy; 13130cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis 13140cd5b429fad6833dda23f0aced14a10907ac5539Argyrios Kyrtzidis /// ParseExpressionList - Used for C/C++ (argument-)expression-list. 1315686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool ParseExpressionList(SmallVectorImpl<Expr*> &Exprs, 1316686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceLocation> &CommaLocs, 1317f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall void (Sema::*Completer)(Scope *S, 1318f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Data, 1319f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr **Args, 1320f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall unsigned NumArgs) = 0, 1321ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Expr *Data = 0); 1322d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl 13235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParenParseOption - Control what ParseParenExpression will parse. 13245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ParenParseOption { 13255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SimpleExpr, // Only parse '(' expression ')' 13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundStmt, // Also allow '(' compound-statement ')' 13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}' 13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CastExpr // Also allow '(' type-name ')' <anything> 13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 133060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseParenExpression(ParenParseOption &ExprType, 13310350ca519405051e8d45d12ee7d09569a6a9c4c9Argyrios Kyrtzidis bool stopIfCastExpr, 13320a85183be6930571f3af8e5a976d24c3f95e5b25Argyrios Kyrtzidis bool isTypeCast, 1333b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType &CastTy, 1334d8c4e15138e69a51754cc259c8a592cc47950c8eSebastian Redl SourceLocation &RParenLoc); 13351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 133660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, 13374a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor ParsedType &CastTy, 13384a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker); 133960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCompoundLiteralExpression(ParsedType Ty, 1340d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation LParenLoc, 1341d974a7b72eb84cdc735b189bcea56fd37e13ebf6Argyrios Kyrtzidis SourceLocation RParenLoc); 13421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseStringLiteralExpression(); 1344eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1345f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult ParseGenericSelectionExpression(); 1346f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1347eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 1348eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis // C++ Expressions 134960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false); 13504bdd91c09fd59e0c154d759288beff300e31e1d0Argyrios Kyrtzidis 1351950be71c745409e373ae8a834490f9026c8ac222Richard Trieu void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr, 1352950be71c745409e373ae8a834490f9026c8ac222Richard Trieu bool EnteringContext, IdentifierInfo &II, 1353950be71c745409e373ae8a834490f9026c8ac222Richard Trieu CXXScopeSpec &SS); 1354950be71c745409e373ae8a834490f9026c8ac222Richard Trieu 13551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, 1356b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 1357b10cd04880672103660e5844e51ee91af7361a20Douglas Gregor bool EnteringContext, 13584147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet bool *MayBePseudoDestructor = 0, 13594147d307086cf024a40a080e2bf379e9725f6f41Francois Pichet bool IsTypename = false); 13601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1362ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // C++0x 5.1.2: Lambda expressions 1363ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 1364ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor // [...] () -> type {...} 1365ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult ParseLambdaExpression(); 1366ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult TryParseLambdaExpression(); 1367ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor llvm::Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro); 1368ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor bool TryParseLambdaIntroducer(LambdaIntroducer &Intro); 1369ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor ExprResult ParseLambdaExpressionAfterIntroducer( 1370ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor LambdaIntroducer &Intro); 1371ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor 1372ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor //===--------------------------------------------------------------------===// 13735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 5.2p1: C++ Casts 137460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXCasts(); 13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1377c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // C++ 5.2p1: C++ Type Identification 137860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeid(); 1379c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 1380c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl //===--------------------------------------------------------------------===// 138101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // C++ : Microsoft __uuidof Expression 138201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult ParseCXXUuidof(); 138301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 138401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet //===--------------------------------------------------------------------===// 1385d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor // C++ 5.2.4: C++ Pseudo-Destructor Expressions 138660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, 1387d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor tok::TokenKind OpKind, 1388d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor CXXScopeSpec &SS, 1389b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType); 1390d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor 1391d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor //===--------------------------------------------------------------------===// 13924cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis // C++ 9.3.2: C++ 'this' pointer 139360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXThis(); 13944cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis 13954cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 139650dd289f45738ed22b7583d52ed2525b927042ffChris Lattner // C++ 15: C++ Throw Expression 139760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseThrowExpression(); 13987acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 13997acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExceptionSpecificationType MaybeParseExceptionSpecification( 14007acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange &SpecificationRange, 1401686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParsedType> &DynamicExceptions, 1402686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceRange> &DynamicExceptionRanges, 14037acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExprResult &NoexceptExpr); 14047acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl 1405ab197baec16bacade82325fb274cf6b992ac5d8aSebastian Redl // EndLoc is filled with the location of the last token of the specification. 14067acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl ExceptionSpecificationType ParseDynamicExceptionSpecification( 14077acafd032e145dbdbbed9274ca57ec2c86b912bcSebastian Redl SourceRange &SpecificationRange, 1408686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParsedType> &Exceptions, 1409686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<SourceRange> &Ranges); 141050dd289f45738ed22b7583d52ed2525b927042ffChris Lattner 141150dd289f45738ed22b7583d52ed2525b927042ffChris Lattner //===--------------------------------------------------------------------===// 1412dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // C++0x 8: Function declaration trailing-return-type 1413ae7902c4293d9de8b9591759513f0d075f45022aDouglas Gregor TypeResult ParseTrailingReturnType(SourceRange &Range); 1414dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 1415dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor //===--------------------------------------------------------------------===// 14165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C++ 2.13.5: C++ Boolean Literals 141760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXBoolLiteral(); 14185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1420987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // C++ 5.2.3: Explicit type conversion (functional notation) 142160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS); 1422987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 14236aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool isCXXSimpleTypeSpecifier() const; 14246aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor 1425987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. 1426987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// This should only be called when the current token is known to be part of 1427987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis /// simple-type-specifier. 1428987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis void ParseCXXSimpleTypeSpecifier(DeclSpec &DS); 1429987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 14302f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor bool ParseCXXTypeSpecifierSeq(DeclSpec &DS); 14312f1bc5285ccd40f411af5f5993f013e27e74ab78Douglas Gregor 1432987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis //===--------------------------------------------------------------------===// 14334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // C++ 5.3.4 and 5.3.5: C++ new and delete 1434686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs, 1435ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall Declarator &D); 14364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDirectNewDeclarator(Declarator &D); 143760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start); 143860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseCXXDeleteExpression(bool UseGlobal, 143959232d35f5820e334b6c8b007ae8006f4390055dChris Lattner SourceLocation Start); 14404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 14414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl //===--------------------------------------------------------------------===// 144299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor // C++ if/switch/while condition expression. 144360d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseCXXCondition(ExprResult &ExprResult, Decl *&DeclResult, 1444586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, bool ConvertToBoolean); 144571b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis 144671b914b999d9c4b6df11068fc5a3291ac4770492Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 144712e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor // C++ types 144812e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor 144912e083c805c0f86be4f8e54b06e75b2c3dc1da64Douglas Gregor //===--------------------------------------------------------------------===// 14505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7.8: Initialization. 14511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14520eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// ParseInitializer 14530eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// initializer: [C99 6.7.8] 14540eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// assignment-expression 14550eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner /// '{' ... 145660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializer() { 14570eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner if (Tok.isNot(tok::l_brace)) 145820df9b7ab9388b2a488c5b1293cd196b1e073b4eSebastian Redl return ParseAssignmentExpression(); 14590eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner return ParseBraceInitializer(); 14600eec2b58678f71af6b5fcf4c439290c0d640546bChris Lattner } 146160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBraceInitializer(); 146260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseInitializerWithPotentialDesignator(); 14631d922960e083906a586609ac6978678147250177Sebastian Redl 14645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1465296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // clang Expressions 14661d922960e083906a586609ac6978678147250177Sebastian Redl 146760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseBlockLiteralExpression(); // ^{...} 1468296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff 1469296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff //===--------------------------------------------------------------------===// 14705508518a2702b00be3b15a26d772bde968972f54Anders Carlsson // Objective-C Expressions 147160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCAtExpression(SourceLocation AtLocation); 147260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCStringLiteral(SourceLocation AtLoc); 147360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc); 147460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc); 147560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc); 14761b730e847ded503f2e615154035c083c4f94a067Douglas Gregor bool isSimpleObjCMessageExpression(); 147760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpression(); 147860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc, 14795cb94a78202ccb1007df0be86884297761f4a53aNico Weber SourceLocation SuperLoc, 14805cb94a78202ccb1007df0be86884297761f4a53aNico Weber ParsedType ReceiverType, 14815cb94a78202ccb1007df0be86884297761f4a53aNico Weber ExprArg ReceiverExpr); 148260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseAssignmentExprWithObjCMessageExprStart( 14832725ca8eb3354975ca77ed4b88ede7b60b216b9aDouglas Gregor SourceLocation LBracloc, SourceLocation SuperLoc, 1484b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ReceiverType, ExprArg ReceiverExpr); 14856aa14d832704ae176c92d4e0f22dfb3f3d83a70aDouglas Gregor bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr); 148661364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 14875508518a2702b00be3b15a26d772bde968972f54Anders Carlsson //===--------------------------------------------------------------------===// 14885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.8: Statements and Blocks. 148961364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl 14905cb94a78202ccb1007df0be86884297761f4a53aNico Weber StmtResult ParseStatement(SourceLocation *TrailingElseLoc = NULL) { 1491c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian StmtVector Stmts(Actions); 14925cb94a78202ccb1007df0be86884297761f4a53aNico Weber return ParseStatementOrDeclaration(Stmts, true, TrailingElseLoc); 149361364dddc33383e62cfe3b841dbc0f471280d95bSebastian Redl } 1494c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian StmtResult ParseStatementOrDeclaration(StmtVector& Stmts, 14955cb94a78202ccb1007df0be86884297761f4a53aNico Weber bool OnlyStatement, 14965cb94a78202ccb1007df0be86884297761f4a53aNico Weber SourceLocation *TrailingElseLoc = NULL); 14975ecdd78408a1c6f4be506d94f776642570d27336Douglas Gregor StmtResult ParseExprStatement(ParsedAttributes &Attrs); 14987f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseLabeledStatement(ParsedAttributes &Attr); 1499bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu StmtResult ParseCaseStatement(ParsedAttributes &Attr, 1500bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu bool MissingCase = false, 1501bb9b80c308d7d3f758886243c7145404a50c66cfRichard Trieu ExprResult Expr = ExprResult()); 15027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseDefaultStatement(ParsedAttributes &Attr); 15037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseCompoundStatement(ParsedAttributes &Attr, 1504312eadb832cab4497a069409954500d8192b8f0dDouglas Gregor bool isStmtExpr = false); 1505bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor StmtResult ParseCompoundStatement(ParsedAttributes &Attr, 1506bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool isStmtExpr, 1507bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor unsigned ScopeFlags); 150860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCompoundStatementBody(bool isStmtExpr = false); 150960d7b3a319d84d688752be3870615ac0f111fb16John McCall bool ParseParenExprOrCondition(ExprResult &ExprResult, 1510d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *&DeclResult, 1511586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor SourceLocation Loc, 151244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis bool ConvertToBoolean); 15135cb94a78202ccb1007df0be86884297761f4a53aNico Weber StmtResult ParseIfStatement(ParsedAttributes &Attr, 15145cb94a78202ccb1007df0be86884297761f4a53aNico Weber SourceLocation *TrailingElseLoc); 15155cb94a78202ccb1007df0be86884297761f4a53aNico Weber StmtResult ParseSwitchStatement(ParsedAttributes &Attr, 15165cb94a78202ccb1007df0be86884297761f4a53aNico Weber SourceLocation *TrailingElseLoc); 15175cb94a78202ccb1007df0be86884297761f4a53aNico Weber StmtResult ParseWhileStatement(ParsedAttributes &Attr, 15185cb94a78202ccb1007df0be86884297761f4a53aNico Weber SourceLocation *TrailingElseLoc); 15197f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseDoStatement(ParsedAttributes &Attr); 15205cb94a78202ccb1007df0be86884297761f4a53aNico Weber StmtResult ParseForStatement(ParsedAttributes &Attr, 15215cb94a78202ccb1007df0be86884297761f4a53aNico Weber SourceLocation *TrailingElseLoc); 15227f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseGotoStatement(ParsedAttributes &Attr); 15237f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseContinueStatement(ParsedAttributes &Attr); 15247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseBreakStatement(ParsedAttributes &Attr); 15257f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseReturnStatement(ParsedAttributes &Attr); 152660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseAsmStatement(bool &msAsm); 15273fedbe1f71c18fba01d39109d606f421a0103a2aEli Friedman StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc); 1528a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 15293896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Describes the behavior that should be taken for an __if_exists 15303896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// block. 15313896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor enum IfExistsBehavior { 15323896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Parse the block; this code is always used. 15333896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Parse, 15343896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Skip the block entirely; this code is never used. 15353896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Skip, 15363896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Parse the block as a dependent block, which may be used in 15373896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// some template instantiations but not others. 15383896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IEB_Dependent 15393896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor }; 1540a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1541a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// \brief Describes the condition of a Microsoft __if_exists or 15423896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// __if_not_exists block. 15433896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor struct IfExistsCondition { 15443896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The location of the initial keyword. 15453896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor SourceLocation KeywordLoc; 1546a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie /// \brief Whether this is an __if_exists block (rather than an 15473896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// __if_not_exists block). 15483896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor bool IsIfExists; 1549a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 15503896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief Nested-name-specifier preceding the name. 15513896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor CXXScopeSpec SS; 1552a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 15533896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The name we're looking for. 15543896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor UnqualifiedId Name; 15553896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor 15563896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// \brief The behavior of this __if_exists or __if_not_exists block 15573896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor /// should. 15583896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor IfExistsBehavior Behavior; 15593896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor}; 1560a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 15613896fc5d4daaf003e451e797e37de57dd8cf9cd5Douglas Gregor bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result); 15621e862693c63067ae467b0b3884c44f753cd6e821Francois Pichet void ParseMicrosoftIfExistsStatement(StmtVector &Stmts); 1563563a645de82231a55e221fe655b7188bf8369662Francois Pichet void ParseMicrosoftIfExistsExternalDeclaration(); 1564563a645de82231a55e221fe655b7188bf8369662Francois Pichet void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, 1565563a645de82231a55e221fe655b7188bf8369662Francois Pichet AccessSpecifier& CurAS); 15669d24a8be93b28488dbfb9bbe8aa6fe35b21a5b0cFrancois Pichet bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, 15679d24a8be93b28488dbfb9bbe8aa6fe35b21a5b0cFrancois Pichet bool &InitExprsOk); 1568f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names, 1569f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu SmallVectorImpl<Expr *> &Constraints, 1570f81e5a9e3f3ff80c56e4afb4fe6311a8735f36e8Richard Trieu SmallVectorImpl<Expr *> &Exprs); 1571a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1572a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 1573a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // C++ 6: Statements and Blocks 1574a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 15757f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall StmtResult ParseCXXTryBlock(ParsedAttributes &Attr); 157660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc); 157760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseCXXCatchBlock(); 1578a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 1579a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl //===--------------------------------------------------------------------===// 158028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley // MS: SEH Statements and Blocks 158128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 158228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHTryBlock(ParsedAttributes &Attr); 158328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHTryBlockCommon(SourceLocation Loc); 158428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHExceptBlock(SourceLocation Loc); 158528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult ParseSEHFinallyBlock(SourceLocation Loc); 158628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 158728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley //===--------------------------------------------------------------------===// 1588a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl // Objective-C Statements 1589a0fd8652f3302d0f39ed9849b521ee5b76597b0aSebastian Redl 159060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCAtStatement(SourceLocation atLoc); 159160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCTryStmt(SourceLocation atLoc); 159260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCThrowStmt(SourceLocation atLoc); 159360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc); 1594f85e193739c953358c865005855253af4f68a497John McCall StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc); 1595b235fc2cf37621c7fc6511bb2b8788c95f9fb9fcAnders Carlsson 15965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 15985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.7: Declarations. 159967d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall 160067d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// A context for parsing declaration specifiers. TODO: flesh this 160167d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// out, there are other significant restrictions on specifiers than 160267d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall /// would be best implemented in the parser. 160367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall enum DeclSpecContext { 160467d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DSC_normal, // normal context 16050efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_class, // class context, enables 'friend' 16060efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DSC_top_level // top-level/namespace declaration context 160767d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall }; 16081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1609ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Information on a C++0x for-range-initializer found while parsing a 1610ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// declaration which turns out to be a for-range-declaration. 1611ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith struct ForRangeInit { 1612ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation ColonLoc; 1613ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult RangeExpr; 1614ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 1615ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); } 1616ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith }; 1617ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 1618c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts, 1619c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian unsigned Context, SourceLocation &DeclEnd, 16207f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributesWithRange &attrs); 1621c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts, 1622c5be7b0fc804d8e6f87298ec03c94d8cccd74f29Fariborz Jahanian unsigned Context, 1623bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt SourceLocation &DeclEnd, 16247f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs, 1625ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool RequireSemi, 1626ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ForRangeInit *FRI = 0); 16270706df40064d4d7559b4304af79d519033414b84Richard Smith bool MightBeDeclarator(unsigned Context); 162854abf7d4fa3123b8324c09d2a4dfb789fd818403John McCall DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, 1629d8ac05753dc4506224d445ff98399c01da3136e5John McCall bool AllowFunctionDefinitions, 1630ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation *DeclEnd = 0, 1631ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ForRangeInit *FRI = 0); 1632d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationAfterDeclarator(Declarator &D, 1633e542c862bdf9a9bcb4f468be8fa6561372430611Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1634ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool ParseAttributesAfterDeclarator(Declarator &D); 1635ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Decl *ParseDeclarationAfterDeclaratorAndAttributes(Declarator &D, 1636ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); 1637c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope); 1638c9977d09a2de7f7d2245973413d4caf86c736640Douglas Gregor Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope); 1639d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 16400fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// \brief When in code-completion, skip parsing of the function/method body 16410fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// unless the body contains the code-completion point. 16420fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// 16430fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis /// \returns true if the function body was skipped. 1644b162054ba8f5b64fe87fbc4837933ab23eebd52bArgyrios Kyrtzidis bool trySkippingFunctionBodyForCodeCompletion(); 16450fe5397b26695926a835fa99eceb7fc879b307afArgyrios Kyrtzidis 1646f4382f50b7ab9f445c3f5b3ddaa59e6da25ea3bbChris Lattner bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, 16474d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 1648e40c295d017a8f75a945fe9ed2aa9d8bb7a7341aChris Lattner AccessSpecifier AS); 16490efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor DeclSpecContext getDeclSpecContextFromDeclaratorContext(unsigned Context); 16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ParseDeclarationSpecifiers(DeclSpec &DS, 16514d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 165267d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall AccessSpecifier AS = AS_none, 165367d1a67f3db2f1aa69083c5c94164d6e0ee05b32John McCall DeclSpecContext DSC = DSC_normal); 16541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseOptionalTypeSpecifier(DeclSpec &DS, bool &isInvalid, 16557a0ab5f387722c83e19c7133b46b16988eb19e45Chris Lattner const char *&PrevSpec, 1656fec54013fcd0eb72642741584ca04c1bc292bef8John McCall unsigned &DiagID, 1657d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 1658d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 16594d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor 1660c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith void ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS = AS_none); 16611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1662cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall void ParseObjCTypeQualifierList(ObjCDeclSpec &DS, 1663cdda47faab5c2c61c239491a1a091e071ed3e38eJohn McCall Declarator::TheContext Context); 16645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16654c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, 16661b21391b3b1b7dd829c35f9b69199ed2a67da25aArgyrios Kyrtzidis const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 16671b21391b3b1b7dd829c35f9b69199ed2a67da25aArgyrios Kyrtzidis AccessSpecifier AS = AS_none); 1668d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl); 16695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, 1670d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 1671bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1672bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall struct FieldCallback { 1673d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall virtual Decl *invoke(FieldDeclarator &Field) = 0; 16746c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual ~FieldCallback() {} 16756c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall 16766c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall private: 16776c94a6d77f456f23ecd4c2061e6413786b5e6571John McCall virtual void _anchor(); 1678bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall }; 1679d0014540005f2a5ab837365db6bd40f479406758John McCall struct ObjCPropertyCallback; 1680bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall 1681bdd563ec391b0a83fc6d04b8a8ea3022aa702f74John McCall void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback); 16821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16839497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false); 1684eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis bool isTypeSpecifierQualifier(); 16855f8aa696619e32bf307232841fedb704ba733b4dSteve Naroff bool isTypeQualifier() const; 1686a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 1687b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// isKnownToBeTypeSpecifier - Return true if we know that the specified token 1688b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// is definitely a type-specifier. Return false if it isn't part of a type 1689b3a4e432c90be98c6d918087750397e86d030368Chris Lattner /// specifier or if we're not sure. 1690b3a4e432c90be98c6d918087750397e86d030368Chris Lattner bool isKnownToBeTypeSpecifier(const Token &Tok) const; 16915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16925404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isDeclarationStatement - Disambiguates between a declaration or an 16935404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// expression statement, when parsing function bodies. 16945404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for declaration, false for expression. 16955404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isDeclarationStatement() { 16965404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis if (getLang().CPlusPlus) 16975404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis return isCXXDeclarationStatement(); 16989497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return isDeclarationSpecifier(true); 16995404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis } 17005404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 17019490ab433deef70105d817616928d700f87642d9Eli Friedman /// isForInitDeclaration - Disambiguates between a declaration or an 17029490ab433deef70105d817616928d700f87642d9Eli Friedman /// expression in the context of the C 'clause-1' or the C++ 1703bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis // 'for-init-statement' part of a 'for' statement. 1704bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis /// Returns true for declaration, false for expression. 17059490ab433deef70105d817616928d700f87642d9Eli Friedman bool isForInitDeclaration() { 1706bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis if (getLang().CPlusPlus) 17079490ab433deef70105d817616928d700f87642d9Eli Friedman return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/true); 17089497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor return isDeclarationSpecifier(true); 1709bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis } 1710bbc70c019f7b7f9a256ee29dab5287ecc82c6553Argyrios Kyrtzidis 17119497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor /// \brief Determine whether we are currently at the start of an Objective-C 17129497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor /// class message that appears to be missing the open bracket '['. 17139497a73ad0d54859edbf48beb93ebb19a7ae50c9Douglas Gregor bool isStartOfObjCClassMessageMissingOpenBracket(); 1714a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 17150efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// \brief Starting with a scope specifier, identifier, or 17160efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// template-id that refers to the current class, determine whether 17170efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor /// this is a constructor declarator. 17180efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor bool isConstructorDeclarator(); 17190efc2c1716be4f1c5f1343cad3b047e74861f030Douglas Gregor 17208b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// \brief Specifies the context in which type-id/expression 17218b642592a35167a3780074e78674e0bece87c40cDouglas Gregor /// disambiguation will occur. 17228b642592a35167a3780074e78674e0bece87c40cDouglas Gregor enum TentativeCXXTypeIdContext { 17238b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdInParens, 17248b642592a35167a3780074e78674e0bece87c40cDouglas Gregor TypeIdAsTemplateArgument 17258b642592a35167a3780074e78674e0bece87c40cDouglas Gregor }; 17268b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 17278b642592a35167a3780074e78674e0bece87c40cDouglas Gregor 172878c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know 172978c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// whether the parens contain an expression or a type-id. 173078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis /// Returns true for a type-id and false for an expression. 1731f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens(bool &isAmbiguous) { 173278c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis if (getLang().CPlusPlus) 1733f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(TypeIdInParens, isAmbiguous); 1734f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis isAmbiguous = false; 173578c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis return isTypeSpecifierQualifier(); 173678c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis } 1737f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isTypeIdInParens() { 1738f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1739f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isTypeIdInParens(isAmbiguous); 1740f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 174178c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 17425404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXDeclarationStatement - C++-specialized function that disambiguates 17435404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a declaration or an expression statement, when parsing function 17445404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// bodies. Returns true for declaration, false for expression. 17455404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis bool isCXXDeclarationStatement(); 17465404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 17475404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXSimpleDeclaration - C++-specialized function that disambiguates 17485404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// between a simple-declaration or an expression-statement. 17495404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 17505404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 17515404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns false if the statement is disambiguated as expression. 17529490ab433deef70105d817616928d700f87642d9Eli Friedman bool isCXXSimpleDeclaration(bool AllowForRangeDecl); 17535404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 17545404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// isCXXFunctionDeclarator - Disambiguates between a function declarator or 17555404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// a constructor-style initializer, when parsing declaration statements. 17565404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Returns true for function declarator and false for constructor-style 1757e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis /// initializer. If 'warnIfAmbiguous' is true a warning will be emitted to 1758259b0d91f2ff90d8daf39221fe133bf1596c5ffbArgyrios Kyrtzidis /// indicate that the parens were disambiguated as function declarator. 17595404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 17605404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1761e75d849d9141d8e47d05a91b7b5c04194854e47aArgyrios Kyrtzidis bool isCXXFunctionDeclarator(bool warnIfAmbiguous); 17625404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1763a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// isCXXConditionDeclaration - Disambiguates between a declaration or an 1764a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// expression for a condition of a if/switch/while/for statement. 1765a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// If during the disambiguation process a parsing error is encountered, 1766a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis /// the function returns true to let the declaration parsing code handle it. 1767a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis bool isCXXConditionDeclaration(); 1768a8a4598b6f2a07339ab8a1248295a07d771a2b2aArgyrios Kyrtzidis 1769f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous); 1770f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isCXXTypeId(TentativeCXXTypeIdContext Context) { 1771f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis bool isAmbiguous; 1772f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis return isCXXTypeId(Context, isAmbiguous); 1773f58f45e6d76792df8c643ce1c6d364dce5db4826Argyrios Kyrtzidis } 177478c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis 1775b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult - Used as the result value for functions whose purpose is to 1776b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// disambiguate C++ constructs by "tentatively parsing" them. 1777b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// This is a class instead of a simple enum because the implicit enum-to-bool 1778b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// conversions may cause subtle bugs. 1779b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis class TPResult { 1780b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis enum Result { 1781b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_true, 1782b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_false, 1783b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_ambiguous, 1784b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPR_error 1785b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis }; 1786b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis Result Res; 1787b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult(Result result) : Res(result) {} 1788b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis public: 1789b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult True() { return TPR_true; } 1790b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult False() { return TPR_false; } 1791b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Ambiguous() { return TPR_ambiguous; } 1792b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis static TPResult Error() { return TPR_error; } 1793b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis 1794b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator==(const TPResult &RHS) const { return Res == RHS.Res; } 1795b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; } 1796b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis }; 1797b47e38683f288cd4a73098091d629df417377a6bArgyrios Kyrtzidis 1798a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// \brief Based only on the given token kind, determine whether we know that 1799a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// we're at the start of an expression or a type-specifier-seq (which may 1800a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// be an expression, in C++). 1801a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// 1802a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// This routine does not attempt to resolve any of the trick cases, e.g., 1803a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// those involving lookup of identifiers. 1804a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// 1805a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// \returns \c TPR_true if this token starts an expression, \c TPR_false if 1806a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot 1807a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor /// tell. 1808a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind); 1809a61b3e7443056f8d05b24ca4cbea90fe66235d6bDouglas Gregor 1810b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a 1811b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// declaration specifier, TPResult::False() if it is not, 1812b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// TPResult::Ambiguous() if it could be either a decl-specifier or a 1813b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// function-style cast, and TPResult::Error() if a parsing error was 1814b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis /// encountered. 18155404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis /// Doesn't consume tokens. 1816b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult isCXXDeclarationSpecifier(); 1817a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 18185404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // "Tentative parsing" functions, used for disambiguation. If a parsing error 1819b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // is encountered they will return TPResult::Error(). 1820b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // Returning TPResult::True()/False() indicates that the ambiguity was 1821b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // resolved and tentative parsing may stop. TPResult::Ambiguous() indicates 1822b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis // that more tentative parsing is necessary for disambiguation. 18235404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis // They all consume tokens, so backtracking should be used after calling them. 18245404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1825b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseDeclarationSpecifier(); 18269490ab433deef70105d817616928d700f87642d9Eli Friedman TPResult TryParseSimpleDeclaration(bool AllowForRangeDecl); 1827b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseTypeofSpecifier(); 18289bd1d8d174a9d15ae343246c8322299248b9e92aDouglas Gregor TPResult TryParseProtocolQualifiers(); 1829b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseInitDeclaratorList(); 183078c8d80f19cb0bccd4f3d590e71a230e727cfab5Argyrios Kyrtzidis TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true); 1831b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseParameterDeclarationClause(); 1832b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseFunctionDeclarator(); 1833b9f341916e484ff6ba2c2d28c8b2dd5fa12b0015Argyrios Kyrtzidis TPResult TryParseBracketDeclarator(); 18345404a156be26de1c63ca9916187f970848bb4dbbArgyrios Kyrtzidis 1835683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor TypeResult ParseTypeName(SourceRange *Range = 0, 1836683a81f4373cf1fa9d41a751dca6f7c36125b058Douglas Gregor Declarator::TheContext Context 1837f85e193739c953358c865005855253af4f68a497John McCall = Declarator::TypeNameContext, 1838c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith AccessSpecifier AS = AS_none, 1839c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith Decl **OwnedType = 0); 184098eb8a7a702b95183ed015706b1f1c66f5cb27a4Mike Stump void ParseBlockId(); 18417f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 18427f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ProhibitAttributes(ParsedAttributesWithRange &attrs) { 18437f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (!attrs.Range.isValid()) return; 18447f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall DiagnoseProhibitedAttributes(attrs); 18457f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18467f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs); 18477f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 1848eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void MaybeParseGNUAttributes(Declarator &D, 1849eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski LateParsedAttrList *LateAttrs = 0) { 18507f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (Tok.is(tok::kw___attribute)) { 18510b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributes attrs(AttrFactory); 18527f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation endLoc; 1853eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski ParseGNUAttributes(attrs, &endLoc, LateAttrs); 18540b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall D.takeAttributes(attrs, endLoc); 18557f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18567f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18577f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseGNUAttributes(ParsedAttributes &attrs, 1858eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation *endLoc = 0, 1859eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski LateParsedAttrList *LateAttrs = 0) { 18607f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (Tok.is(tok::kw___attribute)) 1861eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski ParseGNUAttributes(attrs, endLoc, LateAttrs); 18627f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18637f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseGNUAttributes(ParsedAttributes &attrs, 1864eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation *endLoc = 0, 1865eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski LateParsedAttrList *LateAttrs = 0); 1866eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski void ParseGNUAttributeArgs(IdentifierInfo *AttrName, 1867eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation AttrNameLoc, 1868eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski ParsedAttributes &Attrs, 1869eff98fc3561f6b717f6348f04b3f4fe03e934466Caitlin Sadowski SourceLocation *EndLoc); 18707f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 18717f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseCXX0XAttributes(Declarator &D) { 18727f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) { 18730b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrs(AttrFactory); 18747f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation endLoc; 18757f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseCXX0XAttributes(attrs, &endLoc); 18760b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall D.takeAttributes(attrs, endLoc); 18777f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18787f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18797f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseCXX0XAttributes(ParsedAttributes &attrs, 18807f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc = 0) { 18817f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) { 18820b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall ParsedAttributesWithRange attrsWithRange(AttrFactory); 18837f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseCXX0XAttributes(attrsWithRange, endLoc); 18840b7e678a11ece4288dc01aebb5b17e5eef8f8d2dJohn McCall attrs.takeAllFrom(attrsWithRange); 18857f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18867f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18877f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseCXX0XAttributes(ParsedAttributesWithRange &attrs, 18887f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc = 0) { 18897f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) 18907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseCXX0XAttributes(attrs, endLoc); 18917f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 18923497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne 18933497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne void ParseCXX0XAttributeSpecifier(ParsedAttributes &attrs, 18943497fdfdb742f55d7b7ec8e22779fb08962b8441Peter Collingbourne SourceLocation *EndLoc = 0); 18957f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseCXX0XAttributes(ParsedAttributesWithRange &attrs, 18967f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *EndLoc = 0); 18977f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 18987f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs, 18997f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc = 0) { 190062ec1f2fd7368542bb926c04797fb07023547694Francois Pichet if (getLang().MicrosoftExt && Tok.is(tok::l_square)) 19017f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParseMicrosoftAttributes(attrs, endLoc); 19027f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall } 19037f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseMicrosoftAttributes(ParsedAttributes &attrs, 19047f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation *endLoc = 0); 19057f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseMicrosoftDeclSpec(ParsedAttributes &attrs); 19067f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs); 19077f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall void ParseBorlandTypeAttributes(ParsedAttributes &attrs); 1908f315fa81eef1977b3457fd7a7d4639e060fe7278Peter Collingbourne void ParseOpenCLAttributes(ParsedAttributes &attrs); 1909207f4d8543529221932af82836016a2ef066c917Peter Collingbourne void ParseOpenCLQualifiers(DeclSpec &DS); 19107f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 19110a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor VersionTuple ParseVersionTuple(SourceRange &Range); 19120a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor void ParseAvailabilityAttribute(IdentifierInfo &Availability, 19130a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor SourceLocation AvailabilityLoc, 19140a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor ParsedAttributes &attrs, 19150a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor SourceLocation *endLoc); 19160a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 1917b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski bool IsThreadSafetyAttribute(llvm::StringRef AttrName); 1918b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski void ParseThreadSafetyAttribute(IdentifierInfo &AttrName, 1919b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski SourceLocation AttrNameLoc, 1920b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski ParsedAttributes &Attrs, 1921b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski SourceLocation *EndLoc); 1922b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski 1923b51e0315d4ffd12670441ea2284ae1188485df14Caitlin Sadowski 1924d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff void ParseTypeofSpecifier(DeclSpec &DS); 192542d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation ParseDecltypeSpecifier(DeclSpec &DS); 192642d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS, 192742d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation StartLoc, 192842d6d0c91ab089cb252ab2f91c16d4557f458a2cDavid Blaikie SourceLocation EndLoc); 1929db5d44b775c60166074acd184ca9f1981c10c2a7Sean Hunt void ParseUnderlyingTypeSpecifier(DeclSpec &DS); 1930b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void ParseAtomicSpecifier(DeclSpec &DS); 1931b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 19320b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne ExprResult ParseAlignArgument(SourceLocation Start, 19330b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne SourceLocation &EllipsisLoc); 193482d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne void ParseAlignmentSpecifier(ParsedAttributes &Attrs, 193582d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne SourceLocation *endLoc = 0); 1936eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 19371c94c16317c1a35c1549e022958188eea2567089Richard Smith VirtSpecifiers::Specifier isCXX0XVirtSpecifier(const Token &Tok) const; 19381c94c16317c1a35c1549e022958188eea2567089Richard Smith VirtSpecifiers::Specifier isCXX0XVirtSpecifier() const { 19391c94c16317c1a35c1549e022958188eea2567089Richard Smith return isCXX0XVirtSpecifier(Tok); 19401c94c16317c1a35c1549e022958188eea2567089Richard Smith } 1941b971dbdb65149a7cf0c046380186d0204e5b411eAnders Carlsson void ParseOptionalCXX0XVirtSpecifierSeq(VirtSpecifiers &VS); 19421f3b6fdabbb10779a473d6315154d7325ce20aeaAnders Carlsson 19438a29ba0d66bce99014651f1e3351aef6c3361d3fAnders Carlsson bool isCXX0XFinalKeyword() const; 1944cc54d594d4f6509c0e3a8e349e481d9b5d899df6Anders Carlsson 1945eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to 1946eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// enter a new C++ declarator scope and exit it when the function is 1947eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis /// finished. 1948eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis class DeclaratorScopeObj { 1949eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis Parser &P; 1950751810234ffb45327f23c5f9fda0b944e480bd2bArgyrios Kyrtzidis CXXScopeSpec &SS; 1951f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis bool EnteredScope; 1952f7f3d0db754db0500b56d49ac19f795f13965912John McCall bool CreatedScope; 1953eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis public: 1954f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) 1955f7f3d0db754db0500b56d49ac19f795f13965912John McCall : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {} 1956eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1957eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis void EnterDeclaratorScope() { 19582bcb3439b50c7f227a21d7118a2a76904ec60331Argyrios Kyrtzidis assert(!EnteredScope && "Already entered the scope!"); 1959f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was not set!"); 1960f7f3d0db754db0500b56d49ac19f795f13965912John McCall 1961f7f3d0db754db0500b56d49ac19f795f13965912John McCall CreatedScope = true; 1962f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.EnterScope(0); // Not a decl scope. 1963f7f3d0db754db0500b56d49ac19f795f13965912John McCall 196423c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS)) 19653fdbed594f4cb238fe37cad2ec3fefa3b6f67125Douglas Gregor EnteredScope = true; 1966eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1967eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis 1968eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis ~DeclaratorScopeObj() { 1969f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis if (EnteredScope) { 1970f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis assert(SS.isSet() && "C++ scope was cleared ?"); 197123c94dbb6631fecdb55ba401aa93722803d980c6Douglas Gregor P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS); 1972f37006bc8a9d398d40d6ce329f023ed1a92fe484Argyrios Kyrtzidis } 1973f7f3d0db754db0500b56d49ac19f795f13965912John McCall if (CreatedScope) 1974f7f3d0db754db0500b56d49ac19f795f13965912John McCall P.ExitScope(); 1975eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis } 1976eb83ecde1a822b1c38cd060a85a08c1ac9f82cf8Argyrios Kyrtzidis }; 19771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ParseDeclarator - Parse and verify a newly-initialized declarator. 19795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDeclarator(Declarator &D); 19804c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl /// A function that parses a variant of direct-declarator. 19814c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef void (Parser::*DirectDeclParseFunction)(Declarator&); 19824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl void ParseDeclaratorInternal(Declarator &D, 19834c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl DirectDeclParseFunction DirectDeclParser); 19847f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall 1985bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, 1986bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt bool CXX0XAttributesAllowed = true); 19875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseDirectDeclarator(Declarator &D); 19885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseParenDeclarator(Declarator &D); 19894a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor void ParseFunctionDeclarator(Declarator &D, 19907f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs, 19914a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker, 19927399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner bool RequiresArg = false); 19933fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor bool isFunctionDeclaratorIdentifierList(); 19943fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor void ParseFunctionDeclaratorIdentifierList( 19953fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor Declarator &D, 1996686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo); 19973fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor void ParseParameterDeclarationClause( 19983fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor Declarator &D, 19993fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor ParsedAttributes &attrs, 2000686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo, 20013fd1ba0fa133d1c6e641770d0bc56606587d3eefDouglas Gregor SourceLocation &EllipsisLoc); 20025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void ParseBracketDeclarator(Declarator &D); 20031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20048f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner //===--------------------------------------------------------------------===// 20058f08cb7d0b97786b17ef05e05caa55aad4d6bd39Chris Lattner // C++ 7: Declarations [dcl.dcl] 20061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2007a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie bool isCXX0XAttributeSpecifier(bool FullLookahead = false, 2008bbd37c62e34db3f5a95c899723484a76c71d7757Sean Hunt tok::TokenKind *After = 0); 2009a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 2010d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd, 2011d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation InlineLoc = SourceLocation()); 2012f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc, 2013f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<IdentifierInfo*>& Ident, 2014f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu std::vector<SourceLocation>& NamespaceLoc, 2015f858bd817e8d6eac58ae496fa96a2f508fbb286fRichard Trieu unsigned int index, SourceLocation& InlineLoc, 20164a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor ParsedAttributes& attrs, 20174a8dfb511e8f84b2e38b7a86d8ddf05ac1e1a41bDouglas Gregor BalancedDelimiterTracker &Tracker); 2018d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context); 2019d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseUsingDirectiveOrDeclaration(unsigned Context, 202078b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 2021d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 2022c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith ParsedAttributesWithRange &attrs, 2023c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith Decl **OwnedType = 0); 202478b810559d89e996e00684335407443936ce34a1John McCall Decl *ParseUsingDirective(unsigned Context, 202578b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 20267f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall SourceLocation &DeclEnd, 20277f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall ParsedAttributes &attrs); 202878b810559d89e996e00684335407443936ce34a1John McCall Decl *ParseUsingDeclaration(unsigned Context, 202978b810559d89e996e00684335407443936ce34a1John McCall const ParsedTemplateInfo &TemplateInfo, 203078b810559d89e996e00684335407443936ce34a1John McCall SourceLocation UsingLoc, 2031d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd, 2032c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith AccessSpecifier AS = AS_none, 2033c89edf5aaa08683f4afcf61a7a1d183c08b76498Richard Smith Decl **OwnedType = 0); 2034d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd); 2035d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc, 2036d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation AliasLoc, IdentifierInfo *Alias, 2037d078e641450bbc5a20df8d3b54f87b27e398acb3Sebastian Redl SourceLocation &DeclEnd); 20381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2039e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 2040e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 9: classes [class] and C structs/unions. 20414c97d762d8c5a84f6554e5bfb31d28c90df64158Chris Lattner void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, 20421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclSpec &DS, 20434d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 2044d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl AccessSpecifier AS = AS_none, 2045efaa93aaa2653f4eb40e6a22e504a448da94aaf8Douglas Gregor bool EnteringContext = false, 2046d9bafa76f8d6eb9e4f4974ed322217f8df6bb82eSebastian Redl bool SuppressDeclarations = false); 20474cc18a4d5222e04bd568b1e3e4d86127dbbcdf3fArgyrios Kyrtzidis void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType, 2048d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *TagDecl); 20497a614d8380297fcd2bc23986241905d97222948cRichard Smith ExprResult ParseCXXMemberInitializer(bool IsFunction, 20507a614d8380297fcd2bc23986241905d97222948cRichard Smith SourceLocation &EqualLoc); 20515f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen void ParseCXXClassMemberDeclaration(AccessSpecifier AS, AttributeList *Attr, 2052c9068d7dd94d439cec66c421115d15303e481025John McCall const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), 2053c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject *DiagsFromTParams = 0); 2054d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseConstructorInitializer(Decl *ConstructorDecl); 2055d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall MemInitResult ParseMemInitializer(Decl *ConstructorDecl); 2056d33133cdc1af466f9c276249b2621be03867888bEli Friedman void HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, 2057d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ThisDecl); 2058e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor 2059e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor //===--------------------------------------------------------------------===// 2060e37ac4ff1620ed2d7026f52baccbfa022d79ced1Douglas Gregor // C++ 10: Derived classes [class.derived] 2061a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc, 206222216eb4fb0936d2488fc03abd285d135c36ff01David Blaikie SourceLocation &EndLocation); 2063d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall void ParseBaseClause(Decl *ClassDecl); 2064d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall BaseResult ParseBaseSpecifier(Decl *ClassDecl); 20651b7f89846f10681ce3cbe89ef5d60691d55bd918Douglas Gregor AccessSpecifier getAccessSpecifierIfPresent() const; 20661cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor 2067a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, 2068e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 20693f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor IdentifierInfo *Name, 20703f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor SourceLocation NameLoc, 20713f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool EnteringContext, 2072b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2073d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor UnqualifiedId &Id, 2074e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool AssumeTemplateId); 2075ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, 2076b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2077ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &Result); 20783f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, 207902a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowDestructorName, 208002a24ee67c0a91bdb0db8a651d5748595652e670Douglas Gregor bool AllowConstructorName, 2081b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectType, 2082e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation& TemplateKWLoc, 20833f9a0566e6793151b99a65ab936220971cf96c1bDouglas Gregor UnqualifiedId &Result); 2084a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 20851cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor //===--------------------------------------------------------------------===// 2086adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14: Templates [temp] 2087c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor 2088adcac8824a9cff13f1ef61a69e38c1041cba12eeDouglas Gregor // C++ 14.1: Template Parameters [temp.param] 2089d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseDeclarationStartingWithTemplate(unsigned Context, 20905f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen SourceLocation &DeclEnd, 20915f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AccessSpecifier AS = AS_none, 20925f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AttributeList *AccessAttrs = 0); 2093d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateDeclarationOrSpecialization(unsigned Context, 20945f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen SourceLocation &DeclEnd, 20955f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AccessSpecifier AS, 20965f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AttributeList *AccessAttrs); 2097d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseSingleDeclarationAfterTemplate( 20981426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor unsigned Context, 20994d9a16f36d3b768672d50e6d02000f982ae448d7Douglas Gregor const ParsedTemplateInfo &TemplateInfo, 2100c9068d7dd94d439cec66c421115d15303e481025John McCall ParsingDeclRAIIObject &DiagsFromParams, 21011426e534b4fca6a05b1120d634aae46be79ca17cDouglas Gregor SourceLocation &DeclEnd, 21025f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AccessSpecifier AS=AS_none, 21035f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen AttributeList *AccessAttrs = 0); 21041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ParseTemplateParameters(unsigned Depth, 2105686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Decl*> &TemplateParams, 21061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation &LAngleLoc, 2107c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor SourceLocation &RAngleLoc); 2108c4b4e7b8f6ca9b036824e048af49cd2a52b57cdfDouglas Gregor bool ParseTemplateParameterList(unsigned Depth, 2109686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Decl*> &TemplateParams); 211098440b4ac17dc5f85ea3db683c1c1785449c17e1Douglas Gregor bool isStartOfTemplateTypeParameter(); 2111d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateParameter(unsigned Depth, unsigned Position); 2112d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTypeParameter(unsigned Depth, unsigned Position); 2113d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); 2114d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); 2115d6fb7ef028d9aa0b3e8943b7bc049c524437b407Douglas Gregor // C++ 14.3: Template arguments [temp.arg] 2116686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList; 2117cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 21187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor bool ParseTemplateIdAfterTemplateName(TemplateTy Template, 21191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation TemplateNameLoc, 2120059101f922de6eb765601459925f4c8914420b23Douglas Gregor const CXXScopeSpec &SS, 2121cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor bool ConsumeLastToken, 2122cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &LAngleLoc, 2123cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor TemplateArgList &TemplateArgs, 2124cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor SourceLocation &RAngleLoc); 2125cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor 2126c8e27cc402043ec86c1698c09e4ee9e415b16207Chris Lattner bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK, 2127059101f922de6eb765601459925f4c8914420b23Douglas Gregor CXXScopeSpec &SS, 2128e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2129ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId &TemplateName, 213039a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor bool AllowTypeAnnotation = true); 2131059101f922de6eb765601459925f4c8914420b23Douglas Gregor void AnnotateTemplateIdTokenAsType(); 2132d5ab9b0a0ae24f7d0f49f6f10fd1b247e64b3306Douglas Gregor bool IsTemplateArgumentList(unsigned Skip = 0); 2133314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs); 2134788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor ParsedTemplateArgument ParseTemplateTemplateArgument(); 2135314b97f8c564b465af605efaee23f91ec18a982bDouglas Gregor ParsedTemplateArgument ParseTemplateArgument(); 21369241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis Decl *ParseExplicitInstantiation(unsigned Context, 21379241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis SourceLocation ExternLoc, 21389241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis SourceLocation TemplateLoc, 21399241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis SourceLocation &DeclEnd, 21409241057266d3460392cbb7fec6ec942d3330ece3Argyrios Kyrtzidis AccessSpecifier AS = AS_none); 214164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 214264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl //===--------------------------------------------------------------------===// 21436aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor // Modules 21445948ae1021122164b22f74353bb7fe325a64f616Douglas Gregor DeclGroupPtrTy ParseModuleImport(SourceLocation AtLoc); 2145a8fbc053eb08c929174bf519a0e9733e4ef90bfaDavid Blaikie 21466aa52ec6b969faabf3764baf79d89810b8249a7eDouglas Gregor //===--------------------------------------------------------------------===// 214764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // GNU G++: Type Traits [Type-Traits.html in the GCC manual] 214860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ParseUnaryTypeTrait(); 21496ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet ExprResult ParseBinaryTypeTrait(); 2150f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor 2151f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor //===--------------------------------------------------------------------===// 215221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley // Embarcadero: Arary and Expression Traits 215321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult ParseArrayTypeTrait(); 2154552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult ParseExpressionTrait(); 2155552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2156552622067dc45013d240f73952fece703f5e63bdJohn Wiegley //===--------------------------------------------------------------------===// 2157f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor // Preprocessor code-completion pass-through 2158f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor virtual void CodeCompleteDirective(bool InConditional); 2159f44e854ed1e3aa86d2ed6d615ccd109d50ddcff9Douglas Gregor virtual void CodeCompleteInConditionalExclusion(); 21601fbb447e9d43c2c676e94081fbfee7eb6cbe933bDouglas Gregor virtual void CodeCompleteMacroName(bool IsDefinition); 2161f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor virtual void CodeCompletePreprocessorExpression(); 2162f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro, 2163f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor MacroInfo *MacroInfo, 2164f29c5233085a5af795c3c01b94d319e5b3235d56Douglas Gregor unsigned ArgumentIndex); 216555817afdf9d453a443262a733f6caf6692dca118Douglas Gregor virtual void CodeCompleteNaturalLanguage(); 21665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 21675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 21695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2171