Goose  Diff

Differences From Artifact [8bde363f70]:

  • File bs/builtins/statements/if.cpp — part of check-in [2efa23555d] at 2019-08-11 01:26:17 on branch trunk —
    • ir: created a new type for LocationId which is handled in a specific way so that two LocationIds are always considered equal by pattern matching. This prevent the values' locationIds stored in ir expressions from fucking up everything.
    • propagate value locations in a few places: in the parser, when resolving invocations and when doing eager evaluation. There are probably a lot of other places still missing.
    • converted all the builtin statements to use the DiagnosticsManager.
    (user: achavasse size: 4312)

To Artifact [3760ba10fe]:

  • File bs/builtins/statements/if.cpp — part of check-in [157221e014] at 2019-08-11 13:36:12 on branch trunk — Ported more error messages to the DiagnosticsManager. (user: achavasse size: 4324)

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();
                }
            }