Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into S4U
[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 "mc_forward.h"
14 #include "mc_location.h"
15
16 namespace simgrid {
17 namespace mc {
18
19 /** Represents a type in the program
20  *
21  *  It is currently used to represent members of structs and unions as well.
22  */
23 class Type {
24 public:
25   Type();
26   Type(Type const& type) = default;
27   Type& operator=(Type const&) = default;
28   Type(Type&& type) = default;
29   Type& operator=(Type&&) = default;
30
31   /** The DWARF TAG of the type (e.g. DW_TAG_array_type) */
32   int type;
33   unsigned id; /* Offset in the section (in hexadecimal form) */
34   std::string name; /* Name of the type */
35   int byte_size; /* Size in bytes */
36   int element_count; /* Number of elements for array type */
37   unsigned type_id; /* DW_AT_type id */
38   std::vector<Type> members; /* if DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type*/
39   int is_pointer_type;
40
41   // Location (for members) is either of:
42   simgrid::mc::DwarfExpression location_expression;
43
44   simgrid::mc::Type* subtype; // DW_AT_type
45   simgrid::mc::Type* full_type; // The same (but more complete) type
46
47   bool has_offset_location() const
48   {
49     return location_expression.size() == 1 &&
50       location_expression[0].atom == DW_OP_plus_uconst;
51   }
52
53   // TODO, check if this shortcut is really necessary
54   int offset() const
55   {
56     xbt_assert(this->has_offset_location());
57     return this->location_expression[0].number;
58   }
59
60   void offset(int new_offset)
61   {
62     Dwarf_Op op;
63     op.atom = DW_OP_plus_uconst;
64     op.number = new_offset;
65     this->location_expression = { op };
66   }
67 };
68
69 inline
70 Type::Type()
71 {
72   this->type = 0;
73   this->id = 0;
74   this->byte_size = 0;
75   this->element_count = 0;
76   this->is_pointer_type = 0;
77   this->type_id = 0;
78   this->subtype = nullptr;
79   this->full_type = nullptr;
80 }
81
82 }
83 }
84
85 #endif