cprover
Loading...
Searching...
No Matches
ansi_c_parser.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9
10#ifndef CPROVER_ANSI_C_ANSI_C_PARSER_H
11#define CPROVER_ANSI_C_ANSI_C_PARSER_H
12
13#include <map>
14
15#include <util/parser.h>
16#include <util/config.h>
17
18#include "ansi_c_parse_tree.h"
19#include "ansi_c_scope.h"
20
22
24{
25public:
27
41
42 virtual bool parse() override
43 {
44 return yyansi_cparse()!=0;
45 }
46
47 virtual void clear() override
48 {
51
52 // scanner state
53 tag_following=false;
56 string_literal.clear();
57 pragma_pack.clear();
59
60 // set up global scope
61 scopes.clear();
62 scopes.push_back(scopet());
63 }
64
65 // internal state of the scanner
69 std::string string_literal;
70 std::list<exprt> pragma_pack;
71
74
75 // recognize C++98 and C++11 keywords
76 bool cpp98, cpp11;
77
78 // in C99 and upwards, for(;;) has a scope
80
81 // ISO/IEC TS 18661-3:2015
85
88
89 typedef std::list<scopet> scopest;
91
93 {
94 return scopes.front();
95 }
96
97 const scopet &root_scope() const
98 {
99 return scopes.front();
100 }
101
103 {
104 scopes.pop_back();
105 }
106
108 {
109 PRECONDITION(!scopes.empty());
110 return scopes.back();
111 }
112
114
115 // convert a declarator and then add it to existing an declaration
116 void add_declarator(exprt &declaration, irept &declarator);
117
118 // adds a tag to the current scope
119 void add_tag_with_body(irept &tag);
120
121 void copy_item(const ansi_c_declarationt &declaration)
122 {
123 PRECONDITION(declaration.id() == ID_declaration);
124 parse_tree.items.push_back(declaration);
125 }
126
127 void new_scope(const std::string &prefix)
128 {
129 const scopet &current=current_scope();
130 scopes.push_back(scopet());
131 scopes.back().prefix=current.prefix+prefix;
132 }
133
135 const irep_idt &base_name, // in
136 irep_idt &identifier, // out
137 bool tag,
138 bool label);
139
140 static ansi_c_id_classt get_class(const typet &type);
141
143 {
144 irep_idt identifier;
145 lookup(base_name, identifier, false, true);
146 return identifier;
147 }
148
151
153 void pragma_cprover_push();
154
156 void pragma_cprover_pop();
157
159 void pragma_cprover_add_check(const irep_idt &name, bool enabled);
160
163 bool pragma_cprover_clash(const irep_idt &name, bool enabled);
164
167 void set_pragma_cprover();
168
169private:
170 std::list<std::map<const irep_idt, bool>> pragma_cprover_stack;
171};
172
174
175int yyansi_cerror(const std::string &error);
177
178#endif // CPROVER_ANSI_C_ANSI_C_PARSER_H
int yyansi_cerror(const std::string &error)
ansi_c_parsert ansi_c_parser
void ansi_c_scanner_init()
int yyansi_cparse()
ansi_c_id_classt
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:563
void pragma_cprover_pop()
Pops a level in the CPROVER pragma stack.
void set_pragma_cprover()
Tags source_location with the current CPROVER pragma stack.
std::list< exprt > pragma_pack
void new_scope(const std::string &prefix)
bool pragma_cprover_empty()
True iff the CPROVER pragma stack is empty.
bool ts_18661_3_Floatn_types
ansi_c_identifiert identifiert
void add_declarator(exprt &declaration, irept &declarator)
ansi_c_scopet scopet
ansi_c_parse_treet parse_tree
std::list< std::map< const irep_idt, bool > > pragma_cprover_stack
unsigned parenthesis_counter
scopet & root_scope()
scopet & current_scope()
configt::ansi_ct::flavourt modet
void add_tag_with_body(irept &tag)
bool pragma_cprover_clash(const irep_idt &name, bool enabled)
Returns true iff the same check with polarity is already present at top of the stack.
const scopet & root_scope() const
std::list< scopet > scopest
static ansi_c_id_classt get_class(const typet &type)
virtual void clear() override
ansi_c_id_classt lookup(const irep_idt &base_name, irep_idt &identifier, bool tag, bool label)
void copy_item(const ansi_c_declarationt &declaration)
void pragma_cprover_push()
Pushes an empty level in the CPROVER pragma stack.
virtual bool parse() override
std::string string_literal
irep_idt lookup_label(const irep_idt base_name)
void pragma_cprover_add_check(const irep_idt &name, bool enabled)
Adds a check to the CPROVER pragma stack.
std::string prefix
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:39
Base class for all expressions.
Definition expr.h:56
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition irep.h:372
const irep_idt & id() const
Definition irep.h:396
virtual void clear()
Definition parser.h:32
The type of an expression, extends irept.
Definition type.h:29
@ NONE
Do not apply loop contracts.
Parser utilities.
#define PRECONDITION(CONDITION)
Definition invariant.h:463