Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3e3995
commit a937efb
Showing
21 changed files
with
396 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (C) 2017-2022 Jonathan Müller and cppast contributors | ||
// SPDX-License-Identifier: MIT | ||
|
||
#ifndef CPPAST_CPP_CONCEPT_HPP_INCLUDED | ||
#define CPPAST_CPP_CONCEPT_HPP_INCLUDED | ||
|
||
#include <cppast/cpp_entity.hpp> | ||
#include <cppast/cpp_template_parameter.hpp> | ||
#include <cppast/cpp_expression.hpp> | ||
|
||
namespace cppast | ||
{ | ||
/// A [[cppast::cpp_entity]() modelling a c++ concept declaration | ||
/// \notes while concepts are technically templates, | ||
/// this is not a [cppast::cpp_template](), | ||
/// as concepts act very differently from other templates | ||
class cpp_concept final : public cpp_entity | ||
{ | ||
public: | ||
static cpp_entity_kind kind() noexcept; | ||
|
||
/// \returns the template parameters as a string | ||
const cpp_token_string& parameters() const noexcept | ||
{ | ||
return parameters_; | ||
} | ||
|
||
/// \returns the [cppast::cpp_expression]() defining the concept constraint | ||
const cpp_expression& constraint_expression() const noexcept | ||
{ | ||
return *expression_; | ||
} | ||
|
||
class builder | ||
{ | ||
public: | ||
builder(std::string name) | ||
: concept_(new cpp_concept(std::move(name))) | ||
{} | ||
|
||
cpp_token_string& set_parameters(cpp_token_string string) noexcept | ||
{ | ||
concept_->parameters_ = std::move(string); | ||
return concept_->parameters_; | ||
} | ||
|
||
cpp_expression& set_expression(std::unique_ptr<cpp_expression> expression) noexcept | ||
{ | ||
concept_->expression_ = std::move(expression); | ||
return *concept_->expression_; | ||
} | ||
|
||
std::unique_ptr<cpp_concept> finish(const cpp_entity_index& idx, cpp_entity_id id); | ||
|
||
private: | ||
std::unique_ptr<cpp_concept> concept_; | ||
}; | ||
|
||
private: | ||
cpp_concept(std::string name) | ||
: cpp_entity(std::move(name)), parameters_({}) | ||
{} | ||
|
||
cpp_entity_kind do_get_entity_kind() const noexcept override; | ||
|
||
cpp_token_string parameters_; | ||
|
||
std::unique_ptr<cpp_expression> expression_; | ||
}; | ||
|
||
|
||
} // namespace cppast | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (C) 2017-2022 Jonathan Müller and cppast contributors | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <cppast/cpp_concept.hpp> | ||
|
||
#include <cppast/cpp_entity_kind.hpp> | ||
|
||
using namespace cppast; | ||
|
||
cpp_entity_kind cppast::cpp_concept::kind() noexcept | ||
{ | ||
return cpp_entity_kind::concept_t; | ||
} | ||
|
||
cpp_entity_kind cpp_concept::do_get_entity_kind() const noexcept | ||
{ | ||
return cpp_entity_kind::concept_t; | ||
} | ||
|
||
std::unique_ptr<cpp_concept> cpp_concept::builder::finish(const cpp_entity_index& idx, cpp_entity_id id) | ||
{ | ||
idx.register_definition(id, type_safe::ref(*concept_)); | ||
return std::move(concept_); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (C) 2017-2022 Jonathan Müller and cppast contributors | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <cppast/cpp_concept.hpp> | ||
|
||
#include <cppast/cpp_entity_kind.hpp> | ||
|
||
#include "libclang_visitor.hpp" | ||
#include "parse_functions.hpp" | ||
|
||
using namespace cppast; | ||
|
||
std::unique_ptr<cpp_entity> detail::try_parse_cpp_concept(const detail::parse_context& context, | ||
const CXCursor& cur) | ||
{ | ||
DEBUG_ASSERT(cur.kind == CXCursor_UnexposedDecl, detail::assert_handler{}); | ||
|
||
detail::cxtokenizer tokenizer(context.tu, context.file, cur); | ||
detail::cxtoken_stream stream(tokenizer, cur); | ||
|
||
if (!detail::skip_if(stream, "template")) | ||
return nullptr; | ||
|
||
if (stream.peek() != "<") | ||
return nullptr; | ||
|
||
|
||
auto closing_bracket_iter = detail::find_closing_bracket(stream); | ||
auto params = to_string(stream, closing_bracket_iter); | ||
|
||
if (!detail::skip_if(stream, ">")) | ||
return nullptr; | ||
|
||
if (!detail::skip_if(stream, "concept")) | ||
return nullptr; | ||
|
||
const auto& identifier_token = stream.get(); | ||
if (identifier_token.kind() != CXTokenKind::CXToken_Identifier) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
cpp_concept::builder builder(identifier_token.value().std_str()); | ||
|
||
if (!detail::skip_if(stream, "=")) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
if (*(stream.end() - 1) != ";") | ||
{ | ||
return nullptr; | ||
} | ||
|
||
builder.set_expression( | ||
parse_raw_expression(context, stream, stream.end() - 1, | ||
cpp_builtin_type::build(cpp_builtin_type_kind::cpp_bool))); | ||
|
||
builder.set_parameters(std::move(params)); | ||
|
||
return builder.finish(*context.idx, detail::get_entity_id(cur)); | ||
} |
Oops, something went wrong.