Skip to content

Commit a87d442

Browse files
committed
[#39]:svarga:fix, resolve merge-conflict damage in h5cpp.cpp, h5_attr_translator.hpp, producer_pb.hpp, producer_sql.hpp
1 parent f12af2f commit a87d442

4 files changed

Lines changed: 80 additions & 94 deletions

File tree

src/h5_attr_translator.hpp

Lines changed: 40 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,9 @@ inline bool is_h5_attr_name(llvm::StringRef name) {
4040
|| name == "serialize_full";
4141
}
4242

43-
inline bool is_rlp_attr_name(llvm::StringRef name) {
44-
return name == "name" || name == "ignore" || name == "doc"
45-
|| name == "alias" || name == "required" || name == "timestamp";
46-
}
47-
4843
inline bool is_json_attr_name(llvm::StringRef name) {
4944
return name == "name" || name == "ignore" || name == "doc"
50-
|| name == "alias" || name == "version" || name == "name_all"
51-
|| name == "required" || name == "format" || name == "pattern"
52-
|| name == "min" || name == "max" || name == "tool_format";
45+
|| name == "alias" || name == "required" || name == "type";
5346
}
5447

5548
inline bool is_msgpack_attr_name(llvm::StringRef name) {
@@ -75,6 +68,11 @@ inline bool is_avro_attr_name(llvm::StringRef name) {
7568
|| name == "uuid" || name == "date" || name == "time";
7669
}
7770

71+
inline bool is_rlp_attr_name(llvm::StringRef name) {
72+
return name == "name" || name == "ignore" || name == "doc"
73+
|| name == "alias" || name == "required" || name == "timestamp";
74+
}
75+
7876
// Skip whitespace and comments at position `i` in `src`. Returns the new
7977
// position. Comments are emitted to `out` verbatim.
8078
inline std::size_t skip_ws(llvm::StringRef src, std::size_t i, std::string& out) {
@@ -173,58 +171,45 @@ inline std::vector<llvm::StringRef> split_attrs(llvm::StringRef block) {
173171
return out;
174172
}
175173

176-
// Rewrite one attribute spec. If it starts with `h5::<recognized-name>`,
177-
// convert to `clang::annotate("h5::<name>", <args>)`. Otherwise leave verbatim.
174+
// Rewrite one attribute spec. If it starts with a recognized namespace,
175+
// convert to `clang::annotate("ns::<name>", <args>)`. Otherwise leave verbatim.
178176
inline std::string rewrite_one_attr(llvm::StringRef spec) {
179177
std::size_t start = 0;
180178
while (start < spec.size() && std::isspace(static_cast<unsigned char>(spec[start]))) ++start;
181179
llvm::StringRef leading = spec.substr(0, start);
182180
llvm::StringRef body = spec.substr(start);
183181

184-
bool is_h5 = body.starts_with("h5::");
185-
bool is_rlp = body.starts_with("rlp::");
186-
if (!is_h5 && !is_rlp) return spec.str();
187-
llvm::StringRef ns = is_h5 ? "h5::" : "rlp::";
188-
bool is_h5 = body.starts_with("h5::");
189-
bool is_json = body.starts_with("json::");
190-
if (!is_h5 && !is_json) return spec.str();
191-
llvm::StringRef ns = is_h5 ? "h5::" : "json::";
192-
bool is_h5 = body.starts_with("h5::");
182+
bool is_h5 = body.starts_with("h5::");
183+
bool is_json = body.starts_with("json::");
193184
bool is_msgpack = body.starts_with("msgpack::");
194-
if (!is_h5 && !is_msgpack) return spec.str();
195-
llvm::StringRef ns = is_h5 ? "h5::" : "msgpack::";
196-
if (!body.starts_with(ns)) return spec.str();
197-
bool is_h5 = body.starts_with("h5::");
198-
bool is_cbor = body.starts_with("cbor::");
199-
if (!is_h5 && !is_cbor) return spec.str();
200-
llvm::StringRef ns = is_h5 ? "h5::" : "cbor::";
201-
bool is_h5 = body.starts_with("h5::");
202-
bool is_bson = body.starts_with("bson::");
203-
if (!is_h5 && !is_bson) return spec.str();
204-
llvm::StringRef ns = is_h5 ? "h5::" : "bson::";
205-
bool is_h5 = body.starts_with("h5::");
206-
bool is_avro = body.starts_with("avro::");
207-
if (!is_h5 && !is_avro) return spec.str();
208-
llvm::StringRef ns = is_h5 ? "h5::" : "avro::";
185+
bool is_cbor = body.starts_with("cbor::");
186+
bool is_bson = body.starts_with("bson::");
187+
bool is_avro = body.starts_with("avro::");
188+
bool is_rlp = body.starts_with("rlp::");
189+
if (!is_h5 && !is_json && !is_msgpack && !is_cbor && !is_bson && !is_avro && !is_rlp) return spec.str();
190+
191+
llvm::StringRef ns;
192+
if (is_h5) ns = "h5::";
193+
else if (is_json) ns = "json::";
194+
else if (is_msgpack) ns = "msgpack::";
195+
else if (is_cbor) ns = "cbor::";
196+
else if (is_bson) ns = "bson::";
197+
else if (is_avro) ns = "avro::";
198+
else ns = "rlp::";
209199

210200
body = body.drop_front(ns.size());
211201
std::size_t i = 0;
212202
while (i < body.size()
213203
&& (std::isalnum(static_cast<unsigned char>(body[i])) || body[i] == '_')) ++i;
214204
if (i == 0) return spec.str();
215205
llvm::StringRef name = body.substr(0, i);
216-
if (is_h5 && !is_h5_attr_name(name)) return spec.str();
217-
if (is_rlp && !is_rlp_attr_name(name)) return spec.str();
218-
if (is_h5 && !is_h5_attr_name(name)) return spec.str();
219-
if (is_json && !is_json_attr_name(name)) return spec.str();
220-
if (is_h5 && !is_h5_attr_name(name)) return spec.str();
206+
if (is_h5 && !is_h5_attr_name(name)) return spec.str();
207+
if (is_json && !is_json_attr_name(name)) return spec.str();
221208
if (is_msgpack && !is_msgpack_attr_name(name)) return spec.str();
222-
if (is_h5 && !is_h5_attr_name(name)) return spec.str();
223-
if (is_cbor && !is_cbor_attr_name(name)) return spec.str();
224-
if (is_h5 && !is_h5_attr_name(name)) return spec.str();
225-
if (is_bson && !is_bson_attr_name(name)) return spec.str();
226-
if (is_h5 && !is_h5_attr_name(name)) return spec.str();
227-
if (is_avro && !is_avro_attr_name(name)) return spec.str();
209+
if (is_cbor && !is_cbor_attr_name(name)) return spec.str();
210+
if (is_bson && !is_bson_attr_name(name)) return spec.str();
211+
if (is_avro && !is_avro_attr_name(name)) return spec.str();
212+
if (is_rlp && !is_rlp_attr_name(name)) return spec.str();
228213

229214
while (i < body.size() && std::isspace(static_cast<unsigned char>(body[i]))) ++i;
230215

@@ -294,12 +279,9 @@ inline std::string rewrite(llvm::StringRef src) {
294279
continue;
295280
}
296281
llvm::StringRef block = src.substr(i + 2, close - i - 2);
297-
if (block.contains("h5::") || block.contains("rlp::")) {
298-
if (block.contains("h5::") || block.contains("json::")) {
299-
if (block.contains("h5::") || block.contains("msgpack::")) {
300-
if (block.contains("h5::") || block.contains("cbor::")) {
301-
if (block.contains("h5::") || block.contains("bson::")) {
302-
if (block.contains("h5::") || block.contains("avro::")) {
282+
if (block.contains("h5::") || block.contains("json::") || block.contains("msgpack::")
283+
|| block.contains("cbor::") || block.contains("bson::") || block.contains("avro::")
284+
|| block.contains("rlp::")) {
303285
auto attrs = split_attrs(block);
304286
out.append("[[");
305287
for (std::size_t k = 0; k < attrs.size(); ++k) {
@@ -332,12 +314,13 @@ inline void install_virtual_files(clang::tooling::ClangTool& Tool,
332314
for (const auto& p : paths) {
333315
std::string content = read_file(p);
334316
if (content.empty()) continue;
335-
if (content.find("h5::") == std::string::npos && content.find("rlp::") == std::string::npos) continue;
336-
if (content.find("h5::") == std::string::npos && content.find("json::") == std::string::npos) continue;
337-
if (content.find("h5::") == std::string::npos && content.find("msgpack::") == std::string::npos) continue;
338-
if (content.find("h5::") == std::string::npos && content.find("cbor::") == std::string::npos) continue;
339-
if (content.find("h5::") == std::string::npos && content.find("bson::") == std::string::npos) continue;
340-
if (content.find("h5::") == std::string::npos && content.find("avro::") == std::string::npos) continue;
317+
if (content.find("h5::") == std::string::npos
318+
&& content.find("json::") == std::string::npos
319+
&& content.find("msgpack::") == std::string::npos
320+
&& content.find("cbor::") == std::string::npos
321+
&& content.find("bson::") == std::string::npos
322+
&& content.find("avro::") == std::string::npos
323+
&& content.find("rlp::") == std::string::npos) continue;
341324
storage.push_back(rewrite(content));
342325
Tool.mapVirtualFile(p, storage.back());
343326
}

src/h5cpp.cpp

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
#include "producer_h5.hpp"
1919
#include "producer_sql.hpp"
2020
#include "consumer.hpp"
21-
#include "consumer_rlp.hpp"
21+
#include "consumer_json.hpp"
22+
#include "consumer_msgpack.hpp"
23+
#include "consumer_cbor.hpp"
2224
#include "consumer_bson.hpp"
2325
#include "consumer_avro.hpp"
26+
#include "consumer_rlp.hpp"
2427
#include "producer_pb.hpp"
2528
#include "consumer_pb.hpp"
2629
#include "consumer_proto.hpp"
2730
#include "pb_attr_translator.hpp"
2831
#include "h5_attr_translator.hpp"
29-
#include "consumer_json.hpp"
30-
#include "consumer_msgpack.hpp"
31-
#include "consumer_cbor.hpp"
3232

3333
clang::ast_matchers::StatementMatcher h5templateMatcher = clang::ast_matchers::callExpr( clang::ast_matchers::allOf(
3434
clang::ast_matchers::hasDescendant( clang::ast_matchers::declRefExpr( clang::ast_matchers::to( clang::ast_matchers::varDecl().bind("variableDecl") ) ) ),
@@ -54,8 +54,6 @@ clang::ast_matchers::StatementMatcher h5templateMatcher = clang::ast_matchers::c
5454
)) )))
5555
));
5656

57-
enum class OutputFormat { hdf5, protobuf, json, msgpack, cbor, bson, avro, rlp,
58-
sql_postgres, sql_mysql, sql_lite3 };
5957
// pbTemplateMatcher: same shape as h5templateMatcher, but triggers on the
6058
// pb.hpp public surface. Covers pb::encode, pb::decode, and pb::encode_into.
6159
clang::ast_matchers::StatementMatcher pbTemplateMatcher = clang::ast_matchers::callExpr( clang::ast_matchers::allOf(
@@ -73,7 +71,8 @@ clang::ast_matchers::StatementMatcher pbTemplateMatcher = clang::ast_matchers::c
7371
)) )))
7472
));
7573

76-
enum class OutputFormat { hdf5, protobuf, json, msgpack, cbor, bson, avro, rlp };
74+
enum class OutputFormat { hdf5, protobuf, json, msgpack, cbor, bson, avro, rlp,
75+
sql_postgres, sql_mysql, sql_lite3 };
7776

7877
static llvm::cl::OptionCategory MyToolCategory("h5cpp options");
7978
static llvm::cl::extrahelp CommonHelp(clang::tooling::CommonOptionsParser::HelpMessage);
@@ -105,16 +104,16 @@ static llvm::cl::opt<OutputFormat> Format(llvm::cl::desc("Output format:"),
105104
llvm::cl::init(OutputFormat::hdf5),
106105
llvm::cl::cat(MyToolCategory));
107106

108-
static llvm::cl::opt<bool> CheckMode("check",
109-
llvm::cl::desc("Verify that the existing generated file is up to date (exit 1 if stale)"),
110-
llvm::cl::cat(MyToolCategory),
111-
llvm::cl::init(false));
112-
113107
static llvm::cl::opt<std::string> ProtoOutputFile("proto-out",
114108
llvm::cl::desc("Phase 3: .proto schema output (used with --protobuf)"),
115109
llvm::cl::value_desc("file"),
116110
llvm::cl::cat(MyToolCategory));
117111

112+
static llvm::cl::opt<bool> CheckMode("check",
113+
llvm::cl::desc("Verify that the existing generated file is up to date (exit 1 if stale)"),
114+
llvm::cl::cat(MyToolCategory),
115+
llvm::cl::init(false));
116+
118117
int main(int argc, const char **argv) {
119118
std::cerr <<
120119
"H5CPP: Copyright (c) 2018-2026, VargaLABS, Toronto, ON Canada\n"
@@ -158,7 +157,6 @@ int main(int argc, const char **argv) {
158157
}
159158
case OutputFormat::protobuf: {
160159
PbTemplateCallback<PbProducer> callback(work_path);
161-
clang::ast_matchers::MatchFinder Finder;
162160
Finder.addMatcher(pbTemplateMatcher, &callback);
163161
std::optional<ProtoTemplateCallback> proto_cb;
164162
if (!ProtoOutputFile.empty()) {
@@ -168,59 +166,43 @@ int main(int argc, const char **argv) {
168166
rc = Tool.run(clang::tooling::newFrontendActionFactory(&Finder).get());
169167
if (rc == 0 && callback.error()) rc = 1;
170168
break;
169+
}
171170
case OutputFormat::json: {
172171
JsonTemplateCallback callback(work_path);
173172
Finder.addMatcher(h5templateMatcher, &callback);
174173
rc = Tool.run(clang::tooling::newFrontendActionFactory(&Finder).get());
175-
}
176-
case OutputFormat::json:
177-
llvm::errs() << "h5cpp-compiler: --format json not yet implemented\n";
178-
rc = 1;
179174
break;
180175
}
181-
case OutputFormat::msgpack:
182-
llvm::errs() << "h5cpp-compiler: --format msgpack not yet implemented\n";
183-
rc = 1;
184176
case OutputFormat::msgpack: {
185177
MsgpackTemplateCallback callback(work_path);
186178
Finder.addMatcher(h5templateMatcher, &callback);
187179
rc = Tool.run(clang::tooling::newFrontendActionFactory(&Finder).get());
188180
break;
189181
}
190-
llvm::errs() << "h5cpp-compiler: --format cbor not yet implemented\n";
191-
rc = 1;
192182
case OutputFormat::cbor: {
193183
CborTemplateCallback callback(work_path);
194184
Finder.addMatcher(h5templateMatcher, &callback);
195185
rc = Tool.run(clang::tooling::newFrontendActionFactory(&Finder).get());
196186
break;
197187
}
198-
case OutputFormat::bson:
199-
llvm::errs() << "h5cpp-compiler: --format bson not yet implemented\n";
200-
rc = 1;
201188
case OutputFormat::bson: {
202189
BsonTemplateCallback callback(work_path);
203190
Finder.addMatcher(h5templateMatcher, &callback);
204191
rc = Tool.run(clang::tooling::newFrontendActionFactory(&Finder).get());
205192
break;
206193
}
207-
case OutputFormat::avro:
208-
llvm::errs() << "h5cpp-compiler: --format avro not yet implemented\n";
209-
rc = 1;
210194
case OutputFormat::avro: {
211195
AvroTemplateCallback callback(work_path);
212196
Finder.addMatcher(h5templateMatcher, &callback);
213197
rc = Tool.run(clang::tooling::newFrontendActionFactory(&Finder).get());
214198
break;
199+
}
215200
case OutputFormat::rlp: {
216201
RlpTemplateCallback callback(work_path);
217202
Finder.addMatcher(h5templateMatcher, &callback);
218203
rc = Tool.run(clang::tooling::newFrontendActionFactory(&Finder).get());
219-
}
220-
case OutputFormat::rlp:
221-
llvm::errs() << "h5cpp-compiler: --format rlp not yet implemented\n";
222-
rc = 1;
223204
break;
205+
}
224206
case OutputFormat::sql_postgres: {
225207
H5TemplateCallback<SqlProducer<SqlDialect::postgres>> callback(work_path);
226208
Finder.addMatcher(h5templateMatcher, &callback);
@@ -239,7 +221,6 @@ int main(int argc, const char **argv) {
239221
rc = Tool.run(clang::tooling::newFrontendActionFactory(&Finder).get());
240222
break;
241223
}
242-
}
243224
}
244225
}
245226

src/producer_pb.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ struct PbProducer : Producer<PbProducer> {
4242
// descriptor's runtime behavior; the .proto emitter (Phase 3) consumes
4343
// the same metadata to produce the `message Foo { ... }` block name and
4444
// the SourceCodeInfo doc string.
45-
void template_decl_impl(const std::string& record){
45+
void template_decl_impl(const std::string& record,
46+
const std::string& /*doc*/ = "",
47+
const std::string& /*alias*/ = "",
48+
const std::string& /*version*/ = ""){
4649
record_name = record;
4750
first_field = true;
4851
io << "template<> struct pb::meta::descriptor_t<" << record << "> {\n";
@@ -118,7 +121,8 @@ struct PbProducer : Producer<PbProducer> {
118121
// decimal string ("1", "2", ...) instead of the HDF5 vname. record_name
119122
// is the qualified record type; field_name is the member identifier.
120123
void type_insert_impl(const std::string& var, const std::string& field_name,
121-
const std::string& rec_name, const std::string& /*type*/){
124+
const std::string& rec_name, const std::string& /*type*/,
125+
const std::string& /*on_disk_name*/ = ""){
122126
consume_leading_comma();
123127
io << "\n pb::field<" << var << ", &" << rec_name << "::" << field_name << ">{}";
124128
first_field = false;
@@ -149,6 +153,13 @@ struct PbProducer : Producer<PbProducer> {
149153
// pure compile-time. No-op.
150154
}
151155

156+
void scatter_type_impl(const std::string& /*record_name*/,
157+
const std::vector<typename Producer<PbProducer>::scatter_field_t>& /*fields*/,
158+
const std::string& /*chunk_size*/, const std::string& /*compress_algo*/,
159+
int /*compress_level*/,
160+
const std::string& /*doc*/, const std::string& /*alias*/,
161+
const std::string& /*version*/, const std::string& /*on_missing*/) {}
162+
152163
// The cache contract is HDF5-shaped (cpp-type → hid_t-var mapping).
153164
// PbProducer doesn't need that vocabulary — pb dispatches via traits at
154165
// the library level, not via per-type variable aliases. Implement as

src/producer_sql.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ struct SqlProducer : Producer<SqlProducer<D>> {
2626

2727
void file_end_impl() {}
2828

29-
void template_decl_impl(const std::string& record) {
29+
void template_decl_impl(const std::string& record,
30+
const std::string& /*doc*/ = "",
31+
const std::string& /*alias*/ = "",
32+
const std::string& /*version*/ = "") {
3033
record_name = record;
3134
}
3235

@@ -55,7 +58,8 @@ struct SqlProducer : Producer<SqlProducer<D>> {
5558
}
5659

5760
void type_insert_impl(const std::string& /*var*/, const std::string& field_name,
58-
const std::string& /*record_name*/, const std::string& type) {
61+
const std::string& /*record_name*/, const std::string& type,
62+
const std::string& /*on_disk_name*/ = "") {
5963
if (first_field) {
6064
first_field = false;
6165
} else {
@@ -68,6 +72,13 @@ struct SqlProducer : Producer<SqlProducer<D>> {
6872

6973
void type_release_impl() {}
7074

75+
void scatter_type_impl(const std::string& /*record_name*/,
76+
const std::vector<typename Producer<SqlProducer>::scatter_field_t>& /*fields*/,
77+
const std::string& /*chunk_size*/, const std::string& /*compress_algo*/,
78+
int /*compress_level*/,
79+
const std::string& /*doc*/, const std::string& /*alias*/,
80+
const std::string& /*version*/, const std::string& /*on_missing*/) {}
81+
7182
bool cache_add_impl(const std::string& key, const std::string& type) {
7283
auto it = record_type_cache.find(type);
7384
if (it != record_type_cache.end()) {

0 commit comments

Comments
 (0)