Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
31ad63ffefb7384ff1866f2c4805b5f8c82dbea0
[simgrid.git] / src / mc / Type.hpp
1 /* Copyright (c) 2007-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_MC_TYPE_HPP
8 #define SIMGRID_MC_TYPE_HPP
9
10 #include <vector>
11 #include <string>
12
13 #include <xbt/base.h>
14
15 #include "src/mc/mc_forward.h"
16 #include "src/mc/LocationList.hpp"
17
18 namespace simgrid {
19 namespace mc {
20
21 /** A member of a structure, union
22  *
23  *  Inheritance is seen as a special member as well.
24  */
25 class Member {
26 public:
27   Member() {}
28
29   bool inheritance = false;
30   std::string name;
31   simgrid::dwarf::DwarfExpression location_expression;
32   std::size_t byte_size = 0; // Do we really need this?
33   unsigned type_id = 0;
34   simgrid::mc::Type* type = nullptr;
35
36   bool has_offset_location() const
37   {
38     return location_expression.size() == 1 &&
39       location_expression[0].atom == DW_OP_plus_uconst;
40   }
41
42   // TODO, check if this shortcut is really necessary
43   int offset() const
44   {
45     xbt_assert(this->has_offset_location());
46     return this->location_expression[0].number;
47   }
48
49   void offset(int new_offset)
50   {
51     Dwarf_Op op;
52     op.atom = DW_OP_plus_uconst;
53     op.number = new_offset;
54     this->location_expression = { op };
55   }
56 };
57
58 /** A type in the model-checked program */
59 class Type {
60 public:
61   Type() {}
62   Type(Type const& type) = default;
63   Type& operator=(Type const&) = default;
64   Type(Type&& type) = default;
65   Type& operator=(Type&&) = default;
66
67   /** The DWARF TAG of the type (e.g. DW_TAG_array_type) */
68   int type = 0;
69   unsigned id = 0; /* Offset in the section (in hexadecimal form) */
70   std::string name; /* Name of the type */
71   int byte_size = 0; /* Size in bytes */
72   int element_count = 0; /* Number of elements for array type */
73   unsigned type_id = 0; /* DW_AT_type id */
74   std::vector<Member> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
75
76   simgrid::mc::Type* subtype = nullptr; // DW_AT_type
77   simgrid::mc::Type* full_type = nullptr; // The same (but more complete) type
78 };
79
80 }
81 }
82
83 #endif