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;
}
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;
}
}

View File

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