Debian Codegraph @

libcextract/ArgvParser.hh

raw
1 //===- ArgvParser.hh - Parse the command-line options -----------*- C++ -*-===//
2 //
3 // This project is licensed under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file
10 /// Parse the command-line options given to clang-extract.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #pragma once
15
16 #include <string>
17 #include <vector>
18
19 /** Class encapsulating the Argv command line that were provided to clang-extract
20 *
21 * clang-extract must accept the original software command line call with some
22 * extra arguments to specify the special options for clang-extract. Those
23 * options should be also acceptable by gcc and clang compilers, so the user
24 * can simply swap the compiler to clang-extract instead of gcc in the
25 * makefiles by overwriting the CC variable.
26 *
27 * Author: Giuliano Belinassi
28 */
29 class ArgvParser
30 {
31 public:
32
33 /** Build from argc and argv passed to clang-extract. */
34 ArgvParser(int argc, char **argv);
35
36
37 inline std::vector<const char *>& Get_Args_To_Clang(void)
38 {
39 return ArgsToClang;
40 }
41
42 inline const std::vector<const char *>& Get_Args_To_Clang(void) const
43 {
44 return ArgsToClang;
45 }
46
47 inline std::vector<std::string>& Get_Functions_To_Extract(void)
48 {
49 return FunctionsToExtract;
50 }
51
52 inline std::vector<std::string>& Get_Symbols_To_Externalize(void)
53 {
54 return SymbolsToExternalize;
55 }
56
57 inline std::vector<std::string>& Get_Headers_To_Expand(void)
58 {
59 return HeadersToExpand;
60 }
61
62 inline std::vector<std::string>& Get_Headers_To_Not_Expand(void)
63 {
64 return HeadersToNotExpand;
65 }
66
67 inline std::string &Get_Output_File(void)
68 {
69 return OutputFile;
70 }
71
72 inline bool Is_Externalization_Disabled(void)
73 {
74 return DisableExternalization;
75 }
76
77 inline bool Should_Keep_Includes(void)
78 {
79 return WithIncludes;
80 }
81
82 inline bool Should_Dump_Passes(void)
83 {
84 return DumpPasses;
85 }
86
87 inline bool Is_Kernel(void)
88 {
89 return Kernel;
90 }
91
92 inline bool Has_Ibt(void)
93 {
94 return Ibt;
95 }
96
97 inline std::string Get_PatchObject(void)
98 {
99 return PatchObject;
100 }
101
102 inline std::vector<std::string> &Get_Debuginfo_Path(void)
103 {
104 return Debuginfos;
105 }
106
107 inline const char *Get_Ipaclones_Path(void)
108 {
109 return IpaclonesPath;
110 }
111
112 inline const char *Get_Symvers_Path(void)
113 {
114 return SymversPath;
115 }
116
117 inline const char *Get_Dsc_Output_Path(void)
118 {
119 return DescOutputPath;
120 }
121
122 inline bool Should_Rename_Symbols(void)
123 {
124 return RenameSymbols;
125 }
126
127 inline const char *Get_Include_Expansion_Policy(void)
128 {
129 return IncExpansionPolicy;
130 }
131
132 inline const char *Get_Output_Path_To_Prototype_Header(void)
133 {
134 return OutputFunctionPrototypeHeader;
135 }
136
137 inline bool Get_Allow_Late_Externalization(void)
138 {
139 return AllowLateExternalization;
140 }
141
142 inline bool Get_Ignore_Clang_Errors(void)
143 {
144 return IgnoreClangErrors;
145 }
146
147 /** Print help usage message. */
148 void Print_Usage_Message(void);
149
150 private:
151 bool Handle_Clang_Extract_Arg(const char *str);
152 void Insert_Required_Parameters(void);
153
154 std::vector<const char *> ArgsToClang;
155
156 std::vector<std::string> FunctionsToExtract;
157 std::vector<std::string> SymbolsToExternalize;
158 std::vector<std::string> HeadersToExpand;
159 std::vector<std::string> HeadersToNotExpand;
160 std::string OutputFile;
161
162 bool IgnoreClangErrors;
163 bool DisableExternalization;
164 bool WithIncludes;
165 bool DumpPasses;
166 bool RenameSymbols;
167 bool Kernel;
168 /* If the file was compiled with IBT support */
169 bool Ibt;
170
171 /* If set, then clang-extract may write the externalized decl later than the
172 original code. */
173 bool AllowLateExternalization;
174 std::string PatchObject;
175
176 std::vector<std::string> Debuginfos;
177
178 const char *IpaclonesPath;
179 const char *SymversPath;
180
181 const char *DescOutputPath;
182
183 const char *IncExpansionPolicy;
184
185 const char *OutputFunctionPrototypeHeader;
186 };