Unit

class Unit (concrete, physical)
Direct parents:
Ancestor classes and implemented interfaces:

Physical_IR_Root, Toplevel_Node

Field

Kind

Type

Description

Name

attribute

builtin String

Name of the object file produced by this unit. Corresponds to the Unit_Local_Interface.From_Unit values. For the name of the source file, use Primary_Contents.Name.

Primary_Contents

semantic

class File_Contents

the version of the primary file used for this unit (different units might use different versions of the same primary file)

Included_Contents

semantic

set of class File_Contents

All transitively included files (the versions used in this unit) sorted by node number.

In case of a PCH-client IR, for all includes appearing transitively within the precompiled header (“PCH includes”), the File_Contents are omitted from the PCH-client IR. Instead, Included_Contents contains references into the PCH’s IR file. Those references to PCH includes are bundled towards the end of this list.

Linear_Line_Indices

attribute

list of builtin Natural

Contains the index into Linear_Lines for File_Contents nodes of included files in their order of appearance in Included_Contents.

The Linear_Lines block for the Primary_Contents node always is at offset zero, hence it is not tracked via this list.

This list does not contain entries for PCH includes (see Included_Contents above).

Linear_Lines

attribute

list of builtin Natural

Line numbers in the compilation unit’s flattened input (after expanding all includes).

These compilation-unit-specific values can be used to determine, e.g., relative include order. See ir_scripting APIs like node_a.before(node_b), node_a.before_in_unit(node_b, unit), or units.separate_compilation_units(nodes, sort_by_linear_lines=True).

The linear line for a File_Contents node indicates the start of that file in the flattened input. The linear line for an Include_Declaration indicates where the expansion of that include ends in the flattened input. Given these, a SLoc (as stored, e.g., in the Position field of Physical_IR_Root nodes) can be translated to the corresponding linear line.

This list contains these linear lines arranged in consecutive blocks: For each file there is one entry corresponding to its start line, followed by the linear lines of regular (non-PCH) include declarations contained therein.

PCH-client IRs do not contain blocks for PCH includes, as those are already stored in the PCH IR (see Included_Contents above).

The first block corresponds to the Primary_Contents file. It only contains entries for its include declarations, since its start linear line always is 1 (and thus is not stored explicitly).

Accordingly, to get the linear line for an Include_Declaration node inc within the primary file use:

line = unit.Linear_Lines[inc.enclosing_file().Sorted_Includes.index(inc)]

To get the first linear line corresponding to a non-primary File_Contents node c use:

first_index = unit.Linear_Line_Indices[unit.Included_Contents.index(c)]
line = unit.Linear_Lines[first_index]

And to get the linear line for an Include_Declaration node inc within that non-primary file use:

# + 1, since the first index for the file stores the “start of file”
first_include_index = first_index + 1
line = unit.Linear_Lines[
    first_include_index + inc.enclosing_file().Sorted_Includes.index(inc)
]

Command_Line_Defines

syntactic

list of class Macro_Definition

the -D given on the command line

Command_Line_Undefs

syntactic

list of class Command_Line_Undef_Directive

the -U given on the command line

Predefined_Macros

syntactic

set of interface Predefined_Macro_Definition_Interface

things like __DATE__, sorted by name

Suppressed_Includes

semantic

set of interface Include_Interface

these includes were suppressed in this unit by an include guard (so do not consider their target File_Contents node) sorted by node number for faster lookups

Num_External_Variables

attribute

builtin Natural

Number of external variables occurring in this translation unit (counts both declarations and definitions)

Num_External_Routines

attribute

builtin Natural

Number of external variables occurring in this translation unit (counts both declarations and definitions)

Parent (from Physical_IR_Root)

semantic

class Physical_IR_Root

The parent of the node in the syntactic forest.

Original_Position_Index (from Physical_IR_Root)

attribute

builtin SLoc_Index_Type

Internal source location info. If from macro expansion, this location is inside the macro body or macro argument

Original_Position (from Physical_IR_Root)

attribute

builtin SLoc

Source location. If from macro expansion, this location is inside the macro body or macro argument

Position (from Physical_IR_Root)

attribute

builtin SLoc

Source location. If from macro expansion, this location is that of the macro expansion

Artificial (from Physical_IR_Root)

attribute

builtin Boolean

Whether this node was compiler-generated

Parenthesized (from Physical_IR_Root)

attribute

builtin Boolean

Whether this node was enclosed in parentheses (used for expressions)

In_Template_Instance (from Physical_IR_Root)

attribute

builtin Boolean

Whether this node is inside a template instance

Enclosing_Template_Instance (from Physical_IR_Root)

semantic

class Physical_IR_Root

Innermost enclosing template instance if In_Template_Instance is true