-
Notifications
You must be signed in to change notification settings - Fork 2
/
lp_creation_policy.hh
133 lines (106 loc) · 3.5 KB
/
lp_creation_policy.hh
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* Copyright (C) 2019 SUSE Software Solutions Germany GmbH
*
* This file is part of klp-ccp.
*
* klp-ccp is free software: you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* klp-ccp is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with klp-ccp. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LP_CREATION_POLICY_HH
#define LP_CREATION_POLICY_HH
#include <string>
#include <set>
#include "pp_result.hh"
namespace klp
{
namespace ccp
{
namespace ast
{
class direct_declarator_id;
class init_declarator;
class function_definition;
};
class code_remarks;
class lp_creation_policy
{
public:
virtual ~lp_creation_policy() noexcept;
virtual bool
is_patched(const ast::function_definition &fd,
code_remarks &remarks) const = 0;
virtual bool
is_header_eligible(const pp_result::header_inclusion_root &pre_include,
code_remarks &remarks) const = 0;
virtual bool
is_header_eligible(const pp_result::header_inclusion_child &h,
code_remarks &remarks) const = 0;
virtual bool
is_function_externalizable(const ast::function_definition &fd,
code_remarks &remarks) const = 0;
virtual bool
is_function_externalizable(const ast::init_declarator &id,
code_remarks &remarks) const = 0;
virtual bool
is_function_externalization_preferred(const ast::function_definition &fd,
const bool in_eligible_headers,
code_remarks &remarks) const = 0;
virtual bool
shall_externalize_object(const ast::init_declarator &id,
code_remarks &remarks) const = 0;
struct symbol_modification
{
enum class linkage_change
{
lc_none,
lc_make_static,
lc_make_extern,
};
symbol_modification();
symbol_modification(std::string &&_new_name,
const linkage_change _new_linkage);
bool is_rename() const noexcept
{ return !new_name.empty(); }
std::string new_name;
linkage_change new_linkage;
};
struct externalized_symbol_modification
{
externalized_symbol_modification();
externalized_symbol_modification
(std::string &&_new_name,
const symbol_modification::linkage_change _new_linkage,
const bool _make_pointer);
symbol_modification sym_mod;
bool make_pointer;
};
typedef std::set<std::string> allocated_ids_type;
virtual externalized_symbol_modification
get_sym_mod_for_externalized_fun(const ast::direct_declarator_id &ddid,
const allocated_ids_type &allocated_ids,
code_remarks &remarks) const = 0;
virtual symbol_modification
get_sym_mod_for_patched_fun(const ast::function_definition &fd,
const allocated_ids_type &allocated_ids,
code_remarks &remarks) const = 0;
virtual std::string
rename_rewritten_closure_fun(const ast::function_definition &fd,
const allocated_ids_type &allocated_ids,
code_remarks &remarks) const = 0;
virtual externalized_symbol_modification
get_sym_mod_for_externalized_obj(const ast::init_declarator &id,
const allocated_ids_type &allocated_ids,
code_remarks &remarks) const = 0;
};
}
}
#endif