9 #include "conv-config.h"
14 #define XLAT_ERROR(...) \
16 if (xi::num_errors++ == xi::MAX_NUM_ERRORS) { \
19 pretty_msg("error", __VA_ARGS__); \
23 #define XLAT_ERROR_NOCOL(str, line) XLAT_ERROR((str), -1, -1, (line), (line))
25 #define XLAT_NOTE(str, line) pretty_msg("note", (str), -1, -1, (line), (line))
27 extern unsigned int lineno
;
31 extern void pretty_msg(std::string type
, std::string msg
, int first_col
= -1,
32 int last_col
= -1, int first_line
= -1, int last_line
= -1);
34 extern const int MAX_NUM_ERRORS
;
35 extern int num_errors
;
37 extern std::vector
<std::string
> inputBuffer
;
41 extern "C" int isatty(int);
50 unsigned int len
, blklen
;
51 void initTo(const char* _s
);
52 void operator=(const XStr
& str
); //<- don't use this
54 // MAB: following append methods were earlier private. However,
55 // in order to minimize changes to sdag translator, they have been made
56 // public. Once the sdag translator is fully embedded in charmxi,
57 // they will be made private again.
58 void append(const char* _s
);
60 // MAB: the print method is needed for debugging sdag translator.
61 // this too will go away later.
62 void print(int indent
) {
63 for (int i
= 0; i
< indent
; i
++) std::cout
<< " ";
64 std::cout
<< get_string();
66 /// Appends character c to every line
67 void line_append(const char c
);
68 /// pads with spaces and appends character c to every line. Also converts tabs to
70 void line_append_padding(const char c
, int lineWidth
= 80);
71 // Replace all occurences of character "a" in string with character "b"
72 void replace(const char a
, const char b
);
77 XStr(const XStr
& _s
); // Copy constructor
78 ~XStr() { delete[] s
; }
80 char* get_string(void) const { return s
; }
81 const char* get_string_const(void) const { return s
; }
82 // this is to allow XStr to be substituted for CString in
83 // structured dagger translator without a lot of changes
84 char* charstar(void) const { return get_string(); }
85 // This operator allows us to use XStr's interchangably with char *'s:
86 operator char*() { return get_string(); }
87 size_t length() const { return len
; }
88 // Comparison operators
89 int operator==(XStr
& s2
) const { return 0 == strcmp(s
, s2
.s
); }
90 int operator!=(XStr
& s2
) const { return 0 != strcmp(s
, s2
.s
); }
91 int operator==(const char* s2
) const { return 0 == strcmp(s
, s2
); }
92 int operator!=(const char* s2
) const { return 0 != strcmp(s
, s2
); }
94 XStr
operator+(const XStr
& s2
) const {
99 // Insertion operators
100 XStr
& operator<<(const char* _s
) {
104 // XStr& operator << (const string & _s) { append(_s.c_str()); return *this;}
105 XStr
& operator<<(char c
) {
109 XStr
& operator<<(int i
);
110 XStr
& operator<<(const XStr
& x
) {
111 append(x
.get_string_const());
114 XStr
& operator<<(const XStr
* x
) {
115 append(x
->get_string_const());
118 void spew(const char* b
, const char* a1
= 0, const char* a2
= 0, const char* a3
= 0,
119 const char* a4
= 0, const char* a5
= 0);
126 virtual void print(XStr
& str
) = 0;
127 // This lets us cast printables to XStr
133 // These let us stream Printables to XStr.
134 virtual ~Printable() {}
135 friend XStr
& operator<<(XStr
& str
, Printable
& p
) {
139 friend XStr
& operator<<(XStr
& str
, Printable
* p
) {
145 void templateGuardBegin(bool templateOnly
, XStr
& str
);
146 void templateGuardEnd(XStr
& str
);
148 inline void indentBy(XStr
& s
, int num
) {
149 for (int i
= 0; i
< num
; i
++) s
<< " ";
153 XStr
generateTemplateSpec(TVarList
* tspec
, bool printDefault
= true);
163 const char* forWhomStr(forWhom w
);
165 // FIXME: this same function is used for both syntax error messages as well as
166 // e.g. code generation errors
167 void die(const char* why
, int line
= -1);
169 char* fortranify(const char* s
, const char* suff1
= "", const char* suff2
= "",
170 const char* suff3
= "");
172 void templateGuardBegin(bool templateOnly
, XStr
& str
);
173 void templateGuardEnd(XStr
& str
);
175 std::string
addLineNumbers(char* str
, const char* filename
);
176 extern void sanitizeComments(std::string
& code
);
177 extern void sanitizeStrings(std::string
& code
);
178 extern void desanitizeCode(std::string
& code
);
184 extern const char* Proxy
;
185 extern const char* ProxyElement
;
186 extern const char* ProxySection
;
187 extern const char* Message
;
188 extern const char* Index
;
189 extern const char* Python
;
191 } // namespace Prefix