aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/xml_expression.go
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-30 02:40:55 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-30 02:40:55 -0400
commit05d8ec6a16acf88c5ae7521d86131f5ea7f9b4e4 (patch)
tree028bfcc345c02afad9a6201e2af63ed638a3e8d9 /nexgb/xgbgen/xml_expression.go
parent3115c13e88badfd3b6b1762f2239edbf9d0b8951 (diff)
downloadhaven-05d8ec6a16acf88c5ae7521d86131f5ea7f9b4e4.tar.gz
haven-05d8ec6a16acf88c5ae7521d86131f5ea7f9b4e4.tar.xz
haven-05d8ec6a16acf88c5ae7521d86131f5ea7f9b4e4.zip
complete and total overhaul like i promised. things are much easier to reason about. still not working yet though.
Diffstat (limited to 'nexgb/xgbgen/xml_expression.go')
-rw-r--r--nexgb/xgbgen/xml_expression.go30
1 files changed, 15 insertions, 15 deletions
diff --git a/nexgb/xgbgen/xml_expression.go b/nexgb/xgbgen/xml_expression.go
index dd32512..57ff62e 100644
--- a/nexgb/xgbgen/xml_expression.go
+++ b/nexgb/xgbgen/xml_expression.go
@@ -7,25 +7,25 @@ import (
"strconv"
)
-type Expression struct {
+type XMLExpression struct {
XMLName xml.Name
- Exprs []*Expression `xml:",any"`
+ Exprs []*XMLExpression `xml:",any"`
Data string `xml:",chardata"`
Op string `xml:"op,attr"`
Ref string `xml:"ref,attr"`
}
-func newValueExpression(v uint) *Expression {
- return &Expression{
+func newValueExpression(v uint) *XMLExpression {
+ return &XMLExpression{
XMLName: xml.Name{Local: "value"},
Data: fmt.Sprintf("%d", v),
}
}
// String is for debugging. For actual use, please use 'Morph'.
-func (e *Expression) String() string {
+func (e *XMLExpression) String() string {
switch e.XMLName.Local {
case "op":
return fmt.Sprintf("(%s %s %s)", e.Exprs[0], e.Op, e.Exprs[1])
@@ -55,7 +55,7 @@ func (e *Expression) String() string {
// empty items in enums.
// We can't compute a concrete value for expressions that rely on a context,
// i.e., some field value.
-func (e *Expression) Eval() uint {
+func (e *XMLExpression) Eval() uint {
switch e.XMLName.Local {
case "op":
if len(e.Exprs) != 2 {
@@ -108,7 +108,7 @@ func (e *Expression) Eval() uint {
panic("unreachable")
}
-func (e *Expression) BinaryOp(operand1, operand2 *Expression) *Expression {
+func (e *XMLExpression) BinaryOp(oprnd1, oprnd2 *XMLExpression) *XMLExpression {
if e.XMLName.Local != "op" {
log.Panicf("Cannot perform binary operation on non-op expression: %s",
e.XMLName.Local)
@@ -121,17 +121,17 @@ func (e *Expression) BinaryOp(operand1, operand2 *Expression) *Expression {
wrap := newValueExpression
switch e.Op {
case "+":
- return wrap(operand1.Eval() + operand2.Eval())
+ return wrap(oprnd1.Eval() + oprnd2.Eval())
case "-":
- return wrap(operand1.Eval() + operand2.Eval())
+ return wrap(oprnd1.Eval() + oprnd2.Eval())
case "*":
- return wrap(operand1.Eval() * operand2.Eval())
+ return wrap(oprnd1.Eval() * oprnd2.Eval())
case "/":
- return wrap(operand1.Eval() / operand2.Eval())
+ return wrap(oprnd1.Eval() / oprnd2.Eval())
case "&amp;":
- return wrap(operand1.Eval() & operand2.Eval())
+ return wrap(oprnd1.Eval() & oprnd2.Eval())
case "&lt;&lt;":
- return wrap(operand1.Eval() << operand2.Eval())
+ return wrap(oprnd1.Eval() << oprnd2.Eval())
}
log.Panicf("Invalid binary operator '%s' for '%s' expression.",
@@ -139,7 +139,7 @@ func (e *Expression) BinaryOp(operand1, operand2 *Expression) *Expression {
panic("unreachable")
}
-func (e *Expression) UnaryOp(operand *Expression) *Expression {
+func (e *XMLExpression) UnaryOp(oprnd *XMLExpression) *XMLExpression {
if e.XMLName.Local != "unop" {
log.Panicf("Cannot perform unary operation on non-unop expression: %s",
e.XMLName.Local)
@@ -151,7 +151,7 @@ func (e *Expression) UnaryOp(operand *Expression) *Expression {
switch e.Op {
case "~":
- return newValueExpression(^operand.Eval())
+ return newValueExpression(^oprnd.Eval())
}
log.Panicf("Invalid unary operator '%s' for '%s' expression.",