* @file
*
* This file manages type check information that should be controlled by scope.
*/
#ifndef CANGJIE_SEMA_EXTRASCOPES_H
#define CANGJIE_SEMA_EXTRASCOPES_H
#include "cangjie/Sema/TypeManager.h"
#include "cangjie/AST/ASTContext.h"
#include "TypeCheckerImpl.h"
#include "Diags.h"
namespace Cangjie {
class TyVarScope {
public:
explicit TyVarScope(TypeManager& tyMgr);
~TyVarScope();
TyVarScope(const TyVarScope& other) = delete;
TyVarScope& operator =(const TyVarScope& other) = delete;
private:
friend class TypeManager;
void AddTyVar(Ptr<AST::GenericsTy> tyVar);
std::vector<Ptr<AST::GenericsTy>> tyVars;
TypeManager& tyMgr;
std::string scope;
};
class InstCtxScope {
public:
explicit InstCtxScope(TypeChecker::TypeCheckerImpl& typeChecker);
~InstCtxScope();
* If we are using FuncA within FuncB, then current decl is FuncB,
* referenced decl is FuncA.
*/
void SetRefDecl(const AST::Decl& decl, Ptr<AST::Ty> instTy);
bool SetRefDecl(ASTContext& ctx, AST::FuncDecl& fd, AST::CallExpr& ce);
void SetRefDeclSimple(const AST::FuncDecl& fd, const AST::CallExpr& ce);
InstCtxScope(const InstCtxScope& other) = delete;
InstCtxScope& operator =(const InstCtxScope& other) = delete;
private:
friend class TypeManager;
SubstPack curMaps;
SubstPack refMaps;
SubstPack maps;
TypeManager& tyMgr;
DiagnosticEngine& diag;
TypeChecker::TypeCheckerImpl& typeChecker;
bool GenerateExtendGenericTypeMapping(
const ASTContext& ctx, const AST::FuncDecl& fd, const AST::CallExpr& ce, SubstPack& typeMapping);
bool GenerateTypeMappingByCallContext(
const ASTContext& ctx, const AST::FuncDecl& fd, const AST::CallExpr& ce, SubstPack& typeMapping);
void GenerateSubstPackByTyArgs(
SubstPack& tmaps, const std::vector<Ptr<AST::Type>>& typeArgs, const AST::Generic& generic) const;
};
}
#endif