Simple binding for virtprops.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-01-09 15:33:34 +01:00
parent ce3d92e0a5
commit bce1b1c79c
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 29 additions and 6 deletions

View File

@ -209,6 +209,29 @@ namespace MalachScript::Binder {
break; break;
} }
case ParsedStatementKind::VirtProp: {
const auto* var = static_cast<const ParsedVirtPropStatement*>(statement);
const auto& typeStatement = var->GetReturnType();
// FIXME: Resolve namespace of scoped identifier
auto type = ResolveType(ns, typeStatement->GetScopedIdentifier().GetIdentifier());
if (!type.has_value()) {
log(DiagnosticLevel::Error, DiagnosticType::UnknownType, typeStatement->GetSpan(),
{typeStatement->GetScopedIdentifier().GetIdentifier().GetStdString()});
type = UnknownType;
}
if (activeType.has_value()) {
if (var->GetGetStatement() == nullptr && var->GetSetStatement() == nullptr) {
// FIXME: we're just adding properties as a field now, this is wrong.
activeType.value()->AddField(var->GetIdentifier(),
new BoundVariable(type.value(), var->GetAccess()));
} else {
// TODO: non-auto property.
}
} else {
throw std::logic_error("TODO: Property outside of class should log an error");
}
break;
}
default: break; default: break;
} }
} }

View File

@ -209,17 +209,17 @@ namespace MalachScript::Parser {
class ParsedVirtPropStatement : public ParsedStatementImpl<ParsedStatementKind::VirtProp> { class ParsedVirtPropStatement : public ParsedStatementImpl<ParsedStatementKind::VirtProp> {
public: public:
ParsedVirtPropStatement(const ScriptTextSpan& span, AccessModifier access, const ParsedStatement* returnType, ParsedVirtPropStatement(const ScriptTextSpan& span, AccessModifier access,
bool isReturnTypeRef, Identifier identifier, bool hasGet, bool getConst, const ParsedTypeStatement* returnType, bool isReturnTypeRef, Identifier identifier,
FuncAttr getAttr, const ParsedStatement* getStatement, bool hasSet, bool setConst, bool hasGet, bool getConst, FuncAttr getAttr, const ParsedStatement* getStatement,
FuncAttr setAttr, const ParsedStatement* setStatement) bool hasSet, bool setConst, FuncAttr setAttr, const ParsedStatement* setStatement)
: ParsedStatementImpl(span), _access(access), _returnType(returnType), _isReturnTypeRef(isReturnTypeRef), : ParsedStatementImpl(span), _access(access), _returnType(returnType), _isReturnTypeRef(isReturnTypeRef),
_identifier(identifier), _hasGet(hasGet), _getConst(getConst), _getAttr(getAttr), _identifier(identifier), _hasGet(hasGet), _getConst(getConst), _getAttr(getAttr),
_getStatement(getStatement), _hasSet(hasSet), _setConst(setConst), _setAttr(setAttr), _getStatement(getStatement), _hasSet(hasSet), _setConst(setConst), _setAttr(setAttr),
_setStatement(setStatement) {} _setStatement(setStatement) {}
[[nodiscard]] inline AccessModifier GetAccess() const noexcept { return _access; } [[nodiscard]] inline AccessModifier GetAccess() const noexcept { return _access; }
[[nodiscard]] inline const std::unique_ptr<const ParsedStatement>& GetReturnType() const noexcept { [[nodiscard]] inline const std::unique_ptr<const ParsedTypeStatement>& GetReturnType() const noexcept {
return _returnType; return _returnType;
} }
[[nodiscard]] inline bool IsReturnTypeRef() const noexcept { return _isReturnTypeRef; } [[nodiscard]] inline bool IsReturnTypeRef() const noexcept { return _isReturnTypeRef; }
@ -241,7 +241,7 @@ namespace MalachScript::Parser {
private: private:
AccessModifier _access; AccessModifier _access;
std::unique_ptr<const ParsedStatement> _returnType; std::unique_ptr<const ParsedTypeStatement> _returnType;
bool _isReturnTypeRef; bool _isReturnTypeRef;
Identifier _identifier; Identifier _identifier;