forked from standardese/cppast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_preprocessor.hpp
More file actions
127 lines (106 loc) · 4.37 KB
/
Copy pathcpp_preprocessor.hpp
File metadata and controls
127 lines (106 loc) · 4.37 KB
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
// Copyright (C) 2017-2018 Jonathan Müller <[email protected]>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#ifndef CPPAST_CPP_PREPROCESSOR_HPP_INCLUDED
#define CPPAST_CPP_PREPROCESSOR_HPP_INCLUDED
#include <type_safe/optional.hpp>
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_file.hpp>
namespace cppast
{
/// A [cppast::cpp_entity]() modelling a macro definition.
class cpp_macro_definition final : public cpp_entity
{
public:
static cpp_entity_kind kind() noexcept;
/// \returns A newly built macro definition.
/// \notes It is not meant to be registered in the [cppast::cpp_entity_index](),
/// as no other [cppast::cpp_entity]() can refer to it.
static std::unique_ptr<cpp_macro_definition> build(
std::string name, type_safe::optional<std::string> parameters, std::string replacement)
{
return std::unique_ptr<cpp_macro_definition>(
new cpp_macro_definition(std::move(name), std::move(parameters),
std::move(replacement)));
}
/// \returns The replacement text of the macro.
const std::string& replacement() const noexcept
{
return replacement_;
}
/// \returns Whether or not it is a function like macro.
bool is_function_like() const noexcept
{
return parameters_.has_value();
}
/// \returns The parameters of the macro, as the string spelled out in the source code.
/// \notes It has none if it is not a function like macro.
const type_safe::optional<std::string>& parameters() const noexcept
{
return parameters_;
}
private:
cpp_entity_kind do_get_entity_kind() const noexcept override;
cpp_macro_definition(std::string name, type_safe::optional<std::string> parameters,
std::string replacement)
: cpp_entity(std::move(name)),
parameters_(std::move(parameters)),
replacement_(std::move(replacement))
{
}
type_safe::optional<std::string> parameters_;
std::string replacement_;
};
/// The kind of [cppast::cpp_include_directive]().
enum class cpp_include_kind
{
system, //< An `#include <...>`.
local, //< An `#include "..."`.
};
/// A [cppast::cpp_entity]() modelling an `#include`.
class cpp_include_directive final : public cpp_entity
{
public:
static cpp_entity_kind kind() noexcept;
/// \returns A newly built include directive.
/// \notes It is not meant to be registered in the [cppast::cpp_entity_index](),
/// as no other [cppast::cpp_entity]() can refer to it.
static std::unique_ptr<cpp_include_directive> build(const cpp_file_ref& target,
cpp_include_kind kind,
std::string full_path)
{
return std::unique_ptr<cpp_include_directive>(
new cpp_include_directive(target, kind, std::move(full_path)));
}
/// \returns A reference to the [cppast::cpp_file]() it includes.
cpp_file_ref target() const noexcept
{
return cpp_file_ref(target_, name());
}
/// \returns The kind of include it is.
cpp_include_kind include_kind() const noexcept
{
return kind_;
}
/// \returns The full path of the included file.
const std::string& full_path() const noexcept
{
return full_path_;
}
private:
cpp_entity_kind do_get_entity_kind() const noexcept override;
cpp_include_directive(const cpp_file_ref& target, cpp_include_kind kind,
std::string full_path)
: cpp_entity(target.name()),
target_(target.id()[0u]),
kind_(kind),
full_path_(std::move(full_path))
{
DEBUG_ASSERT(!target.is_overloaded(), detail::precondition_error_handler{});
}
cpp_entity_id target_;
cpp_include_kind kind_;
std::string full_path_;
};
} // namespace cppast
#endif // CPPAST_CPP_PREPROCESSOR_HPP_INCLUDED