This is an archive of the discontinued LLVM Phabricator instance.

Improve the functionality of JSONNumber
ClosedPublic

Authored by tberghammer on Dec 3 2015, 5:45 AM.

Details

Summary

Improve the functionality of JSONNumber

  • Add support for representing signed integers
  • Add new constructors taking any signed or unsigned integer types

Diff Detail

Repository
rL LLVM

Event Timeline

tberghammer updated this revision to Diff 41743.Dec 3 2015, 5:45 AM
tberghammer retitled this revision from to Improve the functionality of JSONNumber.
tberghammer updated this object.
tberghammer added a subscriber: lldb-commits.
clayborg edited edge metadata.Dec 3 2015, 9:34 AM

Everything looks good, just wondering why we need the template code? See inlined comments.

include/lldb/Utility/JSON.h
102–104 ↗(On Diff #41743)

What value is the template code giving us? Why can't we omit this and just have a constructor with int64_t and double?

granata.enrico edited edge metadata.Dec 3 2015, 9:44 AM
granata.enrico added a subscriber: granata.enrico.

IIU my C++ correctly, this code covers neither int64_t nor double; it covers the unsigned variety of int64 - as well as any other unsigned integer type.

The main advantage (other than not relying on implicit promotions) would be that if someone writes their new integral data type (BigNum), and mark it with the appropriate traits, it would Just Work

  • Enrico
tberghammer added inline comments.Dec 3 2015, 9:47 AM
include/lldb/Utility/JSON.h
102–104 ↗(On Diff #41743)

If we have a constructor with int64_t and one with double then we will get a compilation error when we try to call it with an int32_t because the 2 overload will be ambiguous. We can work it around at each call site with casting the value to the type what the constructor takes but I would prefer to handle the issue it in 1 place instead of all call site.

clayborg accepted this revision.Dec 3 2015, 9:54 AM
clayborg edited edge metadata.

Ok, thanks for the explanation. You might add a comment saying something like you just said above the template stuff so people can see why it is needed.

This revision is now accepted and ready to land.Dec 3 2015, 9:54 AM
This revision was automatically updated to reflect the committed changes.