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_
11 #include "tools/gn/location.h"
12 #include "tools/gn/token.h"
17 // Result of doing some operation. Check has_error() to see if an error
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.
27 typedef std::vector<LocationRange> RangeList;
29 // Indicates no error.
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());
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;
72 void InternalPrintToStdout(bool is_sub_err) const;
77 std::vector<LocationRange> ranges_;
80 std::string help_text_;
82 std::vector<Err> sub_errs_;
85 #endif // TOOLS_GN_ERR_H_