From 38945479aa1a8d07bd11f9e5d091b187b482fcdb Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 19 Dec 2014 15:34:54 +0100 Subject: [PATCH 1/4] - wrap mode on alert message. --- mix/qml/BasicMessage.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/mix/qml/BasicMessage.qml b/mix/qml/BasicMessage.qml index 7127d29ff..8ac8bcd45 100644 --- a/mix/qml/BasicMessage.qml +++ b/mix/qml/BasicMessage.qml @@ -16,6 +16,7 @@ Rectangle { objectName: "messageContent" id: messageTxt text: "" + wrapMode: "Wrap" } } From 68dd4f1ffdd1e32600955cca917b611aa419d457 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 19 Dec 2014 19:23:05 +0100 Subject: [PATCH 2/4] - Capitals on comments. - Class suffix renamed Ctrl => Control. - Use specialized QList (QVariableDeclaration instead of QObject). - Use CompilerStack::getContractDefinition instead of CompilerStack::getAst. --- mix/AppContext.h | 18 ++--- ...erCtrl.cpp => AssemblyDebuggerControl.cpp} | 80 ++++++++++--------- ...buggerCtrl.h => AssemblyDebuggerControl.h} | 16 ++-- mix/AssemblyDebuggerModel.h | 8 +- mix/CodeEditorExtensionManager.cpp | 10 +-- mix/CodeEditorExtensionManager.h | 12 +-- ...trl.cpp => ConstantCompilationControl.cpp} | 26 +++--- ...ionCtrl.h => ConstantCompilationControl.h} | 10 +-- mix/ConstantCompilationModel.h | 2 +- mix/ContractCallDataEncoder.cpp | 2 +- mix/ContractCallDataEncoder.h | 16 ++-- mix/DebuggingStateWrapper.h | 34 ++++---- mix/Extension.h | 14 ++-- mix/KeyEventManager.h | 10 +-- mix/QBasicNodeDefinition.h | 6 +- mix/QContractDefinition.cpp | 5 +- mix/QContractDefinition.h | 6 +- mix/QFunctionDefinition.h | 19 ++--- mix/QVariableDeclaration.h | 2 +- mix/QVariableDefinition.h | 8 +- 20 files changed, 153 insertions(+), 151 deletions(-) rename mix/{AssemblyDebuggerCtrl.cpp => AssemblyDebuggerControl.cpp} (67%) rename mix/{AssemblyDebuggerCtrl.h => AssemblyDebuggerControl.h} (87%) rename mix/{ConstantCompilationCtrl.cpp => ConstantCompilationControl.cpp} (77%) rename mix/{ConstantCompilationCtrl.h => ConstantCompilationControl.h} (86%) diff --git a/mix/AppContext.h b/mix/AppContext.h index a8dc2f469..5fde565e1 100644 --- a/mix/AppContext.h +++ b/mix/AppContext.h @@ -47,19 +47,19 @@ class AppContext: public QObject public: AppContext(QQmlApplicationEngine* _engine); ~AppContext() {} - /// get the current QQmlApplicationEngine instance. + /// Get the current QQmlApplicationEngine instance. static AppContext* getInstance() { return Instance; } - /// renew QQMLApplicationEngine with a new instance. + /// Renew QQMLApplicationEngine with a new instance. static void setApplicationContext(QQmlApplicationEngine* _engine); - /// get the current QQMLApplicationEngine instance. + /// Get the current QQMLApplicationEngine instance. QQmlApplicationEngine* appEngine(); - /// initialize KeyEventManager (used to handle key pressed event). + /// Initialize KeyEventManager (used to handle key pressed event). void initKeyEventManager(QObject* _obj); - /// get the current KeyEventManager instance. + /// Get the current KeyEventManager instance. KeyEventManager* getKeyEventManager(); - /// get the current Compiler instance (used to parse and compile contract code). + /// Get the current Compiler instance (used to parse and compile contract code). dev::solidity::CompilerStack* compiler(); - /// display an alert message. + /// Display an alert message. void displayMessageDialog(QString _title, QString _message); private: @@ -70,9 +70,9 @@ private: std::unique_ptr m_compiler; public slots: - /// delete the current instance when application quit. + /// Delete the current instance when application quit. void quitApplication() { delete Instance; } - /// initialize components after the loading of the main QML view. + /// Initialize components after the loading of the main QML view. void resourceLoaded(QObject* _obj, QUrl _url) { Q_UNUSED(_url); initKeyEventManager(_obj); } }; diff --git a/mix/AssemblyDebuggerCtrl.cpp b/mix/AssemblyDebuggerControl.cpp similarity index 67% rename from mix/AssemblyDebuggerCtrl.cpp rename to mix/AssemblyDebuggerControl.cpp index 5602e49a9..8bc4831d0 100644 --- a/mix/AssemblyDebuggerCtrl.cpp +++ b/mix/AssemblyDebuggerControl.cpp @@ -11,7 +11,7 @@ You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ -/** @file AssemblyDebuggerCtrl.cpp +/** @file AssemblyDebuggerControl.cpp * @author Yann yann@ethdev.com * @date 2014 * display opcode debugging. @@ -25,7 +25,7 @@ #include #include #include "AssemblyDebuggerModel.h" -#include "AssemblyDebuggerCtrl.h" +#include "AssemblyDebuggerControl.h" #include "KeyEventManager.h" #include "AppContext.h" #include "DebuggingStateWrapper.h" @@ -36,11 +36,12 @@ using namespace dev::eth; using namespace dev::mix; -AssemblyDebuggerCtrl::AssemblyDebuggerCtrl(QTextDocument* _doc): Extension(ExtensionDisplayBehavior::ModalDialog) +AssemblyDebuggerControl::AssemblyDebuggerControl(QTextDocument* _doc): Extension(ExtensionDisplayBehavior::ModalDialog) { qRegisterMetaType("QVariableDefinition*"); qRegisterMetaType("QVariableDefinitionList*"); qRegisterMetaType>("QList"); + qRegisterMetaType>("QList"); qRegisterMetaType("QVariableDeclaration*"); qRegisterMetaType("AssemblyDebuggerData"); qRegisterMetaType("DebuggingStatusResult"); @@ -53,23 +54,23 @@ AssemblyDebuggerCtrl::AssemblyDebuggerCtrl(QTextDocument* _doc): Extension(Exten m_doc = _doc; } -QString AssemblyDebuggerCtrl::contentUrl() const +QString AssemblyDebuggerControl::contentUrl() const { return QStringLiteral("qrc:/qml/Debugger.qml"); } -QString AssemblyDebuggerCtrl::title() const +QString AssemblyDebuggerControl::title() const { return QApplication::tr("debugger"); } -void AssemblyDebuggerCtrl::start() const +void AssemblyDebuggerControl::start() const { //start to listen on F5 m_ctx->getKeyEventManager()->registerEvent(this, SLOT(keyPressed(int))); } -void AssemblyDebuggerCtrl::keyPressed(int _key) +void AssemblyDebuggerControl::keyPressed(int _key) { if (_key == Qt::Key_F5) { @@ -85,53 +86,54 @@ void AssemblyDebuggerCtrl::keyPressed(int _key) } } -void AssemblyDebuggerCtrl::callContract(TransactionSettings _tr, Address _contract) +void AssemblyDebuggerControl::callContract(TransactionSettings _tr, Address _contract) { CompilerResult compilerRes = m_compilation->compile(m_doc->toPlainText()); if (!compilerRes.success) - { AppContext::getInstance()->displayMessageDialog("debugger","compilation failed"); - return; - } - ContractCallDataEncoder c; - std::shared_ptr contractDef = QContractDefinition::Contract(m_doc->toPlainText()); - QFunctionDefinition* f = nullptr; - for (int k = 0; k < contractDef->functions().size(); k++) + else { - if (contractDef->functions().at(k)->name() == _tr.functionId) + ContractCallDataEncoder c; + std::shared_ptr contractDef = QContractDefinition::Contract(m_doc->toPlainText()); + QFunctionDefinition* f = nullptr; + for (int k = 0; k < contractDef->functions().size(); k++) { - f = (QFunctionDefinition*)contractDef->functions().at(k); + if (contractDef->functions().at(k)->name() == _tr.functionId) + { + f = (QFunctionDefinition*)contractDef->functions().at(k); + break; + } + } + if (!f) + AppContext::getInstance()->displayMessageDialog(QApplication::tr("debugger"), QApplication::tr("function not found. Please redeploy this contract.")); + else + { + c.encode(f->index()); + for (int k = 0; k < f->parameters().size(); k++) + { + QVariableDeclaration* var = (QVariableDeclaration*)f->parameters().at(k); + c.encode(var, _tr.parameterValues[var->name()]); + } + DebuggingContent debuggingContent = m_modelDebugger->callContract(_contract, c.encodedData(), _tr); + debuggingContent.returnParameters = c.decode(f->returnParameters(), debuggingContent.returnValue); + finalizeExecution(debuggingContent); } } - if (!f) - { - AppContext::getInstance()->displayMessageDialog(QApplication::tr("debugger"), QApplication::tr("function not found. Please redeploy this contract.")); - return; - } - c.encode(f->index()); - for (int k = 0; k < f->parameters().size(); k++) - { - QVariableDeclaration* var = (QVariableDeclaration*)f->parameters().at(k); - c.encode(var, _tr.parameterValues[var->name()]); - } - DebuggingContent debuggingContent = m_modelDebugger->callContract(_contract, c.encodedData(), _tr); - debuggingContent.returnParameters = c.decode(f->returnParameters(), debuggingContent.returnValue); - finalizeExecution(debuggingContent); } -void AssemblyDebuggerCtrl::deployContract(QString _source) +void AssemblyDebuggerControl::deployContract(QString _source) { CompilerResult compilerRes = m_compilation->compile(_source); if (!compilerRes.success) - { emit dataAvailable(false, DebuggingStatusResult::Compilationfailed); - return; + else + { + m_previousDebugResult = m_modelDebugger->deployContract(compilerRes.bytes); + finalizeExecution(m_previousDebugResult); } - m_previousDebugResult = m_modelDebugger->deployContract(compilerRes.bytes); - finalizeExecution(m_previousDebugResult); } -void AssemblyDebuggerCtrl::finalizeExecution(DebuggingContent _debuggingContent) +void AssemblyDebuggerControl::finalizeExecution(DebuggingContent _debuggingContent) { //we need to wrap states in a QObject before sending to QML. QList wStates; @@ -145,7 +147,7 @@ void AssemblyDebuggerCtrl::finalizeExecution(DebuggingContent _debuggingContent) emit dataAvailable(true, DebuggingStatusResult::Ok, _debuggingContent.returnParameters, wStates, code); } -void AssemblyDebuggerCtrl::updateGUI(bool _success, DebuggingStatusResult const& _reason, QList const& _returnParam, QList const& _wStates, AssemblyDebuggerData const& _code) +void AssemblyDebuggerControl::updateGUI(bool _success, DebuggingStatusResult const& _reason, QList const& _returnParam, QList const& _wStates, AssemblyDebuggerData const& _code) { Q_UNUSED(_reason); if (_success) @@ -160,7 +162,7 @@ void AssemblyDebuggerCtrl::updateGUI(bool _success, DebuggingStatusResult const& m_ctx->displayMessageDialog(QApplication::tr("debugger"), QApplication::tr("compilation failed")); } -void AssemblyDebuggerCtrl::runTransaction(TransactionSettings const& _tr) +void AssemblyDebuggerControl::runTransaction(TransactionSettings const& _tr) { QtConcurrent::run([this, _tr]() { diff --git a/mix/AssemblyDebuggerCtrl.h b/mix/AssemblyDebuggerControl.h similarity index 87% rename from mix/AssemblyDebuggerCtrl.h rename to mix/AssemblyDebuggerControl.h index 114610246..702839250 100644 --- a/mix/AssemblyDebuggerCtrl.h +++ b/mix/AssemblyDebuggerControl.h @@ -11,7 +11,7 @@ You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ -/** @file AssemblyDebuggerCtrl.h +/** @file AssemblyDebuggerControl.h * @author Yann yann@ethdev.com * @date 2014 * Extension which display debugging steps in assembly code. @@ -46,13 +46,13 @@ 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 AssemblyDebuggerControl: public Extension { Q_OBJECT public: - AssemblyDebuggerCtrl(QTextDocument* _doc); - ~AssemblyDebuggerCtrl() {} + AssemblyDebuggerControl(QTextDocument* _doc); + ~AssemblyDebuggerControl() {} void start() const override; QString title() const override; QString contentUrl() const override; @@ -68,15 +68,15 @@ private: QTextDocument* m_doc; public slots: - /// handle key pressed. F5 deploy contract - F6 reset state. + /// Handle key pressed. F5 deploy contract - F6 reset state. void keyPressed(int); - /// update UI with machine states result. Display a modal dialog. + /// Update UI with machine states result. Display a modal dialog. void updateGUI(bool _success, DebuggingStatusResult const& _reason, QList const& _returnParams = QList(), QList const& _wStates = QList(), AssemblyDebuggerData const& _code = AssemblyDebuggerData()); - /// run the given transaction. + /// Run the given transaction. void runTransaction(TransactionSettings const& _tr); signals: - /// emited when machine states are available. + /// Emited when machine states are available. void dataAvailable(bool _success, DebuggingStatusResult const& _reason, QList const& _returnParams = QList(), QList const& _wStates = QList(), AssemblyDebuggerData const& _code = AssemblyDebuggerData()); }; diff --git a/mix/AssemblyDebuggerModel.h b/mix/AssemblyDebuggerModel.h index 21a0c1f7b..1b1254464 100644 --- a/mix/AssemblyDebuggerModel.h +++ b/mix/AssemblyDebuggerModel.h @@ -14,7 +14,7 @@ /** @file AssemblyDebuggerModel.h * @author Yann yann@ethdev.com * @date 2014 - * serves as a model to debug contract assembly code. + * Used as a model to debug contract assembly code. */ #pragma once @@ -40,11 +40,11 @@ class AssemblyDebuggerModel { public: AssemblyDebuggerModel(); - /// call function in a already deployed contract. + /// Call function in a already deployed contract. DebuggingContent callContract(Address const& _contract, bytes const& _data, TransactionSettings const& _tr); - /// deploy the contract described by _code. + /// Deploy the contract described by _code. DebuggingContent deployContract(bytes const& _code); - /// reset state to the base state. + /// Reset state to the base state. void resetState(); private: diff --git a/mix/CodeEditorExtensionManager.cpp b/mix/CodeEditorExtensionManager.cpp index a6f7e798a..6c94a805e 100644 --- a/mix/CodeEditorExtensionManager.cpp +++ b/mix/CodeEditorExtensionManager.cpp @@ -26,8 +26,8 @@ #include #include #include -#include "ConstantCompilationCtrl.h" -#include "AssemblyDebuggerCtrl.h" +#include "ConstantCompilationControl.h" +#include "AssemblyDebuggerControl.h" #include "TransactionListView.h" #include "AppContext.h" #include "CodeEditorExtensionManager.h" @@ -70,10 +70,10 @@ void CodeEditorExtensionManager::loadEditor(QQuickItem* _editor) void CodeEditorExtensionManager::initExtensions() { - initExtension(std::make_shared(m_doc)); - std::shared_ptr debug = std::make_shared(m_doc); + initExtension(std::make_shared(m_doc)); + std::shared_ptr debug = std::make_shared(m_doc); std::shared_ptr tr = std::make_shared(m_doc); - QObject::connect(tr->model(), &TransactionListModel::transactionStarted, debug.get(), &AssemblyDebuggerCtrl::runTransaction); + QObject::connect(tr->model(), &TransactionListModel::transactionStarted, debug.get(), &AssemblyDebuggerControl::runTransaction); initExtension(debug); initExtension(tr); } diff --git a/mix/CodeEditorExtensionManager.h b/mix/CodeEditorExtensionManager.h index af1e984ad..94a5f4b2e 100644 --- a/mix/CodeEditorExtensionManager.h +++ b/mix/CodeEditorExtensionManager.h @@ -25,7 +25,7 @@ #include #include #include -#include "ConstantCompilationCtrl.h" +#include "ConstantCompilationControl.h" namespace dev { @@ -46,15 +46,15 @@ class CodeEditorExtensionManager: public QObject public: CodeEditorExtensionManager() {} ~CodeEditorExtensionManager(); - /// initialize all extensions. + /// Initialize all extensions. void initExtensions(); - /// initialize extension. + /// Initialize extension. void initExtension(std::shared_ptr); - /// set current text editor. + /// Set current text editor. void setEditor(QQuickItem*); - /// set current tab view + /// Set current tab view void setTabView(QQuickItem*); - /// set current right tab view. + /// Set current right tab view. void setRightTabView(QQuickItem*); private: diff --git a/mix/ConstantCompilationCtrl.cpp b/mix/ConstantCompilationControl.cpp similarity index 77% rename from mix/ConstantCompilationCtrl.cpp rename to mix/ConstantCompilationControl.cpp index 4aaf137aa..3082ba677 100644 --- a/mix/ConstantCompilationCtrl.cpp +++ b/mix/ConstantCompilationControl.cpp @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ -/** @file ConstantCompilationCtrl.cpp +/** @file ConstantCompilationControl.cpp * @author Yann yann@ethdev.com * @date 2014 * Ethereum IDE client. @@ -27,45 +27,45 @@ #include #include #include -#include "ConstantCompilationCtrl.h" +#include "ConstantCompilationControl.h" #include "ConstantCompilationModel.h" #include "QContractDefinition.h" using namespace dev::mix; -ConstantCompilationCtrl::ConstantCompilationCtrl(QTextDocument* _doc): Extension(ExtensionDisplayBehavior::Tab) +ConstantCompilationControl::ConstantCompilationControl(QTextDocument* _doc): Extension(ExtensionDisplayBehavior::Tab) { m_editor = _doc; m_compilationModel = std::unique_ptr(new ConstantCompilationModel()); } -QString ConstantCompilationCtrl::contentUrl() const +QString ConstantCompilationControl::contentUrl() const { return QStringLiteral("qrc:/qml/BasicContent.qml"); } -QString ConstantCompilationCtrl::title() const +QString ConstantCompilationControl::title() const { return QApplication::tr("compiler"); } -void ConstantCompilationCtrl::start() const +void ConstantCompilationControl::start() const { connect(m_editor, SIGNAL(contentsChange(int,int,int)), this, SLOT(compile())); } -void ConstantCompilationCtrl::compile() +void ConstantCompilationControl::compile() { QString codeContent = m_editor->toPlainText().replace("\n", ""); if (codeContent.isEmpty()) - { resetOutPut(); - return; + else + { + CompilerResult res = m_compilationModel->compile(m_editor->toPlainText().replace("\t", " ")); + writeOutPut(res); } - CompilerResult res = m_compilationModel->compile(m_editor->toPlainText().replace("\t", " ")); - writeOutPut(res); } -void ConstantCompilationCtrl::resetOutPut() +void ConstantCompilationControl::resetOutPut() { QObject* status = m_view->findChild("status", Qt::FindChildrenRecursively); QObject* content = m_view->findChild("content", Qt::FindChildrenRecursively); @@ -73,7 +73,7 @@ void ConstantCompilationCtrl::resetOutPut() content->setProperty("text", ""); } -void ConstantCompilationCtrl::writeOutPut(CompilerResult const& _res) +void ConstantCompilationControl::writeOutPut(CompilerResult const& _res) { QObject* status = m_view->findChild("status", Qt::FindChildrenRecursively); QObject* content = m_view->findChild("content", Qt::FindChildrenRecursively); diff --git a/mix/ConstantCompilationCtrl.h b/mix/ConstantCompilationControl.h similarity index 86% rename from mix/ConstantCompilationCtrl.h rename to mix/ConstantCompilationControl.h index ba75c11ab..b2ffaadd3 100644 --- a/mix/ConstantCompilationCtrl.h +++ b/mix/ConstantCompilationControl.h @@ -11,7 +11,7 @@ You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ -/** @file ConstantCompilationCtrl.h +/** @file ConstantCompilationControl.h * @author Yann yann@ethdev.com * @date 2014 * Ethereum IDE client. @@ -31,13 +31,13 @@ namespace mix /** * @brief Extension which display assembly code of the contract being edited. */ -class ConstantCompilationCtrl: public Extension +class ConstantCompilationControl: public Extension { Q_OBJECT public: - ConstantCompilationCtrl(QTextDocument* _doc); - ~ConstantCompilationCtrl() {} + ConstantCompilationControl(QTextDocument* _doc); + ~ConstantCompilationControl() {} void start() const override; QString title() const override; QString contentUrl() const override; @@ -49,7 +49,7 @@ private: void resetOutPut(); public slots: - /// compile text editor content. + /// Compile text editor content. void compile(); }; diff --git a/mix/ConstantCompilationModel.h b/mix/ConstantCompilationModel.h index 68d75cea3..a4c4f3de5 100644 --- a/mix/ConstantCompilationModel.h +++ b/mix/ConstantCompilationModel.h @@ -51,7 +51,7 @@ class ConstantCompilationModel public: ConstantCompilationModel() {} ~ConstantCompilationModel() {} - /// compile code. + /// Compile code. CompilerResult compile(QString _code); }; diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index f1a081264..c631793d4 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -65,7 +65,7 @@ void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, u256 _value) encodedData(); } -QList ContractCallDataEncoder::decode(QList _returnParameters, bytes _value) +QList ContractCallDataEncoder::decode(QList _returnParameters, bytes _value) { QList r; std::string returnValue = toJS(_value); diff --git a/mix/ContractCallDataEncoder.h b/mix/ContractCallDataEncoder.h index 268865ea6..a66d9b4b6 100644 --- a/mix/ContractCallDataEncoder.h +++ b/mix/ContractCallDataEncoder.h @@ -31,23 +31,23 @@ namespace mix { /** - * @brief encode/decode data to be sent to a transaction or to be displayed in a view. + * @brief Encode/Decode data to be sent to a transaction or to be displayed in a view. */ class ContractCallDataEncoder { public: ContractCallDataEncoder() {} - /// encode variable in order to be sent as parameter. + /// Encode variable in order to be sent as parameter. void encode(QVariableDeclaration* _dec, QString _value); - /// encode variable in order to be sent as parameter. + /// Encode variable in order to be sent as parameter. void encode(QVariableDeclaration* _dec, u256 _value); - /// encode variable in order to be sent as parameter. + /// Encode variable in order to be sent as parameter. void encode(QVariableDeclaration* _dec, bool _value); - /// encode index of the function to call. + /// Encode index of the function to call. void encode(int _functionIndex); - /// decode variable in order to be sent to QML view. - QList decode(QList _dec, bytes _value); - /// get all encoded data encoded by encode function. + /// Decode variable in order to be sent to QML view. + QList decode(QList _dec, bytes _value); + /// Get all encoded data encoded by encode function. bytes encodedData(); private: diff --git a/mix/DebuggingStateWrapper.h b/mix/DebuggingStateWrapper.h index be969b1d1..219edfed3 100644 --- a/mix/DebuggingStateWrapper.h +++ b/mix/DebuggingStateWrapper.h @@ -77,9 +77,9 @@ class HumanReadableCode: public QObject public: HumanReadableCode(QString _line, int _processIndex): QObject(), m_line(_line), m_processIndex(_processIndex) {} - /// get the assembly code line. + /// Get the assembly code line. QString line() { return m_line; } - /// get corresponding index. + /// Get corresponding index. int processIndex() { return m_processIndex; } private: @@ -97,7 +97,7 @@ class QQMLMap: public QObject public: QQMLMap(QMap _map): QObject(), m_map(_map) { } - /// get the value associated with _key store in n_map. + /// Get the value associated with _key store in n_map. Q_INVOKABLE int getValue(int _key) { return m_map.value(_key); } private: @@ -125,35 +125,35 @@ class DebuggingStateWrapper: public QObject public: DebuggingStateWrapper(bytes _code, bytes _data): QObject(), m_code(_code), m_data(_data) {} - /// get the step of this machine states. + /// Get the step of this machine states. int step() { return (int)m_state.steps; } - /// get the proccessed code. + /// Get the proccessed code index. int curPC() { return (int)m_state.curPC; } - /// get gas left. + /// Get gas left. QString gasLeft(); - /// get gas cost. + /// Get gas cost. QString gasCost(); - /// get gas used. + /// Get gas used. QString gas(); - /// get stack. + /// Get stack. QString debugStack(); - /// get storage. + /// Get storage. QString debugStorage(); - /// get memory. + /// Get memory. QString debugMemory(); - /// get call data. + /// Get call data. QString debugCallData(); - /// get info to be displayed in the header. + /// Get info to be displayed in the header. QString headerInfo(); /// get end of debug information. QString endOfDebug(); - /// get all previous steps. + /// Get all previous steps. QStringList levels(); - /// get the current processed machine state. + /// Get the current processed machine state. DebuggingState state() { return m_state; } - /// set the current processed machine state. + /// Set the current processed machine state. void setState(DebuggingState _state) { m_state = _state; } - /// convert all machine state in human readable code. + /// Convert all machine state in human readable code. static std::tuple, QQMLMap*> getHumanReadableCode(bytes const& _code); private: diff --git a/mix/Extension.h b/mix/Extension.h index 9f29a0290..9e3e7f55b 100644 --- a/mix/Extension.h +++ b/mix/Extension.h @@ -43,19 +43,19 @@ class Extension: public QObject public: Extension(); Extension(ExtensionDisplayBehavior _displayBehavior); - /// return the QML url of the view to display. + /// Return the QML url of the view to display. virtual QString contentUrl() const { return ""; } - /// reuturn the title of this extension. + /// Return the title of this extension. virtual QString title() const { return ""; } - /// initialize extension. + /// Initialize extension. virtual void start() const {} - /// add the view define in contentUrl() in the _view QObject. + /// 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). + /// Add the view define in contentUrl() in the _view QObject (_view has to be a tab). void addTabOn(QObject* _view); - /// modify the display behavior of this extension. + /// Modify the display behavior of this extension. void setDisplayBehavior(ExtensionDisplayBehavior _displayBehavior) { m_displayBehavior = _displayBehavior; } - /// get the display behavior of thi extension. + /// Get the display behavior of thi extension. ExtensionDisplayBehavior getDisplayBehavior() { return m_displayBehavior; } protected: diff --git a/mix/KeyEventManager.h b/mix/KeyEventManager.h index 65f9b4a01..badc27216 100644 --- a/mix/KeyEventManager.h +++ b/mix/KeyEventManager.h @@ -17,7 +17,7 @@ /** @file KeyEventManager.h * @author Yann yann@ethdev.com * @date 2014 - * use as an event handler for all classes which need keyboard interactions + * Used as an event handler for all classes which need keyboard interactions */ #pragma once @@ -30,17 +30,17 @@ class KeyEventManager: public QObject public: KeyEventManager() {} - /// allows _receiver to handle key pressed event. + /// Allows _receiver to handle key pressed event. void registerEvent(const QObject* _receiver, const char* _slot); - /// unregister _receiver. + /// Unregister _receiver. void unRegisterEvent(QObject* _receiver); signals: - /// emited when a key is pressed. + /// Emited when a key is pressed. void onKeyPressed(int _event); public slots: - /// called when a key is pressed. + /// Called when a key is pressed. void keyPressed(QVariant _event); }; diff --git a/mix/QBasicNodeDefinition.h b/mix/QBasicNodeDefinition.h index 7d3ee475a..8aa07109a 100644 --- a/mix/QBasicNodeDefinition.h +++ b/mix/QBasicNodeDefinition.h @@ -37,12 +37,12 @@ class QBasicNodeDefinition: public QObject public: QBasicNodeDefinition(): QObject() {} ~QBasicNodeDefinition() {} - QBasicNodeDefinition(dev::solidity::Declaration* _d): QObject(), m_dec(_d) {} - /// get the name of the node. + QBasicNodeDefinition(dev::solidity::Declaration const* _d): QObject(), m_dec(_d) {} + /// Get the name of the node. QString name() const { return QString::fromStdString(m_dec->getName()); } protected: - dev::solidity::Declaration* m_dec; + dev::solidity::Declaration const* m_dec; }; } diff --git a/mix/QContractDefinition.cpp b/mix/QContractDefinition.cpp index e469bd629..8ab37619e 100644 --- a/mix/QContractDefinition.cpp +++ b/mix/QContractDefinition.cpp @@ -35,12 +35,11 @@ std::shared_ptr QContractDefinition::Contract(QString _sour CompilerStack* comp = AppContext::getInstance()->compiler(); comp->addSource("contract", _source.toStdString()); comp->parse(); - SourceUnit const& unit = comp->getAST("contract"); - ContractDefinition* def = (ContractDefinition*)unit.getNodes().at(0).get(); + ContractDefinition const* def = &comp->getContractDefinition(comp->getContractNames().front()); return std::make_shared(def); } -QContractDefinition::QContractDefinition(ContractDefinition* _contract): QBasicNodeDefinition(_contract) +QContractDefinition::QContractDefinition(ContractDefinition const* _contract): QBasicNodeDefinition(_contract) { initQFunctions(); } diff --git a/mix/QContractDefinition.h b/mix/QContractDefinition.h index fdbd29c3e..91d825e8a 100644 --- a/mix/QContractDefinition.h +++ b/mix/QContractDefinition.h @@ -37,10 +37,10 @@ class QContractDefinition: public QBasicNodeDefinition Q_PROPERTY(QList functions READ functions) public: - QContractDefinition(dev::solidity::ContractDefinition* _contract); - /// get all the functions of the contract. + QContractDefinition(dev::solidity::ContractDefinition const* _contract); + /// Get all the functions of the contract. QList functions() const { return m_functions; } - /// get the description (functions, parameters, return parameters, ...) of the contract describes by _code. + /// Get the description (functions, parameters, return parameters, ...) of the contract describes by _code. static std::shared_ptr Contract(QString _code); private: diff --git a/mix/QFunctionDefinition.h b/mix/QFunctionDefinition.h index 000a54f6e..6134a17b9 100644 --- a/mix/QFunctionDefinition.h +++ b/mix/QFunctionDefinition.h @@ -23,6 +23,7 @@ #include #include +#include #include "QBasicNodeDefinition.h" namespace dev @@ -33,21 +34,21 @@ namespace mix class QFunctionDefinition: public QBasicNodeDefinition { Q_OBJECT - Q_PROPERTY(QList parameters READ parameters) + Q_PROPERTY(QList parameters READ parameters) Q_PROPERTY(int index READ index) public: - QFunctionDefinition(dev::solidity::FunctionDefinition* _f, int _index): QBasicNodeDefinition(_f), m_index(_index) { initQParameters(); } - /// get all input parameters of this function. - QList parameters() const { return m_parameters; } - /// get all return parameters of this function. - QList returnParameters() const { return m_returnParameters; } - /// get the index of this function on the contract ABI. + QFunctionDefinition(dev::solidity::FunctionDefinition const* _f, int _index): QBasicNodeDefinition(_f), m_index(_index) { initQParameters(); } + /// Get all input parameters of this function. + QList parameters() const { return m_parameters; } + /// Get all return parameters of this function. + QList returnParameters() const { return m_returnParameters; } + /// Get the index of this function on the contract ABI. int index() const { return m_index; } private: - QList m_parameters; - QList m_returnParameters; + QList m_parameters; + QList m_returnParameters; int m_index; void initQParameters(); }; diff --git a/mix/QVariableDeclaration.h b/mix/QVariableDeclaration.h index 5e89c1c1b..147719c7c 100644 --- a/mix/QVariableDeclaration.h +++ b/mix/QVariableDeclaration.h @@ -36,7 +36,7 @@ class QVariableDeclaration: public QBasicNodeDefinition public: QVariableDeclaration(dev::solidity::VariableDeclaration* _v): QBasicNodeDefinition(_v){} - /// get the type of this variable. + /// Get the type of this variable. QString type() const { return QString::fromStdString(((solidity::VariableDeclaration*)m_dec)->getType()->toString()); } }; diff --git a/mix/QVariableDefinition.h b/mix/QVariableDefinition.h index fdea5ff34..898a02621 100644 --- a/mix/QVariableDefinition.h +++ b/mix/QVariableDefinition.h @@ -38,9 +38,9 @@ class QVariableDefinition: public QObject public: QVariableDefinition(QVariableDeclaration* _def, QString _value): QObject(), m_value(_value), m_dec(_def) {} - /// return the associated declaration of this variable definition. + /// Return the associated declaration of this variable definition. QVariableDeclaration* declaration() const { return m_dec; } - /// return the variable value. + /// Return the variable value. QString value() const { return m_value; } private: @@ -57,9 +57,9 @@ public: int rowCount(const QModelIndex& parent = QModelIndex()) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; QHash roleNames() const override; - /// return the variable definition at index _idx. + /// Return the variable definition at index _idx. QVariableDefinition* val(int _idx); - /// return the list of variables. + /// Return the list of variables. QList def() { return m_def; } private: From ce14b0c150401d00d43452d029e09d06d9dc5f19 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 19 Dec 2014 21:19:06 +0100 Subject: [PATCH 3/4] - Rollback previous change on toCompactBigEndian, unpadded(bytes _b). - Change content of padded(bytes _b, unsigned _l). - Add function unpadLeft. --- libdevcore/CommonData.h | 2 +- libdevcore/CommonJS.cpp | 9 +++------ libdevcore/CommonJS.h | 9 ++++++++- mix/ContractCallDataEncoder.cpp | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index 3dd5edab7..87d2f5e28 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -113,7 +113,7 @@ inline bytes toBigEndian(u160 _val) { bytes ret(20); toBigEndian(_val, ret); ret /// Convenience function for toBigEndian. /// @returns a byte array just big enough to represent @a _val. template -inline bytes toCompactBigEndian(_T _val, unsigned _min = 1) +inline bytes toCompactBigEndian(_T _val, unsigned _min = 0) { int i = 0; for (_T v = _val; v; ++i, v >>= 8) {} diff --git a/libdevcore/CommonJS.cpp b/libdevcore/CommonJS.cpp index 157dfd91e..ee2074cd1 100644 --- a/libdevcore/CommonJS.cpp +++ b/libdevcore/CommonJS.cpp @@ -42,25 +42,22 @@ bytes padded(bytes _b, unsigned _l) { while (_b.size() < _l) _b.insert(_b.begin(), 0); - while (_b.size() < _l) - _b.push_back(0); return asBytes(asString(_b).substr(_b.size() - std::max(_l, _l))); } bytes unpadded(bytes _b) { - auto p = asString(_b).find_first_not_of("0"); + auto p = asString(_b).find_last_not_of((char)0); _b.resize(p == std::string::npos ? 0 : (p + 1)); return _b; } -std::string unpadded(std::string _b) +std::string unpadLeft(std::string _b) { auto p = _b.find_first_not_of('0'); if (p == std::string::npos) return "0"; - _b = _b.substr(p, _b.length() - 1); - return _b; + return _b.substr(p, _b.length() - 1); } std::string prettyU256(u256 _n) diff --git a/libdevcore/CommonJS.h b/libdevcore/CommonJS.h index ed3a77181..9491bd4b7 100644 --- a/libdevcore/CommonJS.h +++ b/libdevcore/CommonJS.h @@ -46,12 +46,19 @@ inline std::string toJS(dev::bytes const& _n) return "0x" + dev::toHex(_n); } +/// Convert string to byte array. bytes jsToBytes(std::string const& _s); +/// Add '0' on the head of _b until _l. bytes padded(bytes _b, unsigned _l); +/// Removing all trailing '0'. bytes unpadded(bytes _s); -std::string unpadded(std::string _s); +/// Remove all '0' on the head of _s. +std::string unpadLeft(std::string _s); +/// Convert u256 to readable string. std::string prettyU256(u256 _n); +/// Convert h256 to readable string. std::string fromRaw(h256 _n, unsigned* _inc = nullptr); +/// Convert string to Address (h160). Address fromString(std::string const& _a); template FixedHash jsToFixed(std::string const& _s) diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index c631793d4..b83a0c582 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -75,7 +75,7 @@ QList ContractCallDataEncoder::decode(QListpadding(dec->type()); std::string rawParam = returnValue.substr(0, padding * 2); - r.append(new QVariableDefinition(dec, convertToReadable(unpadded(rawParam), dec))); + r.append(new QVariableDefinition(dec, convertToReadable(unpadLeft(rawParam), dec))); returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1); } return r; From c6b6fddda1ecb503dfdda569c39f5b11140bac9b Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 19 Dec 2014 21:59:42 +0100 Subject: [PATCH 4/4] - move Solidity 'Declaration' obj in each specialized Qclass. --- mix/QBasicNodeDefinition.h | 8 ++++---- mix/QContractDefinition.cpp | 12 ++---------- mix/QContractDefinition.h | 3 ++- mix/QFunctionDefinition.cpp | 8 ++------ mix/QFunctionDefinition.h | 5 +++-- mix/QVariableDeclaration.h | 7 +++++-- 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/mix/QBasicNodeDefinition.h b/mix/QBasicNodeDefinition.h index 8aa07109a..0d7365b72 100644 --- a/mix/QBasicNodeDefinition.h +++ b/mix/QBasicNodeDefinition.h @@ -37,12 +37,12 @@ class QBasicNodeDefinition: public QObject public: QBasicNodeDefinition(): QObject() {} ~QBasicNodeDefinition() {} - QBasicNodeDefinition(dev::solidity::Declaration const* _d): QObject(), m_dec(_d) {} + QBasicNodeDefinition(solidity::Declaration const* _d): QObject(), m_name(QString::fromStdString(_d->getName())) {} /// Get the name of the node. - QString name() const { return QString::fromStdString(m_dec->getName()); } + QString name() const { return m_name; } -protected: - dev::solidity::Declaration const* m_dec; +private: + QString m_name; }; } diff --git a/mix/QContractDefinition.cpp b/mix/QContractDefinition.cpp index 8ab37619e..6d98f67cb 100644 --- a/mix/QContractDefinition.cpp +++ b/mix/QContractDefinition.cpp @@ -39,17 +39,9 @@ std::shared_ptr QContractDefinition::Contract(QString _sour return std::make_shared(def); } -QContractDefinition::QContractDefinition(ContractDefinition const* _contract): QBasicNodeDefinition(_contract) -{ - initQFunctions(); -} - void QContractDefinition::initQFunctions() { - std::vector functions = ((ContractDefinition*)m_dec)->getInterfaceFunctions(); + std::vector functions = m_contract->getInterfaceFunctions(); for (unsigned i = 0; i < functions.size(); i++) - { - FunctionDefinition* func = (FunctionDefinition*)functions.at(i); - m_functions.append(new QFunctionDefinition(func, i)); - } + m_functions.append(new QFunctionDefinition(functions.at(i), i)); } diff --git a/mix/QContractDefinition.h b/mix/QContractDefinition.h index 91d825e8a..e4e767380 100644 --- a/mix/QContractDefinition.h +++ b/mix/QContractDefinition.h @@ -37,13 +37,14 @@ class QContractDefinition: public QBasicNodeDefinition Q_PROPERTY(QList functions READ functions) public: - QContractDefinition(dev::solidity::ContractDefinition const* _contract); + QContractDefinition(solidity::ContractDefinition const* _contract): QBasicNodeDefinition(_contract), m_contract(_contract) { initQFunctions(); } /// Get all the functions of the contract. QList functions() const { return m_functions; } /// Get the description (functions, parameters, return parameters, ...) of the contract describes by _code. static std::shared_ptr Contract(QString _code); private: + solidity::ContractDefinition const* m_contract; QList m_functions; void initQFunctions(); }; diff --git a/mix/QFunctionDefinition.cpp b/mix/QFunctionDefinition.cpp index 3f8e19290..e1884b5aa 100644 --- a/mix/QFunctionDefinition.cpp +++ b/mix/QFunctionDefinition.cpp @@ -27,15 +27,11 @@ using namespace dev::mix; void QFunctionDefinition::initQParameters() { - std::vector> parameters = ((FunctionDefinition*)m_dec)->getParameterList().getParameters(); + std::vector> parameters = m_functions->getParameterList().getParameters(); for (unsigned i = 0; i < parameters.size(); i++) - { m_parameters.append(new QVariableDeclaration(parameters.at(i).get())); - } - std::vector> returnParameters = ((FunctionDefinition*)m_dec)->getReturnParameters(); + std::vector> returnParameters = m_functions->getReturnParameters(); for (unsigned i = 0; i < returnParameters.size(); i++) - { m_returnParameters.append(new QVariableDeclaration(returnParameters.at(i).get())); - } } diff --git a/mix/QFunctionDefinition.h b/mix/QFunctionDefinition.h index 6134a17b9..368e2e239 100644 --- a/mix/QFunctionDefinition.h +++ b/mix/QFunctionDefinition.h @@ -38,7 +38,7 @@ class QFunctionDefinition: public QBasicNodeDefinition Q_PROPERTY(int index READ index) public: - QFunctionDefinition(dev::solidity::FunctionDefinition const* _f, int _index): QBasicNodeDefinition(_f), m_index(_index) { initQParameters(); } + QFunctionDefinition(solidity::FunctionDefinition const* _f, int _index): QBasicNodeDefinition(_f), m_index(_index), m_functions(_f) { initQParameters(); } /// Get all input parameters of this function. QList parameters() const { return m_parameters; } /// Get all return parameters of this function. @@ -47,9 +47,10 @@ public: int index() const { return m_index; } private: + int m_index; + solidity::FunctionDefinition const* m_functions; QList m_parameters; QList m_returnParameters; - int m_index; void initQParameters(); }; diff --git a/mix/QVariableDeclaration.h b/mix/QVariableDeclaration.h index 147719c7c..2d2c40970 100644 --- a/mix/QVariableDeclaration.h +++ b/mix/QVariableDeclaration.h @@ -35,9 +35,12 @@ class QVariableDeclaration: public QBasicNodeDefinition Q_PROPERTY(QString type READ type CONSTANT) public: - QVariableDeclaration(dev::solidity::VariableDeclaration* _v): QBasicNodeDefinition(_v){} + QVariableDeclaration(solidity::VariableDeclaration const* _v): QBasicNodeDefinition(_v), m_variable(_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(m_variable->getType()->toString()); } + +private: + solidity::VariableDeclaration const* m_variable; }; }