summaryrefslogtreecommitdiffstats
path: root/include/clang/Parse/Parser.h
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2011-02-20 13:06:31 +0000
committerdim <dim@FreeBSD.org>2011-02-20 13:06:31 +0000
commit39fcc9a984e2820e4ea0fa2ac4abd17d9f3a31df (patch)
treea9243275843fbeaa590afc07ee888e006b8d54ea /include/clang/Parse/Parser.h
parent69b4eca4a4255ba43baa5c1d9bbdec3ec17f479e (diff)
downloadFreeBSD-src-39fcc9a984e2820e4ea0fa2ac4abd17d9f3a31df.zip
FreeBSD-src-39fcc9a984e2820e4ea0fa2ac4abd17d9f3a31df.tar.gz
Vendor import of clang trunk r126079:
http://llvm.org/svn/llvm-project/cfe/trunk@126079
Diffstat (limited to 'include/clang/Parse/Parser.h')
-rw-r--r--include/clang/Parse/Parser.h358
1 files changed, 268 insertions, 90 deletions
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index 41a2fb6..7587920 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -25,8 +25,6 @@
#include <list>
namespace clang {
- class AttributeList;
- struct CXX0XAttributeList;
class PragmaHandler;
class Scope;
class DeclGroupRef;
@@ -34,7 +32,8 @@ namespace clang {
class Parser;
class PragmaUnusedHandler;
class ColonProtectionRAIIObject;
-
+ class InMessageExpressionRAIIObject;
+
/// PrettyStackTraceParserEntry - If a crash happens while the parser is active,
/// an entry is printed for it.
class PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry {
@@ -75,6 +74,7 @@ namespace prec {
class Parser : public CodeCompletionHandler {
friend class PragmaUnusedHandler;
friend class ColonProtectionRAIIObject;
+ friend class InMessageExpressionRAIIObject;
friend class ParenBraceBracketBalancer;
PrettyStackTraceParserEntry CrashInfo;
@@ -112,12 +112,18 @@ class Parser : public CodeCompletionHandler {
IdentifierInfo *Ident_vector;
IdentifierInfo *Ident_pixel;
+ /// C++0x contextual keywords.
+ mutable IdentifierInfo *Ident_final;
+ mutable IdentifierInfo *Ident_override;
+
llvm::OwningPtr<PragmaHandler> AlignHandler;
llvm::OwningPtr<PragmaHandler> GCCVisibilityHandler;
llvm::OwningPtr<PragmaHandler> OptionsHandler;
llvm::OwningPtr<PragmaHandler> PackHandler;
llvm::OwningPtr<PragmaHandler> UnusedHandler;
llvm::OwningPtr<PragmaHandler> WeakHandler;
+ llvm::OwningPtr<PragmaHandler> FPContractHandler;
+ llvm::OwningPtr<PragmaHandler> OpenCLExtensionHandler;
/// Whether the '>' token acts as an operator or not. This will be
/// true except when we are parsing an expression within a C++
@@ -131,8 +137,18 @@ class Parser : public CodeCompletionHandler {
/// ColonProtectionRAIIObject RAII object.
bool ColonIsSacred;
+ /// \brief When true, we are directly inside an Ojective-C messsage
+ /// send expression.
+ ///
+ /// This is managed by the \c InMessageExpressionRAIIObject class, and
+ /// should not be set directly.
+ bool InMessageExpression;
+
/// The "depth" of the template parameters currently being parsed.
unsigned TemplateParameterDepth;
+
+ /// Factory object for creating AttributeList objects.
+ AttributeList::Factory AttrFactory;
public:
Parser(Preprocessor &PP, Sema &Actions);
@@ -152,7 +168,7 @@ public:
typedef Stmt StmtTy;
typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
typedef CXXBaseSpecifier BaseTy;
- typedef CXXBaseOrMemberInitializer MemInitTy;
+ typedef CXXCtorInitializer MemInitTy;
typedef NestedNameSpecifier CXXScopeTy;
typedef TemplateParameterList TemplateParamsTy;
typedef OpaquePtr<TemplateName> TemplateTy;
@@ -227,6 +243,11 @@ private:
Tok.getKind() == tok::wide_string_literal;
}
+ /// \brief Returns true if the current token is a '=' or '==' and
+ /// false otherwise. If it's '==', we assume that it's a typo and we emit
+ /// DiagID and a fixit hint to turn '==' -> '='.
+ bool isTokenEqualOrMistypedEqualEqual(unsigned DiagID);
+
/// ConsumeToken - Consume the current 'peek token' and lex the next one.
/// This does not work with all kinds of tokens: strings and specific other
/// tokens must be consumed with custom methods below. This returns the
@@ -330,6 +351,9 @@ private:
/// based on context.
void CodeCompletionRecovery();
+ /// \brief Handle the annotation token produced for #pragma unused(...)
+ void HandlePragmaUnused();
+
/// GetLookAheadToken - This peeks ahead N tokens and returns that token
/// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1)
/// returns the token after Tok, etc.
@@ -464,6 +488,13 @@ private:
const char *DiagMsg = "",
tok::TokenKind SkipToTok = tok::unknown);
+ /// \brief The parser expects a semicolon and, if present, will consume it.
+ ///
+ /// If the next token is not a semicolon, this emits the specified diagnostic,
+ /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior
+ /// to the semicolon, consumes that extra token.
+ bool ExpectAndConsumeSemi(unsigned DiagID);
+
//===--------------------------------------------------------------------===//
// Scope manipulation
@@ -531,21 +562,59 @@ private:
/// If SkipUntil finds the specified token, it returns true, otherwise it
/// returns false.
bool SkipUntil(tok::TokenKind T, bool StopAtSemi = true,
- bool DontConsume = false) {
- return SkipUntil(&T, 1, StopAtSemi, DontConsume);
+ bool DontConsume = false, bool StopAtCodeCompletion = false) {
+ return SkipUntil(&T, 1, StopAtSemi, DontConsume, StopAtCodeCompletion);
}
bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, bool StopAtSemi = true,
- bool DontConsume = false) {
+ bool DontConsume = false, bool StopAtCodeCompletion = false) {
tok::TokenKind TokArray[] = {T1, T2};
- return SkipUntil(TokArray, 2, StopAtSemi, DontConsume);
+ return SkipUntil(TokArray, 2, StopAtSemi, DontConsume,StopAtCodeCompletion);
}
bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
- bool StopAtSemi = true, bool DontConsume = false);
+ bool StopAtSemi = true, bool DontConsume = false,
+ bool StopAtCodeCompletion = false);
//===--------------------------------------------------------------------===//
// Lexing and parsing of C++ inline methods.
- struct LexedMethod {
+ struct ParsingClass;
+
+ /// [class.mem]p1: "... the class is regarded as complete within
+ /// - function bodies
+ /// - default arguments
+ /// - exception-specifications (TODO: C++0x)
+ /// - and brace-or-equal-initializers (TODO: C++0x)
+ /// for non-static data members (including such things in nested classes)."
+ /// LateParsedDeclarations build the tree of those elements so they can
+ /// be parsed after parsing the top-level class.
+ class LateParsedDeclaration {
+ public:
+ virtual ~LateParsedDeclaration();
+
+ virtual void ParseLexedMethodDeclarations();
+ virtual void ParseLexedMethodDefs();
+ };
+
+ /// Inner node of the LateParsedDeclaration tree that parses
+ /// all its members recursively.
+ class LateParsedClass : public LateParsedDeclaration {
+ public:
+ LateParsedClass(Parser *P, ParsingClass *C);
+ virtual ~LateParsedClass();
+
+ virtual void ParseLexedMethodDeclarations();
+ virtual void ParseLexedMethodDefs();
+
+ private:
+ Parser *Self;
+ ParsingClass *Class;
+ };
+
+ /// Contains the lexed tokens of a member function definition
+ /// which needs to be parsed at the end of the class declaration
+ /// after parsing all other member declarations.
+ struct LexedMethod : public LateParsedDeclaration {
+ Parser *Self;
Decl *D;
CachedTokens Toks;
@@ -554,7 +623,10 @@ private:
/// othewise, it is a member function declaration.
bool TemplateScope;
- explicit LexedMethod(Decl *MD) : D(MD), TemplateScope(false) {}
+ explicit LexedMethod(Parser* P, Decl *MD)
+ : Self(P), D(MD), TemplateScope(false) {}
+
+ virtual void ParseLexedMethodDefs();
};
/// LateParsedDefaultArgument - Keeps track of a parameter that may
@@ -580,9 +652,13 @@ private:
/// contains at least one entity whose parsing needs to be delayed
/// until the class itself is completely-defined, such as a default
/// argument (C++ [class.mem]p2).
- struct LateParsedMethodDeclaration {
- explicit LateParsedMethodDeclaration(Decl *M)
- : Method(M), TemplateScope(false) { }
+ struct LateParsedMethodDeclaration : public LateParsedDeclaration {
+ explicit LateParsedMethodDeclaration(Parser *P, Decl *M)
+ : Self(P), Method(M), TemplateScope(false) { }
+
+ virtual void ParseLexedMethodDeclarations();
+
+ Parser* Self;
/// Method - The method declaration.
Decl *Method;
@@ -600,17 +676,12 @@ private:
llvm::SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
};
- /// LateParsedMethodDecls - During parsing of a top (non-nested) C++
- /// class, its method declarations that contain parts that won't be
+ /// LateParsedDeclarationsContainer - During parsing of a top (non-nested)
+ /// C++ class, its method declarations that contain parts that won't be
/// parsed until after the definiton is completed (C++ [class.mem]p2),
- /// the method declarations will be stored here with the tokens that
- /// will be parsed to create those entities.
- typedef std::list<LateParsedMethodDeclaration> LateParsedMethodDecls;
-
- /// LexedMethodsForTopClass - During parsing of a top (non-nested) C++ class,
- /// its inline method definitions and the inline method definitions of its
- /// nested classes are lexed and stored here.
- typedef std::list<LexedMethod> LexedMethodsForTopClass;
+ /// the method declarations and possibly attached inline definitions
+ /// will be stored here with the tokens that will be parsed to create those entities.
+ typedef llvm::SmallVector<LateParsedDeclaration*, 2> LateParsedDeclarationsContainer;
/// \brief Representation of a class that has been parsed, including
/// any member function declarations or definitions that need to be
@@ -632,16 +703,10 @@ private:
/// \brief The class or class template whose definition we are parsing.
Decl *TagOrTemplate;
- /// MethodDecls - Method declarations that contain pieces whose
- /// parsing will be delayed until the class is fully defined.
- LateParsedMethodDecls MethodDecls;
-
- /// MethodDefs - Methods whose definitions will be parsed once the
- /// class has been fully defined.
- LexedMethodsForTopClass MethodDefs;
-
- /// \brief Nested classes inside this class.
- llvm::SmallVector<ParsingClass*, 4> NestedClasses;
+ /// LateParsedDeclarations - Method declarations, inline definitions and
+ /// nested classes that contain pieces whose parsing will be delayed until
+ /// the top-level class is fully defined.
+ LateParsedDeclarationsContainer LateParsedDeclarations;
};
/// \brief The stack of classes that is currently being
@@ -660,7 +725,7 @@ private:
/// class or function definition.
class ParsingDeclRAIIObject {
Sema &Actions;
- Sema::ParsingDeclStackState State;
+ Sema::ParsingDeclState State;
bool Popped;
public:
@@ -772,23 +837,24 @@ private:
class ParsingClassDefinition {
Parser &P;
bool Popped;
+ Sema::ParsingClassState State;
public:
ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass)
- : P(P), Popped(false) {
- P.PushParsingClass(TagOrTemplate, TopLevelClass);
+ : P(P), Popped(false),
+ State(P.PushParsingClass(TagOrTemplate, TopLevelClass)) {
}
/// \brief Pop this class of the stack.
void Pop() {
assert(!Popped && "Nested class has already been popped");
Popped = true;
- P.PopParsingClass();
+ P.PopParsingClass(State);
}
~ParsingClassDefinition() {
if (!Popped)
- P.PopParsingClass();
+ P.PopParsingClass(State);
}
};
@@ -838,16 +904,22 @@ private:
/// \brief Whether the last template parameter list was empty.
bool LastParameterListWasEmpty;
+
+ SourceRange getSourceRange() const;
};
- void PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass);
+ Sema::ParsingClassState
+ PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass);
void DeallocateParsedClasses(ParsingClass *Class);
- void PopParsingClass();
+ void PopParsingClass(Sema::ParsingClassState);
- Decl *ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D,
- const ParsedTemplateInfo &TemplateInfo);
+ Decl *ParseCXXInlineMethodDef(AccessSpecifier AS, ParsingDeclarator &D,
+ const ParsedTemplateInfo &TemplateInfo,
+ const VirtSpecifiers& VS);
void ParseLexedMethodDeclarations(ParsingClass &Class);
+ void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
void ParseLexedMethodDefs(ParsingClass &Class);
+ void ParseLexedMethodDef(LexedMethod &LM);
bool ConsumeAndStoreUntil(tok::TokenKind T1,
CachedTokens &Toks,
bool StopAtSemi = true,
@@ -861,14 +933,17 @@ private:
//===--------------------------------------------------------------------===//
// C99 6.9: External Definitions.
- DeclGroupPtrTy ParseExternalDeclaration(CXX0XAttributeList Attr,
+ struct ParsedAttributesWithRange : ParsedAttributes {
+ SourceRange Range;
+ };
+
+ DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
ParsingDeclSpec *DS = 0);
bool isDeclarationAfterDeclarator() const;
bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator);
- DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(AttributeList *Attr,
- AccessSpecifier AS = AS_none);
+ DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsedAttributes &attrs,
+ AccessSpecifier AS = AS_none);
DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS,
- AttributeList *Attr,
AccessSpecifier AS = AS_none);
Decl *ParseFunctionDefinition(ParsingDeclarator &D,
@@ -883,7 +958,7 @@ private:
Decl *ParseObjCAtDirectives();
Decl *ParseObjCAtClassDeclaration(SourceLocation atLoc);
Decl *ParseObjCAtInterfaceDeclaration(SourceLocation atLoc,
- AttributeList *prefixAttrs = 0);
+ ParsedAttributes &prefixAttrs);
void ParseObjCClassInstanceVariables(Decl *interfaceDecl,
tok::ObjCKeywordKind visibility,
SourceLocation atLoc);
@@ -892,10 +967,11 @@ private:
bool WarnOnDeclarations,
SourceLocation &LAngleLoc,
SourceLocation &EndProtoLoc);
+ bool ParseObjCProtocolQualifiers(DeclSpec &DS);
void ParseObjCInterfaceDeclList(Decl *interfaceDecl,
tok::ObjCKeywordKind contextKey);
Decl *ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
- AttributeList *prefixAttrs = 0);
+ ParsedAttributes &prefixAttrs);
Decl *ObjCImpDecl;
llvm::SmallVector<Decl *, 4> PendingObjCImpDecl;
@@ -923,8 +999,7 @@ private:
Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
Decl *classDecl,
tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
- void ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl,
- Decl **Methods, unsigned NumMethods);
+ void ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl);
Decl *ParseObjCMethodDefinition();
@@ -1022,6 +1097,10 @@ private:
ExprResult ParseCXXTypeid();
//===--------------------------------------------------------------------===//
+ // C++ : Microsoft __uuidof Expression
+ ExprResult ParseCXXUuidof();
+
+ //===--------------------------------------------------------------------===//
// C++ 5.2.4: C++ Pseudo-Destructor Expressions
ExprResult ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc,
tok::TokenKind OpKind,
@@ -1042,6 +1121,10 @@ private:
bool &hasAnyExceptionSpec);
//===--------------------------------------------------------------------===//
+ // C++0x 8: Function declaration trailing-return-type
+ TypeResult ParseTrailingReturnType();
+
+ //===--------------------------------------------------------------------===//
// C++ 2.13.5: C++ Boolean Literals
ExprResult ParseCXXBoolLiteral();
@@ -1117,30 +1200,32 @@ private:
// C99 6.8: Statements and Blocks.
StmtResult ParseStatement() {
- return ParseStatementOrDeclaration(true);
+ StmtVector Stmts(Actions);
+ return ParseStatementOrDeclaration(Stmts, true);
}
- StmtResult ParseStatementOrDeclaration(bool OnlyStatement = false);
- StmtResult ParseLabeledStatement(AttributeList *Attr);
- StmtResult ParseCaseStatement(AttributeList *Attr);
- StmtResult ParseDefaultStatement(AttributeList *Attr);
- StmtResult ParseCompoundStatement(AttributeList *Attr,
+ StmtResult ParseStatementOrDeclaration(StmtVector& Stmts,
+ bool OnlyStatement = false);
+ StmtResult ParseLabeledStatement(ParsedAttributes &Attr);
+ StmtResult ParseCaseStatement(ParsedAttributes &Attr);
+ StmtResult ParseDefaultStatement(ParsedAttributes &Attr);
+ StmtResult ParseCompoundStatement(ParsedAttributes &Attr,
bool isStmtExpr = false);
StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
bool ParseParenExprOrCondition(ExprResult &ExprResult,
Decl *&DeclResult,
SourceLocation Loc,
bool ConvertToBoolean);
- StmtResult ParseIfStatement(AttributeList *Attr);
- StmtResult ParseSwitchStatement(AttributeList *Attr);
- StmtResult ParseWhileStatement(AttributeList *Attr);
- StmtResult ParseDoStatement(AttributeList *Attr);
- StmtResult ParseForStatement(AttributeList *Attr);
- StmtResult ParseGotoStatement(AttributeList *Attr);
- StmtResult ParseContinueStatement(AttributeList *Attr);
- StmtResult ParseBreakStatement(AttributeList *Attr);
- StmtResult ParseReturnStatement(AttributeList *Attr);
+ StmtResult ParseIfStatement(ParsedAttributes &Attr);
+ StmtResult ParseSwitchStatement(ParsedAttributes &Attr);
+ StmtResult ParseWhileStatement(ParsedAttributes &Attr);
+ StmtResult ParseDoStatement(ParsedAttributes &Attr);
+ StmtResult ParseForStatement(ParsedAttributes &Attr);
+ StmtResult ParseGotoStatement(ParsedAttributes &Attr);
+ StmtResult ParseContinueStatement(ParsedAttributes &Attr);
+ StmtResult ParseBreakStatement(ParsedAttributes &Attr);
+ StmtResult ParseReturnStatement(ParsedAttributes &Attr);
StmtResult ParseAsmStatement(bool &msAsm);
- StmtResult FuzzyParseMicrosoftAsmStatement();
+ StmtResult FuzzyParseMicrosoftAsmStatement(SourceLocation AsmLoc);
bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<IdentifierInfo *> &Names,
llvm::SmallVectorImpl<ExprTy *> &Constraints,
llvm::SmallVectorImpl<ExprTy *> &Exprs);
@@ -1148,7 +1233,7 @@ private:
//===--------------------------------------------------------------------===//
// C++ 6: Statements and Blocks
- StmtResult ParseCXXTryBlock(AttributeList *Attr);
+ StmtResult ParseCXXTryBlock(ParsedAttributes &Attr);
StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc);
StmtResult ParseCXXCatchBlock();
@@ -1173,11 +1258,13 @@ private:
DSC_top_level // top-level/namespace declaration context
};
- DeclGroupPtrTy ParseDeclaration(unsigned Context, SourceLocation &DeclEnd,
- CXX0XAttributeList Attr);
- DeclGroupPtrTy ParseSimpleDeclaration(unsigned Context,
+ DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts,
+ unsigned Context, SourceLocation &DeclEnd,
+ ParsedAttributesWithRange &attrs);
+ DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts,
+ unsigned Context,
SourceLocation &DeclEnd,
- AttributeList *Attr,
+ ParsedAttributes &attrs,
bool RequireSemi);
DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context,
bool AllowFunctionDefinitions,
@@ -1187,6 +1274,12 @@ private:
Decl *ParseFunctionStatementBody(Decl *Decl);
Decl *ParseFunctionTryBlock(Decl *Decl);
+ /// \brief When in code-completion, skip parsing of the function/method body
+ /// unless the body contains the code-completion point.
+ ///
+ /// \returns true if the function body was skipped.
+ bool trySkippingFunctionBodyForCodeCompletion();
+
bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
const ParsedTemplateInfo &TemplateInfo,
AccessSpecifier AS);
@@ -1206,7 +1299,8 @@ private:
void ParseObjCTypeQualifierList(ObjCDeclSpec &DS, bool IsParameter);
void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
- const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(), AccessSpecifier AS = AS_none);
+ const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
+ AccessSpecifier AS = AS_none);
void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
Decl *TagDecl);
@@ -1222,7 +1316,7 @@ private:
void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback);
- bool isDeclarationSpecifier();
+ bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
bool isTypeSpecifierQualifier();
bool isTypeQualifier() const;
@@ -1237,7 +1331,7 @@ private:
bool isDeclarationStatement() {
if (getLang().CPlusPlus)
return isCXXDeclarationStatement();
- return isDeclarationSpecifier();
+ return isDeclarationSpecifier(true);
}
/// isSimpleDeclaration - Disambiguates between a declaration or an
@@ -1247,9 +1341,13 @@ private:
bool isSimpleDeclaration() {
if (getLang().CPlusPlus)
return isCXXSimpleDeclaration();
- return isDeclarationSpecifier();
+ return isDeclarationSpecifier(true);
}
+ /// \brief Determine whether we are currently at the start of an Objective-C
+ /// class message that appears to be missing the open bracket '['.
+ bool isStartOfObjCClassMessageMissingOpenBracket();
+
/// \brief Starting with a scope specifier, identifier, or
/// template-id that refers to the current class, determine whether
/// this is a constructor declarator.
@@ -1333,6 +1431,18 @@ private:
bool operator!=(const TPResult &RHS) const { return Res != RHS.Res; }
};
+ /// \brief Based only on the given token kind, determine whether we know that
+ /// we're at the start of an expression or a type-specifier-seq (which may
+ /// be an expression, in C++).
+ ///
+ /// This routine does not attempt to resolve any of the trick cases, e.g.,
+ /// those involving lookup of identifiers.
+ ///
+ /// \returns \c TPR_true if this token starts an expression, \c TPR_false if
+ /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot
+ /// tell.
+ TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind);
+
/// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a
/// declaration specifier, TPResult::False() if it is not,
/// TPResult::Ambiguous() if it could be either a decl-specifier or a
@@ -1340,7 +1450,7 @@ private:
/// encountered.
/// Doesn't consume tokens.
TPResult isCXXDeclarationSpecifier();
-
+
// "Tentative parsing" functions, used for disambiguation. If a parsing error
// is encountered they will return TPResult::Error().
// Returning TPResult::True()/False() indicates that the ambiguity was
@@ -1351,26 +1461,87 @@ private:
TPResult TryParseDeclarationSpecifier();
TPResult TryParseSimpleDeclaration();
TPResult TryParseTypeofSpecifier();
+ TPResult TryParseProtocolQualifiers();
TPResult TryParseInitDeclaratorList();
TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier=true);
TPResult TryParseParameterDeclarationClause();
TPResult TryParseFunctionDeclarator();
TPResult TryParseBracketDeclarator();
- TypeResult ParseTypeName(SourceRange *Range = 0);
+ TypeResult ParseTypeName(SourceRange *Range = 0,
+ Declarator::TheContext Context
+ = Declarator::TypeNameContext);
void ParseBlockId();
- // EndLoc, if non-NULL, is filled with the location of the last token of
- // the attribute list.
- CXX0XAttributeList ParseCXX0XAttributes(SourceLocation *EndLoc = 0);
- AttributeList *ParseGNUAttributes(SourceLocation *EndLoc = 0);
- AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0);
- AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0);
- AttributeList *ParseBorlandTypeAttributes(AttributeList* CurrAttr = 0);
+
+ void ProhibitAttributes(ParsedAttributesWithRange &attrs) {
+ if (!attrs.Range.isValid()) return;
+ DiagnoseProhibitedAttributes(attrs);
+ }
+ void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs);
+
+ void MaybeParseGNUAttributes(Declarator &D) {
+ if (Tok.is(tok::kw___attribute)) {
+ ParsedAttributes attrs;
+ SourceLocation endLoc;
+ ParseGNUAttributes(attrs, &endLoc);
+ D.addAttributes(attrs.getList(), endLoc);
+ }
+ }
+ void MaybeParseGNUAttributes(ParsedAttributes &attrs,
+ SourceLocation *endLoc = 0) {
+ if (Tok.is(tok::kw___attribute))
+ ParseGNUAttributes(attrs, endLoc);
+ }
+ void ParseGNUAttributes(ParsedAttributes &attrs,
+ SourceLocation *endLoc = 0);
+
+ void MaybeParseCXX0XAttributes(Declarator &D) {
+ if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) {
+ ParsedAttributesWithRange attrs;
+ SourceLocation endLoc;
+ ParseCXX0XAttributes(attrs, &endLoc);
+ D.addAttributes(attrs.getList(), endLoc);
+ }
+ }
+ void MaybeParseCXX0XAttributes(ParsedAttributes &attrs,
+ SourceLocation *endLoc = 0) {
+ if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) {
+ ParsedAttributesWithRange attrsWithRange;
+ ParseCXX0XAttributes(attrsWithRange, endLoc);
+ attrs.append(attrsWithRange.getList());
+ }
+ }
+ void MaybeParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
+ SourceLocation *endLoc = 0) {
+ if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
+ ParseCXX0XAttributes(attrs, endLoc);
+ }
+ void ParseCXX0XAttributes(ParsedAttributesWithRange &attrs,
+ SourceLocation *EndLoc = 0);
+
+ void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs,
+ SourceLocation *endLoc = 0) {
+ if (getLang().Microsoft && Tok.is(tok::l_square))
+ ParseMicrosoftAttributes(attrs, endLoc);
+ }
+ void ParseMicrosoftAttributes(ParsedAttributes &attrs,
+ SourceLocation *endLoc = 0);
+ void ParseMicrosoftDeclSpec(ParsedAttributes &attrs);
+ void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
+ void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
+ void ParseOpenCLAttributes(ParsedAttributes &attrs);
+
void ParseTypeofSpecifier(DeclSpec &DS);
void ParseDecltypeSpecifier(DeclSpec &DS);
ExprResult ParseCXX0XAlignArgument(SourceLocation Start);
+ VirtSpecifiers::Specifier isCXX0XVirtSpecifier() const;
+ void ParseOptionalCXX0XVirtSpecifierSeq(VirtSpecifiers &VS);
+
+ ClassVirtSpecifiers::Specifier isCXX0XClassVirtSpecifier() const;
+ void ParseOptionalCXX0XClassVirtSpecifierSeq(ClassVirtSpecifiers &CVS);
+
/// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
/// enter a new C++ declarator scope and exit it when the function is
/// finished.
@@ -1410,12 +1581,13 @@ private:
typedef void (Parser::*DirectDeclParseFunction)(Declarator&);
void ParseDeclaratorInternal(Declarator &D,
DirectDeclParseFunction DirectDeclParser);
+
void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true,
bool CXX0XAttributesAllowed = true);
void ParseDirectDeclarator(Declarator &D);
void ParseParenDeclarator(Declarator &D);
void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
- AttributeList *AttrList = 0,
+ ParsedAttributes &attrs,
bool RequiresArg = false);
void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc,
IdentifierInfo *FirstIdent,
@@ -1433,11 +1605,16 @@ private:
SourceLocation InlineLoc = SourceLocation());
Decl *ParseLinkage(ParsingDeclSpec &DS, unsigned Context);
Decl *ParseUsingDirectiveOrDeclaration(unsigned Context,
+ const ParsedTemplateInfo &TemplateInfo,
SourceLocation &DeclEnd,
- CXX0XAttributeList Attrs);
- Decl *ParseUsingDirective(unsigned Context, SourceLocation UsingLoc,
- SourceLocation &DeclEnd, AttributeList *Attr);
- Decl *ParseUsingDeclaration(unsigned Context, SourceLocation UsingLoc,
+ ParsedAttributesWithRange &attrs);
+ Decl *ParseUsingDirective(unsigned Context,
+ SourceLocation UsingLoc,
+ SourceLocation &DeclEnd,
+ ParsedAttributes &attrs);
+ Decl *ParseUsingDeclaration(unsigned Context,
+ const ParsedTemplateInfo &TemplateInfo,
+ SourceLocation UsingLoc,
SourceLocation &DeclEnd,
AccessSpecifier AS = AS_none);
Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
@@ -1542,6 +1719,7 @@ private:
//===--------------------------------------------------------------------===//
// GNU G++: Type Traits [Type-Traits.html in the GCC manual]
ExprResult ParseUnaryTypeTrait();
+ ExprResult ParseBinaryTypeTrait();
//===--------------------------------------------------------------------===//
// Preprocessor code-completion pass-through
OpenPOWER on IntegriCloud