Skip to content

Commit

Permalink
ast restructring
Browse files Browse the repository at this point in the history
  • Loading branch information
JeneLitsch committed Dec 25, 2021
1 parent 57230e8 commit 4eb3737
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*.a
.vscode
/bin
.VSCodeCounter
.VSCodeCounter
optimize
2 changes: 1 addition & 1 deletion ltnc/Backend.hxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <ostream>
#include "ltnc/ast/Source.hxx"
#include "ltnc/ast/Ast.hxx"
#include "Config.hxx"
namespace ltn::c {
class Backend {
Expand Down
6 changes: 3 additions & 3 deletions ltnc/Ltnc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion ltnc/Ltnc.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ namespace ltn::c {
Config config;
std::size_t line = 1;
std::unique_ptr<Backend> backend;
std::vector<std::unique_ptr<ast::Functional>> functions;
ast::Program program;
};
}
13 changes: 13 additions & 0 deletions ltnc/ast/Ast.hxx
Original file line number Diff line number Diff line change
@@ -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<std::unique_ptr<Functional>> functions;
};
}
15 changes: 0 additions & 15 deletions ltnc/ast/Source.hxx

This file was deleted.

10 changes: 1 addition & 9 deletions ltnc/compile/compiling.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions ltnc/compile/compilingSource.cxx

This file was deleted.

8 changes: 2 additions & 6 deletions ltnc/parse/parsing.hxx
Original file line number Diff line number Diff line change
@@ -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<ast::Source> source(lex::Lexer & lexer);
std::vector<std::unique_ptr<ast::Functional>> source(lex::Lexer & lexer);

// Funcionals
std::unique_ptr<ast::Functional> functional(
Expand Down
6 changes: 2 additions & 4 deletions ltnc/parse/parsingSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace ltn::c::parse {
}
}

std::unique_ptr<ast::Source> source(lex::Lexer & lexer) {
std::vector<std::unique_ptr<ast::Functional>> source(lex::Lexer & lexer) {
Functionals functions;
ast::Namespace nameSpace;
while(!lexer.match(TT::___EOF___)) {
Expand All @@ -81,9 +81,7 @@ namespace ltn::c::parse {
else throw unknownDeclaration(lexer);
}
if(nameSpace.empty()) {
return std::make_unique<ast::Source>(
std::move(functions),
lexer.debug());
return functions;
}
else throw unclosedNamespace(lexer);
}
Expand Down

0 comments on commit 4eb3737

Please sign in to comment.