<commit_before>"""This module implements detection of compilers types from their command
line."""
import re
import sys

from numscons.core.utils import popen_wrapper
from numscons.core.errors import UnknownCompiler

# How to detect a new compiler:
#   - implements a function is_*, which takes the (full) path of the compiler,
#   and returns a tuple (st, version), where st is a boolean set to True is the
#   given compiler is of the expected type, and version a string.
#   - the function is_ can use the function _parse

GNUCC = [re.compile('gcc version ([0-9-.]+)')]
ICC = [re.compile(r'Intel.*?C Compiler.*?Version ([0-9-.]+)')]
IFORT = [re.compile(r'Intel.*?Fortran Compiler.*?Version ([0-9-.]+)')]
SUNCC = [re.compile('Sun Ceres C ([0-9-.]+)'), re.compile('Sun C ([0-9-.]+)')]
SUNCXX = [re.compile('Sun Ceres C\+\+ ([0-9-.]+)'), re.compile('Sun C\+\+ ([0-9-.]+)')]
SUNFC = [re.compile('Sun Ceres Fortran 95 ([0-9-.]+)'), re.compile('Sun Fortran 95 ([0-9-.]+)')]

def _parse(regex, string):
    for r in regex:
        m = r.search(string)
        if m:
            return True, m.group(1)
    return False, None

def parse_icc(string):
    return _parse(ICC, string)

def parse_ifort(string):
    return _parse(IFORT, string)

def parse_suncc(string):
    return _parse(SUNCC, string)

def parse_suncxx(string):
    return _parse(SUNCXX, string)

def parse_sunfortran(string):
    return _parse(SUNFC, string)

def parse_gnu(string):
    return _parse(GNUCC, string)

def _is_compiler(path, cmdargs, parser):
    # cmdargs is a list of arguments to get verbose information
    cmd = [path] + cmdargs
    try:
        st, cnt = popen_wrapper(cmd, merge = True, shell = False,
                                env={'LC_ALL': 'C'})
    except OSError, e:
	return False, None
    ret, ver = parser(cnt)
    if st == 0 and ret:
        return ret, ver
    else:
        return False, None

def is_suncc(path):
    """Return True if the compiler in path is sun C compiler."""
    # If the Sun compiler is not given a file as an argument, it returns an
    # error code, even when using dry run and version. So we give a non
    # existing file as an argument: this seems to work, at least for Sun Studio
    # 12 (5.9)
    return _is_compiler(path, ['-V', "-###", "nonexistingfile.fakec"], 
                        parse_suncc)

def is_suncxx(path):
    """Return True if the compiler in path is sun CXX compiler."""
    # Note that the C++ compiler works in a<commit_msg>Fix wrong indentation.<commit_after>"""This module implements detection of compilers types from their command
line."""
import re
import sys

from numscons.core.utils import popen_wrapper
from numscons.core.errors import UnknownCompiler

# How to detect a new compiler:
#   - implements a function is_*, which takes the (full) path of the compiler,
#   and returns a tuple (st, version), where st is a boolean set to True is the
#   given compiler is of the expected type, and version a string.
#   - the function is_ can use the function _parse

GNUCC = [re.compile('gcc version ([0-9-.]+)')]
ICC = [re.compile(r'Intel.*?C Compiler.*?Version ([0-9-.]+)')]
IFORT = [re.compile(r'Intel.*?Fortran Compiler.*?Version ([0-9-.]+)')]
SUNCC = [re.compile('Sun Ceres C ([0-9-.]+)'), re.compile('Sun C ([0-9-.]+)')]
SUNCXX = [re.compile('Sun Ceres C\+\+ ([0-9-.]+)'), re.compile('Sun C\+\+ ([0-9-.]+)')]
SUNFC = [re.compile('Sun Ceres Fortran 95 ([0-9-.]+)'), re.compile('Sun Fortran 95 ([0-9-.]+)')]

def _parse(regex, string):
    for r in regex:
        m = r.search(string)
        if m:
            return True, m.group(1)
    return False, None

def parse_icc(string):
    return _parse(ICC, string)

def parse_ifort(string):
    return _parse(IFORT, string)

def parse_suncc(string):
    return _parse(SUNCC, string)

def parse_suncxx(string):
    return _parse(SUNCXX, string)

def parse_sunfortran(string):
    return _parse(SUNFC, string)

def parse_gnu(string):
    return _parse(GNUCC, string)

def _is_compiler(path, cmdargs, parser):
    # cmdargs is a list of arguments to get verbose information
    cmd = [path] + cmdargs
    try:
        st, cnt = popen_wrapper(cmd, merge = True, shell = False,
                                env={'LC_ALL': 'C'})
    except OSError, e:
        return False, None
    ret, ver = parser(cnt)
    if st == 0 and ret:
        return ret, ver
    else:
        return False, None

def is_suncc(path):
    """Return True if the compiler in path is sun C compiler."""
    # If the Sun compiler is not given a file as an argument, it returns an
    # error code, even when using dry run and version. So we give a non
    # existing file as an argument: this seems to work, at least for Sun Studio
    # 12 (5.9)
    return _is_compiler(path, ['-V', "-###", "nonexistingfile.fakec"], 
                        parse_suncc)

def is_suncxx(path):
    """Return True if the compiler in path is sun CXX compiler."""
    # Note that the C++ compiler works in a
{'fraction_non_alphanumeric': 0.13643692059653365, 'fraction_numerical': 0.01128577186618299, 'mean_word_length': 3.0713699753896635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4114873', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1625, 'n_words': 587}