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

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: Address comments, set element for constructors in frontend_ast_to_backend_ast, adjust status-file 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 [makeExpression(left.index), makeExpression(exp.right)]); 336 [makeExpression(left.index), makeExpression(exp.right)]);
337 } else { 337 } else {
338 throw "Unexpected left-hand side of assignment: ${left}"; 338 throw "Unexpected left-hand side of assignment: ${left}";
339 } 339 }
340 tree.Operator op = new tree.Operator(assignmentToken(exp.operator)); 340 tree.Operator op = new tree.Operator(assignmentToken(exp.operator));
341 result = new tree.SendSet(receiver, selector, op, arguments); 341 result = new tree.SendSet(receiver, selector, op, arguments);
342 if (left is Identifier) { 342 if (left is Identifier) {
343 setElement(result, element, exp); 343 setElement(result, element, exp);
344 } 344 }
345 precedence = EXPRESSION; 345 precedence = EXPRESSION;
346 } else if (exp is FieldInitializer) {
347 precedence = EXPRESSION;
348 tree.Node receiver = makeIdentifier('this');
349 tree.Node selector = makeIdentifier(exp.element.name);
350 tree.Operator op = new tree.Operator(assignmentToken("="));
351 // We pass CALLEE to ensure we write eg.:
352 // class B { var x; B() : x = (() {return a;}) {}}
353 // Not the invalid:
354 // class B { var x; B() : x = () {return a;} {}}
355 result = new tree.SendSet(receiver, selector, op,
356 singleton(makeExp(exp.body, CALLEE)));
357 setElement(result, exp.element, exp);
358 } else if (exp is SuperInitializer) {
359 precedence = EXPRESSION;
360 tree.Node receiver = makeIdentifier('super');
361 tree.NodeList arguments =
362 argList(exp.arguments.map(makeArgument).toList());
363 if (exp.target.name == "") {
364 result = new tree.Send(null, receiver, arguments);
365 } else {
366 result = new tree.Send(receiver,
367 makeIdentifier(exp.target.name),
368 arguments);
369 }
370 setElement(result, exp.target, exp);
346 } else if (exp is BinaryOperator) { 371 } else if (exp is BinaryOperator) {
347 precedence = BINARY_PRECEDENCE[exp.operator]; 372 precedence = BINARY_PRECEDENCE[exp.operator];
348 int deltaLeft = isAssociativeBinaryOperator(precedence) ? 0 : 1; 373 int deltaLeft = isAssociativeBinaryOperator(precedence) ? 0 : 1;
349 result = new tree.Send( 374 result = new tree.Send(
350 makeExp(exp.left, precedence + deltaLeft, beginStmt: beginStmt), 375 makeExp(exp.left, precedence + deltaLeft, beginStmt: beginStmt),
351 new tree.Operator(binopToken(exp.operator)), 376 new tree.Operator(binopToken(exp.operator)),
352 singleton(makeExp(exp.right, precedence + 1))); 377 singleton(makeExp(exp.right, precedence + 1)));
353 } else if (exp is CallFunction) { 378 } else if (exp is CallFunction) {
354 precedence = CALLEE; 379 precedence = CALLEE;
355 tree.Node selector; 380 tree.Node selector;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 makeExp(exp.thenExpression, EXPRESSION), 441 makeExp(exp.thenExpression, EXPRESSION),
417 makeExp(exp.elseExpression, EXPRESSION), 442 makeExp(exp.elseExpression, EXPRESSION),
418 question, 443 question,
419 colon); 444 colon);
420 } else if (exp is FieldExpression) { 445 } else if (exp is FieldExpression) {
421 precedence = PRIMARY; 446 precedence = PRIMARY;
422 tree.Node receiver = exp.object is This 447 tree.Node receiver = exp.object is This
423 ? null 448 ? null
424 : makeExp(exp.object, PRIMARY, beginStmt: beginStmt); 449 : makeExp(exp.object, PRIMARY, beginStmt: beginStmt);
425 result = new tree.Send(receiver, makeIdentifier(exp.fieldName)); 450 result = new tree.Send(receiver, makeIdentifier(exp.fieldName));
451 } else if (exp is ConstructorDefinition) {
452 precedence = EXPRESSION;
453 tree.NodeList parameters = makeParameters(exp.parameters);
454 tree.NodeList initializers =
455 exp.initializers == null || exp.initializers.isEmpty
456 ? null
457 : makeList(",", exp.initializers.map(makeExpression).toList());
458 tree.Node body = exp.isConst || exp.body == null
459 ? new tree.EmptyStatement(semicolon)
460 : makeFunctionBody(exp.body);
461 result = new tree.FunctionExpression(constructorName(exp),
462 parameters,
463 body,
464 null, // return type
465 makeFunctionModifiers(exp),
466 initializers,
467 null, // get/set
468 null); // async modifier
469 setElement(result, exp.element, exp);
426 } else if (exp is FunctionExpression) { 470 } else if (exp is FunctionExpression) {
427 precedence = PRIMARY; 471 precedence = PRIMARY;
428 if (beginStmt && exp.name != null) { 472 if (beginStmt && exp.name != null) {
429 needParen = true; // Do not mistake for function declaration. 473 needParen = true; // Do not mistake for function declaration.
430 } 474 }
431 Token getOrSet = exp.isGetter 475 Token getOrSet = exp.isGetter
432 ? getToken 476 ? getToken
433 : exp.isSetter 477 : exp.isSetter
434 ? setToken 478 ? setToken
435 : null; 479 : null;
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 return makeModifiers(isStatic: isStatic, 1046 return makeModifiers(isStatic: isStatic,
1003 isConst: isConst, 1047 isConst: isConst,
1004 isFinal: isFinal, 1048 isFinal: isFinal,
1005 isVar: useVar && !(isConst || isFinal)); 1049 isVar: useVar && !(isConst || isFinal));
1006 } 1050 }
1007 1051
1008 tree.Modifiers makeFunctionModifiers(FunctionExpression exp) { 1052 tree.Modifiers makeFunctionModifiers(FunctionExpression exp) {
1009 if (exp.element == null) return makeEmptyModifiers(); 1053 if (exp.element == null) return makeEmptyModifiers();
1010 return makeModifiers(isExternal: exp.element.isExternal, 1054 return makeModifiers(isExternal: exp.element.isExternal,
1011 isStatic: exp.element.isStatic, 1055 isStatic: exp.element.isStatic,
1012 isFactory: exp.element.isFactoryConstructor); 1056 isFactory: exp.element.isFactoryConstructor,
1057 isConst: exp.element.isConst);
1013 } 1058 }
1014 1059
1015 tree.Node makeNodeForClassElement(elements.ClassElement cls) { 1060 tree.Node makeNodeForClassElement(elements.ClassElement cls) {
1016 if (cls.isMixinApplication) { 1061 if (cls.isMixinApplication) {
1017 return makeNamedMixinApplication(cls); 1062 return makeNamedMixinApplication(cls);
1018 } else { 1063 } else {
1019 return makeClassNode(cls); 1064 return makeClassNode(cls);
1020 } 1065 }
1021 } 1066 }
1022 1067
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 cls.interfaces, mixinTypes); 1219 cls.interfaces, mixinTypes);
1175 1220
1176 Token extendsKeyword = supernode != null ? extendsToken : null; 1221 Token extendsKeyword = supernode != null ? extendsToken : null;
1177 return new tree.ClassNode( 1222 return new tree.ClassNode(
1178 modifiers, name, typeParameters, supernode, 1223 modifiers, name, typeParameters, supernode,
1179 interfaces, openBrace, extendsKeyword, 1224 interfaces, openBrace, extendsKeyword,
1180 null, // No body. 1225 null, // No body.
1181 closeBrace); 1226 closeBrace);
1182 } 1227 }
1183 1228
1229 tree.Node constructorName(ConstructorDefinition exp) {
1230 String name = exp.name;
1231 tree.Identifier className = makeIdentifier(exp.element.enclosingClass.name);
1232 tree.Node result = name == ""
1233 ? className
1234 : new tree.Send(className, makeIdentifier(name));
1235 setElement(result, exp.element, exp);
1236 return result;
1237 }
1238
1184 tree.Node functionName(FunctionExpression exp) { 1239 tree.Node functionName(FunctionExpression exp) {
1185 String name = exp.name; 1240 String name = exp.name;
1186 if (name == null) return null; 1241 if (name == null) return null;
1187 if (isUserDefinableOperator(name)) { 1242 if (isUserDefinableOperator(name)) {
1188 return makeOperator("operator$name"); 1243 return makeOperator("operator$name");
1189 } else if (name == "unary-") { 1244 } else if (name == "unary-") {
1190 return makeOperator("operator-"); 1245 return makeOperator("operator-");
1191 } 1246 }
1192 return makeIdentifier(name); 1247 return makeIdentifier(name);
1193 } 1248 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 printStringChunk(chunk.previous), 1319 printStringChunk(chunk.previous),
1265 node); 1320 node);
1266 } else { 1321 } else {
1267 return node; 1322 return node;
1268 } 1323 }
1269 } 1324 }
1270 return printStringChunk(output.chunk); 1325 return printStringChunk(output.chunk);
1271 } 1326 }
1272 1327
1273 } 1328 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/dart_backend/backend_ast_nodes.dart ('k') | pkg/compiler/lib/src/dart_backend/placeholder_collector.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698