It looks like the current code does: 1. Find top-level names in this file. 2. ...
11 years, 4 months ago
(2012-12-20 19:28:23 UTC)
#2
It looks like the current code does:
1. Find top-level names in this file.
2. Reject examples using those names.
3. Ignore mentions of predefined identifiers like int.
4. Assume all other undefined names refer to imports.
5. Introduce those imports.
This seems backward to me. Among other things it does not handle uses of
top-level names declared elsewhere.
Instead of all this guessing, why not:
1. Look at import list to make list of packages (assume last element = package
name).
2. Make list of top-level names used by code.
3. Exclude predefined names (int)
4. Exclude imported packages (but remember that the import is needed).
5. Reject any other use of an unknown name.
Russ
The second list seems incomplete. How does it determine which are top-level names? How about: ...
11 years, 4 months ago
(2012-12-20 19:48:25 UTC)
#3
The second list seems incomplete. How does it determine which are top-level
names?
How about:
1. Walk the example function, noting:
1a. names declared inside the function
1b. otherwise resolved names
1c. unresolved names
2. If anything in 1c, bail.
3. Exclude predefined identifiers from 1b
4. Exclude imported packages from 1b (but note them)
5. If anything remains in 1b, bail
6. Synthesize new file, import list, and main function.
?
> How about: > > 1. Walk the example function, noting: > 1a. names declared ...
11 years, 4 months ago
(2012-12-20 19:57:15 UTC)
#4
> How about:
>
> 1. Walk the example function, noting:
> 1a. names declared inside the function
> 1b. otherwise resolved names
> 1c. unresolved names
> 2. If anything in 1c, bail.
> 3. Exclude predefined identifiers from 1b
> 4. Exclude imported packages from 1b (but note them)
> 5. If anything remains in 1b, bail
> 6. Synthesize new file, import list, and main function.
I see: I was assuming that id.Obj==nil for top-level names, but it's
only nil for top-level unresolved names. So you do need some way to
tell whether a resolved name points to a declared top-level name or
not. That's fine.
Note that if you are looking at a single file, predefined identifiers
like bool are in 1c (they have id.Obj==nil) not 1b. They are not
resolved because you need information from the other files to make the
final decision: if you have var int = 1 in some other file in the same
package, then 'int' refers to that.
Russ
On 21 December 2012 06:57, Russ Cox <rsc@golang.org> wrote: > That's fine. So should I ...
11 years, 4 months ago
(2012-12-20 20:00:27 UTC)
#5
On 21 December 2012 06:57, Russ Cox <rsc@golang.org> wrote:
> That's fine.
So should I just stick with what I have, or rewrite a bit to get what I
proposed?
The one thing I haven't tried yet is looking for declarations. Shouldn't be
a big deal.
*** Submitted as https://code.google.com/p/go/source/detail?r=41b82b6b2ccd *** go/doc: don't synthesize code for examples that are not self-contained ...
11 years, 4 months ago
(2012-12-20 20:06:47 UTC)
#7
Issue 6974045: code review 6974045: go/doc: don't synthesize code for examples that are not...
(Closed)
Created 11 years, 4 months ago by adg
Modified 11 years, 4 months ago
Reviewers:
Base URL:
Comments: 0