aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/Pragma.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2011-02-26 22:09:03 +0000
committerDimitry Andric <dim@FreeBSD.org>2011-02-26 22:09:03 +0000
commitc3b054d250cdca485c71845089c316e10610ebad (patch)
treeabae0246ec9156cc1a7cbb947b2b0dfe95fa3189 /lib/Lex/Pragma.cpp
parentbca07a4524feb4edec581062d631a13116320a24 (diff)
downloadsrc-c3b054d250cdca485c71845089c316e10610ebad.tar.gz
src-c3b054d250cdca485c71845089c316e10610ebad.zip
Vendor import of clang trunk r126547:vendor/clang/clang-r126547
Notes
Notes: svn path=/vendor/clang/dist/; revision=219069 svn path=/vendor/clang/clang-r126547/; revision=219070; tag=vendor/clang/clang-r126547
Diffstat (limited to 'lib/Lex/Pragma.cpp')
-rw-r--r--lib/Lex/Pragma.cpp68
1 files changed, 31 insertions, 37 deletions
diff --git a/lib/Lex/Pragma.cpp b/lib/Lex/Pragma.cpp
index f0475bc0cb20..80d3bb1d2790 100644
--- a/lib/Lex/Pragma.cpp
+++ b/lib/Lex/Pragma.cpp
@@ -110,7 +110,8 @@ void Preprocessor::HandlePragmaDirective(unsigned Introducer) {
PragmaHandlers->HandlePragma(*this, PragmaIntroducerKind(Introducer), Tok);
// If the pragma handler didn't read the rest of the line, consume it now.
- if (CurPPLexer && CurPPLexer->ParsingPreprocessorDirective)
+ if ((CurTokenLexer && CurTokenLexer->isParsingPreprocessorDirective())
+ || (CurPPLexer && CurPPLexer->ParsingPreprocessorDirective))
DiscardUntilEndOfDirective();
}
@@ -174,7 +175,22 @@ void Preprocessor::Handle_Pragma(Token &Tok) {
}
}
- Handle_Pragma(PIK__Pragma, StrVal, PragmaLoc, RParenLoc);
+ // Plop the string (including the newline and trailing null) into a buffer
+ // where we can lex it.
+ Token TmpTok;
+ TmpTok.startToken();
+ CreateString(&StrVal[0], StrVal.size(), TmpTok);
+ SourceLocation TokLoc = TmpTok.getLocation();
+
+ // Make and enter a lexer object so that we lex and expand the tokens just
+ // like any others.
+ Lexer *TL = Lexer::Create_PragmaLexer(TokLoc, PragmaLoc, RParenLoc,
+ StrVal.size(), *this);
+
+ EnterSourceFileWithLexer(TL, 0);
+
+ // With everything set up, lex this as a #pragma directive.
+ HandlePragmaDirective(PIK__Pragma);
// Finally, return whatever came after the pragma directive.
return Lex(Tok);
@@ -193,16 +209,16 @@ void Preprocessor::HandleMicrosoft__pragma(Token &Tok) {
return;
}
- // Get the tokens enclosed within the __pragma().
+ // Get the tokens enclosed within the __pragma(), as well as the final ')'.
llvm::SmallVector<Token, 32> PragmaToks;
int NumParens = 0;
Lex(Tok);
while (Tok.isNot(tok::eof)) {
+ PragmaToks.push_back(Tok);
if (Tok.is(tok::l_paren))
NumParens++;
else if (Tok.is(tok::r_paren) && NumParens-- == 0)
break;
- PragmaToks.push_back(Tok);
Lex(Tok);
}
@@ -211,45 +227,23 @@ void Preprocessor::HandleMicrosoft__pragma(Token &Tok) {
return;
}
- // Build the pragma string.
- std::string StrVal = " ";
- for (llvm::SmallVector<Token, 32>::iterator I =
- PragmaToks.begin(), E = PragmaToks.end(); I != E; ++I) {
- StrVal += getSpelling(*I);
- }
-
- SourceLocation RParenLoc = Tok.getLocation();
-
- Handle_Pragma(PIK___pragma, StrVal, PragmaLoc, RParenLoc);
+ PragmaToks.front().setFlag(Token::LeadingSpace);
- // Finally, return whatever came after the pragma directive.
- return Lex(Tok);
-}
+ // Replace the ')' with an EOM to mark the end of the pragma.
+ PragmaToks.back().setKind(tok::eom);
-void Preprocessor::Handle_Pragma(unsigned Introducer,
- const std::string &StrVal,
- SourceLocation PragmaLoc,
- SourceLocation RParenLoc) {
+ Token *TokArray = new Token[PragmaToks.size()];
+ std::copy(PragmaToks.begin(), PragmaToks.end(), TokArray);
- // Plop the string (including the newline and trailing null) into a buffer
- // where we can lex it.
- Token TmpTok;
- TmpTok.startToken();
- CreateString(&StrVal[0], StrVal.size(), TmpTok);
- SourceLocation TokLoc = TmpTok.getLocation();
-
- // Make and enter a lexer object so that we lex and expand the tokens just
- // like any others.
- Lexer *TL = Lexer::Create_PragmaLexer(TokLoc, PragmaLoc, RParenLoc,
- StrVal.size(), *this);
-
- EnterSourceFileWithLexer(TL, 0);
+ // Push the tokens onto the stack.
+ EnterTokenStream(TokArray, PragmaToks.size(), true, true);
// With everything set up, lex this as a #pragma directive.
- HandlePragmaDirective(Introducer);
-}
-
+ HandlePragmaDirective(PIK___pragma);
+ // Finally, return whatever came after the pragma directive.
+ return Lex(Tok);
+}
/// HandlePragmaOnce - Handle #pragma once. OnceTok is the 'once'.
///