PreprocessorLexer.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //===--- PreprocessorLexer.cpp - C Language Family Lexer ------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the PreprocessorLexer and Token interfaces.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/Lex/PreprocessorLexer.h"
  14. #include "clang/Basic/SourceManager.h"
  15. #include "clang/Lex/LexDiagnostic.h"
  16. #include "clang/Lex/Preprocessor.h"
  17. using namespace clang;
  18. void PreprocessorLexer::anchor() { }
  19. PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
  20. : PP(pp), FID(fid), InitialNumSLocEntries(0),
  21. ParsingPreprocessorDirective(false),
  22. ParsingFilename(false), LexingRawMode(false) {
  23. if (pp)
  24. InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
  25. }
  26. /// \brief After the preprocessor has parsed a \#include, lex and
  27. /// (potentially) macro expand the filename.
  28. void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
  29. assert(ParsingPreprocessorDirective &&
  30. ParsingFilename == false &&
  31. "Must be in a preprocessing directive!");
  32. // We are now parsing a filename!
  33. ParsingFilename = true;
  34. // Lex the filename.
  35. if (LexingRawMode)
  36. IndirectLex(FilenameTok);
  37. else
  38. PP->Lex(FilenameTok);
  39. // We should have obtained the filename now.
  40. ParsingFilename = false;
  41. // No filename?
  42. if (FilenameTok.is(tok::eod))
  43. PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
  44. }
  45. /// getFileEntry - Return the FileEntry corresponding to this FileID. Like
  46. /// getFileID(), this only works for lexers with attached preprocessors.
  47. const FileEntry *PreprocessorLexer::getFileEntry() const {
  48. return PP->getSourceManager().getFileEntryForID(getFileID());
  49. }