summaryrefslogtreecommitdiff
path: root/gcc/expr-rewriter.c
blob: 4ada49a3a7cd99370a385d858f0da4bb2ef6a7a7 (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
#include "expr-rewriter.hpp"
#include "type-stringifier.hpp"
#include <string>
#include <map>

void
ExprTypeRewriter::_walk_post(const_tree e)
{
  gcc_assert(e);
  tree t = TREE_TYPE(e);
  const bool in_map = _map.find(t) != _map.end();
  if (!in_map) return;

  tree r_t = _map[t];
  TREE_TYPE((tree)e) = r_t;
  TypeStringifier stringifer;
  const std::string t_name = stringifer.stringify(t);
  const std::string r_t_name = stringifer.stringify(r_t);
  log("replacing %s with %s\n", t_name.c_str(), r_t_name.c_str());
}

void
ExprTypeRewriter::_walk_COMPONENT_REF_pre(const_tree e)
{
  // TODO: I need to rewrite the field 
  const_tree f = TREE_OPERAND(e, 1);
  // So, what we need is a map between this field and the new field
  const bool in_map = _map2.find(f) != _map2.end();
  if (!in_map) return;

  tree n_f = _map2[f];
  TREE_OPERAND(e, 1) = n_f;
  log("replacing field %s with %s\n", TypeStringifier::get_field_identifier(f).c_str(), TypeStringifier::get_field_identifier(n_f).c_str());
}