GDBserver

format.h
Go to the documentation of this file.
1 /* Parse a printf-style format string.
2
3 Copyright (C) 1986-2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef COMMON_FORMAT_H
21 #define COMMON_FORMAT_H
22
23 #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG)
24 # define USE_PRINTF_I64 1
25 # define PRINTF_HAS_LONG_LONG
26 #else
27 # define USE_PRINTF_I64 0
28 #endif
29
30 /* The argclass represents the general type of data that goes with a
31 format directive; int_arg for %d, long_arg for %l, and so forth.
32 Note that these primarily distinguish types by size and need for
33 special handling, so for instance %u and %x are (at present) also
34 classed as int_arg. */
35
36 enum argclass
37 {
38 literal_piece,
39 int_arg, long_arg, long_long_arg, ptr_arg,
40 string_arg, wide_string_arg, wide_char_arg,
41 double_arg, long_double_arg,
42 dec32float_arg, dec64float_arg, dec128float_arg
43 };
44
45 /* A format piece is a section of the format string that may include a
46 single print directive somewhere in it, and the associated class
47 for the argument. */
48
49 struct format_piece
50 {
51 format_piece (const char *str, enum argclass argc)
52 : string (str),
53 argclass (argc)
54 {
55 }
56
57 const char *string;
58 enum argclass argclass;
59 };
60
61 class format_pieces
62 {
63 public:
64
65 format_pieces (const char **arg);
66 ~format_pieces () = default;
67
68 DISABLE_COPY_AND_ASSIGN (format_pieces);
69
70 format_piece &operator[] (size_t index)
71 {
72 return m_pieces[index];
73 }
74
75 typedef std::vector<format_piece>::iterator iterator;
76
77 iterator begin ()
78 {
79 return m_pieces.begin ();
80 }
81
82 iterator end ()
83 {
84 return m_pieces.end ();
85 }
86
87 private:
88
89 std::vector<format_piece> m_pieces;
90 gdb::unique_xmalloc_ptr<char> m_storage;
91 };
92
93 #endif /* COMMON_FORMAT_H */
format_pieces::end
iterator end()
Definition: format.h:82
wide_string_arg
Definition: format.h:40
argclass
argclass
Definition: format.h:36
dec64float_arg
Definition: format.h:42
long_arg
Definition: format.h:39
format_pieces::m_storage
gdb::unique_xmalloc_ptr< char > m_storage
Definition: format.h:90
format_pieces::~format_pieces
~format_pieces()=default
format_pieces::format_pieces
format_pieces(const char **arg)
Definition: format.c:23
gdb::unique_xmalloc_ptr
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
Definition: gdb_unique_ptr.h:48
wide_char_arg
Definition: format.h:40
dec128float_arg
Definition: format.h:42
format_piece::string
const char * string
Definition: format.h:57
ptr_arg
Definition: format.h:39
format_piece::argclass
enum argclass argclass
Definition: format.h:58
long_long_arg
Definition: format.h:39
dec32float_arg
Definition: format.h:42
format_pieces::begin
iterator begin()
Definition: format.h:77
long_double_arg
Definition: format.h:41
literal_piece
Definition: format.h:38
format_pieces::operator[]
format_piece & operator[](size_t index)
Definition: format.h:70
format_piece::format_piece
format_piece(const char *str, enum argclass argc)
Definition: format.h:51
format_piece
Definition: format.h:49
double_arg
Definition: format.h:41
format_pieces
Definition: format.h:61
format_pieces::iterator
std::vector< format_piece >::iterator iterator
Definition: format.h:75
format_pieces::DISABLE_COPY_AND_ASSIGN
DISABLE_COPY_AND_ASSIGN(format_pieces)
int_arg
Definition: format.h:39
format_pieces::m_pieces
std::vector< format_piece > m_pieces
Definition: format.h:89
string_arg
Definition: format.h:40