| 1 | /* |
| 2 | * %injeqt copyright begin% |
| 3 | * Copyright 2014 Rafał Malinowski ([email protected]) |
| 4 | * %injeqt copyright end% |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include "type-relations.h"cxx . . $ `<file>/src/internal/type-relations.h`/ |
| 22 | |
| 23 | #include <injeqt/exception/ambiguous-types.h>cxx . . $ `<file>/include/injeqt/exception/ambiguous-types.h`/ |
| 24 | |
| 25 | #include "interfaces-utils.h"cxx . . $ `<file>/src/internal/interfaces-utils.h`/ |
| 26 | |
| 27 | #include <map> |
| 28 | |
| 29 | namespace injeqtcxx . . $ injeqt/ { namespace internalcxx . . $ injeqt/internal/ { |
| 30 | |
| 31 | type_relationscxx . . $ injeqt/internal/type_relations#::type_relationscxx . . $ injeqt/internal/type_relations#type_relations(49f6e7a06ebc5aa8).() |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | type_relationscxx . . $ injeqt/internal/type_relations#::type_relationscxx . . $ injeqt/internal/type_relations#type_relations(a71c920939daffde).(implemented_by_mappingcxx . . $ injeqt/internal/implemented_by_mapping# unique, typescxx . . $ injeqt/internal/types# ambiguous) : |
| 36 | _uniquecxx . . $ injeqt/internal/type_relations#_unique.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(unique)}, |
| 37 | _ambiguouscxx . . $ injeqt/internal/type_relations#_ambiguous.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(ambiguous)} |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | const implemented_by_mappingcxx . . $ injeqt/internal/implemented_by_mapping# & type_relationscxx . . $ injeqt/internal/type_relations#::uniquecxx . . $ injeqt/internal/type_relations#unique(f204e9055a5335f3).() const |
| 42 | { |
| 43 | return _uniquecxx . . $ injeqt/internal/type_relations#_unique.; |
| 44 | } |
| 45 | |
| 46 | const typescxx . . $ injeqt/internal/types# & type_relationscxx . . $ injeqt/internal/type_relations#::ambiguouscxx . . $ injeqt/internal/type_relations#ambiguous(e96f08e6bae3c6ec).() const |
| 47 | { |
| 48 | return _ambiguouscxx . . $ injeqt/internal/type_relations#_ambiguous.; |
| 49 | } |
| 50 | |
| 51 | type_relationscxx . . $ injeqt/internal/type_relations# make_type_relationscxx . . $ injeqt/internal/make_type_relations(c4fcecab799fa482).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<typecxx . . $ injeqt/v1/type#> &main_types) |
| 52 | { |
| 53 | auto type_count = stdcxx . . $ std/map#map(3d8f9cfb6064bed1).::mapcxx . . $ std/map#<typecxx . . $ injeqt/v1/type#, stdcxx . . $ std/::size_tcxx . . $ std/size_t#>{}; |
| 54 | auto implemented_by_type = stdcxx . . $ std/map#map(3d8f9cfb6064bed1).::mapcxx . . $ std/map#<typecxx . . $ injeqt/v1/type#, typecxx . . $ injeqt/v1/type#>{}; |
| 55 | |
| 56 | for (auto &&main_type : main_types) |
| 57 | { |
| 58 | auto interface_types = extract_interfacescxx . . $ injeqt/internal/extract_interfaces(859a62e7a8dc5225).(main_type); |
| 59 | for (auto &&interface_type : interface_types) |
| 60 | { |
| 61 | type_count[cxx . . $ std/map#`operator[]`(bbd415b616967878).interface_type]++; |
| 62 | implemented_by_type.insertcxx . . $ std/map#insert(274b9441a76f0de8).({cxx . . $ std/pair#pair(13c11f7bd0e7e3d2).interface_type, main_type}); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | auto unique = stdcxx . . $ std/vector#vector(b1ea180184b47f03).::vectorcxx . . $ std/vector#<implemented_bycxx . . $ injeqt/internal/implemented_by#>{}; |
| 67 | auto ambiguous = stdcxx . . $ std/vector#vector(b1ea180184b47f03).::vectorcxx . . $ std/vector#<typecxx . . $ injeqt/v1/type#>{}; |
| 68 | for (auto &&counted_type : type_count) |
| 69 | if (counted_type.secondcxx . . $ std/pair#second. == 1) |
| 70 | unique.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(implemented_bycxx . . $ injeqt/internal/implemented_by#implemented_by(4db51c5aea7c0a3b).{counted_type.firstcxx . . $ std/pair#first., implemented_by_type.atcxx . . $ std/map#at(bbd415b616967878).(counted_type.firstcxx . . $ std/pair#first.)}); |
| 71 | else if (counted_type.secondcxx . . $ std/pair#second. > 1) |
| 72 | ambiguous.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(counted_type.firstcxx . . $ std/pair#first.); |
| 73 | |
| 74 | return type_relationscxx . . $ injeqt/internal/type_relations#type_relations(a71c920939daffde).{implemented_by_mappingcxx . . $ injeqt/internal/sorted_unique_vector#sorted_unique_vector(26e8deb829554aa).{uniquecxx . . $ std/vector#vector(a1201200cf0efa42).}, typescxx . . $ injeqt/internal/sorted_unique_vector#sorted_unique_vector(26e8deb829554aa).{ambiguouscxx . . $ std/vector#vector(a1201200cf0efa42).}}; |
| 75 | } |
| 76 | |
| 77 | void validate_non_ambiguouscxx . . $ injeqt/internal/validate_non_ambiguous(cc2d613cdd36498c).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<typecxx . . $ injeqt/v1/type#> &types, const type_relationscxx . . $ injeqt/internal/type_relations# &relations) |
| 78 | { |
| 79 | for (auto &&t : types) |
| 80 | { |
| 81 | auto message = stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{}; |
| 82 | if (relations.ambiguouscxx . . $ injeqt/internal/type_relations#ambiguous(e96f08e6bae3c6ec).().containscxx . . $ injeqt/internal/sorted_unique_vector#contains(83b2481dfe9844ed).(t)) |
| 83 | { |
| 84 | message.appendcxx . . $ std/__cxx11/basic_string#append(c0b47be1fddc0e75).(t.namecxx . . $ injeqt/v1/type#name(219584694fe2b248).()); |
| 85 | message.appendcxx . . $ std/__cxx11/basic_string#append(978ca1133b5f6e74).("\n"); |
| 86 | } |
| 87 | |
| 88 | if (!message.emptycxx . . $ std/__cxx11/basic_string#empty(50ce9a9e25b4a850).()) |
| 89 | throw exceptioncxx . . $ injeqt/v1/exception/ambiguous_types#ambiguous_types(8d4ab0a187bf9331).::ambiguous_typescxx . . $ injeqt/v1/exception/ambiguous_types#{messagecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).}; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | }} |