From 2ff5f0612c893cedae009a7ad900fefdb0334857 Mon Sep 17 00:00:00 2001 From: LeonardoBizzoni Date: Mon, 2 Sep 2024 17:16:27 +0200 Subject: [PATCH] Merged `/lib` and `/src` --- CMakeLists.txt | 40 +++++++++++++++---- lib/runtime_error.h | 33 --------------- main.lbpl | 37 +++++++++++++++++ shell.nix | 20 ++++++++++ lib/LBPLCallable.h => src/LBPLCallable.hpp | 2 +- src/LBPLClass.cpp | 6 +-- lib/LBPLClass.h => src/LBPLClass.hpp | 4 +- src/LBPLFunction.cpp | 4 +- lib/LBPLFunction.h => src/LBPLFunction.hpp | 7 ++-- src/LBPLInstance.cpp | 3 +- lib/LBPLInstance.h => src/LBPLInstance.hpp | 4 +- lib/LBPLTypes.h => src/LBPLTypes.hpp | 0 src/ast_printer.cpp | 4 +- lib/ast_printer.h => src/ast_printer.hpp | 4 +- .../builtin_methods.hpp | 3 +- lib/common.h => src/common.hpp | 4 +- src/environment.cpp | 25 +++++++----- lib/environment.h => src/environment.hpp | 6 +-- lib/expressions.h => src/expressions.hpp | 14 ++++--- src/interpreter.cpp | 12 +++--- lib/interpreter.h => src/interpreter.hpp | 9 ++--- src/lexer.cpp | 2 +- lib/lexer.h => src/lexer.hpp | 9 ++--- src/main.cpp | 5 ++- lib/main.h => src/main.hpp | 0 src/parser.cpp | 10 ++++- lib/parser.h => src/parser.hpp | 8 ++-- src/resolver.cpp | 3 +- lib/resolver.h => src/resolver.hpp | 8 ++-- src/runtime_error.cpp | 3 +- src/runtime_error.hpp | 33 +++++++++++++++ lib/statements.h => src/statements.hpp | 30 +++++++------- src/syntax_error.cpp | 3 +- lib/syntax_error.h => src/syntax_error.hpp | 18 ++++----- lib/token.h => src/token.hpp | 2 +- lib/token_type.h => src/token_type.hpp | 0 lib/tree_nodes.h => src/tree_nodes.hpp | 0 lib/visitor.h => src/visitor.hpp | 6 +-- 38 files changed, 234 insertions(+), 147 deletions(-) delete mode 100644 lib/runtime_error.h create mode 100644 main.lbpl create mode 100644 shell.nix rename lib/LBPLCallable.h => src/LBPLCallable.hpp (89%) rename lib/LBPLClass.h => src/LBPLClass.hpp (92%) rename lib/LBPLFunction.h => src/LBPLFunction.hpp (90%) rename lib/LBPLInstance.h => src/LBPLInstance.hpp (86%) rename lib/LBPLTypes.h => src/LBPLTypes.hpp (100%) rename lib/ast_printer.h => src/ast_printer.hpp (96%) rename lib/builtin_methods.h => src/builtin_methods.hpp (96%) rename lib/common.h => src/common.hpp (63%) rename lib/environment.h => src/environment.hpp (92%) rename lib/expressions.h => src/expressions.hpp (96%) rename lib/interpreter.h => src/interpreter.hpp (95%) rename lib/lexer.h => src/lexer.hpp (88%) rename lib/main.h => src/main.hpp (100%) rename lib/parser.h => src/parser.hpp (95%) rename lib/resolver.h => src/resolver.hpp (94%) create mode 100644 src/runtime_error.hpp rename lib/statements.h => src/statements.hpp (82%) rename lib/syntax_error.h => src/syntax_error.hpp (56%) rename lib/token.h => src/token.hpp (93%) rename lib/token_type.h => src/token_type.hpp (100%) rename lib/tree_nodes.h => src/tree_nodes.hpp (100%) rename lib/visitor.h => src/visitor.hpp (95%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b93afa3..d53e115 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,38 @@ -cmake_minimum_required (VERSION 3.26.4) - -add_compile_options(-O2) +cmake_minimum_required(VERSION 3.29) +project(lbpl CXX) +# Set C++ standard set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -project (lbpl VERSION 0.1.0) -include_directories(lib) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") +endif() + +# Set output directories +set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") + +file(GLOB_RECURSE SRC "src/*.cpp" "src/*.hpp") +add_executable(${PROJECT_NAME} ${SRC}) + +set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) +target_compile_definitions(${PROJECT_NAME} PRIVATE ROOTDIR="${CMAKE_SOURCE_DIR}") + +# Set output directories +set_target_properties(${PROJECT_NAME} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}" + ARCHITE_OUTPUT_DIRECTORY "${OUTPUT_DIR}" + LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}") + +# Configuration-specific settings +target_compile_definitions(${PROJECT_NAME} PRIVATE + $<$:DEBUG> + $<$:OPTDEBUG> + $<$:RELEASE>) -file(GLOB SRCFILES src/*.cpp) -add_executable(${PROJECT_NAME} ${SRCFILES}) +# Configuration-specific optimizations +target_compile_options(${PROJECT_NAME} PRIVATE + $<$:-g> + $<$:-O3> + $<$:-O3>) diff --git a/lib/runtime_error.h b/lib/runtime_error.h deleted file mode 100644 index 1d791de..0000000 --- a/lib/runtime_error.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef RUNTIME_ERROR_H -#define RUNTIME_ERROR_H - -#include "token.h" -#include "expressions.h" -#include "statements.h" - -#include -#include -#include -#include - -struct RuntimeError { -public: - int line; - int column; - std::string filename; - std::string msg; - -public: - RuntimeError(const Token *errToken, const std::string &msg) - : line(errToken->line), column(errToken->column), filename(errToken->filename), msg(msg) {} - - RuntimeError(Expr *errToken, const std::string &msg) - : line(errToken->line), column(errToken->column), filename(errToken->file), msg(msg) {} - - RuntimeError(Stmt *errToken, const std::string &msg) - : line(errToken->line), column(errToken->column), filename(errToken->filename), msg(msg) {} - - std::string what(); -}; - -#endif diff --git a/main.lbpl b/main.lbpl new file mode 100644 index 0000000..d182846 --- /dev/null +++ b/main.lbpl @@ -0,0 +1,37 @@ +fn fib(n) { + return fibIter(n, 0, 1); +} + +fn fibIter(n, curr, next) { + if (n == 0) { + return curr; + } else if (n == 1) { + return next; + } else { + return fibIter(n - 1, next, curr + next); + } +} + +class Prova { + init(n) { + this.n = n; + this.start = clock(); + this.fib_n = fib(n); + this.end = clock(); + } + + runtime() { + println("fib("+ this.n +") = " + + this.fib_n + + " runtime: " + + (this.end - this.start)); + } +} + +let a = Prova(25); +a.var1 = 10; +println(a.var1); +a.var1 = 210; +println(a.var1); + +a.runtime(); \ No newline at end of file diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..fe2e96d --- /dev/null +++ b/shell.nix @@ -0,0 +1,20 @@ +{ pkgs ? import { } }: + +pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + man-pages + man-pages-posix + + gnumake + cmake + seer + clang-tools + cmake-language-server + tree-sitter-grammars.tree-sitter-cpp + tree-sitter-grammars.tree-sitter-c + ]; + + shellHook = '' + ${pkgs.onefetch}/bin/onefetch + ''; +} diff --git a/lib/LBPLCallable.h b/src/LBPLCallable.hpp similarity index 89% rename from lib/LBPLCallable.h rename to src/LBPLCallable.hpp index eb2b056..c18dd0d 100644 --- a/lib/LBPLCallable.h +++ b/src/LBPLCallable.hpp @@ -1,7 +1,7 @@ #ifndef LBPL_CALLABLE_H #define LBPL_CALLABLE_H -#include "LBPLTypes.h" +#include "LBPLTypes.hpp" #include class Interpreter; diff --git a/src/LBPLClass.cpp b/src/LBPLClass.cpp index f4a2bd6..3870718 100644 --- a/src/LBPLClass.cpp +++ b/src/LBPLClass.cpp @@ -1,6 +1,6 @@ -#include "LBPLClass.h" -#include "LBPLInstance.h" -#include "interpreter.h" +#include "LBPLClass.hpp" +#include "LBPLInstance.hpp" +#include "interpreter.hpp" Value LBPLClass::call(Interpreter *interpreter, std::vector &args) { auto instance = std::make_shared(this); diff --git a/lib/LBPLClass.h b/src/LBPLClass.hpp similarity index 92% rename from lib/LBPLClass.h rename to src/LBPLClass.hpp index 752e7eb..846db0b 100644 --- a/lib/LBPLClass.h +++ b/src/LBPLClass.hpp @@ -1,8 +1,8 @@ #ifndef LBPL_CLASS_H #define LBPL_CLASS_H -#include "LBPLCallable.h" -#include "LBPLFunction.h" +#include "LBPLCallable.hpp" +#include "LBPLFunction.hpp" #include #include diff --git a/src/LBPLFunction.cpp b/src/LBPLFunction.cpp index c2a7a5e..ac9c602 100644 --- a/src/LBPLFunction.cpp +++ b/src/LBPLFunction.cpp @@ -1,5 +1,5 @@ -#include "LBPLFunction.h" -#include "interpreter.h" +#include "LBPLFunction.hpp" +#include "interpreter.hpp" void LBPLFunc::bind(std::shared_ptr &&instance) { closureEnv = std::make_shared(); diff --git a/lib/LBPLFunction.h b/src/LBPLFunction.hpp similarity index 90% rename from lib/LBPLFunction.h rename to src/LBPLFunction.hpp index c33d905..f4df5de 100644 --- a/lib/LBPLFunction.h +++ b/src/LBPLFunction.hpp @@ -1,9 +1,10 @@ #ifndef LBPL_FUNCTION_H #define LBPL_FUNCTION_H -#include "LBPLCallable.h" -#include "environment.h" -#include "statements.h" +#include "LBPLCallable.hpp" +#include "environment.hpp" +#include "statements.hpp" + #include class LBPLFunc : public LBPLCallable { diff --git a/src/LBPLInstance.cpp b/src/LBPLInstance.cpp index 73e0d3e..72951b9 100644 --- a/src/LBPLInstance.cpp +++ b/src/LBPLInstance.cpp @@ -1,4 +1,5 @@ -#include "LBPLInstance.h" +#include "LBPLInstance.hpp" +#include "runtime_error.hpp" Value LBPLInstance::get(const Token *name) { if (fields.contains(name->lexeme)) { diff --git a/lib/LBPLInstance.h b/src/LBPLInstance.hpp similarity index 86% rename from lib/LBPLInstance.h rename to src/LBPLInstance.hpp index d895701..9c16356 100644 --- a/lib/LBPLInstance.h +++ b/src/LBPLInstance.hpp @@ -1,11 +1,9 @@ #ifndef LBPL_INSTANCE_H #define LBPL_INSTANCE_H -#include "LBPLClass.h" -#include "runtime_error.h" +#include "LBPLClass.hpp" #include -#include class LBPLInstance { private: diff --git a/lib/LBPLTypes.h b/src/LBPLTypes.hpp similarity index 100% rename from lib/LBPLTypes.h rename to src/LBPLTypes.hpp diff --git a/src/ast_printer.cpp b/src/ast_printer.cpp index 04c89a8..18dff9f 100755 --- a/src/ast_printer.cpp +++ b/src/ast_printer.cpp @@ -1,5 +1,5 @@ -#include "ast_printer.h" -#include "statements.h" +#include "ast_printer.hpp" +#include "statements.hpp" #include diff --git a/lib/ast_printer.h b/src/ast_printer.hpp similarity index 96% rename from lib/ast_printer.h rename to src/ast_printer.hpp index 3b8a4b5..0bf1bb7 100755 --- a/lib/ast_printer.h +++ b/src/ast_printer.hpp @@ -1,8 +1,8 @@ #ifndef AST_PRINTER_H #define AST_PRINTER_H -#include "tree_nodes.h" -#include "visitor.h" +#include "tree_nodes.hpp" +#include "visitor.hpp" class AST_Printer : public Statement::Visitor, public Expression::Visitor { void printLocation(Stmt *); diff --git a/lib/builtin_methods.h b/src/builtin_methods.hpp similarity index 96% rename from lib/builtin_methods.h rename to src/builtin_methods.hpp index 24f0613..be2a64c 100644 --- a/lib/builtin_methods.h +++ b/src/builtin_methods.hpp @@ -1,8 +1,7 @@ #ifndef BUILTIN_METHODS_H #define BUILTIN_METHODS_H -#include "LBPLCallable.h" -#include "statements.h" +#include "LBPLCallable.hpp" #include #include diff --git a/lib/common.h b/src/common.hpp similarity index 63% rename from lib/common.h rename to src/common.hpp index fbdc444..cea8e3e 100755 --- a/lib/common.h +++ b/src/common.hpp @@ -1,8 +1,8 @@ #ifndef COMMON_H #define COMMON_H -#include "token.h" -#include "token_type.h" +#include "token.hpp" +#include "token_type.hpp" #include #include diff --git a/src/environment.cpp b/src/environment.cpp index f33df8b..4ef6a96 100755 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1,10 +1,12 @@ -#include "environment.h" -#include "LBPLTypes.h" -#include "runtime_error.h" +#include "environment.hpp" +#include "LBPLTypes.hpp" +#include "runtime_error.hpp" + #include #include #include #include +#include void Environment::define(const std::string &name, Value &value) { env.insert(std::make_pair(name, value)); @@ -13,7 +15,6 @@ void Environment::define(const std::string &name, Value &&value) { env.insert(std::make_pair(name, value)); } - Value Environment::get(std::shared_ptr &name) { auto it = env.find(name->lexeme); @@ -24,7 +25,7 @@ Value Environment::get(std::shared_ptr &name) { return enclosing->get(name); } - throw RuntimeError(name.get(), "Undefined name '"+name->lexeme+"'."); + throw RuntimeError(name.get(), "Undefined name '" + name->lexeme + "'."); } Value Environment::getAt(int depth, std::shared_ptr &name) { @@ -33,7 +34,7 @@ Value Environment::getAt(int depth, std::shared_ptr &name) { Value Environment::getAt(int depth, const std::string &name) { if (depth > 0) { - return enclosing->getAt(depth-1, name); + return enclosing->getAt(depth - 1, name); } auto it = env.find(name); @@ -46,7 +47,8 @@ void Environment::assign(std::shared_ptr &name, Value &value) { } else if (enclosing) { enclosing->assign(name, value); } else { - throw RuntimeError(name.get(), "Undefined variable '"+name->lexeme+"'."); + throw RuntimeError(name.get(), + "Undefined variable '" + name->lexeme + "'."); } } @@ -54,17 +56,18 @@ void Environment::assign(std::shared_ptr &name, Value &&value) { assign(name, value); } -void Environment::assignAt(int depth, std::shared_ptr &name, Value &value) { +void Environment::assignAt(int depth, std::shared_ptr &name, + Value &value) { if (depth > 0) { - enclosing->assignAt(depth-1, name, value); + enclosing->assignAt(depth - 1, name, value); } env.insert_or_assign(name->lexeme, value); } void Environment::printEnv(const std::string &&msg) { - std::cout << "========"<< msg <<"=========" << std::endl; - for (const auto& [key, value] : env) { + std::cout << "========" << msg << "=========" << std::endl; + for (const auto &[key, value] : env) { std::cout << "\t" << key << ": "; if (std::holds_alternative(value)) { diff --git a/lib/environment.h b/src/environment.hpp similarity index 92% rename from lib/environment.h rename to src/environment.hpp index 989fbc1..f8f9415 100755 --- a/lib/environment.h +++ b/src/environment.hpp @@ -1,14 +1,12 @@ #ifndef ENVIRONMENT_H #define ENVIRONMENT_H -#include "LBPLTypes.h" -#include "token.h" -#include "tree_nodes.h" +#include "LBPLTypes.hpp" +#include "token.hpp" #include #include #include -#include class Environment { public: diff --git a/lib/expressions.h b/src/expressions.hpp similarity index 96% rename from lib/expressions.h rename to src/expressions.hpp index 86d1beb..a774eb1 100755 --- a/lib/expressions.h +++ b/src/expressions.hpp @@ -1,11 +1,12 @@ #ifndef EXPRESSIONS_H #define EXPRESSIONS_H -#include "common.h" -#include "token.h" -#include "visitor.h" +#include "token.hpp" + +#include "token.hpp" +#include "visitor.hpp" +#include -#include #include #include @@ -16,7 +17,7 @@ struct Expr { Expr(int line, int column, const std::string &filename) : line(line), column(column), file(filename) {} - virtual ~Expr(){}; + virtual ~Expr() {}; virtual Value accept(Expression::Visitor *) { return nullptr; } }; @@ -99,7 +100,8 @@ struct ThisExpr : public Expr { public: std::shared_ptr keyword; - ThisExpr(int line, int column, const std::string &file, std::shared_ptr& keyword) + ThisExpr(int line, int column, const std::string &file, + std::shared_ptr &keyword) : keyword(keyword), Expr(line, column, file) {} Value accept(Expression::Visitor *visitor) { diff --git a/src/interpreter.cpp b/src/interpreter.cpp index 4ba86d8..a2f9f6a 100644 --- a/src/interpreter.cpp +++ b/src/interpreter.cpp @@ -1,9 +1,9 @@ -#include "interpreter.h" -#include "LBPLClass.h" -#include "LBPLFunction.h" -#include "LBPLInstance.h" -#include "LBPLTypes.h" -#include "runtime_error.h" +#include "interpreter.hpp" +#include "LBPLClass.hpp" +#include "LBPLFunction.hpp" +#include "LBPLInstance.hpp" +#include "LBPLTypes.hpp" +#include "runtime_error.hpp" #include #include diff --git a/lib/interpreter.h b/src/interpreter.hpp similarity index 95% rename from lib/interpreter.h rename to src/interpreter.hpp index 4c4ccb4..1f3535b 100644 --- a/lib/interpreter.h +++ b/src/interpreter.hpp @@ -1,11 +1,10 @@ #ifndef INTERPRETER_H #define INTERPRETER_H -#include "LBPLTypes.h" -#include "builtin_methods.h" -#include "environment.h" -#include "runtime_error.h" -#include "visitor.h" +#include "LBPLTypes.hpp" +#include "builtin_methods.hpp" +#include "environment.hpp" +#include "visitor.hpp" #include #include diff --git a/src/lexer.cpp b/src/lexer.cpp index adde981..4fc6691 100755 --- a/src/lexer.cpp +++ b/src/lexer.cpp @@ -1,4 +1,4 @@ -#include "lexer.h" +#include "lexer.hpp" Lexer::Lexer(const char *stream, const std::string &filename) : line(1), hadError(false), filename(filename), current(stream), start(stream) {} diff --git a/lib/lexer.h b/src/lexer.hpp similarity index 88% rename from lib/lexer.h rename to src/lexer.hpp index c116a22..d18b7fb 100755 --- a/lib/lexer.h +++ b/src/lexer.hpp @@ -1,12 +1,11 @@ #ifndef LEXER_H #define LEXER_H -#include "common.h" +#include "token.hpp" +#include "token_type.hpp" -#include -#include +#include #include -#include class Lexer { private: @@ -41,7 +40,7 @@ private: bool match(char ch); public: - Lexer(const char*, const std::string &); + Lexer(const char *, const std::string &); int getLine(); int getColumn(); diff --git a/src/main.cpp b/src/main.cpp index 6a90ea6..77608cf 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,13 @@ -#include "main.h" #include #include #include #include #include +#include "parser.hpp" +#include "interpreter.hpp" +#include "resolver.hpp" + int main(const int argc, const char **argv) { if (argc < 2) { std::cerr << "\033[1;31mNot enough arguemnts.\tUsage: lbpl [script]" diff --git a/lib/main.h b/src/main.hpp similarity index 100% rename from lib/main.h rename to src/main.hpp diff --git a/src/parser.cpp b/src/parser.cpp index 83a80de..88caeb8 100755 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1,5 +1,8 @@ -#include "parser.h" +#include "parser.hpp" +#include "syntax_error.hpp" + #include +#include #include #include @@ -455,7 +458,8 @@ std::unique_ptr Parser::primary() { return std::make_unique(line, col, lexer->getFilename(), field); } else if (match(TokenType::This)) { - return std::make_unique(line, col, lexer->getFilename(), previous); + return std::make_unique(line, col, lexer->getFilename(), + previous); } else if (match(TokenType::Identifier)) { return std::make_unique(line, col, lexer->getFilename(), previous); @@ -493,6 +497,8 @@ void Parser::synchronize() { case TokenType::If: case TokenType::Return: return; + default: + break; } advance(); diff --git a/lib/parser.h b/src/parser.hpp similarity index 95% rename from lib/parser.h rename to src/parser.hpp index 943849b..94f5867 100755 --- a/lib/parser.h +++ b/src/parser.hpp @@ -1,12 +1,10 @@ #ifndef PARSER_H #define PARSER_H -#include "expressions.h" -#include "lexer.h" -#include "statements.h" -#include "syntax_error.h" +#include "expressions.hpp" +#include "lexer.hpp" +#include "statements.hpp" -#include #include #include #include diff --git a/src/resolver.cpp b/src/resolver.cpp index 29214ce..05c9541 100644 --- a/src/resolver.cpp +++ b/src/resolver.cpp @@ -1,4 +1,5 @@ -#include "resolver.h" +#include "resolver.hpp" +#include "syntax_error.hpp" void Resolver::resolve(std::vector> &stmts) { for (auto &&stmt : stmts) { diff --git a/lib/resolver.h b/src/resolver.hpp similarity index 94% rename from lib/resolver.h rename to src/resolver.hpp index d4e0f93..a8b9e19 100644 --- a/lib/resolver.h +++ b/src/resolver.hpp @@ -1,11 +1,9 @@ #ifndef RESOLVER_H #define RESOLVER_H -#include "environment.h" -#include "interpreter.h" -#include "statements.h" -#include "syntax_error.h" -#include "visitor.h" +#include "interpreter.hpp" +#include "statements.hpp" +#include "visitor.hpp" #include #include diff --git a/src/runtime_error.cpp b/src/runtime_error.cpp index da079da..fb445e1 100644 --- a/src/runtime_error.cpp +++ b/src/runtime_error.cpp @@ -1,4 +1,5 @@ -#include "runtime_error.h" +#include "runtime_error.hpp" +#include std::string RuntimeError::what() { std::stringstream ss(msg); diff --git a/src/runtime_error.hpp b/src/runtime_error.hpp new file mode 100644 index 0000000..5c06189 --- /dev/null +++ b/src/runtime_error.hpp @@ -0,0 +1,33 @@ +#ifndef RUNTIME_ERROR_H +#define RUNTIME_ERROR_H + +#include "expressions.hpp" +#include "statements.hpp" +#include "token.hpp" + +#include + +struct RuntimeError { +public: + int line; + int column; + std::string filename; + std::string msg; + +public: + RuntimeError(const Token *errToken, const std::string &msg) + : line(errToken->line), column(errToken->column), + filename(errToken->filename), msg(msg) {} + + RuntimeError(Expr *errToken, const std::string &msg) + : line(errToken->line), column(errToken->column), + filename(errToken->file), msg(msg) {} + + RuntimeError(Stmt *errToken, const std::string &msg) + : line(errToken->line), column(errToken->column), + filename(errToken->filename), msg(msg) {} + + std::string what(); +}; + +#endif diff --git a/lib/statements.h b/src/statements.hpp similarity index 82% rename from lib/statements.h rename to src/statements.hpp index 992f489..9233113 100755 --- a/lib/statements.h +++ b/src/statements.hpp @@ -1,11 +1,8 @@ #ifndef STATEMENTS_H #define STATEMENTS_H -#include "expressions.h" - +#include "expressions.hpp" #include -#include -#include struct Stmt { std::string filename; @@ -20,12 +17,15 @@ struct Stmt { struct FnStmt : public Stmt { std::shared_ptr name; - std::vector > args; + std::vector> args; std::vector> body; - FnStmt(int line, int column, const std::string &file, std::shared_ptr &name, - std::vector> &args, std::vector> &&body) - : name(name), args(args), body(std::move(body)), Stmt(line, column, file) {} + FnStmt(int line, int column, const std::string &file, + std::shared_ptr &name, + std::vector> &args, + std::vector> &&body) + : name(name), args(args), body(std::move(body)), + Stmt(line, column, file) {} void accept(Statement::Visitor *visitor) { visitor->visitFnStmt(this); } }; @@ -34,10 +34,9 @@ struct VarStmt : public Stmt { std::shared_ptr name; std::unique_ptr value; - VarStmt(int line, int column, const std::string &file, std::shared_ptr &name, - std::unique_ptr &value) - : name(name), value(std::move(value)), - Stmt(line, column, file) {} + VarStmt(int line, int column, const std::string &file, + std::shared_ptr &name, std::unique_ptr &value) + : name(name), value(std::move(value)), Stmt(line, column, file) {} void accept(Statement::Visitor *visitor) { visitor->visitVarStmt(this); } }; @@ -47,7 +46,8 @@ struct ClassStmt : public Stmt { std::unique_ptr superclass; std::vector> body; - ClassStmt(int line, int column, const std::string &file, std::shared_ptr &name, + ClassStmt(int line, int column, const std::string &file, + std::shared_ptr &name, std::unique_ptr &superclass, std::vector> &&body) : name(name), superclass(std::move(superclass)), body(std::move(body)), @@ -62,8 +62,8 @@ struct IfStmt : public Stmt { std::unique_ptr falseBranch; IfStmt(int line, int column, const std::string &file, - std::unique_ptr &condition, - std::unique_ptr &trueBranch, std::unique_ptr &falseBranch) + std::unique_ptr &condition, std::unique_ptr &trueBranch, + std::unique_ptr &falseBranch) : condition(std::move(condition)), trueBranch(std::move(trueBranch)), falseBranch(std::move(falseBranch)), Stmt(line, column, file) {} diff --git a/src/syntax_error.cpp b/src/syntax_error.cpp index fa7ef68..cbb7729 100755 --- a/src/syntax_error.cpp +++ b/src/syntax_error.cpp @@ -1,4 +1,5 @@ -#include "syntax_error.h" +#include "syntax_error.hpp" +#include std::string SyntaxError::what() { std::stringstream ss(msg); diff --git a/lib/syntax_error.h b/src/syntax_error.hpp similarity index 56% rename from lib/syntax_error.h rename to src/syntax_error.hpp index 48c17c8..c464fba 100755 --- a/lib/syntax_error.h +++ b/src/syntax_error.hpp @@ -1,14 +1,11 @@ #ifndef SYNTAX_ERROR_H #define SYNTAX_ERROR_H -#include "token.h" -#include "expressions.h" -#include "statements.h" +#include "expressions.hpp" +#include "statements.hpp" +#include "token.hpp" #include -#include -#include -#include struct SyntaxError { public: @@ -19,13 +16,16 @@ public: public: SyntaxError(const Token *errToken, const std::string &msg) - : line(errToken->line), column(errToken->column), filename(errToken->filename), msg(msg) {} + : line(errToken->line), column(errToken->column), + filename(errToken->filename), msg(msg) {} SyntaxError(Expr *errExpr, const std::string &msg) - : line(errExpr->line), column(errExpr->column), filename(errExpr->file), msg(msg) {} + : line(errExpr->line), column(errExpr->column), filename(errExpr->file), + msg(msg) {} SyntaxError(Stmt *errStmt, const std::string &msg) - : line(errStmt->line), column(errStmt->column), filename(errStmt->filename), msg(msg) {} + : line(errStmt->line), column(errStmt->column), + filename(errStmt->filename), msg(msg) {} std::string what(); }; diff --git a/lib/token.h b/src/token.hpp similarity index 93% rename from lib/token.h rename to src/token.hpp index 47c4be1..8c2ff6b 100755 --- a/lib/token.h +++ b/src/token.hpp @@ -1,7 +1,7 @@ #ifndef TOKEN_H #define TOKEN_H -#include "token_type.h" +#include "token_type.hpp" #include diff --git a/lib/token_type.h b/src/token_type.hpp similarity index 100% rename from lib/token_type.h rename to src/token_type.hpp diff --git a/lib/tree_nodes.h b/src/tree_nodes.hpp similarity index 100% rename from lib/tree_nodes.h rename to src/tree_nodes.hpp diff --git a/lib/visitor.h b/src/visitor.hpp similarity index 95% rename from lib/visitor.h rename to src/visitor.hpp index 255105e..b2afa73 100755 --- a/lib/visitor.h +++ b/src/visitor.hpp @@ -1,10 +1,8 @@ #ifndef VISITOR_H #define VISITOR_H -#include "LBPLTypes.h" -#include "tree_nodes.h" - -#include +#include "LBPLTypes.hpp" +#include "tree_nodes.hpp" namespace Statement { struct Visitor { -- 2.52.0