Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
neo hong committed May 31, 2021
1 parent ca8f34a commit 81ff31b
Show file tree
Hide file tree
Showing 8 changed files with 503 additions and 380 deletions.
763 changes: 440 additions & 323 deletions libsolidity/analysis/GlobalContext.cpp

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,18 +565,14 @@ TypeResult IntegerType::unaryOperatorResult(Token _operator) const
// "delete" is ok for all integer types
if (_operator == Token::Delete)
return TypeResult{TypeProvider::emptyTuple()};
// unary negation only on signed types
else if (_operator == Token::Sub)
return isSigned() ? TypeResult{this} : TypeResult::err("Unary negation is only allowed for signed integers.");
else if (_operator == Token::Inc || _operator == Token::Dec || _operator == Token::BitNot)
return TypeResult{this};
// no further unary operators for trcToken
else if (isTrcToken())
return TypeResult::err("");
// for non-trctoken integers
// we allow -, ++ and --
else if (_operator == Token::Sub || _operator == Token::Inc ||
_operator == Token::Dec || _operator == Token::BitNot)
// unary negation only on signed types
else if (_operator == Token::Sub)
return isSigned() ? TypeResult{this} : TypeResult::err("Unary negation is only allowed for signed integers.");
else if (_operator == Token::Inc || _operator == Token::Dec || _operator == Token::BitNot)
return TypeResult{this};
else
return TypeResult::err("");
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/codegen/CompilerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ CompilerContext& CompilerContext::appendPanic(util::PanicCode _code)
revert(0, 0x24)
})");
templ("selector", util::selectorFromSignature("Panic(uint256)").str());
templ("code", u256(_code).str());
templ("code", toCompactHexWithPrefix(static_cast<unsigned>(_code)));
appendInlineAssembly(templ.render());
return *this;
}
Expand Down
88 changes: 49 additions & 39 deletions libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1499,35 +1499,36 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
_memberAccess.expression().accept(*this);
m_context << funType->externalIdentifier();
break;
case FunctionType::Kind::External:
case FunctionType::Kind::Creation:
case FunctionType::Kind::Send:
case FunctionType::Kind::BareCall:
case FunctionType::Kind::BareCallCode:
case FunctionType::Kind::BareDelegateCall:
case FunctionType::Kind::BareStaticCall:
case FunctionType::Kind::Transfer:
case FunctionType::Kind::TransferToken:
case FunctionType::Kind::TokenBalance:
case FunctionType::Kind::ECRecover:
case FunctionType::Kind::ValidateMultiSign:
case FunctionType::Kind::BatchValidateSign:
case FunctionType::Kind::verifyBurnProof:
case FunctionType::Kind::verifyTransferProof:
case FunctionType::Kind::verifyMintProof:
case FunctionType::Kind::pedersenHash:
case FunctionType::Kind::SHA256:
case FunctionType::Kind::RIPEMD160:
default:
solAssert(false, "unsupported member function");
case FunctionType::Kind::External:
case FunctionType::Kind::Creation:
case FunctionType::Kind::Send:
case FunctionType::Kind::BareCall:
case FunctionType::Kind::BareCallCode:
case FunctionType::Kind::BareDelegateCall:
case FunctionType::Kind::BareStaticCall:
case FunctionType::Kind::Transfer:
case FunctionType::Kind::TransferToken:
case FunctionType::Kind::TokenBalance:
case FunctionType::Kind::ECRecover:
case FunctionType::Kind::ValidateMultiSign:
case FunctionType::Kind::BatchValidateSign:
case FunctionType::Kind::verifyBurnProof:
case FunctionType::Kind::verifyTransferProof:
case FunctionType::Kind::verifyMintProof:
case FunctionType::Kind::pedersenHash:
case FunctionType::Kind::SHA256:
case FunctionType::Kind::RIPEMD160:
default:
solAssert(false, "unsupported member function");
}
}
else if (dynamic_cast<TypeType const*>(_memberAccess.annotation().type))
{
// no-op
}
else
_memberAccess.expression().accept(*this);
}
else if (dynamic_cast<TypeType const*>(_memberAccess.annotation().type))
{
// no-op
}
else
_memberAccess.expression().accept(*this);
}
else if (auto enumType = dynamic_cast<EnumType const*>(type->actualType()))
{
Expand Down Expand Up @@ -1642,6 +1643,15 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
);
m_context << Instruction::ISCONTRACT;
}
else if (member == "isContract")
{
utils().convertType(
*_memberAccess.expression().annotation().type,
*TypeProvider::address(),
true
);
m_context << Instruction::ISCONTRACT;
}
else if (member == "code")
{
// Stack: <address>
Expand Down Expand Up @@ -1686,21 +1696,21 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
}
else if ((set<string>{"send", "transfer", "transferToken"}).count(member))
{
solAssert(dynamic_cast<AddressType const &>(*_memberAccess.expression().annotation().type).stateMutability()
== StateMutability::Payable,
"");
utils().convertType(*_memberAccess.expression().annotation().type,
AddressType(StateMutability::Payable),
true);
solAssert(dynamic_cast<AddressType const&>(*_memberAccess.expression().annotation().type).stateMutability() == StateMutability::Payable, "");
utils().convertType(
*_memberAccess.expression().annotation().type,
AddressType(StateMutability::Payable),
true
);
}
else if ((set<string>{"freeze", "unfreeze"}).count(member))
{
solAssert(dynamic_cast<AddressType const&>(*_memberAccess.expression().annotation().type).stateMutability() == StateMutability::Payable, "");
utils().convertType(
*_memberAccess.expression().annotation().type,
AddressType(StateMutability::Payable),
true
);
solAssert(dynamic_cast<AddressType const&>(*_memberAccess.expression().annotation().type).stateMutability() == StateMutability::Payable, "");
utils().convertType(
*_memberAccess.expression().annotation().type,
AddressType(StateMutability::Payable),
true
);
}
else if ((set<string>{"tokenBalance", "call", "callcode", "delegatecall", "staticcall", "freezeExpireTime"}).count(member))
utils().convertType(
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/codegen/YulUtilFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3953,7 +3953,7 @@ string YulUtilFunctions::panicFunction(util::PanicCode _code)
)")
("functionName", functionName)
("selector", util::selectorFromSignature("Panic(uint256)").str())
("code", toCompactHexWithPrefix(_code))
("code", toCompactHexWithPrefix(static_cast<unsigned>(_code)))
.render();
});
}
Expand Down
6 changes: 3 additions & 3 deletions libsolidity/codegen/ir/IRGeneratorForStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1635,9 +1635,9 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
")\n";
else if (member == "isContract")
define(_memberAccess) <<
"isContract(" <<
expressionAsType(_memberAccess.expression(), *TypeProvider::address()) <<
")\n";
"isContract(" <<
expressionAsType(_memberAccess.expression(), *TypeProvider::address()) <<
")\n";
else if (set<string>{"send", "transfer"}.count(member))
{
solAssert(dynamic_cast<AddressType const&>(*_memberAccess.expression().annotation().type).stateMutability() == StateMutability::Payable, "");
Expand Down
3 changes: 2 additions & 1 deletion libsolutil/CommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ inline std::string toHex(u256 val, HexPrefix prefix = HexPrefix::DontAdd)
return (prefix == HexPrefix::Add) ? "0x" + str : str;
}

inline std::string toCompactHexWithPrefix(u256 const& _value)
template <class T>
inline std::string toCompactHexWithPrefix(T _value)
{
return toHex(toCompactBigEndian(_value, 1), HexPrefix::Add);
}
Expand Down
7 changes: 3 additions & 4 deletions test/ExecutionFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ namespace solidity::test
{
using rational = boost::rational<bigint>;

// The various denominations; here for ease of use where needed within code.
static const u256 sun = 1;
static const u256 trx = sun * 1000000;
// The various denominations; here for ease of use where needed within code.
static const u256 sun = 1;
static const u256 trx = sun * 1000000;

class ExecutionFramework
{
Expand Down Expand Up @@ -289,7 +289,6 @@ class ExecutionFramework
bool m_transactionSuccessful = true;
util::h160 m_sender = account(0);
util::h160 m_contractAddress;
u256 m_blockNumber;
u256 const m_gasPrice = 10000 * sun;
u256 const m_gas = 100000000;
bytes m_output;
Expand Down

0 comments on commit 81ff31b

Please sign in to comment.