Skip to content

Commit f1f8ee0

Browse files
committed
chore: Dom diagnostics and tidy
1 parent 740569c commit f1f8ee0

File tree

4 files changed

+228
-56
lines changed

4 files changed

+228
-56
lines changed

include/mrdox/Support/Dom.hpp

Lines changed: 83 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define MRDOX_API_SUPPORT_DOM_HPP
1313

1414
#include <mrdox/Platform.hpp>
15+
#include <fmt/format.h>
1516
#include <atomic>
1617
#include <cstdint>
1718
#include <initializer_list>
@@ -101,7 +102,6 @@ class MRDOX_DECL
101102
};
102103

103104
template<class U, class... Args>
104-
requires std::derived_from<U, Any>
105105
auto create(Args&&... args);
106106

107107
//------------------------------------------------
@@ -123,7 +123,8 @@ class Pointer
123123
friend class Pointer;
124124

125125
explicit
126-
Pointer(Any* any) noexcept
126+
Pointer(
127+
Any* any) noexcept
127128
: any_(any)
128129
{
129130
}
@@ -143,22 +144,31 @@ class Pointer
143144
}
144145

145146
template<class U>
146-
requires std::convertible_to<U*, T*>
147-
Pointer(U* u) noexcept
147+
requires(
148+
std::convertible_to<U*, T*> &&
149+
std::derived_from<U, Any>)
150+
Pointer(
151+
U* u) noexcept
148152
: any_(u->addref())
149153
{
150154
}
151155

152156
template<class U>
153-
requires std::convertible_to<U*, T*>
154-
Pointer(Pointer<U> const& other) noexcept
157+
requires(
158+
std::convertible_to<U*, T*> &&
159+
std::derived_from<U, Any>)
160+
Pointer(
161+
Pointer<U> const& other) noexcept
155162
: any_(other.any_->addref())
156163
{
157164
}
158165

159166
template<class U>
160-
requires std::convertible_to<U*, T*>
161-
Pointer& operator=(
167+
requires(
168+
std::convertible_to<U*, T*> &&
169+
std::derived_from<U, Any>)
170+
Pointer&
171+
operator=(
162172
Pointer<U> const& other) noexcept
163173
{
164174
Pointer temp(other);
@@ -196,12 +206,10 @@ class Pointer
196206
}
197207

198208
template<class U, class... Args>
199-
requires std::derived_from<U, Any>
200209
friend auto create(Args&&... args);
201210
};
202211

203212
template<class U, class... Args>
204-
requires std::derived_from<U, Any>
205213
auto create(Args&&... args)
206214
{
207215
return Pointer<U>(new U(
@@ -220,6 +228,11 @@ class MRDOX_DECL
220228
public:
221229
virtual std::size_t length() const noexcept;
222230
virtual Value get(std::size_t) const;
231+
232+
/** Return a diagnostic string.
233+
*/
234+
std::string
235+
displayString() const;
223236
};
224237

225238
using ArrayPtr = Pointer<Array>;
@@ -235,13 +248,8 @@ using ArrayPtr = Pointer<Array>;
235248
class MRDOX_DECL
236249
Object : public Any
237250
{
238-
protected:
239-
/** Constructor.
240-
241-
The newly constructed object will retain
242-
a copy of the list of values in `other`.
243-
*/
244-
Object(Object const& other);
251+
template<class U, class... Args>
252+
friend auto create(Args&&... args);
245253

246254
public:
247255
/** The type of an element in this container.
@@ -252,12 +260,20 @@ class MRDOX_DECL
252260
*/
253261
using list_type = std::vector<value_type>;
254262

263+
protected:
255264
/** Constructor.
256265
257266
Default-constructed objects are empty.
258267
*/
259268
Object() noexcept;
260269

270+
/** Constructor.
271+
272+
The newly constructed object will retain
273+
a copy of the list of values in `other`.
274+
*/
275+
Object(Object const& other);
276+
261277
/** Constructor.
262278
263279
Upon construction, the object will retain
@@ -269,6 +285,7 @@ class MRDOX_DECL
269285
*/
270286
explicit Object(list_type list);
271287

288+
public:
272289
/** Return an iterable range with the contents.
273290
*/
274291
list_type const& list() const noexcept;
@@ -322,6 +339,11 @@ class MRDOX_DECL
322339
*/
323340
virtual void set(std::string_view key, Value value);
324341

342+
/** Return a diagnostic string.
343+
*/
344+
std::string
345+
displayString() const;
346+
325347
// VFALCO DEPRECATED (for duktape)
326348
virtual std::vector<std::string_view> props() const;
327349

@@ -405,6 +427,9 @@ class MRDOX_DECL
405427
LazyObjectPtr lazy_obj_;
406428
};
407429

430+
friend class Array;
431+
friend class Object;
432+
408433
public:
409434
~Value();
410435
Value() noexcept;
@@ -553,6 +578,19 @@ class MRDOX_DECL
553578
{
554579
v0.swap(v1);
555580
}
581+
582+
/** Return a diagnostic string.
583+
*/
584+
std::string
585+
displayString() const;
586+
587+
private:
588+
/** Return a diagnostic string.
589+
590+
This function will not traverse children.
591+
*/
592+
std::string
593+
displayString1() const;
556594
};
557595

558596
/** Return a non-empty string, or a null.
@@ -571,4 +609,32 @@ stringOrNull(
571609
} // mrdox
572610
} // clang
573611

612+
//------------------------------------------------
613+
614+
template<>
615+
struct fmt::formatter<clang::mrdox::dom::Object>
616+
: fmt::formatter<std::string>
617+
{
618+
auto format(
619+
clang::mrdox::dom::Object const& value,
620+
fmt::format_context& ctx) const
621+
{
622+
return fmt::formatter<std::string>::format(
623+
value.displayString(), ctx);
624+
}
625+
};
626+
627+
template<>
628+
struct fmt::formatter<clang::mrdox::dom::Value>
629+
: fmt::formatter<std::string>
630+
{
631+
auto format(
632+
clang::mrdox::dom::Value const& value,
633+
fmt::format_context& ctx) const
634+
{
635+
return fmt::formatter<std::string>::format(
636+
value.displayString(), ctx);
637+
}
638+
};
639+
574640
#endif

include/mrdox/Support/JavaScript.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ class Scope
214214
MRDOX_DECL
215215
Object
216216
getGlobal(std::string_view name);
217-
218-
Expected<Value> call();
219217
};
220218

221219
//------------------------------------------------

source/Metadata/DomMetadata.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class DomSymbolArray : public dom::Array
7171
{
7272
}
7373

74-
std::size_t length() const noexcept
74+
std::size_t length() const noexcept override
7575
{
7676
return list_.size();
7777
}
@@ -205,14 +205,6 @@ class DomSourceInfo : public dom::Object
205205
}
206206
};
207207

208-
static
209-
dom::Value
210-
domCreate(
211-
SourceInfo const& I)
212-
{
213-
return dom::create<DomSourceInfo>(I);
214-
}
215-
216208
//------------------------------------------------
217209
//
218210
// TypeInfo
@@ -250,7 +242,6 @@ domCreate(
250242
//
251243
// Param
252244
//
253-
//
254245
//------------------------------------------------
255246

256247
/** A function parameter
@@ -558,7 +549,7 @@ class DomEnumValueArray : public dom::Array
558549
{
559550
}
560551

561-
std::size_t length() const noexcept
552+
std::size_t length() const noexcept override
562553
{
563554
return list_.size();
564555
}
@@ -592,8 +583,7 @@ class DomTrancheArray : public dom::Array
592583
{
593584
}
594585

595-
std::size_t
596-
length() const noexcept override
586+
std::size_t length() const noexcept override
597587
{
598588
return list_.size();
599589
}

0 commit comments

Comments
 (0)