Remove limitation of M_AS_STR to be called within a M_APPLY

This commit is contained in:
Patrick Pelissier committed 2021-02-06 22:22:50 +01:00
1 parent e4dc06a0e2
commit 07eb5697ab
4 files changed
+11 -11

No files matched your search

+3 -3
View File
@@ -1042,9 +1042,9 @@ M_BEGIN_PROTECTED_CODE
#define M_COMMA_P(...) M_RETI_ARG76(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, useless)
#endif
/* Return the string representation of the evaluated x.
NOTE: Need to be used with M_APPLY to defer the evaluation */
#define M_AS_STR(x) #x
/* Return the string representation of the evaluated x. */
#define M_AS_STR(x) M_AS_STRI(x)
#define M_AS_STRI(x) #x
/* Return 1 if the argument is empty (aka ''), 0 otherwise.
Handle: EMPTY_P(), EMPTY_P(x), EMPTY_P(()) and EMPTY_P(,) and EMPTY_P(f) with #define f() 2,3 */
+2 -2
View File
@@ -474,7 +474,7 @@ m_serial_json_read_tuple_id(m_serial_local_t local, m_serial_read_t serial, cons
/* Read the field in the JSON */
c = -1;
char field[M_MAX_IDENTIFIER_LENGTH+1];
int nn = m_core_fscanf(f, " \"%" M_APPLY(M_AS_STR, M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n",
int nn = m_core_fscanf(f, " \"%" M_AS_STR(M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n",
m_core_arg_size(field, M_MAX_IDENTIFIER_LENGTH+1), &c);
(void) nn ; // Unused. Check is done through 'c' (more robust).
if (c <= 0)
@@ -510,7 +510,7 @@ m_serial_json_read_variant_start(m_serial_local_t local, m_serial_read_t serial,
/* Read the field in the JSON */
char field[M_MAX_IDENTIFIER_LENGTH+1];
nn = m_core_fscanf(f, " \"%" M_APPLY(M_AS_STR, M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n",
nn = m_core_fscanf(f, " \"%" M_AS_STR(M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n",
m_core_arg_size(field, M_MAX_IDENTIFIER_LENGTH+1), &final2);
(void) nn ; // Unused. Check is done through final (more robust).
if (final2 <= 0) return m_core_serial_fail();
+1 -1
View File
@@ -517,7 +517,7 @@ namespace m_lib {
/* Return the parameter name as a C string */
#define TUPLEI_STRINGIFY_NAME(a) \
M_APPLY(M_AS_STR, TUPLEI_GET_FIELD a)
M_AS_STR(TUPLEI_GET_FIELD a)
/* Define a OUT_SERIAL method by calling the OUT_SERIAL methods for all params */
+5 -5
View File
@@ -536,7 +536,7 @@
#define VARIANTI_DEFINE_GET_STR_FUNC(name, a) \
case M_C4(name, _, VARIANTI_GET_FIELD a, _value): \
func(str, "@" M_APPLY (M_AS_STR, VARIANTI_GET_FIELD a) "@"); \
func(str, "@" M_AS_STR(VARIANTI_GET_FIELD a) "@"); \
VARIANTI_CALL_GET_STR(a, str, el -> value . VARIANTI_GET_FIELD a, true); \
break;
@@ -576,7 +576,7 @@
}
#define VARIANTI_DEFINE_PARSE_STR_FUNC(name, a) \
else if (strcmp (variantTypeBuf, M_APPLY (M_AS_STR, VARIANTI_GET_FIELD a)) == 0) { \
else if (strcmp (variantTypeBuf, M_AS_STR(VARIANTI_GET_FIELD a)) == 0) { \
el->type = M_C4(name, _, VARIANTI_GET_FIELD a, _value); \
VARIANTI_CALL_INIT(a, el ->value . VARIANTI_GET_FIELD a ); \
bool b = VARIANTI_CALL_PARSE_STR(a, el -> value . VARIANTI_GET_FIELD a, str, &str); \
@@ -600,7 +600,7 @@
#define VARIANTI_DEFINE_OUT_STR_FUNC(name, a) \
case M_C4(name, _, VARIANTI_GET_FIELD a, _value): \
fprintf(f, "@" M_APPLY(M_AS_STR, VARIANTI_GET_FIELD a) "@"); \
fprintf(f, "@" M_AS_STR(VARIANTI_GET_FIELD a) "@"); \
VARIANTI_CALL_OUT_STR(a, f, el -> value . VARIANTI_GET_FIELD a); \
break;
@@ -635,7 +635,7 @@
}
#define VARIANTI_DEFINE_IN_STR_FUNC(name, a) \
else if (strcmp (variantTypeBuf, M_APPLY (M_AS_STR, VARIANTI_GET_FIELD a)) == 0) { \
else if (strcmp (variantTypeBuf, M_AS_STR(VARIANTI_GET_FIELD a)) == 0) { \
el->type = M_C4(name, _, VARIANTI_GET_FIELD a, _value); \
VARIANTI_CALL_INIT(a, el ->value . VARIANTI_GET_FIELD a ); \
b = VARIANTI_CALL_IN_STR(a, el -> value . VARIANTI_GET_FIELD a, f); \
@@ -644,7 +644,7 @@
/* Return the STRING version of a parameter name */
#define VARIANTI_STRINGIFY_NAME(a) \
M_APPLY(M_AS_STR, VARIANTI_GET_FIELD a)
M_AS_STR(VARIANTI_GET_FIELD a)
/* Define the OUT_SERIAL function */