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

Side by Side Diff: tools/gn/c_include_iterator.cc

Issue 588893006: gn: attach comments to parse tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: x64 Created 6 years, 3 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
« no previous file with comments | « no previous file | tools/gn/header_checker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 int cur_line_number = 0; 126 int cur_line_number = 0;
127 while (lines_since_last_include_ <= kMaxNonIncludeLines && 127 while (lines_since_last_include_ <= kMaxNonIncludeLines &&
128 GetNextLine(&line, &cur_line_number)) { 128 GetNextLine(&line, &cur_line_number)) {
129 base::StringPiece include_contents; 129 base::StringPiece include_contents;
130 int begin_char; 130 int begin_char;
131 IncludeType type = ExtractInclude(line, &include_contents, &begin_char); 131 IncludeType type = ExtractInclude(line, &include_contents, &begin_char);
132 if (type == INCLUDE_USER) { 132 if (type == INCLUDE_USER) {
133 // Only count user includes for now. 133 // Only count user includes for now.
134 *out = include_contents; 134 *out = include_contents;
135 *location = LocationRange( 135 *location = LocationRange(
136 Location(input_file_, cur_line_number, begin_char), 136 Location(input_file_,
137 Location(input_file_, cur_line_number, 137 cur_line_number,
138 begin_char + static_cast<int>(include_contents.size()))); 138 begin_char,
139 -1 /* TODO(scottmg): Is this important? */),
140 Location(input_file_,
141 cur_line_number,
142 begin_char + static_cast<int>(include_contents.size()),
143 -1 /* TODO(scottmg): Is this important? */));
139 144
140 lines_since_last_include_ = 0; 145 lines_since_last_include_ = 0;
141 return true; 146 return true;
142 } 147 }
143 148
144 if (ShouldCountTowardNonIncludeLines(line)) 149 if (ShouldCountTowardNonIncludeLines(line))
145 lines_since_last_include_++; 150 lines_since_last_include_++;
146 } 151 }
147 return false; 152 return false;
148 } 153 }
149 154
150 bool CIncludeIterator::GetNextLine(base::StringPiece* line, int* line_number) { 155 bool CIncludeIterator::GetNextLine(base::StringPiece* line, int* line_number) {
151 if (offset_ == file_.size()) 156 if (offset_ == file_.size())
152 return false; 157 return false;
153 158
154 size_t begin = offset_; 159 size_t begin = offset_;
155 while (offset_ < file_.size() && file_[offset_] != '\n') 160 while (offset_ < file_.size() && file_[offset_] != '\n')
156 offset_++; 161 offset_++;
157 line_number_++; 162 line_number_++;
158 163
159 *line = file_.substr(begin, offset_ - begin); 164 *line = file_.substr(begin, offset_ - begin);
160 *line_number = line_number_; 165 *line_number = line_number_;
161 166
162 // If we didn't hit EOF, skip past the newline for the next one. 167 // If we didn't hit EOF, skip past the newline for the next one.
163 if (offset_ < file_.size()) 168 if (offset_ < file_.size())
164 offset_++; 169 offset_++;
165 return true; 170 return true;
166 } 171 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/header_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698