Browse Source

coding standards

cl-refactor
arkpar 10 years ago
parent
commit
1626213af0
  1. 10
      mix/AssemblyDebuggerControl.h
  2. 28
      mix/CodeHighlighter.cpp
  3. 17
      mix/CodeHighlighter.h
  4. 16
      mix/CodeModel.cpp
  5. 4
      mix/CodeModel.h
  6. 1
      mix/StateListView.cpp

10
mix/AssemblyDebuggerControl.h

@ -19,6 +19,7 @@
#pragma once #pragma once
#include <atomic>
#include <QKeySequence> #include <QKeySequence>
#include "Extension.h" #include "Extension.h"
#include "AssemblyDebuggerModel.h" #include "AssemblyDebuggerModel.h"
@ -55,7 +56,7 @@ private:
void executeSequence(std::vector<TransactionSettings> const& _sequence, u256 _balance); void executeSequence(std::vector<TransactionSettings> const& _sequence, u256 _balance);
std::unique_ptr<AssemblyDebuggerModel> m_modelDebugger; std::unique_ptr<AssemblyDebuggerModel> m_modelDebugger;
bool m_running; std::atomic<bool> m_running;
public slots: public slots:
/// Run the contract constructor and show debugger window. /// Run the contract constructor and show debugger window.
@ -67,13 +68,18 @@ public slots:
private slots: private slots:
/// Update UI with machine states result. Display a modal dialog. /// Update UI with machine states result. Display a modal dialog.
void showDebugger(QList<QVariableDefinition*> const& _returnParams = QList<QVariableDefinition*>(), QList<QObject*> const& _wStates = QList<QObject*>(), AssemblyDebuggerData const& _code = AssemblyDebuggerData()); void showDebugger(QList<QVariableDefinition*> const& _returnParams = QList<QVariableDefinition*>(), QList<QObject*> const& _wStates = QList<QObject*>(), AssemblyDebuggerData const& _code = AssemblyDebuggerData());
/// Update UI with transaction run error.
void showDebugError(QString const& _error); void showDebugError(QString const& _error);
signals: signals:
/// Transaction execution started
void runStarted(); void runStarted();
/// Transaction execution completed successfully
void runComplete(); void runComplete();
/// Transaction execution completed with error
/// @param _message Error message
void runFailed(QString const& _message); void runFailed(QString const& _message);
/// Execution state changed
void stateChanged(); void stateChanged();
/// Emited when machine states are available. /// Emited when machine states are available.

28
mix/CodeHighlighter.cpp

@ -25,25 +25,22 @@
#include <QTextDocument> #include <QTextDocument>
#include <QTextBlock> #include <QTextBlock>
#include <QTextLayout> #include <QTextLayout>
#include <libsolidity/ASTVisitor.h>
#include <libsolidity/AST.h>
#include <libsolidity/Scanner.h>
#include <libsolidity/Exceptions.h>
#include "CodeHighlighter.h" #include "CodeHighlighter.h"
#include "libsolidity/ASTVisitor.h"
#include "libsolidity/AST.h"
#include "libsolidity/Scanner.h"
#include "libsolidity/Exceptions.h"
namespace dev using namespace dev::mix;
{
namespace mix
{
CodeHighlighterSettings::CodeHighlighterSettings() CodeHighlighterSettings::CodeHighlighterSettings()
{ {
bg = QColor(0x00, 0x2b, 0x36); backgroundColor = QColor(0x00, 0x2b, 0x36);
fg = QColor (0xee, 0xe8, 0xd5); foregroundColor = QColor (0xee, 0xe8, 0xd5);
formats[Keyword].setForeground(QColor(0x93, 0xa1, 0xa1)); formats[Keyword].setForeground(QColor(0x93, 0xa1, 0xa1));
formats[Comment].setForeground(QColor(0x85, 0x99, 0x00)); formats[Comment].setForeground(QColor(0x85, 0x99, 0x00));
formats[StringLiteral].setForeground(QColor(0xdc, 0x32, 0x2f)); formats[StringLiteral].setForeground(QColor(0xdc, 0x32, 0x2f));
formats[NumLiteral].setForeground(fg); formats[NumLiteral].setForeground(foregroundColor);
formats[Import].setForeground(QColor(0x6c, 0x71, 0xc4)); formats[Import].setForeground(QColor(0x6c, 0x71, 0xc4));
formats[CompilationError].setUnderlineColor(Qt::red); formats[CompilationError].setUnderlineColor(Qt::red);
formats[CompilationError].setUnderlineStyle(QTextCharFormat::SingleUnderline); formats[CompilationError].setUnderlineStyle(QTextCharFormat::SingleUnderline);
@ -52,7 +49,7 @@ CodeHighlighterSettings::CodeHighlighterSettings()
namespace namespace
{ {
using namespace dev::solidity; using namespace dev::solidity;
class HighlightVisitor : public solidity::ASTConstVisitor class HighlightVisitor : public ASTConstVisitor
{ {
public: public:
HighlightVisitor(CodeHighlighter::Formats* _formats) { m_formats = _formats; } HighlightVisitor(CodeHighlighter::Formats* _formats) { m_formats = _formats; }
@ -67,7 +64,6 @@ namespace
}; };
} }
CodeHighlighter::FormatRange::FormatRange(CodeHighlighterSettings::Token _t, solidity::Location const& _location): CodeHighlighter::FormatRange::FormatRange(CodeHighlighterSettings::Token _t, solidity::Location const& _location):
token(_t), start(_location.start), length(_location.end - _location.start) token(_t), start(_location.start), length(_location.end - _location.start)
{} {}
@ -172,9 +168,3 @@ void CodeHighlighter::updateFormatting(QTextDocument* _document, CodeHighlighter
++format; ++format;
} }
} }
}
}

17
mix/CodeHighlighter.h

@ -42,6 +42,7 @@ namespace solidity
namespace mix namespace mix
{ {
/// Code highligting settings
class CodeHighlighterSettings class CodeHighlighterSettings
{ {
public: public:
@ -60,15 +61,16 @@ public:
///Format for each token ///Format for each token
QTextCharFormat formats[Size]; QTextCharFormat formats[Size];
///Background color ///Background color
QColor bg; QColor backgroundColor;
///Foreground color ///Foreground color
QColor fg; QColor foregroundColor;
}; };
/// Code highlighting engine class
class CodeHighlighter class CodeHighlighter
{ {
public: public:
/// Formatting range
struct FormatRange struct FormatRange
{ {
FormatRange(CodeHighlighterSettings::Token _t, int _start, int _length): token(_t), start(_start), length(_length) {} FormatRange(CodeHighlighterSettings::Token _t, int _start, int _length): token(_t), start(_start), length(_length) {}
@ -82,13 +84,20 @@ public:
typedef std::vector<FormatRange> Formats; // Sorted by start position typedef std::vector<FormatRange> Formats; // Sorted by start position
public: public:
/// Collect highligting information /// Collect highligting information by lexing the source
void processSource(std::string const& _source); void processSource(std::string const& _source);
/// Collect additional highligting information from AST
void processAST(solidity::ASTNode const& _ast); void processAST(solidity::ASTNode const& _ast);
/// Collect highlighting information from compilation exception
void processError(dev::Exception const& _exception); void processError(dev::Exception const& _exception);
/// Apply formatting for a text document
/// @todo Remove this once editor is reworked
void updateFormatting(QTextDocument* _document, CodeHighlighterSettings const& _settings); void updateFormatting(QTextDocument* _document, CodeHighlighterSettings const& _settings);
private: private:
/// Collect highligting information by paring for comments
/// @todo Support this in solidity?
void processComments(std::string const& _source); void processComments(std::string const& _source);
private: private:

16
mix/CodeModel.cpp

@ -33,10 +33,7 @@
#include "CodeHighlighter.h" #include "CodeHighlighter.h"
#include "CodeModel.h" #include "CodeModel.h"
namespace dev using namespace dev::mix;
{
namespace mix
{
void BackgroundWorker::queueCodeChange(int _jobId, QString const& _content) void BackgroundWorker::queueCodeChange(int _jobId, QString const& _content)
{ {
@ -45,13 +42,13 @@ void BackgroundWorker::queueCodeChange(int _jobId, QString const& _content)
CompilationResult::CompilationResult(): CompilationResult::CompilationResult():
QObject(nullptr), m_successfull(false), QObject(nullptr), m_successfull(false),
m_codeHash(qHash(QString())),
m_contract(new QContractDefinition()), m_contract(new QContractDefinition()),
m_codeHighlighter(new CodeHighlighter()), m_codeHighlighter(new CodeHighlighter())
m_codeHash(qHash(QString()))
{} {}
CompilationResult::CompilationResult(const solidity::CompilerStack& _compiler): CompilationResult::CompilationResult(const solidity::CompilerStack& _compiler):
QObject(nullptr), m_successfull(true) QObject(nullptr), m_successfull(true), m_codeHash(qHash(QString()))
{ {
if (!_compiler.getContractNames().empty()) if (!_compiler.getContractNames().empty())
{ {
@ -64,7 +61,7 @@ CompilationResult::CompilationResult(const solidity::CompilerStack& _compiler):
} }
CompilationResult::CompilationResult(CompilationResult const& _prev, QString const& _compilerMessage): CompilationResult::CompilationResult(CompilationResult const& _prev, QString const& _compilerMessage):
QObject(nullptr), m_successfull(false), QObject(nullptr), m_successfull(false), m_codeHash(qHash(QString())),
m_contract(_prev.m_contract), m_contract(_prev.m_contract),
m_compilerMessage(_compilerMessage), m_compilerMessage(_compilerMessage),
m_bytes(_prev.m_bytes), m_bytes(_prev.m_bytes),
@ -168,6 +165,3 @@ void CodeModel::updateFormatting(QTextDocument* _document)
{ {
m_result->codeHighlighter()->updateFormatting(_document, *m_codeHighlighterSettings); m_result->codeHighlighter()->updateFormatting(_document, *m_codeHighlighterSettings);
} }
}
}

4
mix/CodeModel.h

@ -91,14 +91,14 @@ public:
private: private:
bool m_successfull; bool m_successfull;
uint m_codeHash;
std::shared_ptr<QContractDefinition> m_contract; std::shared_ptr<QContractDefinition> m_contract;
QString m_compilerMessage; ///< @todo: use some structure here QString m_compilerMessage; ///< @todo: use some structure here
dev::bytes m_bytes; dev::bytes m_bytes;
QString m_assemblyCode; QString m_assemblyCode;
std::shared_ptr<CodeHighlighter> m_codeHighlighter; std::shared_ptr<CodeHighlighter> m_codeHighlighter;
///@todo syntax highlighting, etc
friend class CodeModel; friend class CodeModel;
uint m_codeHash;
}; };
/// Background code compiler /// Background code compiler

1
mix/StateListView.cpp

@ -26,6 +26,7 @@
#include <QQmlContext> #include <QQmlContext>
#include <QDebug> #include <QDebug>
#include "StateListView.h" #include "StateListView.h"
using namespace dev::mix; using namespace dev::mix;
StateListView::StateListView(AppContext* _context): Extension(_context, ExtensionDisplayBehavior::RightTab) StateListView::StateListView(AppContext* _context): Extension(_context, ExtensionDisplayBehavior::RightTab)

Loading…
Cancel
Save