[cfe-commits] r39102 - /cfe/cfe/trunk/Lex/MacroExpander.cpp
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:27:32 PDT 2007
Author: sabre
Date: Wed Jul 11 11:27:32 2007
New Revision: 39102
URL: http://llvm.org/viewvc/llvm-project?rev=39102&view=rev
Log:
implement FIXME: replace use of alloca with use of SmallVector.
Modified:
cfe/cfe/trunk/Lex/MacroExpander.cpp
Modified: cfe/cfe/trunk/Lex/MacroExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/MacroExpander.cpp?rev=39102&r1=39101&r2=39102&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/MacroExpander.cpp (original)
+++ cfe/cfe/trunk/Lex/MacroExpander.cpp Wed Jul 11 11:27:32 2007
@@ -17,7 +17,6 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Diagnostic.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/Config/Alloca.h"
using namespace llvm;
using namespace clang;
@@ -510,6 +509,7 @@
/// operator. Read the ## and RHS, and paste the LHS/RHS together. If there
/// are is another ## after it, chomp it iteratively. Return the result as Tok.
void MacroExpander::PasteTokens(LexerToken &Tok) {
+ SmallVector<char, 128> Buffer;
do {
// Consume the ## operator.
SourceLocation PasteOpLoc = MacroTokens[CurToken].getLocation();
@@ -523,26 +523,28 @@
// Allocate space for the result token. This is guaranteed to be enough for
// the two tokens and a null terminator.
- // FIXME: Use a smallvector here.
- char *Buffer = (char*)alloca(Tok.getLength() + RHS.getLength() + 1);
+ Buffer.resize(Tok.getLength() + RHS.getLength() + 1);
// Get the spelling of the LHS token in Buffer.
- const char *BufPtr = Buffer;
+ const char *BufPtr = &Buffer[0];
unsigned LHSLen = PP.getSpelling(Tok, BufPtr);
- if (BufPtr != Buffer) // Really, we want the chars in Buffer!
- memcpy(Buffer, BufPtr, LHSLen);
+ if (BufPtr != &Buffer[0]) // Really, we want the chars in Buffer!
+ memcpy(&Buffer[0], BufPtr, LHSLen);
- BufPtr = Buffer+LHSLen;
+ BufPtr = &Buffer[LHSLen];
unsigned RHSLen = PP.getSpelling(RHS, BufPtr);
- if (BufPtr != Buffer+LHSLen) // Really, we want the chars in Buffer!
- memcpy(Buffer+LHSLen, BufPtr, RHSLen);
+ if (BufPtr != &Buffer[LHSLen]) // Really, we want the chars in Buffer!
+ memcpy(&Buffer[LHSLen], BufPtr, RHSLen);
// Add null terminator.
Buffer[LHSLen+RHSLen] = '\0';
+ // Trim excess space.
+ Buffer.resize(LHSLen+RHSLen+1);
+
// Plop the pasted result (including the trailing newline and null) into a
// scratch buffer where we can lex it.
- SourceLocation ResultTokLoc = PP.CreateString(Buffer, LHSLen+RHSLen+1);
+ SourceLocation ResultTokLoc = PP.CreateString(&Buffer[0], Buffer.size());
// Lex the resultant pasted token into Result.
LexerToken Result;
@@ -596,7 +598,7 @@
if (isInvalid) {
// If not in assembler language mode.
PP.Diag(PasteOpLoc, diag::err_pp_bad_paste,
- std::string(Buffer, Buffer+LHSLen+RHSLen));
+ std::string(Buffer.begin(), Buffer.end()-1));
return;
}
More information about the cfe-commits
mailing list