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

tudasc / TypeART / 12973752603

26 Jan 2025 10:22AM UTC coverage: 87.53%. First build
12973752603

Pull #152

github

web-flow
Merge 47346d838 into bddfb53e4
Pull Request #152: Pass configuration parser

90 of 215 new or added lines in 10 files covered. (41.86%)

3959 of 4523 relevant lines covered (87.53%)

113474.42 hits per line

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

79.69
/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/Logger.h"
21

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

25
namespace typeart::config {
26

27
TypeARTConfiguration::TypeARTConfiguration(std::unique_ptr<file::FileOptions> config_options,
3,260✔
28
                                           std::unique_ptr<cl::CommandLineOptions> commandline_options,
29
                                           std::unique_ptr<env::EnvironmentFlagsOptions> env_options)
30
    : configuration_options_(std::move(config_options)),
1,630✔
31
      commandline_options_(std::move(commandline_options)),
1,630✔
32
      env_options_(std::move(env_options)) {
4,890✔
33
}
1,630✔
34

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

49
OptionValue TypeARTConfiguration::getValueOr(std::string_view opt_path, OptionValue alt) const {
3,260✔
50
  if (prioritize_commandline) {
3,260✔
51
    if (auto value = env_options_->getValue(opt_path)) {
4,000✔
52
      LOG_DEBUG("Take ENV " << opt_path << "=" << (std::string(value.value())));
53
      return value.value();
740✔
54
    }
55
    if (auto value = commandline_options_->getValue(opt_path)) {
3,672✔
56
      LOG_DEBUG("Take CL " << opt_path << "=" << (std::string(value.value())));
57
      return value.value();
1,152✔
58
    }
59
  }
1,368✔
60
  return configuration_options_->getValueOr(opt_path, alt);
1,368✔
61
}
3,260✔
62

63
OptionValue TypeARTConfiguration::operator[](std::string_view opt_path) const {
139,376✔
64
  if (prioritize_commandline) {
139,376✔
65
    if (auto value = env_options_->getValue(opt_path)) {
140,856✔
66
      LOG_DEBUG("Take ENV " << opt_path << "=" << (std::string(value.value())));
67
      return value.value();
1,480✔
68
    }
69
    if (auto value = commandline_options_->getValue(opt_path)) {
174,017✔
70
      LOG_DEBUG("Take CL " << opt_path << "=" << (std::string(value.value())));
71
      return value.value();
36,121✔
72
    }
73
  }
101,775✔
74
  auto result = configuration_options_->operator[](opt_path);
101,775✔
75
  LOG_DEBUG("Take File " << opt_path << "=" << (std::string(result)));
76
  return result;
101,775✔
77
}
139,376✔
78

79
void TypeARTConfiguration::prioritizeCommandline(bool do_prioritize) {
1,630✔
80
  prioritize_commandline = do_prioritize;
1,630✔
81
}
1,630✔
82

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

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

92
TypeARTConfigOptions TypeARTConfiguration::getOptions() const {
1,630✔
93
  return helper::config_to_options(*this);
1,630✔
94
}
95

96
inline llvm::ErrorOr<std::unique_ptr<TypeARTConfiguration>> make_config(
1,636✔
97
    llvm::ErrorOr<std::unique_ptr<file::FileOptions>> file_opts) {
98
  if (file_opts) {
1,636✔
99
    auto cl_opts  = std::make_unique<config::cl::CommandLineOptions>();
1,630✔
100
    auto env_opts = std::make_unique<config::env::EnvironmentFlagsOptions>();
1,630✔
101
    auto config   = std::make_unique<config::TypeARTConfiguration>(std::move(file_opts.get()), std::move(cl_opts),
3,260✔
102
                                                                 std::move(env_opts));
1,630✔
103
    config->prioritizeCommandline(true);
1,630✔
104
    return config;
1,630✔
105
  }
1,630✔
106
  LOG_FATAL("Could not initialize file configuration. Reason: " << file_opts.getError().message())
6✔
107
  return file_opts.getError();
6✔
108
}
1,636✔
109

110
llvm::ErrorOr<std::unique_ptr<TypeARTConfiguration>> make_typeart_configuration(const TypeARTConfigInit& init) {
36✔
111
  auto file_opts = init.mode != TypeARTConfigInit::FileConfigurationMode::Empty
36✔
112
                       ? config::file::make_file_configuration(init.file_path)
36✔
113
                       : config::file::make_default_file_configuration();
×
114
  return make_config(std::move(file_opts));
36✔
115
}
36✔
116

117
llvm::ErrorOr<std::unique_ptr<TypeARTConfiguration>> make_typeart_configuration_from_opts(
1,600✔
118
    const TypeARTConfigOptions& opts) {
119
  auto file_opts = config::file::make_from_configuration(opts);
1,600✔
120
  return make_config(std::move(file_opts));
1,600✔
121
}
1,600✔
122

123
}  // 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