16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
auto& dm = DiagnosticsManager::GetInstance();
auto pPrecBB = p.currentBB();
auto np = p.makeNestedParser();
if( !np.parseExpression( precedence::IfStmt ) )
{
dm.emitErrorMessage( locationId, "expected an expression following the if statement." );
return false;
}
auto condVal = np.popValue();
if( !condVal )
{
dm.emitErrorMessage( locationId, "expected an expression following the if statement." );
return false;
}
const auto& context = p.resolver()->context();
auto converted = ConvertValueToType( context, *condVal, GetValueType< bool >() );
if( holds_alternative< ValUnifyError >( converted ) )
{
|
|
|
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
auto& dm = DiagnosticsManager::GetInstance();
auto pPrecBB = p.currentBB();
auto np = p.makeNestedParser();
if( !np.parseExpression( precedence::IfStmt ) )
{
dm.emitErrorMessage( locationId, "expected an expression following the if statement.", 0 );
return false;
}
auto condVal = np.popValue();
if( !condVal )
{
dm.emitErrorMessage( locationId, "expected an expression following the if statement.", 0 );
return false;
}
const auto& context = p.resolver()->context();
auto converted = ConvertValueToType( context, *condVal, GetValueType< bool >() );
if( holds_alternative< ValUnifyError >( converted ) )
{
|
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
|
return false;
}
auto pThenBB = ParseSubStatement( p, precedence::IfStmt );
if( !pThenBB )
{
dm.emitErrorMessage( p.resolver()->getCurrentLocation(), "expected a statement after the if condition." );
return false;
}
// Retrieve the successor block of the then branch, if any
auto pThenSuccBB = p.currentBB();
ptr< llr::BasicBlock > pElseBB, pElseSuccBB;
auto next = p.resolver()->lookAheadUnresolved();
if( next )
{
const auto* nextSid = get_if< StringId >( &next->first );
if( nextSid && *nextSid == "else"_sid )
{
p.resolver()->consumeUnresolved();
pElseBB = ParseSubStatement( p, precedence::IfStmt );
if( !pElseBB )
{
dm.emitErrorMessage( p.resolver()->getCurrentLocation(), "expected a statement after 'else'." );
return false;
}
// Retrieve the successor block of the else branch, if any
pElseSuccBB = p.currentBB();
}
}
|
|
|
|
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
|
return false;
}
auto pThenBB = ParseSubStatement( p, precedence::IfStmt );
if( !pThenBB )
{
dm.emitErrorMessage( p.resolver()->getCurrentLocation(), "expected a statement after the if condition.", 0 );
return false;
}
// Retrieve the successor block of the then branch, if any
auto pThenSuccBB = p.currentBB();
ptr< llr::BasicBlock > pElseBB, pElseSuccBB;
auto next = p.resolver()->lookAheadUnresolved();
if( next )
{
const auto* nextSid = get_if< StringId >( &next->first );
if( nextSid && *nextSid == "else"_sid )
{
p.resolver()->consumeUnresolved();
pElseBB = ParseSubStatement( p, precedence::IfStmt );
if( !pElseBB )
{
dm.emitErrorMessage( p.resolver()->getCurrentLocation(), "expected a statement after 'else'.", 0 );
return false;
}
// Retrieve the successor block of the else branch, if any
pElseSuccBB = p.currentBB();
}
}
|