• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ArkScript-lang / Ark / 14600096568

22 Apr 2025 04:42PM UTC coverage: 81.034% (+0.6%) from 80.417%
14600096568

Pull #530

github

web-flow
Merge 77531b0d0 into 32828a045
Pull Request #530: Feat/inst locations

238 of 388 new or added lines in 20 files covered. (61.34%)

8 existing lines in 3 files now uncovered.

6396 of 7893 relevant lines covered (81.03%)

78911.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.78
/include/Ark/TypeChecker.hpp
1
/**
2
 * @file TypeChecker.hpp
3
 * @author Alexandre Plateau (lexplt.dev@gmail.com)
4
 * @brief
5
 * @version 1.1
6
 * @date 2022-01-16
7
 *
8
 * @copyright Copyright (c) 2022-2025
9
 *
10
 */
11

12
#ifndef INCLUDE_ARK_TYPECHECKER_HPP
13
#define INCLUDE_ARK_TYPECHECKER_HPP
14

15
#include <string>
16
#include <vector>
17
#include <ostream>
18

19
#include <Ark/VM/Value.hpp>
20

21
namespace Ark::types
22
{
23
    namespace details
24
    {
25
        template <typename T, typename... Ts>
26
        using AllSame = std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...>>;
27

28
        template <int I>
29
        [[nodiscard]] bool checkN(const std::vector<Value>& args)
10,141✔
30
        {
10,141✔
31
            return I >= args.size();
10,141✔
32
        }
33

34
        template <int I, typename T, typename... Ts>
35
        [[nodiscard]] bool checkN(const std::vector<Value>& args, T type, Ts... xs)
10,657✔
36
        {
10,657✔
37
            if (I >= args.size() || (type != ValueType::Any && args[I].valueType() != type))
10,657✔
38
                return false;
×
39
            return checkN<I + 1>(args, xs...);
10,657✔
40
        }
10,657✔
41
    }
42

43
    /**
44
     * @brief Helper to see if a builtin has been given a wanted set of types
45
     *
46
     * @tparam Ts Variadic argument list composed of ValueTypes
47
     * @param args arguments passed to the function
48
     * @param types accepted types
49
     * @return true if the contract is respected
50
     * @return false otherwise
51
     */
52
    template <typename... Ts, typename = details::AllSame<ValueType, Ts...>>
53
    [[nodiscard]] bool check(const std::vector<Value>& args, Ts... types)
10,298✔
54
    {
10,298✔
55
        if (sizeof...(types) != args.size())
10,298✔
56
            return false;
157✔
57
        return details::checkN<0>(args, types...);
10,141✔
58
    }
10,298✔
59

60
    /**
61
     * @brief A type definition within a contract
62
     *
63
     */
64
    struct ARK_API Typedef
179✔
65
    {
66
        std::string name;
67
        std::vector<ValueType> types;
68
        bool variadic;
69

70
        Typedef(const std::string& type_name, const ValueType type, const bool is_variadic = false) :
15✔
71
            name(type_name), types { type }, variadic(is_variadic)
15✔
72
        {}
30✔
73

74
        Typedef(const std::string& type_name, const std::vector<ValueType>& type_list, const bool is_variadic = false) :
×
75
            name(type_name), types(type_list), variadic(is_variadic)
×
76
        {}
×
77
    };
78

79
    /**
80
     * @brief A contract is a list of typed arguments that a function can follow
81
     *
82
     */
83
    struct ARK_API Contract
132✔
84
    {
85
        std::vector<Typedef> arguments;
86
    };
87

88
    /**
89
     * @brief Generate an error message based on a given set of types contracts provided argument list
90
     *
91
     * @param funcname ArkScript name of the function
92
     * @param contracts types contracts the function can follow
93
     * @param args provided argument list
94
     * @param os output stream, default to cout
95
     * @param colorize enable output colorizing
96
     */
97
    ARK_API void generateError(
98
        const std::string_view& funcname,
99
        const std::vector<Contract>& contracts,
100
        const std::vector<Value>& args,
101
        std::ostream& os = std::cout,
102
        bool colorize = true);
103

NEW
104
    class ARK_API TypeCheckingError : public Error
×
105
    {
106
    public:
NEW
107
        TypeCheckingError(std::string&& funcname, const std::vector<Contract>& contracts, const std::vector<Value>& args) :
×
NEW
108
            Error("TypeCheckingError"),
×
NEW
109
            m_funcname(std::move(funcname)),
×
NEW
110
            m_contracts(contracts),
×
NEW
111
            m_passed_args(args)
×
NEW
112
        {}
×
113

NEW
114
        [[nodiscard]] std::string details() const override
×
NEW
115
        {
×
NEW
116
            std::stringstream stream;
×
NEW
117
            generateError(m_funcname, m_contracts, m_passed_args, stream, shouldColorize());
×
NEW
118
            return stream.str();
×
NEW
119
        }
×
120

121
    private:
122
        std::string m_funcname;
123
        std::vector<Contract> m_contracts;
124
        std::vector<Value> m_passed_args;
125
    };
126
}
127

128
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc