Implement string comparison

This commit is contained in:
2025-02-12 00:56:21 +01:00
parent 33aca4cc07
commit cd949c4be7
11 changed files with 287 additions and 321 deletions

View File

@ -1,3 +1,20 @@
/* Builtin definitions.
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 "config.h"
#include "system.h"
#include "coretypes.h"

View File

@ -36,7 +36,6 @@ namespace gcc
{
class generic_visitor final : public boot::empty_visitor
{
std::forward_list<block_scope> scope;
tree current_expression{ NULL_TREE };
std::shared_ptr<boot::symbol_table<tree>> symbol_map;
@ -44,22 +43,19 @@ namespace gcc
tree build_type(boot::type_expression& type);
void enter_scope();
tree_symbol_mapping leave_scope();
tree leave_scope();
tree lookup(const std::string& name);
void make_if_branch(boot::conditional_statements& branch, tree goto_endif);
bool is_numeric_type(tree type);
tree build_arithmetic_operation(boot::binary_expression *expression,
tree_code operator_code, tree left, tree right);
tree build_comparison_operation(boot::binary_expression *expression,
tree_code operator_code, tree left, tree right);
tree build_logic_operation(boot::binary_expression *expression,
tree_code operator_code, tree left, tree right);
tree build_equality_operation(boot::binary_expression *expression,
tree_code operator_code, tree left, tree right);
tree build_equality_operation(boot::binary_expression *expression, tree left, tree right);
public:
generic_visitor(std::shared_ptr<boot::symbol_table<tree>> symbol_table);

View File

@ -35,6 +35,7 @@ namespace gcc
{
bool is_pointer_type(tree type);
bool is_integral_type(tree type);
bool is_numeric_type(tree type);
/**
* \param lhs Left hand value.
@ -43,59 +44,9 @@ namespace gcc
*/
bool are_compatible_pointers(tree lhs, tree rhs);
class tree_chain_base
{
protected:
tree first{};
tree last{};
public:
tree head();
void append(tree t);
protected:
virtual void chain(tree t) = 0;
};
class tree_chain final : public tree_chain_base
{
protected:
void chain(tree t) override;
};
class block_chain final : public tree_chain_base
{
protected:
void chain(tree t) override;
};
class tree_symbol_mapping final
{
tree m_bind_expression;
tree m_block;
public:
tree_symbol_mapping(tree bind_expression, tree block);
tree bind_expression();
tree block();
};
class block_scope
{
tree m_statement_list{ NULL_TREE };
std::forward_list<std::pair<tree, tree>> defers;
public:
tree_chain variables;
block_chain blocks;
block_scope();
void append_statement(tree statement_tree);
void defer(tree statement_tree);
tree chain_defer();
};
void append_statement(tree statement_tree);
void defer(tree statement_tree);
tree chain_defer();
tree do_pointer_arithmetic(boot::binary_operator binary_operator, tree left, tree right);
tree build_binary_operation(bool condition, boot::binary_expression *expression,

View File

@ -1,3 +1,20 @@
/* Language-dependent hooks for Elna.
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/>. */
enum elna_tree_index
{
ELNA_TI_INT_TYPE,
@ -11,6 +28,7 @@ enum elna_tree_index
};
extern GTY(()) tree elna_global_trees[ELNA_TI_MAX];
extern GTY(()) hash_map<nofree_string_hash, tree> *elna_global_decls;
#define elna_int_type_node elna_global_trees[ELNA_TI_INT_TYPE]
#define elna_word_type_node elna_global_trees[ELNA_TI_WORD_TYPE]
@ -30,18 +48,35 @@ struct GTY (()) lang_decl
{
};
struct GTY (()) binding_level
struct GTY (()) defer_scope
{
// A chain of all declarations in this binding level.
tree names;
tree defer_block;
tree try_statements;
};
struct GTY ((chain_next ("%h.level_chain"))) binding_level
{
// A block chain is needed to call defer statements beloning to each block.
tree blocks;
// Parent level.
struct binding_level *level_chain;
// Statements before the first defer has been seen.
tree statement_list;
// Defer statement coupled with statements following it.
vec<defer_scope, va_gc> *defers;
};
struct GTY (()) language_function
{
// Local variables and constants.
tree names;
// Lexical scope.
struct binding_level *binding_level;
};
#define f_binding_level DECL_STRUCT_FUNCTION(current_function_decl)->language->binding_level
extern tree pushdecl(tree);
extern tree getdecls(void);
#define f_names DECL_STRUCT_FUNCTION(current_function_decl)->language->names