varassignment.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003 by David Saxton                                    *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "varassignment.h"
00012 
00013 #include "libraryitem.h"
00014 #include "flowcode.h"
00015 
00016 #include <klocale.h>
00017 
00018 Item* VarAssignment::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00019 {
00020         return new VarAssignment( (ICNDocument*)itemDocument, newItem, id );
00021 }
00022 
00023 LibraryItem* VarAssignment::libraryItem()
00024 {
00025         return new LibraryItem(
00026                 QString::QString("flow/varassignment"),
00027                 i18n("Assignment"),
00028                 i18n("Variables"),
00029                 "assignment.png",
00030                 LibraryItem::lit_flowpart,
00031                 VarAssignment::construct );
00032 }
00033 
00034 VarAssignment::VarAssignment( ICNDocument *icnDocument, bool newItem, const char *id )
00035         : FlowPart( icnDocument, newItem, (id) ? id : "varassignment" )
00036 {
00037         m_name = i18n("Variable Assignment");
00038         m_desc = i18n("Assigns the evaluation of an expression to a variable. The expression can take many forms. For example:<ul><li><b>x = 2</b></li><li><b>x = y + 3</b></li><li><b>x = y + z</b></li><li><b>x = 2 * y</b></ul>");
00039         initProcessSymbol();
00040         createStdInput();
00041         createStdOutput();
00042         
00043         createProperty( "0-var1", Variant::Type::VarName );
00044         property("0-var1")->setCaption( i18n("Variable") );
00045         property("0-var1")->setValue("x");
00046         
00047         createProperty( "2-var2", Variant::Type::Combo );
00048         property("2-var2")->setToolbarCaption(" = ");
00049         property("2-var2")->setEditorCaption( i18n("Value") );
00050         property("2-var2")->setValue("0");
00051         
00052 }
00053 
00054 VarAssignment::~VarAssignment()
00055 {
00056 }
00057 
00058 void VarAssignment::dataChanged()
00059 {
00060         setCaption( dataString("0-var1") + " " + "=" /*dataString("1-op")*/ + " " + dataString("2-var2") );
00061 }
00062 
00063 void VarAssignment::generateMicrobe( FlowCode *code )
00064 {
00065         code->addCode( dataString("0-var1")+" "+"="/*dataString("1-op")*/+" "+dataString("2-var2") );
00066         code->addCodeBranch( outputPart("stdoutput") );
00067 
00068 #if 0
00069         QString var1 = dataString("0-var1");
00070         QString var2 = dataString("2-var2");
00071         QString op = dataString("1-op");
00072         
00073         if ( FlowCode::isLiteral(var1) ) return;
00074         code->addVariable(var1);
00075         
00076         QString newCode;
00077         
00078         if ( !FlowCode::isLiteral(var1) )
00079         {
00080                 if ( FlowCode::isLiteral(var2) ) newCode += "movlw " + var2 + " ; Assign " + var2 + " to w register\n";
00081         }
00082         
00083         if ( !FlowCode::isLiteral(var2) )
00084         {
00085                 code->addVariable(var2);
00086                 newCode += "movf " + var2 + ",0 ; Move " + var2 + " to w register\n";
00087         }
00088         
00089         if              ( op == "=" ) newCode += "movwf " + var1 + " ; Move contents of w register to " + var1 + "\n";
00090         else if ( op == "+=" ) newCode += "addwf " + var1 + ",1 ; Add contents of w register to " + var1 + " and place result back in " + var1 + "\n";
00091         else if ( op == "-=" ) newCode += "subwf " + var1 + ",1 ; Subtract contents of w register from " + var1 + " and place result back in " + var1 + "\n";
00092         else if ( op == "&=" ) newCode += "andwf " + var1 + ",1 ; Binary AND contents of w register with " + var1 + " and place result back in " + var1 + "\n";
00093         else if ( op == "or=" ) newCode += "iorwf " + var1 + ",1 ; Binary inclusive OR contents of w register with " + var1 + " and place result back in " + var1 + "\n";
00094         else if ( op == "xor=" ) newCode += "xorwf " + var1 + ",1 ; Binary exclusive OR contents of w register with " + var1 + " and place result back in " + var1 + "\n";
00095         
00096         newCode += gotoCode("stdoutput");
00097         
00098         code->addCodeBlock( id(), newCode );
00099 #endif
00100 }

Generated on Tue May 8 17:05:33 2007 for KTechLab by  doxygen 1.5.1