ScratchBuffer.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- ScratchBuffer.h - Scratch space for forming tokens -----*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the ScratchBuffer interface.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_LEX_SCRATCHBUFFER_H
  18. #define LLVM_CLANG_LEX_SCRATCHBUFFER_H
  19. #include "clang/Basic/SourceLocation.h"
  20. namespace clang {
  21. class SourceManager;
  22. /// ScratchBuffer - This class exposes a simple interface for the dynamic
  23. /// construction of tokens. This is used for builtin macros (e.g. __LINE__) as
  24. /// well as token pasting, etc.
  25. class ScratchBuffer {
  26. SourceManager &SourceMgr;
  27. char *CurBuffer;
  28. SourceLocation BufferStartLoc;
  29. unsigned BytesUsed;
  30. public:
  31. ScratchBuffer(SourceManager &SM);
  32. /// getToken - Splat the specified text into a temporary MemoryBuffer and
  33. /// return a SourceLocation that refers to the token. This is just like the
  34. /// previous method, but returns a location that indicates the physloc of the
  35. /// token.
  36. SourceLocation getToken(const char *Buf, unsigned Len, const char *&DestPtr);
  37. private:
  38. void AllocScratchBuffer(unsigned RequestLen);
  39. };
  40. } // end namespace clang
  41. #endif
  42. #ifdef __GNUC__
  43. #pragma GCC diagnostic pop
  44. #endif