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