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

Side by Side Diff: pkg/compiler/lib/src/dart_backend/backend_ast_to_frontend_ast.dart

Issue 787603003: Generative constructors in the new dart backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 6 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart_tree_printer; 5 library dart_tree_printer;
6 6
7 import '../constants/values.dart' as values; 7 import '../constants/values.dart' as values;
8 import '../dart_types.dart' as types; 8 import '../dart_types.dart' as types;
9 import '../dart2jslib.dart' as dart2js; 9 import '../dart2jslib.dart' as dart2js;
10 import '../elements/elements.dart' as elements; 10 import '../elements/elements.dart' as elements;
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 [makeExpression(left.index), makeExpression(exp.right)]); 335 [makeExpression(left.index), makeExpression(exp.right)]);
336 } else { 336 } else {
337 throw "Unexpected left-hand side of assignment: ${left}"; 337 throw "Unexpected left-hand side of assignment: ${left}";
338 } 338 }
339 tree.Operator op = new tree.Operator(assignmentToken(exp.operator)); 339 tree.Operator op = new tree.Operator(assignmentToken(exp.operator));
340 result = new tree.SendSet(receiver, selector, op, arguments); 340 result = new tree.SendSet(receiver, selector, op, arguments);
341 if (left is Identifier) { 341 if (left is Identifier) {
342 setElement(result, element, exp); 342 setElement(result, element, exp);
343 } 343 }
344 precedence = EXPRESSION; 344 precedence = EXPRESSION;
345 } else if (exp is FieldInitializer) {
346 precedence = EXPRESSION;
347 tree.Node receiver = makeIdentifier('this');
348 tree.Node selector = makeIdentifier(exp.element.name);
349 tree.Operator op = new tree.Operator(assignmentToken("="));
350 // We pass CALLEE to ensure we write eg.:
351 // class B { var x; B() : x = (() {return a;}) {}}
352 // Not the invalid:
353 // class B { var x; B() : x = () {return a;} {}}
354 result = new tree.SendSet(receiver, selector, op,
355 singleton(makeExp(exp.body, CALLEE)));
356 setElement(result, exp.element, exp);
357 } else if (exp is SuperInitializer) {
358 precedence = EXPRESSION;
359 tree.Node receiver = makeIdentifier('super');
360 tree.NodeList arguments =
361 argList(exp.arguments.map(makeArgument).toList());
362 if (exp.target.name == "") {
363 result = new tree.Send(null, receiver, arguments);
364 } else {
365 result = new tree.Send(receiver,
366 makeIdentifier(exp.target.name),
367 arguments);
368 }
369 setElement(result, exp.target, exp);
345 } else if (exp is BinaryOperator) { 370 } else if (exp is BinaryOperator) {
346 precedence = BINARY_PRECEDENCE[exp.operator]; 371 precedence = BINARY_PRECEDENCE[exp.operator];
347 int deltaLeft = isAssociativeBinaryOperator(precedence) ? 0 : 1; 372 int deltaLeft = isAssociativeBinaryOperator(precedence) ? 0 : 1;
348 result = new tree.Send( 373 result = new tree.Send(
349 makeExp(exp.left, precedence + deltaLeft, beginStmt: beginStmt), 374 makeExp(exp.left, precedence + deltaLeft, beginStmt: beginStmt),
350 new tree.Operator(binopToken(exp.operator)), 375 new tree.Operator(binopToken(exp.operator)),
351 singleton(makeExp(exp.right, precedence + 1))); 376 singleton(makeExp(exp.right, precedence + 1)));
352 } else if (exp is CallFunction) { 377 } else if (exp is CallFunction) {
353 precedence = CALLEE; 378 precedence = CALLEE;
354 tree.Node selector; 379 tree.Node selector;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 makeExp(exp.thenExpression, EXPRESSION), 440 makeExp(exp.thenExpression, EXPRESSION),
416 makeExp(exp.elseExpression, EXPRESSION), 441 makeExp(exp.elseExpression, EXPRESSION),
417 question, 442 question,
418 colon); 443 colon);
419 } else if (exp is FieldExpression) { 444 } else if (exp is FieldExpression) {
420 precedence = PRIMARY; 445 precedence = PRIMARY;
421 tree.Node receiver = exp.object is This 446 tree.Node receiver = exp.object is This
422 ? null 447 ? null
423 : makeExp(exp.object, PRIMARY, beginStmt: beginStmt); 448 : makeExp(exp.object, PRIMARY, beginStmt: beginStmt);
424 result = new tree.Send(receiver, makeIdentifier(exp.fieldName)); 449 result = new tree.Send(receiver, makeIdentifier(exp.fieldName));
450 } else if (exp is ConstructorDefinition) {
451 precedence = EXPRESSION;
452 tree.NodeList parameters = makeParameters(exp.parameters);
453 tree.NodeList initializers =
454 exp.initializers == null || exp.initializers.isEmpty
455 ? null
456 : makeList(",", exp.initializers.map(makeExpression).toList());
457 tree.Node body = exp.isConst || exp.body == null
458 ? new tree.EmptyStatement(semicolon)
459 : makeFunctionBody(exp.body);
460 result = new tree.FunctionExpression(constructorName(exp),
461 parameters,
462 body,
463 null, // return type
464 makeFunctionModifiers(exp),
465 initializers,
466 null, // get/set
467 null); // async modifier
425 } else if (exp is FunctionExpression) { 468 } else if (exp is FunctionExpression) {
426 precedence = PRIMARY; 469 precedence = PRIMARY;
427 if (beginStmt && exp.name != null) { 470 if (beginStmt && exp.name != null) {
428 needParen = true; // Do not mistake for function declaration. 471 needParen = true; // Do not mistake for function declaration.
429 } 472 }
430 Token getOrSet = exp.isGetter 473 Token getOrSet = exp.isGetter
431 ? getToken 474 ? getToken
432 : exp.isSetter 475 : exp.isSetter
433 ? setToken 476 ? setToken
434 : null; 477 : null;
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 return makeModifiers(isStatic: isStatic, 1044 return makeModifiers(isStatic: isStatic,
1002 isConst: isConst, 1045 isConst: isConst,
1003 isFinal: isFinal, 1046 isFinal: isFinal,
1004 isVar: useVar && !(isConst || isFinal)); 1047 isVar: useVar && !(isConst || isFinal));
1005 } 1048 }
1006 1049
1007 tree.Modifiers makeFunctionModifiers(FunctionExpression exp) { 1050 tree.Modifiers makeFunctionModifiers(FunctionExpression exp) {
1008 if (exp.element == null) return makeEmptyModifiers(); 1051 if (exp.element == null) return makeEmptyModifiers();
1009 return makeModifiers(isExternal: exp.element.isExternal, 1052 return makeModifiers(isExternal: exp.element.isExternal,
1010 isStatic: exp.element.isStatic, 1053 isStatic: exp.element.isStatic,
1011 isFactory: exp.element.isFactoryConstructor); 1054 isFactory: exp.element.isFactoryConstructor,
1055 isConst: exp.element.isConst);
1012 } 1056 }
1013 1057
1014 tree.Node makeNodeForClassElement(elements.ClassElement cls) { 1058 tree.Node makeNodeForClassElement(elements.ClassElement cls) {
1015 if (cls.isMixinApplication) { 1059 if (cls.isMixinApplication) {
1016 return makeNamedMixinApplication(cls); 1060 return makeNamedMixinApplication(cls);
1017 } else { 1061 } else {
1018 return makeClassNode(cls); 1062 return makeClassNode(cls);
1019 } 1063 }
1020 } 1064 }
1021 1065
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 cls.interfaces, mixinTypes); 1198 cls.interfaces, mixinTypes);
1155 1199
1156 Token extendsKeyword = supernode != null ? extendsToken : null; 1200 Token extendsKeyword = supernode != null ? extendsToken : null;
1157 return new tree.ClassNode( 1201 return new tree.ClassNode(
1158 modifiers, name, typeParameters, supernode, 1202 modifiers, name, typeParameters, supernode,
1159 interfaces, openBrace, extendsKeyword, 1203 interfaces, openBrace, extendsKeyword,
1160 null, // No body. 1204 null, // No body.
1161 closeBrace); 1205 closeBrace);
1162 } 1206 }
1163 1207
1208 tree.Node constructorName(ConstructorDefinition exp) {
1209 String name = exp.name;
1210 tree.Identifier className = makeIdentifier(exp.element.enclosingClass.name);
1211 tree.Node result = name == ""
1212 ? className
1213 : new tree.Send(className, makeIdentifier(name));
1214 setElement(result, exp.element, exp);
1215 return result;
1216 }
1217
1164 tree.Node functionName(FunctionExpression exp) { 1218 tree.Node functionName(FunctionExpression exp) {
1165 String name = exp.name; 1219 String name = exp.name;
1166 if (name == null) return null; 1220 if (name == null) return null;
1167 if (isUserDefinableOperator(name)) { 1221 if (isUserDefinableOperator(name)) {
1168 return makeOperator("operator$name"); 1222 return makeOperator("operator$name");
1169 } else if (name == "unary-") { 1223 } else if (name == "unary-") {
1170 return makeOperator("operator-"); 1224 return makeOperator("operator-");
1171 } 1225 }
1172 return makeIdentifier(name); 1226 return makeIdentifier(name);
1173 } 1227 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 printStringChunk(chunk.previous), 1298 printStringChunk(chunk.previous),
1245 node); 1299 node);
1246 } else { 1300 } else {
1247 return node; 1301 return node;
1248 } 1302 }
1249 } 1303 }
1250 return printStringChunk(output.chunk); 1304 return printStringChunk(output.chunk);
1251 } 1305 }
1252 1306
1253 } 1307 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698