Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / mc / inspect / DwarfExpression.hpp
index 797f661..fd9be9f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2015-2022. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -9,6 +9,7 @@
 #include <cstdint>
 #include <cstdlib>
 
+#include <array>
 #include <stdexcept> // runtime_error
 #include <utility>
 #include <vector>
@@ -34,7 +35,7 @@ namespace dwarf {
  *  just a sequence of dwarf instructions. We currently directly use
  *  `Dwarf_Op` from `dwarf.h` for dwarf instructions.
  */
-typedef std::vector<Dwarf_Op> DwarfExpression;
+using DwarfExpression = std::vector<Dwarf_Op>;
 
 /** Context of evaluation of a DWARF expression
  *
@@ -53,7 +54,7 @@ struct ExpressionContext {
 /** When an error happens in the execution of a DWARF expression */
 class evaluation_error : public std::runtime_error {
 public:
-  explicit evaluation_error(const char* what) : std::runtime_error(what) {}
+  using std::runtime_error::runtime_error;
 };
 
 /** A stack for evaluating a DWARF expression
@@ -62,12 +63,12 @@ public:
  */
 class ExpressionStack {
 public:
-  typedef std::uintptr_t value_type;
-  static const std::size_t max_size = 64;
+  using value_type                      = std::uintptr_t;
+  static constexpr std::size_t MAX_SIZE = 64;
 
 private:
   // Values of the stack (the top is stack_[size_ - 1]):
-  uintptr_t stack_[max_size]{0};
+  std::array<uintptr_t, MAX_SIZE> stack_{{0}};
   size_t size_ = 0;
 
 public:
@@ -97,9 +98,10 @@ public:
   /** Push a value on the top of the stack */
   void push(value_type value)
   {
-    if (size_ == max_size)
+    if (size_ == stack_.size())
       throw evaluation_error("DWARF stack overflow");
-    stack_[size_++] = value;
+    stack_[size_] = value;
+    size_++;
   }
 
   /* Pop a value from the top of the stack */
@@ -107,7 +109,8 @@ public:
   {
     if (size_ == 0)
       throw evaluation_error("DWARF stack underflow");
-    return stack_[--size_];
+    --size_;
+    return stack_[size_];
   }
 
   // These are DWARF operations (DW_OP_foo):