10 // =============================================================================
25 ErrorPos(const ErrorPos& that);
26 ErrorPos(const String8& file, int line, const String8& error, Level level);
27 ErrorPos& operator=(const ErrorPos& rhs);
29 void print(FILE* to) const;
32 static vector<ErrorPos> g_errors;
35 :line(-1), level(NOTE)
39 ErrorPos::ErrorPos(const ErrorPos& that)
47 ErrorPos::ErrorPos(const String8& f, int l, const String8& e, Level lev)
56 ErrorPos::operator=(const ErrorPos& rhs)
58 this->file = rhs.file;
59 this->line = rhs.line;
60 this->error = rhs.error;
61 this->level = rhs.level;
66 ErrorPos::print(FILE* to) const
68 const char* type = "";
81 if (!this->file.isEmpty()) {
82 if (this->line >= 0) {
83 fprintf(to, "%s:%d: %s%s\n", this->file.string(), this->line, type, this->error.string());
85 fprintf(to, "%s: %s%s\n", this->file.string(), type, this->error.string());
88 fprintf(to, "%s%s\n", type, this->error.string());
93 // =============================================================================
94 SourcePos::SourcePos(const String8& f, int l)
99 SourcePos::SourcePos(const SourcePos& that)
100 : file(that.file), line(that.line)
104 SourcePos::SourcePos()
105 : file("???", 0), line(-1)
109 SourcePos::~SourcePos()
114 SourcePos::error(const char* fmt, ...) const
118 String8 msg = String8::formatV(fmt, ap);
120 g_errors.push_back(ErrorPos(this->file, this->line, msg, ErrorPos::ERROR));
124 SourcePos::warning(const char* fmt, ...) const
128 String8 msg = String8::formatV(fmt, ap);
130 ErrorPos(this->file, this->line, msg, ErrorPos::WARNING).print(stderr);
134 SourcePos::printf(const char* fmt, ...) const
138 String8 msg = String8::formatV(fmt, ap);
140 ErrorPos(this->file, this->line, msg, ErrorPos::NOTE).print(stderr);
144 SourcePos::operator<(const SourcePos& rhs) const
146 return (file < rhs.file) || (line < rhs.line);
150 SourcePos::hasErrors()
152 return g_errors.size() > 0;
156 SourcePos::printErrors(FILE* to)
158 vector<ErrorPos>::const_iterator it;
159 for (it=g_errors.begin(); it!=g_errors.end(); it++) {