103 changes: 52 additions & 51 deletions llvm/include/llvm/Support/TargetRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class MCSymbolizer;
class MCTargetAsmParser;
class MCTargetOptions;
class MCTargetStreamer;
class raw_ostream;
class raw_pwrite_stream;
class TargetMachine;
class TargetOptions;
Expand Down Expand Up @@ -96,75 +97,75 @@ class Target {
public:
friend struct TargetRegistry;

typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
using ArchMatchFnTy = bool (*)(Triple::ArchType Arch);

typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
const Triple &TT);
typedef void (*MCAdjustCodeGenOptsFnTy)(const Triple &TT, Reloc::Model RM,
CodeModel::Model &CM);
using MCAsmInfoCtorFnTy = MCAsmInfo *(*)(const MCRegisterInfo &MRI,
const Triple &TT);
using MCAdjustCodeGenOptsFnTy = void (*)(const Triple &TT, Reloc::Model RM,
CodeModel::Model &CM);

typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo *Info);
typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(const Triple &TT);
typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(const Triple &TT,
StringRef CPU,
StringRef Features);
typedef TargetMachine *(*TargetMachineCtorTy)(
using MCInstrInfoCtorFnTy = MCInstrInfo *(*)();
using MCInstrAnalysisCtorFnTy = MCInstrAnalysis *(*)(const MCInstrInfo *Info);
using MCRegInfoCtorFnTy = MCRegisterInfo *(*)(const Triple &TT);
using MCSubtargetInfoCtorFnTy = MCSubtargetInfo *(*)(const Triple &TT,
StringRef CPU,
StringRef Features);
using TargetMachineCtorTy = TargetMachine *(*)(
const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
const TargetOptions &Options, Optional<Reloc::Model> RM,
CodeModel::Model CM, CodeGenOpt::Level OL);
// If it weren't for layering issues (this header is in llvm/Support, but
// depends on MC?) this should take the Streamer by value rather than rvalue
// reference.
typedef AsmPrinter *(*AsmPrinterCtorTy)(
using AsmPrinterCtorTy = AsmPrinter *(*)(
TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
const MCRegisterInfo &MRI,
const Triple &TT, StringRef CPU,
const MCTargetOptions &Options);
typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
using MCAsmBackendCtorTy = MCAsmBackend *(*)(const Target &T,
const MCRegisterInfo &MRI,
const Triple &TT, StringRef CPU,
const MCTargetOptions &Options);
using MCAsmParserCtorTy = MCTargetAsmParser *(*)(
const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
const MCTargetOptions &Options);
typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
const MCSubtargetInfo &STI,
MCContext &Ctx);
typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Triple &T,
unsigned SyntaxVariant,
const MCAsmInfo &MAI,
const MCInstrInfo &MII,
const MCRegisterInfo &MRI);
typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
const MCRegisterInfo &MRI,
MCContext &Ctx);
typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
MCAsmBackend &TAB,
raw_pwrite_stream &OS,
MCCodeEmitter *Emitter,
bool RelaxAll);
typedef MCStreamer *(*MachOStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
raw_pwrite_stream &OS,
MCCodeEmitter *Emitter,
bool RelaxAll,
bool DWARFMustBeAtTheEnd);
typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
raw_pwrite_stream &OS,
MCCodeEmitter *Emitter,
bool RelaxAll,
bool IncrementalLinkerCompatible);
typedef MCStreamer *(*WasmStreamerCtorTy)(const Triple &T, MCContext &Ctx,
using MCDisassemblerCtorTy = MCDisassembler *(*)(const Target &T,
const MCSubtargetInfo &STI,
MCContext &Ctx);
using MCInstPrinterCtorTy = MCInstPrinter *(*)(const Triple &T,
unsigned SyntaxVariant,
const MCAsmInfo &MAI,
const MCInstrInfo &MII,
const MCRegisterInfo &MRI);
using MCCodeEmitterCtorTy = MCCodeEmitter *(*)(const MCInstrInfo &II,
const MCRegisterInfo &MRI,
MCContext &Ctx);
using ELFStreamerCtorTy = MCStreamer *(*)(const Triple &T, MCContext &Ctx,
MCAsmBackend &TAB,
raw_pwrite_stream &OS,
MCCodeEmitter *Emitter,
bool RelaxAll);
typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
using MachOStreamerCtorTy = MCStreamer *(*)(MCContext &Ctx, MCAsmBackend &TAB,
raw_pwrite_stream &OS,
MCCodeEmitter *Emitter,
bool RelaxAll,
bool DWARFMustBeAtTheEnd);
using COFFStreamerCtorTy = MCStreamer *(*)(MCContext &Ctx, MCAsmBackend &TAB,
raw_pwrite_stream &OS,
MCCodeEmitter *Emitter,
bool RelaxAll,
bool IncrementalLinkerCompatible);
using WasmStreamerCtorTy = MCStreamer *(*)(const Triple &T, MCContext &Ctx,
MCAsmBackend &TAB,
raw_pwrite_stream &OS,
MCCodeEmitter *Emitter,
bool RelaxAll);
using NullTargetStreamerCtorTy = MCTargetStreamer *(*)(MCStreamer &S);
using AsmTargetStreamerCtorTy = MCTargetStreamer *(*)(
MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
bool IsVerboseAsm);
typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
using ObjectTargetStreamerCtorTy = MCTargetStreamer *(*)(
MCStreamer &S, const MCSubtargetInfo &STI);
typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(const Triple &TT,
MCContext &Ctx);
typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
using MCRelocationInfoCtorTy = MCRelocationInfo *(*)(const Triple &TT,
MCContext &Ctx);
using MCSymbolizerCtorTy = MCSymbolizer *(*)(
const Triple &TT, LLVMOpInfoCallback GetOpInfo,
LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
std::unique_ptr<MCRelocationInfo> &&RelInfo);
Expand Down
97 changes: 51 additions & 46 deletions llvm/include/llvm/Support/YAMLParser.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===--- YAMLParser.h - Simple YAML parser --------------------------------===//
//===- YAMLParser.h - Simple YAML parser ------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
Expand Down Expand Up @@ -41,20 +41,25 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/SMLoc.h"
#include <cassert>
#include <cstddef>
#include <iterator>
#include <map>
#include <memory>
#include <string>
#include <system_error>
#include <utility>

namespace llvm {

class MemoryBufferRef;
class SourceMgr;
class Twine;
class raw_ostream;
class Twine;

namespace yaml {

class document_iterator;
class Document;
class document_iterator;
class Node;
class Scanner;
struct Token;
Expand Down Expand Up @@ -87,6 +92,7 @@ class Stream {
document_iterator end();
void skip();
bool failed();

bool validate() {
skip();
return !failed();
Expand All @@ -95,10 +101,10 @@ class Stream {
void printError(Node *N, const Twine &Msg);

private:
friend class Document;

std::unique_ptr<Scanner> scanner;
std::unique_ptr<Document> CurrentDoc;

friend class Document;
};

/// \brief Abstract base class for all Nodes.
Expand All @@ -119,6 +125,18 @@ class Node {
Node(unsigned int Type, std::unique_ptr<Document> &, StringRef Anchor,
StringRef Tag);

void *operator new(size_t Size, BumpPtrAllocator &Alloc,
size_t Alignment = 16) noexcept {
return Alloc.Allocate(Size, Alignment);
}

void operator delete(void *Ptr, BumpPtrAllocator &Alloc,
size_t Size) noexcept {
Alloc.Deallocate(Ptr, Size);
}

void operator delete(void *) noexcept = delete;

/// \brief Get the value of the anchor attached to this node. If it does not
/// have one, getAnchor().size() will be 0.
StringRef getAnchor() const { return Anchor; }
Expand Down Expand Up @@ -146,22 +164,10 @@ class Node {

unsigned int getType() const { return TypeID; }

void *operator new(size_t Size, BumpPtrAllocator &Alloc,
size_t Alignment = 16) noexcept {
return Alloc.Allocate(Size, Alignment);
}

void operator delete(void *Ptr, BumpPtrAllocator &Alloc,
size_t Size) noexcept {
Alloc.Deallocate(Ptr, Size);
}

protected:
std::unique_ptr<Document> &Doc;
SMRange SourceRange;

void operator delete(void *) noexcept = delete;

~Node() = default;

private:
Expand Down Expand Up @@ -268,8 +274,7 @@ class KeyValueNode final : public Node {

public:
KeyValueNode(std::unique_ptr<Document> &D)
: Node(NK_KeyValue, D, StringRef(), StringRef()), Key(nullptr),
Value(nullptr) {}
: Node(NK_KeyValue, D, StringRef(), StringRef()) {}

/// \brief Parse and return the key.
///
Expand All @@ -296,8 +301,8 @@ class KeyValueNode final : public Node {
}

private:
Node *Key;
Node *Value;
Node *Key = nullptr;
Node *Value = nullptr;
};

/// \brief This is an iterator abstraction over YAML collections shared by both
Expand All @@ -309,7 +314,7 @@ template <class BaseT, class ValueT>
class basic_collection_iterator
: public std::iterator<std::input_iterator_tag, ValueT> {
public:
basic_collection_iterator() : Base(nullptr) {}
basic_collection_iterator() = default;
basic_collection_iterator(BaseT *B) : Base(B) {}

ValueT *operator->() const {
Expand Down Expand Up @@ -358,7 +363,7 @@ class basic_collection_iterator
}

private:
BaseT *Base;
BaseT *Base = nullptr;
};

// The following two templates are used for both MappingNode and Sequence Node.
Expand Down Expand Up @@ -399,11 +404,12 @@ class MappingNode final : public Node {

MappingNode(std::unique_ptr<Document> &D, StringRef Anchor, StringRef Tag,
MappingType MT)
: Node(NK_Mapping, D, Anchor, Tag), Type(MT), IsAtBeginning(true),
IsAtEnd(false), CurrentEntry(nullptr) {}
: Node(NK_Mapping, D, Anchor, Tag), Type(MT) {}

friend class basic_collection_iterator<MappingNode, KeyValueNode>;
typedef basic_collection_iterator<MappingNode, KeyValueNode> iterator;

using iterator = basic_collection_iterator<MappingNode, KeyValueNode>;

template <class T> friend typename T::iterator yaml::begin(T &);
template <class T> friend void yaml::skip(T &);

Expand All @@ -419,9 +425,9 @@ class MappingNode final : public Node {

private:
MappingType Type;
bool IsAtBeginning;
bool IsAtEnd;
KeyValueNode *CurrentEntry;
bool IsAtBeginning = true;
bool IsAtEnd = false;
KeyValueNode *CurrentEntry = nullptr;

void increment();
};
Expand Down Expand Up @@ -453,13 +459,12 @@ class SequenceNode final : public Node {

SequenceNode(std::unique_ptr<Document> &D, StringRef Anchor, StringRef Tag,
SequenceType ST)
: Node(NK_Sequence, D, Anchor, Tag), SeqType(ST), IsAtBeginning(true),
IsAtEnd(false),
WasPreviousTokenFlowEntry(true), // Start with an imaginary ','.
CurrentEntry(nullptr) {}
: Node(NK_Sequence, D, Anchor, Tag), SeqType(ST) {}

friend class basic_collection_iterator<SequenceNode, Node>;
typedef basic_collection_iterator<SequenceNode, Node> iterator;

using iterator = basic_collection_iterator<SequenceNode, Node>;

template <class T> friend typename T::iterator yaml::begin(T &);
template <class T> friend void yaml::skip(T &);

Expand All @@ -477,10 +482,10 @@ class SequenceNode final : public Node {

private:
SequenceType SeqType;
bool IsAtBeginning;
bool IsAtEnd;
bool WasPreviousTokenFlowEntry;
Node *CurrentEntry;
bool IsAtBeginning = true;
bool IsAtEnd = false;
bool WasPreviousTokenFlowEntry = true; // Start with an imaginary ','.
Node *CurrentEntry = nullptr;
};

/// \brief Represents an alias to a Node with an anchor.
Expand All @@ -507,11 +512,11 @@ class AliasNode final : public Node {
/// node.
class Document {
public:
Document(Stream &ParentStream);

/// \brief Root for parsing a node. Returns a single node.
Node *parseBlockNode();

Document(Stream &ParentStream);

/// \brief Finish parsing the current document and return true if there are
/// more. Return false otherwise.
bool skip();
Expand Down Expand Up @@ -564,7 +569,7 @@ class Document {
/// \brief Iterator abstraction for Documents over a Stream.
class document_iterator {
public:
document_iterator() : Doc(nullptr) {}
document_iterator() = default;
document_iterator(std::unique_ptr<Document> &D) : Doc(&D) {}

bool operator==(const document_iterator &Other) {
Expand Down Expand Up @@ -593,11 +598,11 @@ class document_iterator {
private:
bool isAtEnd() const { return !Doc || !*Doc; }

std::unique_ptr<Document> *Doc;
std::unique_ptr<Document> *Doc = nullptr;
};

} // End namespace yaml.
} // end namespace yaml

} // End namespace llvm.
} // end namespace llvm

#endif
#endif // LLVM_SUPPORT_YAMLPARSER_H
182 changes: 93 additions & 89 deletions llvm/include/llvm/Support/YAMLTraits.h

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- CoverageMapping.cpp - Code coverage mapping support ------*- C++ -*-===//
//===- CoverageMapping.cpp - Code coverage mapping support ----------------===//
//
// The LLVM Compiler Infrastructure
//
Expand Down Expand Up @@ -303,8 +303,8 @@ namespace {
/// An instantiation set is a collection of functions that have the same source
/// code, ie, template functions specializations.
class FunctionInstantiationSetCollector {
typedef DenseMap<std::pair<unsigned, unsigned>,
std::vector<const FunctionRecord *>> MapT;
using MapT = DenseMap<std::pair<unsigned, unsigned>,
std::vector<const FunctionRecord *>>;
MapT InstantiatedFunctions;

public:
Expand All @@ -318,7 +318,6 @@ class FunctionInstantiationSetCollector {
}

MapT::iterator begin() { return InstantiatedFunctions.begin(); }

MapT::iterator end() { return InstantiatedFunctions.end(); }
};

Expand Down
16 changes: 8 additions & 8 deletions llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- CoverageMappingReader.cpp - Code coverage mapping reader -*- C++ -*-===//
//===- CoverageMappingReader.cpp - Code coverage mapping reader -----------===//
//
// The LLVM Compiler Infrastructure
//
Expand Down Expand Up @@ -62,7 +62,7 @@ void CoverageMappingIterator::increment() {
}

Error RawCoverageReader::readULEB128(uint64_t &Result) {
if (Data.size() < 1)
if (Data.empty())
return make_error<CoverageMapError>(coveragemap_error::truncated);
unsigned N = 0;
Result = decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);
Expand Down Expand Up @@ -392,9 +392,9 @@ struct CovMapFuncRecordReader {
// A class for reading coverage mapping function records for a module.
template <CovMapVersion Version, class IntPtrT, support::endianness Endian>
class VersionedCovMapFuncRecordReader : public CovMapFuncRecordReader {
typedef typename CovMapTraits<
Version, IntPtrT>::CovMapFuncRecordType FuncRecordType;
typedef typename CovMapTraits<Version, IntPtrT>::NameRefType NameRefType;
using FuncRecordType =
typename CovMapTraits<Version, IntPtrT>::CovMapFuncRecordType;
using NameRefType = typename CovMapTraits<Version, IntPtrT>::NameRefType;

// Maps function's name references to the indexes of their records
// in \c Records.
Expand Down Expand Up @@ -576,15 +576,15 @@ static Error loadTestingFormat(StringRef Data, InstrProfSymtab &ProfileNames,
Endian = support::endianness::little;

Data = Data.substr(StringRef(TestingFormatMagic).size());
if (Data.size() < 1)
if (Data.empty())
return make_error<CoverageMapError>(coveragemap_error::truncated);
unsigned N = 0;
auto ProfileNamesSize =
decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);
if (N > Data.size())
return make_error<CoverageMapError>(coveragemap_error::malformed);
Data = Data.substr(N);
if (Data.size() < 1)
if (Data.empty())
return make_error<CoverageMapError>(coveragemap_error::truncated);
N = 0;
uint64_t Address =
Expand All @@ -598,7 +598,7 @@ static Error loadTestingFormat(StringRef Data, InstrProfSymtab &ProfileNames,
return E;
CoverageMapping = Data.substr(ProfileNamesSize);
// Skip the padding bytes because coverage map data has an alignment of 8.
if (CoverageMapping.size() < 1)
if (CoverageMapping.empty())
return make_error<CoverageMapError>(coveragemap_error::truncated);
size_t Pad = alignmentAdjustment(CoverageMapping.data(), 8);
if (CoverageMapping.size() < Pad)
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/ProfileData/InstrProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ InstrProfLookupTrait::ComputeHash(StringRef K) {
return IndexedInstrProf::ComputeHash(HashType, K);
}

typedef InstrProfLookupTrait::data_type data_type;
typedef InstrProfLookupTrait::offset_type offset_type;
using data_type = InstrProfLookupTrait::data_type;
using offset_type = InstrProfLookupTrait::offset_type;

bool InstrProfLookupTrait::readValueProfilingData(
const unsigned char *&D, const unsigned char *const End) {
Expand Down Expand Up @@ -622,7 +622,7 @@ IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version,
for (unsigned I = 0; I < SummarySize / sizeof(uint64_t); I++)
Dst[I] = endian::byte_swap<uint64_t, little>(Src[I]);

llvm::SummaryEntryVector DetailedSummary;
SummaryEntryVector DetailedSummary;
for (unsigned I = 0; I < SummaryData->NumCutoffEntries; I++) {
const IndexedInstrProf::Summary::Entry &Ent = SummaryData->getEntry(I);
DetailedSummary.emplace_back((uint32_t)Ent.Cutoff, Ent.MinBlockCount,
Expand Down
15 changes: 7 additions & 8 deletions llvm/lib/ProfileData/InstrProfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ class ProfOStream {
write(P[K].D[I]);
}
} else {
raw_string_ostream &SOStream =
static_cast<llvm::raw_string_ostream &>(OS);
raw_string_ostream &SOStream = static_cast<raw_string_ostream &>(OS);
std::string &Data = SOStream.str(); // with flush
for (int K = 0; K < NItems; K++) {
for (int I = 0; I < P[K].N; I++) {
Expand All @@ -91,14 +90,14 @@ class ProfOStream {

class InstrProfRecordWriterTrait {
public:
typedef StringRef key_type;
typedef StringRef key_type_ref;
using key_type = StringRef;
using key_type_ref = StringRef;

typedef const InstrProfWriter::ProfilingData *const data_type;
typedef const InstrProfWriter::ProfilingData *const data_type_ref;
using data_type = const InstrProfWriter::ProfilingData *const;
using data_type_ref = const InstrProfWriter::ProfilingData *const;

typedef uint64_t hash_value_type;
typedef uint64_t offset_type;
using hash_value_type = uint64_t;
using offset_type = uint64_t;

support::endianness ValueProfDataEndianness = support::little;
InstrProfSummaryBuilder *SummaryBuilder;
Expand Down
19 changes: 17 additions & 2 deletions llvm/lib/Support/GraphWriter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- GraphWriter.cpp - Implements GraphWriter support routines ---------===//
//===- GraphWriter.cpp - Implements GraphWriter support routines ----------===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -12,10 +12,22 @@
//===----------------------------------------------------------------------===//

#include "llvm/Support/GraphWriter.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/config.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <system_error>
#include <string>
#include <vector>

using namespace llvm;

static cl::opt<bool> ViewBackground("view-background", cl::Hidden,
Expand Down Expand Up @@ -99,8 +111,10 @@ static bool ExecGraphViewer(StringRef ExecPath, std::vector<const char *> &args,
}

namespace {

struct GraphSession {
std::string LogBuffer;

bool TryFindProgram(StringRef Names, std::string &ProgramPath) {
raw_string_ostream Log(LogBuffer);
SmallVector<StringRef, 8> parts;
Expand All @@ -115,7 +129,8 @@ struct GraphSession {
return false;
}
};
} // namespace

} // end anonymous namespace

static const char *getProgramName(GraphProgram::Name program) {
switch (program) {
Expand Down
58 changes: 38 additions & 20 deletions llvm/lib/Support/YAMLParser.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===--- YAMLParser.cpp - Simple YAML parser ------------------------------===//
//===- YAMLParser.cpp - Simple YAML parser --------------------------------===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -13,15 +13,29 @@

#include "llvm/Support/YAMLParser.h"
#include "llvm/ADT/AllocatorList.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SMLoc.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <system_error>
#include <utility>

using namespace llvm;
using namespace yaml;
Expand All @@ -37,7 +51,7 @@ enum UnicodeEncodingForm {

/// EncodingInfo - Holds the encoding type and length of the byte order mark if
/// it exists. Length is in {0, 2, 3, 4}.
typedef std::pair<UnicodeEncodingForm, unsigned> EncodingInfo;
using EncodingInfo = std::pair<UnicodeEncodingForm, unsigned>;

/// getUnicodeEncoding - Reads up to the first 4 bytes to determine the Unicode
/// encoding form of \a Input.
Expand All @@ -46,7 +60,7 @@ typedef std::pair<UnicodeEncodingForm, unsigned> EncodingInfo;
/// @returns An EncodingInfo indicating the Unicode encoding form of the input
/// and how long the byte order mark is if one exists.
static EncodingInfo getUnicodeEncoding(StringRef Input) {
if (Input.size() == 0)
if (Input.empty())
return std::make_pair(UEF_Unknown, 0);

switch (uint8_t(Input[0])) {
Expand Down Expand Up @@ -95,8 +109,6 @@ static EncodingInfo getUnicodeEncoding(StringRef Input) {
return std::make_pair(UEF_UTF8, 0);
}

namespace llvm {
namespace yaml {
/// Pin the vtables to this file.
void Node::anchor() {}
void NullNode::anchor() {}
Expand All @@ -107,6 +119,9 @@ void MappingNode::anchor() {}
void SequenceNode::anchor() {}
void AliasNode::anchor() {}

namespace llvm {
namespace yaml {

/// Token - A single YAML token.
struct Token {
enum TokenKind {
Expand All @@ -133,7 +148,7 @@ struct Token {
TK_Alias,
TK_Anchor,
TK_Tag
} Kind;
} Kind = TK_Error;

/// A string of length 0 or more whose begin() points to the logical location
/// of the token in the input.
Expand All @@ -142,14 +157,16 @@ struct Token {
/// The value of a block scalar node.
std::string Value;

Token() : Kind(TK_Error) {}
Token() = default;
};
}
}

typedef llvm::BumpPtrList<Token> TokenQueueT;
} // end namespace yaml
} // end namespace llvm

using TokenQueueT = BumpPtrList<Token>;

namespace {

/// @brief This struct is used to track simple keys.
///
/// Simple keys are handled by creating an entry in SimpleKeys for each Token
Expand All @@ -170,12 +187,13 @@ struct SimpleKey {
return Tok == Other.Tok;
}
};
}

} // end anonymous namespace

/// @brief The Unicode scalar value of a UTF-8 minimal well-formed code unit
/// subsequence and the subsequence's length in code units (uint8_t).
/// A length of 0 represents an error.
typedef std::pair<uint32_t, unsigned> UTF8Decoded;
using UTF8Decoded = std::pair<uint32_t, unsigned>;

static UTF8Decoded decodeUTF8(StringRef Range) {
StringRef::iterator Position= Range.begin();
Expand Down Expand Up @@ -229,6 +247,7 @@ static UTF8Decoded decodeUTF8(StringRef Range) {

namespace llvm {
namespace yaml {

/// @brief Scans YAML tokens from a MemoryBuffer.
class Scanner {
public:
Expand Down Expand Up @@ -350,7 +369,8 @@ class Scanner {
/// ns-char.
StringRef::iterator skip_ns_char(StringRef::iterator Position);

typedef StringRef::iterator (Scanner::*SkipWhileFunc)(StringRef::iterator);
using SkipWhileFunc = StringRef::iterator (Scanner::*)(StringRef::iterator);

/// @brief Skip minimal well-formed code unit subsequences until Func
/// returns its input.
///
Expand Down Expand Up @@ -655,10 +675,10 @@ bool yaml::dumpTokens(StringRef Input, raw_ostream &OS) {
}

bool yaml::scanTokens(StringRef Input) {
llvm::SourceMgr SM;
llvm::yaml::Scanner scanner(Input, SM);
for (;;) {
llvm::yaml::Token T = scanner.getNext();
SourceMgr SM;
Scanner scanner(Input, SM);
while (true) {
Token T = scanner.getNext();
if (T.Kind == Token::TK_StreamEnd)
break;
else if (T.Kind == Token::TK_Error)
Expand Down Expand Up @@ -1744,7 +1764,7 @@ Stream::Stream(MemoryBufferRef InputBuffer, SourceMgr &SM, bool ShowColors,
std::error_code *EC)
: scanner(new Scanner(InputBuffer, SM, ShowColors, EC)), CurrentDoc() {}

Stream::~Stream() {}
Stream::~Stream() = default;

bool Stream::failed() { return scanner->failed(); }

Expand Down Expand Up @@ -1851,8 +1871,6 @@ bool Node::failed() const {
return Doc->failed();
}



StringRef ScalarNode::getValue(SmallVectorImpl<char> &Storage) const {
// TODO: Handle newlines properly. We need to remove leading whitespace.
if (Value[0] == '"') { // Double quoted.
Expand Down
31 changes: 16 additions & 15 deletions llvm/lib/Support/YAMLTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,36 @@
//===----------------------------------------------------------------------===//

#include "llvm/Support/YAMLTraits.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/Support/raw_ostream.h"
#include <cctype>
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>

using namespace llvm;
using namespace yaml;

//===----------------------------------------------------------------------===//
// IO
//===----------------------------------------------------------------------===//

IO::IO(void *Context) : Ctxt(Context) {
}
IO::IO(void *Context) : Ctxt(Context) {}

IO::~IO() {
}
IO::~IO() = default;

void *IO::getContext() {
return Ctxt;
Expand All @@ -46,15 +53,13 @@ void IO::setContext(void *Context) {

Input::Input(StringRef InputContent, void *Ctxt,
SourceMgr::DiagHandlerTy DiagHandler, void *DiagHandlerCtxt)
: IO(Ctxt), Strm(new Stream(InputContent, SrcMgr, false, &EC)),
CurrentNode(nullptr) {
: IO(Ctxt), Strm(new Stream(InputContent, SrcMgr, false, &EC)) {
if (DiagHandler)
SrcMgr.setDiagHandler(DiagHandler, DiagHandlerCtxt);
DocIterator = Strm->begin();
}

Input::~Input() {
}
Input::~Input() = default;

std::error_code Input::error() { return EC; }

Expand Down Expand Up @@ -398,13 +403,9 @@ bool Input::canElideEmptySequence() {
//===----------------------------------------------------------------------===//

Output::Output(raw_ostream &yout, void *context, int WrapColumn)
: IO(context), Out(yout), WrapColumn(WrapColumn), Column(0),
ColumnAtFlowStart(0), ColumnAtMapFlowStart(0), NeedBitValueComma(false),
NeedFlowSequenceComma(false), EnumerationMatchFound(false),
NeedsNewLine(false), WriteDefaultValues(false) {}
: IO(context), Out(yout), WrapColumn(WrapColumn) {}

Output::~Output() {
}
Output::~Output() = default;

bool Output::outputting() {
return true;
Expand Down