ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
clang_c_language.h
Go to the documentation of this file.
1#ifndef CLANG_C_FRONTEND_CLANG_C_LANGUAGE_H_
2#define CLANG_C_FRONTEND_CLANG_C_LANGUAGE_H_
3
5
6#define __STDC_LIMIT_MACROS
7#define __STDC_FORMAT_MACROS
8
9// Forward dec, to avoid bringing in clang headers
10namespace clang
11{
12class ASTUnit;
13} // namespace clang
14
16{
17public:
18 virtual bool preprocess(const std::string &path, std::ostream &outstream);
19
20 bool parse(const std::string &path) override;
21
22 bool final(contextt &context) override;
23
24 bool typecheck(contextt &context, const std::string &module) override;
25
26 std::string id() const override
27 {
28 return "c";
29 }
30
31 void show_parse(std::ostream &out) override;
32
33 // conversion from expression into string
34 bool from_expr(
35 const exprt &expr,
36 std::string &code,
37 const namespacet &ns,
38 unsigned flags) override;
39
40 // conversion from type into string
41 bool from_type(
42 const typet &type,
43 std::string &code,
44 const namespacet &ns,
45 unsigned flags) override;
46
47 unsigned default_flags(presentationt target) const override;
48
49 languaget *new_language() const override
50 {
51 return new clang_c_languaget();
52 }
53
56
58 static void register_bundled();
59
60protected:
61 virtual std::string internal_additions();
62
63 static const std::string &clang_resource_dir();
64
65 // Force the file type, .c for the C frontend and .cpp for the C++ one
66 virtual void force_file_type(std::vector<std::string> &compiler_args);
67
68 /* Include search paths, in order (any of 1, 2, 3, 4, 5, 7, 8 may be empty
69 * depending on C/C++ mode and command line options such as --no-library or
70 * --nostdinc):
71 *
72 * 1. any user-specified -I from left to right
73 * 2. our C++ library headers, corresponds to:
74 * src/cpp/library/{CUDA,Qt,Qt/Core}
75 * 3. our C++ standard library and system headers, corresponds to:
76 * src/cpp/library
77 * 4. our C standard library and system headers, corresponds to:
78 * src/c2goto/headers
79 * 5. the system's C++ standard library, e.g., /usr/include/c++/v1 for libc++
80 * or
81 * /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/{.,x86_64-pc-linux-gnu,backward}
82 * for the default libstdc++
83 * 6. the Clang resource directory's /include, e.g.
84 * /usr/lib/llvm/16/bin/../../../../lib/clang/16/include/../include
85 * 7. the default system include directories, e.g. /usr/local/include and
86 * /usr/include
87 * 8. any user-specified --idirafter from left to right
88 *
89 * 1 and 2 are done by passing '-I'; 3 and 4 via '-isystem'; 5, 6 and 7 are
90 * built into Clang where 5 can be adjusted by passing '--gcc-install-dir'
91 * and '-stdlib', 6 is given via '-resource-dir', and 7 is optionally disabled
92 * per '-nostdinc'; 8 is done via '-idirafter'.
93 *
94 * Note: built-in paths are subject to --sysroot.
95 */
96 virtual void build_include_args(std::vector<std::string> &compiler_args);
97 virtual void build_compiler_args(std::vector<std::string> &compiler_args);
98
99 std::vector<std::string> compiler_args(std::string tool_name)
100 {
101 std::vector<std::string> v{std::move(tool_name)};
105 return v;
106 }
107
108 std::unique_ptr<clang::ASTUnit> AST;
109
110private:
111 void set_language_version();
112};
113
115
116#endif
languaget * new_clang_c_language()
Definition clang_c_language.cpp:31
bool typecheck(contextt &context, const std::string &module) override
Definition clang_c_language.cpp:495
std::unique_ptr< clang::ASTUnit > AST
Definition clang_c_language.h:108
std::vector< std::string > compiler_args(std::string tool_name)
Definition clang_c_language.h:99
bool from_type(const typet &type, std::string &code, const namespacet &ns, unsigned flags) override
Definition clang_c_language.cpp:588
languaget * new_language() const override
Definition clang_c_language.h:49
bool from_expr(const exprt &expr, std::string &code, const namespacet &ns, unsigned flags) override
Definition clang_c_language.cpp:578
virtual bool preprocess(const std::string &path, std::ostream &outstream)
Definition clang_c_language.cpp:553
virtual std::string internal_additions()
Definition clang_c_language.cpp:565
virtual void build_compiler_args(std::vector< std::string > &compiler_args)
Definition clang_c_language.cpp:84
virtual void build_include_args(std::vector< std::string > &compiler_args)
Definition clang_c_language.cpp:38
std::string id() const override
Definition clang_c_language.h:26
bool parse(const std::string &path) override
Definition clang_c_language.cpp:375
virtual void force_file_type(std::vector< std::string > &compiler_args)
Definition clang_c_language.cpp:318
static void register_bundled()
Registers the bundled clang headers with file_operations.
Definition clang_headers.cpp:16
unsigned default_flags(presentationt target) const override
Definition clang_c_language.cpp:598
static const std::string & clang_resource_dir()
Definition clang_headers.cpp:32
void show_parse(std::ostream &out) override
Definition clang_c_language.cpp:548
Definition context.h:57
Definition expr.h:34
Definition language.h:16
Definition module.h:60
Definition namespace.h:10
Definition type.h:9
presentationt
Definition language.h:10
Definition build_ast.h:13
Definition path.py:1