public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Arvydas Silanskas <nma.arvydas.silanskas@gmail.com>
To: kawa mailing list <kawa@sourceware.org>
Subject: When/how during compilation are bindings attached?
Date: Sun, 15 Nov 2020 02:57:31 +0200	[thread overview]
Message-ID: <CAPh7weBx=HFUt4QFVMAA4EJFmLoS7skpv36mur==U+=aBmC0fQ@mail.gmail.com> (raw)

I'm working with tracking of definition place for identifiers. For some
reason, found identifiers don't have binding information attached, do you
have insight why that could be? Here is standalone snippet (mostly based on
LSP in kawa source tree)

import gnu.expr.Compilation;
import gnu.expr.ExpExpVisitor;
import gnu.expr.Expression;
import gnu.expr.ReferenceExp;
import gnu.kawa.io.CharArrayInPort;
import gnu.text.SourceMessages;
import kawa.standard.Scheme;

import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;

public class TestModuleBinding {

    public static void main(String[] args) throws IOException {
        var source = new String[]{
                "(define (a) 1)",
                "(a)"
        };
        var sourceCode =
Arrays.stream(source).collect(Collectors.joining("\n"));
        int line = 2;
        int col = 2;
        var language = Scheme.getR7rsInstance();
        var inPort = CharArrayInPort.make(sourceCode);
        var sourceMessages = new SourceMessages();
        Compilation compilation = language.parse(inPort, sourceMessages,
Scheme.PARSE_FOR_EVAL);
        language.resolve(compilation);

        class FindDecl extends ExpExpVisitor<Void> {

            @Override
            protected Expression visitReferenceExp(ReferenceExp exp, Void
ignored) {
                var expLine = exp.getLineNumber();
                var expCol = exp.getColumnNumber();
                if (line == expLine && col == expCol) {
                    if (!exp.getName().equals("a"))
                        throw new RuntimeException("Expected 'a'");
                    if (exp.getBinding() == null)
                        throw new RuntimeException("Expected non-null
binding");
                }
                return super.visitReferenceExp(exp, ignored);
            }
        }
        FindDecl fd  = new FindDecl();
        var module = compilation.getModule();
        fd.visit(module, null);
    }
}

Arvydas

             reply	other threads:[~2020-11-15  0:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-15  0:57 Arvydas Silanskas [this message]
2020-11-15  2:42 ` Per Bothner
2020-11-15  8:59   ` Arvydas Silanskas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPh7weBx=HFUt4QFVMAA4EJFmLoS7skpv36mur==U+=aBmC0fQ@mail.gmail.com' \
    --to=nma.arvydas.silanskas@gmail.com \
    --cc=kawa@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).