1 // Copyright 2017 The Fuchsia 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.
4 
5 #ifndef ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_SOURCE_LOCATION_H_
6 #define ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_SOURCE_LOCATION_H_
7 
8 #include <stdint.h>
9 
10 #include "source_manager.h"
11 #include "string_view.h"
12 
13 namespace fidl {
14 
15 // A SourceLocation represents a range of a source file. It consists
16 // of a StringView, and a reference to the SourceFile that is backing
17 // the StringView.
18 
19 class SourceLocation {
20 public:
SourceLocation(StringView data,const SourceFile & source_file)21     SourceLocation(StringView data, const SourceFile& source_file)
22         : data_(data), source_file_(&source_file) {}
23 
SourceLocation()24     SourceLocation() : data_(StringView()), source_file_(nullptr) {}
25 
valid()26     bool valid() const { return source_file_ != nullptr; }
27 
data()28     const StringView& data() const { return data_; }
source_file()29     const SourceFile& source_file() const { return *source_file_; }
30 
31     StringView SourceLine(SourceFile::Position* position_out) const;
32 
33     std::string position() const;
34 
35 private:
36     StringView data_;
37     const SourceFile* source_file_;
38 };
39 
40 } // namespace fidl
41 
42 #endif // ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_SOURCE_LOCATION_H_
43