compilers: fully type annotate the C compilers

pull/7795/head
Dylan Baker 4 years ago
parent 1d04caff29
commit 96a1ae6dfe
  1. 316
      mesonbuild/compilers/c.py
  2. 1
      mesonbuild/compilers/compilers.py
  3. 2
      mesonbuild/compilers/mixins/arm.py
  4. 2
      mesonbuild/compilers/mixins/c2000.py
  5. 2
      mesonbuild/compilers/mixins/ccrx.py
  6. 2
      mesonbuild/compilers/mixins/compcert.py
  7. 3
      mesonbuild/compilers/mixins/pgi.py
  8. 2
      mesonbuild/compilers/mixins/xc16.py
  9. 4
      mesonbuild/environment.py
  10. 1
      run_mypy.py

@ -39,13 +39,22 @@ from .compilers import (
)
if T.TYPE_CHECKING:
from ..coredata import OptionDictType
from ..dependencies import Dependency, ExternalProgram
from ..envconfig import MachineInfo
from ..environment import Environment
from ..linkers import DynamicLinker
CompilerMixinBase = Compiler
else:
CompilerMixinBase = object
class CCompiler(CLikeCompiler, Compiler):
@staticmethod
def attribute_check_func(name):
def attribute_check_func(name: str) -> str:
try:
return C_FUNC_ATTRIBUTES[name]
except KeyError:
@ -53,20 +62,26 @@ class CCompiler(CLikeCompiler, Compiler):
language = 'c'
def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional[str] = None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
# If a child ObjC or CPP class has already set it, don't set it ourselves
Compiler.__init__(self, exelist, version, for_machine, info, is_cross=is_cross, **kwargs)
Compiler.__init__(self, exelist, version, for_machine, info,
is_cross=is_cross, full_version=full_version, linker=linker)
CLikeCompiler.__init__(self, exe_wrapper)
def get_no_stdinc_args(self):
def get_no_stdinc_args(self) -> T.List[str]:
return ['-nostdinc']
def sanity_check(self, work_dir, environment):
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
code = 'int main(void) { int class=0; return class; }\n'
return self._sanity_check_impl(work_dir, environment, 'sanitycheckc.c', code)
def has_header_symbol(self, hname, symbol, prefix, env, *, extra_args=None, dependencies=None):
def has_header_symbol(self, hname: str, symbol: str, prefix: str,
env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
fargs = {'prefix': prefix, 'header': hname, 'symbol': symbol}
t = '''{prefix}
#include <{header}>
@ -87,10 +102,12 @@ class ClangCCompiler(ClangCompiler, CCompiler):
_C18_VERSION = '>=8.0.0'
_C2X_VERSION = '>=9.0.0'
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None,
defines: T.Optional[T.List[str]] = None, **kwargs):
CCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, **kwargs)
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, linker=linker, full_version=full_version)
ClangCompiler.__init__(self, defines)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
@ -98,7 +115,7 @@ class ClangCCompiler(ClangCompiler, CCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
c_stds = ['c89', 'c99', 'c11']
g_stds = ['gnu89', 'gnu99', 'gnu11']
@ -129,16 +146,21 @@ class ClangCCompiler(ClangCompiler, CCompiler):
})
return opts
def get_option_compile_args(self, options):
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['std']
if std.value != 'none':
args.append('-std=' + std.value)
return args
def get_option_link_args(self, options):
def get_option_link_args(self, options: 'OptionDictType') -> T.List[str]:
if self.info.is_windows() or self.info.is_cygwin():
return options['winlibs'].value[:]
# without a typedict mypy can't understand this.
libs = options['winlibs'].value.copy()
assert isinstance(libs, list)
for l in libs:
assert isinstance(l, str)
return libs
return []
@ -156,21 +178,26 @@ class AppleClangCCompiler(ClangCCompiler):
class EmscriptenCCompiler(EmscriptenMixin, LinkerEnvVarsMixin, ClangCCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', exe_wrapper=None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None):
if not is_cross:
raise MesonException('Emscripten compiler can only be used for cross compilation.')
ClangCCompiler.__init__(self, exelist=exelist, version=version,
for_machine=for_machine, is_cross=is_cross,
info=info, exe_wrapper=exe_wrapper, **kwargs)
ClangCCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper=exe_wrapper, linker=linker,
defines=defines, full_version=full_version)
self.id = 'emscripten'
class ArmclangCCompiler(ArmclangCompiler, CCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, **kwargs)
info, exe_wrapper, linker=linker, full_version=full_version)
ArmclangCompiler.__init__(self)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
@ -178,7 +205,7 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({
'std': coredata.UserComboOption(
@ -189,14 +216,14 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler):
})
return opts
def get_option_compile_args(self, options):
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['std']
if std.value != 'none':
args.append('-std=' + std.value)
return args
def get_option_link_args(self, options):
def get_option_link_args(self, options: 'OptionDictType') -> T.List[str]:
return []
@ -205,11 +232,12 @@ class GnuCCompiler(GnuCompiler, CCompiler):
_C18_VERSION = '>=8.0.0'
_C2X_VERSION = '>=9.0.0'
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None,
defines=None, **kwargs):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, **kwargs)
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, linker=linker, full_version=full_version)
GnuCompiler.__init__(self, defines)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
@ -217,7 +245,7 @@ class GnuCCompiler(GnuCompiler, CCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
c_stds = ['c89', 'c99', 'c11']
g_stds = ['gnu89', 'gnu99', 'gnu11']
@ -243,49 +271,61 @@ class GnuCCompiler(GnuCompiler, CCompiler):
})
return opts
def get_option_compile_args(self, options):
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['std']
if std.value != 'none':
args.append('-std=' + std.value)
return args
def get_option_link_args(self, options):
def get_option_link_args(self, options: 'OptionDictType') -> T.List[str]:
if self.info.is_windows() or self.info.is_cygwin():
return options['winlibs'].value[:]
# without a typeddict mypy can't figure this out
libs = options['winlibs'].value.copy()
assert isinstance(libs, list)
for l in libs:
assert isinstance(l, str)
return libs
return []
def get_pch_use_args(self, pch_dir, header):
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
return ['-fpch-preprocess', '-include', os.path.basename(header)]
class PGICCompiler(PGICompiler, CCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, **kwargs)
info, exe_wrapper, linker=linker, full_version=full_version)
PGICompiler.__init__(self)
class NvidiaHPC_CCompiler(PGICompiler, CCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, **kwargs)
info, exe_wrapper, linker=linker, full_version=full_version)
PGICompiler.__init__(self)
self.id = 'nvidia_hpc'
class ElbrusCCompiler(GnuCCompiler, ElbrusCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None,
defines=None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None):
GnuCCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, defines, **kwargs)
info, exe_wrapper, defines=defines,
linker=linker, full_version=full_version)
ElbrusCompiler.__init__(self)
# It does support some various ISO standards and c/gnu 90, 9x, 1x in addition to those which GNU CC supports.
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({
'std': coredata.UserComboOption(
@ -302,7 +342,9 @@ class ElbrusCCompiler(GnuCCompiler, ElbrusCompiler):
# Elbrus C compiler does not have lchmod, but there is only linker warning, not compiler error.
# So we should explicitly fail at this case.
def has_function(self, funcname, prefix, env, *, extra_args=None, dependencies=None):
def has_function(self, funcname: str, prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
if funcname == 'lchmod':
return False, False
else:
@ -312,10 +354,12 @@ class ElbrusCCompiler(GnuCCompiler, ElbrusCompiler):
class IntelCCompiler(IntelGnuLikeCompiler, CCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, **kwargs)
info, exe_wrapper, linker=linker, full_version=full_version)
IntelGnuLikeCompiler.__init__(self)
self.lang_header = 'c-header'
default_warn_args = ['-Wall', '-w3', '-diag-disable:remark']
@ -324,7 +368,7 @@ class IntelCCompiler(IntelGnuLikeCompiler, CCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra']}
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
c_stds = ['c89', 'c99']
g_stds = ['gnu89', 'gnu99']
@ -339,7 +383,7 @@ class IntelCCompiler(IntelGnuLikeCompiler, CCompiler):
})
return opts
def get_option_compile_args(self, options):
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['std']
if std.value != 'none':
@ -347,11 +391,11 @@ class IntelCCompiler(IntelGnuLikeCompiler, CCompiler):
return args
class VisualStudioLikeCCompilerMixin:
class VisualStudioLikeCCompilerMixin(CompilerMixinBase):
"""Shared methods that apply to MSVC-like C compilers."""
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = super().get_options()
opts.update({
'winlibs': coredata.UserArrayOption(
@ -361,20 +405,28 @@ class VisualStudioLikeCCompilerMixin:
})
return opts
def get_option_link_args(self, options):
return options['winlibs'].value[:]
def get_option_link_args(self, options: 'OptionDictType') -> T.List[str]:
# need a TypeDict to make this work
libs = options['winlibs'].value.copy()
assert isinstance(libs, list)
for l in libs:
assert isinstance(l, str)
return libs
class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrap, target: str,
**kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', target: str,
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrap, **kwargs)
info, exe_wrapper, linker=linker,
full_version=full_version)
MSVCCompiler.__init__(self, target)
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = super().get_options()
c_stds = ['none', 'c89', 'c99', 'c11']
opts.update({
@ -386,7 +438,7 @@ class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompi
})
return opts
def get_option_compile_args(self, options):
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['std']
# As of MVSC 16.7, /std:c11 is the only valid C standard option.
@ -396,10 +448,14 @@ class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompi
class ClangClCCompiler(ClangClCompiler, VisualStudioLikeCCompilerMixin, CCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrap, target, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', target: str,
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrap, **kwargs)
info, exe_wrapper, linker=linker,
full_version=full_version)
ClangClCompiler.__init__(self, target)
@ -407,13 +463,17 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM
"""Intel "ICL" compiler abstraction."""
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrap, target, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', target: str,
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrap, **kwargs)
info, exe_wrapper, linker=linker,
full_version=full_version)
IntelVisualStudioLikeCompiler.__init__(self, target)
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = super().get_options()
c_stds = ['none', 'c89', 'c99', 'c11']
opts.update({
@ -425,7 +485,7 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM
})
return opts
def get_option_compile_args(self, options):
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['std']
if std.value == 'c89':
@ -436,13 +496,17 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM
class ArmCCompiler(ArmCompiler, CCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, **kwargs)
info, exe_wrapper, linker=linker,
full_version=full_version)
ArmCompiler.__init__(self)
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({
'std': coredata.UserComboOption(
@ -453,7 +517,7 @@ class ArmCCompiler(ArmCompiler, CCompiler):
})
return opts
def get_option_compile_args(self, options):
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['std']
if std.value != 'none':
@ -462,17 +526,20 @@ class ArmCCompiler(ArmCompiler, CCompiler):
class CcrxCCompiler(CcrxCompiler, CCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, **kwargs)
info, exe_wrapper, linker=linker, full_version=full_version)
CcrxCompiler.__init__(self)
# Override CCompiler.get_always_args
def get_always_args(self):
def get_always_args(self) -> T.List[str]:
return ['-nologo']
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({
'std': coredata.UserComboOption(
@ -483,10 +550,10 @@ class CcrxCCompiler(CcrxCompiler, CCompiler):
})
return opts
def get_no_stdinc_args(self):
def get_no_stdinc_args(self) -> T.List[str]:
return []
def get_option_compile_args(self, options):
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['std']
if std.value == 'c89':
@ -495,42 +562,45 @@ class CcrxCCompiler(CcrxCompiler, CCompiler):
args.append('-lang=c99')
return args
def get_compile_only_args(self):
def get_compile_only_args(self) -> T.List[str]:
return []
def get_no_optimization_args(self):
def get_no_optimization_args(self) -> T.List[str]:
return ['-optimize=0']
def get_output_args(self, target):
def get_output_args(self, target: str) -> T.List[str]:
return ['-output=obj=%s' % target]
def get_werror_args(self):
def get_werror_args(self) -> T.List[str]:
return ['-change_message=error']
def get_include_args(self, path, is_system):
def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
if path == '':
path = '.'
return ['-include=' + path]
class Xc16CCompiler(Xc16Compiler, CCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, **kwargs)
info, exe_wrapper, linker=linker, full_version=full_version)
Xc16Compiler.__init__(self)
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({'c_std': coredata.UserComboOption('C language standard to use',
['none', 'c89', 'c99', 'gnu89', 'gnu99'],
'none')})
return opts
def get_no_stdinc_args(self):
def get_no_stdinc_args(self) -> T.List[str]:
return []
def get_option_compile_args(self, options):
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['c_std']
if std.value != 'none':
@ -538,95 +608,101 @@ class Xc16CCompiler(Xc16Compiler, CCompiler):
args.append('-std=' + std.value)
return args
def get_compile_only_args(self):
def get_compile_only_args(self) -> T.List[str]:
return []
def get_no_optimization_args(self):
def get_no_optimization_args(self) -> T.List[str]:
return ['-O0']
def get_output_args(self, target):
def get_output_args(self, target: str) -> T.List[str]:
return ['-o%s' % target]
def get_werror_args(self):
def get_werror_args(self) -> T.List[str]:
return ['-change_message=error']
def get_include_args(self, path, is_system):
def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
if path == '':
path = '.'
return ['-I' + path]
class CompCertCCompiler(CompCertCompiler, CCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, **kwargs)
info, exe_wrapper, linker=linker, full_version=full_version)
CompCertCompiler.__init__(self)
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({'c_std': coredata.UserComboOption('C language standard to use',
['none', 'c89', 'c99'],
'none')})
return opts
def get_option_compile_args(self, options):
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
return []
def get_no_optimization_args(self):
def get_no_optimization_args(self) -> T.List[str]:
return ['-O0']
def get_output_args(self, target):
def get_output_args(self, target: str) -> T.List[str]:
return ['-o{}'.format(target)]
def get_werror_args(self):
def get_werror_args(self) -> T.List[str]:
return ['-Werror']
def get_include_args(self, path, is_system):
def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
if path == '':
path = '.'
return ['-I' + path]
class C2000CCompiler(C2000Compiler, CCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
CCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, **kwargs)
info, exe_wrapper, linker=linker, full_version=full_version)
C2000Compiler.__init__(self)
# Override CCompiler.get_always_args
def get_always_args(self):
def get_always_args(self) -> T.List[str]:
return []
def get_options(self):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts.update({'c_std': coredata.UserComboOption('C language standard to use',
['none', 'c89', 'c99', 'c11'],
'none')})
return opts
def get_no_stdinc_args(self):
def get_no_stdinc_args(self) -> T.List[str]:
return []
def get_option_compile_args(self, options):
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
args = []
std = options['c_std']
if std.value != 'none':
args.append('--' + std.value)
return args
def get_compile_only_args(self):
def get_compile_only_args(self) -> T.List[str]:
return []
def get_no_optimization_args(self):
def get_no_optimization_args(self) -> T.List[str]:
return ['-Ooff']
def get_output_args(self, target):
def get_output_args(self, target: str) -> T.List[str]:
return ['--output_file=%s' % target]
def get_werror_args(self):
def get_werror_args(self) -> T.List[str]:
return ['-change_message=error']
def get_include_args(self, path, is_system):
def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
if path == '':
path = '.'
return ['--include_path=' + path]

@ -452,6 +452,7 @@ class Compiler(metaclass=abc.ABCMeta):
if T.TYPE_CHECKING:
language = 'unset'
id = ''
warn_args = {} # type: T.Dict[str, T.List[str]]
def __init__(self, exelist: T.List[str], version: str,
for_machine: MachineChoice, info: 'MachineInfo',

@ -81,7 +81,7 @@ class ArmCompiler(Compiler):
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + [],
'3': default_warn_args + []}
'3': default_warn_args + []} # type: T.Dict[str, T.List[str]]
# Assembly
self.can_compile_suffixes.add('s')

@ -65,7 +65,7 @@ class C2000Compiler(Compiler):
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + [],
'3': default_warn_args + []}
'3': default_warn_args + []} # type: T.Dict[str, T.List[str]]
def get_pic_args(self) -> T.List[str]:
# PIC support is not enabled by default for c2000,

@ -69,7 +69,7 @@ class CcrxCompiler(Compiler):
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + [],
'3': default_warn_args + []}
'3': default_warn_args + []} # type: T.Dict[str, T.List[str]]
def get_pic_args(self) -> T.List[str]:
# PIC support is not enabled by default for CCRX,

@ -68,7 +68,7 @@ class CompCertCompiler(Compiler):
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + [],
'3': default_warn_args + []}
'3': default_warn_args + []} # type: T.Dict[str, T.List[str]]
def get_always_args(self) -> T.List[str]:
return []

@ -50,7 +50,8 @@ class PGICompiler(Compiler):
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args,
'3': default_warn_args}
'3': default_warn_args
} # type: T.Dict[str, T.List[str]]
def get_module_incdir_args(self) -> T.Tuple[str]:
return ('-module', )

@ -65,7 +65,7 @@ class Xc16Compiler(Compiler):
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + [],
'3': default_warn_args + []}
'3': default_warn_args + []} # type: T.Dict[str, T.List[str]]
def get_always_args(self) -> T.List[str]:
return []

@ -1324,8 +1324,8 @@ class Environment:
cls = VisualStudioCCompiler if lang == 'c' else VisualStudioCPPCompiler
linker = self._guess_win_linker(['link'], cls, for_machine)
return cls(
compiler, version, for_machine, is_cross, info, exe_wrap,
target, full_version=cl_signature, linker=linker)
compiler, version, for_machine, is_cross, info, target,
exe_wrap, full_version=cl_signature, linker=linker)
if 'PGI Compilers' in out:
cls = PGICCompiler if lang == 'c' else PGICPPCompiler
self.coredata.add_lang_args(cls.language, cls, for_machine, self)

@ -17,6 +17,7 @@ modules = [
# specific files
'mesonbuild/arglist.py',
'mesonbuild/compilers/compilers.py',
'mesonbuild/compilers/c.py',
'mesonbuild/compilers/c_function_attributes.py',
'mesonbuild/compilers/objc.py',
'mesonbuild/compilers/objcpp.py',

Loading…
Cancel
Save