mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Removed std:: where it made sense.
This commit is contained in:
parent
58be273506
commit
6a96b6b5ad
20
AST.cpp
20
AST.cpp
@ -26,6 +26,8 @@
|
||||
#include <libsolidity/ASTVisitor.h>
|
||||
#include <libsolidity/Exceptions.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
@ -248,7 +250,7 @@ void Literal::accept(ASTVisitor& _visitor)
|
||||
_visitor.endVisit(*this);
|
||||
}
|
||||
|
||||
TypeError ASTNode::createTypeError(std::string const& _description)
|
||||
TypeError ASTNode::createTypeError(string const& _description)
|
||||
{
|
||||
return TypeError() << errinfo_sourceLocation(getLocation()) << errinfo_comment(_description);
|
||||
}
|
||||
@ -263,7 +265,7 @@ void Statement::expectType(Expression& _expression, const Type& _expectedType)
|
||||
|
||||
void Block::checkTypeRequirements()
|
||||
{
|
||||
for (std::shared_ptr<Statement> const& statement: m_statements)
|
||||
for (shared_ptr<Statement> const& statement: m_statements)
|
||||
statement->checkTypeRequirements();
|
||||
}
|
||||
|
||||
@ -354,7 +356,7 @@ void BinaryOperation::checkTypeRequirements()
|
||||
else
|
||||
BOOST_THROW_EXCEPTION(createTypeError("No common type found in binary operation."));
|
||||
if (Token::isCompareOp(m_operator))
|
||||
m_type = std::make_shared<BoolType>();
|
||||
m_type = make_shared<BoolType>();
|
||||
else
|
||||
{
|
||||
assert(Token::isBinaryOp(m_operator));
|
||||
@ -392,7 +394,7 @@ void FunctionCall::checkTypeRequirements()
|
||||
FunctionType const* function = dynamic_cast<FunctionType const*>(expressionType);
|
||||
assert(function);
|
||||
FunctionDefinition const& fun = function->getFunction();
|
||||
std::vector<ASTPointer<VariableDeclaration>> const& parameters = fun.getParameters();
|
||||
vector<ASTPointer<VariableDeclaration>> const& parameters = fun.getParameters();
|
||||
if (parameters.size() != m_arguments.size())
|
||||
BOOST_THROW_EXCEPTION(createTypeError("Wrong argument count for function call."));
|
||||
for (size_t i = 0; i < m_arguments.size(); ++i)
|
||||
@ -401,7 +403,7 @@ void FunctionCall::checkTypeRequirements()
|
||||
// @todo actually the return type should be an anonymous struct,
|
||||
// but we change it to the type of the first return value until we have structs
|
||||
if (fun.getReturnParameterList()->getParameters().empty())
|
||||
m_type = std::make_shared<VoidType>();
|
||||
m_type = make_shared<VoidType>();
|
||||
else
|
||||
m_type = fun.getReturnParameterList()->getParameters().front()->getType();
|
||||
}
|
||||
@ -449,7 +451,7 @@ void Identifier::checkTypeRequirements()
|
||||
if (structDef)
|
||||
{
|
||||
// note that we do not have a struct type here
|
||||
m_type = std::make_shared<TypeType>(std::make_shared<StructType>(*structDef));
|
||||
m_type = make_shared<TypeType>(make_shared<StructType>(*structDef));
|
||||
return;
|
||||
}
|
||||
FunctionDefinition* functionDef = dynamic_cast<FunctionDefinition*>(m_referencedDeclaration);
|
||||
@ -458,13 +460,13 @@ void Identifier::checkTypeRequirements()
|
||||
// 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
|
||||
// conversion.
|
||||
m_type = std::make_shared<FunctionType>(*functionDef);
|
||||
m_type = make_shared<FunctionType>(*functionDef);
|
||||
return;
|
||||
}
|
||||
ContractDefinition* contractDef = dynamic_cast<ContractDefinition*>(m_referencedDeclaration);
|
||||
if (contractDef)
|
||||
{
|
||||
m_type = std::make_shared<TypeType>(std::make_shared<ContractType>(*contractDef));
|
||||
m_type = make_shared<TypeType>(make_shared<ContractType>(*contractDef));
|
||||
return;
|
||||
}
|
||||
assert(false); // declaration reference of unknown/forbidden type
|
||||
@ -472,7 +474,7 @@ void Identifier::checkTypeRequirements()
|
||||
|
||||
void ElementaryTypeNameExpression::checkTypeRequirements()
|
||||
{
|
||||
m_type = std::make_shared<TypeType>(Type::fromElementaryTypeName(m_typeToken));
|
||||
m_type = make_shared<TypeType>(Type::fromElementaryTypeName(m_typeToken));
|
||||
}
|
||||
|
||||
void Literal::checkTypeRequirements()
|
||||
|
@ -23,17 +23,19 @@
|
||||
#include <libsolidity/ASTPrinter.h>
|
||||
#include <libsolidity/AST.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
{
|
||||
|
||||
ASTPrinter::ASTPrinter(ASTPointer<ASTNode> const& _ast, std::string const& _source):
|
||||
ASTPrinter::ASTPrinter(ASTPointer<ASTNode> const& _ast, string const& _source):
|
||||
m_indentation(0), m_source(_source), m_ast(_ast)
|
||||
{
|
||||
}
|
||||
|
||||
void ASTPrinter::print(std::ostream& _stream)
|
||||
void ASTPrinter::print(ostream& _stream)
|
||||
{
|
||||
m_ostream = &_stream;
|
||||
m_ast->accept(*this);
|
||||
@ -87,7 +89,7 @@ bool ASTPrinter::visit(TypeName& _node)
|
||||
|
||||
bool ASTPrinter::visit(ElementaryTypeName& _node)
|
||||
{
|
||||
writeLine(std::string("ElementaryTypeName ") + Token::toString(_node.getTypeName()));
|
||||
writeLine(string("ElementaryTypeName ") + Token::toString(_node.getTypeName()));
|
||||
printSourcePart(_node);
|
||||
return goDeeper();
|
||||
}
|
||||
@ -179,7 +181,7 @@ bool ASTPrinter::visit(Expression& _node)
|
||||
|
||||
bool ASTPrinter::visit(Assignment& _node)
|
||||
{
|
||||
writeLine(std::string("Assignment using operator ") + Token::toString(_node.getAssignmentOperator()));
|
||||
writeLine(string("Assignment using operator ") + Token::toString(_node.getAssignmentOperator()));
|
||||
printType(_node);
|
||||
printSourcePart(_node);
|
||||
return goDeeper();
|
||||
@ -187,7 +189,7 @@ bool ASTPrinter::visit(Assignment& _node)
|
||||
|
||||
bool ASTPrinter::visit(UnaryOperation& _node)
|
||||
{
|
||||
writeLine(std::string("UnaryOperation (") + (_node.isPrefixOperation() ? "prefix" : "postfix") +
|
||||
writeLine(string("UnaryOperation (") + (_node.isPrefixOperation() ? "prefix" : "postfix") +
|
||||
") " + Token::toString(_node.getOperator()));
|
||||
printType(_node);
|
||||
printSourcePart(_node);
|
||||
@ -196,7 +198,7 @@ bool ASTPrinter::visit(UnaryOperation& _node)
|
||||
|
||||
bool ASTPrinter::visit(BinaryOperation& _node)
|
||||
{
|
||||
writeLine(std::string("BinaryOperation using operator ") + Token::toString(_node.getOperator()));
|
||||
writeLine(string("BinaryOperation using operator ") + Token::toString(_node.getOperator()));
|
||||
printType(_node);
|
||||
printSourcePart(_node);
|
||||
return goDeeper();
|
||||
@ -236,7 +238,7 @@ bool ASTPrinter::visit(PrimaryExpression& _node)
|
||||
|
||||
bool ASTPrinter::visit(Identifier& _node)
|
||||
{
|
||||
writeLine(std::string("Identifier ") + _node.getName());
|
||||
writeLine(string("Identifier ") + _node.getName());
|
||||
printType(_node);
|
||||
printSourcePart(_node);
|
||||
return goDeeper();
|
||||
@ -244,7 +246,7 @@ bool ASTPrinter::visit(Identifier& _node)
|
||||
|
||||
bool ASTPrinter::visit(ElementaryTypeNameExpression& _node)
|
||||
{
|
||||
writeLine(std::string("ElementaryTypeNameExpression ") + Token::toString(_node.getTypeToken()));
|
||||
writeLine(string("ElementaryTypeNameExpression ") + Token::toString(_node.getTypeToken()));
|
||||
printType(_node);
|
||||
printSourcePart(_node);
|
||||
return goDeeper();
|
||||
@ -255,7 +257,7 @@ bool ASTPrinter::visit(Literal& _node)
|
||||
char const* tokenString = Token::toString(_node.getToken());
|
||||
if (!tokenString)
|
||||
tokenString = "[no token]";
|
||||
writeLine(std::string("Literal, token: ") + tokenString + " value: " + _node.getValue());
|
||||
writeLine(string("Literal, token: ") + tokenString + " value: " + _node.getValue());
|
||||
printType(_node);
|
||||
printSourcePart(_node);
|
||||
return goDeeper();
|
||||
@ -417,7 +419,7 @@ void ASTPrinter::printSourcePart(ASTNode const& _node)
|
||||
{
|
||||
Location const& location(_node.getLocation());
|
||||
*m_ostream << getIndentation() << " Source: |"
|
||||
<< m_source.substr(location.start, location.end - location.start) << "|" << std::endl;
|
||||
<< m_source.substr(location.start, location.end - location.start) << "|" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -429,14 +431,14 @@ void ASTPrinter::printType(Expression const& _expression)
|
||||
*m_ostream << getIndentation() << " Type unknown.\n";
|
||||
}
|
||||
|
||||
std::string ASTPrinter::getIndentation() const
|
||||
string ASTPrinter::getIndentation() const
|
||||
{
|
||||
return std::string(m_indentation * 2, ' ');
|
||||
return string(m_indentation * 2, ' ');
|
||||
}
|
||||
|
||||
void ASTPrinter::writeLine(std::string const& _line)
|
||||
void ASTPrinter::writeLine(string const& _line)
|
||||
{
|
||||
*m_ostream << getIndentation() << _line << std::endl;
|
||||
*m_ostream << getIndentation() << _line << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include <libsolidity/AST.h>
|
||||
#include <libsolidity/Exceptions.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
@ -67,7 +69,7 @@ Declaration* NameAndTypeResolver::getNameFromCurrentScope(ASTString const& _name
|
||||
}
|
||||
|
||||
|
||||
DeclarationRegistrationHelper::DeclarationRegistrationHelper(std::map<ASTNode*, Scope>& _scopes,
|
||||
DeclarationRegistrationHelper::DeclarationRegistrationHelper(map<ASTNode*, Scope>& _scopes,
|
||||
ASTNode& _astRoot):
|
||||
m_scopes(_scopes), m_currentScope(&m_scopes[nullptr])
|
||||
{
|
||||
@ -119,9 +121,9 @@ void DeclarationRegistrationHelper::endVisit(VariableDeclaration&)
|
||||
|
||||
void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _node)
|
||||
{
|
||||
std::map<ASTNode*, Scope>::iterator iter;
|
||||
map<ASTNode*, Scope>::iterator iter;
|
||||
bool newlyAdded;
|
||||
std::tie(iter, newlyAdded) = m_scopes.emplace(&_node, Scope(m_currentScope));
|
||||
tie(iter, newlyAdded) = m_scopes.emplace(&_node, Scope(m_currentScope));
|
||||
assert(newlyAdded);
|
||||
m_currentScope = &iter->second;
|
||||
}
|
||||
|
29
Scanner.cpp
29
Scanner.cpp
@ -55,6 +55,8 @@
|
||||
#include <tuple>
|
||||
#include <libsolidity/Scanner.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
@ -607,7 +609,7 @@ Token::Value Scanner::scanNumber(bool _periodSeen)
|
||||
KEYWORD("while", Token::WHILE) \
|
||||
|
||||
|
||||
static Token::Value KeywordOrIdentifierToken(std::string const& input)
|
||||
static Token::Value KeywordOrIdentifierToken(string const& input)
|
||||
{
|
||||
assert(!input.empty());
|
||||
int const kMinLength = 2;
|
||||
@ -664,37 +666,36 @@ char CharStream::rollback(size_t _amount)
|
||||
return get();
|
||||
}
|
||||
|
||||
std::string CharStream::getLineAtPosition(int _position) const
|
||||
string CharStream::getLineAtPosition(int _position) const
|
||||
{
|
||||
// if _position points to \n, it returns the line before the \n
|
||||
using size_type = std::string::size_type;
|
||||
size_type searchStart = std::min<size_type>(m_source.size(), _position);
|
||||
using size_type = string::size_type;
|
||||
size_type searchStart = min<size_type>(m_source.size(), _position);
|
||||
if (searchStart > 0)
|
||||
searchStart--;
|
||||
size_type lineStart = m_source.rfind('\n', searchStart);
|
||||
if (lineStart == std::string::npos)
|
||||
if (lineStart == string::npos)
|
||||
lineStart = 0;
|
||||
else
|
||||
lineStart++;
|
||||
return m_source.substr(lineStart,
|
||||
std::min(m_source.find('\n', lineStart),
|
||||
m_source.size()) - lineStart);
|
||||
return m_source.substr(lineStart, min(m_source.find('\n', lineStart),
|
||||
m_source.size()) - lineStart);
|
||||
}
|
||||
|
||||
std::tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const
|
||||
tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const
|
||||
{
|
||||
using size_type = std::string::size_type;
|
||||
size_type searchPosition = std::min<size_type>(m_source.size(), _position);
|
||||
int lineNumber = std::count(m_source.begin(), m_source.begin() + searchPosition, '\n');
|
||||
using size_type = string::size_type;
|
||||
size_type searchPosition = min<size_type>(m_source.size(), _position);
|
||||
int lineNumber = count(m_source.begin(), m_source.begin() + searchPosition, '\n');
|
||||
size_type lineStart;
|
||||
if (searchPosition == 0)
|
||||
lineStart = 0;
|
||||
else
|
||||
{
|
||||
lineStart = m_source.rfind('\n', searchPosition - 1);
|
||||
lineStart = lineStart == std::string::npos ? 0 : lineStart + 1;
|
||||
lineStart = lineStart == string::npos ? 0 : lineStart + 1;
|
||||
}
|
||||
return std::tuple<int, int>(lineNumber, searchPosition - lineStart);
|
||||
return tuple<int, int>(lineNumber, searchPosition - lineStart);
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,57 +24,59 @@
|
||||
#include <libsolidity/Scanner.h>
|
||||
#include <libsolidity/Exceptions.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
{
|
||||
|
||||
void SourceReferenceFormatter::printSourceLocation(std::ostream& _stream,
|
||||
void SourceReferenceFormatter::printSourceLocation(ostream& _stream,
|
||||
Location const& _location,
|
||||
Scanner const& _scanner)
|
||||
{
|
||||
int startLine;
|
||||
int startColumn;
|
||||
std::tie(startLine, startColumn) = _scanner.translatePositionToLineColumn(_location.start);
|
||||
tie(startLine, startColumn) = _scanner.translatePositionToLineColumn(_location.start);
|
||||
_stream << "starting at line " << (startLine + 1) << ", column " << (startColumn + 1) << "\n";
|
||||
int endLine;
|
||||
int endColumn;
|
||||
std::tie(endLine, endColumn) = _scanner.translatePositionToLineColumn(_location.end);
|
||||
tie(endLine, endColumn) = _scanner.translatePositionToLineColumn(_location.end);
|
||||
if (startLine == endLine)
|
||||
{
|
||||
_stream << _scanner.getLineAtPosition(_location.start) << std::endl
|
||||
<< std::string(startColumn, ' ') << "^";
|
||||
_stream << _scanner.getLineAtPosition(_location.start) << endl
|
||||
<< string(startColumn, ' ') << "^";
|
||||
if (endColumn > startColumn + 2)
|
||||
_stream << std::string(endColumn - startColumn - 2, '-');
|
||||
_stream << string(endColumn - startColumn - 2, '-');
|
||||
if (endColumn > startColumn + 1)
|
||||
_stream << "^";
|
||||
_stream << std::endl;
|
||||
_stream << endl;
|
||||
}
|
||||
else
|
||||
_stream << _scanner.getLineAtPosition(_location.start) << std::endl
|
||||
<< std::string(startColumn, ' ') << "^\n"
|
||||
_stream << _scanner.getLineAtPosition(_location.start) << endl
|
||||
<< string(startColumn, ' ') << "^\n"
|
||||
<< "Spanning multiple lines.\n";
|
||||
}
|
||||
|
||||
void SourceReferenceFormatter::printSourcePosition(std::ostream& _stream,
|
||||
void SourceReferenceFormatter::printSourcePosition(ostream& _stream,
|
||||
int _position,
|
||||
const Scanner& _scanner)
|
||||
{
|
||||
int line;
|
||||
int column;
|
||||
std::tie(line, column) = _scanner.translatePositionToLineColumn(_position);
|
||||
_stream << "at line " << (line + 1) << ", column " << (column + 1) << std::endl
|
||||
<< _scanner.getLineAtPosition(_position) << std::endl
|
||||
<< std::string(column, ' ') << "^" << std::endl;
|
||||
tie(line, column) = _scanner.translatePositionToLineColumn(_position);
|
||||
_stream << "at line " << (line + 1) << ", column " << (column + 1) << endl
|
||||
<< _scanner.getLineAtPosition(_position) << endl
|
||||
<< string(column, ' ') << "^" << endl;
|
||||
}
|
||||
|
||||
void SourceReferenceFormatter::printExceptionInformation(std::ostream& _stream,
|
||||
void SourceReferenceFormatter::printExceptionInformation(ostream& _stream,
|
||||
Exception const& _exception,
|
||||
std::string const& _name,
|
||||
string const& _name,
|
||||
Scanner const& _scanner)
|
||||
{
|
||||
_stream << _name;
|
||||
if (std::string const* description = boost::get_error_info<errinfo_comment>(_exception))
|
||||
if (string const* description = boost::get_error_info<errinfo_comment>(_exception))
|
||||
_stream << ": " << *description;
|
||||
|
||||
if (int const* position = boost::get_error_info<errinfo_sourcePosition>(_exception))
|
||||
|
Loading…
Reference in New Issue
Block a user