exclude PluginsFieldTrialTest.NoPrefLeftBehind from valgrind bot
[chromium-blink-merge.git] / tools / gn / location.cc
blob7a18786e57cb45b73c73710ed4b06abc4268e112
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.
5 #include "tools/gn/location.h"
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "tools/gn/input_file.h"
11 Location::Location()
12 : file_(nullptr),
13 line_number_(-1),
14 char_offset_(-1) {
17 Location::Location(const InputFile* file,
18 int line_number,
19 int char_offset,
20 int byte)
21 : file_(file),
22 line_number_(line_number),
23 char_offset_(char_offset),
24 byte_(byte) {
27 bool Location::operator==(const Location& other) const {
28 return other.file_ == file_ &&
29 other.line_number_ == line_number_ &&
30 other.char_offset_ == char_offset_;
33 bool Location::operator!=(const Location& other) const {
34 return !operator==(other);
37 bool Location::operator<(const Location& other) const {
38 DCHECK(file_ == other.file_);
39 if (line_number_ != other.line_number_)
40 return line_number_ < other.line_number_;
41 return char_offset_ < other.char_offset_;
44 std::string Location::Describe(bool include_char_offset) const {
45 if (!file_)
46 return std::string();
48 std::string ret;
49 if (file_->friendly_name().empty())
50 ret = file_->name().value();
51 else
52 ret = file_->friendly_name();
54 ret += ":";
55 ret += base::IntToString(line_number_);
56 if (include_char_offset) {
57 ret += ":";
58 ret += base::IntToString(char_offset_);
60 return ret;
63 LocationRange::LocationRange() {
66 LocationRange::LocationRange(const Location& begin, const Location& end)
67 : begin_(begin),
68 end_(end) {
69 DCHECK(begin_.file() == end_.file());
72 LocationRange LocationRange::Union(const LocationRange& other) const {
73 DCHECK(begin_.file() == other.begin_.file());
74 return LocationRange(
75 begin_ < other.begin_ ? begin_ : other.begin_,
76 end_ < other.end_ ? other.end_ : end_);