00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "unary.h"
00012
00013 #include "libraryitem.h"
00014 #include "flowcode.h"
00015
00016 #include <klocale.h>
00017
00018 Item* Unary::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00019 {
00020 return new Unary( (ICNDocument*)itemDocument, newItem, id );
00021 }
00022
00023 LibraryItem* Unary::libraryItem()
00024 {
00025 return new LibraryItem(
00026 QString("flow/unary"),
00027 i18n("Unary"),
00028 i18n("Variables"),
00029 "unary.png",
00030 LibraryItem::lit_flowpart,
00031 Unary::construct );
00032 }
00033
00034 Unary::Unary( ICNDocument *icnDocument, bool newItem, const char *id )
00035 : FlowPart( icnDocument, newItem, (id) ? id : "unary" )
00036 {
00037 m_name = i18n("Unary");
00038 m_desc = i18n("A unary operation involves only one variable. Suppo operations are:<br><ul><li><b>Rotate Left</b> rotates the binary bits of the variable left (discarding the end bits).</li><li><b>Rotate Right</b> rotates the binary bits right (discarding the start bits).</li><li><b>Increment</b> increases the value of the variable by 1. A value of 255 wraps around to 0.</li><li><b>Decrement</b> decreases the value of a variable by 1. A value of 0 wraps around to 255.</li></ul>");
00039 initProcessSymbol();
00040 createStdInput();
00041 createStdOutput();
00042
00043 createProperty( "0-var", Variant::Type::VarName );
00044 property("0-var")->setValue("x");
00045 property("0-var")->setCaption( i18n("Variable") );
00046
00047 createProperty( "1-op", Variant::Type::Select );
00048 property("1-op")->setCaption( i18n("Operation") );
00049 property("1-op")->setAllowed( QStringList::split( ',', "Rotate Left,Rotate Right,Increment,Decrement" ) );
00050 property("1-op")->setValue("Rotate Left");
00051 }
00052
00053 Unary::~Unary()
00054 {
00055 }
00056
00057 void Unary::dataChanged()
00058 {
00059 setCaption( dataString("0-var") + " " + dataString("1-op") );
00060 }
00061
00062 void Unary::generateMicrobe( FlowCode *code )
00063 {
00064 const QString var = dataString("0-var");
00065 const QString op = dataString("1-op");
00066
00067 if ( op == "Rotate Left" ) code->addCode( "rotateleft "+var );
00068 else if ( op == "Rotate Right" ) code->addCode( "rotateright "+var );
00069 else if ( op == "Increment" ) code->addCode( "increment "+var );
00070 else if ( op == "Decrement" ) code->addCode( "decrement "+var );
00071 else;
00072 code->addCodeBranch( outputPart("stdoutput") );
00073
00074 #if 0
00075 QString rot = dataString("1-rot");
00076
00077 if ( FlowCode::isLiteral(var) ) return;
00078
00079 QString newCode;
00080
00081 code->addVariable(var);
00082 if ( rot == "Left" ) newCode += "rlf " + var + ",1 ; Unary " + var + " left through Carry, place result back in " + var + "\n";
00083 else newCode += "rrf " + var + ",1 ; Unary " + var + " right through Carry, place result back in " + var + "\n";
00084
00085 newCode += gotoCode("stdoutput");
00086 code->addCodeBlock( id(), newCode );
00087 #endif
00088 }
00089
00090