aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/elna/boot/dependency.h16
-rw-r--r--include/elna/boot/result.h4
-rw-r--r--include/elna/gcc/elna-builtins.h2
-rw-r--r--include/elna/gcc/elna-generic.h2
-rw-r--r--include/elna/gcc/elna-module-loader.h5
-rw-r--r--include/elna/gcc/elna-tree.h2
6 files changed, 20 insertions, 11 deletions
diff --git a/include/elna/boot/dependency.h b/include/elna/boot/dependency.h
index 18df64c..9bc1adf 100644
--- a/include/elna/boot/dependency.h
+++ b/include/elna/boot/dependency.h
@@ -174,7 +174,7 @@ namespace elna::boot
{
{ loader.resolve(relative, position, key) } -> std::same_as<std::filesystem::path>;
{ loader.read(key) } -> std::same_as<read_result>;
- loader.finalize(key, module_scope);
+ loader.finalize(key, module_scope, true);
};
/**
@@ -217,6 +217,9 @@ namespace elna::boot
* their canonical paths to detect circular imports.
* \param loader Host-side module loader.
* \param target Target machine information.
+ * \param imported Whether \p key is being compiled because another module
+ * imports it. False for the module the caller asked for; set when
+ * recursing into an import, and passed on to \c finalize.
*
* \return Abstract syntax tree of the module itself and the
* diagnostics of this module and all its imports, grouped by
@@ -224,7 +227,7 @@ namespace elna::boot
*/
template<module_loader Loader>
dependency compile(const std::filesystem::path& key, Loader& loader,
- const target_info& target)
+ const target_info& target, const bool imported = false)
{
auto cached = this->cache.find(key);
if (cached != this->cache.cend())
@@ -257,7 +260,7 @@ namespace elna::boot
module_path.stem().string()));
continue;
}
- dependency sub = this->compile(module_path, loader, target);
+ dependency sub = this->compile(module_path, loader, target, true);
for (auto& diagnostics : sub.errors)
{
result.append(std::move(diagnostics.module), std::move(diagnostics.errors()));
@@ -273,12 +276,11 @@ namespace elna::boot
result.append(key, std::move(analysis.errors));
}
this->cache.insert({ key, analysis.value });
- loader.finalize(key, analysis.value.leave());
- this->in_progress.erase(key);
- if (failed)
+ if (!failed)
{
- tree.reset();
+ loader.finalize(key, analysis.value.leave(), imported);
}
+ this->in_progress.erase(key);
result.value = std::move(tree);
return result;
}
diff --git a/include/elna/boot/result.h b/include/elna/boot/result.h
index eacc072..d37484a 100644
--- a/include/elna/boot/result.h
+++ b/include/elna/boot/result.h
@@ -263,6 +263,10 @@ namespace elna::boot
template<has_to_string T>
std::string join(const std::vector<T>& identifiers, std::string_view delimiter = ", ")
{
+ if (identifiers.empty())
+ {
+ return std::string();
+ }
return std::accumulate(std::next(identifiers.begin()), identifiers.end(),
identifiers.front().to_string(),
[delimiter](const std::string& accumulator, const T& next) -> std::string {
diff --git a/include/elna/gcc/elna-builtins.h b/include/elna/gcc/elna-builtins.h
index 75b409d..10a2732 100644
--- a/include/elna/gcc/elna-builtins.h
+++ b/include/elna/gcc/elna-builtins.h
@@ -33,7 +33,7 @@ namespace elna::gcc
std::shared_ptr<symbol_table> builtin_symbol_table();
void rewrite_symbol_table(const std::shared_ptr<boot::symbol_table>& info_table,
- const std::shared_ptr<symbol_table>& symbols);
+ const std::shared_ptr<symbol_table>& symbols, bool imported);
tree handle_symbol(const std::string& symbol_name,
const std::shared_ptr<boot::alias_type>& reference,
const std::shared_ptr<symbol_table>& symbols);
diff --git a/include/elna/gcc/elna-generic.h b/include/elna/gcc/elna-generic.h
index fd54ba5..c0c23b1 100644
--- a/include/elna/gcc/elna-generic.h
+++ b/include/elna/gcc/elna-generic.h
@@ -62,7 +62,7 @@ namespace elna::gcc
void build_assert_builtin(location_t call_location, const std::vector<boot::expression *>& arguments);
void visit_statements(const std::vector<boot::statement *>& statements);
- bool assert_constant(location_t expression_location);
+ void assert_constant();
tree declare_local_variable(const boot::identifier& name,
const boot::variable_info& info, tree initial_value);
diff --git a/include/elna/gcc/elna-module-loader.h b/include/elna/gcc/elna-module-loader.h
index 2b46fc5..5f5aab6 100644
--- a/include/elna/gcc/elna-module-loader.h
+++ b/include/elna/gcc/elna-module-loader.h
@@ -78,9 +78,12 @@ namespace elna::gcc
*
* \param key Resolved module path.
* \param module_scope Analyzed module scope.
+ * \param imported Whether the module is being registered because another
+ * module imports it, rather than being the translation unit itself.
+ * Its variables are then declarations instead of definitions.
*/
void finalize(const std::filesystem::path& key,
- const std::shared_ptr<boot::symbol_table>& module_scope) const;
+ const std::shared_ptr<boot::symbol_table>& module_scope, bool imported) const;
};
/**
diff --git a/include/elna/gcc/elna-tree.h b/include/elna/gcc/elna-tree.h
index f201e64..a3a9106 100644
--- a/include/elna/gcc/elna-tree.h
+++ b/include/elna/gcc/elna-tree.h
@@ -55,7 +55,7 @@ namespace elna::gcc
tree do_pointer_arithmetic(boot::binary_operator binary_operator,
tree left, tree right, location_t operation_location);
tree build_field(location_t location, tree record_type, const std::string& name, tree type);
- tree find_field_by_name(location_t expression_location, tree type, const std::string& field_name);
+ tree find_field_by_name(tree type, const std::string& field_name);
tree build_static_array_type(tree type, const std::uint64_t size);
tree build_slice(tree slice_type, tree ptr, tree length);
tree build_enumeration_type(const std::vector<std::string>& members);