16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
-
+
+
+
+
|
Value DeclareLocalVar( Parser& p, const Term& type, StringId name, const optional< Value >& initializer )
{
auto cfgId = p.cfg()->uniqueId();
auto index = p.cfg()->getNewTemporaryIndex();
LocalVar lv( type, cfgId, index );
auto bb = p.currentBB();
auto bb = p.cfg()->currentBB();
if( !bb )
return PoisonValue();
auto typeVal = *ValueFromIRExpr( type );
bb->emplace_back( AllocVar( typeVal, cfgId, index ) );
if( initializer )
{
DiagnosticsContext dc( 0, "When invoking InitializeLocalVar." );
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
+
+
+
+
|
p.resolver()->clearLookAheadCache();
return locVar;
}
Value DeclareLocalVarWithTypeInference( Parser& p, const Term& typeTExpr, StringId name, const Value& initVal )
{
auto bb = p.cfg()->currentBB();
if( !bb )
return PoisonValue();
const auto& c = p.resolver()->context();
// To infer the type and obtain a suitable initialization function,
// we want the declaration to behave as if it were the following function call:
// Params: ( $T, _ ( LocalVar[$T], initVal ) initFunc )
// Args: ( pat, InitializeLocalVar )
//
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
-
|
// Retrieve the texpr's location and set it on the inferred type. This way if an
// error occurs later with it, for instance when calling LowerType on it during codegen,
// it will have a meaningful location for the error message to attach itself on.
uint32_t typeLoc = ValueFromIRExpr( typeTExpr )->locationId();
LocalVar lv( type, cfgId, index );
auto bb = p.currentBB();
bb->emplace_back( AllocVar( ValueFromIRExpr( lv.type() )->setLocationId( typeLoc ), cfgId, index ) );
p.pushValue( ResolveInvocation( c, GetInvocationRule( *c.env(), initializerVal ), initializerVal,
MakeTuple( ToValue( lv ), initVal ) ) );
auto locVar = ToValue( lv );
auto identity = AppendToVectorTerm( p.resolver()->context().identity(), name );
|