Skip to content

Commit

Permalink
refactor: remove unused union statement
Browse files Browse the repository at this point in the history
  • Loading branch information
JaDogg committed May 27, 2024
1 parent ba284c9 commit 5e6d605
Show file tree
Hide file tree
Showing 27 changed files with 535 additions and 555 deletions.
2 changes: 0 additions & 2 deletions compiler/scripts/update_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@
"def": "name_",
"class": "name_",
"enum": "name_",
"union": "name_",
"import": "import_token_",
"runtimefeature": "runtimefeature_token_",
"compins": "name_",
Expand Down Expand Up @@ -223,7 +222,6 @@
("stmt*", "function_body"), ("ykdatatype*", "return_type"), ("annotations", "annotations"))),
("class", (("token*", "name"), ("std::vector<parameter>", "members"), ("annotations", "annotations"))),
("enum", (("token*", "name"), ("std::vector<parameter>", "members"), ("annotations", "annotations"))),
("union", (("token*", "name"), ("std::vector<parameter>", "members"), ("annotations", "annotations"))),
# import io [as io]
("import", (("token*", "import_token"), ("std::vector<token*>", "import_names"),
("token*", "name"), ("file_info*", "data"))),
Expand Down
2 changes: 1 addition & 1 deletion compiler/scripts/update_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"and", "continue", "for", "try",
"as", "def", "from", "while",
"assert", "del", "not",
"elif", "if", "or", "defer", "ccode", "runtimefeature", "in", "struct", "macros", "directive"])
"elif", "if", "or", "defer", "ccode", "runtimefeature", "in", "struct", "macros", "directive", "enum"])
TOKENS = sorted([
"NAME", "AT", "DOUBLE_NUMBER", "FLOAT_NUMBER", "INDENT", "BA_INDENT", "BA_DEDENT", "NEW_LINE", "COLON", "SEMICOLON",
"COMMENT",
Expand Down
872 changes: 479 additions & 393 deletions compiler/src/ast/ast.cpp

Large diffs are not rendered by default.

53 changes: 0 additions & 53 deletions compiler/src/ast/ast.h
Original file line number Diff line number Diff line change
@@ -1,41 +1,3 @@
// ==============================================================================================
// ╦ ┬┌─┐┌─┐┌┐┌┌─┐┌─┐ Yaksha Programming Language
// ║ ││ ├┤ │││└─┐├┤ is Licensed with GPLv3 + extra terms. Please see below.
// ╩═╝┴└─┘└─┘┘└┘└─┘└─┘
// Note: libs - MIT license, runtime/3rd - various
// ==============================================================================================
// GPLv3:
//
// Yaksha - Programming Language.
// Copyright (C) 2020 - 2024 Bhathiya Perera
//
// This program is free software: you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with this program.
// If not, see https://www.gnu.org/licenses/.
//
// ==============================================================================================
// Additional Terms:
//
// Please note that any commercial use of the programming language's compiler source code
// (everything except compiler/runtime, compiler/libs and compiler/3rd) require a written agreement
// with author of the language (Bhathiya Perera).
//
// If you are using it for an open source project, please give credits.
// Your own project must use GPLv3 license with these additional terms.
//
// You may use programs written in Yaksha/YakshaLisp for any legal purpose
// (commercial, open-source, closed-source, etc) as long as it agrees
// to the licenses of linked runtime libraries (see compiler/runtime/README.md).
//
// ==============================================================================================
// ast.h
// generated by update_ast.py
#ifndef AST_H
Expand Down Expand Up @@ -93,7 +55,6 @@ namespace yaksha {
struct return_stmt;
struct runtimefeature_stmt;
struct token_soup_stmt;
struct union_stmt;
struct while_stmt;
// Types of expressions and statements
enum class ast_type {
Expand Down Expand Up @@ -140,7 +101,6 @@ namespace yaksha {
STMT_RETURN,
STMT_RUNTIMEFEATURE,
STMT_TOKEN_SOUP,
STMT_UNION,
STMT_WHILE
};
// ------ expression visitor ------
Expand Down Expand Up @@ -190,7 +150,6 @@ namespace yaksha {
virtual void visit_pass_stmt(pass_stmt *obj) = 0;
virtual void visit_return_stmt(return_stmt *obj) = 0;
virtual void visit_runtimefeature_stmt(runtimefeature_stmt *obj) = 0;
virtual void visit_union_stmt(union_stmt *obj) = 0;
virtual void visit_while_stmt(while_stmt *obj) = 0;
virtual ~stmt_visitor() = default;
};
Expand Down Expand Up @@ -629,16 +588,6 @@ namespace yaksha {
token *locate() override;
std::vector<token *> soup_;
};
struct union_stmt : stmt {
union_stmt(token *name, std::vector<parameter> members,
annotations annotations);
void accept(stmt_visitor *v) override;
ast_type get_type() override;
token *locate() override;
token *name_;
std::vector<parameter> members_;
annotations annotations_;
};
struct while_stmt : stmt {
while_stmt(token *while_keyword, expr *expression, stmt *while_body);
void accept(stmt_visitor *v) override;
Expand Down Expand Up @@ -725,8 +674,6 @@ namespace yaksha {
ykdatatype *result_type);
stmt *c_runtimefeature_stmt(token *runtimefeature_token, token *feature);
stmt *c_token_soup_stmt(std::vector<token *> soup);
stmt *c_union_stmt(token *name, std::vector<parameter> members,
annotations annotations);
stmt *c_while_stmt(token *while_keyword, expr *expression,
stmt *while_body);

Expand Down
1 change: 0 additions & 1 deletion compiler/src/ast/ast_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,4 @@ void ast_printer::visit_macro_call_expr(macro_call_expr *obj) {
}
void ast_printer::visit_cfor_stmt(cfor_stmt *obj) {}
void ast_printer::visit_enum_stmt(enum_stmt *obj) {}
void ast_printer::visit_union_stmt(union_stmt *obj) {}
void ast_printer::visit_directive_stmt(directive_stmt *obj) {}
1 change: 0 additions & 1 deletion compiler/src/ast/ast_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ namespace yaksha {
void visit_macro_call_expr(macro_call_expr *obj) override;
void visit_cfor_stmt(cfor_stmt *obj) override;
void visit_enum_stmt(enum_stmt *obj) override;
void visit_union_stmt(union_stmt *obj) override;
void visit_directive_stmt(directive_stmt *obj) override;

private:
Expand Down
1 change: 0 additions & 1 deletion compiler/src/ast/ast_vis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,4 @@ void ast_vis::visit_macro_call_expr(macro_call_expr *obj) {
}
void ast_vis::visit_cfor_stmt(cfor_stmt *obj) {}
void ast_vis::visit_enum_stmt(enum_stmt *obj) {}
void ast_vis::visit_union_stmt(union_stmt *obj) {}
void ast_vis::visit_directive_stmt(directive_stmt *obj) {}
1 change: 0 additions & 1 deletion compiler/src/ast/ast_vis.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ namespace yaksha {
void visit_macro_call_expr(macro_call_expr *obj) override;
void visit_cfor_stmt(cfor_stmt *obj) override;
void visit_enum_stmt(enum_stmt *obj) override;
void visit_union_stmt(union_stmt *obj) override;
void visit_directive_stmt(directive_stmt *obj) override;

private:
Expand Down
3 changes: 0 additions & 3 deletions compiler/src/compiler/codegen_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,6 @@ void to_json_compiler::visit_runtimefeature_stmt(runtimefeature_stmt *obj) {
json_ << "\"feature\": \"" << obj->feature_->token_ << "\"\n";
json_ << "}\n";
}
void to_json_compiler::visit_union_stmt(union_stmt *obj) {
// Placeholder statement - this is not parsed
}
void to_json_compiler::visit_while_stmt(while_stmt *obj) {
json_ << "{\n";
write_location(obj);
Expand Down
1 change: 0 additions & 1 deletion compiler/src/compiler/codegen_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ namespace yaksha {
void visit_pass_stmt(pass_stmt *obj) override;
void visit_return_stmt(return_stmt *obj) override;
void visit_runtimefeature_stmt(runtimefeature_stmt *obj) override;
void visit_union_stmt(union_stmt *obj) override;
void visit_while_stmt(while_stmt *obj) override;
void visit_directive_stmt(directive_stmt *obj) override;
~to_json_compiler() override = default;
Expand Down
1 change: 0 additions & 1 deletion compiler/src/compiler/const_fold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ void const_fold::visit_return_stmt(return_stmt *obj) {
void const_fold::visit_runtimefeature_stmt(runtimefeature_stmt *obj) {
store_statement(obj);
}
void const_fold::visit_union_stmt(union_stmt *obj) { store_statement(obj); }
void const_fold::visit_while_stmt(while_stmt *obj) {
statement_stack_.back()->emplace_back(wrap(obj));
}
Expand Down
1 change: 0 additions & 1 deletion compiler/src/compiler/const_fold.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ namespace yaksha {
void visit_pass_stmt(pass_stmt *obj) override;
void visit_return_stmt(return_stmt *obj) override;
void visit_runtimefeature_stmt(runtimefeature_stmt *obj) override;
void visit_union_stmt(union_stmt *obj) override;
void visit_while_stmt(while_stmt *obj) override;
std::vector<parsing_error> errors_;

Expand Down
1 change: 0 additions & 1 deletion compiler/src/compiler/def_class_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ void def_class_visitor::visit_curly_call_expr(curly_call_expr *obj) {}
void def_class_visitor::visit_macro_call_expr(macro_call_expr *obj) {}
void def_class_visitor::visit_cfor_stmt(cfor_stmt *obj) {}
void def_class_visitor::visit_enum_stmt(enum_stmt *obj) {}
void def_class_visitor::visit_union_stmt(union_stmt *obj) {}
void def_class_visitor::visit_directive_stmt(directive_stmt *obj) {
obj->hits_ = 1;// Always consider this to be used!
auto directive_type = obj->directive_type_->token_;
Expand Down
1 change: 0 additions & 1 deletion compiler/src/compiler/def_class_visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ namespace yaksha {
void visit_macro_call_expr(macro_call_expr *obj) override;
void visit_cfor_stmt(cfor_stmt *obj) override;
void visit_enum_stmt(enum_stmt *obj) override;
void visit_union_stmt(union_stmt *obj) override;
void visit_directive_stmt(directive_stmt *obj) override;
std::vector<std::string> get_all_names();
std::vector<std::string> function_names_{};
Expand Down
3 changes: 0 additions & 3 deletions compiler/src/compiler/desugaring_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,6 @@ void desugaring_compiler::visit_cfor_stmt(cfor_stmt *obj) {
void desugaring_compiler::visit_enum_stmt(enum_stmt *obj) {
statement_stack_.back()->emplace_back(obj);
}
void desugaring_compiler::visit_union_stmt(union_stmt *obj) {
statement_stack_.back()->emplace_back(obj);
}
void desugaring_compiler::visit_directive_stmt(directive_stmt *obj) {
statement_stack_.back()->emplace_back(obj);
}
1 change: 0 additions & 1 deletion compiler/src/compiler/desugaring_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ namespace yaksha {
void visit_while_stmt(while_stmt *obj) override;
void visit_cfor_stmt(cfor_stmt *obj) override;
void visit_enum_stmt(enum_stmt *obj) override;
void visit_union_stmt(union_stmt *obj) override;
void desugar_fixed_arr_foreach(foreach_stmt *obj);
void desugar_arr_foreach(foreach_stmt *obj);
void visit_directive_stmt(directive_stmt *obj) override;
Expand Down
1 change: 0 additions & 1 deletion compiler/src/compiler/return_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ void return_checker::visit_return_stmt(return_stmt *obj) {
found_returns_.push_back(true);
}
void return_checker::visit_runtimefeature_stmt(runtimefeature_stmt *obj) {}
void return_checker::visit_union_stmt(union_stmt *obj) {}
void return_checker::visit_while_stmt(while_stmt *obj) {}
bool return_checker::found_return() {
if (found_returns_.empty()) { return false; }
Expand Down
1 change: 0 additions & 1 deletion compiler/src/compiler/return_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ namespace yaksha {
void visit_pass_stmt(pass_stmt *obj) override;
void visit_return_stmt(return_stmt *obj) override;
void visit_runtimefeature_stmt(runtimefeature_stmt *obj) override;
void visit_union_stmt(union_stmt *obj) override;
void visit_while_stmt(while_stmt *obj) override;
void visit_directive_stmt(directive_stmt *obj) override;
std::vector<parsing_error> errors_{};
Expand Down
1 change: 0 additions & 1 deletion compiler/src/compiler/to_c_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,6 @@ void to_c_compiler::visit_cfor_stmt(cfor_stmt *obj) {
deletions_.pop_delete_stack();
}
void to_c_compiler::visit_enum_stmt(enum_stmt *obj) {}
void to_c_compiler::visit_union_stmt(union_stmt *obj) {}
void to_c_compiler::visit_directive_stmt(directive_stmt *obj) {
// TODO add support for parameters
if (obj->directive_type_->token_ == "ccode") {
Expand Down
1 change: 0 additions & 1 deletion compiler/src/compiler/to_c_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ namespace yaksha {
wrap_in_paren(const std::string &code) const override;
void visit_cfor_stmt(cfor_stmt *obj) override;
void visit_enum_stmt(enum_stmt *obj) override;
void visit_union_stmt(union_stmt *obj) override;
void visit_directive_stmt(directive_stmt *obj) override;

private:
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/compiler/type_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ void type_checker::visit_const_stmt(const_stmt *obj) {
auto match = type_match(obj->data_type_->args_[0], expression_dt, true);
if (match.matched_) {
placeholder = expression_data;
placeholder.datatype_ = obj->data_type_; // Set the correct data type
placeholder.datatype_ = obj->data_type_;// Set the correct data type
} else {
std::stringstream message{};
message << "Constant '" << name << "' data type mismatch. ";
Expand Down Expand Up @@ -1152,7 +1152,8 @@ type_match_result type_checker::type_match(ykdatatype *required_datatype,
if (castable != nullptr) { return type_match_result{"", true, true}; }
}
// Pass a Type to a Const[Type] is allowed (becomes more restrictive)
if (primitive_or_obj && is_identical_type(required_datatype->const_unwrap(), provided_datatype)) {
if (primitive_or_obj &&
is_identical_type(required_datatype->const_unwrap(), provided_datatype)) {
return type_match_result{"", true, false};
}
std::stringstream message{};
Expand Down Expand Up @@ -1436,5 +1437,4 @@ void type_checker::visit_cfor_stmt(cfor_stmt *obj) {
pop_scope_type();
}
void type_checker::visit_enum_stmt(enum_stmt *obj) {}
void type_checker::visit_union_stmt(union_stmt *obj) {}
void type_checker::visit_directive_stmt(directive_stmt *obj) {}
1 change: 0 additions & 1 deletion compiler/src/compiler/type_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ namespace yaksha {
void visit_macro_call_expr(macro_call_expr *obj) override;
void visit_cfor_stmt(cfor_stmt *obj) override;
void visit_enum_stmt(enum_stmt *obj) override;
void visit_union_stmt(union_stmt *obj) override;
void visit_directive_stmt(directive_stmt *obj) override;
/**
* Errors vector, type checker will try and identify as much errors as possible
Expand Down
1 change: 0 additions & 1 deletion compiler/src/compiler/usage_analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,5 +452,4 @@ void usage_analyser::visit_cfor_stmt(cfor_stmt *obj) {
obj->for_body_->accept(this);
}
void usage_analyser::visit_enum_stmt(enum_stmt *obj) { obj->hits_++; }
void usage_analyser::visit_union_stmt(union_stmt *obj) { obj->hits_++; }
void usage_analyser::visit_directive_stmt(directive_stmt *obj) { obj->hits_++; }
1 change: 0 additions & 1 deletion compiler/src/compiler/usage_analyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ namespace yaksha {
~usage_analyser() override;
void visit_cfor_stmt(cfor_stmt *obj) override;
void visit_enum_stmt(enum_stmt *obj) override;
void visit_union_stmt(union_stmt *obj) override;
void visit_directive_stmt(directive_stmt *obj) override;
std::vector<parsing_error> errors_{};

Expand Down
Loading

0 comments on commit 5e6d605

Please sign in to comment.