Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Issue 10669035: Don't lose the expected precedence during && compilation. (Closed)

Created:
8 years, 6 months ago by floitsch
Modified:
8 years, 5 months ago
CC:
reviews_dartlang.org, ngeoffray
Visibility:
Public.

Description

Don't lose the expected precedence during && compilation. When transforming if (foo) bar; to foo && bar make sure that bar is compiled with the correct precedence. In particular avoid foo && toto = 499; instead of foo && (toto = 499). Fixes issue 3862. Committed: https://code.google.com/p/dart/source/detail?r=9157

Patch Set 1 #

Patch Set 2 : Add test. #

Patch Set 3 : Protect non-assignments in define. #

Total comments: 12

Patch Set 4 : Address comments #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+75 lines, -6 lines) Patch
M lib/compiler/implementation/ssa/codegen.dart View 1 2 3 5 chunks +44 lines, -6 lines 1 comment Download
A tests/language/if_and_test.dart View 1 1 chunk +31 lines, -0 lines 0 comments Download

Messages

Total messages: 5 (0 generated)
floitsch
The test is currently not triggering, but future CLs would make this test fail without ...
8 years, 6 months ago (2012-06-26 16:35:22 UTC) #1
floitsch
There was still a case in 'define' that overwrote the expected precedence. Fixed now.
8 years, 6 months ago (2012-06-26 17:12:40 UTC) #2
Lasse Reichstein Nielsen
LGTM http://codereview.chromium.org/10669035/diff/4002/lib/compiler/implementation/ssa/codegen.dart File lib/compiler/implementation/ssa/codegen.dart (right): http://codereview.chromium.org/10669035/diff/4002/lib/compiler/implementation/ssa/codegen.dart#newcode397 lib/compiler/implementation/ssa/codegen.dart:397: // need parenthesis. I.e., this only expects to ...
8 years, 6 months ago (2012-06-27 08:53:57 UTC) #3
floitsch
http://codereview.chromium.org/10669035/diff/4002/lib/compiler/implementation/ssa/codegen.dart File lib/compiler/implementation/ssa/codegen.dart (right): http://codereview.chromium.org/10669035/diff/4002/lib/compiler/implementation/ssa/codegen.dart#newcode397 lib/compiler/implementation/ssa/codegen.dart:397: // need parenthesis. On 2012/06/27 08:53:58, Lasse Reichstein Nielsen ...
8 years, 5 months ago (2012-06-27 11:18:24 UTC) #4
sra1
8 years, 5 months ago (2012-06-29 02:03:57 UTC) #5
https://chromiumcodereview.appspot.com/10669035/diff/10001/lib/compiler/imple...
File lib/compiler/implementation/ssa/codegen.dart (right):

https://chromiumcodereview.appspot.com/10669035/diff/10001/lib/compiler/imple...
lib/compiler/implementation/ssa/codegen.dart:587:
withPrecedence(JSPrecedence.ASSIGNMENT_PRECEDENCE, () {
It bothers me that there are >200 places in this file that say JSPrecedence.XXX
withPrecedence simplifies a few cases and I'm sure it could be used more widely.
 However, the closure passed to withPrecedence has an allocation cost and is
really just an ad-hoc temporary AST that knows only how to emit itself.

The visitor pattern seems error-prone and suffers from being excessively
state-sensitive.

Why not embrace the idea of a temporary AST and generate all expressions via a
lightweight AST for the specific task of emitting well formed expressions? 
There would be no mention of precedence except in the code that emits ASTs. 
Since about half of AST nodes are leaves, a String should be permitted as a
terminal AST, assumed to have a high (primary?) precedence.

Powered by Google App Engine
This is Rietveld 408576698