Skip to content

Commit

Permalink
Merge pull request #125 from pgu-swir/ustring
Browse files Browse the repository at this point in the history
add ustring builtin type (unsigned char*)
  • Loading branch information
MichalPrincNXP authored Oct 5, 2020
2 parents 7539f87 + 1bc5a1f commit 6cbc39c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
7 changes: 5 additions & 2 deletions erpcgen/src/CGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@ string CGenerator::getErrorReturnValue(FunctionBase *fn)
}
else if (dataType->isString())
{
return "(char *) " + returnVal->toString();
return (dataType->isUString() ? "(unsigned char *)" : "(char*)") + returnVal->toString();
}
else if (dataType->isScalar())
{
Expand Down Expand Up @@ -2245,6 +2245,8 @@ string CGenerator::getBuiltinTypename(const BuiltinType *t)
return "double";
case BuiltinType::kStringType:
return "char *";
case BuiltinType::kUStringType:
return "unsigned char*";
case BuiltinType::kBinaryType:
return "uint8_t *";
default:
Expand Down Expand Up @@ -2296,6 +2298,7 @@ void CGenerator::getEncodeDecodeBuiltin(Group *group, BuiltinType *t, data_map &
templateData["freeingCall"] = m_templateData["freeData"];
// needDealloc(templateData, t, structType, nullptr);
templateData["builtinType"] = "kStringType";
templateData["builtinTypeName"] = t->isUString() ? "unsigned char*" : "char*";
}
else
{
Expand Down Expand Up @@ -3060,7 +3063,7 @@ data_map CGenerator::allocateCall(const string &name, Symbol *symbol)
else
{
typeValue = "char";
typePointerValue = "char *";
typePointerValue = dataType->isUString() ? "unsigned char*" : "char *";
}

alloc["name"] = name.c_str();
Expand Down
1 change: 1 addition & 0 deletions erpcgen/src/InterfaceDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void InterfaceDefinition::createBuiltinTypes()
m_globals.addSymbol(new BuiltinType("float", BuiltinType::_builtin_type::kFloatType));
m_globals.addSymbol(new BuiltinType("double", BuiltinType::_builtin_type::kDoubleType));
m_globals.addSymbol(new BuiltinType("string", BuiltinType::_builtin_type::kStringType));
m_globals.addSymbol(new BuiltinType("ustring", BuiltinType::_builtin_type::kUStringType));
m_globals.addSymbol(new BuiltinType("binary", BuiltinType::_builtin_type::kBinaryType));
}

Expand Down
4 changes: 2 additions & 2 deletions erpcgen/src/templates/c_coders.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ uint32_t {$info.stringLocalName}_len;
char * {$info.stringLocalName}_local;
codec->readString(&{$info.stringLocalName}_len, &{$info.stringLocalName}_local);
{% if ((source == "client" && info.withoutAlloc == false) or source == "server") %}
{$info.name} = (char *) erpc_malloc(({$info.stringAllocSize} + 1) * sizeof(char));
{$info.name} = ({$info.builtinTypeName}) erpc_malloc(({$info.stringAllocSize} + 1) * sizeof(char));
{% if generateAllocErrorChecks == true %}
if ({$info.name} == NULL)
{
Expand Down Expand Up @@ -232,7 +232,7 @@ codec->readData({$info.name}, {$info.sizeTemp} * sizeof({$info.builtinTypeName})
{# Encode sending data #}
{% def encodeBuiltinType(info) ----------------- %}
{% if info.builtinType == "kStringType" %}
codec->writeString(strlen({$info.name}), {$info.name});
codec->writeString(strlen((const char*){$info.name}), (const char*){$info.name});
{% else %}
{% if source == "client" && info.pointerScalarTypes %}
codec->write(*{$info.name});
Expand Down
15 changes: 12 additions & 3 deletions erpcgen/src/types/BuiltinType.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class BuiltinType : public DataType
kFloatType,
kDoubleType,
kStringType,
kUStringType,
kBinaryType
};

Expand Down Expand Up @@ -108,10 +109,18 @@ class BuiltinType : public DataType
/*!
* @brief This function return true/false value for identify string type.
*
* @retval true When builtin type is string.
* @retval false When builtin type isn't string.
* @retval true When builtin type is string or ustring.
* @retval false When builtin type isn't string or ustring.
*/
virtual bool isString() const { return m_builtinType == kStringType; }
virtual bool isString() const { return m_builtinType == kStringType || m_builtinType == kUStringType; }

/*!
* @brief This function return true/false value for identify ustring type.
*
* @retval true When builtin type is ustring.
* @retval false When builtin type isn't ustring.
*/
virtual bool isUString() const { return m_builtinType == kUStringType; }

/*!
* @brief This function return true/false value for identify binary type.
Expand Down
7 changes: 7 additions & 0 deletions erpcgen/src/types/DataType.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ class DataType : public Symbol
* @retval false Always return false.
*/
virtual bool isString() const { return false; }

/*!
* @brief This function return "false" value as default for identify ustring type.
*
* @retval false Always return false.
*/
virtual bool isUString() const { return false; }

/*!
* @brief This function return "false" value as default for identify struct type.
Expand Down

0 comments on commit 6cbc39c

Please sign in to comment.