Skip to content

Commit b3a7739

Browse files
nikola-maticmatheusaaguiar
authored andcommitted
Address review comments
1 parent 47fdd4c commit b3a7739

10 files changed

+39
-85
lines changed

Diff for: libsolidity/CMakeLists.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ set(sources
188188
experimental/analysis/Analysis.h
189189
experimental/analysis/DebugWarner.cpp
190190
experimental/analysis/DebugWarner.h
191-
experimental/analysis/FunctionDependencyGraph.cpp
192-
experimental/analysis/FunctionDependencyGraph.h
191+
experimental/analysis/FunctionDependencyAnalysis.cpp
192+
experimental/analysis/FunctionDependencyAnalysis.h
193193
experimental/analysis/TypeClassRegistration.cpp
194194
experimental/analysis/TypeClassRegistration.h
195195
experimental/analysis/TypeInference.cpp
@@ -198,8 +198,7 @@ set(sources
198198
experimental/analysis/TypeRegistration.h
199199
experimental/analysis/SyntaxRestrictor.cpp
200200
experimental/analysis/SyntaxRestrictor.h
201-
experimental/ast/CallGraph.cpp
202-
experimental/ast/CallGraph.h
201+
experimental/ast/FunctionCallGraph.h
203202
experimental/ast/Type.cpp
204203
experimental/ast/Type.h
205204
experimental/ast/TypeSystem.cpp

Diff for: libsolidity/experimental/analysis/Analysis.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// SPDX-License-Identifier: GPL-3.0
1818
#include <libsolidity/experimental/analysis/Analysis.h>
1919
#include <libsolidity/experimental/analysis/DebugWarner.h>
20-
#include <libsolidity/experimental/analysis/FunctionDependencyGraph.h>
20+
#include <libsolidity/experimental/analysis/FunctionDependencyAnalysis.h>
2121
#include <libsolidity/experimental/analysis/SyntaxRestrictor.h>
2222
#include <libsolidity/experimental/analysis/TypeClassRegistration.h>
2323
#include <libsolidity/experimental/analysis/TypeInference.h>
@@ -36,7 +36,7 @@ struct Analysis::AnnotationContainer
3636

3737
struct Analysis::GlobalAnnotationContainer
3838
{
39-
FunctionDependencyGraph::GlobalAnnotation functionCallGraphAnnotation;
39+
FunctionDependencyAnalysis::GlobalAnnotation functionDependencyGraphAnnotation;
4040
TypeClassRegistration::GlobalAnnotation typeClassRegistrationAnnotation;
4141
TypeRegistration::GlobalAnnotation typeRegistrationAnnotation;
4242
TypeInference::GlobalAnnotation typeInferenceAnnotation;
@@ -67,15 +67,15 @@ TypeClassRegistration::Annotation const& solidity::frontend::experimental::detai
6767
}
6868

6969
template<>
70-
FunctionDependencyGraph::GlobalAnnotation const& solidity::frontend::experimental::detail::ConstAnnotationFetcher<FunctionDependencyGraph>::get() const
70+
FunctionDependencyAnalysis::GlobalAnnotation const& solidity::frontend::experimental::detail::ConstAnnotationFetcher<FunctionDependencyAnalysis>::get() const
7171
{
72-
return analysis.annotationContainer().functionCallGraphAnnotation;
72+
return analysis.annotationContainer().functionDependencyGraphAnnotation;
7373
}
7474

7575
template<>
76-
FunctionDependencyGraph::GlobalAnnotation& solidity::frontend::experimental::detail::AnnotationFetcher<FunctionDependencyGraph>::get()
76+
FunctionDependencyAnalysis::GlobalAnnotation& solidity::frontend::experimental::detail::AnnotationFetcher<FunctionDependencyAnalysis>::get()
7777
{
78-
return analysis.annotationContainer().functionCallGraphAnnotation;
78+
return analysis.annotationContainer().functionDependencyGraphAnnotation;
7979
}
8080

8181
template<>
@@ -165,7 +165,7 @@ bool Analysis::check(std::vector<std::shared_ptr<SourceUnit const>> const& _sour
165165
TypeClassRegistration,
166166
TypeRegistration,
167167
// TODO move after step introduced in https://github.com/ethereum/solidity/pull/14578, but before TypeInference
168-
FunctionDependencyGraph,
168+
FunctionDependencyAnalysis,
169169
TypeInference,
170170
DebugWarner
171171
>;

Diff for: libsolidity/experimental/analysis/FunctionDependencyGraph.cpp renamed to libsolidity/experimental/analysis/FunctionDependencyAnalysis.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,42 @@
1717
// SPDX-License-Identifier: GPL-3.0
1818

1919
#include <libsolidity/experimental/analysis/Analysis.h>
20-
#include <libsolidity/experimental/analysis/FunctionDependencyGraph.h>
20+
#include <libsolidity/experimental/analysis/FunctionDependencyAnalysis.h>
2121

2222
using namespace solidity::frontend::experimental;
2323
using namespace solidity::util;
2424

25-
FunctionDependencyGraph::FunctionDependencyGraph(Analysis& _analysis):
25+
FunctionDependencyAnalysis::FunctionDependencyAnalysis(Analysis& _analysis):
2626
m_analysis(_analysis),
2727
m_errorReporter(_analysis.errorReporter())
2828
{
2929
}
3030

31-
bool FunctionDependencyGraph::analyze(SourceUnit const& _sourceUnit)
31+
bool FunctionDependencyAnalysis::analyze(SourceUnit const& _sourceUnit)
3232
{
3333
_sourceUnit.accept(*this);
3434
return !m_errorReporter.hasErrors();
3535
}
3636

37-
bool FunctionDependencyGraph::visit(FunctionDefinition const& _functionDefinition)
37+
bool FunctionDependencyAnalysis::visit(FunctionDefinition const& _functionDefinition)
3838
{
3939
solAssert(!m_currentFunction);
4040
m_currentFunction = &_functionDefinition;
41+
// Insert a function definition pointer that maps to an empty set; the pointed to set will later be
42+
// populated in ``endVisit(Identifier const& _identifier)`` if ``m_currentFunction`` references another.
43+
auto [_, inserted] = annotation().functionCallGraph.edges.try_emplace(
44+
m_currentFunction, std::set<FunctionDefinition const*, ASTCompareByID<FunctionDefinition>>{}
45+
);
46+
solAssert(inserted);
4147
return true;
4248
}
4349

44-
void FunctionDependencyGraph::endVisit(FunctionDefinition const&)
50+
void FunctionDependencyAnalysis::endVisit(FunctionDefinition const&)
4551
{
46-
// If we're done visiting a function declaration without said function referencing/calling
47-
// another function in its body - insert it into the graph without child nodes.
48-
annotation().functionCallGraph.edges.try_emplace(m_currentFunction, std::set<FunctionDefinition const*, CallGraph::CompareByID>{});
4952
m_currentFunction = nullptr;
5053
}
5154

52-
void FunctionDependencyGraph::endVisit(Identifier const& _identifier)
55+
void FunctionDependencyAnalysis::endVisit(Identifier const& _identifier)
5356
{
5457
auto const* callee = dynamic_cast<FunctionDefinition const*>(_identifier.annotation().referencedDeclaration);
5558
// Check that the identifier is within a function body and is a function, and add it to the graph
@@ -58,12 +61,12 @@ void FunctionDependencyGraph::endVisit(Identifier const& _identifier)
5861
addEdge(m_currentFunction, callee);
5962
}
6063

61-
void FunctionDependencyGraph::addEdge(FunctionDefinition const* _caller, FunctionDefinition const* _callee)
64+
void FunctionDependencyAnalysis::addEdge(FunctionDefinition const* _caller, FunctionDefinition const* _callee)
6265
{
6366
annotation().functionCallGraph.edges[_caller].insert(_callee);
6467
}
6568

66-
FunctionDependencyGraph::GlobalAnnotation& FunctionDependencyGraph::annotation()
69+
FunctionDependencyAnalysis::GlobalAnnotation& FunctionDependencyAnalysis::annotation()
6770
{
68-
return m_analysis.annotation<FunctionDependencyGraph>();
71+
return m_analysis.annotation<FunctionDependencyAnalysis>();
6972
}

Diff for: libsolidity/experimental/analysis/FunctionDependencyGraph.h renamed to libsolidity/experimental/analysis/FunctionDependencyAnalysis.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <liblangutil/ErrorReporter.h>
2222
#include <libsolidity/ast/ASTForward.h>
2323
#include <libsolidity/ast/ASTVisitor.h>
24-
#include <libsolidity/experimental/ast/CallGraph.h>
24+
#include <libsolidity/experimental/ast/FunctionCallGraph.h>
2525

2626
#include <memory>
2727

@@ -30,16 +30,16 @@ namespace solidity::frontend::experimental
3030

3131
class Analysis;
3232

33-
class FunctionDependencyGraph: private ASTConstVisitor
33+
class FunctionDependencyAnalysis: private ASTConstVisitor
3434
{
3535
public:
36-
FunctionDependencyGraph(Analysis& _analysis);
36+
FunctionDependencyAnalysis(Analysis& _analysis);
3737
bool analyze(SourceUnit const& _sourceUnit);
3838

3939
struct Annotation {};
4040
struct GlobalAnnotation
4141
{
42-
CallGraph functionCallGraph;
42+
FunctionDependencyGraph functionCallGraph;
4343
};
4444

4545
private:

Diff for: libsolidity/experimental/ast/CallGraph.cpp

-39
This file was deleted.

Diff for: libsolidity/experimental/ast/CallGraph.h renamed to libsolidity/experimental/ast/FunctionCallGraph.h

+4-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
// SPDX-License-Identifier: GPL-3.0
1818

19-
/// Data structure representing a function call graph.
19+
/// Data structure representing a function dependency graph.
2020

2121
#pragma once
2222

@@ -29,21 +29,12 @@
2929
namespace solidity::frontend::experimental
3030
{
3131

32-
struct CallGraph
32+
struct FunctionDependencyGraph
3333
{
34-
struct CompareByID
35-
{
36-
using is_transparent = void;
37-
bool operator()(FunctionDefinition const* _lhs, FunctionDefinition const* _rhs) const;
38-
bool operator()(FunctionDefinition const* _lhs, int64_t _rhs) const;
39-
bool operator()(int64_t _lhs, FunctionDefinition const* _rhs) const;
40-
};
4134
/// Graph edges. Edges are directed and lead from the caller to the callee.
42-
/// The map contains a key for every possible caller, even if does not actually perform
35+
/// The map contains a key for every function, even if does not actually perform
4336
/// any calls.
44-
std::map<FunctionDefinition const*, std::set<FunctionDefinition const*, CompareByID>, CompareByID> edges;
37+
std::map<FunctionDefinition const*, std::set<FunctionDefinition const*, ASTCompareByID<FunctionDefinition>>, ASTCompareByID<FunctionDefinition>> edges;
4538
};
4639

47-
std::ostream& operator<<(std::ostream& _out, CallGraph const& _callGraph);
48-
4940
}

Diff for: libsolidity/interface/CompilerStack.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#include <libsolidity/parsing/Parser.h>
5858

5959
#include <libsolidity/experimental/analysis/Analysis.h>
60-
#include <libsolidity/experimental/analysis/FunctionDependencyGraph.h>
60+
#include <libsolidity/experimental/analysis/FunctionDependencyAnalysis.h>
6161
#include <libsolidity/experimental/codegen/IRGenerator.h>
6262

6363
#include <libsolidity/codegen/ir/Common.h>

Diff for: test/InteractiveTests.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <test/libsolidity/ABIJsonTest.h>
2323
#include <test/libsolidity/ASTJSONTest.h>
2424
#include <test/libsolidity/ASTPropertyTest.h>
25-
#include "libsolidity/FunctionDependencyGraphTest.h"
25+
#include <libsolidity/FunctionDependencyGraphTest.h>
2626
#include <test/libsolidity/GasTest.h>
2727
#include <test/libsolidity/MemoryGuardTest.h>
2828
#include <test/libsolidity/NatspecJSONTest.h>

Diff for: test/libsolidity/FunctionDependencyGraphTest.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
*/
1717
// SPDX-License-Identifier: GPL-3.0
1818

19-
#include "FunctionDependencyGraphTest.h"
19+
#include <test/libsolidity/FunctionDependencyGraphTest.h>
2020

2121
#include <libsolidity/experimental/analysis/Analysis.h>
22-
#include "libsolidity/experimental/analysis/FunctionDependencyGraph.h"
22+
#include <libsolidity/experimental/analysis/FunctionDependencyAnalysis.h>
2323
#include <libyul/backends/evm/EVMDialect.h>
2424
#include <libyul/optimiser/FunctionCallFinder.h>
2525

@@ -46,7 +46,7 @@ TestCase::TestResult FunctionDependencyGraphTest::run(std::ostream& _stream, std
4646
}
4747

4848
m_obtainedResult.clear();
49-
for (auto [top, subs]: compiler().experimentalAnalysis().annotation<experimental::FunctionDependencyGraph>().functionCallGraph.edges)
49+
for (auto [top, subs]: compiler().experimentalAnalysis().annotation<experimental::FunctionDependencyAnalysis>().functionCallGraph.edges)
5050
{
5151
std::string topName = top->name().empty() ? "fallback" : top->name();
5252
m_obtainedResult += "(" + topName + ") --> {";

Diff for: test/libsolidity/analysis/FunctionCallGraph.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
// SPDX-License-Identifier: GPL-3.0
1818

19-
/// Unit tests for libsolidity/analysis/FunctionDependencyGraph.h
19+
/// Unit tests for libsolidity/analysis/FunctionCallGraph.h
2020

2121
#include <libsolidity/analysis/FunctionCallGraph.h>
2222

0 commit comments

Comments
 (0)