Make sure parsed filenames live as long as the AST
This commit is contained in:
parent
6aaa58f518
commit
6a3835951f
3 changed files with 7 additions and 8 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
#include <pslang/ast/statement.hpp>
|
#include <pslang/ast/statement.hpp>
|
||||||
#include <pslang/ast/print.hpp>
|
#include <pslang/ast/print.hpp>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
@ -81,7 +82,7 @@ int main(int argc, char ** argv)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
filenames.push_back(argv[arg]);
|
filenames.push_back(argv[arg]);
|
||||||
parsed.push_back(parser::parse(argv[arg]));
|
parsed.push_back(parser::parse(filenames.back()));
|
||||||
}
|
}
|
||||||
catch (pslang::parser::parse_error const & error)
|
catch (pslang::parser::parse_error const & error)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
#include <pslang/ast/statement_fwd.hpp>
|
#include <pslang/ast/statement_fwd.hpp>
|
||||||
|
|
||||||
#include <filesystem>
|
#include <string_view>
|
||||||
|
|
||||||
namespace pslang::parser
|
namespace pslang::parser
|
||||||
{
|
{
|
||||||
|
|
||||||
ast::statement_list_ptr parse(std::filesystem::path const & file);
|
ast::statement_list_ptr parse(std::string_view path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,13 @@
|
||||||
namespace pslang::parser
|
namespace pslang::parser
|
||||||
{
|
{
|
||||||
|
|
||||||
ast::statement_list_ptr parse(std::filesystem::path const & file)
|
ast::statement_list_ptr parse(std::string_view path)
|
||||||
{
|
{
|
||||||
auto filename = file.string();
|
yyin = fopen(path.data(), "r");
|
||||||
|
|
||||||
yyin = fopen(filename.c_str(), "r");
|
|
||||||
if (!yyin)
|
if (!yyin)
|
||||||
throw std::system_error(std::make_error_code(static_cast<std::errc>(errno)));
|
throw std::system_error(std::make_error_code(static_cast<std::errc>(errno)));
|
||||||
|
|
||||||
ast::location location{filename};
|
ast::location location{path};
|
||||||
indented_statement_list result;
|
indented_statement_list result;
|
||||||
context ctx{location, result};
|
context ctx{location, result};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue