ScratchBuffer.h revision 5f016e2cb5d11daeb237544de1c5d59f20fe1a6e
1//===--- ScratchBuffer.h - Scratch space for forming tokens -----*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the ScratchBuffer interface.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_SCRATCHBUFFER_H
15#define LLVM_CLANG_SCRATCHBUFFER_H
16
17namespace clang {
18  class SourceManager;
19  class SourceLocation;
20
21/// ScratchBuffer - This class exposes a simple interface for the dynamic
22/// construction of tokens.  This is used for builtin macros (e.g. __LINE__) as
23/// well as token pasting, etc.
24class ScratchBuffer {
25  SourceManager &SourceMgr;
26  char *CurBuffer;
27  unsigned FileID;
28  unsigned BytesUsed;
29public:
30  ScratchBuffer(SourceManager &SM);
31
32  /// getToken - Splat the specified text into a temporary MemoryBuffer and
33  /// return a SourceLocation that refers to the token.  The SourceLoc value
34  /// gives a virtual location that the token will appear to be from.
35  SourceLocation getToken(const char *Buf, unsigned Len,
36                          SourceLocation SourceLoc);
37
38  /// getToken - Splat the specified text into a temporary MemoryBuffer and
39  /// return a SourceLocation that refers to the token.  This is just like the
40  /// previous method, but returns a location that indicates the physloc of the
41  /// token.
42  SourceLocation getToken(const char *Buf, unsigned Len);
43
44private:
45  void AllocScratchBuffer(unsigned RequestLen);
46};
47
48} // end namespace clang
49
50#endif
51