Bash++
Bash++ compiler internal documentation
detail.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <string_view>
9#include <source_location>
10#include <type_traits>
11#include <concepts>
12#include <stack>
13
14#include <AST/ASTNode.h>
15#include <AST/Nodes/Nodes.h>
16#include <bpp_include/bpp.h>
17
18namespace bpp {
19namespace detail {
20consteval std::string_view unqualified_function_name(std::string_view function_signature) {
21 // Strip it to the identifier after the last "::"
22 const auto position = function_signature.rfind("::");
23 if (position != std::string_view::npos) function_signature.remove_prefix(position + 2);
24 return function_signature;
25}
26consteval bool starts_with(std::string_view str, std::string_view prefix) {
27 return str.size() >= prefix.size() && str.substr(0, prefix.size()) == prefix;
28}
29
30consteval bool is_enter_context(std::string_view function_name) {
31 if (function_name.find("::enter") != std::string_view::npos) return true;
32 return starts_with(unqualified_function_name(function_name), "enter");
33}
34
35consteval bool is_exit_context(std::string_view function_name) {
36 if (function_name.find("::exit") != std::string_view::npos) return true;
37 return starts_with(unqualified_function_name(function_name), "exit");
38}
39
40template <class...>
41inline constexpr bool false_v = false;
42
43template <typename T>
44concept ASTNodePtrType = std::is_same_v<std::shared_ptr<AST::ASTNode>, T> ||
45 std::is_base_of_v<AST::ASTNode, typename T::element_type>;
46
47template <typename T>
48concept ASTStringToken = std::is_same_v<AST::Token<std::string>, T>;
49
50template <typename T>
51concept ASTParameterToken = std::is_same_v<AST::Token<AST::MethodDefinition::Parameter>, T>;
52
53template <typename T>
55
56template <typename T>
57concept ErrorReportableListener = requires(T t) {
58 { t.get_program() } -> std::same_as<std::shared_ptr<bpp::bpp_program>>;
59 { t.get_include_stack() } -> std::same_as<const std::vector<std::string>&>;
60 { t.get_source_file() } -> std::same_as<std::string>;
61 { t.get_lsp_mode() } -> std::same_as<bool>;
62};
63
64} // namespace detail
65} // namespace bpp
Definition detail.h:54
Definition detail.h:44
Definition detail.h:51
Definition detail.h:48
consteval std::string_view unqualified_function_name(std::string_view function_signature)
Definition detail.h:20
consteval bool is_enter_context(std::string_view function_name)
Definition detail.h:30
constexpr bool false_v
Definition detail.h:41
consteval bool is_exit_context(std::string_view function_name)
Definition detail.h:35
consteval bool starts_with(std::string_view str, std::string_view prefix)
Definition detail.h:26
Definition bash_case.cpp:8