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

Side by Side Diff: frog/frogsh

Issue 8729018: Fixing string compile-time constant evaluation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | frog/gen.dart » ('j') | frog/gen.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env node 1 #!/usr/bin/env node
2 // ********** Library dart:core ************** 2 // ********** Library dart:core **************
3 // ********** Natives dart:core ************** 3 // ********** Natives dart:core **************
4 /** 4 /**
5 * Generates a dynamic call stub for a function. 5 * Generates a dynamic call stub for a function.
6 * Our goal is to create a stub method like this on-the-fly: 6 * Our goal is to create a stub method like this on-the-fly:
7 * function($0, $1, capture) { this($0, $1, true, capture); } 7 * function($0, $1, capture) { this($0, $1, true, capture); }
8 * 8 *
9 * This stub then replaces the dynamic one on Function, with one that is 9 * This stub then replaces the dynamic one on Function, with one that is
10 * specialized for that particular function, taking into account its default 10 * specialized for that particular function, taking into account its default
(...skipping 13922 matching lines...) Expand 10 before | Expand all | Expand 10 after
13933 if ($notnull_bool(x.get$isConst()) && $notnull_bool(y.get$isConst())) { 13933 if ($notnull_bool(x.get$isConst()) && $notnull_bool(y.get$isConst())) {
13934 var value = (kind == 35/*TokenKind.AND*/) ? $notnull_bool(x.get$actualValu e()) && $notnull_bool(y.get$actualValue()) : $notnull_bool(x.get$actualValue()) || $notnull_bool(y.get$actualValue()); 13934 var value = (kind == 35/*TokenKind.AND*/) ? $notnull_bool(x.get$actualValu e()) && $notnull_bool(y.get$actualValue()) : $notnull_bool(x.get$actualValue()) || $notnull_bool(y.get$actualValue());
13935 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, v alue, ('' + value), node.span); 13935 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, v alue, ('' + value), node.span);
13936 } 13936 }
13937 return new Value($globals.world.nonNullBool, code, node.span, true); 13937 return new Value($globals.world.nonNullBool, code, node.span, true);
13938 } 13938 }
13939 else if (kind == 50/*TokenKind.EQ_STRICT*/ || kind == 51/*TokenKind.NE_STRICT* /) { 13939 else if (kind == 50/*TokenKind.EQ_STRICT*/ || kind == 51/*TokenKind.NE_STRICT* /) {
13940 var x = this.visitValue(node.x); 13940 var x = this.visitValue(node.x);
13941 var y = this.visitValue(node.y); 13941 var y = this.visitValue(node.y);
13942 if ($notnull_bool(x.get$isConst()) && $notnull_bool(y.get$isConst())) { 13942 if ($notnull_bool(x.get$isConst()) && $notnull_bool(y.get$isConst())) {
13943 var value = kind == 50/*TokenKind.EQ_STRICT*/ ? $eq(x.get$actualValue(), y .get$actualValue()) : $ne(x.get$actualValue(), y.get$actualValue()); 13943 var xVal = x.get$actualValue();
13944 var yVal = y.get$actualValue();
13945 if ($notnull_bool(x.get$type().get$isString()) && $notnull_bool(y.get$type ().get$isString()) && $notnull_bool($ne(xVal.$index(0), yVal.$index(0)))) {
13946 if ($notnull_bool($eq(xVal.$index(0), '"'))) {
13947 xVal = xVal.substring$2(1, xVal.length - 1);
13948 yVal = toDoubleQuote($assert_String(yVal.substring$2(1, yVal.length - 1)));
13949 }
13950 else {
13951 xVal = toDoubleQuote($assert_String(xVal.substring$2(1, xVal.length - 1)));
13952 yVal = yVal.substring$2(1, yVal.length - 1);
13953 }
13954 }
13955 print(("" + xVal + " vs " + yVal));
13956 var value = kind == 50/*TokenKind.EQ_STRICT*/ ? $eq(xVal, yVal) : $ne(xVal , yVal);
13944 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, v alue, ("" + value), node.span); 13957 return EvaluatedValue.EvaluatedValue$factory($globals.world.nonNullBool, v alue, ("" + value), node.span);
13945 } 13958 }
13946 if ($notnull_bool($eq(x.get$code(), 'null')) || $notnull_bool($eq(y.get$code (), 'null'))) { 13959 if ($notnull_bool($eq(x.get$code(), 'null')) || $notnull_bool($eq(y.get$code (), 'null'))) {
13947 var op = node.op.toString().substring(0, 2); 13960 var op = node.op.toString().substring(0, 2);
13948 return new Value($globals.world.nonNullBool, ('' + x.get$code() + ' ' + op + ' ' + y.get$code()), node.span, true); 13961 return new Value($globals.world.nonNullBool, ('' + x.get$code() + ' ' + op + ' ' + y.get$code()), node.span, true);
13949 } 13962 }
13950 else { 13963 else {
13951 return new Value($globals.world.nonNullBool, ('' + x.get$code() + ' ' + no de.op + ' ' + y.get$code()), node.span, true); 13964 return new Value($globals.world.nonNullBool, ('' + x.get$code() + ' ' + no de.op + ' ' + y.get$code()), node.span, true);
13952 } 13965 }
13953 } 13966 }
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
14329 var u = (item && item.is$UnaryExpression()); 14342 var u = (item && item.is$UnaryExpression());
14330 return u.op.kind == 16/*TokenKind.INCR*/ || u.op.kind == 17/*TokenKind.DECR* /; 14343 return u.op.kind == 16/*TokenKind.INCR*/ || u.op.kind == 17/*TokenKind.DECR* /;
14331 } 14344 }
14332 else { 14345 else {
14333 return false; 14346 return false;
14334 } 14347 }
14335 } 14348 }
14336 MethodGenerator.prototype.visitLiteralExpression = function(node) { 14349 MethodGenerator.prototype.visitLiteralExpression = function(node) {
14337 var $0; 14350 var $0;
14338 var type = node.type.type; 14351 var type = node.type.type;
14339 $assert($ne(type, null), "type != null", "gen.dart", 2250, 12); 14352 $assert($ne(type, null), "type != null", "gen.dart", 2265, 12);
14340 if (!!(($0 = node.value) && $0.is$List)) { 14353 if (!!(($0 = node.value) && $0.is$List)) {
14341 var items = []; 14354 var items = [];
14342 var $list = node.value; 14355 var $list = node.value;
14343 for (var $i = node.value.iterator$0(); $i.hasNext$0(); ) { 14356 for (var $i = node.value.iterator$0(); $i.hasNext$0(); ) {
14344 var item = $i.next$0(); 14357 var item = $i.next$0();
14345 var val = this.visitValue((item && item.is$lang_Expression())); 14358 var val = this.visitValue((item && item.is$lang_Expression()));
14346 val.invoke$4(this, 'toString', item, Arguments.get$EMPTY()); 14359 val.invoke$4(this, 'toString', item, Arguments.get$EMPTY());
14347 var code = val.get$code(); 14360 var code = val.get$code();
14348 if ((item instanceof BinaryExpression) || (item instanceof ConditionalExpr ession) || (item instanceof PostfixExpression) || $notnull_bool(this._isUnaryInc rement((item && item.is$lang_Expression())))) { 14361 if ((item instanceof BinaryExpression) || (item instanceof ConditionalExpr ession) || (item instanceof PostfixExpression) || $notnull_bool(this._isUnaryInc rement((item && item.is$lang_Expression())))) {
14349 code = ('(' + code + ')'); 14362 code = ('(' + code + ')');
14350 } 14363 }
14351 if ($notnull_bool($eq(items.length, 0)) || ($notnull_bool($ne(code, "''")) && $notnull_bool($ne(code, '""')))) { 14364 if ($notnull_bool($eq(items.length, 0)) || ($notnull_bool($ne(code, "''")) && $notnull_bool($ne(code, '""')))) {
14352 items.add$1(code); 14365 items.add$1(code);
14353 } 14366 }
14354 } 14367 }
14355 return new Value(type, ('(' + Strings.join((items && items.is$List_String()) , " + ") + ')'), node.span, true); 14368 return new Value(type, ('(' + Strings.join((items && items.is$List_String()) , " + ") + ')'), node.span, true);
14356 } 14369 }
14357 var text = node.text; 14370 var text = node.text;
14358 if ($notnull_bool(type.get$isString())) { 14371 if ($notnull_bool(type.get$isString())) {
14359 if ($notnull_bool(text.startsWith$1('@'))) { 14372 if ($notnull_bool(text.startsWith$1('@'))) {
14360 text = MethodGenerator._escapeString(parseStringLiteral($assert_String(tex t))); 14373 text = MethodGenerator._escapeString(parseStringLiteral($assert_String(tex t)));
14361 text = ('"' + text + '"'); 14374 text = ('"' + text + '"');
14362 } 14375 }
14363 else if ($notnull_bool(isMultilineString($assert_String(text)))) { 14376 else if ($notnull_bool(isMultilineString($assert_String(text)))) {
14364 text = parseStringLiteral($assert_String(text)); 14377 text = parseStringLiteral($assert_String(text));
14365 text = text.replaceAll$2('\n', '\\n'); 14378 text = text.replaceAll$2('\n', '\\n');
14366 text = text.replaceAll$2('"', '\\"'); 14379 text = toDoubleQuote($assert_String(text));
14367 text = ('"' + text + '"'); 14380 text = ('"' + text + '"');
14368 } 14381 }
14369 if (text !== node.text) { 14382 if (text !== node.text) {
14370 node.value = text; 14383 node.value = text;
14371 node.text = $assert_String(text); 14384 node.text = $assert_String(text);
14372 } 14385 }
14373 } 14386 }
14374 return EvaluatedValue.EvaluatedValue$factory((type && type.is$lang_Type()), no de.value, node.text, null); 14387 return EvaluatedValue.EvaluatedValue$factory((type && type.is$lang_Type()), no de.value, node.text, null);
14375 } 14388 }
14376 MethodGenerator.prototype.visitPostfixExpression$1 = function($0) { 14389 MethodGenerator.prototype.visitPostfixExpression$1 = function($0) {
(...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after
16176 return EvaluatedValue.EvaluatedValue$factory(this.get$inferredResult(), va lue, ("" + value), node.span); 16189 return EvaluatedValue.EvaluatedValue$factory(this.get$inferredResult(), va lue, ("" + value), node.span);
16177 } 16190 }
16178 } 16191 }
16179 else if ($notnull_bool(this.declaringType.get$isString())) { 16192 else if ($notnull_bool(this.declaringType.get$isString())) {
16180 if (this.name == '\$index') { 16193 if (this.name == '\$index') {
16181 return new Value(this.declaringType, ('' + target.code + '[' + argsCode.$i ndex(0) + ']'), node.span, true); 16194 return new Value(this.declaringType, ('' + target.code + '[' + argsCode.$i ndex(0) + ']'), node.span, true);
16182 } 16195 }
16183 else if (this.name == '\$add') { 16196 else if (this.name == '\$add') {
16184 if ($notnull_bool(allConst)) { 16197 if ($notnull_bool(allConst)) {
16185 var val0 = target.get$dynamic().get$actualValue(); 16198 var val0 = target.get$dynamic().get$actualValue();
16199 var quote0 = val0.$index(0);
16186 val0 = val0.substring$2(1, val0.length - 1); 16200 val0 = val0.substring$2(1, val0.length - 1);
16187 var val1 = args.values.$index(0).get$dynamic().get$actualValue(); 16201 var val1 = args.values.$index(0).get$dynamic().get$actualValue();
16202 var quote1 = null;
16188 if ($notnull_bool(args.values.$index(0).get$type().get$isString())) { 16203 if ($notnull_bool(args.values.$index(0).get$type().get$isString())) {
16204 quote1 = val1.$index(0);
16189 val1 = val1.substring$2(1, val1.length - 1); 16205 val1 = val1.substring$2(1, val1.length - 1);
16190 } 16206 }
16191 var value = ('' + val0 + val1); 16207 var value;
16192 value = '"' + value.replaceAll$2('"', '\\"') + '"'; 16208 if ($notnull_bool($eq(quote0, quote1)) || $notnull_bool(quote1 == null)) {
16209 value = ('' + quote0 + val0 + val1 + quote0);
16210 }
16211 else if ($notnull_bool($eq(quote0, '"'))) {
16212 $assert($eq(quote1, "'"), "quote1 == \"'\"", "member.dart", 1197, 20);
16213 value = ('' + quote0 + val0 + toDoubleQuote($assert_String(val1)) + qu ote0);
16214 }
16215 else {
16216 $assert($eq(quote1, '"'), "quote1 == '\"'", "member.dart", 1200, 20);
16217 value = ('' + quote1 + toDoubleQuote($assert_String(val0)) + val1 + qu ote1);
16218 }
16193 return EvaluatedValue.EvaluatedValue$factory($globals.world.stringType, value, $assert_String(value), node.span); 16219 return EvaluatedValue.EvaluatedValue$factory($globals.world.stringType, value, $assert_String(value), node.span);
16194 } 16220 }
16195 return new Value(this.declaringType, ('' + target.code + ' + ' + argsCode. $index(0)), node.span, true); 16221 return new Value(this.declaringType, ('' + target.code + ' + ' + argsCode. $index(0)), node.span, true);
16196 } 16222 }
16197 } 16223 }
16198 else if ($notnull_bool(this.declaringType.get$isNative())) { 16224 else if ($notnull_bool(this.declaringType.get$isNative())) {
16199 if (this.name == '\$index') { 16225 if (this.name == '\$index') {
16200 return new Value(this.returnType, ('' + target.code + '[' + argsCode.$inde x(0) + ']'), node.span, true); 16226 return new Value(this.returnType, ('' + target.code + '[' + argsCode.$inde x(0) + ']'), node.span, true);
16201 } 16227 }
16202 else if (this.name == '\$setindex') { 16228 else if (this.name == '\$setindex') {
(...skipping 7411 matching lines...) Expand 10 before | Expand all | Expand 10 after
23614 values.add(map.$index(k)); 23640 values.add(map.$index(k));
23615 } 23641 }
23616 return values; 23642 return values;
23617 } 23643 }
23618 function isMultilineString(text) { 23644 function isMultilineString(text) {
23619 return text.startsWith('"""') || text.startsWith("'''"); 23645 return text.startsWith('"""') || text.startsWith("'''");
23620 } 23646 }
23621 function isRawMultilineString(text) { 23647 function isRawMultilineString(text) {
23622 return text.startsWith('@"""') || text.startsWith("@'''"); 23648 return text.startsWith('@"""') || text.startsWith("@'''");
23623 } 23649 }
23650 function toDoubleQuote(s) {
23651 return s.replaceAll('"', '\\"').replaceAll("\\'", "'");
23652 }
23624 function parseStringLiteral(lit) { 23653 function parseStringLiteral(lit) {
23625 if (lit.startsWith('@')) { 23654 if (lit.startsWith('@')) {
23626 if ($notnull_bool(isRawMultilineString(lit))) { 23655 if ($notnull_bool(isRawMultilineString(lit))) {
23627 return stripLeadingNewline(lit.substring(4, lit.length - 3)); 23656 return stripLeadingNewline(lit.substring(4, lit.length - 3));
23628 } 23657 }
23629 else { 23658 else {
23630 return lit.substring(2, lit.length - 1); 23659 return lit.substring(2, lit.length - 1);
23631 } 23660 }
23632 } 23661 }
23633 else if ($notnull_bool(isMultilineString(lit))) { 23662 else if ($notnull_bool(isMultilineString(lit))) {
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
24068 NATIVE, 24097 NATIVE,
24069 NEGATE, 24098 NEGATE,
24070 OPERATOR, 24099 OPERATOR,
24071 SET, 24100 SET,
24072 SOURCE, 24101 SOURCE,
24073 STATIC, 24102 STATIC,
24074 TYPEDEF ]*/; 24103 TYPEDEF ]*/;
24075 var $globals = {}; 24104 var $globals = {};
24076 $static_init(); 24105 $static_init();
24077 main(); 24106 main();
OLDNEW
« no previous file with comments | « no previous file | frog/gen.dart » ('j') | frog/gen.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698