Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Rename PerPageCopy to ChunkedData (and move in its own files)
[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 "mc_forward.h"
16 #include "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() : inheritance(false), byte_size(0), type_id(0) {}
28
29   bool inheritance;
30   std::string name;
31   simgrid::dwarf::DwarfExpression location_expression;
32   std::size_t byte_size; // Do we really need this?
33   unsigned type_id;
34   simgrid::mc::Type* type;
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;
69   unsigned id; /* Offset in the section (in hexadecimal form) */
70   std::string name; /* Name of the type */
71   int byte_size; /* Size in bytes */
72   int element_count; /* Number of elements for array type */
73   unsigned type_id; /* DW_AT_type id */
74   std::vector<Member> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
75   int is_pointer_type;
76
77   simgrid::mc::Type* subtype; // DW_AT_type
78   simgrid::mc::Type* full_type; // The same (but more complete) type
79 };
80
81 inline
82 Type::Type()
83 {
84   this->type = 0;
85   this->id = 0;
86   this->byte_size = 0;
87   this->element_count = 0;
88   this->is_pointer_type = 0;
89   this->type_id = 0;
90   this->subtype = nullptr;
91   this->full_type = nullptr;
92 }
93
94 }
95 }
96
97 #endif