@@ -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-
4843inline 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
5548inline 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.
8078inline 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.
178176inline 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 }
0 commit comments