[ucsim] Update email and file info, fix stm8 flash controller
[sdcc.git] / sdcc / sim / ucsim / src / core / utils.src / error.cc
blob6faf22f58ed614ddeebbc8e8e3b482731d06bc66
1 /*
2 * Simulator of microcontrollers (error.cc)
4 * Copyright (C) 1997 Drotos Daniel
5 *
6 * To contact author send email to dr.dkdb@gmail.com
8 */
10 /* This file is part of microcontroller simulator: ucsim.
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
28 #include <stdlib.h>
29 #include "i_string.h"
31 // prj (local)
32 #include "errorcl.h"
33 #include "globals.h"
34 #include "utils.h"
36 // cmd.src
37 #include "newcmdcl.h"
39 struct id_element error_on_off_names[]= {
40 { ERROR_PARENT, "unset" },
41 { ERROR_ON , "on" },
42 { ERROR_OFF , "off" },
43 { 0 , 0 }
46 static class cl_error_registry error_registry;
48 class cl_list *cl_error_registry::registered_errors= 0;
53 cl_error_class::cl_error_class(enum error_type typ, const char *aname,
54 enum error_on_off be_on/* = ERROR_PARENT*/):
55 cl_base()
57 type= typ;
58 on= be_on;
59 set_name(aname, "not-known");
62 cl_error_class::cl_error_class(enum error_type typ, const char *aname,
63 class cl_error_class *parent,
64 enum error_on_off be_on/* = ERROR_PARENT*/):
65 cl_base()
67 type= typ;
68 on= be_on;
69 set_name(aname, "not-known");
70 if (parent)
71 parent->add_child(this);
74 void
75 cl_error_class::set_on(enum error_on_off val)
77 if (!get_parent() &&
78 val == ERROR_PARENT)
79 return;
80 on= val;
83 bool
84 cl_error_class::is_on(void)
86 if (on == ERROR_PARENT)
88 if (!get_parent())
89 return(true);
90 class cl_error_class *p=
91 (class cl_error_class *)(get_parent());
92 return(p->is_on());
94 else
95 return(on == ERROR_ON);
98 enum error_type
99 cl_error_class::get_type(void)
101 return(type);
104 /*char *
105 cl_error_class::get_name(void)
107 return(name);
110 const char *
111 cl_error_class::get_type_name(void)
113 return(get_id_string(error_type_names, type, "untyped"));
114 /*switch (type)
116 case err_unknown: return("unclassified"); break;
117 case err_error: return("error"); break;
118 case err_warning: return("warning"); break;
120 return("untyped");*/
127 cl_error::cl_error(void):
128 cl_base()
130 classification= error_registry.find("non-classified");
134 cl_error::~cl_error(void)
138 cl_error::init(void)
140 //type= get_type();
141 return(0);
144 enum error_type
145 cl_error::get_type(void)
147 if (classification)
148 return(classification->get_type());
149 return(err_unknown);
152 enum error_on_off
153 cl_error::get_on(void)
155 if (!classification)
156 return(ERROR_ON);
157 return(classification->get_on());
160 bool
161 cl_error::is_on(void)
163 if (!classification)
164 return(true);
165 return(classification->is_on());
168 void
169 cl_error::print(class cl_commander_base *c)
171 c->dd_cprintf("error", "%s\n", (char *)get_type_name());
174 const char *
175 cl_error::get_type_name(void)
177 enum error_type type= get_type();
178 return(get_id_string(error_type_names, type, "untyped"));
181 cl_error_registry::cl_error_registry(void)
183 if (NULL == error_registry.find("non-classified"))
184 register_error(new cl_error_class(err_error, "non-classified", ERROR_ON));
187 /* End of sim.src/error.cc */