diff options
author | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-04-30 16:18:17 -0400 |
---|---|---|
committer | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-04-30 16:18:17 -0400 |
commit | 73154769b3eba60fe48a7c08882e8e64b1545e3f (patch) | |
tree | 3fe7c2a1f9ae1d22931b4673901d8ea340192d57 /nexgb/xgbgen/expression.go | |
parent | 2a2d8653b3a7918dfb00dcca8937b0e878279c70 (diff) | |
download | haven-73154769b3eba60fe48a7c08882e8e64b1545e3f.tar.gz haven-73154769b3eba60fe48a7c08882e8e64b1545e3f.tar.xz haven-73154769b3eba60fe48a7c08882e8e64b1545e3f.zip |
splitting up go specific code. too much for one file IMO. more progress. almost done with structs.
Diffstat (limited to 'nexgb/xgbgen/expression.go')
-rw-r--r-- | nexgb/xgbgen/expression.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/nexgb/xgbgen/expression.go b/nexgb/xgbgen/expression.go index 7099c25..a975320 100644 --- a/nexgb/xgbgen/expression.go +++ b/nexgb/xgbgen/expression.go @@ -13,6 +13,34 @@ type Expression interface { Initialize(p *Protocol) } +// Function is a custom expression not found in the XML. It's simply used +// to apply a function named in 'Name' to the Expr expression. +type Function struct { + Name string + Expr Expression +} + +func (e *Function) Concrete() bool { + return false +} + +func (e *Function) Eval() uint { + log.Fatalf("Cannot evaluate a 'Function'. It is not concrete.") + panic("unreachable") +} + +func (e *Function) Reduce(prefix, fun string) string { + return fmt.Sprintf("%s(%s)", e.Name, e.Expr.Reduce(prefix, fun)) +} + +func (e *Function) String() string { + return e.Reduce("", "") +} + +func (e *Function) Initialize(p *Protocol) { + e.Expr.Initialize(p) +} + type BinaryOp struct { Op string Expr1 Expression |