summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/parse/tasks.cc
blob: 142369625b79d8b8c677bca01e0c59968638717c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
 ** \file parse/tasks.cc
 ** \brief Parse module related tasks' implementation.
 **/

#include <cstdlib>
#include <iostream>
#include <memory>

#include <assert/tasks.hh>
#include <ast/tasks.hh>
#include <common.hh>
#include <misc/file-library.hh>
#include <object/tasks.hh>
#include <parse/libparse.hh>
#define DEFINE_TASKS 1
#include <parse/tasks.hh>
#undef DEFINE_TASKS

namespace parse::tasks
{
  const char* tc_pkgdatadir = getenv("TC_PKGDATADIR");
  misc::file_library l =
    misc::file_library(tc_pkgdatadir ? tc_pkgdatadir : PKGDATADIR);

  void no_prelude() { prelude = ""; }

  void parse()
  {
    precondition(filename != nullptr);
    bool scan_trace = scan_trace_p || getenv("SCAN");
    bool parse_trace = parse_trace_p || getenv("PARSE");
    std::pair<ast::ChunkList*, misc::error> result =
      ::parse::parse(prelude, filename, l, scan_trace, parse_trace,
                     object::tasks::enable_object_extensions_p,
                     assert::tasks::enable_assert_extensions_p);

    // If the parsing completely failed, stop.
    task_error() << result.second;
    if (!result.first)
      task_error().exit();

    // FIXME DONE: Some code was deleted here (Set `the_program' to the result of parsing).
    ast::tasks::the_program = std::unique_ptr<ast::ChunkList>{result.first};
  }

  void library_display() { std::cout << l << '\n'; }

  void library_append(const std::string& dir) { l.append_dir(dir); }

  void library_prepend(const std::string& dir) { l.prepend_dir(dir); }

} // namespace parse::tasks