Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
42978af47bba2bbede4094afe7614545c402379f
[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_location.h"
17
18 namespace simgrid {
19 namespace mc {
20
21 /** Represent a member of  a structure (or inheritance) */
22 class Member {
23 public:
24   Member() : inheritance(false), byte_size(0), type_id(0) {}
25
26   bool inheritance;
27   std::string name;
28   simgrid::dwarf::DwarfExpression location_expression;
29   std::size_t byte_size; // Do we really need this?
30   unsigned type_id;
31   simgrid::mc::Type* type;
32
33   bool has_offset_location() const
34   {
35     return location_expression.size() == 1 &&
36       location_expression[0].atom == DW_OP_plus_uconst;
37   }
38
39   // TODO, check if this shortcut is really necessary
40   int offset() const
41   {
42     xbt_assert(this->has_offset_location());
43     return this->location_expression[0].number;
44   }
45
46   void offset(int new_offset)
47   {
48     Dwarf_Op op;
49     op.atom = DW_OP_plus_uconst;
50     op.number = new_offset;
51     this->location_expression = { op };
52   }
53 };
54
55 /** Represents a type in the program
56  *
57  *  It is currently used to represent members of structs and unions as well.
58  */
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