Difference between revisions of "XCSG:Pointer"

From AtlasWiki
Jump to: navigation, search
(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...")
 
(remove self link)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
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]].
+
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==
 
==Specification==
 
{{Node
 
{{Node
| extends = ReferenceType, AddressableEntity
+
| extends = Type
| description = An explicit reference to an addressable entity
+
| description = A typed, explicit reference to a memory location.
 
| references = typedref native int, native unsigned int [27, p. 156],
 
| references = typedref native int, native unsigned int [27, p. 156],
 
unmanaged pointers [28, p. 5, section 1.1.3.1], managed pointers [28, p. 5, section 1.1.3.2],
 
unmanaged pointers [28, p. 5, section 1.1.3.1], managed pointers [28, p. 5, section 1.1.3.2],
Line 12: Line 12:
  
 
{{XCSGTag
 
{{XCSGTag
| name = Managed
+
| name = readOnly
| description = Present if the referenced object is allocated in garbage collected (managed) memory  [31, p. 73, Managed and unmanaged pointers]
+
| description = Indicates that the pointer does not allow modification of the data to which it points.
}}
+
 
+
{{Attribute
+
| name = LevelOfIndirection
+
| description = The number of times the pointer must be dereferenced to reach the referenced type.
+
| type = Integer
+
| default = 1
+
 
}}
 
}}
  
 
==Semantics==
 
==Semantics==
Variables whose declared type is a ReferenceType 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.
+
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 manipuled. 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.
+
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++).
refType specifies the type of the entity referred by the Pointer.
 
  
The value of the Pointer is a reference to an entity this type.
+
=== 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.
 +
 
 +
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.
 +
 
  
The levelOfIndirection associated with the Pointer must be greater than or equal to one. If greater than one, it represents a pointer to a pointer to and instance of the referenced type, a pointer to a pointer to a pointer to an instance of the referenced type, etc.
 
  
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.
+
<!-- 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].
+
Managed pointers cannot be null, and a managed pointer cannot point to another managed pointer [28, p. 6]. -->

Latest revision as of 19:11, 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 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.