summaryrefslogtreecommitdiff
path: root/tools/localize/SourcePos.cpp
diff options
context:
space:
mode:
author Elliott Hughes <enh@google.com> 2012-05-07 17:34:08 -0700
committer Elliott Hughes <enh@google.com> 2012-05-07 17:34:08 -0700
commit436bbd1a6c227148c294117e725e03be75e01ebf (patch)
treec0312cb3d52d2043e993eab54f6093f745e705db /tools/localize/SourcePos.cpp
parent476b03b0c0d5cae4d1b114c6f80858d59ba36cad (diff)
The 'localize' tool is dead.
Change-Id: I6486e50fd1d2f82dd040371a308a2a756beadb64
Diffstat (limited to 'tools/localize/SourcePos.cpp')
-rw-r--r--tools/localize/SourcePos.cpp168
1 files changed, 0 insertions, 168 deletions
diff --git a/tools/localize/SourcePos.cpp b/tools/localize/SourcePos.cpp
deleted file mode 100644
index 184bfe0a649e..000000000000
--- a/tools/localize/SourcePos.cpp
+++ /dev/null
@@ -1,168 +0,0 @@
-#include "SourcePos.h"
-
-#include <stdarg.h>
-#include <cstdio>
-#include <set>
-#include <cstdio>
-
-using namespace std;
-
-const SourcePos GENERATED_POS("<generated>", -1);
-
-// ErrorPos
-// =============================================================================
-struct ErrorPos
-{
- string file;
- int line;
- string error;
-
- ErrorPos();
- ErrorPos(const ErrorPos& that);
- ErrorPos(const string& file, int line, const string& error);
- ~ErrorPos();
- bool operator<(const ErrorPos& rhs) const;
- bool operator==(const ErrorPos& rhs) const;
- ErrorPos& operator=(const ErrorPos& rhs);
-
- void Print(FILE* to) const;
-};
-
-static set<ErrorPos> g_errors;
-
-ErrorPos::ErrorPos()
-{
-}
-
-ErrorPos::ErrorPos(const ErrorPos& that)
- :file(that.file),
- line(that.line),
- error(that.error)
-{
-}
-
-ErrorPos::ErrorPos(const string& f, int l, const string& e)
- :file(f),
- line(l),
- error(e)
-{
-}
-
-ErrorPos::~ErrorPos()
-{
-}
-
-bool
-ErrorPos::operator<(const ErrorPos& rhs) const
-{
- if (this->file < rhs.file) return true;
- if (this->file == rhs.file) {
- if (this->line < rhs.line) return true;
- if (this->line == rhs.line) {
- if (this->error < rhs.error) return true;
- }
- }
- return false;
-}
-
-bool
-ErrorPos::operator==(const ErrorPos& rhs) const
-{
- return this->file == rhs.file
- && this->line == rhs.line
- && this->error == rhs.error;
-}
-
-ErrorPos&
-ErrorPos::operator=(const ErrorPos& rhs)
-{
- this->file = rhs.file;
- this->line = rhs.line;
- this->error = rhs.error;
- return *this;
-}
-
-void
-ErrorPos::Print(FILE* to) const
-{
- if (this->line >= 0) {
- fprintf(to, "%s:%d: %s\n", this->file.c_str(), this->line, this->error.c_str());
- } else {
- fprintf(to, "%s: %s\n", this->file.c_str(), this->error.c_str());
- }
-}
-
-// SourcePos
-// =============================================================================
-SourcePos::SourcePos(const string& f, int l)
- : file(f), line(l)
-{
-}
-
-SourcePos::SourcePos(const SourcePos& that)
- : file(that.file), line(that.line)
-{
-}
-
-SourcePos::SourcePos()
- : file("???", 0)
-{
-}
-
-SourcePos::~SourcePos()
-{
-}
-
-string
-SourcePos::ToString() const
-{
- char buf[1024];
- if (this->line >= 0) {
- snprintf(buf, sizeof(buf)-1, "%s:%d", this->file.c_str(), this->line);
- } else {
- snprintf(buf, sizeof(buf)-1, "%s:", this->file.c_str());
- }
- buf[sizeof(buf)-1] = '\0';
- return string(buf);
-}
-
-int
-SourcePos::Error(const char* fmt, ...) const
-{
- int retval=0;
- char buf[1024];
- va_list ap;
- va_start(ap, fmt);
- retval = vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- char* p = buf + retval - 1;
- while (p > buf && *p == '\n') {
- *p = '\0';
- p--;
- }
- ErrorPos err(this->file, this->line, string(buf));
- if (g_errors.find(err) == g_errors.end()) {
- err.Print(stderr);
- g_errors.insert(err);
- }
- return retval;
-}
-
-bool
-SourcePos::HasErrors()
-{
- return g_errors.size() > 0;
-}
-
-void
-SourcePos::PrintErrors(FILE* to)
-{
- set<ErrorPos>::const_iterator it;
- for (it=g_errors.begin(); it!=g_errors.end(); it++) {
- it->Print(to);
- }
-}
-
-
-
-