mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove nullptr comparisons.
This commit is contained in:
parent
1ae1fc66e2
commit
f8038792ca
16
AST.cpp
16
AST.cpp
@ -291,7 +291,7 @@ void Break::checkTypeRequirements()
|
|||||||
|
|
||||||
void Return::checkTypeRequirements()
|
void Return::checkTypeRequirements()
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(m_returnParameters != nullptr);
|
BOOST_ASSERT(m_returnParameters);
|
||||||
if (m_returnParameters->getParameters().size() != 1)
|
if (m_returnParameters->getParameters().size() != 1)
|
||||||
BOOST_THROW_EXCEPTION(createTypeError("Different number of arguments in return statement "
|
BOOST_THROW_EXCEPTION(createTypeError("Different number of arguments in return statement "
|
||||||
"than in returns declaration."));
|
"than in returns declaration."));
|
||||||
@ -374,7 +374,7 @@ void FunctionCall::checkTypeRequirements()
|
|||||||
if (category == Type::Category::TYPE)
|
if (category == Type::Category::TYPE)
|
||||||
{
|
{
|
||||||
TypeType const* type = dynamic_cast<TypeType const*>(&expressionType);
|
TypeType const* type = dynamic_cast<TypeType const*>(&expressionType);
|
||||||
BOOST_ASSERT(type != nullptr);
|
BOOST_ASSERT(type);
|
||||||
//@todo for structs, we have to check the number of arguments to be equal to the
|
//@todo for structs, we have to check the number of arguments to be equal to the
|
||||||
// number of non-mapping members
|
// number of non-mapping members
|
||||||
if (m_arguments.size() != 1)
|
if (m_arguments.size() != 1)
|
||||||
@ -390,7 +390,7 @@ void FunctionCall::checkTypeRequirements()
|
|||||||
// and then ask if that is implicitly convertible to the struct represented by the
|
// and then ask if that is implicitly convertible to the struct represented by the
|
||||||
// function parameters
|
// function parameters
|
||||||
FunctionType const* function = dynamic_cast<FunctionType const*>(&expressionType);
|
FunctionType const* function = dynamic_cast<FunctionType const*>(&expressionType);
|
||||||
BOOST_ASSERT(function != nullptr);
|
BOOST_ASSERT(function);
|
||||||
FunctionDefinition const& fun = function->getFunction();
|
FunctionDefinition const& fun = function->getFunction();
|
||||||
std::vector<ASTPointer<VariableDeclaration>> const& parameters = fun.getParameters();
|
std::vector<ASTPointer<VariableDeclaration>> const& parameters = fun.getParameters();
|
||||||
if (parameters.size() != m_arguments.size())
|
if (parameters.size() != m_arguments.size())
|
||||||
@ -423,7 +423,7 @@ void IndexAccess::checkTypeRequirements()
|
|||||||
|
|
||||||
void Identifier::checkTypeRequirements()
|
void Identifier::checkTypeRequirements()
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(m_referencedDeclaration != nullptr);
|
BOOST_ASSERT(m_referencedDeclaration);
|
||||||
//@todo these dynamic casts here are not really nice...
|
//@todo these dynamic casts here are not really nice...
|
||||||
// is i useful to have an AST visitor here?
|
// is i useful to have an AST visitor here?
|
||||||
// or can this already be done in NameAndTypeResolver?
|
// or can this already be done in NameAndTypeResolver?
|
||||||
@ -433,7 +433,7 @@ void Identifier::checkTypeRequirements()
|
|||||||
// var y = x;
|
// var y = x;
|
||||||
// the type of x is not yet determined.
|
// the type of x is not yet determined.
|
||||||
VariableDeclaration* variable = dynamic_cast<VariableDeclaration*>(m_referencedDeclaration);
|
VariableDeclaration* variable = dynamic_cast<VariableDeclaration*>(m_referencedDeclaration);
|
||||||
if (variable != nullptr)
|
if (variable)
|
||||||
{
|
{
|
||||||
if (!variable->getType())
|
if (!variable->getType())
|
||||||
BOOST_THROW_EXCEPTION(createTypeError("Variable referenced before type "
|
BOOST_THROW_EXCEPTION(createTypeError("Variable referenced before type "
|
||||||
@ -443,14 +443,14 @@ void Identifier::checkTypeRequirements()
|
|||||||
}
|
}
|
||||||
//@todo can we unify these with TypeName::toType()?
|
//@todo can we unify these with TypeName::toType()?
|
||||||
StructDefinition* structDef = dynamic_cast<StructDefinition*>(m_referencedDeclaration);
|
StructDefinition* structDef = dynamic_cast<StructDefinition*>(m_referencedDeclaration);
|
||||||
if (structDef != nullptr)
|
if (structDef)
|
||||||
{
|
{
|
||||||
// note that we do not have a struct type here
|
// note that we do not have a struct type here
|
||||||
m_type = std::make_shared<TypeType>(std::make_shared<StructType>(*structDef));
|
m_type = std::make_shared<TypeType>(std::make_shared<StructType>(*structDef));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FunctionDefinition* functionDef = dynamic_cast<FunctionDefinition*>(m_referencedDeclaration);
|
FunctionDefinition* functionDef = dynamic_cast<FunctionDefinition*>(m_referencedDeclaration);
|
||||||
if (functionDef != nullptr)
|
if (functionDef)
|
||||||
{
|
{
|
||||||
// a function reference is not a TypeType, because calling a TypeType converts to the type.
|
// a function reference is not a TypeType, because calling a TypeType converts to the type.
|
||||||
// Calling a function (e.g. function(12), otherContract.function(34)) does not do a type
|
// Calling a function (e.g. function(12), otherContract.function(34)) does not do a type
|
||||||
@ -459,7 +459,7 @@ void Identifier::checkTypeRequirements()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ContractDefinition* contractDef = dynamic_cast<ContractDefinition*>(m_referencedDeclaration);
|
ContractDefinition* contractDef = dynamic_cast<ContractDefinition*>(m_referencedDeclaration);
|
||||||
if (contractDef != nullptr)
|
if (contractDef)
|
||||||
{
|
{
|
||||||
m_type = std::make_shared<TypeType>(std::make_shared<ContractType>(*contractDef));
|
m_type = std::make_shared<TypeType>(std::make_shared<ContractType>(*contractDef));
|
||||||
return;
|
return;
|
||||||
|
2
AST.h
2
AST.h
@ -169,7 +169,7 @@ public:
|
|||||||
Declaration(_location, _name), m_typeName(_type) {}
|
Declaration(_location, _name), m_typeName(_type) {}
|
||||||
virtual void accept(ASTVisitor& _visitor) override;
|
virtual void accept(ASTVisitor& _visitor) override;
|
||||||
|
|
||||||
bool isTypeGivenExplicitly() const { return m_typeName.get() != nullptr; }
|
bool isTypeGivenExplicitly() const { return bool(m_typeName); }
|
||||||
TypeName* getTypeName() const { return m_typeName.get(); }
|
TypeName* getTypeName() const { return m_typeName.get(); }
|
||||||
|
|
||||||
//! Returns the declared or inferred type. Can be an empty pointer if no type was explicitly
|
//! Returns the declared or inferred type. Can be an empty pointer if no type was explicitly
|
||||||
|
@ -243,7 +243,7 @@ bool ASTPrinter::visit(ElementaryTypeNameExpression& _node)
|
|||||||
bool ASTPrinter::visit(Literal& _node)
|
bool ASTPrinter::visit(Literal& _node)
|
||||||
{
|
{
|
||||||
char const* tokenString = Token::toString(_node.getToken());
|
char const* tokenString = Token::toString(_node.getToken());
|
||||||
if (tokenString == nullptr)
|
if (!tokenString)
|
||||||
tokenString = "[no token]";
|
tokenString = "[no token]";
|
||||||
writeLine(std::string("Literal, token: ") + tokenString + " value: " + _node.getValue());
|
writeLine(std::string("Literal, token: ") + tokenString + " value: " + _node.getValue());
|
||||||
printSourcePart(_node);
|
printSourcePart(_node);
|
||||||
|
@ -129,13 +129,13 @@ void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _node)
|
|||||||
|
|
||||||
void DeclarationRegistrationHelper::closeCurrentScope()
|
void DeclarationRegistrationHelper::closeCurrentScope()
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(m_currentScope != nullptr);
|
BOOST_ASSERT(m_currentScope);
|
||||||
m_currentScope = m_currentScope->getOuterScope();
|
m_currentScope = m_currentScope->getOuterScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaration, bool _opensScope)
|
void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaration, bool _opensScope)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(m_currentScope != nullptr);
|
BOOST_ASSERT(m_currentScope);
|
||||||
if (!m_currentScope->registerDeclaration(_declaration))
|
if (!m_currentScope->registerDeclaration(_declaration))
|
||||||
BOOST_THROW_EXCEPTION(DeclarationError() << errinfo_sourceLocation(_declaration.getLocation())
|
BOOST_THROW_EXCEPTION(DeclarationError() << errinfo_sourceLocation(_declaration.getLocation())
|
||||||
<< errinfo_comment("Identifier already declared."));
|
<< errinfo_comment("Identifier already declared."));
|
||||||
@ -155,14 +155,14 @@ void ReferencesResolver::endVisit(VariableDeclaration& _variable)
|
|||||||
{
|
{
|
||||||
// endVisit because the internal type needs resolving if it is a user defined type
|
// endVisit because the internal type needs resolving if it is a user defined type
|
||||||
// or mapping
|
// or mapping
|
||||||
if (_variable.getTypeName() != nullptr)
|
if (_variable.getTypeName())
|
||||||
_variable.setType(_variable.getTypeName()->toType());
|
_variable.setType(_variable.getTypeName()->toType());
|
||||||
// otherwise we have a "var"-declaration whose type is resolved by the first assignment
|
// otherwise we have a "var"-declaration whose type is resolved by the first assignment
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReferencesResolver::visit(Return& _return)
|
bool ReferencesResolver::visit(Return& _return)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(m_returnParameters != nullptr);
|
BOOST_ASSERT(m_returnParameters);
|
||||||
_return.setFunctionReturnParameters(*m_returnParameters);
|
_return.setFunctionReturnParameters(*m_returnParameters);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -176,12 +176,12 @@ bool ReferencesResolver::visit(Mapping&)
|
|||||||
bool ReferencesResolver::visit(UserDefinedTypeName& _typeName)
|
bool ReferencesResolver::visit(UserDefinedTypeName& _typeName)
|
||||||
{
|
{
|
||||||
Declaration* declaration = m_resolver.getNameFromCurrentScope(_typeName.getName());
|
Declaration* declaration = m_resolver.getNameFromCurrentScope(_typeName.getName());
|
||||||
if (declaration == nullptr)
|
if (!declaration)
|
||||||
BOOST_THROW_EXCEPTION(DeclarationError() << errinfo_sourceLocation(_typeName.getLocation())
|
BOOST_THROW_EXCEPTION(DeclarationError() << errinfo_sourceLocation(_typeName.getLocation())
|
||||||
<< errinfo_comment("Undeclared identifier."));
|
<< errinfo_comment("Undeclared identifier."));
|
||||||
StructDefinition* referencedStruct = dynamic_cast<StructDefinition*>(declaration);
|
StructDefinition* referencedStruct = dynamic_cast<StructDefinition*>(declaration);
|
||||||
//@todo later, contracts are also valid types
|
//@todo later, contracts are also valid types
|
||||||
if (referencedStruct == nullptr)
|
if (!referencedStruct)
|
||||||
BOOST_THROW_EXCEPTION(_typeName.createTypeError("Identifier does not name a type name."));
|
BOOST_THROW_EXCEPTION(_typeName.createTypeError("Identifier does not name a type name."));
|
||||||
_typeName.setReferencedStruct(*referencedStruct);
|
_typeName.setReferencedStruct(*referencedStruct);
|
||||||
return false;
|
return false;
|
||||||
@ -190,7 +190,7 @@ bool ReferencesResolver::visit(UserDefinedTypeName& _typeName)
|
|||||||
bool ReferencesResolver::visit(Identifier& _identifier)
|
bool ReferencesResolver::visit(Identifier& _identifier)
|
||||||
{
|
{
|
||||||
Declaration* declaration = m_resolver.getNameFromCurrentScope(_identifier.getName());
|
Declaration* declaration = m_resolver.getNameFromCurrentScope(_identifier.getName());
|
||||||
if (declaration == nullptr)
|
if (!declaration)
|
||||||
BOOST_THROW_EXCEPTION(DeclarationError() << errinfo_sourceLocation(_identifier.getLocation())
|
BOOST_THROW_EXCEPTION(DeclarationError() << errinfo_sourceLocation(_identifier.getLocation())
|
||||||
<< errinfo_comment("Undeclared identifier."));
|
<< errinfo_comment("Undeclared identifier."));
|
||||||
_identifier.setReferencedDeclaration(*declaration);
|
_identifier.setReferencedDeclaration(*declaration);
|
||||||
|
@ -41,7 +41,7 @@ Declaration* Scope::resolveName(ASTString const& _name, bool _recursive) const
|
|||||||
auto result = m_declarations.find(_name);
|
auto result = m_declarations.find(_name);
|
||||||
if (result != m_declarations.end())
|
if (result != m_declarations.end())
|
||||||
return result->second;
|
return result->second;
|
||||||
if (_recursive && m_outerScope != nullptr)
|
if (_recursive && m_outerScope)
|
||||||
return m_outerScope->resolveName(_name, true);
|
return m_outerScope->resolveName(_name, true);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -74,18 +74,15 @@ void SourceReferenceFormatter::printExceptionInformation(std::ostream& _stream,
|
|||||||
Scanner const& _scanner)
|
Scanner const& _scanner)
|
||||||
{
|
{
|
||||||
std::cerr << _name;
|
std::cerr << _name;
|
||||||
std::string const* description = boost::get_error_info<errinfo_comment>(_exception);
|
if (std::string const* description = boost::get_error_info<errinfo_comment>(_exception))
|
||||||
if (description != nullptr)
|
|
||||||
std::cerr << ": " << *description;
|
std::cerr << ": " << *description;
|
||||||
|
|
||||||
int const* position = boost::get_error_info<errinfo_sourcePosition>(_exception);
|
if (int const* position = boost::get_error_info<errinfo_sourcePosition>(_exception))
|
||||||
if (position != nullptr)
|
|
||||||
{
|
{
|
||||||
std::cerr << " ";
|
std::cerr << " ";
|
||||||
printSourcePosition(std::cerr, *position, _scanner);
|
printSourcePosition(std::cerr, *position, _scanner);
|
||||||
}
|
}
|
||||||
Location const* location = boost::get_error_info<errinfo_sourceLocation>(_exception);
|
if (Location const* location = boost::get_error_info<errinfo_sourceLocation>(_exception))
|
||||||
if (location != nullptr)
|
|
||||||
{
|
{
|
||||||
std::cerr << " ";
|
std::cerr << " ";
|
||||||
printSourceLocation(_stream, *location, _scanner);
|
printSourceLocation(_stream, *location, _scanner);
|
||||||
|
Loading…
Reference in New Issue
Block a user