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
39
40 virtual bool parse() override
41 {
42 return yyansi_cparse()!=0;
43 }
44
45 virtual void clear() override
46 {
49
50 // scanner state
51 tag_following=false;
57
58 // set up global scope
59 scopes.clear();
60 scopes.push_back(scopet());
61 }
62
63 // internal state of the scanner
67 std::string string_literal;
68 std::list<exprt> pragma_pack;
69
72
73 // recognize C++98 and C++11 keywords
74 bool cpp98, cpp11;
75
76 // in C99 and upwards, for(;;) has a scope
78
79 // ISO/IEC TS 18661-3:2015
81
84
85 typedef std::list<scopet> scopest;
87
89 {
90 return scopes.front();
91 }
92
93 const scopet &root_scope() const
94 {
95 return scopes.front();
96 }
97
98 void pop_scope()
99 {
100 scopes.pop_back();
101 }
102
104 {
105 PRECONDITION(!scopes.empty());
106 return scopes.back();
107 }
108
110
111 // convert a declarator and then add it to existing an declaration
112 void add_declarator(exprt &declaration, irept &declarator);
113
114 // adds a tag to the current scope
115 void add_tag_with_body(irept &tag);
116
117 void copy_item(const ansi_c_declarationt &declaration)
118 {
119 PRECONDITION(declaration.id() == ID_declaration);
120 parse_tree.items.push_back(declaration);
121 }
122
123 void new_scope(const std::string &prefix)
124 {
125 const scopet &current=current_scope();
126 scopes.push_back(scopet());
127 scopes.back().prefix=current.prefix+prefix;
128 }
129
131 const irep_idt &base_name, // in
132 irep_idt &identifier, // out
133 bool tag,
134 bool label);
135
136 static ansi_c_id_classt get_class(const typet &type);
137
139 {
140 irep_idt identifier;
141 lookup(base_name, identifier, false, true);
142 return identifier;
143 }
144
147
149 void pragma_cprover_push();
150
152 void pragma_cprover_pop();
153
155 void pragma_cprover_add_check(const irep_idt &name, bool enabled);
156
159 bool pragma_cprover_clash(const irep_idt &name, bool enabled);
160
163 void set_pragma_cprover();
164
165private:
166 std::list<std::map<const irep_idt, bool>> pragma_cprover_stack;
167};
168
170
171int yyansi_cerror(const std::string &error);
173
174#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
virtual void clear()
Reset the abstract state.
Definition ai.h:266
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