@@ -48,18 +48,24 @@ def find_xml_generator(name=None):
4848
4949 if name is None :
5050 name = "gccxml"
51- p = subprocess .Popen ([command , name ], stdout = subprocess .PIPE )
51+ p = subprocess .Popen ([command , name ], stdout = subprocess .PIPE ,
52+ stderr = subprocess .PIPE )
5253 path = p .stdout .read ().decode ("utf-8" )
5354 p .stdout .close ()
55+ p .stderr .close ()
5456 if path == "" :
5557 name = "castxml"
56- p = subprocess .Popen ([command , name ], stdout = subprocess .PIPE )
58+ p = subprocess .Popen ([command , name ], stdout = subprocess .PIPE ,
59+ stderr = subprocess .PIPE )
5760 path = p .stdout .read ().decode ("utf-8" )
5861 p .stdout .close ()
62+ p .stderr .close ()
5963 else :
60- p = subprocess .Popen ([command , name ], stdout = subprocess .PIPE )
64+ p = subprocess .Popen ([command , name ], stdout = subprocess .PIPE ,
65+ stderr = subprocess .PIPE )
6166 path = p .stdout .read ().decode ("utf-8" )
6267 p .stdout .close ()
68+ p .stderr .close ()
6369 if path == "" :
6470 raise (Exception (
6571 "No c++ parser found. Please install castxml or gccxml." ))
@@ -346,3 +352,94 @@ def get_tr1(name):
346352 if "tr1" in name :
347353 tr1 = "tr1::"
348354 return tr1
355+
356+
357+ class cxx_standard (object ):
358+ """Helper class for parsing the C++ standard version.
359+
360+ This class holds the C++ standard version the XML generator has been
361+ configured with, and provides helpers functions for querying C++ standard
362+ version related information.
363+ """
364+
365+ __STD_CXX = {
366+ '-std=c++98' : 199711 ,
367+ '-std=gnu++98' : 199711 ,
368+ '-std=c++03' : 199711 ,
369+ '-std=gnu++03' : 199711 ,
370+ '-std=c++0x' : 201103 ,
371+ '-std=gnu++0x' : 201103 ,
372+ '-std=c++11' : 201103 ,
373+ '-std=gnu++11' : 201103 ,
374+ '-std=c++1y' : 201402 ,
375+ '-std=gnu++1y' : 201402 ,
376+ '-std=c++14' : 201402 ,
377+ '-std=gnu++14' : 201402 ,
378+ '-std=c++1z' : float ('inf' ),
379+ '-std=gnu++1z' : float ('inf' ),
380+ }
381+
382+ def __init__ (self , cflags ):
383+ """Class constructor that parses the XML generator's command line
384+
385+ Args:
386+ cflags (str): cflags command line arguments passed to the XML
387+ generator
388+ """
389+ super (cxx_standard , self ).__init__ ()
390+
391+ self ._stdcxx = None
392+ self ._is_implicit = False
393+ for key in cxx_standard .__STD_CXX :
394+ if key in cflags :
395+ self ._stdcxx = key
396+ self ._cplusplus = cxx_standard .__STD_CXX [key ]
397+
398+ if not self ._stdcxx :
399+ if '-std=' in cflags :
400+ raise RuntimeError ('Unknown -std=c++xx flag used' )
401+
402+ # Assume c++03 by default
403+ self ._stdcxx = '-std=c++03'
404+ self ._cplusplus = cxx_standard .__STD_CXX ['-std=c++03' ]
405+ self ._is_implicit = True
406+
407+ @property
408+ def stdcxx (self ):
409+ """Returns the -std=c++xx option passed to the constructor"""
410+ return self ._stdcxx
411+
412+ @property
413+ def is_implicit (self ):
414+ """Indicates whether a -std=c++xx was specified"""
415+ return self ._is_implicit
416+
417+ @property
418+ def is_cxx03 (self ):
419+ """Returns true if -std=c++03 is being used"""
420+ return self ._cplusplus == cxx_standard .__STD_CXX ['-std=c++03' ]
421+
422+ @property
423+ def is_cxx11 (self ):
424+ """Returns true if -std=c++11 is being used"""
425+ return self ._cplusplus == cxx_standard .__STD_CXX ['-std=c++11' ]
426+
427+ @property
428+ def is_cxx11_or_greater (self ):
429+ """Returns true if -std=c++11 or a newer standard is being used"""
430+ return self ._cplusplus >= cxx_standard .__STD_CXX ['-std=c++11' ]
431+
432+ @property
433+ def is_cxx14 (self ):
434+ """Returns true if -std=c++14 is being used"""
435+ return self ._cplusplus == cxx_standard .__STD_CXX ['-std=c++14' ]
436+
437+ @property
438+ def is_cxx14_or_greater (self ):
439+ """Returns true if -std=c++14 or a newer standard is being used"""
440+ return self ._cplusplus >= cxx_standard .__STD_CXX ['-std=c++14' ]
441+
442+ @property
443+ def is_cxx1z (self ):
444+ """Returns true if -std=c++1z is being used"""
445+ return self ._cplusplus == cxx_standard .__STD_CXX ['-std=c++1z' ]
0 commit comments