Add semantic passes
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
#include "elna/source/ast.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace elna::source
|
||||
namespace elna
|
||||
{
|
||||
namespace source
|
||||
{
|
||||
void empty_visitor::visit(declaration *declaration)
|
||||
{
|
||||
@ -522,3 +524,4 @@ namespace elna::source
|
||||
return *m_body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "elna/source/driver.hpp"
|
||||
|
||||
namespace elna::source
|
||||
namespace elna
|
||||
{
|
||||
namespace source
|
||||
{
|
||||
position make_position(const yy::location& location)
|
||||
{
|
||||
@ -11,7 +13,7 @@ namespace elna::source
|
||||
}
|
||||
|
||||
syntax_error::syntax_error(const std::string& message,
|
||||
const std::filesystem::path& input_file, const yy::location& location)
|
||||
const std::experimental::filesystem::path& input_file, const yy::location& location)
|
||||
: error(input_file, make_position(location)), message(message)
|
||||
{
|
||||
}
|
||||
@ -21,7 +23,7 @@ namespace elna::source
|
||||
return message;
|
||||
}
|
||||
|
||||
driver::driver(const std::filesystem::path& input_file)
|
||||
driver::driver(const std::experimental::filesystem::path& input_file)
|
||||
: input_file(input_file)
|
||||
{
|
||||
}
|
||||
@ -36,3 +38,4 @@ namespace elna::source
|
||||
return m_errors;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
#include "elna/source/result.hpp"
|
||||
|
||||
namespace elna::source
|
||||
namespace elna
|
||||
{
|
||||
error::error(const std::filesystem::path& path, const position position)
|
||||
namespace source
|
||||
{
|
||||
error::error(const std::experimental::filesystem::path& path, const position position)
|
||||
: m_position(position), m_path(path)
|
||||
{
|
||||
}
|
||||
@ -17,12 +19,12 @@ namespace elna::source
|
||||
return this->m_position.column;
|
||||
}
|
||||
|
||||
const std::filesystem::path& error::path() const noexcept
|
||||
const std::experimental::filesystem::path& error::path() const noexcept
|
||||
{
|
||||
return this->m_path;
|
||||
}
|
||||
|
||||
name_collision::name_collision(const std::string& name, const std::filesystem::path& path,
|
||||
name_collision::name_collision(const std::string& name, const std::experimental::filesystem::path& path,
|
||||
const position current, const position previous)
|
||||
: error(path, current), name(name), previous(previous)
|
||||
{
|
||||
@ -33,8 +35,8 @@ namespace elna::source
|
||||
return "Name '" + name + "' was already defined";
|
||||
}
|
||||
|
||||
type_mismatch::type_mismatch(std::shared_ptr<const type> got, operation kind, const std::filesystem::path& path,
|
||||
const struct position position)
|
||||
type_mismatch::type_mismatch(std::shared_ptr<const type> got, operation kind,
|
||||
const std::experimental::filesystem::path& path, const struct position position)
|
||||
: error(path, position), kind(kind), got(got)
|
||||
{
|
||||
}
|
||||
@ -44,3 +46,4 @@ namespace elna::source
|
||||
return "Type cannot be used here.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,12 @@
|
||||
#include "elna/source/result.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
namespace elna::source
|
||||
namespace elna
|
||||
{
|
||||
namespace source
|
||||
{
|
||||
name_analysis_visitor::name_analysis_visitor(std::shared_ptr<symbol_table> table,
|
||||
const std::filesystem::path& filename, const std::size_t target_pointer_size)
|
||||
const std::experimental::filesystem::path& filename, const std::size_t target_pointer_size)
|
||||
: table(table), filename(filename), pointer_size(target_pointer_size)
|
||||
{
|
||||
}
|
||||
@ -33,11 +35,11 @@ namespace elna::source
|
||||
}
|
||||
}
|
||||
|
||||
void name_analysis_visitor::visit(declaration *declaration)
|
||||
void name_analysis_visitor::visit(declaration *declarationx)
|
||||
{
|
||||
std::shared_ptr<const type> declaration_type = convert_declaration_type(declaration->type());
|
||||
std::shared_ptr<const type> declaration_type = convert_declaration_type(declarationx->type());
|
||||
|
||||
this->table->enter(declaration->identifier(),
|
||||
this->table->enter(declarationx->identifier(),
|
||||
std::make_shared<variable_info>(declaration_type));
|
||||
}
|
||||
|
||||
@ -132,7 +134,7 @@ namespace elna::source
|
||||
}
|
||||
|
||||
type_analysis_visitor::type_analysis_visitor(std::shared_ptr<symbol_table> table,
|
||||
const std::filesystem::path& filename, const std::size_t target_pointer_size)
|
||||
const std::experimental::filesystem::path& filename, const std::size_t target_pointer_size)
|
||||
: table(table), filename(filename), pointer_size(target_pointer_size)
|
||||
{
|
||||
}
|
||||
@ -323,3 +325,4 @@ namespace elna::source
|
||||
return m_errors;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include "elna/source/types.hpp"
|
||||
#include "elna/source/symbol_table.hpp"
|
||||
|
||||
namespace elna::source
|
||||
namespace elna
|
||||
{
|
||||
namespace source
|
||||
{
|
||||
symbol_table::symbol_table(std::shared_ptr<symbol_table> scope)
|
||||
: outer_scope(scope)
|
||||
@ -25,7 +27,7 @@ namespace elna::source
|
||||
|
||||
void symbol_table::enter(const std::string& name, std::shared_ptr<info> entry)
|
||||
{
|
||||
entries.insert_or_assign(name, entry);
|
||||
entries.insert({ name, entry });
|
||||
}
|
||||
|
||||
std::shared_ptr<symbol_table> symbol_table::scope()
|
||||
@ -127,3 +129,4 @@ namespace elna::source
|
||||
return local_stack_size + argument_stack_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <elna/source/types.hpp>
|
||||
|
||||
namespace elna::source
|
||||
namespace elna
|
||||
{
|
||||
namespace source
|
||||
{
|
||||
type::type(const std::size_t byte_size)
|
||||
: byte_size(byte_size)
|
||||
@ -93,4 +95,8 @@ namespace elna::source
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
const primitive_type boolean_type{ "Boolean", 1 };
|
||||
const primitive_type int_type{ "Int", 4 };
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user