summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/assert/libassert.hxx
blob: fcd2eb4d97f220d1f891645f9a0db0a4d944682d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
 ** \file assert/libassert.hxx
 ** \brief Implementation of functions exported by the assert module.
 */

#pragma once

#include <memory>

#include <assert/desugar-visitor.hh>
#include <assert/libassert.hh>
#include <misc/contract.hh>
#include <misc/error.hh>

namespace assert
{

  template <typename A> void bind_and_types_check(A& tree)
  {
    misc::error e;
    e << ::assert::bind(tree);
    e.ice_on_error_here();
    e << ::assert::types_check(tree);
    e.ice_on_error_here();
  }

  template <typename A>
  A* raw_desugar(const A& tree, bool desugar_for_p, bool desugar_string_cmp_p)
  {
    DesugarVisitor desugar(desugar_for_p, desugar_string_cmp_p);
    desugar(tree);
    return dynamic_cast<A*>(desugar.result_get());
  }

  template <typename A>
  A* desugar(const A& tree, bool desugar_for_p, bool desugar_string_cmp_p)
  {
    A* desugared = raw_desugar(tree, desugar_for_p, desugar_string_cmp_p);
    assertion(desugared);
    std::unique_ptr<A> desugared_ptr(desugared);
    bind_and_types_check(*desugared_ptr);
    return desugared_ptr.release();
  }

}