From 476b551be3f472eb24b302dafe9d7a101f7047a8 Mon Sep 17 00:00:00 2001 From: Yuka Takahashi Date: Tue, 23 May 2017 18:39:08 +0000 Subject: [PATCH] [GSoC] Shell autocompletion for clang Summary: This is a first patch for GSoC project, bash-completion for clang. To use this on bash, please run `source clang/utils/bash-autocomplete.sh`. bash-autocomplete.sh is code for bash-completion. Simple flag completion and path completion is available in this patch. Reviewers: teemperor, v.g.vassilev, ruiu, Bigcheese, efriedma Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33237 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303670 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Option/OptTable.h | 8 ++++++++ lib/Option/OptTable.cpp | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/llvm/Option/OptTable.h b/include/llvm/Option/OptTable.h index 390e52774fe..8a323a255ca 100644 --- a/include/llvm/Option/OptTable.h +++ b/include/llvm/Option/OptTable.h @@ -113,6 +113,14 @@ public: return getInfo(id).MetaVar; } + /// Find flags from OptTable which starts with Cur. + /// + /// \param [in] Cur - String prefix that all returned flags need + // to start with. + /// + /// \return The vector of flags which start with Cur. + std::vector findByPrefix(StringRef Cur) const; + /// \brief Parse a single argument; returning the new argument and /// updating Index. /// diff --git a/lib/Option/OptTable.cpp b/lib/Option/OptTable.cpp index 7eafb00855d..b00d21ec8f6 100644 --- a/lib/Option/OptTable.cpp +++ b/lib/Option/OptTable.cpp @@ -186,6 +186,20 @@ static unsigned matchOption(const OptTable::Info *I, StringRef Str, return 0; } +std::vector OptTable::findByPrefix(StringRef Cur) const { + std::vector Ret; + for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) { + if (!In.Prefixes) + continue; + for (int I = 0; In.Prefixes[I]; I++) { + std::string S = std::string(In.Prefixes[I]) + std::string(In.Name); + if (StringRef(S).startswith(Cur)) + Ret.push_back(S); + } + } + return Ret; +} + Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index, unsigned FlagsToInclude, unsigned FlagsToExclude) const { -- 2.40.0