aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-05-19 23:48:36 +0800
committerGitHub <noreply@github.com>2017-05-19 23:48:36 +0800
commit982f661339e695f4ad913ff17bc12a9e190b25ed (patch)
tree421c93ff249d89f3778dae422cea3ebcec7a9e4c
parent6f9428e9008f9d979caf7ff2f67ae85c784a0111 (diff)
parentebcb27e5c14549d114c116889c730c3a8cd82a86 (diff)
downloaddexon-solidity-982f661339e695f4ad913ff17bc12a9e190b25ed.tar.gz
dexon-solidity-982f661339e695f4ad913ff17bc12a9e190b25ed.tar.zst
dexon-solidity-982f661339e695f4ad913ff17bc12a9e190b25ed.zip
Merge pull request #2223 from ethereum/julia-bool
Add support for bool literals in Julia
-rw-r--r--libsolidity/inlineasm/AsmAnalysis.cpp2
-rw-r--r--libsolidity/inlineasm/AsmCodeGen.cpp9
-rw-r--r--libsolidity/inlineasm/AsmData.h3
-rw-r--r--libsolidity/inlineasm/AsmParser.cpp33
-rw-r--r--libsolidity/inlineasm/AsmPrinter.cpp10
-rw-r--r--test/libjulia/Parser.cpp6
-rw-r--r--test/libsolidity/InlineAssembly.cpp6
7 files changed, 63 insertions, 6 deletions
diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp
index 590f9ad6..e03eea2e 100644
--- a/libsolidity/inlineasm/AsmAnalysis.cpp
+++ b/libsolidity/inlineasm/AsmAnalysis.cpp
@@ -72,7 +72,7 @@ bool AsmAnalyzer::operator()(assembly::Instruction const& _instruction)
bool AsmAnalyzer::operator()(assembly::Literal const& _literal)
{
++m_stackHeight;
- if (!_literal.isNumber && _literal.value.size() > 32)
+ if (_literal.kind == assembly::LiteralKind::String && _literal.value.size() > 32)
{
m_errors.push_back(make_shared<Error>(
Error::Type::TypeError,
diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp
index 137a70f5..44e12b3e 100644
--- a/libsolidity/inlineasm/AsmCodeGen.cpp
+++ b/libsolidity/inlineasm/AsmCodeGen.cpp
@@ -118,8 +118,15 @@ public:
void operator()(assembly::Literal const& _literal)
{
m_state.assembly.setSourceLocation(_literal.location);
- if (_literal.isNumber)
+ if (_literal.kind == assembly::LiteralKind::Number)
m_state.assembly.append(u256(_literal.value));
+ else if (_literal.kind == assembly::LiteralKind::Boolean)
+ {
+ if (_literal.value == "true")
+ m_state.assembly.append(u256(1));
+ else
+ m_state.assembly.append(u256(0));
+ }
else
{
solAssert(_literal.value.size() <= 32, "");
diff --git a/libsolidity/inlineasm/AsmData.h b/libsolidity/inlineasm/AsmData.h
index 363873ab..8efe1f07 100644
--- a/libsolidity/inlineasm/AsmData.h
+++ b/libsolidity/inlineasm/AsmData.h
@@ -43,7 +43,8 @@ using TypedNameList = std::vector<TypedName>;
/// Direct EVM instruction (except PUSHi and JUMPDEST)
struct Instruction { SourceLocation location; solidity::Instruction instruction; };
/// Literal number or string (up to 32 bytes)
-struct Literal { SourceLocation location; bool isNumber; std::string value; Type type; };
+enum class LiteralKind { Number, Boolean, String };
+struct Literal { SourceLocation location; LiteralKind kind; std::string value; Type type; };
/// External / internal identifier or label reference
struct Identifier { SourceLocation location; std::string name; };
struct FunctionalInstruction;
diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp
index 7ecad5ea..a96984f5 100644
--- a/libsolidity/inlineasm/AsmParser.cpp
+++ b/libsolidity/inlineasm/AsmParser.cpp
@@ -206,10 +206,29 @@ assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher)
}
case Token::StringLiteral:
case Token::Number:
+ case Token::TrueLiteral:
+ case Token::FalseLiteral:
{
+ LiteralKind kind = LiteralKind::Number;
+ switch (m_scanner->currentToken())
+ {
+ case Token::StringLiteral:
+ kind = LiteralKind::String;
+ break;
+ case Token::Number:
+ kind = LiteralKind::Number;
+ break;
+ case Token::TrueLiteral:
+ case Token::FalseLiteral:
+ kind = LiteralKind::Boolean;
+ break;
+ default:
+ break;
+ }
+
Literal literal{
location(),
- m_scanner->currentToken() == Token::Number,
+ kind,
m_scanner->currentLiteral(),
""
};
@@ -220,6 +239,8 @@ assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher)
literal.location.end = endPosition();
literal.type = expectAsmIdentifier();
}
+ else if (kind == LiteralKind::Boolean)
+ fatalParserError("True and false are not valid literals.");
ret = std::move(literal);
break;
}
@@ -360,7 +381,15 @@ TypedName Parser::parseTypedName()
string Parser::expectAsmIdentifier()
{
string name = m_scanner->currentLiteral();
- if (!m_julia && instructions().count(name))
+ if (m_julia)
+ {
+ if (m_scanner->currentToken() == Token::Bool)
+ {
+ m_scanner->next();
+ return name;
+ }
+ }
+ else if (instructions().count(name))
fatalParserError("Cannot use instruction names for identifier names.");
expectToken(Token::Identifier);
return name;
diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp
index f3b66aee..636e61b8 100644
--- a/libsolidity/inlineasm/AsmPrinter.cpp
+++ b/libsolidity/inlineasm/AsmPrinter.cpp
@@ -46,8 +46,16 @@ string AsmPrinter::operator()(assembly::Instruction const& _instruction)
string AsmPrinter::operator()(assembly::Literal const& _literal)
{
- if (_literal.isNumber)
+ switch (_literal.kind)
+ {
+ case LiteralKind::Number:
return _literal.value + appendTypeName(_literal.type);
+ case LiteralKind::Boolean:
+ return ((_literal.value == "true") ? "true" : "false") + appendTypeName(_literal.type);
+ case LiteralKind::String:
+ break;
+ }
+
string out;
for (char c: _literal.value)
if (c == '\\')
diff --git a/test/libjulia/Parser.cpp b/test/libjulia/Parser.cpp
index c401f57b..d1081067 100644
--- a/test/libjulia/Parser.cpp
+++ b/test/libjulia/Parser.cpp
@@ -120,6 +120,12 @@ BOOST_AUTO_TEST_CASE(vardecl)
BOOST_CHECK(successParse("{ let x:u256 := 7:u256 }"));
}
+BOOST_AUTO_TEST_CASE(vardecl_bool)
+{
+ BOOST_CHECK(successParse("{ let x:bool := true:bool }"));
+ BOOST_CHECK(successParse("{ let x:bool := false:bool }"));
+}
+
BOOST_AUTO_TEST_CASE(assignment)
{
BOOST_CHECK(successParse("{ let x:u256 := 2:u256 let y:u256 := x }"));
diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp
index b7046f80..0729c8db 100644
--- a/test/libsolidity/InlineAssembly.cpp
+++ b/test/libsolidity/InlineAssembly.cpp
@@ -161,6 +161,12 @@ BOOST_AUTO_TEST_CASE(vardecl)
BOOST_CHECK(successParse("{ let x := 7 }"));
}
+BOOST_AUTO_TEST_CASE(vardecl_bool)
+{
+ CHECK_PARSE_ERROR("{ let x := true }", ParserError, "True and false are not valid literals.");
+ CHECK_PARSE_ERROR("{ let x := false }", ParserError, "True and false are not valid literals.");
+}
+
BOOST_AUTO_TEST_CASE(assignment)
{
BOOST_CHECK(successParse("{ let x := 2 7 8 add =: x }"));