aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp3
-rw-r--r--libsolidity/inlineasm/AsmParser.cpp21
-rw-r--r--libsolidity/inlineasm/AsmParser.h2
-rw-r--r--libsolidity/interface/CompilerStack.cpp53
-rw-r--r--libsolidity/interface/CompilerStack.h19
-rw-r--r--libsolidity/interface/StandardCompiler.cpp4
6 files changed, 64 insertions, 38 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 0764bf67..e5660cde 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -546,6 +546,9 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
if (_function.isConstructor())
m_errorReporter.typeError(_function.location(), "Constructor cannot be defined in interfaces.");
}
+ else if (m_scope->contractKind() == ContractDefinition::ContractKind::Library)
+ if (_function.isConstructor())
+ m_errorReporter.typeError(_function.location(), "Constructor cannot be defined in libraries.");
if (_function.isImplemented())
_function.body().accept(*this);
else if (_function.isConstructor())
diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp
index 133f70b1..1dcc42b8 100644
--- a/libsolidity/inlineasm/AsmParser.cpp
+++ b/libsolidity/inlineasm/AsmParser.cpp
@@ -23,6 +23,9 @@
#include <libsolidity/inlineasm/AsmParser.h>
#include <libsolidity/parsing/Scanner.h>
#include <libsolidity/interface/ErrorReporter.h>
+
+#include <boost/algorithm/string.hpp>
+
#include <ctype.h>
#include <algorithm>
@@ -297,6 +300,8 @@ assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher)
kind = LiteralKind::String;
break;
case Token::Number:
+ if (!isValidNumberLiteral(currentLiteral()))
+ fatalParserError("Invalid number literal.");
kind = LiteralKind::Number;
break;
case Token::TrueLiteral:
@@ -501,3 +506,19 @@ string Parser::expectAsmIdentifier()
expectToken(Token::Identifier);
return name;
}
+
+bool Parser::isValidNumberLiteral(string const& _literal)
+{
+ try
+ {
+ u256(_literal);
+ }
+ catch (...)
+ {
+ return false;
+ }
+ if (boost::starts_with(_literal, "0x"))
+ return true;
+ else
+ return _literal.find_first_not_of("0123456789") == string::npos;
+}
diff --git a/libsolidity/inlineasm/AsmParser.h b/libsolidity/inlineasm/AsmParser.h
index 45708afd..a48a3393 100644
--- a/libsolidity/inlineasm/AsmParser.h
+++ b/libsolidity/inlineasm/AsmParser.h
@@ -75,6 +75,8 @@ protected:
TypedName parseTypedName();
std::string expectAsmIdentifier();
+ static bool isValidNumberLiteral(std::string const& _literal);
+
private:
bool m_julia = false;
};
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index 19bfbe63..412d2fd3 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -404,39 +404,42 @@ Json::Value const& CompilerStack::contractABI(Contract const& _contract) const
return *_contract.abi;
}
-Json::Value const& CompilerStack::natspec(string const& _contractName, DocumentationType _type) const
+Json::Value const& CompilerStack::natspecUser(string const& _contractName) const
{
- return natspec(contract(_contractName), _type);
+ return natspecUser(contract(_contractName));
}
-Json::Value const& CompilerStack::natspec(Contract const& _contract, DocumentationType _type) const
+Json::Value const& CompilerStack::natspecUser(Contract const& _contract) const
{
if (m_stackState < AnalysisSuccessful)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
solAssert(_contract.contract, "");
- std::unique_ptr<Json::Value const>* doc;
- // checks wheather we already have the documentation
- switch (_type)
- {
- case DocumentationType::NatspecUser:
- doc = &_contract.userDocumentation;
- // caches the result
- if (!*doc)
- doc->reset(new Json::Value(Natspec::userDocumentation(*_contract.contract)));
- break;
- case DocumentationType::NatspecDev:
- doc = &_contract.devDocumentation;
- // caches the result
- if (!*doc)
- doc->reset(new Json::Value(Natspec::devDocumentation(*_contract.contract)));
- break;
- default:
- solAssert(false, "Illegal documentation type.");
- }
+ // caches the result
+ if (!_contract.userDocumentation)
+ _contract.userDocumentation.reset(new Json::Value(Natspec::userDocumentation(*_contract.contract)));
+
+ return *_contract.userDocumentation;
+}
+
+Json::Value const& CompilerStack::natspecDev(string const& _contractName) const
+{
+ return natspecDev(contract(_contractName));
+}
+
+Json::Value const& CompilerStack::natspecDev(Contract const& _contract) const
+{
+ if (m_stackState < AnalysisSuccessful)
+ BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
+
+ solAssert(_contract.contract, "");
+
+ // caches the result
+ if (!_contract.devDocumentation)
+ _contract.devDocumentation.reset(new Json::Value(Natspec::devDocumentation(*_contract.contract)));
- return *(*doc);
+ return *_contract.devDocumentation;
}
Json::Value CompilerStack::methodIdentifiers(string const& _contractName) const
@@ -817,8 +820,8 @@ string CompilerStack::createMetadata(Contract const& _contract) const
meta["settings"]["libraries"][library.first] = "0x" + toHex(library.second.asBytes());
meta["output"]["abi"] = contractABI(_contract);
- meta["output"]["userdoc"] = natspec(_contract, DocumentationType::NatspecUser);
- meta["output"]["devdoc"] = natspec(_contract, DocumentationType::NatspecDev);
+ meta["output"]["userdoc"] = natspecUser(_contract);
+ meta["output"]["devdoc"] = natspecDev(_contract);
return jsonCompactPrint(meta);
}
diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h
index d287f224..54e3e23f 100644
--- a/libsolidity/interface/CompilerStack.h
+++ b/libsolidity/interface/CompilerStack.h
@@ -63,12 +63,6 @@ class Natspec;
class Error;
class DeclarationContainer;
-enum class DocumentationType: uint8_t
-{
- NatspecUser = 1,
- NatspecDev
-};
-
/**
* Easy to use and self-contained Solidity compiler with as few header dependencies as possible.
* It holds state and can be used to either step through the compilation stages (and abort e.g.
@@ -203,11 +197,13 @@ public:
/// Prerequisite: Successful call to parse or compile.
Json::Value const& contractABI(std::string const& _contractName = "") const;
- /// @returns a JSON representing the contract's documentation.
+ /// @returns a JSON representing the contract's user documentation.
+ /// Prerequisite: Successful call to parse or compile.
+ Json::Value const& natspecUser(std::string const& _contractName) const;
+
+ /// @returns a JSON representing the contract's developer documentation.
/// Prerequisite: Successful call to parse or compile.
- /// @param type The type of the documentation to get.
- /// Can be one of 4 types defined at @c DocumentationType
- Json::Value const& natspec(std::string const& _contractName, DocumentationType _type) const;
+ Json::Value const& natspecDev(std::string const& _contractName) const;
/// @returns a JSON representing a map of method identifiers (hashes) to function names.
Json::Value methodIdentifiers(std::string const& _contractName) const;
@@ -274,7 +270,8 @@ private:
std::string createMetadata(Contract const& _contract) const;
std::string computeSourceMapping(eth::AssemblyItems const& _items) const;
Json::Value const& contractABI(Contract const&) const;
- Json::Value const& natspec(Contract const&, DocumentationType _type) const;
+ Json::Value const& natspecUser(Contract const&) const;
+ Json::Value const& natspecDev(Contract const&) const;
/// @returns the offset of the entry point of the given function into the list of assembly items
/// or zero if it is not found or does not exist.
diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp
index dd135ce5..7a6f9989 100644
--- a/libsolidity/interface/StandardCompiler.cpp
+++ b/libsolidity/interface/StandardCompiler.cpp
@@ -394,8 +394,8 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
Json::Value contractData(Json::objectValue);
contractData["abi"] = m_compilerStack.contractABI(contractName);
contractData["metadata"] = m_compilerStack.metadata(contractName);
- contractData["userdoc"] = m_compilerStack.natspec(contractName, DocumentationType::NatspecUser);
- contractData["devdoc"] = m_compilerStack.natspec(contractName, DocumentationType::NatspecDev);
+ contractData["userdoc"] = m_compilerStack.natspecUser(contractName);
+ contractData["devdoc"] = m_compilerStack.natspecDev(contractName);
// EVM
Json::Value evmData(Json::objectValue);