CBMC
irep_ids.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Internal Representation
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "irep_ids.h"
13 
14 #include "invariant.h"
15 
16 #include "string_container.h"
17 
18 const char *irep_ids_table[]=
19 {
20 #define IREP_ID_ONE(id) #id,
21 #define IREP_ID_TWO(id, str) #str,
22 
23 #include "irep_ids.def"
24 
25  nullptr,
26 };
27 
28 #ifdef USE_DSTRING
29 
30 enum class idt:unsigned
31 {
32 #define IREP_ID_ONE(the_id) id_##the_id,
33 #define IREP_ID_TWO(the_id, str) id_##the_id,
34 
35 #include "irep_ids.def" // NOLINT(build/include)
36 };
37 
38 #define IREP_ID_ONE(the_id) \
39  const dstringt ID_##the_id=dstringt::make_from_table_index( \
40  static_cast<unsigned>(idt::id_##the_id));
41 #define IREP_ID_TWO(the_id, str) \
42  const dstringt ID_##the_id=dstringt::make_from_table_index( \
43  static_cast<unsigned>(idt::id_##the_id));
44 
45 #else
46 
47 #define IREP_ID_ONE(the_id) const std::string ID_##the_id(#the_id);
48 #define IREP_ID_TWO(the_id, str) const std::string ID_##the_id(#the_id);
49 
50 #endif
51 
52 #include "irep_ids.def" // NOLINT(build/include)
53 
55 {
56  // pre-allocate empty string -- this gets index 0
57  get("");
58 
59  // allocate strings
60  for(unsigned i=0; irep_ids_table[i]!=nullptr; i++)
61  {
62  unsigned x=operator[](irep_ids_table[i]);
63  INVARIANT(x==i, "i-th element is inserted at position i"); // sanity check
64  }
65 }
string_containert::string_containert
string_containert()
Definition: irep_ids.cpp:54
invariant.h
string_container.h
idt
idt
Definition: irep_ids.cpp:30
irep_ids.h
irep_ids_table
const char * irep_ids_table[]
Definition: irep_ids.cpp:18
string_containert::get
unsigned get(const char *s)
Definition: string_container.cpp:34
string_containert::operator[]
unsigned operator[](const char *s)
Definition: string_container.h:66
validation_modet::INVARIANT
@ INVARIANT