1 
2 // -*- mode: C++ -*-
3 //
4 // Copyright (c) 2007, 2008, 2010, 2011 The University of Utah
5 // All rights reserved.
6 //
7 // This file is part of `csmith', a random generator of C programs.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 //   * Redistributions of source code must retain the above copyright notice,
13 //     this list of conditions and the following disclaimer.
14 //
15 //   * Redistributions in binary form must reproduce the above copyright
16 //     notice, this list of conditions and the following disclaimer in the
17 //     documentation and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef ERROR_H
32 #define ERROR_H
33 
34 #include "CommonMacros.h"
35 
36 #define SUCCESS 0
37 #define ERROR -1
38 #define EXCEED_MAX_DEPTH_ERROR -2
39 #define FILTER_ERROR -3
40 #define BACKTRACKING_ERROR -4
41 #define COMPATIBLE_CHECK_ERROR -5
42 #define INVALID_SIMPLE_DELTA_SEQUENCE -6
43 
44 #define ERROR_RETURN() \
45 	if (Error::get_error() != SUCCESS) \
46 		return;\
47 
48 #define ERROR_GUARD(rv) \
49 	if (Error::get_error() != SUCCESS) \
50 		return rv; \
51 
52 #define ERROR_GUARD_AND_DEL1(rv, p) \
53 	if (Error::get_error() != SUCCESS) {\
54 		delete p; \
55 		return rv; \
56 	} \
57 
58 #define ERROR_GUARD_AND_DEL2(rv, p1, p2) \
59 	if (Error::get_error() != SUCCESS) {\
60 		delete p1; \
61 		delete p2; \
62 		return rv; \
63 	} \
64 
65 #define ERROR_GUARD_AND_DEL3(rv, p1, p2, p3) \
66 	if (Error::get_error() != SUCCESS) {\
67 		delete p1; \
68 		delete p2; \
69 		delete p3; \
70 		return rv; \
71 	} \
72 
73 #define ERROR_GUARD_AND_DEL4(rv, p1, p2, p3, p4) \
74 	if (Error::get_error() != SUCCESS) {\
75 		delete p1; \
76 		delete p2; \
77 		delete p3; \
78 		delete p4; \
79 		return rv; \
80 	} \
81 
82 
83 #define PRT_ERROR(msg) \
84 	cout << "error: " << msg << ", errorno: " << Error::get_error() << std::endl; \
85 
86 class Error {
87 public:
get_error()88 	static int get_error() { return Error::r_error_; }
set_error(int error)89 	static void set_error(int error) { Error::r_error_ = error; }
90 private:
91 	Error();
92 	~Error();
93 	static int r_error_;
94 
95 	DISALLOW_COPY_AND_ASSIGN(Error);
96 };
97 
98 #endif // ERROR_H
99