clang API Documentation

ScratchBuffer.h
Go to the documentation of this file.
00001 //===--- ScratchBuffer.h - Scratch space for forming tokens -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines the ScratchBuffer interface.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_LEX_SCRATCHBUFFER_H
00015 #define LLVM_CLANG_LEX_SCRATCHBUFFER_H
00016 
00017 #include "clang/Basic/SourceLocation.h"
00018 
00019 namespace clang {
00020   class SourceManager;
00021 
00022 /// ScratchBuffer - This class exposes a simple interface for the dynamic
00023 /// construction of tokens.  This is used for builtin macros (e.g. __LINE__) as
00024 /// well as token pasting, etc.
00025 class ScratchBuffer {
00026   SourceManager &SourceMgr;
00027   char *CurBuffer;
00028   SourceLocation BufferStartLoc;
00029   unsigned BytesUsed;
00030 public:
00031   ScratchBuffer(SourceManager &SM);
00032 
00033   /// getToken - Splat the specified text into a temporary MemoryBuffer and
00034   /// return a SourceLocation that refers to the token.  This is just like the
00035   /// previous method, but returns a location that indicates the physloc of the
00036   /// token.
00037   SourceLocation getToken(const char *Buf, unsigned Len, const char *&DestPtr);
00038 
00039 private:
00040   void AllocScratchBuffer(unsigned RequestLen);
00041 };
00042 
00043 } // end namespace clang
00044 
00045 #endif