Chromium Code Reviews

Side by Side Diff: include/llvm/Bitcode/NaCl/NaClBitcodeParser.h

Issue 865963002: Allow temporary overrides of error stream in NaClBitcodeParser. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Clean up code. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- NaClBitcodeParser.h -----------------------------------*- C++ -*-===// 1 //===- NaClBitcodeParser.h -----------------------------------*- C++ -*-===//
2 // Low-level bitcode driver to parse PNaCl bitcode files. 2 // Low-level bitcode driver to parse PNaCl bitcode files.
3 // 3 //
4 // The LLVM Compiler Infrastructure 4 // The LLVM Compiler Infrastructure
5 // 5 //
6 // This file is distributed under the University of Illinois Open Source 6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details. 7 // License. See LICENSE.TXT for details.
8 // 8 //
9 //===----------------------------------------------------------------------===// 9 //===----------------------------------------------------------------------===//
10 // 10 //
(...skipping 450 matching lines...)
461 // block with the given block ID, and then call's method 461 // block with the given block ID, and then call's method
462 // ParseThisBlock() to parse the corresponding block. Note: 462 // ParseThisBlock() to parse the corresponding block. Note:
463 // Each derived class should define it's own version of this 463 // Each derived class should define it's own version of this
464 // method, following the pattern below. 464 // method, following the pattern below.
465 virtual bool ParseBlock(unsigned BlockID) { 465 virtual bool ParseBlock(unsigned BlockID) {
466 // Default implementation just builds a parser that does nothing. 466 // Default implementation just builds a parser that does nothing.
467 NaClBitcodeParser Parser(BlockID, this); 467 NaClBitcodeParser Parser(BlockID, this);
468 return Parser.ParseThisBlock(); 468 return Parser.ParseThisBlock();
469 } 469 }
470 470
471 // Changes the error stream to print errors to Stream. Warning: 471 // Changes the stream to print errors to, and returns the old error stream.
472 // Stream must exist till the next call to setErrStream. Otherwise 472 // There are two use cases:
473 // it must exist for the entire lifetime of the bitcode parser. 473 // 1) To change (from the default errs()) inside the constructor of the
474 // Note: This err stream should be set immediately after 474 // derived class. In this context, it will be used for all error
475 // construction. Assigning after nested bitcode parsers have been 475 // messages for the derived class.
476 // built will not work. 476 // 2) Temporarily modify it for a single error message. In this context,
477 void setErrStream(raw_ostream &Stream) { 477 // the method Error() is overridden in the derived class, and
478 // calls this method twice. Once before calling base method Error(),
479 // and followed by a second call to restore the default error stream.
480 raw_ostream &setErrStream(raw_ostream &Stream) {
481 raw_ostream &OldErrStream = *ErrStream;
478 ErrStream = &Stream; 482 ErrStream = &Stream;
483 return OldErrStream;
479 } 484 }
480 485
481 // Called when error occurs. Message is the error to report. Always 486 // Called when error occurs. Message is the error to report. Always
482 // returns true (the error return value of Parse). 487 // returns true (the error return value of Parse).
483 virtual bool Error(const std::string &Message) { 488 virtual bool Error(const std::string &Message) {
484 *ErrStream << "Error: " << Message << "\n"; 489 *ErrStream << "Error: " << Message << "\n";
485 return true; 490 return true;
486 } 491 }
487 492
488 // Returns the number of bits in this block, including nested blocks. 493 // Returns the number of bits in this block, including nested blocks.
(...skipping 108 matching lines...)
597 602
598 603
599 void operator=(const NaClBitcodeParser &Parser) LLVM_DELETED_FUNCTION; 604 void operator=(const NaClBitcodeParser &Parser) LLVM_DELETED_FUNCTION;
600 NaClBitcodeParser(const NaClBitcodeParser &Parser) LLVM_DELETED_FUNCTION; 605 NaClBitcodeParser(const NaClBitcodeParser &Parser) LLVM_DELETED_FUNCTION;
601 606
602 }; 607 };
603 608
604 } // namespace llvm 609 } // namespace llvm
605 610
606 #endif 611 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine