Add actual parse framework

This commit is contained in:
Jonathan Müller 2017-02-21 22:10:41 +01:00
commit 51567da741
3 changed files with 56 additions and 1 deletions

View file

@ -10,6 +10,7 @@
#include "libclang_visitor.hpp"
#include "raii_wrapper.hpp"
#include "parse_error.hpp"
#include "parse_functions.hpp"
#include "preprocessor.hpp"
#include "tokenizer.hpp"
@ -179,7 +180,12 @@ std::unique_ptr<cpp_file> libclang_parser::do_parse(const cpp_entity_index& idx,
for (auto& e : preprocessed.entities)
builder.add_child(std::move(e.entity));
detail::visit_tu(tu, path.c_str(), [&](const CXCursor&) {});
detail::parse_context context{tu.get(), file, type_safe::ref(logger()), type_safe::ref(idx)};
detail::visit_tu(tu, path.c_str(), [&](const CXCursor& cur) {
auto entity = detail::parse_entity(context, cur);
if (entity)
builder.add_child(std::move(entity));
});
return builder.finish(idx);
}

View file

@ -0,0 +1,20 @@
// Copyright (C) 2017 Jonathan Müller <jonathanmueller.dev@gmail.com>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#include "parse_functions.hpp"
#include "parse_error.hpp"
using namespace cppast;
std::unique_ptr<cpp_entity> detail::parse_entity(const detail::parse_context& context,
const CXCursor& cur) try
{
return nullptr;
}
catch (parse_error& ex)
{
context.logger->log("libclang parser", ex.get_diagnostic());
return nullptr;
}

View file

@ -0,0 +1,29 @@
// Copyright (C) 2017 Jonathan Müller <jonathanmueller.dev@gmail.com>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#ifndef CPPAST_PARSE_FUNCTIONS_HPP_INCLUDED
#define CPPAST_PARSE_FUNCTIONS_HPP_INCLUDED
#include <cppast/cpp_entity.hpp>
#include <cppast/parser.hpp>
#include "raii_wrapper.hpp"
namespace cppast
{
namespace detail
{
struct parse_context
{
CXTranslationUnit tu;
CXFile file;
type_safe::object_ref<const diagnostic_logger> logger;
type_safe::object_ref<const cpp_entity_index> idx;
};
std::unique_ptr<cpp_entity> parse_entity(const parse_context& context, const CXCursor& cur);
}
} // namespace cppast::detail
#endif // CPPAST_PARSE_FUNCTIONS_HPP_INCLUDED