Inferno
0.2
|
00001 #include "split_instance_declarations.hpp" 00002 #include "tree/cpptree.hpp" 00003 #include "inferno_patterns.hpp" 00004 00005 using namespace CPPTree; 00006 using namespace Steps; 00007 00008 // TODO these to go in a container of transformations, and rename better 00009 00010 SplitInstanceDeclarations::SplitInstanceDeclarations() 00011 { 00012 // Match a compound with an ini9tialised decl in the statements. Replace 00013 // with an uninitialised decl and an assign. Put the new decl in the 00014 // decls section of the compound. 00015 MakeTreePtr<Compound> sc; 00016 MakeTreePtr<LocalVariable> si; 00017 MakeTreePtr< Overlay<LocalVariable> > over; 00018 si->identifier = MakeTreePtr<InstanceIdentifier>(); // Only acting on initialised Instances 00019 si->initialiser = MakeTreePtr<Expression>(); // Only acting on initialised Instances 00020 MakeTreePtr< Star<Declaration> > decls; 00021 sc->members = ( decls ); 00022 MakeTreePtr< Star<Statement> > pre, post; 00023 sc->statements = ( pre, over, post ); 00024 00025 MakeTreePtr<Compound> rc; 00026 MakeTreePtr<LocalVariable> ri; 00027 over->through = si; 00028 over->overlay = ri; 00029 ri->initialiser = MakeTreePtr<Uninitialised>(); 00030 rc->members = ( over, decls ); 00031 MakeTreePtr<Assign> ra; 00032 ra->operands = ( si->identifier, si->initialiser ); 00033 rc->statements = ( pre, ra, post ); 00034 00035 Configure(sc, rc); 00036 } 00037 00038 00039 MoveInstanceDeclarations::MoveInstanceDeclarations() 00040 { 00041 // Just move the decl to the decls collection 00042 MakeTreePtr<Compound> sc; 00043 MakeTreePtr<LocalVariable> var; 00044 MakeTreePtr< Star<Declaration> > decls; 00045 sc->members = ( decls ); 00046 MakeTreePtr< Star<Statement> > pre, post; 00047 sc->statements = ( pre, var, post ); 00048 00049 MakeTreePtr<Compound> rc; 00050 rc->members = ( var, decls ); // Instance now in unordered decls part 00051 rc->statements = ( pre, post ); 00052 00053 Configure(sc, rc); 00054 } 00055 00056 00057 SplitInstanceDeclarations2::SplitInstanceDeclarations2() 00058 { 00059 // Match a compound with an ini9tialised decl in the statements. Replace 00060 // with an uninitialised decl and an assign. Put the new decl in the 00061 // decls section of the compound. 00062 MakeTreePtr<Compound> sc; 00063 MakeTreePtr<LocalVariable> si; 00064 MakeTreePtr< Overlay<LocalVariable> > over; 00065 si->identifier = MakeTreePtr<InstanceIdentifier>(); // Only acting on initialised Instances 00066 si->initialiser = MakeTreePtr<Expression>(); // Only acting on initialised Instances 00067 MakeTreePtr< Star<Declaration> > decls; 00068 sc->members = ( decls, over ); 00069 MakeTreePtr< Star<Statement> > stmts; 00070 sc->statements = ( stmts ); 00071 00072 MakeTreePtr<Compound> rc; 00073 MakeTreePtr<LocalVariable> ri; 00074 over->through = si; 00075 over->overlay = ri; 00076 ri->initialiser = MakeTreePtr<Uninitialised>(); 00077 rc->members = ( over, decls ); 00078 MakeTreePtr<Assign> ra; 00079 ra->operands = ( si->identifier, si->initialiser ); 00080 rc->statements = ( ra, stmts ); 00081 00082 Configure(sc, rc); 00083 } 00084 00085 00086 00087