76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
/* Dependency graph analysis.
|
|
Copyright (C) 2025 Free Software Foundation, Inc.
|
|
|
|
GCC is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
any later version.
|
|
|
|
GCC is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#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::dependency()
|
|
{
|
|
}
|
|
|
|
dependency::dependency(error_list&& errors)
|
|
: m_errors(std::move(errors))
|
|
{
|
|
}
|
|
|
|
bool dependency::has_errors() const
|
|
{
|
|
return !errors().empty();
|
|
}
|
|
|
|
const error_list& dependency::errors() const
|
|
{
|
|
return m_errors;
|
|
}
|
|
|
|
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;
|
|
if (parser())
|
|
{
|
|
return dependency(std::move(parse_driver.errors()));
|
|
}
|
|
else
|
|
{
|
|
std::swap(outcome.tree, parse_driver.tree);
|
|
}
|
|
declaration_visitor declaration_visitor(entry_path);
|
|
outcome.tree->accept(&declaration_visitor);
|
|
|
|
if (!declaration_visitor.errors().empty())
|
|
{
|
|
return dependency(std::move(declaration_visitor.errors()));
|
|
}
|
|
outcome.unresolved = declaration_visitor.unresolved;
|
|
|
|
return outcome;
|
|
}
|
|
}
|