Skip to content

Commit f10c481

Browse files
committed
Many minor code improvements.
Signed-off-by: Cervenka Dusan <cervenka@acrios.com>
1 parent 44de55d commit f10c481

27 files changed

+71
-71
lines changed

erpc_c/infra/erpc_client_server_common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
namespace erpc {
3333

3434
/*!
35-
* @brief Common class inheritand by client and server class.
35+
* @brief Common class inherited by client and server class.
3636
*
3737
* @ingroup infra_utility
3838
*/

erpcgen/src/AstWalker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class AstWalker
5353
*
5454
* @param[in] inputFile Parsed file name.
5555
*/
56-
AstWalker(const std::string &inputFile)
56+
explicit AstWalker(const std::string &inputFile)
5757
: m_fileName(inputFile)
5858
{
5959
}

erpcgen/src/CGenerator.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@ string CGenerator::getErrorReturnValue(FunctionBase *fn)
19681968
}
19691969
}
19701970

1971-
string CGenerator::getFunctionServerCall(Function *fn, FunctionType *functionType, std::string prefix)
1971+
string CGenerator::getFunctionServerCall(Function *fn, FunctionType *functionType, const std::string prefix)
19721972
{
19731973
string proto = "";
19741974
if (!fn->getReturnType()->isVoid() && prefix.length() > 0)
@@ -2910,7 +2910,7 @@ string CGenerator::getExtraDirectionPointer(StructMember *structMember)
29102910
return result;
29112911
}
29122912

2913-
data_map CGenerator::firstAllocOnReturnWhenIsNeed(string name, DataType *dataType)
2913+
data_map CGenerator::firstAllocOnReturnWhenIsNeed(const string &name, DataType *dataType)
29142914
{
29152915
DataType *trueDataType = dataType->getTrueDataType();
29162916
if ((trueDataType->isArray() || trueDataType->isStruct() || trueDataType->isUnion()) &&
@@ -2923,7 +2923,7 @@ data_map CGenerator::firstAllocOnReturnWhenIsNeed(string name, DataType *dataTyp
29232923
return r;
29242924
}
29252925

2926-
data_map CGenerator::firstAllocOnServerWhenIsNeed(string name, StructMember *structMember)
2926+
data_map CGenerator::firstAllocOnServerWhenIsNeed(const string &name, StructMember *structMember)
29272927
{
29282928
DataType *dataType = structMember->getDataType();
29292929
DataType *trueDataType = dataType->getTrueDataType();
@@ -3242,10 +3242,10 @@ bool CGenerator::containsByrefParamToFree(DataType *dataType, set<DataType *> &d
32423242
return false;
32433243
}
32443244

3245-
bool CGenerator::isListStruct(StructType *structType)
3245+
bool CGenerator::isListStruct(const StructType *structType)
32463246
{
32473247
// if structure is transformed list<> to struct{list<>}
3248-
for (StructType *structList : m_structListTypes)
3248+
for (const StructType *structList : m_structListTypes)
32493249
{
32503250
if (structType == structList)
32513251
{
@@ -3272,11 +3272,11 @@ bool CGenerator::isBinaryStruct(StructType *structType)
32723272
return false;
32733273
}
32743274

3275-
bool CGenerator::isBinaryList(ListType *listType)
3275+
bool CGenerator::isBinaryList(const ListType *listType)
32763276
{
32773277

32783278
// If list is same as in s_listBinaryTypes.
3279-
for (ListType *list : m_listBinaryTypes)
3279+
for (const ListType *list : m_listBinaryTypes)
32803280
{
32813281
if (listType == list)
32823282
{

erpcgen/src/CGenerator.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ class CGenerator : public Generator
477477
*
478478
* @return String representation for given function.
479479
*/
480-
std::string getFunctionServerCall(Function *fn, FunctionType *functionType = nullptr, std::string="");
480+
std::string getFunctionServerCall(Function *fn, FunctionType *functionType = nullptr, const std::string="");
481481

482482
/*!
483483
* @brief This function return name with guard.
@@ -585,7 +585,7 @@ class CGenerator : public Generator
585585
*
586586
* @return Erpc_alloc function or empty.
587587
*/
588-
cpptempl::data_map firstAllocOnServerWhenIsNeed(std::string name, StructMember *structMember);
588+
cpptempl::data_map firstAllocOnServerWhenIsNeed(const std::string &name, StructMember *structMember);
589589

590590
/*!
591591
* @brief This function call first erpc_alloc on client side return statement if it is need.
@@ -597,7 +597,7 @@ class CGenerator : public Generator
597597
*
598598
* @return Erpc_alloc function or empty.
599599
*/
600-
cpptempl::data_map firstAllocOnReturnWhenIsNeed(std::string name, DataType *dataType);
600+
cpptempl::data_map firstAllocOnReturnWhenIsNeed(const std::string &name, DataType *dataType);
601601

602602
/*!
603603
* @brief This function return call for alloc space based on given data type.
@@ -713,7 +713,7 @@ class CGenerator : public Generator
713713
* @retval true When structure is used as a wrapper for binary type.
714714
* @retval false When structure is not used as a wrapper for binary type.
715715
*/
716-
bool isBinaryList(ListType *listType);
716+
bool isBinaryList(const ListType *listType);
717717

718718
/*!
719719
* @brief This function returns true when structure is used as a wrapper for list type.
@@ -723,7 +723,7 @@ class CGenerator : public Generator
723723
* @retval true When structure is used as a wrapper for list type.
724724
* @retval false When structure is not used as a wrapper for list type.
725725
*/
726-
bool isListStruct(StructType *structType);
726+
bool isListStruct(const StructType *structType);
727727

728728
/*!
729729
* @brief This function returns true when "retain" annotation wasn't set.

erpcgen/src/Generator.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Generator::Generator(InterfaceDefinition *def, generator_type_t generatorType)
144144
}
145145
}
146146

147-
Group *Generator::getGroupByName(string name)
147+
Group *Generator::getGroupByName(const string &name)
148148
{
149149
for (Group *group : m_groups)
150150
{
@@ -592,22 +592,22 @@ Annotation::program_lang_t Generator::getAnnotationLang()
592592
throw internal_error("Unsupported generator type specified for annotation.");
593593
}
594594

595-
Annotation *Generator::findAnnotation(Symbol *symbol, string name)
595+
Annotation *Generator::findAnnotation(Symbol *symbol, const string &name)
596596
{
597597
return symbol->findAnnotation(name, getAnnotationLang());
598598
}
599599

600-
vector<Annotation *> Generator::getAnnotations(Symbol *symbol, string name)
600+
vector<Annotation *> Generator::getAnnotations(Symbol *symbol, const string &name)
601601
{
602602
return symbol->getAnnotations(name, getAnnotationLang());
603603
}
604604

605-
Value *Generator::getAnnValue(Symbol *symbol, string name)
605+
Value *Generator::getAnnValue(Symbol *symbol, const string &name)
606606
{
607607
return symbol->getAnnValue(name, getAnnotationLang());
608608
}
609609

610-
string Generator::getAnnStringValue(Symbol *symbol, string name)
610+
string Generator::getAnnStringValue(Symbol *symbol, const string &name)
611611
{
612612
return symbol->getAnnStringValue(name, getAnnotationLang());
613613
}

erpcgen/src/Generator.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class Generator
274274
*
275275
* @return Pointer to a group with specified name.
276276
*/
277-
Group *getGroupByName(std::string name);
277+
Group *getGroupByName(const std::string &name);
278278

279279
/*!
280280
* @brief This function returns information if member data type symbol is using forward declared type.
@@ -313,7 +313,7 @@ class Generator
313313
*
314314
* @return An index into the annotation list
315315
*/
316-
Annotation *findAnnotation(Symbol *symbol, std::string name);
316+
Annotation *findAnnotation(Symbol *symbol, const std::string &name);
317317

318318
/*!
319319
* @brief Find annotations matching name in the annotation list
@@ -323,7 +323,7 @@ class Generator
323323
*
324324
* @return A vector of matching annotations
325325
*/
326-
std::vector<Annotation *> getAnnotations(Symbol *symbol, std::string name);
326+
std::vector<Annotation *> getAnnotations(Symbol *symbol, const std::string &name);
327327

328328
/*!
329329
* @brief This function search and returns Value object for given annotation name.
@@ -333,7 +333,7 @@ class Generator
333333
*
334334
* @return NULL if annotation is not found else value object.
335335
*/
336-
Value *getAnnValue(Symbol *symbol, std::string name);
336+
Value *getAnnValue(Symbol *symbol, const std::string &name);
337337

338338
/*!
339339
* @brief This function search and returns string for given annotation name.
@@ -343,7 +343,7 @@ class Generator
343343
*
344344
* @return empty string if annotation is not found else string value.
345345
*/
346-
std::string getAnnStringValue(Symbol *symbol, std::string name);
346+
std::string getAnnStringValue(Symbol *symbol, const std::string &name);
347347

348348
/*!
349349
* @brief This function returns vector of data types from scope.

erpcgen/src/SymbolScanner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ void SymbolScanner::addAnnotations(AstNode *childNode, Symbol *symbol)
15351535
const Token &nameTok = annotation_name->getToken();
15361536
Value *annValue = getAnnotationValue(annotation);
15371537

1538-
Annotation ann = Annotation(nameTok, annValue, annLang);
1538+
Annotation ann(nameTok, annValue, annLang);
15391539

15401540
symbol->addAnnotation(ann);
15411541

erpcgen/src/smart_ptr.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ class smart_ptr
7474
return *this;
7575
}
7676

77+
//! To allow setting the pointer directly. Equivalent to a call to set().
78+
smart_ptr<T> &operator=(ptr_type p)
79+
{
80+
set(p);
81+
return *this;
82+
}
83+
7784
//! Destructor. If an object (pointer) has been set, it will be deleted.
7885
//! Deletes the object using safe_delete().
7986
virtual ~smart_ptr() { safe_delete(); }
@@ -133,13 +140,6 @@ class smart_ptr
133140
//! Returns a boolean indicating whether the object has a pointer set or not.
134141
operator bool() const { return _p != nullptr; }
135142

136-
//! To allow setting the pointer directly. Equivalent to a call to set().
137-
smart_ptr<T> &operator=(ptr_type p)
138-
{
139-
set(p);
140-
return *this;
141-
}
142-
143143
//! Another operator to allow you to treat the object just like a pointer.
144144
ptr_type operator->() { return _p; }
145145

erpcgen/src/types/AliasType.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AliasType : public DataType
3434
* @param[in] name Name.
3535
* @param[in] elementType Given data type.
3636
*/
37-
AliasType(std::string name, DataType *elementType)
37+
AliasType(const std::string &name, DataType *elementType)
3838
: DataType(name, kAliasType)
3939
, m_elementType(elementType)
4040
{
@@ -84,7 +84,7 @@ class AliasType : public DataType
8484
* @see std::string ListType::getDescription() const
8585
* @see std::string UnionType::getDescription() const
8686
*/
87-
virtual std::string getDescription() const;
87+
virtual std::string getDescription() const override;
8888

8989
protected:
9090
DataType *m_elementType; /*!< Alias element data type. */

erpcgen/src/types/Annotation.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Annotation
5959
*
6060
* @param[in] token Token contains annotation name and location in parsed file.
6161
*/
62-
Annotation(const Token &token)
62+
explicit Annotation(const Token &token)
6363
: m_name(token.getStringValue())
6464
, m_value(nullptr)
6565
, m_location(token.getLocation())
@@ -74,7 +74,7 @@ class Annotation
7474
*
7575
* @param[in] a Source annotation.
7676
*/
77-
Annotation(const Annotation &a)
77+
explicit Annotation(const Annotation &a)
7878
: m_name(a.m_name)
7979
, m_value(a.m_value)
8080
, m_location(a.m_location)

0 commit comments

Comments
 (0)