[dart2js] Remove most of elements/operators.dart

The rich hierarchy of operators is no longer relevant since parsing
was moved to the common front-end.

All that remains is a Set of operator names that can be used to
declare instance methods.

This set is used for picking the 'operator' variety of Selector. I'm not
sure we even need operator selectors, but I am leaving that for future
consideration.

Change-Id: I7337c0cf82a3cb8f7ebf5fa17a737bac3a83f48b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241560
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
diff --git a/pkg/compiler/lib/src/constants/constant_system.dart b/pkg/compiler/lib/src/constants/constant_system.dart
index c1ee3c9..9c68b0d 100644
--- a/pkg/compiler/lib/src/constants/constant_system.dart
+++ b/pkg/compiler/lib/src/constants/constant_system.dart
@@ -10,7 +10,6 @@
 
 import '../common/elements.dart' show CommonElements;
 import '../elements/entities.dart';
-import '../elements/operators.dart';
 import '../elements/types.dart';
 import 'values.dart';
 
@@ -185,64 +184,6 @@
   return ConstructedConstantValue(type, fields);
 }
 
-UnaryOperation lookupUnary(UnaryOperator operator) {
-  switch (operator.kind) {
-    case UnaryOperatorKind.COMPLEMENT:
-      return bitNot;
-    case UnaryOperatorKind.NEGATE:
-      return negate;
-    case UnaryOperatorKind.NOT:
-      return not;
-    default:
-      return null;
-  }
-}
-
-BinaryOperation lookupBinary(BinaryOperator operator) {
-  switch (operator.kind) {
-    case BinaryOperatorKind.ADD:
-      return add;
-    case BinaryOperatorKind.SUB:
-      return subtract;
-    case BinaryOperatorKind.MUL:
-      return multiply;
-    case BinaryOperatorKind.DIV:
-      return divide;
-    case BinaryOperatorKind.MOD:
-      return modulo;
-    case BinaryOperatorKind.IDIV:
-      return truncatingDivide;
-    case BinaryOperatorKind.OR:
-      return bitOr;
-    case BinaryOperatorKind.AND:
-      return bitAnd;
-    case BinaryOperatorKind.XOR:
-      return bitXor;
-    case BinaryOperatorKind.LOGICAL_OR:
-      return booleanOr;
-    case BinaryOperatorKind.LOGICAL_AND:
-      return booleanAnd;
-    case BinaryOperatorKind.SHL:
-      return shiftLeft;
-    case BinaryOperatorKind.SHR:
-      return shiftRight;
-    case BinaryOperatorKind.LT:
-      return less;
-    case BinaryOperatorKind.LTEQ:
-      return lessEqual;
-    case BinaryOperatorKind.GT:
-      return greater;
-    case BinaryOperatorKind.GTEQ:
-      return greaterEqual;
-    case BinaryOperatorKind.EQ:
-      return equal;
-    case BinaryOperatorKind.IF_NULL:
-      return ifNull;
-    default:
-      return null;
-  }
-}
-
 abstract class Operation {
   String get name;
 }
diff --git a/pkg/compiler/lib/src/elements/operators.dart b/pkg/compiler/lib/src/elements/operators.dart
index 89d2876..6c7317c 100644
--- a/pkg/compiler/lib/src/elements/operators.dart
+++ b/pkg/compiler/lib/src/elements/operators.dart
@@ -2,339 +2,37 @@
 // 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.
 
-// @dart = 2.10
-
 library dart2js.operators;
 
-import 'names.dart' show PublicName;
-import '../universe/call_structure.dart' show CallStructure;
-import '../universe/selector.dart' show Selector, SelectorKind;
+/// The names of all operators that can be used to define instance methods.
+const Set<String> instanceMethodOperatorNames = {
+  '[]=',
+  ..._unaryOperatorNames,
+  ..._binaryOperatorNames,
+};
 
-enum UnaryOperatorKind {
-  NOT,
-  NEGATE,
-  COMPLEMENT,
-}
+const Set<String> _unaryOperatorNames = {
+  '~',
+  'unary-',
+};
 
-class UnaryOperator {
-  final UnaryOperatorKind kind;
-  final String name;
-  final String selectorName;
-
-  const UnaryOperator(this.kind, this.name, this.selectorName);
-
-  bool get isUserDefinable => selectorName != null;
-
-  Selector get selector => Selector(
-      SelectorKind.OPERATOR, PublicName(selectorName), CallStructure.NO_ARGS);
-
-  @override
-  String toString() => name;
-
-  /// The unary ! operator.
-  static const UnaryOperator NOT =
-      UnaryOperator(UnaryOperatorKind.NOT, '!', null);
-
-  /// The unary - operator.
-  static const UnaryOperator NEGATE =
-      UnaryOperator(UnaryOperatorKind.NEGATE, '-', 'unary-');
-
-  /// The unary ~ operator.
-  static const UnaryOperator COMPLEMENT =
-      UnaryOperator(UnaryOperatorKind.COMPLEMENT, '~', '~');
-
-  static UnaryOperator parse(String value) {
-    switch (value) {
-      case '!':
-        return NOT;
-      case '-':
-        return NEGATE;
-      case '~':
-        return COMPLEMENT;
-      default:
-        return null;
-    }
-  }
-
-  // ignore: MISSING_RETURN
-  static UnaryOperator fromKind(UnaryOperatorKind kind) {
-    switch (kind) {
-      case UnaryOperatorKind.NOT:
-        return NOT;
-      case UnaryOperatorKind.NEGATE:
-        return NEGATE;
-      case UnaryOperatorKind.COMPLEMENT:
-        return COMPLEMENT;
-    }
-  }
-}
-
-enum BinaryOperatorKind {
-  EQ,
-  NOT_EQ,
-  INDEX,
-  ADD,
-  SUB,
-  MUL,
-  DIV,
-  IDIV,
-  MOD,
-  SHL,
-  SHR,
-  SHRU,
-  GTEQ,
-  GT,
-  LTEQ,
-  LT,
-  AND,
-  OR,
-  XOR,
-  LOGICAL_AND,
-  LOGICAL_OR,
-  IF_NULL,
-}
-
-class BinaryOperator {
-  final BinaryOperatorKind kind;
-  final String name;
-
-  const BinaryOperator._(this.kind, this.name);
-
-  /// `true` if this operator can be implemented through an `operator [name]`
-  /// method.
-  bool get isUserDefinable => true;
-
-  String get selectorName => name;
-
-  @override
-  String toString() => name;
-
-  /// The == operator.
-  static const BinaryOperator EQ =
-      BinaryOperator._(BinaryOperatorKind.EQ, '==');
-
-  /// The != operator.
-  static const BinaryOperator NOT_EQ = _NotEqualsOperator();
-
-  /// The [] operator.
-  static const BinaryOperator INDEX =
-      BinaryOperator._(BinaryOperatorKind.INDEX, '[]');
-
-  /// The binary + operator.
-  static const BinaryOperator ADD =
-      BinaryOperator._(BinaryOperatorKind.ADD, '+');
-
-  /// The binary - operator.
-  static const BinaryOperator SUB =
-      BinaryOperator._(BinaryOperatorKind.SUB, '-');
-
-  /// The binary * operator.
-  static const BinaryOperator MUL =
-      BinaryOperator._(BinaryOperatorKind.MUL, '*');
-
-  /// The binary / operator.
-  static const BinaryOperator DIV =
-      BinaryOperator._(BinaryOperatorKind.DIV, '/');
-
-  /// The binary ~/ operator.
-  static const BinaryOperator IDIV =
-      BinaryOperator._(BinaryOperatorKind.IDIV, '~/');
-
-  /// The binary % operator.
-  static const BinaryOperator MOD =
-      BinaryOperator._(BinaryOperatorKind.MOD, '%');
-
-  /// The binary << operator.
-  static const BinaryOperator SHL =
-      BinaryOperator._(BinaryOperatorKind.SHL, '<<');
-
-  /// The binary >> operator.
-  static const BinaryOperator SHR =
-      BinaryOperator._(BinaryOperatorKind.SHR, '>>');
-
-  /// The binary >>> operator.
-  static const BinaryOperator SHRU =
-      BinaryOperator._(BinaryOperatorKind.SHRU, '>>>');
-
-  /// The binary >= operator.
-  static const BinaryOperator GTEQ =
-      BinaryOperator._(BinaryOperatorKind.GTEQ, '>=');
-
-  /// The binary > operator.
-  static const BinaryOperator GT = BinaryOperator._(BinaryOperatorKind.GT, '>');
-
-  /// The binary <= operator.
-  static const BinaryOperator LTEQ =
-      BinaryOperator._(BinaryOperatorKind.LTEQ, '<=');
-
-  /// The binary < operator.
-  static const BinaryOperator LT = BinaryOperator._(BinaryOperatorKind.LT, '<');
-
-  /// The binary & operator.
-  static const BinaryOperator AND =
-      BinaryOperator._(BinaryOperatorKind.AND, '&');
-
-  /// The binary | operator.
-  static const BinaryOperator OR = BinaryOperator._(BinaryOperatorKind.OR, '|');
-
-  /// The binary ^ operator.
-  static const BinaryOperator XOR =
-      BinaryOperator._(BinaryOperatorKind.XOR, '^');
-
-  /// The logical && operator.
-  static const BinaryOperator LOGICAL_AND =
-      _LogicalOperator(BinaryOperatorKind.LOGICAL_AND, '&&');
-
-  /// The binary | operator.
-  static const BinaryOperator LOGICAL_OR =
-      _LogicalOperator(BinaryOperatorKind.LOGICAL_OR, '||');
-
-  /// The if-null ?? operator.
-  static const BinaryOperator IF_NULL =
-      _IfNullOperator(BinaryOperatorKind.IF_NULL, '??');
-
-  static BinaryOperator parse(String value) {
-    switch (value) {
-      case '&&':
-        return LOGICAL_AND;
-      case '||':
-        return LOGICAL_OR;
-      case '??':
-        return IF_NULL;
-      default:
-        return parseUserDefinable(value);
-    }
-  }
-
-  static BinaryOperator parseUserDefinable(String value) {
-    switch (value) {
-      case '==':
-        return EQ;
-      case '!=':
-        return NOT_EQ;
-      case '[]':
-        return INDEX;
-      case '*':
-        return MUL;
-      case '/':
-        return DIV;
-      case '%':
-        return MOD;
-      case '~/':
-        return IDIV;
-      case '+':
-        return ADD;
-      case '-':
-        return SUB;
-      case '<<':
-        return SHL;
-      case '>>':
-        return SHR;
-      case '>>>':
-        return SHRU;
-      case '>=':
-        return GTEQ;
-      case '>':
-        return GT;
-      case '<=':
-        return LTEQ;
-      case '<':
-        return LT;
-      case '&':
-        return AND;
-      case '^':
-        return XOR;
-      case '|':
-        return OR;
-      default:
-        return null;
-    }
-  }
-
-  // ignore: MISSING_RETURN
-  static BinaryOperator fromKind(BinaryOperatorKind kind) {
-    switch (kind) {
-      case BinaryOperatorKind.EQ:
-        return EQ;
-      case BinaryOperatorKind.NOT_EQ:
-        return NOT_EQ;
-      case BinaryOperatorKind.INDEX:
-        return INDEX;
-      case BinaryOperatorKind.MUL:
-        return MUL;
-      case BinaryOperatorKind.DIV:
-        return DIV;
-      case BinaryOperatorKind.MOD:
-        return MOD;
-      case BinaryOperatorKind.IDIV:
-        return IDIV;
-      case BinaryOperatorKind.ADD:
-        return ADD;
-      case BinaryOperatorKind.SUB:
-        return SUB;
-      case BinaryOperatorKind.SHL:
-        return SHL;
-      case BinaryOperatorKind.SHR:
-        return SHR;
-      case BinaryOperatorKind.SHRU:
-        return SHRU;
-      case BinaryOperatorKind.GTEQ:
-        return GTEQ;
-      case BinaryOperatorKind.GT:
-        return GT;
-      case BinaryOperatorKind.LTEQ:
-        return LTEQ;
-      case BinaryOperatorKind.LT:
-        return LT;
-      case BinaryOperatorKind.AND:
-        return AND;
-      case BinaryOperatorKind.XOR:
-        return XOR;
-      case BinaryOperatorKind.OR:
-        return OR;
-      case BinaryOperatorKind.LOGICAL_AND:
-        return LOGICAL_AND;
-      case BinaryOperatorKind.LOGICAL_OR:
-        return LOGICAL_OR;
-      case BinaryOperatorKind.IF_NULL:
-        return IF_NULL;
-    }
-  }
-}
-
-/// The operator !=, which is not user definable operator but instead is a
-/// negation of a call to user definable operator, namely ==.
-class _NotEqualsOperator extends BinaryOperator {
-  const _NotEqualsOperator() : super._(BinaryOperatorKind.NOT_EQ, '!=');
-
-  @override
-  bool get isUserDefinable => false;
-
-  @override
-  String get selectorName => '==';
-}
-
-/// The operators && and || which are not user definable operators but control
-/// structures.
-class _LogicalOperator extends BinaryOperator {
-  const _LogicalOperator(BinaryOperatorKind kind, String name)
-      : super._(kind, name);
-
-  @override
-  bool get isUserDefinable => false;
-
-  @override
-  String get selectorName => null;
-}
-
-/// The operators ?? is not user definable.
-class _IfNullOperator extends BinaryOperator {
-  const _IfNullOperator(BinaryOperatorKind kind, String name)
-      : super._(kind, name);
-
-  @override
-  bool get isUserDefinable => false;
-
-  @override
-  String get selectorName => '??';
-}
+const Set<String> _binaryOperatorNames = {
+  '==',
+  '[]',
+  '*',
+  '/',
+  '%',
+  '~/',
+  '+',
+  '-',
+  '<<',
+  '>>',
+  '>>>',
+  '>=',
+  '>',
+  '<=',
+  '<',
+  '&',
+  '^',
+  '|',
+};
diff --git a/pkg/compiler/lib/src/universe/selector.dart b/pkg/compiler/lib/src/universe/selector.dart
index 757c6c2..cdafadd 100644
--- a/pkg/compiler/lib/src/universe/selector.dart
+++ b/pkg/compiler/lib/src/universe/selector.dart
@@ -68,15 +68,7 @@
   LibraryEntity get library => memberName.library;
 
   static bool isOperatorName(String name) {
-    if (name == Names.INDEX_SET_NAME.text) {
-      return true;
-    } else if (name == UnaryOperator.NEGATE.selectorName) {
-      return true;
-    } else if (name == UnaryOperator.COMPLEMENT.selectorName) {
-      return true;
-    } else {
-      return BinaryOperator.parseUserDefinable(name) != null;
-    }
+    return instanceMethodOperatorNames.contains(name);
   }
 
   Selector.internal(