2006-08-11 02:43:39 +08:00
|
|
|
//===--- Parser.cpp - C Language Family Parser ----------------------------===//
|
2006-07-31 09:59:18 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-07-31 09:59:18 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Parser interfaces.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Parse/Parser.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "ParsePragma.h"
|
|
|
|
#include "RAIIObjectsForParser.h"
|
|
|
|
#include "clang/AST/ASTConsumer.h"
|
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2009-01-29 13:15:15 +08:00
|
|
|
#include "clang/Parse/ParseDiagnostic.h"
|
2010-08-21 02:27:03 +08:00
|
|
|
#include "clang/Sema/DeclSpec.h"
|
|
|
|
#include "clang/Sema/ParsedTemplate.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Sema/Scope.h"
|
2009-03-05 15:24:28 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2006-07-31 09:59:18 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2012-10-27 17:05:45 +08:00
|
|
|
|
2012-07-13 21:25:11 +08:00
|
|
|
namespace {
|
2012-06-20 08:34:58 +08:00
|
|
|
/// \brief A comment handler that passes comments found by the preprocessor
|
|
|
|
/// to the parser action.
|
|
|
|
class ActionCommentHandler : public CommentHandler {
|
|
|
|
Sema &S;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ActionCommentHandler(Sema &S) : S(S) { }
|
|
|
|
|
|
|
|
virtual bool HandleComment(Preprocessor &PP, SourceRange Comment) {
|
|
|
|
S.ActOnComment(Comment);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2012-07-13 21:25:11 +08:00
|
|
|
} // end anonymous namespace
|
2012-06-20 08:34:58 +08:00
|
|
|
|
2011-10-21 11:57:52 +08:00
|
|
|
IdentifierInfo *Parser::getSEHExceptKeyword() {
|
|
|
|
// __except is accepted as a (contextual) keyword
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!Ident__except && (getLangOpts().MicrosoftExt || getLangOpts().Borland))
|
2011-10-21 11:57:52 +08:00
|
|
|
Ident__except = PP.getIdentifierInfo("__except");
|
|
|
|
|
|
|
|
return Ident__except;
|
|
|
|
}
|
|
|
|
|
2012-11-01 01:29:22 +08:00
|
|
|
Parser::Parser(Preprocessor &pp, Sema &actions, bool skipFunctionBodies)
|
2011-03-22 09:15:17 +08:00
|
|
|
: PP(pp), Actions(actions), Diags(PP.getDiagnostics()),
|
2010-09-15 22:51:05 +08:00
|
|
|
GreaterThanIsOperator(true), ColonIsSacred(false),
|
2012-04-12 18:11:59 +08:00
|
|
|
InMessageExpression(false), TemplateParameterDepth(0),
|
2012-11-01 01:29:22 +08:00
|
|
|
ParsingInObjCContainer(false) {
|
|
|
|
SkipFunctionBodies = pp.isCodeCompletionEnabled() || skipFunctionBodies;
|
2012-10-28 03:49:20 +08:00
|
|
|
Tok.startToken();
|
2006-10-14 13:19:21 +08:00
|
|
|
Tok.setKind(tok::eof);
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.CurScope = 0;
|
2007-07-15 08:04:39 +08:00
|
|
|
NumCachedScopes = 0;
|
2006-08-07 05:55:29 +08:00
|
|
|
ParenCount = BracketCount = BraceCount = 0;
|
2012-02-08 00:50:53 +08:00
|
|
|
CurParsedObjCImpl = 0;
|
2008-10-05 03:21:03 +08:00
|
|
|
|
|
|
|
// Add #pragma handlers. These are removed and destroyed in the
|
|
|
|
// destructor.
|
2012-10-04 10:36:51 +08:00
|
|
|
AlignHandler.reset(new PragmaAlignHandler());
|
2010-08-01 03:17:07 +08:00
|
|
|
PP.AddPragmaHandler(AlignHandler.get());
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
GCCVisibilityHandler.reset(new PragmaGCCVisibilityHandler());
|
2010-08-05 14:57:20 +08:00
|
|
|
PP.AddPragmaHandler("GCC", GCCVisibilityHandler.get());
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
OptionsHandler.reset(new PragmaOptionsHandler());
|
2010-07-13 17:07:17 +08:00
|
|
|
PP.AddPragmaHandler(OptionsHandler.get());
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
PackHandler.reset(new PragmaPackHandler());
|
2010-07-13 17:07:17 +08:00
|
|
|
PP.AddPragmaHandler(PackHandler.get());
|
2011-04-26 02:49:15 +08:00
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
MSStructHandler.reset(new PragmaMSStructHandler());
|
2011-04-26 02:49:15 +08:00
|
|
|
PP.AddPragmaHandler(MSStructHandler.get());
|
2010-07-13 17:07:17 +08:00
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
UnusedHandler.reset(new PragmaUnusedHandler());
|
2010-07-13 17:07:17 +08:00
|
|
|
PP.AddPragmaHandler(UnusedHandler.get());
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
WeakHandler.reset(new PragmaWeakHandler());
|
2010-07-13 17:07:17 +08:00
|
|
|
PP.AddPragmaHandler(WeakHandler.get());
|
2011-02-14 09:42:35 +08:00
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
RedefineExtnameHandler.reset(new PragmaRedefineExtnameHandler());
|
2012-02-19 00:12:34 +08:00
|
|
|
PP.AddPragmaHandler(RedefineExtnameHandler.get());
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
FPContractHandler.reset(new PragmaFPContractHandler());
|
2011-02-14 09:42:35 +08:00
|
|
|
PP.AddPragmaHandler("STDC", FPContractHandler.get());
|
2011-02-14 09:42:53 +08:00
|
|
|
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().OpenCL) {
|
2012-10-04 10:36:51 +08:00
|
|
|
OpenCLExtensionHandler.reset(new PragmaOpenCLExtensionHandler());
|
2011-02-14 09:42:53 +08:00
|
|
|
PP.AddPragmaHandler("OPENCL", OpenCLExtensionHandler.get());
|
|
|
|
|
|
|
|
PP.AddPragmaHandler("OPENCL", FPContractHandler.get());
|
|
|
|
}
|
2013-03-22 14:34:35 +08:00
|
|
|
if (getLangOpts().OpenMP)
|
|
|
|
OpenMPHandler.reset(new PragmaOpenMPHandler());
|
|
|
|
else
|
|
|
|
OpenMPHandler.reset(new PragmaNoOpenMPHandler());
|
|
|
|
PP.AddPragmaHandler(OpenMPHandler.get());
|
2012-06-20 08:34:58 +08:00
|
|
|
|
2013-05-07 05:02:12 +08:00
|
|
|
if (getLangOpts().MicrosoftExt) {
|
2013-05-08 21:44:39 +08:00
|
|
|
MSCommentHandler.reset(new PragmaCommentHandler(actions));
|
2013-05-07 05:02:12 +08:00
|
|
|
PP.AddPragmaHandler(MSCommentHandler.get());
|
2013-06-04 10:07:14 +08:00
|
|
|
MSDetectMismatchHandler.reset(new PragmaDetectMismatchHandler(actions));
|
|
|
|
PP.AddPragmaHandler(MSDetectMismatchHandler.get());
|
2013-05-07 05:02:12 +08:00
|
|
|
}
|
|
|
|
|
2012-06-20 09:06:08 +08:00
|
|
|
CommentSemaHandler.reset(new ActionCommentHandler(actions));
|
|
|
|
PP.addCommentHandler(CommentSemaHandler.get());
|
2012-06-20 08:34:58 +08:00
|
|
|
|
2010-08-25 03:08:16 +08:00
|
|
|
PP.setCodeCompletionHandler(*this);
|
2006-08-06 06:46:42 +08:00
|
|
|
}
|
|
|
|
|
2008-11-22 08:59:29 +08:00
|
|
|
DiagnosticBuilder Parser::Diag(SourceLocation Loc, unsigned DiagID) {
|
2010-11-19 04:06:41 +08:00
|
|
|
return Diags.Report(Loc, DiagID);
|
2008-11-18 15:48:38 +08:00
|
|
|
}
|
|
|
|
|
2008-11-22 08:59:29 +08:00
|
|
|
DiagnosticBuilder Parser::Diag(const Token &Tok, unsigned DiagID) {
|
2008-11-18 15:48:38 +08:00
|
|
|
return Diag(Tok.getLocation(), DiagID);
|
2006-07-31 09:59:18 +08:00
|
|
|
}
|
|
|
|
|
Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:
- Insert some new code (a text string) at a particular source
location
- Remove the code within a given range
- Replace the code within a given range with some new code (a text
string)
Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:
template<int I> class B { };
B<1000 >> 2> *b1;
we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:
test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
B<1000 >> 2> *b1;
^
( )
Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.
In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.
This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).
llvm-svn: 65570
2009-02-27 05:00:50 +08:00
|
|
|
/// \brief Emits a diagnostic suggesting parentheses surrounding a
|
|
|
|
/// given range.
|
|
|
|
///
|
|
|
|
/// \param Loc The location where we'll emit the diagnostic.
|
2012-08-24 01:58:28 +08:00
|
|
|
/// \param DK The kind of diagnostic to emit.
|
Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:
- Insert some new code (a text string) at a particular source
location
- Remove the code within a given range
- Replace the code within a given range with some new code (a text
string)
Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:
template<int I> class B { };
B<1000 >> 2> *b1;
we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:
test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
B<1000 >> 2> *b1;
^
( )
Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.
In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.
This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).
llvm-svn: 65570
2009-02-27 05:00:50 +08:00
|
|
|
/// \param ParenRange Source range enclosing code that should be parenthesized.
|
|
|
|
void Parser::SuggestParentheses(SourceLocation Loc, unsigned DK,
|
|
|
|
SourceRange ParenRange) {
|
2009-02-28 01:53:17 +08:00
|
|
|
SourceLocation EndLoc = PP.getLocForEndOfToken(ParenRange.getEnd());
|
|
|
|
if (!ParenRange.getEnd().isFileID() || EndLoc.isInvalid()) {
|
Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:
- Insert some new code (a text string) at a particular source
location
- Remove the code within a given range
- Replace the code within a given range with some new code (a text
string)
Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:
template<int I> class B { };
B<1000 >> 2> *b1;
we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:
test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
B<1000 >> 2> *b1;
^
( )
Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.
In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.
This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).
llvm-svn: 65570
2009-02-27 05:00:50 +08:00
|
|
|
// We can't display the parentheses, so just dig the
|
|
|
|
// warning/error and return.
|
|
|
|
Diag(Loc, DK);
|
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
Diag(Loc, DK)
|
2010-04-01 01:46:05 +08:00
|
|
|
<< FixItHint::CreateInsertion(ParenRange.getBegin(), "(")
|
|
|
|
<< FixItHint::CreateInsertion(EndLoc, ")");
|
Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:
- Insert some new code (a text string) at a particular source
location
- Remove the code within a given range
- Replace the code within a given range with some new code (a text
string)
Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:
template<int I> class B { };
B<1000 >> 2> *b1;
we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:
test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
B<1000 >> 2> *b1;
^
( )
Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.
In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.
This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).
llvm-svn: 65570
2009-02-27 05:00:50 +08:00
|
|
|
}
|
|
|
|
|
2010-09-08 02:31:03 +08:00
|
|
|
static bool IsCommonTypo(tok::TokenKind ExpectedTok, const Token &Tok) {
|
|
|
|
switch (ExpectedTok) {
|
2012-09-18 08:52:05 +08:00
|
|
|
case tok::semi:
|
|
|
|
return Tok.is(tok::colon) || Tok.is(tok::comma); // : or , for ;
|
2010-09-08 02:31:03 +08:00
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-13 03:26:13 +08:00
|
|
|
/// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
|
|
|
|
/// input. If so, it is consumed and false is returned.
|
|
|
|
///
|
|
|
|
/// If the input is malformed, this emits the specified diagnostic. Next, if
|
|
|
|
/// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is
|
|
|
|
/// returned.
|
|
|
|
bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID,
|
2006-08-15 11:41:14 +08:00
|
|
|
const char *Msg, tok::TokenKind SkipToTok) {
|
2010-05-25 13:58:43 +08:00
|
|
|
if (Tok.is(ExpectedTok) || Tok.is(tok::code_completion)) {
|
2006-08-15 12:10:31 +08:00
|
|
|
ConsumeAnyToken();
|
2006-08-13 03:26:13 +08:00
|
|
|
return false;
|
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2010-09-08 02:31:03 +08:00
|
|
|
// Detect common single-character typos and resume.
|
|
|
|
if (IsCommonTypo(ExpectedTok, Tok)) {
|
|
|
|
SourceLocation Loc = Tok.getLocation();
|
|
|
|
Diag(Loc, DiagID)
|
|
|
|
<< Msg
|
|
|
|
<< FixItHint::CreateReplacement(SourceRange(Loc),
|
|
|
|
getTokenSimpleSpelling(ExpectedTok));
|
|
|
|
ConsumeAnyToken();
|
|
|
|
|
|
|
|
// Pretend there wasn't a problem.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:
- Insert some new code (a text string) at a particular source
location
- Remove the code within a given range
- Replace the code within a given range with some new code (a text
string)
Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:
template<int I> class B { };
B<1000 >> 2> *b1;
we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:
test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
B<1000 >> 2> *b1;
^
( )
Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.
In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.
This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).
llvm-svn: 65570
2009-02-27 05:00:50 +08:00
|
|
|
const char *Spelling = 0;
|
2009-02-28 01:53:17 +08:00
|
|
|
SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation);
|
2009-09-09 23:08:12 +08:00
|
|
|
if (EndLoc.isValid() &&
|
2009-02-28 01:53:17 +08:00
|
|
|
(Spelling = tok::getTokenSimpleSpelling(ExpectedTok))) {
|
Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:
- Insert some new code (a text string) at a particular source
location
- Remove the code within a given range
- Replace the code within a given range with some new code (a text
string)
Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:
template<int I> class B { };
B<1000 >> 2> *b1;
we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:
test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
B<1000 >> 2> *b1;
^
( )
Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.
In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.
This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).
llvm-svn: 65570
2009-02-27 05:00:50 +08:00
|
|
|
// Show what code to insert to fix this problem.
|
2009-09-09 23:08:12 +08:00
|
|
|
Diag(EndLoc, DiagID)
|
Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:
- Insert some new code (a text string) at a particular source
location
- Remove the code within a given range
- Replace the code within a given range with some new code (a text
string)
Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:
template<int I> class B { };
B<1000 >> 2> *b1;
we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:
test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
B<1000 >> 2> *b1;
^
( )
Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.
In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.
This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).
llvm-svn: 65570
2009-02-27 05:00:50 +08:00
|
|
|
<< Msg
|
2010-04-01 01:46:05 +08:00
|
|
|
<< FixItHint::CreateInsertion(EndLoc, Spelling);
|
Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:
- Insert some new code (a text string) at a particular source
location
- Remove the code within a given range
- Replace the code within a given range with some new code (a text
string)
Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:
template<int I> class B { };
B<1000 >> 2> *b1;
we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:
test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
B<1000 >> 2> *b1;
^
( )
Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.
In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.
This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).
llvm-svn: 65570
2009-02-27 05:00:50 +08:00
|
|
|
} else
|
|
|
|
Diag(Tok, DiagID) << Msg;
|
|
|
|
|
2006-08-13 03:26:13 +08:00
|
|
|
if (SkipToTok != tok::unknown)
|
|
|
|
SkipUntil(SkipToTok);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-07 23:23:11 +08:00
|
|
|
bool Parser::ExpectAndConsumeSemi(unsigned DiagID) {
|
|
|
|
if (Tok.is(tok::semi) || Tok.is(tok::code_completion)) {
|
2012-05-02 22:34:16 +08:00
|
|
|
ConsumeToken();
|
2010-09-07 23:23:11 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Tok.is(tok::r_paren) || Tok.is(tok::r_square)) &&
|
|
|
|
NextToken().is(tok::semi)) {
|
|
|
|
Diag(Tok, diag::err_extraneous_token_before_semi)
|
|
|
|
<< PP.getSpelling(Tok)
|
|
|
|
<< FixItHint::CreateRemoval(Tok.getLocation());
|
|
|
|
ConsumeAnyToken(); // The ')' or ']'.
|
|
|
|
ConsumeToken(); // The ';'.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ExpectAndConsume(tok::semi, DiagID);
|
|
|
|
}
|
|
|
|
|
2012-07-23 13:45:25 +08:00
|
|
|
void Parser::ConsumeExtraSemi(ExtraSemiKind Kind, unsigned TST) {
|
2012-05-17 03:04:59 +08:00
|
|
|
if (!Tok.is(tok::semi)) return;
|
|
|
|
|
2012-07-23 13:45:25 +08:00
|
|
|
bool HadMultipleSemis = false;
|
2012-05-17 03:04:59 +08:00
|
|
|
SourceLocation StartLoc = Tok.getLocation();
|
|
|
|
SourceLocation EndLoc = Tok.getLocation();
|
|
|
|
ConsumeToken();
|
|
|
|
|
|
|
|
while ((Tok.is(tok::semi) && !Tok.isAtStartOfLine())) {
|
2012-07-23 13:45:25 +08:00
|
|
|
HadMultipleSemis = true;
|
2012-05-17 03:04:59 +08:00
|
|
|
EndLoc = Tok.getLocation();
|
|
|
|
ConsumeToken();
|
|
|
|
}
|
|
|
|
|
2012-07-23 13:45:25 +08:00
|
|
|
// C++11 allows extra semicolons at namespace scope, but not in any of the
|
|
|
|
// other contexts.
|
|
|
|
if (Kind == OutsideFunction && getLangOpts().CPlusPlus) {
|
2013-01-02 19:42:31 +08:00
|
|
|
if (getLangOpts().CPlusPlus11)
|
2012-07-23 13:45:25 +08:00
|
|
|
Diag(StartLoc, diag::warn_cxx98_compat_top_level_semi)
|
|
|
|
<< FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc));
|
|
|
|
else
|
|
|
|
Diag(StartLoc, diag::ext_extra_semi_cxx11)
|
|
|
|
<< FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc));
|
2012-05-17 03:04:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-23 13:45:25 +08:00
|
|
|
if (Kind != AfterMemberFunctionDefinition || HadMultipleSemis)
|
|
|
|
Diag(StartLoc, diag::ext_extra_semi)
|
|
|
|
<< Kind << DeclSpec::getSpecifierName((DeclSpec::TST)TST)
|
|
|
|
<< FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc));
|
|
|
|
else
|
|
|
|
// A single semicolon is valid after a member function definition.
|
|
|
|
Diag(StartLoc, diag::warn_extra_semi_after_mem_fn_def)
|
|
|
|
<< FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc));
|
2012-05-17 03:04:59 +08:00
|
|
|
}
|
|
|
|
|
2006-08-07 05:55:29 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Error recovery.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// SkipUntil - Read tokens until we get to the specified token, then consume
|
2007-07-25 01:03:04 +08:00
|
|
|
/// it (unless DontConsume is true). Because we cannot guarantee that the
|
2006-08-07 05:55:29 +08:00
|
|
|
/// token will ever occur, this skips to the next token, or to some likely
|
|
|
|
/// good stopping point. If StopAtSemi is true, skipping will stop at a ';'
|
|
|
|
/// character.
|
2008-06-20 03:28:49 +08:00
|
|
|
///
|
2006-08-07 05:55:29 +08:00
|
|
|
/// If SkipUntil finds the specified token, it returns true, otherwise it
|
2008-06-20 03:28:49 +08:00
|
|
|
/// returns false.
|
2012-04-10 00:37:11 +08:00
|
|
|
bool Parser::SkipUntil(ArrayRef<tok::TokenKind> Toks, bool StopAtSemi,
|
|
|
|
bool DontConsume, bool StopAtCodeCompletion) {
|
2006-08-11 14:40:25 +08:00
|
|
|
// We always want this function to skip at least one token if the first token
|
|
|
|
// isn't T and if not at EOF.
|
|
|
|
bool isFirstTokenSkipped = true;
|
2006-08-07 05:55:29 +08:00
|
|
|
while (1) {
|
2007-04-28 03:12:15 +08:00
|
|
|
// If we found one of the tokens, stop and return true.
|
2012-04-10 00:37:11 +08:00
|
|
|
for (unsigned i = 0, NumToks = Toks.size(); i != NumToks; ++i) {
|
2007-10-10 01:23:58 +08:00
|
|
|
if (Tok.is(Toks[i])) {
|
2007-04-28 03:12:15 +08:00
|
|
|
if (DontConsume) {
|
|
|
|
// Noop, don't consume the token.
|
|
|
|
} else {
|
|
|
|
ConsumeAnyToken();
|
|
|
|
}
|
|
|
|
return true;
|
2006-08-07 05:55:29 +08:00
|
|
|
}
|
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2013-07-25 10:11:20 +08:00
|
|
|
// Important special case: The caller has given up and just wants us to
|
|
|
|
// skip the rest of the file. Do this without recursing, since we can
|
|
|
|
// get here precisely because the caller detected too much recursion.
|
|
|
|
if (Toks.size() == 1 && Toks[0] == tok::eof && !StopAtSemi &&
|
|
|
|
!StopAtCodeCompletion) {
|
|
|
|
while (Tok.getKind() != tok::eof)
|
|
|
|
ConsumeAnyToken();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-08-07 05:55:29 +08:00
|
|
|
switch (Tok.getKind()) {
|
|
|
|
case tok::eof:
|
|
|
|
// Ran out of tokens.
|
|
|
|
return false;
|
2010-05-25 13:58:43 +08:00
|
|
|
|
|
|
|
case tok::code_completion:
|
2011-01-04 03:44:02 +08:00
|
|
|
if (!StopAtCodeCompletion)
|
|
|
|
ConsumeToken();
|
2010-05-25 13:58:43 +08:00
|
|
|
return false;
|
|
|
|
|
2006-08-07 05:55:29 +08:00
|
|
|
case tok::l_paren:
|
|
|
|
// Recursively skip properly-nested parens.
|
|
|
|
ConsumeParen();
|
2011-01-04 03:44:02 +08:00
|
|
|
SkipUntil(tok::r_paren, false, false, StopAtCodeCompletion);
|
2006-08-07 05:55:29 +08:00
|
|
|
break;
|
|
|
|
case tok::l_square:
|
|
|
|
// Recursively skip properly-nested square brackets.
|
|
|
|
ConsumeBracket();
|
2011-01-04 03:44:02 +08:00
|
|
|
SkipUntil(tok::r_square, false, false, StopAtCodeCompletion);
|
2006-08-07 05:55:29 +08:00
|
|
|
break;
|
|
|
|
case tok::l_brace:
|
|
|
|
// Recursively skip properly-nested braces.
|
|
|
|
ConsumeBrace();
|
2011-01-04 03:44:02 +08:00
|
|
|
SkipUntil(tok::r_brace, false, false, StopAtCodeCompletion);
|
2006-08-07 05:55:29 +08:00
|
|
|
break;
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-08-07 05:55:29 +08:00
|
|
|
// Okay, we found a ']' or '}' or ')', which we think should be balanced.
|
|
|
|
// Since the user wasn't looking for this token (if they were, it would
|
|
|
|
// already be handled), this isn't balanced. If there is a LHS token at a
|
|
|
|
// higher level, we will assume that this matches the unbalanced token
|
|
|
|
// and return it. Otherwise, this is a spurious RHS token, which we skip.
|
|
|
|
case tok::r_paren:
|
2006-08-11 14:40:25 +08:00
|
|
|
if (ParenCount && !isFirstTokenSkipped)
|
|
|
|
return false; // Matches something.
|
2006-08-07 05:55:29 +08:00
|
|
|
ConsumeParen();
|
|
|
|
break;
|
|
|
|
case tok::r_square:
|
2006-08-11 14:40:25 +08:00
|
|
|
if (BracketCount && !isFirstTokenSkipped)
|
|
|
|
return false; // Matches something.
|
2006-08-07 05:55:29 +08:00
|
|
|
ConsumeBracket();
|
|
|
|
break;
|
|
|
|
case tok::r_brace:
|
2006-08-11 14:40:25 +08:00
|
|
|
if (BraceCount && !isFirstTokenSkipped)
|
|
|
|
return false; // Matches something.
|
2006-08-07 05:55:29 +08:00
|
|
|
ConsumeBrace();
|
|
|
|
break;
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-08-07 05:55:29 +08:00
|
|
|
case tok::string_literal:
|
2006-10-06 13:22:26 +08:00
|
|
|
case tok::wide_string_literal:
|
2011-07-27 13:40:30 +08:00
|
|
|
case tok::utf8_string_literal:
|
|
|
|
case tok::utf16_string_literal:
|
|
|
|
case tok::utf32_string_literal:
|
2006-08-07 05:55:29 +08:00
|
|
|
ConsumeStringToken();
|
|
|
|
break;
|
2011-02-23 08:11:21 +08:00
|
|
|
|
2006-08-07 05:55:29 +08:00
|
|
|
case tok::semi:
|
|
|
|
if (StopAtSemi)
|
|
|
|
return false;
|
|
|
|
// FALL THROUGH.
|
|
|
|
default:
|
|
|
|
// Skip this token.
|
|
|
|
ConsumeToken();
|
|
|
|
break;
|
|
|
|
}
|
2006-08-11 14:40:25 +08:00
|
|
|
isFirstTokenSkipped = false;
|
2008-06-20 03:28:49 +08:00
|
|
|
}
|
2006-08-07 05:55:29 +08:00
|
|
|
}
|
|
|
|
|
2006-08-14 08:15:05 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Scope manipulation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// EnterScope - Start a new scope.
|
2006-11-06 07:47:55 +08:00
|
|
|
void Parser::EnterScope(unsigned ScopeFlags) {
|
2007-07-15 08:04:39 +08:00
|
|
|
if (NumCachedScopes) {
|
|
|
|
Scope *N = ScopeCache[--NumCachedScopes];
|
2010-07-03 01:43:08 +08:00
|
|
|
N->Init(getCurScope(), ScopeFlags);
|
|
|
|
Actions.CurScope = N;
|
2006-11-06 08:22:42 +08:00
|
|
|
} else {
|
2010-11-19 08:19:12 +08:00
|
|
|
Actions.CurScope = new Scope(getCurScope(), ScopeFlags, Diags);
|
2006-11-06 08:22:42 +08:00
|
|
|
}
|
2006-08-14 08:15:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ExitScope - Pop a scope off the scope stack.
|
|
|
|
void Parser::ExitScope() {
|
2010-07-03 01:43:08 +08:00
|
|
|
assert(getCurScope() && "Scope imbalance!");
|
2006-08-14 08:15:05 +08:00
|
|
|
|
2007-10-10 04:37:18 +08:00
|
|
|
// Inform the actions module that this scope is going away if there are any
|
|
|
|
// decls in it.
|
2010-07-03 01:43:08 +08:00
|
|
|
if (!getCurScope()->decl_empty())
|
|
|
|
Actions.ActOnPopScope(Tok.getLocation(), getCurScope());
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2010-07-03 01:43:08 +08:00
|
|
|
Scope *OldScope = getCurScope();
|
|
|
|
Actions.CurScope = OldScope->getParent();
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2007-07-15 08:04:39 +08:00
|
|
|
if (NumCachedScopes == ScopeCacheSize)
|
|
|
|
delete OldScope;
|
2006-11-06 08:22:42 +08:00
|
|
|
else
|
2007-07-15 08:04:39 +08:00
|
|
|
ScopeCache[NumCachedScopes++] = OldScope;
|
2006-08-14 08:15:05 +08:00
|
|
|
}
|
|
|
|
|
2011-06-12 01:19:42 +08:00
|
|
|
/// Set the flags for the current scope to ScopeFlags. If ManageFlags is false,
|
|
|
|
/// this object does nothing.
|
|
|
|
Parser::ParseScopeFlags::ParseScopeFlags(Parser *Self, unsigned ScopeFlags,
|
|
|
|
bool ManageFlags)
|
|
|
|
: CurScope(ManageFlags ? Self->getCurScope() : 0) {
|
|
|
|
if (CurScope) {
|
|
|
|
OldFlags = CurScope->getFlags();
|
|
|
|
CurScope->setFlags(ScopeFlags);
|
|
|
|
}
|
|
|
|
}
|
2006-08-14 08:15:05 +08:00
|
|
|
|
2011-06-12 01:19:42 +08:00
|
|
|
/// Restore the flags for the current scope to what they were before this
|
|
|
|
/// object overrode them.
|
|
|
|
Parser::ParseScopeFlags::~ParseScopeFlags() {
|
|
|
|
if (CurScope)
|
|
|
|
CurScope->setFlags(OldFlags);
|
|
|
|
}
|
2006-08-14 08:15:05 +08:00
|
|
|
|
|
|
|
|
2006-07-31 13:09:04 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// C99 6.9: External Definitions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2006-07-31 09:59:18 +08:00
|
|
|
|
2006-11-06 08:22:42 +08:00
|
|
|
Parser::~Parser() {
|
|
|
|
// If we still have scopes active, delete the scope tree.
|
2010-07-03 01:43:08 +08:00
|
|
|
delete getCurScope();
|
|
|
|
Actions.CurScope = 0;
|
|
|
|
|
2006-11-06 08:22:42 +08:00
|
|
|
// Free the scope cache.
|
2007-07-15 08:04:39 +08:00
|
|
|
for (unsigned i = 0, e = NumCachedScopes; i != e; ++i)
|
|
|
|
delete ScopeCache[i];
|
2008-10-05 03:21:03 +08:00
|
|
|
|
|
|
|
// Remove the pragma handlers we installed.
|
2010-08-01 03:17:07 +08:00
|
|
|
PP.RemovePragmaHandler(AlignHandler.get());
|
|
|
|
AlignHandler.reset();
|
2010-08-05 14:57:20 +08:00
|
|
|
PP.RemovePragmaHandler("GCC", GCCVisibilityHandler.get());
|
|
|
|
GCCVisibilityHandler.reset();
|
2010-07-13 17:07:17 +08:00
|
|
|
PP.RemovePragmaHandler(OptionsHandler.get());
|
2010-05-27 07:29:06 +08:00
|
|
|
OptionsHandler.reset();
|
2010-07-13 17:07:17 +08:00
|
|
|
PP.RemovePragmaHandler(PackHandler.get());
|
2009-03-24 06:28:25 +08:00
|
|
|
PackHandler.reset();
|
2011-04-26 02:49:15 +08:00
|
|
|
PP.RemovePragmaHandler(MSStructHandler.get());
|
|
|
|
MSStructHandler.reset();
|
2010-07-13 17:07:17 +08:00
|
|
|
PP.RemovePragmaHandler(UnusedHandler.get());
|
2009-03-24 06:28:25 +08:00
|
|
|
UnusedHandler.reset();
|
2010-07-13 17:07:17 +08:00
|
|
|
PP.RemovePragmaHandler(WeakHandler.get());
|
2009-06-05 08:49:58 +08:00
|
|
|
WeakHandler.reset();
|
2012-02-19 00:12:34 +08:00
|
|
|
PP.RemovePragmaHandler(RedefineExtnameHandler.get());
|
|
|
|
RedefineExtnameHandler.reset();
|
2011-02-14 09:42:53 +08:00
|
|
|
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().OpenCL) {
|
2011-02-14 09:42:53 +08:00
|
|
|
PP.RemovePragmaHandler("OPENCL", OpenCLExtensionHandler.get());
|
|
|
|
OpenCLExtensionHandler.reset();
|
|
|
|
PP.RemovePragmaHandler("OPENCL", FPContractHandler.get());
|
|
|
|
}
|
2013-03-22 14:34:35 +08:00
|
|
|
PP.RemovePragmaHandler(OpenMPHandler.get());
|
|
|
|
OpenMPHandler.reset();
|
2011-02-14 09:42:53 +08:00
|
|
|
|
2013-05-07 05:02:12 +08:00
|
|
|
if (getLangOpts().MicrosoftExt) {
|
|
|
|
PP.RemovePragmaHandler(MSCommentHandler.get());
|
|
|
|
MSCommentHandler.reset();
|
2013-06-04 10:07:14 +08:00
|
|
|
PP.RemovePragmaHandler(MSDetectMismatchHandler.get());
|
|
|
|
MSDetectMismatchHandler.reset();
|
2013-05-07 05:02:12 +08:00
|
|
|
}
|
|
|
|
|
2011-02-14 09:42:35 +08:00
|
|
|
PP.RemovePragmaHandler("STDC", FPContractHandler.get());
|
|
|
|
FPContractHandler.reset();
|
2012-06-20 08:34:58 +08:00
|
|
|
|
2012-06-20 09:06:08 +08:00
|
|
|
PP.removeCommentHandler(CommentSemaHandler.get());
|
2012-06-20 08:34:58 +08:00
|
|
|
|
2010-08-25 03:08:16 +08:00
|
|
|
PP.clearCodeCompletionHandler();
|
2012-04-14 20:14:03 +08:00
|
|
|
|
|
|
|
assert(TemplateIds.empty() && "Still alive TemplateIdAnnotations around?");
|
2006-11-06 08:22:42 +08:00
|
|
|
}
|
|
|
|
|
2006-08-17 15:04:37 +08:00
|
|
|
/// Initialize - Warm up the parser.
|
|
|
|
///
|
|
|
|
void Parser::Initialize() {
|
2007-08-26 14:24:45 +08:00
|
|
|
// Create the translation unit scope. Install it as the current scope.
|
2010-07-03 01:43:08 +08:00
|
|
|
assert(getCurScope() == 0 && "A scope is already active?");
|
2007-08-26 14:24:45 +08:00
|
|
|
EnterScope(Scope::DeclScope);
|
2010-08-26 02:07:12 +08:00
|
|
|
Actions.ActOnTranslationUnitScope(getCurScope());
|
|
|
|
|
2007-08-30 06:54:08 +08:00
|
|
|
// Initialization for Objective-C context sensitive keywords recognition.
|
2008-01-08 03:49:32 +08:00
|
|
|
// Referenced in Parser::ParseObjCTypeQualifierList.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC1) {
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCTypeQuals[objc_in] = &PP.getIdentifierTable().get("in");
|
|
|
|
ObjCTypeQuals[objc_out] = &PP.getIdentifierTable().get("out");
|
|
|
|
ObjCTypeQuals[objc_inout] = &PP.getIdentifierTable().get("inout");
|
|
|
|
ObjCTypeQuals[objc_oneway] = &PP.getIdentifierTable().get("oneway");
|
|
|
|
ObjCTypeQuals[objc_bycopy] = &PP.getIdentifierTable().get("bycopy");
|
|
|
|
ObjCTypeQuals[objc_byref] = &PP.getIdentifierTable().get("byref");
|
2007-08-30 06:54:08 +08:00
|
|
|
}
|
2008-08-15 06:04:54 +08:00
|
|
|
|
2011-09-08 09:46:34 +08:00
|
|
|
Ident_instancetype = 0;
|
2011-01-20 11:47:08 +08:00
|
|
|
Ident_final = 0;
|
|
|
|
Ident_override = 0;
|
2011-01-17 07:56:42 +08:00
|
|
|
|
2008-08-15 06:04:54 +08:00
|
|
|
Ident_super = &PP.getIdentifierTable().get("super");
|
2010-02-05 08:12:22 +08:00
|
|
|
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().AltiVec) {
|
2010-02-05 08:12:22 +08:00
|
|
|
Ident_vector = &PP.getIdentifierTable().get("vector");
|
|
|
|
Ident_pixel = &PP.getIdentifierTable().get("pixel");
|
2013-07-04 04:54:09 +08:00
|
|
|
Ident_bool = &PP.getIdentifierTable().get("bool");
|
2010-02-05 08:12:22 +08:00
|
|
|
}
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
|
|
|
|
Ident_introduced = 0;
|
|
|
|
Ident_deprecated = 0;
|
|
|
|
Ident_obsoleted = 0;
|
2011-03-26 11:35:55 +08:00
|
|
|
Ident_unavailable = 0;
|
2011-04-28 09:08:34 +08:00
|
|
|
|
2011-10-21 11:57:52 +08:00
|
|
|
Ident__except = 0;
|
|
|
|
|
2011-04-28 09:08:34 +08:00
|
|
|
Ident__exception_code = Ident__exception_info = Ident__abnormal_termination = 0;
|
|
|
|
Ident___exception_code = Ident___exception_info = Ident___abnormal_termination = 0;
|
|
|
|
Ident_GetExceptionCode = Ident_GetExceptionInfo = Ident_AbnormalTermination = 0;
|
|
|
|
|
2012-03-11 15:00:24 +08:00
|
|
|
if(getLangOpts().Borland) {
|
2011-04-28 09:08:34 +08:00
|
|
|
Ident__exception_info = PP.getIdentifierInfo("_exception_info");
|
|
|
|
Ident___exception_info = PP.getIdentifierInfo("__exception_info");
|
|
|
|
Ident_GetExceptionInfo = PP.getIdentifierInfo("GetExceptionInformation");
|
|
|
|
Ident__exception_code = PP.getIdentifierInfo("_exception_code");
|
|
|
|
Ident___exception_code = PP.getIdentifierInfo("__exception_code");
|
|
|
|
Ident_GetExceptionCode = PP.getIdentifierInfo("GetExceptionCode");
|
|
|
|
Ident__abnormal_termination = PP.getIdentifierInfo("_abnormal_termination");
|
|
|
|
Ident___abnormal_termination = PP.getIdentifierInfo("__abnormal_termination");
|
|
|
|
Ident_AbnormalTermination = PP.getIdentifierInfo("AbnormalTermination");
|
|
|
|
|
|
|
|
PP.SetPoisonReason(Ident__exception_code,diag::err_seh___except_block);
|
|
|
|
PP.SetPoisonReason(Ident___exception_code,diag::err_seh___except_block);
|
|
|
|
PP.SetPoisonReason(Ident_GetExceptionCode,diag::err_seh___except_block);
|
|
|
|
PP.SetPoisonReason(Ident__exception_info,diag::err_seh___except_filter);
|
|
|
|
PP.SetPoisonReason(Ident___exception_info,diag::err_seh___except_filter);
|
|
|
|
PP.SetPoisonReason(Ident_GetExceptionInfo,diag::err_seh___except_filter);
|
|
|
|
PP.SetPoisonReason(Ident__abnormal_termination,diag::err_seh___finally_block);
|
|
|
|
PP.SetPoisonReason(Ident___abnormal_termination,diag::err_seh___finally_block);
|
|
|
|
PP.SetPoisonReason(Ident_AbnormalTermination,diag::err_seh___finally_block);
|
|
|
|
}
|
2012-11-06 07:58:27 +08:00
|
|
|
|
|
|
|
Actions.Initialize();
|
|
|
|
|
|
|
|
// Prime the lexer look-ahead.
|
|
|
|
ConsumeToken();
|
2006-08-17 15:04:37 +08:00
|
|
|
}
|
|
|
|
|
2012-04-14 20:14:03 +08:00
|
|
|
namespace {
|
|
|
|
/// \brief RAIIObject to destroy the contents of a SmallVector of
|
|
|
|
/// TemplateIdAnnotation pointers and clear the vector.
|
|
|
|
class DestroyTemplateIdAnnotationsRAIIObj {
|
|
|
|
SmallVectorImpl<TemplateIdAnnotation *> &Container;
|
|
|
|
public:
|
|
|
|
DestroyTemplateIdAnnotationsRAIIObj(SmallVectorImpl<TemplateIdAnnotation *>
|
|
|
|
&Container)
|
|
|
|
: Container(Container) {}
|
|
|
|
|
|
|
|
~DestroyTemplateIdAnnotationsRAIIObj() {
|
|
|
|
for (SmallVectorImpl<TemplateIdAnnotation *>::iterator I =
|
|
|
|
Container.begin(), E = Container.end();
|
|
|
|
I != E; ++I)
|
|
|
|
(*I)->Destroy();
|
|
|
|
Container.clear();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2006-08-17 15:04:37 +08:00
|
|
|
/// ParseTopLevelDecl - Parse one top-level declaration, return whatever the
|
|
|
|
/// action tells us to. This returns true if the EOF was encountered.
|
2009-03-30 00:50:03 +08:00
|
|
|
bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result) {
|
2012-04-14 20:14:03 +08:00
|
|
|
DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(TemplateIds);
|
2011-01-18 02:58:44 +08:00
|
|
|
|
2012-03-16 18:40:17 +08:00
|
|
|
// Skip over the EOF token, flagging end of previous input for incremental
|
|
|
|
// processing
|
|
|
|
if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
|
|
|
|
ConsumeToken();
|
|
|
|
|
2011-01-18 02:58:44 +08:00
|
|
|
while (Tok.is(tok::annot_pragma_unused))
|
|
|
|
HandlePragmaUnused();
|
|
|
|
|
2009-03-30 00:50:03 +08:00
|
|
|
Result = DeclGroupPtrTy();
|
2008-08-23 11:19:52 +08:00
|
|
|
if (Tok.is(tok::eof)) {
|
2011-04-23 06:18:13 +08:00
|
|
|
// Late template parsing can begin.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().DelayedTemplateParsing)
|
2011-04-23 06:18:13 +08:00
|
|
|
Actions.SetLateTemplateParser(LateTemplateParserCallback, this);
|
2012-03-16 18:40:17 +08:00
|
|
|
if (!PP.isIncrementalProcessingEnabled())
|
|
|
|
Actions.ActOnEndOfTranslationUnit();
|
|
|
|
//else don't tell Sema that we ended parsing: more input might come.
|
2011-04-23 06:18:13 +08:00
|
|
|
|
2008-08-23 11:19:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2011-03-24 19:26:52 +08:00
|
|
|
ParsedAttributesWithRange attrs(AttrFactory);
|
2013-01-02 20:01:23 +08:00
|
|
|
MaybeParseCXX11Attributes(attrs);
|
2010-12-24 10:08:15 +08:00
|
|
|
MaybeParseMicrosoftAttributes(attrs);
|
2012-03-16 18:40:17 +08:00
|
|
|
|
2010-12-24 10:08:15 +08:00
|
|
|
Result = ParseExternalDeclaration(attrs);
|
2006-08-17 15:04:37 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-07-31 09:59:18 +08:00
|
|
|
/// ParseExternalDeclaration:
|
2008-12-09 05:59:01 +08:00
|
|
|
///
|
2008-11-22 00:10:08 +08:00
|
|
|
/// external-declaration: [C99 6.9], declaration: [C++ dcl.dcl]
|
2007-08-11 04:57:02 +08:00
|
|
|
/// function-definition
|
|
|
|
/// declaration
|
2006-08-15 11:41:14 +08:00
|
|
|
/// [GNU] asm-definition
|
2007-08-11 04:57:02 +08:00
|
|
|
/// [GNU] __extension__ external-declaration
|
2006-11-05 10:05:37 +08:00
|
|
|
/// [OBJC] objc-class-definition
|
|
|
|
/// [OBJC] objc-class-declaration
|
|
|
|
/// [OBJC] objc-alias-declaration
|
|
|
|
/// [OBJC] objc-protocol-definition
|
|
|
|
/// [OBJC] objc-method-definition
|
|
|
|
/// [OBJC] @end
|
2008-11-22 00:10:08 +08:00
|
|
|
/// [C++] linkage-specification
|
2006-08-15 11:41:14 +08:00
|
|
|
/// [GNU] asm-definition:
|
|
|
|
/// simple-asm-expr ';'
|
2013-02-21 03:22:51 +08:00
|
|
|
/// [C++11] empty-declaration
|
|
|
|
/// [C++11] attribute-declaration
|
2006-08-15 11:41:14 +08:00
|
|
|
///
|
2013-02-21 03:22:51 +08:00
|
|
|
/// [C++11] empty-declaration:
|
2009-08-24 20:17:54 +08:00
|
|
|
/// ';'
|
|
|
|
///
|
2009-09-04 14:33:52 +08:00
|
|
|
/// [C++0x/GNU] 'extern' 'template' declaration
|
2010-12-24 10:08:15 +08:00
|
|
|
Parser::DeclGroupPtrTy
|
|
|
|
Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
|
|
|
|
ParsingDeclSpec *DS) {
|
2012-04-14 20:14:03 +08:00
|
|
|
DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(TemplateIds);
|
2010-06-17 18:52:18 +08:00
|
|
|
ParenBraceBracketBalancer BalancerRAIIObj(*this);
|
2011-09-04 11:32:15 +08:00
|
|
|
|
|
|
|
if (PP.isCodeCompletionReached()) {
|
|
|
|
cutOffParsing();
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
}
|
|
|
|
|
2010-08-21 17:40:31 +08:00
|
|
|
Decl *SingleDecl = 0;
|
2006-07-31 09:59:18 +08:00
|
|
|
switch (Tok.getKind()) {
|
2012-01-26 10:02:57 +08:00
|
|
|
case tok::annot_pragma_vis:
|
|
|
|
HandlePragmaVisibility();
|
|
|
|
return DeclGroupPtrTy();
|
2012-02-24 07:47:16 +08:00
|
|
|
case tok::annot_pragma_pack:
|
|
|
|
HandlePragmaPack();
|
|
|
|
return DeclGroupPtrTy();
|
2012-10-04 10:36:51 +08:00
|
|
|
case tok::annot_pragma_msstruct:
|
|
|
|
HandlePragmaMSStruct();
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
case tok::annot_pragma_align:
|
|
|
|
HandlePragmaAlign();
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
case tok::annot_pragma_weak:
|
|
|
|
HandlePragmaWeak();
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
case tok::annot_pragma_weakalias:
|
|
|
|
HandlePragmaWeakAlias();
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
case tok::annot_pragma_redefine_extname:
|
|
|
|
HandlePragmaRedefineExtname();
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
case tok::annot_pragma_fp_contract:
|
|
|
|
HandlePragmaFPContract();
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
case tok::annot_pragma_opencl_extension:
|
|
|
|
HandlePragmaOpenCLExtension();
|
|
|
|
return DeclGroupPtrTy();
|
2013-03-22 14:34:35 +08:00
|
|
|
case tok::annot_pragma_openmp:
|
|
|
|
ParseOpenMPDeclarativeDirective();
|
|
|
|
return DeclGroupPtrTy();
|
2006-07-31 09:59:18 +08:00
|
|
|
case tok::semi:
|
2013-02-21 03:22:51 +08:00
|
|
|
// Either a C++11 empty-declaration or attribute-declaration.
|
2013-02-23 01:15:32 +08:00
|
|
|
SingleDecl = Actions.ActOnEmptyDeclaration(getCurScope(),
|
|
|
|
attrs.getList(),
|
|
|
|
Tok.getLocation());
|
2012-05-17 03:04:59 +08:00
|
|
|
ConsumeExtraSemi(OutsideFunction);
|
2013-02-23 01:15:32 +08:00
|
|
|
break;
|
2008-12-09 05:59:01 +08:00
|
|
|
case tok::r_brace:
|
2012-01-17 09:04:27 +08:00
|
|
|
Diag(Tok, diag::err_extraneous_closing_brace);
|
2008-12-09 05:59:01 +08:00
|
|
|
ConsumeBrace();
|
2009-03-30 00:50:03 +08:00
|
|
|
return DeclGroupPtrTy();
|
2008-12-09 05:59:01 +08:00
|
|
|
case tok::eof:
|
|
|
|
Diag(Tok, diag::err_expected_external_declaration);
|
2009-03-30 00:50:03 +08:00
|
|
|
return DeclGroupPtrTy();
|
2007-08-11 04:57:02 +08:00
|
|
|
case tok::kw___extension__: {
|
2008-10-20 14:45:43 +08:00
|
|
|
// __extension__ silences extension warnings in the subexpression.
|
|
|
|
ExtensionRAIIObject O(Diags); // Use RAII to do this.
|
2008-10-20 14:51:33 +08:00
|
|
|
ConsumeToken();
|
2010-12-24 10:08:15 +08:00
|
|
|
return ParseExternalDeclaration(attrs);
|
2007-08-11 04:57:02 +08:00
|
|
|
}
|
2008-02-08 08:33:21 +08:00
|
|
|
case tok::kw_asm: {
|
2010-12-24 10:08:15 +08:00
|
|
|
ProhibitAttributes(attrs);
|
2009-11-21 16:43:09 +08:00
|
|
|
|
2011-03-03 22:20:18 +08:00
|
|
|
SourceLocation StartLoc = Tok.getLocation();
|
|
|
|
SourceLocation EndLoc;
|
|
|
|
ExprResult Result(ParseSimpleAsm(&EndLoc));
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2008-02-08 08:23:11 +08:00
|
|
|
ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
|
|
|
|
"top-level asm block");
|
2008-02-08 08:33:21 +08:00
|
|
|
|
2009-03-30 00:50:03 +08:00
|
|
|
if (Result.isInvalid())
|
|
|
|
return DeclGroupPtrTy();
|
2011-03-03 22:20:18 +08:00
|
|
|
SingleDecl = Actions.ActOnFileScopeAsmDecl(Result.get(), StartLoc, EndLoc);
|
2009-03-30 00:50:03 +08:00
|
|
|
break;
|
2008-02-08 08:33:21 +08:00
|
|
|
}
|
2006-10-28 07:18:49 +08:00
|
|
|
case tok::at:
|
2011-08-28 04:50:59 +08:00
|
|
|
return ParseObjCAtDirectives();
|
2006-10-28 07:18:49 +08:00
|
|
|
case tok::minus:
|
|
|
|
case tok::plus:
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!getLangOpts().ObjC1) {
|
2009-03-30 00:50:03 +08:00
|
|
|
Diag(Tok, diag::err_expected_external_declaration);
|
|
|
|
ConsumeToken();
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
}
|
|
|
|
SingleDecl = ParseObjCMethodDefinition();
|
|
|
|
break;
|
2009-09-22 04:51:25 +08:00
|
|
|
case tok::code_completion:
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.CodeCompleteOrdinaryName(getCurScope(),
|
2012-02-08 00:50:53 +08:00
|
|
|
CurParsedObjCImpl? Sema::PCC_ObjCImplementation
|
2010-08-27 07:41:50 +08:00
|
|
|
: Sema::PCC_Namespace);
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
|
|
|
return DeclGroupPtrTy();
|
2008-12-30 11:27:21 +08:00
|
|
|
case tok::kw_using:
|
2007-08-25 14:57:03 +08:00
|
|
|
case tok::kw_namespace:
|
2006-11-19 10:31:38 +08:00
|
|
|
case tok::kw_typedef:
|
2008-12-02 07:54:00 +08:00
|
|
|
case tok::kw_template:
|
|
|
|
case tok::kw_export: // As in 'export template'
|
2009-03-12 00:27:10 +08:00
|
|
|
case tok::kw_static_assert:
|
2011-04-15 08:35:57 +08:00
|
|
|
case tok::kw__Static_assert:
|
2012-04-26 06:51:41 +08:00
|
|
|
// A function definition cannot start with any of these keywords.
|
fix a FIXME, providing accurate source range info for DeclStmt's. The end
of the range is now the ';' location. For something like this:
$ cat t2.c
#define bool int
void f(int x, int y) {
bool b = !x && y;
}
We used to produce:
$ clang-cc t2.c -ast-dump
typedef char *__builtin_va_list;
void f(int x, int y)
(CompoundStmt 0x2201f10 <t2.c:3:22, line:5:1>
(DeclStmt 0x2201ef0 <line:2:14> <----
0x2201a20 "int b =
(BinaryOperator 0x2201ed0 <line:4:10, col:16> 'int' '&&'
(UnaryOperator 0x2201e90 <col:10, col:11> 'int' prefix '!'
(DeclRefExpr 0x2201c90 <col:11> 'int' ParmVar='x' 0x2201a50))
(DeclRefExpr 0x2201eb0 <col:16> 'int' ParmVar='y' 0x2201e10))")
Now we produce:
$ clang-cc t2.c -ast-dump
typedef char *__builtin_va_list;
void f(int x, int y)
(CompoundStmt 0x2201f10 <t2.c:3:22, line:5:1>
(DeclStmt 0x2201ef0 <line:2:14, line:4:17> <------
0x2201a20 "int b =
(BinaryOperator 0x2201ed0 <col:10, col:16> 'int' '&&'
(UnaryOperator 0x2201e90 <col:10, col:11> 'int' prefix '!'
(DeclRefExpr 0x2201c90 <col:11> 'int' ParmVar='x' 0x2201a50))
(DeclRefExpr 0x2201eb0 <col:16> 'int' ParmVar='y' 0x2201e10))")
llvm-svn: 68288
2009-04-02 12:16:50 +08:00
|
|
|
{
|
|
|
|
SourceLocation DeclEnd;
|
2012-08-24 06:51:59 +08:00
|
|
|
StmtVector Stmts;
|
2010-12-24 10:08:15 +08:00
|
|
|
return ParseDeclaration(Stmts, Declarator::FileContext, DeclEnd, attrs);
|
fix a FIXME, providing accurate source range info for DeclStmt's. The end
of the range is now the ';' location. For something like this:
$ cat t2.c
#define bool int
void f(int x, int y) {
bool b = !x && y;
}
We used to produce:
$ clang-cc t2.c -ast-dump
typedef char *__builtin_va_list;
void f(int x, int y)
(CompoundStmt 0x2201f10 <t2.c:3:22, line:5:1>
(DeclStmt 0x2201ef0 <line:2:14> <----
0x2201a20 "int b =
(BinaryOperator 0x2201ed0 <line:4:10, col:16> 'int' '&&'
(UnaryOperator 0x2201e90 <col:10, col:11> 'int' prefix '!'
(DeclRefExpr 0x2201c90 <col:11> 'int' ParmVar='x' 0x2201a50))
(DeclRefExpr 0x2201eb0 <col:16> 'int' ParmVar='y' 0x2201e10))")
Now we produce:
$ clang-cc t2.c -ast-dump
typedef char *__builtin_va_list;
void f(int x, int y)
(CompoundStmt 0x2201f10 <t2.c:3:22, line:5:1>
(DeclStmt 0x2201ef0 <line:2:14, line:4:17> <------
0x2201a20 "int b =
(BinaryOperator 0x2201ed0 <col:10, col:16> 'int' '&&'
(UnaryOperator 0x2201e90 <col:10, col:11> 'int' prefix '!'
(DeclRefExpr 0x2201c90 <col:11> 'int' ParmVar='x' 0x2201a50))
(DeclRefExpr 0x2201eb0 <col:16> 'int' ParmVar='y' 0x2201e10))")
llvm-svn: 68288
2009-04-02 12:16:50 +08:00
|
|
|
}
|
2010-08-28 07:12:46 +08:00
|
|
|
|
2010-12-02 04:32:20 +08:00
|
|
|
case tok::kw_static:
|
|
|
|
// Parse (then ignore) 'static' prior to a template instantiation. This is
|
|
|
|
// a GCC extension that we intentionally do not support.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_template)) {
|
2010-12-02 04:32:20 +08:00
|
|
|
Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored)
|
|
|
|
<< 0;
|
2010-08-28 07:12:46 +08:00
|
|
|
SourceLocation DeclEnd;
|
2012-08-24 06:51:59 +08:00
|
|
|
StmtVector Stmts;
|
2010-12-24 10:08:15 +08:00
|
|
|
return ParseDeclaration(Stmts, Declarator::FileContext, DeclEnd, attrs);
|
2010-12-02 04:32:20 +08:00
|
|
|
}
|
|
|
|
goto dont_know;
|
|
|
|
|
|
|
|
case tok::kw_inline:
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().CPlusPlus) {
|
2010-12-02 04:32:20 +08:00
|
|
|
tok::TokenKind NextKind = NextToken().getKind();
|
|
|
|
|
|
|
|
// Inline namespaces. Allowed as an extension even in C++03.
|
|
|
|
if (NextKind == tok::kw_namespace) {
|
|
|
|
SourceLocation DeclEnd;
|
2012-08-24 06:51:59 +08:00
|
|
|
StmtVector Stmts;
|
2010-12-24 10:08:15 +08:00
|
|
|
return ParseDeclaration(Stmts, Declarator::FileContext, DeclEnd, attrs);
|
2010-12-02 04:32:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse (then ignore) 'inline' prior to a template instantiation. This is
|
|
|
|
// a GCC extension that we intentionally do not support.
|
|
|
|
if (NextKind == tok::kw_template) {
|
|
|
|
Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored)
|
|
|
|
<< 1;
|
|
|
|
SourceLocation DeclEnd;
|
2012-08-24 06:51:59 +08:00
|
|
|
StmtVector Stmts;
|
2010-12-24 10:08:15 +08:00
|
|
|
return ParseDeclaration(Stmts, Declarator::FileContext, DeclEnd, attrs);
|
2010-12-02 04:32:20 +08:00
|
|
|
}
|
2010-08-28 07:12:46 +08:00
|
|
|
}
|
|
|
|
goto dont_know;
|
|
|
|
|
2009-09-04 14:33:52 +08:00
|
|
|
case tok::kw_extern:
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_template)) {
|
2009-09-04 14:33:52 +08:00
|
|
|
// Extern templates
|
|
|
|
SourceLocation ExternLoc = ConsumeToken();
|
|
|
|
SourceLocation TemplateLoc = ConsumeToken();
|
2013-01-02 19:42:31 +08:00
|
|
|
Diag(ExternLoc, getLangOpts().CPlusPlus11 ?
|
2011-10-21 02:35:58 +08:00
|
|
|
diag::warn_cxx98_compat_extern_template :
|
|
|
|
diag::ext_extern_template) << SourceRange(ExternLoc, TemplateLoc);
|
2009-09-04 14:33:52 +08:00
|
|
|
SourceLocation DeclEnd;
|
|
|
|
return Actions.ConvertDeclToDeclGroup(
|
2011-12-23 10:16:45 +08:00
|
|
|
ParseExplicitInstantiation(Declarator::FileContext,
|
|
|
|
ExternLoc, TemplateLoc, DeclEnd));
|
2009-09-04 14:33:52 +08:00
|
|
|
}
|
|
|
|
// FIXME: Detect C++ linkage specifications here?
|
2010-08-28 07:12:46 +08:00
|
|
|
goto dont_know;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-05-08 01:30:27 +08:00
|
|
|
case tok::kw___if_exists:
|
|
|
|
case tok::kw___if_not_exists:
|
2011-05-25 18:19:49 +08:00
|
|
|
ParseMicrosoftIfExistsExternalDeclaration();
|
2011-05-08 01:30:27 +08:00
|
|
|
return DeclGroupPtrTy();
|
2011-08-27 07:56:07 +08:00
|
|
|
|
2006-07-31 09:59:18 +08:00
|
|
|
default:
|
2010-08-28 07:12:46 +08:00
|
|
|
dont_know:
|
2006-07-31 09:59:18 +08:00
|
|
|
// We can't tell whether this is a function-definition or declaration yet.
|
2012-12-29 09:09:46 +08:00
|
|
|
return ParseDeclarationOrFunctionDefinition(attrs, DS);
|
2006-07-31 09:59:18 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-30 00:50:03 +08:00
|
|
|
// This routine returns a DeclGroup, if the thing we parsed only contains a
|
|
|
|
// single decl, convert it now.
|
|
|
|
return Actions.ConvertDeclToDeclGroup(SingleDecl);
|
2006-07-31 09:59:18 +08:00
|
|
|
}
|
|
|
|
|
2009-05-13 05:31:51 +08:00
|
|
|
/// \brief Determine whether the current token, if it occurs after a
|
|
|
|
/// declarator, continues a declaration or declaration list.
|
2011-05-12 14:15:49 +08:00
|
|
|
bool Parser::isDeclarationAfterDeclarator() {
|
|
|
|
// Check for '= delete' or '= default'
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().CPlusPlus && Tok.is(tok::equal)) {
|
2011-05-12 14:15:49 +08:00
|
|
|
const Token &KW = NextToken();
|
|
|
|
if (KW.is(tok::kw_default) || KW.is(tok::kw_delete))
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-03 07:37:09 +08:00
|
|
|
|
2009-05-13 05:31:51 +08:00
|
|
|
return Tok.is(tok::equal) || // int X()= -> not a function def
|
|
|
|
Tok.is(tok::comma) || // int X(), -> not a function def
|
|
|
|
Tok.is(tok::semi) || // int X(); -> not a function def
|
|
|
|
Tok.is(tok::kw_asm) || // int X() __asm__ -> not a function def
|
|
|
|
Tok.is(tok::kw___attribute) || // int X() __attr__ -> not a function def
|
2012-03-11 15:00:24 +08:00
|
|
|
(getLangOpts().CPlusPlus &&
|
2012-07-06 03:34:20 +08:00
|
|
|
Tok.is(tok::l_paren)); // int X(0) -> not a function def [C++]
|
2009-05-13 05:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determine whether the current token, if it occurs after a
|
|
|
|
/// declarator, indicates the start of a function definition.
|
2010-07-12 06:42:07 +08:00
|
|
|
bool Parser::isStartOfFunctionDefinition(const ParsingDeclarator &Declarator) {
|
2010-12-11 00:29:40 +08:00
|
|
|
assert(Declarator.isFunctionDeclarator() && "Isn't a function declarator");
|
2009-12-07 02:34:27 +08:00
|
|
|
if (Tok.is(tok::l_brace)) // int X() {}
|
|
|
|
return true;
|
|
|
|
|
2010-07-12 06:42:07 +08:00
|
|
|
// Handle K&R C argument lists: int X(f) int f; {}
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!getLangOpts().CPlusPlus &&
|
2010-12-11 00:29:40 +08:00
|
|
|
Declarator.getFunctionTypeInfo().isKNRPrototype())
|
2010-07-12 06:42:07 +08:00
|
|
|
return isDeclarationSpecifier();
|
2011-05-12 14:15:49 +08:00
|
|
|
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().CPlusPlus && Tok.is(tok::equal)) {
|
2011-05-12 14:15:49 +08:00
|
|
|
const Token &KW = NextToken();
|
|
|
|
return KW.is(tok::kw_default) || KW.is(tok::kw_delete);
|
|
|
|
}
|
2010-07-12 06:42:07 +08:00
|
|
|
|
2009-12-07 02:34:27 +08:00
|
|
|
return Tok.is(tok::colon) || // X() : Base() {} (used for ctors)
|
|
|
|
Tok.is(tok::kw_try); // X() try { ... }
|
2009-05-13 05:31:51 +08:00
|
|
|
}
|
|
|
|
|
2006-07-31 09:59:18 +08:00
|
|
|
/// ParseDeclarationOrFunctionDefinition - Parse either a function-definition or
|
2006-07-31 13:09:04 +08:00
|
|
|
/// a declaration. We can't tell which we have until we read up to the
|
2008-12-24 10:52:09 +08:00
|
|
|
/// compound-statement in function-definition. TemplateParams, if
|
|
|
|
/// non-NULL, provides the template parameters when we're parsing a
|
2009-09-09 23:08:12 +08:00
|
|
|
/// C++ template-declaration.
|
2006-07-31 09:59:18 +08:00
|
|
|
///
|
2006-07-31 13:09:04 +08:00
|
|
|
/// function-definition: [C99 6.9.1]
|
2008-04-05 13:52:15 +08:00
|
|
|
/// decl-specs declarator declaration-list[opt] compound-statement
|
|
|
|
/// [C90] function-definition: [C99 6.7.1] - implicit int result
|
2008-06-20 03:28:49 +08:00
|
|
|
/// [C90] decl-specs[opt] declarator declaration-list[opt] compound-statement
|
2008-04-05 13:52:15 +08:00
|
|
|
///
|
2006-07-31 13:09:04 +08:00
|
|
|
/// declaration: [C99 6.7]
|
2007-08-22 14:06:56 +08:00
|
|
|
/// declaration-specifiers init-declarator-list[opt] ';'
|
|
|
|
/// [!C99] init-declarator-list ';' [TODO: warn in c99 mode]
|
2006-07-31 13:09:04 +08:00
|
|
|
/// [OMP] threadprivate-directive [TODO]
|
|
|
|
///
|
2009-03-30 00:50:03 +08:00
|
|
|
Parser::DeclGroupPtrTy
|
2012-06-23 13:07:58 +08:00
|
|
|
Parser::ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,
|
|
|
|
ParsingDeclSpec &DS,
|
|
|
|
AccessSpecifier AS) {
|
2006-07-31 13:09:04 +08:00
|
|
|
// Parse the common declaration-specifiers piece.
|
2010-01-14 01:31:36 +08:00
|
|
|
ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC_top_level);
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-08-05 16:09:44 +08:00
|
|
|
// C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };"
|
2006-08-10 13:19:57 +08:00
|
|
|
// declaration-specifiers init-declarator-list[opt] ';'
|
2007-10-10 01:23:58 +08:00
|
|
|
if (Tok.is(tok::semi)) {
|
2012-06-23 13:07:58 +08:00
|
|
|
ProhibitAttributes(attrs);
|
2006-08-14 03:58:17 +08:00
|
|
|
ConsumeToken();
|
2010-08-21 17:40:31 +08:00
|
|
|
Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, DS);
|
2009-11-04 10:18:39 +08:00
|
|
|
DS.complete(TheDecl);
|
2009-03-30 00:50:03 +08:00
|
|
|
return Actions.ConvertDeclToDeclGroup(TheDecl);
|
2006-08-14 03:58:17 +08:00
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2012-06-23 13:07:58 +08:00
|
|
|
DS.takeAttributesFrom(attrs);
|
|
|
|
|
2008-09-26 12:48:09 +08:00
|
|
|
// ObjC2 allows prefix attributes on class interfaces and protocols.
|
|
|
|
// FIXME: This still needs better diagnostics. We should only accept
|
|
|
|
// attributes here, no types, etc.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ObjC2 && Tok.is(tok::at)) {
|
2007-08-21 05:31:48 +08:00
|
|
|
SourceLocation AtLoc = ConsumeToken(); // the "@"
|
2009-09-09 23:08:12 +08:00
|
|
|
if (!Tok.isObjCAtKeyword(tok::objc_interface) &&
|
2008-09-26 12:48:09 +08:00
|
|
|
!Tok.isObjCAtKeyword(tok::objc_protocol)) {
|
|
|
|
Diag(Tok, diag::err_objc_unexpected_attr);
|
2007-12-28 03:57:00 +08:00
|
|
|
SkipUntil(tok::semi); // FIXME: better skip?
|
2009-03-30 00:50:03 +08:00
|
|
|
return DeclGroupPtrTy();
|
2007-12-28 03:57:00 +08:00
|
|
|
}
|
2009-11-04 03:26:08 +08:00
|
|
|
|
2009-11-04 10:18:39 +08:00
|
|
|
DS.abort();
|
|
|
|
|
2008-01-03 03:17:38 +08:00
|
|
|
const char *PrevSpec = 0;
|
2009-08-04 04:12:06 +08:00
|
|
|
unsigned DiagID;
|
|
|
|
if (DS.SetTypeSpecType(DeclSpec::TST_unspecified, AtLoc, PrevSpec, DiagID))
|
|
|
|
Diag(AtLoc, DiagID) << PrevSpec;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-09-26 12:48:09 +08:00
|
|
|
if (Tok.isObjCAtKeyword(tok::objc_protocol))
|
2012-01-02 05:23:57 +08:00
|
|
|
return ParseObjCAtProtocolDeclaration(AtLoc, DS.getAttributes());
|
|
|
|
|
|
|
|
return Actions.ConvertDeclToDeclGroup(
|
|
|
|
ParseObjCAtInterfaceDeclaration(AtLoc, DS.getAttributes()));
|
2007-08-21 05:31:48 +08:00
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2008-01-12 15:05:38 +08:00
|
|
|
// If the declspec consisted only of 'extern' and we have a string
|
|
|
|
// literal following it, this must be a C++ linkage specifier like
|
|
|
|
// 'extern "C"'.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (Tok.is(tok::string_literal) && getLangOpts().CPlusPlus &&
|
2008-01-12 15:05:38 +08:00
|
|
|
DS.getStorageClassSpec() == DeclSpec::SCS_extern &&
|
2009-03-30 00:50:03 +08:00
|
|
|
DS.getParsedSpecifiers() == DeclSpec::PQ_StorageClassSpecifier) {
|
2010-08-21 17:40:31 +08:00
|
|
|
Decl *TheDecl = ParseLinkage(DS, Declarator::FileContext);
|
2009-03-30 00:50:03 +08:00
|
|
|
return Actions.ConvertDeclToDeclGroup(TheDecl);
|
|
|
|
}
|
2008-01-12 15:05:38 +08:00
|
|
|
|
2009-11-04 03:26:08 +08:00
|
|
|
return ParseDeclGroup(DS, Declarator::FileContext, true);
|
2006-07-31 13:09:04 +08:00
|
|
|
}
|
|
|
|
|
2009-12-10 05:39:38 +08:00
|
|
|
Parser::DeclGroupPtrTy
|
2012-06-23 13:07:58 +08:00
|
|
|
Parser::ParseDeclarationOrFunctionDefinition(ParsedAttributesWithRange &attrs,
|
|
|
|
ParsingDeclSpec *DS,
|
2009-12-10 05:39:38 +08:00
|
|
|
AccessSpecifier AS) {
|
2012-06-23 13:07:58 +08:00
|
|
|
if (DS) {
|
|
|
|
return ParseDeclOrFunctionDefInternal(attrs, *DS, AS);
|
|
|
|
} else {
|
|
|
|
ParsingDeclSpec PDS(*this);
|
|
|
|
// Must temporarily exit the objective-c container scope for
|
|
|
|
// parsing c constructs and re-enter objc container scope
|
|
|
|
// afterwards.
|
|
|
|
ObjCDeclContextSwitch ObjCDC(*this);
|
|
|
|
|
|
|
|
return ParseDeclOrFunctionDefInternal(attrs, PDS, AS);
|
|
|
|
}
|
2009-12-10 05:39:38 +08:00
|
|
|
}
|
|
|
|
|
2006-08-07 14:31:38 +08:00
|
|
|
/// ParseFunctionDefinition - We parsed and verified that the specified
|
|
|
|
/// Declarator is well formed. If this is a K&R-style function, read the
|
|
|
|
/// parameters declaration-list, then start the compound-statement.
|
|
|
|
///
|
2008-04-05 13:52:15 +08:00
|
|
|
/// function-definition: [C99 6.9.1]
|
|
|
|
/// decl-specs declarator declaration-list[opt] compound-statement
|
|
|
|
/// [C90] function-definition: [C99 6.7.1] - implicit int result
|
2008-06-20 03:28:49 +08:00
|
|
|
/// [C90] decl-specs[opt] declarator declaration-list[opt] compound-statement
|
2008-11-05 12:29:56 +08:00
|
|
|
/// [C++] function-definition: [C++ 8.4]
|
2009-03-30 01:18:04 +08:00
|
|
|
/// decl-specifier-seq[opt] declarator ctor-initializer[opt]
|
|
|
|
/// function-body
|
2008-11-05 12:29:56 +08:00
|
|
|
/// [C++] function-definition: [C++ 8.4]
|
2009-04-27 04:35:05 +08:00
|
|
|
/// decl-specifier-seq[opt] declarator function-try-block
|
2006-08-07 14:31:38 +08:00
|
|
|
///
|
2010-08-21 17:40:31 +08:00
|
|
|
Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
|
2012-02-17 00:50:43 +08:00
|
|
|
const ParsedTemplateInfo &TemplateInfo,
|
|
|
|
LateParsedAttrList *LateParsedAttrs) {
|
2011-04-28 09:08:34 +08:00
|
|
|
// Poison the SEH identifiers so they are flagged as illegal in function bodies
|
|
|
|
PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true);
|
2010-12-11 00:29:40 +08:00
|
|
|
const DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo();
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2008-04-05 13:52:15 +08:00
|
|
|
// If this is C90 and the declspecs were completely missing, fudge in an
|
|
|
|
// implicit int. We do this here because this is the only place where
|
|
|
|
// declaration-specifiers are completely optional in the grammar.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().ImplicitInt && D.getDeclSpec().isEmpty()) {
|
2008-04-05 13:52:15 +08:00
|
|
|
const char *PrevSpec;
|
2009-08-04 04:12:06 +08:00
|
|
|
unsigned DiagID;
|
2008-10-20 10:01:34 +08:00
|
|
|
D.getMutableDeclSpec().SetTypeSpecType(DeclSpec::TST_int,
|
|
|
|
D.getIdentifierLoc(),
|
2009-08-04 04:12:06 +08:00
|
|
|
PrevSpec, DiagID);
|
2009-02-10 02:23:29 +08:00
|
|
|
D.SetRangeBegin(D.getDeclSpec().getSourceRange().getBegin());
|
2008-04-05 13:52:15 +08:00
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-08-07 14:31:38 +08:00
|
|
|
// If this declaration was formed with a K&R-style identifier list for the
|
|
|
|
// arguments, parse declarations for all of the args next.
|
|
|
|
// int foo(a,b) int a; float b; {}
|
2010-07-12 06:42:07 +08:00
|
|
|
if (FTI.isKNRPrototype())
|
2006-12-03 16:41:30 +08:00
|
|
|
ParseKNRParamDeclarations(D);
|
2006-08-07 14:31:38 +08:00
|
|
|
|
2008-11-05 12:29:56 +08:00
|
|
|
// We should have either an opening brace or, in a C++ constructor,
|
|
|
|
// we may have a colon.
|
2011-02-04 19:57:16 +08:00
|
|
|
if (Tok.isNot(tok::l_brace) &&
|
2012-03-11 15:00:24 +08:00
|
|
|
(!getLangOpts().CPlusPlus ||
|
2011-05-24 07:14:04 +08:00
|
|
|
(Tok.isNot(tok::colon) && Tok.isNot(tok::kw_try) &&
|
|
|
|
Tok.isNot(tok::equal)))) {
|
2006-08-09 13:47:47 +08:00
|
|
|
Diag(Tok, diag::err_expected_fn_body);
|
|
|
|
|
|
|
|
// Skip over garbage, until we get to '{'. Don't eat the '{'.
|
|
|
|
SkipUntil(tok::l_brace, true, true);
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-08-09 13:47:47 +08:00
|
|
|
// If we didn't find the '{', bail out.
|
2007-10-10 01:23:58 +08:00
|
|
|
if (Tok.isNot(tok::l_brace))
|
2010-08-21 17:40:31 +08:00
|
|
|
return 0;
|
2006-08-09 13:47:47 +08:00
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2012-02-17 00:50:43 +08:00
|
|
|
// Check to make sure that any normal attributes are allowed to be on
|
|
|
|
// a definition. Late parsed attributes are checked at the end.
|
|
|
|
if (Tok.isNot(tok::equal)) {
|
|
|
|
AttributeList *DtorAttrs = D.getAttributes();
|
|
|
|
while (DtorAttrs) {
|
2013-01-17 09:30:42 +08:00
|
|
|
if (!IsThreadSafetyAttribute(DtorAttrs->getName()->getName()) &&
|
|
|
|
!DtorAttrs->isCXX11Attribute()) {
|
2012-02-17 00:50:43 +08:00
|
|
|
Diag(DtorAttrs->getLoc(), diag::warn_attribute_on_function_definition)
|
|
|
|
<< DtorAttrs->getName()->getName();
|
|
|
|
}
|
|
|
|
DtorAttrs = DtorAttrs->getNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-23 06:18:13 +08:00
|
|
|
// In delayed template parsing mode, for function template we consume the
|
|
|
|
// tokens and store them for late parsing at the end of the translation unit.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().DelayedTemplateParsing &&
|
2012-06-29 05:43:01 +08:00
|
|
|
Tok.isNot(tok::equal) &&
|
2011-04-23 06:18:13 +08:00
|
|
|
TemplateInfo.Kind == ParsedTemplateInfo::Template) {
|
2012-08-24 07:38:35 +08:00
|
|
|
MultiTemplateParamsArg TemplateParameterLists(*TemplateInfo.TemplateParams);
|
2011-04-23 06:18:13 +08:00
|
|
|
|
|
|
|
ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);
|
|
|
|
Scope *ParentScope = getCurScope()->getParent();
|
|
|
|
|
2011-11-08 04:56:01 +08:00
|
|
|
D.setFunctionDefinitionKind(FDK_Definition);
|
2011-04-23 06:18:13 +08:00
|
|
|
Decl *DP = Actions.HandleDeclarator(ParentScope, D,
|
2012-08-24 05:35:17 +08:00
|
|
|
TemplateParameterLists);
|
2011-04-23 06:18:13 +08:00
|
|
|
D.complete(DP);
|
|
|
|
D.getMutableDeclSpec().abort();
|
|
|
|
|
2013-08-08 05:41:30 +08:00
|
|
|
CachedTokens Toks;
|
|
|
|
LexTemplateFunctionForLateParsing(Toks);
|
2011-04-23 06:18:13 +08:00
|
|
|
|
2013-08-08 05:41:30 +08:00
|
|
|
if (DP) {
|
2011-04-23 06:18:13 +08:00
|
|
|
FunctionDecl *FnD = 0;
|
|
|
|
if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(DP))
|
|
|
|
FnD = FunTmpl->getTemplatedDecl();
|
|
|
|
else
|
|
|
|
FnD = cast<FunctionDecl>(DP);
|
|
|
|
|
2013-08-08 05:41:30 +08:00
|
|
|
Actions.CheckForFunctionRedefinition(FnD);
|
|
|
|
Actions.MarkAsLateParsedTemplate(FnD, DP, Toks);
|
2011-04-23 06:18:13 +08:00
|
|
|
}
|
|
|
|
return DP;
|
|
|
|
}
|
2012-08-11 02:10:56 +08:00
|
|
|
else if (CurParsedObjCImpl &&
|
2012-08-11 05:15:06 +08:00
|
|
|
!TemplateInfo.TemplateParams &&
|
|
|
|
(Tok.is(tok::l_brace) || Tok.is(tok::kw_try) ||
|
|
|
|
Tok.is(tok::colon)) &&
|
2012-08-10 23:54:40 +08:00
|
|
|
Actions.CurContext->isTranslationUnit()) {
|
|
|
|
ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);
|
|
|
|
Scope *ParentScope = getCurScope()->getParent();
|
|
|
|
|
|
|
|
D.setFunctionDefinitionKind(FDK_Definition);
|
|
|
|
Decl *FuncDecl = Actions.HandleDeclarator(ParentScope, D,
|
2012-08-24 07:38:35 +08:00
|
|
|
MultiTemplateParamsArg());
|
2012-08-10 23:54:40 +08:00
|
|
|
D.complete(FuncDecl);
|
|
|
|
D.getMutableDeclSpec().abort();
|
|
|
|
if (FuncDecl) {
|
|
|
|
// Consume the tokens and store them for later parsing.
|
|
|
|
StashAwayMethodOrFunctionBodyTokens(FuncDecl);
|
|
|
|
CurParsedObjCImpl->HasCFunction = true;
|
|
|
|
return FuncDecl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-10 01:14:05 +08:00
|
|
|
// Enter a scope for the function body.
|
2008-12-10 14:34:36 +08:00
|
|
|
ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope);
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2007-10-10 01:14:05 +08:00
|
|
|
// Tell the actions module that we have entered a function definition with the
|
|
|
|
// specified Declarator for the function.
|
2010-08-21 17:40:31 +08:00
|
|
|
Decl *Res = TemplateInfo.TemplateParams?
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.ActOnStartOfFunctionTemplateDef(getCurScope(),
|
2012-08-24 07:38:35 +08:00
|
|
|
*TemplateInfo.TemplateParams, D)
|
2010-07-03 01:43:08 +08:00
|
|
|
: Actions.ActOnStartOfFunctionDef(getCurScope(), D);
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2009-11-04 10:18:39 +08:00
|
|
|
// Break out of the ParsingDeclarator context before we parse the body.
|
|
|
|
D.complete(Res);
|
|
|
|
|
|
|
|
// Break out of the ParsingDeclSpec context, too. This const_cast is
|
|
|
|
// safe because we're always the sole owner.
|
|
|
|
D.getMutableDeclSpec().abort();
|
|
|
|
|
2011-05-24 07:14:04 +08:00
|
|
|
if (Tok.is(tok::equal)) {
|
2012-03-11 15:00:24 +08:00
|
|
|
assert(getLangOpts().CPlusPlus && "Only C++ function definitions have '='");
|
2011-05-24 07:14:04 +08:00
|
|
|
ConsumeToken();
|
|
|
|
|
|
|
|
Actions.ActOnFinishFunctionBody(Res, 0, false);
|
|
|
|
|
|
|
|
bool Delete = false;
|
|
|
|
SourceLocation KWLoc;
|
|
|
|
if (Tok.is(tok::kw_delete)) {
|
2013-01-02 19:42:31 +08:00
|
|
|
Diag(Tok, getLangOpts().CPlusPlus11 ?
|
2011-10-15 13:09:34 +08:00
|
|
|
diag::warn_cxx98_compat_deleted_function :
|
2011-12-30 05:57:33 +08:00
|
|
|
diag::ext_deleted_function);
|
2011-05-24 07:14:04 +08:00
|
|
|
|
|
|
|
KWLoc = ConsumeToken();
|
|
|
|
Actions.SetDeclDeleted(Res, KWLoc);
|
|
|
|
Delete = true;
|
|
|
|
} else if (Tok.is(tok::kw_default)) {
|
2013-01-02 19:42:31 +08:00
|
|
|
Diag(Tok, getLangOpts().CPlusPlus11 ?
|
2011-10-15 13:09:34 +08:00
|
|
|
diag::warn_cxx98_compat_defaulted_function :
|
2011-12-30 05:57:33 +08:00
|
|
|
diag::ext_defaulted_function);
|
2011-05-24 07:14:04 +08:00
|
|
|
|
|
|
|
KWLoc = ConsumeToken();
|
|
|
|
Actions.SetDeclDefaulted(Res, KWLoc);
|
|
|
|
} else {
|
|
|
|
llvm_unreachable("function definition after = not 'delete' or 'default'");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.is(tok::comma)) {
|
|
|
|
Diag(KWLoc, diag::err_default_delete_in_multiple_declaration)
|
|
|
|
<< Delete;
|
|
|
|
SkipUntil(tok::semi);
|
|
|
|
} else {
|
|
|
|
ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
|
|
|
|
Delete ? "delete" : "default", tok::semi);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
2009-04-27 04:35:05 +08:00
|
|
|
if (Tok.is(tok::kw_try))
|
2011-03-17 01:05:57 +08:00
|
|
|
return ParseFunctionTryBlock(Res, BodyScope);
|
2009-04-27 04:35:05 +08:00
|
|
|
|
2008-11-05 12:29:56 +08:00
|
|
|
// If we have a colon, then we're probably parsing a C++
|
|
|
|
// ctor-initializer.
|
2010-04-10 15:37:23 +08:00
|
|
|
if (Tok.is(tok::colon)) {
|
2008-11-05 12:29:56 +08:00
|
|
|
ParseConstructorInitializer(Res);
|
2010-04-10 15:37:23 +08:00
|
|
|
|
|
|
|
// Recover from error.
|
|
|
|
if (!Tok.is(tok::l_brace)) {
|
2011-03-17 01:05:57 +08:00
|
|
|
BodyScope.Exit();
|
2010-08-24 07:25:46 +08:00
|
|
|
Actions.ActOnFinishFunctionBody(Res, 0);
|
2010-04-10 15:37:23 +08:00
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
} else
|
2009-07-22 06:36:06 +08:00
|
|
|
Actions.ActOnDefaultCtorInitializers(Res);
|
2008-11-05 12:29:56 +08:00
|
|
|
|
2012-02-17 00:50:43 +08:00
|
|
|
// Late attributes are parsed in the same scope as the function body.
|
|
|
|
if (LateParsedAttrs)
|
|
|
|
ParseLexedAttributeList(*LateParsedAttrs, Res, false, true);
|
|
|
|
|
2011-03-17 01:05:57 +08:00
|
|
|
return ParseFunctionStatementBody(Res, BodyScope);
|
2006-08-07 14:31:38 +08:00
|
|
|
}
|
|
|
|
|
2006-12-03 16:41:30 +08:00
|
|
|
/// ParseKNRParamDeclarations - Parse 'declaration-list[opt]' which provides
|
|
|
|
/// types for a function with a K&R-style identifier list for arguments.
|
|
|
|
void Parser::ParseKNRParamDeclarations(Declarator &D) {
|
|
|
|
// We know that the top-level of this declarator is a function.
|
2010-12-11 00:29:40 +08:00
|
|
|
DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo();
|
2006-12-03 16:41:30 +08:00
|
|
|
|
2008-04-08 12:40:51 +08:00
|
|
|
// Enter function-declaration scope, limiting any declarators to the
|
|
|
|
// function prototype scope, including parameter declarators.
|
2013-01-29 06:42:45 +08:00
|
|
|
ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope |
|
|
|
|
Scope::FunctionDeclarationScope | Scope::DeclScope);
|
2008-04-08 12:40:51 +08:00
|
|
|
|
2006-12-03 16:41:30 +08:00
|
|
|
// Read all the argument declarations.
|
|
|
|
while (isDeclarationSpecifier()) {
|
|
|
|
SourceLocation DSStart = Tok.getLocation();
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-12-03 16:41:30 +08:00
|
|
|
// Parse the common declaration-specifiers piece.
|
2011-03-24 19:26:52 +08:00
|
|
|
DeclSpec DS(AttrFactory);
|
2006-12-03 16:41:30 +08:00
|
|
|
ParseDeclarationSpecifiers(DS);
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-12-03 16:41:30 +08:00
|
|
|
// C99 6.9.1p6: 'each declaration in the declaration list shall have at
|
|
|
|
// least one declarator'.
|
|
|
|
// NOTE: GCC just makes this an ext-warn. It's not clear what it does with
|
|
|
|
// the declarations though. It's trivial to ignore them, really hard to do
|
|
|
|
// anything else with them.
|
2007-10-10 01:23:58 +08:00
|
|
|
if (Tok.is(tok::semi)) {
|
2006-12-03 16:41:30 +08:00
|
|
|
Diag(DSStart, diag::err_declaration_does_not_declare_param);
|
|
|
|
ConsumeToken();
|
|
|
|
continue;
|
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-12-03 16:41:30 +08:00
|
|
|
// C99 6.9.1p6: Declarations shall contain no storage-class specifiers other
|
|
|
|
// than register.
|
|
|
|
if (DS.getStorageClassSpec() != DeclSpec::SCS_unspecified &&
|
|
|
|
DS.getStorageClassSpec() != DeclSpec::SCS_register) {
|
|
|
|
Diag(DS.getStorageClassSpecLoc(),
|
|
|
|
diag::err_invalid_storage_class_in_func_decl);
|
|
|
|
DS.ClearStorageClassSpecs();
|
|
|
|
}
|
2013-04-13 06:46:28 +08:00
|
|
|
if (DS.getThreadStorageClassSpec() != DeclSpec::TSCS_unspecified) {
|
|
|
|
Diag(DS.getThreadStorageClassSpecLoc(),
|
2006-12-03 16:41:30 +08:00
|
|
|
diag::err_invalid_storage_class_in_func_decl);
|
|
|
|
DS.ClearStorageClassSpecs();
|
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-12-03 16:41:30 +08:00
|
|
|
// Parse the first declarator attached to this declspec.
|
|
|
|
Declarator ParmDeclarator(DS, Declarator::KNRTypeListContext);
|
|
|
|
ParseDeclarator(ParmDeclarator);
|
|
|
|
|
|
|
|
// Handle the full declarator list.
|
|
|
|
while (1) {
|
|
|
|
// If attributes are present, parse them.
|
2010-12-24 10:08:15 +08:00
|
|
|
MaybeParseGNUAttributes(ParmDeclarator);
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-12-03 16:41:30 +08:00
|
|
|
// Ask the actions module to compute the type for this declarator.
|
2010-08-21 17:40:31 +08:00
|
|
|
Decl *Param =
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.ActOnParamDeclarator(getCurScope(), ParmDeclarator);
|
2013-08-22 20:12:24 +08:00
|
|
|
|
2008-06-20 03:28:49 +08:00
|
|
|
if (Param &&
|
2006-12-03 16:41:30 +08:00
|
|
|
// A missing identifier has already been diagnosed.
|
|
|
|
ParmDeclarator.getIdentifier()) {
|
|
|
|
|
|
|
|
// Scan the argument list looking for the correct param to apply this
|
|
|
|
// type.
|
|
|
|
for (unsigned i = 0; ; ++i) {
|
|
|
|
// C99 6.9.1p6: those declarators shall declare only identifiers from
|
|
|
|
// the identifier list.
|
|
|
|
if (i == FTI.NumArgs) {
|
2008-11-18 15:48:38 +08:00
|
|
|
Diag(ParmDeclarator.getIdentifierLoc(), diag::err_no_matching_param)
|
2008-11-19 15:51:13 +08:00
|
|
|
<< ParmDeclarator.getIdentifier();
|
2006-12-03 16:41:30 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-12-03 16:41:30 +08:00
|
|
|
if (FTI.ArgInfo[i].Ident == ParmDeclarator.getIdentifier()) {
|
|
|
|
// Reject redefinitions of parameters.
|
2008-04-08 12:40:51 +08:00
|
|
|
if (FTI.ArgInfo[i].Param) {
|
2006-12-03 16:41:30 +08:00
|
|
|
Diag(ParmDeclarator.getIdentifierLoc(),
|
2008-11-18 15:48:38 +08:00
|
|
|
diag::err_param_redefinition)
|
2008-11-19 15:51:13 +08:00
|
|
|
<< ParmDeclarator.getIdentifier();
|
2006-12-03 16:41:30 +08:00
|
|
|
} else {
|
2008-04-08 12:40:51 +08:00
|
|
|
FTI.ArgInfo[i].Param = Param;
|
2006-12-03 16:41:30 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we don't have a comma, it is either the end of the list (a ';') or
|
|
|
|
// an error, bail out.
|
2007-10-10 01:23:58 +08:00
|
|
|
if (Tok.isNot(tok::comma))
|
2006-12-03 16:41:30 +08:00
|
|
|
break;
|
2008-06-20 03:28:49 +08:00
|
|
|
|
Improve 0-argument -Wvexing-parse diagnostic by adding notes with fix-its:
- If the declarator is at the start of a line, and the previous line contained
another declarator and ended with a comma, then that comma was probably a
typo for a semicolon:
int n = 0, m = 1, l = 2, // k = 5;
myImportantFunctionCall(); // oops!
- If removing the parentheses would correctly initialize the object, then
produce a note suggesting that fix.
- Otherwise, if there is a simple initializer we can suggest which performs
value-initialization, then provide a note suggesting a correction to that
initializer.
Sema::Declarator now tracks the location of the comma prior to the declarator in
the declaration, if there is one, to facilitate providing the note. The code to
determine an appropriate initializer from the -Wuninitialized warning has been
factored out to allow use in both that and -Wvexing-parse.
llvm-svn: 148072
2012-01-13 07:53:29 +08:00
|
|
|
ParmDeclarator.clear();
|
|
|
|
|
2006-12-03 16:41:30 +08:00
|
|
|
// Consume the comma.
|
Improve 0-argument -Wvexing-parse diagnostic by adding notes with fix-its:
- If the declarator is at the start of a line, and the previous line contained
another declarator and ended with a comma, then that comma was probably a
typo for a semicolon:
int n = 0, m = 1, l = 2, // k = 5;
myImportantFunctionCall(); // oops!
- If removing the parentheses would correctly initialize the object, then
produce a note suggesting that fix.
- Otherwise, if there is a simple initializer we can suggest which performs
value-initialization, then provide a note suggesting a correction to that
initializer.
Sema::Declarator now tracks the location of the comma prior to the declarator in
the declaration, if there is one, to facilitate providing the note. The code to
determine an appropriate initializer from the -Wuninitialized warning has been
factored out to allow use in both that and -Wvexing-parse.
llvm-svn: 148072
2012-01-13 07:53:29 +08:00
|
|
|
ParmDeclarator.setCommaLoc(ConsumeToken());
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-12-03 16:41:30 +08:00
|
|
|
// Parse the next declarator.
|
|
|
|
ParseDeclarator(ParmDeclarator);
|
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2012-04-29 00:12:17 +08:00
|
|
|
if (ExpectAndConsumeSemi(diag::err_expected_semi_declaration)) {
|
2006-12-03 16:41:30 +08:00
|
|
|
// Skip to end of block or statement
|
|
|
|
SkipUntil(tok::semi, true);
|
2007-10-10 01:23:58 +08:00
|
|
|
if (Tok.is(tok::semi))
|
2006-12-03 16:41:30 +08:00
|
|
|
ConsumeToken();
|
|
|
|
}
|
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2006-12-03 16:41:30 +08:00
|
|
|
// The actions module must verify that all arguments were declared.
|
2010-07-03 01:43:08 +08:00
|
|
|
Actions.ActOnFinishKNRParamDeclarations(getCurScope(), D, Tok.getLocation());
|
2006-12-03 16:41:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-15 14:03:28 +08:00
|
|
|
/// ParseAsmStringLiteral - This is just a normal string-literal, but is not
|
|
|
|
/// allowed to be a wide string, and is not subject to character translation.
|
|
|
|
///
|
|
|
|
/// [GNU] asm-string-literal:
|
|
|
|
/// string-literal
|
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
Parser::ExprResult Parser::ParseAsmStringLiteral() {
|
2011-12-02 08:35:46 +08:00
|
|
|
switch (Tok.getKind()) {
|
|
|
|
case tok::string_literal:
|
|
|
|
break;
|
2012-03-06 11:21:47 +08:00
|
|
|
case tok::utf8_string_literal:
|
|
|
|
case tok::utf16_string_literal:
|
|
|
|
case tok::utf32_string_literal:
|
2011-12-02 08:35:46 +08:00
|
|
|
case tok::wide_string_literal: {
|
|
|
|
SourceLocation L = Tok.getLocation();
|
|
|
|
Diag(Tok, diag::err_asm_operand_wide_string_literal)
|
2012-03-06 11:21:47 +08:00
|
|
|
<< (Tok.getKind() == tok::wide_string_literal)
|
2011-12-02 08:35:46 +08:00
|
|
|
<< SourceRange(L, L);
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
default:
|
2012-11-18 03:16:52 +08:00
|
|
|
Diag(Tok, diag::err_expected_string_literal)
|
|
|
|
<< /*Source='in...'*/0 << "'asm'";
|
2011-12-02 08:35:46 +08:00
|
|
|
return ExprError();
|
2006-08-15 14:03:28 +08:00
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2012-03-06 11:21:47 +08:00
|
|
|
return ParseStringLiteralExpression();
|
2006-08-15 14:03:28 +08:00
|
|
|
}
|
|
|
|
|
2006-08-15 11:41:14 +08:00
|
|
|
/// ParseSimpleAsm
|
|
|
|
///
|
|
|
|
/// [GNU] simple-asm-expr:
|
|
|
|
/// 'asm' '(' asm-string-literal ')'
|
|
|
|
///
|
2010-08-24 14:29:42 +08:00
|
|
|
Parser::ExprResult Parser::ParseSimpleAsm(SourceLocation *EndLoc) {
|
2007-10-10 01:23:58 +08:00
|
|
|
assert(Tok.is(tok::kw_asm) && "Not an asm!");
|
2008-02-08 08:33:21 +08:00
|
|
|
SourceLocation Loc = ConsumeToken();
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2010-01-26 06:27:48 +08:00
|
|
|
if (Tok.is(tok::kw_volatile)) {
|
2010-01-26 07:12:50 +08:00
|
|
|
// Remove from the end of 'asm' to the end of 'volatile'.
|
|
|
|
SourceRange RemovalRange(PP.getLocForEndOfToken(Loc),
|
|
|
|
PP.getLocForEndOfToken(Tok.getLocation()));
|
|
|
|
|
|
|
|
Diag(Tok, diag::warn_file_asm_volatile)
|
2010-04-01 01:46:05 +08:00
|
|
|
<< FixItHint::CreateRemoval(RemovalRange);
|
2010-01-26 06:27:48 +08:00
|
|
|
ConsumeToken();
|
|
|
|
}
|
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
if (T.consumeOpen()) {
|
2008-11-18 15:48:38 +08:00
|
|
|
Diag(Tok, diag::err_expected_lparen_after) << "asm";
|
2008-12-12 03:30:53 +08:00
|
|
|
return ExprError();
|
2006-08-15 11:41:14 +08:00
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult Result(ParseAsmStringLiteral());
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2009-02-10 02:23:29 +08:00
|
|
|
if (Result.isInvalid()) {
|
|
|
|
SkipUntil(tok::r_paren, true, true);
|
|
|
|
if (EndLoc)
|
|
|
|
*EndLoc = Tok.getLocation();
|
|
|
|
ConsumeAnyToken();
|
|
|
|
} else {
|
2011-10-13 00:37:45 +08:00
|
|
|
// Close the paren and get the location of the end bracket
|
|
|
|
T.consumeClose();
|
2009-02-10 02:23:29 +08:00
|
|
|
if (EndLoc)
|
2011-10-13 00:37:45 +08:00
|
|
|
*EndLoc = T.getCloseLocation();
|
2009-02-10 02:23:29 +08:00
|
|
|
}
|
2008-06-20 03:28:49 +08:00
|
|
|
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2006-08-15 11:41:14 +08:00
|
|
|
}
|
2006-10-28 07:18:49 +08:00
|
|
|
|
2011-06-22 14:09:49 +08:00
|
|
|
/// \brief Get the TemplateIdAnnotation from the token and put it in the
|
|
|
|
/// cleanup pool so that it gets destroyed when parsing the current top level
|
|
|
|
/// declaration is finished.
|
|
|
|
TemplateIdAnnotation *Parser::takeTemplateIdAnnotation(const Token &tok) {
|
|
|
|
assert(tok.is(tok::annot_template_id) && "Expected template-id token");
|
|
|
|
TemplateIdAnnotation *
|
|
|
|
Id = static_cast<TemplateIdAnnotation *>(tok.getAnnotationValue());
|
|
|
|
return Id;
|
|
|
|
}
|
|
|
|
|
2012-08-18 08:55:03 +08:00
|
|
|
void Parser::AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation) {
|
|
|
|
// Push the current token back into the token stream (or revert it if it is
|
|
|
|
// cached) and use an annotation scope token for current token.
|
|
|
|
if (PP.isBacktrackEnabled())
|
|
|
|
PP.RevertCachedTokens(1);
|
|
|
|
else
|
|
|
|
PP.EnterToken(Tok);
|
|
|
|
Tok.setKind(tok::annot_cxxscope);
|
|
|
|
Tok.setAnnotationValue(Actions.SaveNestedNameSpecifierAnnotation(SS));
|
|
|
|
Tok.setAnnotationRange(SS.getRange());
|
|
|
|
|
|
|
|
// In case the tokens were cached, have Preprocessor replace them
|
|
|
|
// with the annotation token. We don't need to do this if we've
|
|
|
|
// just reverted back to a prior state.
|
|
|
|
if (IsNewAnnotation)
|
|
|
|
PP.AnnotateCachedTokens(Tok);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Attempt to classify the name at the current token position. This may
|
|
|
|
/// form a type, scope or primary expression annotation, or replace the token
|
|
|
|
/// with a typo-corrected keyword. This is only appropriate when the current
|
|
|
|
/// name must refer to an entity which has already been declared.
|
|
|
|
///
|
|
|
|
/// \param IsAddressOfOperand Must be \c true if the name is preceded by an '&'
|
|
|
|
/// and might possibly have a dependent nested name specifier.
|
|
|
|
/// \param CCC Indicates how to perform typo-correction for this name. If NULL,
|
|
|
|
/// no typo correction will be performed.
|
|
|
|
Parser::AnnotatedNameKind
|
|
|
|
Parser::TryAnnotateName(bool IsAddressOfOperand,
|
|
|
|
CorrectionCandidateCallback *CCC) {
|
|
|
|
assert(Tok.is(tok::identifier) || Tok.is(tok::annot_cxxscope));
|
|
|
|
|
|
|
|
const bool EnteringContext = false;
|
|
|
|
const bool WasScopeAnnotation = Tok.is(tok::annot_cxxscope);
|
|
|
|
|
|
|
|
CXXScopeSpec SS;
|
|
|
|
if (getLangOpts().CPlusPlus &&
|
|
|
|
ParseOptionalCXXScopeSpecifier(SS, ParsedType(), EnteringContext))
|
|
|
|
return ANK_Error;
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::identifier) || SS.isInvalid()) {
|
|
|
|
if (TryAnnotateTypeOrScopeTokenAfterScopeSpec(EnteringContext, false, SS,
|
|
|
|
!WasScopeAnnotation))
|
|
|
|
return ANK_Error;
|
|
|
|
return ANK_Unresolved;
|
|
|
|
}
|
|
|
|
|
|
|
|
IdentifierInfo *Name = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation NameLoc = Tok.getLocation();
|
|
|
|
|
|
|
|
// FIXME: Move the tentative declaration logic into ClassifyName so we can
|
|
|
|
// typo-correct to tentatively-declared identifiers.
|
|
|
|
if (isTentativelyDeclared(Name)) {
|
|
|
|
// Identifier has been tentatively declared, and thus cannot be resolved as
|
|
|
|
// an expression. Fall back to annotating it as a type.
|
|
|
|
if (TryAnnotateTypeOrScopeTokenAfterScopeSpec(EnteringContext, false, SS,
|
|
|
|
!WasScopeAnnotation))
|
|
|
|
return ANK_Error;
|
|
|
|
return Tok.is(tok::annot_typename) ? ANK_Success : ANK_TentativeDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
Token Next = NextToken();
|
|
|
|
|
|
|
|
// Look up and classify the identifier. We don't perform any typo-correction
|
|
|
|
// after a scope specifier, because in general we can't recover from typos
|
|
|
|
// there (eg, after correcting 'A::tempalte B<X>::C', we would need to jump
|
|
|
|
// back into scope specifier parsing).
|
|
|
|
Sema::NameClassification Classification
|
|
|
|
= Actions.ClassifyName(getCurScope(), SS, Name, NameLoc, Next,
|
|
|
|
IsAddressOfOperand, SS.isEmpty() ? CCC : 0);
|
|
|
|
|
|
|
|
switch (Classification.getKind()) {
|
|
|
|
case Sema::NC_Error:
|
|
|
|
return ANK_Error;
|
|
|
|
|
|
|
|
case Sema::NC_Keyword:
|
|
|
|
// The identifier was typo-corrected to a keyword.
|
|
|
|
Tok.setIdentifierInfo(Name);
|
|
|
|
Tok.setKind(Name->getTokenID());
|
|
|
|
PP.TypoCorrectToken(Tok);
|
|
|
|
if (SS.isNotEmpty())
|
|
|
|
AnnotateScopeToken(SS, !WasScopeAnnotation);
|
|
|
|
// We've "annotated" this as a keyword.
|
|
|
|
return ANK_Success;
|
|
|
|
|
|
|
|
case Sema::NC_Unknown:
|
|
|
|
// It's not something we know about. Leave it unannotated.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Sema::NC_Type:
|
|
|
|
Tok.setKind(tok::annot_typename);
|
|
|
|
setTypeAnnotation(Tok, Classification.getType());
|
|
|
|
Tok.setAnnotationEndLoc(NameLoc);
|
|
|
|
if (SS.isNotEmpty())
|
|
|
|
Tok.setLocation(SS.getBeginLoc());
|
|
|
|
PP.AnnotateCachedTokens(Tok);
|
|
|
|
return ANK_Success;
|
|
|
|
|
|
|
|
case Sema::NC_Expression:
|
|
|
|
Tok.setKind(tok::annot_primary_expr);
|
|
|
|
setExprAnnotation(Tok, Classification.getExpression());
|
|
|
|
Tok.setAnnotationEndLoc(NameLoc);
|
|
|
|
if (SS.isNotEmpty())
|
|
|
|
Tok.setLocation(SS.getBeginLoc());
|
|
|
|
PP.AnnotateCachedTokens(Tok);
|
|
|
|
return ANK_Success;
|
|
|
|
|
|
|
|
case Sema::NC_TypeTemplate:
|
|
|
|
if (Next.isNot(tok::less)) {
|
|
|
|
// This may be a type template being used as a template template argument.
|
|
|
|
if (SS.isNotEmpty())
|
|
|
|
AnnotateScopeToken(SS, !WasScopeAnnotation);
|
|
|
|
return ANK_TemplateName;
|
|
|
|
}
|
|
|
|
// Fall through.
|
2013-08-06 09:03:05 +08:00
|
|
|
case Sema::NC_VarTemplate:
|
2012-08-18 08:55:03 +08:00
|
|
|
case Sema::NC_FunctionTemplate: {
|
2013-08-06 09:03:05 +08:00
|
|
|
// We have a type, variable or function template followed by '<'.
|
2012-08-18 08:55:03 +08:00
|
|
|
ConsumeToken();
|
|
|
|
UnqualifiedId Id;
|
|
|
|
Id.setIdentifier(Name, NameLoc);
|
|
|
|
if (AnnotateTemplateIdToken(
|
|
|
|
TemplateTy::make(Classification.getTemplateName()),
|
|
|
|
Classification.getTemplateNameKind(), SS, SourceLocation(), Id))
|
|
|
|
return ANK_Error;
|
|
|
|
return ANK_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Sema::NC_NestedNameSpecifier:
|
|
|
|
llvm_unreachable("already parsed nested name specifier");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unable to classify the name, but maybe we can annotate a scope specifier.
|
|
|
|
if (SS.isNotEmpty())
|
|
|
|
AnnotateScopeToken(SS, !WasScopeAnnotation);
|
|
|
|
return ANK_Unresolved;
|
|
|
|
}
|
|
|
|
|
2008-11-09 00:45:02 +08:00
|
|
|
/// TryAnnotateTypeOrScopeToken - If the current token position is on a
|
|
|
|
/// typename (possibly qualified in C++) or a C++ scope specifier not followed
|
|
|
|
/// by a typename, TryAnnotateTypeOrScopeToken will replace one or more tokens
|
|
|
|
/// with a single annotation token representing the typename or C++ scope
|
|
|
|
/// respectively.
|
|
|
|
/// This simplifies handling of C++ scope specifiers and allows efficient
|
|
|
|
/// backtracking without the need to re-parse and resolve nested-names and
|
|
|
|
/// typenames.
|
2008-11-27 05:51:07 +08:00
|
|
|
/// It will mainly be called when we expect to treat identifiers as typenames
|
|
|
|
/// (if they are typenames). For example, in C we do not expect identifiers
|
|
|
|
/// inside expressions to be treated as typenames so it will not be called
|
|
|
|
/// for expressions in C.
|
|
|
|
/// The benefit for C/ObjC is that a typename will be annotated and
|
2009-01-29 03:39:02 +08:00
|
|
|
/// Actions.getTypeName will not be needed to be called again (e.g. getTypeName
|
2008-11-27 05:51:07 +08:00
|
|
|
/// will not be called twice, once to check whether we have a declaration
|
|
|
|
/// specifier, and another one to get the actual type inside
|
|
|
|
/// ParseDeclarationSpecifiers).
|
2009-01-05 07:23:14 +08:00
|
|
|
///
|
2010-02-26 16:45:28 +08:00
|
|
|
/// This returns true if an error occurred.
|
2009-09-09 23:08:12 +08:00
|
|
|
///
|
2009-01-05 08:13:00 +08:00
|
|
|
/// Note that this routine emits an error if you call it with ::new or ::delete
|
|
|
|
/// as the current tokens, so only call it in contexts where these are invalid.
|
2011-10-11 09:02:41 +08:00
|
|
|
bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext, bool NeedType) {
|
2009-09-09 23:08:12 +08:00
|
|
|
assert((Tok.is(tok::identifier) || Tok.is(tok::coloncolon)
|
2011-12-04 13:04:18 +08:00
|
|
|
|| Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)
|
2012-05-15 06:43:34 +08:00
|
|
|
|| Tok.is(tok::kw_decltype) || Tok.is(tok::annot_template_id))
|
|
|
|
&& "Cannot be a type or scope token!");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-28 07:10:48 +08:00
|
|
|
if (Tok.is(tok::kw_typename)) {
|
2013-09-04 06:36:22 +08:00
|
|
|
// MSVC lets you do stuff like:
|
|
|
|
// typename typedef T_::D D;
|
|
|
|
//
|
|
|
|
// We will consume the typedef token here and put it back after we have
|
|
|
|
// parsed the first identifier, transforming it into something more like:
|
|
|
|
// typename T_::D typedef D;
|
|
|
|
if (getLangOpts().MicrosoftMode && NextToken().is(tok::kw_typedef)) {
|
|
|
|
Token TypedefToken;
|
|
|
|
PP.Lex(TypedefToken);
|
|
|
|
bool Result = TryAnnotateTypeOrScopeToken(EnteringContext, NeedType);
|
|
|
|
PP.EnterToken(Tok);
|
|
|
|
Tok = TypedefToken;
|
|
|
|
if (!Result)
|
|
|
|
Diag(Tok.getLocation(), diag::warn_expected_qualified_after_typename);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2009-03-28 07:10:48 +08:00
|
|
|
// Parse a C++ typename-specifier, e.g., "typename T::type".
|
|
|
|
//
|
|
|
|
// typename-specifier:
|
|
|
|
// 'typename' '::' [opt] nested-name-specifier identifier
|
2009-09-09 23:08:12 +08:00
|
|
|
// 'typename' '::' [opt] nested-name-specifier template [opt]
|
2009-04-01 08:28:59 +08:00
|
|
|
// simple-template-id
|
2009-03-28 07:10:48 +08:00
|
|
|
SourceLocation TypenameLoc = ConsumeToken();
|
|
|
|
CXXScopeSpec SS;
|
2011-11-08 01:33:42 +08:00
|
|
|
if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/ParsedType(),
|
|
|
|
/*EnteringContext=*/false,
|
2011-03-28 03:41:34 +08:00
|
|
|
0, /*IsTypename*/true))
|
2010-02-26 16:45:28 +08:00
|
|
|
return true;
|
|
|
|
if (!SS.isSet()) {
|
2012-07-22 23:10:57 +08:00
|
|
|
if (Tok.is(tok::identifier) || Tok.is(tok::annot_template_id) ||
|
|
|
|
Tok.is(tok::annot_decltype)) {
|
2012-05-15 06:43:34 +08:00
|
|
|
// Attempt to recover by skipping the invalid 'typename'
|
2012-07-22 23:10:57 +08:00
|
|
|
if (Tok.is(tok::annot_decltype) ||
|
|
|
|
(!TryAnnotateTypeOrScopeToken(EnteringContext, NeedType) &&
|
2013-09-04 06:36:22 +08:00
|
|
|
Tok.isAnnotation())) {
|
2012-05-15 06:43:34 +08:00
|
|
|
unsigned DiagID = diag::err_expected_qualified_after_typename;
|
|
|
|
// MS compatibility: MSVC permits using known types with typename.
|
|
|
|
// e.g. "typedef typename T* pointer_type"
|
|
|
|
if (getLangOpts().MicrosoftExt)
|
|
|
|
DiagID = diag::warn_expected_qualified_after_typename;
|
|
|
|
Diag(Tok.getLocation(), DiagID);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Diag(Tok.getLocation(), diag::err_expected_qualified_after_typename);
|
2010-02-26 16:45:28 +08:00
|
|
|
return true;
|
2009-03-28 07:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TypeResult Ty;
|
|
|
|
if (Tok.is(tok::identifier)) {
|
|
|
|
// FIXME: check whether the next token is '<', first!
|
2010-07-03 01:43:08 +08:00
|
|
|
Ty = Actions.ActOnTypenameType(getCurScope(), TypenameLoc, SS,
|
2010-06-17 06:31:08 +08:00
|
|
|
*Tok.getIdentifierInfo(),
|
2009-03-28 07:10:48 +08:00
|
|
|
Tok.getLocation());
|
2009-04-01 08:28:59 +08:00
|
|
|
} else if (Tok.is(tok::annot_template_id)) {
|
2011-06-22 14:09:49 +08:00
|
|
|
TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
|
2009-04-01 08:28:59 +08:00
|
|
|
if (TemplateId->Kind == TNK_Function_template) {
|
|
|
|
Diag(Tok, diag::err_typename_refers_to_non_type_template)
|
|
|
|
<< Tok.getAnnotationRange();
|
2010-02-26 16:45:28 +08:00
|
|
|
return true;
|
2009-04-01 08:28:59 +08:00
|
|
|
}
|
2009-03-28 07:10:48 +08:00
|
|
|
|
2012-08-24 07:38:35 +08:00
|
|
|
ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
|
2011-02-28 06:46:49 +08:00
|
|
|
TemplateId->NumArgs);
|
2012-02-07 06:45:07 +08:00
|
|
|
|
2011-02-28 06:46:49 +08:00
|
|
|
Ty = Actions.ActOnTypenameType(getCurScope(), TypenameLoc, SS,
|
2012-02-07 06:45:07 +08:00
|
|
|
TemplateId->TemplateKWLoc,
|
2011-02-28 06:46:49 +08:00
|
|
|
TemplateId->Template,
|
|
|
|
TemplateId->TemplateNameLoc,
|
|
|
|
TemplateId->LAngleLoc,
|
2012-02-07 06:45:07 +08:00
|
|
|
TemplateArgsPtr,
|
2011-02-28 06:46:49 +08:00
|
|
|
TemplateId->RAngleLoc);
|
2009-04-01 08:28:59 +08:00
|
|
|
} else {
|
|
|
|
Diag(Tok, diag::err_expected_type_name_after_typename)
|
|
|
|
<< SS.getRange();
|
2010-02-26 16:45:28 +08:00
|
|
|
return true;
|
2009-04-01 08:28:59 +08:00
|
|
|
}
|
|
|
|
|
2010-02-09 03:35:18 +08:00
|
|
|
SourceLocation EndLoc = Tok.getLastLoc();
|
2009-04-01 08:28:59 +08:00
|
|
|
Tok.setKind(tok::annot_typename);
|
2010-08-24 13:47:05 +08:00
|
|
|
setTypeAnnotation(Tok, Ty.isInvalid() ? ParsedType() : Ty.get());
|
2010-02-09 03:35:18 +08:00
|
|
|
Tok.setAnnotationEndLoc(EndLoc);
|
2009-04-01 08:28:59 +08:00
|
|
|
Tok.setLocation(TypenameLoc);
|
|
|
|
PP.AnnotateCachedTokens(Tok);
|
2010-02-26 16:45:28 +08:00
|
|
|
return false;
|
2009-03-28 07:10:48 +08:00
|
|
|
}
|
|
|
|
|
2009-12-19 08:35:18 +08:00
|
|
|
// Remembers whether the token was originally a scope annotation.
|
2012-08-18 08:55:03 +08:00
|
|
|
bool WasScopeAnnotation = Tok.is(tok::annot_cxxscope);
|
2009-12-19 08:35:18 +08:00
|
|
|
|
2008-11-09 00:45:02 +08:00
|
|
|
CXXScopeSpec SS;
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().CPlusPlus)
|
2010-08-24 13:47:05 +08:00
|
|
|
if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), EnteringContext))
|
2010-02-26 16:45:28 +08:00
|
|
|
return true;
|
2008-11-09 00:45:02 +08:00
|
|
|
|
2012-08-18 08:55:03 +08:00
|
|
|
return TryAnnotateTypeOrScopeTokenAfterScopeSpec(EnteringContext, NeedType,
|
|
|
|
SS, !WasScopeAnnotation);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Try to annotate a type or scope token, having already parsed an
|
|
|
|
/// optional scope specifier. \p IsNewScope should be \c true unless the scope
|
|
|
|
/// specifier was extracted from an existing tok::annot_cxxscope annotation.
|
|
|
|
bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool EnteringContext,
|
|
|
|
bool NeedType,
|
|
|
|
CXXScopeSpec &SS,
|
|
|
|
bool IsNewScope) {
|
2008-11-09 00:45:02 +08:00
|
|
|
if (Tok.is(tok::identifier)) {
|
2011-10-11 09:02:41 +08:00
|
|
|
IdentifierInfo *CorrectedII = 0;
|
2009-01-05 09:49:50 +08:00
|
|
|
// Determine whether the identifier is a type name.
|
2010-08-24 13:47:05 +08:00
|
|
|
if (ParsedType Ty = Actions.getTypeName(*Tok.getIdentifierInfo(),
|
|
|
|
Tok.getLocation(), getCurScope(),
|
2011-02-09 02:05:59 +08:00
|
|
|
&SS, false,
|
2011-03-02 02:12:44 +08:00
|
|
|
NextToken().is(tok::period),
|
|
|
|
ParsedType(),
|
2012-01-27 16:46:19 +08:00
|
|
|
/*IsCtorOrDtorName=*/false,
|
2011-10-11 09:02:41 +08:00
|
|
|
/*NonTrivialTypeSourceInfo*/true,
|
|
|
|
NeedType ? &CorrectedII : NULL)) {
|
|
|
|
// A FixIt was applied as a result of typo correction
|
|
|
|
if (CorrectedII)
|
|
|
|
Tok.setIdentifierInfo(CorrectedII);
|
2009-01-05 09:49:50 +08:00
|
|
|
// This is a typename. Replace the current token in-place with an
|
|
|
|
// annotation type token.
|
2009-01-06 13:06:21 +08:00
|
|
|
Tok.setKind(tok::annot_typename);
|
2010-08-24 13:47:05 +08:00
|
|
|
setTypeAnnotation(Tok, Ty);
|
2009-01-05 09:49:50 +08:00
|
|
|
Tok.setAnnotationEndLoc(Tok.getLocation());
|
|
|
|
if (SS.isNotEmpty()) // it was a C++ qualified type name.
|
|
|
|
Tok.setLocation(SS.getBeginLoc());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-01-05 09:49:50 +08:00
|
|
|
// In case the tokens were cached, have Preprocessor replace
|
|
|
|
// them with the annotation token.
|
|
|
|
PP.AnnotateCachedTokens(Tok);
|
2010-02-26 16:45:28 +08:00
|
|
|
return false;
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!getLangOpts().CPlusPlus) {
|
2009-01-05 09:49:50 +08:00
|
|
|
// If we're in C, we can't have :: tokens at all (the lexer won't return
|
|
|
|
// them). If the identifier is not a type, then it can't be scope either,
|
2009-09-09 23:08:12 +08:00
|
|
|
// just early exit.
|
2009-01-05 09:49:50 +08:00
|
|
|
return false;
|
2008-11-09 00:45:02 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
// If this is a template-id, annotate with a template-id or type token.
|
2009-02-10 02:46:07 +08:00
|
|
|
if (NextToken().is(tok::less)) {
|
2009-03-31 06:58:21 +08:00
|
|
|
TemplateTy Template;
|
2009-11-04 07:16:33 +08:00
|
|
|
UnqualifiedId TemplateName;
|
|
|
|
TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
|
2010-05-22 07:18:07 +08:00
|
|
|
bool MemberOfUnknownSpecialization;
|
2009-09-09 23:08:12 +08:00
|
|
|
if (TemplateNameKind TNK
|
2010-08-06 20:11:11 +08:00
|
|
|
= Actions.isTemplateName(getCurScope(), SS,
|
|
|
|
/*hasTemplateKeyword=*/false, TemplateName,
|
2010-08-24 13:47:05 +08:00
|
|
|
/*ObjectType=*/ ParsedType(),
|
|
|
|
EnteringContext,
|
2010-08-06 20:11:11 +08:00
|
|
|
Template, MemberOfUnknownSpecialization)) {
|
2009-11-04 08:56:37 +08:00
|
|
|
// Consume the identifier.
|
|
|
|
ConsumeToken();
|
2012-01-27 17:46:47 +08:00
|
|
|
if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(),
|
|
|
|
TemplateName)) {
|
2009-06-26 12:27:47 +08:00
|
|
|
// If an unrecoverable error occurred, we need to return true here,
|
|
|
|
// because the token stream is in a damaged state. We may not return
|
|
|
|
// a valid identifier.
|
2010-02-26 16:45:28 +08:00
|
|
|
return true;
|
2009-06-26 12:27:47 +08:00
|
|
|
}
|
2009-11-04 08:56:37 +08:00
|
|
|
}
|
2009-02-10 02:46:07 +08:00
|
|
|
}
|
2008-12-19 03:37:40 +08:00
|
|
|
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
// The current token, which is either an identifier or a
|
|
|
|
// template-id, is not part of the annotation. Fall through to
|
|
|
|
// push that token back into the stream and complete the C++ scope
|
|
|
|
// specifier annotation.
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2008-11-09 00:45:02 +08:00
|
|
|
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
if (Tok.is(tok::annot_template_id)) {
|
2011-06-22 14:09:49 +08:00
|
|
|
TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
|
2009-03-31 08:43:58 +08:00
|
|
|
if (TemplateId->Kind == TNK_Type_template) {
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
// A template-id that refers to a type was parsed into a
|
|
|
|
// template-id annotation in a context where we weren't allowed
|
|
|
|
// to produce a type annotation token. Update the template-id
|
|
|
|
// annotation token to a type annotation token now.
|
2011-03-02 08:47:37 +08:00
|
|
|
AnnotateTemplateIdTokenAsType();
|
2010-02-26 16:45:28 +08:00
|
|
|
return false;
|
2013-08-06 09:03:05 +08:00
|
|
|
} else if (TemplateId->Kind == TNK_Var_template)
|
|
|
|
return false;
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
}
|
2008-12-19 03:37:40 +08:00
|
|
|
|
2009-01-05 06:32:19 +08:00
|
|
|
if (SS.isEmpty())
|
2010-02-26 16:45:28 +08:00
|
|
|
return false;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-01-05 06:32:19 +08:00
|
|
|
// A C++ scope specifier that isn't followed by a typename.
|
2012-08-18 08:55:03 +08:00
|
|
|
AnnotateScopeToken(SS, IsNewScope);
|
2010-02-26 16:45:28 +08:00
|
|
|
return false;
|
2008-11-09 00:45:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
/// annotates C++ scope specifiers and template-ids. This returns
|
2012-05-09 16:23:23 +08:00
|
|
|
/// true if there was an error that could not be recovered from.
|
2009-09-09 23:08:12 +08:00
|
|
|
///
|
2009-01-05 08:13:00 +08:00
|
|
|
/// Note that this routine emits an error if you call it with ::new or ::delete
|
|
|
|
/// as the current tokens, so only call it in contexts where these are invalid.
|
Improve support for out-of-line definitions of nested templates and
their members, including member class template, member function
templates, and member classes and functions of member templates.
To actually parse the nested-name-specifiers that qualify the name of
an out-of-line definition of a member template, e.g.,
template<typename X> template<typename Y>
X Outer<X>::Inner1<Y>::foo(Y) {
return X();
}
we need to look for the template names (e.g., "Inner1") as a member of
the current instantiation (Outer<X>), even before we have entered the
scope of the current instantiation. Since we can't do this in general
(i.e., we should not be looking into all dependent
nested-name-specifiers as if they were the current instantiation), we
rely on the parser to tell us when it is parsing a declaration
specifier sequence, and, therefore, when we should consider the
current scope specifier to be a current instantiation.
Printing of complicated, dependent nested-name-specifiers may be
somewhat broken by this commit; I'll add tests for this issue and fix
the problem (if it still exists) in a subsequent commit.
llvm-svn: 80044
2009-08-26 06:51:20 +08:00
|
|
|
bool Parser::TryAnnotateCXXScopeToken(bool EnteringContext) {
|
2012-03-11 15:00:24 +08:00
|
|
|
assert(getLangOpts().CPlusPlus &&
|
2009-01-05 06:32:19 +08:00
|
|
|
"Call sites of this function should be guarded by checking for C++");
|
2011-04-27 12:48:22 +08:00
|
|
|
assert((Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
|
2011-12-04 13:04:18 +08:00
|
|
|
(Tok.is(tok::annot_template_id) && NextToken().is(tok::coloncolon)) ||
|
|
|
|
Tok.is(tok::kw_decltype)) && "Cannot be a type or scope token!");
|
2008-11-09 00:45:02 +08:00
|
|
|
|
2008-11-27 05:41:52 +08:00
|
|
|
CXXScopeSpec SS;
|
2010-08-24 13:47:05 +08:00
|
|
|
if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), EnteringContext))
|
2010-02-26 16:45:28 +08:00
|
|
|
return true;
|
2010-04-08 07:29:58 +08:00
|
|
|
if (SS.isEmpty())
|
2010-02-26 16:45:28 +08:00
|
|
|
return false;
|
2008-11-09 00:45:02 +08:00
|
|
|
|
2012-08-18 08:55:03 +08:00
|
|
|
AnnotateScopeToken(SS, true);
|
2010-02-26 16:45:28 +08:00
|
|
|
return false;
|
2008-11-09 00:45:02 +08:00
|
|
|
}
|
2009-11-04 03:33:12 +08:00
|
|
|
|
Extend the error of invalid token after declarations to include fixits for
!=, %=, ^=, &=, *=, -=, |=, /=, <<=, <=, >=, and >>= to =.
llvm-svn: 148499
2012-01-20 06:01:51 +08:00
|
|
|
bool Parser::isTokenEqualOrEqualTypo() {
|
|
|
|
tok::TokenKind Kind = Tok.getKind();
|
|
|
|
switch (Kind) {
|
|
|
|
default:
|
2012-01-19 06:54:52 +08:00
|
|
|
return false;
|
Extend the error of invalid token after declarations to include fixits for
!=, %=, ^=, &=, *=, -=, |=, /=, <<=, <=, >=, and >>= to =.
llvm-svn: 148499
2012-01-20 06:01:51 +08:00
|
|
|
case tok::ampequal: // &=
|
|
|
|
case tok::starequal: // *=
|
|
|
|
case tok::plusequal: // +=
|
|
|
|
case tok::minusequal: // -=
|
|
|
|
case tok::exclaimequal: // !=
|
|
|
|
case tok::slashequal: // /=
|
|
|
|
case tok::percentequal: // %=
|
|
|
|
case tok::lessequal: // <=
|
|
|
|
case tok::lesslessequal: // <<=
|
|
|
|
case tok::greaterequal: // >=
|
|
|
|
case tok::greatergreaterequal: // >>=
|
|
|
|
case tok::caretequal: // ^=
|
|
|
|
case tok::pipeequal: // |=
|
|
|
|
case tok::equalequal: // ==
|
|
|
|
Diag(Tok, diag::err_invalid_token_after_declarator_suggest_equal)
|
|
|
|
<< getTokenSimpleSpelling(Kind)
|
|
|
|
<< FixItHint::CreateReplacement(SourceRange(Tok.getLocation()), "=");
|
|
|
|
case tok::equal:
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-08 10:39:23 +08:00
|
|
|
}
|
|
|
|
|
2011-09-04 11:32:15 +08:00
|
|
|
SourceLocation Parser::handleUnexpectedCodeCompletionToken() {
|
|
|
|
assert(Tok.is(tok::code_completion));
|
|
|
|
PrevTokLocation = Tok.getLocation();
|
|
|
|
|
2010-07-03 01:43:08 +08:00
|
|
|
for (Scope *S = getCurScope(); S; S = S->getParent()) {
|
2010-05-25 13:58:43 +08:00
|
|
|
if (S->getFlags() & Scope::FnScope) {
|
2010-08-27 07:41:50 +08:00
|
|
|
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_RecoveryInFunction);
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
|
|
|
return PrevTokLocation;
|
2010-05-25 13:58:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (S->getFlags() & Scope::ClassScope) {
|
2010-08-27 07:41:50 +08:00
|
|
|
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Class);
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
|
|
|
return PrevTokLocation;
|
2010-05-25 13:58:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Namespace);
|
2011-09-04 11:32:15 +08:00
|
|
|
cutOffParsing();
|
|
|
|
return PrevTokLocation;
|
2010-05-25 13:58:43 +08:00
|
|
|
}
|
|
|
|
|
2009-11-04 03:33:12 +08:00
|
|
|
// Anchor the Parser::FieldCallback vtable to this translation unit.
|
|
|
|
// We use a spurious method instead of the destructor because
|
|
|
|
// destroying FieldCallbacks can actually be slightly
|
|
|
|
// performance-sensitive.
|
|
|
|
void Parser::FieldCallback::_anchor() {
|
|
|
|
}
|
2010-08-25 03:08:16 +08:00
|
|
|
|
|
|
|
// Code-completion pass-through functions
|
|
|
|
|
|
|
|
void Parser::CodeCompleteDirective(bool InConditional) {
|
2010-08-25 06:20:20 +08:00
|
|
|
Actions.CodeCompletePreprocessorDirective(InConditional);
|
2010-08-25 03:08:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::CodeCompleteInConditionalExclusion() {
|
|
|
|
Actions.CodeCompleteInPreprocessorConditionalExclusion(getCurScope());
|
|
|
|
}
|
2010-08-25 04:21:13 +08:00
|
|
|
|
|
|
|
void Parser::CodeCompleteMacroName(bool IsDefinition) {
|
2010-08-25 06:20:20 +08:00
|
|
|
Actions.CodeCompletePreprocessorMacroName(IsDefinition);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::CodeCompletePreprocessorExpression() {
|
|
|
|
Actions.CodeCompletePreprocessorExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::CodeCompleteMacroArgument(IdentifierInfo *Macro,
|
|
|
|
MacroInfo *MacroInfo,
|
|
|
|
unsigned ArgumentIndex) {
|
|
|
|
Actions.CodeCompletePreprocessorMacroArgument(getCurScope(), Macro, MacroInfo,
|
|
|
|
ArgumentIndex);
|
2010-08-25 04:21:13 +08:00
|
|
|
}
|
2010-08-26 01:04:25 +08:00
|
|
|
|
|
|
|
void Parser::CodeCompleteNaturalLanguage() {
|
|
|
|
Actions.CodeCompleteNaturalLanguage();
|
|
|
|
}
|
2011-05-08 01:30:27 +08:00
|
|
|
|
2011-10-25 06:31:10 +08:00
|
|
|
bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition& Result) {
|
2011-05-08 01:30:27 +08:00
|
|
|
assert((Tok.is(tok::kw___if_exists) || Tok.is(tok::kw___if_not_exists)) &&
|
|
|
|
"Expected '__if_exists' or '__if_not_exists'");
|
2011-10-25 06:31:10 +08:00
|
|
|
Result.IsIfExists = Tok.is(tok::kw___if_exists);
|
|
|
|
Result.KeywordLoc = ConsumeToken();
|
2011-05-08 01:30:27 +08:00
|
|
|
|
2011-10-13 00:37:45 +08:00
|
|
|
BalancedDelimiterTracker T(*this, tok::l_paren);
|
|
|
|
if (T.consumeOpen()) {
|
2011-10-25 06:31:10 +08:00
|
|
|
Diag(Tok, diag::err_expected_lparen_after)
|
|
|
|
<< (Result.IsIfExists? "__if_exists" : "__if_not_exists");
|
2011-05-08 01:30:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse nested-name-specifier.
|
2011-11-08 01:33:42 +08:00
|
|
|
ParseOptionalCXXScopeSpecifier(Result.SS, ParsedType(),
|
|
|
|
/*EnteringContext=*/false);
|
2011-05-08 01:30:27 +08:00
|
|
|
|
|
|
|
// Check nested-name specifier.
|
2011-10-25 06:31:10 +08:00
|
|
|
if (Result.SS.isInvalid()) {
|
|
|
|
T.skipToEnd();
|
2011-05-08 01:30:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-27 17:46:47 +08:00
|
|
|
// Parse the unqualified-id.
|
|
|
|
SourceLocation TemplateKWLoc; // FIXME: parsed, but unused.
|
|
|
|
if (ParseUnqualifiedId(Result.SS, false, true, true, ParsedType(),
|
|
|
|
TemplateKWLoc, Result.Name)) {
|
2011-10-25 06:31:10 +08:00
|
|
|
T.skipToEnd();
|
2011-05-08 01:30:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-25 06:31:10 +08:00
|
|
|
if (T.consumeClose())
|
2011-05-08 01:30:27 +08:00
|
|
|
return true;
|
2011-10-25 06:31:10 +08:00
|
|
|
|
2011-05-08 01:30:27 +08:00
|
|
|
// Check if the symbol exists.
|
2011-10-25 11:44:56 +08:00
|
|
|
switch (Actions.CheckMicrosoftIfExistsSymbol(getCurScope(), Result.KeywordLoc,
|
|
|
|
Result.IsIfExists, Result.SS,
|
2011-10-25 06:31:10 +08:00
|
|
|
Result.Name)) {
|
|
|
|
case Sema::IER_Exists:
|
|
|
|
Result.Behavior = Result.IsIfExists ? IEB_Parse : IEB_Skip;
|
|
|
|
break;
|
2011-05-08 01:30:27 +08:00
|
|
|
|
2011-10-25 06:31:10 +08:00
|
|
|
case Sema::IER_DoesNotExist:
|
|
|
|
Result.Behavior = !Result.IsIfExists ? IEB_Parse : IEB_Skip;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Sema::IER_Dependent:
|
|
|
|
Result.Behavior = IEB_Dependent;
|
|
|
|
break;
|
2011-10-25 11:44:56 +08:00
|
|
|
|
|
|
|
case Sema::IER_Error:
|
|
|
|
return true;
|
2011-10-25 06:31:10 +08:00
|
|
|
}
|
2011-05-08 01:30:27 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-25 18:19:49 +08:00
|
|
|
void Parser::ParseMicrosoftIfExistsExternalDeclaration() {
|
2011-10-25 06:31:10 +08:00
|
|
|
IfExistsCondition Result;
|
2011-05-08 01:30:27 +08:00
|
|
|
if (ParseMicrosoftIfExistsCondition(Result))
|
|
|
|
return;
|
|
|
|
|
2011-10-25 06:31:10 +08:00
|
|
|
BalancedDelimiterTracker Braces(*this, tok::l_brace);
|
|
|
|
if (Braces.consumeOpen()) {
|
2011-05-08 01:30:27 +08:00
|
|
|
Diag(Tok, diag::err_expected_lbrace);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-25 06:31:10 +08:00
|
|
|
switch (Result.Behavior) {
|
|
|
|
case IEB_Parse:
|
|
|
|
// Parse declarations below.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IEB_Dependent:
|
|
|
|
llvm_unreachable("Cannot have a dependent external declaration");
|
|
|
|
|
|
|
|
case IEB_Skip:
|
|
|
|
Braces.skipToEnd();
|
2011-05-08 01:30:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-25 06:31:10 +08:00
|
|
|
// Parse the declarations.
|
|
|
|
while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
|
2011-05-08 01:30:27 +08:00
|
|
|
ParsedAttributesWithRange attrs(AttrFactory);
|
2013-01-02 20:01:23 +08:00
|
|
|
MaybeParseCXX11Attributes(attrs);
|
2011-05-08 01:30:27 +08:00
|
|
|
MaybeParseMicrosoftAttributes(attrs);
|
|
|
|
DeclGroupPtrTy Result = ParseExternalDeclaration(attrs);
|
|
|
|
if (Result && !getCurScope()->getParent())
|
|
|
|
Actions.getASTConsumer().HandleTopLevelDecl(Result.get());
|
2011-10-25 06:31:10 +08:00
|
|
|
}
|
|
|
|
Braces.consumeClose();
|
2011-05-08 01:30:27 +08:00
|
|
|
}
|
2011-08-27 07:56:07 +08:00
|
|
|
|
2012-01-04 02:04:46 +08:00
|
|
|
Parser::DeclGroupPtrTy Parser::ParseModuleImport(SourceLocation AtLoc) {
|
2012-12-12 06:11:52 +08:00
|
|
|
assert(Tok.isObjCAtKeyword(tok::objc_import) &&
|
2011-09-01 02:19:09 +08:00
|
|
|
"Improper start to module import");
|
2011-08-27 07:56:07 +08:00
|
|
|
SourceLocation ImportLoc = ConsumeToken();
|
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
|
2011-11-30 08:36:36 +08:00
|
|
|
|
|
|
|
// Parse the module path.
|
|
|
|
do {
|
|
|
|
if (!Tok.is(tok::identifier)) {
|
2012-01-30 02:15:03 +08:00
|
|
|
if (Tok.is(tok::code_completion)) {
|
|
|
|
Actions.CodeCompleteModuleImport(ImportLoc, Path);
|
|
|
|
ConsumeCodeCompletionToken();
|
|
|
|
SkipUntil(tok::semi);
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
}
|
|
|
|
|
2011-11-30 08:36:36 +08:00
|
|
|
Diag(Tok, diag::err_module_expected_ident);
|
|
|
|
SkipUntil(tok::semi);
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record this part of the module path.
|
|
|
|
Path.push_back(std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation()));
|
|
|
|
ConsumeToken();
|
|
|
|
|
|
|
|
if (Tok.is(tok::period)) {
|
|
|
|
ConsumeToken();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} while (true);
|
2013-05-24 13:44:08 +08:00
|
|
|
|
|
|
|
if (PP.hadModuleLoaderFatalFailure()) {
|
|
|
|
// With a fatal failure in the module loader, we abort parsing.
|
|
|
|
cutOffParsing();
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
}
|
|
|
|
|
2012-01-04 02:04:46 +08:00
|
|
|
DeclResult Import = Actions.ActOnModuleImport(AtLoc, ImportLoc, Path);
|
2011-08-27 07:56:07 +08:00
|
|
|
ExpectAndConsumeSemi(diag::err_module_expected_semi);
|
|
|
|
if (Import.isInvalid())
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
|
|
|
|
return Actions.ConvertDeclToDeclGroup(Import.get());
|
|
|
|
}
|
2011-10-13 00:37:45 +08:00
|
|
|
|
2012-06-07 05:18:07 +08:00
|
|
|
bool BalancedDelimiterTracker::diagnoseOverflow() {
|
2013-02-22 09:59:51 +08:00
|
|
|
P.Diag(P.Tok, diag::err_bracket_depth_exceeded)
|
|
|
|
<< P.getLangOpts().BracketDepth;
|
|
|
|
P.Diag(P.Tok, diag::note_bracket_depth);
|
2013-07-25 10:11:20 +08:00
|
|
|
P.SkipUntil(tok::eof, false);
|
2012-03-08 09:00:17 +08:00
|
|
|
return true;
|
2011-10-13 00:37:45 +08:00
|
|
|
}
|
|
|
|
|
2012-06-07 05:18:07 +08:00
|
|
|
bool BalancedDelimiterTracker::expectAndConsume(unsigned DiagID,
|
2011-10-13 00:37:45 +08:00
|
|
|
const char *Msg,
|
|
|
|
tok::TokenKind SkipToToc ) {
|
|
|
|
LOpen = P.Tok.getLocation();
|
2012-03-08 09:00:17 +08:00
|
|
|
if (P.ExpectAndConsume(Kind, DiagID, Msg, SkipToToc))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (getDepth() < MaxDepth)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return diagnoseOverflow();
|
2011-10-13 00:37:45 +08:00
|
|
|
}
|
|
|
|
|
2012-06-07 05:18:07 +08:00
|
|
|
bool BalancedDelimiterTracker::diagnoseMissingClose() {
|
2012-03-08 09:00:17 +08:00
|
|
|
assert(!P.Tok.is(Close) && "Should have consumed closing delimiter");
|
|
|
|
|
|
|
|
const char *LHSName = "unknown";
|
2012-04-07 07:33:59 +08:00
|
|
|
diag::kind DID;
|
2012-03-08 09:00:17 +08:00
|
|
|
switch (Close) {
|
2012-04-07 07:33:59 +08:00
|
|
|
default: llvm_unreachable("Unexpected balanced token");
|
2012-03-08 09:00:17 +08:00
|
|
|
case tok::r_paren : LHSName = "("; DID = diag::err_expected_rparen; break;
|
|
|
|
case tok::r_brace : LHSName = "{"; DID = diag::err_expected_rbrace; break;
|
|
|
|
case tok::r_square: LHSName = "["; DID = diag::err_expected_rsquare; break;
|
2011-10-13 00:37:45 +08:00
|
|
|
}
|
2012-03-08 09:00:17 +08:00
|
|
|
P.Diag(P.Tok, DID);
|
|
|
|
P.Diag(LOpen, diag::note_matching) << LHSName;
|
2013-05-13 12:18:18 +08:00
|
|
|
if (P.SkipUntil(Close, FinalToken, /*StopAtSemi*/ true, /*DontConsume*/ true)
|
|
|
|
&& P.Tok.is(Close))
|
2012-11-08 03:08:05 +08:00
|
|
|
LClose = P.ConsumeAnyToken();
|
2011-10-13 00:37:45 +08:00
|
|
|
return true;
|
|
|
|
}
|
2011-10-25 06:31:10 +08:00
|
|
|
|
2012-06-07 05:18:07 +08:00
|
|
|
void BalancedDelimiterTracker::skipToEnd() {
|
2011-10-25 06:31:10 +08:00
|
|
|
P.SkipUntil(Close, false);
|
|
|
|
}
|