@@ -1018,6 +1018,26 @@ CommandInterpreter::VerifyUserMultiwordCmdPath(Args &path, bool leaf_is_command,
1018
1018
return cur_as_multi;
1019
1019
}
1020
1020
1021
+ CommandObjectSP CommandInterpreter::GetFrameLanguageCommand () const {
1022
+ if (auto frame_sp = GetExecutionContext ().GetFrameSP ()) {
1023
+ auto frame_language = Language::GetPrimaryLanguage (
1024
+ frame_sp->GuessLanguage ().AsLanguageType ());
1025
+
1026
+ auto it = m_command_dict.find (" language" );
1027
+ if (it != m_command_dict.end ()) {
1028
+ // The root "language" command.
1029
+ CommandObjectSP language_cmd_sp = it->second ;
1030
+
1031
+ if (auto *plugin = Language::FindPlugin (frame_language)) {
1032
+ // "cplusplus", "objc", etc.
1033
+ auto lang_name = plugin->GetPluginName ();
1034
+ return language_cmd_sp->GetSubcommandSPExact (lang_name);
1035
+ }
1036
+ }
1037
+ }
1038
+ return {};
1039
+ }
1040
+
1021
1041
CommandObjectSP
1022
1042
CommandInterpreter::GetCommandSP (llvm::StringRef cmd_str, bool include_aliases,
1023
1043
bool exact, StringList *matches,
@@ -1050,11 +1070,20 @@ CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str, bool include_aliases,
1050
1070
command_sp = pos->second ;
1051
1071
}
1052
1072
1073
+ // The `language` subcommand ("language objc", "language cplusplus", etc).
1074
+ CommandObjectMultiword *lang_subcmd = nullptr ;
1075
+ if (!command_sp) {
1076
+ if (auto subcmd_sp = GetFrameLanguageCommand ()) {
1077
+ lang_subcmd = subcmd_sp->GetAsMultiwordCommand ();
1078
+ command_sp = subcmd_sp->GetSubcommandSPExact (cmd_str);
1079
+ }
1080
+ }
1081
+
1053
1082
if (!exact && !command_sp) {
1054
1083
// We will only get into here if we didn't find any exact matches.
1055
1084
1056
1085
CommandObjectSP user_match_sp, user_mw_match_sp, alias_match_sp,
1057
- real_match_sp;
1086
+ real_match_sp, lang_match_sp ;
1058
1087
1059
1088
StringList local_matches;
1060
1089
if (matches == nullptr )
@@ -1064,6 +1093,7 @@ CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str, bool include_aliases,
1064
1093
unsigned int num_alias_matches = 0 ;
1065
1094
unsigned int num_user_matches = 0 ;
1066
1095
unsigned int num_user_mw_matches = 0 ;
1096
+ unsigned int num_lang_matches = 0 ;
1067
1097
1068
1098
// Look through the command dictionaries one by one, and if we get only one
1069
1099
// match from any of them in toto, then return that, otherwise return an
@@ -1121,20 +1151,39 @@ CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str, bool include_aliases,
1121
1151
user_mw_match_sp = pos->second ;
1122
1152
}
1123
1153
1154
+ if (lang_subcmd) {
1155
+ num_lang_matches =
1156
+ AddNamesMatchingPartialString (lang_subcmd->GetSubcommandDictionary (),
1157
+ cmd_str, *matches, descriptions);
1158
+ }
1159
+
1160
+ if (num_lang_matches == 1 ) {
1161
+ cmd.assign (matches->GetStringAtIndex (num_cmd_matches + num_alias_matches +
1162
+ num_user_matches +
1163
+ num_user_mw_matches));
1164
+
1165
+ auto &lang_dict = lang_subcmd->GetSubcommandDictionary ();
1166
+ auto pos = lang_dict.find (cmd);
1167
+ if (pos != lang_dict.end ())
1168
+ lang_match_sp = pos->second ;
1169
+ }
1170
+
1124
1171
// If we got exactly one match, return that, otherwise return the match
1125
1172
// list.
1126
1173
1127
1174
if (num_user_matches + num_user_mw_matches + num_cmd_matches +
1128
- num_alias_matches ==
1175
+ num_alias_matches + num_lang_matches ==
1129
1176
1 ) {
1130
1177
if (num_cmd_matches)
1131
1178
return real_match_sp;
1132
1179
else if (num_alias_matches)
1133
1180
return alias_match_sp;
1134
1181
else if (num_user_mw_matches)
1135
1182
return user_mw_match_sp;
1136
- else
1183
+ else if (num_user_matches)
1137
1184
return user_match_sp;
1185
+ else
1186
+ return lang_match_sp;
1138
1187
}
1139
1188
} else if (matches && command_sp) {
1140
1189
matches->AppendString (cmd_str);
0 commit comments