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