Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ add_library(libpl ${LIBRARY_TYPE}
source/pl/core/ast/ast_node_variable_decl.cpp
source/pl/core/ast/ast_node_while_statement.cpp

source/pl/core/ast/visitors/ast_validator.cpp

source/pl/core/token.cpp
source/pl/core/evaluator.cpp
source/pl/core/lexer.cpp
Expand Down
3 changes: 3 additions & 0 deletions lib/include/pl/core/ast/ast_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <pl/core/token.hpp>
#include <pl/core/location.hpp>
#include <pl/core/ast/visitors/ast_visitor.hpp>

#include <pl/core/errors/runtime_errors.hpp>
#include <pl/helpers/concepts.hpp>
Expand Down Expand Up @@ -36,6 +37,8 @@ namespace pl::core::ast {
void setShouldDocument(bool shouldDocument);
[[nodiscard]] bool shouldDocument() const;

virtual void accept(vis::ASTVisitor& v) = 0;

private:
Location m_location = Location::Empty();

Expand Down
7 changes: 7 additions & 0 deletions lib/include/pl/core/ast/ast_node_array_variable_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@ namespace pl::core::ast {
[[nodiscard]] const std::unique_ptr<ASTNode> &getPlacementOffset() const {
return this->m_placementOffset;
}
[[nodiscard]] const std::unique_ptr<ASTNode> &getPlacementSection() const {
return this->m_placementSection;
}

[[nodiscard]] bool isConstant() const {
return this->m_constant;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::string m_name;
std::shared_ptr<ASTNodeTypeApplication> m_type;
Expand Down
4 changes: 4 additions & 0 deletions lib/include/pl/core/ast/ast_node_attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ namespace pl::core::ast {
return m_aliasNamespaceString;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::string m_attribute;
std::vector<std::unique_ptr<ASTNode>> m_value;
Expand Down
3 changes: 3 additions & 0 deletions lib/include/pl/core/ast/ast_node_bitfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ namespace pl::core::ast {

void createPatterns(Evaluator *evaluator, std::vector<std::shared_ptr<ptrn::Pattern>> &resultPatterns) const override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
private:
std::vector<std::shared_ptr<ASTNode>> m_entries;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ namespace pl::core::ast {
return this->m_size;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::string m_name;
std::shared_ptr<ASTNodeTypeApplication> m_type;
Expand Down
14 changes: 14 additions & 0 deletions lib/include/pl/core/ast/ast_node_bitfield_field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ namespace pl::core::ast {
[[nodiscard]] virtual std::shared_ptr<ptrn::PatternBitfieldField> createBitfield(Evaluator *evaluator, u64 byteOffset, u8 bitOffset, u8 bitSize) const;
void createPatterns(Evaluator *evaluator, std::vector<std::shared_ptr<ptrn::Pattern>> &resultPatterns) const override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
private:
std::string m_name;
std::unique_ptr<ASTNode> m_size;
Expand All @@ -38,6 +41,10 @@ namespace pl::core::ast {
using ASTNodeBitfieldField::ASTNodeBitfieldField;

[[nodiscard]] std::shared_ptr<ptrn::PatternBitfieldField> createBitfield(Evaluator *evaluator, u64 byteOffset, u8 bitOffset, u8 bitSize) const override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
};

class ASTNodeBitfieldFieldSizedType : public ASTNodeBitfieldField {
Expand All @@ -49,8 +56,15 @@ namespace pl::core::ast {
return std::unique_ptr<ASTNode>(new ASTNodeBitfieldFieldSizedType(*this));
}

[[nodiscard]] const std::unique_ptr<ASTNodeTypeApplication> &getType() {
return m_type;
}

[[nodiscard]] std::shared_ptr<ptrn::PatternBitfieldField> createBitfield(Evaluator *evaluator, u64 byteOffset, u8 bitOffset, u8 bitSize) const override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
private:
std::unique_ptr<ASTNodeTypeApplication> m_type;
};
Expand Down
3 changes: 3 additions & 0 deletions lib/include/pl/core/ast/ast_node_builtin_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ namespace pl::core::ast {

void createPatterns(Evaluator *evaluator, std::vector<std::shared_ptr<ptrn::Pattern>> &resultPatterns) const override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
private:
Token::ValueType m_type;
api::FunctionParameterCount m_parameterCount;
Expand Down
10 changes: 10 additions & 0 deletions lib/include/pl/core/ast/ast_node_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ namespace pl::core::ast {

[[nodiscard]] std::unique_ptr<ASTNode> evaluate(Evaluator *evaluator) const override;

[[nodiscard]] const std::unique_ptr<ASTNode> &getValue() const {
return m_value;
}
[[nodiscard]] const std::unique_ptr<ASTNodeTypeApplication> &getType() const {
return m_type;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
private:
std::unique_ptr<ASTNode> castValue(const Token::Literal &literal, Token::ValueType type, const std::shared_ptr<ptrn::Pattern> &typePattern, Evaluator *evaluator) const;

Expand Down
3 changes: 3 additions & 0 deletions lib/include/pl/core/ast/ast_node_compound_statement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace pl::core::ast {
FunctionResult execute(Evaluator *evaluator) const override;
void addAttribute(std::unique_ptr<ASTNodeAttribute> &&attribute) override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
public:
std::vector<std::shared_ptr<ASTNode>> m_statements;
bool m_newScope = false;
Expand Down
3 changes: 3 additions & 0 deletions lib/include/pl/core/ast/ast_node_conditional_statement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace pl::core::ast {
return this->m_falseBody;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
private:
[[nodiscard]] bool evaluateCondition(const std::unique_ptr<ASTNode> &condition, Evaluator *evaluator) const;

Expand Down
11 changes: 11 additions & 0 deletions lib/include/pl/core/ast/ast_node_control_flow_statement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ namespace pl::core::ast {
void createPatterns(Evaluator *evaluator, std::vector<std::shared_ptr<ptrn::Pattern>> &resultPatterns) const override;
FunctionResult execute(Evaluator *evaluator) const override;

[[nodiscard]] ControlFlowStatement getType() const {
return this->m_type;
}

[[nodiscard]] const std::unique_ptr<ASTNode> &getRValue() {
return m_rvalue;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
private:
ControlFlowStatement m_type;
std::unique_ptr<ASTNode> m_rvalue;
Expand Down
3 changes: 3 additions & 0 deletions lib/include/pl/core/ast/ast_node_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ namespace pl::core::ast {

[[nodiscard]] const std::unique_ptr<ASTNode> &getUnderlyingType() { return this->m_underlyingType; }

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
private:
std::map<std::string, std::pair<std::unique_ptr<ASTNode>, std::unique_ptr<ASTNode>>> m_entries;
std::unique_ptr<ASTNode> m_underlyingType;
Expand Down
3 changes: 3 additions & 0 deletions lib/include/pl/core/ast/ast_node_function_call.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace pl::core::ast {
[[nodiscard]] std::unique_ptr<ASTNode> evaluate(Evaluator *evaluator) const override;
FunctionResult execute(Evaluator *evaluator) const override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
private:
std::string m_functionName;
std::vector<std::unique_ptr<ASTNode>> m_params;
Expand Down
3 changes: 3 additions & 0 deletions lib/include/pl/core/ast/ast_node_function_definition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace pl::core::ast {
return this->m_defaultParameters;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::string m_name;
Expand Down
8 changes: 8 additions & 0 deletions lib/include/pl/core/ast/ast_node_imported_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ namespace pl::core::ast {
void createPatterns(Evaluator *evaluator, std::vector<std::shared_ptr<ptrn::Pattern>> &resultPatterns) const override;
std::unique_ptr<ASTNode> evaluate(Evaluator *evaluator) const override;

[[nodiscard]] const std::string &getImportedTypename() const {
return m_importedTypeName;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::string m_importedTypeName;
};
Expand Down
3 changes: 3 additions & 0 deletions lib/include/pl/core/ast/ast_node_literal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace pl::core::ast {
[[nodiscard]] const auto &getValue() const {
return this->m_literal;
}
void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
Token::Literal m_literal;
Expand Down
3 changes: 3 additions & 0 deletions lib/include/pl/core/ast/ast_node_lvalue_assignment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace pl::core::ast {
void createPatterns(Evaluator *evaluator, std::vector<std::shared_ptr<ptrn::Pattern>> &resultPatterns) const override;
FunctionResult execute(Evaluator *evaluator) const override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}
private:
std::string m_lvalueName;
std::unique_ptr<ASTNode> m_rvalue;
Expand Down
11 changes: 11 additions & 0 deletions lib/include/pl/core/ast/ast_node_match_statement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ namespace pl::core::ast {
void createPatterns(Evaluator *evaluator, std::vector<std::shared_ptr<ptrn::Pattern>> &resultPatterns) const override;
FunctionResult execute(Evaluator *evaluator) const override;

[[nodiscard]] const std::optional<MatchCase> &getDefaultCase() const {
return this->m_defaultCase;
}
[[nodiscard]] const std::vector<MatchCase> &getNonDefaultCases() const {
return this->m_cases;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
[[nodiscard]] bool evaluateCondition(const std::unique_ptr<ASTNode> &condition, Evaluator *evaluator) const;
[[nodiscard]] const std::vector<std::unique_ptr<ASTNode>>* getCaseBody(Evaluator *evaluator) const;
Expand Down
4 changes: 4 additions & 0 deletions lib/include/pl/core/ast/ast_node_mathematical_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ namespace pl::core::ast {
[[nodiscard]] const std::unique_ptr<ASTNode> &getRightOperand() const { return this->m_right; }
[[nodiscard]] Token::Operator getOperator() const { return this->m_operator; }

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::unique_ptr<ASTNode> m_left, m_right;
Token::Operator m_operator;
Expand Down
4 changes: 4 additions & 0 deletions lib/include/pl/core/ast/ast_node_multi_variable_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ namespace pl::core::ast {
void createPatterns(Evaluator *evaluator, std::vector<std::shared_ptr<ptrn::Pattern>> &resultPatterns) const override;
FunctionResult execute(Evaluator *evaluator) const override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::vector<std::shared_ptr<ASTNode>> m_variables;
};
Expand Down
4 changes: 4 additions & 0 deletions lib/include/pl/core/ast/ast_node_parameter_pack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ namespace pl::core::ast {
return this->m_values;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::vector<Token::Literal> m_values;
};
Expand Down
5 changes: 5 additions & 0 deletions lib/include/pl/core/ast/ast_node_pointer_variable_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ namespace pl::core::ast {
[[nodiscard]] constexpr const std::shared_ptr<ASTNode> &getType() const { return this->m_type; }
[[nodiscard]] constexpr const std::shared_ptr<ASTNodeTypeApplication> &getSizeType() const { return this->m_sizeType; }
[[nodiscard]] constexpr const std::unique_ptr<ASTNode> &getPlacementOffset() const { return this->m_placementOffset; }
[[nodiscard]] constexpr const std::unique_ptr<ASTNode> &getPlacementSection() const { return this->m_placementSection; }

void createPatterns(Evaluator *evaluator, std::vector<std::shared_ptr<ptrn::Pattern>> &resultPatterns) const override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::string m_name;
std::shared_ptr<ASTNode> m_type;
Expand Down
4 changes: 4 additions & 0 deletions lib/include/pl/core/ast/ast_node_rvalue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace pl::core::ast {
[[nodiscard]] std::unique_ptr<ASTNode> evaluate(Evaluator *evaluator) const override;
void createPatterns(Evaluator *evaluator, std::vector<std::shared_ptr<ptrn::Pattern>> &resultPatterns) const override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
Path m_path;
};
Expand Down
4 changes: 4 additions & 0 deletions lib/include/pl/core/ast/ast_node_rvalue_assignment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ namespace pl::core::ast {
void createPatterns(Evaluator *evaluator, std::vector<std::shared_ptr<ptrn::Pattern>> &resultPatterns) const override;
FunctionResult execute(Evaluator *evaluator) const override;

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::unique_ptr<ASTNode> m_lvalue, m_rvalue;
};
Expand Down
11 changes: 11 additions & 0 deletions lib/include/pl/core/ast/ast_node_scope_resolution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ namespace pl::core::ast {

[[nodiscard]] std::unique_ptr<ASTNode> evaluate(Evaluator *evaluator) const override;

[[nodiscard]] const std::shared_ptr<ASTNodeTypeDecl> &getType() {
return m_type;
}
[[nodiscard]] const std::string &getName() {
return m_name;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::shared_ptr<ASTNodeTypeDecl> m_type;
std::string m_name;
Expand Down
4 changes: 4 additions & 0 deletions lib/include/pl/core/ast/ast_node_struct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace pl::core::ast {
[[nodiscard]] const std::vector<std::shared_ptr<ASTNode>> &getInheritance() const { return this->m_inheritance; }
void addInheritance(std::shared_ptr<ASTNode> &&node) { this->m_inheritance.push_back(std::move(node)); }

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::vector<std::shared_ptr<ASTNode>> m_members;
std::vector<std::shared_ptr<ASTNode>> m_inheritance;
Expand Down
4 changes: 4 additions & 0 deletions lib/include/pl/core/ast/ast_node_template_parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace pl::core::ast {
return this->m_isType;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
Token::Identifier m_name;
bool m_isType;
Expand Down
4 changes: 4 additions & 0 deletions lib/include/pl/core/ast/ast_node_ternary_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ namespace pl::core::ast {
[[nodiscard]] const std::unique_ptr<ASTNode> &getThirdOperand() const { return this->m_third; }
[[nodiscard]] Token::Operator getOperator() const { return this->m_operator; }

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:
std::unique_ptr<ASTNode> m_first, m_second, m_third;
Token::Operator m_operator;
Expand Down
4 changes: 4 additions & 0 deletions lib/include/pl/core/ast/ast_node_try_catch_statement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace pl::core::ast {
return this->m_catchBody;
}

void accept(vis::ASTVisitor &v) override {
v.visit(*this);
}

private:

std::vector<std::unique_ptr<ASTNode>> m_tryBody, m_catchBody;
Expand Down
Loading
Loading