Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: tools/gn/location.h

Issue 21114002: Add initial prototype for the GN meta-buildsystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add owners and readme Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/label_unittest.cc ('k') | tools/gn/ninja_build_writer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/location.h
diff --git a/tools/gn/location.h b/tools/gn/location.h
new file mode 100644
index 0000000000000000000000000000000000000000..20551256e141e723bcd2b345de5f20aa34af8667
--- /dev/null
+++ b/tools/gn/location.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TOOLS_GN_LOCATION_H_
+#define TOOLS_GN_LOCATION_H_
+
+#include <algorithm>
+
+#include "base/logging.h"
+
+class InputFile;
+
+// Represents a place in a source file. Used for error reporting.
+class Location {
+ public:
+ Location()
+ : file_(NULL),
+ line_number_(-1),
+ char_offset_(-1) {
+ }
+ Location(const InputFile* file, int line_number, int char_offset)
+ : file_(file),
+ line_number_(line_number),
+ char_offset_(char_offset) {
+ }
+
+ const InputFile* file() const { return file_; }
+ int line_number() const { return line_number_; }
+ int char_offset() const { return char_offset_; }
+
+ bool operator==(const Location& other) const {
+ return other.file_ == file_ &&
+ other.line_number_ == line_number_ &&
+ other.char_offset_ == char_offset_;
+ }
+
+ bool operator<(const Location& other) const {
+ DCHECK(file_ == other.file_);
+ if (line_number_ != other.line_number_)
+ return line_number_ < other.line_number_;
+ return char_offset_ < other.char_offset_;
+ }
+
+ private:
+ const InputFile* file_; // Null when unset.
+ int line_number_; // -1 when unset.
+ int char_offset_; // -1 when unset.
+};
+
+// Represents a range in a source file. Used for error reporting.
+// The end is exclusive i.e. [begin, end)
+class LocationRange {
+ public:
+ LocationRange() {}
+ LocationRange(const Location& begin, const Location& end)
+ : begin_(begin),
+ end_(end) {
+ DCHECK(begin_.file() == end_.file());
+ }
+
+ const Location& begin() const { return begin_; }
+ const Location& end() const { return end_; }
+
+ LocationRange Union(const LocationRange& other) const {
+ DCHECK(begin_.file() == other.begin_.file());
+ return LocationRange(
+ begin_ < other.begin_ ? begin_ : other.begin_,
+ end_ < other.end_ ? other.end_ : end_);
+ }
+
+ private:
+ Location begin_;
+ Location end_;
+};
+
+#endif // TOOLS_GN_LOCATION_H_
« no previous file with comments | « tools/gn/label_unittest.cc ('k') | tools/gn/ninja_build_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698