diff --git a/mix/AppContext.cpp b/mix/AppContext.cpp index b03548397..e1c49199d 100644 --- a/mix/AppContext.cpp +++ b/mix/AppContext.cpp @@ -26,7 +26,7 @@ #include #include #include -#include "libdevcrypto/FileSystem.h" +#include #include "KeyEventManager.h" #include "AppContext.h" using namespace dev; @@ -41,7 +41,7 @@ AppContext::AppContext(QQmlApplicationEngine* _engine) m_applicationEngine = std::unique_ptr(_engine); m_keyEventManager = std::unique_ptr(new KeyEventManager()); m_webThree = std::unique_ptr(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(new CompilerStack()); + m_compiler = std::unique_ptr(new CompilerStack()); //TODO : to move in a codel model structure. } QQmlApplicationEngine* AppContext::appEngine() @@ -49,11 +49,6 @@ QQmlApplicationEngine* AppContext::appEngine() return m_applicationEngine.get(); } -dev::eth::Client* AppContext::getEthereumClient() -{ - return m_webThree->ethereum(); -} - void AppContext::initKeyEventManager(QObject* _res) { QObject* mainContent = _res->findChild("mainContent", Qt::FindChildrenRecursively); @@ -81,6 +76,7 @@ void AppContext::setApplicationContext(QQmlApplicationEngine* _engine) void AppContext::displayMessageDialog(QString _title, QString _message) { + // TODO : move it in a UI dedicated layer. QObject* dialogWin = m_applicationEngine.get()->rootObjects().at(0)->findChild("alertMessageDialog", Qt::FindChildrenRecursively); QObject* dialogWinComponent = m_applicationEngine.get()->rootObjects().at(0)->findChild("alertMessageDialogContent", Qt::FindChildrenRecursively); dialogWinComponent->setProperty("source", QString("qrc:/qml/BasicMessage.qml")); diff --git a/mix/AppContext.h b/mix/AppContext.h index 88e70f3f4..a8dc2f469 100644 --- a/mix/AppContext.h +++ b/mix/AppContext.h @@ -28,8 +28,8 @@ #pragma once #include -#include "libsolidity/CompilerStack.h" -#include "libwebthree/WebThree.h" +#include +#include #include "KeyEventManager.h" namespace dev @@ -37,6 +37,9 @@ namespace dev namespace mix { +/** + * @brief Provides access to application scope variable. + */ class AppContext: public QObject { Q_OBJECT @@ -44,13 +47,19 @@ class AppContext: public QObject public: AppContext(QQmlApplicationEngine* _engine); ~AppContext() {} + /// get the current QQmlApplicationEngine instance. static AppContext* getInstance() { return Instance; } + /// renew QQMLApplicationEngine with a new instance. static void setApplicationContext(QQmlApplicationEngine* _engine); + /// get the current QQMLApplicationEngine instance. QQmlApplicationEngine* appEngine(); - dev::eth::Client* getEthereumClient(); + /// initialize KeyEventManager (used to handle key pressed event). void initKeyEventManager(QObject* _obj); + /// get the current KeyEventManager instance. KeyEventManager* getKeyEventManager(); + /// get the current Compiler instance (used to parse and compile contract code). dev::solidity::CompilerStack* compiler(); + /// display an alert message. void displayMessageDialog(QString _title, QString _message); private: @@ -61,10 +70,11 @@ private: std::unique_ptr m_compiler; public slots: + /// delete the current instance when application quit. 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); } }; } - } diff --git a/mix/AssemblyDebuggerCtrl.cpp b/mix/AssemblyDebuggerCtrl.cpp index 718dbb7a3..e8ed62ec7 100644 --- a/mix/AssemblyDebuggerCtrl.cpp +++ b/mix/AssemblyDebuggerCtrl.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.h +/** @file AssemblyDebuggerCtrl.cpp * @author Yann yann@ethdev.com * @date 2014 * display opcode debugging. @@ -23,7 +23,7 @@ #include #include #include -#include "libethereum/Transaction.h" +#include #include "AssemblyDebuggerModel.h" #include "AssemblyDebuggerCtrl.h" #include "KeyEventManager.h" @@ -44,6 +44,7 @@ AssemblyDebuggerCtrl::AssemblyDebuggerCtrl(QTextDocument* _doc): Extension(Exten qRegisterMetaType("QVariableDeclaration*"); qRegisterMetaType("AssemblyDebuggerData"); qRegisterMetaType("DebuggingStatusResult"); + connect(this, SIGNAL(dataAvailable(bool, DebuggingStatusResult, QList, QList, AssemblyDebuggerData)), this, SLOT(updateGUI(bool, DebuggingStatusResult, QList, QList, AssemblyDebuggerData)), Qt::QueuedConnection); @@ -77,9 +78,14 @@ void AssemblyDebuggerCtrl::keyPressed(int _key) 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()); if (!compilerRes.success) @@ -99,7 +105,7 @@ void AssemblyDebuggerCtrl::callContract(dev::mix::TransactionSettings _tr, Addre } 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; } c.encode(f->index()); @@ -108,7 +114,7 @@ void AssemblyDebuggerCtrl::callContract(dev::mix::TransactionSettings _tr, Addre QVariableDeclaration* var = (QVariableDeclaration*)f->parameters().at(k); 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); finalizeExecution(debuggingContent); } @@ -121,7 +127,7 @@ void AssemblyDebuggerCtrl::deployContract(QString _source) emit dataAvailable(false, DebuggingStatusResult::Compilationfailed); return; } - m_previousDebugResult = m_modelDebugger->getContractInitiationDebugStates(compilerRes.bytes); + m_previousDebugResult = m_modelDebugger->deployContract(compilerRes.bytes); finalizeExecution(m_previousDebugResult); } @@ -139,7 +145,7 @@ void AssemblyDebuggerCtrl::finalizeExecution(DebuggingContent _debuggingContent) emit dataAvailable(true, DebuggingStatusResult::Ok, _debuggingContent.returnParameters, wStates, code); } -void AssemblyDebuggerCtrl::updateGUI(bool _success, DebuggingStatusResult _reason, QList _returnParam, QList _wStates, AssemblyDebuggerData _code) +void AssemblyDebuggerCtrl::updateGUI(bool _success, DebuggingStatusResult const& _reason, QList const& _returnParam, QList const& _wStates, AssemblyDebuggerData const& _code) { Q_UNUSED(_reason); if (_success) @@ -154,7 +160,7 @@ void AssemblyDebuggerCtrl::updateGUI(bool _success, DebuggingStatusResult _reaso 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]() { diff --git a/mix/AssemblyDebuggerCtrl.h b/mix/AssemblyDebuggerCtrl.h index 7d630836d..114610246 100644 --- a/mix/AssemblyDebuggerCtrl.h +++ b/mix/AssemblyDebuggerCtrl.h @@ -14,13 +14,13 @@ /** @file AssemblyDebuggerCtrl.h * @author Yann yann@ethdev.com * @date 2014 - * Display debugging steps in assembly code.s + * Extension which display debugging steps in assembly code. */ #pragma once #include -#include "QTextDocument" +#include #include "Extension.h" #include "ConstantCompilationModel.h" #include "TransactionListModel.h" @@ -43,12 +43,15 @@ namespace dev 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 { Q_OBJECT public: - AssemblyDebuggerCtrl(QTextDocument*); + AssemblyDebuggerCtrl(QTextDocument* _doc); ~AssemblyDebuggerCtrl() {} void start() const override; QString title() const override; @@ -61,16 +64,20 @@ private: std::unique_ptr m_modelDebugger; std::unique_ptr 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; public slots: + /// handle key pressed. F5 deploy contract - F6 reset state. void keyPressed(int); - void updateGUI(bool _success, DebuggingStatusResult _reason, QList _returnParams = QList(), QList _wStates = QList(), AssemblyDebuggerData _code = AssemblyDebuggerData()); - void runTransaction(TransactionSettings _tr); + /// 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. + void runTransaction(TransactionSettings const& _tr); signals: - void dataAvailable(bool _success, DebuggingStatusResult _reason, QList _returnParams = QList(), QList _wStates = QList(), AssemblyDebuggerData _code = AssemblyDebuggerData()); + /// 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.cpp b/mix/AssemblyDebuggerModel.cpp index af6de8ed7..c823f982e 100644 --- a/mix/AssemblyDebuggerModel.cpp +++ b/mix/AssemblyDebuggerModel.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 AssemblyDebuggerModel.h +/** @file AssemblyDebuggerModel.cpp * @author Yann yann@ethdev.com * @date 2014 * used as a model to debug contract assembly code. @@ -42,13 +42,10 @@ AssemblyDebuggerModel::AssemblyDebuggerModel(): m_currentExecution = std::unique_ptr(new Executive(m_executiveState, 0)); } -DebuggingContent AssemblyDebuggerModel::executeTransaction(bytesConstRef _rawTransaction) +DebuggingContent AssemblyDebuggerModel::executeTransaction(bytesConstRef const& _rawTransaction) { - QList machineStates; - // Reset the state back to our clean premine. - m_currentExecution = std::unique_ptr(new Executive(m_executiveState, 0)); - QList states; + m_currentExecution.reset(new Executive(m_executiveState, 0)); m_currentExecution->setup(_rawTransaction); std::vector levels; bytes code; @@ -89,12 +86,12 @@ DebuggingContent AssemblyDebuggerModel::executeTransaction(bytesConstRef _rawTra return d; } -DebuggingContent AssemblyDebuggerModel::getContractInitiationDebugStates(bytes _code) +DebuggingContent AssemblyDebuggerModel::deployContract(bytes const& _code) { u256 gasPrice = 10000000000000; u256 gas = 1000000; 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(); dev::bytesConstRef bytesRef = &b; DebuggingContent d = executeTransaction(bytesRef); @@ -103,11 +100,9 @@ DebuggingContent AssemblyDebuggerModel::getContractInitiationDebugStates(bytes _ return d; } -DebuggingContent AssemblyDebuggerModel::getContractCallDebugStates(Address _contract, bytes _data, - dev::mix::TransactionSettings _tr) +DebuggingContent AssemblyDebuggerModel::callContract(Address const& _contract, bytes const& _data, TransactionSettings const& _tr) { - - 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()); + 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(); dev::bytesConstRef bytesRef = &b; DebuggingContent d = executeTransaction(bytesRef); @@ -117,5 +112,6 @@ DebuggingContent AssemblyDebuggerModel::getContractCallDebugStates(Address _cont void AssemblyDebuggerModel::resetState() { + // Reset the state back to our clean premine. m_executiveState = m_baseState; } diff --git a/mix/AssemblyDebuggerModel.h b/mix/AssemblyDebuggerModel.h index a9c3e461c..21a0c1f7b 100644 --- a/mix/AssemblyDebuggerModel.h +++ b/mix/AssemblyDebuggerModel.h @@ -40,9 +40,11 @@ class AssemblyDebuggerModel { public: AssemblyDebuggerModel(); - DebuggingContent getContractCallDebugStates(Address _contract, bytes _data, dev::mix::TransactionSettings _tr); - DebuggingContent getContractInitiationDebugStates(bytes _code); - bool compile(QString); + /// call function in a already deployed contract. + DebuggingContent callContract(Address const& _contract, bytes const& _data, TransactionSettings const& _tr); + /// deploy the contract described by _code. + DebuggingContent deployContract(bytes const& _code); + /// reset state to the base state. void resetState(); private: @@ -51,9 +53,8 @@ private: eth::State m_baseState; eth::State m_executiveState; std::unique_ptr m_currentExecution; - DebuggingContent executeTransaction(dev::bytesConstRef _rawTransaction); + DebuggingContent executeTransaction(dev::bytesConstRef const& _rawTransaction); }; } - } diff --git a/mix/CodeEditorExtensionManager.h b/mix/CodeEditorExtensionManager.h index 9e931664d..af1e984ad 100644 --- a/mix/CodeEditorExtensionManager.h +++ b/mix/CodeEditorExtensionManager.h @@ -22,7 +22,6 @@ #pragma once -#include "memory" #include #include #include @@ -33,6 +32,9 @@ namespace dev namespace mix { +/** + * @brief Init and provides connection between extensions. + */ class CodeEditorExtensionManager: public QObject { Q_OBJECT @@ -44,10 +46,15 @@ class CodeEditorExtensionManager: public QObject public: CodeEditorExtensionManager() {} ~CodeEditorExtensionManager(); + /// initialize all extensions. void initExtensions(); + /// initialize extension. void initExtension(std::shared_ptr); + /// set current text editor. void setEditor(QQuickItem*); + /// set current tab view void setTabView(QQuickItem*); + /// set current right tab view. void setRightTabView(QQuickItem*); private: @@ -56,9 +63,8 @@ private: QQuickItem* m_tabView; QQuickItem* m_rightTabView; QTextDocument* m_doc; - void loadEditor(QQuickItem*); + void loadEditor(QQuickItem* _editor); }; } - } diff --git a/mix/ConstantCompilationCtrl.h b/mix/ConstantCompilationCtrl.h index 4e6aa53de..ba75c11ab 100644 --- a/mix/ConstantCompilationCtrl.h +++ b/mix/ConstantCompilationCtrl.h @@ -28,12 +28,15 @@ namespace dev namespace mix { +/** + * @brief Extension which display assembly code of the contract being edited. + */ class ConstantCompilationCtrl: public Extension { Q_OBJECT public: - ConstantCompilationCtrl(QTextDocument*); + ConstantCompilationCtrl(QTextDocument* _doc); ~ConstantCompilationCtrl() {} void start() const override; QString title() const override; @@ -42,13 +45,13 @@ public: private: QTextDocument* m_editor; std::unique_ptr m_compilationModel; - void writeOutPut(CompilerResult const&); + void writeOutPut(CompilerResult const& _res); void resetOutPut(); public slots: + /// compile text editor content. void compile(); }; } - } diff --git a/mix/ConstantCompilationModel.h b/mix/ConstantCompilationModel.h index cecb0d817..68d75cea3 100644 --- a/mix/ConstantCompilationModel.h +++ b/mix/ConstantCompilationModel.h @@ -22,15 +22,18 @@ #pragma once +#include #include #include -#include namespace dev { namespace mix { +/** + * @brief Provides compiler result information. + */ struct CompilerResult { QString hexCode; @@ -39,12 +42,16 @@ struct CompilerResult bool success; }; +/** + * @brief Compile source code using the solidity library. + */ class ConstantCompilationModel { public: ConstantCompilationModel() {} ~ConstantCompilationModel() {} + /// compile code. CompilerResult compile(QString _code); }; diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index 23d16a054..ff8048275 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -24,7 +24,7 @@ #include #include #include -#include "libsolidity/AST.h" +#include #include "QVariableDeclaration.h" #include "QVariableDefinition.h" #include "ContractCallDataEncoder.h" @@ -38,10 +38,6 @@ ContractCallDataEncoder::ContractCallDataEncoder() bytes ContractCallDataEncoder::encodedData() { - std::ostringstream si; - si << std::hex << toJS(m_encodedData); - qDebug() << "encoded data"; - qDebug() << si; return m_encodedData; } @@ -58,9 +54,6 @@ void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, bool _value) void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, QString _value) { - qDebug() << _dec->type(); - qDebug() << _value; - qDebug() << "(())"; int padding = this->padding(_dec->type()); bytes data = padded(jsToBytes(_value.toStdString()), padding); 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) { int padding = this->padding(_dec->type()); - - qDebug() << _dec->type(); std::ostringstream s; s << std::hex << "0x" << _value; - qDebug() << QString::fromStdString(s.str()); 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()); encodedData(); } @@ -88,15 +73,12 @@ QList ContractCallDataEncoder::decode(QList _ret { QList r; std::string returnValue = toJS(_value); - qDebug() << QString::fromStdString(returnValue); returnValue = returnValue.substr(2, returnValue.length() - 1); - for (int k = 0; k <_returnParameters.length(); k++) { QVariableDeclaration* dec = (QVariableDeclaration*)_returnParameters.at(k); int padding = this->padding(dec->type()); std::string rawParam = returnValue.substr(0, padding * 2); - qDebug() << QString::fromStdString(rawParam); r.append(new QVariableDefinition(dec, convertToReadable(unpadded(rawParam), dec))); 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); - //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); std::stringstream ss; ss << std::dec << x; return QString::fromStdString(ss.str()); } - diff --git a/mix/ContractCallDataEncoder.h b/mix/ContractCallDataEncoder.h index 4677b97c8..c303a9d90 100644 --- a/mix/ContractCallDataEncoder.h +++ b/mix/ContractCallDataEncoder.h @@ -30,27 +30,35 @@ namespace dev namespace mix { +/** + * @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. void encode(QVariableDeclaration* _dec, QString _value); + /// encode variable in order to be sent as parameter. void encode(QVariableDeclaration* _dec, u256 _value); - QList decode(QList _dec, bytes _value); + /// encode variable in order to be sent as parameter. void encode(QVariableDeclaration* _dec, bool _value); + /// 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. bytes encodedData(); private: QMap typePadding; int padding(QString _type); + bytes m_encodedData; static QString convertToReadable(std::string _v, QVariableDeclaration* _dec); static QString convertToBool(std::string _v); static QString convertToInt(std::string _v); static int integerPadding(int _bitValue); static QString formatBool(bool _value); - bytes m_encodedData; - }; } diff --git a/mix/DebuggingStateWrapper.cpp b/mix/DebuggingStateWrapper.cpp index 6ce6a07be..72bb02ecd 100644 --- a/mix/DebuggingStateWrapper.cpp +++ b/mix/DebuggingStateWrapper.cpp @@ -23,11 +23,11 @@ #include #include #include -#include "libevmcore/Instruction.h" -#include "libdevcore/CommonJS.h" -#include "libdevcrypto/Common.h" -#include "libevmcore/Instruction.h" -#include "libdevcore/Common.h" +#include +#include +#include +#include +#include #include "DebuggingStateWrapper.h" using namespace dev; using namespace dev::eth; diff --git a/mix/DebuggingStateWrapper.h b/mix/DebuggingStateWrapper.h index 77bebb242..be969b1d1 100644 --- a/mix/DebuggingStateWrapper.h +++ b/mix/DebuggingStateWrapper.h @@ -23,9 +23,9 @@ #pragma once #include -#include "libethereum/State.h" -#include "libethereum/Executive.h" -#include "libdevcore/Common.h" +#include +#include +#include #include "QVariableDefinition.h" namespace dev @@ -33,6 +33,9 @@ namespace dev namespace mix { +/** + * @brief Store information about a machine state. + */ struct DebuggingState { uint64_t steps; @@ -48,6 +51,9 @@ struct DebuggingState std::vector levels; }; +/** + * @brief Store information about a machine states. + */ struct DebuggingContent { QList machineStates; @@ -71,7 +77,9 @@ class HumanReadableCode: public QObject public: HumanReadableCode(QString _line, int _processIndex): QObject(), m_line(_line), m_processIndex(_processIndex) {} + /// get the assembly code line. QString line() { return m_line; } + /// get corresponding index. int processIndex() { return m_processIndex; } private: @@ -89,6 +97,7 @@ class QQMLMap: public QObject public: QQMLMap(QMap _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); } private: @@ -116,20 +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. int step() { return (int)m_state.steps; } + /// get the proccessed code. int curPC() { return (int)m_state.curPC; } + /// get gas left. QString gasLeft(); + /// get gas cost. QString gasCost(); + /// get gas used. QString gas(); + /// get stack. QString debugStack(); + /// get storage. QString debugStorage(); + /// get memory. QString debugMemory(); + /// get call data. QString debugCallData(); + /// get info to be displayed in the header. QString headerInfo(); + /// get end of debug information. QString endOfDebug(); + /// get all previous steps. QStringList levels(); + /// get the current processed machine state. DebuggingState state() { return m_state; } + /// set the current processed machine state. void setState(DebuggingState _state) { m_state = _state; } + /// 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 f983cd74c..9f29a0290 100644 --- a/mix/Extension.h +++ b/mix/Extension.h @@ -43,12 +43,19 @@ class Extension: public QObject public: Extension(); Extension(ExtensionDisplayBehavior _displayBehavior); + /// return the QML url of the view to display. virtual QString contentUrl() const { return ""; } + /// reuturn the title of this extension. virtual QString title() const { return ""; } + /// initialize extension. 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); + /// modify the display behavior of this extension. void setDisplayBehavior(ExtensionDisplayBehavior _displayBehavior) { m_displayBehavior = _displayBehavior; } + /// get the display behavior of thi extension. ExtensionDisplayBehavior getDisplayBehavior() { return m_displayBehavior; } protected: @@ -62,5 +69,4 @@ private: }; } - } diff --git a/mix/KeyEventManager.h b/mix/KeyEventManager.h index f3343cc45..65f9b4a01 100644 --- a/mix/KeyEventManager.h +++ b/mix/KeyEventManager.h @@ -30,13 +30,17 @@ class KeyEventManager: public QObject public: KeyEventManager() {} + /// allows _receiver to handle key pressed event. void registerEvent(const QObject* _receiver, const char* _slot); + /// unregister _receiver. void unRegisterEvent(QObject* _receiver); signals: - void onKeyPressed(int); + /// emited when a key is pressed. + void onKeyPressed(int _event); public slots: + /// called when a key is pressed. void keyPressed(QVariant _event); }; diff --git a/mix/MixApplication.h b/mix/MixApplication.h index 383c5849c..62c37bb5c 100644 --- a/mix/MixApplication.h +++ b/mix/MixApplication.h @@ -41,5 +41,4 @@ public: }; } - } diff --git a/mix/QBasicNodeDefinition.cpp b/mix/QBasicNodeDefinition.cpp deleted file mode 100644 index 5a8378500..000000000 --- a/mix/QBasicNodeDefinition.cpp +++ /dev/null @@ -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 . -*/ -/** @file QBasicNodeDefinition.cpp - * @author Yann yann@ethdev.com - * @date 2014 - */ - -#include "QBasicNodeDefinition.h" - diff --git a/mix/QBasicNodeDefinition.h b/mix/QBasicNodeDefinition.h index 39c592279..7d3ee475a 100644 --- a/mix/QBasicNodeDefinition.h +++ b/mix/QBasicNodeDefinition.h @@ -22,7 +22,7 @@ #pragma once #include -#include "libsolidity/AST.h" +#include namespace dev { @@ -36,9 +36,9 @@ class QBasicNodeDefinition: public QObject public: QBasicNodeDefinition(): QObject() {} - ~QBasicNodeDefinition() { - } + ~QBasicNodeDefinition() {} QBasicNodeDefinition(dev::solidity::Declaration* _d): QObject(), m_dec(_d) {} + /// get the name of the node. QString name() const { return QString::fromStdString(m_dec->getName()); } protected: diff --git a/mix/QContractDefinition.cpp b/mix/QContractDefinition.cpp index bf85030f5..e469bd629 100644 --- a/mix/QContractDefinition.cpp +++ b/mix/QContractDefinition.cpp @@ -20,12 +20,11 @@ */ #include -#include "QContractDefinition.h" -#include "libsolidity/AST.h" -#include "libsolidity/Scanner.h" -#include "libsolidity/Parser.h" -#include "libsolidity/Scanner.h" -#include "libsolidity/NameAndTypeResolver.h" +#include +#include +#include +#include +#include #include "AppContext.h" #include "QContractDefinition.h" using namespace dev::solidity; diff --git a/mix/QContractDefinition.h b/mix/QContractDefinition.h index 7cc145cf8..fdbd29c3e 100644 --- a/mix/QContractDefinition.h +++ b/mix/QContractDefinition.h @@ -22,7 +22,7 @@ #pragma once #include -#include "libsolidity/AST.h" +#include #include "QFunctionDefinition.h" #include "QBasicNodeDefinition.h" @@ -38,7 +38,9 @@ class QContractDefinition: public QBasicNodeDefinition public: QContractDefinition(dev::solidity::ContractDefinition* _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. static std::shared_ptr Contract(QString _code); private: diff --git a/mix/QFunctionDefinition.cpp b/mix/QFunctionDefinition.cpp index 9923e5277..3f8e19290 100644 --- a/mix/QFunctionDefinition.cpp +++ b/mix/QFunctionDefinition.cpp @@ -19,9 +19,9 @@ * @date 2014 */ +#include #include "QVariableDeclaration.h" #include "QFunctionDefinition.h" -#include "libsolidity/AST.h" using namespace dev::solidity; using namespace dev::mix; diff --git a/mix/QFunctionDefinition.h b/mix/QFunctionDefinition.h index 877e1bd53..000a54f6e 100644 --- a/mix/QFunctionDefinition.h +++ b/mix/QFunctionDefinition.h @@ -38,8 +38,11 @@ class QFunctionDefinition: public QBasicNodeDefinition 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. int index() const { return m_index; } private: diff --git a/mix/QVariableDeclaration.cpp b/mix/QVariableDeclaration.cpp deleted file mode 100644 index d8e07a689..000000000 --- a/mix/QVariableDeclaration.cpp +++ /dev/null @@ -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 . -*/ -/** @file QVariableDeclaration.cpp - * @author Yann yann@ethdev.com - * @date 2014 - */ - -#include "QVariableDeclaration.h" -using namespace dev::mix; diff --git a/mix/QVariableDeclaration.h b/mix/QVariableDeclaration.h index b4fd0ca6f..5e89c1c1b 100644 --- a/mix/QVariableDeclaration.h +++ b/mix/QVariableDeclaration.h @@ -19,7 +19,7 @@ * @date 2014 */ -#include "libsolidity/AST.h" +#include #include "QBasicNodeDefinition.h" #pragma once @@ -36,6 +36,7 @@ class QVariableDeclaration: public QBasicNodeDefinition public: 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()); } }; diff --git a/mix/QVariableDefinition.h b/mix/QVariableDefinition.h index 52eed5eec..fdea5ff34 100644 --- a/mix/QVariableDefinition.h +++ b/mix/QVariableDefinition.h @@ -38,7 +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. QVariableDeclaration* declaration() const { return m_dec; } + /// return the variable value. QString value() const { return m_value; } private: @@ -55,7 +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; - QVariableDefinition* val(int idx); + /// return the variable definition at index _idx. + QVariableDefinition* val(int _idx); + /// return the list of variables. QList def() { return m_def; } private: