Declaration base classes#

The Declaration class serves as the base class for all declarations of constructs with an identifier. Declarations of the same kind (e.g., constant, type, sensor, group) are grouped into a list of declarations, contained within classes derived from GlobalDeclaration.

../../../../_images/global.svg

Fig. 3 Declaration classes hierarchy#

Note

In Swan, a global declaration can contain multiple declarations. For example, one can write: const C1: int32; C2: int32; or const C1: int32; const C2: int32;. While the Swan editor produces the second form, having a list of declarations in the first form is also valid.

class ansys.scadeone.core.swan.Declaration(id: Identifier, pragmas: List[Pragma] | None = None)#

Bases: HasPragma

Base class for declarations.

get_full_path() str#

Full path of Swan construct.

static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property id: Identifier#

Language item identifier.

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

property model: IModel#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property pragmas: List[Pragma]#

List of pragmas.

class ansys.scadeone.core.swan.GlobalDeclaration#

Bases: ModuleItem

Abstract class for global declarations:

  • type declaration list

  • constant declaration list

  • sensor declaration list

  • group declarations

get_full_path() str#

Full path of Swan construct.

static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

property model: IModel#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

class ansys.scadeone.core.swan.ProtectedDecl(markup: str, data: str, pragmas: List[Pragma] | None = None)#

Bases: ProtectedItem, GlobalDeclaration, HasPragma

Protected declaration.

get_full_path() str#

Full path of Swan construct.

has_markup(markup: str) bool#

Check if protected data has the specified markup.

Parameters:
markupstr

String markup.

Returns:
result: bool

True when instance markup is same as parameter.

static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property data: str#

Protected data between markups.

Returns:
str

Protected data.

property is_const: bool#

Protected const declaration.

property is_group: bool#

Protected group declaration.

property is_operator: bool#

Protected operator declaration.

Note: operator declaration within {text% … %text} is parsed.

property is_protected: bool#

Tell if item is syntactically protected and provided as a string.

property is_sensor: bool#

Protected sensor declaration.

property is_type: bool#

Protected type declaration.

property markup: str#

Protection markup.

Returns:
str

Markup string.

property model: IModel#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property pragmas: List[Pragma]#

List of pragmas.