Added forward declarations for static functions
This commit is contained in:
parent
2d109f974b
commit
6deb08a4ab
6
bp.c
6
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);
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
4
json.c
4
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) {
|
||||
|
16
printing.c
16
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";
|
||||
|
31
vm.c
31
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
|
||||
|
Loading…
Reference in New Issue
Block a user