Goose  Artifact [050a761c77]

Artifact 050a761c77410e1df97dc5f9216d32aee9831d593dbed25554cc561616c7ae32:

  • File bs/builtins/helpers.h — part of check-in [2e993951e6] at 2019-09-21 21:43:31 on branch trunk —
    • Implemented the 'requires' and 'ensures' verification statements.
    • Verification statements are lazily parsed even for non template functions, so that they can see functions defined out of order, just like in function bodies.
    (user: achavasse size: 1082)

#ifndef EMPATHY_BUILTINS_HELPERS_H
#define EMPATHY_BUILTINS_HELPERS_H

#include "parse/parse.h"

namespace empathy::builtins
{
    extern void RegisterRule( sema::Env& env, const StringId& name, parse::Rule&& rule );
    extern void RegisterVerificationRule( sema::Env& env, const StringId& name, parse::Rule&& rule );

    // Utility function used to parse flow control statements, such as if and loops.
    // This parses a sub statement, which can be enclosed in a brace block or not.
    // It will get its own scope, with visibility rules setup to see the current
    // scope.
    // It returns a pointer to the final basic block generated by the statement.
    ptr< llr::BasicBlock > ParseSubStatement( parse::Parser& p, uint32_t precedence );

    enum class ValUnifyError
    {
        NoSolution,
        Ambiguous
    };

    // Unify the provided value with a value placeholder of the specified type,
    // and return the result or an error code.
    variant< Value, ValUnifyError > ConvertValueToType( const Context& c, const Value& val, const Term& type );
}

#endif