ACAV f0ba4b7c9529
Abstract Syntax Tree (AST) visualization tool for C, C++, and Objective-C
Loading...
Searching...
No Matches
SourceLocation.h
Go to the documentation of this file.
1/*$!{
2* Aurora Clang AST Viewer (ACAV)
3*
4* Copyright (c) 2026 Min Liu
5* Copyright (c) 2026 Michael David Adams
6*
7* SPDX-License-Identifier: GPL-2.0-or-later
8*
9* This program is free software; you can redistribute it and/or modify
10* it under the terms of the GNU General Public License as published by
11* the Free Software Foundation; either version 2 of the License, or
12* (at your option) any later version.
13*
14* This program is distributed in the hope that it will be useful,
15* but WITHOUT ANY WARRANTY; without even the implied warranty of
16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17* GNU General Public License for more details.
18*
19* You should have received a copy of the GNU General Public License along
20* with this program; if not, see <https://www.gnu.org/licenses/>.
21}$!*/
22
25#pragma once
26
27#include "common/FileManager.h"
28
29// Forward declarations for Clang types
30namespace clang {
31class SourceLocation;
32class SourceManager;
33class SourceRange;
34} // namespace clang
35
36namespace acav {
37
44class SourceLocation {
45public:
46 SourceLocation() = delete;
47 SourceLocation(FileID fileId, unsigned line, unsigned column);
48
49 FileID fileID() const { return fileId_; }
50 unsigned line() const { return line_; }
51 unsigned column() const { return column_; }
52 bool isValid() const { return fileId_ != FileManager::InvalidFileID; }
53
59 static SourceLocation fromClang(const clang::SourceLocation &loc,
60 const clang::SourceManager &sm,
61 FileManager &fileMgr);
62
64 static void resetCache();
65
66private:
67 FileID fileId_ = 0; // File identifier (0 = invalid)
68 unsigned line_; // 1-based line number
69 unsigned column_; // 1-based column number
70};
71
75class SourceRange {
76public:
77 SourceRange() = delete;
78 SourceRange(SourceLocation begin, SourceLocation end);
79
80 SourceLocation begin() const { return begin_; }
81 SourceLocation end() const { return end_; }
82
88 static SourceRange fromClang(const clang::SourceRange &range,
89 const clang::SourceManager &sm,
90 FileManager &fileMgr);
91
93 static void resetCache();
94
95private:
96 SourceLocation begin_;
97 SourceLocation end_;
98};
99
100} // namespace acav
Centralized file registry with path-to-FileID mapping.
std::size_t FileID
Type-safe identifier for registered files. 0 is reserved for invalid.
Definition FileManager.h:38
Centralized file registry providing path-to-FileID mapping.
Definition FileManager.h:45
static constexpr FileID InvalidFileID
Reserved invalid FileID.
Definition FileManager.h:47
Represents a specific position in source code.
static void resetCache()
Reset internal caches (per extraction run).
static SourceLocation fromClang(const clang::SourceLocation &loc, const clang::SourceManager &sm, FileManager &fileMgr)
Create SourceLocation from Clang's SourceLocation.
static SourceRange fromClang(const clang::SourceRange &range, const clang::SourceManager &sm, FileManager &fileMgr)
Create SourceRange from Clang's SourceRange.
static void resetCache()
Reset internal caches (per extraction run).