elna/gcc/elna-diagnostic.cc

129 lines
3.5 KiB
C++
Raw Normal View History

/* Elna frontend specific diagnostic routines.
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/>. */
2024-12-27 23:38:25 +01:00
#include "elna/gcc/elna-diagnostic.h"
2024-12-29 22:28:53 +01:00
#include "elna/gcc/elna-tree.h"
2025-02-11 01:37:55 +01:00
#include "elna/gcc/elna1.h"
2024-12-27 23:38:25 +01:00
2024-12-28 14:33:35 +01:00
namespace elna
2024-12-27 23:38:25 +01:00
{
2024-12-28 14:33:35 +01:00
namespace gcc
2024-12-27 23:38:25 +01:00
{
2025-01-31 09:46:17 +01:00
location_t get_location(const boot::position *position)
2024-12-27 23:38:25 +01:00
{
2024-12-28 14:33:35 +01:00
linemap_line_start(line_table, position->line, 0);
return linemap_position_for_column(line_table, position->column);
2024-12-27 23:38:25 +01:00
}
2024-12-28 14:33:35 +01:00
std::string print_aggregate_name(tree type, const std::string& kind_name)
{
if (TYPE_IDENTIFIER(type) == NULL_TREE)
{
return kind_name;
}
else
{
return std::string(IDENTIFIER_POINTER(TYPE_IDENTIFIER(type)));
}
}
std::string print_type(tree type)
2024-12-27 23:38:25 +01:00
{
2024-12-28 14:33:35 +01:00
gcc_assert(TYPE_P(type));
2025-02-11 01:37:55 +01:00
if (type == elna_int_type_node)
2024-12-28 14:33:35 +01:00
{
return "Int";
}
2025-02-11 01:37:55 +01:00
else if (type == elna_word_type_node)
{
return "Word";
}
2025-02-11 01:37:55 +01:00
else if (type == elna_bool_type_node)
2024-12-28 14:33:35 +01:00
{
2024-12-31 18:10:34 +01:00
return "Bool";
2024-12-28 14:33:35 +01:00
}
2025-02-11 01:37:55 +01:00
else if (type == elna_byte_type_node)
{
return "Byte";
}
else if (type == elna_float_type_node)
2024-12-29 22:28:53 +01:00
{
2024-12-31 18:10:34 +01:00
return "Float";
2024-12-29 22:28:53 +01:00
}
2025-02-11 01:37:55 +01:00
else if (type == elna_char_type_node)
2025-01-01 23:02:19 +01:00
{
return "Char";
}
2025-02-12 20:47:47 +01:00
else if (type == elna_string_type_node)
{
return "String";
}
else if (is_void_type(type)) // For procedures without a return type.
{
return "()";
}
2025-01-10 23:17:18 +01:00
else if (is_pointer_type(type))
{
return std::string("^" + print_type(TREE_TYPE(type)));
2025-02-12 20:47:47 +01:00
}
else if (is_procedure_type(type))
{
std::string output = "proc(";
tree parameter_type = TYPE_ARG_TYPES(type);
while (parameter_type != NULL_TREE)
{
output += print_type(TREE_VALUE(parameter_type));
parameter_type = TREE_CHAIN(parameter_type);
if (TREE_VALUE(parameter_type) == void_type_node)
{
break;
}
else
{
output += ", ";
}
}
output += ')';
if (!is_void_type(TREE_TYPE(type)))
{
output += " -> " + print_type(TREE_TYPE(type));
}
return output;
2025-01-10 23:17:18 +01:00
}
2025-02-12 20:47:47 +01:00
else if (is_array_type(type))
2025-01-07 14:37:30 +01:00
{
return "array";
}
2025-01-18 21:30:11 +01:00
else if (TREE_CODE(type) == RECORD_TYPE)
{
return print_aggregate_name(type, "record");
2025-01-18 21:30:11 +01:00
}
else if (TREE_CODE(type) == UNION_TYPE)
{
return print_aggregate_name(type, "union");
2025-01-18 21:30:11 +01:00
}
2024-12-28 14:33:35 +01:00
else
{
return "<<unknown-type>>";
}
2025-02-12 20:47:47 +01:00
gcc_unreachable();
2024-12-27 23:38:25 +01:00
}
}
2024-12-28 14:33:35 +01:00
}