From 61b1b36153f209bc1ac65bb415c725f381cbcb04 Mon Sep 17 00:00:00 2001 From: Dusan Cervenka Date: Fri, 9 Feb 2024 16:33:17 +0100 Subject: [PATCH] align switch brackets (#396) Signed-off-by: Cervenka Dusan Co-authored-by: Michal Princ --- .../transports/erpc_i2c_slave_transport.cpp | 10 +++ .../transports/erpc_lpi2c_slave_transport.cpp | 8 +++ erpcgen/src/AstNode.cpp | 2 + erpcgen/src/AstWalker.cpp | 34 ++++++++++ erpcgen/src/CGenerator.cpp | 47 ++++++++++++++ erpcgen/src/ErpcLexer.cpp | 22 +++++++ erpcgen/src/HexValues.cpp | 8 +++ erpcgen/src/PythonGenerator.cpp | 43 ++++++++++++- erpcgen/src/SymbolScanner.cpp | 63 ++++++++++++++++++- erpcgen/src/erpcgen.cpp | 26 ++++++++ erpcgen/src/types/Type.cpp | 2 + erpcsniffer/src/Sniffer.cpp | 2 + erpcsniffer/src/erpcsniffer.cpp | 8 +++ test/test_lists/test_lists_client_impl.cpp | 6 ++ test/test_unions/test_unions_server_impl.cpp | 1 + 15 files changed, 280 insertions(+), 2 deletions(-) diff --git a/erpc_c/transports/erpc_i2c_slave_transport.cpp b/erpc_c/transports/erpc_i2c_slave_transport.cpp index b96224f8..d90cb287 100644 --- a/erpc_c/transports/erpc_i2c_slave_transport.cpp +++ b/erpc_c/transports/erpc_i2c_slave_transport.cpp @@ -108,39 +108,49 @@ static void I2C_SlaveUserCallback(I2C_Type *base, volatile i2c_slave_transfer_t { /* Address match event */ case kI2C_SlaveAddressMatchEvent: + { transfer->rxData = NULL; transfer->rxSize = 0; break; + } /* Transmit request */ case kI2C_SlaveTransmitEvent: + { /* Update information for transmit process */ transfer->txData = ((I2C_CLB_USER_DATA *)userData)->tx_buffer; transfer->txSize = ((I2C_CLB_USER_DATA *)userData)->tx_size; transfer->rxData = NULL; transfer->rxSize = 0; break; + } /* Setup the slave receive buffer */ case kI2C_SlaveReceiveEvent: + { /* Update information for received process */ transfer->rxData = ((I2C_CLB_USER_DATA *)userData)->rx_buffer; transfer->rxSize = ((I2C_CLB_USER_DATA *)userData)->rx_size; transfer->txData = NULL; transfer->txSize = 0; break; + } /* The master has sent a stop transition on the bus */ case kI2C_SlaveCompletionEvent: + { transport->transfer_cb(); transfer->rxData = NULL; transfer->rxSize = 0; transfer->txData = NULL; transfer->txSize = 0; break; + } default: + { s_isTransferCompleted = false; break; + } } } diff --git a/erpc_c/transports/erpc_lpi2c_slave_transport.cpp b/erpc_c/transports/erpc_lpi2c_slave_transport.cpp index 6a2a6769..5b618dd2 100644 --- a/erpc_c/transports/erpc_lpi2c_slave_transport.cpp +++ b/erpc_c/transports/erpc_lpi2c_slave_transport.cpp @@ -108,20 +108,25 @@ static void LPI2C_SlaveUserCallback(LPI2C_Type *base, lpi2c_slave_transfer_t *tr { /* Transmit request */ case kLPI2C_SlaveTransmitEvent: + { /* Update information for transmit process */ transfer->data = ((LPI2C_CLB_USER_DATA *)userData)->tx_buffer; transfer->dataSize = ((LPI2C_CLB_USER_DATA *)userData)->tx_size; break; + } /* Setup the slave receive buffer */ case kLPI2C_SlaveReceiveEvent: + { /* Update information for received process */ transfer->data = ((LPI2C_CLB_USER_DATA *)userData)->rx_buffer; transfer->dataSize = ((LPI2C_CLB_USER_DATA *)userData)->rx_size; break; + } /* The master has sent a stop transition on the bus */ case kLPI2C_SlaveCompletionEvent: + { /* Filter out dummy transaction completions (additional dummy recv./transmit) */ if (!(transfer->transferredCount == 0 && transfer->dataSize == 0) && transfer->data != NULL) { @@ -130,10 +135,13 @@ static void LPI2C_SlaveUserCallback(LPI2C_Type *base, lpi2c_slave_transfer_t *tr transfer->dataSize = 0; } break; + } default: + { s_isTransferCompleted = false; break; + } } } diff --git a/erpcgen/src/AstNode.cpp b/erpcgen/src/AstNode.cpp index 05b868b7..278487c2 100644 --- a/erpcgen/src/AstNode.cpp +++ b/erpcgen/src/AstNode.cpp @@ -217,7 +217,9 @@ string AstNode::getDescription() const case TOK_UNARY_NEGATE: case TOK_ARRAY: case TOK_UNION_CASE: + { break; + } default: { output += " " + valToString + " "; diff --git a/erpcgen/src/AstWalker.cpp b/erpcgen/src/AstWalker.cpp index 2d898d6c..a473bb46 100644 --- a/erpcgen/src/AstWalker.cpp +++ b/erpcgen/src/AstWalker.cpp @@ -62,49 +62,79 @@ void AstWalker::dispatch(AstNode *node) switch (tok.getToken()) { case TOK_PROGRAM: + { rewrite = handleProgram(node, dir); break; + } case TOK_CHILDREN: + { break; + } case TOK_TYPE: + { rewrite = handleType(node, dir); break; + } case TOK_ENUM: + { rewrite = handleEnum(node, dir); break; + } case TOK_ENUM_MEMBER: + { rewrite = handleEnumMember(node, dir); break; + } case TOK_STRUCT: + { rewrite = handleStruct(node, dir); break; + } case TOK_STRUCT_MEMBER: + { rewrite = handleStructMember(node, dir); break; + } case TOK_UNION: + { rewrite = handleUnion(node, dir); break; + } case TOK_UNION_CASE: + { rewrite = handleUnionCase(node, dir); break; + } case TOK_INTERFACE: + { rewrite = handleInterface(node, dir); break; + } case TOK_FUNCTION: + { rewrite = handleFunction(node, dir); break; + } case TOK_PARAM: + { rewrite = handleParam(node, dir); break; + } case TOK_CONST: + { rewrite = handleConst(node, dir); break; + } case TOK_EXPR: + { rewrite = handleExpr(node, dir); break; + } case TOK_ANNOTATION: + { rewrite = handleAnnotation(node, dir); break; + } case '+': case '-': case '*': @@ -115,12 +145,16 @@ void AstWalker::dispatch(AstNode *node) case '^': case TOK_LSHIFT: case TOK_RSHIFT: + { rewrite = handleBinaryOp(node, dir); break; + } case TOK_UNARY_NEGATE: case '~': + { rewrite = handleUnaryOp(node, dir); break; + } } if (rewrite) diff --git a/erpcgen/src/CGenerator.cpp b/erpcgen/src/CGenerator.cpp index f891a06a..16b86311 100644 --- a/erpcgen/src/CGenerator.cpp +++ b/erpcgen/src/CGenerator.cpp @@ -821,7 +821,9 @@ void CGenerator::makeAliasesTemplateData() break; } default: + { throw internal_error("Only structs or enums are allowed as unnamed types."); + } } } aliases.push_back(aliasInfo); @@ -2268,8 +2270,11 @@ string CGenerator::getTypenameName(DataType *t, const string &name) break; } default: + { throw internal_error(format_string("In getTypenameName: unknown data type: %s value:%d", t->getName().c_str(), t->getDataType())); + break; + } } return returnName; } @@ -2279,35 +2284,65 @@ string CGenerator::getBuiltinTypename(const BuiltinType *t) switch (t->getBuiltinType()) { case BuiltinType::builtin_type_t::kBoolType: + { return "bool"; + } case BuiltinType::builtin_type_t::kInt8Type: + { return "int8_t"; + } case BuiltinType::builtin_type_t::kInt16Type: + { return "int16_t"; + } case BuiltinType::builtin_type_t::kInt32Type: + { return "int32_t"; + } case BuiltinType::builtin_type_t::kInt64Type: + { return "int64_t"; + } case BuiltinType::builtin_type_t::kUInt8Type: + { return "uint8_t"; + } case BuiltinType::builtin_type_t::kUInt16Type: + { return "uint16_t"; + } case BuiltinType::builtin_type_t::kUInt32Type: + { return "uint32_t"; + } case BuiltinType::builtin_type_t::kUInt64Type: + { return "uint64_t"; + } case BuiltinType::builtin_type_t::kFloatType: + { return "float"; + } case BuiltinType::builtin_type_t::kDoubleType: + { return "double"; + } case BuiltinType::builtin_type_t::kStringType: + { return "char *"; + } case BuiltinType::builtin_type_t::kUStringType: + { return "unsigned char*"; + } case BuiltinType::builtin_type_t::kBinaryType: + { return "uint8_t *"; + } default: + { throw internal_error("unknown builtin type"); + } } } @@ -3039,7 +3074,9 @@ bool CGenerator::isNeedCallFree(DataType *dataType) return false; } default: + { return false; + } } } @@ -3422,15 +3459,25 @@ string CGenerator::getDirection(param_direction_t direction) switch (direction) { case param_direction_t::kInDirection: + { return "kInDirection"; + } case param_direction_t::kOutDirection: + { return "kOutDirection"; + } case param_direction_t::kInoutDirection: + { return "kInoutDirection"; + } case param_direction_t::kReturn: + { return "kReturn"; + } default: + { throw semantic_error("Unsupported direction type"); + } } } diff --git a/erpcgen/src/ErpcLexer.cpp b/erpcgen/src/ErpcLexer.cpp index d3763b86..4883fbf3 100644 --- a/erpcgen/src/ErpcLexer.cpp +++ b/erpcgen/src/ErpcLexer.cpp @@ -82,7 +82,9 @@ int ErpcLexer::processStringEscapes(const char *in, char *out) switch (c) { case 0: // end of the string, bail + { break; + } case 'x': { // start of a hex char escape sequence @@ -90,10 +92,14 @@ int ErpcLexer::processStringEscapes(const char *in, char *out) // read high and low nibbles, checking for end of string char hi = *++in; if (hi == 0) + { break; + } char lo = *++in; if (lo == 0) + { break; + } if (isHexDigit(hi) && isHexDigit(lo)) { @@ -111,41 +117,57 @@ int ErpcLexer::processStringEscapes(const char *in, char *out) break; } case 'n': + { *out++ = '\n'; count++; break; + } case 't': + { *out++ = '\t'; count++; break; + } case 'r': + { *out++ = '\r'; count++; break; + } case 'b': + { *out++ = '\b'; count++; break; + } case 'f': + { *out++ = '\f'; count++; break; + } case '0': + { *out++ = '\0'; count++; break; + } default: + { *out++ = c; count++; break; + } } break; } default: + { // copy all other chars directly *out++ = *in++; count++; + } } } diff --git a/erpcgen/src/HexValues.cpp b/erpcgen/src/HexValues.cpp index a1190993..63e5fb58 100644 --- a/erpcgen/src/HexValues.cpp +++ b/erpcgen/src/HexValues.cpp @@ -21,13 +21,21 @@ bool isHexDigit(char c) uint8_t hexCharToInt(char c) { if (c >= '0' && c <= '9') + { return c - '0'; + } else if (c >= 'a' && c <= 'f') + { return c - 'a' + 10; + } else if (c >= 'A' && c <= 'F') + { return c - 'A' + 10; + } else + { return static_cast(-1); + } } //! \param encodedByte Must point to at least two ASCII hex characters. diff --git a/erpcgen/src/PythonGenerator.cpp b/erpcgen/src/PythonGenerator.cpp index 3c1f581f..680c5e89 100644 --- a/erpcgen/src/PythonGenerator.cpp +++ b/erpcgen/src/PythonGenerator.cpp @@ -237,20 +237,29 @@ data_map PythonGenerator::getFunctionTemplateData(Group *group, Function *fn) switch (dir) { case param_direction_t::kInDirection: + { paramInfo["direction"] = "in"; inParams.push_back(paramInfo); break; + } case param_direction_t::kOutDirection: + { paramInfo["direction"] = "out"; outParams.push_back(paramInfo); break; + } case param_direction_t::kInoutDirection: + { paramInfo["direction"] = "inout"; inParams.push_back(paramInfo); outParams.push_back(paramInfo); break; + } default: + { paramInfo["direction"] = "none"; + break; + } } params.push_back(paramInfo); @@ -516,7 +525,9 @@ data_map PythonGenerator::makeGroupSymbolsTemplateData(Group *group) break; } default: + { break; + } } } } @@ -701,7 +712,7 @@ data_map PythonGenerator::getTypeInfo(DataType *t) { EnumType *enumType = dynamic_cast(it); assert(enumType); - for (auto itMember : enumType->getMembers()) + for (const auto itMember : enumType->getMembers()) { if (unionCase->getCaseName() == itMember->getName()) { @@ -777,7 +788,9 @@ data_map PythonGenerator::getTypeInfo(DataType *t) break; } default: + { throw internal_error("unknown data type"); + } } return info; } @@ -787,33 +800,61 @@ string PythonGenerator::getBuiltinTypename(const BuiltinType *t) switch (t->getBuiltinType()) { case BuiltinType::builtin_type_t::kBoolType: + { return "bool"; + } case BuiltinType::builtin_type_t::kInt8Type: + { return "int8"; + } case BuiltinType::builtin_type_t::kInt16Type: + { return "int16"; + } case BuiltinType::builtin_type_t::kInt32Type: + { return "int32"; + } case BuiltinType::builtin_type_t::kInt64Type: + { return "int64"; + } case BuiltinType::builtin_type_t::kUInt8Type: + { return "uint8"; + } case BuiltinType::builtin_type_t::kUInt16Type: + { return "uint16"; + } case BuiltinType::builtin_type_t::kUInt32Type: + { return "uint32"; + } case BuiltinType::builtin_type_t::kUInt64Type: + { return "uint64"; + } case BuiltinType::builtin_type_t::kFloatType: + { return "float"; + } case BuiltinType::builtin_type_t::kDoubleType: + { return "double"; + } case BuiltinType::builtin_type_t::kStringType: + { return "string"; + } case BuiltinType::builtin_type_t::kBinaryType: + { return "binary"; + } default: + { throw internal_error("unknown builtin type"); + } } } diff --git a/erpcgen/src/SymbolScanner.cpp b/erpcgen/src/SymbolScanner.cpp index c47b5f23..9b752654 100644 --- a/erpcgen/src/SymbolScanner.cpp +++ b/erpcgen/src/SymbolScanner.cpp @@ -406,15 +406,22 @@ AstNode *SymbolScanner::handleBinaryOp(AstNode *node, bottom_up) switch (tok.getToken()) { case '+': + { result = l + r; break; + } case '-': + { result = l - r; break; + } case '*': + { result = l * r; break; + } case '/': + { // Just make the result a zero if div-by-zero. if (r == 0) { @@ -425,7 +432,9 @@ AstNode *SymbolScanner::handleBinaryOp(AstNode *node, bottom_up) result = l / r; } break; + } case '%': + { // Just make the result a zero if div-by-zero. if (r == 0) { @@ -436,23 +445,36 @@ AstNode *SymbolScanner::handleBinaryOp(AstNode *node, bottom_up) result = l % r; } break; + } case '&': + { result = l & r; break; + } case '|': + { result = l | r; break; + } case '^': + { result = l ^ r; break; + } case TOK_LSHIFT: + { result = l << r; break; + } case TOK_RSHIFT: + { result = l >> r; break; + } default: + { throw internal_error("unknown binary operator"); + } } IntegerValue::int_type_t intType; @@ -504,15 +526,22 @@ AstNode *SymbolScanner::handleBinaryOp(AstNode *node, bottom_up) switch (tok.getToken()) { case '+': + { result = l + r; break; + } case '-': + { result = l - r; break; + } case '*': + { result = l * r; break; + } case '/': + { /* Just make the result a zero if div-by-zero. */ if (r == 0) { @@ -523,6 +552,7 @@ AstNode *SymbolScanner::handleBinaryOp(AstNode *node, bottom_up) result = l / r; } break; + } /* Throw semantic error on invalid operators for floats. */ case '%': @@ -531,9 +561,13 @@ AstNode *SymbolScanner::handleBinaryOp(AstNode *node, bottom_up) case '^': case TOK_LSHIFT: case TOK_RSHIFT: + { throw semantic_error(format_string("line %d: invalid operator on float value", tok.getFirstLine())); + } default: + { throw internal_error("unknown binary operator"); + } } resultNode = new AstNode(Token(TOK_FLOAT_LITERAL, new FloatValue(result))); @@ -579,13 +613,19 @@ AstNode *SymbolScanner::handleUnaryOp(AstNode *node, bottom_up) switch (tok.getToken()) { case TOK_UNARY_NEGATE: + { value = (-(int64_t)(value)); break; + } case '~': + { value = ~value; break; + } default: + { throw internal_error("unknown unary operator"); + } } return new AstNode(Token(TOK_INT_LITERAL, new IntegerValue(value, valueInt->getIntType()))); @@ -596,15 +636,21 @@ AstNode *SymbolScanner::handleUnaryOp(AstNode *node, bottom_up) switch (tok.getToken()) { case TOK_UNARY_NEGATE: + { value = -value; return new AstNode(Token(TOK_FLOAT_LITERAL, new FloatValue(value))); + } // It is a semantic error to use the binary invert operator on a float. case '~': + { throw semantic_error(format_string("line %d: invalid operator on float value", tok.getFirstLine())); + } default: + { throw internal_error("unknown unary operator"); + } } } @@ -1116,18 +1162,24 @@ AstNode *SymbolScanner::handleFunction(AstNode *node, top_down) switch (returnTypeToken.getToken()) { case TOK_ONEWAY: + { func->setIsOneway(true); func->setReturnStructMemberType(new StructMember("(return)", new VoidType)); break; + } case TOK_VOID: + { func->setReturnStructMemberType(new StructMember("(return)", new VoidType)); break; + } default: + { DataType *dataType = lookupDataType(returnTypeNode); func->setReturnStructMemberType(new StructMember("(return)", dataType)); break; + } } if (returnTypeToken.getToken() != TOK_ONEWAY) { @@ -1382,19 +1434,26 @@ void SymbolScanner::setParameterDirection(StructMember *param, AstNode *directio switch (directionNode->getToken().getToken()) { case TOK_IN: + { param_direction = param_direction_t::kInDirection; break; + } case TOK_OUT: + { param_direction = param_direction_t::kOutDirection; break; + } case TOK_INOUT: + { param_direction = param_direction_t::kInoutDirection; break; + } default: + { delete param; throw semantic_error(format_string("line %d: expected parameter direction type", directionNode->getToken().getFirstLine())); - break; + } } } else /* if no direction specified, default case is an 'in' variable */ @@ -1474,8 +1533,10 @@ DataType *SymbolScanner::lookupDataType(const AstNode *typeNode) return lookupDataTypeByName(typeNode->getChild(3)->getToken(), &(m_currentStruct->getScope()), false); } default: + { throw internal_error(format_string("unexpected token type %s on line %d", typeToken.getTokenName(), typeToken.getLocation().m_firstLine)); + } } } diff --git a/erpcgen/src/erpcgen.cpp b/erpcgen/src/erpcgen.cpp index e5288c72..fe520d2c 100644 --- a/erpcgen/src/erpcgen.cpp +++ b/erpcgen/src/erpcgen.cpp @@ -171,27 +171,37 @@ class erpcgenTool switch (optchar) { case '?': + { printUsage(options); return 0; + } case 'V': + { printf("%s %s\n%s\n", k_toolName, k_version, k_copyright); return 0; + } case 'o': + { m_outputFilePath = optarg; break; + } case 'v': + { if (m_verboseType != verbose_type_t::kExtraDebug) { m_verboseType = (verbose_type_t)(((int)m_verboseType) + 1); } break; + } case 'I': + { PathSearcher::getGlobalSearcher().addSearchPath(optarg); break; + } case 'g': { @@ -238,9 +248,11 @@ class erpcgenTool } default: + { Log::error("error: unrecognized option\n\n"); printUsage(options); return 0; + } } } @@ -325,15 +337,21 @@ class erpcgenTool switch (m_outputLanguage) { case languages_t::kCLanguage: + { CGenerator(&def).generate(); break; + } case languages_t::kPythonLanguage: + { PythonGenerator(&def).generate(); break; + } case languages_t::kJavaLanguage: + { // TODO: Check java package JavaGenerator(&def, m_javaPackageName).generate(); break; + } } } catch (exception &e) @@ -373,17 +391,25 @@ class erpcgenTool switch (m_verboseType) { case verbose_type_t::kWarning: + { Log::getLogger()->setFilterLevel(Logger::log_level_t::kWarning); break; + } case verbose_type_t::kInfo: + { Log::getLogger()->setFilterLevel(Logger::log_level_t::kInfo); break; + } case verbose_type_t::kDebug: + { Log::getLogger()->setFilterLevel(Logger::log_level_t::kDebug); break; + } case verbose_type_t::kExtraDebug: + { Log::getLogger()->setFilterLevel(Logger::log_level_t::kDebug2); break; + } } } }; diff --git a/erpcgen/src/types/Type.cpp b/erpcgen/src/types/Type.cpp index 78ba49f7..748d6a25 100644 --- a/erpcgen/src/types/Type.cpp +++ b/erpcgen/src/types/Type.cpp @@ -488,7 +488,9 @@ DataType *DataType::getTrueContainerDataType() return a->getElementType()->getTrueContainerDataType(); } default: + { return trueDataType; + } } } diff --git a/erpcsniffer/src/Sniffer.cpp b/erpcsniffer/src/Sniffer.cpp index fd363a92..5e7007b7 100644 --- a/erpcsniffer/src/Sniffer.cpp +++ b/erpcsniffer/src/Sniffer.cpp @@ -690,7 +690,9 @@ string Sniffer::getDataTypeName(DataType *dataType) return "void"; } default: + { return dataType->getName(); + } } } diff --git a/erpcsniffer/src/erpcsniffer.cpp b/erpcsniffer/src/erpcsniffer.cpp index 80b94735..5839084a 100644 --- a/erpcsniffer/src/erpcsniffer.cpp +++ b/erpcsniffer/src/erpcsniffer.cpp @@ -415,17 +415,25 @@ class erpcsnifferTool switch (m_verboseType) { case verbose_type_t::kWarning: + { Log::getLogger()->setFilterLevel(Logger::log_level_t::kWarning); break; + } case verbose_type_t::kInfo: + { Log::getLogger()->setFilterLevel(Logger::log_level_t::kInfo); break; + } case verbose_type_t::kDebug: + { Log::getLogger()->setFilterLevel(Logger::log_level_t::kDebug); break; + } case verbose_type_t::kExtraDebug: + { Log::getLogger()->setFilterLevel(Logger::log_level_t::kDebug2); break; + } } } }; diff --git a/test/test_lists/test_lists_client_impl.cpp b/test/test_lists/test_lists_client_impl.cpp index f648712a..f6706d65 100644 --- a/test/test_lists/test_lists_client_impl.cpp +++ b/test/test_lists/test_lists_client_impl.cpp @@ -205,14 +205,20 @@ TEST(test_list, SendReceived2Enum) switch (j) { case 0: + { *list_s = red; break; + } case 1: + { *list_s = green; break; + } case 2: + { *list_s = blue; break; + } } ++list_s; } diff --git a/test/test_unions/test_unions_server_impl.cpp b/test/test_unions/test_unions_server_impl.cpp index 8c2140d1..55c2d785 100644 --- a/test/test_unions/test_unions_server_impl.cpp +++ b/test/test_unions/test_unions_server_impl.cpp @@ -87,6 +87,7 @@ gapGenericEvent_t *testGenericCallback(const gapGenericEvent_t *event) case gAdvTxPowerLevelRead_c: default: { + break; } } return newEvent;