|
CodeSonar C++ API
|
A compilation unit. More...
Public Member Functions | |
| std::string | as_repr () const |
| Get a representation of a compunit object that includes information useful for debugging. | |
| std::string | as_string () const |
| Get the unnormalized file path corresponding to a compilation unit. | |
| int | cmp (const compunit &other) const |
| Comparison function for compunit. | |
| std::vector< std::string > | compiler_command_line () const |
| Get the native command line used to build a compilation unit. | |
| std::string | compiler_model () const |
| Get the name of the compiler model used to build a compilation unit. | |
| std::vector< std::string > | compiler_wall_enable_flags () const |
| Get the list of flags that enable all warnings for the compiler that compiled this compilation unit. | |
| std::vector< std::string > | compiler_werror_enable_flags () const |
| Get the list of flags that cause the compiler that compiled this compilation unit to treat warnings as errors. | |
| std::vector< std::string > | cs_frontend_command_line () const |
| Get the front end command line used to build a compilation unit. | |
| std::string | csonar_front_end_run_id () const |
| [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. | |
| std::vector< std::string > | effective_compiler_flags () const |
| Get the effective flags for the native build of a compilation unit. | |
| size_t | error_count () const |
| Get the number of errors encountered in compiling a compilation unit. | |
| effective_address | get_address_for_section_offset (const std::string &sec_name, csuint32 sec_offset) |
| [Binary analyses only] Returns the address that corresponds to the given (section, offset) location in this compilation unit. | |
| ast | get_ast (ast_family family=ast_family::DEFAULT) const |
| Get the AST (of the specified ast_family) for a compilation unit. | |
| csuint32 | get_group_uid () const |
| Get the group to which a compilation unit belongs. | |
| language | get_language () const |
| Get the source language of a compilation unit. | |
| sfileinst | get_sfileinst () const |
| Get the root source file instance of a compilation unit. | |
| compunit_global_iterator | global_symbols () const |
| Get an iterator over the global symbols (symbol) in a compilation unit. | |
| std::string | handle () const |
| Get a handle for this compilation unit. | |
| cs_hash_t | hash () const |
| Get a hash value for a compunit. | |
| csuint32 | id () const |
| Get the unique identifier of a compilation unit. | |
| bool | is_backend () const |
| Check: does a compunit object correspond to a compilation unit generated by the back end to hold #System_Initialization and undefined functions? | |
| [CodeSonar for Binaries only] Check: is a compilation unit an 'offstage binary' (that is, one that is analyzed but not included in results)? | |
| bool | is_library_model () const |
| Check: does a compunit object correspond to a compilation unit for a library model shipped with CodeSonar or CodeSurfer? | |
| bool | is_rewriting () const |
| Check: does a compunit object correspond to a rewriting compilation unit ? | |
| bool | is_shared () const |
| Check: can a compilation unit be shared by multiple projects and analyses? | |
| bool | is_user () const |
| Check: does a compunit object correspond to a user-generated compilation unit? | |
| bool | limit_reached () const |
| Check: did the front end reach any limits while parsing the specified compilation unit (which may have resulted in missing IR)? | |
| symbol | lookup_symbol (const std::string &name) const |
| Get a symbol from the compilation unit by name. | |
| std::string | name () const |
| Get the unnormalized file path corresponding to a compilation unit. | |
| std::string | normalized_name () const |
| Get the normalized file path corresponding to a compilation unit. | |
| compunit_procedure_iterator | procedures () const |
| Get an iterator over the procedures (procedure) in a compilation unit. | |
| std::vector< std::string > | seen_wall_disable_flags () const |
| Get the list of flags seen on the native command line that disable a subset of warnings for the compiler that compiled this compilation unit. | |
| std::vector< std::string > | seen_werror_disable_flags () const |
| Get the list of flags seen on the native command line that disable a subset of errors or cause warnings to not be treated as errors for the compiler that compiled this compilation unit. | |
| size_t | warning_count () const |
| Get the number of warnings encountered in compiling a compilation unit. | |
Related Symbols | |
(Note that these are not member symbols.) | |
| bool | operator!= (const compunit &a, const compunit &b) |
| Inequality operator for compunit. | |
| bool | operator< (const compunit &a, const compunit &b) |
| Less-than operator for compunit. | |
| std::ostream & | operator<< (std::ostream &out, const compunit &a) |
| bool | operator<= (const compunit &a, const compunit &b) |
| Less-than-or-equal operator for compunit. | |
| bool | operator== (const compunit &a, const compunit &b) |
| Equality operator for compunit. | |
| bool | operator> (const compunit &a, const compunit &b) |
| Greater-than operator for compunit. | |
| bool | operator>= (const compunit &a, const compunit &b) |
| Greater-than-or-equal operator for compunit. | |
A compilation unit.
A project is a combination of compilation units (compunit). Each compilation unit has:
m.c.m.c.m.c, a.h, b.h, c.h.m.c, corresponding to its role as the top level file in the compilation unit.a.h: one for its inclusion in m.c and one for its inclusion in b.h.b.h, corresponding to its two inclusions in m.c.c.h, corresponding to its inclusion in b.h.
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() |
|
inline |
Get a representation of a compunit object that includes information useful for debugging.
|
inline |
|
inline |
|
inline |
Get the native command line used to build a compilation unit.
| result::GENERATED_COMPILATION | if the compilation unit was generated in the back end. |
| result::ELEMENT_NOT_PRESENT | if 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.
|
inline |
Get the name of the compiler model used to build a compilation unit.
| result::GENERATED_COMPILATION | if the compilation unit was generated in the back end. |
| result::ELEMENT_NOT_PRESENT | if compiler model information for the compilation unit is not available. |
|
inline |
Get the list of flags that enable all warnings for the compiler that compiled this compilation unit.
| result::ELEMENT_NOT_PRESENT | if the information is not available. |
For example, -Wall in gcc. The compiler model is responsible for populating this list and passing the information to the front-end.
|
inline |
Get the list of flags that cause the compiler that compiled this compilation unit to treat warnings as errors.
| result::ELEMENT_NOT_PRESENT | if the information is not available. |
For example, -Werror in gcc. The compiler model is responsible for populating this list and passing the information to the front-end.
|
inline |
Get the front end command line used to build a compilation unit.
| result::GENERATED_COMPILATION | if the compilation unit was generated in the back end. |
| result::ELEMENT_NOT_PRESENT | if 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.
|
inline |
[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.
| result::GENERATED_COMPILATION | if the compilation unit was generated in the back end. |
| result::ELEMENT_NOT_PRESENT | if 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.
|
inline |
Get the effective flags for the native build of a compilation unit.
| result::GENERATED_COMPILATION | if the compilation unit was generated in the back end. |
| result::ELEMENT_NOT_PRESENT | if 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.
|
inline |
Get the number of errors encountered in compiling a compilation unit.
|
inline |
[Binary analyses only] Returns the address that corresponds to the given (section, offset) location in this compilation unit.
| [in] | sec_name | The name of the section containing the address. |
| [in] | sec_offset | The offset of the address within the section. |
| result::NOT_IMPLEMENTED | if the CodeSonar installation does not include binary analysis functionality. |
| result::ELEMENT_NOT_PRESENT | if this is not a binary compunit, if sec_name does not correspond to a section in this, or if the offset is beyond the given section's size. |
| result::TRUNCATED | if more than one section with the specified name and offset is found. |
|
inline |
Get the AST (of the specified ast_family) for a compilation unit.
| [in] | family | The compilation unit may have multiple ASTs from different families. This specifies which one to get. |
family for the compunit.| result::ERROR_INVALID_ARGUMENT | if family is not a valid ast_family. |
| result::ELEMENT_NOT_PRESENT | if the compilation unit has no such AST. |
|
inline |
Get the group to which a compilation unit belongs.
The Group UID for a compilation unit is determined as follows.
For example, suppose cs-java-scan is invoked on a file J.jar containing two class files: A.class and B.class. Then:
A.class and one for B.class. We will refer to the corresponding compunit objects as UA and UB, respectively.cs-java-scan invocation.UA.id() or UB.id(), depending on whether A.class or B.class was encountered first during the cs-java-scan invocation.Additional notes:
cs-java-scan / cs-dotnet-scan / C/C++ compiler are not in one-to-one correspondence in general.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-scan or cs-dotnet-scan, the first compilation unit encountered is not necessarily the same each time.
For example, say A.class is encountered first in an earlier invocation of cs-bin-scan on J.jar. Then the group UID for the compilation units corresponding to A.class and B.class will match UA.id(). If A.class is then removed from J.jar and cs-bin-scan is invoked again, B.class will be encountered first (because it is the only class left) and so the group UID for the compilation unit corresponding to B.class is updated to match UB.id().
|
inline |
Get the source language of a compilation unit.
|
inline |
Get the root source file instance of a compilation unit.
.c file containing main).| result::GENERATED_COMPILATION | if the compilation unit was generated in the back end. |
|
inline |
Get an iterator over the global symbols (symbol) in a compilation unit.
|
inline |
Get a handle for this compilation unit.
Use this function to retrieve a handle to a compilation unit (compunit) which can be stored externally and used with project::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 std::string consisting of letters (upper and lower case) and numbers, and could also include the following characters: "+", "=", and "_".
|
inline |
Get a hash value for a compunit.
|
inline |
Get the unique identifier of a compilation unit.
To get a compilation unit given its ID, use project::find_compunit().
|
inline |
Check: does a compunit object correspond to a compilation unit generated by the back end to hold #System_Initialization and undefined functions?
true if the object corresponds to a back end compilation unit, false if it does not.
|
inline |
[CodeSonar for Binaries only] Check: is a compilation unit an 'offstage binary' (that is, one that is analyzed but not included in results)?
true if the compilation unit is an offstage binary, false if it is not.| result::GENERATED_COMPILATION | if the compilation unit was generated in the back end. |
|
inline |
Check: does a compunit object correspond to a compilation unit for a library model shipped with CodeSonar or CodeSurfer?
true if the object corresponds to a library model compilation unit; false if it does not.
|
inline |
Check: does a compunit object correspond to a rewriting compilation unit ?
true if the object corresponds to a rewriting compilation unit, false if it does not.
|
inline |
Check: can a compilation unit be shared by multiple projects and analyses?
true if the compilation can be shared, false otherwise.| result::GENERATED_COMPILATION | if 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).
|
inline |
Check: does a compunit object correspond to a user-generated compilation unit?
true if the object corresponds to a user-generated compilation unit, false otherwise.This function will return false for the following kinds of compilation units.
|
inline |
Check: did the front end reach any limits while parsing the specified compilation unit (which may have resulted in missing IR)?
bool: true if 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.false if the front end did not encounter any of these limits while processing the compilation unit| result::GENERATED_COMPILATION | if the compilation unit was generated in the back end. |
|
inline |
Get a symbol from the compilation unit by name.
| [in] | name | The name of a symbol, as given by symbol::verbose_name(). Note that this does not necessarily match the code token for the symbol. |
| result::ERROR_SDG_NOT_PRESENT | |
| result::ELEMENT_NOT_PRESENT | if no such symbol exists. |
|
inline |
Get the unnormalized file path corresponding to a compilation unit.
Use normalized_name() to get the normalized file path.
|
inline |
|
inline |
Get an iterator over the procedures (procedure) in a compilation unit.
|
inline |
Get the list of flags seen on the native command line that disable a subset of warnings for the compiler that compiled this compilation unit.
| result::ELEMENT_NOT_PRESENT | if the information is not available. |
For example, -Wno-format-zero-length in gcc. The compiler model is responsible for populating this list and passing the information to the front-end.
|
inline |
Get the list of flags seen on the native command line that disable a subset of errors or cause warnings to not be treated as errors for the compiler that compiled this compilation unit.
| result::ELEMENT_NOT_PRESENT | if the information is not available. |
For example, -Wno-error=declaration-missing-parameter-type in gcc. The compiler model is responsible for populating this list and passing the information to the front-end.
|
inline |
Get the number of warnings encountered in compiling a compilation unit.
Inequality operator for compunit.
false if a and b are equal according to compunit::cmp(), true otherwise. Less-than operator for compunit.
true if a < b according to compunit::cmp() , false otherwise.
|
related |
Less-than-or-equal operator for compunit.
true if a <= b according to compunit::cmp() , false otherwise. Equality operator for compunit.
true if a and b are equal according to compunit::cmp(), false otherwise. Greater-than operator for compunit.
true if a > b according to compunit::cmp() , false otherwise. Greater-than-or-equal operator for compunit.
true if a >= b according to compunit::cmp() , false otherwise.