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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1050203002: Begin making copies of AST nodes for constants during resolution. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 engine.resolver; 5 library engine.resolver;
6 6
7 import "dart:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/utilities_collection.dart'; 10 import 'package:analyzer/src/generated/utilities_collection.dart';
(...skipping 2828 matching lines...) Expand 10 before | Expand all | Expand 10 after
2839 //of this parameter. 2839 //of this parameter.
2840 // 2840 //
2841 ElementHolder holder = new ElementHolder(); 2841 ElementHolder holder = new ElementHolder();
2842 _visitChildren(holder, node); 2842 _visitChildren(holder, node);
2843 (node.element as ParameterElementImpl).parameters = holder.parameters; 2843 (node.element as ParameterElementImpl).parameters = holder.parameters;
2844 holder.validate(); 2844 holder.validate();
2845 return null; 2845 return null;
2846 } 2846 }
2847 2847
2848 @override 2848 @override
2849 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
2850 if (node.isConst) {
2851 node.constantHandle = new ConstantInstanceCreationHandle();
2852 }
2853 return super.visitInstanceCreationExpression(node);
2854 }
2855
2856 @override
2849 Object visitLabeledStatement(LabeledStatement node) { 2857 Object visitLabeledStatement(LabeledStatement node) {
2850 bool onSwitchStatement = node.statement is SwitchStatement; 2858 bool onSwitchStatement = node.statement is SwitchStatement;
2851 for (Label label in node.labels) { 2859 for (Label label in node.labels) {
2852 SimpleIdentifier labelName = label.label; 2860 SimpleIdentifier labelName = label.label;
2853 LabelElementImpl element = 2861 LabelElementImpl element =
2854 new LabelElementImpl(labelName, onSwitchStatement, false); 2862 new LabelElementImpl(labelName, onSwitchStatement, false);
2855 _currentHolder.addLabel(element); 2863 _currentHolder.addLabel(element);
2856 labelName.staticElement = element; 2864 labelName.staticElement = element;
2857 } 2865 }
2858 return super.visitLabeledStatement(node); 2866 return super.visitLabeledStatement(node);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
3057 } else { 3065 } else {
3058 field = new FieldElementImpl.forNode(fieldName); 3066 field = new FieldElementImpl.forNode(fieldName);
3059 } 3067 }
3060 element = field; 3068 element = field;
3061 _currentHolder.addField(field); 3069 _currentHolder.addField(field);
3062 fieldName.staticElement = field; 3070 fieldName.staticElement = field;
3063 } else if (_inFunction) { 3071 } else if (_inFunction) {
3064 SimpleIdentifier variableName = node.name; 3072 SimpleIdentifier variableName = node.name;
3065 LocalVariableElementImpl variable; 3073 LocalVariableElementImpl variable;
3066 if (isConst && hasInitializer) { 3074 if (isConst && hasInitializer) {
3067 variable = new ConstLocalVariableElementImpl(variableName); 3075 variable = new ConstLocalVariableElementImpl.forNode(variableName);
3068 } else { 3076 } else {
3069 variable = new LocalVariableElementImpl.forNode(variableName); 3077 variable = new LocalVariableElementImpl.forNode(variableName);
3070 } 3078 }
3071 element = variable; 3079 element = variable;
3072 Block enclosingBlock = node.getAncestor((node) => node is Block); 3080 Block enclosingBlock = node.getAncestor((node) => node is Block);
3073 int functionEnd = node.offset + node.length; 3081 int functionEnd = node.offset + node.length;
3074 int blockEnd = enclosingBlock.offset + enclosingBlock.length; 3082 int blockEnd = enclosingBlock.offset + enclosingBlock.length;
3075 // TODO(brianwilkerson) This isn't right for variables declared in a for 3083 // TODO(brianwilkerson) This isn't right for variables declared in a for
3076 // loop. 3084 // loop.
3077 variable.setVisibleRange(functionEnd, blockEnd - functionEnd - 1); 3085 variable.setVisibleRange(functionEnd, blockEnd - functionEnd - 1);
(...skipping 7631 matching lines...) Expand 10 before | Expand all | Expand 10 after
10709 10717
10710 @override 10718 @override
10711 Object visitConstructorDeclaration(ConstructorDeclaration node) { 10719 Object visitConstructorDeclaration(ConstructorDeclaration node) {
10712 ExecutableElement outerFunction = _enclosingFunction; 10720 ExecutableElement outerFunction = _enclosingFunction;
10713 try { 10721 try {
10714 _enclosingFunction = node.element; 10722 _enclosingFunction = node.element;
10715 super.visitConstructorDeclaration(node); 10723 super.visitConstructorDeclaration(node);
10716 } finally { 10724 } finally {
10717 _enclosingFunction = outerFunction; 10725 _enclosingFunction = outerFunction;
10718 } 10726 }
10727 ConstructorElementImpl constructor = node.element;
10728 constructor.constantInitializers =
10729 new ConstantAstCloner().cloneNodeList(node.initializers);
10719 return null; 10730 return null;
10720 } 10731 }
10721 10732
10722 @override 10733 @override
10723 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { 10734 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
10724 // 10735 //
10725 // We visit the expression, but do not visit the field name because it needs 10736 // We visit the expression, but do not visit the field name because it needs
10726 // to be visited in the context of the constructor field initializer node. 10737 // to be visited in the context of the constructor field initializer node.
10727 // 10738 //
10728 safelyVisit(node.expression); 10739 safelyVisit(node.expression);
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
11151 _overrideManager.exitScope(); 11162 _overrideManager.exitScope();
11152 _overrideManager.applyOverrides(overrides); 11163 _overrideManager.applyOverrides(overrides);
11153 } 11164 }
11154 return null; 11165 return null;
11155 } 11166 }
11156 11167
11157 @override 11168 @override
11158 Object visitTypeName(TypeName node) => null; 11169 Object visitTypeName(TypeName node) => null;
11159 11170
11160 @override 11171 @override
11172 Object visitVariableDeclaration(VariableDeclaration node) {
11173 super.visitVariableDeclaration(node);
11174 if (node.element.isConst && node.initializer != null) {
11175 ConstVariableElementImpl element = node.element;
11176 element.constantInitializer =
11177 new ConstantAstCloner().cloneNode(node.initializer);
11178 }
11179 return null;
11180 }
11181
11182 @override
11161 Object visitWhileStatement(WhileStatement node) { 11183 Object visitWhileStatement(WhileStatement node) {
11162 // Note: since we don't call the base class, we have to maintain 11184 // Note: since we don't call the base class, we have to maintain
11163 // _implicitLabelScope ourselves. 11185 // _implicitLabelScope ourselves.
11164 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; 11186 ImplicitLabelScope outerImplicitScope = _implicitLabelScope;
11165 try { 11187 try {
11166 _implicitLabelScope = _implicitLabelScope.nest(node); 11188 _implicitLabelScope = _implicitLabelScope.nest(node);
11167 Expression condition = node.condition; 11189 Expression condition = node.condition;
11168 safelyVisit(condition); 11190 safelyVisit(condition);
11169 Statement body = node.body; 11191 Statement body = node.body;
11170 if (body != null) { 11192 if (body != null) {
(...skipping 4181 matching lines...) Expand 10 before | Expand all | Expand 10 after
15352 element.displayName 15374 element.displayName
15353 ]); 15375 ]);
15354 } 15376 }
15355 super.visitPropertyAccessorElement(element); 15377 super.visitPropertyAccessorElement(element);
15356 } 15378 }
15357 15379
15358 bool _isNamedUnderscore(LocalVariableElement element) { 15380 bool _isNamedUnderscore(LocalVariableElement element) {
15359 String name = element.name; 15381 String name = element.name;
15360 if (name != null) { 15382 if (name != null) {
15361 for (int index = name.length - 1; index >= 0; --index) { 15383 for (int index = name.length - 1; index >= 0; --index) {
15362 if (name.codeUnitAt(index) != 0x5F) { // 0x5F => '_' 15384 if (name.codeUnitAt(index) != 0x5F) {
15385 // 0x5F => '_'
15363 return false; 15386 return false;
15364 } 15387 }
15365 } 15388 }
15366 return true; 15389 return true;
15367 } 15390 }
15368 return false; 15391 return false;
15369 } 15392 }
15370 15393
15371 bool _isReadMember(Element element) { 15394 bool _isReadMember(Element element) {
15372 if (element.isPublic) { 15395 if (element.isPublic) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
15460 } 15483 }
15461 15484
15462 bool isCatchException(LocalVariableElement element) { 15485 bool isCatchException(LocalVariableElement element) {
15463 return catchExceptionElements.contains(element); 15486 return catchExceptionElements.contains(element);
15464 } 15487 }
15465 15488
15466 bool isCatchStackTrace(LocalVariableElement element) { 15489 bool isCatchStackTrace(LocalVariableElement element) {
15467 return catchStackTraceElements.contains(element); 15490 return catchStackTraceElements.contains(element);
15468 } 15491 }
15469 } 15492 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698