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

Side by Side Diff: pkg/analyzer2dart/lib/src/cps_generator.dart

Issue 867233004: Support constructor declarations in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months 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 analyzer2dart.cps_generator; 5 library analyzer2dart.cps_generator;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 8
9 import 'package:compiler/src/dart_types.dart' as dart2js; 9 import 'package:compiler/src/dart_types.dart' as dart2js;
10 import 'package:compiler/src/elements/elements.dart' as dart2js; 10 import 'package:compiler/src/elements/elements.dart' as dart2js;
(...skipping 27 matching lines...) Expand all
38 element, functionDeclaration.functionExpression); 38 element, functionDeclaration.functionExpression);
39 } 39 }
40 40
41 @override 41 @override
42 ir.FieldDefinition visitTopLevelVariableElement( 42 ir.FieldDefinition visitTopLevelVariableElement(
43 analyzer.TopLevelVariableElement element) { 43 analyzer.TopLevelVariableElement element) {
44 CpsGeneratingVisitor visitor = new CpsGeneratingVisitor(converter, element); 44 CpsGeneratingVisitor visitor = new CpsGeneratingVisitor(converter, element);
45 VariableDeclaration variableDeclaration = node; 45 VariableDeclaration variableDeclaration = node;
46 return visitor.handleFieldDeclaration(element, variableDeclaration); 46 return visitor.handleFieldDeclaration(element, variableDeclaration);
47 } 47 }
48
49 @override
50 ir.ExecutableDefinition visitConstructorElement(
51 analyzer.ConstructorElement element) {
52 CpsGeneratingVisitor visitor = new CpsGeneratingVisitor(converter, element);
53 if (!element.isFactory) {
54 ConstructorDeclaration constructorDeclaration = node;
55 return visitor.handleConstructorDeclaration(
56 element, constructorDeclaration);
57 }
58 // TODO(johnniwinther): Support factory constructors.
59 return null;
60 }
48 } 61 }
49 62
50 /// Visitor that converts analyzer AST nodes into CPS ir nodes. 63 /// Visitor that converts analyzer AST nodes into CPS ir nodes.
51 class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> 64 class CpsGeneratingVisitor extends SemanticVisitor<ir.Node>
52 with IrBuilderMixin<AstNode> { 65 with IrBuilderMixin<AstNode> {
53 /// Promote the type of [irBuilder] to [DartIrBuilder]. 66 /// Promote the type of [irBuilder] to [DartIrBuilder].
54 /// The JS backend requires closure conversion which we do not support yet. 67 /// The JS backend requires closure conversion which we do not support yet.
55 DartIrBuilder get irBuilder => super.irBuilder; 68 DartIrBuilder get irBuilder => super.irBuilder;
56 final analyzer.Element element; 69 final analyzer.Element element;
57 final ElementConverter converter; 70 final ElementConverter converter;
58 71
59 CpsGeneratingVisitor(this.converter, this.element); 72 CpsGeneratingVisitor(this.converter, this.element);
60 73
61 Source get currentSource => element.source; 74 Source get currentSource => element.source;
62 75
63 analyzer.LibraryElement get currentLibrary => element.library; 76 analyzer.LibraryElement get currentLibrary => element.library;
64 77
65 ir.Node visit(AstNode node) => node.accept(this); 78 ir.Node visit(AstNode node) => node.accept(this);
66 79
80 ir.ConstructorDefinition handleConstructorDeclaration(
81 analyzer.ConstructorElement constructor, ConstructorDeclaration node) {
82 FunctionBody body = node.body;
83 dart2js.ConstructorElement element = converter.convertElement(constructor);
84 return withBuilder(
85 new DartIrBuilder(DART_CONSTANT_SYSTEM,
86 element,
87 // TODO(johnniwinther): Supported closure variables.
88 new NullCapturedVariableInfo()),
89 () {
90 irBuilder.buildFunctionHeader(
91 constructor.parameters.map(converter.convertElement));
92 // Visit the body directly to avoid processing the signature as
93 // expressions.
94 visit(node.body);
95 return irBuilder.makeConstructorDefinition(const [], const []);
96 });
97 }
98
67 ir.FieldDefinition handleFieldDeclaration( 99 ir.FieldDefinition handleFieldDeclaration(
68 analyzer.PropertyInducingElement field, VariableDeclaration node) { 100 analyzer.PropertyInducingElement field, VariableDeclaration node) {
69 dart2js.FieldElement element = converter.convertElement(field); 101 dart2js.FieldElement element = converter.convertElement(field);
70 return withBuilder( 102 return withBuilder(
71 new DartIrBuilder(DART_CONSTANT_SYSTEM, 103 new DartIrBuilder(DART_CONSTANT_SYSTEM,
72 element, 104 element,
73 // TODO(johnniwinther): Supported closure variables. 105 // TODO(johnniwinther): Supported closure variables.
74 new NullCapturedVariableInfo()), 106 new NullCapturedVariableInfo()),
75 () { 107 () {
76 irBuilder.buildFieldInitializerHeader(); 108 irBuilder.buildFieldInitializerHeader();
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 return irBuilder.buildTypeOperator( 556 return irBuilder.buildTypeOperator(
525 visit(node.expression), 557 visit(node.expression),
526 converter.convertType(node.type.type), 558 converter.convertType(node.type.type),
527 isTypeTest: false); 559 isTypeTest: false);
528 } 560 }
529 } 561 }
530 562
531 class NullCapturedVariableInfo extends DartCapturedVariableInfo { 563 class NullCapturedVariableInfo extends DartCapturedVariableInfo {
532 Iterable get capturedVariables => const []; 564 Iterable get capturedVariables => const [];
533 } 565 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer2dart/lib/src/dart_backend.dart » ('j') | pkg/analyzer2dart/lib/src/dart_backend.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698