Skip to content

Commit

Permalink
Resubmit "Add support for advanced number formatting."
Browse files Browse the repository at this point in the history
This resubmits commits 284425 and r284428, which were reverted
in r284429 due to some infinite recursion caused by an incorrect
selection of function overloads.  Reproduced the failure on Linux
using GCC 4.8.4, and confirmed that with the new patch the tests
path on GCC as well as MSVC.  So hopefully this fixes everything.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284436 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Zachary Turner committed Oct 17, 2016
1 parent 18560f1 commit b3a1851
Show file tree
Hide file tree
Showing 5 changed files with 717 additions and 100 deletions.
57 changes: 46 additions & 11 deletions include/llvm/Support/NativeFormatting.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,57 @@
#ifndef LLVM_SUPPORT_NATIVE_FORMATTING_H
#define LLVM_SUPPORT_NATIVE_FORMATTING_H

#include "llvm/ADT/Optional.h"
#include "llvm/Support/raw_ostream.h"

#include <cstdint>

namespace llvm {
enum class FloatStyle { Exponent, Decimal };

void write_ulong(raw_ostream &S, unsigned long N, std::size_t MinWidth);
void write_long(raw_ostream &S, long N, std::size_t MinWidth);
void write_ulonglong(raw_ostream &S, unsigned long long N,
std::size_t MinWidth);
void write_longlong(raw_ostream &S, long long N, std::size_t MinWidth);
void write_hex(raw_ostream &S, unsigned long long N, std::size_t MinWidth,
bool Upper, bool Prefix);
void write_double(raw_ostream &S, double D, std::size_t MinWidth,
std::size_t MinDecimals, FloatStyle Style);
enum class FloatStyle { Exponent, ExponentUpper, Fixed, Percent };
enum class IntegerStyle {
Exponent,
ExponentUpper,
Integer,
Fixed,
Number,
Percent,
HexUpperPrefix,
HexUpperNoPrefix,
HexLowerPrefix,
HexLowerNoPrefix
};
enum class HexStyle { Upper, Lower, PrefixUpper, PrefixLower };

IntegerStyle hexStyleToIntHexStyle(HexStyle S);

size_t getDefaultPrecision(FloatStyle Style);
size_t getDefaultPrecision(IntegerStyle Style);
size_t getDefaultPrecision(HexStyle Style);

void write_integer(raw_ostream &S, unsigned int N, IntegerStyle Style,
Optional<size_t> Precision = None,
Optional<int> Width = None);
void write_integer(raw_ostream &S, int N, IntegerStyle Style,
Optional<size_t> Precision = None,
Optional<int> Width = None);
void write_integer(raw_ostream &S, unsigned long N, IntegerStyle Style,
Optional<size_t> Precision = None,
Optional<int> Width = None);
void write_integer(raw_ostream &S, long N, IntegerStyle Style,
Optional<size_t> Precision = None,
Optional<int> Width = None);
void write_integer(raw_ostream &S, unsigned long long N, IntegerStyle Style,
Optional<size_t> Precision = None,
Optional<int> Width = None);
void write_integer(raw_ostream &S, long long N, IntegerStyle Style,
Optional<size_t> Precision = None,
Optional<int> Width = None);

void write_hex(raw_ostream &S, uint64_t N, HexStyle Style,
Optional<size_t> Precision = None, Optional<int> Width = None);
void write_double(raw_ostream &S, double D, FloatStyle Style,
Optional<size_t> Precision = None,
Optional<int> Width = None);
}

#endif
Loading

0 comments on commit b3a1851

Please sign in to comment.