summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdemangle/common/rust.h
blob: fbe609ab9db9c1919ec73a9a5d8a73c16d9d9750 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2019 Joyent, Inc.
 * Copyright 2021 Jason King
 */

#ifndef _RUST_H
#define	_RUST_H

#include <errno.h>
#include <sys/types.h>
#include "demangle-sys.h"
#include "demangle_int.h"
#include "strview.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum rustenc_version {
	RUSTENC_LEGACY = -1,
	RUSTENC_V0 = 0
} rustenc_version_t;

typedef struct rust_state {
	const char	*rs_str; /* The original string */
	custr_t		*rs_demangled;
	sysdem_ops_t	*rs_ops;
	custr_alloc_t	rs_cualloc;
	strview_t	rs_orig; /* strview of original string, sans prefix */
	int		rs_error;
	rustenc_version_t rs_encver;
	uint64_t	rs_lt_depth;
	boolean_t	rs_skip;
	boolean_t	rs_args_stay_open;
	boolean_t	rs_args_is_open;
	boolean_t	rs_verbose;
	boolean_t	rs_show_const_type;
	boolean_t	rs_isutf8;
} rust_state_t;
#define	HAS_ERROR(_st) ((_st)->rs_error != 0)
#define	SET_ERROR(_st) ((_st)->rs_error = errno)

/*
 * In certain circumstances, we need to parse an item, but not emit any
 * output. These macros assist in that. To use:
 *
 * rust_state_t *st;
 * boolean_t saved_state;
 * ...
 * SKIP_BEGIN(st, saved_state);
 * ... stuff to no emit
 * SKIP_END(st, saved_state);
 */
#define	SKIP_BEGIN(_st, _save)		\
	(_save) = (_st)->rs_skip,	\
	(_st)->rs_skip = B_TRUE
#define	SKIP_END(_st, _n) (_st)->rs_skip = (_n)

boolean_t rust_appendc(rust_state_t *, char);
boolean_t rust_append(rust_state_t *, const char *);
boolean_t rust_append_printf(rust_state_t *, const char *, ...) __PRINTFLIKE(2);
boolean_t rust_append_sv(rust_state_t *restrict, uint64_t, strview_t *restrict);
boolean_t rust_append_utf8_c(rust_state_t *, uint32_t);
boolean_t rust_parse_base10(rust_state_t *restrict, strview_t *restrict,
    uint64_t *restrict);
boolean_t rust_demangle_legacy(rust_state_t *restrict, strview_t *restrict);
boolean_t rust_demangle_v0(rust_state_t *restrict, strview_t *restrict);

boolean_t rustv0_puny_decode(rust_state_t *restrict, strview_t *restrict,
    boolean_t);

#ifdef __cplusplus
}
#endif

#endif /* _RUST_H */