Removed std:: where it made sense.

This commit is contained in:
Christian 2014-10-24 19:06:30 +02:00
parent 58be273506
commit 6a96b6b5ad
5 changed files with 66 additions and 57 deletions

20
AST.cpp
View File

@ -26,6 +26,8 @@
#include <libsolidity/ASTVisitor.h> #include <libsolidity/ASTVisitor.h>
#include <libsolidity/Exceptions.h> #include <libsolidity/Exceptions.h>
using namespace std;
namespace dev namespace dev
{ {
namespace solidity namespace solidity
@ -248,7 +250,7 @@ void Literal::accept(ASTVisitor& _visitor)
_visitor.endVisit(*this); _visitor.endVisit(*this);
} }
TypeError ASTNode::createTypeError(std::string const& _description) TypeError ASTNode::createTypeError(string const& _description)
{ {
return TypeError() << errinfo_sourceLocation(getLocation()) << errinfo_comment(_description); return TypeError() << errinfo_sourceLocation(getLocation()) << errinfo_comment(_description);
} }
@ -263,7 +265,7 @@ void Statement::expectType(Expression& _expression, const Type& _expectedType)
void Block::checkTypeRequirements() void Block::checkTypeRequirements()
{ {
for (std::shared_ptr<Statement> const& statement: m_statements) for (shared_ptr<Statement> const& statement: m_statements)
statement->checkTypeRequirements(); statement->checkTypeRequirements();
} }
@ -354,7 +356,7 @@ void BinaryOperation::checkTypeRequirements()
else else
BOOST_THROW_EXCEPTION(createTypeError("No common type found in binary operation.")); BOOST_THROW_EXCEPTION(createTypeError("No common type found in binary operation."));
if (Token::isCompareOp(m_operator)) if (Token::isCompareOp(m_operator))
m_type = std::make_shared<BoolType>(); m_type = make_shared<BoolType>();
else else
{ {
assert(Token::isBinaryOp(m_operator)); assert(Token::isBinaryOp(m_operator));
@ -392,7 +394,7 @@ void FunctionCall::checkTypeRequirements()
FunctionType const* function = dynamic_cast<FunctionType const*>(expressionType); FunctionType const* function = dynamic_cast<FunctionType const*>(expressionType);
assert(function); assert(function);
FunctionDefinition const& fun = function->getFunction(); 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()) if (parameters.size() != m_arguments.size())
BOOST_THROW_EXCEPTION(createTypeError("Wrong argument count for function call.")); BOOST_THROW_EXCEPTION(createTypeError("Wrong argument count for function call."));
for (size_t i = 0; i < m_arguments.size(); ++i) 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, // @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 // but we change it to the type of the first return value until we have structs
if (fun.getReturnParameterList()->getParameters().empty()) if (fun.getReturnParameterList()->getParameters().empty())
m_type = std::make_shared<VoidType>(); m_type = make_shared<VoidType>();
else else
m_type = fun.getReturnParameterList()->getParameters().front()->getType(); m_type = fun.getReturnParameterList()->getParameters().front()->getType();
} }
@ -449,7 +451,7 @@ void Identifier::checkTypeRequirements()
if (structDef) 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 = make_shared<TypeType>(make_shared<StructType>(*structDef));
return; return;
} }
FunctionDefinition* functionDef = dynamic_cast<FunctionDefinition*>(m_referencedDeclaration); 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. // 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
// conversion. // conversion.
m_type = std::make_shared<FunctionType>(*functionDef); m_type = make_shared<FunctionType>(*functionDef);
return; return;
} }
ContractDefinition* contractDef = dynamic_cast<ContractDefinition*>(m_referencedDeclaration); ContractDefinition* contractDef = dynamic_cast<ContractDefinition*>(m_referencedDeclaration);
if (contractDef) if (contractDef)
{ {
m_type = std::make_shared<TypeType>(std::make_shared<ContractType>(*contractDef)); m_type = make_shared<TypeType>(make_shared<ContractType>(*contractDef));
return; return;
} }
assert(false); // declaration reference of unknown/forbidden type assert(false); // declaration reference of unknown/forbidden type
@ -472,7 +474,7 @@ void Identifier::checkTypeRequirements()
void ElementaryTypeNameExpression::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() void Literal::checkTypeRequirements()

View File

@ -23,17 +23,19 @@
#include <libsolidity/ASTPrinter.h> #include <libsolidity/ASTPrinter.h>
#include <libsolidity/AST.h> #include <libsolidity/AST.h>
using namespace std;
namespace dev namespace dev
{ {
namespace solidity 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) m_indentation(0), m_source(_source), m_ast(_ast)
{ {
} }
void ASTPrinter::print(std::ostream& _stream) void ASTPrinter::print(ostream& _stream)
{ {
m_ostream = &_stream; m_ostream = &_stream;
m_ast->accept(*this); m_ast->accept(*this);
@ -87,7 +89,7 @@ bool ASTPrinter::visit(TypeName& _node)
bool ASTPrinter::visit(ElementaryTypeName& _node) bool ASTPrinter::visit(ElementaryTypeName& _node)
{ {
writeLine(std::string("ElementaryTypeName ") + Token::toString(_node.getTypeName())); writeLine(string("ElementaryTypeName ") + Token::toString(_node.getTypeName()));
printSourcePart(_node); printSourcePart(_node);
return goDeeper(); return goDeeper();
} }
@ -179,7 +181,7 @@ bool ASTPrinter::visit(Expression& _node)
bool ASTPrinter::visit(Assignment& _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); printType(_node);
printSourcePart(_node); printSourcePart(_node);
return goDeeper(); return goDeeper();
@ -187,7 +189,7 @@ bool ASTPrinter::visit(Assignment& _node)
bool ASTPrinter::visit(UnaryOperation& _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())); ") " + Token::toString(_node.getOperator()));
printType(_node); printType(_node);
printSourcePart(_node); printSourcePart(_node);
@ -196,7 +198,7 @@ bool ASTPrinter::visit(UnaryOperation& _node)
bool ASTPrinter::visit(BinaryOperation& _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); printType(_node);
printSourcePart(_node); printSourcePart(_node);
return goDeeper(); return goDeeper();
@ -236,7 +238,7 @@ bool ASTPrinter::visit(PrimaryExpression& _node)
bool ASTPrinter::visit(Identifier& _node) bool ASTPrinter::visit(Identifier& _node)
{ {
writeLine(std::string("Identifier ") + _node.getName()); writeLine(string("Identifier ") + _node.getName());
printType(_node); printType(_node);
printSourcePart(_node); printSourcePart(_node);
return goDeeper(); return goDeeper();
@ -244,7 +246,7 @@ bool ASTPrinter::visit(Identifier& _node)
bool ASTPrinter::visit(ElementaryTypeNameExpression& _node) bool ASTPrinter::visit(ElementaryTypeNameExpression& _node)
{ {
writeLine(std::string("ElementaryTypeNameExpression ") + Token::toString(_node.getTypeToken())); writeLine(string("ElementaryTypeNameExpression ") + Token::toString(_node.getTypeToken()));
printType(_node); printType(_node);
printSourcePart(_node); printSourcePart(_node);
return goDeeper(); return goDeeper();
@ -255,7 +257,7 @@ bool ASTPrinter::visit(Literal& _node)
char const* tokenString = Token::toString(_node.getToken()); char const* tokenString = Token::toString(_node.getToken());
if (!tokenString) if (!tokenString)
tokenString = "[no token]"; tokenString = "[no token]";
writeLine(std::string("Literal, token: ") + tokenString + " value: " + _node.getValue()); writeLine(string("Literal, token: ") + tokenString + " value: " + _node.getValue());
printType(_node); printType(_node);
printSourcePart(_node); printSourcePart(_node);
return goDeeper(); return goDeeper();
@ -417,7 +419,7 @@ void ASTPrinter::printSourcePart(ASTNode const& _node)
{ {
Location const& location(_node.getLocation()); Location const& location(_node.getLocation());
*m_ostream << getIndentation() << " Source: |" *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"; *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;
} }
} }

View File

@ -25,6 +25,8 @@
#include <libsolidity/AST.h> #include <libsolidity/AST.h>
#include <libsolidity/Exceptions.h> #include <libsolidity/Exceptions.h>
using namespace std;
namespace dev namespace dev
{ {
namespace solidity 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): ASTNode& _astRoot):
m_scopes(_scopes), m_currentScope(&m_scopes[nullptr]) m_scopes(_scopes), m_currentScope(&m_scopes[nullptr])
{ {
@ -119,9 +121,9 @@ void DeclarationRegistrationHelper::endVisit(VariableDeclaration&)
void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _node) void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _node)
{ {
std::map<ASTNode*, Scope>::iterator iter; map<ASTNode*, Scope>::iterator iter;
bool newlyAdded; 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); assert(newlyAdded);
m_currentScope = &iter->second; m_currentScope = &iter->second;
} }

View File

@ -55,6 +55,8 @@
#include <tuple> #include <tuple>
#include <libsolidity/Scanner.h> #include <libsolidity/Scanner.h>
using namespace std;
namespace dev namespace dev
{ {
namespace solidity namespace solidity
@ -607,7 +609,7 @@ Token::Value Scanner::scanNumber(bool _periodSeen)
KEYWORD("while", Token::WHILE) \ KEYWORD("while", Token::WHILE) \
static Token::Value KeywordOrIdentifierToken(std::string const& input) static Token::Value KeywordOrIdentifierToken(string const& input)
{ {
assert(!input.empty()); assert(!input.empty());
int const kMinLength = 2; int const kMinLength = 2;
@ -664,37 +666,36 @@ char CharStream::rollback(size_t _amount)
return get(); 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 // if _position points to \n, it returns the line before the \n
using size_type = std::string::size_type; using size_type = string::size_type;
size_type searchStart = std::min<size_type>(m_source.size(), _position); size_type searchStart = min<size_type>(m_source.size(), _position);
if (searchStart > 0) if (searchStart > 0)
searchStart--; searchStart--;
size_type lineStart = m_source.rfind('\n', searchStart); size_type lineStart = m_source.rfind('\n', searchStart);
if (lineStart == std::string::npos) if (lineStart == string::npos)
lineStart = 0; lineStart = 0;
else else
lineStart++; lineStart++;
return m_source.substr(lineStart, return m_source.substr(lineStart, min(m_source.find('\n', lineStart),
std::min(m_source.find('\n', lineStart), m_source.size()) - 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; using size_type = string::size_type;
size_type searchPosition = std::min<size_type>(m_source.size(), _position); size_type searchPosition = min<size_type>(m_source.size(), _position);
int lineNumber = std::count(m_source.begin(), m_source.begin() + searchPosition, '\n'); int lineNumber = count(m_source.begin(), m_source.begin() + searchPosition, '\n');
size_type lineStart; size_type lineStart;
if (searchPosition == 0) if (searchPosition == 0)
lineStart = 0; lineStart = 0;
else else
{ {
lineStart = m_source.rfind('\n', searchPosition - 1); 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);
} }

View File

@ -24,57 +24,59 @@
#include <libsolidity/Scanner.h> #include <libsolidity/Scanner.h>
#include <libsolidity/Exceptions.h> #include <libsolidity/Exceptions.h>
using namespace std;
namespace dev namespace dev
{ {
namespace solidity namespace solidity
{ {
void SourceReferenceFormatter::printSourceLocation(std::ostream& _stream, void SourceReferenceFormatter::printSourceLocation(ostream& _stream,
Location const& _location, Location const& _location,
Scanner const& _scanner) Scanner const& _scanner)
{ {
int startLine; int startLine;
int startColumn; 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"; _stream << "starting at line " << (startLine + 1) << ", column " << (startColumn + 1) << "\n";
int endLine; int endLine;
int endColumn; int endColumn;
std::tie(endLine, endColumn) = _scanner.translatePositionToLineColumn(_location.end); tie(endLine, endColumn) = _scanner.translatePositionToLineColumn(_location.end);
if (startLine == endLine) if (startLine == endLine)
{ {
_stream << _scanner.getLineAtPosition(_location.start) << std::endl _stream << _scanner.getLineAtPosition(_location.start) << endl
<< std::string(startColumn, ' ') << "^"; << string(startColumn, ' ') << "^";
if (endColumn > startColumn + 2) if (endColumn > startColumn + 2)
_stream << std::string(endColumn - startColumn - 2, '-'); _stream << string(endColumn - startColumn - 2, '-');
if (endColumn > startColumn + 1) if (endColumn > startColumn + 1)
_stream << "^"; _stream << "^";
_stream << std::endl; _stream << endl;
} }
else else
_stream << _scanner.getLineAtPosition(_location.start) << std::endl _stream << _scanner.getLineAtPosition(_location.start) << endl
<< std::string(startColumn, ' ') << "^\n" << string(startColumn, ' ') << "^\n"
<< "Spanning multiple lines.\n"; << "Spanning multiple lines.\n";
} }
void SourceReferenceFormatter::printSourcePosition(std::ostream& _stream, void SourceReferenceFormatter::printSourcePosition(ostream& _stream,
int _position, int _position,
const Scanner& _scanner) const Scanner& _scanner)
{ {
int line; int line;
int column; int column;
std::tie(line, column) = _scanner.translatePositionToLineColumn(_position); tie(line, column) = _scanner.translatePositionToLineColumn(_position);
_stream << "at line " << (line + 1) << ", column " << (column + 1) << std::endl _stream << "at line " << (line + 1) << ", column " << (column + 1) << endl
<< _scanner.getLineAtPosition(_position) << std::endl << _scanner.getLineAtPosition(_position) << endl
<< std::string(column, ' ') << "^" << std::endl; << string(column, ' ') << "^" << endl;
} }
void SourceReferenceFormatter::printExceptionInformation(std::ostream& _stream, void SourceReferenceFormatter::printExceptionInformation(ostream& _stream,
Exception const& _exception, Exception const& _exception,
std::string const& _name, string const& _name,
Scanner const& _scanner) Scanner const& _scanner)
{ {
_stream << _name; _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; _stream << ": " << *description;
if (int const* position = boost::get_error_info<errinfo_sourcePosition>(_exception)) if (int const* position = boost::get_error_info<errinfo_sourcePosition>(_exception))