Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5728A200C32 for ; Thu, 23 Feb 2017 00:07:23 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 55BF0160B72; Wed, 22 Feb 2017 23:07:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 729FB160B62 for ; Thu, 23 Feb 2017 00:07:22 +0100 (CET) Received: (qmail 43462 invoked by uid 500); 22 Feb 2017 23:07:21 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 43452 invoked by uid 99); 22 Feb 2017 23:07:21 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Feb 2017 23:07:21 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 2364A18E16A for ; Wed, 22 Feb 2017 23:07:21 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.219 X-Spam-Level: X-Spam-Status: No, score=-0.219 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=asert-com-au.20150623.gappssmtp.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id I5LC2IVXOLOk for ; Wed, 22 Feb 2017 23:07:19 +0000 (UTC) Received: from mail-it0-f51.google.com (mail-it0-f51.google.com [209.85.214.51]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 322495FAD4 for ; Wed, 22 Feb 2017 23:07:18 +0000 (UTC) Received: by mail-it0-f51.google.com with SMTP id h10so146460821ith.1 for ; Wed, 22 Feb 2017 15:07:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asert-com-au.20150623.gappssmtp.com; s=20150623; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to; bh=NFMjeeTgmoBnjNb/Ira4/fL1CIidmVFFtUIEWHnsbwQ=; b=SbStqmAzNLwyVOLZ761WL6nwydr5+fp90LRBBt/qHWvy7KsK0AcOmStlUHNUrupOY6 iFN1uF5cYUUY39E51bZqRXkQcyaXJWsL6KpT0FgLG/r9g1GRJwQvWRHhpg/2bEzrBRGK y/azMWJGyCxcxK9QT7xslqMMK/18OWhFR0/lkNNU4hUxgSUfL1ydTiAYgZFxn3CpdII7 7aPnZJZuz441QFHxEr0nTKC6HAvb9+O6JZu9eBBxw7bpGsH9jODh44q14XTPSO66CKZv pn53w/1iw/bX47m5BRZk1vfkzpjVRzlUezTRjLaBZUti4zpcuhurrh9SolO3rio/ijag qLSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to; bh=NFMjeeTgmoBnjNb/Ira4/fL1CIidmVFFtUIEWHnsbwQ=; b=Kj2j2u5TXRG18oJpDpyvlyX82y4N+NqQRqrkarg9DV/QQWQsPrBQel0BdxV3OhpBIQ sTZk1DN+eHBaslUPIl7QQL1sX8/1pncQj499tz7KOCqOV7TCRnQqoe1r12ZYEwGgbhCD EpyMtiRUZLMLw6Pvqu3OPsQOAY5aqcc8F5zjv/jSzDjfBIY49uaQ8ErpMH8VUibLsDMh QMl/EBLR5hFhycKHk6MB6QgN9XO5WD2rLivEmlf0xWEaWtQBgqhRohk3FKQ9KnXK2xLp IZodqQDyupwPZXwjwtvg4/c/aEY3V86q0PltgeUd5hRANIsdYLcPcCP4w7GvLrY4vYJu Y68w== X-Gm-Message-State: AMke39lWF0jwopA8u1PTtizgbW92+Cf06jwSsh3QhDArvj0vBiwV5UeNw6UFijEmwDfXK2dTQejBDiffTV77KQ== X-Received: by 10.36.147.71 with SMTP id y68mr599264itd.85.1487804838051; Wed, 22 Feb 2017 15:07:18 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.138.155 with HTTP; Wed, 22 Feb 2017 15:07:17 -0800 (PST) Reply-To: paulk@asert.com.au In-Reply-To: References: <5866C1A8.6020809@gmx.org> <337fe01e-3af4-5345-cd5f-8836cd565a94@ameritech.net> <10564426-910c-7a84-1cdb-c6f3a75c57b1@gmx.org> <2af0d74f-d064-1bd2-d44e-830e7a49c086@ameritech.net> <64a993eb-9897-ad16-0844-1d6e67564392@ameritech.net> From: Paul King Date: Thu, 23 Feb 2017 09:07:17 +1000 Message-ID: Subject: Re: help with an AST To: users@groovy.apache.org Content-Type: text/plain; charset=UTF-8 archived-at: Wed, 22 Feb 2017 23:07:23 -0000 You can probably use ASSIGN rather than ASSIGNMENT_OPERATOR which is meant to be a type class though I am not sure we really use it. On Thu, Feb 23, 2017 at 2:08 AM, Ed Clark wrote: > I can report progress. Turns out there were two problems. > > The error message that I was getting concerning : "=" > not being supported had to do with how I built the token for the > BinaryExpression. > > I was using: > > new BinaryExpression( > sV, // a VariableExpression > new Token( Types.ASSIGNMENT_OPERATOR, '=', -1, -1), > rtV // another VariableExpression > > When I examined the AST that was generated after the transform, I noticed > that > the corresponding token mentioned: . But, if I looked > at > a separate AST from hand written code that matched the output of the > transform, > that token mentioned: symbol "=". Not the same > > After a quick Google search I hit upon: > > new BinaryExpression( > sV, // a VariableExpression > Token.newSymbol( '=', -1, -1), > rtV // another VariableExpression > > This gets rid of the error! I'm not sure why the first way to build a Token > doesn't > work. I'll also note that there are a number code examples using the first > approach that turn up in a web search. In any case, I'm happy to have one > that > does work. > > At this point, applying the VariableScopeVisitor that Paul suggested seems > to > clean up my remaining problem with scoping issues. > > Yeah! > > On to the next wall, how to generate a table of method signatures (at > transform time) > for all the methods defined in the user written classes (marked with my > annotation)... > > Many thanks, > > Ed > > > > On 02/20/2017 12:06 PM, Ed Clark wrote: > > Ok, poking around the source for VariableScopeVisitor didn't provide me > with any insights. It did lead me to try > VariableScopeVisitor scopeVisitor = new VariableScopeVisitor( source, > true) > but I still get the error: > BUG! exception in phase 'class generation' in source unit > 'CtxTest2.groovy' Operation: (: "=" ) not supported > > One possible twist that I noticed, is if I run my test script under > groovyConsole > I get one error message. But, if I run the equivalent code (with a 'main') > as a > standalone groovy file, the error message is printed twice. Not sure what > that > indicates. > > But, it is tied to my inserted statements. If I comment out the statement > insertions, the compiler is happy. So I'm guessing I'm building bad > statements. > > What is the proper way to build a statement that set a property that is > defined in a base class (i.e., extended by a class that gets instantiated)? > > I'm currently doing: > > VariableExpression cV = new VariableExpression( '__currentContext') > // PropertyExpression cP = new PropertyExpression( cnStack[ -1], > '__currentContext') > ExpressionStatement currStmt = new ExpressionStatement( > new BinaryExpression( > cV, // also tried assigning to cP > instead of cV > new Token(Types.ASSIGNMENT_OPERATOR, "=", -1, -1), > cnStack[ -1] > // new MethodCallExpression( > VariableExpression.THIS_EXPRESSION, > // new > ConstantExpression( 'getDelegate'), > // new > ArgumentListExpress()) > ) > ) > blockStatement.statements.add( 0, currStmt) > > (I've tried with and without the VariableScopeVisitor call, and with and > without > a call to "blockStatement.variableScope.putReferencedClassVariable( cv)".) > > So, does this look like the correct way to set the value of a property that > is > inherited from a base class? > > (The somewhat frustrating thing is the resultant AST with the inserted > statements > looks correct after the transform (up through the Instruction Selection > phase). > In fact, if I type that code into a separate groovyConsole, it runs.) > > > Thanks for your time, > > Ed > > > > On 02/16/2017 04:41 PM, Paul King wrote: > > Do you have something like: > > VariableScopeVisitor scopeVisitor = new VariableScopeVisitor(source) > scopeVisitor.visitClass(cNode) > > for each of your closure(s)? Where cNode is a closure's classNode? > > Cheers, Paul. > >