33#include " fs.hpp"
44#include < deque>
55#include < stdexcept>
6+ #include < sstream>
67#include < toml.hpp>
78
89namespace cmkr {
@@ -30,23 +31,23 @@ static MsvcRuntimeType parse_msvcRuntimeType(const std::string &name) {
3031 return msvc_last;
3132}
3233
33- using TomlBasicValue = toml::basic_value<toml::discard_comments, tsl::ordered_map, std::vector >;
34+ using TomlBasicValue = toml::basic_value<toml::ordered_type_config >;
3435
35- static std::string format_key_message (const std::string &message, const toml::key &ky, const TomlBasicValue &value) {
36+ static std::string format_key_message (const std::string &message, const std::string &ky, const TomlBasicValue &value) {
3637 auto loc = value.location ();
37- auto line_number_str = std::to_string (loc.line ());
38+ auto line_number_str = std::to_string (loc.first_line_number ());
3839 auto line_width = line_number_str.length ();
39- const auto &line_str = loc.line_str ();
40+ const auto &line_str = loc.first_line ();
4041
4142 std::ostringstream oss;
4243 oss << message << " \n " ;
43- oss << " --> " << loc.file_name () << ' :' << loc.line () << ' \n ' ;
44+ oss << " --> " << loc.file_name () << ' :' << loc.first_line_number () << ' \n ' ;
4445
4546 oss << std::string (line_width + 2 , ' ' ) << " |\n " ;
4647 oss << ' ' << line_number_str << " | " << line_str << ' \n ' ;
4748
4849 oss << std::string (line_width + 2 , ' ' ) << ' |' ;
49- auto key_start = line_str.substr (0 , loc.column () - 1 ).rfind (ky);
50+ auto key_start = line_str.substr (0 , loc.first_column_number () - 1 ).rfind (ky);
5051 if (key_start == std::string::npos) {
5152 key_start = line_str.find (ky);
5253 }
@@ -57,29 +58,29 @@ static std::string format_key_message(const std::string &message, const toml::ke
5758 return oss.str ();
5859}
5960
60- static void throw_key_error (const std::string &error, const toml::key &ky, const TomlBasicValue &value) {
61+ static void throw_key_error (const std::string &error, const std::string &ky, const TomlBasicValue &value) {
6162 throw std::runtime_error (format_key_message (" [error] " + error, ky, value));
6263}
6364
64- static void print_key_warning (const std::string &message, const toml::key &ky, const TomlBasicValue &value) {
65+ static void print_key_warning (const std::string &message, const std::string &ky, const TomlBasicValue &value) {
6566 puts (format_key_message (" [warning] " + message, ky, value).c_str ());
6667}
6768
6869class TomlChecker {
6970 const TomlBasicValue &m_v;
70- tsl::ordered_set<toml::key > m_visited;
71- tsl::ordered_set<toml::key > m_conditionVisited;
71+ tsl::ordered_set<std::string > m_visited;
72+ tsl::ordered_set<std::string > m_conditionVisited;
7273
7374 public:
74- TomlChecker (const TomlBasicValue &v, const toml::key &ky) : m_v(toml::find(v, ky)) {
75+ TomlChecker (const TomlBasicValue &v, const std::string &ky) : m_v(toml::find(v, ky)) {
7576 }
7677 explicit TomlChecker (const TomlBasicValue &v) : m_v(v) {
7778 }
7879 TomlChecker (const TomlChecker &) = delete ;
7980 TomlChecker (TomlChecker &&) = delete ;
8081
8182 template <typename T>
82- void optional (const toml::key &ky, Condition<T> &destination) {
83+ void optional (const std::string &ky, Condition<T> &destination) {
8384 // TODO: this algorithm in O(n) over the amount of keys, kinda bad
8485 const auto &table = m_v.as_table ();
8586 for (const auto &itr : table) {
@@ -104,7 +105,7 @@ class TomlChecker {
104105 }
105106
106107 template <typename T>
107- void optional (const toml::key &ky, T &destination) {
108+ void optional (const std::string &ky, T &destination) {
108109 // TODO: this currently doesn't allow you to get an optional map<string, X>
109110 if (m_v.contains (ky)) {
110111 destination = toml::find<T>(m_v, ky);
@@ -113,26 +114,26 @@ class TomlChecker {
113114 }
114115
115116 template <typename T>
116- void required (const toml::key &ky, T &destination) {
117+ void required (const std::string &ky, T &destination) {
117118 destination = toml::find<T>(m_v, ky);
118119 visit (ky);
119120 }
120121
121- bool contains (const toml::key &ky) {
122+ bool contains (const std::string &ky) {
122123 visit (ky);
123124 return m_v.contains (ky);
124125 }
125126
126- const TomlBasicValue &find (const toml::key &ky) {
127+ const TomlBasicValue &find (const std::string &ky) {
127128 visit (ky);
128129 return toml::find (m_v, ky);
129130 }
130131
131- void visit (const toml::key &ky) {
132+ void visit (const std::string &ky) {
132133 m_visited.emplace (ky);
133134 }
134135
135- bool visisted (const toml::key &ky) const {
136+ bool visisted (const std::string &ky) const {
136137 return m_visited.contains (ky);
137138 }
138139
@@ -171,7 +172,7 @@ class TomlChecker {
171172class TomlCheckerRoot {
172173 const TomlBasicValue &m_root;
173174 std::deque<TomlChecker> m_checkers;
174- tsl::ordered_set<toml::key > m_visisted;
175+ tsl::ordered_set<std::string > m_visisted;
175176 bool m_checked = false ;
176177
177178 public:
@@ -180,7 +181,7 @@ class TomlCheckerRoot {
180181 TomlCheckerRoot (const TomlCheckerRoot &) = delete ;
181182 TomlCheckerRoot (TomlCheckerRoot &&) = delete ;
182183
183- bool contains (const toml::key &ky) {
184+ bool contains (const std::string &ky) {
184185 m_visisted.emplace (ky);
185186 return m_root.contains (ky);
186187 }
@@ -190,7 +191,7 @@ class TomlCheckerRoot {
190191 return m_checkers.back ();
191192 }
192193
193- TomlChecker &create (const TomlBasicValue &v, const toml::key &ky) {
194+ TomlChecker &create (const TomlBasicValue &v, const std::string &ky) {
194195 m_checkers.emplace_back (v, ky);
195196 return m_checkers.back ();
196197 }
@@ -214,7 +215,7 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
214215 if (!fs::exists (toml_path)) {
215216 throw std::runtime_error (" File not found '" + toml_path.string () + " '" );
216217 }
217- const auto toml = toml::parse<toml::discard_comments, tsl::ordered_map, std::vector >(toml_path.string ());
218+ const auto toml = toml::parse<toml::ordered_type_config >(toml_path.string ());
218219 if (toml.size () == 0 ) {
219220 throw std::runtime_error (" Empty TOML '" + toml_path.string () + " '" );
220221 }
@@ -431,11 +432,11 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
431432 throw_key_error (" Unsupported option value '" + str + " '" , str, value);
432433 }
433434 } else {
434- throw_key_error (toml::concat_to_string (" Unsupported value type: " , ovalue.type ()), " value" , value);
435+ throw_key_error (std::string (" Unsupported value type: " ) + toml::to_string ( ovalue.type ()), " value" , value);
435436 }
436437 }
437438 } else {
438- throw_key_error (toml::concat_to_string (" Unsupported value type: " , itr.second .type ()), itr.first , itr.second );
439+ throw_key_error (std::string (" Unsupported value type: " ) + toml::to_string ( itr.second .type ()), itr.first , itr.second );
439440 }
440441 options.push_back (o);
441442
@@ -711,7 +712,7 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
711712 if (cond_itr.first .empty ()) {
712713 report = &t.find (" msvc-runtime" );
713714 } else {
714- report = &t.find (cond_itr.first ).as_table ().find (" msvc-runtime" ). value ( );
715+ report = &t.find (cond_itr.first ).as_table ().at (" msvc-runtime" );
715716 }
716717 throw_key_error (error, cond_itr.second , *report);
717718 }
@@ -722,7 +723,7 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
722723 t.optional (" alias" , target.alias );
723724
724725 if (t.contains (" properties" )) {
725- auto store_property = [&target](const toml::key &k, const TomlBasicValue &v, const std::string &condition) {
726+ auto store_property = [&target](const std::string &k, const TomlBasicValue &v, const std::string &condition) {
726727 if (v.is_array ()) {
727728 std::string property_list;
728729 for (const auto &list_val : v.as_array ()) {
@@ -840,7 +841,7 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
840841
841842 for (const auto &p : v.find (" packages" ).as_array ()) {
842843 Vcpkg::Package package;
843- const auto &package_str = p.as_string (). str ;
844+ const auto &package_str = p.as_string ();
844845 const auto open_bracket = package_str.find (' [' );
845846 const auto close_bracket = package_str.find (' ]' , open_bracket);
846847 if (open_bracket == std::string::npos && close_bracket == std::string::npos) {
@@ -923,7 +924,7 @@ bool is_root_path(const std::string &path) {
923924 if (!fs::exists (toml_path)) {
924925 return false ;
925926 }
926- const auto toml = toml::parse<toml::discard_comments, tsl::ordered_map, std::vector >(toml_path.string ());
927+ const auto toml = toml::parse<toml::ordered_type_config >(toml_path.string ());
927928 return toml.contains (" project" );
928929}
929930
0 commit comments