Translate position to a GCC location

This commit is contained in:
2024-12-27 23:38:25 +01:00
parent 51f5603c4a
commit d46608b358
9 changed files with 182 additions and 61 deletions

View File

@ -0,0 +1,13 @@
#pragma once
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "input.h"
#include "tree.h"
#include "elna/source/result.h"
location_t elna_gcc_location(const elna::source::position *position);
const char *elna_gcc_print_type(tree type);

View File

@ -8,6 +8,9 @@
#include "tree.h"
#include "tree-iterator.h"
#include <unordered_map>
#include <string>
namespace elna
{
namespace gcc
@ -16,12 +19,17 @@ namespace gcc
{
tree current_statements{ NULL_TREE };
tree current_expression{ NULL_TREE };
std::unordered_map<std::string, tree> symbol_map;
public:
void visit(source::program *program) override;
void visit(source::call_statement *statement) override;
void visit(source::integer_literal *literal) override;
void visit(source::boolean_literal *literal) override;
void visit(source::binary_expression *expression) override;
void visit(source::declaration *declaration) override;
void visit(source::variable_expression *expression) override;
void visit(source::assign_statement *statement) override;
};
}
}

View File

@ -27,8 +27,6 @@ namespace source
*/
class error
{
position m_position;
protected:
/**
* Constructs an error.
@ -36,9 +34,10 @@ namespace source
* \param path Source file name.
* \param position Error position in the source text.
*/
error(const char *path, const position position);
error(const char *path, const struct position position);
public:
const struct position position;
const char *path;
virtual ~error() noexcept = default;
@ -55,7 +54,7 @@ namespace source
class name_collision final : public error
{
position previous;
const struct position previous;
std::string name;
public:
@ -66,7 +65,7 @@ namespace source
* \param previous Position of the previously defined symbol.
*/
name_collision(const std::string& name, const char *path,
const position current, const position previous);
const struct position current, const struct position previous);
std::string what() const override;
};