MalachScript/src/Binder/Binder.hpp

37 lines
1.8 KiB
C++

#ifndef MALACHSCRIPT_BINDER_HPP
#define MALACHSCRIPT_BINDER_HPP
#include <functional>
#include "../Diagnostics/Logger.hpp"
#include "../Parser/Statements/ParsedStatement.hpp"
#include "BoundNamespace.hpp"
namespace MalachScript::Binder {
class Binder {
public:
using log_func = const std::function<void(Diagnostics::DiagnosticLevel level, Diagnostics::DiagnosticType,
const ScriptTextSpan&, const std::vector<std::string>&)>;
static void Bind(BoundNamespace* ns,
const std::vector<const MalachScript::Parser::ParsedStatement*>& statements,
const log_func& log);
private:
// Register all types and namespaces
static void TypeRegistrationFirstPass(BoundNamespace* ns,
const MalachScript::Parser::ParsedStatement* statement,
std::optional<BoundType*> activeType, const log_func& log);
// Register typedefs and type inheritance
static void TypeRegistrationSecondPass(BoundNamespace* ns,
const MalachScript::Parser::ParsedStatement* statement,
std::optional<BoundType*> activeType, const log_func& log);
// Register variables, fields, etc
static void TypeRegistrationThirdPass(BoundNamespace* ns,
const MalachScript::Parser::ParsedStatement* statement,
std::optional<BoundType*> activeType, const log_func& log);
// Finalise types, calculating size.
static void FinaliseTypes(BoundNamespace* ns, const log_func& log);
};
}
#endif // MALACHSCRIPT_BINDER_HPP