From c83d1646a0ff35a88933c601338bd2abdec80af9 Mon Sep 17 00:00:00 2001 From: Kevin Traini Date: Wed, 9 Aug 2023 19:07:52 +0200 Subject: [PATCH] phew!: Rm *.old files Closes #40 Don't need them longer. And If we need them, just look before this commit --- src/antlr/FilLexer.g4.old | 99 ---- src/antlr/FilParser.g4.old | 652 --------------------- src/fil/FilCompiler.cpp.old | 224 ------- src/fil/FilCompiler.h.old | 56 -- src/fil/ast/AST.cpp.old | 47 -- src/fil/ast/AST.hpp.old | 601 ------------------- src/fil/ast/AST_decl.h.old | 100 ---- src/fil/ast/AbstractExpr.cpp.old | 53 -- src/fil/ast/AbstractLiteral.cpp.old | 27 - src/fil/ast/AbstractType.cpp.old | 47 -- src/fil/ast/Assignation.cpp.old | 43 -- src/fil/ast/BinaryCalcul.cpp.old | 87 --- src/fil/ast/BlockBody.cpp.old | 53 -- src/fil/ast/BooleanLiteral.cpp.old | 41 -- src/fil/ast/CharLiteral.cpp.old | 39 -- src/fil/ast/FloatLiteral.cpp.old | 39 -- src/fil/ast/ForI.cpp.old | 44 -- src/fil/ast/ForICondition.cpp.old | 58 -- src/fil/ast/ForIter.cpp.old | 44 -- src/fil/ast/ForIterCondition.cpp.old | 43 -- src/fil/ast/Function.cpp.old | 51 -- src/fil/ast/FunctionCall.cpp.old | 58 -- src/fil/ast/FunctionDeclaration.cpp.old | 59 -- src/fil/ast/FunctionParam.cpp.old | 44 -- src/fil/ast/Identifier.cpp.old | 45 -- src/fil/ast/If.cpp.old | 55 -- src/fil/ast/IntegerLiteral.cpp.old | 39 -- src/fil/ast/Lambda.cpp.old | 62 -- src/fil/ast/LambdaType.cpp.old | 67 --- src/fil/ast/Operator.cpp.old | 106 ---- src/fil/ast/ParenthesisBody.cpp.old | 43 -- src/fil/ast/Program.cpp.old | 105 ---- src/fil/ast/StringLiteral.cpp.old | 40 -- src/fil/ast/Switch.cpp.old | 55 -- src/fil/ast/SwitchCase.cpp.old | 44 -- src/fil/ast/SwitchPattern.cpp.old | 56 -- src/fil/ast/Type.cpp.old | 64 -- src/fil/ast/UnaryCalcul.cpp.old | 48 -- src/fil/ast/VariableDeclaration.cpp.old | 62 -- src/fil/ast/While.cpp.old | 44 -- src/fil/environment/Environment.cpp.old | 287 --------- src/fil/environment/Environment.h.old | 53 -- src/fil/environment/Symbol.cpp.old | 68 --- src/fil/environment/Symbol.h.old | 64 -- src/fil/errors/ErrorsRegister.cpp.old | 70 --- src/fil/errors/ErrorsRegister.h.old | 58 -- src/fil/errors/LexerErrorListener.cpp.old | 36 -- src/fil/errors/LexerErrorListener.h.old | 38 -- src/fil/errors/Message.cpp.old | 73 --- src/fil/errors/Message.h.old | 72 --- src/fil/errors/ParserErrorListener.cpp.old | 35 -- src/fil/errors/ParserErrorListener.h.old | 38 -- 52 files changed, 4436 deletions(-) delete mode 100644 src/antlr/FilLexer.g4.old delete mode 100644 src/antlr/FilParser.g4.old delete mode 100644 src/fil/FilCompiler.cpp.old delete mode 100644 src/fil/FilCompiler.h.old delete mode 100644 src/fil/ast/AST.cpp.old delete mode 100644 src/fil/ast/AST.hpp.old delete mode 100644 src/fil/ast/AST_decl.h.old delete mode 100644 src/fil/ast/AbstractExpr.cpp.old delete mode 100644 src/fil/ast/AbstractLiteral.cpp.old delete mode 100644 src/fil/ast/AbstractType.cpp.old delete mode 100644 src/fil/ast/Assignation.cpp.old delete mode 100644 src/fil/ast/BinaryCalcul.cpp.old delete mode 100644 src/fil/ast/BlockBody.cpp.old delete mode 100644 src/fil/ast/BooleanLiteral.cpp.old delete mode 100644 src/fil/ast/CharLiteral.cpp.old delete mode 100644 src/fil/ast/FloatLiteral.cpp.old delete mode 100644 src/fil/ast/ForI.cpp.old delete mode 100644 src/fil/ast/ForICondition.cpp.old delete mode 100644 src/fil/ast/ForIter.cpp.old delete mode 100644 src/fil/ast/ForIterCondition.cpp.old delete mode 100644 src/fil/ast/Function.cpp.old delete mode 100644 src/fil/ast/FunctionCall.cpp.old delete mode 100644 src/fil/ast/FunctionDeclaration.cpp.old delete mode 100644 src/fil/ast/FunctionParam.cpp.old delete mode 100644 src/fil/ast/Identifier.cpp.old delete mode 100644 src/fil/ast/If.cpp.old delete mode 100644 src/fil/ast/IntegerLiteral.cpp.old delete mode 100644 src/fil/ast/Lambda.cpp.old delete mode 100644 src/fil/ast/LambdaType.cpp.old delete mode 100644 src/fil/ast/Operator.cpp.old delete mode 100644 src/fil/ast/ParenthesisBody.cpp.old delete mode 100644 src/fil/ast/Program.cpp.old delete mode 100644 src/fil/ast/StringLiteral.cpp.old delete mode 100644 src/fil/ast/Switch.cpp.old delete mode 100644 src/fil/ast/SwitchCase.cpp.old delete mode 100644 src/fil/ast/SwitchPattern.cpp.old delete mode 100644 src/fil/ast/Type.cpp.old delete mode 100644 src/fil/ast/UnaryCalcul.cpp.old delete mode 100644 src/fil/ast/VariableDeclaration.cpp.old delete mode 100644 src/fil/ast/While.cpp.old delete mode 100644 src/fil/environment/Environment.cpp.old delete mode 100644 src/fil/environment/Environment.h.old delete mode 100644 src/fil/environment/Symbol.cpp.old delete mode 100644 src/fil/environment/Symbol.h.old delete mode 100644 src/fil/errors/ErrorsRegister.cpp.old delete mode 100644 src/fil/errors/ErrorsRegister.h.old delete mode 100644 src/fil/errors/LexerErrorListener.cpp.old delete mode 100644 src/fil/errors/LexerErrorListener.h.old delete mode 100644 src/fil/errors/Message.cpp.old delete mode 100644 src/fil/errors/Message.h.old delete mode 100644 src/fil/errors/ParserErrorListener.cpp.old delete mode 100644 src/fil/errors/ParserErrorListener.h.old diff --git a/src/antlr/FilLexer.g4.old b/src/antlr/FilLexer.g4.old deleted file mode 100644 index cc08db55..00000000 --- a/src/antlr/FilLexer.g4.old +++ /dev/null @@ -1,99 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -lexer grammar FilLexer; - -@lexer::header { -#include "utils.h" -} - -// Keywords -EXPORT: 'export'; -MODULE: 'module'; -USE: 'use'; -TRUE: 'true'; -FALSE: 'false'; -VAL: 'val'; -VAR: 'var'; -FUN: 'fun'; -IF: 'if'; -ELSE: 'else'; -SWITCH: 'switch'; -DEFAULT: 'default'; -FOR: 'for'; -WHILE: 'while'; -OPERATOR: 'operator'; - -// Operators -EQ: '='; -COLON: ':'; -LBRACK: '['; -RBRACK: ']'; -STAR: '*'; -PLUSPLUS: '++'; -MINUSMINUS: '--'; -REF: '&'; -NOT: '!'; -AND: '&&'; -OR: '||'; -LESS: '<'; -GREATER: '>'; -EQEQ: '=='; -LEQ: '<='; -GEQ: '>='; -NEQ: '!='; -FLEFT: '<<'; -FRIGHT: '>>'; -PLUS: '+'; -MINUS: '-'; -DIV: '/'; -MOD: '%'; -LPAREN: '('; -RPAREN: ')'; -COMMA: ','; -LBRACE: '{'; -RBRACE: '}'; -ARROW: '->'; -SEMI: ';'; - -// Literals -fragment DIGIT: [0-9]; -INTEGER: '-'? DIGIT+; -FLOAT: '-'? DIGIT* '.' DIGIT+; -fragment UPPERCASE: [A-Z]; -fragment LOWERCASE: [a-z]; -fragment LETTER: LOWERCASE | UPPERCASE; -fragment STRING_CHAR: ~('"' | '\\' | '\n'); -STRING: '"' (STRING_CHAR | '\\"' | '\\\\')* '"'; -CHARACTER: '\'' ~('\'' | '\\' | '\n') '\''; - -// Comments -COMMENT: '//' (~('\n' | '\r'))* -> skip; -COMMENT_BLOCK: '/*' .*? '*/' -> skip; - -// Ignoring chars -SEPARATOR: (' ' | '\t' | '\r' | '\n' | EOF) -> skip; - -// Others -DOT: '.'; -IDENTIFIER: (LETTER | DIGIT | '_')+; diff --git a/src/antlr/FilParser.g4.old b/src/antlr/FilParser.g4.old deleted file mode 100644 index 7029be63..00000000 --- a/src/antlr/FilParser.g4.old +++ /dev/null @@ -1,652 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -parser grammar FilParser; - -options { - tokenVocab = FilLexer; -} - -@parser::header { -#include "AST.hpp" -#include "FilCompiler.h" - -#include -#include -} - -@parser::postinclude { -using namespace ast; -using namespace std; -} - -@parser::members { -Program* parseTree() { - return prog()->tree; -} -} - -prog returns[Program *tree] -@init { - auto imports = vector(); - auto exprs = vector(); -} -@after { - $tree = new Program($m.text, imports, exprs); -} - : m=module (i=import_ { - imports.push_back($i.text); - })* (exported=EXPORT? e=expr { - auto e = $e.tree; - if (e) - e->isExported($exported ? true : false); - exprs.push_back(e); - })* EOF; - -module returns[string text] - : MODULE i1=IDENTIFIER { - $text = $i1.text; - } (DOT ii=IDENTIFIER { - $text += "." + $ii.text; - })* - ; - -import_ returns[std::string text] -@init { - string name; -} -@after { - $text = FilCompiler::import(name, $s); -} - : s=USE i1=IDENTIFIER { - name = $i1.text; - } (DOT ii=IDENTIFIER { - name += "." + $ii.text; - })* - ; - -// _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - -expr returns[AbstractExpr *tree] - : e1=literal { - $tree = $e1.tree; - } - | e2=variable_declaration { - $tree = $e2.tree; - } - | e3=assignation { - $tree = $e3.tree; - } - | e6=unary_calcul { - $tree = $e6.tree; - } - | e7=expr e8=binary_operator e9=expr { - $tree = new BinaryCalcul($e7.tree, $e8.tree, $e9.tree); - $tree->setPosition($e7.start); - } - | e10=function { - $tree = $e10.tree; - } - | e11=lambda { - $tree = $e11.tree; - } - | e12=control { - $tree = $e12.tree; - } - | e13=parenthesis_body { - $tree = $e13.tree; - } - | e5=IDENTIFIER { - $tree = new Identifier($e5.text); - $tree->setPosition($e5); - } - ; - -// _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - -literal returns[AbstractLiteral *tree] - : l1=boolean { - $tree = $l1.tree; - } - | l2=number { - $tree = $l2.tree; - } - | l3=CHARACTER { - $tree = new CharLiteral($l3.text); - $tree->setPosition($l3); - } - | l4=STRING { - $tree = new StringLiteral($l4.text); - $tree->setPosition($l4); - } - ; - -boolean returns[BooleanLiteral *tree] - : b1=TRUE { - $tree = new BooleanLiteral(true); - $tree->setPosition($b1); - } - | b2=FALSE { - $tree = new BooleanLiteral(false); - $tree->setPosition($b2); - }; - -number returns[AbstractLiteral *tree] - : i=INTEGER { - $tree = new IntegerLiteral(stoi($i.text)); - $tree->setPosition($i); - } - | f=FLOAT { - $tree = new FloatLiteral(stof($f.text)); - $tree->setPosition($f); - }; - -// _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - -variable_declaration returns[VariableDeclaration *tree] -@init { - bool isVal = false; - Identifier *name = nullptr; - AbstractType *vt = nullptr; - Assignation *va = nullptr; -} -@after { - $tree = new VariableDeclaration(isVal, name, vt, va); - $tree->setPosition($v); -} - : (v=VAL { - isVal = true; - } | v=VAR) i=IDENTIFIER { - name = new Identifier($i.text); - name->setPosition($i); - } COLON t=type { - vt = $t.tree; - } (a=assignation { - va = $a.tree; - })?; - -assignation returns[Assignation *tree] - : s=EQ e=expr { - $tree = new Assignation($e.tree); - $tree->setPosition($s); - }; - -type returns[AbstractType *tree] -@init { - AbstractType *prev = nullptr; -} -@after { - $tree = prev; -} - : i=IDENTIFIER { - auto id = new Identifier($i.text); - id->setPosition($i); - prev = new Type(id); - prev->setPosition($i); - } (st=LBRACK s=INTEGER RBRACK { - prev = new Type(stoi($s.text), prev); - prev->setPosition($st); - } - | st=STAR { - prev = new Type(prev); - prev->setPosition($st); - })* - | t=lambda_type { - prev = $t.tree; - }; - -// _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - -unary_calcul returns[UnaryCalcul *tree] - : i1=IDENTIFIER o1=post_operator { - auto id = new Identifier($i1.text); - id->setPosition($i1); - $tree = new UnaryCalcul(id, $o1.tree); - $tree->setPosition($i1); - } - | o2=pre_operator i2=IDENTIFIER { - auto id = new Identifier($i2.text); - id->setPosition($i2); - $tree = new UnaryCalcul($o2.tree, id); - $tree->setPosition($o2.start); - }; - -post_operator returns[Operator *tree] - : o1=PLUSPLUS { - $tree = new Operator(Operator::PLUSPLUS); - $tree->setPosition($o1); - } - | o2=MINUSMINUS { - $tree = new Operator(Operator::MINUSMINUS); - $tree->setPosition($o2); - } - | (o3=LBRACK e1=expr RBRACK) { - $tree = new Operator($e1.tree); - $tree->setPosition($o3); - } - | (o4=LPAREN e2=function_call_params RPAREN) { - $tree = new Operator($e2.tree); - $tree->setPosition($o4); - }; - -pre_operator returns[Operator *tree] - : o1=PLUSPLUS { - $tree = new Operator(Operator::PLUSPLUS); - $tree->setPosition($o1); - } - | o2=MINUSMINUS { - $tree = new Operator(Operator::PLUSPLUS); - $tree->setPosition($o2); - } - | o3=REF { - $tree = new Operator(Operator::REF); - $tree->setPosition($o3); - } - | o4=STAR { - $tree = new Operator(Operator::STAR); - $tree->setPosition($o4); - } - | o5=NOT { - $tree = new Operator(Operator::NOT); - $tree->setPosition($o5); - }; - -binary_operator returns[Operator *tree] - : b1=STAR { - $tree = new Operator(Operator::STAR); - $tree->setPosition($b1); - } - | b2=DIV { - $tree = new Operator(Operator::DIV); - $tree->setPosition($b2); - } - | b3=MOD { - $tree = new Operator(Operator::MOD); - $tree->setPosition($b3); - } - - | b4=PLUS { - $tree = new Operator(Operator::PLUS); - $tree->setPosition($b4); - } - | b5=MINUS { - $tree = new Operator(Operator::MINUS); - $tree->setPosition($b5); - } - - | b6=FLEFT { - $tree = new Operator(Operator::FLEFT); - $tree->setPosition($b6); - } - | b7=FRIGHT { - $tree = new Operator(Operator::FRIGHT); - $tree->setPosition($b7); - } - - | b8=LESS { - $tree = new Operator(Operator::LESS); - $tree->setPosition($b8); - } - | b9=GREATER { - $tree = new Operator(Operator::GREATER); - $tree->setPosition($b9); - } - | b10=EQEQ { - $tree = new Operator(Operator::EQEQ); - $tree->setPosition($b10); - } - | b11=LEQ { - $tree = new Operator(Operator::LEQ); - $tree->setPosition($b11); - } - | b12=GEQ { - $tree = new Operator(Operator::GEQ); - $tree->setPosition($b12); - } - | b13=NEQ { - $tree = new Operator(Operator::NEQ); - $tree->setPosition($b13); - } - - | b14=AND { - $tree = new Operator(Operator::AND); - $tree->setPosition($b14); - } - | b15=OR { - $tree = new Operator(Operator::OR); - $tree->setPosition($b15); - }; - -// _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - -function returns[Function *tree] - : d=function_declaration b=function_body { - $tree = new Function($d.tree, $b.tree); - $tree->setPosition($d.start); - }; - -function_declaration returns[FunctionDeclaration *tree] -@init { - AbstractType *ft = nullptr; - vector params; -} -@after { - auto id = new Identifier($i.text); - id->setPosition($i.start); - $tree = new FunctionDeclaration(id, params, ft); - $tree->setPosition($f); -} - : f=FUN i=function_identifier LPAREN (p=function_params { - params = $p.tree; - })? RPAREN t=function_type { - ft = $t.tree; - }; - -function_identifier returns[std::string text] - : (o=OPERATOR f=function_operator) { - $text = $o.text + $f.text; - } - | i=IDENTIFIER { - $text = $i.text; - }; - -function_operator returns[std::string text] - : (LBRACK RBRACK) { $text = "[]"; } - | STAR { $text = "*"; } - | PLUSPLUS { $text = "++"; } - | MINUSMINUS { $text = "--"; } - | REF { $text = "&"; } - | NOT { $text = "!"; } - | AND { $text = "&&"; } - | OR { $text = "||"; } - | LESS { $text = "<"; } - | GREATER { $text = ">"; } - | EQEQ { $text = "=="; } - | LEQ { $text = "<="; } - | GEQ { $text = ">="; } - | NEQ { $text = "!="; } - | FLEFT { $text = "<<"; } - | FRIGHT { $text = ">>"; } - | PLUS { $text = "+"; } - | MINUS { $text = "-"; } - | DIV { $text = "/"; } - | MOD { $text = "%"; } - | (LPAREN RPAREN) { $text = "()"; } - ; - -function_params returns[vector tree] -@init { - vector res; -} -@after { - $tree = res; -} - : i1=IDENTIFIER COLON t1=type { - auto id = new Identifier($i1.text); - id->setPosition($i1); - auto param1 = new FunctionParam(id, $t1.tree); - param1->setPosition($i1); - res.push_back(param1); - } (COMMA ii=IDENTIFIER COLON ti=type { - auto id = new Identifier($ii.text); - id->setPosition($ii); - auto paramI = new FunctionParam(id, $ti.tree); - paramI->setPosition($ii); - res.push_back(paramI); - })?; - -function_type returns[AbstractType *tree] - : COLON t=type { - $tree = $t.tree; - $tree->setPosition($t.start); - }; - -function_body returns[AbstractExpr *tree] - : b1=assignation { - $tree = $b1.tree; - } - | b2=parenthesis_body { - $tree = $b2.tree; - } - | b3=block_body { - $tree = $b3.tree; - }; - -parenthesis_body returns[ParenthesisBody *tree] - : LPAREN e=expr { - $tree = new ParenthesisBody($e.tree); - $tree->setPosition($e.start); - } RPAREN; - -block_body returns[BlockBody *tree] -@init { - vector res; -} -@after { - $tree = new BlockBody(res); - $tree->setPosition($s); -} - : s=LBRACE (ei=expr { - res.push_back($ei.tree); - })* RBRACE; - -// _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - -lambda returns[Lambda *tree] -@init { - vector lp; - AbstractType *lt = nullptr; - AbstractExpr *lb = nullptr; -} -@after { - $tree = new Lambda(lp, lt, lb); - $tree->setPosition($s); -} - : s=LPAREN (p=function_params { - lp = $p.tree; - })? RPAREN t=function_type { - lt = $t.tree; - } ARROW (b1=expr { - lb = $b1.tree; - } | b2=parenthesis_body { - lb = $b2.tree; - } | b3=block_body { - lb = $b3.tree; - }); - -lambda_type returns[LambdaType *tree] -@init { - vector args; -} -@after { - $tree = new LambdaType(args, $r.tree); - $tree->setPosition($s); -} - : s=LPAREN (a1=type { - args.push_back($a1.tree); - } (COMMA ai=type { - args.push_back($ai.tree); - })*)? RPAREN ARROW r=type; - -// _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - -control returns[AbstractExpr *tree] - : c=condition { - $tree = $c.tree; - } - | l=loop { - $tree = $l.tree; - }; - -condition returns[AbstractExpr *tree] - : i=if_ { - $tree = $i.tree; - } - | s=switch_ { - $tree = $s.tree; - }; - -if_ returns[If *tree] -@init { - AbstractExpr *else_ = nullptr; -} -@after { - $tree = new If($c.tree, $b.tree, else_); - $tree->setPosition($s); -} - : s=IF c=if_condition b=if_body (ELSE (e1=if_ { - else_ = $e1.tree; - } | e2=if_body { - else_ = $e2.tree; - }))?; - -if_condition returns[AbstractExpr *tree] - : LPAREN e=expr { - $tree = $e.tree; - } RPAREN; - -if_body returns[AbstractExpr *tree] - : b1=expr { - $tree = $b1.tree; - } | b2=block_body { - $tree = $b2.tree; - }; - -switch_ returns[Switch *tree] - : s=SWITCH c=if_condition b=switch_body { - $tree = new Switch($c.tree, $b.tree); - $tree->setPosition($s); - }; - -switch_body returns[vector tree] -@init { - vector res; -} -@after { - $tree = res; -} - : LBRACE (c=switch_case { - res.push_back($c.tree); - })* RBRACE; - -switch_case returns[SwitchCase *tree] -@init { - AbstractExpr *body = nullptr; -} -@after { - $tree = new SwitchCase($p.tree, body); - $tree->setPosition($p.start); -} - : p=switch_pattern ARROW (b1=expr { - body = $b1.tree; - } | b2=parenthesis_body { - body = $b2.tree; - } | b3=block_body { - body = $b3.tree; - }); - -switch_pattern returns[SwitchPattern *tree] - : s=DEFAULT { - $tree = new SwitchPattern(); - $tree->setPosition($s); - } | l=literal { - $tree = new SwitchPattern($l.tree); - $tree->setPosition($l.start); - }; - -loop returns[AbstractExpr *tree] - : l1=for_i { - $tree = $l1.tree; - } - | l2=for_iter { - $tree = $l2.tree; - } - | l3=while_ { - $tree = $l3.tree; - }; - -for_i returns[ForI *tree] - : s=FOR c=for_i_condition b=if_body { - $tree = new ForI($c.tree, $b.tree); - $tree->setPosition($s); - }; - -for_i_condition returns[ForICondition *tree] -@init { - VariableDeclaration *decl = nullptr; - AbstractExpr *cond = nullptr; - AbstractExpr *iter = nullptr; -} -@after { - $tree = new ForICondition(decl, cond, iter); - $tree->setPosition($s); -} - : s=LPAREN (d=variable_declaration { - decl = $d.tree; - })? SEMI (c=expr { - cond = $c.tree; - })? SEMI (i=expr { - iter = $i.tree; - })? RPAREN; - -for_iter returns[ForIter *tree] - : s=FOR c=for_iter_condition b=if_body { - $tree = new ForIter($c.tree, $b.tree); - $tree->setPosition($s); - }; - -for_iter_condition returns[ForIterCondition *tree] -@init { - bool isVal = false; -} - : s=LPAREN (VAL { - isVal = true; - } | VAR) i1=IDENTIFIER COLON i2=IDENTIFIER RPAREN { - auto id1 = new Identifier($i1.text); - id1->setPosition($i1); - auto id2 = new Identifier($i2.text); - id2->setPosition($i2); - $tree = new ForIterCondition(isVal, id1, id2); - $tree->setPosition($s); - }; - -while_ returns[While *tree] - : s=WHILE c=if_condition b=if_body { - $tree = new While($c.tree, $b.tree); - $tree->setPosition($s); - }; - -// _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - -function_call_params returns[vector tree] -@init { - vector res; -} -@after { - $tree = res; -} - : e1=expr { - res.push_back($e1.tree); - } (COMMA ei=expr { - res.push_back($ei.tree); - })*; diff --git a/src/fil/FilCompiler.cpp.old b/src/fil/FilCompiler.cpp.old deleted file mode 100644 index 9bdc5edd..00000000 --- a/src/fil/FilCompiler.cpp.old +++ /dev/null @@ -1,224 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "ErrorsRegister.h" -#include "FilCompiler.h.old" -#include "FilLexer.h" -#include "FilParser.h" -#include "LexerErrorListener.h" -#include "ParserErrorListener.h" -#include "antlr4-runtime.h" - -#include -#include - -using namespace std; -using namespace antlr4; -using namespace antlrcppfil; - -string FilCompiler::_current_dir; -map FilCompiler::_modules; - -FilCompiler::FilCompiler(string filename) : _filename(std::move(filename)) { - _current_dir = _filename.substr(0, _filename.find_last_of("/\\")); -} - -auto FilCompiler::compile(int flag, bool debug, const string &output) -> int { - ifstream file(_filename); - if (!file.is_open()) { - cout << "File " << _filename << " not found" << endl; - file.close(); - return 1; - } - file.close(); - - try { - ErrorsRegister::init(); - - ANTLRFileStream input; - input.loadFromFile(_filename); - FilLexer lexer(&input); - lexer.removeErrorListeners(); - lexer.addErrorListener(new LexerErrorListener()); - CommonTokenStream tokens(&lexer); - - tokens.fill(); - - FilParser parser(&tokens); - parser.removeErrorListeners(); - parser.addErrorListener(new ParserErrorListener()); - Program *program = parser.parseTree(); - - ErrorsRegister::dump(cerr); - if (ErrorsRegister::containsError()) { - return 1; - } - ErrorsRegister::clean(); - - if (flag == DECOMPILE) { - cout << program->decompile(0); - - return 0; - } - - // Resolve environment - program->resolveEnvironment(); - - ErrorsRegister::dump(cerr); - if (ErrorsRegister::containsError()) { - return 1; - } - ErrorsRegister::clean(); - - if (flag == FLAGS::AST) { - cout << program->dump(0) << endl; - - return 0; - } - - // TODO : LLVM IR generation - (void) debug; - (void) output; - } catch (exception &e) { - cout << e.what() << endl; - return 1; - } - - return 0; -} - -auto FilCompiler::import(const string &module_name, antlr4::Token *tkn) -> string { - // Check if the module is already imported - if (_modules.find(module_name) != _modules.end()) { - return module_name; - } - // It fixes the infinite loop of import - // The nullptr is replaced by the Program pointer just after the parsing - _modules[module_name] = nullptr; - - -#ifdef _WIN32 - char sep = '\\'; - string ssep = "\\"; -#else - char sep = '/'; - string ssep = "/"; -#endif - - // Lambda to parse the file and return the AST - auto get_program = [module_name](const string &filename) { - ANTLRFileStream input; - input.loadFromFile(filename); - FilLexer lexer(&input); - CommonTokenStream tokens(&lexer); - - tokens.fill(); - - FilParser parser(&tokens); - parser.removeErrorListeners(); - parser.addErrorListener(new ParserErrorListener()); - Program *program = parser.parseTree(); - _modules[module_name] = program; - }; - - // Looking for the module in the current directory - auto filename = _current_dir + ssep + replace(module_name, '.', sep) + ".fil"; - ifstream file(filename); - if (file.is_open()) { - file.close(); - get_program(filename); - return module_name; - } - // ---- - filename = _current_dir + ssep + replace(module_name, '.', sep) + ssep + - *(split(module_name, '.').end() - 1) + ".fil"; - file = ifstream(filename); - if (file.is_open()) { - file.close(); - get_program(filename); - return module_name; - } - - // Special case for the standard library - if (module_name == "fil.system") { - auto *prog = getSystemProgram(); - _modules[module_name] = prog; - return module_name; - } - - // Looking for the module in the include path $FIL_PATH - auto fil_path = toString(getenv("FIL_PATH")); - auto paths = split(fil_path, ':'); - for (auto &path: paths) { - filename = path + ssep + replace(module_name, '.', sep) + ".fil"; - file = ifstream(filename); - if (file.is_open()) { - file.close(); - get_program(filename); - return module_name; - } - // ---- - filename = path + ssep; - filename += replace(module_name, '.', sep) + ssep; - filename += *(split(module_name, '.').end() - 1) + ".fil"; - file = ifstream(filename); - if (file.is_open()) { - file.close(); - get_program(filename); - return module_name; - } - } - - // Module not found - ErrorsRegister::addError(new Error( - "Module " + module_name + " not found", - new Position((int) tkn->getLine(), - (int) tkn->getCharPositionInLine(), - tkn->getTokenSource()->getSourceName()))); - - return ""; -} - -auto FilCompiler::getModule(const std::string &module_name) -> ast::Program * { - return _modules[module_name]; -} - -auto FilCompiler::getSystemProgram() -> Program * { - static auto *system_program = new Program("fil.system", {}, {}); - static bool initialized = false; - - if (initialized) { - return system_program; - } - - initialized = true; - - auto *env = Environment::getGlobalEnvironment(); - - // Add system functions - // TODO - - system_program->setEnvironment(env); - - return system_program; -} diff --git a/src/fil/FilCompiler.h.old b/src/fil/FilCompiler.h.old deleted file mode 100644 index 7f6e0c9d..00000000 --- a/src/fil/FilCompiler.h.old +++ /dev/null @@ -1,56 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef FILC_FILCOMPILER_H -#define FILC_FILCOMPILER_H - -#include "AST_decl.h" -#include "antlr4-runtime.h" -#include - -class FilCompiler { -public: - explicit FilCompiler(std::string filename); - - auto compile(int flag, bool debug, const std::string &output) -> int; - - static auto import(const std::string &module_name, antlr4::Token *tkn) -> std::string; - - static auto getModule(const std::string &module_name) -> ast::Program *; - -private: - static auto getSystemProgram() -> ast::Program *; - - std::string _filename; - static std::string _current_dir; - static std::map _modules; -}; - -using FLAGS = enum FLAGS { - NONE, - - DECOMPILE, - AST, -}; - -#endif//FILC_FILCOMPILER_H diff --git a/src/fil/ast/AST.cpp.old b/src/fil/ast/AST.cpp.old deleted file mode 100644 index e8b41d65..00000000 --- a/src/fil/ast/AST.cpp.old +++ /dev/null @@ -1,47 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -AST::AST() : _pos(nullptr) {} - -auto AST::decompile(int indent) const -> string { - throw; -} - -auto AST::dump(int indent) const -> std::string { - throw; -} - -void AST::setPosition(antlr4::Token *token) { - _pos = new Position((int) token->getLine(), - (int) token->getCharPositionInLine(), - token->getTokenSource()->getSourceName()); -} - -auto AST::getPosition() const -> Position * { - return _pos; -} diff --git a/src/fil/ast/AST.hpp.old b/src/fil/ast/AST.hpp.old deleted file mode 100644 index 6c7a874c..00000000 --- a/src/fil/ast/AST.hpp.old +++ /dev/null @@ -1,601 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef FILC_AST_HPP -#define FILC_AST_HPP - -#include "antlr4-runtime.h" -#include -#include - -#include "AST_decl.h.old" -#include "Environment.h" -#include "ErrorsRegister.h" -#include "utils.h" - -namespace ast { - class AST { - public: - AST(); - - virtual ~AST() = default; - - [[nodiscard]] virtual auto decompile(int indent) const -> std::string; - - [[nodiscard]] virtual auto dump(int indent) const -> std::string; - - void setPosition(antlr4::Token *token); - - [[nodiscard]] auto getPosition() const -> Position *; - - protected: - Position *_pos; - }; - - class AbstractExpr : public AST { - public: - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - void isExported(bool exported); - - [[nodiscard]] auto isExported() const -> bool; - - [[nodiscard]] virtual auto isVar() const -> bool; - - [[nodiscard]] virtual auto isFunc() const -> bool; - - [[nodiscard]] auto getExprType() const -> AbstractType *; - - protected: - AbstractExpr(); - - bool _is_exported; - AbstractType *_expr_type; - }; - - class Program : public AST { - public: - Program(std::string module, - const std::vector &imports, - const std::vector &exprs); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - void resolveEnvironment(); - - void setEnvironment(Environment *environment); - - private: - std::string _module; - std::vector _imports; - std::vector _imported_modules; - std::vector _exprs; - Environment *_environment; - - bool _resolved; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class Identifier : public AbstractExpr { - public: - explicit Identifier(std::string name); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto getName() const -> const std::string &; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - std::string _name; - Symbol *_symbol; - }; - - class AbstractType : public AST { - protected: - AbstractType() = default; - - public: - [[nodiscard]] virtual auto getName() const -> std::string = 0; - - [[nodiscard]] auto equals(const AbstractType &other) const -> bool; - - [[nodiscard]] virtual auto isIterable() const -> bool; - - virtual auto getIterableType() -> AbstractType *; - }; - - class Type : public AbstractType { - public: - explicit Type(Identifier *name);// IDENTIFIER - - Type(int array_size, AbstractType *sub_type);// IDENTIFIER '[' INTEGER ']' - - explicit Type(AbstractType *sub_type);// IDENTIFIER '*' - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto getName() const -> std::string override; - - [[nodiscard]] auto isIterable() const -> bool override; - - auto getIterableType() -> AbstractType * override; - - private: - Identifier *_name; - - bool _is_array; - int _array_size; - - bool _is_pointer; - AbstractType *_sub_type; - }; - - class LambdaType : public AbstractType { - public: - LambdaType(const std::vector &args, AbstractType *ret); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto getName() const -> std::string override; - - [[nodiscard]] auto getReturnType() const -> AbstractType *; - - void setReturnType(AbstractType *ret); - - [[nodiscard]] auto getArgsTypes() const -> const std::vector &; - - private: - std::vector _args; - AbstractType *_ret; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class BlockBody : public AbstractExpr { - public: - explicit BlockBody(const std::vector &exprs); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - std::vector _exprs; - Environment *_environment; - }; - - class ParenthesisBody : public AbstractExpr { - public: - explicit ParenthesisBody(AbstractExpr *expr); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - AbstractExpr *_expr; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class AbstractLiteral : public AbstractExpr { - }; - - class BooleanLiteral : public AbstractLiteral { - public: - explicit BooleanLiteral(bool value); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - bool _value; - }; - - class IntegerLiteral : public AbstractLiteral { - public: - explicit IntegerLiteral(int value); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - int _value; - }; - - class FloatLiteral : public AbstractLiteral { - public: - explicit FloatLiteral(float value); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - float _value; - }; - - class CharLiteral : public AbstractLiteral { - public: - explicit CharLiteral(const std::string &value); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - char _value; - }; - - class StringLiteral : public AbstractLiteral { - public: - explicit StringLiteral(const std::string &value); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - protected: - std::string _value; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class Assignation : public AbstractExpr { - public: - explicit Assignation(AbstractExpr *expr); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - AbstractExpr *_expr; - }; - - class VariableDeclaration : public AbstractExpr { - public: - VariableDeclaration(bool is_val, Identifier *name, AbstractType *type, Assignation *assignation); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto isVar() const -> bool override; - - [[nodiscard]] auto getSymbol() const -> Symbol *; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - bool _is_val; - Identifier *_name; - AbstractType *_type; - Assignation *_assignation; - Symbol *_symbol; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class Operator : public AST { - public: - using Op = enum { - STAR, - PLUSPLUS, - MINUSMINUS, - REF, - NOT, - AND, - OR, - LESS, - GREATER, - EQEQ, - LEQ, - GEQ, - NEQ, - FLEFT, - FRIGHT, - PLUS, - MINUS, - DIV, - MOD, - ARRAY, - FUNCTION, - }; - - explicit Operator(Op p_operator); - - explicit Operator(AbstractExpr *index); - - explicit Operator(const std::vector &args); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto getOp() const -> Op; - - private: - Op _operator; - AbstractExpr *_index; - std::vector _args; - }; - - class UnaryCalcul : public AbstractExpr { - public: - UnaryCalcul(Operator *p_operator, Identifier *identifier); - - UnaryCalcul(Identifier *identifier, Operator *p_operator); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - Operator *_operator; - Identifier *_identifier; - bool _is_prefix; - }; - - class BinaryCalcul : public AbstractExpr { - public: - BinaryCalcul(AbstractExpr *left, Operator *p_operator, AbstractExpr *right); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - AbstractExpr *_left; - Operator *_op; - AbstractExpr *_right; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class FunctionParam : public AST { - public: - FunctionParam(Identifier *name, AbstractType *type); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - Identifier *_name; - AbstractType *_type; - }; - - class FunctionDeclaration : public AbstractExpr { - public: - FunctionDeclaration(Identifier *name, const std::vector ¶ms, AbstractType *type); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - Identifier *_name; - std::vector _params; - AbstractType *_type; - }; - - class Function : public AbstractExpr { - public: - Function(FunctionDeclaration *declaration, AbstractExpr *body); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto isFunc() const -> bool override; - - [[nodiscard]] auto getSymbol() const -> Symbol *; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - FunctionDeclaration *_declaration; - AbstractExpr *_body; - Symbol *_symbol; - Environment *_environment; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class Lambda : public AbstractExpr { - public: - Lambda(const std::vector ¶ms, AbstractType *type, AbstractExpr *body); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - std::vector _params; - AbstractType *_type; - AbstractExpr *_body; - Environment *_environment; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class If : public AbstractExpr { - public: - If(AbstractExpr *condition, AbstractExpr *then_case, AbstractExpr *else_case); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - AbstractExpr *_condition; - AbstractExpr *_then; - AbstractExpr *_else; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class SwitchPattern : public AST { - public: - SwitchPattern(); - - explicit SwitchPattern(AbstractLiteral *literal); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto getLiteral() const -> AbstractLiteral *; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - [[nodiscard]] auto isDefault() const -> bool; - - private: - bool _is_default; - AbstractLiteral *_literal; - }; - - class SwitchCase : public AbstractExpr { - public: - explicit SwitchCase(SwitchPattern *pattern, AbstractExpr *body); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - SwitchPattern *_pattern; - AbstractExpr *_body; - }; - - class Switch : public AbstractExpr { - public: - Switch(AbstractExpr *condition, const std::vector &cases); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - AbstractExpr *_condition; - std::vector _cases; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class ForICondition : public AST { - public: - ForICondition(VariableDeclaration *declaration, AbstractExpr *condition, AbstractExpr *increment); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - VariableDeclaration *_declaration; - AbstractExpr *_condition; - AbstractExpr *_increment; - }; - - class ForI : public AbstractExpr { - public: - ForI(ForICondition *condition, AbstractExpr *body); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - ForICondition *_condition; - AbstractExpr *_body; - Environment *_environment; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class ForIterCondition : public AST { - public: - ForIterCondition(bool is_val, Identifier *iterator, Identifier *iterable); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - bool _is_val; - Identifier *_iterator; - Identifier *_iterable; - Symbol *_iterator_symbol; - }; - - class ForIter : public AbstractExpr { - public: - ForIter(ForIterCondition *condition, AbstractExpr *body); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - ForIterCondition *_condition; - AbstractExpr *_body; - Environment *_environment; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class While : public AbstractExpr { - public: - While(AbstractExpr *condition, AbstractExpr *body); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - AbstractExpr *_condition; - AbstractExpr *_body; - Environment *_environment; - }; - - // _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - - class FunctionCall : public AbstractExpr { - public: - FunctionCall(Identifier *name, const std::vector &args); - - [[nodiscard]] auto decompile(int indent) const -> std::string override; - - [[nodiscard]] auto dump(int indent) const -> std::string override; - - private: - Identifier *_name; - std::vector _args; - }; -}// namespace ast - -auto operator==(const ast::AbstractType &first, const ast::AbstractType &other) -> bool; - -auto operator!=(const ast::AbstractType &first, const ast::AbstractType &other) -> bool; - -#endif//FILC_AST_HPP diff --git a/src/fil/ast/AST_decl.h.old b/src/fil/ast/AST_decl.h.old deleted file mode 100644 index eab9ee6a..00000000 --- a/src/fil/ast/AST_decl.h.old +++ /dev/null @@ -1,100 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef FILC_AST_DECL_H -#define FILC_AST_DECL_H - -/** - * Pre-declaration of all AST classes - */ -namespace ast { - class AST; - - class AbstractExpr; - - class Program; - - class Identifier; - - class AbstractType; - - class Type; - - class LambdaType; - - class BlockBody; - - class ParenthesisBody; - - class AbstractLiteral; - - class BooleanLiteral; - - class IntegerLiteral; - - class FloatLiteral; - - class CharLiteral; - - class StringLiteral; - - class Assignation; - - class VariableDeclaration; - - class Operator; - - class UnaryCalcul; - - class BinaryCalcul; - - class FunctionParam; - - class FunctionDeclaration; - - class Function; - - class Lambda; - - class If; - - class SwitchPattern; - - class SwitchCase; - - class Switch; - - class ForICondition; - - class ForI; - - class ForIterCondition; - - class ForIter; - - class While; - - class FunctionCall; -} - -#endif //FILC_AST_DECL_H diff --git a/src/fil/ast/AbstractExpr.cpp.old b/src/fil/ast/AbstractExpr.cpp.old deleted file mode 100644 index 350141b1..00000000 --- a/src/fil/ast/AbstractExpr.cpp.old +++ /dev/null @@ -1,53 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -AbstractExpr::AbstractExpr() : _is_exported(false), _expr_type(nullptr) {} - -auto AbstractExpr::decompile(int indent) const -> string { - throw; -} - -void AbstractExpr::isExported(bool exported) { - _is_exported = exported; -} - -auto AbstractExpr::isExported() const -> bool { - return _is_exported; -} - -auto AbstractExpr::isVar() const -> bool { - return false; -} - -auto AbstractExpr::isFunc() const -> bool { - return false; -} - -auto AbstractExpr::getExprType() const -> AbstractType * { - return _expr_type; -} diff --git a/src/fil/ast/AbstractLiteral.cpp.old b/src/fil/ast/AbstractLiteral.cpp.old deleted file mode 100644 index b2789ca5..00000000 --- a/src/fil/ast/AbstractLiteral.cpp.old +++ /dev/null @@ -1,27 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; diff --git a/src/fil/ast/AbstractType.cpp.old b/src/fil/ast/AbstractType.cpp.old deleted file mode 100644 index 14644664..00000000 --- a/src/fil/ast/AbstractType.cpp.old +++ /dev/null @@ -1,47 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -auto AbstractType::equals(const AbstractType &other) const -> bool { - return getName() == other.getName(); -} - -auto AbstractType::isIterable() const -> bool { - return false; -} - -auto AbstractType::getIterableType() -> AbstractType * { - return this; -} - -auto operator==(const AbstractType &first, const AbstractType &other) -> bool { - return first.equals(other); -} - -auto operator!=(const AbstractType &first, const AbstractType &other) -> bool { - return !first.equals(other); -} diff --git a/src/fil/ast/Assignation.cpp.old b/src/fil/ast/Assignation.cpp.old deleted file mode 100644 index bdb766f4..00000000 --- a/src/fil/ast/Assignation.cpp.old +++ /dev/null @@ -1,43 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -Assignation::Assignation(AbstractExpr *expr) - : _expr(expr) {} - -auto Assignation::decompile(int indent) const -> string { - return "= " + _expr->decompile(indent); -} - -auto Assignation::dump(int indent) const -> string { - string res = string(indent, '\t') + "[Assignation]" + (_is_exported ? " " : "") + - " getName() + ">\n"; - - res += _expr->dump(indent + 1); - - return res; -} diff --git a/src/fil/ast/BinaryCalcul.cpp.old b/src/fil/ast/BinaryCalcul.cpp.old deleted file mode 100644 index 226b010c..00000000 --- a/src/fil/ast/BinaryCalcul.cpp.old +++ /dev/null @@ -1,87 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -BinaryCalcul::BinaryCalcul(AbstractExpr *left, Operator *p_operator, AbstractExpr *right) - : _left(left), _op(p_operator), _right(right) {} - -auto BinaryCalcul::decompile(int indent) const -> string { - return _left->decompile(indent) + " " + _op->decompile(indent) + " " + _right->decompile(indent); -} - -//AbstractType *BinaryCalcul::inferType(Environment *env) { -// auto leftType = _left->inferType(env); -// auto rightType = _right->inferType(env); -// -// if (leftType && rightType && *leftType != *rightType) { -// ErrorsRegister::addError( -// "Type mismatch: " + leftType->getName() + " and " + rightType->getName(), -// _pos -// ); -// } -// -// switch (_op->getOp()) { -// case Operator::AND: -// case Operator::OR: -// case Operator::LESS: -// case Operator::GREATER: -// case Operator::EQEQ: -// case Operator::LEQ: -// case Operator::GEQ: -// case Operator::NEQ: -// _exprType = env->getSymbol("bool")->getSignature(); -// break; -// -// case Operator::FLEFT: -// case Operator::FRIGHT: -// _exprType = leftType; // FIXME : temporary, need to implement fil.io in stl to have corresponding types -// break; -// -// case Operator::PLUS: -// case Operator::MINUS: -// case Operator::DIV: -// case Operator::MOD: -// case Operator::STAR: -// _exprType = leftType; -// break; -// -// default: -// _exprType = leftType; -// break; -// } -// -// return _exprType; -//} - -auto BinaryCalcul::dump(int indent) const -> string { - string res = string(indent, '\t') + "[BinaryCalcul]" + (_is_exported ? " " : "") + " decompile(0) + "> " + "getName() + ">\n"; - - res += _left->dump(indent + 1); - res += _right->dump(indent + 1); - - return res; -} diff --git a/src/fil/ast/BlockBody.cpp.old b/src/fil/ast/BlockBody.cpp.old deleted file mode 100644 index 844bfb6a..00000000 --- a/src/fil/ast/BlockBody.cpp.old +++ /dev/null @@ -1,53 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -BlockBody::BlockBody(const vector &exprs) - : _exprs(exprs), _environment(nullptr) {} - -auto BlockBody::decompile(int indent) const -> string { - string result = "{\n"; - - for (auto *expr: _exprs) { - result += string(indent + 1, '\t') + expr->decompile(indent + 1) + "\n"; - } - - result += string(indent, '\t') + "}"; - - return result; -} - -auto BlockBody::dump(int indent) const -> string { - string res = string(indent, '\t') + "[BlockBody]" + (_is_exported ? " " : "") + - " getName() + ">\n"; - - for (auto *expr: _exprs) { - res += expr->dump(indent + 1); - } - - return res; -} diff --git a/src/fil/ast/BooleanLiteral.cpp.old b/src/fil/ast/BooleanLiteral.cpp.old deleted file mode 100644 index ced57f3b..00000000 --- a/src/fil/ast/BooleanLiteral.cpp.old +++ /dev/null @@ -1,41 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -BooleanLiteral::BooleanLiteral(bool value) - : _value(value) {} - -auto BooleanLiteral::decompile(int indent) const -> string { - return _value ? "true" : "false"; -} - -auto BooleanLiteral::dump(int indent) const -> string { - string res = string(indent, '\t') + "[BooleanLiteral]" + (_is_exported ? " " : "") + " \n"; -} diff --git a/src/fil/ast/CharLiteral.cpp.old b/src/fil/ast/CharLiteral.cpp.old deleted file mode 100644 index cd02e46a..00000000 --- a/src/fil/ast/CharLiteral.cpp.old +++ /dev/null @@ -1,39 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -CharLiteral::CharLiteral(const string &value) - : _value(value[1]) {} - -auto CharLiteral::decompile(int indent) const -> string { - return "'" + string(1, _value) + "'"; -} - -auto CharLiteral::dump(int indent) const -> string { - return string(indent, '\t') + "[CharLiteral]" + (_is_exported ? " " : "") + - " \n"; -} diff --git a/src/fil/ast/FloatLiteral.cpp.old b/src/fil/ast/FloatLiteral.cpp.old deleted file mode 100644 index b051549a..00000000 --- a/src/fil/ast/FloatLiteral.cpp.old +++ /dev/null @@ -1,39 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -FloatLiteral::FloatLiteral(float value) - : _value(value) {} - -auto FloatLiteral::decompile(int indent) const -> string { - return to_string(_value); -} - -auto FloatLiteral::dump(int indent) const -> string { - return string(indent, '\t') + "[FloatLiteral]" + (_is_exported ? " " : "") + - " \n"; -} diff --git a/src/fil/ast/ForI.cpp.old b/src/fil/ast/ForI.cpp.old deleted file mode 100644 index df86b008..00000000 --- a/src/fil/ast/ForI.cpp.old +++ /dev/null @@ -1,44 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -ForI::ForI(ForICondition *condition, AbstractExpr *body) - : _condition(condition), _body(body), _environment(nullptr) {} - -auto ForI::decompile(int indent) const -> string { - return "for (" + _condition->decompile(indent) + ") " + _body->decompile(indent); -} - -auto ForI::dump(int indent) const -> string { - string res = string(indent, '\t') + "[ForI]" + (_is_exported ? " " : " ") + - "getName() + ">\n"; - - res += _condition->dump(indent + 1); - res += _body->dump(indent + 1); - - return res; -} diff --git a/src/fil/ast/ForICondition.cpp.old b/src/fil/ast/ForICondition.cpp.old deleted file mode 100644 index 979e50ce..00000000 --- a/src/fil/ast/ForICondition.cpp.old +++ /dev/null @@ -1,58 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -ForICondition::ForICondition(VariableDeclaration *declaration, AbstractExpr *condition, AbstractExpr *increment) - : _declaration(declaration), _condition(condition), _increment(increment) {} - -auto ForICondition::decompile(int indent) const -> string { - return _declaration->decompile(indent) + "; " + _condition->decompile(indent) + "; " + _increment->decompile(indent); -} - -auto ForICondition::dump(int indent) const -> string { - string res = string(indent, '\t') + "[ForICondition]\n"; - - if (_declaration != nullptr) { - res += _declaration->dump(indent + 1); - } else { - res += string(indent + 1, '\t') + "_\n"; - } - - if (_condition != nullptr) { - res += _condition->dump(indent + 1); - } else { - res += string(indent + 1, '\t') + "_\n"; - } - - if (_increment != nullptr) { - res += _increment->dump(indent + 1); - } else { - res += string(indent + 1, '\t') + "_\n"; - } - - return res; -} diff --git a/src/fil/ast/ForIter.cpp.old b/src/fil/ast/ForIter.cpp.old deleted file mode 100644 index 7613a3db..00000000 --- a/src/fil/ast/ForIter.cpp.old +++ /dev/null @@ -1,44 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -ForIter::ForIter(ForIterCondition *condition, AbstractExpr *body) - : _condition(condition), _body(body), _environment(nullptr) {} - -auto ForIter::decompile(int indent) const -> string { - return "for (" + _condition->decompile(indent) + ") " + _body->decompile(indent); -} - -auto ForIter::dump(int indent) const -> string { - string res = string(indent, '\t') + "[ForIter]" + (_is_exported ? " " : " ") + - "getName() + ">\n"; - - res += _condition->dump(indent + 1); - res += _body->dump(indent + 1); - - return res; -} diff --git a/src/fil/ast/ForIterCondition.cpp.old b/src/fil/ast/ForIterCondition.cpp.old deleted file mode 100644 index 1fbe3dda..00000000 --- a/src/fil/ast/ForIterCondition.cpp.old +++ /dev/null @@ -1,43 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -ForIterCondition::ForIterCondition(bool is_val, Identifier *iterator, Identifier *iterable) - : _is_val(is_val), _iterator(iterator), _iterable(iterable), _iterator_symbol(nullptr) {} - -auto ForIterCondition::decompile(int indent) const -> string { - return (_is_val ? "val " : "var ") + _iterator->decompile(indent) + ": " + _iterable->decompile(indent); -} - -auto ForIterCondition::dump(int indent) const -> string { - string res = string(indent, '\t') + "[ForIterCondition] " + (_is_val ? "" : "") + "\n"; - - res += _iterator->dump(indent + 1); - res += _iterable->dump(indent + 1); - - return res; -} diff --git a/src/fil/ast/Function.cpp.old b/src/fil/ast/Function.cpp.old deleted file mode 100644 index 3dada003..00000000 --- a/src/fil/ast/Function.cpp.old +++ /dev/null @@ -1,51 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -Function::Function(FunctionDeclaration *declaration, AbstractExpr *body) - : _declaration(declaration), _body(body), _symbol(nullptr), _environment(nullptr) {} - -auto Function::decompile(int indent) const -> string { - return "fun " + _declaration->decompile(indent) + " " + _body->decompile(indent); -} - -auto Function::isFunc() const -> bool { - return true; -} - -auto Function::getSymbol() const -> Symbol * { - return _symbol; -} - -auto Function::dump(int indent) const -> string { - string res = string(indent, '\t') + "[Function]" + (_is_exported ? " " : " ") + "getName() + "> " + " getName() + ">\n"; - - res += _declaration->dump(indent + 1); - res += _body->dump(indent + 1); - - return res; -} diff --git a/src/fil/ast/FunctionCall.cpp.old b/src/fil/ast/FunctionCall.cpp.old deleted file mode 100644 index 2d71422d..00000000 --- a/src/fil/ast/FunctionCall.cpp.old +++ /dev/null @@ -1,58 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -FunctionCall::FunctionCall(Identifier *name, const vector &args) - : _name(name), _args(args) {} - -auto FunctionCall::decompile(int indent) const -> string { - string res = _name->decompile(indent) + "("; - for (auto it = _args.begin(); it != _args.end(); ++it) { - res += (*it)->decompile(indent); - if (it + 1 != _args.end()) { - res += ", "; - } - } - res += ")"; - - return res; -} - -auto FunctionCall::dump(int indent) const -> string { - string res = string(indent, '\t') + "[FunctionCall]" + (_is_exported ? " " : " ") + - "getName() + ">"; - if (_expr_type != nullptr) {// Problem from recursive call, see inferType - res += " getName() + ">"; - } - res += "\n"; - - for (const auto &arg: _args) { - res += arg->dump(indent + 1); - } - - return res; -} diff --git a/src/fil/ast/FunctionDeclaration.cpp.old b/src/fil/ast/FunctionDeclaration.cpp.old deleted file mode 100644 index 77226e8b..00000000 --- a/src/fil/ast/FunctionDeclaration.cpp.old +++ /dev/null @@ -1,59 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -FunctionDeclaration::FunctionDeclaration(Identifier *name, const vector ¶ms, AbstractType *type) - : _name(name), _params(params), _type(type) {} - -auto FunctionDeclaration::decompile(int indent) const -> string { - string result = _name->decompile(indent); - - result += "("; - for (auto it = _params.begin(); it != _params.end(); ++it) { - result += (*it)->decompile(indent); - if (it + 1 != _params.end()) { - result += ", "; - } - } - result += ")"; - - if (_type != nullptr) { - result += " : " + _type->decompile(indent); - } - - return result; -} - -auto FunctionDeclaration::dump(int indent) const -> string { - string res = string(indent, '\t') + "[FunctionDeclaration]" + (_is_exported ? " " : " ") + "getName() + "> " + "getName() + ">\n"; - - for (auto *param: _params) { - res += param->dump(indent + 1); - } - - return res; -} diff --git a/src/fil/ast/FunctionParam.cpp.old b/src/fil/ast/FunctionParam.cpp.old deleted file mode 100644 index f21c445c..00000000 --- a/src/fil/ast/FunctionParam.cpp.old +++ /dev/null @@ -1,44 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -FunctionParam::FunctionParam(Identifier *name, AbstractType *type) - : _name(name), _type(type) {} - -auto FunctionParam::decompile(int indent) const -> string { - string result = _name->decompile(indent); - - if (_type != nullptr) { - result += " : " + _type->decompile(indent); - } - - return result; -} - -auto FunctionParam::dump(int indent) const -> string { - return string(indent, '\t') + "[FunctionParam] getName() + "> getName() + ">\n"; -} diff --git a/src/fil/ast/Identifier.cpp.old b/src/fil/ast/Identifier.cpp.old deleted file mode 100644 index 3278ea76..00000000 --- a/src/fil/ast/Identifier.cpp.old +++ /dev/null @@ -1,45 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include - -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -Identifier::Identifier(string name) - : _name(std::move(name)), _symbol(nullptr) {} - -auto Identifier::decompile(int indent) const -> string { - return _name; -} - -auto Identifier::getName() const -> const string & { - return _name; -} - -auto Identifier::dump(int indent) const -> string { - return string(indent, '\t') + "[Identifier]" + (_is_exported ? " " : "") + - " getName() + ">\n"; -} diff --git a/src/fil/ast/If.cpp.old b/src/fil/ast/If.cpp.old deleted file mode 100644 index b49a834d..00000000 --- a/src/fil/ast/If.cpp.old +++ /dev/null @@ -1,55 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -If::If(AbstractExpr *condition, AbstractExpr *then_case, AbstractExpr *else_case) - : _condition(condition), _then(then_case), _else(else_case) {} - -auto If::decompile(int indent) const -> string { - string res = "if (" + _condition->decompile(indent) + ") " + _then->decompile(indent); - - if (_else != nullptr) { - res += " else " + _else->decompile(indent); - } - - return res; -} - -auto If::dump(int indent) const -> string { - string res = string(indent, '\t') + "[If]" + (_is_exported ? " " : " ") + - "getName() + ">\n"; - - res += _condition->dump(indent + 1); - res += string(indent, '\t') + "\n"; - res += _then->dump(indent + 1); - if (_else != nullptr) { - res += string(indent, '\t') + "\n"; - res += _else->dump(indent + 1); - } - - return res; -} diff --git a/src/fil/ast/IntegerLiteral.cpp.old b/src/fil/ast/IntegerLiteral.cpp.old deleted file mode 100644 index 93107fe1..00000000 --- a/src/fil/ast/IntegerLiteral.cpp.old +++ /dev/null @@ -1,39 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -IntegerLiteral::IntegerLiteral(int value) - : _value(value) {} - -auto IntegerLiteral::decompile(int indent) const -> string { - return to_string(_value); -} - -auto IntegerLiteral::dump(int indent) const -> string { - return string(indent, '\t') + "[IntegerLiteral]" + (_is_exported ? " " : "") + - " \n"; -} diff --git a/src/fil/ast/Lambda.cpp.old b/src/fil/ast/Lambda.cpp.old deleted file mode 100644 index ab42ee48..00000000 --- a/src/fil/ast/Lambda.cpp.old +++ /dev/null @@ -1,62 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -Lambda::Lambda(const vector ¶ms, AbstractType *type, AbstractExpr *body) - : _params(params), _type(type), _body(body), _environment(nullptr) {} - -auto Lambda::decompile(int indent) const -> string { - string res = "("; - for (auto it = _params.begin(); it != _params.end(); ++it) { - res += (*it)->decompile(indent); - if (it + 1 != _params.end()) { - res += ", "; - } - } - res += ")"; - - if (_type != nullptr) { - res += " : " + _type->decompile(indent); - } - - res += " -> " + _body->decompile(indent); - - return res; -} - -auto Lambda::dump(int indent) const -> string { - string res = string(indent, '\t') + "[Lambda]" + (_is_exported ? " " : " ") + - "getName() + ">\n"; - - for (auto *param: _params) { - res += param->dump(indent + 1); - } - - res += _body->dump(indent + 1); - - return res; -} diff --git a/src/fil/ast/LambdaType.cpp.old b/src/fil/ast/LambdaType.cpp.old deleted file mode 100644 index aa1522cb..00000000 --- a/src/fil/ast/LambdaType.cpp.old +++ /dev/null @@ -1,67 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -LambdaType::LambdaType(const vector &args, AbstractType *ret) - : _args(args), _ret(ret) {} - -auto LambdaType::decompile(int indent) const -> string { - string res = "("; - for (auto it = _args.begin(); it != _args.end(); ++it) { - res += (*it)->decompile(indent); - if (it + 1 != _args.end()) { - res += ", "; - } - } - res += ") -> " + _ret->decompile(indent); - - return res; -} - -auto LambdaType::getName() const -> string { - string res = "("; - for (auto it = _args.begin(); it != _args.end(); ++it) { - res += (*it)->getName(); - if (it + 1 != _args.end()) { - res += ", "; - } - } - - return res + ") -> " + _ret->getName(); -} - -auto LambdaType::getReturnType() const -> AbstractType * { - return _ret; -} - -auto LambdaType::getArgsTypes() const -> const vector & { - return _args; -} - -void LambdaType::setReturnType(AbstractType *ret) { - _ret = ret; -} diff --git a/src/fil/ast/Operator.cpp.old b/src/fil/ast/Operator.cpp.old deleted file mode 100644 index 0551deb5..00000000 --- a/src/fil/ast/Operator.cpp.old +++ /dev/null @@ -1,106 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -Operator::Operator(Op p_operator) - : _operator(p_operator), _index(nullptr) {} - -Operator::Operator(AbstractExpr *index) - : _operator(ARRAY), _index(index) {} - -Operator::Operator(const vector &args) - : _operator(FUNCTION), _index(nullptr), _args(args) {} - -auto toString(Operator::Op p_operator) -> string { - switch (p_operator) { - case Operator::STAR: - return "*"; - case Operator::PLUSPLUS: - return "++"; - case Operator::MINUSMINUS: - return "--"; - case Operator::REF: - return "&"; - case Operator::NOT: - return "!"; - case Operator::AND: - return "&&"; - case Operator::OR: - return "||"; - case Operator::LESS: - return "<"; - case Operator::GREATER: - return ">"; - case Operator::EQEQ: - return "=="; - case Operator::LEQ: - return "<="; - case Operator::GEQ: - return ">="; - case Operator::NEQ: - return "!="; - case Operator::FLEFT: - return "<<"; - case Operator::FRIGHT: - return ">>"; - case Operator::PLUS: - return "+"; - case Operator::MINUS: - return "-"; - case Operator::DIV: - return "/"; - case Operator::MOD: - return "%"; - case Operator::ARRAY: - return "[]"; - case Operator::FUNCTION: - return "()"; - default: - return ""; - } -} - -auto Operator::decompile(int indent) const -> string { - if (_operator == ARRAY) { - return "[" + _index->decompile(indent) + "]"; - } - if (_operator == FUNCTION) { - string args; - for (auto *arg: _args) { - args += arg->decompile(0) + ", "; - } - if (!_args.empty()) { - args.resize(args.size() - 2); - } - return "(" + args + ")"; - } - return toString(_operator); -} - -auto Operator::getOp() const -> Operator::Op { - return _operator; -} diff --git a/src/fil/ast/ParenthesisBody.cpp.old b/src/fil/ast/ParenthesisBody.cpp.old deleted file mode 100644 index 740fca17..00000000 --- a/src/fil/ast/ParenthesisBody.cpp.old +++ /dev/null @@ -1,43 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -ParenthesisBody::ParenthesisBody(AbstractExpr *expr) - : _expr(expr) {} - -auto ParenthesisBody::decompile(int indent) const -> string { - return "(" + _expr->decompile(indent) + ")"; -} - -auto ParenthesisBody::dump(int indent) const -> string { - string res = string(indent, '\t') + "[ParenthesisBody]" + (_is_exported ? " " : "") + - " getName() + ">\n"; - - res += _expr->dump(indent + 1); - - return res; -} diff --git a/src/fil/ast/Program.cpp.old b/src/fil/ast/Program.cpp.old deleted file mode 100644 index 069dfdee..00000000 --- a/src/fil/ast/Program.cpp.old +++ /dev/null @@ -1,105 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include - -#include "AST.hpp.old" -#include "FilCompiler.h" - -using namespace std; -using namespace ast; - -Program::Program(string module, - const vector &imports, - const vector &exprs) - : _module(std::move(module)), _imports(imports), _exprs(exprs), _environment(nullptr), _resolved(false) {} - -auto Program::decompile(int indent) const -> string { - string result = "module " + _module + "\n"; - - if (!_imports.empty()) { - result += "\n"; - } - for (const auto &import: _imports) { - result += "use " + import + "\n"; - } - - if (!_exprs.empty()) { - result += "\n"; - } - for (auto it = _exprs.begin(); it != _exprs.end(); it++) { - result += ((*it)->isExported() ? "export " : "") + (*it)->decompile(indent) + "\n"; - - if (it + 1 != _exprs.end()) { - result += "\n"; - } - } - - return result; -} - -void Program::resolveEnvironment() { - if (_resolved) {// Fix infinite loop of resolve - return; - } - _resolved = true; - - // Remove duplicate imports - sort(_imports.begin(), _imports.end()); - _imports.erase(unique(_imports.begin(), _imports.end()), _imports.end()); - - // Resolve imports - for (auto &import: _imports) { - auto *module = FilCompiler::getModule(import); - if (module == nullptr) { - ErrorsRegister::addWarning( - new BasicWarning("\033[1mDev code 2\033[21m\nModule '" + import + "' not found")); - continue; - } - - module->resolveEnvironment(); - _imported_modules.push_back(module); - } - - // TODO : merge imports env to _environment - - // TODO : resolve exprs -} - -auto Program::dump(int indent) const -> string { - string res = string(indent, '\t') + "[Program] \n"; - - for (const auto &imp: _imported_modules) { - res += imp->dump(indent + 1); - } - - for (const auto &expr: _exprs) { - res += expr->dump(indent + 1); - } - - return res; -} - -void Program::setEnvironment(Environment *environment) { - _environment = environment; -} diff --git a/src/fil/ast/StringLiteral.cpp.old b/src/fil/ast/StringLiteral.cpp.old deleted file mode 100644 index de762856..00000000 --- a/src/fil/ast/StringLiteral.cpp.old +++ /dev/null @@ -1,40 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -StringLiteral::StringLiteral(const std::string &value) { - _value = value.substr(1, value.size() - 2); -} - -auto StringLiteral::decompile(int indent) const -> string { - return "\"" + _value + "\""; -} - -auto StringLiteral::dump(int indent) const -> string { - return string(indent, '\t') + "[StringLiteral]" + (_is_exported ? " " : "") + - " \n"; -} diff --git a/src/fil/ast/Switch.cpp.old b/src/fil/ast/Switch.cpp.old deleted file mode 100644 index 0796ecd0..00000000 --- a/src/fil/ast/Switch.cpp.old +++ /dev/null @@ -1,55 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -Switch::Switch(AbstractExpr *condition, const vector &cases) - : _condition(condition), _cases(cases) {} - -auto Switch::decompile(int indent) const -> string { - string res = "switch (" + _condition->decompile(indent) + ") {\n"; - - for (const auto ¤t_case: _cases) { - res += string(indent + 1, '\t') + current_case->decompile(indent); - } - - res += "}"; - - return res; -} - -auto Switch::dump(int indent) const -> string { - string res = string(indent, '\t') + "[Switch]" + (_is_exported ? " " : " ") + - "getName() + ">\n"; - - res += _condition->dump(indent + 1); - - for (const auto ¤t_case: _cases) { - res += current_case->dump(indent + 1); - } - - return res; -} diff --git a/src/fil/ast/SwitchCase.cpp.old b/src/fil/ast/SwitchCase.cpp.old deleted file mode 100644 index b178d481..00000000 --- a/src/fil/ast/SwitchCase.cpp.old +++ /dev/null @@ -1,44 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -SwitchCase::SwitchCase(SwitchPattern *pattern, AbstractExpr *body) - : _pattern(pattern), _body(body) {} - -auto SwitchCase::decompile(int indent) const -> string { - return _pattern->decompile(indent) + " -> " + _body->decompile(indent) + "\n"; -} - -auto SwitchCase::dump(int indent) const -> string { - string res = string(indent, '\t') + "[SwitchCase]" + (_is_exported ? " " : " ") + - "getName() + ">\n"; - - res += _pattern->dump(indent + 1); - res += _body->dump(indent + 1); - - return res; -} diff --git a/src/fil/ast/SwitchPattern.cpp.old b/src/fil/ast/SwitchPattern.cpp.old deleted file mode 100644 index 4cefe51f..00000000 --- a/src/fil/ast/SwitchPattern.cpp.old +++ /dev/null @@ -1,56 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -SwitchPattern::SwitchPattern() - : _is_default(true), _literal(nullptr) {} - -SwitchPattern::SwitchPattern(AbstractLiteral *literal) - : _is_default(false), _literal(literal) {} - -auto SwitchPattern::decompile(int indent) const -> string { - return _is_default ? "default" : _literal->decompile(indent); -} - -auto SwitchPattern::getLiteral() const -> AbstractLiteral * { - return _literal; -} - -auto SwitchPattern::dump(int indent) const -> string { - if (_is_default) { - return string(indent, '\t') + "[SwitchPattern] \n"; - } - string res = string(indent, '\t') + "[SwitchPattern]\n"; - - res += _literal->dump(indent + 1); - - return res; -} - -auto SwitchPattern::isDefault() const -> bool { - return _is_default; -} diff --git a/src/fil/ast/Type.cpp.old b/src/fil/ast/Type.cpp.old deleted file mode 100644 index 44be68a8..00000000 --- a/src/fil/ast/Type.cpp.old +++ /dev/null @@ -1,64 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -Type::Type(Identifier *name) - : _name(name), _is_array(false), _array_size(0), _is_pointer(false), _sub_type(nullptr) {} - -Type::Type(int array_size, AbstractType *sub_type) - : _name(nullptr), _is_array(true), _array_size(array_size), _is_pointer(false), _sub_type(sub_type) {} - -Type::Type(AbstractType *sub_type) - : _name(nullptr), _is_array(false), _array_size(0), _is_pointer(true), _sub_type(sub_type) {} - -auto Type::decompile(int indent) const -> string { - if (_is_pointer) { - return _sub_type->decompile(indent) + "*"; - } - if (_is_array) { - return _sub_type->decompile(indent) + "[" + to_string(_array_size) + "]"; - } - return _name->decompile(indent); -} - -auto Type::getName() const -> string { - if (_is_pointer) { - return _sub_type->getName() + "*"; - } - if (_is_array) { - return _sub_type->getName() + "[" + to_string(_array_size) + "]"; - } - return _name->getName(); -} - -auto Type::isIterable() const -> bool { - return _is_array; -} - -auto Type::getIterableType() -> AbstractType * { - return isIterable() ? _sub_type : AbstractType::getIterableType(); -} diff --git a/src/fil/ast/UnaryCalcul.cpp.old b/src/fil/ast/UnaryCalcul.cpp.old deleted file mode 100644 index 9ef00a00..00000000 --- a/src/fil/ast/UnaryCalcul.cpp.old +++ /dev/null @@ -1,48 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -UnaryCalcul::UnaryCalcul(Identifier *identifier, Operator *p_operator) - : _operator(p_operator), _identifier(identifier), _is_prefix(false) {} - -UnaryCalcul::UnaryCalcul(Operator *p_operator, Identifier *identifier) - : _operator(p_operator), _identifier(identifier), _is_prefix(true) {} - -auto UnaryCalcul::decompile(int indent) const -> std::string { - if (_is_prefix) { - return _operator->decompile(indent) + _identifier->decompile(indent); - } - return _identifier->decompile(indent) + _operator->decompile(indent); -} - -auto UnaryCalcul::dump(int indent) const -> string { - string res = string(indent, '\t') + "[UnaryCalcul]" + (_is_exported ? " " : " ") + (_is_prefix ? "" : "") + " decompile(indent) + ">" + " getName() + ">\n"; - - res += _identifier->dump(indent + 1); - - return res; -} diff --git a/src/fil/ast/VariableDeclaration.cpp.old b/src/fil/ast/VariableDeclaration.cpp.old deleted file mode 100644 index 51df82c3..00000000 --- a/src/fil/ast/VariableDeclaration.cpp.old +++ /dev/null @@ -1,62 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -VariableDeclaration::VariableDeclaration(bool is_val, Identifier *name, AbstractType *type, Assignation *assignation) - : _is_val(is_val), _name(name), _type(type), _assignation(assignation), _symbol(nullptr) {} - -auto VariableDeclaration::decompile(int indent) const -> string { - string result = (_is_val ? "val " : "var ") + _name->decompile(indent); - - if (_type != nullptr) { - result += " : " + _type->decompile(indent); - } - - if (_assignation != nullptr) { - result += " " + _assignation->decompile(indent); - } - - return result; -} - -auto VariableDeclaration::isVar() const -> bool { - return true; -} - -auto VariableDeclaration::getSymbol() const -> Symbol * { - return _symbol; -} - -auto VariableDeclaration::dump(int indent) const -> string { - string res = string(indent, '\t') + "[VariableDeclaration]" + (_is_exported ? " " : " ") + (_is_val ? " " : " ") + "getName() + "> " + "getName() + ">\n"; - - if (_assignation != nullptr) { - res += _assignation->dump(indent + 1); - } - - return res; -} diff --git a/src/fil/ast/While.cpp.old b/src/fil/ast/While.cpp.old deleted file mode 100644 index 3f6b8d9d..00000000 --- a/src/fil/ast/While.cpp.old +++ /dev/null @@ -1,44 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp.old" - -using namespace std; -using namespace ast; - -While::While(AbstractExpr *condition, AbstractExpr *body) - : _condition(condition), _body(body), _environment(nullptr) {} - -auto While::decompile(int indent) const -> string { - return "while (" + _condition->decompile(indent) + ") " + _body->decompile(indent); -} - -auto While::dump(int indent) const -> string { - string res = string(indent, '\t') + "[While]" + (_is_exported ? " " : " ") + - "getName() + ">\n"; - - res += _condition->dump(indent + 1); - res += _body->dump(indent + 1); - - return res; -} diff --git a/src/fil/environment/Environment.cpp.old b/src/fil/environment/Environment.cpp.old deleted file mode 100644 index 9b57f2f9..00000000 --- a/src/fil/environment/Environment.cpp.old +++ /dev/null @@ -1,287 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "AST.hpp" -#include "Environment.h.old" - -using namespace std; -using namespace ast; - -Environment::Environment(Environment *parent) - : _parent(parent), _symbols(deque()) {} - -Environment::~Environment() = default; - -Environment *Environment::getGlobalEnvironment() { - static auto *globalEnvironment = new Environment(); - static bool initialized = false; - - if (initialized) - return globalEnvironment; - initialized = true; - - // Add builtins types - auto tInt = globalEnvironment->addSymbol("int", new Position(0, 0, "builtin"), Symbol::SymbolKind::TYPE) - ->setSignature(new Type(new Identifier("int"))); - auto tFloat = globalEnvironment->addSymbol("float", new Position(0, 0, "builtin"), Symbol::SymbolKind::TYPE) - ->setSignature(new Type(new Identifier("float"))); - auto tChar = globalEnvironment->addSymbol("char", new Position(0, 0, "builtin"), Symbol::SymbolKind::TYPE) - ->setSignature(new Type(new Identifier("char"))); - auto tBool = globalEnvironment->addSymbol("bool", new Position(0, 0, "builtin"), Symbol::SymbolKind::TYPE) - ->setSignature(new Type(new Identifier("bool"))); - globalEnvironment->addSymbol("void", new Position(0, 0, "builtin"), Symbol::SymbolKind::TYPE) - ->setSignature(new Type(new Identifier("void"))); - - // Add builtins operators - globalEnvironment->addSymbol("operator+", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tInt}, tInt)); - globalEnvironment->addSymbol("operator+", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator+", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tChar}, tChar)); - globalEnvironment->addSymbol("operator+", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator+", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tInt}, tFloat)); - globalEnvironment->addSymbol("operator+", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tInt}, tInt)); - globalEnvironment->addSymbol("operator+", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tChar}, tInt)); - globalEnvironment->addSymbol("operator+", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator+", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tChar}, tFloat)); - globalEnvironment->addSymbol("operator-", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tInt}, tInt)); - globalEnvironment->addSymbol("operator-", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator-", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tChar}, tChar)); - globalEnvironment->addSymbol("operator-", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator-", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tInt}, tFloat)); - globalEnvironment->addSymbol("operator-", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tInt}, tInt)); - globalEnvironment->addSymbol("operator-", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tChar}, tInt)); - globalEnvironment->addSymbol("operator-", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator-", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tChar}, tFloat)); - globalEnvironment->addSymbol("operator*", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tInt}, tInt)); - globalEnvironment->addSymbol("operator*", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator*", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tChar}, tChar)); - globalEnvironment->addSymbol("operator*", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator*", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tInt}, tFloat)); - globalEnvironment->addSymbol("operator*", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tInt}, tInt)); - globalEnvironment->addSymbol("operator*", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tChar}, tInt)); - globalEnvironment->addSymbol("operator*", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator*", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tChar}, tFloat)); - globalEnvironment->addSymbol("operator/", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tInt}, tInt)); - globalEnvironment->addSymbol("operator/", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator/", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tChar}, tChar)); - globalEnvironment->addSymbol("operator/", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator/", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tInt}, tFloat)); - globalEnvironment->addSymbol("operator/", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tInt}, tInt)); - globalEnvironment->addSymbol("operator/", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tChar}, tInt)); - globalEnvironment->addSymbol("operator/", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tFloat}, tFloat)); - globalEnvironment->addSymbol("operator/", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tChar}, tFloat)); - globalEnvironment->addSymbol("operator%", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tInt}, tInt)); - globalEnvironment->addSymbol("operator%", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tInt}, tInt)); - globalEnvironment->addSymbol("operator%", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tInt}, tInt)); - globalEnvironment->addSymbol("operator++", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt}, tInt)); - globalEnvironment->addSymbol("operator++", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat}, tFloat)); - globalEnvironment->addSymbol("operator++", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar}, tChar)); - globalEnvironment->addSymbol("operator--", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt}, tInt)); - globalEnvironment->addSymbol("operator--", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat}, tFloat)); - globalEnvironment->addSymbol("operator--", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar}, tChar)); - globalEnvironment->addSymbol("operator==", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tInt}, tBool)); - globalEnvironment->addSymbol("operator==", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tFloat}, tBool)); - globalEnvironment->addSymbol("operator==", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tChar}, tBool)); - globalEnvironment->addSymbol("operator==", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tBool, tBool}, tBool)); - globalEnvironment->addSymbol("operator==", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tInt}, tBool)); - globalEnvironment->addSymbol("operator==", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tChar}, tBool)); - globalEnvironment->addSymbol("operator!=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tInt}, tBool)); - globalEnvironment->addSymbol("operator!=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tFloat}, tBool)); - globalEnvironment->addSymbol("operator!=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tChar}, tBool)); - globalEnvironment->addSymbol("operator!=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tBool, tBool}, tBool)); - globalEnvironment->addSymbol("operator!=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tInt}, tBool)); - globalEnvironment->addSymbol("operator!=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tChar}, tBool)); - globalEnvironment->addSymbol("operator>", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tInt}, tBool)); - globalEnvironment->addSymbol("operator>", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tFloat}, tBool)); - globalEnvironment->addSymbol("operator>", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tChar}, tBool)); - globalEnvironment->addSymbol("operator>", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tInt}, tBool)); - globalEnvironment->addSymbol("operator>", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tChar}, tBool)); - globalEnvironment->addSymbol("operator>=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tInt}, tBool)); - globalEnvironment->addSymbol("operator>=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tFloat}, tBool)); - globalEnvironment->addSymbol("operator>=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tChar}, tBool)); - globalEnvironment->addSymbol("operator>=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tInt}, tBool)); - globalEnvironment->addSymbol("operator>=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tChar}, tBool)); - globalEnvironment->addSymbol("operator<", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tInt}, tBool)); - globalEnvironment->addSymbol("operator<", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tFloat}, tBool)); - globalEnvironment->addSymbol("operator<", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tChar}, tBool)); - globalEnvironment->addSymbol("operator<", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tInt}, tBool)); - globalEnvironment->addSymbol("operator<", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tChar}, tBool)); - globalEnvironment->addSymbol("operator<=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tInt}, tBool)); - globalEnvironment->addSymbol("operator<=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tFloat, tFloat}, tBool)); - globalEnvironment->addSymbol("operator<=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tChar}, tBool)); - globalEnvironment->addSymbol("operator<=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tChar, tInt}, tBool)); - globalEnvironment->addSymbol("operator<=", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tInt, tChar}, tBool)); - globalEnvironment->addSymbol("operator!", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tBool}, tBool)); - globalEnvironment->addSymbol("operator&&", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tBool, tBool}, tBool)); - globalEnvironment->addSymbol("operator||", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tBool, tBool}, tBool)); - - // FIXME : temporary, to be removed later as string is part of stl - auto tString = globalEnvironment->addSymbol("String", new Position(0, 0, "builtin"), Symbol::SymbolKind::TYPE) - ->setSignature(new Type(new Identifier("String"))); - globalEnvironment->addSymbol("operator+", new Position(0, 0, "builtin"), Symbol::SymbolKind::FUNCTION) - ->setSignature(new LambdaType({tString, tString}, tString)); - // FIXME : end of fixme - - return globalEnvironment; -} - -Symbol *Environment::addSymbol(const std::string &name, Position *position, Symbol::SymbolKind type) { - auto *symbol = new Symbol(name, position, type); - _symbols.push_back(symbol); - - return symbol; -} - -bool Environment::hasSymbol(const std::string &name, ast::AbstractType *signature) { - if (std::any_of(_symbols.begin(), _symbols.end(), [name, signature](Symbol *symbol) { - if (signature == nullptr) - return symbol->getName() == name; - else - return symbol->getName() == name && symbol->getSignature() == signature; - })) { - return true; - } - - if (_parent != nullptr) { - return _parent->hasSymbol(name, signature); - } - - return false; -} - -Symbol *Environment::getSymbol(const std::string &name, ast::AbstractType *signature) { - auto it = std::find_if(_symbols.begin(), _symbols.end(), [name, signature](Symbol *symbol) { - if (signature == nullptr) - return symbol->getName() == name; - else - return symbol->getName() == name && symbol->getSignature() == signature; - }); - - if (it != _symbols.end()) { - return *it; - } - - if (_parent != nullptr) { - return _parent->getSymbol(name, signature); - } - - return nullptr; -} - -std::deque Environment::getSymbols(const std::string &name) { - std::deque symbols; - - std::copy_if(_symbols.begin(), _symbols.end(), std::back_inserter(symbols), [name](Symbol *symbol) { - return symbol->getName() == name; - }); - - if (_parent != nullptr) { - auto parentSymbols = _parent->getSymbols(name); - symbols.insert(symbols.end(), parentSymbols.begin(), parentSymbols.end()); - } - - return symbols; -} - -void Environment::setParent(Environment *parent) { - _parent = parent; -} diff --git a/src/fil/environment/Environment.h.old b/src/fil/environment/Environment.h.old deleted file mode 100644 index 931548d1..00000000 --- a/src/fil/environment/Environment.h.old +++ /dev/null @@ -1,53 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef FILC_ENVIRONMENT_H -#define FILC_ENVIRONMENT_H - -#include "Symbol.h.old" -#include - -class Environment { -public: - explicit Environment(Environment *parent = nullptr); - - ~Environment(); - - static auto getGlobalEnvironment() -> Environment *; - - auto addSymbol(const std::string &name, Position *position, Symbol::SymbolKind type) -> Symbol *; - - auto hasSymbol(const std::string &name, ast::AbstractType *signature = nullptr) -> bool; - - auto getSymbol(const std::string &name, ast::AbstractType *signature = nullptr) -> Symbol *; - - auto getSymbols(const std::string &name) -> std::deque; - - void setParent(Environment *parent); - -private: - Environment *_parent; - std::deque _symbols; -}; - -#endif//FILC_ENVIRONMENT_H diff --git a/src/fil/environment/Symbol.cpp.old b/src/fil/environment/Symbol.cpp.old deleted file mode 100644 index a70dabf6..00000000 --- a/src/fil/environment/Symbol.cpp.old +++ /dev/null @@ -1,68 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "Symbol.h.old" - -#include - -using namespace std; -using namespace ast; - -Symbol::Symbol(string name, Position *position, SymbolKind kind) - : _name(std::move(name)), _position(position), _kind(kind), _signature(nullptr) {} - -Symbol::~Symbol() { - delete _position; -} - -auto Symbol::getName() const -> std::string { - return _name; -} - -auto Symbol::getPosition() const -> Position * { - return _position; -} - -auto Symbol::getKind() const -> Symbol::SymbolKind { - return _kind; -} - -auto Symbol::getSignature() const -> ast::AbstractType * { - return _signature; -} - -auto Symbol::setSignature(AbstractType *signature) -> AbstractType * { - _signature = signature; - - return _signature; -} - -auto Symbol::operator==(const Symbol &other) const -> bool { - return _name == other._name && - _kind == other._kind && - _signature == other._signature; -} - -auto Symbol::operator!=(const Symbol &other) const -> bool { - return !(other == *this); -} diff --git a/src/fil/environment/Symbol.h.old b/src/fil/environment/Symbol.h.old deleted file mode 100644 index 9751df0d..00000000 --- a/src/fil/environment/Symbol.h.old +++ /dev/null @@ -1,64 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef FILC_SYMBOL_H -#define FILC_SYMBOL_H - -#include "AST_decl.h" -#include "utils.h" -#include - -class Symbol { -public: - enum SymbolKind { - FUNCTION, - VARIABLE, - TYPE - }; - - Symbol(std::string name, Position *position, SymbolKind kind); - - ~Symbol(); - - [[nodiscard]] auto getName() const -> std::string; - - [[nodiscard]] auto getPosition() const -> Position *; - - [[nodiscard]] auto getKind() const -> SymbolKind; - - [[nodiscard]] auto getSignature() const -> ast::AbstractType *; - - auto setSignature(ast::AbstractType *signature) -> ast::AbstractType *; - - auto operator==(const Symbol &other) const -> bool; - - auto operator!=(const Symbol &other) const -> bool; - -private: - std::string _name; - Position *_position; - SymbolKind _kind; - ast::AbstractType *_signature; -}; - -#endif//FILC_SYMBOL_H diff --git a/src/fil/errors/ErrorsRegister.cpp.old b/src/fil/errors/ErrorsRegister.cpp.old deleted file mode 100644 index 4ea51793..00000000 --- a/src/fil/errors/ErrorsRegister.cpp.old +++ /dev/null @@ -1,70 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "ErrorsRegister.h.old" - -ErrorsRegister *ErrorsRegister::_instance = nullptr; - -ErrorsRegister::ErrorsRegister() {} - -void ErrorsRegister::init() { - if (_instance == nullptr) { - _instance = new ErrorsRegister(); - } -} - -void ErrorsRegister::clean() { - if (_instance != nullptr) { - _instance->_messages.clear(); - } -} - -auto ErrorsRegister::containsError() -> bool { - return _instance != nullptr && _instance->_contains_error; -} - -auto ErrorsRegister::containsWarning() -> bool { - return _instance != nullptr && _instance->_contains_warning; -} - -void ErrorsRegister::addWarning(Message *message) { - if (_instance != nullptr) { - _instance->_messages.push_back(message); - _instance->_contains_warning = true; - } -} - -void ErrorsRegister::addError(Message *message) { - if (_instance != nullptr) { - _instance->_messages.push_back(message); - _instance->_contains_error = true; - } -} - -void ErrorsRegister::dump(std::ostream &out) { - if (_instance != nullptr) { - for (auto &message: _instance->_messages) { - out << message->dump() << std::endl; - } - } -} diff --git a/src/fil/errors/ErrorsRegister.h.old b/src/fil/errors/ErrorsRegister.h.old deleted file mode 100644 index 91d6da31..00000000 --- a/src/fil/errors/ErrorsRegister.h.old +++ /dev/null @@ -1,58 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef FILC_ERRORSREGISTER_H -#define FILC_ERRORSREGISTER_H - -#include "Message.h.old" -#include -#include - -class ErrorsRegister { -private: - static ErrorsRegister *_instance; - - ErrorsRegister(); - -public: - static void init(); - - static void clean(); - - static auto containsError() -> bool; - - static auto containsWarning() -> bool; - - static void addWarning(Message *message); - - static void addError(Message *message); - - static void dump(std::ostream &out); - -private: - bool _contains_error = false; - bool _contains_warning = false; - std::vector _messages; -}; - -#endif//FILC_ERRORSREGISTER_H diff --git a/src/fil/errors/LexerErrorListener.cpp.old b/src/fil/errors/LexerErrorListener.cpp.old deleted file mode 100644 index 19375201..00000000 --- a/src/fil/errors/LexerErrorListener.cpp.old +++ /dev/null @@ -1,36 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "ErrorsRegister.h.old" -#include "LexerErrorListener.h.old" - -using namespace std; - -void LexerErrorListener::syntaxError(antlr4::Recognizer *recognizer, antlr4::Token *offending_symbol, size_t line, - size_t char_position_in_line, const std::string &msg, std::exception_ptr exception_ptr) { - ErrorsRegister::addError(new Error( - msg, - new Position((int) line, (int) char_position_in_line, - recognizer->getInputStream()->getSourceName()) - )); -} diff --git a/src/fil/errors/LexerErrorListener.h.old b/src/fil/errors/LexerErrorListener.h.old deleted file mode 100644 index 2012be67..00000000 --- a/src/fil/errors/LexerErrorListener.h.old +++ /dev/null @@ -1,38 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef FILC_LEXERERRORLISTENER_H -#define FILC_LEXERERRORLISTENER_H - -#include "antlr4-runtime.h" - -class LexerErrorListener : public antlr4::BaseErrorListener { - void syntaxError(antlr4::Recognizer *recognizer, - antlr4::Token *offending_symbol, - size_t line, - size_t char_position_in_line, - const std::string &msg, - std::exception_ptr exception_ptr) override; -}; - -#endif//FILC_LEXERERRORLISTENER_H diff --git a/src/fil/errors/Message.cpp.old b/src/fil/errors/Message.cpp.old deleted file mode 100644 index 3773986a..00000000 --- a/src/fil/errors/Message.cpp.old +++ /dev/null @@ -1,73 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "Message.h.old" - -#include - -auto printMessage(const std::string &message, - Position *position, - const std::string &type, - const std::string &color) -> std::string { - static const std::string RESET = "\033[0m"; - - std::string res = color + type + ": " + RESET + message + "\n " + position->dump() + "\n\n"; - - std::string nth = " " + std::to_string(position->getLine()) + " "; - - res += nth + "|" + position->getLineContent() + "\n"; - res += std::string(nth.length(), ' ') + "|"; - std::string spaces = position->getColumn() > 0 ? std::string(position->getColumn() - 1, ' ') : ""; - res += spaces + color + "^" + RESET + "\n"; - - return res; -} - -// _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-. - -Message::Message(std::string message, Position *position) - : _message(std::move(message)), _position(position) {} - -BasicWarning::BasicWarning(const std::string &message) : Message(message, nullptr) {} - -auto BasicWarning::dump() const -> std::string { - return "\033[1;33mWARNING: " + _message + "\033[0m\n"; -} - -Warning::Warning(const std::string &message, Position *position) : Message(message, position) {} - -auto Warning::dump() const -> std::string { - return printMessage(_message, _position, "WARNING", "\033[1;33m"); -} - -BasicError::BasicError(const std::string &message) : Message(message, nullptr) {} - -auto BasicError::dump() const -> std::string { - return "\033[1;31mERROR: " + _message + "\033[0m\n"; -} - -Error::Error(const std::string &message, Position *position) : Message(message, position) {} - -auto Error::dump() const -> std::string { - return printMessage(_message, _position, "ERROR", "\033[1;31m"); -} diff --git a/src/fil/errors/Message.h.old b/src/fil/errors/Message.h.old deleted file mode 100644 index 1e02c477..00000000 --- a/src/fil/errors/Message.h.old +++ /dev/null @@ -1,72 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef FILC_MESSAGE_H -#define FILC_MESSAGE_H - -#include "utils.h" -#include - -class Message { -protected: - Message(std::string message, Position *position); - -public: - virtual ~Message() = default; - - [[nodiscard]] virtual auto dump() const -> std::string = 0; - -protected: - std::string _message; - Position *_position; -}; - -class BasicWarning : public Message { -public: - explicit BasicWarning(const std::string &message); - - [[nodiscard]] auto dump() const -> std::string override; -}; - -class Warning : public Message { -public: - Warning(const std::string &message, Position *position); - - [[nodiscard]] auto dump() const -> std::string override; -}; - -class BasicError : public Message { -public: - explicit BasicError(const std::string &message); - - [[nodiscard]] auto dump() const -> std::string override; -}; - -class Error : public Message { -public: - Error(const std::string &message, Position *position); - - [[nodiscard]] auto dump() const -> std::string override; -}; - -#endif//FILC_MESSAGE_H diff --git a/src/fil/errors/ParserErrorListener.cpp.old b/src/fil/errors/ParserErrorListener.cpp.old deleted file mode 100644 index 4d5b9c15..00000000 --- a/src/fil/errors/ParserErrorListener.cpp.old +++ /dev/null @@ -1,35 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "ErrorsRegister.h.old" -#include "ParserErrorListener.h.old" - -using namespace std; - -void ParserErrorListener::syntaxError(antlr4::Recognizer *recognizer, antlr4::Token *offending_symbol, size_t line, - size_t char_position_in_line, const string &msg, exception_ptr exception_ptr) { - ErrorsRegister::addError(new Error( - msg, - new Position((int) line, (int) char_position_in_line, - recognizer->getInputStream()->getSourceName()))); -} diff --git a/src/fil/errors/ParserErrorListener.h.old b/src/fil/errors/ParserErrorListener.h.old deleted file mode 100644 index 246ac890..00000000 --- a/src/fil/errors/ParserErrorListener.h.old +++ /dev/null @@ -1,38 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-Present Kevin Traini - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef FILC_PARSERERRORLISTENER_H -#define FILC_PARSERERRORLISTENER_H - -#include "antlr4-runtime.h" - -class ParserErrorListener : public antlr4::BaseErrorListener { - void syntaxError(antlr4::Recognizer *recognizer, - antlr4::Token *offending_symbol, - size_t line, - size_t char_position_in_line, - const std::string &msg, - std::exception_ptr exception_ptr) override; -}; - -#endif//FILC_PARSERERRORLISTENER_H