mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Coding style cleanup: const and vecptr.
This commit is contained in:
parent
646f106a34
commit
f0c334670d
2
AST.cpp
2
AST.cpp
@ -394,7 +394,7 @@ ptr<Type> FunctionCall::checkTypeRequirements()
|
|||||||
FunctionType* function = dynamic_cast<FunctionType*>(expressionType.get());
|
FunctionType* function = dynamic_cast<FunctionType*>(expressionType.get());
|
||||||
BOOST_ASSERT(function != nullptr);
|
BOOST_ASSERT(function != nullptr);
|
||||||
FunctionDefinition const& fun = function->getFunction();
|
FunctionDefinition const& fun = function->getFunction();
|
||||||
vecptr<VariableDeclaration> const& parameters = fun.getParameters();
|
std::vector<ptr<VariableDeclaration>> const& parameters = fun.getParameters();
|
||||||
if (parameters.size() != m_arguments.size())
|
if (parameters.size() != m_arguments.size())
|
||||||
BOOST_THROW_EXCEPTION(TypeError() << errinfo_comment("Wrong argument count for "
|
BOOST_THROW_EXCEPTION(TypeError() << errinfo_comment("Wrong argument count for "
|
||||||
"function call."));
|
"function call."));
|
||||||
|
40
AST.h
40
AST.h
@ -51,7 +51,7 @@ public:
|
|||||||
|
|
||||||
virtual void accept(ASTVisitor& _visitor) = 0;
|
virtual void accept(ASTVisitor& _visitor) = 0;
|
||||||
template <class T>
|
template <class T>
|
||||||
static void listAccept(vecptr<T>& _list, ASTVisitor& _visitor)
|
static void listAccept(std::vector<ptr<T>>& _list, ASTVisitor& _visitor)
|
||||||
{
|
{
|
||||||
for (ptr<T>& element: _list)
|
for (ptr<T>& element: _list)
|
||||||
element->accept(_visitor);
|
element->accept(_visitor);
|
||||||
@ -78,9 +78,9 @@ class ContractDefinition: public Declaration
|
|||||||
public:
|
public:
|
||||||
ContractDefinition(Location const& _location,
|
ContractDefinition(Location const& _location,
|
||||||
ptr<ASTString> const& _name,
|
ptr<ASTString> const& _name,
|
||||||
vecptr<StructDefinition> const& _definedStructs,
|
std::vector<ptr<StructDefinition>> const& _definedStructs,
|
||||||
vecptr<VariableDeclaration> const& _stateVariables,
|
std::vector<ptr<VariableDeclaration>> const& _stateVariables,
|
||||||
vecptr<FunctionDefinition> const& _definedFunctions)
|
std::vector<ptr<FunctionDefinition>> const& _definedFunctions)
|
||||||
: Declaration(_location, _name),
|
: Declaration(_location, _name),
|
||||||
m_definedStructs(_definedStructs),
|
m_definedStructs(_definedStructs),
|
||||||
m_stateVariables(_stateVariables),
|
m_stateVariables(_stateVariables),
|
||||||
@ -89,13 +89,13 @@ public:
|
|||||||
|
|
||||||
virtual void accept(ASTVisitor& _visitor) override;
|
virtual void accept(ASTVisitor& _visitor) override;
|
||||||
|
|
||||||
vecptr<StructDefinition> const& getDefinedStructs() { return m_definedStructs; }
|
std::vector<ptr<StructDefinition>> const& getDefinedStructs() { return m_definedStructs; }
|
||||||
vecptr<VariableDeclaration> const& getStateVariables() { return m_stateVariables; }
|
std::vector<ptr<VariableDeclaration>> const& getStateVariables() { return m_stateVariables; }
|
||||||
vecptr<FunctionDefinition> const& getDefinedFunctions() { return m_definedFunctions; }
|
std::vector<ptr<FunctionDefinition>> const& getDefinedFunctions() { return m_definedFunctions; }
|
||||||
private:
|
private:
|
||||||
vecptr<StructDefinition> m_definedStructs;
|
std::vector<ptr<StructDefinition>> m_definedStructs;
|
||||||
vecptr<VariableDeclaration> m_stateVariables;
|
std::vector<ptr<VariableDeclaration>> m_stateVariables;
|
||||||
vecptr<FunctionDefinition> m_definedFunctions;
|
std::vector<ptr<FunctionDefinition>> m_definedFunctions;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StructDefinition: public Declaration
|
class StructDefinition: public Declaration
|
||||||
@ -103,12 +103,12 @@ class StructDefinition: public Declaration
|
|||||||
public:
|
public:
|
||||||
StructDefinition(Location const& _location,
|
StructDefinition(Location const& _location,
|
||||||
ptr<ASTString> const& _name,
|
ptr<ASTString> const& _name,
|
||||||
vecptr<VariableDeclaration> const& _members)
|
std::vector<ptr<VariableDeclaration>> const& _members)
|
||||||
: Declaration(_location, _name), m_members(_members) {}
|
: Declaration(_location, _name), m_members(_members) {}
|
||||||
virtual void accept(ASTVisitor& _visitor) override;
|
virtual void accept(ASTVisitor& _visitor) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vecptr<VariableDeclaration> m_members;
|
std::vector<ptr<VariableDeclaration>> m_members;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Used as function parameter list and return list
|
/// Used as function parameter list and return list
|
||||||
@ -117,13 +117,13 @@ private:
|
|||||||
class ParameterList: public ASTNode
|
class ParameterList: public ASTNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ParameterList(Location const& _location, vecptr<VariableDeclaration> const& _parameters)
|
ParameterList(Location const& _location, std::vector<ptr<VariableDeclaration>> const& _parameters)
|
||||||
: ASTNode(_location), m_parameters(_parameters) {}
|
: ASTNode(_location), m_parameters(_parameters) {}
|
||||||
virtual void accept(ASTVisitor& _visitor) override;
|
virtual void accept(ASTVisitor& _visitor) override;
|
||||||
|
|
||||||
vecptr<VariableDeclaration> const& getParameters() { return m_parameters; }
|
std::vector<ptr<VariableDeclaration>> const& getParameters() { return m_parameters; }
|
||||||
private:
|
private:
|
||||||
vecptr<VariableDeclaration> m_parameters;
|
std::vector<ptr<VariableDeclaration>> m_parameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FunctionDefinition: public Declaration
|
class FunctionDefinition: public Declaration
|
||||||
@ -141,7 +141,7 @@ public:
|
|||||||
|
|
||||||
bool isPublic() const { return m_isPublic; }
|
bool isPublic() const { return m_isPublic; }
|
||||||
bool isDeclaredConst() const { return m_isDeclaredConst; }
|
bool isDeclaredConst() const { return m_isDeclaredConst; }
|
||||||
vecptr<VariableDeclaration> const& getParameters() const { return m_parameters->getParameters(); }
|
std::vector<ptr<VariableDeclaration>> const& getParameters() const { return m_parameters->getParameters(); }
|
||||||
ParameterList& getParameterList() { return *m_parameters; }
|
ParameterList& getParameterList() { return *m_parameters; }
|
||||||
ptr<ParameterList> const& getReturnParameterList() const { return m_returnParameters; }
|
ptr<ParameterList> const& getReturnParameterList() const { return m_returnParameters; }
|
||||||
Block& getBody() { return *m_body; }
|
Block& getBody() { return *m_body; }
|
||||||
@ -254,13 +254,13 @@ protected:
|
|||||||
class Block: public Statement
|
class Block: public Statement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Block(Location const& _location, vecptr<Statement> const& _statements)
|
Block(Location const& _location, std::vector<ptr<Statement>> const& _statements)
|
||||||
: Statement(_location), m_statements(_statements) {}
|
: Statement(_location), m_statements(_statements) {}
|
||||||
virtual void accept(ASTVisitor& _visitor) override;
|
virtual void accept(ASTVisitor& _visitor) override;
|
||||||
|
|
||||||
virtual ptr<Type> checkTypeRequirements() override;
|
virtual ptr<Type> checkTypeRequirements() override;
|
||||||
private:
|
private:
|
||||||
vecptr<Statement> m_statements;
|
std::vector<ptr<Statement>> m_statements;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IfStatement: public Statement
|
class IfStatement: public Statement
|
||||||
@ -415,13 +415,13 @@ class FunctionCall: public Expression
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FunctionCall(Location const& _location, ptr<Expression> const& _expression,
|
FunctionCall(Location const& _location, ptr<Expression> const& _expression,
|
||||||
vecptr<Expression> const& _arguments)
|
std::vector<ptr<Expression>> const& _arguments)
|
||||||
: Expression(_location), m_expression(_expression), m_arguments(_arguments) {}
|
: Expression(_location), m_expression(_expression), m_arguments(_arguments) {}
|
||||||
virtual void accept(ASTVisitor& _visitor) override;
|
virtual void accept(ASTVisitor& _visitor) override;
|
||||||
virtual ptr<Type> checkTypeRequirements() override;
|
virtual ptr<Type> checkTypeRequirements() override;
|
||||||
private:
|
private:
|
||||||
ptr<Expression> m_expression;
|
ptr<Expression> m_expression;
|
||||||
vecptr<Expression> m_arguments;
|
std::vector<ptr<Expression>> m_arguments;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MemberAccess: public Expression
|
class MemberAccess: public Expression
|
||||||
|
@ -70,8 +70,6 @@ class Literal;
|
|||||||
// explicitly.
|
// explicitly.
|
||||||
template <class T>
|
template <class T>
|
||||||
using ptr = std::shared_ptr<T>;
|
using ptr = std::shared_ptr<T>;
|
||||||
template <class T>
|
|
||||||
using vecptr = std::vector<ptr<T>>;
|
|
||||||
|
|
||||||
using ASTString = std::string;
|
using ASTString = std::string;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ namespace dev
|
|||||||
namespace solidity
|
namespace solidity
|
||||||
{
|
{
|
||||||
|
|
||||||
ASTPrinter::ASTPrinter(ptr<ASTNode> _ast, const std::string& _source)
|
ASTPrinter::ASTPrinter(ptr<ASTNode> _ast, std::string const& _source)
|
||||||
: m_indentation(0), m_source(_source), m_ast(_ast)
|
: m_indentation(0), m_source(_source), m_ast(_ast)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -242,7 +242,7 @@ bool ASTPrinter::visit(ElementaryTypeNameExpression& _node)
|
|||||||
|
|
||||||
bool ASTPrinter::visit(Literal& _node)
|
bool ASTPrinter::visit(Literal& _node)
|
||||||
{
|
{
|
||||||
const char* tokenString = Token::toString(_node.getToken());
|
char const* tokenString = Token::toString(_node.getToken());
|
||||||
if (tokenString == nullptr)
|
if (tokenString == nullptr)
|
||||||
tokenString = "[no token]";
|
tokenString = "[no token]";
|
||||||
writeLine(std::string("Literal, token: ") + tokenString + " value: " + _node.getValue());
|
writeLine(std::string("Literal, token: ") + tokenString + " value: " + _node.getValue());
|
||||||
@ -415,7 +415,7 @@ std::string ASTPrinter::getIndentation() const
|
|||||||
return std::string(m_indentation * 2, ' ');
|
return std::string(m_indentation * 2, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASTPrinter::writeLine(const std::string& _line)
|
void ASTPrinter::writeLine(std::string const& _line)
|
||||||
{
|
{
|
||||||
*m_ostream << getIndentation() << _line << '\n';
|
*m_ostream << getIndentation() << _line << '\n';
|
||||||
}
|
}
|
||||||
|
30
Parser.cpp
30
Parser.cpp
@ -43,12 +43,12 @@ ptr<ContractDefinition> Parser::parse(std::shared_ptr<Scanner> const& _scanner)
|
|||||||
class Parser::ASTNodeFactory
|
class Parser::ASTNodeFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ASTNodeFactory(const Parser& _parser) : m_parser(_parser), m_location(_parser.getPosition(), -1) {}
|
ASTNodeFactory(Parser const& _parser) : m_parser(_parser), m_location(_parser.getPosition(), -1) {}
|
||||||
|
|
||||||
void markEndPosition() { m_location.end = m_parser.getEndPosition(); }
|
void markEndPosition() { m_location.end = m_parser.getEndPosition(); }
|
||||||
void setLocationEmpty() { m_location.end = m_location.start; }
|
void setLocationEmpty() { m_location.end = m_location.start; }
|
||||||
/// Set the end position to the one of the given node.
|
/// Set the end position to the one of the given node.
|
||||||
void setEndPositionFromNode(const ptr<ASTNode>& _node) { m_location.end = _node->getLocation().end; }
|
void setEndPositionFromNode(ptr<ASTNode> const& _node) { m_location.end = _node->getLocation().end; }
|
||||||
|
|
||||||
template <class NodeType, typename... Args>
|
template <class NodeType, typename... Args>
|
||||||
ptr<NodeType> createNode(Args&& ... _args)
|
ptr<NodeType> createNode(Args&& ... _args)
|
||||||
@ -59,7 +59,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Parser& m_parser;
|
Parser const& m_parser;
|
||||||
Location m_location;
|
Location m_location;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,9 +80,9 @@ ptr<ContractDefinition> Parser::parseContractDefinition()
|
|||||||
expectToken(Token::CONTRACT);
|
expectToken(Token::CONTRACT);
|
||||||
ptr<ASTString> name = expectIdentifierToken();
|
ptr<ASTString> name = expectIdentifierToken();
|
||||||
expectToken(Token::LBRACE);
|
expectToken(Token::LBRACE);
|
||||||
vecptr<StructDefinition> structs;
|
std::vector<ptr<StructDefinition>> structs;
|
||||||
vecptr<VariableDeclaration> stateVariables;
|
std::vector<ptr<VariableDeclaration>> stateVariables;
|
||||||
vecptr<FunctionDefinition> functions;
|
std::vector<ptr<FunctionDefinition>> functions;
|
||||||
bool visibilityIsPublic = true;
|
bool visibilityIsPublic = true;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -130,7 +130,7 @@ ptr<FunctionDefinition> Parser::parseFunctionDefinition(bool _isPublic)
|
|||||||
ptr<ParameterList> returnParameters;
|
ptr<ParameterList> returnParameters;
|
||||||
if (m_scanner->getCurrentToken() == Token::RETURNS)
|
if (m_scanner->getCurrentToken() == Token::RETURNS)
|
||||||
{
|
{
|
||||||
const bool permitEmptyParameterList = false;
|
bool const permitEmptyParameterList = false;
|
||||||
m_scanner->next();
|
m_scanner->next();
|
||||||
returnParameters = parseParameterList(permitEmptyParameterList);
|
returnParameters = parseParameterList(permitEmptyParameterList);
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ ptr<FunctionDefinition> Parser::parseFunctionDefinition(bool _isPublic)
|
|||||||
// create an empty parameter list at a zero-length location
|
// create an empty parameter list at a zero-length location
|
||||||
ASTNodeFactory nodeFactory(*this);
|
ASTNodeFactory nodeFactory(*this);
|
||||||
nodeFactory.setLocationEmpty();
|
nodeFactory.setLocationEmpty();
|
||||||
returnParameters = nodeFactory.createNode<ParameterList>(vecptr<VariableDeclaration>());
|
returnParameters = nodeFactory.createNode<ParameterList>(std::vector<ptr<VariableDeclaration>>());
|
||||||
}
|
}
|
||||||
ptr<Block> block = parseBlock();
|
ptr<Block> block = parseBlock();
|
||||||
nodeFactory.setEndPositionFromNode(block);
|
nodeFactory.setEndPositionFromNode(block);
|
||||||
@ -152,7 +152,7 @@ ptr<StructDefinition> Parser::parseStructDefinition()
|
|||||||
ASTNodeFactory nodeFactory(*this);
|
ASTNodeFactory nodeFactory(*this);
|
||||||
expectToken(Token::STRUCT);
|
expectToken(Token::STRUCT);
|
||||||
ptr<ASTString> name = expectIdentifierToken();
|
ptr<ASTString> name = expectIdentifierToken();
|
||||||
vecptr<VariableDeclaration> members;
|
std::vector<ptr<VariableDeclaration>> members;
|
||||||
expectToken(Token::LBRACE);
|
expectToken(Token::LBRACE);
|
||||||
while (m_scanner->getCurrentToken() != Token::RBRACE)
|
while (m_scanner->getCurrentToken() != Token::RBRACE)
|
||||||
{
|
{
|
||||||
@ -224,7 +224,7 @@ ptr<Mapping> Parser::parseMapping()
|
|||||||
ptr<ParameterList> Parser::parseParameterList(bool _allowEmpty)
|
ptr<ParameterList> Parser::parseParameterList(bool _allowEmpty)
|
||||||
{
|
{
|
||||||
ASTNodeFactory nodeFactory(*this);
|
ASTNodeFactory nodeFactory(*this);
|
||||||
vecptr<VariableDeclaration> parameters;
|
std::vector<ptr<VariableDeclaration>> parameters;
|
||||||
expectToken(Token::LPAREN);
|
expectToken(Token::LPAREN);
|
||||||
if (!_allowEmpty || m_scanner->getCurrentToken() != Token::RPAREN)
|
if (!_allowEmpty || m_scanner->getCurrentToken() != Token::RPAREN)
|
||||||
{
|
{
|
||||||
@ -245,7 +245,7 @@ ptr<Block> Parser::parseBlock()
|
|||||||
{
|
{
|
||||||
ASTNodeFactory nodeFactory(*this);
|
ASTNodeFactory nodeFactory(*this);
|
||||||
expectToken(Token::LBRACE);
|
expectToken(Token::LBRACE);
|
||||||
vecptr<Statement> statements;
|
std::vector<ptr<Statement>> statements;
|
||||||
while (m_scanner->getCurrentToken() != Token::RBRACE)
|
while (m_scanner->getCurrentToken() != Token::RBRACE)
|
||||||
statements.push_back(parseStatement());
|
statements.push_back(parseStatement());
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
@ -433,7 +433,7 @@ ptr<Expression> Parser::parseLeftHandSideExpression()
|
|||||||
case Token::LPAREN:
|
case Token::LPAREN:
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
m_scanner->next();
|
||||||
vecptr<Expression> arguments = parseFunctionCallArguments();
|
std::vector<ptr<Expression>> arguments = parseFunctionCallArguments();
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
expectToken(Token::RPAREN);
|
expectToken(Token::RPAREN);
|
||||||
expression = nodeFactory.createNode<FunctionCall>(expression, arguments);
|
expression = nodeFactory.createNode<FunctionCall>(expression, arguments);
|
||||||
@ -490,9 +490,9 @@ ptr<Expression> Parser::parsePrimaryExpression()
|
|||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
vecptr<Expression> Parser::parseFunctionCallArguments()
|
std::vector<ptr<Expression>> Parser::parseFunctionCallArguments()
|
||||||
{
|
{
|
||||||
vecptr<Expression> arguments;
|
std::vector<ptr<Expression>> arguments;
|
||||||
if (m_scanner->getCurrentToken() != Token::RPAREN)
|
if (m_scanner->getCurrentToken() != Token::RPAREN)
|
||||||
{
|
{
|
||||||
arguments.push_back(parseExpression());
|
arguments.push_back(parseExpression());
|
||||||
@ -535,7 +535,7 @@ ptr<ASTString> Parser::getLiteralAndAdvance()
|
|||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::throwExpectationError(const std::string& _description)
|
void Parser::throwExpectationError(std::string const& _description)
|
||||||
{
|
{
|
||||||
//@todo put some of this stuff into ParserError
|
//@todo put some of this stuff into ParserError
|
||||||
int line, column;
|
int line, column;
|
||||||
|
4
Parser.h
4
Parser.h
@ -63,7 +63,7 @@ private:
|
|||||||
ptr<Expression> parseUnaryExpression();
|
ptr<Expression> parseUnaryExpression();
|
||||||
ptr<Expression> parseLeftHandSideExpression();
|
ptr<Expression> parseLeftHandSideExpression();
|
||||||
ptr<Expression> parsePrimaryExpression();
|
ptr<Expression> parsePrimaryExpression();
|
||||||
vecptr<Expression> parseFunctionCallArguments();
|
std::vector<ptr<Expression>> parseFunctionCallArguments();
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
/// Helper functions
|
/// Helper functions
|
||||||
@ -73,7 +73,7 @@ private:
|
|||||||
Token::Value expectAssignmentOperator();
|
Token::Value expectAssignmentOperator();
|
||||||
ptr<ASTString> expectIdentifierToken();
|
ptr<ASTString> expectIdentifierToken();
|
||||||
ptr<ASTString> getLiteralAndAdvance();
|
ptr<ASTString> getLiteralAndAdvance();
|
||||||
void throwExpectationError(const std::string& _description);
|
void throwExpectationError(std::string const& _description);
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
std::shared_ptr<Scanner> m_scanner;
|
std::shared_ptr<Scanner> m_scanner;
|
||||||
|
16
Scanner.cpp
16
Scanner.cpp
@ -88,12 +88,12 @@ int HexValue(char c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Scanner::Scanner(const CharStream& _source)
|
Scanner::Scanner(CharStream const& _source)
|
||||||
{
|
{
|
||||||
reset(_source);
|
reset(_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scanner::reset(const CharStream& _source)
|
void Scanner::reset(CharStream const& _source)
|
||||||
{
|
{
|
||||||
m_source = _source;
|
m_source = _source;
|
||||||
m_char = m_source.get();
|
m_char = m_source.get();
|
||||||
@ -145,7 +145,7 @@ Token::Value Scanner::selectToken(char _next, Token::Value _then, Token::Value _
|
|||||||
|
|
||||||
bool Scanner::skipWhitespace()
|
bool Scanner::skipWhitespace()
|
||||||
{
|
{
|
||||||
const int start_position = getSourcePos();
|
int const start_position = getSourcePos();
|
||||||
while (IsWhiteSpace(m_char))
|
while (IsWhiteSpace(m_char))
|
||||||
advance();
|
advance();
|
||||||
// Return whether or not we skipped any characters.
|
// Return whether or not we skipped any characters.
|
||||||
@ -425,7 +425,7 @@ bool Scanner::scanEscape()
|
|||||||
|
|
||||||
Token::Value Scanner::scanString()
|
Token::Value Scanner::scanString()
|
||||||
{
|
{
|
||||||
const char quote = m_char;
|
char const quote = m_char;
|
||||||
advance(); // consume quote
|
advance(); // consume quote
|
||||||
LiteralScope literal(this);
|
LiteralScope literal(this);
|
||||||
while (m_char != quote && !isSourcePastEndOfInput() && !IsLineTerminator(m_char))
|
while (m_char != quote && !isSourcePastEndOfInput() && !IsLineTerminator(m_char))
|
||||||
@ -592,11 +592,11 @@ Token::Value Scanner::scanNumber(bool _periodSeen)
|
|||||||
KEYWORD("while", Token::WHILE) \
|
KEYWORD("while", Token::WHILE) \
|
||||||
|
|
||||||
|
|
||||||
static Token::Value KeywordOrIdentifierToken(const std::string& input)
|
static Token::Value KeywordOrIdentifierToken(std::string const& input)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(!input.empty());
|
BOOST_ASSERT(!input.empty());
|
||||||
const int kMinLength = 2;
|
int const kMinLength = 2;
|
||||||
const int kMaxLength = 10;
|
int const kMaxLength = 10;
|
||||||
if (input.size() < kMinLength || input.size() > kMaxLength)
|
if (input.size() < kMinLength || input.size() > kMaxLength)
|
||||||
return Token::IDENTIFIER;
|
return Token::IDENTIFIER;
|
||||||
switch (input[0])
|
switch (input[0])
|
||||||
@ -609,7 +609,7 @@ case ch:
|
|||||||
{ \
|
{ \
|
||||||
/* 'keyword' is a char array, so sizeof(keyword) is */ \
|
/* 'keyword' is a char array, so sizeof(keyword) is */ \
|
||||||
/* strlen(keyword) plus 1 for the NUL char. */ \
|
/* strlen(keyword) plus 1 for the NUL char. */ \
|
||||||
const int keyword_length = sizeof(keyword) - 1; \
|
int const keyword_length = sizeof(keyword) - 1; \
|
||||||
BOOST_STATIC_ASSERT(keyword_length >= kMinLength); \
|
BOOST_STATIC_ASSERT(keyword_length >= kMinLength); \
|
||||||
BOOST_STATIC_ASSERT(keyword_length <= kMaxLength); \
|
BOOST_STATIC_ASSERT(keyword_length <= kMaxLength); \
|
||||||
if (input == keyword) { \
|
if (input == keyword) { \
|
||||||
|
@ -64,7 +64,7 @@ class CharStream
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CharStream() : m_pos(0) {}
|
CharStream() : m_pos(0) {}
|
||||||
explicit CharStream(const std::string& _source): m_source(_source), m_pos(0) {}
|
explicit CharStream(std::string const& _source): m_source(_source), m_pos(0) {}
|
||||||
int getPos() const { return m_pos; }
|
int getPos() const { return m_pos; }
|
||||||
bool isPastEndOfInput() const { return m_pos >= m_source.size(); }
|
bool isPastEndOfInput() const { return m_pos >= m_source.size(); }
|
||||||
char get() const { return m_source[m_pos]; }
|
char get() const { return m_source[m_pos]; }
|
||||||
@ -100,10 +100,10 @@ public:
|
|||||||
bool complete_;
|
bool complete_;
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit Scanner(const CharStream& _source);
|
explicit Scanner(CharStream const& _source);
|
||||||
|
|
||||||
/// Resets the scanner as if newly constructed with _input as input.
|
/// Resets the scanner as if newly constructed with _input as input.
|
||||||
void reset(const CharStream& _source);
|
void reset(CharStream const& _source);
|
||||||
|
|
||||||
/// Returns the next token and advances input.
|
/// Returns the next token and advances input.
|
||||||
Token::Value next();
|
Token::Value next();
|
||||||
|
@ -48,7 +48,7 @@ namespace solidity
|
|||||||
{
|
{
|
||||||
|
|
||||||
#define T(name, string, precedence) #name,
|
#define T(name, string, precedence) #name,
|
||||||
const char* const Token::m_name[NUM_TOKENS] =
|
char const* const Token::m_name[NUM_TOKENS] =
|
||||||
{
|
{
|
||||||
TOKEN_LIST(T, T)
|
TOKEN_LIST(T, T)
|
||||||
};
|
};
|
||||||
@ -56,7 +56,7 @@ const char* const Token::m_name[NUM_TOKENS] =
|
|||||||
|
|
||||||
|
|
||||||
#define T(name, string, precedence) string,
|
#define T(name, string, precedence) string,
|
||||||
const char* const Token::m_string[NUM_TOKENS] =
|
char const* const Token::m_string[NUM_TOKENS] =
|
||||||
{
|
{
|
||||||
TOKEN_LIST(T, T)
|
TOKEN_LIST(T, T)
|
||||||
};
|
};
|
||||||
@ -64,7 +64,7 @@ const char* const Token::m_string[NUM_TOKENS] =
|
|||||||
|
|
||||||
|
|
||||||
#define T(name, string, precedence) precedence,
|
#define T(name, string, precedence) precedence,
|
||||||
const int8_t Token::m_precedence[NUM_TOKENS] =
|
int8_t const Token::m_precedence[NUM_TOKENS] =
|
||||||
{
|
{
|
||||||
TOKEN_LIST(T, T)
|
TOKEN_LIST(T, T)
|
||||||
};
|
};
|
||||||
@ -73,7 +73,7 @@ const int8_t Token::m_precedence[NUM_TOKENS] =
|
|||||||
|
|
||||||
#define KT(a, b, c) 'T',
|
#define KT(a, b, c) 'T',
|
||||||
#define KK(a, b, c) 'K',
|
#define KK(a, b, c) 'K',
|
||||||
const char Token::m_tokenType[] =
|
char const Token::m_tokenType[] =
|
||||||
{
|
{
|
||||||
TOKEN_LIST(KT, KK)
|
TOKEN_LIST(KT, KK)
|
||||||
};
|
};
|
||||||
|
12
Token.h
12
Token.h
@ -223,7 +223,7 @@ public:
|
|||||||
|
|
||||||
// Returns a string corresponding to the C++ token name
|
// Returns a string corresponding to the C++ token name
|
||||||
// (e.g. "LT" for the token LT).
|
// (e.g. "LT" for the token LT).
|
||||||
static const char* getName(Value tok)
|
static char const* getName(Value tok)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(tok < NUM_TOKENS); // tok is unsigned
|
BOOST_ASSERT(tok < NUM_TOKENS); // tok is unsigned
|
||||||
return m_name[tok];
|
return m_name[tok];
|
||||||
@ -309,7 +309,7 @@ public:
|
|||||||
// Returns a string corresponding to the JS token string
|
// Returns a string corresponding to the JS token string
|
||||||
// (.e., "<" for the token LT) or NULL if the token doesn't
|
// (.e., "<" for the token LT) or NULL if the token doesn't
|
||||||
// have a (unique) string (e.g. an IDENTIFIER).
|
// have a (unique) string (e.g. an IDENTIFIER).
|
||||||
static const char* toString(Value tok)
|
static char const* toString(Value tok)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(tok < NUM_TOKENS); // tok is unsigned.
|
BOOST_ASSERT(tok < NUM_TOKENS); // tok is unsigned.
|
||||||
return m_string[tok];
|
return m_string[tok];
|
||||||
@ -324,10 +324,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char* const m_name[NUM_TOKENS];
|
static char const* const m_name[NUM_TOKENS];
|
||||||
static const char* const m_string[NUM_TOKENS];
|
static char const* const m_string[NUM_TOKENS];
|
||||||
static const int8_t m_precedence[NUM_TOKENS];
|
static int8_t const m_precedence[NUM_TOKENS];
|
||||||
static const char m_tokenType[NUM_TOKENS];
|
static char const m_tokenType[NUM_TOKENS];
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
14
Types.cpp
14
Types.cpp
@ -52,18 +52,18 @@ ptr<Type> Type::fromElementaryTypeName(Token::Value _typeToken)
|
|||||||
BOOST_ASSERT(false); // @todo add other tyes
|
BOOST_ASSERT(false); // @todo add other tyes
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr<Type> Type::fromUserDefinedTypeName(const UserDefinedTypeName& _typeName)
|
ptr<Type> Type::fromUserDefinedTypeName(UserDefinedTypeName const& _typeName)
|
||||||
{
|
{
|
||||||
return std::make_shared<StructType>(*_typeName.getReferencedStruct());
|
return std::make_shared<StructType>(*_typeName.getReferencedStruct());
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr<Type> Type::fromMapping(const Mapping&)
|
ptr<Type> Type::fromMapping(Mapping const&)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(false); //@todo not yet implemented
|
BOOST_ASSERT(false); //@todo not yet implemented
|
||||||
return ptr<Type>();
|
return ptr<Type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr<Type> Type::forLiteral(const Literal& _literal)
|
ptr<Type> Type::forLiteral(Literal const& _literal)
|
||||||
{
|
{
|
||||||
switch (_literal.getToken())
|
switch (_literal.getToken())
|
||||||
{
|
{
|
||||||
@ -110,7 +110,7 @@ bool IntegerType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
|||||||
return !convertTo.isSigned() || convertTo.m_bits > m_bits;
|
return !convertTo.isSigned() || convertTo.m_bits > m_bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IntegerType::isExplicitlyConvertibleTo(const Type& _convertTo) const
|
bool IntegerType::isExplicitlyConvertibleTo(Type const& _convertTo) const
|
||||||
{
|
{
|
||||||
return _convertTo.getCategory() == Category::INTEGER;
|
return _convertTo.getCategory() == Category::INTEGER;
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ bool IntegerType::acceptsUnaryOperator(Token::Value _operator) const
|
|||||||
return _operator == Token::DELETE || (!isAddress() && _operator == Token::BIT_NOT);
|
return _operator == Token::DELETE || (!isAddress() && _operator == Token::BIT_NOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BoolType::isExplicitlyConvertibleTo(const Type& _convertTo) const
|
bool BoolType::isExplicitlyConvertibleTo(Type const& _convertTo) const
|
||||||
{
|
{
|
||||||
// conversion to integer is fine, but not to address
|
// conversion to integer is fine, but not to address
|
||||||
// this is an example of explicit conversions being not transitive (though implicit should be)
|
// this is an example of explicit conversions being not transitive (though implicit should be)
|
||||||
@ -143,7 +143,7 @@ bool BoolType::isExplicitlyConvertibleTo(const Type& _convertTo) const
|
|||||||
return isImplicitlyConvertibleTo(_convertTo);
|
return isImplicitlyConvertibleTo(_convertTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContractType::isImplicitlyConvertibleTo(const Type& _convertTo) const
|
bool ContractType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
||||||
{
|
{
|
||||||
if (_convertTo.getCategory() != Category::CONTRACT)
|
if (_convertTo.getCategory() != Category::CONTRACT)
|
||||||
return false;
|
return false;
|
||||||
@ -151,7 +151,7 @@ bool ContractType::isImplicitlyConvertibleTo(const Type& _convertTo) const
|
|||||||
return &m_contract == &convertTo.m_contract;
|
return &m_contract == &convertTo.m_contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StructType::isImplicitlyConvertibleTo(const Type& _convertTo) const
|
bool StructType::isImplicitlyConvertibleTo(Type const& _convertTo) const
|
||||||
{
|
{
|
||||||
if (_convertTo.getCategory() != Category::STRUCT)
|
if (_convertTo.getCategory() != Category::STRUCT)
|
||||||
return false;
|
return false;
|
||||||
|
10
Types.h
10
Types.h
@ -64,8 +64,8 @@ public:
|
|||||||
static ptr<Type> forLiteral(Literal const& _literal);
|
static ptr<Type> forLiteral(Literal const& _literal);
|
||||||
|
|
||||||
virtual Category getCategory() const = 0;
|
virtual Category getCategory() const = 0;
|
||||||
virtual bool isImplicitlyConvertibleTo(const Type&) const { return false; }
|
virtual bool isImplicitlyConvertibleTo(Type const&) const { return false; }
|
||||||
virtual bool isExplicitlyConvertibleTo(const Type& _convertTo) const
|
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const
|
||||||
{
|
{
|
||||||
return isImplicitlyConvertibleTo(_convertTo);
|
return isImplicitlyConvertibleTo(_convertTo);
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ public:
|
|||||||
explicit IntegerType(int _bits, Modifier _modifier = Modifier::UNSIGNED);
|
explicit IntegerType(int _bits, Modifier _modifier = Modifier::UNSIGNED);
|
||||||
|
|
||||||
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;
|
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;
|
||||||
virtual bool isExplicitlyConvertibleTo(const Type& _convertTo) const override;
|
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
|
||||||
virtual bool acceptsBinaryOperator(Token::Value _operator) const override;
|
virtual bool acceptsBinaryOperator(Token::Value _operator) const override;
|
||||||
virtual bool acceptsUnaryOperator(Token::Value _operator) const override;
|
virtual bool acceptsUnaryOperator(Token::Value _operator) const override;
|
||||||
|
|
||||||
@ -104,11 +104,11 @@ class BoolType: public Type
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual Category getCategory() const { return Category::BOOL; }
|
virtual Category getCategory() const { return Category::BOOL; }
|
||||||
virtual bool isImplicitlyConvertibleTo(const Type& _convertTo) const override
|
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override
|
||||||
{
|
{
|
||||||
return _convertTo.getCategory() == Category::BOOL;
|
return _convertTo.getCategory() == Category::BOOL;
|
||||||
}
|
}
|
||||||
virtual bool isExplicitlyConvertibleTo(const Type& _convertTo) const override;
|
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
|
||||||
virtual bool acceptsBinaryOperator(Token::Value _operator) const override
|
virtual bool acceptsBinaryOperator(Token::Value _operator) const override
|
||||||
{
|
{
|
||||||
return _operator == Token::AND || _operator == Token::OR;
|
return _operator == Token::AND || _operator == Token::OR;
|
||||||
|
Loading…
Reference in New Issue
Block a user