~ubuntu-branches/ubuntu/breezy/pmccabe/breezy

« back to all changes in this revision

Viewing changes to test000

  • Committer: Bazaar Package Importer
  • Author(s): Paul Bame
  • Date: 2003-03-12 14:05:33 UTC
  • Revision ID: james.westby@ubuntu.com-20030312140533-moud629bi4ryp48y
Tags: 2.2-3
tweek for running under buildd and whenever pmccabe not installed
and . not in $PATH

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
#include <Expr.h>
 
4
#include <assert.h>
 
5
 
 
6
Add::Add(Expr *e1, Expr *e2)
 
7
{
 
8
        _result.TypePtr(e1->eval_type());
 
9
        _left = e1;
 
10
        _right = e2;
 
11
}
 
12
 
 
13
Add::~Add()
 
14
{
 
15
        delete _left;
 
16
        delete _right;
 
17
}
 
18
 
 
19
void Add::print(ostream &o) const
 
20
{
 
21
        PrintBinaryExpression(o,*_left,"+",*_right);
 
22
}
 
23
 
 
24
const TypedValue &Add::eval(ValueStore &t)
 
25
{
 
26
        const TypedValue &left = _left->eval(t);
 
27
        const TypedValue &right = _right->eval(t);
 
28
 
 
29
        if(!left.HasValue() || !right.HasValue())
 
30
        {
 
31
                _result.ResetValue();
 
32
                return _result;
 
33
        }
 
34
        
 
35
        switch(left.Type())
 
36
        {
 
37
                case TypeInt:
 
38
                case TypeTime:
 
39
                        _result = (int)left + (int)right;
 
40
                        break;
 
41
                case TypeFloat:
 
42
                        _result = (float)left + (float)right;
 
43
                        break;
 
44
                case TypeString:
 
45
                        {
 
46
                                Str s=(const char *)left;
 
47
                                s += (const char *)right;
 
48
                                _result = strdup(s);
 
49
                        }
 
50
                        break;
 
51
                case TypeDate:
 
52
                        _result = (time_t)left + (time_t)right;
 
53
                        break;
 
54
                default:
 
55
                        _result.ResetValue();
 
56
        }
 
57
        return _result;
 
58
}
 
59
 
 
60
Boolean Add::modified_attributes(ConstCharPtrArray *arr, Boolean /*in_lvalue*/)
 
61
{
 
62
        return _left->modified_attributes(arr,FALSE) +  _right->modified_attributes(arr,FALSE);
 
63
}
 
64