Code section items#
CodeElement subclasses#
Each code section item is represented by one of the following classes, which all inherit from CodeElement,
thus provide the get_model_element() method to access the associated model element. (see Model section items)
Functions and Parameters
CFunction- C function declarationCParameter- Function parameter
Variables and Macros
Type Definitions
CPredefinedType- Predefined typeCArray- Array type definitionCStructField- Field within a structureCStruct- Structure type definitionCEnum- Enumeration type definitionCEnumValue- Value within an enumerationCUnion- Union type definitionCUnionVariant- Variant within a unionCTypedef- Typedef definitionCExternalType- External type
Code Container#
A CodeContainer represents a code unit associated with a pair of C files:
an interface file (
.hheader)an optional implementation file (
.csource)
Each container holds a list of CDeclaration items (functions, variables, types, macros, …)
that are declared or defined in those files.
A container can also be marked as user-provided, meaning it needs to be provided by the user.
The full set of containers is accessible from get_all_code_containers().
API Documentation#
Code module for Swan Code Generator mapping data.
This module implements classes representing C code elements generated from Swan language. Each code item has a unique integer ID and can reference other code items or model items by their IDs.
- class ansys.scadeone.core.svc.cgmapping.code.CArray(id: int, name: str, base_type: int, size: int, copy: int | None = None, equality: int | None = None, equality_use: str | None = None)#
Bases:
CodeTypeBaseC array type definition.
- Parameters:
- id
int Unique identifier for this array type.
- name
str Name of the array type.
- base_type
int Reference ID to the base type of the array.
- size
int Size of the array.
- copy
int|None Reference ID to copy function (if any).
- equality
int|None Reference ID to equality function (if any).
- equality_use
str|None Usage string for equality function.
- id
- class ansys.scadeone.core.svc.cgmapping.code.CEnum(id: int, name: str, values: list[CEnumValue])#
Bases:
CodeElementC enum type definition.
- Parameters:
- id
int Unique identifier for this enum type.
- name
str Name of the enum type.
- values
list[CEnumValue] List of enum values.
- id
- class ansys.scadeone.core.svc.cgmapping.code.CEnumValue(id: int, name: str, user_value: str | None = None)#
Bases:
CodeElementC enum type value.
- class ansys.scadeone.core.svc.cgmapping.code.CExternalType(id: int, name: str, scalar: bool | None = None, init: int | None = None, copy: int | None = None, equality: int | None = None)#
Bases:
CodeTypeBaseC external type.
- Parameters:
- id
int Unique identifier for this external type.
- name
str Name of the external type.
- scalarbool |
None Whether this is a scalar type.
- init
int|None Reference ID to initialization function (if any).
- copy
int|None Reference ID to copy function (if any).
- equality
int|None Reference ID to equality function (if any).
- id
- class ansys.scadeone.core.svc.cgmapping.code.CFunction(id: int, name: str, parameters: list[CParameter], return_type: int | None = None)#
Bases:
CodeElementC function declaration.
- class ansys.scadeone.core.svc.cgmapping.code.CGlobal(id: int, name: str, type: int)#
Bases:
CodeElementC global variable.
- class ansys.scadeone.core.svc.cgmapping.code.CMacro(id: int, name: str)#
Bases:
CodeElementC macro definition.
- class ansys.scadeone.core.svc.cgmapping.code.CParameter(id: int, name: str, type: int, pointer: bool | None = None, const: bool | None = None)#
Bases:
CodeElementC function parameter.
- class ansys.scadeone.core.svc.cgmapping.code.CPredefinedType(id: int, name: str)#
Bases:
CodeElementC predefined type.
- class ansys.scadeone.core.svc.cgmapping.code.CStruct(id: int, name: str, fields: list[CStructField], copy: int | None = None, equality: int | None = None, equality_use: str | None = None)#
Bases:
CodeTypeBaseC structure type definition.
- Parameters:
- id
int Unique identifier for this struct type.
- name
str Name of the struct type.
- fields
list[CStructField] List of fields in the structure.
- copy
int|None Reference ID to copy function (if any).
- equality
int|None Reference ID to equality function (if any).
- equality_use
str|None Usage string for equality function.
- id
- class ansys.scadeone.core.svc.cgmapping.code.CStructField(id: int, name: str, type: int, pointer: bool | None = None, size: list[int] | None = None)#
Bases:
CodeElementC structure field.
- Parameters:
- get_model_element() ModelElement | None#
Get the model element for this code element.
- Returns:
ModelElement|NoneThe model element mapped to this code element, or None if not found.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
AttributeErrorIf the class does not have an ‘id’ attribute.
- class ansys.scadeone.core.svc.cgmapping.code.CTypedef(id: int, name: str, type: int, copy: int | None = None, equality: int | None = None)#
Bases:
CodeTypeBaseC typedef definition.
- class ansys.scadeone.core.svc.cgmapping.code.CUnion(id: int, name: str, variants: list[CUnionVariant], copy: int | None = None, equality: int | None = None, equality_use: str | None = None)#
Bases:
CodeTypeBaseC union type definition.
- Parameters:
- class ansys.scadeone.core.svc.cgmapping.code.CUnionVariant(id: int, name: str, enum_value: int, type: int)#
Bases:
CodeElementC union type variant.
- class ansys.scadeone.core.svc.cgmapping.code.CodeContainer(interface_file: str, declarations: list[CDeclaration], implementation_file: str | None = None, user_provided: bool | None = None)#
Bases:
objectGenerated code item with interface file, optional implementation file, and declarations.
- class ansys.scadeone.core.svc.cgmapping.code.CodeElement#
Bases:
objectBase class for all C code elements.
This class provides common functionality for all code elements, including access to their corresponding model elements through the mapping system.
All code elements that inherit from this class must have an ‘id’ attribute.
- get_model_element() ModelElement | None#
Get the model element for this code element.
- Returns:
ModelElement|NoneThe model element mapped to this code element, or None if not found.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
AttributeErrorIf the class does not have an ‘id’ attribute.
- get_type() CodeTypeBase | None#
Get the type of this code element if it has a type attribute.
- Returns:
CodeTypeBase|NoneThe code type if this element has a type, or None otherwise.
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- class ansys.scadeone.core.svc.cgmapping.code.CodeTypeBase#
Bases:
CodeElementBase class for code elements that represent types.
- get_copy_function_name() str | None#
Get copy function name if it exists.
- Returns:
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_equality_function() CFunction | None#
Get the equality function for this type if it exists.
- Returns:
- Raises:
ValueErrorIf no cgmapping is set on this instance.
- get_equality_use_macro() str | None#
Get the equality use macro string for this type if it exists. It is the name of the C macro that conditionates equality function compilation. CArray, CStruct, and `CUnion types can have an equality use macro. CExternalType and CTypedef don’t have equality use macro thus always return None.