summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuka Takahashi <yukatkh@gmail.com>2017-07-08 17:48:59 +0000
committerYuka Takahashi <yukatkh@gmail.com>2017-07-08 17:48:59 +0000
commit609e5597294ea440f9a10102e7f1c2a00aec8687 (patch)
treeed72de107ef34f2baa09ce844322c12ff7a2a306
parented22ecfce63e19e9f51b2a2305d37ec2d240fa3b (diff)
[Bash-autocompletion] Auto complete cc1 options if -cc1 is specified
Summary: We don't want to autocomplete flags whose Flags class has `NoDriverOption` when argv[1] is not `-cc1`. Another idea for this implementation is to make --autocomplete a cc1 option and handle it in clang Frontend, by porting --autocomplete handler from Driver to Frontend, so that we can handle Driver options and CC1 options in unified manner. Differential Revision: https://reviews.llvm.org/D34770 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307479 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Driver/Driver.cpp11
-rw-r--r--test/Driver/autocomplete.c4
-rw-r--r--utils/bash-autocomplete.sh16
3 files changed, 24 insertions, 7 deletions
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 8031d78a21..42478013cc 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -1261,11 +1261,20 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
StringRef PassedFlags = A->getValue();
std::vector<std::string> SuggestedCompletions;
+ unsigned short DisableFlags = options::NoDriverOption | options::Unsupported | options::Ignored;
+ // We want to show cc1-only options only when clang is invoked as "clang -cc1".
+ // When clang is invoked as "clang -cc1", we add "#" to the beginning of an --autocomplete
+ // option so that the clang driver can distinguish whether it is requested to show cc1-only options or not.
+ if (PassedFlags[0] == '#') {
+ DisableFlags &= ~options::NoDriverOption;
+ PassedFlags = PassedFlags.substr(1);
+ }
+
if (PassedFlags.find(',') == StringRef::npos) {
// If the flag is in the form of "--autocomplete=-foo",
// we were requested to print out all option names that start with "-foo".
// For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
- SuggestedCompletions = Opts->findByPrefix(PassedFlags);
+ SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
} else {
// If the flag is in the form of "--autocomplete=foo,bar", we were
// requested to print out all option values for "-foo" that start with
diff --git a/test/Driver/autocomplete.c b/test/Driver/autocomplete.c
index f0bdcce570..e9e2e992ba 100644
--- a/test/Driver/autocomplete.c
+++ b/test/Driver/autocomplete.c
@@ -36,3 +36,7 @@
// MTHREADMODELALL: posix single
// RUN: %clang --autocomplete=-mrelocation-model, | FileCheck %s -check-prefix=MRELOCMODELALL
// MRELOCMODELALL: dynamic-no-pic pic ropi ropi-rwpi rwpi static
+// RUN: %clang --autocomplete=-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CLANG
+// MRELOCMODEL_CLANG-NOT: -mrelocation-model
+// RUN: %clang --autocomplete=#-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CC1
+// MRELOCMODEL_CC1: -mrelocation-model
diff --git a/utils/bash-autocomplete.sh b/utils/bash-autocomplete.sh
index bab193c56b..1e38bcfcaa 100644
--- a/utils/bash-autocomplete.sh
+++ b/utils/bash-autocomplete.sh
@@ -27,25 +27,29 @@ _clang()
w1="${COMP_WORDS[$cword - 1]}"
if [[ $cword > 1 ]]; then
w2="${COMP_WORDS[$cword - 2]}"
+ # Clang want to know if -cc1 or -Xclang option is specified or not, because we don't want to show
+ # cc1 options otherwise.
+ if [[ "${COMP_WORDS[1]}" == "-cc1" || "$w1" == "-Xclang" ]]; then
+ arg="#"
fi
if [[ "$cur" == -* ]]; then
# -foo<tab>
- arg="$cur"
+ arg="$arg$cur"
elif [[ "$w1" == -* && "$cur" == '=' ]]; then
# -foo=<tab>
- arg="$w1=,"
+ arg="$arg$w1=,"
elif [[ "$cur" == -*= ]]; then
# -foo=<tab>
- arg="$cur,"
+ arg="$arg$cur,"
elif [[ "$w1" == -* ]]; then
# -foo <tab> or -foo bar<tab>
- arg="$w1,$cur"
+ arg="$arg$w1,$cur"
elif [[ "$w2" == -* && "$w1" == '=' ]]; then
# -foo=bar<tab>
- arg="$w2=,$cur"
+ arg="$arg$w2=,$cur"
elif [[ ${cur: -1} != '=' && ${cur/=} != $cur ]]; then
# -foo=bar<tab>
- arg="${cur%=*}=,${cur#*=}"
+ arg="$arg${cur%=*}=,${cur#*=}"
fi
# expand ~ to $HOME