forked from kframework/c-semantics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompound-literal.k
84 lines (76 loc) · 3.61 KB
/
compound-literal.k
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
module C-COMPOUND-LITERAL
imports C-DYNAMIC-SYNTAX
imports C-ENV-SYNTAX
imports C-MEMORY-ALLOC-SYNTAX
imports C-SEQUENCE-POINT-SYNTAX
imports C-SETTINGS-SYNTAX
imports C-SYMLOC-SYNTAX
imports C-SYNTAX
imports C-TYPING-SYNTAX
imports C-CONFIGURATION
/*@ \fromStandard{\source[n1570]{\para{6.5.2.5}{3--7}}}{
A postfix expression that consists of a parenthesized type name followed
by a brace-enclosed list of initializers is a \emph{compound literal}. It
provides an unnamed object whose value is given by the initializer list.
If the type name specifies an array of unknown size, the size is
determined by the initializer list as specified in 6.7.9, and the type of
the compound literal is that of the completed array type. Otherwise (when
the type name specifies an object type), the type of the compound literal
is that specified by the type name. In either case, the result is an
lvalue.
The value of the compound literal is that of an unnamed object initialized
by the initializer list. If the compound literal occurs outside the body
of a function, the object has static storage duration; otherwise, it has
automatic storage duration associated with the enclosing block.
All the semantic rules for initializer lists in 6.7.9 also apply to
compound literals.
String literals, and compound literals with const-qualified types, need
not designate distinct objects.
}*/
/*@ We use \kinline{compoundLiteral(N:Int)} here as the identifier of the
compound literal.*/
// comes back from figureInit as initValue(id, type, inits)
rule <k> initCompoundLiteral(initValue(X:CId, T:Type, Init:K))
=> initCompoundLiteralHelper(initValue(X, T, Init), !I:Int @ D)
...</k>
<compound-lit-map> M:Map </compound-lit-map>
<duration> D:Duration </duration>
requires notBool (X in_keys(M))
[structural]
rule <k> initCompoundLiteral(initValue(X:CId, T:Type, Init:K))
=> initCompoundLiteralHelper(initValue(X, T, Init), !I:Int @ D)
...</k>
<compound-lit-map>... X |-> Base:SymBase ...</compound-lit-map>
<local-addresses> Addrs:Set </local-addresses>
<duration> D:Duration </duration>
requires notBool (Base in Addrs)
[structural]
syntax KItem ::= initCompoundLiteralHelper(K, SymBase)
rule <k> initCompoundLiteralHelper(
initValue(X:CId, T:Type, Init:K),
Base:SymBase)
=> allocObject(Base, T)
~> addToEnv(X, Base)
~> giveType(X, T)
~> allowInit(Init)
~> sequencePoint
~> X
...</k>
<compound-lit-map> M:Map => M[X <- Base] </compound-lit-map>
<local-addresses>... .Set => SetItem(Base) </local-addresses>
[structural]
// This and the compound-lit-map is apparently needed to properly handle
// gotos. An instance (i.e., syntactic occurance) of a compound literal
// apparently must always refer to the same object, even if it is
// encountered multiple times (e.g., when in the body of a loop).
rule <k> initCompoundLiteral(initValue(X:CId, T:Type, Init:K))
=> addToEnv(X, Base)
~> giveType(X, T)
~> allowInit(Init)
~> sequencePoint
~> X
...</k>
<local-addresses>... SetItem(Base) ...</local-addresses>
<compound-lit-map>... X |-> Base:SymBase ...</compound-lit-map>
[structural]
endmodule