10b57cec5SDimitry Andric //===--- ScratchBuffer.h - Scratch space for forming tokens -----*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file defines the ScratchBuffer interface. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #ifndef LLVM_CLANG_LEX_SCRATCHBUFFER_H 140b57cec5SDimitry Andric #define LLVM_CLANG_LEX_SCRATCHBUFFER_H 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric #include "clang/Basic/SourceLocation.h" 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric namespace clang { 190b57cec5SDimitry Andric class SourceManager; 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric /// ScratchBuffer - This class exposes a simple interface for the dynamic 220b57cec5SDimitry Andric /// construction of tokens. This is used for builtin macros (e.g. __LINE__) as 230b57cec5SDimitry Andric /// well as token pasting, etc. 240b57cec5SDimitry Andric class ScratchBuffer { 250b57cec5SDimitry Andric SourceManager &SourceMgr; 260b57cec5SDimitry Andric char *CurBuffer; 270b57cec5SDimitry Andric SourceLocation BufferStartLoc; 280b57cec5SDimitry Andric unsigned BytesUsed; 290b57cec5SDimitry Andric public: 300b57cec5SDimitry Andric ScratchBuffer(SourceManager &SM); 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric /// getToken - Splat the specified text into a temporary MemoryBuffer and 330b57cec5SDimitry Andric /// return a SourceLocation that refers to the token. This is just like the 340b57cec5SDimitry Andric /// previous method, but returns a location that indicates the physloc of the 350b57cec5SDimitry Andric /// token. 360b57cec5SDimitry Andric SourceLocation getToken(const char *Buf, unsigned Len, const char *&DestPtr); 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric private: 390b57cec5SDimitry Andric void AllocScratchBuffer(unsigned RequestLen); 400b57cec5SDimitry Andric }; 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric } // end namespace clang 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric #endif 45