CBMC
ansi_c_language.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_ANSI_C_ANSI_C_LANGUAGE_H
11 #define CPROVER_ANSI_C_ANSI_C_LANGUAGE_H
12 
13 #include <memory>
14 
15 #include <langapi/language.h>
16 
17 #include "ansi_c_parse_tree.h"
19 
20 // clang-format off
21 #define OPT_ANSI_C_LANGUAGE \
22  "(max-nondet-tree-depth):" \
23  "(min-null-tree-depth):"
24 
25 #define HELP_ANSI_C_LANGUAGE \
26  " {y--max-nondet-tree-depth} {uN} \t " \
27  "limit size of nondet (e.g. input) object tree; at level {uN} pointers are " \
28  "set to null\n" \
29  " {y--min-null-tree-depth} {uN} \t " \
30  "minimum level at which a pointer can first be NULL in a recursively " \
31  "nondet initialized struct\n" \
32 // clang-format on
33 
35 {
36 public:
37  void
38  set_language_options(const optionst &options, message_handlert &) override
39  {
40  object_factory_params.set(options);
41  }
42 
43  bool preprocess(
44  std::istream &instream,
45  const std::string &path,
46  std::ostream &outstream,
47  message_handlert &message_handler) override;
48 
49  bool parse(
50  std::istream &instream,
51  const std::string &path,
52  message_handlert &message_handler) override;
53 
55  symbol_table_baset &symbol_table,
56  message_handlert &message_handler) override;
57 
58  bool typecheck(
59  symbol_table_baset &symbol_table,
60  const std::string &module,
61  message_handlert &message_handler,
62  const bool keep_file_local) override;
63 
64  bool typecheck(
65  symbol_table_baset &symbol_table,
66  const std::string &module,
67  message_handlert &message_handler,
68  const bool keep_file_local,
69  const std::set<irep_idt> &keep);
70 
71  bool can_keep_file_local() override
72  {
73  return true;
74  }
75 
76  bool typecheck(
77  symbol_table_baset &symbol_table,
78  const std::string &module,
79  message_handlert &message_handler) override
80  {
81  return typecheck(symbol_table, module, message_handler, true);
82  }
83 
84  void show_parse(std::ostream &out, message_handlert &) override;
85 
86  ~ansi_c_languaget() override;
88 
89  bool from_expr(
90  const exprt &expr,
91  std::string &code,
92  const namespacet &ns) override;
93 
94  bool from_type(
95  const typet &type,
96  std::string &code,
97  const namespacet &ns) override;
98 
99  bool type_to_name(
100  const typet &type,
101  std::string &name,
102  const namespacet &ns) override;
103 
104  bool to_expr(
105  const std::string &code,
106  const std::string &module,
107  exprt &expr,
108  const namespacet &ns,
109  message_handlert &message_handler) override;
110 
111  std::unique_ptr<languaget> new_language() override
112  {
113  return std::make_unique<ansi_c_languaget>();
114  }
115 
116  std::string id() const override { return "C"; }
117  std::string description() const override { return "ANSI-C 99"; }
118  std::set<std::string> extensions() const override;
119 
120  void modules_provided(std::set<std::string> &modules) override;
121 
122 protected:
124  std::string parse_path;
125 
127 };
128 
129 std::unique_ptr<languaget> new_ansi_c_language();
130 
131 #endif // CPROVER_ANSI_C_ANSI_C_LANGUAGE_H
std::unique_ptr< languaget > new_ansi_c_language()
~ansi_c_languaget() override
std::set< std::string > extensions() const override
void show_parse(std::ostream &out, message_handlert &) override
bool from_type(const typet &type, std::string &code, const namespacet &ns) override
Formats the given type in a language-specific way.
std::unique_ptr< languaget > new_language() override
void set_language_options(const optionst &options, message_handlert &) override
Set language-specific options.
std::string parse_path
bool from_expr(const exprt &expr, std::string &code, const namespacet &ns) override
Formats the given expression in a language-specific way.
bool to_expr(const std::string &code, const std::string &module, exprt &expr, const namespacet &ns, message_handlert &message_handler) override
Parses the given string into an expression.
std::string description() const override
void modules_provided(std::set< std::string > &modules) override
bool type_to_name(const typet &type, std::string &name, const namespacet &ns) override
Encodes the given type in a language-specific way.
bool typecheck(symbol_table_baset &symbol_table, const std::string &module, message_handlert &message_handler, const bool keep_file_local) override
typecheck without removing specified entries from the symbol table
bool can_keep_file_local() override
Is it possible to call three-argument typecheck() on this object?
bool preprocess(std::istream &instream, const std::string &path, std::ostream &outstream, message_handlert &message_handler) override
ANSI-C preprocessing.
bool generate_support_functions(symbol_table_baset &symbol_table, message_handlert &message_handler) override
Create language-specific support functions, such as __CPROVER_start, __CPROVER_initialize and languag...
ansi_c_parse_treet parse_tree
c_object_factory_parameterst object_factory_params
std::string id() const override
bool parse(std::istream &instream, const std::string &path, message_handlert &message_handler) override
bool typecheck(symbol_table_baset &symbol_table, const std::string &module, message_handlert &message_handler) override
Base class for all expressions.
Definition: expr.h:56
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
The symbol table base class interface.
The type of an expression, extends irept.
Definition: type.h:29
Abstract interface to support a programming language.
void set(const optionst &)
Assigns the parameters from given options.