Landing Recent QUIC changes until 8/19/2015 17:00 UTC.
[chromium-blink-merge.git] / tools / gn / err.h
blob3e077e9fb892303d5b7127eacbd3441b7a791c26
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 #ifndef TOOLS_GN_ERR_H_
6 #define TOOLS_GN_ERR_H_
8 #include <string>
9 #include <vector>
11 #include "tools/gn/location.h"
12 #include "tools/gn/token.h"
14 class ParseNode;
15 class Value;
17 // Result of doing some operation. Check has_error() to see if an error
18 // occurred.
20 // An error has a location and a message. Below that, is some optional help
21 // text to go with the annotation of the location.
23 // An error can also have sub-errors which are additionally printed out
24 // below. They can provide additional context.
25 class Err {
26 public:
27 typedef std::vector<LocationRange> RangeList;
29 // Indicates no error.
30 Err();
32 // Error at a single point.
33 Err(const Location& location,
34 const std::string& msg,
35 const std::string& help = std::string());
37 // Error at a given range.
38 Err(const LocationRange& range,
39 const std::string& msg,
40 const std::string& help = std::string());
42 // Error at a given token.
43 Err(const Token& token,
44 const std::string& msg,
45 const std::string& help_text = std::string());
47 // Error at a given node.
48 Err(const ParseNode* node,
49 const std::string& msg,
50 const std::string& help_text = std::string());
52 // Error at a given value.
53 Err(const Value& value,
54 const std::string msg,
55 const std::string& help_text = std::string());
57 ~Err();
59 bool has_error() const { return has_error_; }
60 const Location& location() const { return location_; }
61 const std::string& message() const { return message_; }
62 const std::string& help_text() const { return help_text_; }
64 void AppendRange(const LocationRange& range) { ranges_.push_back(range); }
65 const RangeList& ranges() const { return ranges_; }
67 void AppendSubErr(const Err& err);
69 void PrintToStdout() const;
71 private:
72 void InternalPrintToStdout(bool is_sub_err) const;
74 bool has_error_;
75 Location location_;
77 std::vector<LocationRange> ranges_;
79 std::string message_;
80 std::string help_text_;
82 std::vector<Err> sub_errs_;
85 #endif // TOOLS_GN_ERR_H_