Skip to content

Commit 120aeef

Browse files
committed
Remove some operator fwd decls and replace with direct inline impl
1 parent 48c56b8 commit 120aeef

4 files changed

Lines changed: 38 additions & 54 deletions

File tree

include/phasar/Utils/DOTGraph.h

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,26 @@ struct DOTNode {
104104
bool IsStmt = true, bool Isv = true);
105105
[[nodiscard]] std::string str(const std::string &Indent = "") const;
106106

107-
friend bool operator<(const DOTNode &Lhs, const DOTNode &Rhs);
108-
friend bool operator==(const DOTNode &Lhs, const DOTNode &Rhs);
107+
friend bool operator<(const DOTNode &Lhs, const DOTNode &Rhs) {
108+
StringIDLess StrLess;
109+
// comparing control flow nodes
110+
if (Lhs.FactId == 0 && Rhs.FactId == 0) {
111+
return StrLess(Lhs.StmtId, Rhs.StmtId);
112+
} // comparing fact nodes
113+
if (Lhs.FactId == Rhs.FactId) {
114+
return StrLess(Lhs.StmtId, Rhs.StmtId);
115+
}
116+
return Lhs.FactId < Rhs.FactId;
117+
}
118+
119+
friend bool operator==(const DOTNode &Lhs, const DOTNode &Rhs) {
120+
return !(Lhs < Rhs) && !(Rhs < Lhs);
121+
}
122+
109123
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
110-
const DOTNode &Node);
124+
const DOTNode &Node) {
125+
return OS << Node.str();
126+
}
111127
};
112128

113129
struct DOTEdge {
@@ -121,9 +137,17 @@ struct DOTEdge {
121137
std::string Vl = "");
122138
[[nodiscard]] std::string str(const std::string &Indent = "") const;
123139

124-
friend bool operator<(const DOTEdge &Lhs, const DOTEdge &Rhs);
140+
friend bool operator<(const DOTEdge &Lhs, const DOTEdge &Rhs) {
141+
if (Lhs.Source == Rhs.Source) {
142+
return Lhs.Target < Rhs.Target;
143+
}
144+
return Lhs.Source < Rhs.Source;
145+
}
146+
125147
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
126-
const DOTEdge &Edge);
148+
const DOTEdge &Edge) {
149+
return OS << Edge.str();
150+
}
127151
};
128152

129153
struct DOTFactSubGraph {
@@ -138,7 +162,9 @@ struct DOTFactSubGraph {
138162
[[nodiscard]] std::string str(const std::string &Indent = "") const;
139163

140164
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
141-
const DOTFactSubGraph &FactSG);
165+
const DOTFactSubGraph &FactSG) {
166+
return OS << FactSG.str();
167+
}
142168
};
143169

144170
struct DOTFunctionSubGraph {
@@ -161,7 +187,9 @@ struct DOTFunctionSubGraph {
161187
void createLayoutFactEdges();
162188

163189
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
164-
const DOTFunctionSubGraph &FunctionSG);
190+
const DOTFunctionSubGraph &FunctionSG) {
191+
return OS << FunctionSG.str();
192+
}
165193
};
166194

167195
template <typename D> struct DOTGraph {

lib/Utils/DOTGraph.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -199,46 +199,6 @@ void DOTFunctionSubGraph::createLayoutFactEdges() {
199199
}
200200
}
201201

202-
bool operator<(const DOTNode &Lhs, const DOTNode &Rhs) {
203-
StringIDLess StrLess;
204-
// comparing control flow nodes
205-
if (Lhs.FactId == 0 && Rhs.FactId == 0) {
206-
return StrLess(Lhs.StmtId, Rhs.StmtId);
207-
} // comparing fact nodes
208-
if (Lhs.FactId == Rhs.FactId) {
209-
return StrLess(Lhs.StmtId, Rhs.StmtId);
210-
}
211-
return Lhs.FactId < Rhs.FactId;
212-
}
213-
214-
bool operator==(const DOTNode &Lhs, const DOTNode &Rhs) {
215-
return !(Lhs < Rhs) && !(Rhs < Lhs);
216-
}
217-
218-
std::ostream &operator<<(std::ostream &OS, const DOTNode &Node) {
219-
return OS << Node.str();
220-
}
221-
222-
bool operator<(const DOTEdge &Lhs, const DOTEdge &Rhs) {
223-
if (Lhs.Source == Rhs.Source) {
224-
return Lhs.Target < Rhs.Target;
225-
}
226-
return Lhs.Source < Rhs.Source;
227-
}
228-
229-
std::ostream &operator<<(std::ostream &OS, const DOTEdge &Edge) {
230-
return OS << Edge.str();
231-
}
232-
233-
std::ostream &operator<<(std::ostream &OS, const DOTFactSubGraph &FactSG) {
234-
return OS << FactSG.str();
235-
}
236-
237-
std::ostream &operator<<(std::ostream &OS,
238-
const DOTFunctionSubGraph &FunctionSG) {
239-
return OS << FunctionSG.str();
240-
}
241-
242202
DOTConfig &DOTConfig::getDOTConfig() {
243203
static DOTConfig DC;
244204
return DC;

tools/ptaben/PTAResult.cpp

Lines changed: 0 additions & 6 deletions
This file was deleted.

tools/ptaben/PTAResult.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ struct PTAResult {
2121
QueryId Query{};
2222
AliasResult Result{};
2323

24-
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, PTAResult Res);
24+
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, PTAResult Res) {
25+
return OS << uint64_t(Res.Query) << ", " << to_string(Res.Result);
26+
}
2527
};
2628

2729
} // namespace psr::ptaben

0 commit comments

Comments
 (0)