1 // -*- mode: C++ -*- 2 // 3 // Copyright (c) 2007, 2008, 2010, 2011 The University of Utah 4 // All rights reserved. 5 // 6 // This file is part of `csmith', a random generator of C programs. 7 // 8 // Redistribution and use in source and binary forms, with or without 9 // modification, are permitted provided that the following conditions are met: 10 // 11 // * Redistributions of source code must retain the above copyright notice, 12 // this list of conditions and the following disclaimer. 13 // 14 // * Redistributions in binary form must reproduce the above copyright 15 // notice, this list of conditions and the following disclaimer in the 16 // documentation and/or other materials provided with the distribution. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 // POSSIBILITY OF SUCH DAMAGE. 29 30 #ifndef EXPRESSION_VARIABLE_H 31 #define EXPRESSION_VARIABLE_H 32 33 /////////////////////////////////////////////////////////////////////////////// 34 35 #include <ostream> 36 #include <vector> 37 #include "Expression.h" 38 using namespace std; 39 40 class CGContext; 41 class Variable; 42 43 /* 44 * 45 */ 46 class ExpressionVariable : public Expression 47 { 48 public: 49 // Factory method. 50 static ExpressionVariable *make_random(CGContext &cg_context, const Type* type, const CVQualifiers* qfer=0, bool as_param=false, bool as_return=false); 51 52 explicit ExpressionVariable(const Variable &v); 53 54 ExpressionVariable(const Variable &v, const Type* t); 55 56 virtual ~ExpressionVariable(void); 57 58 virtual Expression* clone() const; 59 60 virtual CVQualifiers get_qualifiers(void) const; 61 get_eval_to_subexps(vector<const Expression * > & subs)62 virtual void get_eval_to_subexps(vector<const Expression*>& subs) const {subs.push_back(this);} 63 64 int get_indirect_level(void) const; 65 get_var(void)66 const Variable* get_var(void) const {return &var;}; 67 // 68 virtual std::vector<const ExpressionVariable*> get_dereferenced_ptrs(void) const; 69 virtual void get_referenced_ptrs(std::vector<const Variable*>& ptrs) const; 70 get_complexity(void)71 virtual unsigned int get_complexity(void) const { return 1;} 72 73 virtual bool visit_facts(vector<const Fact*>& inputs, CGContext& cg_context) const; 74 75 virtual const Type &get_type(void) const; 76 77 virtual bool compatible(const Expression *exp) const; 78 79 virtual bool compatible(const Variable *v) const; 80 use_var(const Variable * v)81 virtual bool use_var(const Variable* v) const { return v == &var;} 82 83 virtual void Output(std::ostream &) const; 84 85 private: 86 explicit ExpressionVariable(const ExpressionVariable &expr); 87 88 const Variable &var; 89 90 const Type* type; 91 92 // unimplementable 93 ExpressionVariable &operator=(const ExpressionVariable &ev); 94 }; 95 96 /////////////////////////////////////////////////////////////////////////////// 97 98 #endif // EXPRESSION_VARIABLE_H 99 100 // Local Variables: 101 // c-basic-offset: 4 102 // tab-width: 4 103 // End: 104 105 // End of file. 106