Mercurial > hg > CbC > CbC_gcc
diff gcc/go/gofrontend/types.h @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
line wrap: on
line diff
--- a/gcc/go/gofrontend/types.h Fri Oct 27 22:46:09 2017 +0900 +++ b/gcc/go/gofrontend/types.h Thu Oct 25 07:37:49 2018 +0900 @@ -563,30 +563,26 @@ verify() { return this->do_verify(); } - // Return true if two types are identical. If ERRORS_ARE_IDENTICAL, - // returns that an erroneous type is identical to any other type; - // this is used to avoid cascading errors. If this returns false, + // Bit flags to pass to are_identical and friends. + + // Treat error types as their own distinct type. Sometimes we + // ignore error types--treat them as identical to every other + // type--to avoid cascading errors. + static const int COMPARE_ERRORS = 1; + + // Compare struct field tags when comparing structs. We ignore + // struct field tags for purposes of type conversion. + static const int COMPARE_TAGS = 2; + + // Compare aliases: treat an alias to T as distinct from T. + static const int COMPARE_ALIASES = 4; + + // Return true if two types are identical. If this returns false, // and REASON is not NULL, it may set *REASON. static bool - are_identical(const Type* lhs, const Type* rhs, bool errors_are_identical, + are_identical(const Type* lhs, const Type* rhs, int flags, std::string* reason); - // An argument to are_identical_cmp_tags, indicating whether or not - // to compare struct field tags. - enum Cmp_tags { - COMPARE_TAGS, - IGNORE_TAGS - }; - - // Return true if two types are identical. This is like the - // are_identical function, but also takes a CMP_TAGS argument - // indicating whether to compare struct tags. Otherwise the - // parameters are as for are_identical. - static bool - are_identical_cmp_tags(const Type* lhs, const Type* rhs, - Cmp_tags, bool errors_are_identical, - std::string* reason); - // Return true if two types are compatible for use in a binary // operation, other than a shift, comparison, or channel send. This // is an equivalence relation. @@ -648,7 +644,7 @@ // Types which are equivalent according to are_identical will have // the same hash code. unsigned int - hash_for_method(Gogo*) const; + hash_for_method(Gogo*, int) const; // Return the type classification. Type_classification @@ -676,6 +672,15 @@ const Type* forwarded() const; + // Return the type skipping any alias definitions and any defined + // forward declarations. This is like forwarded, but also + // recursively expands alias definitions to the aliased type. + Type* + unalias(); + + const Type* + unalias() const; + // Return true if this is a basic type: a type which is not composed // of other types, and is not void. bool @@ -907,6 +912,15 @@ is_unsafe_pointer_type() const { return this->points_to() != NULL && this->points_to()->is_void_type(); } + // Return a version of this type with any expressions copied, but + // only if copying the expressions will affect the size of the type. + // If there are no such expressions in the type (expressions can + // only occur in array types), just return the same type. If any + // expressions can not affect the size of the type, just return the + // same type. + Type* + copy_expressions(); + // Look for field or method NAME for TYPE. Return an expression for // it, bound to EXPR. static Expression* @@ -1064,7 +1078,7 @@ { return true; } virtual unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; virtual Btype* do_get_backend(Gogo*) = 0; @@ -1363,14 +1377,18 @@ bool in_heap_; }; -// Type hash table operations. +// Type hash table operations, treating aliases as identical to the +// types that they alias. class Type_hash_identical { public: unsigned int operator()(const Type* type) const - { return type->hash_for_method(NULL); } + { + return type->hash_for_method(NULL, + Type::COMPARE_ERRORS | Type::COMPARE_TAGS); + } }; class Type_identical @@ -1378,7 +1396,11 @@ public: bool operator()(const Type* t1, const Type* t2) const - { return Type::are_identical(t1, t2, false, NULL); } + { + return Type::are_identical(t1, t2, + Type::COMPARE_ERRORS | Type::COMPARE_TAGS, + NULL); + } }; // An identifier with a type. @@ -1480,7 +1502,7 @@ // Traverse types. int - traverse(Traverse*); + traverse(Traverse*) const; // Return the first and last elements. Typed_identifier& @@ -1706,7 +1728,7 @@ { return true; } unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; Btype* do_get_backend(Gogo*); @@ -1792,7 +1814,7 @@ { return true; } unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; Btype* do_get_backend(Gogo*); @@ -1870,7 +1892,7 @@ { return true; } unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; Btype* do_get_backend(Gogo*); @@ -2018,8 +2040,8 @@ // Whether this type is the same as T. bool - is_identical(const Function_type* t, bool ignore_receiver, - Cmp_tags, bool errors_are_identical, std::string*) const; + is_identical(const Function_type* t, bool ignore_receiver, int flags, + std::string*) const; // Record that this is a varargs function. void @@ -2065,6 +2087,11 @@ Btype* get_backend_fntype(Gogo*); + // Return whether this is a Backend_function_type. + virtual bool + is_backend_function_type() const + { return false; } + protected: int do_traverse(Traverse*); @@ -2079,7 +2106,7 @@ { return false; } unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; Btype* do_get_backend(Gogo*); @@ -2158,6 +2185,12 @@ : Function_type(receiver, parameters, results, location) { } + // Return whether this is a Backend_function_type. This overrides + // Function_type::is_backend_function_type. + bool + is_backend_function_type() const + { return true; } + protected: Btype* do_get_backend(Gogo* gogo) @@ -2202,7 +2235,7 @@ { return true; } unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; Btype* do_get_backend(Gogo*); @@ -2424,6 +2457,11 @@ field_count() const { return this->fields_->size(); } + // Location of struct definition. + Location + location() const + { return this->location_; } + // Push a new field onto the end of the struct. This is used when // building a closure variable. void @@ -2444,8 +2482,7 @@ // Whether this type is identical with T. bool - is_identical(const Struct_type* t, Cmp_tags, - bool errors_are_identical) const; + is_identical(const Struct_type* t, int) const; // Return whether NAME is a local field which is not exported. This // is only used for better error reporting. @@ -2464,7 +2501,7 @@ has_any_methods() const { return this->all_methods_ != NULL; } - // Return the methods for tihs type. This should only be called + // Return the methods for this type. This should only be called // after the finalize_methods pass. const Methods* methods() const @@ -2556,7 +2593,7 @@ do_in_heap(); unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; Btype* do_get_backend(Gogo*); @@ -2650,8 +2687,7 @@ // Whether this type is identical with T. bool - is_identical(const Array_type* t, Cmp_tags, - bool errors_are_identical) const; + is_identical(const Array_type* t, int) const; // Return an expression for the pointer to the values in an array. Expression* @@ -2733,7 +2769,7 @@ { return this->length_ == NULL || this->element_type_->in_heap(); } unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; Btype* do_get_backend(Gogo*); @@ -2816,8 +2852,7 @@ // Whether this type is identical with T. bool - is_identical(const Map_type* t, Cmp_tags, - bool errors_are_identical) const; + is_identical(const Map_type* t, int) const; // Import a map type. static Map_type* @@ -2826,6 +2861,9 @@ static Type* make_map_type_descriptor_type(); + // This must be in sync with libgo/go/runtime/hashmap.go. + static const int bucket_size = 8; + protected: int do_traverse(Traverse*); @@ -2848,7 +2886,7 @@ } unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; Btype* do_get_backend(Gogo*); @@ -2867,7 +2905,6 @@ private: // These must be in sync with libgo/go/runtime/hashmap.go. - static const int bucket_size = 8; static const int max_key_size = 128; static const int max_val_size = 128; static const int max_zero_size = 1024; @@ -2934,8 +2971,7 @@ // Whether this type is identical with T. bool - is_identical(const Channel_type* t, Cmp_tags, - bool errors_are_identical) const; + is_identical(const Channel_type* t, int) const; // Import a channel type. static Channel_type* @@ -2945,7 +2981,7 @@ make_chan_type_descriptor_type(); static Type* - select_type(int ncases); + select_case_type(); protected: int @@ -2964,7 +3000,7 @@ { return true; } unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; Btype* do_get_backend(Gogo*); @@ -3023,8 +3059,15 @@ return this->all_methods_ == NULL; } - // Return the list of methods. This will return NULL for an empty - // interface. + // Return the list of locally defined methos. This will return NULL + // for an empty interface. Embedded interfaces will appear in this + // list as an entry with no name. + const Typed_identifier_list* + local_methods() const + { return this->parse_methods_; } + + // Return the list of all methods. This will return NULL for an + // empty interface. const Typed_identifier_list* methods() const; @@ -3054,8 +3097,7 @@ // Whether this type is identical with T. REASON is as in // implements_interface. bool - is_identical(const Interface_type* t, Cmp_tags, - bool errors_are_identical) const; + is_identical(const Interface_type* t, int) const; // Whether we can assign T to this type. is_identical is known to // be false. @@ -3115,7 +3157,7 @@ { return true; } unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; Btype* do_get_backend(Gogo*); @@ -3149,6 +3191,20 @@ bool assume_identical(const Interface_type*, const Interface_type*) const; + struct Bmethods_map_entry + { + Btype *btype; + bool is_placeholder; + }; + + // A mapping from Interface_type to the backend type of its bmethods_, + // used to ensure that the backend representation of identical types + // is identical. + typedef Unordered_map_hash(const Interface_type*, Bmethods_map_entry, + Type_hash_identical, Type_identical) Bmethods_map; + + static Bmethods_map bmethods_map; + // The list of methods associated with the interface from the // parser. This will be NULL for the empty interface. This may // include unnamed interface types. @@ -3193,8 +3249,8 @@ interface_method_tables_(NULL), pointer_interface_method_tables_(NULL), location_(location), named_btype_(NULL), dependencies_(), is_alias_(false), is_visible_(true), is_error_(false), in_heap_(true), - is_placeholder_(false), is_converted_(false), is_circular_(false), - is_verified_(false), seen_(false), seen_in_compare_is_identity_(false), + is_placeholder_(false), is_converted_(false), is_verified_(false), + seen_(false), seen_in_compare_is_identity_(false), seen_in_get_backend_(false), seen_alias_(false) { } @@ -3295,12 +3351,6 @@ is_valid() const { return !this->is_error_; } - // Whether this is a circular type: a pointer or function type that - // refers to itself, which is not possible in C. - bool - is_circular() const - { return this->is_circular_; } - // Return the base type for this type. Type* named_base(); @@ -3395,10 +3445,6 @@ void append_mangled_type_name(Gogo*, bool use_alias, std::string*) const; - // Export the type. - void - export_named_type(Export*, const std::string& name) const; - // Import a named type. static void import_named_type(Import*, Named_type**); @@ -3432,7 +3478,7 @@ { return this->in_heap_ && this->type_->in_heap(); } unsigned int - do_hash_for_method(Gogo*) const; + do_hash_for_method(Gogo*, int) const; Btype* do_get_backend(Gogo*); @@ -3507,9 +3553,6 @@ // Whether this type has been converted to the backend // representation. Implies that is_placeholder_ is false. bool is_converted_; - // Whether this is a pointer or function type which refers to the - // type itself. - bool is_circular_; // Whether this type has been verified. bool is_verified_; // In a recursive operation such as has_pointer, this flag is used @@ -3598,8 +3641,8 @@ { return this->real_type()->in_heap(); } unsigned int - do_hash_for_method(Gogo* gogo) const - { return this->real_type()->hash_for_method(gogo); } + do_hash_for_method(Gogo* gogo, int flags) const + { return this->real_type()->hash_for_method(gogo, flags); } Btype* do_get_backend(Gogo* gogo);