* sim/ucsim/error.cc, sim/ucsim/errorcl.h,
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 5 Nov 2005 23:56:37 +0000 (23:56 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 5 Nov 2005 23:56:37 +0000 (23:56 +0000)
  sim/ucsim/sim.src/stack.cc, sim/ucsim/sim.src/stackcl.h,
  sim/ucsim/sim.src/uc.cc, sim/ucsim/sim.src/uccl.h,
  sim/ucsim/sim.src/mem.cc, sim/ucsim/sim.src/memcl.h,
  sim/ucsim/cmd.src/set.cc, sim/ucsim/cmd.src/show.cc:
  dynamic construction of cl_error_class and derivates - 2.nd try

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3934 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
sim/ucsim/cmd.src/set.cc
sim/ucsim/cmd.src/show.cc
sim/ucsim/error.cc
sim/ucsim/errorcl.h
sim/ucsim/sim.src/mem.cc
sim/ucsim/sim.src/memcl.h
sim/ucsim/sim.src/stack.cc
sim/ucsim/sim.src/stackcl.h
sim/ucsim/sim.src/uc.cc
sim/ucsim/sim.src/uccl.h

index 179926ebc90d86ec32aea61f260eb6f3a88ce291..b3a8ffe48ba444f5aa14c7e70da084d9dd85aac0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-11-06 Borut Razem <borut.razem AT siol.net>
+
+       * sim/ucsim/error.cc, sim/ucsim/errorcl.h,
+         sim/ucsim/sim.src/stack.cc, sim/ucsim/sim.src/stackcl.h,
+         sim/ucsim/sim.src/uc.cc, sim/ucsim/sim.src/uccl.h,
+         sim/ucsim/sim.src/mem.cc, sim/ucsim/sim.src/memcl.h,
+         sim/ucsim/cmd.src/set.cc, sim/ucsim/cmd.src/show.cc:
+         dynamic construction of cl_error_class and derivates - 2.nd try
+
 2005-11-05 Borut Razem <borut.razem AT siol.net>
 
        * sim/ucsim/sim.src/error.cc: fixed uninitialized class member variable
index 07d0134c12a2eaa65e625512c9bce1ae17a20c3c..5fd6ceaaad82dfb843a30b2f046430979a415304 100644 (file)
@@ -259,6 +259,7 @@ COMMAND_DO_WORK_APP(cl_set_error_cmd)
   else
     con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
 
+  class cl_list *registered_errors = cl_error_registry::get_list();
   if (error_name &&
       value &&
       registered_errors)
index 8f6fee137ca68aca471c684122bdcb921cff32e2..8cd4118646996c4696e16e8be94b65d22de1d0f3 100644 (file)
@@ -174,6 +174,7 @@ COMMAND_DO_WORK_APP(cl_show_error_cmd)
   else
     con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
   */
+  class cl_list *registered_errors = cl_error_registry::get_list();
   int i;
   for (i= 0; i < registered_errors->count; i++)
     {
index b63a9bf5183cdbedfc619491c1c577c28d547834..5b125a8c545346f389029dfab86712512e4c2c39 100644 (file)
@@ -45,7 +45,9 @@ struct id_element error_on_off_names[]= {
   { 0          , 0 }
 };
 
-class cl_list *registered_errors= NIL;
+static class cl_error_registry error_registry;
+
+class cl_list *cl_error_registry::registered_errors= NIL;
 
 /*
  */
@@ -57,9 +59,6 @@ cl_error_class::cl_error_class(enum error_type typ, char *aname,
   type= typ;
   on= be_on;
   set_name(aname, "not-known");
-  if (!registered_errors)
-    registered_errors= new cl_list(2, 2, "registered errors");
-  registered_errors->add(this);
 }
 
 cl_error_class::cl_error_class(enum error_type typ, char *aname,
@@ -70,9 +69,6 @@ cl_error_class::cl_error_class(enum error_type typ, char *aname,
   type= typ;
   on= be_on;
   set_name(aname, "not-known");
-  if (!registered_errors)
-    registered_errors= new cl_list(2, 2, "registered errors");
-  registered_errors->add(this);
   if (parent)
     parent->add_child(this);
 }
@@ -130,15 +126,10 @@ cl_error_class::get_type_name()
 /*
  */
 
-class cl_error_class *cl_error::error_class_base;
-
 cl_error::cl_error(void):
   cl_base()
 {
-  if (NULL == error_class_base)
-    error_class_base = new cl_error_class(err_error, "non-classified", ERROR_ON);
-  //type= err_unknown;
-  classification= error_class_base;
+  classification= error_registry.find("non-classified");
 }
 
 cl_error::~cl_error(void)
@@ -188,5 +179,11 @@ cl_error::get_type_name()
   return(get_id_string(error_type_names, type, "untyped"));
 }
 
+cl_error_registry::cl_error_registry(void)
+{
+  if (NULL == error_registry.find("non-classified"))
+    register_error(new cl_error_class(err_error, "non-classified", ERROR_ON));
+}
+
 
 /* End of sim.src/error.cc */
index a061b3a311e6d0c07de6704fff515bc8637ae04c..dd7bb8d9f16176cbe049640e9e92e2839e34e759 100644 (file)
@@ -30,6 +30,8 @@
 #ifndef ERRORCL_HEADER
 #define ERRORCL_HEADER
 
+#include <string.h>
+
 // prj
 #include "pobjcl.h"
 #include "stypes.h"
@@ -44,8 +46,6 @@ enum error_on_off {
 
 const int err_stop= (err_unknown|err_error);
 
-extern class cl_list *registered_errors;
-
 class cl_error_class: public cl_base
 {
 protected:
@@ -67,12 +67,42 @@ public:
   //char *get_name(void);
 };
 
+class cl_error_registry
+{
+public:
+  cl_error_registry(void);
+  class cl_error_class *find(char *type_name)
+  {
+    if (NIL == registered_errors)
+      return NIL;
+    return static_cast<class cl_error_class *>(registered_errors->first_that(compare, static_cast<void *>(type_name)));
+  }
+  static class cl_list *get_list(void)
+  {
+    return registered_errors;
+  }
+
+protected:
+  class cl_error_class *register_error(class cl_error_class *error_class)
+  {
+    if (!registered_errors)
+      registered_errors= new cl_list(2, 2, "registered errors");
+    registered_errors->add(error_class);
+    return error_class;
+  }
+
+private:
+  static class cl_list *registered_errors;
+  static int compare(void *obj1, void *obj2)
+  {
+    return (static_cast<class cl_base *>(obj1))->is_named(static_cast<char *>(obj2));
+  }
+};
+
 class cl_commander; //forward
 
 class cl_error: public cl_base
 {
-private:
-  static class cl_error_class *error_class_base;
 protected:
   class cl_error_class *classification;
 public:
@@ -93,7 +123,7 @@ public:
   virtual char *get_type_name();
 };
 
-
 #endif
 
+
 /* End of sim.src/errorcl.h */
index 1ac443ee582a1e6a0ddc3b2eb336b733e5d23ecd..6be08f6460a2f7873e59538b8633411f8fe271dc 100644 (file)
@@ -48,6 +48,8 @@
 #include "hwcl.h"
 
 
+static class cl_mem_error_registry mem_error_registry;
+
 /*
  *                                                3rd version of memory system
  */
@@ -1378,28 +1380,20 @@ cl_decoder_list::compare(void *key1, void *key2)
 
 /* All of memory errors */
 
-class cl_error_class *cl_error_mem::error_mem_class;
-
 cl_error_mem::cl_error_mem(class cl_memory *amem, t_addr aaddr)
 {
   mem= amem;
   addr= aaddr;
-  if (NULL == error_mem_class)
-    error_mem_class= new cl_error_class(err_error, "memory", classification, ERROR_OFF);
-  classification= error_mem_class;
+  classification= mem_error_registry.find("memory");
 }
 
 /* Invalid address in memory access */
 
-class cl_error_class *cl_error_mem_invalid_address::error_mem_invalid_address_class;
-
 cl_error_mem_invalid_address::
 cl_error_mem_invalid_address(class cl_memory *amem, t_addr aaddr):
   cl_error_mem(amem, aaddr)
 {
-  if (NULL == error_mem_invalid_address_class)
-    error_mem_invalid_address_class= new cl_error_class(err_error, "invalid_address", classification);
-  classification= error_mem_invalid_address_class;
+  classification= mem_error_registry.find("invalid_address");
 }
 
 void
@@ -1413,15 +1407,11 @@ cl_error_mem_invalid_address::print(class cl_commander *c)
 
 /* Non-decoded address space access */
 
-class cl_error_class *cl_error_mem_non_decoded::error_mem_non_decoded_class;
-
 cl_error_mem_non_decoded::
 cl_error_mem_non_decoded(class cl_memory *amem, t_addr aaddr):
   cl_error_mem(amem, aaddr)
 {
-  if (NULL == error_mem_non_decoded_class)
-    error_mem_non_decoded_class= new cl_error_class(err_error, "non_decoded", classification);
-  classification= error_mem_non_decoded_class;
+  classification= mem_error_registry.find("non_decoded");
 }
 
 void
@@ -1433,5 +1423,13 @@ cl_error_mem_non_decoded::print(class cl_commander *c)
   cmd_fprintf(f, " in memory %s.\n", mem->get_name());
 }
 
+cl_mem_error_registry::cl_mem_error_registry(void)
+{
+  class cl_error_class *prev = mem_error_registry.find("non-classified");
+  prev = register_error(new cl_error_class(err_error, "memory", prev, ERROR_OFF));
+  prev = register_error(new cl_error_class(err_error, "invalid_address", prev));
+  prev = register_error(new cl_error_class(err_error, "non_decoded", prev));
+}
+
 
 /* End of mem.cc */
index 855028acb82f2cedafc0473857ddb76a0251aeff..e12819b7b2507743531cd0fe45bdf1a8a664bfa0 100644 (file)
@@ -422,8 +422,6 @@ public:
 
 class cl_error_mem: public cl_error
 {
-private:
-  static class cl_error_class *error_mem_class;
 protected:
   class cl_memory *mem;
   t_addr addr;
@@ -433,8 +431,6 @@ public:
 
 class cl_error_mem_invalid_address: public cl_error_mem
 {
-private:
-  static class cl_error_class *error_mem_invalid_address_class;
 public:
   cl_error_mem_invalid_address(class cl_memory *amem, t_addr aaddr);
 
@@ -443,15 +439,19 @@ public:
 
 class cl_error_mem_non_decoded: public cl_error_mem
 {
-private:
-  static class cl_error_class *error_mem_non_decoded_class;
 public:
   cl_error_mem_non_decoded(class cl_memory *amem, t_addr aaddr);
 
   virtual void print(class cl_commander *c);
 };
 
+class cl_mem_error_registry: public cl_error_registry
+{
+public:
+  cl_mem_error_registry(void);
+};
 
 #endif
 
+
 /* End of memcl.h */
index f10ab8fc077b273db6fcaaa1eb71e9a77ffb116c..39a8b16fdf80621edc4bb996ab2f9070e9ff21a1 100644 (file)
@@ -34,6 +34,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "stackcl.h"
 
 
+static class cl_stack_error_registry stack_error_registry;
+
 cl_stack_op::cl_stack_op(enum stack_op op,
                         t_addr iPC,
                         t_addr iSP_before, t_addr iSP_after):
@@ -420,39 +422,25 @@ cl_stack_pop::match(class cl_stack_op *op)
  * Stack Errors
  */
 
-class cl_error_class *cl_error_stack::error_stack_class;
-
 cl_error_stack::cl_error_stack(void)
 {
-  if (NULL == error_stack_class)
-    error_stack_class= new cl_error_class(err_error, "stack", classification, ERROR_OFF);
-  classification= error_stack_class;
+  classification = stack_error_registry.find("stack");
 }
 
 /* Stack Tracker Errors */
 
-class cl_error_class *cl_error_stack_tracker::error_stack_tracker_class;
-
 cl_error_stack_tracker::cl_error_stack_tracker(void)
 {
-//  cl_error_class *error_stack_tracker_class = new cl_error_class(err_error, "stack_tracker", error_stack_class, ERROR_OFF);
-//  classification= &error_stack_tracker_class;
-  if (NULL == error_stack_tracker_class)
-    error_stack_tracker_class= new cl_error_class(err_error, "stack_tracker", classification);
-  classification= error_stack_tracker_class;
+  classification = stack_error_registry.find("stack_tracker");
 }
 
 /* Stack Tracker: wrong handle */
 
-class cl_error_class *cl_error_stack_tracker_wrong_handle::error_stack_tracker_wrong_handle_class;
-
 cl_error_stack_tracker_wrong_handle::cl_error_stack_tracker_wrong_handle(bool write_op):
   cl_error_stack_tracker()
 {
   write_operation= write_op;
-  if (NULL == error_stack_tracker_wrong_handle_class)
-    error_stack_tracker_wrong_handle_class= new cl_error_class(err_error, "stack_tracker_wrong_handle", classification);
-  classification= error_stack_tracker_wrong_handle_class;
+  classification = stack_error_registry.find("stack_tracker_wrong_handle");
 }
 
 void
@@ -464,16 +452,12 @@ cl_error_stack_tracker_wrong_handle::print(class cl_commander *c)
 
 /* Stack Tracker: operation on empty stack */
 
-class cl_error_class *cl_error_stack_tracker_empty::error_stack_tracker_empty_class;
-
 cl_error_stack_tracker_empty::
 cl_error_stack_tracker_empty(class cl_stack_op *op):
   cl_error_stack_tracker()
 {
   operation= op->mk_copy();
-  if (NULL == error_stack_tracker_empty_class)
-    error_stack_tracker_empty_class= new cl_error_class(err_error, "operation_on_empty_stack", classification);
-  classification= error_stack_tracker_empty_class;
+  classification = stack_error_registry.find("operation_on_empty_stack");
 }
 
 cl_error_stack_tracker_empty::~cl_error_stack_tracker_empty(void)
@@ -492,17 +476,13 @@ cl_error_stack_tracker_empty::print(class cl_commander *c)
 
 /* Stack Tracker: operation on empty stack */
 
-class cl_error_class *cl_error_stack_tracker_unmatch::error_stack_tracker_unmatch_class;
-
 cl_error_stack_tracker_unmatch::
 cl_error_stack_tracker_unmatch(class cl_stack_op *Top, class cl_stack_op *op):
   cl_error_stack_tracker()
 {
   top= Top->mk_copy();
   operation= op->mk_copy();
-  if (NULL == error_stack_tracker_unmatch_class)
-    error_stack_tracker_unmatch_class= new cl_error_class(err_warning, "stack_operation_unmatched_to_top_of_stack", classification);
-  classification= error_stack_tracker_unmatch_class;
+  classification = stack_error_registry.find("stack_operation_unmatched_to_top_of_stack");
 }
 
 cl_error_stack_tracker_unmatch::~cl_error_stack_tracker_unmatch(void)
@@ -523,17 +503,13 @@ cl_error_stack_tracker_unmatch::print(class cl_commander *c)
 
 /* Stack Tracker: stack is inconsistent */
 
-class cl_error_class *cl_error_stack_tracker_inconsistent::error_stack_tracker_inconsistent_class;
-
 cl_error_stack_tracker_inconsistent::
 cl_error_stack_tracker_inconsistent(class cl_stack_op *op,
                                    int the_unread_data_size)
 {
   operation= op->mk_copy();
   unread_data_size= the_unread_data_size;
-  if (NULL == error_stack_tracker_inconsistent_class)
-    error_stack_tracker_inconsistent_class= new cl_error_class(err_warning, "stack_looks_corrupted", classification);
-  classification= error_stack_tracker_inconsistent_class;
+  classification = stack_error_registry.find("stack_looks_corrupted");
 }
 
 cl_error_stack_tracker_inconsistent::~cl_error_stack_tracker_inconsistent(void)
@@ -549,5 +525,16 @@ cl_error_stack_tracker_inconsistent::print(class cl_commander *c)
               unread_data_size);
 }
 
+cl_stack_error_registry::cl_stack_error_registry(void)
+{
+  class cl_error_class *prev = stack_error_registry.find("non-classified");
+  prev = register_error(new cl_error_class(err_error, "stack", prev, ERROR_OFF));
+  prev = register_error(new cl_error_class(err_error, "stack_tracker", prev));
+  prev = register_error(new cl_error_class(err_error, "stack_tracker_wrong_handle", prev));
+  prev = register_error(new cl_error_class(err_error, "operation_on_empty_stack", prev));
+  prev = register_error(new cl_error_class(err_warning, "stack_operation_unmatched_to_top_of_stack", prev));
+  prev = register_error(new cl_error_class(err_warning, "stack_looks_corrupted", prev));
+}
+
 
 /* End of sim.src/stack.cc */
index e4dd4e4c4c265fca58decb6f0f2fd9003b27fa5e..15c97dc27455e81bf3c1027171882870c46e1f7b 100644 (file)
@@ -173,8 +173,6 @@ public:
 /*
  * All kind of stack errors
  */
-//extern class cl_error_class error_stack_class;
-//class cl_error_stack: public cl_error
 class cl_error_stack: public cl_error
 {
 private:
@@ -188,16 +186,12 @@ public:
  */
 class cl_error_stack_tracker: public cl_error_stack
 {
-private:
-  static class cl_error_class *error_stack_tracker_class;
 public:
   cl_error_stack_tracker(void);
 };
 
 class cl_error_stack_tracker_wrong_handle: public cl_error_stack_tracker
 {
-private:
-  static class cl_error_class *error_stack_tracker_wrong_handle_class;
 public:
   bool write_operation;
 public:
@@ -208,8 +202,6 @@ public:
 
 class cl_error_stack_tracker_empty: public cl_error_stack_tracker
 {
-private:
-  static class cl_error_class *error_stack_tracker_empty_class;
 protected:
   class cl_stack_op *operation;
 public:
@@ -221,8 +213,6 @@ public:
 
 class cl_error_stack_tracker_unmatch: public cl_error_stack_tracker
 {
-private:
-  static class cl_error_class *error_stack_tracker_unmatch_class;
 protected:
   class cl_stack_op *top, *operation;
 public:
@@ -235,8 +225,6 @@ public:
 
 class cl_error_stack_tracker_inconsistent: public cl_error_stack_tracker
 {
-private:
-  static class cl_error_class *error_stack_tracker_inconsistent_class;
 protected:
   class cl_stack_op *operation;
   int unread_data_size;
@@ -248,7 +236,13 @@ public:
   virtual void print(class cl_commander *c);
 };
 
+class cl_stack_error_registry: public cl_error_registry
+{
+public:
+  cl_stack_error_registry(void);
+};
 
 #endif
 
+
 /* End of sim.src/stackcl.h */
index 374b3af701af3313fa9cc45e6d5b17982c566985..8af862db2c2dcd06fb12ec7f9b84da287ac9b5e0 100644 (file)
@@ -56,6 +56,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "simcl.h"
 #include "itsrccl.h"
 
+static class cl_uc_error_registry uc_error_registry;
 
 /*
  * Clock counter
@@ -1855,14 +1856,10 @@ cl_uc::check_events(void)
  *----------------------------------------------------------------------------
  */
 
-class cl_error_class *cl_error_unknown_code::error_unknown_code_class;
-
 cl_error_unknown_code::cl_error_unknown_code(class cl_uc *the_uc)
 {
   uc= the_uc;
-  if (NULL == error_unknown_code_class)
-    error_unknown_code_class= new cl_error_class(err_error, "unknown_code", classification, ERROR_OFF);
-  classification= error_unknown_code_class;
+  classification= uc_error_registry.find("unknown_code");
 }
 
 void
@@ -1882,5 +1879,11 @@ cl_error_unknown_code::print(class cl_commander *c)
   cmd_fprintf(f, "\n");
 }
 
+cl_uc_error_registry::cl_uc_error_registry(void)
+{
+  class cl_error_class *prev = uc_error_registry.find("non-classified");
+  prev = register_error(new cl_error_class(err_error, "unknown_code", prev, ERROR_OFF));
+}
+
 
 /* End of uc.cc */
index dada96ec233ca2820c570a5d344e19dc41eb3b1a..d26af2076a3aa65f8227ddb15bb4003f552c1617 100644 (file)
@@ -247,8 +247,6 @@ public:
 
 class cl_error_unknown_code: public cl_error
 {
-private:
-  static class cl_error_class *error_unknown_code_class;
 protected:
   class cl_uc *uc;
 public:
@@ -257,7 +255,13 @@ public:
   virtual void print(class cl_commander *c);
 };
 
+class cl_uc_error_registry: public cl_error_registry
+{
+public:
+  cl_uc_error_registry(void);
+};
 
 #endif
 
+
 /* End of uccl.h */