]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/d/dmd/common/outbuffer.h
d: Merge upstream dmd, druntime 09faa4eacd, phobos 13ef27a56.
[thirdparty/gcc.git] / gcc / d / dmd / common / outbuffer.h
CommitLineData
b4c522fa 1
f99303eb 2/* Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved
5fee5ec3 3 * written by Walter Bright
c43b5909 4 * https://www.digitalmars.com
b4c522fa 5 * Distributed under the Boost Software License, Version 1.0.
c43b5909 6 * https://www.boost.org/LICENSE_1_0.txt
0fb57034 7 * https://github.com/dlang/dmd/blob/master/src/dmd/common/outbuffer.h
b4c522fa
IB
8 */
9
10#pragma once
11
0fb57034
IB
12#include "../root/dsystem.h"
13#include "../root/dcompat.h"
14#include "../root/rmem.h"
b4c522fa
IB
15
16class RootObject;
17
18struct OutBuffer
19{
5fee5ec3 20 // IMPORTANT: PLEASE KEEP STATE AND DESTRUCTOR IN SYNC WITH DEFINITION IN ./outbuffer.d.
d103f336
IB
21private:
22 DArray<unsigned char> data;
5fee5ec3 23 d_size_t offset;
d103f336 24 bool notlinehead;
0fb57034 25 void *fileMapping; // pointer to a file mapping object not used on the C++ side
d103f336 26public:
b4c522fa 27 bool doindent;
5fee5ec3
IB
28 bool spaces;
29 int level;
b4c522fa
IB
30
31 OutBuffer()
32 {
d103f336 33 data = DArray<unsigned char>();
b4c522fa 34 offset = 0;
b4c522fa
IB
35
36 doindent = 0;
37 level = 0;
38 notlinehead = 0;
5fee5ec3 39 fileMapping = 0;
b4c522fa
IB
40 }
41 ~OutBuffer()
42 {
d103f336 43 mem.xfree(data.ptr);
b4c522fa 44 }
5fee5ec3 45 d_size_t length() const { return offset; }
b4c522fa 46 char *extractData();
5fee5ec3 47 void destroy();
b4c522fa 48
5fee5ec3
IB
49 void reserve(d_size_t nbytes);
50 void setsize(d_size_t size);
b4c522fa 51 void reset();
9c7d5e88 52 void write(const void *data, d_size_t nbytes);
b4c522fa
IB
53 void writestring(const char *string);
54 void prependstring(const char *string);
55 void writenl(); // write newline
56 void writeByte(unsigned b);
57 void writeUTF8(unsigned b);
58 void prependbyte(unsigned b);
59 void writewchar(unsigned w);
60 void writeword(unsigned w);
61 void writeUTF16(unsigned w);
62 void write4(unsigned w);
5fee5ec3 63 void write(const OutBuffer *buf);
b4c522fa 64 void write(RootObject *obj);
5fee5ec3 65 void fill0(d_size_t nbytes);
b4c522fa
IB
66 void vprintf(const char *format, va_list args);
67 void printf(const char *format, ...);
68 void bracket(char left, char right);
5fee5ec3
IB
69 d_size_t bracket(d_size_t i, const char *left, d_size_t j, const char *right);
70 void spread(d_size_t offset, d_size_t nbytes);
71 d_size_t insert(d_size_t offset, const void *data, d_size_t nbytes);
72 void remove(d_size_t offset, d_size_t nbytes);
b4c522fa 73 // Append terminating null if necessary and get view of internal buffer
fced594b 74 char *peekChars();
b4c522fa 75 // Append terminating null if necessary and take ownership of data
fced594b 76 char *extractChars();
b4c522fa 77};