Chris Lattner | 22eb972 | 2006-06-18 05:43:12 +0000 | [diff] [blame^] | 1 | //===--- 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" |
| 17 | using namespace llvm; |
| 18 | using namespace clang; |
| 19 | |
| 20 | /// Lex - Lex and return a token from this macro stream. |
| 21 | bool 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 | } |