yarp 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -8
- data/CONTRIBUTING.md +2 -2
- data/Makefile +5 -5
- data/README.md +11 -12
- data/config.yml +6 -2
- data/docs/build_system.md +21 -21
- data/docs/building.md +4 -4
- data/docs/configuration.md +25 -21
- data/docs/design.md +2 -2
- data/docs/encoding.md +17 -17
- data/docs/fuzzing.md +4 -4
- data/docs/heredocs.md +3 -3
- data/docs/mapping.md +94 -94
- data/docs/ripper.md +4 -4
- data/docs/ruby_api.md +11 -11
- data/docs/serialization.md +17 -16
- data/docs/testing.md +6 -6
- data/ext/prism/api_node.c +4725 -0
- data/ext/{yarp → prism}/api_pack.c +82 -82
- data/ext/{yarp → prism}/extconf.rb +13 -13
- data/ext/{yarp → prism}/extension.c +175 -168
- data/ext/prism/extension.h +18 -0
- data/include/prism/ast.h +1932 -0
- data/include/prism/defines.h +45 -0
- data/include/prism/diagnostic.h +231 -0
- data/include/{yarp/enc/yp_encoding.h → prism/enc/pm_encoding.h} +40 -40
- data/include/prism/node.h +41 -0
- data/include/prism/pack.h +141 -0
- data/include/{yarp → prism}/parser.h +143 -142
- data/include/prism/regexp.h +19 -0
- data/include/prism/unescape.h +48 -0
- data/include/prism/util/pm_buffer.h +51 -0
- data/include/{yarp/util/yp_char.h → prism/util/pm_char.h} +20 -20
- data/include/{yarp/util/yp_constant_pool.h → prism/util/pm_constant_pool.h} +26 -22
- data/include/{yarp/util/yp_list.h → prism/util/pm_list.h} +21 -21
- data/include/prism/util/pm_memchr.h +14 -0
- data/include/{yarp/util/yp_newline_list.h → prism/util/pm_newline_list.h} +11 -11
- data/include/prism/util/pm_state_stack.h +24 -0
- data/include/{yarp/util/yp_string.h → prism/util/pm_string.h} +20 -20
- data/include/prism/util/pm_string_list.h +25 -0
- data/include/{yarp/util/yp_strpbrk.h → prism/util/pm_strpbrk.h} +7 -7
- data/include/prism/version.h +4 -0
- data/include/prism.h +82 -0
- data/lib/prism/compiler.rb +465 -0
- data/lib/prism/debug.rb +157 -0
- data/lib/{yarp/desugar_visitor.rb → prism/desugar_compiler.rb} +4 -2
- data/lib/prism/dispatcher.rb +2051 -0
- data/lib/prism/dsl.rb +750 -0
- data/lib/{yarp → prism}/ffi.rb +66 -67
- data/lib/{yarp → prism}/lex_compat.rb +40 -43
- data/lib/{yarp/mutation_visitor.rb → prism/mutation_compiler.rb} +3 -3
- data/lib/{yarp → prism}/node.rb +2012 -2593
- data/lib/prism/node_ext.rb +55 -0
- data/lib/prism/node_inspector.rb +68 -0
- data/lib/{yarp → prism}/pack.rb +1 -1
- data/lib/{yarp → prism}/parse_result/comments.rb +1 -1
- data/lib/{yarp → prism}/parse_result/newlines.rb +1 -1
- data/lib/prism/parse_result.rb +266 -0
- data/lib/{yarp → prism}/pattern.rb +14 -14
- data/lib/{yarp → prism}/ripper_compat.rb +5 -5
- data/lib/{yarp → prism}/serialize.rb +12 -7
- data/lib/prism/visitor.rb +470 -0
- data/lib/prism.rb +64 -0
- data/lib/yarp.rb +2 -614
- data/src/diagnostic.c +213 -208
- data/src/enc/pm_big5.c +52 -0
- data/src/enc/pm_euc_jp.c +58 -0
- data/src/enc/{yp_gbk.c → pm_gbk.c} +16 -16
- data/src/enc/pm_shift_jis.c +56 -0
- data/src/enc/{yp_tables.c → pm_tables.c} +69 -69
- data/src/enc/{yp_unicode.c → pm_unicode.c} +40 -40
- data/src/enc/pm_windows_31j.c +56 -0
- data/src/node.c +1293 -1233
- data/src/pack.c +247 -247
- data/src/prettyprint.c +1479 -1479
- data/src/{yarp.c → prism.c} +5205 -5083
- data/src/regexp.c +132 -132
- data/src/serialize.c +1121 -1121
- data/src/token_type.c +169 -167
- data/src/unescape.c +106 -87
- data/src/util/pm_buffer.c +103 -0
- data/src/util/{yp_char.c → pm_char.c} +72 -72
- data/src/util/{yp_constant_pool.c → pm_constant_pool.c} +85 -64
- data/src/util/{yp_list.c → pm_list.c} +10 -10
- data/src/util/{yp_memchr.c → pm_memchr.c} +6 -4
- data/src/util/{yp_newline_list.c → pm_newline_list.c} +21 -21
- data/src/util/{yp_state_stack.c → pm_state_stack.c} +4 -4
- data/src/util/{yp_string.c → pm_string.c} +38 -38
- data/src/util/pm_string_list.c +29 -0
- data/src/util/{yp_strncasecmp.c → pm_strncasecmp.c} +1 -1
- data/src/util/{yp_strpbrk.c → pm_strpbrk.c} +8 -8
- data/yarp.gemspec +68 -59
- metadata +70 -61
- data/ext/yarp/api_node.c +0 -4728
- data/ext/yarp/extension.h +0 -18
- data/include/yarp/ast.h +0 -1929
- data/include/yarp/defines.h +0 -45
- data/include/yarp/diagnostic.h +0 -226
- data/include/yarp/node.h +0 -42
- data/include/yarp/pack.h +0 -141
- data/include/yarp/regexp.h +0 -19
- data/include/yarp/unescape.h +0 -44
- data/include/yarp/util/yp_buffer.h +0 -51
- data/include/yarp/util/yp_memchr.h +0 -14
- data/include/yarp/util/yp_state_stack.h +0 -24
- data/include/yarp/util/yp_string_list.h +0 -25
- data/include/yarp/version.h +0 -4
- data/include/yarp.h +0 -82
- data/src/enc/yp_big5.c +0 -52
- data/src/enc/yp_euc_jp.c +0 -58
- data/src/enc/yp_shift_jis.c +0 -56
- data/src/enc/yp_windows_31j.c +0 -56
- data/src/util/yp_buffer.c +0 -101
- data/src/util/yp_string_list.c +0 -29
data/include/yarp.h
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
#ifndef YARP_H
|
2
|
-
#define YARP_H
|
3
|
-
|
4
|
-
#include "yarp/defines.h"
|
5
|
-
#include "yarp/ast.h"
|
6
|
-
#include "yarp/diagnostic.h"
|
7
|
-
#include "yarp/node.h"
|
8
|
-
#include "yarp/pack.h"
|
9
|
-
#include "yarp/parser.h"
|
10
|
-
#include "yarp/regexp.h"
|
11
|
-
#include "yarp/unescape.h"
|
12
|
-
#include "yarp/util/yp_buffer.h"
|
13
|
-
#include "yarp/util/yp_char.h"
|
14
|
-
#include "yarp/util/yp_memchr.h"
|
15
|
-
#include "yarp/util/yp_strpbrk.h"
|
16
|
-
#include "yarp/version.h"
|
17
|
-
|
18
|
-
#include <assert.h>
|
19
|
-
#include <errno.h>
|
20
|
-
#include <stdarg.h>
|
21
|
-
#include <stdbool.h>
|
22
|
-
#include <stdint.h>
|
23
|
-
#include <stdio.h>
|
24
|
-
#include <stdlib.h>
|
25
|
-
#include <string.h>
|
26
|
-
|
27
|
-
#ifndef _WIN32
|
28
|
-
#include <strings.h>
|
29
|
-
#endif
|
30
|
-
|
31
|
-
void yp_serialize_content(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer);
|
32
|
-
|
33
|
-
void yp_print_node(yp_parser_t *parser, yp_node_t *node);
|
34
|
-
|
35
|
-
void yp_parser_metadata(yp_parser_t *parser, const char *metadata);
|
36
|
-
|
37
|
-
// Generate a scope node from the given node.
|
38
|
-
void yp_scope_node_init(yp_node_t *node, yp_scope_node_t *dest);
|
39
|
-
|
40
|
-
// The YARP version and the serialization format.
|
41
|
-
YP_EXPORTED_FUNCTION const char * yp_version(void);
|
42
|
-
|
43
|
-
// Initialize a parser with the given start and end pointers.
|
44
|
-
YP_EXPORTED_FUNCTION void yp_parser_init(yp_parser_t *parser, const uint8_t *source, size_t size, const char *filepath);
|
45
|
-
|
46
|
-
// Register a callback that will be called whenever YARP changes the encoding it
|
47
|
-
// is using to parse based on the magic comment.
|
48
|
-
YP_EXPORTED_FUNCTION void yp_parser_register_encoding_changed_callback(yp_parser_t *parser, yp_encoding_changed_callback_t callback);
|
49
|
-
|
50
|
-
// Register a callback that will be called when YARP encounters a magic comment
|
51
|
-
// with an encoding referenced that it doesn't understand. The callback should
|
52
|
-
// return NULL if it also doesn't understand the encoding or it should return a
|
53
|
-
// pointer to a yp_encoding_t struct that contains the functions necessary to
|
54
|
-
// parse identifiers.
|
55
|
-
YP_EXPORTED_FUNCTION void yp_parser_register_encoding_decode_callback(yp_parser_t *parser, yp_encoding_decode_callback_t callback);
|
56
|
-
|
57
|
-
// Free any memory associated with the given parser.
|
58
|
-
YP_EXPORTED_FUNCTION void yp_parser_free(yp_parser_t *parser);
|
59
|
-
|
60
|
-
// Parse the Ruby source associated with the given parser and return the tree.
|
61
|
-
YP_EXPORTED_FUNCTION yp_node_t * yp_parse(yp_parser_t *parser);
|
62
|
-
|
63
|
-
// Pretty-prints the AST represented by the given node to the given buffer.
|
64
|
-
YP_EXPORTED_FUNCTION void yp_prettyprint(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer);
|
65
|
-
|
66
|
-
// Serialize the AST represented by the given node to the given buffer.
|
67
|
-
YP_EXPORTED_FUNCTION void yp_serialize(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer);
|
68
|
-
|
69
|
-
// Parse the given source to the AST and serialize the AST to the given buffer.
|
70
|
-
YP_EXPORTED_FUNCTION void yp_parse_serialize(const uint8_t *source, size_t size, yp_buffer_t *buffer, const char *metadata);
|
71
|
-
|
72
|
-
// Lex the given source and serialize to the given buffer.
|
73
|
-
YP_EXPORTED_FUNCTION void yp_lex_serialize(const uint8_t *source, size_t size, const char *filepath, yp_buffer_t *buffer);
|
74
|
-
|
75
|
-
// Parse and serialize both the AST and the tokens represented by the given
|
76
|
-
// source to the given buffer.
|
77
|
-
YP_EXPORTED_FUNCTION void yp_parse_lex_serialize(const uint8_t *source, size_t size, yp_buffer_t *buffer, const char *metadata);
|
78
|
-
|
79
|
-
// Returns a string representation of the given token type.
|
80
|
-
YP_EXPORTED_FUNCTION const char * yp_token_type_to_str(yp_token_type_t token_type);
|
81
|
-
|
82
|
-
#endif
|
data/src/enc/yp_big5.c
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
#include "yarp/enc/yp_encoding.h"
|
2
|
-
|
3
|
-
static size_t
|
4
|
-
yp_encoding_big5_char_width(const uint8_t *b, ptrdiff_t n) {
|
5
|
-
// These are the single byte characters.
|
6
|
-
if (*b < 0x80) {
|
7
|
-
return 1;
|
8
|
-
}
|
9
|
-
|
10
|
-
// These are the double byte characters.
|
11
|
-
if ((n > 1) && (b[0] >= 0xA1 && b[0] <= 0xFE) && (b[1] >= 0x40 && b[1] <= 0xFE)) {
|
12
|
-
return 2;
|
13
|
-
}
|
14
|
-
|
15
|
-
return 0;
|
16
|
-
}
|
17
|
-
|
18
|
-
static size_t
|
19
|
-
yp_encoding_big5_alpha_char(const uint8_t *b, ptrdiff_t n) {
|
20
|
-
if (yp_encoding_big5_char_width(b, n) == 1) {
|
21
|
-
return yp_encoding_ascii_alpha_char(b, n);
|
22
|
-
} else {
|
23
|
-
return 0;
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
static size_t
|
28
|
-
yp_encoding_big5_alnum_char(const uint8_t *b, ptrdiff_t n) {
|
29
|
-
if (yp_encoding_big5_char_width(b, n) == 1) {
|
30
|
-
return yp_encoding_ascii_alnum_char(b, n);
|
31
|
-
} else {
|
32
|
-
return 0;
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
static bool
|
37
|
-
yp_encoding_big5_isupper_char(const uint8_t *b, ptrdiff_t n) {
|
38
|
-
if (yp_encoding_big5_char_width(b, n) == 1) {
|
39
|
-
return yp_encoding_ascii_isupper_char(b, n);
|
40
|
-
} else {
|
41
|
-
return false;
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
yp_encoding_t yp_encoding_big5 = {
|
46
|
-
.name = "big5",
|
47
|
-
.char_width = yp_encoding_big5_char_width,
|
48
|
-
.alnum_char = yp_encoding_big5_alnum_char,
|
49
|
-
.alpha_char = yp_encoding_big5_alpha_char,
|
50
|
-
.isupper_char = yp_encoding_big5_isupper_char,
|
51
|
-
.multibyte = true
|
52
|
-
};
|
data/src/enc/yp_euc_jp.c
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
#include "yarp/enc/yp_encoding.h"
|
2
|
-
|
3
|
-
static size_t
|
4
|
-
yp_encoding_euc_jp_char_width(const uint8_t *b, ptrdiff_t n) {
|
5
|
-
// These are the single byte characters.
|
6
|
-
if (*b < 0x80) {
|
7
|
-
return 1;
|
8
|
-
}
|
9
|
-
|
10
|
-
// These are the double byte characters.
|
11
|
-
if (
|
12
|
-
(n > 1) &&
|
13
|
-
(
|
14
|
-
((b[0] == 0x8E) && (b[1] >= 0xA1 && b[1] <= 0xFE)) ||
|
15
|
-
((b[0] >= 0xA1 && b[0] <= 0xFE) && (b[1] >= 0xA1 && b[1] <= 0xFE))
|
16
|
-
)
|
17
|
-
) {
|
18
|
-
return 2;
|
19
|
-
}
|
20
|
-
|
21
|
-
return 0;
|
22
|
-
}
|
23
|
-
|
24
|
-
static size_t
|
25
|
-
yp_encoding_euc_jp_alpha_char(const uint8_t *b, ptrdiff_t n) {
|
26
|
-
if (yp_encoding_euc_jp_char_width(b, n) == 1) {
|
27
|
-
return yp_encoding_ascii_alpha_char(b, n);
|
28
|
-
} else {
|
29
|
-
return 0;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
static size_t
|
34
|
-
yp_encoding_euc_jp_alnum_char(const uint8_t *b, ptrdiff_t n) {
|
35
|
-
if (yp_encoding_euc_jp_char_width(b, n) == 1) {
|
36
|
-
return yp_encoding_ascii_alnum_char(b, n);
|
37
|
-
} else {
|
38
|
-
return 0;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
static bool
|
43
|
-
yp_encoding_euc_jp_isupper_char(const uint8_t *b, ptrdiff_t n) {
|
44
|
-
if (yp_encoding_euc_jp_char_width(b, n) == 1) {
|
45
|
-
return yp_encoding_ascii_isupper_char(b, n);
|
46
|
-
} else {
|
47
|
-
return 0;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
yp_encoding_t yp_encoding_euc_jp = {
|
52
|
-
.name = "euc-jp",
|
53
|
-
.char_width = yp_encoding_euc_jp_char_width,
|
54
|
-
.alnum_char = yp_encoding_euc_jp_alnum_char,
|
55
|
-
.alpha_char = yp_encoding_euc_jp_alpha_char,
|
56
|
-
.isupper_char = yp_encoding_euc_jp_isupper_char,
|
57
|
-
.multibyte = true
|
58
|
-
};
|
data/src/enc/yp_shift_jis.c
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
#include "yarp/enc/yp_encoding.h"
|
2
|
-
|
3
|
-
static size_t
|
4
|
-
yp_encoding_shift_jis_char_width(const uint8_t *b, ptrdiff_t n) {
|
5
|
-
// These are the single byte characters.
|
6
|
-
if (*b < 0x80 || (*b >= 0xA1 && *b <= 0xDF)) {
|
7
|
-
return 1;
|
8
|
-
}
|
9
|
-
|
10
|
-
// These are the double byte characters.
|
11
|
-
if (
|
12
|
-
(n > 1) &&
|
13
|
-
((b[0] >= 0x81 && b[0] <= 0x9F) || (b[0] >= 0xE0 && b[0] <= 0xFC)) &&
|
14
|
-
(b[1] >= 0x40 && b[1] <= 0xFC)
|
15
|
-
) {
|
16
|
-
return 2;
|
17
|
-
}
|
18
|
-
|
19
|
-
return 0;
|
20
|
-
}
|
21
|
-
|
22
|
-
static size_t
|
23
|
-
yp_encoding_shift_jis_alpha_char(const uint8_t *b, ptrdiff_t n) {
|
24
|
-
if (yp_encoding_shift_jis_char_width(b, n) == 1) {
|
25
|
-
return yp_encoding_ascii_alpha_char(b, n);
|
26
|
-
} else {
|
27
|
-
return 0;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
static size_t
|
32
|
-
yp_encoding_shift_jis_alnum_char(const uint8_t *b, ptrdiff_t n) {
|
33
|
-
if (yp_encoding_shift_jis_char_width(b, n) == 1) {
|
34
|
-
return yp_encoding_ascii_alnum_char(b, n);
|
35
|
-
} else {
|
36
|
-
return 0;
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
static bool
|
41
|
-
yp_encoding_shift_jis_isupper_char(const uint8_t *b, ptrdiff_t n) {
|
42
|
-
if (yp_encoding_shift_jis_char_width(b, n) == 1) {
|
43
|
-
return yp_encoding_ascii_isupper_char(b, n);
|
44
|
-
} else {
|
45
|
-
return 0;
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
yp_encoding_t yp_encoding_shift_jis = {
|
50
|
-
.name = "shift_jis",
|
51
|
-
.char_width = yp_encoding_shift_jis_char_width,
|
52
|
-
.alnum_char = yp_encoding_shift_jis_alnum_char,
|
53
|
-
.alpha_char = yp_encoding_shift_jis_alpha_char,
|
54
|
-
.isupper_char = yp_encoding_shift_jis_isupper_char,
|
55
|
-
.multibyte = true
|
56
|
-
};
|
data/src/enc/yp_windows_31j.c
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
#include "yarp/enc/yp_encoding.h"
|
2
|
-
|
3
|
-
static size_t
|
4
|
-
yp_encoding_windows_31j_char_width(const uint8_t *b, ptrdiff_t n) {
|
5
|
-
// These are the single byte characters.
|
6
|
-
if (*b < 0x80 || (*b >= 0xA1 && *b <= 0xDF)) {
|
7
|
-
return 1;
|
8
|
-
}
|
9
|
-
|
10
|
-
// These are the double byte characters.
|
11
|
-
if (
|
12
|
-
(n > 1) &&
|
13
|
-
((b[0] >= 0x81 && b[0] <= 0x9F) || (b[0] >= 0xE0 && b[0] <= 0xFC)) &&
|
14
|
-
(b[1] >= 0x40 && b[1] <= 0xFC)
|
15
|
-
) {
|
16
|
-
return 2;
|
17
|
-
}
|
18
|
-
|
19
|
-
return 0;
|
20
|
-
}
|
21
|
-
|
22
|
-
static size_t
|
23
|
-
yp_encoding_windows_31j_alpha_char(const uint8_t *b, ptrdiff_t n) {
|
24
|
-
if (yp_encoding_windows_31j_char_width(b, n) == 1) {
|
25
|
-
return yp_encoding_ascii_alpha_char(b, n);
|
26
|
-
} else {
|
27
|
-
return 0;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
static size_t
|
32
|
-
yp_encoding_windows_31j_alnum_char(const uint8_t *b, ptrdiff_t n) {
|
33
|
-
if (yp_encoding_windows_31j_char_width(b, n) == 1) {
|
34
|
-
return yp_encoding_ascii_alnum_char(b, n);
|
35
|
-
} else {
|
36
|
-
return 0;
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
static bool
|
41
|
-
yp_encoding_windows_31j_isupper_char(const uint8_t *b, ptrdiff_t n) {
|
42
|
-
if (yp_encoding_windows_31j_char_width(b, n) == 1) {
|
43
|
-
return yp_encoding_ascii_isupper_char(b, n);
|
44
|
-
} else {
|
45
|
-
return false;
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
yp_encoding_t yp_encoding_windows_31j = {
|
50
|
-
.name = "windows-31j",
|
51
|
-
.char_width = yp_encoding_windows_31j_char_width,
|
52
|
-
.alnum_char = yp_encoding_windows_31j_alnum_char,
|
53
|
-
.alpha_char = yp_encoding_windows_31j_alpha_char,
|
54
|
-
.isupper_char = yp_encoding_windows_31j_isupper_char,
|
55
|
-
.multibyte = true
|
56
|
-
};
|
data/src/util/yp_buffer.c
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
#include "yarp/util/yp_buffer.h"
|
2
|
-
|
3
|
-
#define YP_BUFFER_INITIAL_SIZE 1024
|
4
|
-
|
5
|
-
// Return the size of the yp_buffer_t struct.
|
6
|
-
size_t
|
7
|
-
yp_buffer_sizeof(void) {
|
8
|
-
return sizeof(yp_buffer_t);
|
9
|
-
}
|
10
|
-
|
11
|
-
// Initialize a yp_buffer_t with its default values.
|
12
|
-
bool
|
13
|
-
yp_buffer_init(yp_buffer_t *buffer) {
|
14
|
-
buffer->length = 0;
|
15
|
-
buffer->capacity = YP_BUFFER_INITIAL_SIZE;
|
16
|
-
|
17
|
-
buffer->value = (char *) malloc(YP_BUFFER_INITIAL_SIZE);
|
18
|
-
return buffer->value != NULL;
|
19
|
-
}
|
20
|
-
|
21
|
-
// Return the value of the buffer.
|
22
|
-
char *
|
23
|
-
yp_buffer_value(yp_buffer_t *buffer) {
|
24
|
-
return buffer->value;
|
25
|
-
}
|
26
|
-
|
27
|
-
// Return the length of the buffer.
|
28
|
-
size_t
|
29
|
-
yp_buffer_length(yp_buffer_t *buffer) {
|
30
|
-
return buffer->length;
|
31
|
-
}
|
32
|
-
|
33
|
-
// Append the given amount of space to the buffer.
|
34
|
-
static inline void
|
35
|
-
yp_buffer_append_length(yp_buffer_t *buffer, size_t length) {
|
36
|
-
size_t next_length = buffer->length + length;
|
37
|
-
|
38
|
-
if (next_length > buffer->capacity) {
|
39
|
-
do {
|
40
|
-
buffer->capacity *= 2;
|
41
|
-
} while (next_length > buffer->capacity);
|
42
|
-
|
43
|
-
buffer->value = realloc(buffer->value, buffer->capacity);
|
44
|
-
}
|
45
|
-
|
46
|
-
buffer->length = next_length;
|
47
|
-
}
|
48
|
-
|
49
|
-
// Append a generic pointer to memory to the buffer.
|
50
|
-
static inline void
|
51
|
-
yp_buffer_append(yp_buffer_t *buffer, const void *source, size_t length) {
|
52
|
-
yp_buffer_append_length(buffer, length);
|
53
|
-
memcpy(buffer->value + (buffer->length - length), source, length);
|
54
|
-
}
|
55
|
-
|
56
|
-
// Append the given amount of space as zeroes to the buffer.
|
57
|
-
void
|
58
|
-
yp_buffer_append_zeroes(yp_buffer_t *buffer, size_t length) {
|
59
|
-
yp_buffer_append_length(buffer, length);
|
60
|
-
memset(buffer->value + (buffer->length - length), 0, length);
|
61
|
-
}
|
62
|
-
|
63
|
-
// Append a string to the buffer.
|
64
|
-
void
|
65
|
-
yp_buffer_append_str(yp_buffer_t *buffer, const char *value, size_t length) {
|
66
|
-
yp_buffer_append(buffer, value, length);
|
67
|
-
}
|
68
|
-
|
69
|
-
// Append a list of bytes to the buffer.
|
70
|
-
void
|
71
|
-
yp_buffer_append_bytes(yp_buffer_t *buffer, const uint8_t *value, size_t length) {
|
72
|
-
yp_buffer_append(buffer, (const char *) value, length);
|
73
|
-
}
|
74
|
-
|
75
|
-
// Append a single byte to the buffer.
|
76
|
-
void
|
77
|
-
yp_buffer_append_u8(yp_buffer_t *buffer, uint8_t value) {
|
78
|
-
const void *source = &value;
|
79
|
-
yp_buffer_append(buffer, source, sizeof(uint8_t));
|
80
|
-
}
|
81
|
-
|
82
|
-
// Append a 32-bit unsigned integer to the buffer.
|
83
|
-
void
|
84
|
-
yp_buffer_append_u32(yp_buffer_t *buffer, uint32_t value) {
|
85
|
-
if (value < 128) {
|
86
|
-
yp_buffer_append_u8(buffer, (uint8_t) value);
|
87
|
-
} else {
|
88
|
-
uint32_t n = value;
|
89
|
-
while (n >= 128) {
|
90
|
-
yp_buffer_append_u8(buffer, (uint8_t) (n | 128));
|
91
|
-
n >>= 7;
|
92
|
-
}
|
93
|
-
yp_buffer_append_u8(buffer, (uint8_t) n);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
// Free the memory associated with the buffer.
|
98
|
-
void
|
99
|
-
yp_buffer_free(yp_buffer_t *buffer) {
|
100
|
-
free(buffer->value);
|
101
|
-
}
|
data/src/util/yp_string_list.c
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#include "yarp/util/yp_string_list.h"
|
2
|
-
|
3
|
-
// Initialize a yp_string_list_t with its default values.
|
4
|
-
void
|
5
|
-
yp_string_list_init(yp_string_list_t *string_list) {
|
6
|
-
string_list->strings = (yp_string_t *) malloc(sizeof(yp_string_t));
|
7
|
-
string_list->length = 0;
|
8
|
-
string_list->capacity = 1;
|
9
|
-
}
|
10
|
-
|
11
|
-
// Append a yp_string_t to the given string list.
|
12
|
-
void
|
13
|
-
yp_string_list_append(yp_string_list_t *string_list, yp_string_t *string) {
|
14
|
-
if (string_list->length + 1 > string_list->capacity) {
|
15
|
-
yp_string_t *original_string = string_list->strings;
|
16
|
-
string_list->capacity *= 2;
|
17
|
-
string_list->strings = (yp_string_t *) malloc(string_list->capacity * sizeof(yp_string_t));
|
18
|
-
memcpy(string_list->strings, original_string, (string_list->length) * sizeof(yp_string_t));
|
19
|
-
free(original_string);
|
20
|
-
}
|
21
|
-
|
22
|
-
string_list->strings[string_list->length++] = *string;
|
23
|
-
}
|
24
|
-
|
25
|
-
// Free the memory associated with the string list.
|
26
|
-
void
|
27
|
-
yp_string_list_free(yp_string_list_t *string_list) {
|
28
|
-
free(string_list->strings);
|
29
|
-
}
|