File indexing completed on 2024-12-08 11:06:54

0001 /***************************************************************************
0002  *   Copyright (C) 2003 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 "varassignment.h"
0012 
0013 #include "flowcode.h"
0014 #include "libraryitem.h"
0015 #include "icndocument.h"
0016 
0017 #include <KLocalizedString>
0018 
0019 Item *VarAssignment::construct(ItemDocument *itemDocument, bool newItem, const char *id)
0020 {
0021     return new VarAssignment(static_cast<ICNDocument *>(itemDocument), newItem, id);
0022 }
0023 
0024 LibraryItem *VarAssignment::libraryItem()
0025 {
0026     return new LibraryItem(QStringList(QString("flow/varassignment")), i18n("Assignment"), i18n("Variables"), "assignment.png", LibraryItem::lit_flowpart, VarAssignment::construct);
0027 }
0028 
0029 VarAssignment::VarAssignment(ICNDocument *icnDocument, bool newItem, const char *id)
0030     : FlowPart(icnDocument, newItem, id ? id : "varassignment")
0031 {
0032     m_name = i18n("Variable Assignment");
0033     initProcessSymbol();
0034     createStdInput();
0035     createStdOutput();
0036 
0037     createProperty("0-var1", Variant::Type::VarName);
0038     property("0-var1")->setCaption(i18n("Variable"));
0039     property("0-var1")->setValue("x");
0040 
0041     createProperty("2-var2", Variant::Type::Combo);
0042     property("2-var2")->setToolbarCaption(" = ");
0043     property("2-var2")->setEditorCaption(i18n("Value"));
0044     property("2-var2")->setValue("0");
0045 }
0046 
0047 VarAssignment::~VarAssignment()
0048 {
0049 }
0050 
0051 void VarAssignment::dataChanged()
0052 {
0053     setCaption(dataString("0-var1") + " " + "=" /*dataString("1-op")*/ + " " + dataString("2-var2"));
0054 }
0055 
0056 void VarAssignment::generateMicrobe(FlowCode *code)
0057 {
0058     code->addCode(dataString("0-var1") + " " + "=" /*dataString("1-op")*/ + " " + dataString("2-var2"));
0059     code->addCodeBranch(outputPart("stdoutput"));
0060 
0061 #if 0
0062     QString var1 = dataString("0-var1");
0063     QString var2 = dataString("2-var2");
0064     QString op = dataString("1-op");
0065     
0066     if ( FlowCode::isLiteral(var1) ) return;
0067     code->addVariable(var1);
0068     
0069     QString newCode;
0070     
0071     if ( !FlowCode::isLiteral(var1) )
0072     {
0073         if ( FlowCode::isLiteral(var2) ) newCode += "movlw " + var2 + " ; Assign " + var2 + " to w register\n";
0074     }
0075     
0076     if ( !FlowCode::isLiteral(var2) )
0077     {
0078         code->addVariable(var2);
0079         newCode += "movf " + var2 + ",0 ; Move " + var2 + " to w register\n";
0080     }
0081     
0082     if      ( op == "=" ) newCode += "movwf " + var1 + " ; Move contents of w register to " + var1 + "\n";
0083     else if ( op == "+=" ) newCode += "addwf " + var1 + ",1 ; Add contents of w register to " + var1 + " and place result back in " + var1 + "\n";
0084     else if ( op == "-=" ) newCode += "subwf " + var1 + ",1 ; Subtract contents of w register from " + var1 + " and place result back in " + var1 + "\n";
0085     else if ( op == "&=" ) newCode += "andwf " + var1 + ",1 ; Binary AND contents of w register with " + var1 + " and place result back in " + var1 + "\n";
0086     else if ( op == "or=" ) newCode += "iorwf " + var1 + ",1 ; Binary inclusive OR contents of w register with " + var1 + " and place result back in " + var1 + "\n";
0087     else if ( op == "xor=" ) newCode += "xorwf " + var1 + ",1 ; Binary exclusive OR contents of w register with " + var1 + " and place result back in " + var1 + "\n";
0088     
0089     newCode += gotoCode("stdoutput");
0090     
0091     code->addCodeBlock( id(), newCode );
0092 #endif
0093 }