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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
auto UsingValProvider = [content, localIdentity, bInUse, nameSid, nameLoc]( Env& e, const Term& identity, const Term& contextId, Term& result ) mutable
{
auto& dm = DiagnosticsManager::GetInstance();
if( holds_alternative< vector< TermLoc > >( content ) )
{
if( bInUse )
{
dm.emitErrorMessage( nameLoc, "recursive using expression." );
return Env::Status::NoMatch;
}
bInUse = true;
Context localContext( e.shared_from_this(), localIdentity );
auto tokProvider = lex::MakeVectorAdapter( get< vector< TermLoc > >( content ) );
auto r = make_shared< parse::Resolver >( tokProvider, localContext );
Parser p( r );
if( !p.parseExpression() )
{
// TODO: Perhaps return a poison value instead of nothing?
dm.emitErrorMessage( nameLoc, "invalid expression." );
return Env::Status::NoMatch;
}
auto result = p.peekLastValue();
if( !result )
{
// TODO: Perhaps return a poison value instead of nothing?
dm.emitErrorMessage( nameLoc, "invalid expression." );
return Env::Status::NoMatch;
}
if( !result->isConstant() )
{
// TODO: Perhaps return a poison value instead of nothing?
dm.emitErrorMessage( nameLoc, "using expression doesn't evaluate to a constant." );
return Env::Status::NoMatch;
}
content = ValueToIRExpr( *result );
bInUse = false;
}
result = get< Term >( content );
|
>
>
>
>
>
>
>
|
<
>
>
>
|
<
<
>
<
<
>
|
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
auto UsingValProvider = [content, localIdentity, bInUse, nameSid, nameLoc]( Env& e, const Term& identity, const Term& contextId, Term& result ) mutable
{
auto& dm = DiagnosticsManager::GetInstance();
if( holds_alternative< vector< TermLoc > >( content ) )
{
// In case of errors, we poison the result so that code invoking
// this using expression will not emit cascading errors.
if( bInUse )
{
dm.emitErrorMessage( nameLoc, "recursive using expression." );
// We only poison the result here, not "content", since the token
// vector that it contains is currently in use. It will get poisoned
// down the line once the parent recursion level of this using
// expression finishes.
result = ValueToIRExpr( PoisonValue() );
return Env::Status::Success;
}
bInUse = true;
Context localContext( e.shared_from_this(), localIdentity );
auto tokProvider = lex::MakeVectorAdapter( get< vector< TermLoc > >( content ) );
auto r = make_shared< parse::Resolver >( tokProvider, localContext );
Parser p( r );
if( !p.parseExpression() )
{
dm.emitErrorMessage( nameLoc, "invalid expression." );
content = ValueToIRExpr( PoisonValue() );
result = get< Term >( content );
bInUse = false;
return Env::Status::Success;
}
auto result = p.peekLastValue();
if( !result )
{
dm.emitErrorMessage( nameLoc, "invalid expression." );
result = PoisonValue();
}
if( !result->isConstant() )
{
dm.emitErrorMessage( nameLoc, "using expression doesn't evaluate to a constant." );
result = PoisonValue();
}
content = ValueToIRExpr( *result );
bInUse = false;
}
result = get< Term >( content );
|