XCSG:StackVariable
A Local variable is a variable declared inside a Function.
Note that, unlike other variables, many local variables do not appear in XCSG graphs. Since local variables do not cause interprocedural flows, unless they have static storage, or their address is taken and passed to another method, they are typically represented in data flow only by Initialization and Assignment nodes.
Consider the following example:
function foo(){ int x = 5; x = x + 1; return x; }
This function always returns 6
, never 5
, or any other value. However, if we were to represent DataFlow using a single node for the LocalVariable x, we would see incoming data flow from the Literal 5
through an Initialization node to the LocalVariable x
, and another incoming data flow from the Operator +
, which would read x
and the literal 1
.
Trying to make sense of this data flow graph, we would see a self-referential loop incrementing the variable, and would (at best) be able to conclude that the value returned was 5 or greater.
For this reason, it is preferable to leave out an actual LocalVariable node, and instead connect the Initialization node x=
directly to the +
Operator, and only the final Assignment node to the Return, giving a more realistic, tree-like structure, leaving it clear that the returned value comes from executing 5 + 1.
If the address of a local variable is taken, it then becomes an addressed location in memory, which may be modified by other Functions, or even other threads, and a typical conservative analysis will then reify the LocalVariable in the XCSG graph, and connect it via InterproceduralDataFlow edges from writes and to reads.
Specification
Metaclass | StackVariable |
---|---|
Extends | Variable |
Description | A Variable declared inside a Function. |
All Superkinds | Variable, Node, ModelElement |
---|
Specified In Edges
| ||||
---|---|---|---|---|
Inherited From | In Edge | Predecessor | Multiplicity | Description |
Variable | DataFlow (Edge) | DataFlow (Node) | ✱ | Connects DataFlow nodes to one another and to Variables, linking the origin of data to locations that it is modified or consumed. |
Specified Out Edges
| ||||
---|---|---|---|---|
Inherited From | Out Edge | Successor | Multiplicity | Description |
Variable | DataFlow (Edge) | DataFlow (Node) | ✱ | Connects DataFlow nodes to one another and to Variables, linking the origin of data to locations that it is modified or consumed.
|
DefinedAs | TypeAlias | 0..1 | Connects a Variable or DataFlow node which received its Type via a TypeAlias (such as a C/C++ typedef) to that TypeAlias. | |
InstanceVariableWritten | InstanceVariableAssignment | ✱ | Connects a value (DataFlow (Node) or Variable) representing an object instance to an InstanceVariableAssignment representing a write to a field of that object. | |
TypeOf | Type | 1 | Links a Variable or DataFlow node to its Type |
Known Possible In Edges
| ||||
---|---|---|---|---|
Inherited From | In Edge | Predecessor | Multiplicity | Description |
Variable | HasVariable | Namespace | 1 | Links a Classifier or Package to one of its Variables.
|
InterproceduralDataFlow | Assignment | ✱ | Represents data flows between Functions, or involving Variables visible to multiple Functions. | |
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 |
Variable | InterproceduralDataFlow | DataFlow (Node) | ✱ | Represents data flows between Functions, or involving Variables visible to multiple Functions. |
Node | Contains | Node | ✱ | Indicates that the predecessor contains the successor in a sense specified by the specific type of Contains edge. |