summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
authorKaelyn Uhrain <rikka@google.com>2011-10-11 01:02:41 +0000
committerKaelyn Uhrain <rikka@google.com>2011-10-11 01:02:41 +0000
commit85308c6ecd19f1bc230ed7888fe0dd7910e3facc (patch)
treeaa1e9313119bee3bc5e247b9346d257c5c3eef3d /clang/lib/Parse/Parser.cpp
parent03eec6048300a2644f6cc044f677fada993eae81 (diff)
downloadbcm5719-llvm-85308c6ecd19f1bc230ed7888fe0dd7910e3facc.tar.gz
bcm5719-llvm-85308c6ecd19f1bc230ed7888fe0dd7910e3facc.zip
Add typo correction for type names.
The main motivation was to do typo correction in C++ "new" statements, though picking it up in other places where type names are expected was pretty much a freebie. llvm-svn: 141621
Diffstat (limited to 'clang/lib/Parse/Parser.cpp')
-rw-r--r--clang/lib/Parse/Parser.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 131bd9d3c5a..05a2b15abf9 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1204,7 +1204,7 @@ TemplateIdAnnotation *Parser::takeTemplateIdAnnotation(const Token &tok) {
///
/// 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.
-bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext) {
+bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext, bool NeedType) {
assert((Tok.is(tok::identifier) || Tok.is(tok::coloncolon)
|| Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)) &&
"Cannot be a type or scope token!");
@@ -1278,13 +1278,18 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext) {
return true;
if (Tok.is(tok::identifier)) {
+ IdentifierInfo *CorrectedII = 0;
// Determine whether the identifier is a type name.
if (ParsedType Ty = Actions.getTypeName(*Tok.getIdentifierInfo(),
Tok.getLocation(), getCurScope(),
&SS, false,
NextToken().is(tok::period),
ParsedType(),
- /*NonTrivialTypeSourceInfo*/true)) {
+ /*NonTrivialTypeSourceInfo*/true,
+ NeedType ? &CorrectedII : NULL)) {
+ // A FixIt was applied as a result of typo correction
+ if (CorrectedII)
+ Tok.setIdentifierInfo(CorrectedII);
// This is a typename. Replace the current token in-place with an
// annotation type token.
Tok.setKind(tok::annot_typename);
OpenPOWER on IntegriCloud