chipsalliance / chipsalliance/Surelog
Parameters: more readable if either const reference or pointer. But no writable reference.
- Dominant language
- C++
- Stars
- 475
- Forks
- 90
- Avg merge
- 1h 39m
- Merged PRs (30d)
- 37
Description
To denote output parameters, it is best practice to use pointers instead of references to avoid confusing call site where it is not clear that the content would be modified:
https://google.github.io/styleguide/cppguide.html#Reference_Arguments
Similar with return values: if a value is returned, it is a good time to decide if it shall be returned as a pointer (possibly like in some of the `trim()` functions below), or as a const reference.
Here a quick grep that show some instances the might be worthwhile reconsidering.
```
$ find . -name "*.h" -o -name "*.cpp"| xargs egrep 'std::string\w*&' | grep -v const
./Design/ModuleDefinition.cpp: std::string& name)
./Design/FileContent.cpp:bool FileContent::diffTree(std::string& diff, NodeId root, FileContent* oFc,
./Design/Enum.h: void addValue(std::string& name, Value* value) {
./Design/Enum.h: Value* getValue(std::string& name);
./Design/Enum.cpp:Value* Enum::getValue(std::string& name) {
./Design/ModuleDefinition.h: ModuleDefinition(FileContent* fileContent, NodeId nodeId, std::string& name);
./Design/FileContent.h: bool diffTree(std::string& diff, NodeId id, FileContent* oFc, NodeId oId);
./Library/Library.h: std::string& getName() { return m_name; }
./Utils/StringUtils.h: static std::string& trim(std::string& str);
./Utils/StringUtils.h: static std::string& ltrim(std::string& str);
./Utils/StringUtils.h: static std::string& ltrim(std::string& str, char c);
./Utils/StringUtils.h: static bool ltrimStat(std::string& str, char c);
./Utils/StringUtils.h: static std::string& rtrim(std::string& str);
./Utils/StringUtils.h: static std::string& rtrimEqual(std::string& str);
./Utils/StringUtils.h: static std::string& rtrim(std::string& str, char c);
./Utils/StringUtils.h: static std::string& getRootFileName(std::string& str);
./Utils/StringUtils.h: static std::string getLineInString(std::string& bulk, unsigned int line);
./Utils/StringUtils.cpp:std::string& StringUtils::trim(std::string& str) { return ltrim(rtrim(str)); }
./Utils/StringUtils.cpp:std::string& StringUtils::ltrim(std::string& str) {
./Utils/StringUtils.cpp:std::string& StringUtils::rtrim(std::string& str) {
./Utils/StringUtils.cpp:std::string& StringUtils::rtrimEqual(std::string& str) {
./Utils/StringUtils.cpp:std::string& StringUtils::rtrim(std::string& str, char c) {
./Utils/StringUtils.cpp:std::string& StringUtils::ltrim(std::string& str, char c) {
./Utils/StringUtils.cpp:bool StringUtils::ltrimStat(std::string& str, char c) {
./Utils/StringUtils.cpp:std::string& StringUtils::getRootFileName(std::string& str) {
./Utils/StringUtils.cpp:std::string StringUtils::getLineInString(std::string& bulk, unsigned int line) {
./Testbench/ClassObject.h: bool setValue(std::string& property, Value* value);
./Testbench/ClassObject.h: Value* getValue(std::string& property);
./Testbench/ClassObject.cpp:bool ClassObject::setValue(std::string& property, Value* value) {
./Testbench/ClassObject.cpp:Value* ClassObject::getValue(std::string& property) {
./Testcases/AmiqEth/uvmc-2.2/src/connect/sc/uvmc_packer.cpp: void unpack_string(std::string& s);
./Testcases/AmiqEth/uvmc-2.2/src/connect/sc/uvmc_packer.cpp:void uvmc_packer_rep::unpack_string(std::string& a) {
./Testcases/AmiqEth/uvmc-2.2/src/connect/sc/uvmc_packer.cpp:uvmc_packer& uvmc_packer::operator >> (std::string& a) {
./DesignCompile/TestbenchElaboration.cpp: Design* design, std::string& datatypeName) {
./DesignCompile/TestbenchElaboration.cpp: std::string& datatypeName) {
./SourceCompile/SV3_1aPpTreeShapeListener.cpp: std::string& macroName, ParserRuleContext* ctx) {
./SourceCompile/AnalyzeFile.h: std::string& origFile);
./SourceCompile/AnalyzeFile.cpp:void saveContent(std::string fileName, std::string& content) {
./SourceCompile/AnalyzeFile.cpp: std::string& origFile) {
./SourceCompile/SV3_1aPpTreeShapeListener.h: void checkMultiplyDefinedMacro(std::string& macroName, ParserRuleContext* ctx);
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.