mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
- added isPartOfExternalInterface to Declaration
- changed position for the constant specifier. now it goes after type: <type> <constant> <name> = <value> - removed tests for constant functions, checkings for constant function doesn't belong to this story
This commit is contained in:
parent
67cd3a7180
commit
7d6357ae53
4
AST.cpp
4
AST.cpp
@ -189,7 +189,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
|
|||||||
for (ContractDefinition const* contract: getLinearizedBaseContracts())
|
for (ContractDefinition const* contract: getLinearizedBaseContracts())
|
||||||
{
|
{
|
||||||
for (ASTPointer<FunctionDefinition> const& f: contract->getDefinedFunctions())
|
for (ASTPointer<FunctionDefinition> const& f: contract->getDefinedFunctions())
|
||||||
if (f->isPublic() && !f->isConstructor() && !f->getName().empty() && functionsSeen.count(f->getName()) == 0)
|
if (functionsSeen.count(f->getName()) == 0 && f->isPartOfExternalInterface())
|
||||||
{
|
{
|
||||||
functionsSeen.insert(f->getName());
|
functionsSeen.insert(f->getName());
|
||||||
FixedHash<4> hash(dev::sha3(f->getCanonicalSignature()));
|
FixedHash<4> hash(dev::sha3(f->getCanonicalSignature()));
|
||||||
@ -197,7 +197,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (ASTPointer<VariableDeclaration> const& v: contract->getStateVariables())
|
for (ASTPointer<VariableDeclaration> const& v: contract->getStateVariables())
|
||||||
if (v->isPublic() && functionsSeen.count(v->getName()) == 0 && !v->isConstant())
|
if (functionsSeen.count(v->getName()) == 0 && v->isPartOfExternalInterface())
|
||||||
{
|
{
|
||||||
FunctionType ftype(*v);
|
FunctionType ftype(*v);
|
||||||
functionsSeen.insert(v->getName());
|
functionsSeen.insert(v->getName());
|
||||||
|
4
AST.h
4
AST.h
@ -156,6 +156,7 @@ public:
|
|||||||
/// contract types.
|
/// contract types.
|
||||||
virtual TypePointer getType(ContractDefinition const* m_currentContract = nullptr) const = 0;
|
virtual TypePointer getType(ContractDefinition const* m_currentContract = nullptr) const = 0;
|
||||||
virtual bool isLValue() const { return false; }
|
virtual bool isLValue() const { return false; }
|
||||||
|
virtual bool isPartOfExternalInterface() const { return false; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual Visibility getDefaultVisibility() const { return Visibility::Public; }
|
virtual Visibility getDefaultVisibility() const { return Visibility::Public; }
|
||||||
@ -415,6 +416,7 @@ public:
|
|||||||
getVisibility() >= Visibility::Internal;
|
getVisibility() >= Visibility::Internal;
|
||||||
}
|
}
|
||||||
virtual TypePointer getType(ContractDefinition const*) const override;
|
virtual TypePointer getType(ContractDefinition const*) const override;
|
||||||
|
virtual bool isPartOfExternalInterface() const override { return isPublic() && !m_isConstructor && !getName().empty(); }
|
||||||
|
|
||||||
/// Checks that all parameters have allowed types and calls checkTypeRequirements on the body.
|
/// Checks that all parameters have allowed types and calls checkTypeRequirements on the body.
|
||||||
void checkTypeRequirements();
|
void checkTypeRequirements();
|
||||||
@ -468,6 +470,8 @@ public:
|
|||||||
void setType(std::shared_ptr<Type const> const& _type) { m_type = _type; }
|
void setType(std::shared_ptr<Type const> const& _type) { m_type = _type; }
|
||||||
|
|
||||||
virtual bool isLValue() const override;
|
virtual bool isLValue() const override;
|
||||||
|
virtual bool isPartOfExternalInterface() const override { return isPublic() && !m_isConstant; }
|
||||||
|
|
||||||
|
|
||||||
void checkTypeRequirements();
|
void checkTypeRequirements();
|
||||||
bool isLocalVariable() const { return !!dynamic_cast<FunctionDefinition const*>(getScope()); }
|
bool isLocalVariable() const { return !!dynamic_cast<FunctionDefinition const*>(getScope()); }
|
||||||
|
@ -859,6 +859,8 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier)
|
|||||||
{
|
{
|
||||||
if (!variable->isConstant())
|
if (!variable->isConstant())
|
||||||
setLValueFromDeclaration(*declaration, _identifier);
|
setLValueFromDeclaration(*declaration, _identifier);
|
||||||
|
else
|
||||||
|
variable->getValue()->accept(*this);
|
||||||
}
|
}
|
||||||
else if (dynamic_cast<ContractDefinition const*>(declaration))
|
else if (dynamic_cast<ContractDefinition const*>(declaration))
|
||||||
{
|
{
|
||||||
|
18
Parser.cpp
18
Parser.cpp
@ -135,7 +135,6 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition()
|
|||||||
}
|
}
|
||||||
while (m_scanner->getCurrentToken() == Token::Comma);
|
while (m_scanner->getCurrentToken() == Token::Comma);
|
||||||
expectToken(Token::LBrace);
|
expectToken(Token::LBrace);
|
||||||
bool isDeclaredConst = false;
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Token::Value currentToken = m_scanner->getCurrentToken();
|
Token::Value currentToken = m_scanner->getCurrentToken();
|
||||||
@ -153,21 +152,13 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition()
|
|||||||
VarDeclParserOptions options;
|
VarDeclParserOptions options;
|
||||||
options.isStateVariable = true;
|
options.isStateVariable = true;
|
||||||
options.allowInitialValue = true;
|
options.allowInitialValue = true;
|
||||||
options.isDeclaredConst = isDeclaredConst;
|
|
||||||
stateVariables.push_back(parseVariableDeclaration(options));
|
stateVariables.push_back(parseVariableDeclaration(options));
|
||||||
isDeclaredConst = false;
|
|
||||||
expectToken(Token::Semicolon);
|
expectToken(Token::Semicolon);
|
||||||
}
|
}
|
||||||
else if (currentToken == Token::Modifier)
|
else if (currentToken == Token::Modifier)
|
||||||
modifiers.push_back(parseModifierDefinition());
|
modifiers.push_back(parseModifierDefinition());
|
||||||
else if (currentToken == Token::Event)
|
else if (currentToken == Token::Event)
|
||||||
events.push_back(parseEventDefinition());
|
events.push_back(parseEventDefinition());
|
||||||
else if (currentToken == Token::Const)
|
|
||||||
{
|
|
||||||
solAssert(Token::isElementaryTypeName(m_scanner->peekNextToken()), "");
|
|
||||||
isDeclaredConst = true;
|
|
||||||
m_scanner->next();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(createParserError("Function, variable, struct or modifier declaration expected."));
|
BOOST_THROW_EXCEPTION(createParserError("Function, variable, struct or modifier declaration expected."));
|
||||||
}
|
}
|
||||||
@ -326,6 +317,7 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(
|
|||||||
nodeFactory.setEndPositionFromNode(type);
|
nodeFactory.setEndPositionFromNode(type);
|
||||||
}
|
}
|
||||||
bool isIndexed = false;
|
bool isIndexed = false;
|
||||||
|
bool isDeclaredConst = false;
|
||||||
ASTPointer<ASTString> identifier;
|
ASTPointer<ASTString> identifier;
|
||||||
Token::Value token = m_scanner->getCurrentToken();
|
Token::Value token = m_scanner->getCurrentToken();
|
||||||
Declaration::Visibility visibility(Declaration::Visibility::Default);
|
Declaration::Visibility visibility(Declaration::Visibility::Default);
|
||||||
@ -336,7 +328,13 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(
|
|||||||
isIndexed = true;
|
isIndexed = true;
|
||||||
m_scanner->next();
|
m_scanner->next();
|
||||||
}
|
}
|
||||||
|
if (token == Token::Const)
|
||||||
|
{
|
||||||
|
m_scanner->next();
|
||||||
|
isDeclaredConst = true;
|
||||||
|
}
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
|
|
||||||
if (_options.allowEmptyName && m_scanner->getCurrentToken() != Token::Identifier)
|
if (_options.allowEmptyName && m_scanner->getCurrentToken() != Token::Identifier)
|
||||||
{
|
{
|
||||||
identifier = make_shared<ASTString>("");
|
identifier = make_shared<ASTString>("");
|
||||||
@ -357,7 +355,7 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(
|
|||||||
}
|
}
|
||||||
return nodeFactory.createNode<VariableDeclaration>(type, identifier, value,
|
return nodeFactory.createNode<VariableDeclaration>(type, identifier, value,
|
||||||
visibility, _options.isStateVariable,
|
visibility, _options.isStateVariable,
|
||||||
isIndexed, _options.isDeclaredConst);
|
isIndexed, isDeclaredConst);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<ModifierDefinition> Parser::parseModifierDefinition()
|
ASTPointer<ModifierDefinition> Parser::parseModifierDefinition()
|
||||||
|
4
Parser.h
4
Parser.h
@ -54,7 +54,6 @@ private:
|
|||||||
bool allowIndexed = false;
|
bool allowIndexed = false;
|
||||||
bool allowEmptyName = false;
|
bool allowEmptyName = false;
|
||||||
bool allowInitialValue = false;
|
bool allowInitialValue = false;
|
||||||
bool isDeclaredConst = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
///@{
|
///@{
|
||||||
@ -67,8 +66,7 @@ private:
|
|||||||
ASTPointer<StructDefinition> parseStructDefinition();
|
ASTPointer<StructDefinition> parseStructDefinition();
|
||||||
ASTPointer<EnumDefinition> parseEnumDefinition();
|
ASTPointer<EnumDefinition> parseEnumDefinition();
|
||||||
ASTPointer<EnumValue> parseEnumValue();
|
ASTPointer<EnumValue> parseEnumValue();
|
||||||
ASTPointer<VariableDeclaration> parseVariableDeclaration(
|
ASTPointer<VariableDeclaration> parseVariableDeclaration(VarDeclParserOptions const& _options = VarDeclParserOptions(),
|
||||||
VarDeclParserOptions const& _options = VarDeclParserOptions(),
|
|
||||||
ASTPointer<TypeName> const& _lookAheadArrayType = ASTPointer<TypeName>());
|
ASTPointer<TypeName> const& _lookAheadArrayType = ASTPointer<TypeName>());
|
||||||
ASTPointer<ModifierDefinition> parseModifierDefinition();
|
ASTPointer<ModifierDefinition> parseModifierDefinition();
|
||||||
ASTPointer<EventDefinition> parseEventDefinition();
|
ASTPointer<EventDefinition> parseEventDefinition();
|
||||||
|
Loading…
Reference in New Issue
Block a user