diff mbox

[ovs-dev,1/9] expr: Rename "macros" to "addr_sets".

Message ID 1483582391-114359-1-git-send-email-jpettit@ovn.org
State Accepted
Headers show

Commit Message

Justin Pettit Jan. 5, 2017, 2:13 a.m. UTC
Macro is a very generic term, but the arguments are only ever address
sets, so rename for clarity.

Signed-off-by: Justin Pettit <jpettit@ovn.org>
---
 include/ovn/expr.h        | 18 +++++-----
 ovn/controller/lflow.c    |  7 ++--
 ovn/lib/expr.c            | 91 ++++++++++++++++++++++++-----------------------
 ovn/utilities/ovn-trace.c |  6 ++--
 tests/test-ovn.c          | 20 +++++------
 5 files changed, 73 insertions(+), 69 deletions(-)

Comments

Ben Pfaff Jan. 5, 2017, 3:25 p.m. UTC | #1
On Wed, Jan 04, 2017 at 06:13:03PM -0800, Justin Pettit wrote:
> Macro is a very generic term, but the arguments are only ever address
> sets, so rename for clarity.
> 
> Signed-off-by: Justin Pettit <jpettit@ovn.org>

Still some hits for "macro":

ovn/lib/expr.c:911:/* Adds a macro named 'name' to 'addr_sets', replacing any existing
ovn/lib/expr.c:926:        /* Use the lexer to convert each macro into the proper
ovn/lib/lex.c:565:lex_parse_macro(const char *p, struct lex_token *token)
ovn/lib/lex.c:747:        p = lex_parse_macro(p, token);

If you fix those,
Acked-by: Ben Pfaff <blp@ovn.org>
diff mbox

Patch

diff --git a/include/ovn/expr.h b/include/ovn/expr.h
index 371ba20..2169a8c 100644
--- a/include/ovn/expr.h
+++ b/include/ovn/expr.h
@@ -365,9 +365,9 @@  expr_from_node(const struct ovs_list *node)
 void expr_format(const struct expr *, struct ds *);
 void expr_print(const struct expr *);
 struct expr *expr_parse(struct lexer *, const struct shash *symtab,
-                        const struct shash *macros);
+                        const struct shash *addr_sets);
 struct expr *expr_parse_string(const char *, const struct shash *symtab,
-                               const struct shash *macros,
+                               const struct shash *addr_sets,
                                char **errorp);
 
 struct expr *expr_clone(struct expr *);
@@ -383,7 +383,7 @@  bool expr_is_simplified(const struct expr *);
 bool expr_is_normalized(const struct expr *);
 
 char *expr_parse_microflow(const char *, const struct shash *symtab,
-                           const struct shash *macros,
+                           const struct shash *addr_sets,
                            bool (*lookup_port)(const void *aux,
                                                const char *port_name,
                                                unsigned int *portp),
@@ -466,19 +466,19 @@  void expr_constant_set_format(const struct expr_constant_set *, struct ds *);
 void expr_constant_set_destroy(struct expr_constant_set *cs);
 
 
-/* Address sets, aka "macros".
+/* Address sets.
  *
  * Instead of referring to a set of value as:
  *    {addr1, addr2, ..., addrN}
  * You can register a set of values and refer to them as:
  *    $name
- * The macros should all have integer/masked-integer values.
+ * The address set entries should all have integer/masked-integer values.
  * The values that don't qualify are ignored.
  */
 
-void expr_macros_add(struct shash *macros, const char *name,
-                     const char * const *values, size_t n_values);
-void expr_macros_remove(struct shash *macros, const char *name);
-void expr_macros_destroy(struct shash *macros);
+void expr_addr_sets_add(struct shash *addr_sets, const char *name,
+                        const char * const *values, size_t n_values);
+void expr_addr_sets_remove(struct shash *addr_sets, const char *name);
+void expr_addr_sets_destroy(struct shash *addr_sets);
 
 #endif /* ovn/expr.h */
diff --git a/ovn/controller/lflow.c b/ovn/controller/lflow.c
index 9f5341a..724ab99 100644
--- a/ovn/controller/lflow.c
+++ b/ovn/controller/lflow.c
@@ -53,8 +53,9 @@  update_address_sets(struct controller_ctx *ctx,
 {
     const struct sbrec_address_set *as;
     SBREC_ADDRESS_SET_FOR_EACH (as, ctx->ovnsb_idl) {
-        expr_macros_add(expr_address_sets_p, as->name,
-                        (const char *const *) as->addresses, as->n_addresses);
+        expr_addr_sets_add(expr_address_sets_p, as->name,
+                           (const char *const *) as->addresses,
+                           as->n_addresses);
     }
 }
 
@@ -385,7 +386,7 @@  lflow_run(struct controller_ctx *ctx, const struct lport_index *lports,
                       group_table, ct_zones, flow_table, &expr_address_sets);
     add_neighbor_flows(ctx, lports, flow_table);
 
-    expr_macros_destroy(&expr_address_sets);
+    expr_addr_sets_destroy(&expr_address_sets);
     shash_destroy(&expr_address_sets);
 }
 
diff --git a/ovn/lib/expr.c b/ovn/lib/expr.c
index 5399985..b89a003 100644
--- a/ovn/lib/expr.c
+++ b/ovn/lib/expr.c
@@ -434,10 +434,10 @@  expr_print(const struct expr *e)
 
 /* Context maintained during expr_parse(). */
 struct expr_context {
-    struct lexer *lexer;        /* Lexer for pulling more tokens. */
-    const struct shash *symtab; /* Symbol table. */
-    const struct shash *macros; /* Table of macros. */
-    bool not;                   /* True inside odd number of NOT operators. */
+    struct lexer *lexer;           /* Lexer for pulling more tokens. */
+    const struct shash *symtab;    /* Symbol table. */
+    const struct shash *addr_sets; /* Address set table. */
+    bool not;                    /* True inside odd number of NOT operators. */
 };
 
 struct expr *expr_parse__(struct expr_context *);
@@ -692,14 +692,14 @@  assign_constant_set_type(struct expr_context *ctx,
 }
 
 static bool
-parse_macros(struct expr_context *ctx, struct expr_constant_set *cs,
-             size_t *allocated_values)
+parse_addr_sets(struct expr_context *ctx, struct expr_constant_set *cs,
+                size_t *allocated_values)
 {
-    struct expr_constant_set *addr_set
-        = (ctx->macros
-           ? shash_find_data(ctx->macros, ctx->lexer->token.s)
+    struct expr_constant_set *addr_sets
+        = (ctx->addr_sets
+           ? shash_find_data(ctx->addr_sets, ctx->lexer->token.s)
            : NULL);
-    if (!addr_set) {
+    if (!addr_sets) {
         lexer_syntax_error(ctx->lexer, "expecting address set name");
         return false;
     }
@@ -708,13 +708,13 @@  parse_macros(struct expr_context *ctx, struct expr_constant_set *cs,
         return false;
     }
 
-    size_t n_values = cs->n_values + addr_set->n_values;
+    size_t n_values = cs->n_values + addr_sets->n_values;
     if (n_values >= *allocated_values) {
         cs->values = xrealloc(cs->values, n_values * sizeof *cs->values);
         *allocated_values = n_values;
     }
-    for (size_t i = 0; i < addr_set->n_values; i++) {
-        cs->values[cs->n_values++] = addr_set->values[i];
+    for (size_t i = 0; i < addr_sets->n_values; i++) {
+        cs->values[cs->n_values++] = addr_sets->values[i];
     }
 
     return true;
@@ -752,7 +752,7 @@  parse_constant(struct expr_context *ctx, struct expr_constant_set *cs,
         lexer_get(ctx->lexer);
         return true;
     } else if (ctx->lexer->token.type == LEX_T_MACRO) {
-        if (!parse_macros(ctx, cs, allocated_values)) {
+        if (!parse_addr_sets(ctx, cs, allocated_values)) {
             return false;
         }
         lexer_get(ctx->lexer);
@@ -908,14 +908,14 @@  expr_constant_set_destroy(struct expr_constant_set *cs)
     }
 }
 
-/* Adds a macro named 'name' to 'macros', replacing any existing macro with the
- * given name. */
+/* Adds a macro named 'name' to 'addr_sets', replacing any existing
+ * address set entry with the given name. */
 void
-expr_macros_add(struct shash *macros, const char *name,
-                const char *const *values, size_t n_values)
+expr_addr_sets_add(struct shash *addr_sets, const char *name,
+                   const char *const *values, size_t n_values)
 {
     /* Replace any existing entry for this name. */
-    expr_macros_remove(macros, name);
+    expr_addr_sets_remove(addr_sets, name);
 
     struct expr_constant_set *cs = xzalloc(sizeof *cs);
     cs->type = EXPR_C_INTEGER;
@@ -944,29 +944,29 @@  expr_macros_add(struct shash *macros, const char *name,
         lexer_destroy(&lex);
     }
 
-    shash_add(macros, name, cs);
+    shash_add(addr_sets, name, cs);
 }
 
 void
-expr_macros_remove(struct shash *macros, const char *name)
+expr_addr_sets_remove(struct shash *addr_sets, const char *name)
 {
-    struct expr_constant_set *cs = shash_find_and_delete(macros, name);
+    struct expr_constant_set *cs = shash_find_and_delete(addr_sets, name);
     if (cs) {
         expr_constant_set_destroy(cs);
         free(cs);
     }
 }
 
-/* Destroy all contents of 'macros'. */
+/* Destroy all contents of 'addr_sets'. */
 void
-expr_macros_destroy(struct shash *macros)
+expr_addr_sets_destroy(struct shash *addr_sets)
 {
     struct shash_node *node, *next;
 
-    SHASH_FOR_EACH_SAFE (node, next, macros) {
+    SHASH_FOR_EACH_SAFE (node, next, addr_sets) {
         struct expr_constant_set *cs = node->data;
 
-        shash_delete(macros, node);
+        shash_delete(addr_sets, node);
         expr_constant_set_destroy(cs);
         free(cs);
     }
@@ -1144,33 +1144,35 @@  expr_parse__(struct expr_context *ctx)
     return e;
 }
 
-/* Parses an expression from 'lexer' using the symbols in 'symtab' and macros
- * in 'macros'.  If successful, returns the new expression; on failure, returns
- * NULL.  Returns nonnull if and only if lexer->error is NULL. */
+/* Parses an expression from 'lexer' using the symbols in 'symtab' and
+ * address set table in 'addr_sets'.  If successful, returns the new
+ * expression; on failure, returns NULL.  Returns nonnull if and only if
+ * lexer->error is NULL. */
 struct expr *
 expr_parse(struct lexer *lexer, const struct shash *symtab,
-           const struct shash *macros)
+           const struct shash *addr_sets)
 {
     struct expr_context ctx = { .lexer = lexer,
                                 .symtab = symtab,
-                                .macros = macros };
+                                .addr_sets = addr_sets };
     return lexer->error ? NULL : expr_parse__(&ctx);
 }
 
-/* Parses the expression in 's' using the symbols in 'symtab' and macros in
- * 'macros'.  If successful, returns the new expression and sets '*errorp' to
- * NULL.  On failure, returns NULL and sets '*errorp' to an explanatory error
- * message.  The caller must eventually free the returned expression (with
- * expr_destroy()) or error (with free()). */
+/* Parses the expression in 's' using the symbols in 'symtab' and
+ * address set table in 'addr_sets'.  If successful, returns the new
+ * expression and sets '*errorp' to NULL.  On failure, returns NULL and
+ * sets '*errorp' to an explanatory error message.  The caller must
+ * eventually free the returned expression (with expr_destroy()) or
+ * error (with free()). */
 struct expr *
 expr_parse_string(const char *s, const struct shash *symtab,
-                  const struct shash *macros, char **errorp)
+                  const struct shash *addr_sets, char **errorp)
 {
     struct lexer lexer;
 
     lexer_init(&lexer, s);
     lexer_get(&lexer);
-    struct expr *expr = expr_parse(&lexer, symtab, macros);
+    struct expr *expr = expr_parse(&lexer, symtab, addr_sets);
     lexer_force_end(&lexer);
     *errorp = lexer_steal_error(&lexer);
     if (*errorp) {
@@ -3074,10 +3076,11 @@  expr_parse_microflow__(struct lexer *lexer,
     return e;
 }
 
-/* Parses 's' as a microflow, using symbols from 'symtab', macros from
- * 'macros', and looking up port numbers using 'lookup_port' and 'aux'.  On
- * success, stores the result in 'uflow' and returns NULL, otherwise zeros
- * 'uflow' and returns an error message that the caller must free().
+/* Parses 's' as a microflow, using symbols from 'symtab', address set
+ * table from 'addr_sets', and looking up port numbers using 'lookup_port'
+ * and 'aux'.  On success, stores the result in 'uflow' and returns
+ * NULL, otherwise zeros 'uflow' and returns an error message that the
+ * caller must free().
  *
  * A "microflow" is a description of a single stream of packets, such as half a
  * TCP connection.  's' uses the syntax of an OVN logical expression to express
@@ -3103,7 +3106,7 @@  expr_parse_microflow__(struct lexer *lexer,
  * the last two as ambiguous.  Just don't be too clever. */
 char * OVS_WARN_UNUSED_RESULT
 expr_parse_microflow(const char *s, const struct shash *symtab,
-                     const struct shash *macros,
+                     const struct shash *addr_sets,
                      bool (*lookup_port)(const void *aux,
                                          const char *port_name,
                                          unsigned int *portp),
@@ -3113,7 +3116,7 @@  expr_parse_microflow(const char *s, const struct shash *symtab,
     lexer_init(&lexer, s);
     lexer_get(&lexer);
 
-    struct expr *e = expr_parse(&lexer, symtab, macros);
+    struct expr *e = expr_parse(&lexer, symtab, addr_sets);
     lexer_force_end(&lexer);
 
     if (e) {
diff --git a/ovn/utilities/ovn-trace.c b/ovn/utilities/ovn-trace.c
index 718929e..82b5ee6 100644
--- a/ovn/utilities/ovn-trace.c
+++ b/ovn/utilities/ovn-trace.c
@@ -579,9 +579,9 @@  read_address_sets(void)
 
     const struct sbrec_address_set *sbas;
     SBREC_ADDRESS_SET_FOR_EACH (sbas, ovnsb_idl) {
-        expr_macros_add(&address_sets, sbas->name,
-                        (const char *const *) sbas->addresses,
-                        sbas->n_addresses);
+        expr_addr_sets_add(&address_sets, sbas->name,
+                           (const char *const *) sbas->addresses,
+                           sbas->n_addresses);
     }
 }
 
diff --git a/tests/test-ovn.c b/tests/test-ovn.c
index 2e82a6f..c0bc484 100644
--- a/tests/test-ovn.c
+++ b/tests/test-ovn.c
@@ -188,9 +188,9 @@  create_dhcp_opts(struct hmap *dhcp_opts, struct hmap *dhcpv6_opts)
 }
 
 static void
-create_macros(struct shash *macros)
+create_addr_sets(struct shash *addr_sets)
 {
-    shash_init(macros);
+    shash_init(addr_sets);
 
     static const char *const addrs1[] = {
         "10.0.0.1", "10.0.0.2", "10.0.0.3",
@@ -202,9 +202,9 @@  create_macros(struct shash *macros)
         "00:00:00:00:00:01", "00:00:00:00:00:02", "00:00:00:00:00:03",
     };
 
-    expr_macros_add(macros, "set1", addrs1, 3);
-    expr_macros_add(macros, "set2", addrs2, 3);
-    expr_macros_add(macros, "set3", addrs3, 3);
+    expr_addr_sets_add(addr_sets, "set1", addrs1, 3);
+    expr_addr_sets_add(addr_sets, "set2", addrs2, 3);
+    expr_addr_sets_add(addr_sets, "set3", addrs3, 3);
 }
 
 static bool
@@ -223,12 +223,12 @@  static void
 test_parse_expr__(int steps)
 {
     struct shash symtab;
-    struct shash macros;
+    struct shash addr_sets;
     struct simap ports;
     struct ds input;
 
     create_symtab(&symtab);
-    create_macros(&macros);
+    create_addr_sets(&addr_sets);
 
     simap_init(&ports);
     simap_put(&ports, "eth0", 5);
@@ -240,7 +240,7 @@  test_parse_expr__(int steps)
         struct expr *expr;
         char *error;
 
-        expr = expr_parse_string(ds_cstr(&input), &symtab, &macros, &error);
+        expr = expr_parse_string(ds_cstr(&input), &symtab, &addr_sets, &error);
         if (!error && steps > 0) {
             expr = expr_annotate(expr, &symtab, &error);
         }
@@ -277,8 +277,8 @@  test_parse_expr__(int steps)
     simap_destroy(&ports);
     expr_symtab_destroy(&symtab);
     shash_destroy(&symtab);
-    expr_macros_destroy(&macros);
-    shash_destroy(&macros);
+    expr_addr_sets_destroy(&addr_sets);
+    shash_destroy(&addr_sets);
 }
 
 static void