From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4571 invoked by alias); 28 May 2014 20:31:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 4555 invoked by uid 89); 28 May 2014 20:31:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-vc0-f172.google.com Received: from mail-vc0-f172.google.com (HELO mail-vc0-f172.google.com) (209.85.220.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 28 May 2014 20:30:39 +0000 Received: by mail-vc0-f172.google.com with SMTP id ik5so9644415vcb.31 for ; Wed, 28 May 2014 13:30:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=EwciQOam3hEpeneDcjenu2QUPPvB7H5wstoi5jQcBGY=; b=bf3vm6GfBUl1CZ/MzCkbfhTURRio/PNMKw4z9evvU6gqN+pJoxRpZD5VcKohTD2fan vOtGTmwEzPDqbTER0P+81TxZ8YR1FLi3EOTgXVxf2daDrQYL/OaWRWdYlgaAJmCX4uKt 2/A5MWDHkfSavsDJJac+C56UvA/XZnPz0a/TMXkTMQtr5KgRvxAlKxNfFD7eYPnzIvDx 6gULj8fTnCEcSCudZfdoQpBxYe9JXlM/EgQOjBC6ByW0R9UFCAF1o3iCViYjGyGaBzI+ n4egvNuTGww+GEn7uvtGV5VR1e8boxgmc1SC7LBqutdxqempYNcLfGfwtl1mOzqZYdWy ytww== X-Gm-Message-State: ALoCoQmsC+vyj0CsoAtWbvIXsMm60YvP29SUzCeKsZ/6TC4fyy3DQxCEXvz5s/S+YtKmXNqVfQdX MIME-Version: 1.0 X-Received: by 10.52.125.198 with SMTP id ms6mr1810775vdb.28.1401309037677; Wed, 28 May 2014 13:30:37 -0700 (PDT) Received: by 10.52.28.230 with HTTP; Wed, 28 May 2014 13:30:37 -0700 (PDT) In-Reply-To: References: Date: Wed, 28 May 2014 20:31:00 -0000 Message-ID: Subject: Re: [Patch v18 4/4] Add xmethod support to the Python API From: Doug Evans To: Siva Chandra Cc: gdb-patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2014-05/txt/msg00702.txt.bz2 On Wed, May 28, 2014 at 12:12 PM, Siva Chandra wrote: > On Tue, May 27, 2014 at 10:41 PM, Doug Evans wrote: >> Another thing occurs to me. >> Pretty-printers are invoked, initially, via __call__, not via a "print" >> method or some such. >> It would be more python-esque if XMethodMatcher.match was renamed __call__ >> and XMethodWorker.invoke was renamed __call__. > > While I agree XMethodWorker.invoke can be removed and we could make > XMethodWorker a callable, I am not sure we want to make XMethodMatcher > a callable. I know pretty printers are callables but do not know the > reason why they are so (probably because there is an old way and a new > way of writing pretty printers and both have to be supported). For me, > a __call__ method in Python is like operator() in C++ which I feel > should be used only if it is meaningful to make the objects callable. > Even for the XMethodWorker, I preferred a method 'invoke' over making > workers callables because they are named as workers and not as > methods. The only reason I had to bring in the notion of XMethods > (which are used only for enable/disable) and XMethodWorker is because > I had to ape the pretty printer setup. I propose a slightly different > design here which does not ape the pretty printers completely but > makes it less confusing: > > 1. Have XMethodMatchers with a method named 'match'. Matchers have an > attribute 'enabled'. GDB invokes the 'match' method on registered > matchers if they are enabled. On a match, the matcher returns a > sequence of matching and enabled XMethods. See #2 to know what > XMethods are. An XMethodMatcher also has an attribute 'method', which > is a sequence of XMethods the matcher manages. This provides a way to > enable/disable individual XMethods from enable/disable commands. > 2. Have XMethods which are callables, but also have a method > 'get_arg_types'. XMethods also have an 'enabled' attribute to indicate > whether they are enabled or not. GDB calls an XMethod (they are > callables) if it determines that the XMethod is the best overload > match. By analogy, what this does is merge SubPrettyPrinter with the pretty-printer worker object. FAOD, XMethodMatcher attributes: name, enabled, methods, match XMethod attributes: name, enabled, get_arg_types, __call__ "works for me"