llvm.org GIT mirror llvm / 148f440
Modify the SlowOperationInformer interface to not throw exceptions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29028 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 14 years ago
3 changed file(s) with 16 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
1616 // appears on the screen (ie, the cursor should be at the start of the line).
1717 //
1818 // If the user presses CTRL-C during the operation, the next invocation of the
19 // progress method with throw an std::string object indicating that the
20 // operation was cancelled. As such, client code must be exception safe around
21 // the progress method.
19 // progress method return true indicating that the operation was cancelled.
2220 //
2321 // Because SlowOperationInformers fiddle around with signals, they cannot be
2422 // nested, and interact poorly with threads. The SIGALRM handler is set back to
4543 SlowOperationInformer(const std::string &Name);
4644 ~SlowOperationInformer();
4745
48 /// progress - Clients should periodically call this method when they are in
49 /// an exception-safe state. The Amount variable should indicate how far
46 /// progress - Clients should periodically call this method when they can
47 /// handle cancellation. The Amount variable should indicate how far
5048 /// along the operation is, given in 1/10ths of a percent (in other words,
51 /// Amount should range from 0 to 1000).
52 void progress(unsigned Amount);
49 /// Amount should range from 0 to 1000). If the user cancels the operation,
50 /// this returns true, false otherwise.
51 bool progress(unsigned Amount);
5352
5453 /// progress - Same as the method above, but this performs the division for
5554 /// you, and helps you avoid overflow if you are dealing with largish
5655 /// numbers.
57 void progress(unsigned Current, unsigned Maximum) {
56 bool progress(unsigned Current, unsigned Maximum) {
5857 assert(Maximum != 0 &&
5958 "Shouldn't be doing work if there is nothing to do!");
60 progress(Current*uint64_t(1000UL)/Maximum);
59 return progress(Current*uint64_t(1000UL)/Maximum);
6160 }
6261 };
6362 } // end namespace llvm
279279 // mapping.
280280 for (unsigned i = 0, e = TranslationUnits.size(); i != e; ++i) {
281281 getSourceFile(TranslationUnits[i]);
282 SOI.progress(i+1, e);
282 if (SOI.progress(i+1, e))
283 throw "While building source files index, operation cancelled.";
283284 }
284285
285286 // Ok, if we got this far, then we indexed the whole program.
360361 // Loop over all of the functions found, building the SourceFunctions mapping.
361362 for (unsigned i = 0, e = Functions.size(); i != e; ++i) {
362363 getFunction(Functions[i]);
363 SOI.progress(i+1, e);
364 if (SOI.progress(i+1, e))
365 throw "While functions index, operation cancelled.";
364366 }
365367
366368 // Ok, if we got this far, then we indexed the whole program.
3636 /// an exception-safe state. The Amount variable should indicate how far
3737 /// along the operation is, given in 1/10ths of a percent (in other words,
3838 /// Amount should range from 0 to 1000).
39 void SlowOperationInformer::progress(unsigned Amount) {
39 bool SlowOperationInformer::progress(unsigned Amount) {
4040 int status = sys::AlarmStatus();
4141 if (status == -1) {
4242 std::cout << "\n";
4343 LastPrintAmount = 0;
44 throw "While " + OperationName + ", operation cancelled.";
44 return true;
4545 }
4646
4747 // If we haven't spent enough time in this operation to warrant displaying the
4848 // progress bar, don't do so yet.
4949 if (status == 0)
50 return;
50 return false;
5151
5252 // Delete whatever we printed last time.
5353 std::string ToPrint = std::string(LastPrintAmount, '\b');
6161
6262 LastPrintAmount = OS.str().size();
6363 std::cout << ToPrint+OS.str() << std::flush;
64 return false;
6465 }