From f7338eb8cf065efd48c4ca326198e21df039f17d Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 7 May 2015 13:32:26 +0200 Subject: [PATCH 1/2] added interface function for SourceLocation/ position convertation to compilerstack --- libsolidity/CompilerStack.cpp | 9 +++++++++ libsolidity/CompilerStack.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/libsolidity/CompilerStack.cpp b/libsolidity/CompilerStack.cpp index 554d06fd7..a1c9b4a5c 100644 --- a/libsolidity/CompilerStack.cpp +++ b/libsolidity/CompilerStack.cpp @@ -257,6 +257,15 @@ bytes CompilerStack::staticCompile(std::string const& _sourceCode, bool _optimiz return stack.compile(_sourceCode, _optimize); } +pair CompilerStack::positionFromSourceLocation(SourceLocation const& _sourceLocation) const +{ + int initLine; + int initColumn; + tie(initLine, initColumn) = getScanner(*_sourceLocation.sourceName).translatePositionToLineColumn(_sourceLocation.start); + + return make_pair(++initLine, ++initColumn); +} + void CompilerStack::reset(bool _keepSources) { m_parseSuccessful = false; diff --git a/libsolidity/CompilerStack.h b/libsolidity/CompilerStack.h index 7d9198622..3eff75773 100644 --- a/libsolidity/CompilerStack.h +++ b/libsolidity/CompilerStack.h @@ -31,6 +31,7 @@ #include #include #include +#include namespace dev { @@ -131,6 +132,9 @@ public: /// scanning the source code - this is useful for printing exception information. static bytes staticCompile(std::string const& _sourceCode, bool _optimize = false); + /// helper function for printing logs. Do only use in error cases, it's quite expensive. + std::pair positionFromSourceLocation(SourceLocation const& _sourceLocation) const; + private: /** * Information pertaining to one source unit, filled gradually during parsing and compilation. From 14ab7baa76851882ed9070ae0017e349e38fd023 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 7 May 2015 17:22:24 +0200 Subject: [PATCH 2/2] adde the positions for the end of SourceLocation --- libsolidity/CompilerStack.cpp | 15 +++++++++------ libsolidity/CompilerStack.h | 6 ++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libsolidity/CompilerStack.cpp b/libsolidity/CompilerStack.cpp index a1c9b4a5c..b3fedc45d 100644 --- a/libsolidity/CompilerStack.cpp +++ b/libsolidity/CompilerStack.cpp @@ -257,13 +257,16 @@ bytes CompilerStack::staticCompile(std::string const& _sourceCode, bool _optimiz return stack.compile(_sourceCode, _optimize); } -pair CompilerStack::positionFromSourceLocation(SourceLocation const& _sourceLocation) const +tuple CompilerStack::positionFromSourceLocation(SourceLocation const& _sourceLocation) const { - int initLine; - int initColumn; - tie(initLine, initColumn) = getScanner(*_sourceLocation.sourceName).translatePositionToLineColumn(_sourceLocation.start); - - return make_pair(++initLine, ++initColumn); + int startLine; + int startColumn; + int endLine; + int endColumn; + tie(startLine, startColumn) = getScanner(*_sourceLocation.sourceName).translatePositionToLineColumn(_sourceLocation.start); + tie(endLine, endColumn) = getScanner(*_sourceLocation.sourceName).translatePositionToLineColumn(_sourceLocation.end); + + return make_tuple(++startLine, ++startColumn, ++endLine, ++endColumn); } void CompilerStack::reset(bool _keepSources) diff --git a/libsolidity/CompilerStack.h b/libsolidity/CompilerStack.h index 3eff75773..2ad791f22 100644 --- a/libsolidity/CompilerStack.h +++ b/libsolidity/CompilerStack.h @@ -132,8 +132,10 @@ public: /// scanning the source code - this is useful for printing exception information. static bytes staticCompile(std::string const& _sourceCode, bool _optimize = false); - /// helper function for printing logs. Do only use in error cases, it's quite expensive. - std::pair positionFromSourceLocation(SourceLocation const& _sourceLocation) const; + /// Helper function for logs printing. Do only use in error cases, it's quite expensive. + /// line and columns are numbered starting from 1 with following order: + /// start line, start column, end line, end column + std::tuple positionFromSourceLocation(SourceLocation const& _sourceLocation) const; private: /**