diff options
author | Přemysl Janouch <p@janouch.name> | 2018-09-08 16:54:17 +0200 |
---|---|---|
committer | Přemysl Janouch <p@janouch.name> | 2018-09-08 16:54:17 +0200 |
commit | 3173202cc1e08762c6e156a8fffd23269a5ddb2b (patch) | |
tree | 95c4a06f8384d41b15e9c22afac0a387de79dc51 /nexgb/xgbgen/size.go | |
parent | 632b3ae494d45755525644fe5d04475c95aae364 (diff) | |
parent | 3906399e7c2a40fbaf355de572cf50a314083f64 (diff) | |
download | haven-3173202cc1e08762c6e156a8fffd23269a5ddb2b.tar.gz haven-3173202cc1e08762c6e156a8fffd23269a5ddb2b.tar.xz haven-3173202cc1e08762c6e156a8fffd23269a5ddb2b.zip |
Merge aarzilli/xgb, branch xcb1.12 as nexgb
History has been linearized and rewritten to stay under the new
subdirectory. I want to make changes incompatible to BurntSushi/xgb.
The history begs for being thrown away entirely because of its quality
and because it doesn't cover the Google period but it is still useful
for copyright tracking.
Diffstat (limited to 'nexgb/xgbgen/size.go')
-rw-r--r-- | nexgb/xgbgen/size.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/nexgb/xgbgen/size.go b/nexgb/xgbgen/size.go new file mode 100644 index 0000000..6e49371 --- /dev/null +++ b/nexgb/xgbgen/size.go @@ -0,0 +1,31 @@ +package main + +// Size corresponds to an expression that represents the number of bytes +// in some *thing*. Generally, sizes are used to allocate buffers and to +// inform X how big requests are. +// Size is basically a thin layer over an Expression that yields easy methods +// for adding and multiplying sizes. +type Size struct { + Expression + exact bool +} + +// newFixedSize creates a new Size with some fixed and known value. +func newFixedSize(fixed uint, exact bool) Size { + return Size{&Value{v: int(fixed)}, exact} +} + +// newExpressionSize creates a new Size with some expression. +func newExpressionSize(variable Expression, exact bool) Size { + return Size{variable, exact} +} + +// Add adds s1 and s2 and returns a new Size. +func (s1 Size) Add(s2 Size) Size { + return Size{newBinaryOp("+", s1, s2), s1.exact && s2.exact} +} + +// Multiply mupltiplies s1 and s2 and returns a new Size. +func (s1 Size) Multiply(s2 Size) Size { + return Size{newBinaryOp("*", s1, s2), s1.exact && s2.exact} +} |