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

Side by Side Diff: lib/src/utils.dart

Issue 1055923002: Don't call dinvoke on Object methods (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Refactor dynamic target logic 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// Holds a couple utility functions used at various places in the system. 5 /// Holds a couple utility functions used at various places in the system.
6 library dev_compiler.src.utils; 6 library dev_compiler.src.utils;
7 7
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
11 import 'package:analyzer/src/generated/ast.dart' 11 import 'package:analyzer/src/generated/ast.dart'
12 show 12 show
13 ImportDirective, 13 ImportDirective,
14 ExportDirective, 14 ExportDirective,
15 PartDirective, 15 PartDirective,
16 CompilationUnit, 16 CompilationUnit,
17 Identifier, 17 Identifier,
18 AnnotatedNode, 18 AnnotatedNode,
19 AstNode; 19 AstNode,
20 Expression,
21 SimpleIdentifier;
20 import 'package:analyzer/src/generated/engine.dart' 22 import 'package:analyzer/src/generated/engine.dart'
21 show ParseDartTask, AnalysisContext; 23 show ParseDartTask, AnalysisContext;
22 import 'package:analyzer/src/generated/source.dart' show Source; 24 import 'package:analyzer/src/generated/source.dart' show Source;
23 import 'package:analyzer/src/generated/element.dart'; 25 import 'package:analyzer/src/generated/element.dart';
24 import 'package:analyzer/analyzer.dart' show parseDirectives; 26 import 'package:analyzer/analyzer.dart' show parseDirectives;
25 import 'package:crypto/crypto.dart' show CryptoUtils, MD5; 27 import 'package:crypto/crypto.dart' show CryptoUtils, MD5;
26 import 'package:source_span/source_span.dart'; 28 import 'package:source_span/source_span.dart';
27 import 'package:yaml/yaml.dart'; 29 import 'package:yaml/yaml.dart';
28 30
29 import 'codegen/js_names.dart' show invalidJSVariableName; 31 import 'codegen/js_names.dart' show invalidJSVariableName;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } catch (e) { 196 } catch (e) {
195 // TODO(sigmund): remove this try-catch block (see issue #48). 197 // TODO(sigmund): remove this try-catch block (see issue #48).
196 } 198 }
197 if (baseMethod == null || baseMethod.isStatic) return null; 199 if (baseMethod == null || baseMethod.isStatic) return null;
198 return baseMethod.type; 200 return baseMethod.type;
199 } 201 }
200 ; 202 ;
201 return f; 203 return f;
202 } 204 }
203 205
206 bool isDynamicTarget(Expression target) {
207 return target != null &&
208 !(target is SimpleIdentifier && target.staticElement is PrefixElement) &&
209 target.staticType.isDynamic;
210 }
211
204 /// Returns an ANSII color escape sequence corresponding to [levelName]. Colors 212 /// Returns an ANSII color escape sequence corresponding to [levelName]. Colors
205 /// are defined for: severe, error, warning, or info. Returns null if the level 213 /// are defined for: severe, error, warning, or info. Returns null if the level
206 /// name is not recognized. 214 /// name is not recognized.
207 String colorOf(String levelName) { 215 String colorOf(String levelName) {
208 levelName = levelName.toLowerCase(); 216 levelName = levelName.toLowerCase();
209 if (levelName == 'shout' || levelName == 'severe' || levelName == 'error') { 217 if (levelName == 'shout' || levelName == 'severe' || levelName == 'error') {
210 return _RED_COLOR; 218 return _RED_COLOR;
211 } 219 }
212 if (levelName == 'warning') return _MAGENTA_COLOR; 220 if (levelName == 'warning') return _MAGENTA_COLOR;
213 if (levelName == 'info') return _CYAN_COLOR; 221 if (levelName == 'info') return _CYAN_COLOR;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 // TODO(jmesserly): can we implement this without repeatedly reading pubspec? 337 // TODO(jmesserly): can we implement this without repeatedly reading pubspec?
330 // It seems like we should know our package's root directory without needing 338 // It seems like we should know our package's root directory without needing
331 // to search like this. 339 // to search like this.
332 var pubspec = 340 var pubspec =
333 loadYaml(new File(path.join(dir, 'pubspec.yaml')).readAsStringSync()); 341 loadYaml(new File(path.join(dir, 'pubspec.yaml')).readAsStringSync());
334 342
335 // Ensure this is loaded from the dev_compiler package. 343 // Ensure this is loaded from the dev_compiler package.
336 if (pubspec['name'] != 'dev_compiler') return null; 344 if (pubspec['name'] != 'dev_compiler') return null;
337 return path.join('dev_compiler', 'runtime', filename); 345 return path.join('dev_compiler', 'runtime', filename);
338 } 346 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698