PreprocessorLexer.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. OptionalFileEntryRefDegradesToFileEntryPtr
  42. PreprocessorLexer::getFileEntry() const {
  43. return PP->getSourceManager().getFileEntryRefForID(getFileID());
  44. }