-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcallbacks.hpp
51 lines (37 loc) · 1.11 KB
/
callbacks.hpp
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
46
47
48
49
50
51
#pragma once
class CallBack;
#include <vector>
//#include <iostream>
#include <string.h>
#include <gcc-plugin.h>
#include <coretypes.h>
#include <tree.h>
using namespace std;
extern vector < CallBack * >callbacks;
/*
Each callback object is typed for a specific type.
We want to lookup the global object and cast them into the right type
*/
template < class TypedCallBack > TypedCallBack * get_typed_callback (tree f)
{
// get the tree code from the node
enum tree_code tc = f->typed.base.code;
// lookup the callback from the table
CallBack *pT0 = callbacks[tc];
// cast the callback to the type TypedCallBack
TypedCallBack *pT = dynamic_cast < TypedCallBack * >(pT0);
return pT;
}
template < class TypedCallBack, class Ret,
class T > Ret call_type_ret (tree f, T fn)
{
// get the TypedCallBack
TypedCallBack *pT = get_typed_callback < TypedCallBack > (f);
// call the function with the new typed callback
return fn (pT, f);
}
/*
The call back base class implementation
*/
void save_callback (enum tree_code tc, CallBack * self); // save this
CallBack *lookup_callback (enum tree_code tc);