// The filename without the directory and without the '.asy' suffix.
// Note that this assumes name are separated by a forward slash.
string moduleName() const {
size_t start = filename.rfind('/');
if (start == filename.npos)
start = 0;
else
// Step over slash.
++start;
size_t end = filename.rfind(".asy");
if (end != filename.size() - 4)
end = filename.size();
return filename.substr(start, end-start);
}
// Specifies a newline symbol at the character position given.
void newline() {
++lineNum;
}
};
inline bool operator == (const fileinfo& a, const fileinfo& b)
{
return a.line() == b.line() && a.name() == b.name();
}
class position : public gc {
fileinfo *file;
size_t line;
size_t column;
public:
void init(fileinfo *f, Int p) {
file = f;
if (file) {
line = file->line();
column = p;
} else {
line = column = 0;
}
}
// An error is encountered, not in the user's code, but in the way the
// compiler works! This may be augmented in the future with a message
// to contact the compiler writers.
void compiler();
void compiler(position pos);
// An error encountered when running compiled code. This method does
// not stop the executable, but the executable should be stopped
// shortly after calling this method.
void runtime(position pos);
// Errors encountered when compiling making it impossible to run the code.
void error(position pos);
// Indicate potential problems in the code, but the code is still usable.
void warning(position pos);
void warning(position pos, string s);
// Single a fatal error and execute the main process.
void fatal(position pos);
// Print out position in code to aid debugging.
void trace(position pos);
// Sends stuff to out to print.
// NOTE: May later make it do automatic line breaking for long messages.
template<class T>
errorstream& operator << (const T& x) {
flush(out);
out << x;
return *this;
}
// Reporting errors to the stream may be incomplete. This draws the
// appropriate newlines or file excerpts that may be needed at the end.
void sync(bool reportTraceback=false);
// Returns true if no errors have occured that should be reported by the
// return value of the process.
bool processStatus() const {
return !anyStatusErrors;
}
};