LLVM: include/llvm/Support/YAMLParser.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37#ifndef LLVM_SUPPORT_YAMLPARSER_H

38#define LLVM_SUPPORT_YAMLPARSER_H

39

45#include

46#include

47#include

48#include

49#include

50#include

51#include

52#include <system_error>

53

54namespace llvm {

55

59

60namespace yaml {

61

67

68

69

71

72

73

74

76

77

78

79

80

82

83

85

86

87

89public:

90

92 std::error_code *EC = nullptr);

93

95 bool ShowColors = true, std::error_code *EC = nullptr);

97

102

107

112

113private:

115

116 std::unique_ptr scanner;

117 std::unique_ptr CurrentDoc;

118};

119

120

122 virtual void anchor();

123

124public:

134

137

138

139

142

144 size_t Alignment = 16) noexcept {

145 return Alloc.Allocate(Size, Alignment);

146 }

147

149 size_t Size) noexcept {

151 }

152

153 void operator delete(void *) noexcept = delete;

154

155

156

158

159

160

162

163

164

165 std::string getVerbatimTag() const;

166

169

170

171 Token &peekNext();

173 Node *parseBlockNode();

175 void setError(const Twine &Message, Token &Location) const;

177

179

180 unsigned int getType() const { return TypeID; }

181

182protected:

183 std::unique_ptr &Doc;

185

187

188private:

189 unsigned int TypeID;

191

193};

194

195

196

197

198

200 void anchor() override;

201

202public:

205

207};

208

209

210

211

212

213

215 void anchor() override;

216

217public:

225

226

227

228

230

231

232

233

234

235

237

241

242private:

244

247

250

253};

254

255

256

257

258

259

260

261

263 void anchor() override;

264

265public:

273

274

276

280

281private:

283};

284

285

286

287

288

289

290

291

293 void anchor() override;

294

295public:

298

299

300

301

302

303

304 Node *getKey();

305

306

307

308

309

310

311 Node *getValue();

312

315 Key->skip();

317 Val->skip();

318 }

319 }

320

324

325private:

328};

329

330

331

332

333

334

336public:

342

345

347 assert(Base && Base->CurrentEntry && "Attempted to access end iterator!");

348 return Base->CurrentEntry;

349 }

350

352 assert(Base && Base->CurrentEntry &&

353 "Attempted to dereference end iterator!");

354 return *Base->CurrentEntry;

355 }

356

357 operator ValueT *() const {

358 assert(Base && Base->CurrentEntry && "Attempted to access end iterator!");

359 return Base->CurrentEntry;

360 }

361

362

363

364

365

366

367

368

370 if (Base && (Base == Other.Base)) {

371 assert((Base->CurrentEntry == Other.Base->CurrentEntry)

372 && "Equal Bases expected to point to equal Entries");

373 }

374

375 return Base == Other.Base;

376 }

377

379 return !(Base == Other.Base);

380 }

381

383 assert(Base && "Attempted to advance iterator past end!");

384 Base->increment();

385

386 if (!Base->CurrentEntry)

387 Base = nullptr;

388 return *this;

389 }

390

391private:

392 BaseT *Base = nullptr;

393};

394

395

396template

397typename CollectionType::iterator begin(CollectionType &C) {

398 assert(C.IsAtBeginning && "You may only iterate over a collection once!");

399 C.IsAtBeginning = false;

400 typename CollectionType::iterator ret(&C);

401 ++ret;

402 return ret;

403}

404

405template void skip(CollectionType &C) {

406

407 assert((C.IsAtBeginning || C.IsAtEnd) && "Cannot skip mid parse!");

408 if (C.IsAtBeginning)

409 for (typename CollectionType::iterator i = begin(C), e = C.end(); i != e;

410 ++i)

411 i->skip();

412}

413

414

415

416

417

418

419

420

422 void anchor() override;

423

424public:

430

434

436

438

439 template friend typename T::iterator yaml::begin(T &);

441

443

445

447

451

452private:

453 MappingType Type;

454 bool IsAtBeginning = true;

455 bool IsAtEnd = false;

457

458 void increment();

459};

460

461

462

463

464

465

466

467

468

470 void anchor() override;

471

472public:

476

477

478

479

480

481

482

484 };

485

489

491

493

494 template friend typename T::iterator yaml::begin(T &);

496

498

500

502

504

508

509private:

510 SequenceType SeqType;

511 bool IsAtBeginning = true;

512 bool IsAtEnd = false;

513 bool WasPreviousTokenFlowEntry = true;

514 Node *CurrentEntry = nullptr;

515};

516

517

518

519

520

522 void anchor() override;

523

524public:

527

529

531

532private:

534};

535

536

537

539public:

541

542

544

545

546

548

549

551 if (Root)

552 return Root;

554 }

555

556 const std::map<StringRef, StringRef> &getTagMap() const { return TagMap; }

557

558private:

561

562

564

565

566

568

569

570

572

573

574 std::map<StringRef, StringRef> TagMap;

575

576 Token &peekNext();

578 void setError(const Twine &Message, Token &Location) const;

579 bool failed() const;

580

581

582 bool parseDirectives();

583

584

585 void parseYAMLDirective();

586

587

588 void parseTAGDirective();

589

590

591 bool expectToken(int TK);

592};

593

594

596public:

599

601 if (isAtEnd() || Other.isAtEnd())

602 return isAtEnd() && Other.isAtEnd();

603

604 return Doc == Other.Doc;

605 }

607 return !(*this == Other);

608 }

609

611 assert(Doc && "incrementing iterator past the end.");

612 if (!(*Doc)->skip()) {

613 Doc->reset(nullptr);

614 } else {

615 Stream &S = (*Doc)->stream;

617 }

618 return *this;

619 }

620

622

623 std::unique_ptr &operator->() { return *Doc; }

624

625private:

626 bool isAtEnd() const { return !Doc || !*Doc; }

627

628 std::unique_ptr *Doc = nullptr;

629};

630

631}

632

633}

634

635#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file defines the BumpPtrAllocator interface.

static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))

Represents a location in source code.

static SMLoc getFromPointer(const char *Ptr)

Represents a range in source code.

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.

StringRef - Represent a constant reference to a string, i.e.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

The instances of the Type class are immutable: once they are created, they are never changed.

LLVM Value Representation.

This class implements an extremely fast bulk output stream that can only output to a stream.

AliasNode(std::unique_ptr< Document > &D, StringRef Val)

Definition YAMLParser.h:525

static bool classof(const Node *N)

Definition YAMLParser.h:530

StringRef getName() const

Definition YAMLParser.h:528

static bool classof(const Node *N)

Definition YAMLParser.h:277

BlockScalarNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, StringRef Value, StringRef RawVal)

Definition YAMLParser.h:266

StringRef getValue() const

Gets the value of this node as a StringRef.

Definition YAMLParser.h:275

A YAML Stream is a sequence of Documents.

Definition YAMLParser.h:538

LLVM_ABI Node * parseBlockNode()

Root for parsing a node. Returns a single node.

const std::map< StringRef, StringRef > & getTagMap() const

Definition YAMLParser.h:556

LLVM_ABI bool skip()

Finish parsing the current document and return true if there are more.

Node * getRoot()

Parse and return the root level node.

Definition YAMLParser.h:550

friend class Node

Definition YAMLParser.h:559

friend class document_iterator

Definition YAMLParser.h:560

LLVM_ABI Document(Stream &ParentStream)

The Input class is used to parse a yaml document into in-memory structs and vectors.

A key and value pair.

Definition YAMLParser.h:292

Node * getValue()

Parse and return the value.

void skip() override

Definition YAMLParser.h:313

static bool classof(const Node *N)

Definition YAMLParser.h:321

Node * getKey()

Parse and return the key.

KeyValueNode(std::unique_ptr< Document > &D)

Definition YAMLParser.h:296

Represents a YAML map created from either a block map for a flow map.

Definition YAMLParser.h:421

MappingType

Definition YAMLParser.h:425

@ MT_Block

Definition YAMLParser.h:426

@ MT_Flow

Definition YAMLParser.h:427

@ MT_Inline

An inline mapping node is used for "[key: value]".

Definition YAMLParser.h:428

static bool classof(const Node *N)

Definition YAMLParser.h:448

basic_collection_iterator< MappingNode, KeyValueNode > iterator

Definition YAMLParser.h:437

iterator begin()

Definition YAMLParser.h:442

MappingNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, MappingType MT)

Definition YAMLParser.h:431

iterator end()

Definition YAMLParser.h:444

void skip() override

Definition YAMLParser.h:446

Abstract base class for all Nodes.

Definition YAMLParser.h:121

StringRef getRawTag() const

Get the tag as it was written in the document.

Definition YAMLParser.h:161

unsigned int getType() const

Definition YAMLParser.h:180

std::unique_ptr< Document > & Doc

Definition YAMLParser.h:183

Node(const Node &)=delete

StringRef getAnchor() const

Get the value of the anchor attached to this node.

Definition YAMLParser.h:157

SMRange SourceRange

Definition YAMLParser.h:184

void setSourceRange(SMRange SR)

Definition YAMLParser.h:168

NodeKind

Definition YAMLParser.h:125

@ NK_Mapping

Definition YAMLParser.h:130

@ NK_Null

Definition YAMLParser.h:126

@ NK_BlockScalar

Definition YAMLParser.h:128

@ NK_Scalar

Definition YAMLParser.h:127

@ NK_Sequence

Definition YAMLParser.h:131

@ NK_KeyValue

Definition YAMLParser.h:129

@ NK_Alias

Definition YAMLParser.h:132

Node(unsigned int Type, std::unique_ptr< Document > &, StringRef Anchor, StringRef Tag)

virtual void skip()

Definition YAMLParser.h:178

SMRange getSourceRange() const

Definition YAMLParser.h:167

void operator=(const Node &)=delete

NullNode(std::unique_ptr< Document > &D)

Definition YAMLParser.h:203

static bool classof(const Node *N)

Definition YAMLParser.h:206

static bool classof(const Node *N)

Definition YAMLParser.h:238

ScalarNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, StringRef Val)

Definition YAMLParser.h:218

StringRef getRawValue() const

Definition YAMLParser.h:229

Scans YAML tokens from a MemoryBuffer.

Represents a YAML sequence created from either a block sequence for a flow sequence.

Definition YAMLParser.h:469

static bool classof(const Node *N)

Definition YAMLParser.h:505

iterator begin()

Definition YAMLParser.h:499

iterator end()

Definition YAMLParser.h:501

SequenceType

Definition YAMLParser.h:473

@ ST_Indentless

Definition YAMLParser.h:483

@ ST_Block

Definition YAMLParser.h:474

@ ST_Flow

Definition YAMLParser.h:475

void skip() override

Definition YAMLParser.h:503

SequenceNode(std::unique_ptr< Document > &D, StringRef Anchor, StringRef Tag, SequenceType ST)

Definition YAMLParser.h:486

basic_collection_iterator< SequenceNode, Node > iterator

Definition YAMLParser.h:492

This class represents a YAML stream potentially containing multiple documents.

Definition YAMLParser.h:88

bool validate()

Definition YAMLParser.h:103

LLVM_ABI document_iterator end()

LLVM_ABI document_iterator begin()

LLVM_ABI Stream(StringRef Input, SourceMgr &, bool ShowColors=true, std::error_code *EC=nullptr)

This keeps a reference to the string referenced by Input.

friend class Document

Definition YAMLParser.h:114

LLVM_ABI void printError(Node *N, const Twine &Msg, SourceMgr::DiagKind Kind=SourceMgr::DK_Error)

This is an iterator abstraction over YAML collections shared by both sequences and maps.

Definition YAMLParser.h:335

bool operator==(const basic_collection_iterator &Other) const

Note on EqualityComparable:

Definition YAMLParser.h:369

basic_collection_iterator & operator++()

Definition YAMLParser.h:382

ValueT value_type

Definition YAMLParser.h:338

ValueT & operator*() const

Definition YAMLParser.h:351

bool operator!=(const basic_collection_iterator &Other) const

Definition YAMLParser.h:378

value_type * pointer

Definition YAMLParser.h:340

std::input_iterator_tag iterator_category

Definition YAMLParser.h:337

std::ptrdiff_t difference_type

Definition YAMLParser.h:339

basic_collection_iterator(BaseT *B)

Definition YAMLParser.h:344

ValueT * operator->() const

Definition YAMLParser.h:346

basic_collection_iterator()=default

value_type & reference

Definition YAMLParser.h:341

Iterator abstraction for Documents over a Stream.

Definition YAMLParser.h:595

document_iterator operator++()

Definition YAMLParser.h:610

document_iterator(std::unique_ptr< Document > &D)

Definition YAMLParser.h:598

bool operator==(const document_iterator &Other) const

Definition YAMLParser.h:600

bool operator!=(const document_iterator &Other) const

Definition YAMLParser.h:606

Document & operator*()

Definition YAMLParser.h:621

document_iterator()=default

std::unique_ptr< Document > & operator->()

Definition YAMLParser.h:623

@ C

The default llvm calling convention, compatible with C.

LLVM_ABI bool dumpTokens(StringRef Input, raw_ostream &)

Dump all the tokens in this stream to OS.

LLVM_ABI std::optional< bool > parseBool(StringRef S)

Parse S as a bool according to https://yaml.org/type/bool.html.

LLVM_ABI bool scanTokens(StringRef Input)

Scans all tokens in input without outputting anything.

void skip(CollectionType &C)

Definition YAMLParser.h:405

CollectionType::iterator begin(CollectionType &C)

Definition YAMLParser.h:397

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.

bool failed(LogicalResult Result)

Utility function that returns true if the provided LogicalResult corresponds to a failure value.

LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key

BumpPtrAllocatorImpl<> BumpPtrAllocator

The standard BumpPtrAllocator which just uses the default template parameters.

Token - A single YAML token.