JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++
Binaries
C#
Java

Description: Source Files

API functions provide access to information in project source files.

Language Module Support: Internal representation for compilation units, source files, and source file instances is available for C/C++, binary, C#, and Java analyses.



General Information Structure

A project is a combination of compilation units. Each compilation unit has:

We distinguish between "files" and "file instances" because a given file may have multiple roles in a project. The top-level file instances and the include-file instances of a project are collectively known as source-file instances.

The following table summarizes the information stored about each compilation unit.

each... ...has an associated... ...that...
compilation unit unique identifier (UID) is assigned when the unit is (re)compiled
include tree represents the inclusion relations among the file instances
source file unique source-file identifier (SF) is generated as needed and only remains valid for the duration of the browsing session.
unnormalized file path identifies its location in the file system
normalized file path is generated from the unnormalized file path as follows.
  • Windows: normalized file path is the downcased version of the unnormalized file path, with backslash directory separators replaced by forward slashes.
  • Mac: normalized file path is the downcased version of the unnormalized file path.
  • Otherwise: normalized file path is the same as the unnormalized file path.
directory directly contains the source file
source file instance unique source-file-instance identifier (SFID) is generated as needed and only remains valid for the duration of the browsing session.
include path identifies its location in a compilation unit's include tree.
character in a source file line and column specifies its location within the file
character in a source file instance offset specifies its location within the compilation unit

Example

Suppose we build a project based on observing the following compilation:

gcc -c m.c

where the project source files are as follows.

/* m.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:

diagram showing example project structure

In a project with multiple compilation units, a single source file could have instances in more than one compilation unit.

Available Information

API functions provide access to compilation unit information as follows:

Given: Return:
UID
  • Unnormalized file path and normalized file path for the unit's top-level file.
  • Line count for the unit's top-level file.
  • Language the unit is in.
  • Number of compiler warnings and errors generated for the unit.
UID + include path
  • SFID for the corresponding include file instance.
UID + offset
  • SFID + line: the file instance, and line in that file instance, in which the character with the specified offset in the unit occurs.
  • SFID + line + column: the file instance, and line and column in that file instance, in which the character with the specified offset in the unit occurs.
UID + offset1 + offset2
SF
SFID
SFID + line
  • offset of the first character of the corresponding line in the unit to which the file instance belongs.
  • offset1 + offset2: the offsets of the first and last characters of the corresponding line in the unit to which the file instance belongs.

Links

By API language:

C++ classes compunit, sfile , and sfileinst
Python classes compunit, sfile , and sfileinst
C Header cs_source_files.h provides functions and types for source files, file instances, and compilation units.

See also:

 

To report problems with this documentation, please visit https://support.codesecure.com/.