rust: Move helper macros into rust/helpers.h
This commit is contained in:
parent
37b42d8a41
commit
7a96af8260
|
@ -124,6 +124,10 @@ Files: src/crypto/ctaes/*
|
||||||
Copyright: Copyright (c) 2016 Pieter Wuille
|
Copyright: Copyright (c) 2016 Pieter Wuille
|
||||||
License: Expat
|
License: Expat
|
||||||
|
|
||||||
|
Files: src/rust/include/rust/map.h
|
||||||
|
Copyright: Copyright (c) 2012 William Swanson
|
||||||
|
License: Expat-with-advertising-clause
|
||||||
|
|
||||||
Files: src/rust/include/rust/VA_OPT.hpp
|
Files: src/rust/include/rust/VA_OPT.hpp
|
||||||
Copyright: Copyright (c) 2019 Will Wray
|
Copyright: Copyright (c) 2019 Will Wray
|
||||||
License: Boost-Software-License-1.0
|
License: Boost-Software-License-1.0
|
||||||
|
@ -133,10 +137,6 @@ Files: src/rust/include/tracing.h
|
||||||
Copyright: Copyright (c) 2020 Jack Grigg
|
Copyright: Copyright (c) 2020 Jack Grigg
|
||||||
License: Expat
|
License: Expat
|
||||||
|
|
||||||
Files: src/rust/include/tracing/map.h
|
|
||||||
Copyright: Copyright (c) 2012 William Swanson
|
|
||||||
License: Expat-with-advertising-clause
|
|
||||||
|
|
||||||
Files: src/secp256k1/*
|
Files: src/secp256k1/*
|
||||||
Copyright: Copyright (c) 2013 Pieter Wuille
|
Copyright: Copyright (c) 2013 Pieter Wuille
|
||||||
License: Expat
|
License: Expat
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright (c) 2020 Jack Grigg
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
||||||
|
|
||||||
|
#ifndef ZCASH_RUST_INCLUDE_HELPERS_H
|
||||||
|
#define ZCASH_RUST_INCLUDE_HELPERS_H
|
||||||
|
|
||||||
|
#include "rust/map.h"
|
||||||
|
#include "rust/VA_OPT.hpp"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Helper macros
|
||||||
|
//
|
||||||
|
|
||||||
|
#define MAP_PAIR_LIST0(f, x, y, peek, ...) f(x, y) MAP_LIST_NEXT(peek, MAP_PAIR_LIST1)(f, peek, __VA_ARGS__)
|
||||||
|
#define MAP_PAIR_LIST1(f, x, y, peek, ...) f(x, y) MAP_LIST_NEXT(peek, MAP_PAIR_LIST0)(f, peek, __VA_ARGS__)
|
||||||
|
|
||||||
|
/// Applies the function macro `f` to each pair of the remaining parameters and
|
||||||
|
/// inserts commas between the results.
|
||||||
|
#define MAP_PAIR_LIST(f, ...) EVAL(MAP_PAIR_LIST1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
|
||||||
|
|
||||||
|
#define T_FIELD_NAME(x, y) x
|
||||||
|
#define T_FIELD_VALUE(x, y) y
|
||||||
|
|
||||||
|
#define T_FIELD_NAMES(...) IFN(__VA_ARGS__)(MAP_PAIR_LIST(T_FIELD_NAME, __VA_ARGS__))
|
||||||
|
#define T_FIELD_VALUES(...) IFN(__VA_ARGS__)(MAP_PAIR_LIST(T_FIELD_VALUE, __VA_ARGS__))
|
||||||
|
|
||||||
|
#define T_DOUBLEESCAPE(a) #a
|
||||||
|
#define T_ESCAPEQUOTE(a) T_DOUBLEESCAPE(a)
|
||||||
|
|
||||||
|
// Computes the length of the given array. This is COUNT_OF from Chromium.
|
||||||
|
#define T_ARRLEN(x) ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x])))))
|
||||||
|
|
||||||
|
#endif // ZCASH_RUST_INCLUDE_HELPERS_H
|
|
@ -5,9 +5,8 @@
|
||||||
#ifndef ZCASH_RUST_INCLUDE_TRACING_H
|
#ifndef ZCASH_RUST_INCLUDE_TRACING_H
|
||||||
#define ZCASH_RUST_INCLUDE_TRACING_H
|
#define ZCASH_RUST_INCLUDE_TRACING_H
|
||||||
|
|
||||||
|
#include "rust/helpers.h"
|
||||||
#include "rust/types.h"
|
#include "rust/types.h"
|
||||||
#include "rust/VA_OPT.hpp"
|
|
||||||
#include "tracing/map.h"
|
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -108,25 +107,6 @@ void tracing_log(
|
||||||
// Helper macros
|
// Helper macros
|
||||||
//
|
//
|
||||||
|
|
||||||
#define MAP_PAIR_LIST0(f, x, y, peek, ...) f(x, y) MAP_LIST_NEXT(peek, MAP_PAIR_LIST1)(f, peek, __VA_ARGS__)
|
|
||||||
#define MAP_PAIR_LIST1(f, x, y, peek, ...) f(x, y) MAP_LIST_NEXT(peek, MAP_PAIR_LIST0)(f, peek, __VA_ARGS__)
|
|
||||||
|
|
||||||
/// Applies the function macro `f` to each pair of the remaining parameters and
|
|
||||||
/// inserts commas between the results.
|
|
||||||
#define MAP_PAIR_LIST(f, ...) EVAL(MAP_PAIR_LIST1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
|
|
||||||
|
|
||||||
#define T_FIELD_NAME(x, y) x
|
|
||||||
#define T_FIELD_VALUE(x, y) y
|
|
||||||
|
|
||||||
#define T_FIELD_NAMES(...) IFN(__VA_ARGS__)(MAP_PAIR_LIST(T_FIELD_NAME, __VA_ARGS__))
|
|
||||||
#define T_FIELD_VALUES(...) IFN(__VA_ARGS__)(MAP_PAIR_LIST(T_FIELD_VALUE, __VA_ARGS__))
|
|
||||||
|
|
||||||
#define T_DOUBLEESCAPE(a) #a
|
|
||||||
#define T_ESCAPEQUOTE(a) T_DOUBLEESCAPE(a)
|
|
||||||
|
|
||||||
// Computes the length of the given array. This is COUNT_OF from Chromium.
|
|
||||||
#define T_ARRLEN(x) ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x])))))
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// Constructs a tracing callsite.
|
// Constructs a tracing callsite.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue