summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/combine
diff options
context:
space:
mode:
Diffstat (limited to 'tiger-compiler/src/combine')
-rw-r--r--tiger-compiler/src/combine/binder.cc17
-rw-r--r--tiger-compiler/src/combine/binder.hh16
-rw-r--r--tiger-compiler/src/combine/libcombine.cc26
-rw-r--r--tiger-compiler/src/combine/libcombine.hh44
-rw-r--r--tiger-compiler/src/combine/local.am6
-rw-r--r--tiger-compiler/src/combine/tasks.cc74
-rw-r--r--tiger-compiler/src/combine/tasks.hh56
-rw-r--r--tiger-compiler/src/combine/type-checker.cc14
-rw-r--r--tiger-compiler/src/combine/type-checker.hh20
9 files changed, 273 insertions, 0 deletions
diff --git a/tiger-compiler/src/combine/binder.cc b/tiger-compiler/src/combine/binder.cc
new file mode 100644
index 0000000..c5fc66e
--- /dev/null
+++ b/tiger-compiler/src/combine/binder.cc
@@ -0,0 +1,17 @@
+/**
+ ** \file combine/combine-binder.cc
+ ** \brief Implementation of combine::Binder.
+ */
+
+#include <ast/all.hh>
+#include <combine/binder.hh>
+
+namespace combine
+{
+ /*---------------.
+ | Visiting Dec. |
+ `---------------*/
+
+ // FIXME: Some code was deleted here.
+
+} // namespace combine
diff --git a/tiger-compiler/src/combine/binder.hh b/tiger-compiler/src/combine/binder.hh
new file mode 100644
index 0000000..1789b47
--- /dev/null
+++ b/tiger-compiler/src/combine/binder.hh
@@ -0,0 +1,16 @@
+/**
+ ** \file combine/binder.hh
+ ** \brief Declaration of combine::Binder.
+ **/
+
+#pragma once
+
+#include <object/binder.hh>
+#include <overload/binder.hh>
+
+namespace combine
+{
+ /// \brief Compute bindings with support for objects and overload.
+ // FIXME: Some code was deleted here (class Binder inheriting from object::Binder and overload::Binder).
+
+} // namespace combine
diff --git a/tiger-compiler/src/combine/libcombine.cc b/tiger-compiler/src/combine/libcombine.cc
new file mode 100644
index 0000000..29834de
--- /dev/null
+++ b/tiger-compiler/src/combine/libcombine.cc
@@ -0,0 +1,26 @@
+/**
+ ** \file combine/libcombine.cc
+ ** \brief Define exported combine functions.
+ */
+
+#include <combine/libcombine.hh>
+
+// FIXME: Some code was deleted here.
+
+namespace combine
+{
+ std::pair<overload::overfun_bindings_type, misc::error>
+ combine_bind(ast::Ast& tree, bool overloads_enabled)
+ {
+ // FIXME: Some code was deleted here.
+ }
+
+ misc::error
+ combine_types_check(ast::Ast& tree,
+ const overload::overfun_bindings_type& combine_bindings,
+ bool overloads_enabled)
+ {
+ // FIXME: Some code was deleted here.
+ }
+
+} // namespace combine
diff --git a/tiger-compiler/src/combine/libcombine.hh b/tiger-compiler/src/combine/libcombine.hh
new file mode 100644
index 0000000..66f3c4c
--- /dev/null
+++ b/tiger-compiler/src/combine/libcombine.hh
@@ -0,0 +1,44 @@
+/**
+ ** \file combine/libcombine.hh
+ ** \brief Declare functions and variables exported by combine module.
+ */
+
+#pragma once
+
+#include <ast/fwd.hh>
+#include <misc/error.hh>
+#include <overload/binder.hh>
+
+namespace combine
+{
+ /*-------.
+ | Bind. |
+ `-------*/
+
+ /** \brief Bind identifier uses to their definition, allowing
+ function overloading, and return a list of potential definition
+ sites for each function call.
+
+ \param tree AST to bind.
+
+ \return a pair whose first element is the potential function
+ bindings, and the second element the error status. */
+ std::pair<overload::overfun_bindings_type, misc::error>
+ combine_bind(ast::Ast& tree, bool overloads_enabled);
+
+ /*------------------------------.
+ | Compute types with overload. |
+ `------------------------------*/
+
+ /** \brief Check types allowing function overloading.
+
+ \param tree abstract syntax tree's root.
+ \param combine_bindings potential function bindings.
+
+ \return success of the type-checking. */
+ misc::error
+ combine_types_check(ast::Ast& tree,
+ const overload::overfun_bindings_type& combine_bindings,
+ bool overloads_enabled);
+
+} // namespace combine
diff --git a/tiger-compiler/src/combine/local.am b/tiger-compiler/src/combine/local.am
new file mode 100644
index 0000000..7fd348c
--- /dev/null
+++ b/tiger-compiler/src/combine/local.am
@@ -0,0 +1,6 @@
+src_libtc_la_SOURCES += \
+ %D%/libcombine.hh %D%/libcombine.cc \
+ %D%/binder.hh %D%/binder.cc \
+ %D%/type-checker.hh %D%/type-checker.cc
+
+TASKS += %D%/tasks.hh %D%/tasks.cc
diff --git a/tiger-compiler/src/combine/tasks.cc b/tiger-compiler/src/combine/tasks.cc
new file mode 100644
index 0000000..48470ac
--- /dev/null
+++ b/tiger-compiler/src/combine/tasks.cc
@@ -0,0 +1,74 @@
+/**
+ ** \file combine/tasks.cc
+ ** \brief Combine module related tasks' implementation.
+ */
+
+#include <ast/tasks.hh>
+#include <bind/tasks.hh>
+#include <desugar/tasks.hh>
+#include <escapes/tasks.hh>
+#include <object/tasks.hh>
+
+#include <astclone/libastclone.hh>
+#include <desugar/libdesugar.hh>
+#include <inlining/libinlining.hh>
+
+#include <common.hh>
+
+#include <combine/libcombine.hh>
+#define DEFINE_TASKS 1
+#include <combine/tasks.hh>
+#undef DEFINE_TASKS
+
+namespace combine::tasks
+{
+ std::unique_ptr<overload::overfun_bindings_type> the_overfun_bindings =
+ nullptr;
+
+ void combine_bindings_compute()
+ {
+ auto result =
+ ::combine::combine_bind(*ast::tasks::the_program, c_overload_p);
+ ::combine::tasks::the_overfun_bindings =
+ std::make_unique<overload::overfun_bindings_type>(
+ std::move(result.first));
+
+ task_error() << result.second << &misc::error::exit_on_error;
+ }
+
+ void combine_types_compute()
+ {
+ task_error() << ::combine::combine_types_check(
+ *ast::tasks::the_program, *::combine::tasks::the_overfun_bindings,
+ c_overload_p);
+ the_overfun_bindings.reset();
+ task_error().exit_on_error();
+ }
+
+ void combine_rename()
+ {
+ // FIXME: Some code was deleted here (Call appropriate renaming tasks).
+ }
+
+ void combine_desugar()
+ {
+ if (c_object_p)
+ ::object::tasks::object_desugar();
+
+ if (c_desugar_p)
+ ::desugar::tasks::desugar();
+
+ if (c_bounds_p)
+ astclone::apply(::desugar::bounds_checks_add, ast::tasks::the_program);
+
+ if (c_inline_p)
+ astclone::apply(::inlining::inline_expand, ast::tasks::the_program);
+
+ if (c_prune_p)
+ astclone::apply(::inlining::prune, ast::tasks::the_program);
+
+ if (c_escapes_p)
+ ::escapes::tasks::escapes_compute();
+ }
+
+} // namespace combine::tasks
diff --git a/tiger-compiler/src/combine/tasks.hh b/tiger-compiler/src/combine/tasks.hh
new file mode 100644
index 0000000..67cc169
--- /dev/null
+++ b/tiger-compiler/src/combine/tasks.hh
@@ -0,0 +1,56 @@
+/**
+ ** \file combine/tasks.hh
+ ** \brief Combine module related tasks.
+ */
+
+#pragma once
+
+#include <overload/binder.hh>
+#include <task/libtask.hh>
+
+namespace combine::tasks
+{
+ TASK_GROUP("Combine");
+
+ BOOLEAN_TASK_DECLARE("c-object", "combine objects", c_object_p, "object");
+ BOOLEAN_TASK_DECLARE("c-bounds", "combine bounds checking", c_bounds_p, "");
+ BOOLEAN_TASK_DECLARE("c-escapes", "combine escapes", c_escapes_p, "");
+ BOOLEAN_TASK_DECLARE("c-desugar",
+ "combine for and string comparison desugaring",
+ c_desugar_p,
+ "desugar-for desugar-string-cmp");
+ BOOLEAN_TASK_DECLARE("c-inline", "combine inlining", c_inline_p, "");
+ BOOLEAN_TASK_DECLARE("c-prune", "combine pruning", c_prune_p, "");
+ BOOLEAN_TASK_DECLARE("c-overload", "combine overloading", c_overload_p, "");
+
+ BOOLEAN_TASK_DECLARE(
+ "a|c-all",
+ "combine all compiler options",
+ c_all_p,
+ "c-object c-bounds c-escapes c-desugar c-inline c-prune c-overload");
+
+ TASK_DECLARE("combine-bindings-compute",
+ "bind the identifiers, "
+ "allowing various compiler options",
+ combine_bindings_compute,
+ "parse");
+
+ TASK_DECLARE("combine-types-compute",
+ "check for type violations, "
+ "allowing various compiler options",
+ combine_types_compute,
+ "combine-bindings-compute");
+
+ TASK_DECLARE("combine-rename",
+ "rename identifiers to unique names, "
+ "allowing various compiler options",
+ combine_rename,
+ "combine-types-compute");
+
+ TASK_DECLARE("c|combine-desugar",
+ "remove object and complex constructs from the program"
+ "allowing various compiler options",
+ combine_desugar,
+ "combine-rename");
+
+} // namespace combine::tasks
diff --git a/tiger-compiler/src/combine/type-checker.cc b/tiger-compiler/src/combine/type-checker.cc
new file mode 100644
index 0000000..67cbfbc
--- /dev/null
+++ b/tiger-compiler/src/combine/type-checker.cc
@@ -0,0 +1,14 @@
+/**
+ ** \file combine/type-checker.cc
+ ** \brief Implementation for combine/type-checker.hh.
+ */
+
+#include <ast/all.hh>
+#include <combine/type-checker.hh>
+#include <type/types.hh>
+
+namespace combine
+{
+ // FIXME: Some code was deleted here.
+
+} // namespace combine
diff --git a/tiger-compiler/src/combine/type-checker.hh b/tiger-compiler/src/combine/type-checker.hh
new file mode 100644
index 0000000..02370d2
--- /dev/null
+++ b/tiger-compiler/src/combine/type-checker.hh
@@ -0,0 +1,20 @@
+/**
+ ** \file combine/type-checker.hh
+ ** \brief Declaration of combine::TypeChecker.
+ */
+
+#pragma once
+
+#include <object/type-checker.hh>
+#include <overload/binder.hh>
+#include <overload/type-checker.hh>
+#include <type/class.hh>
+#include <type/types.hh>
+
+namespace combine
+{
+ /// Perform type checking, allowing objects, and compute
+ /// the bindings of the object's methods and fields.
+ // FIXME: Some code was deleted here (class TypeChecker inheriting from overload::TypeChecker and object::TypeChecker).
+
+} // namespace combine