Difference between revisions of "XCSG:Pointer"
(Created page with "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. ==Spec...") |
(→Semantics) |
||
Line 24: | Line 24: | ||
==Semantics== | ==Semantics== | ||
− | Variables whose | + | [[Variables]] whose [[TypeOf]] edge points to a [[Classifier]] represent references. 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 | + | 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++). | 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++ <code>const</code> 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 "<code>const</code> 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. | |
− | Managed pointers cannot be null, and a managed pointer cannot point to another managed pointer [28, p. 6]. | + | What is called a "pointer to <code>const</code>" 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. |
+ | |||
+ | |||
+ | |||
+ | <!-- We're not indexing any CLS languages yet, so managed pointers aren't a thing to us...the following (from the XCIL document) may be worth adding if we do later: The deallocation of referenced objects is the responsibility of the application unless the pointer is managed. Otherwise, it is the responsibility of the garbage collector. | ||
+ | |||
+ | Managed pointers cannot be null, and a managed pointer cannot point to another managed pointer [28, p. 6]. --> |
Revision as of 18:48, 18 April 2014
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 | , ReferenceType, AddressableEntity |
Description | An explicit reference to an addressable entity |
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 | Managed |
---|---|
Description | Present if the referenced object is allocated in garbage collected (managed) memory [31, p. 73, Managed and unmanaged pointers] |
Attribute | LevelOfIndirection |
---|---|
Description | The number of times the pointer must be dereferenced to reach the referenced type. |
Type | Integer |
Required | Yes |
Semantics
Variables whose TypeOf edge points to a Classifier represent references. 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.