37IO::IO(
void *Context) : Ctxt(Context) {}
59 :
IO(Ctxt), Strm(new
Stream(InputContent, SrcMgr,
false, &EC)) {
61 SrcMgr.setDiagHandler(
DiagHandler, DiagHandlerCtxt);
62 DocIterator = Strm->begin();
69 SrcMgr.setDiagHandler(
DiagHandler, DiagHandlerCtxt);
70 DocIterator = Strm->begin();
82 if (DocIterator != Strm->end()) {
83 Node *
N = DocIterator->getRoot();
94 releaseHNodeBuffers();
95 TopNode = createHNodes(
N);
96 CurrentNode = TopNode;
103 return ++DocIterator != Strm->end();
107 return CurrentNode ? CurrentNode->_node :
nullptr;
117 if (foundTag.empty()) {
122 return Tag == foundTag;
131 MN->ValidKeys.clear();
137 std::vector<StringRef>
Ret;
139 setError(CurrentNode,
"not a mapping");
142 for (
auto &
P : MN->Mapping)
143 Ret.push_back(
P.first());
147bool Input::preflightKey(
const char *
Key,
bool Required,
bool,
bool &UseDefault,
166 setError(CurrentNode,
"not a mapping");
171 MN->ValidKeys.push_back(
Key);
172 HNode *
Value = MN->Mapping[
Key].first;
175 setError(CurrentNode, Twine(
"missing required key '") +
Key +
"'");
180 SaveInfo = CurrentNode;
185void Input::postflightKey(
void *saveInfo) {
186 CurrentNode =
reinterpret_cast<HNode *
>(saveInfo);
196 for (
const auto &NN : MN->Mapping) {
198 const SMRange &ReportLoc = NN.second.second;
199 if (!AllowUnknownKeys) {
200 setError(ReportLoc, Twine(
"unknown key '") + NN.first() +
"'");
203 reportWarning(ReportLoc, Twine(
"unknown key '") + NN.first() +
"'");
214 return SQ->Entries.size();
223 setError(CurrentNode,
"not a sequence");
230bool Input::preflightElement(
unsigned Index,
void *&SaveInfo) {
234 SaveInfo = CurrentNode;
235 CurrentNode = SQ->Entries[
Index];
241void Input::postflightElement(
void *SaveInfo) {
242 CurrentNode =
reinterpret_cast<HNode *
>(SaveInfo);
247bool Input::preflightFlowElement(
unsigned index,
void *&SaveInfo) {
251 SaveInfo = CurrentNode;
252 CurrentNode = SQ->Entries[index];
258void Input::postflightFlowElement(
void *SaveInfo) {
259 CurrentNode =
reinterpret_cast<HNode *
>(SaveInfo);
266 ScalarMatchFound =
false;
269bool Input::matchEnumScalar(
const char *Str,
bool) {
270 if (ScalarMatchFound)
273 if (SN->value() == Str) {
274 ScalarMatchFound =
true;
282 if (ScalarMatchFound)
284 ScalarMatchFound =
true;
289 if (!ScalarMatchFound) {
290 setError(CurrentNode,
"unknown enumerated scalar");
294bool Input::beginBitSetScalar(
bool &DoClear) {
295 BitValuesUsed.clear();
297 BitValuesUsed.resize(SQ->Entries.size());
299 setError(CurrentNode,
"expected sequence of bit values");
305bool Input::bitSetMatch(
const char *Str,
bool) {
310 for (
auto &
N : SQ->Entries) {
312 if (SN->value() == Str) {
313 BitValuesUsed[
Index] =
true;
317 setError(CurrentNode,
"unexpected scalar in sequence of bit values");
322 setError(CurrentNode,
"expected sequence of bit values");
331 assert(BitValuesUsed.size() == SQ->Entries.size());
332 for (
unsigned i = 0; i < SQ->Entries.size(); ++i) {
333 if (!BitValuesUsed[i]) {
334 setError(SQ->Entries[i],
"unknown bit value");
341void Input::scalarString(StringRef &S,
QuotingType) {
345 setError(CurrentNode,
"unexpected scalar");
349void Input::blockScalarString(StringRef &S) { scalarString(S,
QuotingType::None); }
351void Input::scalarTag(std::string &
Tag) {
352 Tag = CurrentNode->_node->getVerbatimTag();
355void Input::setError(HNode *hnode,
const Twine &message) {
356 assert(hnode &&
"HNode must not be NULL");
357 setError(hnode->_node, message);
370void Input::setError(
Node *node,
const Twine &message) {
371 Strm->printError(node, message);
375void Input::setError(
const SMRange &range,
const Twine &message) {
376 Strm->printError(range, message);
380void Input::reportWarning(HNode *hnode,
const Twine &message) {
381 assert(hnode &&
"HNode must not be NULL");
385void Input::reportWarning(
Node *node,
const Twine &message) {
389void Input::reportWarning(
const SMRange &range,
const Twine &message) {
393void Input::releaseHNodeBuffers() {
394 EmptyHNodeAllocator.DestroyAll();
395 ScalarHNodeAllocator.DestroyAll();
396 SequenceHNodeAllocator.DestroyAll();
397 MapHNodeAllocator.DestroyAll();
400Input::HNode *Input::createHNodes(
Node *
N) {
401 SmallString<128> StringStorage;
402 switch (
N->getType()) {
405 StringRef KeyStr = SN->
getValue(StringStorage);
406 if (!StringStorage.
empty()) {
408 KeyStr = StringStorage.
str().
copy(StringAllocator);
410 return new (ScalarHNodeAllocator.Allocate()) ScalarHNode(
N, KeyStr);
414 StringRef ValueCopy = BSN->
getValue().
copy(StringAllocator);
415 return new (ScalarHNodeAllocator.Allocate()) ScalarHNode(
N, ValueCopy);
419 auto SQHNode =
new (SequenceHNodeAllocator.Allocate()) SequenceHNode(
N);
420 for (Node &SN : *SQ) {
421 auto Entry = createHNodes(&SN);
424 SQHNode->Entries.push_back(Entry);
430 auto mapHNode =
new (MapHNodeAllocator.Allocate()) MapHNode(
N);
431 for (KeyValueNode &KVN : *
Map) {
432 Node *KeyNode = KVN.getKey();
437 setError(KeyNode,
"Map key must be a scalar");
439 setError(KeyNode,
"Map value must not be empty");
442 StringStorage.
clear();
443 StringRef KeyStr =
Key->getValue(StringStorage);
444 if (!StringStorage.
empty()) {
446 KeyStr = StringStorage.
str().
copy(StringAllocator);
448 if (mapHNode->Mapping.count(KeyStr))
452 setError(KeyNode, Twine(
"duplicated mapping key '") + KeyStr +
"'");
453 auto ValueHNode = createHNodes(
Value);
456 mapHNode->Mapping[KeyStr] =
457 std::make_pair(std::move(ValueHNode), KeyNode->getSourceRange());
459 return std::move(mapHNode);
462 return new (EmptyHNodeAllocator.Allocate()) EmptyHNode(
N);
464 setError(
N,
"unknown node kind");
469void Input::setError(
const Twine &Message) {
470 setError(CurrentNode, Message);
484 :
IO(context), Out(yout), WrapColumn(WrapColumn) {}
493 StateStack.push_back(inMapFirstKey);
494 PaddingBeforeContainer = Padding;
503 bool SequenceElement =
false;
504 if (StateStack.size() > 1) {
505 auto &E = StateStack[StateStack.size() - 2];
506 SequenceElement = inSeqAnyElement(E) || inFlowSeqAnyElement(E);
508 if (SequenceElement && StateStack.back() == inMapFirstKey) {
514 if (SequenceElement) {
517 if (StateStack.back() == inMapFirstKey) {
518 StateStack.pop_back();
519 StateStack.push_back(inMapOtherKey);
531 if (StateStack.back() == inMapFirstKey) {
532 Padding = PaddingBeforeContainer;
537 StateStack.pop_back();
545 bool &UseDefault,
void *&SaveInfo) {
548 if (
Required || !SameAsDefault || WriteDefaultValues) {
549 auto State = StateStack.back();
550 if (State == inFlowMapFirstKey || State == inFlowMapOtherKey) {
562 if (StateStack.back() == inMapFirstKey) {
563 StateStack.pop_back();
564 StateStack.push_back(inMapOtherKey);
565 }
else if (StateStack.back() == inFlowMapFirstKey) {
566 StateStack.pop_back();
567 StateStack.push_back(inFlowMapOtherKey);
572 StateStack.push_back(inFlowMapFirstKey);
574 ColumnAtMapFlowStart = Column;
579 StateStack.pop_back();
580 outputUpToEndOfLine(
" }");
584 outputUpToEndOfLine(
"---");
589 outputUpToEndOfLine(
"\n---");
601 StateStack.push_back(inSeqFirstElement);
602 PaddingBeforeContainer = Padding;
609 if (StateStack.back() == inSeqFirstElement) {
610 Padding = PaddingBeforeContainer;
615 StateStack.pop_back();
624 if (StateStack.back() == inSeqFirstElement) {
625 StateStack.pop_back();
626 StateStack.push_back(inSeqOtherElement);
627 }
else if (StateStack.back() == inFlowSeqFirstElement) {
628 StateStack.pop_back();
629 StateStack.push_back(inFlowSeqOtherElement);
634 StateStack.push_back(inFlowSeqFirstElement);
636 ColumnAtFlowStart = Column;
638 NeedFlowSequenceComma =
false;
643 StateStack.pop_back();
644 outputUpToEndOfLine(
" ]");
648 if (NeedFlowSequenceComma)
650 if (WrapColumn && Column > WrapColumn) {
652 for (
int i = 0; i < ColumnAtFlowStart; ++i)
654 Column = ColumnAtFlowStart;
662 NeedFlowSequenceComma =
true;
666 EnumerationMatchFound =
false;
670 if (Match && !EnumerationMatchFound) {
672 outputUpToEndOfLine(Str);
673 EnumerationMatchFound =
true;
679 if (EnumerationMatchFound)
681 EnumerationMatchFound =
true;
686 if (!EnumerationMatchFound)
693 NeedBitValueComma =
false;
700 if (NeedBitValueComma)
703 NeedBitValueComma =
true;
709 outputUpToEndOfLine(
" ]");
717 outputUpToEndOfLine(
"''");
720 output(S, MustQuote);
721 outputUpToEndOfLine(
"");
725 if (!StateStack.empty())
729 unsigned Indent = StateStack.empty() ? 1 : StateStack.size();
732 for (
line_iterator Lines(*Buffer,
false); !Lines.is_at_end(); ++Lines) {
734 for (
unsigned I = 0;
I < Indent; ++
I) {
739 outputUpToEndOfLine(
"");
761 if (StateStack.size() < 2)
763 if (StateStack.back() != inMapFirstKey)
765 return !inSeqAnyElement(StateStack[StateStack.size() - 2]);
796 unsigned End = S.
size();
803 output(StringRef(&
Base[i], j - i));
804 output(StringLiteral(
"''"));
809 output(StringRef(&
Base[i], j - i));
813void Output::outputUpToEndOfLine(StringRef s) {
815 if (StateStack.empty() || (!inFlowSeqAnyElement(StateStack.back()) &&
816 !inFlowMapAnyKey(StateStack.back())))
820void Output::outputNewLine() {
829void Output::newLineCheck(
bool EmptySequence) {
830 if (Padding !=
"\n") {
838 if (StateStack.size() == 0 || EmptySequence)
841 unsigned Indent = StateStack.size() - 1;
842 bool PossiblyNestedSeq =
false;
843 auto I = StateStack.rbegin(),
E = StateStack.rend();
845 if (inSeqAnyElement(*
I)) {
846 PossiblyNestedSeq =
true;
848 }
else if (*
I == inMapFirstKey || *
I == inFlowMapFirstKey ||
849 inFlowSeqAnyElement(*
I)) {
850 PossiblyNestedSeq =
true;
854 unsigned OutputDashCount = 0;
855 if (PossiblyNestedSeq) {
860 if (!inSeqAnyElement(*
I))
866 if (*
I++ != inSeqFirstElement)
871 for (
unsigned I = OutputDashCount;
I < Indent; ++
I)
874 for (
unsigned I = 0;
I < OutputDashCount; ++
I)
878void Output::paddedKey(StringRef key) {
888void Output::flowKey(StringRef
Key) {
889 if (StateStack.back() == inFlowMapOtherKey)
891 if (WrapColumn && Column > WrapColumn) {
893 for (
int I = 0;
I < ColumnAtMapFlowStart; ++
I)
895 Column = ColumnAtMapFlowStart;
904bool Output::inSeqAnyElement(InState State) {
905 return State == inSeqFirstElement || State == inSeqOtherElement;
908bool Output::inFlowSeqAnyElement(InState State) {
909 return State == inFlowSeqFirstElement || State == inFlowSeqOtherElement;
912bool Output::inMapAnyKey(InState State) {
913 return State == inMapFirstKey || State == inMapOtherKey;
916bool Output::inFlowMapAnyKey(InState State) {
917 return State == inFlowMapFirstKey || State == inFlowMapOtherKey;
925 Out << (Val ?
"true" :
"false");
933 return "invalid boolean";
966 unsigned long long n;
968 return "invalid number";
970 return "out of range number";
982 unsigned long long n;
984 return "invalid number";
986 return "out of range number";
998 unsigned long long n;
1000 return "invalid number";
1001 if (n > 0xFFFFFFFFUL)
1002 return "out of range number";
1014 unsigned long long N;
1016 return "invalid number";
1030 return "invalid number";
1031 if ((
N > 127) || (
N < -128))
1032 return "out of range number";
1045 return "invalid number";
1046 if ((
N > INT16_MAX) || (
N < INT16_MIN))
1047 return "out of range number";
1060 return "invalid number";
1061 if ((
N > INT32_MAX) || (
N < INT32_MIN))
1062 return "out of range number";
1075 return "invalid number";
1081 Out <<
format(
"%g", Val);
1087 return "invalid floating point number";
1091 Out <<
format(
"%g", Val);
1097 return "invalid floating point number";
1101 Out <<
format(
"0x%" PRIX8, (uint8_t)Val);
1105 unsigned long long n;
1107 return "invalid hex8 number";
1109 return "out of range hex8 number";
1115 Out <<
format(
"0x%" PRIX16, (uint16_t)Val);
1119 unsigned long long n;
1121 return "invalid hex16 number";
1123 return "out of range hex16 number";
1129 Out <<
format(
"0x%" PRIX32, (uint32_t)Val);
1133 unsigned long long n;
1135 return "invalid hex32 number";
1136 if (n > 0xFFFFFFFFUL)
1137 return "out of range hex32 number";
1143 Out <<
format(
"0x%" PRIX64, (uint64_t)Val);
1147 unsigned long long Num;
1149 return "invalid hex64 number";
1155 llvm::raw_ostream &Out) {
1160 VersionTuple &Val) {
1162 return "invalid version format";
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the SmallString class.
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
Defines the llvm::VersionTuple class, which represents a version in the form major[....
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
StringRef str() const
Explicit conversion to StringRef.
void(*)(const SMDiagnostic &, void *Context) DiagHandlerTy
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef copy(Allocator &A) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A Use represents the edge between a Value definition and its users.
LLVM_ABI bool tryParse(StringRef string)
Try to parse the given string as a version number.
LLVM_ABI std::string getAsString() const
Retrieve a string representation of the version number.
A forward iterator which reads text lines from a buffer.
This class implements an extremely fast bulk output stream that can only output to a stream.
StringRef getValue() const
Gets the value of this node as a StringRef.
virtual bool canElideEmptySequence()=0
virtual NodeKind getNodeKind()=0
virtual void endSequence()=0
virtual void endEnumScalar()=0
virtual bool outputting() const =0
virtual unsigned beginFlowSequence()=0
virtual void endFlowSequence()=0
virtual void beginMapping()=0
virtual void setAllowUnknownKeys(bool Allow)
virtual void endMapping()=0
virtual unsigned beginSequence()=0
virtual void beginEnumScalar()=0
void * getContext() const
virtual void endFlowMapping()=0
virtual void beginFlowMapping()=0
virtual bool matchEnumFallback()=0
virtual void endBitSetScalar()=0
virtual std::vector< StringRef > keys()=0
Abstract base class for all Nodes.
std::string getVerbatimTag() const
Get the verbatium tag for a given Node.
unsigned beginFlowSequence() override
bool bitSetMatch(const char *, bool) override
std::vector< StringRef > keys() override
Output(raw_ostream &, void *Ctxt=nullptr, int WrapColumn=70)
void setError(const Twine &message) override
void scalarString(StringRef &, QuotingType) override
void endBitSetScalar() override
void beginFlowMapping() override
void endFlowMapping() override
void endFlowSequence() override
void postflightElement(void *) override
void endEnumScalar() override
void blockScalarString(StringRef &) override
bool preflightDocument(unsigned)
bool canElideEmptySequence() override
void beginMapping() override
bool preflightKey(const char *key, bool, bool, bool &, void *&) override
void postflightFlowElement(void *) override
void scalarTag(std::string &) override
bool beginBitSetScalar(bool &) override
bool mapTag(StringRef, bool) override
bool preflightElement(unsigned, void *&) override
bool matchEnumFallback() override
void beginEnumScalar() override
void endSequence() override
bool outputting() const override
unsigned beginSequence() override
NodeKind getNodeKind() override
bool matchEnumScalar(const char *, bool) override
void endMapping() override
std::error_code error() override
void postflightKey(void *) override
void postflightDocument()
bool preflightFlowElement(unsigned, void *&) override
StringRef getValue(SmallVectorImpl< char > &Storage) const
Gets the value of this node as a StringRef.
This class represents a YAML stream potentially containing multiple documents.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
NodeAddr< NodeBase * > Node
QuotingType
Describe which type of quotes should be used when quoting is necessary.
LLVM_ABI std::optional< bool > parseBool(StringRef S)
Parse S as a bool according to https://yaml.org/type/bool.html.
QuotingType needsQuotes(StringRef S, bool ForcePreserveAsString=true)
LLVM_ABI std::string escape(StringRef Input, bool EscapePrintable=true)
Escape Input for a double quoted scalar; if EscapePrintable is true, all UTF8 sequences will be escap...
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
LLVM_ABI bool getAsSignedInteger(StringRef Str, unsigned Radix, long long &Result)
std::error_code make_error_code(BitcodeError E)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool to_float(const Twine &T, float &Num)
auto dyn_cast_or_null(const Y &Val)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
@ Default
The result values are uniform if and only if all operands are uniform.
This class should be specialized by type that requires custom conversion to/from a yaml scalar.