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
#include <atomic>
#include <QKeySequence>
#include "Extension.h"
#include "AssemblyDebuggerModel.h"
@ -55,7 +56,7 @@ private:
void executeSequence(std::vector<TransactionSettings> const& _sequence, u256 _balance);
std::unique_ptr<AssemblyDebuggerModel> m_modelDebugger;
bool m_running;
std::atomic<bool> m_running;
public slots:
/// Run the contract constructor and show debugger window.
@ -67,13 +68,18 @@ public slots:
private slots:
/// 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());
/// Update UI with transaction run error.
void showDebugError(QString const& _error);
signals:
/// Transaction execution started
void runStarted();
/// Transaction execution completed successfully
void runComplete();
/// Transaction execution completed with error
/// @param _message Error message
void runFailed(QString const& _message);
/// Execution state changed
void stateChanged();
/// Emited when machine states are available.

28
mix/CodeHighlighter.cpp

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

17
mix/CodeHighlighter.h

@ -42,6 +42,7 @@ namespace solidity
namespace mix
{
/// Code highligting settings
class CodeHighlighterSettings
{
public:
@ -60,15 +61,16 @@ public:
///Format for each token
QTextCharFormat formats[Size];
///Background color
QColor bg;
QColor backgroundColor;
///Foreground color
QColor fg;
QColor foregroundColor;
};
/// Code highlighting engine class
class CodeHighlighter
{
public:
/// Formatting range
struct FormatRange
{
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
public:
/// Collect highligting information
/// Collect highligting information by lexing the source
void processSource(std::string const& _source);
/// Collect additional highligting information from AST
void processAST(solidity::ASTNode const& _ast);
/// Collect highlighting information from compilation 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);
private:
/// Collect highligting information by paring for comments
/// @todo Support this in solidity?
void processComments(std::string const& _source);
private:

16
mix/CodeModel.cpp

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

4
mix/CodeModel.h

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

1
mix/StateListView.cpp

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

Loading…
Cancel
Save