[PATCH] Support named values in the autocomplete feature.

Samuel Benzaquen sbenza at google.com
Tue Aug 5 11:23:53 PDT 2014


Sorry for the very long delay.
I applied your suggestions.

================
Comment at: include/clang/ASTMatchers/Dynamic/Parser.h:86
@@ +85,3 @@
+    virtual std::vector<MatcherCompletion>
+    getNamedValueCompletions(llvm::ArrayRef<ArgKind> AcceptedTypes);
+
----------------
Peter Collingbourne wrote:
> Samuel Benzaquen wrote:
> > Peter Collingbourne wrote:
> > > This approach requires a bunch of common logic to be duplicated between individual Sema implementations. Instead, you could have a virtual function in this class that returns (a const reference to) a map of named values, which would be called by this function and getNamedValue.
> > > 
> > > You might also consider changing the parser API to pass the map separately (along with Sema) to the parser. That way, you could also avoid complicating Sema too much as a result of having to allow completeExpression to take custom Semas.
> > Having this in the Sema object is following the same logic as having the matchers.
> > It allows an implementation of it to do whatever it wants. It could be backed by an in-memory std::map, be generated on demand, or by some other source.
> > Earlier, I added 'RegistrySema' because it was common to use that one.
> > I was thinking in providing a MappedValueSema, and make both of these mix-ins that the user can add to their implementations.
> > 
> > wrt duplicated logic, I added most of the required logic in the support classes (VariantValue, etc). The implementation of this method of a backing string->value map is just a few lines.
> I realize why you added this flexibility, and I sort of see the value in it, but I'm not convinced that it is necessary.
> 
> If I were designing this, I would make the std::map part of the interface to the parser, and defer the design of any additional flexibility for when it is needed, so that I'd have something concrete to base my design on. For example, it could be done incrementally on top of the std::map design by adding something to Sema that lets a client augment the contents of the map. I won't insist on you changing your current design though.
Followed your suggestion.
To make it consistent I had to remove the getNamedValue() method also. This will break clang-query temporarily.

================
Comment at: lib/ASTMatchers/Dynamic/Parser.cpp:578
@@ -545,1 +577,3 @@
 
+  // Sort by specifity, then by name.
+  std::sort(P.Completions.begin(), P.Completions.end(),
----------------
Peter Collingbourne wrote:
> Nit: specificity.
Fixed

http://reviews.llvm.org/D3509






More information about the cfe-commits mailing list