From 51567da7414f4c50f158150354c1a182047d9f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 21 Feb 2017 22:10:41 +0100 Subject: [PATCH] Add actual parse framework --- src/libclang/libclang_parser.cpp | 8 +++++++- src/libclang/parse_functions.cpp | 20 ++++++++++++++++++++ src/libclang/parse_functions.hpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/libclang/parse_functions.cpp create mode 100644 src/libclang/parse_functions.hpp diff --git a/src/libclang/libclang_parser.cpp b/src/libclang/libclang_parser.cpp index fe13c9e..a565613 100644 --- a/src/libclang/libclang_parser.cpp +++ b/src/libclang/libclang_parser.cpp @@ -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 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); } diff --git a/src/libclang/parse_functions.cpp b/src/libclang/parse_functions.cpp new file mode 100644 index 0000000..4097b64 --- /dev/null +++ b/src/libclang/parse_functions.cpp @@ -0,0 +1,20 @@ +// Copyright (C) 2017 Jonathan Müller +// 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 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; +} diff --git a/src/libclang/parse_functions.hpp b/src/libclang/parse_functions.hpp new file mode 100644 index 0000000..8b174b1 --- /dev/null +++ b/src/libclang/parse_functions.hpp @@ -0,0 +1,29 @@ +// Copyright (C) 2017 Jonathan Müller +// 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 +#include + +#include "raii_wrapper.hpp" + +namespace cppast +{ + namespace detail + { + struct parse_context + { + CXTranslationUnit tu; + CXFile file; + type_safe::object_ref logger; + type_safe::object_ref idx; + }; + + std::unique_ptr parse_entity(const parse_context& context, const CXCursor& cur); + } +} // namespace cppast::detail + +#endif // CPPAST_PARSE_FUNCTIONS_HPP_INCLUDED