MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / getErrorReturnValue

Method getErrorReturnValue

erpcgen/src/CGenerator.cpp:1878–1952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1876}
1877
1878string CGenerator::getErrorReturnValue(FunctionBase *fn)
1879{
1880 Symbol *symbol = dynamic_cast<Symbol *>(fn);
1881 assert(symbol);
1882
1883 Value *returnVal = getAnnValue(symbol, ERROR_RETURN_ANNOTATION);
1884 DataType *dataType = fn->getReturnType()->getTrueDataType();
1885 if (returnVal)
1886 {
1887 if (returnVal->toString().empty())
1888 {
1889 throw semantic_error(format_string("Expected value for @%s annotation for function on line %d",
1890 ERROR_RETURN_ANNOTATION, symbol->getLocation().m_firstLine));
1891 }
1892 else if (dataType->isString())
1893 {
1894 return (dataType->isUString() ? "(unsigned char *)" : "(char*)") + returnVal->toString();
1895 }
1896 else if (dataType->isScalar())
1897 {
1898 BuiltinType *builtinType = dynamic_cast<BuiltinType *>(dataType);
1899 assert(builtinType);
1900 if (builtinType->getBuiltinType() == BuiltinType::builtin_type_t::kBoolType)
1901 {
1902 IntegerValue *integerValue = dynamic_cast<IntegerValue *>(returnVal);
1903 assert(integerValue);
1904 return (integerValue->getValue()) ? "true" : "false";
1905 }
1906 }
1907 return returnVal->toString();
1908 }
1909 else
1910 {
1911 if (dataType->isScalar())
1912 {
1913 BuiltinType *builtinType = dynamic_cast<BuiltinType *>(dataType);
1914 assert(builtinType);
1915 switch (builtinType->getBuiltinType())
1916 {
1917 case BuiltinType::builtin_type_t::kBoolType:
1918 {
1919 return "false";
1920 }
1921 case BuiltinType::builtin_type_t::kUInt8Type:
1922 {
1923 return "0xFFU";
1924 }
1925 case BuiltinType::builtin_type_t::kUInt16Type:
1926 {
1927 return "0xFFFFU";
1928 }
1929 case BuiltinType::builtin_type_t::kUInt32Type:
1930 {
1931 return "0xFFFFFFFFU";
1932 }
1933 case BuiltinType::builtin_type_t::kUInt64Type:
1934 {
1935 return "0xFFFFFFFFFFFFFFFFU";

Callers

nothing calls this directly

Calls 12

semantic_errorClass · 0.85
format_stringFunction · 0.85
getTrueDataTypeMethod · 0.80
getReturnTypeMethod · 0.80
getBuiltinTypeMethod · 0.80
isEnumMethod · 0.80
emptyMethod · 0.45
toStringMethod · 0.45
isStringMethod · 0.45
isUStringMethod · 0.45
isScalarMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected