//===--- MacroExpansion.cpp - Top level Macro Expansion -------------------===////// The LLVM Compiler Infrastructure//// This file is distributed under the University of Illinois Open Source// License. See LICENSE.TXT for details.////===----------------------------------------------------------------------===////// This file implements the top level handling of macro expasion for the// preprocessor.////===----------------------------------------------------------------------===//#include"clang/Lex/Preprocessor.h"#include"clang/Lex/MacroArgs.h"#include"clang/Basic/FileManager.h"#include"clang/Basic/SourceManager.h"#include"clang/Basic/TargetInfo.h"#include"clang/Lex/CodeCompletionHandler.h"#include"clang/Lex/ExternalPreprocessorSource.h"#include"clang/Lex/LexDiagnostic.h"#include"clang/Lex/MacroInfo.h"#include"llvm/ADT/STLExtras.h"#include"llvm/ADT/SmallString.h"#include"llvm/ADT/StringSwitch.h"#include"llvm/Config/llvm-config.h"#include"llvm/Support/ErrorHandling.h"#include"llvm/Support/Format.h"#include"llvm/Support/raw_ostream.h"#include<cstdio>#include<ctime>usingnamespaceclang;MacroDirective*Preprocessor::getMacroDirectiveHistory(constIdentifierInfo*II)const{assert(II->hadMacroDefinition()&&"Identifier has not been not a macro!");macro_iteratorPos=Macros.find(II);assert(Pos!=Macros.end()&&"Identifier macro info is missing!");returnPos->second;}voidPreprocessor::appendMacroDirective(IdentifierInfo*II,MacroDirective*MD){assert(MD&&"MacroDirective should be non-zero!");assert(!MD->getPrevious()&&"Already attached to a MacroDirective history.");MacroDirective*&StoredMD=Macros[II];MD->setPrevious(StoredMD);StoredMD=MD;II->setHasMacroDefinition(MD->isDefined());boolisImportedMacro=isa<DefMacroDirective>(MD)&&cast<DefMacroDirective>(MD)->isImported();if(II->isFromAST()&&!isImportedMacro)II->setChangedSinceDeserialization();}voidPreprocessor::setLoadedMacroDirective(IdentifierInfo*II,MacroDirective*MD){assert(II&&MD);MacroDirective*&StoredMD=Macros[II];assert(!StoredMD&&"the macro history was modified before initializing it from a pch");StoredMD=MD;// Setup the identifier as having associated macro history.II->setHasMacroDefinition(true);if(!MD->isDefined())II->setHasMacroDefinition(false);}/// RegisterBuiltinMacro - Register the specified identifier in the identifier/// table and mark it as a builtin macro to be expanded.staticIdentifierInfo*RegisterBuiltinMacro(Preprocessor&PP,constchar*Name){// Get the identifier.