XCSG:Pointer

From AtlasWiki
Jump to: navigation, search

A Pointer in XCSG is a possible data type for a Variable; in XCSG, such a variable is represented as variable node whose TypeOf edge goes to a Pointer.

Specification

Metaclass Pointer
Extends Type
Description A typed, explicit reference to a memory location.
All Superkinds Type, Node, ModelElement
Specified In Edges

Inherited From In Edge Predecessor Multiplicity Description
Type AliasedType TypeAlias Connects a TypeAlias to the Type or TypeAlias it was declared to duplicate.

ArrayElementType ArrayType 0..1 Connects an ArrayType to the Type of elements contained by arrays of that type.
C:CompletedBy OpaqueType 1 Connects an OpaqueType to the complete definition of the corresponding Type.
ReferencedType Pointer Connects a Pointer to the Type of the data pointed to.
Returns Function Connects a Function to the Type of its return value (which may be Void).
TypeOf Variable Links a Variable or DataFlow node to its Type

DataFlow (Node)
Specified Out Edges
Out Edge Successor Multiplicity Description
ReferencedType Type 1 Connects a Pointer to the Type of the data pointed to.

Inherited From Out Edge Successor Multiplicity Description
Type TypeChecked InstanceOf Connects a Type (usually a Classifier) to an InstanceOf test.
Known Possible In Edges

Inherited From In Edge Predecessor Multiplicity Description
Node Contains Node 1 Indicates that the predecessor contains the successor in a sense specified by the specific type of Contains edge.
Known Possible Out Edges

Inherited From Out Edge Successor Multiplicity Description
Node Contains Node Indicates that the predecessor contains the successor in a sense specified by the specific type of Contains edge.
Tag readOnly
Description Indicates that the pointer does not allow modification of the data to which it points.

Semantics

A Variable whose TypeOf edge points to a Classifier represents a reference. Such references are opaque; the addresses they represent cannot be manipulated. The only operations on such references are involve assignment to type-compatible variables, comparison using equality and inequality, and use of the reference to gain access to the referenced object.

In contrast, variables whose type is Pointer represent explicit references that can be manipulated. For instance, it is possible to increment and decrement array element pointers, add or subtract values from them, and subtract one pointer from another if they both refer to the same array dimension.

Since the JVM does not support pointers in this sense, our definition of pointer semantics is based on Microsoft’s MS-IL, and on languages with pointer operations (such as C++).

C/C++ const and XCSG Pointers

In C and C++, it is customary to think of a variable whose type is any pointer type as a pointer; but in XCSG, the distinction between the variable and the pointer data type is important.

What is typically called a "const pointer" is represented in XCSG as an immutable Variable whose TypeOf edge points to an ordinary Pointer that allows modification of the data it points to.

What is called a "pointer to const" is represented in XCSG as a Variable whose TypeOf edge points to a Pointer tagged readOnly, indicating that the pointer does not allow the data it points to to be modified.