Cthulhu  0.2.10
Cthulhu compiler collection
compile.cpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-3.0-only
2 #include "stdafx.hpp"
3 
4 #include "editor/compile.hpp"
5 
7 
8 #include "memory/memory.h"
9 #include "notify/notify.h"
10 
11 #include "std/str.h"
12 
13 #include "std/typed/vector.h"
14 
15 #include "support/support.h"
16 
17 using namespace ed;
18 
19 static constexpr frontend_t kEditorInfo = {
20  .info = {
21  .id = "frontend-editor",
22  .name = "Editor GUI",
23  .version = {
24  .license = "GPLv3",
25  .desc = "ImGui based frontend for the Cthulhu Compiler Collection",
26  .author = "Elliot Haisley",
27  .version = CT_NEW_VERSION(1, 0, 2),
28  }
29  }
30 };
31 
32 Broker::Broker(loader_t *loader, const char *name)
33  : name(name)
34  , broker(broker_new(&kEditorInfo, get_global_arena()))
35  , loader(loader)
36 { }
37 
43 char *Broker::parse_source(size_t)
44 {
45 #if 0
46  const char *path = sources.get_path(index);
47  arena_t *arena = get_global_arena();
48 
49  char *ext = str_ext(path, arena);
50  if (ext == nullptr)
51  {
52  return str_format(arena, "could not determine file extension for '%s'", path);
53  }
54 
56  if (lang == nullptr)
57  {
58  const char *basepath = str_filename(path, arena);
59  return str_format(arena, "could not find language for `%s` by extension `%s`", basepath, ext);
60  }
61 
62  io_t *io = sources.get_io(index);
63 
64  broker_parse(lang, io);
65 #endif
66  return nullptr;
67 }
68 
69 void Broker::init_support()
70 {
73 }
74 
76 {
77  if (setup) return;
78  setup = true;
79 
80  init_support();
81 }
82 
88 {
90  typevec_t *events = logger_get_events(logger);
91  return typevec_len(events) == 0;
92 }
broker_t * broker
Definition: compile.hpp:24
bool check_reports() const
check if there are any reports
Definition: compile.cpp:87
loader_t * loader
Definition: compile.hpp:25
void init()
Definition: compile.cpp:75
bool setup
Definition: compile.hpp:23
Broker(loader_t *loader, const char *name)
Definition: compile.cpp:32
support_t * support
Definition: compile.hpp:26
char * parse_source(size_t index)
parse a source file
Definition: compile.cpp:43
CT_BROKER_API void broker_parse(language_runtime_t *runtime, io_t *io)
Definition: broker.c:376
CT_BROKER_API broker_t * broker_new(const frontend_t *frontend, arena_t *arena)
Definition: broker.c:130
CT_BROKER_API logger_t * broker_get_logger(broker_t *broker)
Definition: broker.c:325
#define CT_NEW_VERSION(major, minor, patch)
creates a new ctu_version_t from major, minor and patch
Definition: version_def.h:20
CT_MEMORY_API arena_t * get_global_arena(void)
get the global memory arena
Definition: memory.c:16
CT_SUPPORT_API language_runtime_t * support_get_lang(support_t *support, const char *ext)
Definition: support.c:176
CT_SUPPORT_API void support_load_default_modules(support_t *support)
load all default modules
Definition: support.c:139
CT_SUPPORT_API support_t * support_new(broker_t *broker, loader_t *loader, arena_t *arena)
create a support instance from an existing loader and broker configures the broker with the modules i...
Definition: support.c:113
CT_NODISCARD CT_NOTIFY_API typevec_t * logger_get_events(const logger_t *logs)
get the events from the logger
Definition: notify.c:36
CT_NODISCARD CT_STD_API char * str_filename(const char *path, arena_t *arena)
get the filename from a path
Definition: str.c:218
CT_NODISCARD CT_STD_API char * str_ext(const char *path, arena_t *arena)
get the last file extension from a path
Definition: str.c:173
CT_NODISCARD CT_PUREFN CT_STD_API size_t typevec_len(const typevec_t *vec)
get the length of a vector
Definition: vector.c:120
Definition: compile.hpp:13
STA_DECL char * str_format(arena_t *arena, const char *fmt,...)
Definition: str.c:97
an allocator object
Definition: arena.h:86
the frontend running the mediator
Definition: broker.h:251
module_info_t info
information about the frontend
Definition: broker.h:253
io object implementation
Definition: impl.h:122
Definition: common.h:8
a logging sink
Definition: notify.c:14
const char * id
unique id for the module
Definition: broker.h:101
A vector with a fixed type size.
Definition: vector.h:24