Inferno
0.2
|
00001 #include "steps/to_sc_method.hpp" 00002 #include "tree/cpptree.hpp" 00003 #include "tree/sctree.hpp" 00004 #include "common/common.hpp" 00005 #include "sr/soft_patterns.hpp" 00006 #include "tree/typeof.hpp" 00007 #include "tree/misc.hpp" 00008 #include "inferno_patterns.hpp" 00009 00010 using namespace CPPTree; 00011 using namespace SCTree; 00012 using namespace Steps; 00013 00014 AutosToModule::AutosToModule() 00015 { 00016 MakeTreePtr<Scope> rec; 00017 MakeTreePtr< Star<Declaration> > decls, vdecls; 00018 MakeTreePtr< Star<Statement> > vstmts; 00019 MakeTreePtr<Automatic> s_var; 00020 MakeTreePtr<Field> fn, r_var; 00021 MakeTreePtr<Callable> ft; 00022 MakeTreePtr< Stuff<Initialiser> > stuff; 00023 MakeTreePtr<Compound> s_comp, r_comp; 00024 MakeTreePtr< Overlay<Compound> > over; 00025 MakeTreePtr< Star<Base> > bases; 00026 MakeTreePtr<Type> type; 00027 MakeTreePtr<InstanceIdentifier> var_id; 00028 MakeTreePtr<Initialiser> init; 00029 MakeTreePtr< MatchAll<Compound> > s_all; 00030 MakeTreePtr< NotMatch<Compound> > sx_not; 00031 MakeTreePtr< Stuff<Compound> > sx_stuff; 00032 MakeTreePtr<Call> sx_call; 00033 MakeTreePtr< Insert<Declaration> > insert; 00034 00035 rec->members = (decls, fn, insert); 00036 fn->type = ft; 00037 fn->initialiser = stuff; 00038 // TODO recurse restriction for locally declared classes 00039 stuff->terminus = over; 00040 over->through = s_all; 00041 s_all->patterns = (sx_not, s_comp); 00042 sx_not->pattern = sx_stuff; 00043 sx_stuff->terminus = sx_call; 00044 s_comp->members = (vdecls, s_var); 00045 s_comp->statements = (vstmts); 00046 s_var->type = type; 00047 s_var->identifier = var_id; 00048 s_var->initialiser = init; 00049 00050 insert->insert = (r_var); 00051 over->overlay = r_comp; 00052 r_comp->members = (vdecls); 00053 r_comp->statements = (vstmts); 00054 r_var->type = type; 00055 r_var->identifier = var_id; 00056 r_var->initialiser = init; 00057 r_var->virt = MakeTreePtr<NonVirtual>(); 00058 r_var->access = MakeTreePtr<Private>(); 00059 r_var->constancy = MakeTreePtr<NonConst>(); 00060 00061 Configure( rec ); 00062 } 00063 00064 00065 TempsAndStaticsToModule::TempsAndStaticsToModule() 00066 { 00067 MakeTreePtr<Scope> rec; 00068 MakeTreePtr< Star<Declaration> > decls, vdecls; 00069 MakeTreePtr< Star<Statement> > vstmts; 00070 MakeTreePtr< MatchAny<Instance> > var; 00071 MakeTreePtr<Temporary> tempvar; 00072 MakeTreePtr<Static> staticvar; 00073 MakeTreePtr<Field> fn; 00074 MakeTreePtr<Thread> ft; 00075 MakeTreePtr< Stuff<Initialiser> > stuff; 00076 MakeTreePtr<Compound> s_comp, r_comp; 00077 MakeTreePtr< Overlay<Compound> > over; 00078 MakeTreePtr< Star<Base> > bases; 00079 MakeTreePtr<Type> type; 00080 MakeTreePtr<InstanceIdentifier> var_id; 00081 MakeTreePtr<Initialiser> init; 00082 MakeTreePtr< Insert<Declaration> > insert; 00083 00084 rec->members = (decls, fn, insert); 00085 fn->type = ft; 00086 fn->initialiser = stuff; 00087 // TODO recurse restriction for locally declared classes 00088 stuff->terminus = over; 00089 over->through = s_comp; 00090 s_comp->members = (vdecls, var); 00091 s_comp->statements = (vstmts); 00092 var->patterns = (tempvar, staticvar); 00093 00094 insert->insert = (var); 00095 over->overlay = r_comp; 00096 r_comp->members = (vdecls); 00097 r_comp->statements = (vstmts); 00098 00099 Configure( rec ); 00100 } 00101 00102 00103 DeclsToModule::DeclsToModule() 00104 { 00105 MakeTreePtr<Scope> rec; 00106 MakeTreePtr< Star<Declaration> > decls, vdecls; 00107 MakeTreePtr< Star<Statement> > vstmts; 00108 MakeTreePtr<Field> fn; 00109 MakeTreePtr<UserType> ut; 00110 MakeTreePtr<Thread> ft; 00111 MakeTreePtr< Stuff<Initialiser> > stuff; 00112 MakeTreePtr<Compound> s_comp, r_comp; 00113 MakeTreePtr< Overlay<Compound> > over; 00114 MakeTreePtr< Star<Base> > bases; 00115 MakeTreePtr< Insert<Declaration> > insert; 00116 00117 rec->members = (decls, fn, insert); 00118 fn->type = ft; 00119 fn->initialiser = stuff; 00120 // TODO recurse restriction for locally declared classes 00121 stuff->terminus = over; 00122 over->through = s_comp; 00123 s_comp->members = (vdecls, ut); 00124 s_comp->statements = (vstmts); 00125 00126 insert->insert = (ut); 00127 over->overlay = r_comp; 00128 r_comp->members = (vdecls); 00129 r_comp->statements = (vstmts); 00130 00131 Configure( rec ); 00132 } 00133 00134 00135 ThreadToMethod::ThreadToMethod() 00136 { 00137 MakeTreePtr<Instance> s_thread, r_method; 00138 MakeTreePtr<Thread> s_thread_type; 00139 MakeTreePtr<Method> r_method_type; 00140 MakeTreePtr<Compound> s_comp, loop_comp; 00141 MakeTreePtr<InstanceIdentifier> id; 00142 MakeTreePtr<Do> s_loop; 00143 MakeTreePtr<True> s_loop_cond; 00144 MakeTreePtr< Star<Declaration> > loop_decls; 00145 MakeTreePtr< Star<Statement> > loop_stmts; 00146 MakeTreePtr<WaitDynamic> ls_wait_dynamic; 00147 MakeTreePtr<NextTriggerDynamic> lr_nt_dynamic; 00148 MakeTreePtr<WaitStatic> ms_wait_static; 00149 MakeTreePtr<NextTriggerStatic> mr_nt_static; 00150 MakeTreePtr<WaitDelta> ns_wait_delta; 00151 MakeTreePtr<NextTriggerDelta> nr_nt_delta; 00152 MakeTreePtr<Continue> os_continue; 00153 MakeTreePtr<Return> or_return; 00154 MakeTreePtr<Uninitialised> or_retval; 00155 MakeTreePtr<Expression> l_event; 00156 00157 or_return->return_value = or_retval; 00158 00159 MakeTreePtr< SlaveSearchReplace<Compound> > slaveo( loop_comp, os_continue, or_return); 00160 MakeTreePtr< SlaveSearchReplace<Compound> > slaven( slaveo, ns_wait_delta, nr_nt_delta); 00161 MakeTreePtr< SlaveSearchReplace<Compound> > slavem( slaven, ms_wait_static, mr_nt_static); 00162 MakeTreePtr< SlaveSearchReplace<Compound> > slavel( slavem, ls_wait_dynamic, lr_nt_dynamic); 00163 00164 s_thread->type = s_thread_type; 00165 s_thread->initialiser = s_comp; 00166 s_thread->identifier = id; 00167 // s_comp->members = (); important - locals in the body scope not allowed, they would lose their values every itheration in SC_METHOD 00168 s_comp->statements = s_loop; 00169 s_loop->condition = s_loop_cond; 00170 s_loop->body = loop_comp; 00171 loop_comp->members = (loop_decls); 00172 loop_comp->statements = (loop_stmts); 00173 r_method->type = r_method_type; 00174 r_method->initialiser = slavel; 00175 r_method->identifier = id; 00176 00177 ls_wait_dynamic->event = l_event; 00178 lr_nt_dynamic->event = l_event; 00179 00180 Configure( s_thread, r_method ); 00181 } 00182 00183 00184 ExplicitiseReturns::ExplicitiseReturns() 00185 { 00186 MakeTreePtr<Instance> inst; 00187 MakeTreePtr<Callable> s_callable; 00188 MakeTreePtr<Compound> comp, m_comp; 00189 MakeTreePtr< MatchAll<Instance> > s_all; 00190 MakeTreePtr< Stuff<Instance> > s_stuff; 00191 MakeTreePtr<Return> s_return, ls_return, m_return; 00192 MakeTreePtr< Star<Declaration> > decls, m_decls; 00193 MakeTreePtr< Star<Statement> > stmts, m_pre, m_mid, m_post; 00194 MakeTreePtr< Insert<Declaration> > insert; 00195 MakeTreePtr<Temporary> r_flag; 00196 MakeTreePtr<Boolean> r_boolean; 00197 MakeTreePtr<BuildInstanceIdentifier> r_flag_id("enabled"); 00198 MakeTreePtr<False> lr_false; 00199 MakeTreePtr<True> r_true; 00200 MakeTreePtr<Uninitialised> s_uninit, ls_uninit, m_uninit; 00201 MakeTreePtr<Assign> lr_assign; 00202 MakeTreePtr< Stuff<Statement> > m_stuff; 00203 MakeTreePtr< NotMatch<Statement> > ms_affected; 00204 MakeTreePtr<If> ms_if, mr_if; 00205 MakeTreePtr< Overlay<Statement> > m_over; 00206 00207 m_comp->members = (m_decls); 00208 m_comp->statements = (m_pre, m_stuff, m_mid, m_over, m_post); 00209 m_stuff->terminus = m_return; 00210 m_return->return_value = m_uninit; 00211 m_over->through = ms_affected; 00212 ms_affected->pattern = ms_if; 00213 ms_if->condition = r_flag_id; 00214 m_over->overlay = mr_if; 00215 mr_if->condition = r_flag_id; 00216 mr_if->body = ms_affected; 00217 mr_if->else_body = MakeTreePtr<Nop>(); 00218 00219 MakeTreePtr< SlaveSearchReplace<Compound> > slavem( comp, m_comp ); 00220 00221 ls_return->return_value = ls_uninit; 00222 lr_assign->operands = (r_flag_id, lr_false); 00223 00224 MakeTreePtr< SlaveSearchReplace<Compound> > slavel( slavem, ls_return, lr_assign); 00225 00226 s_all->patterns = (inst, s_stuff); 00227 inst->type = s_callable; // TODO when functions are sorted out, set return type to void 00228 inst->initialiser = slavel; 00229 s_stuff->terminus = s_return; 00230 s_return->return_value = s_uninit; 00231 comp->members = (decls, insert); 00232 comp->statements = (stmts); 00233 insert->insert = r_flag; 00234 r_flag->type = r_boolean; 00235 r_flag->identifier = r_flag_id; 00236 r_flag->initialiser = r_true; 00237 00238 Configure( s_all, inst ); 00239 }