Debian Codegraph @

libcextract/Parser.hh

raw
1 //===- Parser.hh - Base class for parsers -----------------------*- 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 /// Base class for parsers.
11 //
12 //===----------------------------------------------------------------------===//
13
14 /* Author: Marcos Paulo de Souza */
15
16 #pragma once
17
18 #include <vector>
19 #include <string>
20 #include <string.h>
21 #include <errno.h>
22 #include <stdexcept>
23 #ifndef _WIN32
24 #include <wordexp.h>
25 #endif
26
27 class Parser
28 {
29 public:
30 Parser(const std::string &path)
31 : Parser(path.c_str())
32 {
33 }
34
35 Parser(const char *path)
36 {
37 #ifndef _WIN32
38 /* Expand shell characters like '~' in paths. */
39 wordexp_t exp_result;
40 wordexp(path, &exp_result, 0);
41
42 /* Store in parser_path. */
43 parser_path = std::string(exp_result.we_wordv[0]);
44
45 /* Release expansion object. */
46 wordfree(&exp_result);
47 #else
48 /* wordexp is not available on Windows, use path as-is */
49 parser_path = std::string(path);
50 #endif
51 }
52
53 // Some parsers work on files
54 void Parse();
55 void Parse(const char *path);
56
57 std::vector<std::string> Get_All_Symbols();
58 bool Needs_Externalization(const std::string &symbol);
59 inline const std::string &Get_Path(void)
60 {
61 return parser_path;
62 }
63
64
65 protected:
66 std::string parser_path;
67 };