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

Side by Side Diff: lib/src/codegen/code_generator.dart

Issue 1141013002: Fixes #179 -- compile error if editing files during server mode (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 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 library dev_compiler.src.codegen.code_generator; 5 library dev_compiler.src.codegen.code_generator;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analyzer/src/generated/ast.dart' show CompilationUnit; 9 import 'package:analyzer/src/generated/ast.dart' show CompilationUnit;
10 import 'package:analyzer/src/generated/element.dart' 10 import 'package:analyzer/src/generated/element.dart'
11 show CompilationUnitElement, LibraryElement; 11 show CompilationUnitElement, LibraryElement;
12 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
12 import 'package:path/path.dart' as path; 13 import 'package:path/path.dart' as path;
13 14
15 import 'package:dev_compiler/devc.dart' show CompilerContext;
14 import 'package:dev_compiler/src/info.dart'; 16 import 'package:dev_compiler/src/info.dart';
15 import 'package:dev_compiler/src/utils.dart' show canonicalLibraryName; 17 import 'package:dev_compiler/src/utils.dart' show canonicalLibraryName;
16 import 'package:dev_compiler/src/checker/rules.dart'; 18 import 'package:dev_compiler/src/checker/rules.dart';
19 import 'package:dev_compiler/src/options.dart';
17 20
18 abstract class CodeGenerator { 21 abstract class CodeGenerator {
22 final CompilerContext compiler;
19 final String outDir; 23 final String outDir;
20 final Uri root; 24 final Uri root;
21 final TypeRules rules; 25 final TypeRules rules;
26 final AnalysisContext context;
27 final CompilerOptions options;
28
29 CodeGenerator(CompilerContext compiler)
30 : compiler = compiler,
31 outDir = path.absolute(compiler.options.outputDir),
32 root = compiler.entryPointUri,
33 rules = compiler.rules,
34 context = compiler.context,
35 options = compiler.options;
36
37 /// Return a hash, if any, that can be used for caching purposes. When two
38 /// invocations to this function return the same hash, the underlying
39 /// code-generator generated the same code.
40 String generateLibrary(LibraryUnit unit, LibraryInfo info);
22 41
23 static List<String> _searchPaths = () { 42 static List<String> _searchPaths = () {
24 // TODO(vsm): Can we remove redundancy with multi_package_resolver logic? 43 // TODO(vsm): Can we remove redundancy with multi_package_resolver logic?
25 var packagePaths = 44 var packagePaths =
26 new String.fromEnvironment('package_paths', defaultValue: null); 45 new String.fromEnvironment('package_paths', defaultValue: null);
27 if (packagePaths == null) return null; 46 if (packagePaths == null) return null;
28 var list = packagePaths.split(','); 47 var list = packagePaths.split(',');
29 // Normalize the paths. 48 // Normalize the paths.
30 list = new List<String>.from(list.map(_dirToPrefix)); 49 list = new List<String>.from(list.map(_dirToPrefix));
31 // The current directory is implicitly in the search path. 50 // The current directory is implicitly in the search path.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 if (index < 0) { 136 if (index < 0) {
118 // Not a package. 137 // Not a package.
119 // TODO(leafp) These may need to be adjusted 138 // TODO(leafp) These may need to be adjusted
120 // relative to the import location 139 // relative to the import location
121 return new Uri(path: suffix); 140 return new Uri(path: suffix);
122 } 141 }
123 assert(index == 0); 142 assert(index == 0);
124 return new Uri( 143 return new Uri(
125 scheme: 'package', path: path.joinAll(parts.sublist(index + 1))); 144 scheme: 'package', path: path.joinAll(parts.sublist(index + 1)));
126 } 145 }
127
128 CodeGenerator(String outDir, this.root, this.rules)
129 : outDir = path.absolute(outDir);
130
131 /// Return a hash, if any, that can be used for caching purposes. When two
132 /// invocations to this function return the same hash, the underlying
133 /// code-generator generated the same code.
134 String generateLibrary(LibraryUnit unit, LibraryInfo info);
135 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698