File indexing completed on 2024-12-08 11:06:54
0001 /*************************************************************************** 0002 * Copyright (C) 2003-2004 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #include "unary.h" 0012 0013 #include "flowcode.h" 0014 #include "libraryitem.h" 0015 #include "icndocument.h" 0016 0017 #include <KLocalizedString> 0018 0019 Item *Unary::construct(ItemDocument *itemDocument, bool newItem, const char *id) 0020 { 0021 return new Unary(static_cast<ICNDocument *>(itemDocument), newItem, id); 0022 } 0023 0024 LibraryItem *Unary::libraryItem() 0025 { 0026 return new LibraryItem(QStringList(QString("flow/unary")), i18n("Unary"), i18n("Variables"), "unary.png", LibraryItem::lit_flowpart, Unary::construct); 0027 } 0028 0029 Unary::Unary(ICNDocument *icnDocument, bool newItem, const char *id) 0030 : FlowPart(icnDocument, newItem, id ? id : "unary") 0031 { 0032 m_name = i18n("Unary"); 0033 initProcessSymbol(); 0034 createStdInput(); 0035 createStdOutput(); 0036 0037 createProperty("0-var", Variant::Type::VarName); 0038 property("0-var")->setValue("x"); 0039 property("0-var")->setCaption(i18n("Variable")); 0040 0041 createProperty("1-op", Variant::Type::Select); 0042 property("1-op")->setCaption(i18n("Operation")); 0043 QStringMap allowed; 0044 allowed["Rotate Left"] = i18n("Rotate Left"); 0045 allowed["Rotate Right"] = i18n("Rotate Right"); 0046 allowed["Increment"] = i18n("Increment"); 0047 allowed["Decrement"] = i18n("Decrement"); 0048 property("1-op")->setAllowed(allowed); 0049 property("1-op")->setValue("Rotate Left"); 0050 } 0051 0052 Unary::~Unary() 0053 { 0054 } 0055 0056 void Unary::dataChanged() 0057 { 0058 setCaption(dataString("0-var") + " " + dataString("1-op")); 0059 } 0060 0061 void Unary::generateMicrobe(FlowCode *code) 0062 { 0063 const QString var = dataString("0-var"); 0064 const QString op = dataString("1-op"); 0065 0066 if (op == "Rotate Left") 0067 code->addCode("rotateleft " + var); 0068 else if (op == "Rotate Right") 0069 code->addCode("rotateright " + var); 0070 else if (op == "Increment") 0071 code->addCode("increment " + var); 0072 else if (op == "Decrement") 0073 code->addCode("decrement " + var); 0074 // else; // Hmm... 0075 code->addCodeBranch(outputPart("stdoutput")); 0076 0077 #if 0 0078 QString rot = dataString("1-rot"); 0079 0080 if ( FlowCode::isLiteral(var) ) return; 0081 0082 QString newCode; 0083 0084 code->addVariable(var); 0085 if ( rot == "Left" ) newCode += "rlf " + var + ",1 ; Unary " + var + " left through Carry, place result back in " + var + "\n"; 0086 else newCode += "rrf " + var + ",1 ; Unary " + var + " right through Carry, place result back in " + var + "\n"; 0087 0088 newCode += gotoCode("stdoutput"); 0089 code->addCodeBlock( id(), newCode ); 0090 #endif 0091 }