From fd7fc4293ebe00abf8c3d9239eb6b61b9f568ef5 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 24 Oct 2014 19:06:30 +0200 Subject: [PATCH] Removed std:: where it made sense. --- libsolidity/AST.cpp | 20 +++++++------ libsolidity/ASTPrinter.cpp | 30 +++++++++++--------- libsolidity/NameAndTypeResolver.cpp | 8 ++++-- libsolidity/Scanner.cpp | 29 ++++++++++--------- libsolidity/SourceReferenceFormatter.cpp | 36 +++++++++++++----------- 5 files changed, 66 insertions(+), 57 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index 49bb071a0..0b635339d 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -26,6 +26,8 @@ #include #include +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 const& statement: m_statements) + for (shared_ptr 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(); + m_type = make_shared(); else { assert(Token::isBinaryOp(m_operator)); @@ -392,7 +394,7 @@ void FunctionCall::checkTypeRequirements() FunctionType const* function = dynamic_cast(expressionType); assert(function); FunctionDefinition const& fun = function->getFunction(); - std::vector> const& parameters = fun.getParameters(); + vector> 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(); + m_type = make_shared(); 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(std::make_shared(*structDef)); + m_type = make_shared(make_shared(*structDef)); return; } FunctionDefinition* functionDef = dynamic_cast(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(*functionDef); + m_type = make_shared(*functionDef); return; } ContractDefinition* contractDef = dynamic_cast(m_referencedDeclaration); if (contractDef) { - m_type = std::make_shared(std::make_shared(*contractDef)); + m_type = make_shared(make_shared(*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(Type::fromElementaryTypeName(m_typeToken)); + m_type = make_shared(Type::fromElementaryTypeName(m_typeToken)); } void Literal::checkTypeRequirements() diff --git a/libsolidity/ASTPrinter.cpp b/libsolidity/ASTPrinter.cpp index b933e7caa..9b545ac9e 100644 --- a/libsolidity/ASTPrinter.cpp +++ b/libsolidity/ASTPrinter.cpp @@ -23,17 +23,19 @@ #include #include +using namespace std; + namespace dev { namespace solidity { -ASTPrinter::ASTPrinter(ASTPointer const& _ast, std::string const& _source): +ASTPrinter::ASTPrinter(ASTPointer 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; } } diff --git a/libsolidity/NameAndTypeResolver.cpp b/libsolidity/NameAndTypeResolver.cpp index edd946df8..9626ca848 100644 --- a/libsolidity/NameAndTypeResolver.cpp +++ b/libsolidity/NameAndTypeResolver.cpp @@ -25,6 +25,8 @@ #include #include +using namespace std; + namespace dev { namespace solidity @@ -67,7 +69,7 @@ Declaration* NameAndTypeResolver::getNameFromCurrentScope(ASTString const& _name } -DeclarationRegistrationHelper::DeclarationRegistrationHelper(std::map& _scopes, +DeclarationRegistrationHelper::DeclarationRegistrationHelper(map& _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::iterator iter; + map::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; } diff --git a/libsolidity/Scanner.cpp b/libsolidity/Scanner.cpp index 649054356..3148de52e 100644 --- a/libsolidity/Scanner.cpp +++ b/libsolidity/Scanner.cpp @@ -55,6 +55,8 @@ #include #include +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(m_source.size(), _position); + using size_type = string::size_type; + size_type searchStart = min(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 CharStream::translatePositionToLineColumn(int _position) const +tuple CharStream::translatePositionToLineColumn(int _position) const { - using size_type = std::string::size_type; - size_type searchPosition = std::min(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(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(lineNumber, searchPosition - lineStart); + return tuple(lineNumber, searchPosition - lineStart); } diff --git a/libsolidity/SourceReferenceFormatter.cpp b/libsolidity/SourceReferenceFormatter.cpp index b270342c9..d3f2152a6 100644 --- a/libsolidity/SourceReferenceFormatter.cpp +++ b/libsolidity/SourceReferenceFormatter.cpp @@ -24,57 +24,59 @@ #include #include +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(_exception)) + if (string const* description = boost::get_error_info(_exception)) _stream << ": " << *description; if (int const* position = boost::get_error_info(_exception))