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

Unified Diff: lib/compiler/implementation/compiler.dart

Issue 10703188: Allow patch files to add top-level declarations to the patched library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated min/max in unified/math library. Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: lib/compiler/implementation/compiler.dart
diff --git a/lib/compiler/implementation/compiler.dart b/lib/compiler/implementation/compiler.dart
index 6b130e442bb074e78040abd5a662f3bb11e6d8d2..1f060b13f65c78825f04b1c2c2b8ab4ec6acb344 100644
--- a/lib/compiler/implementation/compiler.dart
+++ b/lib/compiler/implementation/compiler.dart
@@ -534,7 +534,7 @@ class Compiler implements DiagnosticListener {
Uri resolved = patchBase.resolve(argument.dartString.slowToString());
LibraryElement importedLibrary =
scanner.loadLibrary(resolved, argument);
- scanner.importLibrary(original, importedLibrary, tag, patch);
+ scanner.importLibrary(original, importedLibrary, tag, patch.script);
if (resolved.scheme == "dart") {
delayedPatches[resolved.path] = importedLibrary;
}
@@ -588,11 +588,20 @@ class Compiler implements DiagnosticListener {
}
}
} else if (originalElement === null) {
+ // The original library does not have an element with the same name
+ // as the patch library element.
+ // In this case, the patch library element must not be marked as
+ // "patch", and its name must make it private.
if (isPatchElement(patchElement)) {
internalError("Cannot patch non-existing member '"
"${patchElement.name.slowToString()}'.");
}
- original.addMember(clonePatch(patchElement), this);
+ if (!patchElement.name.isPrivate()) {
+ internalError("Cannot add non-private member '"
+ "${patchElement.name.slowToString()}' from patch.");
+ }
+ Element cloneElement = patchElement.cloneTo(original, this);
+ original.addMember(cloneElement, this);
} else {
patchMember(originalElement, patchElement);
}
@@ -606,20 +615,6 @@ class Compiler implements DiagnosticListener {
return !element.metadata.isEmpty();
}
- Element clonePatch(Element patchElement) {
- // The original library does not have an element with the same name
- // as the patch library element.
- // In this case, the patch library element must not be marked as "patch",
- // and its name must make it private.
- if (!patchElement.name.isPrivate()) {
- internalError("Cannot add non-private member '"
- "${patchElement.name.slowToString()}' from patch.");
- }
- // TODO(lrn): Create a copy of patchElement that isn't added to any
- // object/library yet, but which takes its source from patchElement.
- throw "Adding members from patch is unsupported";
- }
-
void patchMember(Element originalElement, Element patchElement) {
// The original library has an element with the same name as the patch
// library element.
@@ -978,7 +973,7 @@ class Compiler implements DiagnosticListener {
throw 'Cannot find tokens to produce error message.';
}
if (uri === null && currentElement !== null) {
- uri = currentElement.getCompilationUnit().script.uri;
+ uri = currentElement.getScript().uri;
}
return SourceSpan.withCharacterOffsets(begin, end,
(beginOffset, endOffset) => new SourceSpan(uri, beginOffset, endOffset));
@@ -1002,7 +997,7 @@ class Compiler implements DiagnosticListener {
element = currentElement;
}
Token position = element.position();
- Uri uri = element.getCompilationUnit().script.uri;
+ Uri uri = element.getScript().uri;
return (position === null)
? new SourceSpan(uri, 0, 0)
: spanFromTokens(position, position, uri);

Powered by Google App Engine
This is Rietveld 408576698