Support one hardcoded import
This commit is contained in:
@ -17,46 +17,67 @@ along with GCC; see the file COPYING3. If not see
|
||||
|
||||
#include "elna/boot/dependency.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string.h>
|
||||
|
||||
#include "elna/boot/driver.h"
|
||||
#include "elna/boot/semantic.h"
|
||||
#include "parser.hh"
|
||||
|
||||
namespace elna::boot
|
||||
{
|
||||
dependency_graph::dependency_graph()
|
||||
dependency::dependency(const char *path)
|
||||
: error_container(path)
|
||||
{
|
||||
}
|
||||
|
||||
dependency_graph::dependency_graph(error_list&& errors)
|
||||
: m_errors(std::move(errors))
|
||||
{
|
||||
}
|
||||
|
||||
bool dependency_graph::has_errors() const
|
||||
{
|
||||
return !errors().empty();
|
||||
}
|
||||
|
||||
const error_list& dependency_graph::errors() const
|
||||
{
|
||||
return m_errors;
|
||||
}
|
||||
|
||||
dependency_graph read_sources(std::istream& entry_point, const char *entry_path)
|
||||
dependency read_sources(std::istream& entry_point, const char *entry_path)
|
||||
{
|
||||
driver parse_driver{ entry_path };
|
||||
lexer tokenizer(entry_point);
|
||||
yy::parser parser(tokenizer, parse_driver);
|
||||
|
||||
dependency outcome{ entry_path };
|
||||
if (parser())
|
||||
{
|
||||
return dependency_graph(std::move(parse_driver.errors()));
|
||||
std::swap(outcome.errors(), parse_driver.errors());
|
||||
return outcome;
|
||||
}
|
||||
else
|
||||
{
|
||||
dependency_graph outcome;
|
||||
outcome.modules.emplace_back(std::move(parse_driver.tree));
|
||||
|
||||
return outcome;
|
||||
std::swap(outcome.tree, parse_driver.tree);
|
||||
}
|
||||
declaration_visitor declaration_visitor(entry_path);
|
||||
outcome.tree->accept(&declaration_visitor);
|
||||
|
||||
if (!declaration_visitor.errors().empty())
|
||||
{
|
||||
std::swap(outcome.errors(), parse_driver.errors());
|
||||
}
|
||||
outcome.unresolved = declaration_visitor.unresolved;
|
||||
|
||||
return outcome;
|
||||
}
|
||||
|
||||
std::filesystem::path build_path(const std::vector<std::string>& segments)
|
||||
{
|
||||
std::filesystem::path result;
|
||||
std::vector<std::string>::const_iterator segment_iterator = std::cbegin(segments);
|
||||
|
||||
if (segment_iterator == std::cend(segments))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
result = *segment_iterator;
|
||||
|
||||
++segment_iterator;
|
||||
for (; segment_iterator != std::cend(segments); ++segment_iterator)
|
||||
{
|
||||
result /= *segment_iterator;
|
||||
}
|
||||
result.replace_extension(".elna");
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user