1 //
2 // aegis - project change supervisor
3 // Copyright (C) 1994, 1996, 2002-2008, 2012 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published
7 // by the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #include <common/ac/assert.h>
20 
21 #include <common/mem.h>
22 #include <common/symtab.h>
23 #include <common/trace.h>
24 #include <libaegis/aer/expr/struct.h>
25 #include <libaegis/aer/value/struct.h>
26 #include <libaegis/aer/value/void.h>
27 
28 static size_t ntab;
29 static size_t ntab_max;
30 static rpt_value_struct **tab;
31 
32 
33 static void
symtab_push(rpt_value_struct * stp)34 symtab_push(rpt_value_struct *stp)
35 {
36     trace(("%s\n", __PRETTY_FUNCTION__));
37     if (ntab >= ntab_max)
38     {
39         size_t new_ntab_max = ntab_max * 2 + 4;
40         rpt_value_struct **new_tab = new rpt_value_struct * [new_ntab_max];
41         for (size_t j = 0; j < ntab; ++j)
42             new_tab[j] = tab[j];
43         delete [] tab;
44         tab = new_tab;
45         ntab_max = new_ntab_max;
46     }
47     tab[ntab++] = stp;
48 }
49 
50 
51 static void
symtab_pop(void)52 symtab_pop(void)
53 {
54     trace(("%s\n", __PRETTY_FUNCTION__));
55     assert(ntab);
56     --ntab;
57     tab[ntab] = 0;
58 }
59 
60 
61 rpt_value_struct *
symtab_query(void)62 rpt_expr_struct::symtab_query(void)
63 {
64     trace(("%s\n", __PRETTY_FUNCTION__));
65     assert(ntab);
66     return tab[ntab - 1];
67 }
68 
69 
~rpt_expr_struct()70 rpt_expr_struct::~rpt_expr_struct()
71 {
72 }
73 
74 
rpt_expr_struct()75 rpt_expr_struct::rpt_expr_struct()
76 {
77 }
78 
79 
80 rpt_expr::pointer
create()81 rpt_expr_struct::create()
82 {
83     trace(("%s\n", __PRETTY_FUNCTION__));
84     return pointer(new rpt_expr_struct());
85 }
86 
87 
88 rpt_value::pointer
evaluate() const89 rpt_expr_struct::evaluate()
90     const
91 {
92     trace(("%s\n", __PRETTY_FUNCTION__));
93     rpt_value_struct *stp = new rpt_value_struct();
94     symtab_push(stp);
95     rpt_value::pointer result(stp);
96     for (size_t j = 0; ; ++j)
97     {
98         rpt_expr::pointer ep = nth_child(j);
99         if (!ep)
100             break;
101         rpt_value::pointer vp = ep->evaluate(false, false);
102         if (vp->is_an_error())
103         {
104             symtab_pop();
105             return vp;
106         }
107         assert(dynamic_cast<rpt_value_void *>(vp.get()));
108     }
109     symtab_pop();
110     return result;
111 }
112 
113 
114 // vim: set ts=8 sw=4 et :
115