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
44 changes: 39 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
---
BasedOnStyle: LLVM
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: Left
AlignConsecutiveAssignments:
Enabled: true
AcrossComments: true
AlignConsecutiveBitFields:
Enabled: true
AcrossComments: true
AlignConsecutiveMacros:
Enabled: true
AcrossComments: true
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossComments: true
AlignEscapedNewlines: Left
AlignOperands: AlignAfterOperator
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLambdasOnASingleLine: Empty
AlwaysBreakBeforeMultilineStrings: true
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: All
ColumnLimit: 120
IncludeBlocks: Regroup
IndentWidth: 4
---
Language: Cpp
Standard: c++17
UseTab: Never
InsertBraces: true
InsertNewlineAtEOF: true
ColumnLimit: 120
InsertTrailingCommas: Wrapped
LineEnding: LF
RemoveParentheses: MultipleParentheses
RemoveSemicolon: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: true
SpaceAfterTemplateKeyword: false
SpaceBeforeCtorInitializerColon: false
SpacesInContainerLiterals: false
Standard: c++17
TabWidth: 4
BracedInitializerIndentWidth: 2
2 changes: 0 additions & 2 deletions include/filc/filc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
#ifndef FILC_FILC_H
#define FILC_FILC_H

#include "filc/grammar/Parser.h"
#include "filc/options/OptionsParser.h"
#include "filc/grammar/DumpVisitor.h"
#include "filc/validation/ValidationVisitor.h"
#include "filc/llvm/IRGenerator.h"

namespace filc {
class FilCompiler final {
Expand Down
2 changes: 1 addition & 1 deletion include/filc/grammar/DumpVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DumpVisitor final: public Visitor<void> {
std::ostream &_out;
int _indent_level;

auto printIdent() -> void;
auto printIdent() const -> void;
};
}

Expand Down
14 changes: 8 additions & 6 deletions include/filc/grammar/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
#ifndef FILC_TYPE_H
#define FILC_TYPE_H

#include <string>
#include <memory>
#include <llvm/IR/Type.h>
#include <memory>
#include <string>

namespace filc {
class AbstractType {
public:
virtual ~AbstractType() = default;

[[nodiscard]] virtual auto getName() const noexcept -> std::string = 0;

[[nodiscard]] virtual auto getDisplayName() const noexcept -> std::string = 0;
Expand All @@ -48,7 +50,7 @@ class AbstractType {
llvm::Type *_llvm_type = nullptr;
};

class Type final: public AbstractType {
class Type final : public AbstractType {
public:
explicit Type(std::string name);

Expand All @@ -62,7 +64,7 @@ class Type final: public AbstractType {
std::string _name;
};

class PointerType final: public AbstractType {
class PointerType final : public AbstractType {
public:
explicit PointerType(std::shared_ptr<AbstractType> pointed_type);

Expand All @@ -76,7 +78,7 @@ class PointerType final: public AbstractType {
std::shared_ptr<AbstractType> _pointed_type;
};

class AliasType final: public AbstractType {
class AliasType final : public AbstractType {
public:
AliasType(std::string name, std::shared_ptr<AbstractType> aliased_type);

Expand All @@ -90,7 +92,7 @@ class AliasType final: public AbstractType {
std::string _name;
std::shared_ptr<AbstractType> _aliased_type;
};
}
} // namespace filc

auto operator==(const std::shared_ptr<filc::AbstractType> &a, const std::shared_ptr<filc::AbstractType> &b) -> bool;
auto operator!=(const std::shared_ptr<filc::AbstractType> &a, const std::shared_ptr<filc::AbstractType> &b) -> bool;
Expand Down
10 changes: 6 additions & 4 deletions include/filc/grammar/Visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
#define FILC_VISITOR_H

#include "filc/grammar/ast.h"

#include "llvm/IR/Value.h"

namespace filc {
template<typename Return>
class Visitor {
template<typename Return> class Visitor {
public:
virtual ~Visitor() = default;

Expand Down Expand Up @@ -59,10 +59,12 @@ class Visitor {

class Visitable {
public:
virtual ~Visitable() = default;

virtual auto acceptVoidVisitor(Visitor<void> *visitor) -> void = 0;

virtual auto acceptIRVisitor(Visitor<llvm::Value*> *visitor) -> llvm::Value * = 0;
virtual auto acceptIRVisitor(Visitor<llvm::Value *> *visitor) -> llvm::Value * = 0;
};
}
} // namespace filc

#endif // FILC_VISITOR_H
1 change: 0 additions & 1 deletion include/filc/grammar/assignation/Assignation.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#ifndef FILC_ASSIGNATION_H
#define FILC_ASSIGNATION_H

#include "filc/grammar/ast.h"
#include "filc/grammar/expression/Expression.h"
#include <string>
#include <memory>
Expand Down
1 change: 0 additions & 1 deletion include/filc/grammar/calcul/Calcul.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#ifndef FILC_CALCUL_H
#define FILC_CALCUL_H

#include "filc/grammar/ast.h"
#include "filc/grammar/expression/Expression.h"
#include <memory>
#include <string>
Expand Down
2 changes: 0 additions & 2 deletions include/filc/grammar/expression/Expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
#ifndef FILC_EXPRESSION_H
#define FILC_EXPRESSION_H

#include "filc/grammar/ast.h"
#include "filc/grammar/Visitor.h"
#include "filc/grammar/Position.h"
#include "filc/grammar/Type.h"
#include <string>

namespace filc {
class Expression: public Visitable {
Expand Down
1 change: 0 additions & 1 deletion include/filc/grammar/identifier/Identifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#ifndef FILC_IDENTIFIER_H
#define FILC_IDENTIFIER_H

#include "filc/grammar/ast.h"
#include "filc/grammar/expression/Expression.h"
#include <string>

Expand Down
1 change: 0 additions & 1 deletion include/filc/grammar/literal/Literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#ifndef FILC_LITERAL_H
#define FILC_LITERAL_H

#include "filc/grammar/ast.h"
#include "filc/grammar/expression/Expression.h"

namespace filc {
Expand Down
3 changes: 1 addition & 2 deletions include/filc/grammar/variable/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
#ifndef FILC_VARIABLE_H
#define FILC_VARIABLE_H

#include "filc/grammar/ast.h"
#include "filc/grammar/expression/Expression.h"
#include <string>
#include <memory>

namespace filc {
class VariableDeclaration: public Expression {
class VariableDeclaration final: public Expression {
public:
VariableDeclaration(bool is_constant, std::string name, std::string _type_name, std::shared_ptr<Expression> value);

Expand Down
15 changes: 7 additions & 8 deletions include/filc/llvm/CalculBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#ifndef FILC_CALCULBUILDER_H
#define FILC_CALCULBUILDER_H

#include "filc/grammar/calcul/Calcul.h"
#include "filc/llvm/IRGenerator.h"
#include <llvm/IR/IRBuilder.h>

Expand All @@ -33,23 +32,23 @@ class CalculBuilder final {
public:
explicit CalculBuilder(IRGenerator *generator, llvm::IRBuilder<> *builder);

auto buildCalculValue(BinaryCalcul *calcul) const -> llvm::Value *;
auto buildCalculValue(const BinaryCalcul *calcul) const -> llvm::Value *;

private:
IRGenerator *_generator;
llvm::IRBuilder<> *_builder;

auto buildSignedInteger(BinaryCalcul *calcul) const -> llvm::Value *;
auto buildSignedInteger(const BinaryCalcul *calcul) const -> llvm::Value *;

auto buildUnsignedInteger(BinaryCalcul *calcul) const -> llvm::Value *;
auto buildUnsignedInteger(const BinaryCalcul *calcul) const -> llvm::Value *;

auto buildFloat(BinaryCalcul *calcul) const -> llvm::Value *;
auto buildFloat(const BinaryCalcul *calcul) const -> llvm::Value *;

auto buildBool(BinaryCalcul *calcul) const -> llvm::Value *;
auto buildBool(const BinaryCalcul *calcul) const -> llvm::Value *;

auto buildPointer(BinaryCalcul *calcul) const -> llvm::Value *;
auto buildPointer(const BinaryCalcul *calcul) const -> llvm::Value *;

auto static buildError(BinaryCalcul *calcul) -> std::logic_error;
auto static buildError(const BinaryCalcul *calcul) -> std::logic_error;
};
}

Expand Down
3 changes: 1 addition & 2 deletions include/filc/options/OptionsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <cxxopts.hpp>
#include <exception>
#include <string>
#include <ostream>

namespace filc {
class OptionsParser final {
Expand Down Expand Up @@ -58,7 +57,7 @@ class OptionsParser final {
cxxopts::ParseResult _result;
};

class OptionsParserException : public std::exception {
class OptionsParserException final : public std::exception {
public:
explicit OptionsParserException(std::string message);

Expand Down
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <filc/filc.h>

auto main(int argc, char **argv) -> int {
auto compiler =
filc::FilCompiler(filc::OptionsParser(), filc::DumpVisitor(std::cout), filc::ValidationVisitor(std::cout));
auto compiler
= filc::FilCompiler(filc::OptionsParser(), filc::DumpVisitor(std::cout), filc::ValidationVisitor(std::cout));
return compiler.run(argc, argv);
}
11 changes: 8 additions & 3 deletions src/filc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
* SOFTWARE.
*/
#include "filc/filc.h"

#include "filc/grammar/Parser.h"
#include "filc/grammar/program/Program.h"
#include "filc/llvm/IRGenerator.h"

#include <filesystem>
#include <iostream>
#include <utility>

using namespace filc;

FilCompiler::FilCompiler(OptionsParser options_parser, DumpVisitor ast_dump_visitor,
ValidationVisitor validation_visitor)
FilCompiler::FilCompiler(
OptionsParser options_parser, DumpVisitor ast_dump_visitor, ValidationVisitor validation_visitor
)
: _options_parser(std::move(options_parser)), _ast_dump_visitor(std::move(ast_dump_visitor)),
_validation_visitor(std::move(validation_visitor)) {}

Expand All @@ -46,7 +51,7 @@ auto FilCompiler::run(int argc, char **argv) -> int {
}

const auto filename = _options_parser.getFile();
if (!std::filesystem::exists(filename) || !std::filesystem::is_regular_file(filename)) {
if (! std::filesystem::exists(filename) || ! std::filesystem::is_regular_file(filename)) {
std::cerr << "File " << filename << " not found";
return 1;
}
Expand Down
11 changes: 7 additions & 4 deletions src/grammar/DumpVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/
#include "filc/grammar/DumpVisitor.h"

#include "filc/grammar/assignation/Assignation.h"
#include "filc/grammar/calcul/Calcul.h"
#include "filc/grammar/identifier/Identifier.h"
Expand All @@ -31,7 +32,7 @@

using namespace filc;

DumpVisitor::DumpVisitor(std::ostream &out) : _out(out), _indent_level(0) {}
DumpVisitor::DumpVisitor(std::ostream &out): _out(out), _indent_level(0) {}

auto DumpVisitor::visitProgram(Program *program) -> void {
_out << "=== Begin AST dump ===\n";
Expand All @@ -57,7 +58,7 @@ auto DumpVisitor::visitFloatLiteral(FloatLiteral *literal) -> void {
}

auto DumpVisitor::visitCharacterLiteral(CharacterLiteral *literal) -> void {
auto value = literal->getValue();
const auto value = literal->getValue();
std::string to_print;
switch (value) {
case '\'':
Expand Down Expand Up @@ -109,7 +110,7 @@ auto DumpVisitor::visitStringLiteral(StringLiteral *literal) -> void {
auto DumpVisitor::visitVariableDeclaration(VariableDeclaration *variable) -> void {
printIdent();
_out << "[Variable:" << (variable->isConstant() ? "val" : "var") << ":" << variable->getName();
if (!variable->getTypeName().empty()) {
if (! variable->getTypeName().empty()) {
_out << ":" << variable->getTypeName();
}
_out << "]\n";
Expand Down Expand Up @@ -143,4 +144,6 @@ auto DumpVisitor::visitAssignation(Assignation *assignation) -> void {
_indent_level--;
}

auto DumpVisitor::printIdent() -> void { _out << std::string(_indent_level, '\t'); }
auto DumpVisitor::printIdent() const -> void {
_out << std::string(_indent_level, '\t');
}
4 changes: 3 additions & 1 deletion src/grammar/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
* SOFTWARE.
*/
#include "filc/grammar/Parser.h"

#include "FilLexer.h"
#include "FilParser.h"
#include "antlr4-runtime.h"

#include <filesystem>

using namespace filc;

auto ParserProxy::parse(const std::string &filename) -> std::shared_ptr<Program> {
if (!std::filesystem::exists(filename)) {
if (! std::filesystem::exists(filename)) {
throw std::logic_error("File '" + filename + "' not found");
}

Expand Down
Loading