Support basic parsing function statements.
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
#ifndef MALACHSCRIPT_PARSEDSTATEMENT_HPP
|
||||
#define MALACHSCRIPT_PARSEDSTATEMENT_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "../../CoreData/AccessModifier.hpp"
|
||||
#include "../../CoreData/FuncAttr.hpp"
|
||||
#include "../../CoreData/TypeMod.hpp"
|
||||
#include "../../TextSpan.hpp"
|
||||
#include "../Expressions/ParsedExpression.hpp"
|
||||
#include "ParsedStatementKind.hpp"
|
||||
namespace MalachScript::Parser {
|
||||
class ParsedStatement {
|
||||
@@ -65,7 +70,7 @@ namespace MalachScript::Parser {
|
||||
|
||||
class ParsedNamespaceStatement : public ParsedStatementImpl<ParsedStatementKind::Namespace> {
|
||||
Identifier _identifier;
|
||||
const ParsedScriptStatement* _parsedScript;
|
||||
std::unique_ptr<const ParsedStatement> _parsedScript;
|
||||
|
||||
public:
|
||||
ParsedNamespaceStatement(TextSpan span, const Identifier& identifier, const ParsedScriptStatement* script)
|
||||
@@ -73,7 +78,100 @@ namespace MalachScript::Parser {
|
||||
_parsedScript(script) {}
|
||||
|
||||
[[nodiscard]] inline const Identifier& GetIdentifier() const noexcept { return _identifier; }
|
||||
[[nodiscard]] inline const ParsedScriptStatement* GetScript() const noexcept { return _parsedScript; }
|
||||
[[nodiscard]] inline const std::unique_ptr<const ParsedStatement>& GetScript() const noexcept {
|
||||
return _parsedScript;
|
||||
}
|
||||
};
|
||||
|
||||
class ParsedTypeStatement : public ParsedStatementImpl<ParsedStatementKind::Type> {
|
||||
bool _isConst;
|
||||
bool _isArray;
|
||||
bool _isHandle;
|
||||
ScopedIdentifier _scopedIdentifier;
|
||||
|
||||
public:
|
||||
ParsedTypeStatement(TextSpan span, bool isConst, bool isArray, bool isHandle,
|
||||
const ScopedIdentifier& scopedIdentifier)
|
||||
: ParsedStatementImpl<ParsedStatementKind::Type>(span), _isConst(isConst), _isArray(isArray),
|
||||
_isHandle(isHandle), _scopedIdentifier(scopedIdentifier) {}
|
||||
|
||||
[[nodiscard]] inline bool IsConst() const noexcept { return _isConst; }
|
||||
[[nodiscard]] inline bool IsArray() const noexcept { return _isArray; }
|
||||
[[nodiscard]] inline bool IsHandle() const noexcept { return _isHandle; }
|
||||
[[nodiscard]] inline const ScopedIdentifier& GetScopedIdentifier() const noexcept { return _scopedIdentifier; }
|
||||
};
|
||||
|
||||
class ParsedParamListStatement : public ParsedStatementImpl<ParsedStatementKind::ParamList> {
|
||||
public:
|
||||
class ParsedParameter {
|
||||
private:
|
||||
const ParsedTypeStatement* _typeStatement = nullptr;
|
||||
TypeMod _typeMod;
|
||||
Identifier _identifier;
|
||||
const ParsedExpression* _defaultExpression = nullptr;
|
||||
|
||||
public:
|
||||
ParsedParameter(){};
|
||||
|
||||
[[nodiscard]] const ParsedTypeStatement*& GetTypeStatement() noexcept { return _typeStatement; }
|
||||
[[nodiscard]] const ParsedTypeStatement* GetTypeStatement() const noexcept { return _typeStatement; }
|
||||
|
||||
[[nodiscard]] TypeMod& GetTypeMod() noexcept { return _typeMod; }
|
||||
[[nodiscard]] const TypeMod& GetTypeMod() const noexcept { return _typeMod; }
|
||||
|
||||
[[nodiscard]] Identifier& GetIdentifier() noexcept { return _identifier; }
|
||||
[[nodiscard]] const Identifier& GetIdentifier() const noexcept { return _identifier; }
|
||||
|
||||
[[nodiscard]] const ParsedExpression*& GetDefaultExpression() noexcept { return _defaultExpression; }
|
||||
[[nodiscard]] const ParsedExpression* GetDefaultExpression() const noexcept { return _defaultExpression; }
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<ParsedParameter> _parameters;
|
||||
|
||||
public:
|
||||
ParsedParamListStatement(TextSpan span, std::vector<ParsedParameter> parameters)
|
||||
: ParsedStatementImpl<ParsedStatementKind::ParamList>(span), _parameters(std::move(parameters)){};
|
||||
};
|
||||
|
||||
class ParsedFuncStatement : public ParsedStatementImpl<ParsedStatementKind::Func> {
|
||||
private:
|
||||
bool _isShared;
|
||||
bool _isExternal;
|
||||
AccessModifier _access;
|
||||
std::unique_ptr<const ParsedStatement> _type;
|
||||
bool _returnsReference;
|
||||
Identifier _identifier;
|
||||
std::unique_ptr<const ParsedStatement> _paramList;
|
||||
bool isConst;
|
||||
FuncAttr _funcAttr;
|
||||
std::unique_ptr<const ParsedStatement> _statBlock;
|
||||
|
||||
public:
|
||||
ParsedFuncStatement(const TextSpan& span, bool isShared, bool isExternal, AccessModifier access,
|
||||
const ParsedStatement* type, bool returnsReference, const Identifier& identifier,
|
||||
const ParsedStatement* paramList, bool isConst, FuncAttr funcAttr,
|
||||
const ParsedStatement* statBlock)
|
||||
: ParsedStatementImpl<ParsedStatementKind::Func>(span), _isShared(isShared), _isExternal(isExternal),
|
||||
_access(access), _type(type), _returnsReference(returnsReference), _identifier(identifier),
|
||||
_paramList(paramList), isConst(isConst), _funcAttr(funcAttr), _statBlock(statBlock) {}
|
||||
|
||||
[[nodiscard]] inline bool IsShared() const noexcept { return _isShared; }
|
||||
[[nodiscard]] inline bool IsExternal() const noexcept { return _isExternal; }
|
||||
[[nodiscard]] inline AccessModifier GetAccess() const noexcept { return _access; }
|
||||
[[nodiscard]] inline const std::unique_ptr<const ParsedStatement>& GetTypeStatement() const noexcept {
|
||||
return _type;
|
||||
}
|
||||
[[nodiscard]] inline bool ReturnsReference() const noexcept { return _returnsReference; }
|
||||
[[nodiscard]] inline const Identifier& GetIdentifier() const noexcept { return _identifier; }
|
||||
[[nodiscard]] inline const std::unique_ptr<const ParsedStatement>& GetParamList() const noexcept {
|
||||
return _paramList;
|
||||
}
|
||||
[[nodiscard]] inline bool IsConst() const noexcept { return isConst; }
|
||||
[[nodiscard]] inline FuncAttr GetFuncAttr() const noexcept { return _funcAttr; }
|
||||
[[nodiscard]] inline const std::unique_ptr<const ParsedStatement>& GetStatBlock() const noexcept {
|
||||
return _statBlock;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user