class compunit¶
A compilation unit.
A project is a combination of compilation units ( compunit ). Each compilation unit has:
- a top-level file instance,
- a collection of include-file instances, and
- command-line flags used for the compilation.
We distinguish between “files” ( sfile ) and “file instances” ( sfileinst ) because a given file may be used multiple times in a project.
For example, suppose we build a project by observing the compilation of m.c.
gcc -c m.c
Where the project source files are as follows.
/* mainfile.c */
#include "a.h"
#include "b.h"
#define ONE
#include "b.h"
#undef ONE
/* ... */
/* a.h */
/* (no #include statements) */
/* b.h */
#ifdef ONE
#include "a.h"
#else
#include "c.h"
#endif
/* ... */
/* c.h */
/* (no #include statements) */
The project has:
- One compilation unit (
compunit), representing this observed compilation. The compilation unit’s top level file ism.c. - Four source files (
sfile):m.c,a.h,b.h,c.h. - Six source file instances (
sfileinst):- One instance of
m.c, corresponding to its role as the top level file in the compilation unit. - Two instances of
a.h:one for its inclusion inm.cand one for its inclusion inb.h. - Two instances of
b.h, corresponding to its two inclusions inm.c. - One instance of
c.h, corresponding to its inclusion inb.h.
- One instance of
The following image illustrates the relationships between compilation unit, source files, and source file instances in this project.

For more information, see the Source Files manual page.
The following are useful for retrieving compilation units.
| Class | Methods |
|---|---|
procedure |
procedure.get_compunit() |
sfileinst |
sfileinst.get_compunit() |
project |
project.compunits(), project.ignored_compunits() |
compunit Members¶
compunit Details¶
-
class
cs.compunit¶ A compilation unit.
-
__cmp__(other)¶ Comparison function for
compunit.Parameters: other ( compunit) – Thecompunitobject to compare against.Return type: int Returns: An integer N such that: - N==0 if the two objects compare equal
- N<0 if
self< other - N>0 if
self> other
>>> cu = project.current().compunits_vector() >>> cu[0].__cmp__(cu[1]) 1
-
__eq__(b)¶ Equality operator for
compunit.Parameters: b ( compunit) – Thecompunitto compare against.Return type: bool Returns: Trueifselfandbcompare equal,Falseotherwise.>>> v0 = project.current() >>> v1 = v0.compunits_vector() >>> v1[1] == v1[1] True
-
__ge__(b)¶ Greater-than-or-equal operator for
compunit.Parameters: b ( compunit) – Thecompunitto compare against.Return type: bool Returns: Trueifself>=b,Falseotherwise.>>> v0 = project.current() >>> v1 = v0.compunits_vector() >>> v1[0] >= v1[1] False
-
__gt__(b)¶ Greater-than operator for
compunit.Parameters: b ( compunit) – Thecompunitto compare against.Return type: bool Returns: Trueifself>b,Falseotherwise.>>> v0 = project.current() >>> v1 = v0.compunits_vector() >>> v1[0] > v1[0] False
-
__hash__()¶ Get a hash value for a
compunit.Return type: int >>> v0 = project.current() >>> v1 = v0.compunits_vector() >>> hash(v1[1]) 268435457
-
__le__(b)¶ Less-than-or-equal operator for
compunit.Parameters: b ( compunit) – Thecompunitto compare against.Return type: bool Returns: Trueifself<=b,Falseotherwise.>>> v0 = project.current() >>> v1 = v0.compunits_vector() >>> v1[0] <= v1[1] True
-
__lt__(b)¶ Less-than operator for
compunit.Parameters: b ( compunit) – Thecompunitto compare against.Return type: bool Returns: Trueifself<b,Falseotherwise.>>> v0 = project.current() >>> v1 = v0.compunits_vector() >>> v1[0] < v1[1] True
-
__ne__(b)¶ Inequality operator for
compunit.Parameters: b ( compunit) – Thecompunitto compare against.Return type: bool Returns: Falseifselfandbcompare equal,Trueotherwise.>>> v0 = project.current() >>> v1 = v0.compunits_vector() >>> v1[0] != v1[1] True
-
__repr__()¶ Get a representation of a
compunitobject that includes information useful for debugging.Return type: str Returns: The string representation. >>> v0 = project.current() >>> v1 = v0.compunits_vector() >>> repr(v1[0]) '<cs.compunit System Initialization, Indirect & Undefined>'
-
__str__()¶ Get the unnormalized file path corresponding to a compilation unit.
Return type: str Returns: The unnormalized file path, if called on a compunitwith an associated file path.Equivalent to
compunit.name().>>> v0 = project.current() >>> v1 = v0.compunits_vector() >>> str(v1[1]) '/mys0/alex/trunk/cso-tests/regression/functional/apitest.cpp'
-
compiler_command_line()¶ Get the native command line used to build a compilation unit.
Return type: [str]
Returns: The native command line, as a sequence of strings: one element for each command line token.
Raises: result.GENERATED_COMPILATIONif the compilation unit was generated in the back end.result.ELEMENT_NOT_PRESENTif native command line information for the compilation unit is not available.
All compilations built from a single native compiler invocation will share the same native command line.
>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.compiler_command_line() ('C:\\cygwin\\bin\\gcc.exe', '-m32', '-c', 'apitest.cpp')
-
compiler_model()¶ Get the name of the compiler model used to build a compilation unit.
Return type: str
Returns: The compiler model name.
Raises: result.GENERATED_COMPILATIONif the compilation unit was generated in the back end.result.ELEMENT_NOT_PRESENTif compiler model information for the compilation unit is not available.
>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.compiler_model() 'gcc'
-
cs_frontend_command_line()¶ Get the front end command line used to build a compilation unit.
Return type: [str]
Returns: The front end command line, as a sequence of strings: one element for each command line token.
Raises: result.GENERATED_COMPILATIONif the compilation unit was generated in the back end.result.ELEMENT_NOT_PRESENTif the information is not available.
For the C/C++ front end, this includes options specified with configuration file parameters EDG_FRONTEND_OPTIONS_PREPEND and EDG_FRONTEND_OPTIONS_APPEND, and excludes CodeSurfer options.
>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.cs_frontend_command_line() ('C:\\Program Files\\CodeSecure\\CodeSonar\\csurf\\bin\\cprocess', '--hard_define_macro', '__OSX_AVAILABLE_BUT_DEPRECATED(osx_intro,osx_deprecated,ios_intro,ios_deprecated)=', '--hard_define_macro', '_GLIBCXX_FULLY_DYNAMIC_STRING=1', '--cs_control_z_is_not_eof', '--hard_define_macro', '__transaction_cancel=', '--hard_define_macro', '__transaction_relaxed=', '--hard_define_macro', '__transaction_atomic=', '--hard_define_macro', '__builtin_object_size(t,i)=__builtin_object_size(0,0)', '-w', '--c++', '--cs_compiler_model', 'gcc', '--cs_native_compiler', 'gcc', '--cs_native_compiler_version', '9.3.0', '--preinclude', 'C:\\Program Files\\CodeSecure\\CodeSonar\\csurf\\csinclude\\gcc_builtins.h', '-D__STDC__=1', '-D__STDC_HOSTED__=1', '-D__GNUC__=9', '-D__GNUC_MINOR__=3', '-D__GNUC_PATCHLEVEL__=0', '-D__GNUG__=9', '-D__VERSION__="9.3.0"', '-D__NO_INLINE__=1', '-D__WCHAR_UNSIGNED__=1', '-D__REGISTER_PREFIX__=', '-D__USER_LABEL_PREFIX__=_', '-D__SIZE_TYPE__=unsigned int', '-D__PTRDIFF_TYPE__=int', '-D__WCHAR_TYPE__=short unsigned int', '-D__WINT_TYPE__=unsigned int', '-D__CHAR_BIT__=8', '-D__SCHAR_MAX__=0x7f', '-D__WCHAR_MAX__=0xffff', '-D__SHRT_MAX__=0x7fff', '-D__INT_MAX__=0x7fffffff', '-D__LONG_MAX__=0x7fffffffL', '-D__LONG_LONG_MAX__=0x7fffffffffffffffLL', '--sys_include', '/usr/lib/gcc/i686-pc-cygwin/9.3.0/include/c++', '--sys_include', '/usr/lib/gcc/i686-pc-cygwin/9.3.0/include/c++/i686-pc-cygwin', '--sys_include', '/usr/lib/gcc/i686-pc-cygwin/9.3.0/include/c++/backward', '--sys_include', '/usr/lib/gcc/i686-pc-cygwin/9.3.0/include', '--sys_include', '/usr/include', '--sys_include', '/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../include/w32api', '-D__DBL_MIN_EXP__=(-1021)', '-D__FLT32X_MAX_EXP__=1024', '-D__cpp_attributes=200809', '-D__pentiumpro__=1', '-D__UINT_LEAST16_MAX__=0xffff', '-D__ATOMIC_ACQUIRE=2', '-D__FLT128_MAX_10_EXP__=4932', '-D__FLT_MIN__=1.17549435082228750796873653722224568e-38F', '-D__GCC_IEC_559_COMPLEX=2', '-D__cpp_aggregate_nsdmi=201304', '-D__UINT_LEAST8_TYPE__=unsigned char', '-D__SIZEOF_FLOAT80__=12', '-D__INTMAX_C(c)=c ## LL', '-D__CHAR_BIT__=8', '-D__UINT8_MAX__=0xff', '-D__WINT_MAX__=0xffffffffU', '-D__FLT32_MIN_EXP__=(-125)', '-D__cpp_static_assert=200410', '-D__ORDER_LITTLE_ENDIAN__=1234', '-D__SIZE_MAX__=0xffffffffU', '-D__WCHAR_MAX__=0xffff', '-D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1=1', '-D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2=1', '-D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4=1', '-D__DBL_DENORM_MIN__=double(4.94065645841246544176568792868221372e-324L)', '-D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8=1', '-D__GCC_ATOMIC_CHAR_LOCK_FREE=2', '-D__GCC_IEC_559=2', '-D__FLT32X_DECIMAL_DIG__=17', '-D__FLT_EVAL_METHOD__=2', '-D__unix__=1', '-D__cpp_binary_literals=201304', '-D__FLT64_DECIMAL_DIG__=17', '-D__GCC_ATOMIC_CHAR32_T_LOCK_FREE=2', '-D__cpp_variadic_templates=200704', '-D__UINT_FAST64_MAX__=0xffffffffffffffffULL', '-D__SIG_ATOMIC_TYPE__=int', '-D__DBL_MIN_10_EXP__=(-307)', '-D__FINITE_MATH_ONLY__=0', '-D__cpp_variable_templates=201304', '-D__GNUC_PATCHLEVEL__=0', '-D__FLT32_HAS_DENORM__=1', '-D__UINT_FAST8_MAX__=0xff', '-D__cpp_rvalue_reference=200610', '-D_stdcall=__attribute__((__stdcall__))', '-D__DEC64_MAX_EXP__=385', '-D__INT8_C(c)=c', '-D__INT_LEAST8_WIDTH__=8', '-D__UINT_LEAST64_MAX__=0xffffffffffffffffULL', '-D__SHRT_MAX__=0x7fff', '-D__LDBL_MAX__=1.18973149535723176502126385303097021e+4932L', '-D__FLT64X_MAX_10_EXP__=4932', '-D__UINT_LEAST8_MAX__=0xff', '-D__GCC_ATOMIC_BOOL_LOCK_FREE=2', '-D__FLT128_DENORM_MIN__=6.47517511943802511092443895822764655e-4966F128', '-D__UINTMAX_TYPE__=long long unsigned int', '-D__DEC32_EPSILON__=1E-6DF', '-D__FLT_EVAL_METHOD_TS_18661_3__=2', '-D__unix=1', '-D__UINT32_MAX__=0xffffffffU', '-D__GXX_EXPERIMENTAL_CXX0X__=1', '-D__LDBL_MAX_EXP__=16384', '-D__FLT128_MIN_EXP__=(-16381)', '-D__WINT_MIN__=0U', '-D__FLT128_MIN_10_EXP__=(-4931)', '-D__INT_LEAST16_WIDTH__=16', '-D__SCHAR_MAX__=0x7f', '-D__FLT128_MANT_DIG__=113', '-D__WCHAR_MIN__=0', '-D__INT64_C(c)=c ## LL', '-D__DBL_DIG__=15', '-D__GCC_ATOMIC_POINTER_LOCK_FREE=2', '-D__FLT64X_MANT_DIG__=64', '-D__SIZEOF_INT__=4', '-D__SIZEOF_POINTER__=4', '-D__GCC_ATOMIC_CHAR16_T_LOCK_FREE=2', '-D__USER_LABEL_PREFIX__=_', '-D__FLT64X_EPSILON__=1.08420217248550443400745280086994171e-19F64x', '-D__STDC_HOSTED__=1', '-D__LDBL_HAS_INFINITY__=1', '-D__FLT32_DIG__=6', '-D__FLT_EPSILON__=1.19209289550781250000000000000000000e-7F', '-D__GXX_WEAK__=1', '-D__SHRT_WIDTH__=16', '-D__LDBL_MIN__=3.36210314311209350626267781732175260e-4932L', '-D__DEC32_MAX__=9.999999E96DF', '-D__cpp_threadsafe_static_init=200806', '-D__FLT64X_DENORM_MIN__=3.64519953188247460252840593361941982e-4951F64x', '-D__FLT32X_HAS_INFINITY__=1', '-D__INT32_MAX__=0x7fffffff', '-D__INT_WIDTH__=32', '-D__SIZEOF_LONG__=4', '-D__UINT16_C(c)=c', '-D__PTRDIFF_WIDTH__=32', '-D__DECIMAL_DIG__=21', '-D__FLT64_EPSILON__=2.22044604925031308084726333618164062e-16F64', '-D__INTMAX_WIDTH__=64', '-D__FLT64_MIN_EXP__=(-1021)', '-D__FLT64X_MIN_10_EXP__=(-4931)', '-D__LDBL_HAS_QUIET_NAN__=1', '-D__FLT64_MANT_DIG__=53', '-D__GNUC__=9', '-D_cdecl=__attribute__((__cdecl__))', '-D__GXX_RTTI=1', '-D__cpp_delegating_constructors=200604', '-D__FLT_HAS_DENORM__=1', '-D__SIZEOF_LONG_DOUBLE__=12', '-D__BIGGEST_ALIGNMENT__=16', '-D__STDC_UTF_16__=1', '-D__FLT64_MAX_10_EXP__=308', '-D__i686=1', '-D__FLT32_HAS_INFINITY__=1', '-D__DBL_MAX__=double(1.79769313486231570814527423731704357e+308L)', '-D_thiscall=__attribute__((__thiscall__))', '-D__cpp_raw_strings=200710', '-D__INT_FAST32_MAX__=0x7fffffff', '-D__DBL_HAS_INFINITY__=1', '-D__HAVE_SPECULATION_SAFE_VALUE=1', '-D__DEC32_MIN_EXP__=(-94)', '-D__INTPTR_WIDTH__=32', '-D__FLT32X_HAS_DENORM__=1', '-D__INT_FAST16_TYPE__=int', '-D_fastcall=__attribute__((__fastcall__))', '-D__LDBL_HAS_DENORM__=1', '-D__cplusplus=201402L', '-D__cpp_ref_qualifiers=200710', '-D__DEC128_MAX__=9.999999999999999999999999999999999E6144DL', '-D__INT_LEAST32_MAX__=0x7fffffff', '-D__DEC32_MIN__=1E-95DF', '-D__DEPRECATED=1', '-D__cpp_rvalue_references=200610', '-D__DBL_MAX_EXP__=1024', '-D__WCHAR_WIDTH__=16', '-D__FLT32_MAX__=3.40282346638528859811704183484516925e+38F32', '-D__DEC128_EPSILON__=1E-33DL', '-D__ATOMIC_HLE_RELEASE=131072', '-D__PTRDIFF_MAX__=0x7fffffff', '-D__ATOMIC_HLE_ACQUIRE=65536', '-D__FLT32_HAS_QUIET_NAN__=1', '-D__GNUG__=9', '-D__LONG_LONG_MAX__=0x7fffffffffffffffLL', '-D__SIZEOF_SIZE_T__=4', '-D__cpp_nsdmi=200809', '-D__FLT64X_MIN_EXP__=(-16381)', '-D__SIZEOF_WINT_T__=4', '-D__LONG_LONG_WIDTH__=64', '-D__cpp_initializer_lists=200806', '-D__FLT32_MAX_EXP__=128', '-D__cpp_hex_float=201603', '-D__GCC_HAVE_DWARF2_CFI_ASM=1', '-D__GXX_ABI_VERSION=1013', '-D__FLT128_HAS_INFINITY__=1', '-D__FLT_MIN_EXP__=(-125)', '-D__i686__=1', '-D__cpp_lambdas=200907', '-D__FLT64X_HAS_QUIET_NAN__=1', '-D__INT_FAST64_TYPE__=long long int', '-D__FLT64_DENORM_MIN__=4.94065645841246544176568792868221372e-324F64', '-D__DBL_MIN__=double(2.22507385850720138309023271733240406e-308L)', '-D__FLT32X_EPSILON__=2.22044604925031308084726333618164062e-16F32x', '-D__DECIMAL_BID_FORMAT__=1', '-D__GXX_TYPEINFO_EQUALITY_INLINE=0', '-D__FLT64_MIN_10_EXP__=(-307)', '-D__FLT64X_DECIMAL_DIG__=21', '-D__DEC128_MIN__=1E-6143DL', '-D__REGISTER_PREFIX__=', '-D__UINT16_MAX__=0xffff', '-D__cdecl=__attribute__((__cdecl__))', '-D__FLT32_MIN__=1.17549435082228750796873653722224568e-38F32', '-D__UINT8_TYPE__=unsigned char', '-D__NO_INLINE__=1', '-D__i386=1', '-D__FLT_MANT_DIG__=24', '-D__LDBL_DECIMAL_DIG__=21', '-D__VERSION__="9.3.0"', '-D__UINT64_C(c)=c ## ULL', '-D__cpp_unicode_characters=200704', '-D__cpp_decltype_auto=201304', '-D__GCC_ATOMIC_INT_LOCK_FREE=2', '-D__FLT128_MAX_EXP__=16384', '-D__FLT32_MANT_DIG__=24', '-D_X86_=1', '-D__FLOAT_WORD_ORDER__=__ORDER_LITTLE_ENDIAN__', '-D__FLT128_HAS_DENORM__=1', '-D__FLT128_DIG__=33', '-D__SCHAR_WIDTH__=8', '-D__INT32_C(c)=c', '-D__DEC64_EPSILON__=1E-15DD', '-D__ORDER_PDP_ENDIAN__=3412', '-D__DEC128_MIN_EXP__=(-6142)', '-D__code_model_32__=1', '-D__FLT32_MAX_10_EXP__=38', '-D__INT_FAST32_TYPE__=int', '-D__UINT_LEAST16_TYPE__=short unsigned int', '-D__FLT64X_HAS_INFINITY__=1', '-Dunix=1', '-D__DBL_HAS_DENORM__=1', '-D__INT16_MAX__=0x7fff', '-D__i386__=1', '-D__cpp_rtti=199711', '-D__SIZE_TYPE__=unsigned int', '-D__UINT64_MAX__=0xffffffffffffffffULL', '-D__FLT64X_DIG__=18', '-D__INT8_TYPE__=signed char', '-D__cpp_digit_separators=201309', '-D__GCC_ASM_FLAG_OUTPUTS__=1', '-D__FLT_RADIX__=2', '-D__INT_LEAST16_TYPE__=short int', '-D__LDBL_EPSILON__=1.08420217248550443400745280086994171e-19L', '-D__UINTMAX_C(c)=c ## ULL', '-D__SIG_ATOMIC_MAX__=0x7fffffff', '-D__GCC_ATOMIC_WCHAR_T_LOCK_FREE=2', '-D__SIZEOF_PTRDIFF_T__=4', '-D__FLT32X_MANT_DIG__=53', '-D__CYGWIN__=1', '-D__FLT32X_MIN_EXP__=(-1021)', '-D__DEC32_SUBNORMAL_MIN__=0.000001E-95DF', '-D__pentiumpro=1', '-D__INT_FAST16_MAX__=0x7fffffff', '-D__FLT64_DIG__=15', '-D__UINT_FAST32_MAX__=0xffffffffU', '-D__UINT_LEAST64_TYPE__=long long unsigned int', '-D__FLT_HAS_QUIET_NAN__=1', '-D__FLT_MAX_10_EXP__=38', '-D__LONG_MAX__=0x7fffffffL', '-D__FLT64X_HAS_DENORM__=1', '-D__DEC128_SUBNORMAL_MIN__=0.000000000000000000000000000000001E-6143DL', '-D__FLT_HAS_INFINITY__=1', '-D__cpp_unicode_literals=200710', '-D__UINT_FAST16_TYPE__=unsigned int', '-D__DEC64_MAX__=9.999999999999999E384DD', '-D__INT_FAST32_WIDTH__=32', '-D__CHAR16_TYPE__=short unsigned int', '-D__PRAGMA_REDEFINE_EXTNAME=1', '-D__SIZE_WIDTH__=32', '-D__SEG_FS=1', '-D__INT_LEAST16_MAX__=0x7fff', '-D__DEC64_MANT_DIG__=16', '-D__INT64_MAX__=0x7fffffffffffffffLL', '-D__UINT_LEAST32_MAX__=0xffffffffU', '-D__SEG_GS=1', '-D__FLT32_DENORM_MIN__=1.40129846432481707092372958328991613e-45F32', '-D__GCC_ATOMIC_LONG_LOCK_FREE=2', '-D__SIG_ATOMIC_WIDTH__=32', '-D__INT_LEAST64_TYPE__=long long int', '-D__INT16_TYPE__=short int', '-D__INT_LEAST8_TYPE__=signed char', '-D__DEC32_MAX_EXP__=97', '-D__INT_FAST8_MAX__=0x7f', '-D__FLT128_MAX__=1.18973149535723176508575932662800702e+4932F128', '-D__INTPTR_MAX__=0x7fffffff', '-D__cpp_sized_deallocation=201309', '-D__GXX_MERGED_TYPEINFO_NAMES=0', '-D__cpp_range_based_for=200907', '-D__FLT64_HAS_QUIET_NAN__=1', '-D__stdcall=__attribute__((__stdcall__))', '-D__FLT32_MIN_10_EXP__=(-37)', '-D__EXCEPTIONS=1', '-D__LDBL_MANT_DIG__=64', '-D__DBL_HAS_QUIET_NAN__=1', '-D__FLT64_HAS_INFINITY__=1', '-D__FLT64X_MAX__=1.18973149535723176502126385303097021e+4932F64x', '-D__SIG_ATOMIC_MIN__=(-__SIG_ATOMIC_MAX__ - 1)', '-D__cpp_return_type_deduction=201304', '-D__INTPTR_TYPE__=int', '-D__UINT16_TYPE__=short unsigned int', '-D__WCHAR_TYPE__=short unsigned int', '-D__SIZEOF_FLOAT__=4', '-D__UINTPTR_MAX__=0xffffffffU', '-D__INT_FAST64_WIDTH__=64', '-D__DEC64_MIN_EXP__=(-382)', '-D__cpp_decltype=200707', '-D__FLT32_DECIMAL_DIG__=9', '-D__INT_FAST64_MAX__=0x7fffffffffffffffLL', '-D__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1', '-D__FLT_DIG__=6', '-D__FLT64X_MAX_EXP__=16384', '-D__UINT_FAST64_TYPE__=long long unsigned int', '-D__INT_MAX__=0x7fffffff', '-D__INT64_TYPE__=long long int', '-D__FLT_MAX_EXP__=128', '-D__DBL_MANT_DIG__=53', '-D__cpp_inheriting_constructors=201511', '-D__SIZEOF_FLOAT128__=16', '-D__INT_LEAST64_MAX__=0x7fffffffffffffffLL', '-D__DEC64_MIN__=1E-383DD', '-D__WINT_TYPE__=unsigned int', '-D__UINT_LEAST32_TYPE__=unsigned int', '-D__SIZEOF_SHORT__=2', '-D__LDBL_MIN_EXP__=(-16381)', '-D__FLT64_MAX__=1.79769313486231570814527423731704357e+308F64', '-D__WINT_WIDTH__=32', '-D__INT_LEAST8_MAX__=0x7f', '-D__FLT32X_MAX_10_EXP__=308', '-D__WCHAR_UNSIGNED__=1', '-D__LDBL_MAX_10_EXP__=4932', '-D__ATOMIC_RELAXED=0', '-D__DBL_EPSILON__=double(2.22044604925031308084726333618164062e-16L)', '-D__thiscall=__attribute__((__thiscall__))', '-D__FLT128_MIN__=3.36210314311209350626267781732175260e-4932F128', '-D__UINT8_C(c)=c', '-D__FLT64_MAX_EXP__=1024', '-D__INT_LEAST32_TYPE__=int', '-D__SIZEOF_WCHAR_T__=2', '-D__FLT128_HAS_QUIET_NAN__=1', '-D__INT_FAST8_TYPE__=signed char', '-D__fastcall=__attribute__((__fastcall__))', '-D__FLT64X_MIN__=3.36210314311209350626267781732175260e-4932F64x', '-D__GNUC_STDC_INLINE__=1', '-D__FLT64_HAS_DENORM__=1', '-D__CYGWIN32__=1', '-D__FLT32_EPSILON__=1.19209289550781250000000000000000000e-7F32', '-D__DBL_DECIMAL_DIG__=17', '-D__STDC_UTF_32__=1', '-D__INT_FAST8_WIDTH__=8', '-D__DEC_EVAL_METHOD__=2', '-D__FLT32X_MAX__=1.79769313486231570814527423731704357e+308F32x', '-D__ORDER_BIG_ENDIAN__=4321', '-D__cpp_runtime_arrays=198712', '-D__UINT64_TYPE__=long long unsigned int', '-D__UINT32_C(c)=c ## U', '-D__INTMAX_MAX__=0x7fffffffffffffffLL', '-D__cpp_alias_templates=200704', '-D__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__', '-D__FLT_DENORM_MIN__=1.40129846432481707092372958328991613e-45F', '-D__INT8_MAX__=0x7f', '-D__LONG_WIDTH__=32', '-D__UINT_FAST32_TYPE__=unsigned int', '-D__CHAR32_TYPE__=unsigned int', '-D__FLT_MAX__=3.40282346638528859811704183484516925e+38F', '-D__cpp_constexpr=201304', '-D__INT32_TYPE__=int', '-D__SIZEOF_DOUBLE__=8', '-D__cpp_exceptions=199711', '-D__FLT_MIN_10_EXP__=(-37)', '-D__FLT64_MIN__=2.22507385850720138309023271733240406e-308F64', '-D__INT_LEAST32_WIDTH__=32', '-D__INTMAX_TYPE__=long long int', '-Di386=1', '-D__DEC128_MAX_EXP__=6145', '-D__FLT32X_HAS_QUIET_NAN__=1', '-D__ATOMIC_CONSUME=1', '-D__GNUC_MINOR__=3', '-D__INT_FAST16_WIDTH__=32', '-D__UINTMAX_MAX__=0xffffffffffffffffULL', '-D__DEC32_MANT_DIG__=7', '-D__FLT32X_DENORM_MIN__=4.94065645841246544176568792868221372e-324F32x', '-D__DBL_MAX_10_EXP__=308', '-D__LDBL_DENORM_MIN__=3.64519953188247460252840593361941982e-4951L', '-D__INT16_C(c)=c', '-D__cpp_generic_lambdas=201304', '-D__STDC__=1', '-D__FLT32X_DIG__=15', '-D__PTRDIFF_TYPE__=int', '-D__ATOMIC_SEQ_CST=5', '-D__UINT32_TYPE__=unsigned int', '-D__FLT32X_MIN_10_EXP__=(-307)', '-D__UINTPTR_TYPE__=unsigned int', '-D__DEC64_SUBNORMAL_MIN__=0.000000000000001E-383DD', '-D__DEC128_MANT_DIG__=34', '-D__LDBL_MIN_10_EXP__=(-4931)', '-D__FLT128_EPSILON__=1.92592994438723585305597794258492732e-34F128', '-D__SIZEOF_LONG_LONG__=8', '-D__cpp_user_defined_literals=200809', '-D__FLT128_DECIMAL_DIG__=36', '-D__GCC_ATOMIC_LLONG_LOCK_FREE=2', '-D__FLT32X_MIN__=2.22507385850720138309023271733240406e-308F32x', '-D__LDBL_DIG__=18', '-D__FLT_DECIMAL_DIG__=9', '-D__UINT_FAST16_MAX__=0xffffffffU', '-D__GCC_ATOMIC_SHORT_LOCK_FREE=2', '-D__INT_LEAST64_WIDTH__=64', '-D__UINT_FAST8_TYPE__=unsigned char', '-D__cpp_init_captures=201304', '-D__ATOMIC_ACQ_REL=4', '-D__ATOMIC_RELEASE=3', '-D__declspec(x)=__attribute__((x))', '--g++', '--pending_instantiations', '900', '--c++14', '--cs_fold_expressions', '--cs_variadic_using_decls', '--cs_inline_variables_allowed', '--cs_struct_bindings', '--warn_exception_specification_difference', '--instantiate', 'used', '--gnu_version', '90300', '--cs_cygwin_path_translation', '--unicode_source_kind', 'UTF-8', '--hard_undefine_macro', '_GLIBCXX_USE_FLOAT128', 'apitest.cpp')
-
csonar_front_end_run_id()¶ [CodeSonar only] Get the value used to identify a compilation unit to the hub: this will allow you to construct a hub URL for the Parse Details Log.
Return type: str
Returns: The identifying value.
Raises: result.GENERATED_COMPILATIONif the compilation unit was generated in the back end.result.ELEMENT_NOT_PRESENTif this information is not available for the compilation unit.
The hub URL for the Parse Details Log for a compilation unit can be constructed from the return value as follows. Let W be the value returned from a successful call to this function; let host:port be the hub location. Then the URL is
http://host:port/frontendrun/W.html.>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.csonar_front_end_run_id() '56'
-
effective_compiler_flags()¶ Get the effective flags for the native build of a compilation unit.
Return type: [str]
Returns: The effective command line flags, as a sequence of strings: one element for each flag.
Raises: result.GENERATED_COMPILATIONif the compilation unit was generated in the back end.result.ELEMENT_NOT_PRESENTif build flag information for the compilation unit is not available.
This retrieves the effective flags after the content of the command file (the file specified as the value of ‘@’) is inserted; input and output file names are removed; and flags like -c, -o are dropped.
>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.effective_compiler_flags() ('C:\\cygwin\\bin\\gcc.exe', '-m32')
-
error_count()¶ Get the number of errors encountered in compiling a compilation unit.
Return type: int
Returns: The aggregate number of errors for the compilation unit.
Raises: >>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.effective_compiler_flags() ('C:\\cygwin\\bin\\gcc.exe', '-m32') >>> cu.error_count() 0
-
get_ast([family = ast_family.DEFAULT])¶ Get the AST (of the specified
ast_family) for a compilation unit.Parameters: family (
ast_family) – (optional) The compilation unit may have multiple ASTs from different families. This specifies which one to get.Return type: Returns: The
astofast_familyfamilyfor thecompunit.Raises: result.ELEMENT_NOT_PRESENTif the compilation unit has no such AST.result.ERROR_INVALID_ARGUMENTiffamilyis not a validast_family.
>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.get_ast(ast_family.C_NORMALIZED) <cs.ast [c:file-info] >
>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.get_ast() <cs.ast [c:file-info] >
-
get_group_uid()¶ Get the group to which a compilation unit belongs.
Return type: int Returns: The Group UID for the compilation unit. The Group UID for a compilation unit is determined as follows.
- For a C or C++ compilation unit U, the Group UID will always match the compilation unit UID returned by U.
get_id()(compunit.get_id()). - For a Java compilation unit U, the Group UID is the first compilation unit UID encountered during the cs-java-scan invocation that produced U. This may be an existing compilation unit UID for a .java file that is being reanalyzed, or a new UID produced for a .java file that does not already have a corresponding compilation unit in the project.
- For a C# compilation unit U, the situation is analogous to that for Java: the Group UID is the first compilation unit UID encountered during the cs-dotnet-scan invocation that produced U.
For example, suppose
cs-java-scanis invoked on a fileJ.jarcontaining two class files:A.classandB.class. Then:- Two compilation units will be produced from this invocation: one for
A.classand one forB.class. We will refer to the correspondingcompunitobjects asUAandUB, respectively. - These two compilation units constitute a group, because they were produced by the same
cs-java-scaninvocation. - The group UID of the group matches either
UA.get_id()orUB.get_id(), depending on whetherA.classorB.classwas encountered first during thecs-java-scaninvocation.
Additional notes:
Group UIDs and invocations of
cs-java-scan/cs-dotnet-scan/ C/C++ compiler are not in one-to-one correspondence in general.Do not interpret the returned value as a compilation unit identifier, for example by passing it as the argument to
project.find_compunit(). Depending on the sequence of events during the CodeSonar project build phase, it may no longer refer to a compilation unit that is present in the project.For Java and C#, the group UID for a compilation unit can change as the project is built. In particular, if the same artifact is built into the CodeSonar project multiple times via multiple invocations of
cs-java-scanorcs-dotnet-scan, the first compilation unit encountered is not necessarily the same each time.For example, say
A.classis encountered first in an earlier invocation ofcs-bin-scanonJ.jar. Then the group UID for the compilation units corresponding toA.classandB.classwill matchUA.get_id(). IfA.classis then removed fromJ.jarandcs-bin-scanis invoked again,B.classwill be encountered first (because it is the only class left) and so the group UID for the compilation unit corresponding toB.classis updated to matchUB.get_id().For C and C++, the group UID of an existing compilation unit does not change, and will always match the compilation unit UID.
>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.get_language() <cs.language C++> >>> cu.get_group_uid() 268435457 >>> # True because this is a C++ compilation unit. >>> cu.get_group_uid() == cu.get_id() True
- For a C or C++ compilation unit U, the Group UID will always match the compilation unit UID returned by U.
-
get_id()¶ Get the unique identifier of a compilation unit.
Return type: int Returns: The unique identifier. - In an incremental analysis, a compilation unit will have the same identifier that it did in the incremental parent if and only if the compilation unit is not recompiled.
- If the compilation unit is recompiled, it will have a new unique identifier not previously used for any compilation unit in any incremental ancestor analysis. In all other cases identifiers do not persist between different analyses of the same project (or the same code in a different project).
To get a compilation unit given its ID, use
project.find_compunit().>>> cu = next(c for c in project.current().compunits() if c.is_user()) >>> cu.name() 'C:\\cygwin64\\home\\alex\\apitest.cpp' >>> cuid = cu.get_id() >>> cuid 268435457 >>> cu2 = project.current().find_compunit(cuid) >>> cu == cu2 True
-
get_language()¶ Get the source language of a compilation unit.
Return type: languageReturns: The compilation unit language: identifies the front end used to build the compilation unit and the source language the compilation unit is in.>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.get_language() <cs.language C++>
-
get_sfileinst()¶ Get the root source file instance of a compilation unit.
Return type: sfileinstReturns: The root source file instance ( sfileinst). This can be thought of as the root of the include tree for that compilation unit (for example, the.cfile containingmain).Raises: result.GENERATED_COMPILATIONif the compilation unit was generated in the back end.>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.get_sfileinst() <cs.sfileinst /mys0/alex/trunk/cso-tests/regression/functional/apitest.cpp>
-
global_symbols()¶ Get an iterator over the global symbols (
symbol) in a compilation unit.Return type: compunit_global_iteratorReturns: The initialized iterator. >>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.global_symbols() <cs.compunit_global_iterator begin>
-
handle()¶ Get a handle for this compilation unit.
Return type: str Returns: The compilation unit’s handle. Use this function to retrieve a handle to a compilation unit (
compunit) which can be stored externally and used withproject.lookup_compunit_handle()to retrieve the compilation unit when needed. This handle is valid only for the analysis it was generated from. If you rebuild the project, the handle will no longer be valid.A handle is a string consisting of letters (upper and lower case) and numbers, and could also include the following characters: “+”, “=”, and “_”.
>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.handle() 'goCAgAI='
-
is_backend()¶ Check: does a
compunitobject correspond to a compilation unit generated by the back end to hold #System_Initialization and undefined functions?Return type: bool Returns: Trueif the object corresponds to a back end compilation unit,Falseif it does not.>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.is_backend() False
-
is_library_model()¶ Check: does a
compunitobject correspond to a compilation unit for a library model shipped with CodeSonar or CodeSurfer?Return type: bool Returns: Trueif the object corresponds to a library model compilation unit;Falseif it does not.>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.is_library_model() False
-
is_rewriting()¶ Check: does a
compunitobject correspond to a rewriting compilation unit ?Return type: bool Returns: Trueif the object corresponds to a rewriting compilation unit,Falseif it does not.>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.is_rewriting() False
-
is_shared()¶ Check: can a compilation unit be shared by multiple projects and analyses?
Return type: bool Returns: Trueif the compilation can be shared,Falseotherwise.Raises: result.GENERATED_COMPILATIONif the compilation unit was generated in the back end.Only compilation units for library models can be shared by multiple projects and analyses. This function checks whether a specific compilation unit fits into this category (it does not check whether any such sharing is currently occurring).
>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.is_shared() False
-
is_user()¶ Check: does a
compunitobject correspond to a user-generated compilation unit?Return type: bool Returns: Trueif the object corresponds to a user-generated compilation unit,Falseotherwise.This function will return
Falsefor the following kinds of compilation units.- Compilation units generated in the back end.
- Library models.
>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.is_user() True
-
limit_reached()¶ Check: did the front end reach any limits while parsing the specified compilation unit (which may have resulted in missing IR)?
Return type: bool Returns: A bool:Trueif the front end encountered one or more limits (such as INITIALIZER_LIMIT, CONSTEXPR_CALL_DEPTH_LIMIT, AST_DEPTH_LIMIT) while processing the compilation unit. Part of the compilation unit internal representation (IR) may have been dropped in this case.Falseif the front end did not encounter any of these limits while processing the compilation unit
Raises: result.GENERATED_COMPILATIONif the compilation unit was generated in the back end.>>> v0 = project.current() >>> v1 = v0.compunits_vector() >>> v1[13].limit_reached() False
-
lookup_symbol(name)¶ Get a
symbolfrom the compilation unit by name.Parameters: name (str) – The name of a
symbol, as given bysymbol.verbose_name(). Note that this does not necessarily match the code token for the symbol.Return type: Returns: The
symbolassociated with name.Raises: result.ELEMENT_NOT_PRESENTif no such symbol exists.result.ERROR_SDG_NOT_PRESENT
>>> v0 = project.current() >>> v1 = v0.compunits_vector() >>> v1[0].lookup_symbol('#System_Initialization') <cs.symbol #System_Initialization>
-
name()¶ Get the unnormalized file path corresponding to a compilation unit.
Return type: str Returns: The unnormalized file path, if called on a compunitwith an associated file path.Use
compunit.normalized_name()to get the normalized file path.>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.name() 'C:\\alex\\test\\apitest.cpp'
-
normalized_name()¶ Get the normalized file path corresponding to a compilation unit.
Return type: str Returns: The normalized file path, if called on a compunitwith an associated file path.- Windows: this path is the downcased version of the one output by
compunit.name(), with backslash directory separators replaced by forward slashes. - Otherwise: this path is the same as the one output by
compunit.name().
Use
compunit.name()to get the unnormalized file path.>>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.normalized_name() 'c:/alex/test/apitest.cpp'
- Windows: this path is the downcased version of the one output by
-
procedures()¶ Get an iterator over the procedures (
procedure) in a compilation unit.Return type: compunit_procedure_iteratorReturns: The initialized iterator. >>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.procedures() <cs.compunit_iterator begin>
-
warning_count()¶ Get the number of warnings encountered in compiling a compilation unit.
Return type: int
Returns: The aggregate number of warnings for the compilation unit.
Raises: >>> cu = next(u for u in project.current().compunits() if u.is_user()) >>> cu.warning_count() 0
-