зеркало из https://github.com/microsoft/clang-1.git
rename the MacroExpander class to TokenLexer. It handles both
token streams and macro lexing, so a more generic name is useful. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48071 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
8d89643803
Коммит
1543e9c692
|
@ -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 @@ MacroArgs::getPreExpArgument(unsigned Arg, Preprocessor &PP) {
|
|||
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 @@ const Token &MacroArgs::getStringifiedArgument(unsigned ArgNo,
|
|||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// 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 @@ void MacroExpander::Init(Token &Tok, MacroArgs *Actuals) {
|
|||
|
||||
|
||||
|
||||
/// 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::Init(const Token *TokArray, unsigned NumToks) {
|
|||
}
|
||||
|
||||
|
||||
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 @@ void MacroExpander::destroy() {
|
|||
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 @@ void MacroExpander::ExpandFunctionArguments() {
|
|||
|
||||
/// 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 @@ void MacroExpander::Lex(Token &Tok) {
|
|||
/// 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 @@ bool MacroExpander::PasteTokens(Token &Tok) {
|
|||
}
|
||||
}
|
||||
|
||||
// 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 @@ bool MacroExpander::PasteTokens(Token &Tok) {
|
|||
/// 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 @@ unsigned MacroExpander::isNextTokenLParen() const {
|
|||
/// 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.
|
||||
|
||||
|
|
|
@ -620,7 +620,7 @@ void Preprocessor::EnterMacro(Token &Tok, MacroArgs *Args) {
|
|||
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 @@ void Preprocessor::EnterTokenStream(const Token *Toks, unsigned NumToks) {
|
|||
|
||||
// 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);
|
||||
|
|
|
@ -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 @@ public:
|
|||
};
|
||||
|
||||
|
||||
/// 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 @@ class MacroExpander {
|
|||
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
|
||||
|
|
|
@ -98,7 +98,7 @@ class Preprocessor {
|
|||
|
||||
/// 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 @@ class Preprocessor {
|
|||
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 @@ class Preprocessor {
|
|||
/// 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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче