ROSE  0.11.2.0
processSupport.h
1 #ifndef ROSE_PROCESSSUPPORT_H
2 #define ROSE_PROCESSSUPPORT_H
3 
4 #include <vector>
5 #include <string>
6 #include <cstdio>
7 #include <exception>
8 #include "rosedll.h"
9 #include <Sawyer/Assert.h>
10 
11 // The various definistions of ROSE_ASSERT have been moved in to the
12 // following file. JFR 2020-Jun-05
13 
14 #include "RoseAsserts.h"
15 
16 ROSE_UTIL_API int systemFromVector(const std::vector<std::string>& argv);
17 FILE* popenReadFromVector(const std::vector<std::string>& argv);
18 // Assumes there is only one child process
19 int pcloseFromVector(FILE* f);
20 
21 // Introducing class rose_excepction
22 // this class gets thrown by ROSE_ABORT
23 // it should probably inherit from std::runtime_error
24 // See also Rose::Diagnostics::FailedAssertion
25 class ROSE_UTIL_API rose_exception
26  : public std::exception
27 {
28  public:
29  // call constructor with a reason for that exception
30  explicit rose_exception( const char *what = "" );
31 
32  virtual const char *what() const throw();
33 
34  private:
35  const char *what_;
36 };
37 
38 // DQ (8/22/2009): Added throw since EDG wants to see that the throw options match when ROSE_ABORT is a macro to "abort()" in
39 // "stdlib.h".
40 // throws rose_exception with the reason "abort" void ROSE_ABORT();
41 //
42 #ifdef ROSE_ABORT
43  // If ROSE_ABORT is #defined as abort then avoid redefining ::abort(). If ::abort() is redefined to throw an exception we
44  // run the risk of infinite recursion since the C++ runtime's exception handler might itself call ::abort(). For example,
45  // try adding "ROSE_ABORT()" to the beginning of CxxGrammarMetaProgram and see what happens! [Robb P. Matzke 2015-04-25]
46 #else
47  extern "C" {
48  #ifdef USE_ROSE
49  // DQ (9/3/2009): This is required for EDG to correctly compile
50  // tps (01/22/2010) : gcc43 requires abort(void)
51  inline void ROSE_ABORT() __THROW __attribute__ ((__noreturn__));
52  #elif defined(_MSC_VER)
53  // DQ (11/28/2009): This is a warning in MSVC ("warning C4273: 'abort' : inconsistent dll linkage")
54  inline ROSE_UTIL_API void ROSE_ABORT(void) { throw rose_exception("abort"); }
55  #elif defined(__clang__)
56  inline void ROSE_ABORT(void) { throw rose_exception("abort"); }
57  #else
58  inline void ROSE_ABORT() throw() { throw rose_exception("abort"); }
59  #endif
60  }
61 #endif
62 
63 // throw rose_exception with user defined abort message
64 ROSE_UTIL_API void ROSE_ABORT(const char *message);
65 
67 // Assertion handling
69 namespace Rose {
70 
72 ROSE_UTIL_API void abortOnFailedAssertion(const char*, const char*, const std::string&, const char*, unsigned, const char*);
73 
75 ROSE_UTIL_API void exitOnFailedAssertion(const char*, const char*, const std::string&, const char*, unsigned, const char*);
76 
80 ROSE_UTIL_API void throwOnFailedAssertion(const char*, const char*, const std::string&, const char*, unsigned, const char*);
81 
98 struct FailedAssertion: std::runtime_error {
99  const char *mesg; // a short message, like "assertion failed", "not implemented" etc.
100  const char *expr; // C++ expression that caused the failure (optional)
101  std::string note; // second argument from ASSERT_*() macros, or empty
102  const char *fileName; // name of file where assertion failed
103  unsigned lineNumber; // line number where assertion failed (1-origin)
104  const char *functionName; // function name (perhaps with arg types) where assertion failed
105  FailedAssertion(const char *mesg, const char *expr, const std::string &note,
106  const char *fileName, unsigned lineNumber, const char *functionName)
107  : std::runtime_error(expr?expr:mesg), mesg(mesg), expr(expr), note(note), fileName(fileName),
108  lineNumber(lineNumber), functionName(functionName) {}
109  ~FailedAssertion() throw () {};
110 };
111 
112 } // namespace
113 
114 #endif // ROSE_PROCESSSUPPORT_H
ROSE_UTIL_API void exitOnFailedAssertion(const char *, const char *, const std::string &, const char *, unsigned, const char *)
Exits with non-zero status for a failed assertion.
Main namespace for the ROSE library.
void(* AssertFailureHandler)(const char *mesg, const char *expr, const std::string &note, const char *filename, unsigned linenum, const char *funcname)
Type for user-defined assertion failure handler.
Definition: Assert.h:101
Exception that can be thrown for a failed assertion.
ROSE_UTIL_API void abortOnFailedAssertion(const char *, const char *, const std::string &, const char *, unsigned, const char *)
Aborts for a failed assertion.
ROSE_UTIL_API void throwOnFailedAssertion(const char *, const char *, const std::string &, const char *, unsigned, const char *)
Throws an exception for a failed assertion.
ROSE_UTIL_API void failedAssertionBehavior(Sawyer::Assert::AssertFailureHandler handler)
Property: behavior of failed assertions.