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

tudasc / TypeART / 13955121336

19 Mar 2025 07:30PM UTC coverage: 88.842%. First build
13955121336

push

github

web-flow
Merge PR #167 from tudasc/devel

1174 of 1361 new or added lines in 49 files covered. (86.26%)

4212 of 4741 relevant lines covered (88.84%)

261950.04 hits per line

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

68.18
/lib/passes/TypeARTConfiguration.cpp
1
// TypeART library
2
//
3
// Copyright (c) 2017-2025 TypeART Authors
4
// Distributed under the BSD 3-Clause license.
5
// (See accompanying file LICENSE.txt or copy at
6
// https://opensource.org/licenses/BSD-3-Clause)
7
//
8
// Project home: https://github.com/tudasc/TypeART
9
//
10
// SPDX-License-Identifier: BSD-3-Clause
11
//
12

13
#include "TypeARTConfiguration.h"
14

15
#include "Commandline.h"
16
#include "configuration/Configuration.h"
17
#include "configuration/EnvironmentConfiguration.h"
18
#include "configuration/FileConfiguration.h"
19
#include "configuration/TypeARTOptions.h"
20
#include "support/ConfigurationBase.h"
21
#include "support/Logger.h"
22

23
#include <string>
24
#include <string_view>
25

26
namespace typeart::config {
27

28
TypeARTConfiguration::TypeARTConfiguration(std::unique_ptr<file::FileOptions> config_options,
4,796✔
29
                                           std::unique_ptr<cl::CommandLineOptions> commandline_options,
30
                                           std::unique_ptr<env::EnvironmentFlagsOptions> env_options)
31
    : configuration_options_(std::move(config_options)),
3,118✔
32
      commandline_options_(std::move(commandline_options)),
3,118✔
33
      env_options_(std::move(env_options)) {
7,914✔
34
}
1,678✔
35

NEW
36
std::optional<OptionValue> TypeARTConfiguration::getValue(std::string_view opt_path) const {
×
NEW
37
  if (prioritize_commandline) {
×
NEW
38
    if (auto value = env_options_->getValue(opt_path)) {
×
39
      // LOG_DEBUG("Take ENV " << opt_path << "=" << (std::string(value.value())));
40
      return value.value();
1,678✔
41
    }
NEW
42
    if (auto value = commandline_options_->getValue(opt_path)) {
×
43
      // LOG_DEBUG("Take CL " << opt_path << "=" << (std::string(value.value())));
NEW
44
      return value.value();
×
45
    }
46
  }
×
47
  return configuration_options_->getValue(opt_path);
×
48
}
×
49

50
OptionValue TypeARTConfiguration::getValueOr(std::string_view opt_path, const OptionValue& alt) const {
6,236✔
51
  if (prioritize_commandline) {
6,236✔
52
    if (auto value = env_options_->getValue(opt_path)) {
7,588✔
53
      // LOG_DEBUG("Take ENV " << opt_path << "=" << (std::string(value.value())));
54
      return value.value();
1,352✔
55
    }
56
    if (auto value = commandline_options_->getValue(opt_path)) {
4,884✔
57
      // LOG_DEBUG("Take CL " << opt_path << "=" << (std::string(value.value())));
NEW
58
      return value.value();
×
59
    }
60
  }
4,884✔
61
  return configuration_options_->getValueOr(opt_path, alt);
4,884✔
62
}
6,236✔
63

64
OptionValue TypeARTConfiguration::operator[](std::string_view opt_path) const {
238,936✔
65
  if (prioritize_commandline) {
238,936✔
66
    if (auto value = env_options_->getValue(opt_path)) {
251,347✔
67
      // LOG_DEBUG("Take ENV " << opt_path << "=" << (std::string(value.value())));
68
      return value.value();
12,411✔
69
    }
70
    if (auto value = commandline_options_->getValue(opt_path)) {
226,525✔
71
      // LOG_DEBUG("Take CL " << opt_path << "=" << (std::string(value.value())));
NEW
72
      return value.value();
×
73
    }
74
  }
226,525✔
75
  auto result = configuration_options_->operator[](opt_path);
226,525✔
76
  // LOG_DEBUG("Take File " << opt_path << "=" << (std::string(result)));
77
  return result;
226,525✔
78
}
345,422✔
79

80
void TypeARTConfiguration::prioritizeCommandline(bool do_prioritize) {
3,118✔
81
  prioritize_commandline = do_prioritize;
3,118✔
82
}
3,118✔
83

84
void TypeARTConfiguration::emitTypeartFileConfiguration(llvm::raw_ostream& out_stream) {
×
85
  out_stream << configuration_options_->getConfigurationAsString();
×
86
}
×
87

88
template <typename ClOpt>
89
std::pair<llvm::StringRef, typename OptionsMap::mapped_type> make_occurr_entry(std::string&& key, ClOpt&& cl_opt) {
90
  return {key, (cl_opt.getNumOccurrences() > 0)};
91
}
92

93
TypeARTConfigOptions TypeARTConfiguration::getOptions() const {
3,118✔
94
  return helper::config_to_options(*this);
3,118✔
95
}
96

97
inline llvm::ErrorOr<std::unique_ptr<TypeARTConfiguration>> make_config(
3,118✔
98
    llvm::ErrorOr<std::unique_ptr<file::FileOptions>> file_opts) {
99
  if (file_opts) {
3,118✔
100
    const bool heap  = file_opts->get()->getValue(config::ConfigStdArgs::heap).value_or(OptionValue{false});
3,118✔
101
    const bool stack = file_opts->get()->getValue(config::ConfigStdArgs::stack).value_or(OptionValue{false});
3,118✔
102
    auto cl_opts     = std::make_unique<config::cl::CommandLineOptions>();
3,118✔
103
    auto env_opts    = std::make_unique<config::env::EnvironmentFlagsOptions>();
3,118✔
104
    env_opts->parsePhaseEnvFlags({heap, stack});
3,118✔
105
    auto config = std::make_unique<config::TypeARTConfiguration>(std::move(file_opts.get()), std::move(cl_opts),
4,796✔
106
                                                                 std::move(env_opts));
1,678✔
107
    config->prioritizeCommandline(true);
3,118✔
108
    return config;
3,118✔
109
  }
3,118✔
NEW
110
  LOG_FATAL("Could not initialize file configuration. Reason: " << file_opts.getError().message())
×
111
  return file_opts.getError();
×
112
}
3,118✔
113

NEW
114
llvm::ErrorOr<std::unique_ptr<TypeARTConfiguration>> make_typeart_configuration(const TypeARTConfigInit& init) {
×
NEW
115
  auto file_opts = init.mode != TypeARTConfigInit::FileConfigurationMode::Empty
×
NEW
116
                       ? config::file::make_file_configuration(init.file_path)
×
NEW
117
                       : config::file::make_default_file_configuration();
×
NEW
118
  return make_config(std::move(file_opts));
×
NEW
119
}
×
120

121
llvm::ErrorOr<std::unique_ptr<TypeARTConfiguration>> make_typeart_configuration_from_opts(
3,118✔
122
    const TypeARTConfigOptions& opts) {
123
  auto file_opts = config::file::make_from_configuration(opts);
3,118✔
124
  return make_config(std::move(file_opts));
3,118✔
125
}
3,118✔
126

127
}  // namespace typeart::config
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