OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2211 int index) { | 2211 int index) { |
2212 return HasSpan('\0', '\0', descriptor_proto, field_name, index); | 2212 return HasSpan('\0', '\0', descriptor_proto, field_name, index); |
2213 } | 2213 } |
2214 | 2214 |
2215 bool HasSpanWithComment( | 2215 bool HasSpanWithComment( |
2216 char start_marker, char end_marker, const Message& descriptor_proto, | 2216 char start_marker, char end_marker, const Message& descriptor_proto, |
2217 const FieldDescriptor* field, int index, | 2217 const FieldDescriptor* field, int index, |
2218 const char* expected_leading_comments, | 2218 const char* expected_leading_comments, |
2219 const char* expected_trailing_comments, | 2219 const char* expected_trailing_comments, |
2220 const char* expected_leading_detached_comments) { | 2220 const char* expected_leading_detached_comments) { |
2221 std::pair<SpanMap::iterator, SpanMap::iterator> range = | 2221 pair<SpanMap::iterator, SpanMap::iterator> range = |
2222 spans_.equal_range(SpanKey(descriptor_proto, field, index)); | 2222 spans_.equal_range(SpanKey(descriptor_proto, field, index)); |
2223 | 2223 |
2224 if (start_marker == '\0') { | 2224 if (start_marker == '\0') { |
2225 if (range.first == range.second) { | 2225 if (range.first == range.second) { |
2226 return false; | 2226 return false; |
2227 } else { | 2227 } else { |
2228 spans_.erase(range.first); | 2228 spans_.erase(range.first); |
2229 return true; | 2229 return true; |
2230 } | 2230 } |
2231 } else { | 2231 } else { |
2232 std::pair<int, int> start_pos = FindOrDie(markers_, start_marker); | 2232 pair<int, int> start_pos = FindOrDie(markers_, start_marker); |
2233 std::pair<int, int> end_pos = FindOrDie(markers_, end_marker); | 2233 pair<int, int> end_pos = FindOrDie(markers_, end_marker); |
2234 | 2234 |
2235 RepeatedField<int> expected_span; | 2235 RepeatedField<int> expected_span; |
2236 expected_span.Add(start_pos.first); | 2236 expected_span.Add(start_pos.first); |
2237 expected_span.Add(start_pos.second); | 2237 expected_span.Add(start_pos.second); |
2238 if (end_pos.first != start_pos.first) { | 2238 if (end_pos.first != start_pos.first) { |
2239 expected_span.Add(end_pos.first); | 2239 expected_span.Add(end_pos.first); |
2240 } | 2240 } |
2241 expected_span.Add(end_pos.second); | 2241 expected_span.Add(end_pos.second); |
2242 | 2242 |
2243 for (SpanMap::iterator iter = range.first; iter != range.second; ++iter) { | 2243 for (SpanMap::iterator iter = range.first; iter != range.second; ++iter) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2288 | 2288 |
2289 inline bool operator<(const SpanKey& other) const { | 2289 inline bool operator<(const SpanKey& other) const { |
2290 if (descriptor_proto < other.descriptor_proto) return true; | 2290 if (descriptor_proto < other.descriptor_proto) return true; |
2291 if (descriptor_proto > other.descriptor_proto) return false; | 2291 if (descriptor_proto > other.descriptor_proto) return false; |
2292 if (field < other.field) return true; | 2292 if (field < other.field) return true; |
2293 if (field > other.field) return false; | 2293 if (field > other.field) return false; |
2294 return index < other.index; | 2294 return index < other.index; |
2295 } | 2295 } |
2296 }; | 2296 }; |
2297 | 2297 |
2298 typedef std::multimap<SpanKey, const SourceCodeInfo::Location*> SpanMap; | 2298 typedef multimap<SpanKey, const SourceCodeInfo::Location*> SpanMap; |
2299 SpanMap spans_; | 2299 SpanMap spans_; |
2300 std::map<char, std::pair<int, int> > markers_; | 2300 map<char, pair<int, int> > markers_; |
2301 string text_without_markers_; | 2301 string text_without_markers_; |
2302 | 2302 |
2303 void ExtractMarkers(const char* text) { | 2303 void ExtractMarkers(const char* text) { |
2304 markers_.clear(); | 2304 markers_.clear(); |
2305 text_without_markers_.clear(); | 2305 text_without_markers_.clear(); |
2306 int line = 0; | 2306 int line = 0; |
2307 int column = 0; | 2307 int column = 0; |
2308 while (*text != '\0') { | 2308 while (*text != '\0') { |
2309 if (*text == '$') { | 2309 if (*text == '$') { |
2310 ++text; | 2310 ++text; |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3148 EXPECT_TRUE(HasSpan(bar_int, "number")); | 3148 EXPECT_TRUE(HasSpan(bar_int, "number")); |
3149 } | 3149 } |
3150 | 3150 |
3151 // =================================================================== | 3151 // =================================================================== |
3152 | 3152 |
3153 } // anonymous namespace | 3153 } // anonymous namespace |
3154 | 3154 |
3155 } // namespace compiler | 3155 } // namespace compiler |
3156 } // namespace protobuf | 3156 } // namespace protobuf |
3157 } // namespace google | 3157 } // namespace google |
OLD | NEW |