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

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/hint/Dart2JSVerifier.java

Issue 23496048: Add additional hints to the analyzer to catch the 'x is double' dart2js bug. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase to latest & merge Created 7 years, 3 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: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/hint/Dart2JSVerifier.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/hint/Dart2JSVerifier.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/hint/Dart2JSVerifier.java
new file mode 100644
index 0000000000000000000000000000000000000000..8fe72c38447f8ecb9d92fb04febde56921d0de4a
--- /dev/null
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/hint/Dart2JSVerifier.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2013, the Dart project authors.
+ *
+ * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.dart.engine.internal.hint;
+
+import com.google.dart.engine.ast.IsExpression;
+import com.google.dart.engine.ast.TypeName;
+import com.google.dart.engine.ast.visitor.RecursiveASTVisitor;
+import com.google.dart.engine.element.Element;
+import com.google.dart.engine.element.LibraryElement;
+import com.google.dart.engine.error.HintCode;
+import com.google.dart.engine.internal.error.ErrorReporter;
+import com.google.dart.engine.type.Type;
+
+/**
+ * Instances of the class {@code Dart2JSVerifier} traverse an AST structure looking for hints for
+ * code that will be compiled to JS, such as {@link HintCode#IS_DOUBLE}.
+ *
+ * @coverage dart.engine.resolver
+ */
+public class Dart2JSVerifier extends RecursiveASTVisitor<Void> {
+
+ /**
+ * The error reporter by which errors will be reported.
+ */
+ private ErrorReporter errorReporter;
+
+ /**
+ * The name of the {@code double} type.
+ */
+ private static final String DOUBLE_TYPE_NAME = "double";
+
+ /**
+ * The name of the {@code int} type.
+ */
+ private static final String INT_TYPE_NAME = "int";
+
+ /**
+ * Create a new instance of the {@link Dart2JSVerifier}.
+ *
+ * @param errorReporter the error reporter
+ */
+ public Dart2JSVerifier(ErrorReporter errorReporter) {
+ this.errorReporter = errorReporter;
+ }
+
+ @Override
+ public Void visitIsExpression(IsExpression node) {
+ checkForIsDoubleHints(node);
+ return super.visitIsExpression(node);
+ }
+
+ /**
+ * Check for instances of {@code x is double}, {@code x is int}, {@code x is! double} and
+ * {@code x is! int}.
+ *
+ * @param node the is expression to check
+ * @return {@code true} if and only if a hint code is generated on the passed node
+ * @see HintCode#IS_DOUBLE
+ * @see HintCode#IS_INT
+ * @see HintCode#IS_NOT_DOUBLE
+ * @see HintCode#IS_NOT_INT
+ */
+ private boolean checkForIsDoubleHints(IsExpression node) {
+ TypeName typeName = node.getType();
+ Type type = typeName.getType();
+ if (type != null && type.getElement() != null) {
+ Element element = type.getElement();
+ String typeNameStr = element.getName();
+ LibraryElement libraryElement = element.getLibrary();
+ if (typeNameStr.equals(INT_TYPE_NAME) && libraryElement != null
+ && libraryElement.isDartCore()) {
+ if (node.getNotOperator() == null) {
+ errorReporter.reportError(HintCode.IS_INT, node);
+ } else {
+ errorReporter.reportError(HintCode.IS_NOT_INT, node);
+ }
+ return true;
+ } else if (typeNameStr.equals(DOUBLE_TYPE_NAME) && libraryElement != null
+ && libraryElement.isDartCore()) {
+ if (node.getNotOperator() == null) {
+ errorReporter.reportError(HintCode.IS_DOUBLE, node);
+ } else {
+ errorReporter.reportError(HintCode.IS_NOT_DOUBLE, node);
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+}

Powered by Google App Engine
This is Rietveld 408576698