dart-lang / macros

A Dart mono-repo for macro development.
BSD 3-Clause "New" or "Revised" License
65 stars 5 forks source link

Design high level model structure #10

Open davidmorgan opened 4 months ago

davidmorgan commented 4 months ago

In #3 it's

Model: Map<String, Library> uris Library: Map<String, Interface> scopes where Interface is expected to be replaced with a union type of more types

but this has a couple of issues :)

davidmorgan commented 4 months ago

@jakemac53

So two things here :)

The top level map, I called uris with the idea that it can hold anything in the workspace we want to refer to by URI: obviously libraries, with part files and library augmentations as the examples that we should probably be open to referring to other types of thing.

"Scopes" is not a good word, pretty much I just mean "the next obvious level of map", which more concretely might be "a place where methods, getters, variables, ... can be declared".

So in particular I want a top level "scope" for top level declarations, maybe that has "" for the name:

{
  "uris": {
    "package:foo/foo.dart": {
      "scopes": {
        "": {
          "someTopLevelDeclaration": {"properties": {"isField": true}}
        },
        "Foo": {
          "fooMethod": {"properties": {"isMethod": true}}
        }
      }
    }
  }
}

I guess what I actually mean by "scopes" is "thingsWithMembers" :)

Currently I added only Interface as a "type of scope" but obviously there are other types of thing that can have members, for example we might have "TopLevel", "Mixin", "Class", ...

Suggestions welcome :)

jakemac53 commented 4 months ago

Note that as currently specified, part files will have a different scope from the library itself. So we will need to represent them specially, if we want to for instance talk about resolving an identifier within a specific scope, the URI needs to be the exact file URI in which the declaration appears.