00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #ifndef SHSTATEMENT_HPP
00028 #define SHSTATEMENT_HPP
00029
00030 #include <iosfwd>
00031 #include <set>
00032 #include <list>
00033 #include "ShOperation.hpp"
00034 #include "ShDllExport.hpp"
00035 #include "ShVariable.hpp"
00036
00037 namespace SH {
00038
00042 class
00043 SH_DLLEXPORT
00044 ShStatementInfo {
00045 public:
00046 virtual ~ShStatementInfo();
00047
00048 virtual ShStatementInfo* clone() const = 0;
00049
00050 protected:
00051 ShStatementInfo();
00052
00053 };
00054
00063 class
00064 SH_DLLEXPORT ShStatement {
00065 public:
00066 ShStatement(ShVariable dest, ShOperation op);
00067 ShStatement(ShVariable dest, ShOperation op, ShVariable src);
00068 ShStatement(ShVariable dest, ShVariable src0, ShOperation op, ShVariable src1);
00069 ShStatement(ShVariable dest, ShOperation op, ShVariable src0, ShVariable src1, ShVariable src2);
00070 ShStatement(const ShStatement& other);
00071
00072 ~ShStatement();
00073
00074 ShStatement& operator=(const ShStatement& other);
00075
00076
00077 ShVariable dest;
00078 ShVariable src[3];
00079
00080 ShOperation op;
00081
00082
00083
00084
00085 std::list<ShStatementInfo*> info;
00086
00087
00088
00089 template<typename T>
00090 T* get_info();
00091
00092
00093 template<typename T>
00094 void destroy_info();
00095
00096
00097 void add_info(ShStatementInfo* new_info);
00098
00099
00100
00101 void remove_info(ShStatementInfo* old_info);
00102
00103 bool marked;
00104
00105 friend SH_DLLEXPORT std::ostream& operator<<(std::ostream& out, const SH::ShStatement& stmt);
00106 };
00107
00108
00109 template<typename T>
00110 T* ShStatement::get_info()
00111 {
00112 for (std::list<ShStatementInfo*>::iterator I = info.begin(); I != info.end(); ++I) {
00113 T* item = dynamic_cast<T*>(*I);
00114 if (item) {
00115 return item;
00116 }
00117 }
00118 return 0;
00119 }
00120
00121 template<typename T>
00122 void ShStatement::destroy_info()
00123 {
00124 for (std::list<ShStatementInfo*>::iterator I = info.begin(); I != info.end();) {
00125 T* item = dynamic_cast<T*>(*I);
00126 if (item) {
00127 I = info.erase(I);
00128 delete item;
00129 } else {
00130 ++I;
00131 }
00132 }
00133 }
00134
00135 }
00136
00137 #endif