a8c533bbc7f5d40bce7ca99ad00fbe83631be4ec
[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 class cl_error_class error_class_base(err_error, "non-classified", ERROR_ON);
49
50 class cl_list *registered_errors= NIL;
51
52 /*
53  */
54
55 cl_error_class::cl_error_class(enum error_type typ, char *aname):
56   cl_base()
57 {
58   type= typ;
59   on= ERROR_PARENT;
60   set_name(aname, "not-known");
61   if (!registered_errors)
62     registered_errors= new cl_list(2, 2, "registered errors");
63   registered_errors->add(this);
64 }
65
66 cl_error_class::cl_error_class(enum error_type typ, char *aname,
67                                enum error_on_off be_on):
68   cl_base()
69 {
70   type= typ;
71   on= be_on;
72   set_name(aname, "not-known");
73   if (!registered_errors)
74     registered_errors= new cl_list(2, 2, "registered errors");
75   registered_errors->add(this);
76 }
77
78 cl_error_class::cl_error_class(enum error_type typ, char *aname,
79                                class cl_error_class *parent):
80   cl_base()
81 {
82   type= typ;
83   on= ERROR_PARENT;
84   set_name(aname, "not-known");
85   if (!registered_errors)
86     registered_errors= new cl_list(2, 2, "registered errors");
87   registered_errors->add(this);
88   if (parent)
89     parent->add_child(this);
90 }
91
92 cl_error_class::cl_error_class(enum error_type typ, char *aname,
93                                class cl_error_class *parent,
94                                enum error_on_off be_on):
95   cl_base()
96 {
97   type= typ;
98   on= be_on;
99   set_name(aname, "not-known");
100   if (!registered_errors)
101     registered_errors= new cl_list(2, 2, "registered errors");
102   registered_errors->add(this);
103   if (parent)
104     parent->add_child(this);
105 }
106
107 void
108 cl_error_class::set_on(enum error_on_off val)
109 {
110   if (!get_parent() &&
111       val == ERROR_PARENT)
112     return;
113   on= val;
114 }
115
116 bool
117 cl_error_class::is_on(void)
118 {
119   if (on == ERROR_PARENT)
120     {
121       if (!get_parent())
122         return(DD_TRUE);
123       class cl_error_class *p=
124         dynamic_cast<class cl_error_class *>(get_parent());
125       return(p->is_on());
126     }
127   else
128     return(on == ERROR_ON);
129 }
130
131 enum error_type
132 cl_error_class::get_type(void)
133 {
134   return(type);
135 }
136
137 /*char *
138 cl_error_class::get_name(void)
139 {
140   return(name);
141 }*/
142
143 char *
144 cl_error_class::get_type_name()
145 {
146   return(get_id_string(error_type_names, type, "untyped"));
147   /*switch (type)
148     {
149     case err_unknown: return("unclassified"); break;
150     case err_error: return("error"); break;
151     case err_warning: return("warning"); break;
152     }
153     return("untyped");*/
154 }
155
156
157 /*
158  */
159
160 cl_error::cl_error(void):
161   cl_base()
162 {
163   //type= err_unknown;
164   classification= 0;
165 }
166
167 cl_error::~cl_error(void)
168 {}
169
170 int
171 cl_error::init(void)
172 {
173   //type= get_type();
174   return(0);
175 }
176
177 enum error_type
178 cl_error::get_type(void)
179 {
180   if (classification)
181     return(classification->get_type());
182   return(err_unknown);
183 }
184
185 enum error_on_off
186 cl_error::get_on(void)
187 {
188   if (!classification)
189     return(ERROR_ON);
190   return(classification->get_on());
191 }
192
193 bool
194 cl_error::is_on(void)
195 {
196   if (!classification)
197     return(DD_TRUE);
198   return(classification->is_on());
199 }
200
201 void
202 cl_error::print(class cl_commander *c)
203 {
204   c->dd_printf("%s\n", get_type_name());
205 }
206
207 char *
208 cl_error::get_type_name()
209 {
210   enum error_type type= get_type();
211   return(get_id_string(error_type_names, type, "untyped"));
212 }
213
214
215 /* End of sim.src/error.cc */