diff options
Diffstat (limited to 'gcc/type-stringifier.hpp')
-rw-r--r-- | gcc/type-stringifier.hpp | 113 |
1 files changed, 85 insertions, 28 deletions
diff --git a/gcc/type-stringifier.hpp b/gcc/type-stringifier.hpp index 33f5cb359cb..98e0546b8d7 100644 --- a/gcc/type-stringifier.hpp +++ b/gcc/type-stringifier.hpp @@ -1,6 +1,7 @@ #pragma once #include "type-walker.hpp" +#include <string> class TypeStringifier : public TypeWalker { @@ -8,10 +9,11 @@ private: std::string _stringification; static std::string get_type_identifier(const_tree t); + static std::string get_field_identifier(const_tree t); - void _stringifiy_simple(const_tree t); - void _stringifiy_aggregate_pre(const_tree t); - void _stringifiy_aggregate_post(const_tree t); + void _stringify_simple(const_tree t); + void _stringify_aggregate_pre(const_tree t); + void _stringify_aggregate_post(const_tree t); void _stringify_fm_pre(const_tree t); void _stringify_fm_post(const_tree t); @@ -29,109 +31,119 @@ private: virtual void _walk_record_post(const_tree t); virtual void _walk_union_pre(const_tree t); virtual void _walk_union_post(const_tree t); + virtual void _walk_field_post(const_tree t); + virtual void _walk_return_pre(const_tree t); + virtual void _walk_return_post(const_tree t); + virtual void _walk_args_pre(const_tree t); + virtual void _walk_args_post(const_tree t); + virtual void _walk_arg_post(const_tree t); virtual void _walk_method_pre(const_tree t); virtual void _walk_method_post(const_tree t); virtual void _walk_function_pre(const_tree t); virtual void _walk_function_post(const_tree t); public: - std::string stringifiy(const_tree t); + std::string stringify(const_tree t); TypeStringifier() {}; }; std::string TypeStringifier::stringify(const_tree t) { + _stringification.clear(); gcc_assert(t); walk(t); + return _stringification; } -virtual void +void TypeStringifier::_walk_void_pre(const_tree t) { - _stringifiy_simple(t); + _stringify_simple(t); } -virtual void +void TypeStringifier::_walk_integer_pre(const_tree t) { - _stringifiy_simple(t); + _stringify_simple(t); } -virtual void +void TypeStringifier::_walk_real_pre(const_tree t) { - _stringifiy_simple(t); + _stringify_simple(t); } -virtual void +void TypeStringifier::_walk_fixed_point_pre(const_tree t) { - _stringifiy_simple(t); + _stringify_simple(t); } -virtual void +void TypeStringifier::_walk_complex_pre(const_tree t) { - _stringifiy_simple(t); + _stringify_simple(t); } -virtual void +void TypeStringifier::_walk_offset_pre(const_tree t) { - _stringifiy_simple(t); + _stringify_simple(t); } -virtual void +void TypeStringifier::_walk_boolean_pre(const_tree t) { - _stringifiy_simple(t); + _stringify_simple(t); } void -TypeStringifier::_stringifiy_simple(const_tree t) +TypeStringifier::_stringify_simple(const_tree t) { gcc_assert(t); const enum tree_code code = TREE_CODE(t); this->_stringification += std::string(get_tree_code_name(code)); } -virtual void +void TypeStringifier::_walk_pointer_post(const_tree t) { this->_stringification += std::string("*"); } -virtual void +void TypeStringifier::_walk_array_post(const_tree t) { this->_stringification += std::string("[]"); } -virtual void +void TypeStringifier::_walk_reference_post(const_tree t) { this->_stringification += std::string("&"); } -virtual void +void TypeStringifier::_walk_union_pre(const_tree t) { + this->_stringification += std::string(" union "); _stringify_aggregate_pre(t); } -virtual void +void TypeStringifier::_walk_union_post(const_tree t) { _stringify_aggregate_post(t); } -virtual void +void TypeStringifier::_walk_record_pre(const_tree t) { + this->_stringification += std::string(" record "); _stringify_aggregate_pre(t); } -virtual void +void TypeStringifier::_walk_record_post(const_tree t) { _stringify_aggregate_post(t); @@ -150,6 +162,12 @@ TypeStringifier::_stringify_aggregate_post(const_tree t) } void +TypeStringifier::_walk_field_post(const_tree t) +{ + this->_stringification += std::string(" ") + TypeStringifier::get_field_identifier(t) + std::string(";"); +} + +void TypeStringifier::_walk_method_pre(const_tree t) { _stringify_fm_pre(t); @@ -176,7 +194,6 @@ TypeStringifier::_walk_function_post(const_tree t) void TypeStringifier::_stringify_fm_pre(const_tree t) { - this->_stringification += std::string("function { "); } @@ -186,7 +203,37 @@ TypeStringifier::_stringify_fm_post(const_tree t) this->_stringification += std::string("}"); } -static std::string +void +TypeStringifier::_walk_return_pre(const_tree t) +{ + this->_stringification += std::string("("); +} + +void +TypeStringifier::_walk_return_post(const_tree t) +{ + this->_stringification += std::string(")"); +} + +void +TypeStringifier::_walk_args_pre(const_tree t) +{ + this->_stringification += std::string("("); +} + +void +TypeStringifier::_walk_args_post(const_tree t) +{ + this->_stringification += std::string(")"); +} + +void +TypeStringifier::_walk_arg_post(const_tree t) +{ + this->_stringification += std::string(", "); +} + +std::string TypeStringifier::get_type_identifier(const_tree t) { tree name = TYPE_NAME(t); @@ -201,3 +248,13 @@ TypeStringifier::get_type_identifier(const_tree t) return std::string(identifier_ptr); } +std::string +TypeStringifier::get_field_identifier(const_tree t) +{ + assert_is_type(t, FIELD_DECL); + const_tree decl_name = DECL_NAME(t); + if (!decl_name) return std::string(""); + + const char* identifier = IDENTIFIER_POINTER(decl_name); + return std::string(identifier); +} |