Browse Source

- class / function documentation.

- misc changes.
cl-refactor
yann300 10 years ago
parent
commit
ab85477987
  1. 10
      mix/AppContext.cpp
  2. 18
      mix/AppContext.h
  3. 22
      mix/AssemblyDebuggerCtrl.cpp
  4. 21
      mix/AssemblyDebuggerCtrl.h
  5. 20
      mix/AssemblyDebuggerModel.cpp
  6. 11
      mix/AssemblyDebuggerModel.h
  7. 12
      mix/CodeEditorExtensionManager.h
  8. 9
      mix/ConstantCompilationCtrl.h
  9. 9
      mix/ConstantCompilationModel.h
  10. 23
      mix/ContractCallDataEncoder.cpp
  11. 14
      mix/ContractCallDataEncoder.h
  12. 10
      mix/DebuggingStateWrapper.cpp
  13. 30
      mix/DebuggingStateWrapper.h
  14. 10
      mix/Extension.h
  15. 6
      mix/KeyEventManager.h
  16. 1
      mix/MixApplication.h
  17. 23
      mix/QBasicNodeDefinition.cpp
  18. 6
      mix/QBasicNodeDefinition.h
  19. 11
      mix/QContractDefinition.cpp
  20. 4
      mix/QContractDefinition.h
  21. 2
      mix/QFunctionDefinition.cpp
  22. 3
      mix/QFunctionDefinition.h
  23. 23
      mix/QVariableDeclaration.cpp
  24. 3
      mix/QVariableDeclaration.h
  25. 6
      mix/QVariableDefinition.h

10
mix/AppContext.cpp

@ -26,7 +26,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QQmlComponent> #include <QQmlComponent>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include "libdevcrypto/FileSystem.h" #include <libdevcrypto/FileSystem.h>
#include "KeyEventManager.h" #include "KeyEventManager.h"
#include "AppContext.h" #include "AppContext.h"
using namespace dev; using namespace dev;
@ -41,7 +41,7 @@ AppContext::AppContext(QQmlApplicationEngine* _engine)
m_applicationEngine = std::unique_ptr<QQmlApplicationEngine>(_engine); m_applicationEngine = std::unique_ptr<QQmlApplicationEngine>(_engine);
m_keyEventManager = std::unique_ptr<KeyEventManager>(new KeyEventManager()); m_keyEventManager = std::unique_ptr<KeyEventManager>(new KeyEventManager());
m_webThree = std::unique_ptr<dev::WebThreeDirect>(new WebThreeDirect(std::string("Mix/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir() + "/Mix", false, {"eth", "shh"})); m_webThree = std::unique_ptr<dev::WebThreeDirect>(new WebThreeDirect(std::string("Mix/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir() + "/Mix", false, {"eth", "shh"}));
m_compiler = std::unique_ptr<CompilerStack>(new CompilerStack()); m_compiler = std::unique_ptr<CompilerStack>(new CompilerStack()); //TODO : to move in a codel model structure.
} }
QQmlApplicationEngine* AppContext::appEngine() QQmlApplicationEngine* AppContext::appEngine()
@ -49,11 +49,6 @@ QQmlApplicationEngine* AppContext::appEngine()
return m_applicationEngine.get(); return m_applicationEngine.get();
} }
dev::eth::Client* AppContext::getEthereumClient()
{
return m_webThree->ethereum();
}
void AppContext::initKeyEventManager(QObject* _res) void AppContext::initKeyEventManager(QObject* _res)
{ {
QObject* mainContent = _res->findChild<QObject*>("mainContent", Qt::FindChildrenRecursively); QObject* mainContent = _res->findChild<QObject*>("mainContent", Qt::FindChildrenRecursively);
@ -81,6 +76,7 @@ void AppContext::setApplicationContext(QQmlApplicationEngine* _engine)
void AppContext::displayMessageDialog(QString _title, QString _message) void AppContext::displayMessageDialog(QString _title, QString _message)
{ {
// TODO : move it in a UI dedicated layer.
QObject* dialogWin = m_applicationEngine.get()->rootObjects().at(0)->findChild<QObject*>("alertMessageDialog", Qt::FindChildrenRecursively); QObject* dialogWin = m_applicationEngine.get()->rootObjects().at(0)->findChild<QObject*>("alertMessageDialog", Qt::FindChildrenRecursively);
QObject* dialogWinComponent = m_applicationEngine.get()->rootObjects().at(0)->findChild<QObject*>("alertMessageDialogContent", Qt::FindChildrenRecursively); QObject* dialogWinComponent = m_applicationEngine.get()->rootObjects().at(0)->findChild<QObject*>("alertMessageDialogContent", Qt::FindChildrenRecursively);
dialogWinComponent->setProperty("source", QString("qrc:/qml/BasicMessage.qml")); dialogWinComponent->setProperty("source", QString("qrc:/qml/BasicMessage.qml"));

18
mix/AppContext.h

@ -28,8 +28,8 @@
#pragma once #pragma once
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include "libsolidity/CompilerStack.h" #include <libsolidity/CompilerStack.h>
#include "libwebthree/WebThree.h" #include <libwebthree/WebThree.h>
#include "KeyEventManager.h" #include "KeyEventManager.h"
namespace dev namespace dev
@ -37,6 +37,9 @@ namespace dev
namespace mix namespace mix
{ {
/**
* @brief Provides access to application scope variable.
*/
class AppContext: public QObject class AppContext: public QObject
{ {
Q_OBJECT Q_OBJECT
@ -44,13 +47,19 @@ class AppContext: public QObject
public: public:
AppContext(QQmlApplicationEngine* _engine); AppContext(QQmlApplicationEngine* _engine);
~AppContext() {} ~AppContext() {}
/// get the current QQmlApplicationEngine instance.
static AppContext* getInstance() { return Instance; } static AppContext* getInstance() { return Instance; }
/// renew QQMLApplicationEngine with a new instance.
static void setApplicationContext(QQmlApplicationEngine* _engine); static void setApplicationContext(QQmlApplicationEngine* _engine);
/// get the current QQMLApplicationEngine instance.
QQmlApplicationEngine* appEngine(); QQmlApplicationEngine* appEngine();
dev::eth::Client* getEthereumClient(); /// initialize KeyEventManager (used to handle key pressed event).
void initKeyEventManager(QObject* _obj); void initKeyEventManager(QObject* _obj);
/// get the current KeyEventManager instance.
KeyEventManager* getKeyEventManager(); KeyEventManager* getKeyEventManager();
/// get the current Compiler instance (used to parse and compile contract code).
dev::solidity::CompilerStack* compiler(); dev::solidity::CompilerStack* compiler();
/// display an alert message.
void displayMessageDialog(QString _title, QString _message); void displayMessageDialog(QString _title, QString _message);
private: private:
@ -61,10 +70,11 @@ private:
std::unique_ptr<solidity::CompilerStack> m_compiler; std::unique_ptr<solidity::CompilerStack> m_compiler;
public slots: public slots:
/// delete the current instance when application quit.
void quitApplication() { delete Instance; } void quitApplication() { delete Instance; }
/// initialize components after the loading of the main QML view.
void resourceLoaded(QObject* _obj, QUrl _url) { Q_UNUSED(_url); initKeyEventManager(_obj); } void resourceLoaded(QObject* _obj, QUrl _url) { Q_UNUSED(_url); initKeyEventManager(_obj); }
}; };
} }
} }

22
mix/AssemblyDebuggerCtrl.cpp

@ -11,7 +11,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file AssemblyDebuggerCtrl.h /** @file AssemblyDebuggerCtrl.cpp
* @author Yann yann@ethdev.com * @author Yann yann@ethdev.com
* @date 2014 * @date 2014
* display opcode debugging. * display opcode debugging.
@ -23,7 +23,7 @@
#include <QQmlContext> #include <QQmlContext>
#include <QModelIndex> #include <QModelIndex>
#include <libdevcore/CommonJS.h> #include <libdevcore/CommonJS.h>
#include "libethereum/Transaction.h" #include <libethereum/Transaction.h>
#include "AssemblyDebuggerModel.h" #include "AssemblyDebuggerModel.h"
#include "AssemblyDebuggerCtrl.h" #include "AssemblyDebuggerCtrl.h"
#include "KeyEventManager.h" #include "KeyEventManager.h"
@ -44,6 +44,7 @@ AssemblyDebuggerCtrl::AssemblyDebuggerCtrl(QTextDocument* _doc): Extension(Exten
qRegisterMetaType<QVariableDeclaration*>("QVariableDeclaration*"); qRegisterMetaType<QVariableDeclaration*>("QVariableDeclaration*");
qRegisterMetaType<AssemblyDebuggerData>("AssemblyDebuggerData"); qRegisterMetaType<AssemblyDebuggerData>("AssemblyDebuggerData");
qRegisterMetaType<DebuggingStatusResult>("DebuggingStatusResult"); qRegisterMetaType<DebuggingStatusResult>("DebuggingStatusResult");
connect(this, SIGNAL(dataAvailable(bool, DebuggingStatusResult, QList<QVariableDefinition*>, QList<QObject*>, AssemblyDebuggerData)), connect(this, SIGNAL(dataAvailable(bool, DebuggingStatusResult, QList<QVariableDefinition*>, QList<QObject*>, AssemblyDebuggerData)),
this, SLOT(updateGUI(bool, DebuggingStatusResult, QList<QVariableDefinition*>, QList<QObject*>, AssemblyDebuggerData)), Qt::QueuedConnection); this, SLOT(updateGUI(bool, DebuggingStatusResult, QList<QVariableDefinition*>, QList<QObject*>, AssemblyDebuggerData)), Qt::QueuedConnection);
@ -77,9 +78,14 @@ void AssemblyDebuggerCtrl::keyPressed(int _key)
deployContract(m_doc->toPlainText()); deployContract(m_doc->toPlainText());
}); });
} }
else if (_key == Qt::Key_F6)
{
m_modelDebugger.get()->resetState();
AppContext::getInstance()->displayMessageDialog(QApplication::tr("State status"), QApplication::tr("State reseted ... need to redeploy contract"));
}
} }
void AssemblyDebuggerCtrl::callContract(dev::mix::TransactionSettings _tr, Address _contract) void AssemblyDebuggerCtrl::callContract(TransactionSettings _tr, Address _contract)
{ {
CompilerResult compilerRes = m_compilation.get()->compile(m_doc->toPlainText()); CompilerResult compilerRes = m_compilation.get()->compile(m_doc->toPlainText());
if (!compilerRes.success) if (!compilerRes.success)
@ -99,7 +105,7 @@ void AssemblyDebuggerCtrl::callContract(dev::mix::TransactionSettings _tr, Addre
} }
if (!f) if (!f)
{ {
AppContext::getInstance()->displayMessageDialog(QApplication::tr("debugger"), QApplication::tr("contract code changed. Please redeploy contract")); AppContext::getInstance()->displayMessageDialog(QApplication::tr("debugger"), QApplication::tr("function not found. Please redeploy this contract."));
return; return;
} }
c.encode(f->index()); c.encode(f->index());
@ -108,7 +114,7 @@ void AssemblyDebuggerCtrl::callContract(dev::mix::TransactionSettings _tr, Addre
QVariableDeclaration* var = (QVariableDeclaration*)f->parameters().at(k); QVariableDeclaration* var = (QVariableDeclaration*)f->parameters().at(k);
c.encode(var, _tr.parameterValues[var->name()]); c.encode(var, _tr.parameterValues[var->name()]);
} }
DebuggingContent debuggingContent = m_modelDebugger->getContractCallDebugStates(_contract, c.encodedData(), _tr); DebuggingContent debuggingContent = m_modelDebugger->callContract(_contract, c.encodedData(), _tr);
debuggingContent.returnParameters = c.decode(f->returnParameters(), debuggingContent.returnValue); debuggingContent.returnParameters = c.decode(f->returnParameters(), debuggingContent.returnValue);
finalizeExecution(debuggingContent); finalizeExecution(debuggingContent);
} }
@ -121,7 +127,7 @@ void AssemblyDebuggerCtrl::deployContract(QString _source)
emit dataAvailable(false, DebuggingStatusResult::Compilationfailed); emit dataAvailable(false, DebuggingStatusResult::Compilationfailed);
return; return;
} }
m_previousDebugResult = m_modelDebugger->getContractInitiationDebugStates(compilerRes.bytes); m_previousDebugResult = m_modelDebugger->deployContract(compilerRes.bytes);
finalizeExecution(m_previousDebugResult); finalizeExecution(m_previousDebugResult);
} }
@ -139,7 +145,7 @@ void AssemblyDebuggerCtrl::finalizeExecution(DebuggingContent _debuggingContent)
emit dataAvailable(true, DebuggingStatusResult::Ok, _debuggingContent.returnParameters, wStates, code); emit dataAvailable(true, DebuggingStatusResult::Ok, _debuggingContent.returnParameters, wStates, code);
} }
void AssemblyDebuggerCtrl::updateGUI(bool _success, DebuggingStatusResult _reason, QList<QVariableDefinition*> _returnParam, QList<QObject*> _wStates, AssemblyDebuggerData _code) void AssemblyDebuggerCtrl::updateGUI(bool _success, DebuggingStatusResult const& _reason, QList<QVariableDefinition*> const& _returnParam, QList<QObject*> const& _wStates, AssemblyDebuggerData const& _code)
{ {
Q_UNUSED(_reason); Q_UNUSED(_reason);
if (_success) if (_success)
@ -154,7 +160,7 @@ void AssemblyDebuggerCtrl::updateGUI(bool _success, DebuggingStatusResult _reaso
m_ctx->displayMessageDialog(QApplication::tr("debugger"), QApplication::tr("compilation failed")); m_ctx->displayMessageDialog(QApplication::tr("debugger"), QApplication::tr("compilation failed"));
} }
void AssemblyDebuggerCtrl::runTransaction(TransactionSettings _tr) void AssemblyDebuggerCtrl::runTransaction(TransactionSettings const& _tr)
{ {
QtConcurrent::run([this, _tr]() QtConcurrent::run([this, _tr]()
{ {

21
mix/AssemblyDebuggerCtrl.h

@ -14,13 +14,13 @@
/** @file AssemblyDebuggerCtrl.h /** @file AssemblyDebuggerCtrl.h
* @author Yann yann@ethdev.com * @author Yann yann@ethdev.com
* @date 2014 * @date 2014
* Display debugging steps in assembly code.s * Extension which display debugging steps in assembly code.
*/ */
#pragma once #pragma once
#include <QKeySequence> #include <QKeySequence>
#include "QTextDocument" #include <QTextDocument>
#include "Extension.h" #include "Extension.h"
#include "ConstantCompilationModel.h" #include "ConstantCompilationModel.h"
#include "TransactionListModel.h" #include "TransactionListModel.h"
@ -43,12 +43,15 @@ namespace dev
namespace mix namespace mix
{ {
/**
* @brief Extension which display transaction creation or transaction call debugging. handle: F5 to deploy contract, F6 to reset state.
*/
class AssemblyDebuggerCtrl: public Extension class AssemblyDebuggerCtrl: public Extension
{ {
Q_OBJECT Q_OBJECT
public: public:
AssemblyDebuggerCtrl(QTextDocument*); AssemblyDebuggerCtrl(QTextDocument* _doc);
~AssemblyDebuggerCtrl() {} ~AssemblyDebuggerCtrl() {}
void start() const override; void start() const override;
QString title() const override; QString title() const override;
@ -61,16 +64,20 @@ private:
std::unique_ptr<AssemblyDebuggerModel> m_modelDebugger; std::unique_ptr<AssemblyDebuggerModel> m_modelDebugger;
std::unique_ptr<ConstantCompilationModel> m_compilation; std::unique_ptr<ConstantCompilationModel> m_compilation;
DebuggingContent m_previousDebugResult; //TODO: to be replaced by more consistent struct. Used for now to keep the contract address in case of future transaction call. DebuggingContent m_previousDebugResult; //TODO: to be replaced in a more consistent struct. Used for now to keep the contract address in case of future transaction call.
QTextDocument* m_doc; QTextDocument* m_doc;
public slots: public slots:
/// handle key pressed. F5 deploy contract - F6 reset state.
void keyPressed(int); void keyPressed(int);
void updateGUI(bool _success, DebuggingStatusResult _reason, QList<QVariableDefinition*> _returnParams = QList<QVariableDefinition*>(), QList<QObject*> _wStates = QList<QObject*>(), AssemblyDebuggerData _code = AssemblyDebuggerData()); /// update UI with machine states result. Display a modal dialog.
void runTransaction(TransactionSettings _tr); void updateGUI(bool _success, DebuggingStatusResult const& _reason, QList<QVariableDefinition*> const& _returnParams = QList<QVariableDefinition*>(), QList<QObject*> const& _wStates = QList<QObject*>(), AssemblyDebuggerData const& _code = AssemblyDebuggerData());
/// run the given transaction.
void runTransaction(TransactionSettings const& _tr);
signals: signals:
void dataAvailable(bool _success, DebuggingStatusResult _reason, QList<QVariableDefinition*> _returnParams = QList<QVariableDefinition*>(), QList<QObject*> _wStates = QList<QObject*>(), AssemblyDebuggerData _code = AssemblyDebuggerData()); /// emited when machine states are available.
void dataAvailable(bool _success, DebuggingStatusResult const& _reason, QList<QVariableDefinition*> const& _returnParams = QList<QVariableDefinition*>(), QList<QObject*> const& _wStates = QList<QObject*>(), AssemblyDebuggerData const& _code = AssemblyDebuggerData());
}; };
} }

20
mix/AssemblyDebuggerModel.cpp

@ -11,7 +11,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file AssemblyDebuggerModel.h /** @file AssemblyDebuggerModel.cpp
* @author Yann yann@ethdev.com * @author Yann yann@ethdev.com
* @date 2014 * @date 2014
* used as a model to debug contract assembly code. * used as a model to debug contract assembly code.
@ -42,13 +42,10 @@ AssemblyDebuggerModel::AssemblyDebuggerModel():
m_currentExecution = std::unique_ptr<Executive>(new Executive(m_executiveState, 0)); m_currentExecution = std::unique_ptr<Executive>(new Executive(m_executiveState, 0));
} }
DebuggingContent AssemblyDebuggerModel::executeTransaction(bytesConstRef _rawTransaction) DebuggingContent AssemblyDebuggerModel::executeTransaction(bytesConstRef const& _rawTransaction)
{ {
QList<DebuggingState> machineStates; QList<DebuggingState> machineStates;
// Reset the state back to our clean premine. m_currentExecution.reset(new Executive(m_executiveState, 0));
m_currentExecution = std::unique_ptr<Executive>(new Executive(m_executiveState, 0));
QList<DebuggingState> states;
m_currentExecution->setup(_rawTransaction); m_currentExecution->setup(_rawTransaction);
std::vector<DebuggingState const*> levels; std::vector<DebuggingState const*> levels;
bytes code; bytes code;
@ -89,12 +86,12 @@ DebuggingContent AssemblyDebuggerModel::executeTransaction(bytesConstRef _rawTra
return d; return d;
} }
DebuggingContent AssemblyDebuggerModel::getContractInitiationDebugStates(bytes _code) DebuggingContent AssemblyDebuggerModel::deployContract(bytes const& _code)
{ {
u256 gasPrice = 10000000000000; u256 gasPrice = 10000000000000;
u256 gas = 1000000; u256 gas = 1000000;
u256 amount = 100; u256 amount = 100;
dev::eth::Transaction _tr(amount, gasPrice, min(gas, m_baseState.gasLimitRemaining()), _code, m_executiveState.transactionsFrom(dev::toAddress(m_userAccount.secret())), m_userAccount.secret()); Transaction _tr(amount, gasPrice, min(gas, m_baseState.gasLimitRemaining()), _code, m_executiveState.transactionsFrom(dev::toAddress(m_userAccount.secret())), m_userAccount.secret());
bytes b = _tr.rlp(); bytes b = _tr.rlp();
dev::bytesConstRef bytesRef = &b; dev::bytesConstRef bytesRef = &b;
DebuggingContent d = executeTransaction(bytesRef); DebuggingContent d = executeTransaction(bytesRef);
@ -103,11 +100,9 @@ DebuggingContent AssemblyDebuggerModel::getContractInitiationDebugStates(bytes _
return d; return d;
} }
DebuggingContent AssemblyDebuggerModel::getContractCallDebugStates(Address _contract, bytes _data, DebuggingContent AssemblyDebuggerModel::callContract(Address const& _contract, bytes const& _data, TransactionSettings const& _tr)
dev::mix::TransactionSettings _tr)
{ {
Transaction tr = Transaction(_tr.value, _tr.gasPrice, min(_tr.gas, m_baseState.gasLimitRemaining()), _contract, _data, m_executiveState.transactionsFrom(dev::toAddress(m_userAccount.secret())), m_userAccount.secret());
dev::eth::Transaction tr = Transaction(_tr.value, _tr.gasPrice, min(_tr.gas, m_baseState.gasLimitRemaining()), _contract, _data, m_executiveState.transactionsFrom(dev::toAddress(m_userAccount.secret())), m_userAccount.secret());
bytes b = tr.rlp(); bytes b = tr.rlp();
dev::bytesConstRef bytesRef = &b; dev::bytesConstRef bytesRef = &b;
DebuggingContent d = executeTransaction(bytesRef); DebuggingContent d = executeTransaction(bytesRef);
@ -117,5 +112,6 @@ DebuggingContent AssemblyDebuggerModel::getContractCallDebugStates(Address _cont
void AssemblyDebuggerModel::resetState() void AssemblyDebuggerModel::resetState()
{ {
// Reset the state back to our clean premine.
m_executiveState = m_baseState; m_executiveState = m_baseState;
} }

11
mix/AssemblyDebuggerModel.h

@ -40,9 +40,11 @@ class AssemblyDebuggerModel
{ {
public: public:
AssemblyDebuggerModel(); AssemblyDebuggerModel();
DebuggingContent getContractCallDebugStates(Address _contract, bytes _data, dev::mix::TransactionSettings _tr); /// call function in a already deployed contract.
DebuggingContent getContractInitiationDebugStates(bytes _code); DebuggingContent callContract(Address const& _contract, bytes const& _data, TransactionSettings const& _tr);
bool compile(QString); /// deploy the contract described by _code.
DebuggingContent deployContract(bytes const& _code);
/// reset state to the base state.
void resetState(); void resetState();
private: private:
@ -51,9 +53,8 @@ private:
eth::State m_baseState; eth::State m_baseState;
eth::State m_executiveState; eth::State m_executiveState;
std::unique_ptr<eth::Executive> m_currentExecution; std::unique_ptr<eth::Executive> m_currentExecution;
DebuggingContent executeTransaction(dev::bytesConstRef _rawTransaction); DebuggingContent executeTransaction(dev::bytesConstRef const& _rawTransaction);
}; };
} }
} }

12
mix/CodeEditorExtensionManager.h

@ -22,7 +22,6 @@
#pragma once #pragma once
#include "memory"
#include <QQuickItem> #include <QQuickItem>
#include <QTextDocument> #include <QTextDocument>
#include <QVector> #include <QVector>
@ -33,6 +32,9 @@ namespace dev
namespace mix namespace mix
{ {
/**
* @brief Init and provides connection between extensions.
*/
class CodeEditorExtensionManager: public QObject class CodeEditorExtensionManager: public QObject
{ {
Q_OBJECT Q_OBJECT
@ -44,10 +46,15 @@ class CodeEditorExtensionManager: public QObject
public: public:
CodeEditorExtensionManager() {} CodeEditorExtensionManager() {}
~CodeEditorExtensionManager(); ~CodeEditorExtensionManager();
/// initialize all extensions.
void initExtensions(); void initExtensions();
/// initialize extension.
void initExtension(std::shared_ptr<Extension>); void initExtension(std::shared_ptr<Extension>);
/// set current text editor.
void setEditor(QQuickItem*); void setEditor(QQuickItem*);
/// set current tab view
void setTabView(QQuickItem*); void setTabView(QQuickItem*);
/// set current right tab view.
void setRightTabView(QQuickItem*); void setRightTabView(QQuickItem*);
private: private:
@ -56,9 +63,8 @@ private:
QQuickItem* m_tabView; QQuickItem* m_tabView;
QQuickItem* m_rightTabView; QQuickItem* m_rightTabView;
QTextDocument* m_doc; QTextDocument* m_doc;
void loadEditor(QQuickItem*); void loadEditor(QQuickItem* _editor);
}; };
} }
} }

9
mix/ConstantCompilationCtrl.h

@ -28,12 +28,15 @@ namespace dev
namespace mix namespace mix
{ {
/**
* @brief Extension which display assembly code of the contract being edited.
*/
class ConstantCompilationCtrl: public Extension class ConstantCompilationCtrl: public Extension
{ {
Q_OBJECT Q_OBJECT
public: public:
ConstantCompilationCtrl(QTextDocument*); ConstantCompilationCtrl(QTextDocument* _doc);
~ConstantCompilationCtrl() {} ~ConstantCompilationCtrl() {}
void start() const override; void start() const override;
QString title() const override; QString title() const override;
@ -42,13 +45,13 @@ public:
private: private:
QTextDocument* m_editor; QTextDocument* m_editor;
std::unique_ptr<ConstantCompilationModel> m_compilationModel; std::unique_ptr<ConstantCompilationModel> m_compilationModel;
void writeOutPut(CompilerResult const&); void writeOutPut(CompilerResult const& _res);
void resetOutPut(); void resetOutPut();
public slots: public slots:
/// compile text editor content.
void compile(); void compile();
}; };
} }
} }

9
mix/ConstantCompilationModel.h

@ -22,15 +22,18 @@
#pragma once #pragma once
#include <QObject>
#include <libevm/VM.h> #include <libevm/VM.h>
#include <libsolidity/AST.h> #include <libsolidity/AST.h>
#include <QObject>
namespace dev namespace dev
{ {
namespace mix namespace mix
{ {
/**
* @brief Provides compiler result information.
*/
struct CompilerResult struct CompilerResult
{ {
QString hexCode; QString hexCode;
@ -39,12 +42,16 @@ struct CompilerResult
bool success; bool success;
}; };
/**
* @brief Compile source code using the solidity library.
*/
class ConstantCompilationModel class ConstantCompilationModel
{ {
public: public:
ConstantCompilationModel() {} ConstantCompilationModel() {}
~ConstantCompilationModel() {} ~ConstantCompilationModel() {}
/// compile code.
CompilerResult compile(QString _code); CompilerResult compile(QString _code);
}; };

23
mix/ContractCallDataEncoder.cpp

@ -24,7 +24,7 @@
#include <QMap> #include <QMap>
#include <QStringList> #include <QStringList>
#include <libdevcore/CommonJS.h> #include <libdevcore/CommonJS.h>
#include "libsolidity/AST.h" #include <libsolidity/AST.h>
#include "QVariableDeclaration.h" #include "QVariableDeclaration.h"
#include "QVariableDefinition.h" #include "QVariableDefinition.h"
#include "ContractCallDataEncoder.h" #include "ContractCallDataEncoder.h"
@ -38,10 +38,6 @@ ContractCallDataEncoder::ContractCallDataEncoder()
bytes ContractCallDataEncoder::encodedData() bytes ContractCallDataEncoder::encodedData()
{ {
std::ostringstream si;
si << std::hex << toJS(m_encodedData);
qDebug() << "encoded data";
qDebug() << si;
return m_encodedData; return m_encodedData;
} }
@ -58,9 +54,6 @@ void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, bool _value)
void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, QString _value) void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, QString _value)
{ {
qDebug() << _dec->type();
qDebug() << _value;
qDebug() << "(())";
int padding = this->padding(_dec->type()); int padding = this->padding(_dec->type());
bytes data = padded(jsToBytes(_value.toStdString()), padding); bytes data = padded(jsToBytes(_value.toStdString()), padding);
m_encodedData.insert(m_encodedData.end(), data.begin(), data.end()); m_encodedData.insert(m_encodedData.end(), data.begin(), data.end());
@ -69,17 +62,9 @@ void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, QString _value)
void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, u256 _value) void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, u256 _value)
{ {
int padding = this->padding(_dec->type()); int padding = this->padding(_dec->type());
qDebug() << _dec->type();
std::ostringstream s; std::ostringstream s;
s << std::hex << "0x" << _value; s << std::hex << "0x" << _value;
qDebug() << QString::fromStdString(s.str());
bytes data = padded(jsToBytes(s.str()), padding); bytes data = padded(jsToBytes(s.str()), padding);
std::ostringstream si;
si << std::hex << toJS(data);
qDebug() << si;
m_encodedData.insert(m_encodedData.end(), data.begin(), data.end()); m_encodedData.insert(m_encodedData.end(), data.begin(), data.end());
encodedData(); encodedData();
} }
@ -88,15 +73,12 @@ QList<QVariableDefinition*> ContractCallDataEncoder::decode(QList<QObject*> _ret
{ {
QList<QVariableDefinition*> r; QList<QVariableDefinition*> r;
std::string returnValue = toJS(_value); std::string returnValue = toJS(_value);
qDebug() << QString::fromStdString(returnValue);
returnValue = returnValue.substr(2, returnValue.length() - 1); returnValue = returnValue.substr(2, returnValue.length() - 1);
for (int k = 0; k <_returnParameters.length(); k++) for (int k = 0; k <_returnParameters.length(); k++)
{ {
QVariableDeclaration* dec = (QVariableDeclaration*)_returnParameters.at(k); QVariableDeclaration* dec = (QVariableDeclaration*)_returnParameters.at(k);
int padding = this->padding(dec->type()); int padding = this->padding(dec->type());
std::string rawParam = returnValue.substr(0, padding * 2); std::string rawParam = returnValue.substr(0, padding * 2);
qDebug() << QString::fromStdString(rawParam);
r.append(new QVariableDefinition(dec, convertToReadable(unpadded(rawParam), dec))); r.append(new QVariableDefinition(dec, convertToReadable(unpadded(rawParam), dec)));
returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1); returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1);
} }
@ -161,10 +143,9 @@ QString ContractCallDataEncoder::convertToInt(std::string _v)
{ {
qDebug() << "QString::fromStdString(_v);"; qDebug() << "QString::fromStdString(_v);";
qDebug() << QString::fromStdString(_v); qDebug() << QString::fromStdString(_v);
//TO DO to be improve to manage all int, uint size (128, 256, ...) //TO DO to be improve to manage all int, uint size (128, 256, ...) in ethereum QML types task #612.
int x = std::stol(_v, nullptr, 16); int x = std::stol(_v, nullptr, 16);
std::stringstream ss; std::stringstream ss;
ss << std::dec << x; ss << std::dec << x;
return QString::fromStdString(ss.str()); return QString::fromStdString(ss.str());
} }

14
mix/ContractCallDataEncoder.h

@ -30,27 +30,35 @@ namespace dev
namespace mix namespace mix
{ {
/**
* @brief encode/decode data to be sent to a transaction or to be displayed in a view.
*/
class ContractCallDataEncoder class ContractCallDataEncoder
{ {
public: public:
ContractCallDataEncoder(); ContractCallDataEncoder();
/// encode variable in order to be sent as parameter.
void encode(QVariableDeclaration* _dec, QString _value); void encode(QVariableDeclaration* _dec, QString _value);
/// encode variable in order to be sent as parameter.
void encode(QVariableDeclaration* _dec, u256 _value); void encode(QVariableDeclaration* _dec, u256 _value);
QList<QVariableDefinition*> decode(QList<QObject*> _dec, bytes _value); /// encode variable in order to be sent as parameter.
void encode(QVariableDeclaration* _dec, bool _value); void encode(QVariableDeclaration* _dec, bool _value);
/// encode index of the function to call.
void encode(int _functionIndex); void encode(int _functionIndex);
/// decode variable in order to be sent to QML view.
QList<QVariableDefinition*> decode(QList<QObject*> _dec, bytes _value);
/// get all encoded data encoded by encode function.
bytes encodedData(); bytes encodedData();
private: private:
QMap<QString, int> typePadding; QMap<QString, int> typePadding;
int padding(QString _type); int padding(QString _type);
bytes m_encodedData;
static QString convertToReadable(std::string _v, QVariableDeclaration* _dec); static QString convertToReadable(std::string _v, QVariableDeclaration* _dec);
static QString convertToBool(std::string _v); static QString convertToBool(std::string _v);
static QString convertToInt(std::string _v); static QString convertToInt(std::string _v);
static int integerPadding(int _bitValue); static int integerPadding(int _bitValue);
static QString formatBool(bool _value); static QString formatBool(bool _value);
bytes m_encodedData;
}; };
} }

10
mix/DebuggingStateWrapper.cpp

@ -23,11 +23,11 @@
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QPointer> #include <QPointer>
#include "libevmcore/Instruction.h" #include <libevmcore/Instruction.h>
#include "libdevcore/CommonJS.h" #include <libdevcore/CommonJS.h>
#include "libdevcrypto/Common.h" #include <libdevcrypto/Common.h>
#include "libevmcore/Instruction.h" #include <libevmcore/Instruction.h>
#include "libdevcore/Common.h" #include <libdevcore/Common.h>
#include "DebuggingStateWrapper.h" #include "DebuggingStateWrapper.h"
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;

30
mix/DebuggingStateWrapper.h

@ -23,9 +23,9 @@
#pragma once #pragma once
#include <QStringList> #include <QStringList>
#include "libethereum/State.h" #include <libdevcore/Common.h>
#include "libethereum/Executive.h" #include <libethereum/State.h>
#include "libdevcore/Common.h" #include <libethereum/Executive.h>
#include "QVariableDefinition.h" #include "QVariableDefinition.h"
namespace dev namespace dev
@ -33,6 +33,9 @@ namespace dev
namespace mix namespace mix
{ {
/**
* @brief Store information about a machine state.
*/
struct DebuggingState struct DebuggingState
{ {
uint64_t steps; uint64_t steps;
@ -48,6 +51,9 @@ struct DebuggingState
std::vector<DebuggingState const*> levels; std::vector<DebuggingState const*> levels;
}; };
/**
* @brief Store information about a machine states.
*/
struct DebuggingContent struct DebuggingContent
{ {
QList<DebuggingState> machineStates; QList<DebuggingState> machineStates;
@ -71,7 +77,9 @@ class HumanReadableCode: public QObject
public: public:
HumanReadableCode(QString _line, int _processIndex): QObject(), m_line(_line), m_processIndex(_processIndex) {} HumanReadableCode(QString _line, int _processIndex): QObject(), m_line(_line), m_processIndex(_processIndex) {}
/// get the assembly code line.
QString line() { return m_line; } QString line() { return m_line; }
/// get corresponding index.
int processIndex() { return m_processIndex; } int processIndex() { return m_processIndex; }
private: private:
@ -89,6 +97,7 @@ class QQMLMap: public QObject
public: public:
QQMLMap(QMap<int, int> _map): QObject(), m_map(_map) { } QQMLMap(QMap<int, int> _map): QObject(), m_map(_map) { }
/// get the value associated with _key store in n_map.
Q_INVOKABLE int getValue(int _key) { return m_map.value(_key); } Q_INVOKABLE int getValue(int _key) { return m_map.value(_key); }
private: private:
@ -116,20 +125,35 @@ class DebuggingStateWrapper: public QObject
public: public:
DebuggingStateWrapper(bytes _code, bytes _data): QObject(), m_code(_code), m_data(_data) {} DebuggingStateWrapper(bytes _code, bytes _data): QObject(), m_code(_code), m_data(_data) {}
/// get the step of this machine states.
int step() { return (int)m_state.steps; } int step() { return (int)m_state.steps; }
/// get the proccessed code.
int curPC() { return (int)m_state.curPC; } int curPC() { return (int)m_state.curPC; }
/// get gas left.
QString gasLeft(); QString gasLeft();
/// get gas cost.
QString gasCost(); QString gasCost();
/// get gas used.
QString gas(); QString gas();
/// get stack.
QString debugStack(); QString debugStack();
/// get storage.
QString debugStorage(); QString debugStorage();
/// get memory.
QString debugMemory(); QString debugMemory();
/// get call data.
QString debugCallData(); QString debugCallData();
/// get info to be displayed in the header.
QString headerInfo(); QString headerInfo();
/// get end of debug information.
QString endOfDebug(); QString endOfDebug();
/// get all previous steps.
QStringList levels(); QStringList levels();
/// get the current processed machine state.
DebuggingState state() { return m_state; } DebuggingState state() { return m_state; }
/// set the current processed machine state.
void setState(DebuggingState _state) { m_state = _state; } void setState(DebuggingState _state) { m_state = _state; }
/// convert all machine state in human readable code.
static std::tuple<QList<QObject*>, QQMLMap*> getHumanReadableCode(bytes const& _code); static std::tuple<QList<QObject*>, QQMLMap*> getHumanReadableCode(bytes const& _code);
private: private:

10
mix/Extension.h

@ -43,12 +43,19 @@ class Extension: public QObject
public: public:
Extension(); Extension();
Extension(ExtensionDisplayBehavior _displayBehavior); Extension(ExtensionDisplayBehavior _displayBehavior);
/// return the QML url of the view to display.
virtual QString contentUrl() const { return ""; } virtual QString contentUrl() const { return ""; }
/// reuturn the title of this extension.
virtual QString title() const { return ""; } virtual QString title() const { return ""; }
/// initialize extension.
virtual void start() const {} virtual void start() const {}
void addContentOn(QObject* _tabView); /// add the view define in contentUrl() in the _view QObject.
void addContentOn(QObject* _view);
/// add the view define in contentUrl() in the _view QObject (_view has to be a tab).
void addTabOn(QObject* _view); void addTabOn(QObject* _view);
/// modify the display behavior of this extension.
void setDisplayBehavior(ExtensionDisplayBehavior _displayBehavior) { m_displayBehavior = _displayBehavior; } void setDisplayBehavior(ExtensionDisplayBehavior _displayBehavior) { m_displayBehavior = _displayBehavior; }
/// get the display behavior of thi extension.
ExtensionDisplayBehavior getDisplayBehavior() { return m_displayBehavior; } ExtensionDisplayBehavior getDisplayBehavior() { return m_displayBehavior; }
protected: protected:
@ -62,5 +69,4 @@ private:
}; };
} }
} }

6
mix/KeyEventManager.h

@ -30,13 +30,17 @@ class KeyEventManager: public QObject
public: public:
KeyEventManager() {} KeyEventManager() {}
/// allows _receiver to handle key pressed event.
void registerEvent(const QObject* _receiver, const char* _slot); void registerEvent(const QObject* _receiver, const char* _slot);
/// unregister _receiver.
void unRegisterEvent(QObject* _receiver); void unRegisterEvent(QObject* _receiver);
signals: signals:
void onKeyPressed(int); /// emited when a key is pressed.
void onKeyPressed(int _event);
public slots: public slots:
/// called when a key is pressed.
void keyPressed(QVariant _event); void keyPressed(QVariant _event);
}; };

1
mix/MixApplication.h

@ -41,5 +41,4 @@ public:
}; };
} }
} }

23
mix/QBasicNodeDefinition.cpp

@ -1,23 +0,0 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file QBasicNodeDefinition.cpp
* @author Yann yann@ethdev.com
* @date 2014
*/
#include "QBasicNodeDefinition.h"

6
mix/QBasicNodeDefinition.h

@ -22,7 +22,7 @@
#pragma once #pragma once
#include <QObject> #include <QObject>
#include "libsolidity/AST.h" #include <libsolidity/AST.h>
namespace dev namespace dev
{ {
@ -36,9 +36,9 @@ class QBasicNodeDefinition: public QObject
public: public:
QBasicNodeDefinition(): QObject() {} QBasicNodeDefinition(): QObject() {}
~QBasicNodeDefinition() { ~QBasicNodeDefinition() {}
}
QBasicNodeDefinition(dev::solidity::Declaration* _d): QObject(), m_dec(_d) {} QBasicNodeDefinition(dev::solidity::Declaration* _d): QObject(), m_dec(_d) {}
/// get the name of the node.
QString name() const { return QString::fromStdString(m_dec->getName()); } QString name() const { return QString::fromStdString(m_dec->getName()); }
protected: protected:

11
mix/QContractDefinition.cpp

@ -20,12 +20,11 @@
*/ */
#include <QObject> #include <QObject>
#include "QContractDefinition.h" #include <libsolidity/AST.h>
#include "libsolidity/AST.h" #include <libsolidity/Scanner.h>
#include "libsolidity/Scanner.h" #include <libsolidity/Parser.h>
#include "libsolidity/Parser.h" #include <libsolidity/Scanner.h>
#include "libsolidity/Scanner.h" #include <libsolidity/NameAndTypeResolver.h>
#include "libsolidity/NameAndTypeResolver.h"
#include "AppContext.h" #include "AppContext.h"
#include "QContractDefinition.h" #include "QContractDefinition.h"
using namespace dev::solidity; using namespace dev::solidity;

4
mix/QContractDefinition.h

@ -22,7 +22,7 @@
#pragma once #pragma once
#include <QObject> #include <QObject>
#include "libsolidity/AST.h" #include <libsolidity/AST.h>
#include "QFunctionDefinition.h" #include "QFunctionDefinition.h"
#include "QBasicNodeDefinition.h" #include "QBasicNodeDefinition.h"
@ -38,7 +38,9 @@ class QContractDefinition: public QBasicNodeDefinition
public: public:
QContractDefinition(dev::solidity::ContractDefinition* _contract); QContractDefinition(dev::solidity::ContractDefinition* _contract);
/// get all the functions of the contract.
QList<QFunctionDefinition*> functions() const { return m_functions; } QList<QFunctionDefinition*> functions() const { return m_functions; }
/// get the description (functions, parameters, return parameters, ...) of the contract describes by _code.
static std::shared_ptr<QContractDefinition> Contract(QString _code); static std::shared_ptr<QContractDefinition> Contract(QString _code);
private: private:

2
mix/QFunctionDefinition.cpp

@ -19,9 +19,9 @@
* @date 2014 * @date 2014
*/ */
#include <libsolidity/AST.h>
#include "QVariableDeclaration.h" #include "QVariableDeclaration.h"
#include "QFunctionDefinition.h" #include "QFunctionDefinition.h"
#include "libsolidity/AST.h"
using namespace dev::solidity; using namespace dev::solidity;
using namespace dev::mix; using namespace dev::mix;

3
mix/QFunctionDefinition.h

@ -38,8 +38,11 @@ class QFunctionDefinition: public QBasicNodeDefinition
public: public:
QFunctionDefinition(dev::solidity::FunctionDefinition* _f, int _index): QBasicNodeDefinition(_f), m_index(_index) { initQParameters(); } QFunctionDefinition(dev::solidity::FunctionDefinition* _f, int _index): QBasicNodeDefinition(_f), m_index(_index) { initQParameters(); }
/// get all input parameters of this function.
QList<QObject*> parameters() const { return m_parameters; } QList<QObject*> parameters() const { return m_parameters; }
/// get all return parameters of this function.
QList<QObject*> returnParameters() const { return m_returnParameters; } QList<QObject*> returnParameters() const { return m_returnParameters; }
/// get the index of this function on the contract ABI.
int index() const { return m_index; } int index() const { return m_index; }
private: private:

23
mix/QVariableDeclaration.cpp

@ -1,23 +0,0 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file QVariableDeclaration.cpp
* @author Yann yann@ethdev.com
* @date 2014
*/
#include "QVariableDeclaration.h"
using namespace dev::mix;

3
mix/QVariableDeclaration.h

@ -19,7 +19,7 @@
* @date 2014 * @date 2014
*/ */
#include "libsolidity/AST.h" #include <libsolidity/AST.h>
#include "QBasicNodeDefinition.h" #include "QBasicNodeDefinition.h"
#pragma once #pragma once
@ -36,6 +36,7 @@ class QVariableDeclaration: public QBasicNodeDefinition
public: public:
QVariableDeclaration(dev::solidity::VariableDeclaration* _v): QBasicNodeDefinition(_v){} QVariableDeclaration(dev::solidity::VariableDeclaration* _v): QBasicNodeDefinition(_v){}
/// get the type of this variable.
QString type() const { return QString::fromStdString(((solidity::VariableDeclaration*)m_dec)->getType()->toString()); } QString type() const { return QString::fromStdString(((solidity::VariableDeclaration*)m_dec)->getType()->toString()); }
}; };

6
mix/QVariableDefinition.h

@ -38,7 +38,9 @@ class QVariableDefinition: public QObject
public: public:
QVariableDefinition(QVariableDeclaration* _def, QString _value): QObject(), m_value(_value), m_dec(_def) {} QVariableDefinition(QVariableDeclaration* _def, QString _value): QObject(), m_value(_value), m_dec(_def) {}
/// return the associated declaration of this variable definition.
QVariableDeclaration* declaration() const { return m_dec; } QVariableDeclaration* declaration() const { return m_dec; }
/// return the variable value.
QString value() const { return m_value; } QString value() const { return m_value; }
private: private:
@ -55,7 +57,9 @@ public:
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
QVariableDefinition* val(int idx); /// return the variable definition at index _idx.
QVariableDefinition* val(int _idx);
/// return the list of variables.
QList<QVariableDefinition*> def() { return m_def; } QList<QVariableDefinition*> def() { return m_def; }
private: private:

Loading…
Cancel
Save