subtly
10 years ago
78 changed files with 1770 additions and 621 deletions
@ -0,0 +1,35 @@ |
|||
cmake_policy(SET CMP0015 NEW) |
|||
# let cmake autolink dependencies on windows |
|||
cmake_policy(SET CMP0020 NEW) |
|||
# this policy was introduced in cmake 3.0 |
|||
# remove if, once 3.0 will be used on unix |
|||
if (${CMAKE_MAJOR_VERSION} GREATER 2) |
|||
# old policy do not use MACOSX_RPATH |
|||
cmake_policy(SET CMP0042 OLD) |
|||
cmake_policy(SET CMP0043 OLD) |
|||
endif() |
|||
set(CMAKE_AUTOMOC OFF) |
|||
|
|||
set(CMAKE_INCLUDE_CURRENT_DIR ON) |
|||
aux_source_directory(. SRC_LIST) |
|||
|
|||
include_directories(..) |
|||
|
|||
set(EXECUTABLE natspec) |
|||
|
|||
file(GLOB HEADERS "*.h") |
|||
|
|||
qt5_add_resources(NATSPECQRC natspec.qrc) |
|||
|
|||
if (ETH_STATIC) |
|||
add_library(${EXECUTABLE} STATIC ${RESOURCE_ADDED} ${SRC_LIST} ${HEADERS} ${NATSPECQRC}) |
|||
else() |
|||
add_library(${EXECUTABLE} SHARED ${RESOURCE_ADDED} ${SRC_LIST} ${HEADERS} ${NATSPECQRC}) |
|||
endif() |
|||
|
|||
target_link_libraries(${EXECUTABLE} Qt5::Core) |
|||
target_link_libraries(${EXECUTABLE} Qt5::Qml) |
|||
target_link_libraries(${EXECUTABLE} devcore) |
|||
|
|||
install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) |
|||
install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) |
@ -0,0 +1,59 @@ |
|||
/*
|
|||
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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file NatspecExpressionEvaluator.cpp
|
|||
* @author Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include <libdevcore/Log.h> |
|||
#include <libdevcore/Exceptions.h> |
|||
#include "NatspecExpressionEvaluator.h" |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
|
|||
static QString contentsOfQResource(string const& _res) |
|||
{ |
|||
QFile file(QString::fromStdString(_res)); |
|||
if (!file.open(QFile::ReadOnly)) |
|||
BOOST_THROW_EXCEPTION(FileError()); |
|||
QTextStream in(&file); |
|||
return in.readAll(); |
|||
} |
|||
|
|||
NatspecExpressionEvaluator::NatspecExpressionEvaluator(QString const& _abi, QString const& _method, QString const& _params) |
|||
{ |
|||
Q_INIT_RESOURCE(natspec); |
|||
QJSValue result = m_engine.evaluate(contentsOfQResource(":/natspec/natspec.js")); |
|||
if (result.isError()) |
|||
BOOST_THROW_EXCEPTION(FileError()); |
|||
|
|||
m_engine.evaluate("globals.abi = " + _abi); |
|||
m_engine.evaluate("globals.method = " + _method); |
|||
m_engine.evaluate("globals.params = " + _params); |
|||
} |
|||
|
|||
QString NatspecExpressionEvaluator::evalExpression(QString const& _expression) |
|||
{ |
|||
QJSValue result = m_engine.evaluate("evaluateExpression(\"" + _expression + "\")"); |
|||
if (result.isError()) |
|||
{ |
|||
cerr << "Could not evaluate expression: \"" << _expression.toStdString() << "\"" << endl; |
|||
return _expression; |
|||
} |
|||
return result.toString(); |
|||
} |
@ -0,0 +1,49 @@ |
|||
/*
|
|||
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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file NatspecExpressionEvaluator.h
|
|||
* @author Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include <QtCore/QObject> |
|||
#include <QtCore/QtCore> |
|||
#include <QtQml/QJSEngine> |
|||
|
|||
/**
|
|||
* Should be used to evaluate natspec expression. |
|||
* @see test/natspec.cpp for natspec expression examples |
|||
*/ |
|||
class NatspecExpressionEvaluator |
|||
{ |
|||
public: |
|||
/// Construct natspec expression evaluator
|
|||
/// @params abi - contract's abi in json format, passed as string
|
|||
/// @params method - name of the contract's method for which we evaluate the natspec.
|
|||
/// If we want to use raw string, it should be passed with quotation marks eg. "\"helloWorld\""
|
|||
/// If we pass string "helloWorld", the value of the object with name "helloWorld" will be used
|
|||
/// @params params - array of method input params, passed as string, objects in array should be
|
|||
/// javascript valid objects
|
|||
NatspecExpressionEvaluator(QString const& _abi = "[]", QString const& _method = "", QString const& _params = "[]"); |
|||
|
|||
/// Should be called to evaluate natspec expression
|
|||
/// @params expression - natspec expression
|
|||
/// @returns evaluated natspec expression if it was valid, otherwise original expression
|
|||
QString evalExpression(QString const& _expression); |
|||
|
|||
private: |
|||
QJSEngine m_engine; |
|||
}; |
@ -0,0 +1,5 @@ |
|||
<RCC> |
|||
<qresource prefix="/natspec"> |
|||
<file>natspec.js</file> |
|||
</qresource> |
|||
</RCC> |
@ -1,45 +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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file AssemblyDebuggerControl.cpp
|
|||
* @author Yann yann@ethdev.com |
|||
* @date 2014 |
|||
* display opcode debugging. |
|||
*/ |
|||
|
|||
#include <QDebug> |
|||
#include <QQmlContext> |
|||
#include <QQmlApplicationEngine> |
|||
#include "ClientModel.h" |
|||
#include "AssemblyDebuggerControl.h" |
|||
|
|||
using namespace dev::mix; |
|||
|
|||
AssemblyDebuggerControl::AssemblyDebuggerControl(AppContext* _context): |
|||
Extension(_context, ExtensionDisplayBehavior::RightView) |
|||
{ |
|||
} |
|||
|
|||
QString AssemblyDebuggerControl::contentUrl() const |
|||
{ |
|||
return QStringLiteral("qrc:/qml/Debugger.qml"); |
|||
} |
|||
|
|||
QString AssemblyDebuggerControl::title() const |
|||
{ |
|||
return QApplication::tr("Debugger"); |
|||
} |
|||
|
|||
void AssemblyDebuggerControl::start() const |
|||
{ |
|||
} |
@ -1,48 +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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file AssemblyDebuggerControl.h
|
|||
* @author Yann yann@ethdev.com |
|||
* @date 2014 |
|||
* Extension which display debugging steps in assembly code. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <atomic> |
|||
#include "Extension.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace mix |
|||
{ |
|||
|
|||
class AppContext; |
|||
|
|||
/**
|
|||
* @brief Extension which display transaction creation or transaction call debugging. |
|||
*/ |
|||
class AssemblyDebuggerControl: public Extension |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
AssemblyDebuggerControl(AppContext* _context); |
|||
~AssemblyDebuggerControl() {} |
|||
void start() const override; |
|||
QString title() const override; |
|||
QString contentUrl() const override; |
|||
}; |
|||
|
|||
} |
|||
} |
@ -1,48 +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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file StateListView.cpp
|
|||
* @author Arkadiy Paronyan arkadiy@ethdev.com |
|||
* @date 2014 |
|||
* Ethereum IDE client. |
|||
*/ |
|||
|
|||
#include <QQuickItem> |
|||
#include <QApplication> |
|||
#include <QQmlApplicationEngine> |
|||
#include <QQmlContext> |
|||
#include <QDebug> |
|||
#include "StateListView.h" |
|||
|
|||
using namespace dev::mix; |
|||
|
|||
StateListView::StateListView(AppContext* _context): Extension(_context, ExtensionDisplayBehavior::RightView) |
|||
{ |
|||
} |
|||
|
|||
QString StateListView::contentUrl() const |
|||
{ |
|||
return QStringLiteral("qrc:/qml/StateList.qml"); |
|||
} |
|||
|
|||
QString StateListView::title() const |
|||
{ |
|||
return QApplication::tr("States"); |
|||
} |
|||
|
|||
void StateListView::start() const |
|||
{ |
|||
} |
@ -1,45 +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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file StateListView.h
|
|||
* @author Arkadiy Paronyan arkadiy@ethdev.com |
|||
* @date 2014 |
|||
* Ethereum IDE client. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <memory> |
|||
#include <QTextDocument> |
|||
#include "Extension.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace mix |
|||
{ |
|||
|
|||
/// State list control
|
|||
class StateListView: public Extension |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
StateListView(AppContext* _context); |
|||
void start() const override; |
|||
QString title() const override; |
|||
QString contentUrl() const override; |
|||
}; |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,243 @@ |
|||
import QtQuick 2.0 |
|||
import QtQuick.Window 2.0 |
|||
import QtQuick.Layouts 1.0 |
|||
import QtQuick.Controls 1.0 |
|||
import QtQuick.Controls.Styles 1.3 |
|||
import "." |
|||
|
|||
|
|||
ColumnLayout { |
|||
id: wrapperItem |
|||
signal documentSelected(string doc, string groupName) |
|||
property alias model: filesList.model |
|||
property string sectionName; |
|||
property variant selManager; |
|||
Layout.fillWidth: true |
|||
Layout.minimumHeight: hiddenHeightTopLevel() |
|||
height: hiddenHeightTopLevel() |
|||
Layout.maximumHeight: hiddenHeightTopLevel() |
|||
spacing: 0 |
|||
|
|||
function hiddenHeightTopLevel() |
|||
{ |
|||
return section.state === "hidden" ? Style.documentsList.height : Style.documentsList.fileNameHeight * model.count + Style.documentsList.height; |
|||
} |
|||
|
|||
function hiddenHeightRepeater() |
|||
{ |
|||
return section.state === "hidden" ? 0 : Style.documentsList.fileNameHeight * wrapperItem.model.count; |
|||
} |
|||
|
|||
function hiddenHeightElement() |
|||
{ |
|||
return section.state === "hidden" ? 0 : Style.documentsList.fileNameHeight; |
|||
} |
|||
|
|||
function getDocumentIndex(documentId) |
|||
{ |
|||
for (var i = 0; i < model.count; i++) |
|||
if (model.get(i).documentId === documentId) |
|||
return i; |
|||
return -1; |
|||
} |
|||
|
|||
function removeDocument(documentId) |
|||
{ |
|||
var i = getDocumentIndex(documentId); |
|||
if (i !== -1) |
|||
model.remove(i); |
|||
} |
|||
|
|||
FontLoader |
|||
{ |
|||
id: fileNameFont |
|||
source: "qrc:/qml/fonts/SourceSansPro-Regular.ttf" |
|||
} |
|||
|
|||
RowLayout |
|||
{ |
|||
anchors.top: parent.top |
|||
id: rowCol |
|||
width: parent.width |
|||
height: Style.documentsList.height |
|||
|
|||
Image { |
|||
source: "qrc:/qml/img/opentriangleindicator_filesproject.png" |
|||
width: 15 |
|||
sourceSize.width: 15 |
|||
id: imgArrow |
|||
anchors.right: section.left |
|||
anchors.rightMargin: 5 |
|||
anchors.top: parent.top |
|||
anchors.topMargin: 8 |
|||
} |
|||
|
|||
Text |
|||
{ |
|||
id: section |
|||
text: sectionName |
|||
anchors.left: parent.left |
|||
anchors.leftMargin: Style.general.leftMargin |
|||
color: Style.documentsList.sectionColor |
|||
font.family: fileNameFont.name |
|||
font.pointSize: Style.documentsList.fontSize |
|||
font.weight: Font.Bold |
|||
font.letterSpacing: 1 |
|||
states: [ |
|||
State { |
|||
name: "hidden" |
|||
PropertyChanges { target: filesList; visible: false; } |
|||
PropertyChanges { target: rowCol; Layout.minimumHeight: Style.documentsList.height; Layout.maximumHeight: Style.documentsList.height; height: Style.documentsList.height; } |
|||
PropertyChanges { target: imgArrow; source: "qrc:/qml/img/closedtriangleindicator_filesproject.png" } |
|||
} |
|||
] |
|||
} |
|||
|
|||
MouseArea { |
|||
id: titleMouseArea |
|||
anchors.fill: parent |
|||
hoverEnabled: true |
|||
z: 2 |
|||
onClicked: { |
|||
if (section.state === "hidden") |
|||
section.state = ""; |
|||
else |
|||
section.state = "hidden"; |
|||
} |
|||
} |
|||
} |
|||
|
|||
ColumnLayout { |
|||
height: wrapperItem.hiddenHeightRepeater() |
|||
Layout.minimumHeight: wrapperItem.hiddenHeightRepeater() |
|||
Layout.preferredHeight: wrapperItem.hiddenHeightRepeater() |
|||
Layout.maximumHeight: wrapperItem.hiddenHeightRepeater() |
|||
width: parent.width |
|||
visible: section.state !== "hidden" |
|||
spacing: 0 |
|||
Repeater |
|||
{ |
|||
id: filesList |
|||
visible: section.state !== "hidden" |
|||
Rectangle |
|||
{ |
|||
visible: section.state !== "hidden" |
|||
id: rootItem |
|||
Layout.fillWidth: true |
|||
Layout.minimumHeight: wrapperItem.hiddenHeightElement() |
|||
Layout.preferredHeight: wrapperItem.hiddenHeightElement() |
|||
Layout.maximumHeight: wrapperItem.hiddenHeightElement() |
|||
height: wrapperItem.hiddenHeightElement() |
|||
color: isSelected ? Style.documentsList.highlightColor : Style.documentsList.background |
|||
property bool isSelected |
|||
property bool renameMode |
|||
Text { |
|||
id: nameText |
|||
height: parent.height |
|||
visible: !renameMode |
|||
color: rootItem.isSelected ? Style.documentsList.selectedColor : Style.documentsList.color |
|||
text: name; |
|||
font.family: fileNameFont.name |
|||
font.pointSize: Style.documentsList.fontSize |
|||
anchors.verticalCenter: parent.verticalCenter |
|||
verticalAlignment: Text.AlignVCenter |
|||
anchors.left: parent.left |
|||
anchors.leftMargin: Style.general.leftMargin + 2 |
|||
width: parent.width |
|||
Connections |
|||
{ |
|||
target: selManager |
|||
onSelected: { |
|||
if (groupName != sectionName) |
|||
rootItem.isSelected = false; |
|||
else if (doc === documentId) |
|||
rootItem.isSelected = true; |
|||
else |
|||
rootItem.isSelected = false; |
|||
} |
|||
} |
|||
} |
|||
|
|||
TextInput { |
|||
id: textInput |
|||
text: nameText.text |
|||
visible: renameMode |
|||
anchors.verticalCenter: parent.verticalCenter |
|||
anchors.left: parent.left |
|||
anchors.leftMargin: Style.general.leftMargin |
|||
MouseArea { |
|||
id: textMouseArea |
|||
anchors.fill: parent |
|||
hoverEnabled: true |
|||
z: 2 |
|||
onClicked: { |
|||
textInput.forceActiveFocus(); |
|||
} |
|||
} |
|||
|
|||
onVisibleChanged: { |
|||
if (visible) { |
|||
selectAll(); |
|||
forceActiveFocus(); |
|||
} |
|||
} |
|||
|
|||
onAccepted: close(true); |
|||
onCursorVisibleChanged: { |
|||
if (!cursorVisible) |
|||
close(false); |
|||
} |
|||
onFocusChanged: { |
|||
if (!focus) |
|||
close(false); |
|||
} |
|||
function close(accept) { |
|||
rootItem.renameMode = false; |
|||
if (accept) |
|||
{ |
|||
var i = getDocumentIndex(documentId); |
|||
projectModel.renameDocument(documentId, textInput.text); |
|||
wrapperItem.model.set(i, projectModel.getDocument(documentId)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
MouseArea { |
|||
id: mouseArea |
|||
z: 1 |
|||
hoverEnabled: false |
|||
anchors.fill: parent |
|||
acceptedButtons: Qt.LeftButton | Qt.RightButton |
|||
onClicked:{ |
|||
if (mouse.button === Qt.RightButton && !isContract) |
|||
contextMenu.popup(); |
|||
else if (mouse.button === Qt.LeftButton) |
|||
{ |
|||
rootItem.isSelected = true; |
|||
projectModel.openDocument(documentId); |
|||
documentSelected(documentId, groupName); |
|||
} |
|||
} |
|||
} |
|||
|
|||
Menu { |
|||
id: contextMenu |
|||
MenuItem { |
|||
text: qsTr("Rename") |
|||
onTriggered: { |
|||
rootItem.renameMode = true; |
|||
} |
|||
} |
|||
MenuItem { |
|||
text: qsTr("Delete") |
|||
onTriggered: { |
|||
projectModel.removeDocument(documentId); |
|||
wrapperItem.removeDocument(documentId); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
@ -0,0 +1,29 @@ |
|||
pragma Singleton |
|||
import QtQuick 2.0 |
|||
|
|||
/* |
|||
* Project Files |
|||
*/ |
|||
QtObject { |
|||
property QtObject general: QtObject { |
|||
property int leftMargin: 45 |
|||
} |
|||
|
|||
property QtObject title: QtObject { |
|||
property string color: "#808080" |
|||
property string background: "#f0f0f0" |
|||
property int height: 70 |
|||
property int pointSize: 18 |
|||
} |
|||
|
|||
property QtObject documentsList: QtObject { |
|||
property string background: "#f7f7f7" |
|||
property string color: "#4d4d4d" |
|||
property string sectionColor: "#808080" |
|||
property string selectedColor: "white" |
|||
property string highlightColor: "#4a90e2" |
|||
property int height: 32 |
|||
property int fileNameHeight: 45 |
|||
property int fontSize: 15 |
|||
} |
|||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 244 B |
After Width: | Height: | Size: 228 B |
After Width: | Height: | Size: 286 B |
@ -0,0 +1 @@ |
|||
singleton Style 1.0 Style.qml |
@ -0,0 +1,13 @@ |
|||
include pysol/*.cpp |
|||
include *.py |
|||
include libdevcore/*cpp |
|||
include libdevcore/*h |
|||
include libdevcrypto/*cpp |
|||
include libdevcrypto/*h |
|||
include libethcore/*cpp |
|||
include libethcore/*h |
|||
include libsolidity/*cpp |
|||
include libsolidity/*h |
|||
include libevmcore/*cpp |
|||
include libevmcore/*h |
|||
include pysol/README.md |
@ -0,0 +1,115 @@ |
|||
#include <Python.h> |
|||
#include "structmember.h" |
|||
#include <stdlib.h> |
|||
#include <stdio.h> |
|||
#include <iostream> |
|||
#include <vector> |
|||
|
|||
#include "../libdevcore/CommonData.h" |
|||
|
|||
|
|||
#include <libsolidity/Compiler.h> |
|||
#include <libsolidity/CompilerStack.h> |
|||
#include <libsolidity/CompilerUtils.h> |
|||
#include <libsolidity/SourceReferenceFormatter.h> |
|||
|
|||
|
|||
std::string compile(std::string src) { |
|||
dev::solidity::CompilerStack compiler; |
|||
try |
|||
{ |
|||
std::vector<uint8_t> m_data = compiler.compile(src, false); |
|||
return std::string(m_data.begin(), m_data.end()); |
|||
} |
|||
catch (dev::Exception const& exception) |
|||
{ |
|||
std::ostringstream error; |
|||
dev::solidity::SourceReferenceFormatter::printExceptionInformation(error, exception, "Error", compiler); |
|||
std::string e = error.str(); |
|||
throw(e); |
|||
} |
|||
} |
|||
|
|||
|
|||
std::string mk_full_signature(std::string src) { |
|||
dev::solidity::CompilerStack compiler; |
|||
try |
|||
{ |
|||
compiler.compile(src); |
|||
return compiler.getInterface(""); |
|||
} |
|||
catch (dev::Exception const& exception) |
|||
{ |
|||
std::ostringstream error; |
|||
dev::solidity::SourceReferenceFormatter::printExceptionInformation(error, exception, "Error", compiler); |
|||
std::string e = error.str(); |
|||
throw(e); |
|||
} |
|||
} |
|||
|
|||
std::string bob(std::string src) { return src + src; } |
|||
|
|||
#define PYMETHOD(name, FROM, method, TO) \ |
|||
static PyObject * name(PyObject *, PyObject *args) { \ |
|||
try { \ |
|||
FROM(med) \ |
|||
return TO(method(med)); \ |
|||
} \ |
|||
catch (std::string e) { \ |
|||
PyErr_SetString(PyExc_Exception, e.c_str()); \ |
|||
return NULL; \ |
|||
} \ |
|||
} |
|||
|
|||
#define FROMSTR(v) \ |
|||
const char *command; \ |
|||
int len; \ |
|||
if (!PyArg_ParseTuple(args, "s#", &command, &len)) \ |
|||
return NULL; \ |
|||
std::string v = std::string(command, len); \ |
|||
|
|||
// Convert string into python wrapper form
|
|||
PyObject* pyifyString(std::string s) { |
|||
return Py_BuildValue("s#", s.c_str(), s.length()); |
|||
} |
|||
|
|||
// Convert integer into python wrapper form
|
|||
PyObject* pyifyInteger(unsigned int i) { |
|||
return Py_BuildValue("i", i); |
|||
} |
|||
|
|||
// Convert pyobject int into normal form
|
|||
int cppifyInt(PyObject* o) { |
|||
int out; |
|||
if (!PyArg_Parse(o, "i", &out)) |
|||
throw("Argument should be integer"); |
|||
return out; |
|||
} |
|||
|
|||
// Convert pyobject string into normal form
|
|||
std::string cppifyString(PyObject* o) { |
|||
const char *command; |
|||
if (!PyArg_Parse(o, "s", &command)) |
|||
throw("Argument should be string"); |
|||
return std::string(command); |
|||
} |
|||
|
|||
int fh(std::string i) { |
|||
return dev::fromHex(i[0]); |
|||
} |
|||
|
|||
PYMETHOD(ps_compile, FROMSTR, compile, pyifyString) |
|||
PYMETHOD(ps_mk_full_signature, FROMSTR, mk_full_signature, pyifyString) |
|||
|
|||
static PyMethodDef PyextMethods[] = { |
|||
{"compile", ps_compile, METH_VARARGS, |
|||
"Compile code."}, |
|||
{"mk_full_signature", ps_mk_full_signature, METH_VARARGS, |
|||
"Get the signature of a piece of code."}, |
|||
{NULL, NULL, 0, NULL} /* Sentinel */ |
|||
}; |
|||
|
|||
PyMODINIT_FUNC initsolidity(void) |
|||
{ |
|||
Py_InitModule( "solidity", PyextMethods ); |
|||
} |
@ -0,0 +1,41 @@ |
|||
import os |
|||
os.chdir('..') |
|||
|
|||
from setuptools import setup, Extension |
|||
|
|||
from distutils.sysconfig import get_config_vars |
|||
|
|||
(opt,) = get_config_vars('OPT') |
|||
os.environ['OPT'] = " ".join( |
|||
flag for flag in opt.split() if flag != '-Wstrict-prototypes' |
|||
) |
|||
|
|||
setup( |
|||
# Name of this package |
|||
name="ethereum-solidity", |
|||
|
|||
# Package version |
|||
version='1.8.0', |
|||
|
|||
description='Solidity compiler python wrapper', |
|||
maintainer='Vitalik Buterin', |
|||
maintainer_email='v@buterin.com', |
|||
license='WTFPL', |
|||
url='http://www.ethereum.org/', |
|||
|
|||
# Describes how to build the actual extension module from C source files. |
|||
ext_modules=[ |
|||
Extension( |
|||
'solidity', # Python name of the module |
|||
sources= ['libdevcore/Common.cpp', 'libdevcore/CommonData.cpp', 'libdevcore/CommonIO.cpp', 'libdevcore/FixedHash.cpp', 'libdevcore/Guards.cpp', 'libdevcore/Log.cpp', 'libdevcore/RangeMask.cpp', 'libdevcore/RLP.cpp', 'libdevcore/Worker.cpp', 'libdevcrypto/AES.cpp', 'libdevcrypto/Common.cpp', 'libdevcrypto/CryptoPP.cpp', 'libdevcrypto/ECDHE.cpp', 'libdevcrypto/FileSystem.cpp', 'libdevcrypto/MemoryDB.cpp', 'libdevcrypto/OverlayDB.cpp', 'libdevcrypto/SHA3.cpp', 'libdevcrypto/TrieCommon.cpp', 'libdevcrypto/TrieDB.cpp', 'libethcore/CommonEth.cpp', 'libethcore/CommonJS.cpp', 'libethcore/Exceptions.cpp', 'libsolidity/AST.cpp', 'libsolidity/ASTJsonConverter.cpp', 'libsolidity/ASTPrinter.cpp', 'libsolidity/CompilerContext.cpp', 'libsolidity/Compiler.cpp', 'libsolidity/CompilerStack.cpp', 'libsolidity/CompilerUtils.cpp', 'libsolidity/DeclarationContainer.cpp', 'libsolidity/ExpressionCompiler.cpp', 'libsolidity/GlobalContext.cpp', 'libsolidity/InterfaceHandler.cpp', 'libsolidity/NameAndTypeResolver.cpp', 'libsolidity/Parser.cpp', 'libsolidity/Scanner.cpp', 'libsolidity/SourceReferenceFormatter.cpp', 'libsolidity/Token.cpp', 'libsolidity/Types.cpp', 'libevmcore/Assembly.cpp', 'libevmcore/Instruction.cpp', 'pysol/pysolidity.cpp'], |
|||
libraries=['boost_python', 'boost_filesystem', 'boost_chrono', 'boost_thread', 'cryptopp', 'leveldb', 'jsoncpp'], |
|||
include_dirs=['/usr/include/boost', '..', '../..', '.'], |
|||
extra_compile_args=['--std=c++11', '-Wno-unknown-pragmas'] |
|||
)], |
|||
py_modules=[ |
|||
], |
|||
scripts=[ |
|||
], |
|||
entry_points={ |
|||
} |
|||
), |
@ -0,0 +1,112 @@ |
|||
/*
|
|||
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 <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file natspec.cpp
|
|||
* @author Marek Kotewicz <marek@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include <boost/test/unit_test.hpp> |
|||
#include <libdevcore/Log.h> |
|||
#include <libnatspec/NatspecExpressionEvaluator.h> |
|||
|
|||
using namespace std; |
|||
|
|||
BOOST_AUTO_TEST_SUITE(natspec) |
|||
|
|||
BOOST_AUTO_TEST_CASE(natspec_eval_function_exists) |
|||
{ |
|||
// given
|
|||
NatspecExpressionEvaluator e; |
|||
// when
|
|||
string result = e.evalExpression("`typeof evaluateExpression`").toStdString(); |
|||
// then
|
|||
BOOST_CHECK_EQUAL(result, "function"); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(natspec_js_eval) |
|||
{ |
|||
// given
|
|||
NatspecExpressionEvaluator e; |
|||
// when
|
|||
string result = e.evalExpression("`1 + 2`").toStdString(); |
|||
// then
|
|||
BOOST_CHECK_EQUAL(result, "3"); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(natspec_create_custom_function) |
|||
{ |
|||
// given
|
|||
NatspecExpressionEvaluator e; |
|||
// when
|
|||
auto x = e.evalExpression("`test = function (x) { return x + 'ok'; }`"); // ommit var, make it global
|
|||
string result = e.evalExpression("`test(5)`").toStdString(); |
|||
string result2 = e.evalExpression("`typeof test`").toStdString(); |
|||
// then
|
|||
BOOST_CHECK_EQUAL(result, "5ok"); |
|||
BOOST_CHECK_EQUAL(result2, "function"); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(natspec_js_eval_separated_expressions) |
|||
{ |
|||
// given
|
|||
NatspecExpressionEvaluator e; |
|||
// when
|
|||
string result = e.evalExpression("`x = 1` + `y = 2` will be equal `x + y`").toStdString(); |
|||
// then
|
|||
BOOST_CHECK_EQUAL(result, "1 + 2 will be equal 3"); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(natspec_js_eval_input_params) |
|||
{ |
|||
// given
|
|||
char const* abi = R"([ |
|||
{ |
|||
"name": "f", |
|||
"constant": false, |
|||
"type": "function", |
|||
"inputs": [ |
|||
{ |
|||
"name": "a", |
|||
"type": "uint256" |
|||
} |
|||
], |
|||
"outputs": [ |
|||
{ |
|||
"name": "d", |
|||
"type": "uint256" |
|||
} |
|||
] |
|||
} |
|||
])"; |
|||
NatspecExpressionEvaluator e(abi, "'f'", "[4]"); |
|||
// when
|
|||
string result = e.evalExpression("Will multiply `a` by 7 and return `a * 7`.").toStdString(); |
|||
// then
|
|||
BOOST_CHECK_EQUAL(result, "Will multiply 4 by 7 and return 28."); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(natspec_js_eval_error) |
|||
{ |
|||
// given
|
|||
NatspecExpressionEvaluator e; |
|||
// when
|
|||
string result = e.evalExpression("`test(`").toStdString(); |
|||
// then
|
|||
BOOST_CHECK_EQUAL(result, "`test(`"); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_SUITE_END() |
Loading…
Reference in new issue