* sim/ucsim/error.cc, sim/ucsim/errorcl.h,
[fw/sdcc] / sim / ucsim / error.cc
1 /*
2  * Simulator of microcontrollers (error.cc)
3  *
4  * Copyright (C) 2001,01 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /*
11   This file is part of microcontroller simulator: ucsim.
12
13   UCSIM is free software; you can redistribute it and/or modify
14   it under the terms of the GNU General Public License as published by
15   the Free Software Foundation; either version 2 of the License, or
16   (at your option) any later version.
17
18   UCSIM is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21   GNU General Public License for more details.
22
23   You should have received a copy of the GNU General Public License
24   along with UCSIM; see the file COPYING.  If not, write to the Free
25   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26   02111-1307, USA.
27 */
28 /*@1@*/
29
30 #include <stdlib.h>
31 #include "i_string.h"
32
33 // prj (local)
34 #include "errorcl.h"
35 #include "globals.h"
36 #include "utils.h"
37
38 // cmd.src
39 #include "newcmdcl.h"
40
41 struct id_element error_on_off_names[]= {
42   { ERROR_PARENT, "unset" },
43   { ERROR_ON    , "on" },
44   { ERROR_OFF   , "off" },
45   { 0           , 0 }
46 };
47
48 static class cl_error_registry error_registry;
49
50 class cl_list *cl_error_registry::registered_errors= NIL;
51
52 /*
53  */
54
55 cl_error_class::cl_error_class(enum error_type typ, char *aname,
56                                enum error_on_off be_on/* = ERROR_PARENT*/):
57   cl_base()
58 {
59   type= typ;
60   on= be_on;
61   set_name(aname, "not-known");
62 }
63
64 cl_error_class::cl_error_class(enum error_type typ, char *aname,
65                                class cl_error_class *parent,
66                                enum error_on_off be_on/* = ERROR_PARENT*/):
67   cl_base()
68 {
69   type= typ;
70   on= be_on;
71   set_name(aname, "not-known");
72   if (parent)
73     parent->add_child(this);
74 }
75
76 void
77 cl_error_class::set_on(enum error_on_off val)
78 {
79   if (!get_parent() &&
80       val == ERROR_PARENT)
81     return;
82   on= val;
83 }
84
85 bool
86 cl_error_class::is_on(void)
87 {
88   if (on == ERROR_PARENT)
89     {
90       if (!get_parent())
91         return(DD_TRUE);
92       class cl_error_class *p=
93         dynamic_cast<class cl_error_class *>(get_parent());
94       return(p->is_on());
95     }
96   else
97     return(on == ERROR_ON);
98 }
99
100 enum error_type
101 cl_error_class::get_type(void)
102 {
103   return(type);
104 }
105
106 /*char *
107 cl_error_class::get_name(void)
108 {
109   return(name);
110 }*/
111
112 char *
113 cl_error_class::get_type_name()
114 {
115   return(get_id_string(error_type_names, type, "untyped"));
116   /*switch (type)
117     {
118     case err_unknown: return("unclassified"); break;
119     case err_error: return("error"); break;
120     case err_warning: return("warning"); break;
121     }
122     return("untyped");*/
123 }
124
125
126 /*
127  */
128
129 cl_error::cl_error(void):
130   cl_base()
131 {
132   classification= error_registry.find("non-classified");
133 }
134
135 cl_error::~cl_error(void)
136 {}
137
138 int
139 cl_error::init(void)
140 {
141   //type= get_type();
142   return(0);
143 }
144
145 enum error_type
146 cl_error::get_type(void)
147 {
148   if (classification)
149     return(classification->get_type());
150   return(err_unknown);
151 }
152
153 enum error_on_off
154 cl_error::get_on(void)
155 {
156   if (!classification)
157     return(ERROR_ON);
158   return(classification->get_on());
159 }
160
161 bool
162 cl_error::is_on(void)
163 {
164   if (!classification)
165     return(DD_TRUE);
166   return(classification->is_on());
167 }
168
169 void
170 cl_error::print(class cl_commander *c)
171 {
172   c->dd_printf("%s\n", get_type_name());
173 }
174
175 char *
176 cl_error::get_type_name()
177 {
178   enum error_type type= get_type();
179   return(get_id_string(error_type_names, type, "untyped"));
180 }
181
182 cl_error_registry::cl_error_registry(void)
183 {
184   if (NULL == error_registry.find("non-classified"))
185     register_error(new cl_error_class(err_error, "non-classified", ERROR_ON));
186 }
187
188
189 /* End of sim.src/error.cc */