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

Unified Diff: pkg/front_end/lib/src/base/instrumentation.dart

Issue 2824393002: Introduce a testing framework for use with fasta type inference. (Closed)
Patch Set: Created 3 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 side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/src/base/instrumentation.dart
diff --git a/pkg/front_end/lib/src/base/instrumentation.dart b/pkg/front_end/lib/src/base/instrumentation.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6722c0062fe29cc0e4f788c82481a046a0fd49ad
--- /dev/null
+++ b/pkg/front_end/lib/src/base/instrumentation.dart
@@ -0,0 +1,58 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// 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 'package:kernel/ast.dart';
+
+/// Interface providing the ability to record property/value pairs associated
+/// with source file locations. Intended to facilitate testing.
+abstract class Instrumentation {
+ /// Records a property/value pair associated with the given URI and offset.
+ void record(String property, Uri uri, int offset, InstrumentationValue value);
+}
+
+/// Interface for values recorded by [Instrumentation].
+abstract class InstrumentationValue {
+ const InstrumentationValue();
+
+ /// Converts the value to the string representation most suitable for
+ /// storing as an annotation in a source file.
+ ///
+ /// Invariant: `this.matches(this.canonicalize())` should always return
+ /// `true`.
+ String canonicalize();
ahe 2017/04/19 11:38:29 Is this a potential gotcha? Perhaps we should just
Paul Berry 2017/04/19 13:20:09 Good point. Fixed.
+
+ /// Checks if the given String is an accurate description of this value.
+ ///
+ /// The default implementation just checks for equality with the return value
+ /// of [canonicalize], however derived classes may want a more sophisticated
+ /// implementation (e.g. to allow abbreviations in the description).
+ ///
+ /// Derived classes should ensure that the invariant holds:
+ /// `this.matches(this.canonicalize())` should always return `true`.
+ bool matches(String description) => description == canonicalize();
+}
+
+/// Instance of [InstrumentationValue] describing a [DartType].
+class InstrumentationValueForType extends InstrumentationValue {
+ final DartType type;
+
+ InstrumentationValueForType(this.type);
+
+ @override
+ String canonicalize() {
+ // Convert '→' to '->' because '→' doesn't show up in some terminals.
+ return type.toString().replaceAll('→', '->');
+ }
+}
+
+/// Instance of [InstrumentationValue] which only matches the given literal
+/// string.
+class InstrumentationValueLiteral extends InstrumentationValue {
+ final String value;
+
+ const InstrumentationValueLiteral(this.value);
+
+ @override
+ String canonicalize() => value;
+}

Powered by Google App Engine
This is Rietveld 408576698