@@ -52,320 +52,6 @@ Settings::Settings()
5252 posix = false ;
5353}
5454
55- std::string Settings::Suppressions::parseFile (std::istream &istr)
56- {
57- // Change '\r' to '\n' in the istr
58- std::string filedata;
59- std::string line;
60- while (std::getline (istr, line))
61- filedata += line + " \n " ;
62- while (filedata.find (" \r " ) != std::string::npos)
63- filedata[filedata.find (" \r " )] = ' \n ' ;
64-
65- // Parse filedata..
66- std::istringstream istr2 (filedata);
67- while (std::getline (istr2, line))
68- {
69- // Skip empty lines
70- if (line.empty ())
71- continue ;
72-
73- // Skip comments
74- if (line.length () >= 2 && line[0 ] == ' /' && line[1 ] == ' /' )
75- continue ;
76-
77- const std::string errmsg (addSuppressionLine (line));
78- if (!errmsg.empty ())
79- return errmsg;
80- }
81-
82- return " " ;
83- }
84-
85- std::string Settings::Suppressions::addSuppressionLine (const std::string &line)
86- {
87- std::istringstream lineStream (line);
88- std::string id;
89- std::string file;
90- unsigned int lineNumber = 0 ;
91- if (std::getline (lineStream, id, ' :' ))
92- {
93- if (std::getline (lineStream, file))
94- {
95- // If there is not a dot after the last colon in "file" then
96- // the colon is a separator and the contents after the colon
97- // is a line number..
98-
99- // Get position of last colon
100- const std::string::size_type pos = file.rfind (" :" );
101-
102- // if a colon is found and there is no dot after it..
103- if (pos != std::string::npos &&
104- file.find (" ." , pos) == std::string::npos)
105- {
106- // Try to parse out the line number
107- try
108- {
109- std::istringstream istr1 (file.substr (pos+1 ));
110- istr1 >> lineNumber;
111- }
112- catch (...)
113- {
114- lineNumber = 0 ;
115- }
116-
117- if (lineNumber > 0 )
118- {
119- file.erase (pos);
120- }
121- }
122- }
123- }
124-
125- // We could perhaps check if the id is valid and return error if it is not
126- const std::string errmsg (addSuppression (id, file, lineNumber));
127- if (!errmsg.empty ())
128- return errmsg;
129-
130- return " " ;
131- }
132-
133- bool Settings::Suppressions::FileMatcher::match (const std::string &pattern, const std::string &name)
134- {
135- const char *p = pattern.c_str ();
136- const char *n = name.c_str ();
137- std::stack<std::pair<const char *, const char *> > backtrack;
138-
139- for (;;)
140- {
141- bool matching = true ;
142- while (*p != ' \0 ' && matching)
143- {
144- switch (*p)
145- {
146- case ' *' :
147- // Step forward until we match the next character after *
148- while (*n != ' \0 ' && *n != p[1 ])
149- {
150- n++;
151- }
152- if (*n != ' \0 ' )
153- {
154- // If this isn't the last possibility, save it for later
155- backtrack.push (std::make_pair (p, n));
156- }
157- break ;
158- case ' ?' :
159- // Any character matches unless we're at the end of the name
160- if (*n != ' \0 ' )
161- {
162- n++;
163- }
164- else
165- {
166- matching = false ;
167- }
168- break ;
169- default :
170- // Non-wildcard characters match literally
171- if (*n == *p)
172- {
173- n++;
174- }
175- else
176- {
177- matching = false ;
178- }
179- break ;
180- }
181- p++;
182- }
183-
184- // If we haven't failed matching and we've reached the end of the name, then success
185- if (matching && *n == ' \0 ' )
186- {
187- return true ;
188- }
189-
190- // If there are no other paths to tray, then fail
191- if (backtrack.empty ())
192- {
193- return false ;
194- }
195-
196- // Restore pointers from backtrack stack
197- p = backtrack.top ().first ;
198- n = backtrack.top ().second ;
199- backtrack.pop ();
200-
201- // Advance name pointer by one because the current position didn't work
202- n++;
203- }
204- }
205-
206- std::string Settings::Suppressions::FileMatcher::addFile (const std::string &name, unsigned int line)
207- {
208- if (name.find_first_of (" *?" ) != std::string::npos)
209- {
210- for (std::string::const_iterator i = name.begin (); i != name.end (); ++i)
211- {
212- if (*i == ' *' )
213- {
214- std::string::const_iterator j = i + 1 ;
215- if (j != name.end () && (*j == ' *' || *j == ' ?' ))
216- {
217- return " Failed to add suppression. Syntax error in glob." ;
218- }
219- }
220- }
221- _globs[name][line] = false ;
222- }
223- else if (name.empty ())
224- {
225- _globs[" *" ][0U ] = false ;
226- }
227- else
228- {
229- _files[Path::simplifyPath (name.c_str ())][line] = false ;
230- }
231- return " " ;
232- }
233-
234- bool Settings::Suppressions::FileMatcher::isSuppressed (const std::string &file, unsigned int line)
235- {
236- if (isSuppressedLocal (file, line))
237- return true ;
238-
239- for (std::map<std::string, std::map<unsigned int , bool > >::iterator g = _globs.begin (); g != _globs.end (); ++g)
240- {
241- if (match (g->first , file))
242- {
243- if (g->second .find (0U ) != g->second .end ())
244- {
245- g->second [0U ] = true ;
246- return true ;
247- }
248- std::map<unsigned int , bool >::iterator l = g->second .find (line);
249- if (l != g->second .end ())
250- {
251- l->second = true ;
252- return true ;
253- }
254- }
255- }
256-
257- return false ;
258- }
259-
260- bool Settings::Suppressions::FileMatcher::isSuppressedLocal (const std::string &file, unsigned int line)
261- {
262- std::map<std::string, std::map<unsigned int , bool > >::iterator f = _files.find (file);
263- if (f != _files.end ())
264- {
265- if (f->second .find (0U ) != f->second .end ())
266- {
267- f->second [0U ] = true ;
268- return true ;
269- }
270- std::map<unsigned int , bool >::iterator l = f->second .find (line);
271- if (l != f->second .end ())
272- {
273- l->second = true ;
274- return true ;
275- }
276- }
277-
278- return false ;
279- }
280-
281- std::string Settings::Suppressions::addSuppression (const std::string &errorId, const std::string &file, unsigned int line)
282- {
283- // Check that errorId is valid..
284- if (errorId.empty ())
285- {
286- return " Failed to add suppression. No id." ;
287- }
288- if (errorId != " *" )
289- {
290- for (std::string::size_type pos = 0 ; pos < errorId.length (); ++pos)
291- {
292- if (errorId[pos] < 0 || !std::isalnum (errorId[pos]))
293- {
294- return " Failed to add suppression. Invalid id \" " + errorId + " \" " ;
295- }
296- if (pos == 0 && std::isdigit (errorId[pos]))
297- {
298- return " Failed to add suppression. Invalid id \" " + errorId + " \" " ;
299- }
300- }
301- }
302-
303- return _suppressions[errorId].addFile (file, line);
304- }
305-
306- bool Settings::Suppressions::isSuppressed (const std::string &errorId, const std::string &file, unsigned int line)
307- {
308- if (errorId != " unmatchedSuppression" && _suppressions.find (" *" ) != _suppressions.end ())
309- if (_suppressions[" *" ].isSuppressed (file, line))
310- return true ;
311-
312- if (_suppressions.find (errorId) == _suppressions.end ())
313- return false ;
314-
315- return _suppressions[errorId].isSuppressed (file, line);
316- }
317-
318- bool Settings::Suppressions::isSuppressedLocal (const std::string &errorId, const std::string &file, unsigned int line)
319- {
320- if (errorId != " unmatchedSuppression" && _suppressions.find (" *" ) != _suppressions.end ())
321- if (_suppressions[" *" ].isSuppressedLocal (file, line))
322- return true ;
323-
324- if (_suppressions.find (errorId) == _suppressions.end ())
325- return false ;
326-
327- return _suppressions[errorId].isSuppressedLocal (file, line);
328- }
329-
330- std::list<Settings::Suppressions::SuppressionEntry> Settings::Suppressions::getUnmatchedLocalSuppressions (const std::string &file) const
331- {
332- std::list<SuppressionEntry> r;
333- for (std::map<std::string, FileMatcher>::const_iterator i = _suppressions.begin (); i != _suppressions.end (); ++i)
334- {
335- std::map<std::string, std::map<unsigned int , bool > >::const_iterator f = i->second ._files .find (file);
336- if (f != i->second ._files .end ())
337- {
338- for (std::map<unsigned int , bool >::const_iterator l = f->second .begin (); l != f->second .end (); ++l)
339- {
340- if (!l->second )
341- {
342- r.push_back (SuppressionEntry (i->first , f->first , l->first ));
343- }
344- }
345- }
346- }
347- return r;
348- }
349-
350- std::list<Settings::Suppressions::SuppressionEntry> Settings::Suppressions::getUnmatchedGlobalSuppressions () const
351- {
352- std::list<SuppressionEntry> r;
353- for (std::map<std::string, FileMatcher>::const_iterator i = _suppressions.begin (); i != _suppressions.end (); ++i)
354- {
355- for (std::map<std::string, std::map<unsigned int , bool > >::const_iterator g = i->second ._globs .begin (); g != i->second ._globs .end (); ++g)
356- {
357- for (std::map<unsigned int , bool >::const_iterator l = g->second .begin (); l != g->second .end (); ++l)
358- {
359- if (!l->second )
360- {
361- r.push_back (SuppressionEntry (i->first , g->first , l->first ));
362- }
363- }
364- }
365- }
366- return r;
367- }
368-
36955std::string Settings::addEnabled (const std::string &str)
37056{
37157 // Enable parameters may be comma separated...
0 commit comments