OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/c_include_iterator.h" | 5 #include "tools/gn/c_include_iterator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "tools/gn/input_file.h" | 9 #include "tools/gn/input_file.h" |
10 #include "tools/gn/location.h" | 10 #include "tools/gn/location.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 size_t terminator_index = contents.find(terminating_char, 1); | 98 size_t terminator_index = contents.find(terminating_char, 1); |
99 if (terminator_index == base::StringPiece::npos) | 99 if (terminator_index == base::StringPiece::npos) |
100 return INCLUDE_NONE; | 100 return INCLUDE_NONE; |
101 | 101 |
102 *path = contents.substr(1, terminator_index - 1); | 102 *path = contents.substr(1, terminator_index - 1); |
103 // Note: one based so we do "+ 1". | 103 // Note: one based so we do "+ 1". |
104 *begin_char = static_cast<int>(path->data() - line.data()) + 1; | 104 *begin_char = static_cast<int>(path->data() - line.data()) + 1; |
105 return type; | 105 return type; |
106 } | 106 } |
107 | 107 |
| 108 // Returns true if this line has a "nogncheck" comment associated with it. |
| 109 bool HasNoCheckAnnotation(const base::StringPiece& line) { |
| 110 return line.find("nogncheck") != base::StringPiece::npos; |
| 111 } |
| 112 |
108 } // namespace | 113 } // namespace |
109 | 114 |
110 const int CIncludeIterator::kMaxNonIncludeLines = 10; | 115 const int CIncludeIterator::kMaxNonIncludeLines = 10; |
111 | 116 |
112 CIncludeIterator::CIncludeIterator(const InputFile* input) | 117 CIncludeIterator::CIncludeIterator(const InputFile* input) |
113 : input_file_(input), | 118 : input_file_(input), |
114 file_(input->contents()), | 119 file_(input->contents()), |
115 offset_(0), | 120 offset_(0), |
116 line_number_(0), | 121 line_number_(0), |
117 lines_since_last_include_(0) { | 122 lines_since_last_include_(0) { |
118 } | 123 } |
119 | 124 |
120 CIncludeIterator::~CIncludeIterator() { | 125 CIncludeIterator::~CIncludeIterator() { |
121 } | 126 } |
122 | 127 |
123 bool CIncludeIterator::GetNextIncludeString(base::StringPiece* out, | 128 bool CIncludeIterator::GetNextIncludeString(base::StringPiece* out, |
124 LocationRange* location) { | 129 LocationRange* location) { |
125 base::StringPiece line; | 130 base::StringPiece line; |
126 int cur_line_number = 0; | 131 int cur_line_number = 0; |
127 while (lines_since_last_include_ <= kMaxNonIncludeLines && | 132 while (lines_since_last_include_ <= kMaxNonIncludeLines && |
128 GetNextLine(&line, &cur_line_number)) { | 133 GetNextLine(&line, &cur_line_number)) { |
129 base::StringPiece include_contents; | 134 base::StringPiece include_contents; |
130 int begin_char; | 135 int begin_char; |
131 IncludeType type = ExtractInclude(line, &include_contents, &begin_char); | 136 IncludeType type = ExtractInclude(line, &include_contents, &begin_char); |
132 if (type == INCLUDE_USER) { | 137 if (type == INCLUDE_USER && !HasNoCheckAnnotation(line)) { |
133 // Only count user includes for now. | 138 // Only count user includes for now. |
134 *out = include_contents; | 139 *out = include_contents; |
135 *location = LocationRange( | 140 *location = LocationRange( |
136 Location(input_file_, | 141 Location(input_file_, |
137 cur_line_number, | 142 cur_line_number, |
138 begin_char, | 143 begin_char, |
139 -1 /* TODO(scottmg): Is this important? */), | 144 -1 /* TODO(scottmg): Is this important? */), |
140 Location(input_file_, | 145 Location(input_file_, |
141 cur_line_number, | 146 cur_line_number, |
142 begin_char + static_cast<int>(include_contents.size()), | 147 begin_char + static_cast<int>(include_contents.size()), |
(...skipping 19 matching lines...) Expand all Loading... |
162 line_number_++; | 167 line_number_++; |
163 | 168 |
164 *line = file_.substr(begin, offset_ - begin); | 169 *line = file_.substr(begin, offset_ - begin); |
165 *line_number = line_number_; | 170 *line_number = line_number_; |
166 | 171 |
167 // If we didn't hit EOF, skip past the newline for the next one. | 172 // If we didn't hit EOF, skip past the newline for the next one. |
168 if (offset_ < file_.size()) | 173 if (offset_ < file_.size()) |
169 offset_++; | 174 offset_++; |
170 return true; | 175 return true; |
171 } | 176 } |
OLD | NEW |