summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2016-07-15 15:31:42 -0700
committerBen Pfaff <blp@ovn.org>2016-08-08 11:00:59 -0700
commit6383b6df755fafaf0830081af6cfb45aeaf167fd (patch)
tree7e0d363d155131bb28dba1a553411258f374e17a /include
parentaddc63174e22f925b2373d91d59ab4c1c81cf9c2 (diff)
downloadopenvswitch-6383b6df755fafaf0830081af6cfb45aeaf167fd.tar.gz
expr: Give a subfield a direct pointer to its parent in struct expr_symbol.
Until now, symbols that represent subfields and predicates were both implemented as the same string member, named 'expansion', inside struct expr. This makes it a little inconvenient to find the parent of a subfield for two reasons. First, one must actually parse the string, e.g. to convert "vlan.tci[13..15]" into a pointer to a struct. Second, and more importantly, to parse the string it's necessary to have access to the symbol table, which isn't always convenient to pass around. This commit avoids the problem by breaking apart subfields and predicates and giving the former a direct pointer to the parent symbol. We could do the same thing for predicates by storing a pointer to a pre-built struct expr, but so far it's not necessary. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
Diffstat (limited to 'include')
-rw-r--r--include/ovn/expr.h34
1 files changed, 19 insertions, 15 deletions
diff --git a/include/ovn/expr.h b/include/ovn/expr.h
index 569c524c5..011685dca 100644
--- a/include/ovn/expr.h
+++ b/include/ovn/expr.h
@@ -106,20 +106,23 @@ const char *expr_level_to_string(enum expr_level);
* Fields:
*
* One might, for example, define a field named "vlan.tci" to refer to
- * MFF_VLAN_TCI. For integer fields, 'field' specifies the referent; for
- * string fields, 'field' is NULL.
+ * MFF_VLAN_TCI. 'field' specifies the field.
*
- * 'expansion' is NULL.
+ * 'parent' and 'predicate' are NULL, and 'parent_ofs' is 0.
*
* Integer fields can be nominal or ordinal (see below). String fields are
* always nominal.
*
* Subfields:
*
- * 'expansion' is a string that specifies a subfield of some larger field,
- * e.g. "vlan.tci[0..11]" for a field that represents a VLAN VID.
+ * 'parent' specifies the field (which may itself be a subfield,
+ * recursively) in which the subfield is embedded, and 'parent_ofs' a
+ * bitwise offset from the least-significant bit of the parent. The
+ * subfield can contain a subset of the bits of the parent or all of them
+ * (in the latter case the subfield is really just a synonym for the
+ * parent).
*
- * 'field' is NULL.
+ * 'field' and 'predicate' are NULL.
*
* Only ordinal fields (see below) may have subfields, and subfields are
* always ordinal.
@@ -127,16 +130,15 @@ const char *expr_level_to_string(enum expr_level);
* Predicates:
*
* A predicate is an arbitrary Boolean expression that can be used in an
- * expression much like a 1-bit field. 'expansion' specifies the Boolean
+ * expression much like a 1-bit field. 'predicate' specifies the Boolean
* expression, e.g. "ip4" might expand to "eth.type == 0x800". The
- * expansion of a predicate might refer to other predicates, e.g. "icmp4"
- * might expand to "ip4 && ip4.proto == 1".
+ * epxression might refer to other predicates, e.g. "icmp4" might expand to
+ * "ip4 && ip4.proto == 1".
*
- * 'field' is NULL.
+ * 'field' and 'parent' are NULL, and 'parent_ofs' is 0.
*
- * A predicate whose expansion refers to any nominal field or predicate
- * (see below) is nominal; other predicates have Boolean level of
- * measurement.
+ * A predicate that refers to any nominal field or predicate (see below) is
+ * nominal; other predicates have Boolean level of measurement.
*
*
* Level of Measurement
@@ -239,8 +241,10 @@ struct expr_symbol {
char *name;
int width;
- const struct mf_field *field;
- char *expansion;
+ const struct mf_field *field; /* Fields only, otherwise NULL. */
+ const struct expr_symbol *parent; /* Subfields only, otherwise NULL. */
+ int parent_ofs; /* Subfields only, otherwise 0. */
+ char *predicate; /* Predicates only, otherwise NULL. */
enum expr_level level;