diff --git a/.gitignore b/.gitignore index fcb2c3f6..f116564c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ *.a .vscode /bin -.VSCodeCounter \ No newline at end of file +.VSCodeCounter +optimize \ No newline at end of file diff --git a/ltnc/Backend.hxx b/ltnc/Backend.hxx index e36a9a72..8ef0672b 100644 --- a/ltnc/Backend.hxx +++ b/ltnc/Backend.hxx @@ -1,6 +1,6 @@ #pragma once #include -#include "ltnc/ast/Source.hxx" +#include "ltnc/ast/Ast.hxx" #include "Config.hxx" namespace ltn::c { class Backend { diff --git a/ltnc/Ltnc.cxx b/ltnc/Ltnc.cxx index b14a3759..05c75495 100644 --- a/ltnc/Ltnc.cxx +++ b/ltnc/Ltnc.cxx @@ -23,11 +23,11 @@ void ltn::c::Ltnc::compile(std::istream & in, const std::string &) { this->line = 0; lex::Lexer lexer{in, this->line}; auto source = parse::source(lexer); - for(auto && fx : source->functions) { - this->functions.push_back(std::move(fx)); + for(auto && fx : source) { + this->program.functions.push_back(std::move(fx)); } } void ltn::c::Ltnc::yield(std::ostream & out) { - this->backend->compile(out, this->config, this->functions); + this->backend->compile(out, this->config, this->program.functions); } diff --git a/ltnc/Ltnc.hxx b/ltnc/Ltnc.hxx index 7e3cb0d2..6ed8fd07 100644 --- a/ltnc/Ltnc.hxx +++ b/ltnc/Ltnc.hxx @@ -17,6 +17,6 @@ namespace ltn::c { Config config; std::size_t line = 1; std::unique_ptr backend; - std::vector> functions; + ast::Program program; }; } \ No newline at end of file diff --git a/ltnc/ast/Ast.hxx b/ltnc/ast/Ast.hxx new file mode 100644 index 00000000..a055d366 --- /dev/null +++ b/ltnc/ast/Ast.hxx @@ -0,0 +1,13 @@ +#pragma once +#include "Node.hxx" +#include "Function.hxx" +#include "Expression.hxx" +#include "Statement.hxx" +#include "Literals.hxx" +#include "Assignable.hxx" + +namespace ltn::c::ast { + struct Program { + std::vector> functions; + }; +} \ No newline at end of file diff --git a/ltnc/ast/Source.hxx b/ltnc/ast/Source.hxx deleted file mode 100644 index fff267f0..00000000 --- a/ltnc/ast/Source.hxx +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "Node.hxx" -#include "Function.hxx" - -namespace ltn::c::ast { - struct Source : public Node { - Source( - std::vector> && functions, - const lex::DebugInfo & debugInfo) - : Node(debugInfo), - functions(std::move(functions)) {} - virtual ~Source() = default; - std::vector> functions; - }; -} \ No newline at end of file diff --git a/ltnc/compile/compiling.hxx b/ltnc/compile/compiling.hxx index 4b17e75b..b55902b6 100644 --- a/ltnc/compile/compiling.hxx +++ b/ltnc/compile/compiling.hxx @@ -10,13 +10,7 @@ #include "ExprCode.hxx" #include "ltnc/Config.hxx" #include "ltnc/CompilerError.hxx" -#include "ltnc/ast/Node.hxx" -#include "ltnc/ast/Source.hxx" -#include "ltnc/ast/Function.hxx" -#include "ltnc/ast/Expression.hxx" -#include "ltnc/ast/Statement.hxx" -#include "ltnc/ast/Literals.hxx" -#include "ltnc/ast/Assignable.hxx" +#include "ltnc/ast/Ast.hxx" namespace ltn::c::compile { struct CompilerInfo { @@ -27,8 +21,6 @@ namespace ltn::c::compile { }; - // Source - std::string source(const ast::Source & source, CompilerInfo & info); // Functional std::string functional(const ast::Functional & fx, CompilerInfo & info); diff --git a/ltnc/compile/compilingSource.cxx b/ltnc/compile/compilingSource.cxx deleted file mode 100644 index 5f92b853..00000000 --- a/ltnc/compile/compilingSource.cxx +++ /dev/null @@ -1,5 +0,0 @@ -#include "compiling.hxx" - -namespace ltn::c::compile { - -} \ No newline at end of file diff --git a/ltnc/parse/parsing.hxx b/ltnc/parse/parsing.hxx index 673211d8..708ffee0 100644 --- a/ltnc/parse/parsing.hxx +++ b/ltnc/parse/parsing.hxx @@ -1,15 +1,11 @@ #pragma once -#include "ltnc/ast/Function.hxx" -#include "ltnc/ast/Source.hxx" -#include "ltnc/ast/Statement.hxx" -#include "ltnc/ast/Assignable.hxx" -#include "ltnc/ast/Literals.hxx" +#include "ltnc/ast/Ast.hxx" #include "ltnc/lex/Lexer.hxx" namespace ltn::c::parse { // Sources - std::unique_ptr source(lex::Lexer & lexer); + std::vector> source(lex::Lexer & lexer); // Funcionals std::unique_ptr functional( diff --git a/ltnc/parse/parsingSource.cxx b/ltnc/parse/parsingSource.cxx index 528cfc0d..1db89b3f 100644 --- a/ltnc/parse/parsingSource.cxx +++ b/ltnc/parse/parsingSource.cxx @@ -65,7 +65,7 @@ namespace ltn::c::parse { } } - std::unique_ptr source(lex::Lexer & lexer) { + std::vector> source(lex::Lexer & lexer) { Functionals functions; ast::Namespace nameSpace; while(!lexer.match(TT::___EOF___)) { @@ -81,9 +81,7 @@ namespace ltn::c::parse { else throw unknownDeclaration(lexer); } if(nameSpace.empty()) { - return std::make_unique( - std::move(functions), - lexer.debug()); + return functions; } else throw unclosedNamespace(lexer); }