80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
auto bb = cfg->currentBB();
if( !bb )
return PoisonValue();
// 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], initValType ) initFunc )
// Args: ( pat, Initialize )
//
// Where pat is the TNamedDecl's type pattern and initValType is the initialization
// expression's type.
// We construct the above expressions and unify them. The best solution (if any)
// will give us the wanted type and the function to invoke to initialize it.
// Create the _ texpr.
static auto anyTVar = ValueToIRExpr( ToValue( TVar( "_"_sid ) ) );
// The $T texpr.
static auto TTVar = ValueToIRExpr( ToValue( TVar( "T"_sid ) ) );
// Create the LocalVar[$T] param.
auto locVarPatParam = ValueToIRExpr( ToValue( TNamedDecl( GetValueType< LocalVar >( TTVar ), "lv"_sid ) ) );
auto initValPattern = ValueToIRExpr( ValuePattern( TSID( constant ), initVal.type(), MkHole( "_"_sid ) ) );
// Create the _ ( LocalVar[pat], initType ) initFunc param.
auto initFuncTFTParam = ValueToIRExpr( ToValue(
TNamedDecl( ValueToIRExpr( ToValue( TFuncType( DomainAny(), anyTVar, VEC( move( locVarPatParam ), move( initValPattern ) ),
make_shared< vector< TermLoc > >(), make_shared< vector< TermLoc > >() ) ) ), "initFunc"_sid ) ) );
// Create our parameter list pattern.
auto paramPat = VEC(
*BuildTemplateSignature( c, TTVar ),
*BuildTemplateSignature( c, initFuncTFTParam )
);
|
|
|
|
|
|
|
|
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
auto bb = cfg->currentBB();
if( !bb )
return PoisonValue();
// 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, _ ( MutRef[$T], initValType ) initFunc )
// Args: ( pat, Initialize )
//
// Where pat is the TNamedDecl's type pattern and initValType is the initialization
// expression's type.
// We construct the above expressions and unify them. The best solution (if any)
// will give us the wanted type and the function to invoke to initialize it.
// Create the _ texpr.
static auto anyTVar = ValueToIRExpr( ToValue( TVar( "_"_sid ) ) );
// The $T texpr.
static auto TTVar = ValueToIRExpr( ToValue( TVar( "T"_sid ) ) );
// Create the MutRef[$T] param.
auto mutRefParamPattern = ValueToIRExpr( ToValue( TNamedDecl( GetValueType< Reference >( TTVar, ReferenceType::Behavior::Mutable ), "lv"_sid ) ) );
auto initValPattern = ValueToIRExpr( ValuePattern( TSID( constant ), initVal.type(), MkHole( "_"_sid ) ) );
// Create the _ ( MutRef[pat], initType ) initFunc param.
auto initFuncTFTParam = ValueToIRExpr( ToValue(
TNamedDecl( ValueToIRExpr( ToValue( TFuncType( DomainAny(), anyTVar, VEC( move( mutRefParamPattern ), move( initValPattern ) ),
make_shared< vector< TermLoc > >(), make_shared< vector< TermLoc > >() ) ) ), "initFunc"_sid ) ) );
// Create our parameter list pattern.
auto paramPat = VEC(
*BuildTemplateSignature( c, TTVar ),
*BuildTemplateSignature( c, initFuncTFTParam )
);
|