mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Parsing accessor functions for public contract state variables
- During the contract parsing depending on whether or not a state variable is public an extra acessor FunctionDefinition is parsed for it
This commit is contained in:
parent
282d4b8add
commit
97c31b3e7d
25
Parser.cpp
25
Parser.cpp
@ -109,6 +109,29 @@ ASTPointer<ImportDirective> Parser::parseImportDirective()
|
||||
return nodeFactory.createNode<ImportDirective>(url);
|
||||
}
|
||||
|
||||
void Parser::addStateVariableAccessor(ASTPointer<VariableDeclaration> const& _varDecl,
|
||||
vector<ASTPointer<FunctionDefinition>> & _functions)
|
||||
{
|
||||
ASTNodeFactory nodeFactory(*this);
|
||||
ASTPointer<ASTString> emptyDoc;
|
||||
ASTPointer<ParameterList> emptyParamList;
|
||||
nodeFactory.markEndPosition();
|
||||
auto expression = nodeFactory.createNode<Identifier>(make_shared<ASTString>(_varDecl->getName()));
|
||||
vector<ASTPointer<Statement>> block_statements = {nodeFactory.createNode<Return>(expression)};
|
||||
|
||||
_functions.push_back(nodeFactory.createNode<FunctionDefinition>(
|
||||
make_shared<ASTString>(_varDecl->getName()),
|
||||
true, // isPublic
|
||||
false, // not a Constructor
|
||||
emptyDoc, // no documentation
|
||||
emptyParamList, // no parameters (temporary, a mapping would need parameters for example)
|
||||
true, // is constant
|
||||
emptyParamList, // no return parameters
|
||||
nodeFactory.createNode<Block>(block_statements)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
ASTPointer<ContractDefinition> Parser::parseContractDefinition()
|
||||
{
|
||||
ASTNodeFactory nodeFactory(*this);
|
||||
@ -151,6 +174,8 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition()
|
||||
{
|
||||
bool const allowVar = false;
|
||||
stateVariables.push_back(parseVariableDeclaration(allowVar));
|
||||
if (visibilityIsPublic)
|
||||
addStateVariableAccessor(stateVariables.back(), functions);
|
||||
expectToken(Token::SEMICOLON);
|
||||
}
|
||||
else if (currentToken == Token::MODIFIER)
|
||||
|
4
Parser.h
4
Parser.h
@ -78,6 +78,10 @@ private:
|
||||
///@{
|
||||
///@name Helper functions
|
||||
|
||||
/// Depending on whether a state Variable is Public, appends an accessor to the contract's functions
|
||||
void addStateVariableAccessor(ASTPointer<VariableDeclaration> const& _varDecl,
|
||||
std::vector<ASTPointer<FunctionDefinition>> & _functions);
|
||||
|
||||
/// Peeks ahead in the scanner to determine if a variable definition is going to follow
|
||||
bool peekVariableDefinition();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user