forked from include-what-you-use/include-what-you-use
-
Notifications
You must be signed in to change notification settings - Fork 6
/
iwyu_path_util.h
93 lines (69 loc) · 3.18 KB
/
iwyu_path_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//===--- iwyu_path_util.h - file-path utilities for include-what-you-use --===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// File-path utilities for the IWYU checker.
#ifndef INCLUDE_WHAT_YOU_USE_IWYU_PATH_UTIL_H_
#define INCLUDE_WHAT_YOU_USE_IWYU_PATH_UTIL_H_
#include <string> // for string, allocator, etc
#include <vector>
#include "iwyu_string_util.h"
namespace include_what_you_use {
using std::string;
using std::vector;
// One entry in the search-path list of where to find #include files.
struct HeaderSearchPath {
enum Type { kUnusedPath = 0, kSystemPath, kUserPath };
HeaderSearchPath(const string& p, Type pt) : path(p), path_type(pt) { }
string path; // the path-entry as specified on the commandline (via -I)
Type path_type;
};
// The directories to look for #includes in, including from -I, -isystem, etc.
void SetHeaderSearchPaths(const vector<HeaderSearchPath>& search_paths);
const vector<HeaderSearchPath>& HeaderSearchPaths();
// Returns true if 'path' is a path of a (possibly enclosed in double
// quotes or <>) C++ header file.
bool IsHeaderFile(string path);
// If the path has a slash, return the part after the last slash,
// else return the input path.
string Basename(const string& path);
// Normalizes the file path, then strips uninteresting suffixes from
// the file name. Replaces "/internal/" with "/public/" and
// "/include/" with "/src".
string GetCanonicalName(string file_path);
// Replaces "\" by "/" (Microsoft platform paths) and collapses all dot
// components in path.
string NormalizeFilePath(const string& path);
// Normalizes like NormalizeFilePath and ensures trailing slash.
// Hence use only for directories!
string NormalizeDirPath(const string& path);
// Is path absolute?
bool IsAbsolutePath(const string& path);
// Get absolute version of path.
string MakeAbsolutePath(const string& path);
string MakeAbsolutePath(const string& base_path, const string& relative_path);
// Get the parent of path.
string GetParentPath(const string& path);
// Try to strip the prefix_path from the front of path.
// The path assumed to be normalized but either absolute or relative.
// Return true if path was stripped.
bool StripPathPrefix(string* path, const string& prefix_path);
// Below, we talk 'quoted' includes. A quoted include is something
// that would be written on an #include line, complete with the <> or
// "". In the line '#include <time.h>', "<time.h>" is the quoted
// include.
// Converts a file-path, such as /usr/include/stdio.h, to a
// quoted include, such as <stdio.h>.
string ConvertToQuotedInclude(const string& filepath,
const string& includer_path = "");
// Returns true if the string is a quoted include.
bool IsQuotedInclude(const string& s);
// Returns whether this is a system (as opposed to user) include
// file, based on where it lives.
bool IsSystemIncludeFile(const string& filepath);
} // namespace include_what_you_use
#endif // INCLUDE_WHAT_YOU_USE_IWYU_PATH_UTIL_H_