Skip to content

Commit

Permalink
Make parser accept transient as location (but not a keyword)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusaaguiar committed Apr 7, 2024
1 parent 3d7b3d9 commit 1ea64d6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
18 changes: 16 additions & 2 deletions libsolidity/analysis/DeclarationTypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
{
case Location::Memory: return "\"memory\"";
case Location::Storage: return "\"storage\"";
case Location::Transient: return "\"transient\"";
case Location::CallData: return "\"calldata\"";
case Location::Unspecified: return "none";
}
Expand Down Expand Up @@ -456,8 +457,18 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
}
else if (_variable.isStateVariable())
{
solAssert(varLoc == Location::Unspecified, "");
typeLoc = (_variable.isConstant() || _variable.immutable()) ? DataLocation::Memory : DataLocation::Storage;
switch (varLoc)
{
case Location::Unspecified:
typeLoc = (_variable.isConstant() || _variable.immutable()) ? DataLocation::Memory : DataLocation::Storage;
break;
case Location::Transient:
solAssert(false, "Transient storage type checking not implemented yet");
break;
default:
solAssert(false, "");
break;
}
}
else if (
dynamic_cast<StructDefinition const*>(_variable.scope()) ||
Expand All @@ -477,6 +488,9 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
case Location::CallData:
typeLoc = DataLocation::CallData;
break;
case Location::Transient:
solAssert(false, "Transient storage type checking not implemented yet");
break;
case Location::Unspecified:
solAssert(!_variable.hasReferenceOrMappingType(), "Data location not properly set.");
}
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/ast/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ class FunctionDefinition: public CallableDeclaration, public StructurallyDocumen
class VariableDeclaration: public Declaration, public StructurallyDocumented
{
public:
enum Location { Unspecified, Storage, Memory, CallData };
enum Location { Unspecified, Storage, Transient, Memory, CallData };
enum class Mutability { Mutable, Immutable, Constant };
static std::string mutabilityToString(Mutability _mutability)
{
Expand Down
2 changes: 2 additions & 0 deletions libsolidity/ast/ASTJsonExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,8 @@ std::string ASTJsonExporter::location(VariableDeclaration::Location _location)
return "memory";
case VariableDeclaration::Location::CallData:
return "calldata";
case VariableDeclaration::Location::Transient:
return "transient";
}
// To make the compiler happy
return {};
Expand Down
17 changes: 17 additions & 0 deletions libsolidity/parsing/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,23 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(
{
nodeFactory.markEndPosition();
tie(identifier, nameLocation) = expectIdentifierWithLocation();
if (
*identifier == "transient" &&
m_scanner->currentToken() == Token::Identifier &&
(
_options.allowLocationSpecifier ||
_options.kind == VarDeclKind::State
)
)
{
if (location != VariableDeclaration::Location::Unspecified)
parserError(ErrorId{3548}, "Location already specified.");
else
location = VariableDeclaration::Location::Transient;

nodeFactory.markEndPosition();
tie(identifier, nameLocation) = expectIdentifierWithLocation();
}
}
ASTPointer<Expression> value;
if (_options.allowInitialValue)
Expand Down

0 comments on commit 1ea64d6

Please sign in to comment.