-
Notifications
You must be signed in to change notification settings - Fork 139
/
Variable.h
193 lines (168 loc) · 8.37 KB
/
Variable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// -*- mode: C++ -*-
//
// Copyright (c) 2007, 2008, 2009, 2010, 2011 The University of Utah
// All rights reserved.
//
// This file is part of `csmith', a random generator of C programs.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// This file was derived from a random program generator written by Bryan
// Turner. The attributions in that file was:
//
// Random Program Generator
// Bryan Turner (bryan.turner@pobox.com)
// July, 2005
//
#ifndef VARIABLE_H
#define VARIABLE_H
///////////////////////////////////////////////////////////////////////////////
#include <ostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#include "Effect.h"
#include "Type.h"
#include "CVQualifiers.h"
#include "StringUtils.h"
class CGContext;
class Expression;
class Function;
class Block;
class Lhs;
class ArrayVariable;
class Variable
{
friend class VariableSelector;
friend class ArrayVariable;
public:
static Variable *CreateVariable(const std::string &name, const Type *type, const Expression* init, const CVQualifiers* qfer);
static Variable *CreateVariable(const std::string &name, const Type *type,
bool isConst, bool isVolatile,
bool isAuto, bool isStatic, bool isRegister, bool isBitfield, const Variable* isFieldVarOf);
static Variable *CreateVariable(const std::string &name, const Type *type,
const vector<bool>& isConsts, const vector<bool>& isVolatiles,
bool isAuto, bool isStatic, bool isRegister, bool isBitfield, const Variable* isFieldVarOf);
static void doFinalization(void);
static void setup_ctrl_vars(void);
virtual ~Variable(void);
virtual bool is_global(void) const;
virtual bool is_visible_local(const Block* blk) const;
virtual size_t get_dimension(void) const { return 0;}
bool is_visible(const Block* blk) const { return is_global() || is_visible_local(blk);}
bool is_argument(void) const;
bool is_tmp_var(void) const;
bool is_const(void) const;
bool is_volatile(void) const;
bool is_const_after_deref(int deref_level) const;
bool is_volatile_after_deref(int deref_level) const;
bool has_field_var(const Variable* v) const;
bool is_field_var(void) const { return field_var_of != 0; };
int get_field_id(void) const;
bool is_union_field(void) const { return field_var_of != 0 && field_var_of->type->eType == eUnion; };
bool is_array_field(void) const;
bool is_virtual(void) const;
bool is_aggregate(void) const { return type && type->is_aggregate(); }
bool match(const Variable* v) const;
bool loose_match(const Variable* v) const;
bool is_pointer(void) const { return type && type->eType == ePointer;}
bool is_rv(void) const { return StringUtils::end_with(name, "_rv"); }
int compare_field(const Variable* v) const;
int get_seq_num(void) const;
virtual std::string get_actual_name() const;
std::string to_string(void) const;
std::vector<std::string> deputy_annotation(void) const;
// ISSUE: we treat volatiles specially
bool compatible(const Variable *v) const;
const Variable* get_named_var(void) const;
const Variable* match_var_name(const string& vname) const;
virtual void hash(std::ostream& out) const;
virtual const Variable* get_collective(void) const;
virtual const ArrayVariable* get_array(string& field) const;
virtual int get_index_vars(vector<const Variable*>& /* vars */) const { return 0;}
///////////////////////////////////////////////////////////////////////
virtual void Output(std::ostream &) const;
int output_runtime_value(ostream &out, string prefix, string suffix, int indent, bool multi_lines=false) const;
int output_addressable_name(ostream &out, int indent) const;
int output_volatile_address(ostream &out, int indent, const string &fp_string, vector<string> &seen_names) const;
int output_volatile_fprintf(ostream &out, int indent, const string &name,
const string &sizeof_string, const string &fp_string) const;
bool is_seen_name(vector<std::string> &seen_names, const std::string &name) const;
bool is_valid_volatile(void) const;
int output_value_dump(ostream &out, string prefix, int indent) const;
void OutputAddrOf(std::ostream &) const;
void OutputForComment(std::ostream &) const;
virtual void OutputDef(std::ostream &out, int indent) const;
virtual void OutputDecl(std::ostream &) const;
virtual void output_qualified_type(std::ostream &out) const;
virtual void OutputLowerBound(std::ostream &) const;
virtual void OutputUpperBound(std::ostream &) const;
static size_t GetMaxArrayDimension(const vector<Variable*>& vars);
vector<Variable *> field_vars; // field variables for struct/unions
const std::string name;
const Type *type;
const Expression *init;
// Storage-class specifiers.
const bool isAuto;
// bool isExtern;
const bool isStatic;
const bool isRegister;
const bool isBitfield_; // expanded from a full-bitfield struct var
const Variable* field_var_of; //expanded from a struct/union
const bool isArray;
const CVQualifiers qfer;
static std::vector<const Variable*> ctrl_vars;
static const char sink_var_name[];
private:
Variable(const std::string &name, const Type *type, const Expression* init, const CVQualifiers* qfer);
Variable(const std::string &name, const Type *type, const Expression* init, const CVQualifiers* qfer, const Variable* isFieldVarOf, bool isArray);
Variable(const std::string &name, const Type *type,
const vector<bool>& isConsts, const vector<bool>& isVolatiles,
bool isAuto, bool isStatic, bool isRegister, bool isBitfield, const Variable* isFieldVarOf);
void create_field_vars(const Type* type);
};
void OutputVariableList(const std::vector<Variable*> &var, std::ostream &out, int indent = 0);
void OutputVariableDeclList(const std::vector<Variable*> &var, std::ostream &out, std::string prefix = "", int indent = 0);
void OutputArrayInitializers(const vector<Variable*>& vars, std::ostream &out, int indent);
void OutputArrayCtrlVars(std::ostream &out, size_t dimen, int indent);
void OutputVolatileAddress(const vector<Variable*> &vars, std::ostream &out, int indent, const string &fp_string);
void MapVariableList(const vector<Variable*> &var, std::ostream &out, int (*func)(Variable *var, std::ostream *pOut));
int HashVariable(Variable *var, std::ostream *pOut);
int find_variable_in_set(const vector<const Variable*>& set, const Variable* v);
int find_variable_in_set(const vector<Variable*>& set, const Variable* v);
int find_field_variable_in_set(const vector<const Variable*>& set, const Variable* v);
bool is_variable_in_set(const vector<const Variable*>& set, const Variable* v);
bool add_variable_to_set(vector<const Variable*>& set, const Variable* v);
bool add_variables_to_set(vector<const Variable*>& set, const vector<const Variable*>& new_set);
bool equal_variable_sets(const vector<const Variable*>& set1, const vector<const Variable*>& set2);
bool sub_variable_sets(const vector<const Variable*>& set1, const vector<const Variable*>& set2);
void combine_variable_sets(const vector<const Variable*>& set1, const vector<const Variable*>& set2, vector<const Variable*>& set_all);
void remove_field_vars(vector<const Variable*>& set);
///////////////////////////////////////////////////////////////////////////////
#endif // VARIABLE_H
// Local Variables:
// c-basic-offset: 4
// tab-width: 4
// End:
// End of file.