Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(82)

Issue 148045: First stage of replacing Scope with a more flexible API (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
16 years, 5 months ago by MikeSamuel
Modified:
16 years, 5 months ago
Reviewers:
DavidSarah, ihab.awad
CC:
google-caja-discuss_googlegroups.com
Base URL:
http://google-caja.googlecode.com/svn/trunk/
Visibility:
Public.

Description

This is part 5 of https://groups.google.com/group/google-caja-discuss/browse_thread/thread/50db6111ae71c2c9 We currently have a Scope class which was defined for the Rewriter scheme. For each optimization pass I've done, I've ended up writing my own scope scheme, often on top of Scope. E.g. the AlphaRenaming uses an identity map to associate extra info with scopes, and the array index optimization builds it's own scope tree, so that it can easily walk from a scope to its children. The linter uses a scoping scheme that abstracts away the decision of where declarations are introduced into scopes and which scopes they are hoisted to, so that it can make sure that scoping is consistent between JScript and other interpreters. Further changelists will unify these scoping schemes and support the following use cases: # In a rewriter to scope lazily # On an entire tree to attach a scope to each node # To generate masking errors about violations of Cajita specific invariants (such as forbidding declaration of the name "cajita") # To identify the kind of symbol -- function declaration, local function name, exception, data, globals # To collect information about declarations # To resolve references to declaration points or to scopes # To detect redelcaration # To emulate ES5 scoping rules # To emulate broken IE scoping # To collect uses of a variable # To determine whether/where a symbol is used as a LeftHandSideExpression # To collect uses in narrower scopes. # To collect the set of symbols from wider scopes. There are a few separable concerns here: # Applying scoping rules of a given variant of JS -- exception hoisting, whether function constructors' names intrude on the containing scope to introduce scopes, and collect declarations # Associating scopes with parse tree nodes Collecting usage information Please see ScopeListener for a general interface to collecting and collating Scope information. See ScopeAnalyzer for a general implementation that implements a scoping scheme, and its concrete implementations: ES5ScopeAnalyzer, JScriptScopeAnalyzer, WorstCaseScopeAnalyzer. The ScopeAnalyzerTests give an idea of how ScopeAnalyzer works. In later CLS, Scope has been rewritten to use ES5ScopeAnalyzer under the hood, and Rewriter will change to create the scopes so that it is no longer the responsibility of Rules to create and pass around scopes. Submitted @3849

Patch Set 1 #

Total comments: 40

Patch Set 2 : First stage of replacing Scope with a more flexible API #

Patch Set 3 : First stage of replacing Scope with a more flexible API #

Total comments: 9

Patch Set 4 : First stage of replacing Scope with a more flexible API #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1414 lines, -95 lines) Patch
M build.xml View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M src/com/google/caja/ancillary/opt/LocalVarRenamer.java View 1 2 3 3 chunks +3 lines, -2 lines 0 comments Download
M src/com/google/caja/parser/js/CajoledModule.java View 4 chunks +4 lines, -4 lines 0 comments Download
M src/com/google/caja/parser/js/Operation.java View 1 2 3 1 chunk +5 lines, -0 lines 0 comments Download
A src/com/google/caja/parser/js/scope/AbstractScope.java View 1 2 1 chunk +48 lines, -0 lines 0 comments Download
A src/com/google/caja/parser/js/scope/ES5ScopeAnalyzer.java View 1 chunk +28 lines, -0 lines 0 comments Download
A src/com/google/caja/parser/js/scope/JScriptScopeAnalyzer.java View 1 chunk +23 lines, -0 lines 0 comments Download
A src/com/google/caja/parser/js/scope/ScopeAnalyzer.java View 1 2 3 1 chunk +396 lines, -0 lines 0 comments Download
A src/com/google/caja/parser/js/scope/ScopeListener.java View 1 2 1 chunk +135 lines, -0 lines 0 comments Download
A src/com/google/caja/parser/js/scope/ScopeType.java View 1 1 chunk +90 lines, -0 lines 0 comments Download
A src/com/google/caja/parser/js/scope/WorstCaseScopeAnalyzer.java View 1 chunk +30 lines, -0 lines 0 comments Download
M src/com/google/caja/parser/quasiliteral/Scope.java View 1 2 3 7 chunks +11 lines, -67 lines 0 comments Download
M src/com/google/caja/parser/quasiliteral/SyntheticRuleSet.java View 1 2 3 3 chunks +10 lines, -3 lines 0 comments Download
M src/com/google/caja/render/SourceSpansRenderer.java View 3 chunks +18 lines, -16 lines 0 comments Download
A tests/com/google/caja/parser/js/scope/ScopeAnalyzerTest.java View 1 2 1 chunk +610 lines, -0 lines 0 comments Download
M tests/com/google/caja/parser/quasiliteral/testModule.out.js View 1 chunk +1 line, -1 line 0 comments Download
M tests/com/google/caja/render/ssp-golden.txt View 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 10
MikeSamuel
16 years, 5 months ago (2009-11-04 20:04:42 UTC) #1
MikeSamuel
On 2009/11/04 20:04:42, MikeSamuel wrote: > ping
16 years, 5 months ago (2009-11-06 22:54:05 UTC) #2
ihab.awad
Some detailed comments inline, but general comments below. I have not finished going through ScopeAnalyzer.java ...
16 years, 5 months ago (2009-11-10 00:39:07 UTC) #3
ihab.awad
LGTM++ The one comment I am really wondering about is why ScopeAnalyzer is parameterized on ...
16 years, 5 months ago (2009-11-17 06:14:57 UTC) #4
MikeSamuel
On 2009/11/17 06:14:57, ihab.awad wrote: > LGTM++ > > The one comment I am really ...
16 years, 5 months ago (2009-11-17 18:14:23 UTC) #5
MikeSamuel
On 2009/11/17 06:14:57, ihab.awad wrote: > LGTM++ > > The one comment I am really ...
16 years, 5 months ago (2009-11-17 18:14:27 UTC) #6
MikeSamuel
http://codereview.appspot.com/148045/diff/1/11 File src/com/google/caja/parser/js/scope/AbstractScope.java (right): http://codereview.appspot.com/148045/diff/1/11#newcode22 src/com/google/caja/parser/js/scope/AbstractScope.java:22: public interface AbstractScope { On 2009/11/10 00:39:07, ihab.awad wrote: ...
16 years, 5 months ago (2009-11-17 19:26:17 UTC) #7
ihab.awad
LGTM++ http://codereview.appspot.com/148045/diff/1/2 File tests/com/google/caja/parser/js/scope/ScopeAnalyzerTest.java (right): http://codereview.appspot.com/148045/diff/1/2#newcode245 tests/com/google/caja/parser/js/scope/ScopeAnalyzerTest.java:245: " var arguments = (function (arguments) { return ...
16 years, 5 months ago (2009-11-17 19:31:08 UTC) #8
DavidSarah
http://codereview.appspot.com/148045/diff/5017/6006 File src/com/google/caja/parser/js/scope/ScopeAnalyzer.java (right): http://codereview.appspot.com/148045/diff/5017/6006#newcode72 src/com/google/caja/parser/js/scope/ScopeAnalyzer.java:72: * containing scope. Add "A symbol is not considered ...
16 years, 5 months ago (2009-11-17 21:14:45 UTC) #9
MikeSamuel
16 years, 5 months ago (2009-11-17 22:42:51 UTC) #10
On 2009/11/17 21:14:45, DavidSarah wrote:
> http://codereview.appspot.com/148045/diff/5017/6006
> File src/com/google/caja/parser/js/scope/ScopeAnalyzer.java (right):
> 
> http://codereview.appspot.com/148045/diff/5017/6006#newcode72
> src/com/google/caja/parser/js/scope/ScopeAnalyzer.java:72: *       containing
> scope.
> Add "A symbol is not considered to mask itself."
> 
> http://codereview.appspot.com/148045/diff/5017/6006#newcode237
> src/com/google/caja/parser/js/scope/ScopeAnalyzer.java:237: private
ScopeTree<S>
> defSite(String symbolName, ScopeTree<S> useSite) {
> "defSite" sounds like a verb. How about "definingSite"?
> 
> http://codereview.appspot.com/148045/diff/5017/6007
> File src/com/google/caja/parser/js/scope/ScopeListener.java (right):
> 
> http://codereview.appspot.com/148045/diff/5017/6007#newcode63
> src/com/google/caja/parser/js/scope/ScopeListener.java:63: * {@code e = 3}
> affects the exception variable.
> Crumbs, hadn't thought of that. Now I remember why I didn't allow multiple
> declaration in Jacaranda.
> 
> How does this interact with
> http://code.google.com/p/google-caja/wiki/CatchBlocksScopeBleed -- presumably
> the variables get merged in IE (so a 'duplicate' event should be fired)?
> 
> http://codereview.appspot.com/148045/diff/5017/6007#newcode92
> src/com/google/caja/parser/js/scope/ScopeListener.java:92: * @param defSite
the
> scope in which id is defined or null in the case
> Rename to "definingSite" here (and below) also if you decide to rename it in
> ScopeAnalyzer.
> 
> http://codereview.appspot.com/148045/diff/5017/6009
> File src/com/google/caja/parser/js/scope/ScopeType.java (right):
> 
> http://codereview.appspot.com/148045/diff/5017/6009#newcode77
> src/com/google/caja/parser/js/scope/ScopeType.java:77: public final boolean
> isDeclarationContainer;
> document
> 
> http://codereview.appspot.com/148045/diff/5017/6009#newcode79
> src/com/google/caja/parser/js/scope/ScopeType.java:79: ScopeType() {
> this(false); }
> document
> 
> http://codereview.appspot.com/148045/diff/5017/6009#newcode80
> src/com/google/caja/parser/js/scope/ScopeType.java:80: ScopeType(boolean
> isDeclarationContainer) {
> document
> 
> http://codereview.appspot.com/148045/diff/5017/6009#newcode84
> src/com/google/caja/parser/js/scope/ScopeType.java:84: public static ScopeType
> forNode(ParseTreeNode n) {
> document
> 
> http://codereview.appspot.com/148045/diff/5017/6002
> File tests/com/google/caja/parser/js/scope/ScopeAnalyzerTest.java (right):
> 
> http://codereview.appspot.com/148045/diff/5017/6002#newcode34
> tests/com/google/caja/parser/js/scope/ScopeAnalyzerTest.java:34: public class
> ScopeAnalyzerTest extends CajaTestCase {
> This doesn't test that JScriptScopeAnalyzer or WorstCaseScopeAnalyzer give the
> same results as ES5ScopeAnalyzer in the cases where they are expected to be
the
> same. Perhaps define a helper method that will test all three on a given test
> case.

D-S H, I believe I have addressed all these comments in issue 156050.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b