mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-02 07:26:08 +00:00

Now, instead of keeping a pointer to the start of the token in memory, we keep the start of the token as a SourceLocation node. This means that each LexerToken knows the full include stack it was created with, and means that the LexerToken isn't reliant on a "CurLexer" member to be around (lexer tokens would previously go out of scope when their lexers were deallocated). This simplifies several things, and forces good cleanup elsewhere. Now the Preprocessor is the one that knows how to dump tokens/macros and is the one that knows how to get the spelling of a token (it has all the context). llvm-svn: 38551
54 lines
1.7 KiB
C++
54 lines
1.7 KiB
C++
//===--- MacroExpander.cpp - Lex from a macro expansion -------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the MacroExpander interface.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/Lex/MacroExpander.h"
|
|
#include "clang/Lex/MacroInfo.h"
|
|
#include "clang/Lex/Preprocessor.h"
|
|
using namespace llvm;
|
|
using namespace clang;
|
|
|
|
MacroExpander::MacroExpander(LexerToken &Tok, Preprocessor &pp)
|
|
: Macro(*Tok.getIdentifierInfo()->getMacroInfo()), PP(pp), CurToken(0),
|
|
InstantiateLoc(Tok.getSourceLocation()),
|
|
AtStartOfLine(Tok.isAtStartOfLine()),
|
|
HasLeadingSpace(Tok.hasLeadingSpace()) {
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Lex - Lex and return a token from this macro stream.
|
|
///
|
|
void MacroExpander::Lex(LexerToken &Tok) {
|
|
// Lexing off the end of the macro, pop this macro off the expansion stack.
|
|
if (CurToken == Macro.getNumTokens())
|
|
return PP.HandleEndOfMacro(Tok);
|
|
|
|
// Get the next token to return.
|
|
Tok = Macro.getReplacementToken(CurToken++);
|
|
//Tok.SetLocation(InstantiateLoc);
|
|
|
|
// If this is the first token, set the lexical properties of the token to
|
|
// match the lexical properties of the macro identifier.
|
|
if (CurToken == 1) {
|
|
Tok.SetFlagValue(LexerToken::StartOfLine , AtStartOfLine);
|
|
Tok.SetFlagValue(LexerToken::LeadingSpace, HasLeadingSpace);
|
|
}
|
|
|
|
// Handle recursive expansion!
|
|
if (Tok.getIdentifierInfo())
|
|
return PP.HandleIdentifier(Tok);
|
|
|
|
// Otherwise, return a normal token.
|
|
}
|