Skip to content
This repository was archived by the owner on Oct 12, 2026. It is now read-only.

Commit 29d2c66

Browse files
committed
Refactor AST, support source::Range inside Interpreter instead of source::Location.
1 parent 4894cae commit 29d2c66

39 files changed

Lines changed: 637 additions & 638 deletions

‎CMakeLists.txt‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,27 @@ target_link_libraries(lbdDiagnostics PUBLIC
8383
fmt::fmt
8484
)
8585

86+
87+
###### TYPE ######
88+
89+
file(GLOB_RECURSE TYPE_SOURCE_FILES CONFIGURE_DEPENDS
90+
${PROJECT_SOURCE_DIR}/src/type/*.cpp
91+
)
92+
93+
add_library(lbdType STATIC
94+
${TYPE_SOURCE_FILES}
95+
)
96+
97+
target_include_directories(lbdType PUBLIC
98+
${PROJECT_SOURCE_DIR}/include
99+
)
100+
86101
###### FRONTEND ######
87102

88103
file(GLOB_RECURSE FRONTEND_SOURCE_FILES CONFIGURE_DEPENDS
89104
${PROJECT_SOURCE_DIR}/src/frontend/*.cpp
90105
)
91106

92-
list(FILTER FRONTEND_SOURCE_FILES EXCLUDE REGEX
93-
".*/src/frontend/ast/.*\\.cpp$"
94-
)
95-
96107
add_library(lbdFrontend STATIC
97108
${FRONTEND_SOURCE_FILES}
98109
)
@@ -144,6 +155,7 @@ target_link_libraries(lbd PRIVATE
144155
lbdDiagnostics
145156
lbdFrontend
146157
lbdRuntime
158+
lbdType
147159
replxx
148160
CLI11::CLI11
149161
)

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,6 @@ SUBCOMMANDS:
119119

120120
## Dependencies
121121

122-
1. [replxx](https://github.com/AmokHuginnsson/replxx.git): For better REPL user experience.
123-
2. [CLI11](https://github.com/CLIUtils/CLI11.git): For better CLI support.
122+
1. [fmt](https://github.com/fmtlib/fmt.git): String formatting.
123+
2. [replxx](https://github.com/AmokHuginnsson/replxx.git): For better REPL user experience.
124+
3. [CLI11](https://github.com/CLIUtils/CLI11.git): For better CLI support.

‎include/lbd/diagnostics/DiagnosticInfo.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ static_assert(
2727
static_cast<std::size_t>(DiagnosticId::COUNT) == std::size(DIAGNOSTIC_INFOS),
2828
"Mismatch between DiagnosticId and DiagnosticInfo table."
2929
);
30-
}
30+
}

‎include/lbd/frontend/Program.hpp‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#pragma once
22

3-
#include <iostream>
43
#include <vector>
5-
#include <lbd/frontend/ast/Ast.hpp>
4+
#include <lbd/frontend/ast/AstNode.hpp>
65

76
namespace lbd::frontend
87
{
9-
// TODO: Remove this later.
108
class Program
119
{
1210
public:
13-
explicit Program(std::vector<std::unique_ptr<ast::AstNode>> nodes);
11+
explicit Program(std::vector<ast::AstNodePtr> astNodePtrs);
1412

1513
friend std::ostream &operator<<(std::ostream &outputStream, const Program &program);
1614

17-
std::vector<std::unique_ptr<ast::AstNode>> astNodes;
15+
[[nodiscard]] std::vector<ast::AstNodePtr> &getAstNodePtrs() noexcept;
16+
17+
[[nodiscard]] const std::vector<ast::AstNodePtr> &getAstNodePtrs() const noexcept;
18+
19+
private:
20+
std::vector<ast::AstNodePtr> astNodePtrs;
1821
};
19-
}
22+
}

‎include/lbd/frontend/Type.hpp‎

Lines changed: 0 additions & 38 deletions
This file was deleted.

‎include/lbd/frontend/ast/Ast.hpp‎

Lines changed: 0 additions & 124 deletions
This file was deleted.
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
#pragma once
22

3+
#include <memory>
34
#include <lbd/frontend/ast/AstNodeKind.hpp>
45
#include <lbd/source/Range.hpp>
56

67
namespace lbd::frontend::ast
78
{
9+
class AstNode;
10+
using AstNodePtr = std::unique_ptr<AstNode>;
11+
812
class AstNode
913
{
1014
public:
1115
AstNode(AstNodeKind kind, source::Range range);
1216

1317
virtual ~AstNode() = default;
1418

19+
[[nodiscard]] source::Range getRange() const;
20+
1521
virtual void print(std::ostream &outputStream, size_t indent) const noexcept = 0;
1622

1723
friend std::ostream &operator<<(std::ostream &outputStream, const AstNode &node);
1824

25+
AstNode(const AstNode &) = delete;
26+
27+
AstNode &operator=(const AstNode &) = delete;
28+
1929
private:
2030
const AstNodeKind kind;
2131
const source::Range range;
2232

2333
protected:
2434
static void printIndent(std::ostream &outputStream, size_t indent) noexcept;
2535
};
26-
}
36+
}

‎include/lbd/frontend/ast/AstNodeKind.hpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ namespace lbd::frontend::ast
99
NUMBER_EXPRESSION,
1010
LAMBDA_EXPRESSION,
1111
FUNCTION_APPLICATION_EXPRESSION,
12-
SYMBOL_DEFINITION,
1312
EXPRESSION_STATEMENT,
1413
SYMBOL_DEFINITION_STATEMENT,
1514
};
16-
}
15+
}

‎include/lbd/frontend/ast/expression/Expression.hpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
namespace lbd::frontend::ast::expression
66
{
7+
class Expression;
8+
using ExpressionPtr = std::unique_ptr<Expression>;
9+
710
class Expression : public AstNode
811
{
912
using AstNode::AstNode;
1013
};
11-
}
14+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <vector>
5+
#include <lbd/frontend/ast/expression/IdentifierExpression.hpp>
6+
7+
namespace lbd::frontend::ast::expression
8+
{
9+
class FunctionApplicationExpression final : public Expression
10+
{
11+
public:
12+
// TODO: Update the design: instead of function-name callee should also be able to provide a lambda-expression.
13+
FunctionApplicationExpression(const source::Range &range,
14+
IdentifierExpressionPtr functionNameIdentifierExpressionPtr,
15+
std::vector<ExpressionPtr> argumentPtrs) noexcept;
16+
17+
void print(std::ostream &outputStream, size_t indent) const noexcept override;
18+
19+
[[nodiscard]] const IdentifierExpression &getFunctionNameIdentifierExpression() const noexcept;
20+
21+
[[nodiscard]] const std::vector<ExpressionPtr> &getArguments() const noexcept;
22+
23+
private:
24+
IdentifierExpressionPtr functionNameIdentifierExpressionPtr;
25+
std::vector<ExpressionPtr> argumentPtrs;
26+
};
27+
}

0 commit comments

Comments
 (0)