[mlir][int-range] Limit xor int range inference to i1 (#116968)
[llvm-project.git] / lldb / tools / lldb-dap / IOStream.h
blob57d5fd458b7165d4bafe5700e13185b225325813
1 //===-- IOStream.h ----------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_TOOLS_LLDB_DAP_IOSTREAM_H
10 #define LLDB_TOOLS_LLDB_DAP_IOSTREAM_H
12 #if defined(_WIN32)
13 // We need to #define NOMINMAX in order to skip `min()` and `max()` macro
14 // definitions that conflict with other system headers.
15 // We also need to #undef GetObject (which is defined to GetObjectW) because
16 // the JSON code we use also has methods named `GetObject()` and we conflict
17 // against these.
18 #define NOMINMAX
19 #include <windows.h>
20 #else
21 typedef int SOCKET;
22 #endif
24 #include "llvm/ADT/StringRef.h"
26 #include <fstream>
27 #include <string>
29 // Windows requires different system calls for dealing with sockets and other
30 // types of files, so we can't simply have one code path that just uses read
31 // and write everywhere. So we need an abstraction in order to allow us to
32 // treat them identically.
33 namespace lldb_dap {
34 struct StreamDescriptor {
35 StreamDescriptor();
36 ~StreamDescriptor();
37 StreamDescriptor(StreamDescriptor &&other);
39 StreamDescriptor &operator=(StreamDescriptor &&other);
41 static StreamDescriptor from_socket(SOCKET s, bool close);
42 static StreamDescriptor from_file(int fd, bool close);
44 bool m_is_socket = false;
45 bool m_close = false;
46 union {
47 int m_fd;
48 SOCKET m_socket;
52 struct InputStream {
53 StreamDescriptor descriptor;
55 bool read_full(std::ofstream *log, size_t length, std::string &text);
57 bool read_line(std::ofstream *log, std::string &line);
59 bool read_expected(std::ofstream *log, llvm::StringRef expected);
62 struct OutputStream {
63 StreamDescriptor descriptor;
65 bool write_full(llvm::StringRef str);
67 } // namespace lldb_dap
69 #endif