mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
removed get prefix
style fixes
This commit is contained in:
parent
1b5e6fc9e7
commit
02d4198242
@ -817,10 +817,16 @@ void BinaryOperation::checkTypeRequirements(TypePointers const*)
|
||||
m_right->checkTypeRequirements(nullptr);
|
||||
m_commonType = m_left->type()->binaryOperatorResult(m_operator, m_right->type());
|
||||
if (!m_commonType)
|
||||
BOOST_THROW_EXCEPTION(createTypeError("Operator " + string(Token::toString(m_operator)) +
|
||||
" not compatible with types " +
|
||||
m_left->type()->toString() + " and " +
|
||||
m_right->type()->toString()));
|
||||
BOOST_THROW_EXCEPTION(
|
||||
createTypeError(
|
||||
"Operator " +
|
||||
string(Token::toString(m_operator)) +
|
||||
" not compatible with types " +
|
||||
m_left->type()->toString() +
|
||||
" and " +
|
||||
m_right->type()->toString()
|
||||
)
|
||||
);
|
||||
m_type = Token::isCompareOp(m_operator) ? make_shared<BoolType>() : m_commonType;
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ bool ASTJsonConverter::visit(Assignment const& _node)
|
||||
{
|
||||
addJsonNode("Assignment",
|
||||
{ make_pair("operator", Token::toString(_node.assignmentOperator())),
|
||||
make_pair("type", getType(_node)) },
|
||||
make_pair("type", type(_node)) },
|
||||
true);
|
||||
return true;
|
||||
}
|
||||
@ -219,7 +219,7 @@ bool ASTJsonConverter::visit(UnaryOperation const& _node)
|
||||
addJsonNode("UnaryOperation",
|
||||
{ make_pair("prefix", boost::lexical_cast<std::string>(_node.isPrefixOperation())),
|
||||
make_pair("operator", Token::toString(_node.getOperator())),
|
||||
make_pair("type", getType(_node)) },
|
||||
make_pair("type", type(_node)) },
|
||||
true);
|
||||
return true;
|
||||
}
|
||||
@ -228,7 +228,7 @@ bool ASTJsonConverter::visit(BinaryOperation const& _node)
|
||||
{
|
||||
addJsonNode("BinaryOperation",
|
||||
{ make_pair("operator", Token::toString(_node.getOperator())),
|
||||
make_pair("type", getType(_node))},
|
||||
make_pair("type", type(_node))},
|
||||
true);
|
||||
return true;
|
||||
}
|
||||
@ -237,14 +237,14 @@ bool ASTJsonConverter::visit(FunctionCall const& _node)
|
||||
{
|
||||
addJsonNode("FunctionCall",
|
||||
{ make_pair("type_conversion", boost::lexical_cast<std::string>(_node.isTypeConversion())),
|
||||
make_pair("type", getType(_node)) },
|
||||
make_pair("type", type(_node)) },
|
||||
true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ASTJsonConverter::visit(NewExpression const& _node)
|
||||
{
|
||||
addJsonNode("NewExpression", { make_pair("type", getType(_node)) }, true);
|
||||
addJsonNode("NewExpression", { make_pair("type", type(_node)) }, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -252,28 +252,28 @@ bool ASTJsonConverter::visit(MemberAccess const& _node)
|
||||
{
|
||||
addJsonNode("MemberAccess",
|
||||
{ make_pair("member_name", _node.memberName()),
|
||||
make_pair("type", getType(_node)) },
|
||||
make_pair("type", type(_node)) },
|
||||
true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ASTJsonConverter::visit(IndexAccess const& _node)
|
||||
{
|
||||
addJsonNode("IndexAccess", { make_pair("type", getType(_node)) }, true);
|
||||
addJsonNode("IndexAccess", { make_pair("type", type(_node)) }, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ASTJsonConverter::visit(Identifier const& _node)
|
||||
{
|
||||
addJsonNode("Identifier",
|
||||
{ make_pair("value", _node.name()), make_pair("type", getType(_node)) });
|
||||
{ make_pair("value", _node.name()), make_pair("type", type(_node)) });
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ASTJsonConverter::visit(ElementaryTypeNameExpression const& _node)
|
||||
{
|
||||
addJsonNode("ElementaryTypenameExpression",
|
||||
{ make_pair("value", Token::toString(_node.typeToken())), make_pair("type", getType(_node)) });
|
||||
{ make_pair("value", Token::toString(_node.typeToken())), make_pair("type", type(_node)) });
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -283,7 +283,7 @@ bool ASTJsonConverter::visit(Literal const& _node)
|
||||
addJsonNode("Literal",
|
||||
{ make_pair("string", (tokenString) ? tokenString : "null"),
|
||||
make_pair("value", _node.value()),
|
||||
make_pair("type", getType(_node)) });
|
||||
make_pair("type", type(_node)) });
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -428,7 +428,7 @@ void ASTJsonConverter::process()
|
||||
processed = true;
|
||||
}
|
||||
|
||||
string ASTJsonConverter::getType(Expression const& _expression)
|
||||
string ASTJsonConverter::type(Expression const& _expression)
|
||||
{
|
||||
return (_expression.type()) ? _expression.type()->toString() : "Unknown";
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ private:
|
||||
void addJsonNode(std::string const& _nodeName,
|
||||
std::initializer_list<std::pair<std::string const, std::string const>> _list,
|
||||
bool _hasChildren);
|
||||
std::string getType(Expression const& _expression);
|
||||
std::string type(Expression const& _expression);
|
||||
inline void goUp()
|
||||
{
|
||||
solAssert(!m_jsonNodePtrs.empty(), "Uneven json nodes stack. Internal error.");
|
||||
|
@ -507,11 +507,11 @@ void ASTPrinter::endVisit(Literal const&)
|
||||
void ASTPrinter::printSourcePart(ASTNode const& _node)
|
||||
{
|
||||
if (m_gasCosts.count(&_node))
|
||||
*m_ostream << getIndentation() << " Gas costs: " << m_gasCosts.at(&_node) << endl;
|
||||
*m_ostream << indentation() << " Gas costs: " << m_gasCosts.at(&_node) << endl;
|
||||
if (!m_source.empty())
|
||||
{
|
||||
SourceLocation const& location(_node.location());
|
||||
*m_ostream << getIndentation() << " Source: "
|
||||
*m_ostream << indentation() << " Source: "
|
||||
<< escaped(m_source.substr(location.start, location.end - location.start), false) << endl;
|
||||
}
|
||||
}
|
||||
@ -519,19 +519,19 @@ void ASTPrinter::printSourcePart(ASTNode const& _node)
|
||||
void ASTPrinter::printType(Expression const& _expression)
|
||||
{
|
||||
if (_expression.type())
|
||||
*m_ostream << getIndentation() << " Type: " << _expression.type()->toString() << "\n";
|
||||
*m_ostream << indentation() << " Type: " << _expression.type()->toString() << "\n";
|
||||
else
|
||||
*m_ostream << getIndentation() << " Type unknown.\n";
|
||||
*m_ostream << indentation() << " Type unknown.\n";
|
||||
}
|
||||
|
||||
string ASTPrinter::getIndentation() const
|
||||
string ASTPrinter::indentation() const
|
||||
{
|
||||
return string(m_indentation * 2, ' ');
|
||||
}
|
||||
|
||||
void ASTPrinter::writeLine(string const& _line)
|
||||
{
|
||||
*m_ostream << getIndentation() << _line << endl;
|
||||
*m_ostream << indentation() << _line << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ public:
|
||||
private:
|
||||
void printSourcePart(ASTNode const& _node);
|
||||
void printType(Expression const& _expression);
|
||||
std::string getIndentation() const;
|
||||
std::string indentation() const;
|
||||
void writeLine(std::string const& _line);
|
||||
bool goDeeper() { m_indentation++; return true; }
|
||||
|
||||
|
@ -59,9 +59,9 @@ public:
|
||||
return m_context.streamAssembly(_stream, _sourceCodes, _inJsonFormat);
|
||||
}
|
||||
/// @returns Assembly items of the normal compiler context
|
||||
eth::AssemblyItems const& assemblyItems() const { return m_context.assembly().getItems(); }
|
||||
eth::AssemblyItems const& assemblyItems() const { return m_context.assembly().items(); }
|
||||
/// @returns Assembly items of the runtime compiler context
|
||||
eth::AssemblyItems const& runtimeAssemblyItems() const { return m_context.assembly().getSub(m_runtimeSub).getItems(); }
|
||||
eth::AssemblyItems const& runtimeAssemblyItems() const { return m_context.assembly().sub(m_runtimeSub).items(); }
|
||||
|
||||
/// @returns the entry label of the given function. Might return an AssemblyItem of type
|
||||
/// UndefinedItem if it does not exist yet.
|
||||
|
@ -339,9 +339,11 @@ void CompilerStack::resolveImports()
|
||||
{
|
||||
string const& id = import->identifier();
|
||||
if (!m_sources.count(id))
|
||||
BOOST_THROW_EXCEPTION(ParserError()
|
||||
<< errinfo_sourceLocation(import->location())
|
||||
<< errinfo_comment("Source not found."));
|
||||
BOOST_THROW_EXCEPTION(
|
||||
ParserError()
|
||||
<< errinfo_sourceLocation(import->location())
|
||||
<< errinfo_comment("Source not found.")
|
||||
);
|
||||
toposort(&m_sources[id]);
|
||||
}
|
||||
sourceOrder.push_back(_source);
|
||||
|
@ -450,8 +450,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
arg->accept(*this);
|
||||
argumentTypes.push_back(arg->type());
|
||||
}
|
||||
ContractDefinition const& contract = dynamic_cast<ContractType const&>(
|
||||
*function.returnParameterTypes().front()).contractDefinition();
|
||||
ContractDefinition const& contract =
|
||||
dynamic_cast<ContractType const&>(*function.returnParameterTypes().front()).contractDefinition();
|
||||
// copy the contract's code into memory
|
||||
bytes const& bytecode = m_context.compiledContract(contract);
|
||||
utils().fetchFreeMemoryPointer();
|
||||
@ -1087,8 +1087,10 @@ void ExpressionCompiler::appendExternalFunctionCall(
|
||||
vector<ASTPointer<Expression const>> const& _arguments
|
||||
)
|
||||
{
|
||||
solAssert(_functionType.takesArbitraryParameters() ||
|
||||
_arguments.size() == _functionType.parameterTypes().size(), "");
|
||||
solAssert(
|
||||
_functionType.takesArbitraryParameters() ||
|
||||
_arguments.size() == _functionType.parameterTypes().size(), ""
|
||||
);
|
||||
|
||||
// Assumed stack content here:
|
||||
// <stack top>
|
||||
|
@ -52,7 +52,7 @@ GasEstimator::ASTGasConsumptionSelfAccumulated GasEstimator::structuralEstimatio
|
||||
GasMeter meter(block.startState->copy());
|
||||
auto const end = _items.begin() + block.end;
|
||||
for (auto iter = _items.begin() + block.begin; iter != end; ++iter)
|
||||
particularCosts[iter->getLocation()] += meter.estimateMax(*iter);
|
||||
particularCosts[iter->location()] += meter.estimateMax(*iter);
|
||||
}
|
||||
|
||||
set<ASTNode const*> finestNodes = finestNodesAtLocation(_ast);
|
||||
|
@ -393,7 +393,7 @@ string::const_iterator InterfaceHandler::appendDocTag(
|
||||
}
|
||||
}
|
||||
|
||||
static inline string::const_iterator getFirstSpaceOrNl(
|
||||
static inline string::const_iterator firstSpaceOrNl(
|
||||
string::const_iterator _pos,
|
||||
string::const_iterator _end
|
||||
)
|
||||
@ -416,7 +416,7 @@ void InterfaceHandler::parseDocString(string const& _string, CommentOwner _owner
|
||||
if (tagPos != end && tagPos < nlPos)
|
||||
{
|
||||
// we found a tag
|
||||
auto tagNameEndPos = getFirstSpaceOrNl(tagPos, end);
|
||||
auto tagNameEndPos = firstSpaceOrNl(tagPos, end);
|
||||
if (tagNameEndPos == end)
|
||||
BOOST_THROW_EXCEPTION(
|
||||
DocstringParsingError() <<
|
||||
|
@ -697,8 +697,10 @@ bool ContractType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
|
||||
bool ContractType::isExplicitlyConvertibleTo(Type const& _convertTo) const
|
||||
{
|
||||
return isImplicitlyConvertibleTo(_convertTo) || _convertTo.category() == Category::Integer ||
|
||||
_convertTo.category() == Category::Contract;
|
||||
return
|
||||
isImplicitlyConvertibleTo(_convertTo) ||
|
||||
_convertTo.category() == Category::Integer ||
|
||||
_convertTo.category() == Category::Contract;
|
||||
}
|
||||
|
||||
TypePointer ContractType::unaryOperatorResult(Token::Value _operator) const
|
||||
|
@ -80,10 +80,10 @@ void checkAssemblyLocations(AssemblyItems const& _items, vector<SourceLocation>
|
||||
for (size_t i = 0; i < min(_items.size(), _locations.size()); ++i)
|
||||
{
|
||||
BOOST_CHECK_MESSAGE(
|
||||
_items[i].getLocation() == _locations[i],
|
||||
_items[i].location() == _locations[i],
|
||||
"Location mismatch for assembly item " + to_string(i) + ". Found: " +
|
||||
to_string(_items[i].getLocation().start) + "-" +
|
||||
to_string(_items[i].getLocation().end) + ", expected: " +
|
||||
to_string(_items[i].location().start) + "-" +
|
||||
to_string(_items[i].location().end) + ", expected: " +
|
||||
to_string(_locations[i].start) + "-" +
|
||||
to_string(_locations[i].end));
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class FirstExpressionExtractor: private ASTVisitor
|
||||
{
|
||||
public:
|
||||
FirstExpressionExtractor(ASTNode& _node): m_expression(nullptr) { _node.accept(*this); }
|
||||
Expression* getExpression() const { return m_expression; }
|
||||
Expression* expression() const { return m_expression; }
|
||||
private:
|
||||
virtual bool visit(Assignment& _expression) override { return checkExpression(_expression); }
|
||||
virtual bool visit(UnaryOperation& _expression) override { return checkExpression(_expression); }
|
||||
@ -123,7 +123,7 @@ bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _
|
||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||
{
|
||||
FirstExpressionExtractor extractor(*contract);
|
||||
BOOST_REQUIRE(extractor.getExpression() != nullptr);
|
||||
BOOST_REQUIRE(extractor.expression() != nullptr);
|
||||
|
||||
CompilerContext context;
|
||||
context.resetVisitedNodes(contract);
|
||||
@ -134,7 +134,7 @@ bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _
|
||||
context.addVariable(dynamic_cast<VariableDeclaration const&>(resolveDeclaration(variable, resolver)),
|
||||
parametersSize--);
|
||||
|
||||
ExpressionCompiler(context).compile(*extractor.getExpression());
|
||||
ExpressionCompiler(context).compile(*extractor.expression());
|
||||
|
||||
for (vector<string> const& function: _functions)
|
||||
context << context.functionEntryLabel(dynamic_cast<FunctionDefinition const&>(resolveDeclaration(function, resolver)));
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
return m_reCompiler.contractDefinition(_contractName);
|
||||
}
|
||||
|
||||
string getSourcePart(ASTNode const& _node) const
|
||||
string sourcePart(ASTNode const& _node) const
|
||||
{
|
||||
SourceLocation location = _node.location();
|
||||
BOOST_REQUIRE(!location.isEmpty());
|
||||
@ -67,7 +67,7 @@ BOOST_FIXTURE_TEST_SUITE(SolidityInterface, SolidityInterfaceChecker)
|
||||
BOOST_AUTO_TEST_CASE(empty_contract)
|
||||
{
|
||||
ContractDefinition const& contract = checkInterface("contract test {}");
|
||||
BOOST_CHECK_EQUAL(getSourcePart(contract), "contract test{}");
|
||||
BOOST_CHECK_EQUAL(sourcePart(contract), "contract test{}");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(single_function)
|
||||
@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(single_function)
|
||||
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
||||
"}\n");
|
||||
BOOST_REQUIRE_EQUAL(1, contract.definedFunctions().size());
|
||||
BOOST_CHECK_EQUAL(getSourcePart(*contract.definedFunctions().front()),
|
||||
BOOST_CHECK_EQUAL(sourcePart(*contract.definedFunctions().front()),
|
||||
"function f(uint256 a)returns(uint256 d);");
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(single_constant_function)
|
||||
ContractDefinition const& contract = checkInterface(
|
||||
"contract test { function f(uint a) constant returns(bytes1 x) { 1==2; } }");
|
||||
BOOST_REQUIRE_EQUAL(1, contract.definedFunctions().size());
|
||||
BOOST_CHECK_EQUAL(getSourcePart(*contract.definedFunctions().front()),
|
||||
BOOST_CHECK_EQUAL(sourcePart(*contract.definedFunctions().front()),
|
||||
"function f(uint256 a)constant returns(bytes1 x);");
|
||||
}
|
||||
|
||||
@ -100,15 +100,15 @@ BOOST_AUTO_TEST_CASE(multiple_functions)
|
||||
set<string> expectation({"function f(uint256 a)returns(uint256 d);",
|
||||
"function g(uint256 b)returns(uint256 e);"});
|
||||
BOOST_REQUIRE_EQUAL(2, contract.definedFunctions().size());
|
||||
BOOST_CHECK(expectation == set<string>({getSourcePart(*contract.definedFunctions().at(0)),
|
||||
getSourcePart(*contract.definedFunctions().at(1))}));
|
||||
BOOST_CHECK(expectation == set<string>({sourcePart(*contract.definedFunctions().at(0)),
|
||||
sourcePart(*contract.definedFunctions().at(1))}));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(exclude_fallback_function)
|
||||
{
|
||||
char const* sourceCode = "contract test { function() {} }";
|
||||
ContractDefinition const& contract = checkInterface(sourceCode);
|
||||
BOOST_CHECK_EQUAL(getSourcePart(contract), "contract test{}");
|
||||
BOOST_CHECK_EQUAL(sourcePart(contract), "contract test{}");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(events)
|
||||
@ -138,8 +138,8 @@ BOOST_AUTO_TEST_CASE(inheritance)
|
||||
set<string> expectedFunctions({"function baseFunction(uint256 p)returns(uint256 i);",
|
||||
"function derivedFunction(bytes32 p)returns(bytes32 i);"});
|
||||
BOOST_REQUIRE_EQUAL(2, contract.definedFunctions().size());
|
||||
BOOST_CHECK(expectedFunctions == set<string>({getSourcePart(*contract.definedFunctions().at(0)),
|
||||
getSourcePart(*contract.definedFunctions().at(1))}));
|
||||
BOOST_CHECK(expectedFunctions == set<string>({sourcePart(*contract.definedFunctions().at(0)),
|
||||
sourcePart(*contract.definedFunctions().at(1))}));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -101,7 +101,7 @@ public:
|
||||
return state;
|
||||
}
|
||||
|
||||
AssemblyItems getCSE(AssemblyItems const& _input, eth::KnownState const& _state = eth::KnownState())
|
||||
AssemblyItems CSE(AssemblyItems const& _input, eth::KnownState const& _state = eth::KnownState())
|
||||
{
|
||||
AssemblyItems input = addDummyLocations(_input);
|
||||
|
||||
@ -111,7 +111,7 @@ public:
|
||||
|
||||
for (AssemblyItem const& item: output)
|
||||
{
|
||||
BOOST_CHECK(item == Instruction::POP || !item.getLocation().isEmpty());
|
||||
BOOST_CHECK(item == Instruction::POP || !item.location().isEmpty());
|
||||
}
|
||||
return output;
|
||||
}
|
||||
@ -122,11 +122,11 @@ public:
|
||||
KnownState const& _state = eth::KnownState()
|
||||
)
|
||||
{
|
||||
AssemblyItems output = getCSE(_input, _state);
|
||||
AssemblyItems output = CSE(_input, _state);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(_expectation.begin(), _expectation.end(), output.begin(), output.end());
|
||||
}
|
||||
|
||||
AssemblyItems getCFG(AssemblyItems const& _input)
|
||||
AssemblyItems CFG(AssemblyItems const& _input)
|
||||
{
|
||||
AssemblyItems output = _input;
|
||||
// Running it four times should be enough for these tests.
|
||||
@ -144,7 +144,7 @@ public:
|
||||
|
||||
void checkCFG(AssemblyItems const& _input, AssemblyItems const& _expectation)
|
||||
{
|
||||
AssemblyItems output = getCFG(_input);
|
||||
AssemblyItems output = CFG(_input);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(_expectation.begin(), _expectation.end(), output.begin(), output.end());
|
||||
}
|
||||
|
||||
@ -890,7 +890,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content_noninterfering_store_in_between
|
||||
Instruction::SHA3 // sha3(m[12..(12+32)])
|
||||
};
|
||||
// if this changes too often, only count the number of SHA3 and MSTORE instructions
|
||||
AssemblyItems output = getCSE(input);
|
||||
AssemblyItems output = CSE(input);
|
||||
BOOST_CHECK_EQUAL(4, count(output.begin(), output.end(), AssemblyItem(Instruction::MSTORE)));
|
||||
BOOST_CHECK_EQUAL(1, count(output.begin(), output.end(), AssemblyItem(Instruction::SHA3)));
|
||||
}
|
||||
@ -914,7 +914,7 @@ BOOST_AUTO_TEST_CASE(cse_equality_on_initially_known_stack)
|
||||
AssemblyItems input{
|
||||
Instruction::EQ
|
||||
};
|
||||
AssemblyItems output = getCSE(input, state);
|
||||
AssemblyItems output = CSE(input, state);
|
||||
// check that it directly pushes 1 (true)
|
||||
BOOST_CHECK(find(output.begin(), output.end(), AssemblyItem(u256(1))) != output.end());
|
||||
}
|
||||
@ -938,7 +938,7 @@ BOOST_AUTO_TEST_CASE(cse_access_previous_sequence)
|
||||
u256(0),
|
||||
Instruction::SLOAD,
|
||||
};
|
||||
BOOST_CHECK_THROW(getCSE(input, state), StackTooDeepException);
|
||||
BOOST_CHECK_THROW(CSE(input, state), StackTooDeepException);
|
||||
// @todo for now, this throws an exception, but it should recover to the following
|
||||
// (or an even better version) at some point:
|
||||
// 0, SLOAD, 1, ADD, SSTORE, 0 SLOAD
|
||||
|
Loading…
Reference in New Issue
Block a user