[cfe-commits] r48071 - in /cfe/trunk: Lex/MacroExpander.cpp Lex/Preprocessor.cpp include/clang/Lex/MacroExpander.h include/clang/Lex/Preprocessor.h
Chris Lattner
sabre at nondot.org
Sat Mar 8 18:18:51 PST 2008
Author: lattner
Date: Sat Mar 8 20:18:51 2008
New Revision: 48071
URL: http://llvm.org/viewvc/llvm-project?rev=48071&view=rev
Log:
rename the MacroExpander class to TokenLexer. It handles both
token streams and macro lexing, so a more generic name is useful.
Modified:
cfe/trunk/Lex/MacroExpander.cpp
cfe/trunk/Lex/Preprocessor.cpp
cfe/trunk/include/clang/Lex/MacroExpander.h
cfe/trunk/include/clang/Lex/Preprocessor.h
Modified: cfe/trunk/Lex/MacroExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/MacroExpander.cpp?rev=48071&r1=48070&r2=48071&view=diff
==============================================================================
--- cfe/trunk/Lex/MacroExpander.cpp (original)
+++ cfe/trunk/Lex/MacroExpander.cpp Sat Mar 8 20:18:51 2008
@@ -1,4 +1,4 @@
-//===--- MacroExpander.cpp - Lex from a macro expansion -------------------===//
+//===--- TokenLexer.cpp - Lex from a token stream -------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
//
-// This file implements the MacroExpander interface.
+// This file implements the TokenLexer interface.
//
//===----------------------------------------------------------------------===//
@@ -115,7 +115,7 @@
unsigned NumToks = getArgLength(AT)+1; // Include the EOF.
// Otherwise, we have to pre-expand this argument, populating Result. To do
- // this, we set up a fake MacroExpander to lex from the unexpanded argument
+ // this, we set up a fake TokenLexer to lex from the unexpanded argument
// list. With this installed, we lex expanded tokens until we hit the EOF
// token at the end of the unexp list.
PP.EnterTokenStream(AT, NumToks);
@@ -229,13 +229,13 @@
}
//===----------------------------------------------------------------------===//
-// MacroExpander Implementation
+// TokenLexer Implementation
//===----------------------------------------------------------------------===//
-/// Create a macro expander for the specified macro with the specified actual
+/// Create a TokenLexer for the specified macro with the specified actual
/// arguments. Note that this ctor takes ownership of the ActualArgs pointer.
-void MacroExpander::Init(Token &Tok, MacroArgs *Actuals) {
- // If the client is reusing a macro expander, make sure to free any memory
+void TokenLexer::Init(Token &Tok, MacroArgs *Actuals) {
+ // If the client is reusing a TokenLexer, make sure to free any memory
// associated with it.
destroy();
@@ -262,10 +262,10 @@
-/// Create a macro expander for the specified token stream. This does not
+/// Create a TokenLexer for the specified token stream. This does not
/// take ownership of the specified token vector.
-void MacroExpander::Init(const Token *TokArray, unsigned NumToks) {
- // If the client is reusing a macro expander, make sure to free any memory
+void TokenLexer::Init(const Token *TokArray, unsigned NumToks) {
+ // If the client is reusing a TokenLexer, make sure to free any memory
// associated with it.
destroy();
@@ -288,7 +288,7 @@
}
-void MacroExpander::destroy() {
+void TokenLexer::destroy() {
// If this was a function-like macro that actually uses its arguments, delete
// the expanded tokens.
if (OwnsTokens) {
@@ -296,13 +296,13 @@
Tokens = 0;
}
- // MacroExpander owns its formal arguments.
+ // TokenLexer owns its formal arguments.
if (ActualArgs) ActualArgs->destroy();
}
/// Expand the arguments of a function-like macro so that we can quickly
/// return preexpanded tokens from Tokens.
-void MacroExpander::ExpandFunctionArguments() {
+void TokenLexer::ExpandFunctionArguments() {
llvm::SmallVector<Token, 128> ResultToks;
// Loop through 'Tokens', expanding them into ResultToks. Keep
@@ -481,7 +481,7 @@
/// Lex - Lex and return a token from this macro stream.
///
-void MacroExpander::Lex(Token &Tok) {
+void TokenLexer::Lex(Token &Tok) {
// Lexing off the end of the macro, pop this macro off the expansion stack.
if (isAtEnd()) {
// If this is a macro (not a token stream), mark the macro enabled now
@@ -543,7 +543,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.
/// If this returns true, the caller should immediately return the token.
-bool MacroExpander::PasteTokens(Token &Tok) {
+bool TokenLexer::PasteTokens(Token &Tok) {
llvm::SmallVector<char, 128> Buffer;
do {
// Consume the ## operator.
@@ -640,7 +640,8 @@
}
}
- // Turn ## into 'other' to avoid # ## # from looking like a paste operator.
+ // Turn ## into 'unknown' to avoid # ## # from looking like a paste
+ // operator.
if (Result.is(tok::hashhash))
Result.setKind(tok::unknown);
// FIXME: Turn __VA_ARGS__ into "not a token"?
@@ -668,7 +669,7 @@
/// isNextTokenLParen - If the next token lexed will pop this macro off the
/// expansion stack, return 2. If the next unexpanded token is a '(', return
/// 1, otherwise return 0.
-unsigned MacroExpander::isNextTokenLParen() const {
+unsigned TokenLexer::isNextTokenLParen() const {
// Out of tokens?
if (isAtEnd())
return 2;
@@ -681,7 +682,7 @@
/// macro, other active macros, and anything left on the current physical
/// source line of the instantiated buffer. Handle this by returning the
/// first token on the next line.
-void MacroExpander::HandleMicrosoftCommentPaste(Token &Tok) {
+void TokenLexer::HandleMicrosoftCommentPaste(Token &Tok) {
// We 'comment out' the rest of this macro by just ignoring the rest of the
// tokens that have not been lexed yet, if any.
Modified: cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Preprocessor.cpp?rev=48071&r1=48070&r2=48071&view=diff
==============================================================================
--- cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/Lex/Preprocessor.cpp Sat Mar 8 20:18:51 2008
@@ -620,7 +620,7 @@
CurDirLookup = 0;
if (NumCachedMacroExpanders == 0) {
- CurMacroExpander = new MacroExpander(Tok, Args, *this);
+ CurMacroExpander = new TokenLexer(Tok, Args, *this);
} else {
CurMacroExpander = MacroExpanderCache[--NumCachedMacroExpanders];
CurMacroExpander->Init(Tok, Args);
@@ -641,7 +641,7 @@
// Create a macro expander to expand from the specified token stream.
if (NumCachedMacroExpanders == 0) {
- CurMacroExpander = new MacroExpander(Toks, NumToks, *this);
+ CurMacroExpander = new TokenLexer(Toks, NumToks, *this);
} else {
CurMacroExpander = MacroExpanderCache[--NumCachedMacroExpanders];
CurMacroExpander->Init(Toks, NumToks);
Modified: cfe/trunk/include/clang/Lex/MacroExpander.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroExpander.h?rev=48071&r1=48070&r2=48071&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/MacroExpander.h (original)
+++ cfe/trunk/include/clang/Lex/MacroExpander.h Sat Mar 8 20:18:51 2008
@@ -1,4 +1,4 @@
-//===--- MacroExpander.h - Lex from a macro expansion -----------*- C++ -*-===//
+//===--- TokenLexer.h - Lex from a token buffer -----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,12 +7,12 @@
//
//===----------------------------------------------------------------------===//
//
-// This file defines the MacroExpander and MacroArgs interfaces.
+// This file defines the TokenLexer and MacroArgs interfaces.
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_MACROEXPANDER_H
-#define LLVM_CLANG_MACROEXPANDER_H
+#ifndef LLVM_CLANG_TOKENLEXER_H
+#define LLVM_CLANG_TOKENLEXER_H
#include "clang/Basic/SourceLocation.h"
#include <vector>
@@ -98,17 +98,17 @@
};
-/// MacroExpander - This implements a lexer that returns token from a macro body
+/// TokenLexer - This implements a lexer that returns token from a macro body
/// or token stream instead of lexing from a character buffer.
///
-class MacroExpander {
+class TokenLexer {
/// Macro - The macro we are expanding from. This is null if expanding a
/// token stream.
///
MacroInfo *Macro;
/// ActualArgs - The actual arguments specified for a function-like macro, or
- /// null. The MacroExpander owns the pointed-to object.
+ /// null. The TokenLexer owns the pointed-to object.
MacroArgs *ActualArgs;
/// PP - The current preprocessor object we are expanding for.
@@ -137,39 +137,39 @@
bool AtStartOfLine : 1;
bool HasLeadingSpace : 1;
- /// OwnsTokens - This is true if this MacroExpander allocated the Tokens
+ /// OwnsTokens - This is true if this TokenLexer allocated the Tokens
/// array, and thus needs to free it when destroyed. For simple object-like
/// macros (for example) we just point into the token buffer of the macro
/// definition, we don't make a copy of it.
bool OwnsTokens : 1;
- MacroExpander(const MacroExpander&); // DO NOT IMPLEMENT
- void operator=(const MacroExpander&); // DO NOT IMPLEMENT
+ TokenLexer(const TokenLexer&); // DO NOT IMPLEMENT
+ void operator=(const TokenLexer&); // DO NOT IMPLEMENT
public:
- /// Create a macro expander for the specified macro with the specified actual
+ /// Create a TokenLexer for the specified macro with the specified actual
/// arguments. Note that this ctor takes ownership of the ActualArgs pointer.
- MacroExpander(Token &Tok, MacroArgs *ActualArgs, Preprocessor &pp)
+ TokenLexer(Token &Tok, MacroArgs *ActualArgs, Preprocessor &pp)
: Macro(0), ActualArgs(0), PP(pp), OwnsTokens(false) {
Init(Tok, ActualArgs);
}
- /// Init - Initialize this macro expander to expand from the specified macro
+ /// Init - Initialize this TokenLexer to expand from the specified macro
/// with the specified argument information. Note that this ctor takes
/// ownership of the ActualArgs pointer.
void Init(Token &Tok, MacroArgs *ActualArgs);
- /// Create a macro expander for the specified token stream. This does not
+ /// Create a TokenLexer for the specified token stream. This does not
/// take ownership of the specified token vector.
- MacroExpander(const Token *TokArray, unsigned NumToks, Preprocessor &pp)
+ TokenLexer(const Token *TokArray, unsigned NumToks, Preprocessor &pp)
: Macro(0), ActualArgs(0), PP(pp), OwnsTokens(false) {
Init(TokArray, NumToks);
}
- /// Init - Initialize this macro expander with the specified token stream.
+ /// Init - Initialize this TokenLexer with the specified token stream.
/// This does not take ownership of the specified token vector.
void Init(const Token *TokArray, unsigned NumToks);
- ~MacroExpander() { destroy(); }
+ ~TokenLexer() { destroy(); }
/// isNextTokenLParen - If the next token lexed will pop this macro off the
/// expansion stack, return 2. If the next unexpanded token is a '(', return
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=48071&r1=48070&r2=48071&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sat Mar 8 20:18:51 2008
@@ -98,7 +98,7 @@
/// CurMacroExpander - This is the current macro we are expanding, if we are
/// expanding a macro. One of CurLexer and CurMacroExpander must be null.
- MacroExpander *CurMacroExpander;
+ TokenLexer *CurMacroExpander;
/// IncludeMacroStack - This keeps track of the stack of files currently
/// #included, and macros currently being expanded from, not counting
@@ -106,9 +106,9 @@
struct IncludeStackInfo {
Lexer *TheLexer;
const DirectoryLookup *TheDirLookup;
- MacroExpander *TheMacroExpander;
- IncludeStackInfo(Lexer *L, const DirectoryLookup *D, MacroExpander *M)
- : TheLexer(L), TheDirLookup(D), TheMacroExpander(M) {
+ TokenLexer *TheMacroExpander;
+ IncludeStackInfo(Lexer *L, const DirectoryLookup *D, TokenLexer *TL)
+ : TheLexer(L), TheDirLookup(D), TheMacroExpander(TL) {
}
};
std::vector<IncludeStackInfo> IncludeMacroStack;
@@ -136,7 +136,7 @@
/// MacroExpanderCache - Cache macro expanders to reduce malloc traffic.
enum { MacroExpanderCacheSize = 8 };
unsigned NumCachedMacroExpanders;
- MacroExpander *MacroExpanderCache[MacroExpanderCacheSize];
+ TokenLexer *MacroExpanderCache[MacroExpanderCacheSize];
public:
Preprocessor(Diagnostic &diags, const LangOptions &opts, TargetInfo &target,
SourceManager &SM, HeaderSearch &Headers);
More information about the cfe-commits
mailing list