@@ -76,27 +76,69 @@ namespace {
7676 };
7777}
7878
79- static void inlineSuppressions (const simplecpp::TokenList &tokens, Settings & mSettings , std::list<BadInlineSuppression> *bad)
79+ static void parseCommentToken (const simplecpp::Token *tok, std::list<Suppressions::Suppression> &inlineSuppressions , std::list<BadInlineSuppression> *bad)
8080{
81- std::list<Suppressions::Suppression> inlineSuppressions;
82- for (const simplecpp::Token *tok = tokens.cfront (); tok; tok = tok->next ) {
83- if (tok->comment ) {
84- Suppressions::Suppression s;
81+ const std::size_t position=tok->str ().find (" cppcheck-suppress" );
82+ if (position != std::string::npos) {
83+ if ((tok->str ().length () > position+17 ) && (tok->str ()[position+17 ] == ' [' )) { // multi suppress format
8584 std::string errmsg;
86- if (!s.parseComment (tok->str (), &errmsg))
87- continue ;
85+ std::vector<Suppressions::Suppression> ss;
86+ ss = Suppressions::parseMultiSuppressComment (tok->str (), &errmsg);
87+
8888 if (!errmsg.empty ())
8989 bad->push_back (BadInlineSuppression (tok->location , errmsg));
90+
91+ for (std::vector<Suppressions::Suppression>::iterator iter = ss.begin (); iter!=ss.end (); ++iter) {
92+ if (!(*iter).errorId .empty ())
93+ inlineSuppressions.push_back (*iter);
94+ }
95+ }
96+ else { // single suppress format
97+ std::string errmsg;
98+ Suppressions::Suppression s;
99+ if (!s.parseComment (tok->str (), &errmsg))
100+ return ;
101+
90102 if (!s.errorId .empty ())
91103 inlineSuppressions.push_back (s);
104+
105+ if (!errmsg.empty ())
106+ bad->push_back (BadInlineSuppression (tok->location , errmsg));
107+ }
108+ }
109+
110+ return ;
111+ }
112+
113+ static void inlineSuppressions (const simplecpp::TokenList &tokens, Settings &mSettings , std::list<BadInlineSuppression> *bad)
114+ {
115+ const simplecpp::Token *current_non_comment_tok;
116+ std::list<Suppressions::Suppression> inlineSuppressions;
117+
118+ for (const simplecpp::Token *tok = tokens.cfront (); tok; /* none*/ ) {
119+ // parse all comment before current non-comment tok
120+ if (tok->comment ) {
121+ parseCommentToken (tok, inlineSuppressions, bad);
122+ tok = tok->next ;
92123 continue ;
93124 }
94125
95- if (inlineSuppressions.empty ())
126+ current_non_comment_tok = tok;
127+
128+ // parse all comment tok after current non-comment tok in the same line
129+ for (tok = tok->next ; tok; tok = tok->next ) {
130+ if ((tok->location .line != current_non_comment_tok->location .line ) || !(tok->comment ))
131+ break ;
132+ parseCommentToken (tok, inlineSuppressions, bad);
133+ }
134+
135+ // if there is no suppress, jump it!
136+ if (inlineSuppressions.empty ()) {
96137 continue ;
138+ }
97139
98140 // Relative filename
99- std::string relativeFilename (tok ->location .file ());
141+ std::string relativeFilename (current_non_comment_tok ->location .file ());
100142 if (mSettings .relativePaths ) {
101143 for (const std::string & basePath : mSettings .basePaths ) {
102144 const std::string bp = basePath + " /" ;
@@ -110,7 +152,7 @@ static void inlineSuppressions(const simplecpp::TokenList &tokens, Settings &mSe
110152 // Add the suppressions.
111153 for (Suppressions::Suppression &suppr : inlineSuppressions) {
112154 suppr.fileName = relativeFilename;
113- suppr.lineNumber = tok ->location .line ;
155+ suppr.lineNumber = current_non_comment_tok ->location .line ;
114156 mSettings .nomsg .addSuppression (suppr);
115157 }
116158 inlineSuppressions.clear ();
0 commit comments