aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-01-12 22:33:28 -0800
committerBruce Hill <bruce@bruce-hill.com>2021-01-12 22:33:28 -0800
commit6deb08a4ab64a998a5844df8f61fb8abe56f5d7b (patch)
treea868d425cacc7f5b4c5775aa26a76fe26c2e3696
parent2d109f974b6a03a79db3dd8a5ffe5c2aff76659e (diff)
Added forward declarations for static functions
-rw-r--r--bp.c6
-rw-r--r--file_loader.c4
-rw-r--r--file_loader.h2
-rw-r--r--grammar.c4
-rw-r--r--json.c4
-rw-r--r--printing.c16
-rw-r--r--vm.c31
7 files changed, 44 insertions, 23 deletions
diff --git a/bp.c b/bp.c
index 8d48ed3..1db9bf4 100644
--- a/bp.c
+++ b/bp.c
@@ -41,11 +41,15 @@ static const char *usage = (
static print_options_t print_options = 0;
+__attribute__((nonnull))
+static char *getflag(const char *flag, char *argv[], int *i);
+__attribute__((nonnull(3)))
+static int process_file(def_t *defs, const char *filename, vm_op_t *pattern, unsigned int flags);
+
//
// Return a pointer to the value part of a flag, if present, otherwise NULL.
// This works for --foo=value or --foo value
//
-__attribute__((nonnull))
static char *getflag(const char *flag, char *argv[], int *i)
{
size_t n = strlen(flag);
diff --git a/file_loader.c b/file_loader.c
index a7ce56d..749e985 100644
--- a/file_loader.c
+++ b/file_loader.c
@@ -15,11 +15,13 @@
#include "file_loader.h"
#include "utils.h"
+__attribute__((nonnull))
+static void populate_lines(file_t *f);
+
//
// In the file object, populate the `lines` array with pointers to the
// beginning of each line.
//
-__attribute__((nonnull))
static void populate_lines(file_t *f)
{
// Calculate line numbers:
diff --git a/file_loader.h b/file_loader.h
index 3b0f15b..0094732 100644
--- a/file_loader.h
+++ b/file_loader.h
@@ -26,7 +26,7 @@ __attribute__((pure, nonnull))
size_t get_char_number(file_t *f, const char *p);
__attribute__((pure, nonnull))
const char *get_line(file_t *f, size_t line_number);
-__attribute__((nonnull(1,2,3,4), format(printf, 5, 6)))
+__attribute__((nonnull(1,2,3), format(printf, 5, 6)))
void fprint_line(FILE *dest, file_t *f, const char *start, const char *end, const char *fmt, ...);
#endif
diff --git a/grammar.c b/grammar.c
index e9ea4b4..cdc8f51 100644
--- a/grammar.c
+++ b/grammar.c
@@ -10,6 +10,9 @@
#include "grammar.h"
#include "utils.h"
+__attribute__((nonnull(2,3,4), returns_nonnull))
+static def_t *with_backref(def_t *defs, file_t *f, const char *name, match_t *m);
+
//
// Return a new list of definitions with one added to the front
//
@@ -67,7 +70,6 @@ vm_op_t *lookup(def_t *defs, const char *name)
//
// Push a backreference onto the backreference stack
//
-__attribute__((nonnull))
static def_t *with_backref(def_t *defs, file_t *f, const char *name, match_t *m)
{
vm_op_t *op = new(vm_op_t);
diff --git a/json.c b/json.c
index f099554..22905cc 100644
--- a/json.c
+++ b/json.c
@@ -6,12 +6,14 @@
#include "types.h"
+__attribute__((nonnull))
+static int _json_match(const char *text, match_t *m, int comma, int verbose);
+
//
// Helper function for json_match().
// `comma` is used to track whether a comma will need to be printed before the
// next object or not.
//
-__attribute__((nonnull))
static int _json_match(const char *text, match_t *m, int comma, int verbose)
{
if (!verbose) {
diff --git a/printing.c b/printing.c
index 9491646..833a580 100644
--- a/printing.c
+++ b/printing.c
@@ -21,11 +21,21 @@ typedef struct {
const char *color;
} print_state_t;
+__attribute__((nonnull, pure))
+static int height_of_match(match_t *m);
+__attribute__((nonnull))
+static void _visualize_matches(match_node_t *firstmatch, int depth, const char *text, size_t textlen);
+__attribute__((nonnull))
+static void _visualize_patterns(match_t *m);
+__attribute__((nonnull))
+static void print_line_number(FILE *out, print_state_t *state, print_options_t options);
+__attribute__((nonnull))
+static void _print_match(FILE *out, file_t *f, match_t *m, print_state_t *state, print_options_t options);
+
//
// Return the height of a match object (i.e. the number of descendents of the
// structure).
//
-__attribute__((nonnull, pure))
static int height_of_match(match_t *m)
{
int height = 0;
@@ -39,7 +49,6 @@ static int height_of_match(match_t *m)
//
// Print a visual explanation for the as-yet-unprinted matches provided.
//
-__attribute__((nonnull))
static void _visualize_matches(match_node_t *firstmatch, int depth, const char *text, size_t textlen)
{
const char *V = "│"; // Vertical bar
@@ -164,7 +173,6 @@ static void _visualize_matches(match_node_t *firstmatch, int depth, const char *
// Recursively look for references to a rule called "pattern" and print an
// explanation for each one.
//
-__attribute__((nonnull))
static void _visualize_patterns(match_t *m)
{
if (m->op->type == VM_REF && streq(m->op->args.s, "pattern")) {
@@ -191,7 +199,6 @@ void visualize_match(match_t *m)
//
// Print a line number.
//
-__attribute__((nonnull))
static void print_line_number(FILE *out, print_state_t *state, print_options_t options)
{
state->printed_line = state->line;
@@ -205,7 +212,6 @@ static void print_line_number(FILE *out, print_state_t *state, print_options_t o
//
// Helper function for print_match(), using a struct to keep track of some state.
//
-__attribute__((nonnull))
static void _print_match(FILE *out, file_t *f, match_t *m, print_state_t *state, print_options_t options)
{
static const char *hl = "\033[0;31;1m";
diff --git a/vm.c b/vm.c
index 330f24f..6200e1b 100644
--- a/vm.c
+++ b/vm.c
@@ -12,11 +12,28 @@
#include "utils.h"
#include "vm.h"
+typedef struct recursive_ref_s {
+ const vm_op_t *op;
+ const char *pos;
+ struct recursive_ref_s *prev;
+ int hit;
+ match_t *result;
+} recursive_ref_t;
+
+__attribute__((nonnull, pure))
+static inline const char *next_char(file_t *f, const char *str);
+__attribute__((nonnull))
+static const char *match_backref(const char *str, vm_op_t *op, match_t *cap, unsigned int flags);
+__attribute__((hot, nonnull(2,3,4)))
+static match_t *_match(def_t *defs, file_t *f, const char *str, vm_op_t *op, unsigned int flags, recursive_ref_t *rec);
+__attribute__((nonnull))
+static match_t *get_capture_by_num(match_t *m, int *n);
+__attribute__((nonnull, pure))
+static match_t *get_capture_by_name(match_t *m, const char *name);
//
// UTF8-compliant char iteration
//
-__attribute__((nonnull, pure))
static inline const char *next_char(file_t *f, const char *str)
{
char c = *str;
@@ -44,19 +61,10 @@ void destroy_match(match_t **m)
*m = NULL;
}
-typedef struct recursive_ref_s {
- const vm_op_t *op;
- const char *pos;
- struct recursive_ref_s *prev;
- int hit;
- match_t *result;
-} recursive_ref_t;
-
//
// Attempt to match text against a previously captured value.
// Return the character position after the backref has matched, or NULL if no match has occurred.
//
-__attribute__((nonnull))
static const char *match_backref(const char *str, vm_op_t *op, match_t *cap, unsigned int flags)
{
check(op->type == VM_BACKREF, "Attempt to match backref against something that's not a backref");
@@ -117,7 +125,6 @@ static const char *match_backref(const char *str, vm_op_t *op, match_t *cap, uns
// a match struct, or NULL if no match is found.
// The returned value should be free()'d to avoid memory leaking.
//
-__attribute__((hot, nonnull(2,3,4)))
static match_t *_match(def_t *defs, file_t *f, const char *str, vm_op_t *op, unsigned int flags, recursive_ref_t *rec)
{
switch (op->type) {
@@ -477,7 +484,6 @@ static match_t *_match(def_t *defs, file_t *f, const char *str, vm_op_t *op, uns
//
// Get a specific numbered pattern capture.
//
-__attribute__((nonnull))
static match_t *get_capture_by_num(match_t *m, int *n)
{
if (*n == 0) return m;
@@ -493,7 +499,6 @@ static match_t *get_capture_by_num(match_t *m, int *n)
//
// Get a capture with a specific name.
//
-__attribute__((nonnull, pure))
static match_t *get_capture_by_name(match_t *m, const char *name)
{
if (m->op->type == VM_CAPTURE && m->op->args.capture.name