blob: ffcdad8d6e5007a0a23546e6243db25e9a925da9 [file] [log] [blame]
Chris Lattner22eb9722006-06-18 05:43:12 +00001//===--- MacroExpander.cpp - Lex from a macro expansion -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the MacroExpander interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Lex/MacroExpander.h"
15#include "clang/Lex/MacroInfo.h"
16#include "clang/Lex/Preprocessor.h"
17using namespace llvm;
18using namespace clang;
19
20/// Lex - Lex and return a token from this macro stream.
21bool MacroExpander::Lex(LexerToken &Tok) {
22 // Lexing off the end of the macro, pop this macro off the expansion stack.
23 if (CurToken == Macro.getNumTokens())
24 return PP.HandleEndOfMacro(Tok);
25
26 // Get the next token to return.
27 Tok = Macro.getReplacementToken(CurToken++);
28
29 // If this is the first token, set the lexical properties of the token to
30 // match the lexical properties of the macro identifier.
31 if (CurToken == 1) {
32 Tok.SetFlagValue(LexerToken::StartOfLine , AtStartOfLine);
33 Tok.SetFlagValue(LexerToken::LeadingSpace, HasLeadingSpace);
34 }
35
36 // Handle recursive expansion!
37 if (Tok.getIdentifierInfo())
38 return PP.HandleIdentifier(Tok);
39
40 // Otherwise, return a normal token.
41 return false;
42}