[VER] 0.3.3-alpha
[FEAT] interface + impl 支持! Duck Typing + 严格的检查让语言健壮 [FEAT][IMPL] 增加辅助函数 isTypeMatch等 [IMPL] TypeInfo构造函数FString 现在 explicit
This commit is contained in:
59
src/Ast/Statements/InterfaceDefSt.hpp
Normal file
59
src/Ast/Statements/InterfaceDefSt.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <Ast/functionParameters.hpp>
|
||||
#include <Ast/astBase.hpp>
|
||||
|
||||
|
||||
namespace Fig::Ast
|
||||
{
|
||||
/*
|
||||
|
||||
interface Readable
|
||||
{
|
||||
read() -> String
|
||||
{
|
||||
// default
|
||||
}
|
||||
|
||||
flush() -> Null; // non-default
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
struct InterfaceMethod
|
||||
{
|
||||
FString name;
|
||||
FunctionParameters paras;
|
||||
FString returnType;
|
||||
|
||||
BlockStatement defaultBody = nullptr; // nullptr is non-default func
|
||||
|
||||
bool hasDefaultBody() const
|
||||
{
|
||||
return defaultBody != nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class InterfaceDefAst final : public StatementAst
|
||||
{
|
||||
public:
|
||||
FString name;
|
||||
std::vector<InterfaceMethod> methods;
|
||||
std::vector<FString> parents; // Feature, NOT NOW
|
||||
bool isPublic;
|
||||
|
||||
InterfaceDefAst()
|
||||
{
|
||||
type = AstType::InterfaceDefSt;
|
||||
}
|
||||
|
||||
InterfaceDefAst(FString _name, std::vector<InterfaceMethod> _methods, bool _isPublic) :
|
||||
name(std::move(_name)), methods(std::move(_methods)), isPublic(_isPublic)
|
||||
{
|
||||
type = AstType::InterfaceDefSt;
|
||||
}
|
||||
};
|
||||
|
||||
using InterfaceDef = std::shared_ptr<InterfaceDefAst>;
|
||||
};
|
||||
Reference in New Issue
Block a user