Path: blob/master/Analysis/include/Luau/BuiltinDefinitions.h
2727 views
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details1#pragma once23#include "Luau/Scope.h"4#include "Luau/Type.h"56#include <optional>78namespace Luau9{1011inline constexpr char kRequireTagName[] = "require";1213struct Frontend;14struct GlobalTypes;15struct TypeChecker;16struct TypeArena;17struct Subtyping;1819void registerBuiltinGlobals(Frontend& frontend, GlobalTypes& globals, bool typeCheckForAutocomplete = false);20TypeId makeUnion(TypeArena& arena, std::vector<TypeId>&& types);21TypeId makeIntersection(TypeArena& arena, std::vector<TypeId>&& types);2223/** Build an optional 't'24*/25TypeId makeOption(NotNull<BuiltinTypes> builtinTypes, TypeArena& arena, TypeId t);2627/** Small utility function for building up type definitions from C++.28*/29TypeId makeFunction( // Monomorphic30TypeArena& arena,31std::optional<TypeId> selfType,32std::initializer_list<TypeId> paramTypes,33std::initializer_list<TypeId> retTypes,34bool checked = false35);3637TypeId makeFunction( // Polymorphic38TypeArena& arena,39std::optional<TypeId> selfType,40std::initializer_list<TypeId> generics,41std::initializer_list<TypePackId> genericPacks,42std::initializer_list<TypeId> paramTypes,43std::initializer_list<TypeId> retTypes,44bool checked = false45);4647TypeId makeFunction( // Monomorphic48TypeArena& arena,49std::optional<TypeId> selfType,50std::initializer_list<TypeId> paramTypes,51std::initializer_list<std::string> paramNames,52std::initializer_list<TypeId> retTypes,53bool checked = false54);5556TypeId makeFunction( // Polymorphic57TypeArena& arena,58std::optional<TypeId> selfType,59std::initializer_list<TypeId> generics,60std::initializer_list<TypePackId> genericPacks,61std::initializer_list<TypeId> paramTypes,62std::initializer_list<std::string> paramNames,63std::initializer_list<TypeId> retTypes,64bool checked = false65);6667void attachMagicFunction(TypeId ty, std::shared_ptr<MagicFunction> fn);68Property makeProperty(TypeId ty, std::optional<std::string> documentationSymbol = std::nullopt);69void assignPropDocumentationSymbols(TableType::Props& props, const std::string& baseName);7071std::string getBuiltinDefinitionSource();72std::string getTypeFunctionDefinitionSource();7374void addGlobalBinding(GlobalTypes& globals, const std::string& name, TypeId ty, const std::string& packageName);75void addGlobalBinding(GlobalTypes& globals, const std::string& name, Binding binding);76void addGlobalBinding(GlobalTypes& globals, const ScopePtr& scope, const std::string& name, TypeId ty, const std::string& packageName);77void addGlobalBinding(GlobalTypes& globals, const ScopePtr& scope, const std::string& name, Binding binding);78std::optional<Binding> tryGetGlobalBinding(GlobalTypes& globals, const std::string& name);79Binding* tryGetGlobalBindingRef(GlobalTypes& globals, const std::string& name);80TypeId getGlobalBinding(GlobalTypes& globals, const std::string& name);818283/** A number of built-in functions are magical enough that we need to match on them specifically by84* name when they are called. These are listed here to be used whenever necessary, instead of duplicating this logic repeatedly.85*/8687bool matchSetMetatable(const AstExprCall& call);88bool matchTableFreeze(const AstExprCall& call);89bool matchAssert(const AstExprCall& call);90bool matchTypeOf(const AstExprCall& call);9192// Returns `true` if the function should introduce typestate for its first argument.93bool shouldTypestateForFirstArgument(const AstExprCall& call);9495} // namespace Luau969798