PreprocessorLexer.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===- PreprocessorLexer.cpp - C Language Family Lexer --------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the PreprocessorLexer and Token interfaces.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/Lex/PreprocessorLexer.h"
  13. #include "clang/Basic/SourceManager.h"
  14. #include "clang/Lex/LexDiagnostic.h"
  15. #include "clang/Lex/Preprocessor.h"
  16. #include "clang/Lex/Token.h"
  17. #include <cassert>
  18. using namespace clang;
  19. void PreprocessorLexer::anchor() {}
  20. PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
  21. : PP(pp), FID(fid) {
  22. if (pp)
  23. InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
  24. }
  25. /// After the preprocessor has parsed a \#include, lex and
  26. /// (potentially) macro expand the filename.
  27. void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
  28. assert(ParsingFilename == false && "reentered LexIncludeFilename");
  29. // We are now parsing a filename!
  30. ParsingFilename = true;
  31. // Lex the filename.
  32. if (LexingRawMode)
  33. IndirectLex(FilenameTok);
  34. else
  35. PP->Lex(FilenameTok);
  36. // We should have obtained the filename now.
  37. ParsingFilename = false;
  38. }
  39. /// getFileEntry - Return the FileEntry corresponding to this FileID. Like
  40. /// getFileID(), this only works for lexers with attached preprocessors.
  41. const FileEntry *PreprocessorLexer::getFileEntry() const {
  42. return PP->getSourceManager().getFileEntryForID(getFileID());
  43. }