Skip to content

Commit 1423298

Browse files
Rename ContractType::stateVariables
1 parent b601fb4 commit 1423298

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

libsolidity/ast/Types.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ FunctionType const* ContractType::newExpressionType() const
21502150
return m_constructorType;
21512151
}
21522152

2153-
std::vector<std::tuple<VariableDeclaration const*, u256, unsigned>> ContractType::stateVariables(DataLocation _location) const
2153+
std::vector<std::tuple<VariableDeclaration const*, u256, unsigned>> ContractType::linearizedStateVariables(DataLocation _location) const
21542154
{
21552155
VariableDeclaration::Location location;
21562156
switch (_location)

libsolidity/ast/Types.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,12 @@ class ContractType: public Type
10051005
/// Returns the function type of the constructor modified to return an object of the contract's type.
10061006
FunctionType const* newExpressionType() const;
10071007

1008-
/// @returns a list of all state variables (including inherited) of the contract and their
1009-
/// offsets in storage/transient storage.
1010-
std::vector<std::tuple<VariableDeclaration const*, u256, unsigned>> stateVariables(DataLocation _location) const;
1008+
/// @returns a list of all state variables in the linearized inheritance hierarchy and
1009+
/// their respective slots and offsets in storage/transient storage.
1010+
/// It should only be called for the top level contract in order to get the absolute slots and
1011+
/// offsets values in storage/transient storage. Otherwise, the slots of the state variables
1012+
/// will be relative to the contract position in the hierarchy.
1013+
std::vector<std::tuple<VariableDeclaration const*, u256, unsigned>> linearizedStateVariables(DataLocation _location) const;
10111014
/// @returns a list of all immutable variables (including inherited) of the contract.
10121015
std::vector<VariableDeclaration const*> immutableVariables() const;
10131016
protected:

libsolidity/codegen/ContractCompiler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ void ContractCompiler::appendReturnValuePacker(TypePointers const& _typeParamete
571571
void ContractCompiler::registerStateVariables(ContractDefinition const& _contract)
572572
{
573573
for (auto const location: {DataLocation::Storage, DataLocation::Transient})
574-
for (auto const& var: ContractType(_contract).stateVariables(location))
574+
for (auto const& var: ContractType(_contract).linearizedStateVariables(location))
575575
m_context.addStateVariable(*std::get<0>(var), std::get<1>(var), std::get<2>(var));
576576
}
577577

libsolidity/codegen/ir/IRGenerator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ void IRGenerator::resetContext(ContractDefinition const& _contract, ExecutionCon
11751175

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

libsolidity/interface/StorageLayout.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Json StorageLayout::generate(ContractDefinition const& _contractDef, DataLocatio
3636
solAssert(contractType, "");
3737

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

4242
Json layout;

0 commit comments

Comments
 (0)