Skip to content

Commit 26731cc

Browse files
committed
Make sure we have at least one declaration in TUs
1 parent b66fbf9 commit 26731cc

8 files changed

Lines changed: 33 additions & 12 deletions

File tree

include/prism/compiler/unused.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
* compiler-agnostic way.
1111
*/
1212
#if defined(__GNUC__)
13-
# define PRISM_ATTRIBUTE_UNUSED __attribute__((unused))
13+
# define PRISM_UNUSED __attribute__((unused))
1414
#else
15-
# define PRISM_ATTRIBUTE_UNUSED
15+
# define PRISM_UNUSED
1616
#endif
1717

1818
#endif

src/encoding.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4094,7 +4094,7 @@ pm_encoding_ascii_isupper_char(const uint8_t *b, ptrdiff_t n) {
40944094
* matter what the codepoint, so this function is shared between them.
40954095
*/
40964096
static size_t
4097-
pm_encoding_single_char_width(PRISM_ATTRIBUTE_UNUSED const uint8_t *b, PRISM_ATTRIBUTE_UNUSED ptrdiff_t n) {
4097+
pm_encoding_single_char_width(PRISM_UNUSED const uint8_t *b, PRISM_UNUSED ptrdiff_t n) {
40984098
return 1;
40994099
}
41004100

src/json.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
/* We optionally support dumping to JSON. For systems that don not want or need
1212
* this functionality, it can be turned off with the PRISM_EXCLUDE_JSON define.
1313
*/
14-
#ifndef PRISM_EXCLUDE_JSON
14+
#ifdef PRISM_EXCLUDE_JSON
15+
16+
#include "prism/compiler/unused.h"
17+
18+
void
19+
pm_dump_json(PRISM_UNUSED pm_buffer_t *buffer, PRISM_UNUSED const pm_parser_t *parser, PRISM_UNUSED const pm_node_t *node) {}
20+
21+
#else
1522

1623
#include "prism/internal/buffer.h"
1724
#include "prism/internal/constant_pool.h"

src/prism.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ lex_state_set(pm_parser_t *parser, pm_lex_state_t state) {
454454
#endif
455455

456456
#if PM_DEBUG_LOGGING
457-
PRISM_ATTRIBUTE_UNUSED static void
457+
PRISM_UNUSED static void
458458
debug_state(pm_parser_t *parser) {
459459
fprintf(stderr, "STATE: ");
460460
bool first = true;
@@ -1073,7 +1073,7 @@ pm_locals_reads(pm_locals_t *locals, pm_constant_id_t name) {
10731073
* written but not read in certain contexts.
10741074
*/
10751075
static void
1076-
pm_locals_order(PRISM_ATTRIBUTE_UNUSED pm_parser_t *parser, pm_locals_t *locals, pm_constant_id_list_t *list, bool toplevel) {
1076+
pm_locals_order(pm_parser_t *parser, pm_locals_t *locals, pm_constant_id_list_t *list, bool toplevel) {
10771077
pm_constant_id_list_init_capacity(parser->arena, list, locals->size);
10781078

10791079
// If we're still below the threshold for switching to a hash, then we only

src/static_literals.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ pm_compare_integer_nodes(const pm_static_literals_metadata_t *metadata, const pm
285285
* A comparison function for comparing two FloatNode instances.
286286
*/
287287
static int
288-
pm_compare_float_nodes(PRISM_ATTRIBUTE_UNUSED const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
288+
pm_compare_float_nodes(PRISM_UNUSED const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
289289
const double left_value = ((const pm_float_node_t *) left)->value;
290290
const double right_value = ((const pm_float_node_t *) right)->value;
291291
return PM_NUMERIC_COMPARISON(left_value, right_value);
@@ -344,7 +344,7 @@ pm_string_value(const pm_node_t *node) {
344344
* A comparison function for comparing two nodes that have attached strings.
345345
*/
346346
static int
347-
pm_compare_string_nodes(PRISM_ATTRIBUTE_UNUSED const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
347+
pm_compare_string_nodes(PRISM_UNUSED const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
348348
const pm_string_t *left_string = pm_string_value(left);
349349
const pm_string_t *right_string = pm_string_value(right);
350350
return pm_string_compare(left_string, right_string);
@@ -354,7 +354,7 @@ pm_compare_string_nodes(PRISM_ATTRIBUTE_UNUSED const pm_static_literals_metadata
354354
* A comparison function for comparing two RegularExpressionNode instances.
355355
*/
356356
static int
357-
pm_compare_regular_expression_nodes(PRISM_ATTRIBUTE_UNUSED const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
357+
pm_compare_regular_expression_nodes(PRISM_UNUSED const pm_static_literals_metadata_t *metadata, const pm_node_t *left, const pm_node_t *right) {
358358
const pm_regular_expression_node_t *left_regexp = (const pm_regular_expression_node_t *) left;
359359
const pm_regular_expression_node_t *right_regexp = (const pm_regular_expression_node_t *) right;
360360

src/strpbrk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ scan_strpbrk_ascii(pm_parser_t *parser, const uint8_t *source, size_t maximum, c
257257
#else
258258

259259
static PRISM_INLINE bool
260-
scan_strpbrk_ascii(PRISM_ATTRIBUTE_UNUSED pm_parser_t *parser, PRISM_ATTRIBUTE_UNUSED const uint8_t *source, PRISM_ATTRIBUTE_UNUSED size_t maximum, PRISM_ATTRIBUTE_UNUSED const uint8_t *charset, size_t *index) {
260+
scan_strpbrk_ascii(PRISM_UNUSED pm_parser_t *parser, PRISM_UNUSED const uint8_t *source, PRISM_UNUSED size_t maximum, PRISM_UNUSED const uint8_t *charset, size_t *index) {
261261
*index = 0;
262262
return false;
263263
}

templates/src/prettyprint.c.erb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
/* We optionally support pretty printing nodes. For systems that don't want or
55
* need this functionality, it can be turned off with the
66
* PRISM_EXCLUDE_PRETTYPRINT define. */
7-
#ifndef PRISM_EXCLUDE_PRETTYPRINT
7+
#ifdef PRISM_EXCLUDE_PRETTYPRINT
8+
9+
#include "prism/compiler/unused.h"
10+
11+
void
12+
pm_prettyprint(PRISM_UNUSED pm_buffer_t *buffer, PRISM_UNUSED const pm_parser_t *parser, PRISM_UNUSED const pm_node_t *node) {}
13+
14+
#else
815

916
#include "prism/compiler/inline.h"
1017
#include "prism/internal/buffer.h"

templates/src/serialize.c.erb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
/* We optionally support serializing to a binary string. For systems that do not
44
* want or need this functionality, it can be turned off with the
55
* PRISM_EXCLUDE_SERIALIZATION define. */
6-
#ifndef PRISM_EXCLUDE_SERIALIZATION
6+
#ifdef PRISM_EXCLUDE_SERIALIZATION
7+
8+
#include "prism/compiler/unused.h"
9+
10+
void
11+
pm_serialize_lex(PRISM_UNUSED pm_buffer_t *buffer, PRISM_UNUSED const uint8_t *source, PRISM_UNUSED size_t size, PRISM_UNUSED const char *data) {}
12+
13+
#else
714

815
#include "prism/compiler/inline.h"
916

0 commit comments

Comments
 (0)