diff --git a/cfg/pro_c_sql.cfg b/cfg/pro_c_sql.cfg new file mode 100644 index 000000000..39c151531 --- /dev/null +++ b/cfg/pro_c_sql.cfg @@ -0,0 +1,4 @@ + + + + diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 226b77e56..76039fb3c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1980,12 +1980,12 @@ void Tokenizer::simplifyRoundCurlyParentheses() void Tokenizer::simplifySQL() { for (Token *tok = list.front(); tok; tok = tok->next()) { - if (Token::simpleMatch(tok, "EXEC SQL")) { + if (Token::simpleMatch(tok, "__CPPCHECK_PRO_C_EXEC__ SQL")) { const Token *end = findSQLBlockEnd(tok); if (end == nullptr) syntaxError(nullptr); - std::string instruction = tok->stringifyList(end); + const std::string instruction = tok->stringifyList(end); // delete all tokens until the embedded SQL block end Token::eraseTokens(tok, end); @@ -9893,8 +9893,8 @@ const Token *Tokenizer::findSQLBlockEnd(const Token *tokSQLStart) const for (const Token *tok = tokSQLStart->tokAt(2); tok != nullptr; tok = tok->next()) { if (tokLastEnd == nullptr && tok->str() == ";") tokLastEnd = tok; - else if (tok->str() == "EXEC") { - if (Token::simpleMatch(tok->tokAt(-2), "END - EXEC ;")) + else if (tok->str() == "__CPPCHECK_PRO_C_EXEC__") { + if (Token::simpleMatch(tok->tokAt(-2), "END - __CPPCHECK_PRO_C_EXEC__ ;")) return tok->next(); return tokLastEnd; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ad98e151a..186584e8f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5782,19 +5782,19 @@ private: void simplifySQL() { // Oracle PRO*C extensions for inline SQL. Just replace the SQL with "asm()" to fix wrong error messages // ticket: #1959 - ASSERT_EQUALS("asm ( \"\"EXEC SQL SELECT A FROM B\"\" ) ;", tokenizeAndStringify("EXEC SQL SELECT A FROM B;",false)); - ASSERT_THROW(tokenizeAndStringify("EXEC SQL",false), InternalError); + ASSERT_EQUALS("asm ( \"\"__CPPCHECK_PRO_C_EXEC__ SQL SELECT A FROM B\"\" ) ;", tokenizeAndStringify("__CPPCHECK_PRO_C_EXEC__ SQL SELECT A FROM B;",false)); + ASSERT_THROW(tokenizeAndStringify("__CPPCHECK_PRO_C_EXEC__ SQL",false), InternalError); - ASSERT_EQUALS("asm ( \"\"EXEC SQL EXECUTE BEGIN Proc1 ( A ) ; END ; END - EXEC\"\" ) ; asm ( \"\"EXEC SQL COMMIT\"\" ) ;", - tokenizeAndStringify("EXEC SQL EXECUTE BEGIN Proc1(A); END; END-EXEC; EXEC SQL COMMIT;",false)); - ASSERT_EQUALS("asm ( \"\"EXEC SQL UPDATE A SET B = C\"\" ) ; asm ( \"\"EXEC SQL COMMIT\"\" ) ;", - tokenizeAndStringify("EXEC SQL UPDATE A SET B = C; EXEC SQL COMMIT;",false)); - ASSERT_EQUALS("asm ( \"\"EXEC SQL COMMIT\"\" ) ; asm ( \"\"EXEC SQL EXECUTE BEGIN Proc1 ( A ) ; END ; END - EXEC\"\" ) ;", - tokenizeAndStringify("EXEC SQL COMMIT; EXEC SQL EXECUTE BEGIN Proc1(A); END; END-EXEC;",false)); + ASSERT_EQUALS("asm ( \"\"__CPPCHECK_PRO_C_EXEC__ SQL EXECUTE BEGIN Proc1 ( A ) ; END ; END - __CPPCHECK_PRO_C_EXEC__\"\" ) ; asm ( \"\"__CPPCHECK_PRO_C_EXEC__ SQL COMMIT\"\" ) ;", + tokenizeAndStringify("__CPPCHECK_PRO_C_EXEC__ SQL EXECUTE BEGIN Proc1(A); END; END-__CPPCHECK_PRO_C_EXEC__; __CPPCHECK_PRO_C_EXEC__ SQL COMMIT;",false)); + ASSERT_EQUALS("asm ( \"\"__CPPCHECK_PRO_C_EXEC__ SQL UPDATE A SET B = C\"\" ) ; asm ( \"\"__CPPCHECK_PRO_C_EXEC__ SQL COMMIT\"\" ) ;", + tokenizeAndStringify("__CPPCHECK_PRO_C_EXEC__ SQL UPDATE A SET B = C; __CPPCHECK_PRO_C_EXEC__ SQL COMMIT;",false)); + ASSERT_EQUALS("asm ( \"\"__CPPCHECK_PRO_C_EXEC__ SQL COMMIT\"\" ) ; asm ( \"\"__CPPCHECK_PRO_C_EXEC__ SQL EXECUTE BEGIN Proc1 ( A ) ; END ; END - __CPPCHECK_PRO_C_EXEC__\"\" ) ;", + tokenizeAndStringify("__CPPCHECK_PRO_C_EXEC__ SQL COMMIT; __CPPCHECK_PRO_C_EXEC__ SQL EXECUTE BEGIN Proc1(A); END; END-__CPPCHECK_PRO_C_EXEC__;",false)); - ASSERT_THROW(tokenizeAndStringify("int f(){ EXEC SQL } int a;",false), InternalError); - ASSERT_THROW(tokenizeAndStringify("EXEC SQL int f(){",false), InternalError); - ASSERT_THROW(tokenizeAndStringify("EXEC SQL END-EXEC int a;",false), InternalError); + ASSERT_THROW(tokenizeAndStringify("int f(){ __CPPCHECK_PRO_C_EXEC__ SQL } int a;",false), InternalError); + ASSERT_THROW(tokenizeAndStringify("__CPPCHECK_PRO_C_EXEC__ SQL int f(){",false), InternalError); + ASSERT_THROW(tokenizeAndStringify("__CPPCHECK_PRO_C_EXEC__ SQL END-__CPPCHECK_PRO_C_EXEC__ int a;",false), InternalError); } void simplifyCAlternativeTokens() {