Pass std::shared_ptr's by const reference
MODIFY
src/assembler/expreval.cpp
src/assembler/expreval.cpp
@@ -36,49 +36,49 @@ struct Literal : Printable {
};
struct Add : Printable {
- Add(std::shared_ptr<Expr> _lhs, std::shared_ptr<Expr> _rhs) : lhs(_lhs), rhs(_rhs) {}
+ Add(const std::shared_ptr<Expr>& _lhs, const std::shared_ptr<Expr>& _rhs) : lhs(_lhs), rhs(_rhs) {}
std::shared_ptr<Expr> lhs, rhs;
void print(std::ostream& str) const override;
};
struct Sub : Printable {
- Sub(std::shared_ptr<Expr> _lhs, std::shared_ptr<Expr> _rhs) : lhs(_lhs), rhs(_rhs) {}
+ Sub(const std::shared_ptr<Expr>& _lhs, const std::shared_ptr<Expr>& _rhs) : lhs(_lhs), rhs(_rhs) {}
std::shared_ptr<Expr> lhs, rhs;
void print(std::ostream& str) const override;
};
struct Mul : Printable {
- Mul(std::shared_ptr<Expr> _lhs, std::shared_ptr<Expr> _rhs) : lhs(_lhs), rhs(_rhs) {}
+ Mul(const std::shared_ptr<Expr>& _lhs, const std::shared_ptr<Expr>& _rhs) : lhs(_lhs), rhs(_rhs) {}
std::shared_ptr<Expr> lhs, rhs;
void print(std::ostream& str) const override;
};
struct Div : Printable {
- Div(std::shared_ptr<Expr> _lhs, std::shared_ptr<Expr> _rhs) : lhs(_lhs), rhs(_rhs) {}
+ Div(const std::shared_ptr<Expr>& _lhs, const std::shared_ptr<Expr>& _rhs) : lhs(_lhs), rhs(_rhs) {}
std::shared_ptr<Expr> lhs, rhs;
void print(std::ostream& str) const override;
};
struct Mod : Printable {
- Mod(std::shared_ptr<Expr> _lhs, std::shared_ptr<Expr> _rhs) : lhs(_lhs), rhs(_rhs) {}
+ Mod(const std::shared_ptr<Expr>& _lhs, const std::shared_ptr<Expr>& _rhs) : lhs(_lhs), rhs(_rhs) {}
std::shared_ptr<Expr> lhs, rhs;
void print(std::ostream& str) const override;
};
struct And : Printable {
- And(std::shared_ptr<Expr> _lhs, std::shared_ptr<Expr> _rhs) : lhs(_lhs), rhs(_rhs) {}
+ And(const std::shared_ptr<Expr>& _lhs, const std::shared_ptr<Expr>& _rhs) : lhs(_lhs), rhs(_rhs) {}
std::shared_ptr<Expr> lhs, rhs;
void print(std::ostream& str) const override;
};
struct Or : Printable {
- Or(std::shared_ptr<Expr> _lhs, std::shared_ptr<Expr> _rhs) : lhs(_lhs), rhs(_rhs) {}
+ Or(const std::shared_ptr<Expr>& _lhs, const std::shared_ptr<Expr>& _rhs) : lhs(_lhs), rhs(_rhs) {}
std::shared_ptr<Expr> lhs, rhs;
void print(std::ostream& str) const override;
};
struct SignExtend : Printable {
- SignExtend(std::shared_ptr<Expr> _lhs, std::shared_ptr<Expr> _rhs) : lhs(_lhs), rhs(_rhs) {}
+ SignExtend(const std::shared_ptr<Expr>& _lhs, const std::shared_ptr<Expr>& _rhs) : lhs(_lhs), rhs(_rhs) {}
std::shared_ptr<Expr> lhs, rhs;
void print(std::ostream& str) const override;
};
@@ -148,7 +148,7 @@ using ExprRes = std::variant<Error, std::shared_ptr<Expr>>;
ExprRes parseRight(const QString& s, int& pos, int& depth);
template <typename BinOp>
-ExprRes rightRec(std::shared_ptr<Expr> lhs, const QString& s, int& pos, int& depth) {
+ExprRes rightRec(const std::shared_ptr<Expr>& lhs, const QString& s, int& pos, int& depth) {
auto rhs = parseRight(s, pos, depth);
if (auto* err = std::get_if<Error>(&rhs)) {
return {*err};

MODIFY
src/assembler/objdump.cpp
src/assembler/objdump.cpp
@@ -61,7 +61,7 @@ QString stringifyProgram(std::weak_ptr<const Program> program, unsigned stride,
return QString();
}
-QString objdump(std::shared_ptr<const Program> program, AddrOffsetMap& addrOffsetMap) {
+QString objdump(const std::shared_ptr<const Program>& program, AddrOffsetMap& addrOffsetMap) {
auto assembler = ProcessorHandler::getAssembler();
return stringifyProgram(
program, 4,
@@ -77,7 +77,7 @@ QString objdump(std::shared_ptr<const Program> program, AddrOffsetMap& addrOffse
addrOffsetMap);
}
-QString binobjdump(std::shared_ptr<const Program> program, AddrOffsetMap& addrOffsetMap) {
+QString binobjdump(const std::shared_ptr<const Program>& program, AddrOffsetMap& addrOffsetMap) {
return stringifyProgram(
program, 4,
[](const std::vector<char>& buffer, uint32_t) {

MODIFY
src/assembler/objdump.h
src/assembler/objdump.h
@@ -22,8 +22,8 @@ namespace Assembler {
*/
using AddrOffsetMap = std::map<unsigned long, std::pair<int, QString>>;
-QString objdump(std::shared_ptr<const Program> program, AddrOffsetMap& addrOffsetMap);
-QString binobjdump(std::shared_ptr<const Program> program, AddrOffsetMap& addrOffsetMap);
+QString objdump(const std::shared_ptr<const Program>& program, AddrOffsetMap& addrOffsetMap);
+QString binobjdump(const std::shared_ptr<const Program>& program, AddrOffsetMap& addrOffsetMap);
} // namespace Assembler
} // namespace Ripes

MODIFY
src/cachesim/cacheconfigwidget.cpp
src/cachesim/cacheconfigwidget.cpp
@@ -22,7 +22,7 @@ CacheConfigWidget::CacheConfigWidget(QWidget* parent) : QWidget(parent), m_ui(ne
m_ui->replacementPolicy, m_ui->wrMiss, m_ui->wrHit};
}
-void CacheConfigWidget::setCache(std::shared_ptr<CacheSim>& cache) {
+void CacheConfigWidget::setCache(const std::shared_ptr<CacheSim>& cache) {
m_cache = cache;
setupEnumCombobox(m_ui->replacementPolicy, s_cacheReplPolicyStrings);

MODIFY
src/cachesim/cacheconfigwidget.h
src/cachesim/cacheconfigwidget.h
@@ -16,7 +16,7 @@ public:
CacheConfigWidget(QWidget* parent);
~CacheConfigWidget() override;
- void setCache(std::shared_ptr<CacheSim>& cache);
+ void setCache(const std::shared_ptr<CacheSim>& cache);
signals:
void configurationChanged();

MODIFY
src/cachesim/cacheplotwidget.cpp
src/cachesim/cacheplotwidget.cpp
@@ -87,7 +87,7 @@ void CachePlotWidget::showSizeBreakdown() {
QMessageBox::information(this, "Cache Size Breakdown", sizeText);
}
-void CachePlotWidget::setCache(std::shared_ptr<CacheSim> cache) {
+void CachePlotWidget::setCache(const std::shared_ptr<CacheSim>& cache) {
m_cache = cache;
connect(m_cache.get(), &CacheSim::hitrateChanged, this, &CachePlotWidget::updateHitrate);

MODIFY
src/cachesim/cacheplotwidget.h
src/cachesim/cacheplotwidget.h
@@ -48,7 +48,7 @@ class CachePlotWidget : public QWidget {
public:
enum Variable { Writes = 0, Reads, Hits, Misses, Writebacks, Accesses, N_TraceVars, Unary };
explicit CachePlotWidget(QWidget* parent = nullptr);
- void setCache(std::shared_ptr<CacheSim> cache);
+ void setCache(const std::shared_ptr<CacheSim>& cache);
~CachePlotWidget();
public slots:

MODIFY
src/cachesim/cachesim.h
src/cachesim/cachesim.h
@@ -63,7 +63,7 @@ public:
* A function called by the logical "child" of this cache, indicating that it desires to access this cache
*/
virtual void access(uint32_t address, AccessType type) = 0;
- void setNextLevelCache(std::shared_ptr<CacheSim>& cache) { m_nextLevelCache = cache; }
+ void setNextLevelCache(const std::shared_ptr<CacheSim>& cache) { m_nextLevelCache = cache; }
/**
* @brief reset

MODIFY
src/cachesim/cachewidget.cpp
src/cachesim/cachewidget.cpp
@@ -30,7 +30,7 @@ CacheWidget::CacheWidget(QWidget* parent) : QWidget(parent), m_ui(new Ui::CacheW
});
}
-void CacheWidget::setNextLevelCache(std::shared_ptr<CacheSim>& cache) {
+void CacheWidget::setNextLevelCache(const std::shared_ptr<CacheSim>& cache) {
m_cacheSim.get()->setNextLevelCache(cache);
}

MODIFY
src/cachesim/cachewidget.h
src/cachesim/cachewidget.h
@@ -23,7 +23,7 @@ public:
explicit CacheWidget(QWidget* parent = nullptr);
~CacheWidget();
- void setNextLevelCache(std::shared_ptr<CacheSim>& cache);
+ void setNextLevelCache(const std::shared_ptr<CacheSim>& cache);
std::shared_ptr<CacheSim>& getCacheSim() { return m_cacheSim; }
QGraphicsScene* getScene() { return m_scene.get(); }

MODIFY
src/editor/codeeditor.h
src/editor/codeeditor.h
@@ -31,7 +31,7 @@ public:
void setupChangedTimer();
void rehighlight();
- void setErrors(std::shared_ptr<Assembler::Errors> errors) { m_errors = errors; }
+ void setErrors(const std::shared_ptr<Assembler::Errors>& errors) { m_errors = errors; }
signals:
/**

MODIFY
src/edittab.h
src/edittab.h
@@ -42,7 +42,7 @@ public:
void loadExternalFile(const LoadFileParams& params);
signals:
- void programChanged(std::shared_ptr<Program> program);
+ void programChanged(const std::shared_ptr<Program>& program);
void editorStateChanged(bool enabled);
public slots:

MODIFY
src/processorhandler.cpp
src/processorhandler.cpp
@@ -53,7 +53,7 @@ ProcessorHandler::ProcessorHandler() {
m_syscallManager = std::make_unique<RISCVSyscallManager>();
}
-void ProcessorHandler::loadProgram(std::shared_ptr<Program> p) {
+void ProcessorHandler::loadProgram(const std::shared_ptr<Program>& p) {
// Stop any currently executing simulation
stopRun();

MODIFY
src/processorhandler.h
src/processorhandler.h
@@ -182,7 +182,7 @@ signals:
void procStateChangedNonRun(); // processorReset | processorReversed | processorClockedNonRun
public slots:
- void loadProgram(std::shared_ptr<Program> p);
+ void loadProgram(const std::shared_ptr<Program>& p);
private slots:
/**

Pass std::shared_ptr's by const reference