Skip to content

Commit

Permalink
Rename ContractType::stateVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusaaguiar committed Mar 6, 2025
1 parent 6cf3df6 commit 0c0c671
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,7 @@ FunctionType const* ContractType::newExpressionType() const
return m_constructorType;
}

std::vector<std::tuple<VariableDeclaration const*, u256, unsigned>> ContractType::stateVariables(DataLocation _location) const
std::vector<std::tuple<VariableDeclaration const*, u256, unsigned>> ContractType::linearizedStateVariables(DataLocation _location) const
{
VariableDeclaration::Location location;
switch (_location)
Expand Down
9 changes: 6 additions & 3 deletions libsolidity/ast/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,12 @@ class ContractType: public Type
/// Returns the function type of the constructor modified to return an object of the contract's type.
FunctionType const* newExpressionType() const;

/// @returns a list of all state variables (including inherited) of the contract and their
/// offsets in storage/transient storage.
std::vector<std::tuple<VariableDeclaration const*, u256, unsigned>> stateVariables(DataLocation _location) const;
/// @returns a list of all state variables in the linearized inheritance hierarchy and
/// their respective slots and offsets in storage/transient storage.
/// It should only be called for the top level contract in order to get the absolute slots and
/// offsets values in storage/transient storage. Otherwise, the slots of the state variables
/// will be relative to the contract position in the hierarchy.
std::vector<std::tuple<VariableDeclaration const*, u256, unsigned>> linearizedStateVariables(DataLocation _location) const;
/// @returns a list of all immutable variables (including inherited) of the contract.
std::vector<VariableDeclaration const*> immutableVariables() const;
protected:
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/codegen/ContractCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void ContractCompiler::appendReturnValuePacker(TypePointers const& _typeParamete
void ContractCompiler::registerStateVariables(ContractDefinition const& _contract)
{
for (auto const location: {DataLocation::Storage, DataLocation::Transient})
for (auto const& var: ContractType(_contract).stateVariables(location))
for (auto const& var: ContractType(_contract).linearizedStateVariables(location))
m_context.addStateVariable(*std::get<0>(var), std::get<1>(var), std::get<2>(var));
}

Expand Down
2 changes: 1 addition & 1 deletion libsolidity/codegen/ir/IRGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ void IRGenerator::resetContext(ContractDefinition const& _contract, ExecutionCon

m_context.setMostDerivedContract(_contract);
for (auto const location: {DataLocation::Storage, DataLocation::Transient})
for (auto const& var: ContractType(_contract).stateVariables(location))
for (auto const& var: ContractType(_contract).linearizedStateVariables(location))
m_context.addStateVariable(*std::get<0>(var), std::get<1>(var), std::get<2>(var));
}

Expand Down
2 changes: 1 addition & 1 deletion libsolidity/interface/StorageLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Json StorageLayout::generate(ContractDefinition const& _contractDef, DataLocatio
solAssert(contractType, "");

Json variables = Json::array();
for (auto [var, slot, offset]: contractType->stateVariables(_location))
for (auto [var, slot, offset]: contractType->linearizedStateVariables(_location))
variables.emplace_back(generate(*var, slot, offset));

Json layout;
Expand Down

0 comments on commit 0c0c671

Please sign in to comment.