]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/d/dmd/root/outbuffer.h
b635373c1838956dc1349b452047abd5b13eb1f1
[thirdparty/gcc.git] / gcc / d / dmd / root / outbuffer.h
1
2 /* Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved
3 * written by Walter Bright
4 * http://www.digitalmars.com
5 * Distributed under the Boost Software License, Version 1.0.
6 * http://www.boost.org/LICENSE_1_0.txt
7 * https://github.com/dlang/dmd/blob/master/src/dmd/root/outbuffer.h
8 */
9
10 #pragma once
11
12 #include "dsystem.h"
13 #include "dcompat.h"
14 #include "rmem.h"
15
16 class RootObject;
17
18 struct OutBuffer
19 {
20 // IMPORTANT: PLEASE KEEP STATE AND DESTRUCTOR IN SYNC WITH DEFINITION IN ./outbuffer.d.
21 private:
22 DArray<unsigned char> data;
23 d_size_t offset;
24 bool notlinehead;
25 void* fileMapping; // pointer to a file mapping object not used on the C++ side
26 public:
27 bool doindent;
28 bool spaces;
29 int level;
30
31 OutBuffer()
32 {
33 data = DArray<unsigned char>();
34 offset = 0;
35
36 doindent = 0;
37 level = 0;
38 notlinehead = 0;
39 fileMapping = 0;
40 }
41 ~OutBuffer()
42 {
43 mem.xfree(data.ptr);
44 }
45 d_size_t length() const { return offset; }
46 char *extractData();
47 void destroy();
48
49 void reserve(d_size_t nbytes);
50 void setsize(d_size_t size);
51 void reset();
52 void write(const void *data, size_t nbytes);
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);
63 void write(const OutBuffer *buf);
64 void write(RootObject *obj);
65 void fill0(d_size_t nbytes);
66 void vprintf(const char *format, va_list args);
67 void printf(const char *format, ...);
68 void bracket(char left, char right);
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);
73 // Append terminating null if necessary and get view of internal buffer
74 char *peekChars();
75 // Append terminating null if necessary and take ownership of data
76 char *extractChars();
77 };