Browse Source

- Capitals on comments.

- Class suffix renamed Ctrl => Control.
 - Use specialized QList (QVariableDeclaration instead of QObject).
 - Use CompilerStack::getContractDefinition instead of
CompilerStack::getAst.
cl-refactor
yann300 10 years ago
parent
commit
68dd4f1ffd
  1. 18
      mix/AppContext.h
  2. 80
      mix/AssemblyDebuggerControl.cpp
  3. 16
      mix/AssemblyDebuggerControl.h
  4. 8
      mix/AssemblyDebuggerModel.h
  5. 10
      mix/CodeEditorExtensionManager.cpp
  6. 12
      mix/CodeEditorExtensionManager.h
  7. 26
      mix/ConstantCompilationControl.cpp
  8. 10
      mix/ConstantCompilationControl.h
  9. 2
      mix/ConstantCompilationModel.h
  10. 2
      mix/ContractCallDataEncoder.cpp
  11. 16
      mix/ContractCallDataEncoder.h
  12. 34
      mix/DebuggingStateWrapper.h
  13. 14
      mix/Extension.h
  14. 10
      mix/KeyEventManager.h
  15. 6
      mix/QBasicNodeDefinition.h
  16. 5
      mix/QContractDefinition.cpp
  17. 6
      mix/QContractDefinition.h
  18. 19
      mix/QFunctionDefinition.h
  19. 2
      mix/QVariableDeclaration.h
  20. 8
      mix/QVariableDefinition.h

18
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<solidity::CompilerStack> 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); }
};

80
mix/AssemblyDebuggerCtrl.cpp → 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 <http://www.gnu.org/licenses/>.
*/
/** @file AssemblyDebuggerCtrl.cpp
/** @file AssemblyDebuggerControl.cpp
* @author Yann yann@ethdev.com
* @date 2014
* display opcode debugging.
@ -25,7 +25,7 @@
#include <libdevcore/CommonJS.h>
#include <libethereum/Transaction.h>
#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*>("QVariableDefinition*");
qRegisterMetaType<QVariableDefinitionList*>("QVariableDefinitionList*");
qRegisterMetaType<QList<QVariableDefinition*>>("QList<QVariableDefinition*>");
qRegisterMetaType<QList<QVariableDeclaration*>>("QList<QVariableDeclaration*>");
qRegisterMetaType<QVariableDeclaration*>("QVariableDeclaration*");
qRegisterMetaType<AssemblyDebuggerData>("AssemblyDebuggerData");
qRegisterMetaType<DebuggingStatusResult>("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<QContractDefinition> 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<QContractDefinition> 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<QObject*> 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<QVariableDefinition*> const& _returnParam, QList<QObject*> const& _wStates, AssemblyDebuggerData const& _code)
void AssemblyDebuggerControl::updateGUI(bool _success, DebuggingStatusResult const& _reason, QList<QVariableDefinition*> const& _returnParam, QList<QObject*> 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]()
{

16
mix/AssemblyDebuggerCtrl.h → 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 <http://www.gnu.org/licenses/>.
*/
/** @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<QVariableDefinition*> const& _returnParams = QList<QVariableDefinition*>(), QList<QObject*> const& _wStates = QList<QObject*>(), 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<QVariableDefinition*> const& _returnParams = QList<QVariableDefinition*>(), QList<QObject*> const& _wStates = QList<QObject*>(), AssemblyDebuggerData const& _code = AssemblyDebuggerData());
};

8
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:

10
mix/CodeEditorExtensionManager.cpp

@ -26,8 +26,8 @@
#include <QQmlComponent>
#include <QQuickTextDocument>
#include <libevm/VM.h>
#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<ConstantCompilationCtrl>(m_doc));
std::shared_ptr<AssemblyDebuggerCtrl> debug = std::make_shared<AssemblyDebuggerCtrl>(m_doc);
initExtension(std::make_shared<ConstantCompilationControl>(m_doc));
std::shared_ptr<AssemblyDebuggerControl> debug = std::make_shared<AssemblyDebuggerControl>(m_doc);
std::shared_ptr<TransactionListView> tr = std::make_shared<TransactionListView>(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);
}

12
mix/CodeEditorExtensionManager.h

@ -25,7 +25,7 @@
#include <QQuickItem>
#include <QTextDocument>
#include <QVector>
#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<Extension>);
/// 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:

26
mix/ConstantCompilationCtrl.cpp → 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 <http://www.gnu.org/licenses/>.
*/
/** @file ConstantCompilationCtrl.cpp
/** @file ConstantCompilationControl.cpp
* @author Yann yann@ethdev.com
* @date 2014
* Ethereum IDE client.
@ -27,45 +27,45 @@
#include <QQmlApplicationEngine>
#include <QtCore/QtCore>
#include <QDebug>
#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<ConstantCompilationModel>(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<QObject*>("status", Qt::FindChildrenRecursively);
QObject* content = m_view->findChild<QObject*>("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<QObject*>("status", Qt::FindChildrenRecursively);
QObject* content = m_view->findChild<QObject*>("content", Qt::FindChildrenRecursively);

10
mix/ConstantCompilationCtrl.h → 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 <http://www.gnu.org/licenses/>.
*/
/** @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();
};

2
mix/ConstantCompilationModel.h

@ -51,7 +51,7 @@ class ConstantCompilationModel
public:
ConstantCompilationModel() {}
~ConstantCompilationModel() {}
/// compile code.
/// Compile code.
CompilerResult compile(QString _code);
};

2
mix/ContractCallDataEncoder.cpp

@ -65,7 +65,7 @@ void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, u256 _value)
encodedData();
}
QList<QVariableDefinition*> ContractCallDataEncoder::decode(QList<QObject*> _returnParameters, bytes _value)
QList<QVariableDefinition*> ContractCallDataEncoder::decode(QList<QVariableDeclaration*> _returnParameters, bytes _value)
{
QList<QVariableDefinition*> r;
std::string returnValue = toJS(_value);

16
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<QVariableDefinition*> decode(QList<QObject*> _dec, bytes _value);
/// get all encoded data encoded by encode function.
/// Decode variable in order to be sent to QML view.
QList<QVariableDefinition*> decode(QList<QVariableDeclaration*> _dec, bytes _value);
/// Get all encoded data encoded by encode function.
bytes encodedData();
private:

34
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<int, int> _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<QList<QObject*>, QQMLMap*> getHumanReadableCode(bytes const& _code);
private:

14
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:

10
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);
};

6
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;
};
}

5
mix/QContractDefinition.cpp

@ -35,12 +35,11 @@ std::shared_ptr<QContractDefinition> 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<QContractDefinition>(def);
}
QContractDefinition::QContractDefinition(ContractDefinition* _contract): QBasicNodeDefinition(_contract)
QContractDefinition::QContractDefinition(ContractDefinition const* _contract): QBasicNodeDefinition(_contract)
{
initQFunctions();
}

6
mix/QContractDefinition.h

@ -37,10 +37,10 @@ class QContractDefinition: public QBasicNodeDefinition
Q_PROPERTY(QList<QFunctionDefinition*> 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<QFunctionDefinition*> 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<QContractDefinition> Contract(QString _code);
private:

19
mix/QFunctionDefinition.h

@ -23,6 +23,7 @@
#include <QObject>
#include <libsolidity/AST.h>
#include <QVariableDeclaration.h>
#include "QBasicNodeDefinition.h"
namespace dev
@ -33,21 +34,21 @@ namespace mix
class QFunctionDefinition: public QBasicNodeDefinition
{
Q_OBJECT
Q_PROPERTY(QList<QObject*> parameters READ parameters)
Q_PROPERTY(QList<QVariableDeclaration*> 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<QObject*> parameters() const { return m_parameters; }
/// get all return parameters of this function.
QList<QObject*> 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<QVariableDeclaration*> parameters() const { return m_parameters; }
/// Get all return parameters of this function.
QList<QVariableDeclaration*> returnParameters() const { return m_returnParameters; }
/// Get the index of this function on the contract ABI.
int index() const { return m_index; }
private:
QList<QObject*> m_parameters;
QList<QObject*> m_returnParameters;
QList<QVariableDeclaration*> m_parameters;
QList<QVariableDeclaration*> m_returnParameters;
int m_index;
void initQParameters();
};

2
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()); }
};

8
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<int, QByteArray> 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<QVariableDefinition*> def() { return m_def; }
private:

Loading…
Cancel
Save