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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/label_unittest.cc ('k') | tools/gn/ninja_build_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef TOOLS_GN_LOCATION_H_
6 #define TOOLS_GN_LOCATION_H_
7
8 #include <algorithm>
9
10 #include "base/logging.h"
11
12 class InputFile;
13
14 // Represents a place in a source file. Used for error reporting.
15 class Location {
16 public:
17 Location()
18 : file_(NULL),
19 line_number_(-1),
20 char_offset_(-1) {
21 }
22 Location(const InputFile* file, int line_number, int char_offset)
23 : file_(file),
24 line_number_(line_number),
25 char_offset_(char_offset) {
26 }
27
28 const InputFile* file() const { return file_; }
29 int line_number() const { return line_number_; }
30 int char_offset() const { return char_offset_; }
31
32 bool operator==(const Location& other) const {
33 return other.file_ == file_ &&
34 other.line_number_ == line_number_ &&
35 other.char_offset_ == char_offset_;
36 }
37
38 bool operator<(const Location& other) const {
39 DCHECK(file_ == other.file_);
40 if (line_number_ != other.line_number_)
41 return line_number_ < other.line_number_;
42 return char_offset_ < other.char_offset_;
43 }
44
45 private:
46 const InputFile* file_; // Null when unset.
47 int line_number_; // -1 when unset.
48 int char_offset_; // -1 when unset.
49 };
50
51 // Represents a range in a source file. Used for error reporting.
52 // The end is exclusive i.e. [begin, end)
53 class LocationRange {
54 public:
55 LocationRange() {}
56 LocationRange(const Location& begin, const Location& end)
57 : begin_(begin),
58 end_(end) {
59 DCHECK(begin_.file() == end_.file());
60 }
61
62 const Location& begin() const { return begin_; }
63 const Location& end() const { return end_; }
64
65 LocationRange Union(const LocationRange& other) const {
66 DCHECK(begin_.file() == other.begin_.file());
67 return LocationRange(
68 begin_ < other.begin_ ? begin_ : other.begin_,
69 end_ < other.end_ ? other.end_ : end_);
70 }
71
72 private:
73 Location begin_;
74 Location end_;
75 };
76
77 #endif // TOOLS_GN_LOCATION_H_
OLDNEW
« 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