fix #33036, dartdevk now uses CFE for patching its SDK

Change-Id: I65e7df5373c359019b4b7c5714ae71a80d60df13
Reviewed-on: https://dart-review.googlesource.com/53682
Reviewed-by: Vijay Menon <vsm@google.com>
diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart
index e8aa203..bc50ca2 100644
--- a/pkg/dev_compiler/lib/src/kernel/compiler.dart
+++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart
@@ -1367,15 +1367,19 @@
 
   JS.Expression _emitConstructor(
       Constructor node, List<Field> fields, JS.Expression className) {
+    var savedUri = _currentUri;
+    _currentUri = node.fileUri ?? savedUri;
     var params = _emitFormalParameters(node.function);
     var body = _withCurrentFunction(
         node.function,
         () => _superDisallowed(
             () => _emitConstructorBody(node, fields, className)));
 
-    return new JS.Fun(params, new JS.Block(body))
-      ..sourceInformation = _nodeEnd(node.fileEndOffset) ??
-          _nodeEnd(node.enclosingClass.fileEndOffset);
+    var end = _nodeEnd(node.fileEndOffset);
+    _currentUri = savedUri;
+    end ??= _nodeEnd(node.enclosingClass.fileEndOffset);
+
+    return new JS.Fun(params, new JS.Block(body))..sourceInformation = end;
   }
 
   List<JS.Statement> _emitConstructorBody(
@@ -1617,7 +1621,9 @@
       }
     }
 
+    var savedUri = _currentUri;
     for (var m in c.procedures) {
+      _currentUri = m.fileUri ?? savedUri;
       if (m.isForwardingStub) {
         // TODO(jmesserly): is there any other kind of forwarding stub?
         jsMethods.addAll(_emitCovarianceCheckStub(m));
@@ -1636,6 +1642,7 @@
         jsMethods.add(_emitMethodDeclaration(m));
       }
     }
+    _currentUri = savedUri;
 
     _classProperties.mockMembers.forEach((String name, Member member) {
       jsMethods
diff --git a/pkg/dev_compiler/tool/input_sdk/lib/libraries.json b/pkg/dev_compiler/tool/input_sdk/lib/libraries.json
index 74a20ef..49b904f 100644
--- a/pkg/dev_compiler/tool/input_sdk/lib/libraries.json
+++ b/pkg/dev_compiler/tool/input_sdk/lib/libraries.json
@@ -18,7 +18,7 @@
       },
       "_internal": {
         "uri": "../../../../../sdk/lib/internal/internal.dart",
-        "patch": "../patch/internal_patch.dart"
+        "patches": "../patch/internal_patch.dart"
       },
       "_isolate_helper": {
         "uri": "../private/isolate_helper.dart"
@@ -40,43 +40,43 @@
       },
       "async": {
         "uri": "../../../../../sdk/lib/async/async.dart",
-        "patch": "../patch/async_patch.dart"
+        "patches": "../patch/async_patch.dart"
       },
       "collection": {
         "uri": "../../../../../sdk/lib/collection/collection.dart",
-        "patch": "../patch/collection_patch.dart"
+        "patches": "../patch/collection_patch.dart"
       },
       "convert": {
         "uri": "../../../../../sdk/lib/convert/convert.dart",
-        "patch": "../patch/convert_patch.dart"
+        "patches": "../patch/convert_patch.dart"
       },
       "core": {
         "uri": "../../../../../sdk/lib/core/core.dart",
-        "patch": "../patch/core_patch.dart"
+        "patches": "../patch/core_patch.dart"
       },
       "developer": {
         "uri": "../../../../../sdk/lib/developer/developer.dart",
-        "patch": "../patch/developer_patch.dart"
+        "patches": "../patch/developer_patch.dart"
       },
       "io": {
         "uri": "../../../../../sdk/lib/io/io.dart",
-        "patch": "../patch/io_patch.dart"
+        "patches": "../patch/io_patch.dart"
       },
       "isolate": {
         "uri": "../../../../../sdk/lib/isolate/isolate.dart",
-        "patch": "../patch/isolate_patch.dart"
+        "patches": "../patch/isolate_patch.dart"
       },
       "mirrors": {
         "uri": "../../../../../sdk/lib/mirrors/mirrors.dart",
-        "patch": "../patch/mirrors_patch.dart"
+        "patches": "../patch/mirrors_patch.dart"
       },
       "math": {
         "uri": "../../../../../sdk/lib/math/math.dart",
-        "patch": "../patch/math_patch.dart"
+        "patches": "../patch/math_patch.dart"
       },
       "typed_data": {
         "uri": "../../../../../sdk/lib/typed_data/typed_data.dart",
-        "patch": "../patch/typed_data_patch.dart"
+        "patches": "../patch/typed_data_patch.dart"
       },
       "html": {
         "uri": "../../../../../sdk/lib/html/dart2js/html_dart2js.dart"
diff --git a/pkg/dev_compiler/tool/input_sdk/patch/async_patch.dart b/pkg/dev_compiler/tool/input_sdk/patch/async_patch.dart
index b04009e..1dabfb7 100644
--- a/pkg/dev_compiler/tool/input_sdk/patch/async_patch.dart
+++ b/pkg/dev_compiler/tool/input_sdk/patch/async_patch.dart
@@ -15,7 +15,7 @@
 
 @JSExportName('async')
 @ReifyFunctionTypes(false)
-async_<T>(Function() initGenerator) {
+_async<T>(Function() initGenerator) {
   var iter;
   Object Function(Object) onValue;
   Object Function(Object) onError;
diff --git a/pkg/dev_compiler/tool/input_sdk/patch/core_patch.dart b/pkg/dev_compiler/tool/input_sdk/patch/core_patch.dart
index 4ed3ec3..7ae52ae 100644
--- a/pkg/dev_compiler/tool/input_sdk/patch/core_patch.dart
+++ b/pkg/dev_compiler/tool/input_sdk/patch/core_patch.dart
@@ -19,13 +19,11 @@
         Primitives,
         PrivateSymbol,
         quoteStringForRegExp;
-
 import 'dart:_runtime' as dart;
-
 import 'dart:_foreign_helper' show JS;
-
 import 'dart:_native_typed_data' show NativeUint8List;
-
+import 'dart:collection' show UnmodifiableMapView;
+import 'dart:convert' show Encoding, utf8;
 import 'dart:typed_data' show Endian, Uint8List, Uint16List;
 
 String _symbolToString(Symbol symbol) => symbol is PrivateSymbol
diff --git a/pkg/dev_compiler/tool/input_sdk/patch/developer_patch.dart b/pkg/dev_compiler/tool/input_sdk/patch/developer_patch.dart
index d9c577b..99a85fd 100644
--- a/pkg/dev_compiler/tool/input_sdk/patch/developer_patch.dart
+++ b/pkg/dev_compiler/tool/input_sdk/patch/developer_patch.dart
@@ -6,6 +6,8 @@
 
 import 'dart:_js_helper' show patch, ForceInline;
 import 'dart:_foreign_helper' show JS;
+import 'dart:async';
+import 'dart:isolate';
 
 @patch
 @ForceInline()
diff --git a/pkg/dev_compiler/tool/input_sdk/patch/internal_patch.dart b/pkg/dev_compiler/tool/input_sdk/patch/internal_patch.dart
index c750542..5e850bb 100644
--- a/pkg/dev_compiler/tool/input_sdk/patch/internal_patch.dart
+++ b/pkg/dev_compiler/tool/input_sdk/patch/internal_patch.dart
@@ -2,6 +2,8 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+import 'dart:core' hide Symbol;
+import 'dart:core' as core show Symbol;
 import 'dart:_js_primitives' show printString;
 import 'dart:_js_helper' show patch;
 import 'dart:_interceptors' show JSArray;
diff --git a/pkg/dev_compiler/tool/input_sdk/patch/io_patch.dart b/pkg/dev_compiler/tool/input_sdk/patch/io_patch.dart
index 8d3236e..604c0c8 100644
--- a/pkg/dev_compiler/tool/input_sdk/patch/io_patch.dart
+++ b/pkg/dev_compiler/tool/input_sdk/patch/io_patch.dart
@@ -3,6 +3,10 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'dart:_js_helper' show patch;
+import 'dart:async';
+import 'dart:convert';
+import 'dart:isolate' show SendPort;
+import 'dart:typed_data';
 
 @patch
 class _Directory {
diff --git a/pkg/dev_compiler/tool/input_sdk/patch/isolate_patch.dart b/pkg/dev_compiler/tool/input_sdk/patch/isolate_patch.dart
index a0464f3..bd0b258 100644
--- a/pkg/dev_compiler/tool/input_sdk/patch/isolate_patch.dart
+++ b/pkg/dev_compiler/tool/input_sdk/patch/isolate_patch.dart
@@ -5,6 +5,7 @@
 // Patch file for the dart:isolate library.
 
 import 'dart:_js_helper' show patch, NoReifyGeneric;
+import 'dart:async';
 
 @patch
 class Isolate {
diff --git a/pkg/dev_compiler/tool/kernel_sdk.dart b/pkg/dev_compiler/tool/kernel_sdk.dart
index fac6737..f2d5623 100755
--- a/pkg/dev_compiler/tool/kernel_sdk.dart
+++ b/pkg/dev_compiler/tool/kernel_sdk.dart
@@ -15,7 +15,6 @@
 import 'package:front_end/src/api_prototype/kernel_generator.dart';
 import 'package:kernel/kernel.dart';
 import 'package:path/path.dart' as path;
-import 'patch_sdk.dart' as patch_sdk;
 
 Future main(List<String> args) async {
   // Parse flags.
@@ -28,9 +27,7 @@
   var outputPath =
       path.absolute(rest.length > 0 ? rest[0] : 'gen/sdk/kernel/ddc_sdk.dill');
 
-  patch_sdk.main(['../..', 'tool/input_sdk', 'gen/patched_sdk']);
-
-  var inputPath = path.absolute('gen/patched_sdk');
+  var inputPath = path.absolute('tool/input_sdk');
   var target = new DevCompilerTarget();
   var options = new CompilerOptions()
     ..compileSdk = true